1 diff -urN libpcap-0.9.8/gencode.c.rej libpcap-0.9.8.new/gencode.c.rej
2 --- libpcap-0.9.8/gencode.c.rej 2007-07-10 21:38:15.000000000 +0200
3 +++ libpcap-0.9.8.new/gencode.c.rej 1970-01-01 01:00:00.000000000 +0100
7 - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.51 2007/06/14 20:54:12 gianluca Exp $ (LBL)";
10 - #ifdef HAVE_CONFIG_H
14 - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.51 2007/06/14 20:54:12 gianluca Exp $ (LBL)";
17 -+ #define ENABLE_WLAN_FILTERING_PATCH
19 - #ifdef HAVE_CONFIG_H
24 - OR_NET, /* relative to the network-layer header */
25 - OR_NET_NOSNAP, /* relative to the network-layer header, with no SNAP header at the link layer */
26 - OR_TRAN_IPV4, /* relative to the transport-layer header, with IPv4 network layer */
27 -- OR_TRAN_IPV6 /* relative to the transport-layer header, with IPv6 network layer */
32 - OR_NET, /* relative to the network-layer header */
33 - OR_NET_NOSNAP, /* relative to the network-layer header, with no SNAP header at the link layer */
34 - OR_TRAN_IPV4, /* relative to the transport-layer header, with IPv4 network layer */
35 -+ OR_TRAN_IPV6, /* relative to the transport-layer header, with IPv6 network layer */
36 -+ OR_LINK_AFTER_WIRELESS_HDR /* After the 802.11 variable length header */
42 - static struct block *gen_linktype(int);
43 - static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);
44 - static struct block *gen_llc_linktype(int);
45 - static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
47 - static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);
49 - static struct block *gen_linktype(int);
50 - static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);
51 - static struct block *gen_llc_linktype(int);
52 -+ static struct block *gen_802_11_llc_linktype(int);
53 - static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);
55 - static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);
58 - static struct slist *xfer_to_a(struct arth *);
59 - static struct block *gen_mac_multicast(int);
60 - static struct block *gen_len(int, int);
62 - static struct block *gen_ppi_dlt_check();
63 - static struct block *gen_msg_abbrev(int type);
65 - static struct slist *xfer_to_a(struct arth *);
66 - static struct block *gen_mac_multicast(int);
67 - static struct block *gen_len(int, int);
68 -+ static struct block *gen_check_802_11_data_frame();
70 - static struct block *gen_ppi_dlt_check();
71 - static struct block *gen_msg_abbrev(int type);
79 - * Load a value relative to the beginning of the specified header.
85 -+ * Load a value relative to the beginning of the link-layer header after the 802.11
86 -+ * header, i.e. LLC_SNAP.
87 -+ * The link-layer header doesn't necessarily begin at the beginning
88 -+ * of the packet data; there might be a variable-length prefix containing
89 -+ * radio information.
91 -+ static struct slist *
92 -+ gen_load_ll_after_802_11_rel(offset, size)
93 -+ u_int offset, size;
95 -+ struct slist *s, *s_load_fc;
96 -+ struct slist *sjset_qos;
97 -+ struct slist *s_load;
98 -+ struct slist *s_ld_a_2;
99 -+ struct slist *s_add_a_x;
100 -+ struct slist *s_a_to_x;
101 -+ struct slist *sjset_data_frame_1;
102 -+ struct slist *sjset_data_frame_2;
103 -+ struct slist *s_load_x_0;
106 -+ * This code is not compatible with the optimizer, as
107 -+ * we are generating jmp instructions within a normal
108 -+ * slist of instructions
113 -+ s = gen_llprefixlen();
116 -+ * If "s" is non-null, it has code to arrange that the X register
117 -+ * contains the length of the prefix preceding the link-layer
120 -+ * Otherwise, the length of the prefix preceding the link-layer
121 -+ * header is "off_ll".
125 -+ * There's a variable-length prefix preceding the
126 -+ * link-layer header. "s" points to a list of statements
127 -+ * that put the length of that prefix into the X register.
128 -+ * do an indirect load, to use the X register as an offset.
132 -+ * Load the Frame Control field
134 -+ s_load_fc = new_stmt(BPF_LD|BPF_IND|BPF_B);
135 -+ s_load_fc->s.k = 0;
138 -+ * There is no variable-length header preceding the
139 -+ * link-layer header; add in off_ll, which, if there's
140 -+ * a fixed-length header preceding the link-layer header,
141 -+ * is the length of that header.
145 -+ * We need to load the Frame control directly, and
146 -+ * then load X with a fake 0, i.e. the length of the
147 -+ * non-existing prepended header
151 -+ * TODO GV: I'm not sure if 0 is the right constant in this
152 -+ * case. If the link layer has a fixed length prepended header,
153 -+ * that should be the value that we put here
156 -+ /* Load 0 into X */
157 -+ s_load_x_0 = new_stmt(BPF_LDX|BPF_IMM);
158 -+ s_load_x_0->s.k = 0;
161 -+ * TODO GV: I'm not sure if 0 is the right constant in this
162 -+ * case. If the link layer has a fixed length prepended header,
163 -+ * that should be the value that we put here
167 -+ * load the Frame Control with absolute access
169 -+ s_load_fc = new_stmt(BPF_LD|BPF_ABS|BPF_B);
170 -+ s_load_fc->s.k = 0;
175 -+ * Generate the common instructions to check if it's a data frame
176 -+ * and if so compute the 802.11 header length
178 -+ sjset_data_frame_1 = new_stmt(JMP(BPF_JSET)); // b3 should be 1
179 -+ sjset_data_frame_1->s.k = 0x8;
181 -+ sjset_data_frame_2 = new_stmt(JMP(BPF_JSET)); // b2 should be 0
182 -+ sjset_data_frame_2->s.k = 0x04;
184 -+ sjset_qos = new_stmt(JMP(BPF_JSET));
185 -+ sjset_qos->s.k = 0x80; //QOS bit
187 -+ s_ld_a_2 = new_stmt(BPF_LD|BPF_IMM);
188 -+ s_ld_a_2->s.k = 2;
190 -+ s_add_a_x = new_stmt(BPF_ALU|BPF_ADD|BPF_X);
191 -+ s_a_to_x = new_stmt(BPF_MISC|BPF_TAX);
193 -+ s_load = new_stmt(BPF_LD|BPF_IND|size);
194 -+ s_load->s.k = offset;
196 -+ sjset_data_frame_1->s.jt = sjset_data_frame_2;
197 -+ sjset_data_frame_1->s.jf = s_load;
199 -+ sjset_data_frame_2->s.jt = s_load;
200 -+ sjset_data_frame_2->s.jf = sjset_qos;
202 -+ sjset_qos->s.jt = s_ld_a_2;
203 -+ sjset_qos->s.jf = s_load;
205 -+ sappend(s, s_load_fc);
206 -+ sappend(s_load_fc, sjset_data_frame_1);
207 -+ sappend(sjset_data_frame_1, sjset_data_frame_2);
208 -+ sappend(sjset_data_frame_2, sjset_qos);
209 -+ sappend(sjset_qos, s_ld_a_2);
210 -+ sappend(s_ld_a_2, s_add_a_x);
211 -+ sappend(s_add_a_x,s_a_to_x);
212 -+ sappend(s_a_to_x, s_load);
218 - * Load a value relative to the beginning of the specified header.
221 - s = gen_load_llrel(offset, size);
225 - s = gen_load_llrel(off_nl + offset, size);
228 - s = gen_load_llrel(offset, size);
231 -+ #ifdef ENABLE_WLAN_FILTERING_PATCH
233 -+ case OR_LINK_AFTER_WIRELESS_HDR:
234 -+ if (linktype != DLT_IEEE802_11_RADIO
235 -+ && linktype != DLT_PPI
236 -+ && linktype != DLT_IEEE802_11
237 -+ && linktype != DLT_PRISM_HEADER
238 -+ && linktype != DLT_IEEE802_11_RADIO_AVS)
243 -+ s = gen_load_ll_after_802_11_rel(offset + 24, size);
245 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
248 - s = gen_load_llrel(off_nl + offset, size);
257 -- case DLT_IEEE802_11:
258 - case DLT_IEEE802_11_RADIO_AVS:
259 -- case DLT_IEEE802_11_RADIO:
260 - case DLT_PRISM_HEADER:
261 - case DLT_ATM_RFC1483:
267 -+ case DLT_IEEE802_11_RADIO:
268 -+ case DLT_IEEE802_11:
269 -+ #ifdef ENABLE_WLAN_FILTERING_PATCH
270 -+ return gen_802_11_llc_linktype(proto);
273 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
277 - case DLT_IEEE802_11_RADIO_AVS:
278 - case DLT_PRISM_HEADER:
279 - case DLT_ATM_RFC1483:
286 - static struct block *
287 - gen_hostop(addr, mask, dir, proto, src_off, dst_off)
294 -+ * Generate code to match a particular packet type, for link-layer types
295 -+ * using 802.2 LLC headers.
297 -+ * This is *NOT* used for Ethernet; "gen_ether_linktype()" is used
298 -+ * for that - it handles the D/I/X Ethernet vs. 802.3+802.2 issues.
300 -+ * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
301 -+ * value, if <= ETHERMTU. We use that to determine whether to
302 -+ * match the DSAP or both DSAP and LSAP or to check the OUI and
303 -+ * protocol ID in a SNAP header.
305 -+ static struct block *
306 -+ gen_802_11_llc_linktype(proto)
309 -+ struct block *b_check_data_frame;
310 -+ struct block *b_check_linktype;
312 -+ b_check_data_frame = gen_check_802_11_data_frame();
315 -+ * XXX - generate the code that discards non data frames
320 -+ case LLCSAP_ISONS:
321 -+ case LLCSAP_NETBEUI:
323 -+ * XXX - should we check both the DSAP and the
324 -+ * SSAP, like this, or should we check just the
325 -+ * DSAP, as we do for other types <= ETHERMTU
326 -+ * (i.e., other SAP values)?
328 -+ b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_H, (bpf_u_int32)
329 -+ ((proto << 8) | proto));
334 -+ * XXX - are there ever SNAP frames for IPX on
335 -+ * non-Ethernet 802.x networks?
337 -+ b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_B,
338 -+ (bpf_int32)LLCSAP_IPX);
343 -+ case ETHERTYPE_ATALK:
345 -+ * 802.2-encapsulated ETHERTYPE_ATALK packets are
346 -+ * SNAP packets with an organization code of
347 -+ * 0x080007 (Apple, for Appletalk) and a protocol
348 -+ * type of ETHERTYPE_ATALK (Appletalk).
350 -+ * XXX - check for an organization code of
351 -+ * encapsulated Ethernet as well?
353 -+ return gen_snap(0x080007, ETHERTYPE_ATALK, off_linktype);
357 -+ * XXX - we don't have to check for IPX 802.3
358 -+ * here, but should we check for the IPX Ethertype?
360 -+ if (proto <= ETHERMTU) {
362 -+ * This is an LLC SAP value, so check
365 -+ b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_B,
366 -+ (bpf_int32)proto);
369 -+ * This is an Ethernet type; we assume that it's
370 -+ * unlikely that it'll appear in the right place
371 -+ * at random, and therefore check only the
372 -+ * location that would hold the Ethernet type
373 -+ * in a SNAP frame with an organization code of
374 -+ * 0x000000 (encapsulated Ethernet).
376 -+ * XXX - if we were to check for the SNAP DSAP and
377 -+ * LSAP, as per XXX, and were also to check for an
378 -+ * organization code of 0x000000 (encapsulated
379 -+ * Ethernet), we'd do
381 -+ * return gen_snap(0x000000, proto,
384 -+ * here; for now, we don't, as per the above.
385 -+ * I don't know whether it's worth the extra CPU
386 -+ * time to do the right check or not.
388 -+ b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0+6, BPF_H,
389 -+ (bpf_int32)proto);
393 -+ gen_and(b_check_data_frame, b_check_linktype);
394 -+ return b_check_linktype;
400 - static struct block *
401 - gen_hostop(addr, mask, dir, proto, src_off, dst_off)
405 - register struct block *b0, *b1, *b2;
406 - register struct slist *s;
412 - register struct block *b0, *b1, *b2;
413 - register struct slist *s;
415 -+ #ifdef ENABLE_WLAN_FILTERING_PATCH
417 -+ * TODO GV 20070613
418 -+ * We need to disable the optimizer because the optimizer is buggy
419 -+ * and wipes out some LD instructions generated by the below
420 -+ * code to validate the Frame Control bits
424 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
436 - * Generate code that checks whether the packet is a packet for protocol
441 -+ static struct block *
442 -+ gen_check_802_11_data_frame()
445 -+ struct block *b0, *b1;
447 -+ * Now check for a data frame.
448 -+ * I.e, check "link[0] & 0x08".
450 -+ s = gen_load_a(OR_LINK, 0, BPF_B);
451 -+ b0 = new_block(JMP(BPF_JSET));
455 -+ s = gen_load_a(OR_LINK, 0, BPF_B);
456 -+ b1 = new_block(JMP(BPF_JSET));
469 - * Generate code that checks whether the packet is a packet for protocol