vblade-15-socketfilter.2.diff 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. diff -uNpr vblade-15-orig/freebsd.c vblade-15-lsf/freebsd.c
  2. --- vblade-15-orig/freebsd.c 2008-03-07 20:22:16.000000000 +0000
  3. +++ vblade-15-lsf/freebsd.c 2008-04-30 10:45:11.000000000 +0100
  4. @@ -54,40 +54,44 @@ dial(char *eth)
  5. /* packet filter for bpf */
  6. struct bpf_insn bpf_insns[] = {
  7. - /* Load the type into register */
  8. - BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
  9. - /* Does it match AoE Type (0x88a2)? No, goto INVALID */
  10. - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 10),
  11. - /* Load the flags into register */
  12. - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14),
  13. - /* Check to see if the Resp flag is set */
  14. - BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp),
  15. - /* Yes, goto INVALID */
  16. - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 7),
  17. - /* Load the command into register */
  18. - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 19),
  19. - /* Is this a ATAcmd? No, goto VALID */
  20. - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ATAcmd, 0, 4),
  21. - /* Load the shelf number into register */
  22. - BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16),
  23. - /* Does it match shelf number? No, goto INVALID */
  24. - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 3),
  25. - /* Load the slot number into register */
  26. - BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18),
  27. - /* Does it match shelf number? No, goto INVALID */
  28. - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 0, 1),
  29. - /* VALID: return -1 (allow the packet to be read) */
  30. - BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
  31. - /* INVALID: return 0 (ignore the packet) */
  32. - BPF_STMT(BPF_RET+BPF_K, 0),
  33. + /* Load the type into register */
  34. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
  35. + /* Does it match AoE Type (0x88a2)? No, goto INVALID */
  36. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 12),
  37. + /* Load the flags into register */
  38. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14),
  39. + /* Check to see if the Resp flag is set */
  40. + BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp),
  41. + /* Yes, goto INVALID */
  42. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 9),
  43. + /* Load the shelf number into register */
  44. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16),
  45. + /* Does it match shelf number? No, goto CHECKBROADCAST */
  46. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 2),
  47. + /* Load the slot number into register */
  48. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18),
  49. + /* Does it match shelf number? Yes, goto VALID */
  50. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 4, 0),
  51. + /* CHECKBROADCAST: is (shelf, slot) == (0xffff, 0xff)? */
  52. + /* Load the shelf number into register */
  53. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16),
  54. + /* Is it 0xffff? No, goto INVALID */
  55. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xffff, 0, 3),
  56. + /* Load the slot number into register */
  57. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18),
  58. + /* Is it 0xff? No, goto INVALID */
  59. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xff, 0, 1),
  60. + /* VALID: return -1 (allow the packet to be read) */
  61. + BPF_STMT(BPF_RET+BPF_K, (u_int) -1),
  62. + /* INVALID: return 0 (ignore the packet) */
  63. + BPF_STMT(BPF_RET+BPF_K, 0),
  64. };
  65. struct bpf_program bpf_program = {
  66. - sizeof(bpf_insns)/sizeof(struct bpf_insn),
  67. - bpf_insns
  68. + sizeof(bpf_insns)/sizeof(struct bpf_insn),
  69. + bpf_insns
  70. };
  71. -
  72. -
  73. +
  74. strncpy(device, BPF_DEV, sizeof BPF_DEV);
  75. /* find a bpf device we can use, check /dev/bpf[0-9] */
  76. diff -uNpr vblade-15-orig/linux.c vblade-15-lsf/linux.c
  77. --- vblade-15-orig/linux.c 2008-03-07 20:22:16.000000000 +0000
  78. +++ vblade-15-lsf/linux.c 2008-04-30 10:46:04.000000000 +0100
  79. @@ -22,6 +22,7 @@
  80. #include <netinet/in.h>
  81. #include <linux/fs.h>
  82. #include <sys/stat.h>
  83. +#include <pcap-bpf.h>
  84. #include "dat.h"
  85. #include "fns.h"
  86. @@ -54,6 +55,49 @@ dial(char *eth) // get us a raw connect
  87. perror("bind funky");
  88. return -1;
  89. }
  90. +
  91. + /* bpf packet filter for socket */
  92. + struct bpf_insn bpf_insns[] = {
  93. + /* Load the type into register */
  94. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
  95. + /* Does it match AoE Type (0x88a2)? No, goto INVALID */
  96. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x88a2, 0, 12),
  97. + /* Load the flags into register */
  98. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 14),
  99. + /* Check to see if the Resp flag is set */
  100. + BPF_STMT(BPF_ALU+BPF_AND+BPF_K, Resp),
  101. + /* Yes, goto INVALID */
  102. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 9),
  103. + /* Load the shelf number into register */
  104. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16),
  105. + /* Does it match shelf number? No, goto CHECKBROADCAST */
  106. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) shelf, 0, 2),
  107. + /* Load the slot number into register */
  108. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18),
  109. + /* Does it match shelf number? Yes, goto VALID */
  110. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) slot, 4, 0),
  111. + /* CHECKBROADCAST: is (shelf, slot) == (0xffff, 0xff)? */
  112. + /* Load the shelf number into register */
  113. + BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 16),
  114. + /* Is it 0xffff? No, goto INVALID */
  115. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xffff, 0, 3),
  116. + /* Load the slot number into register */
  117. + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 18),
  118. + /* Is it 0xff? No, goto INVALID */
  119. + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (u_int) 0xff, 0, 1),
  120. + /* VALID: return -1 (allow the packet to be read) */
  121. + BPF_STMT(BPF_RET+BPF_K, (u_int) -1),
  122. + /* INVALID: return 0 (ignore the packet) */
  123. + BPF_STMT(BPF_RET+BPF_K, 0),
  124. + };
  125. +
  126. + struct bpf_program bpf_program = {
  127. + sizeof(bpf_insns)/sizeof(struct bpf_insn),
  128. + bpf_insns
  129. + };
  130. +
  131. + setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_program, sizeof(bpf_program));
  132. +
  133. return s;
  134. }