Update libpcap to 0.9.8 (#3571)
[openwrt.git] / package / libpcap / patches / 104-no_rej_files.patch
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
4 @@ -1,465 +0,0 @@
5 -***************
6 -*** 24,29 ****
7 -      "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.51 2007/06/14 20:54:12 gianluca Exp $ (LBL)";\r
8 -  #endif\r
9 -  \r
10 -  #ifdef HAVE_CONFIG_H\r
11 -  #include "config.h"\r
12 -  #endif\r
13 ---- 24,31 ----
14 -      "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.221.2.51 2007/06/14 20:54:12 gianluca Exp $ (LBL)";\r
15 -  #endif\r
16 -  \r
17 -+ #define ENABLE_WLAN_FILTERING_PATCH
18 -+ 
19 -  #ifdef HAVE_CONFIG_H\r
20 -  #include "config.h"\r
21 -  #endif\r
22 -***************
23 -*** 144,150 ****
24 -       OR_NET,         /* relative to the network-layer header */\r
25 -       OR_NET_NOSNAP,  /* relative to the network-layer header, with no SNAP header at the link layer */\r
26 -       OR_TRAN_IPV4,   /* relative to the transport-layer header, with IPv4 network layer */\r
27 --      OR_TRAN_IPV6    /* relative to the transport-layer header, with IPv6 network layer */\r
28 -  };\r
29 -  \r
30 -  /*\r
31 ---- 146,153 ----
32 -       OR_NET,         /* relative to the network-layer header */\r
33 -       OR_NET_NOSNAP,  /* relative to the network-layer header, with no SNAP header at the link layer */\r
34 -       OR_TRAN_IPV4,   /* relative to the transport-layer header, with IPv4 network layer */\r
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 */
37 -  };\r
38 -  \r
39 -  /*\r
40 -***************
41 -*** 199,204 ****
42 -  static struct block *gen_linktype(int);\r
43 -  static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);\r
44 -  static struct block *gen_llc_linktype(int);\r
45 -  static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int);\r
46 -  #ifdef INET6\r
47 -  static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);\r
48 ---- 202,208 ----
49 -  static struct block *gen_linktype(int);\r
50 -  static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int);\r
51 -  static struct block *gen_llc_linktype(int);\r
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);\r
54 -  #ifdef INET6\r
55 -  static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int);\r
56 -***************
57 -*** 242,247 ****
58 -  static struct slist *xfer_to_a(struct arth *);\r
59 -  static struct block *gen_mac_multicast(int);\r
60 -  static struct block *gen_len(int, int);\r
61 -  \r
62 -  static struct block *gen_ppi_dlt_check();\r
63 -  static struct block *gen_msg_abbrev(int type);\r
64 ---- 246,252 ----
65 -  static struct slist *xfer_to_a(struct arth *);\r
66 -  static struct block *gen_mac_multicast(int);\r
67 -  static struct block *gen_len(int, int);\r
68 -+ static struct block *gen_check_802_11_data_frame();
69 -  \r
70 -  static struct block *gen_ppi_dlt_check();\r
71 -  static struct block *gen_msg_abbrev(int type);\r
72 -***************
73 -*** 1345,1350 ****
74 -       return s;\r
75 -  }\r
76 -  \r
77 -  \r
78 -  /*\r
79 -   * Load a value relative to the beginning of the specified header.\r
80 ---- 1350,1487 ----
81 -       return s;\r
82 -  }\r
83 -  \r
84 -+ /*
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.
90 -+  */
91 -+ static struct slist *
92 -+ gen_load_ll_after_802_11_rel(offset, size)
93 -+      u_int offset, size;
94 -+ {
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;       
104 -+ 
105 -+      /*
106 -+       * This code is not compatible with the optimizer, as
107 -+       * we are generating jmp instructions within a normal
108 -+       * slist of instructions
109 -+       *
110 -+       */
111 -+      no_optimize = 1;
112 -+      
113 -+      s = gen_llprefixlen();
114 -+ 
115 -+      /*
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
118 -+       * header.
119 -+       *
120 -+       * Otherwise, the length of the prefix preceding the link-layer
121 -+       * header is "off_ll".
122 -+       */
123 -+      if (s != NULL) {
124 -+              /*
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.
129 -+               */
130 -+ 
131 -+              /*
132 -+               * Load the Frame Control field
133 -+               */
134 -+              s_load_fc = new_stmt(BPF_LD|BPF_IND|BPF_B);
135 -+              s_load_fc->s.k = 0;
136 -+      } else {
137 -+              /*
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.
142 -+               */
143 -+ 
144 -+              /*
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
148 -+               */
149 -+ 
150 -+              /*
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
154 -+               */
155 -+ 
156 -+              /* Load 0 into X */
157 -+              s_load_x_0 = new_stmt(BPF_LDX|BPF_IMM);
158 -+              s_load_x_0->s.k = 0;
159 -+ 
160 -+              /*
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
164 -+               */
165 -+ 
166 -+              /*
167 -+               * load the Frame Control with absolute access
168 -+               */
169 -+              s_load_fc = new_stmt(BPF_LD|BPF_ABS|BPF_B);
170 -+              s_load_fc->s.k = 0;
171 -+              s = s_load_x_0;
172 -+      }
173 -+ 
174 -+      /*
175 -+       * Generate the common instructions to check if it's a data frame
176 -+       * and if so compute the 802.11 header length
177 -+       */
178 -+      sjset_data_frame_1 = new_stmt(JMP(BPF_JSET));   // b3 should be 1
179 -+      sjset_data_frame_1->s.k = 0x8;
180 -+              
181 -+      sjset_data_frame_2 = new_stmt(JMP(BPF_JSET));   // b2 should be 0
182 -+      sjset_data_frame_2->s.k = 0x04;
183 -+ 
184 -+      sjset_qos = new_stmt(JMP(BPF_JSET));
185 -+      sjset_qos->s.k = 0x80; //QOS bit
186 -+              
187 -+      s_ld_a_2 = new_stmt(BPF_LD|BPF_IMM);
188 -+      s_ld_a_2->s.k = 2;
189 -+ 
190 -+      s_add_a_x = new_stmt(BPF_ALU|BPF_ADD|BPF_X);
191 -+      s_a_to_x = new_stmt(BPF_MISC|BPF_TAX);
192 -+ 
193 -+      s_load = new_stmt(BPF_LD|BPF_IND|size);
194 -+      s_load->s.k = offset;
195 -+ 
196 -+      sjset_data_frame_1->s.jt = sjset_data_frame_2;
197 -+      sjset_data_frame_1->s.jf = s_load;
198 -+              
199 -+      sjset_data_frame_2->s.jt = s_load;
200 -+      sjset_data_frame_2->s.jf = sjset_qos;
201 -+              
202 -+      sjset_qos->s.jt = s_ld_a_2;
203 -+      sjset_qos->s.jf = s_load;
204 -+ 
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);
213 -+      
214 -+      return s;
215 -+ }
216 -  \r
217 -  /*\r
218 -   * Load a value relative to the beginning of the specified header.\r
219 -***************
220 -*** 1367,1372 ****
221 -               s = gen_load_llrel(offset, size);\r
222 -               break;\r
223 -  \r
224 -       case OR_NET:\r
225 -               s = gen_load_llrel(off_nl + offset, size);\r
226 -               break;\r
227 ---- 1504,1525 ----
228 -               s = gen_load_llrel(offset, size);\r
229 -               break;\r
230 -  \r
231 -+ #ifdef ENABLE_WLAN_FILTERING_PATCH
232 -+ 
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)
239 -+              {
240 -+                      abort();
241 -+                      return NULL;
242 -+              }
243 -+              s = gen_load_ll_after_802_11_rel(offset + 24, size);
244 -+              break;
245 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
246 -+ 
247 -       case OR_NET:\r
248 -               s = gen_load_llrel(off_nl + offset, size);\r
249 -               break;\r
250 -***************
251 -*** 2163,2173 ****
252 -               break;\r
253 -  \r
254 -       case DLT_PPI:\r
255 -       case DLT_FDDI:\r
256 -       case DLT_IEEE802:\r
257 --      case DLT_IEEE802_11:\r
258 -       case DLT_IEEE802_11_RADIO_AVS:\r
259 --      case DLT_IEEE802_11_RADIO:\r
260 -       case DLT_PRISM_HEADER:\r
261 -       case DLT_ATM_RFC1483:\r
262 -       case DLT_ATM_CLIP:\r
263 ---- 2316,2332 ----
264 -               break;\r
265 -  \r
266 -       case DLT_PPI:\r
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);
271 -+              /*NOTREACHED*/
272 -+              break;
273 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
274 -+ 
275 -       case DLT_FDDI:\r
276 -       case DLT_IEEE802:\r
277 -       case DLT_IEEE802_11_RADIO_AVS:\r
278 -       case DLT_PRISM_HEADER:\r
279 -       case DLT_ATM_RFC1483:\r
280 -       case DLT_ATM_CLIP:\r
281 -***************
282 -*** 2711,2716 ****
283 -       }\r
284 -  }\r
285 -  \r
286 -  static struct block *\r
287 -  gen_hostop(addr, mask, dir, proto, src_off, dst_off)\r
288 -       bpf_u_int32 addr;\r
289 ---- 2870,2982 ----
290 -       }\r
291 -  }\r
292 -  \r
293 -+ /*
294 -+  * Generate code to match a particular packet type, for link-layer types
295 -+  * using 802.2 LLC headers.
296 -+  *
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.
299 -+  *
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.
304 -+  */
305 -+ static struct block *
306 -+ gen_802_11_llc_linktype(proto)
307 -+      int proto;
308 -+ {
309 -+      struct block *b_check_data_frame;
310 -+      struct block *b_check_linktype;
311 -+ 
312 -+      b_check_data_frame = gen_check_802_11_data_frame();
313 -+ 
314 -+      /*
315 -+       * XXX - generate the code that discards non data frames
316 -+       */
317 -+      switch (proto) {
318 -+ 
319 -+      case LLCSAP_IP:
320 -+      case LLCSAP_ISONS:
321 -+      case LLCSAP_NETBEUI:
322 -+              /*
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)?
327 -+               */
328 -+              b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_H, (bpf_u_int32)
329 -+                           ((proto << 8) | proto));
330 -+              break;
331 -+ 
332 -+      case LLCSAP_IPX:
333 -+              /*
334 -+               * XXX - are there ever SNAP frames for IPX on
335 -+               * non-Ethernet 802.x networks?
336 -+               */
337 -+              b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_B,
338 -+                  (bpf_int32)LLCSAP_IPX);
339 -+ 
340 -+              break;
341 -+ 
342 -+ #if 0
343 -+      case ETHERTYPE_ATALK:
344 -+              /*
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).
349 -+               *
350 -+               * XXX - check for an organization code of
351 -+               * encapsulated Ethernet as well?
352 -+               */
353 -+              return gen_snap(0x080007, ETHERTYPE_ATALK, off_linktype);
354 -+ #endif
355 -+      default:
356 -+              /*
357 -+               * XXX - we don't have to check for IPX 802.3
358 -+               * here, but should we check for the IPX Ethertype?
359 -+               */
360 -+              if (proto <= ETHERMTU) {
361 -+                      /*
362 -+                       * This is an LLC SAP value, so check
363 -+                       * the DSAP.
364 -+                       */
365 -+                      b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0, BPF_B,
366 -+                          (bpf_int32)proto);
367 -+              } else {
368 -+                      /*
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).
375 -+                       *
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
380 -+                       *
381 -+                       *      return gen_snap(0x000000, proto,
382 -+                       *          off_linktype);
383 -+                       *
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.
387 -+                       */
388 -+                      b_check_linktype = gen_cmp(OR_LINK_AFTER_WIRELESS_HDR, 0+6, BPF_H,
389 -+                          (bpf_int32)proto);
390 -+              }
391 -+      }
392 -+ 
393 -+      gen_and(b_check_data_frame, b_check_linktype);
394 -+      return b_check_linktype;
395 -+ 
396 -+ }
397 -+ 
398 -+ 
399 -+ 
400 -  static struct block *\r
401 -  gen_hostop(addr, mask, dir, proto, src_off, dst_off)\r
402 -       bpf_u_int32 addr;\r
403 -***************
404 -*** 2925,2930 ****
405 -       register struct block *b0, *b1, *b2;\r
406 -       register struct slist *s;\r
407 -  \r
408 -       switch (dir) {\r
409 -       case Q_SRC:\r
410 -               /*\r
411 ---- 3191,3207 ----
412 -       register struct block *b0, *b1, *b2;\r
413 -       register struct slist *s;\r
414 -  \r
415 -+ #ifdef ENABLE_WLAN_FILTERING_PATCH
416 -+      /*
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
421 -+       *
422 -+       */
423 -+      no_optimize = 1;
424 -+ #endif /* ENABLE_WLAN_FILTERING_PATCH */
425 -+ 
426 -       switch (dir) {\r
427 -       case Q_SRC:\r
428 -               /*\r
429 -***************
430 -*** 4713,4718 ****
431 -  #endif\r
432 -  }\r
433 -  \r
434 -  \r
435 -  /*\r
436 -   * Generate code that checks whether the packet is a packet for protocol\r
437 ---- 4990,5021 ----
438 -  #endif\r
439 -  }\r
440 -  \r
441 -+ static struct block *
442 -+ gen_check_802_11_data_frame()
443 -+ {
444 -+      struct slist *s;
445 -+      struct block *b0, *b1;
446 -+      /*
447 -+      * Now check for a data frame.
448 -+      * I.e, check "link[0] & 0x08".
449 -+      */
450 -+      s = gen_load_a(OR_LINK, 0, BPF_B);
451 -+      b0 = new_block(JMP(BPF_JSET));
452 -+      b0->s.k = 0x08;
453 -+      b0->stmts = s;
454 -+      
455 -+      s = gen_load_a(OR_LINK, 0, BPF_B);
456 -+      b1 = new_block(JMP(BPF_JSET));
457 -+      b1->s.k = 0x04;
458 -+      b1->stmts = s;
459 -+      gen_not(b1);
460 -+      
461 -+ 
462 -+      gen_and(b1, b0);
463 -+ 
464 -+      return b0;
465 -+ }
466 -+ 
467 -  \r
468 -  /*\r
469 -   * Generate code that checks whether the packet is a packet for protocol\r