File: vblade-15-socketfilter.2.diff

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