gencode.c (57763) | gencode.c (75110) |
---|---|
1/*#define CHASE_CHAIN*/ 2/* 3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that: (1) source code distributions 8 * retain the above copyright notice and this paragraph in its entirety, (2) --- 5 unchanged lines hidden (view full) --- 14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * the University nor the names of its contributors may be used to endorse 16 * or promote products derived from this software without specific prior 17 * written permission. 18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * | 1/*#define CHASE_CHAIN*/ 2/* 3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that: (1) source code distributions 8 * retain the above copyright notice and this paragraph in its entirety, (2) --- 5 unchanged lines hidden (view full) --- 14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15 * the University nor the names of its contributors may be used to endorse 16 * or promote products derived from this software without specific prior 17 * written permission. 18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 * |
22 * $FreeBSD: head/contrib/libpcap/gencode.c 57763 2000-03-04 23:57:39Z fenner $ | 22 * $FreeBSD: head/contrib/libpcap/gencode.c 75110 2001-04-03 04:32:48Z fenner $ |
23 */ 24#ifndef lint 25static const char rcsid[] = | 23 */ 24#ifndef lint 25static const char rcsid[] = |
26 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.100.2.1 2000/03/01 14:12:54 itojun Exp $ (LBL)"; | 26 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.140.2.1 2001/01/14 06:48:35 guy Exp $ (LBL)"; |
27#endif 28 | 27#endif 28 |
29#ifdef HAVE_CONFIG_H 30#include "config.h" 31#endif 32 |
|
29#include <sys/types.h> 30#include <sys/socket.h> 31#include <sys/time.h> 32#ifdef __NetBSD__ 33#include <sys/param.h> 34#endif 35 | 33#include <sys/types.h> 34#include <sys/socket.h> 35#include <sys/time.h> 36#ifdef __NetBSD__ 37#include <sys/param.h> 38#endif 39 |
36#if __STDC__ | |
37struct mbuf; 38struct rtentry; | 40struct mbuf; 41struct rtentry; |
39#endif 40 | |
41#include <net/if.h> | 42#include <net/if.h> |
42#include <net/ethernet.h> | |
43 44#include <netinet/in.h> 45 46#include <stdlib.h> | 43 44#include <netinet/in.h> 45 46#include <stdlib.h> |
47#include <string.h> |
|
47#include <memory.h> 48#include <setjmp.h> | 48#include <memory.h> 49#include <setjmp.h> |
49#include <net/if_llc.h> 50#if __STDC__ | |
51#include <stdarg.h> | 50#include <stdarg.h> |
52#else 53#include <varargs.h> 54#endif | |
55 56#include "pcap-int.h" 57 58#include "ethertype.h" 59#include "nlpid.h" 60#include "gencode.h" 61#include "ppp.h" | 51 52#include "pcap-int.h" 53 54#include "ethertype.h" 55#include "nlpid.h" 56#include "gencode.h" 57#include "ppp.h" |
58#include "sll.h" |
|
62#include <pcap-namedb.h> 63#ifdef INET6 64#include <netdb.h> 65#include <sys/socket.h> 66#endif /*INET6*/ 67 | 59#include <pcap-namedb.h> 60#ifdef INET6 61#include <netdb.h> 62#include <sys/socket.h> 63#endif /*INET6*/ 64 |
68#include "gnuc.h" | 65#define LLC_SNAP_LSAP 0xaa 66#define LLC_ISO_LSAP 0xfe 67 68#undef ETHERMTU 69#define ETHERMTU 1500 70 |
69#ifdef HAVE_OS_PROTO_H 70#include "os-proto.h" 71#endif 72 73#define JMP(c) ((c)|BPF_JMP|BPF_K) 74 75/* Locals */ 76static jmp_buf top_ctx; 77static pcap_t *bpf_pcap; 78 79/* XXX */ 80#ifdef PCAP_FDDIPAD 81int pcap_fddipad = PCAP_FDDIPAD; 82#else 83int pcap_fddipad; 84#endif 85 86/* VARARGS */ | 71#ifdef HAVE_OS_PROTO_H 72#include "os-proto.h" 73#endif 74 75#define JMP(c) ((c)|BPF_JMP|BPF_K) 76 77/* Locals */ 78static jmp_buf top_ctx; 79static pcap_t *bpf_pcap; 80 81/* XXX */ 82#ifdef PCAP_FDDIPAD 83int pcap_fddipad = PCAP_FDDIPAD; 84#else 85int pcap_fddipad; 86#endif 87 88/* VARARGS */ |
87__dead void 88#if __STDC__ | 89void |
89bpf_error(const char *fmt, ...) | 90bpf_error(const char *fmt, ...) |
90#else 91bpf_error(fmt, va_alist) 92 const char *fmt; 93 va_dcl 94#endif | 91 |
95{ 96 va_list ap; 97 | 92{ 93 va_list ap; 94 |
98#if __STDC__ | |
99 va_start(ap, fmt); | 95 va_start(ap, fmt); |
100#else 101 va_start(ap); 102#endif | |
103 if (bpf_pcap != NULL) | 96 if (bpf_pcap != NULL) |
104 (void)vsprintf(pcap_geterr(bpf_pcap), fmt, ap); | 97 (void)vsnprintf(pcap_geterr(bpf_pcap), PCAP_ERRBUF_SIZE, 98 fmt, ap); |
105 va_end(ap); 106 longjmp(top_ctx, 1); 107 /* NOTREACHED */ 108} 109 110static void init_linktype(int); 111 112static int alloc_reg(void); --- 22 unchanged lines hidden (view full) --- 135static inline struct block *new_block(int); 136static inline struct slist *new_stmt(int); 137static struct block *gen_retblk(int); 138static inline void syntax(void); 139 140static void backpatch(struct block *, struct block *); 141static void merge(struct block *, struct block *); 142static struct block *gen_cmp(u_int, u_int, bpf_int32); | 99 va_end(ap); 100 longjmp(top_ctx, 1); 101 /* NOTREACHED */ 102} 103 104static void init_linktype(int); 105 106static int alloc_reg(void); --- 22 unchanged lines hidden (view full) --- 129static inline struct block *new_block(int); 130static inline struct slist *new_stmt(int); 131static struct block *gen_retblk(int); 132static inline void syntax(void); 133 134static void backpatch(struct block *, struct block *); 135static void merge(struct block *, struct block *); 136static struct block *gen_cmp(u_int, u_int, bpf_int32); |
137static struct block *gen_cmp_gt(u_int, u_int, bpf_int32); |
|
143static struct block *gen_mcmp(u_int, u_int, bpf_int32, bpf_u_int32); 144static struct block *gen_bcmp(u_int, u_int, const u_char *); 145static struct block *gen_uncond(int); 146static inline struct block *gen_true(void); 147static inline struct block *gen_false(void); 148static struct block *gen_linktype(int); | 138static struct block *gen_mcmp(u_int, u_int, bpf_int32, bpf_u_int32); 139static struct block *gen_bcmp(u_int, u_int, const u_char *); 140static struct block *gen_uncond(int); 141static inline struct block *gen_true(void); 142static inline struct block *gen_false(void); 143static struct block *gen_linktype(int); |
144static struct block *gen_snap(bpf_u_int32, bpf_u_int32, u_int); |
|
149static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int); 150#ifdef INET6 151static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int); 152#endif 153static struct block *gen_ehostop(const u_char *, int); 154static struct block *gen_fhostop(const u_char *, int); | 145static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int); 146#ifdef INET6 147static struct block *gen_hostop6(struct in6_addr *, struct in6_addr *, int, int, u_int, u_int); 148#endif 149static struct block *gen_ehostop(const u_char *, int); 150static struct block *gen_fhostop(const u_char *, int); |
151static struct block *gen_thostop(const u_char *, int); |
|
155static struct block *gen_dnhostop(bpf_u_int32, int, u_int); 156static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int); 157#ifdef INET6 158static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int); 159#endif | 152static struct block *gen_dnhostop(bpf_u_int32, int, u_int); 153static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int); 154#ifdef INET6 155static struct block *gen_host6(struct in6_addr *, struct in6_addr *, int, int); 156#endif |
157#ifndef INET6 |
|
160static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int); | 158static struct block *gen_gateway(const u_char *, bpf_u_int32 **, int, int); |
159#endif |
|
161static struct block *gen_ipfrag(void); 162static struct block *gen_portatom(int, bpf_int32); 163#ifdef INET6 164static struct block *gen_portatom6(int, bpf_int32); 165#endif 166struct block *gen_portop(int, int, int); 167static struct block *gen_port(int, int, int); 168#ifdef INET6 169struct block *gen_portop6(int, int, int); 170static struct block *gen_port6(int, int, int); 171#endif 172static int lookup_proto(const char *, int); | 160static struct block *gen_ipfrag(void); 161static struct block *gen_portatom(int, bpf_int32); 162#ifdef INET6 163static struct block *gen_portatom6(int, bpf_int32); 164#endif 165struct block *gen_portop(int, int, int); 166static struct block *gen_port(int, int, int); 167#ifdef INET6 168struct block *gen_portop6(int, int, int); 169static struct block *gen_port6(int, int, int); 170#endif 171static int lookup_proto(const char *, int); |
172static struct block *gen_protochain(int, int, int); |
|
173static struct block *gen_proto(int, int, int); 174static struct slist *xfer_to_x(struct arth *); 175static struct slist *xfer_to_a(struct arth *); 176static struct block *gen_len(int, int); 177 178static void * 179newchunk(n) 180 u_int n; --- 43 unchanged lines hidden (view full) --- 224 */ 225char * 226sdup(s) 227 register const char *s; 228{ 229 int n = strlen(s) + 1; 230 char *cp = newchunk(n); 231 | 173static struct block *gen_proto(int, int, int); 174static struct slist *xfer_to_x(struct arth *); 175static struct slist *xfer_to_a(struct arth *); 176static struct block *gen_len(int, int); 177 178static void * 179newchunk(n) 180 u_int n; --- 43 unchanged lines hidden (view full) --- 224 */ 225char * 226sdup(s) 227 register const char *s; 228{ 229 int n = strlen(s) + 1; 230 char *cp = newchunk(n); 231 |
232 strcpy(cp, s); | 232 strlcpy(cp, s, n); |
233 return (cp); 234} 235 236static inline struct block * 237new_block(code) 238 int code; 239{ 240 struct block *p; --- 44 unchanged lines hidden (view full) --- 285 extern int n_errors; 286 int len; 287 288 no_optimize = 0; 289 n_errors = 0; 290 root = NULL; 291 bpf_pcap = p; 292 if (setjmp(top_ctx)) { | 233 return (cp); 234} 235 236static inline struct block * 237new_block(code) 238 int code; 239{ 240 struct block *p; --- 44 unchanged lines hidden (view full) --- 285 extern int n_errors; 286 int len; 287 288 no_optimize = 0; 289 n_errors = 0; 290 root = NULL; 291 bpf_pcap = p; 292 if (setjmp(top_ctx)) { |
293 lex_cleanup(); |
|
293 freechunks(); 294 return (-1); 295 } 296 297 netmask = mask; | 294 freechunks(); 295 return (-1); 296 } 297 298 netmask = mask; |
299 |
|
298 snaplen = pcap_snapshot(p); | 300 snaplen = pcap_snapshot(p); |
301 if (snaplen == 0) { 302 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, 303 "snaplen of 0 rejects all packets"); 304 return -1; 305 } |
|
299 300 lex_init(buf ? buf : ""); 301 init_linktype(pcap_datalink(p)); 302 (void)pcap_parse(); 303 304 if (n_errors) 305 syntax(); 306 --- 4 unchanged lines hidden (view full) --- 311 bpf_optimize(&root); 312 if (root == NULL || 313 (root->s.code == (BPF_RET|BPF_K) && root->s.k == 0)) 314 bpf_error("expression rejects all packets"); 315 } 316 program->bf_insns = icode_to_fcode(root, &len); 317 program->bf_len = len; 318 | 306 307 lex_init(buf ? buf : ""); 308 init_linktype(pcap_datalink(p)); 309 (void)pcap_parse(); 310 311 if (n_errors) 312 syntax(); 313 --- 4 unchanged lines hidden (view full) --- 318 bpf_optimize(&root); 319 if (root == NULL || 320 (root->s.code == (BPF_RET|BPF_K) && root->s.k == 0)) 321 bpf_error("expression rejects all packets"); 322 } 323 program->bf_insns = icode_to_fcode(root, &len); 324 program->bf_len = len; 325 |
326 lex_cleanup(); |
|
319 freechunks(); 320 return (0); 321} 322 323/* 324 * entry point for using the compiler with no pcap open 325 * pass in all the stuff that is needed explicitly instead. 326 */ 327int 328pcap_compile_nopcap(int snaplen_arg, int linktype_arg, 329 struct bpf_program *program, 330 char *buf, int optimize, bpf_u_int32 mask) 331{ | 327 freechunks(); 328 return (0); 329} 330 331/* 332 * entry point for using the compiler with no pcap open 333 * pass in all the stuff that is needed explicitly instead. 334 */ 335int 336pcap_compile_nopcap(int snaplen_arg, int linktype_arg, 337 struct bpf_program *program, 338 char *buf, int optimize, bpf_u_int32 mask) 339{ |
332 extern int n_errors; 333 int len; | 340 pcap_t *p; 341 int ret; |
334 | 342 |
335 n_errors = 0; 336 root = NULL; 337 bpf_pcap = NULL; 338 if (setjmp(top_ctx)) { 339 freechunks(); | 343 p = pcap_open_dead(linktype_arg, snaplen_arg); 344 if (p == NULL) |
340 return (-1); | 345 return (-1); |
341 } | 346 ret = pcap_compile(p, program, buf, optimize, mask); 347 pcap_close(p); 348 return (ret); 349} |
342 | 350 |
343 netmask = mask; 344 345 /* XXX needed? I don't grok the use of globals here. */ 346 snaplen = snaplen_arg; 347 348 lex_init(buf ? buf : ""); 349 init_linktype(linktype_arg); 350 (void)pcap_parse(); 351 352 if (n_errors) 353 syntax(); 354 355 if (root == NULL) 356 root = gen_retblk(snaplen_arg); 357 358 if (optimize) { 359 bpf_optimize(&root); 360 if (root == NULL || 361 (root->s.code == (BPF_RET|BPF_K) && root->s.k == 0)) 362 bpf_error("expression rejects all packets"); | 351/* 352 * Clean up a "struct bpf_program" by freeing all the memory allocated 353 * in it. 354 */ 355void 356pcap_freecode(struct bpf_program *program) 357{ 358 program->bf_len = 0; 359 if (program->bf_insns != NULL) { 360 free((char *)program->bf_insns); 361 program->bf_insns = NULL; |
363 } | 362 } |
364 program->bf_insns = icode_to_fcode(root, &len); 365 program->bf_len = len; 366 367 freechunks(); 368 return (0); | |
369} 370 371/* 372 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates 373 * which of the jt and jf fields has been resolved and which is a pointer 374 * back to another unresolved block (or nil). At least one of the fields 375 * in each block is already resolved. 376 */ --- 87 unchanged lines hidden (view full) --- 464 b = new_block(JMP(BPF_JEQ)); 465 b->stmts = s; 466 b->s.k = v; 467 468 return b; 469} 470 471static struct block * | 363} 364 365/* 366 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates 367 * which of the jt and jf fields has been resolved and which is a pointer 368 * back to another unresolved block (or nil). At least one of the fields 369 * in each block is already resolved. 370 */ --- 87 unchanged lines hidden (view full) --- 458 b = new_block(JMP(BPF_JEQ)); 459 b->stmts = s; 460 b->s.k = v; 461 462 return b; 463} 464 465static struct block * |
466gen_cmp_gt(offset, size, v) 467 u_int offset, size; 468 bpf_int32 v; 469{ 470 struct slist *s; 471 struct block *b; 472 473 s = new_stmt(BPF_LD|BPF_ABS|size); 474 s->s.k = offset; 475 476 b = new_block(JMP(BPF_JGT)); 477 b->stmts = s; 478 b->s.k = v; 479 480 return b; 481} 482 483static struct block * |
|
472gen_mcmp(offset, size, v, mask) 473 u_int offset, size; 474 bpf_int32 v; 475 bpf_u_int32 mask; 476{ 477 struct block *b = gen_cmp(offset, size, v); 478 struct slist *s; 479 --- 77 unchanged lines hidden (view full) --- 557 case DLT_SLIP_BSDOS: 558 /* XXX this may be the same as the DLT_PPP_BSDOS case */ 559 off_linktype = -1; 560 /* XXX end */ 561 off_nl = 24; 562 return; 563 564 case DLT_NULL: | 484gen_mcmp(offset, size, v, mask) 485 u_int offset, size; 486 bpf_int32 v; 487 bpf_u_int32 mask; 488{ 489 struct block *b = gen_cmp(offset, size, v); 490 struct slist *s; 491 --- 77 unchanged lines hidden (view full) --- 569 case DLT_SLIP_BSDOS: 570 /* XXX this may be the same as the DLT_PPP_BSDOS case */ 571 off_linktype = -1; 572 /* XXX end */ 573 off_nl = 24; 574 return; 575 576 case DLT_NULL: |
577 case DLT_LOOP: |
|
565 off_linktype = 0; 566 off_nl = 4; 567 return; 568 569 case DLT_PPP: | 578 off_linktype = 0; 579 off_nl = 4; 580 return; 581 582 case DLT_PPP: |
570#ifdef DLT_CHDLC 571 case DLT_CHDLC: 572#endif | 583 case DLT_C_HDLC: 584 case DLT_PPP_SERIAL: |
573 off_linktype = 2; 574 off_nl = 4; 575 return; 576 577 case DLT_PPP_BSDOS: 578 off_linktype = 5; 579 off_nl = 24; 580 return; 581 582 case DLT_FDDI: 583 /* 584 * FDDI doesn't really have a link-level type field. 585 * We assume that SSAP = SNAP is being used and pick 586 * out the encapsulated Ethernet type. | 585 off_linktype = 2; 586 off_nl = 4; 587 return; 588 589 case DLT_PPP_BSDOS: 590 off_linktype = 5; 591 off_nl = 24; 592 return; 593 594 case DLT_FDDI: 595 /* 596 * FDDI doesn't really have a link-level type field. 597 * We assume that SSAP = SNAP is being used and pick 598 * out the encapsulated Ethernet type. |
599 * 600 * XXX - should we generate code to check for SNAP? |
|
587 */ 588 off_linktype = 19; 589#ifdef PCAP_FDDIPAD 590 off_linktype += pcap_fddipad; 591#endif 592 off_nl = 21; 593#ifdef PCAP_FDDIPAD 594 off_nl += pcap_fddipad; 595#endif 596 return; 597 598 case DLT_IEEE802: | 601 */ 602 off_linktype = 19; 603#ifdef PCAP_FDDIPAD 604 off_linktype += pcap_fddipad; 605#endif 606 off_nl = 21; 607#ifdef PCAP_FDDIPAD 608 off_nl += pcap_fddipad; 609#endif 610 return; 611 612 case DLT_IEEE802: |
613 /* 614 * Token Ring doesn't really have a link-level type field. 615 * We assume that SSAP = SNAP is being used and pick 616 * out the encapsulated Ethernet type. 617 * 618 * XXX - should we generate code to check for SNAP? 619 * 620 * XXX - the header is actually variable-length. 621 * Some various Linux patched versions gave 38 622 * as "off_linktype" and 40 as "off_nl"; however, 623 * if a token ring packet has *no* routing 624 * information, i.e. is not source-routed, the correct 625 * values are 20 and 22, as they are in the vanilla code. 626 * 627 * A packet is source-routed iff the uppermost bit 628 * of the first byte of the source address, at an 629 * offset of 8, has the uppermost bit set. If the 630 * packet is source-routed, the total number of bytes 631 * of routing information is 2 plus bits 0x1F00 of 632 * the 16-bit value at an offset of 14 (shifted right 633 * 8 - figure out which byte that is). 634 */ |
|
599 off_linktype = 20; 600 off_nl = 22; 601 return; 602 603 case DLT_ATM_RFC1483: 604 /* 605 * assume routed, non-ISO PDUs 606 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00) 607 */ 608 off_linktype = 6; 609 off_nl = 8; 610 return; 611 612 case DLT_RAW: 613 off_linktype = -1; 614 off_nl = 0; 615 return; | 635 off_linktype = 20; 636 off_nl = 22; 637 return; 638 639 case DLT_ATM_RFC1483: 640 /* 641 * assume routed, non-ISO PDUs 642 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00) 643 */ 644 off_linktype = 6; 645 off_nl = 8; 646 return; 647 648 case DLT_RAW: 649 off_linktype = -1; 650 off_nl = 0; 651 return; |
652 653 case DLT_ATM_CLIP: /* Linux ATM defines this */ 654 off_linktype = 6; 655 off_nl = 8; 656 return; 657 658 case DLT_LINUX_SLL: /* fake header for Linux cooked socket */ 659 off_linktype = 14; 660 off_nl = 16; 661 return; |
|
616 } | 662 } |
617 bpf_error("unknown data link type 0x%x", linktype); | 663 bpf_error("unknown data link type %d", linktype); |
618 /* NOTREACHED */ 619} 620 621static struct block * 622gen_uncond(rsense) 623 int rsense; 624{ 625 struct block *b; --- 14 unchanged lines hidden (view full) --- 640} 641 642static inline struct block * 643gen_false() 644{ 645 return gen_uncond(0); 646} 647 | 664 /* NOTREACHED */ 665} 666 667static struct block * 668gen_uncond(rsense) 669 int rsense; 670{ 671 struct block *b; --- 14 unchanged lines hidden (view full) --- 686} 687 688static inline struct block * 689gen_false() 690{ 691 return gen_uncond(0); 692} 693 |
694/* 695 * Byte-swap a 32-bit number. 696 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on 697 * big-endian platforms.) 698 */ 699#define SWAPLONG(y) \ 700((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) 701 |
|
648static struct block * 649gen_linktype(proto) 650 register int proto; 651{ 652 struct block *b0, *b1; 653 | 702static struct block * 703gen_linktype(proto) 704 register int proto; 705{ 706 struct block *b0, *b1; 707 |
654 /* If we're not using encapsulation and checking for IP, we're done */ 655 if (off_linktype == -1 && proto == ETHERTYPE_IP) | 708 /* If we're not using encapsulation, we're done */ 709 if (off_linktype == -1) |
656 return gen_true(); 657 658 switch (linktype) { 659 | 710 return gen_true(); 711 712 switch (linktype) { 713 |
714 case DLT_EN10MB: 715 /* 716 * XXX - handle other LLC-encapsulated protocols here 717 * (IPX, OSI)? 718 */ 719 switch (proto) { 720 721 case LLC_ISO_LSAP: 722 /* 723 * OSI protocols always use 802.2 encapsulation. 724 */ 725 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU); 726 gen_not(b0); 727 b1 = gen_cmp(off_linktype + 2, BPF_H, (bpf_int32) 728 ((LLC_ISO_LSAP << 8) | LLC_ISO_LSAP)); 729 gen_and(b0, b1); 730 return b1; 731 732 case ETHERTYPE_ATALK: 733 case ETHERTYPE_AARP: 734 /* 735 * EtherTalk (AppleTalk protocols on Ethernet link 736 * layer) may use 802.2 encapsulation. 737 */ 738 739 /* 740 * Check for 802.2 encapsulation (EtherTalk phase 2?); 741 * we check for an Ethernet type field less than 742 * 1500, which means it's an 802.3 length field. 743 */ 744 b0 = gen_cmp_gt(off_linktype, BPF_H, ETHERMTU); 745 gen_not(b0); 746 747 /* 748 * 802.2-encapsulated ETHERTYPE_ATALK packets are 749 * SNAP packets with an organization code of 750 * 0x080007 (Apple, for Appletalk) and a protocol 751 * type of ETHERTYPE_ATALK (Appletalk). 752 * 753 * 802.2-encapsulated ETHERTYPE_AARP packets are 754 * SNAP packets with an organization code of 755 * 0x000000 (encapsulated Ethernet) and a protocol 756 * type of ETHERTYPE_AARP (Appletalk ARP). 757 */ 758 if (proto == ETHERTYPE_ATALK) 759 b1 = gen_snap(0x080007, ETHERTYPE_ATALK, 14); 760 else /* proto == ETHERTYPE_AARP */ 761 b1 = gen_snap(0x000000, ETHERTYPE_AARP, 14); 762 gen_and(b0, b1); 763 764 /* 765 * Check for Ethernet encapsulation (Ethertalk 766 * phase 1?); we just check for the Ethernet 767 * protocol type. 768 */ 769 b0 = gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); 770 771 gen_or(b0, b1); 772 return b1; 773 } 774 break; 775 |
|
660 case DLT_SLIP: 661 return gen_false(); 662 663 case DLT_PPP: | 776 case DLT_SLIP: 777 return gen_false(); 778 779 case DLT_PPP: |
664 if (proto == ETHERTYPE_IP) | 780 case DLT_PPP_SERIAL: 781 /* 782 * We use Ethernet protocol types inside libpcap; 783 * map them to the corresponding PPP protocol types. 784 */ 785 switch (proto) { 786 787 case ETHERTYPE_IP: |
665 proto = PPP_IP; /* XXX was 0x21 */ | 788 proto = PPP_IP; /* XXX was 0x21 */ |
789 break; 790 |
|
666#ifdef INET6 | 791#ifdef INET6 |
667 else if (proto == ETHERTYPE_IPV6) | 792 case ETHERTYPE_IPV6: |
668 proto = PPP_IPV6; | 793 proto = PPP_IPV6; |
794 break; |
|
669#endif | 795#endif |
796 797 case ETHERTYPE_DN: 798 proto = PPP_DECNET; 799 break; 800 801 case ETHERTYPE_ATALK: 802 proto = PPP_APPLE; 803 break; 804 805 case ETHERTYPE_NS: 806 proto = PPP_NS; 807 break; 808 809 case LLC_ISO_LSAP: 810 proto = PPP_OSI; 811 break; 812 } |
|
670 break; 671 672 case DLT_PPP_BSDOS: | 813 break; 814 815 case DLT_PPP_BSDOS: |
816 /* 817 * We use Ethernet protocol types inside libpcap; 818 * map them to the corresponding PPP protocol types. 819 */ |
|
673 switch (proto) { 674 675 case ETHERTYPE_IP: 676 b0 = gen_cmp(off_linktype, BPF_H, PPP_IP); 677 b1 = gen_cmp(off_linktype, BPF_H, PPP_VJC); 678 gen_or(b0, b1); 679 b0 = gen_cmp(off_linktype, BPF_H, PPP_VJNC); 680 gen_or(b1, b0); --- 12 unchanged lines hidden (view full) --- 693 694 case ETHERTYPE_ATALK: 695 proto = PPP_APPLE; 696 break; 697 698 case ETHERTYPE_NS: 699 proto = PPP_NS; 700 break; | 820 switch (proto) { 821 822 case ETHERTYPE_IP: 823 b0 = gen_cmp(off_linktype, BPF_H, PPP_IP); 824 b1 = gen_cmp(off_linktype, BPF_H, PPP_VJC); 825 gen_or(b0, b1); 826 b0 = gen_cmp(off_linktype, BPF_H, PPP_VJNC); 827 gen_or(b1, b0); --- 12 unchanged lines hidden (view full) --- 840 841 case ETHERTYPE_ATALK: 842 proto = PPP_APPLE; 843 break; 844 845 case ETHERTYPE_NS: 846 proto = PPP_NS; 847 break; |
848 849 case LLC_ISO_LSAP: 850 proto = PPP_OSI; 851 break; |
|
701 } 702 break; 703 704 case DLT_NULL: | 852 } 853 break; 854 855 case DLT_NULL: |
705 /* XXX */ 706 if (proto == ETHERTYPE_IP) 707 return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET))); | 856 case DLT_LOOP: 857 /* 858 * For DLT_NULL, the link-layer header is a 32-bit 859 * word containing an AF_ value in *host* byte order. 860 * 861 * In addition, if we're reading a saved capture file, 862 * the host byte order in the capture may not be the 863 * same as the host byte order on this machine. 864 * 865 * For DLT_LOOP, the link-layer header is a 32-bit 866 * word containing an AF_ value in *network* byte order. 867 * 868 * XXX - AF_ values may, unfortunately, be platform- 869 * dependent; for example, FreeBSD's AF_INET6 is 24 870 * whilst NetBSD's and OpenBSD's is 26. 871 * 872 * This means that, when reading a capture file, just 873 * checking for our AF_INET6 value won't work if the 874 * capture file came from another OS. 875 */ 876 switch (proto) { 877 878 case ETHERTYPE_IP: 879 proto = AF_INET; 880 break; 881 |
708#ifdef INET6 | 882#ifdef INET6 |
709 else if (proto == ETHERTYPE_IPV6) 710 return (gen_cmp(0, BPF_W, (bpf_int32)htonl(AF_INET6))); | 883 case ETHERTYPE_IPV6: 884 proto = AF_INET6; 885 break; |
711#endif | 886#endif |
712 else | 887 888 default: 889 /* 890 * Not a type on which we support filtering. 891 * XXX - support those that have AF_ values 892 * #defined on this platform, at least? 893 */ |
713 return gen_false(); | 894 return gen_false(); |
714 case DLT_EN10MB: 715 /* 716 * Having to look at SAP's here is quite disgusting, 717 * but given an internal architecture that _knows_ that 718 * it's looking at IP on Ethernet... 719 */ 720 if (proto == LLC_ISO_LSAP) { 721 struct block *b0, *b1; | 895 } |
722 | 896 |
723 b0 = gen_cmp(off_linktype, BPF_H, (long)ETHERMTU); 724 b0->s.code = JMP(BPF_JGT); 725 gen_not(b0); 726 b1 = gen_cmp(off_linktype + 2, BPF_H, (long) 727 ((LLC_ISO_LSAP << 8) | LLC_ISO_LSAP)); 728 gen_and(b0, b1); 729 return b1; | 897 if (linktype == DLT_NULL) { 898 /* 899 * The AF_ value is in host byte order, but 900 * the BPF interpreter will convert it to 901 * network byte order. 902 * 903 * If this is a save file, and it's from a 904 * machine with the opposite byte order to 905 * ours, we byte-swap the AF_ value. 906 * 907 * Then we run it through "htonl()", and 908 * generate code to compare against the result. 909 */ 910 if (bpf_pcap->sf.rfile != NULL && 911 bpf_pcap->sf.swapped) 912 proto = SWAPLONG(proto); 913 proto = htonl(proto); |
730 } | 914 } |
731 break; | 915 return (gen_cmp(0, BPF_W, (bpf_int32)proto)); |
732 } 733 return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); 734} 735 | 916 } 917 return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); 918} 919 |
920/* 921 * Check for an LLC SNAP packet with a given organization code and 922 * protocol type; we check the entire contents of the 802.2 LLC and 923 * snap headers, checking for DSAP and SSAP of SNAP and a control 924 * field of 0x03 in the LLC header, and for the specified organization 925 * code and protocol type in the SNAP header. 926 */ |
|
736static struct block * | 927static struct block * |
928gen_snap(orgcode, ptype, offset) 929 bpf_u_int32 orgcode; 930 bpf_u_int32 ptype; 931 u_int offset; 932{ 933 u_char snapblock[8]; 934 935 snapblock[0] = LLC_SNAP_LSAP; /* DSAP = SNAP */ 936 snapblock[1] = LLC_SNAP_LSAP; /* SSAP = SNAP */ 937 snapblock[2] = 0x03; /* control = UI */ 938 snapblock[3] = (orgcode >> 16); /* upper 8 bits of organization code */ 939 snapblock[4] = (orgcode >> 8); /* middle 8 bits of organization code */ 940 snapblock[5] = (orgcode >> 0); /* lower 8 bits of organization code */ 941 snapblock[6] = (ptype >> 8); /* upper 8 bits of protocol type */ 942 snapblock[7] = (ptype >> 0); /* lower 8 bits of protocol type */ 943 return gen_bcmp(offset, 8, snapblock); 944} 945 946static struct block * |
|
737gen_hostop(addr, mask, dir, proto, src_off, dst_off) 738 bpf_u_int32 addr; 739 bpf_u_int32 mask; 740 int dir, proto; 741 u_int src_off, dst_off; 742{ 743 struct block *b0, *b1; 744 u_int offset; --- 153 unchanged lines hidden (view full) --- 898 gen_or(b0, b1); 899 return b1; 900 } 901 abort(); 902 /* NOTREACHED */ 903} 904 905/* | 947gen_hostop(addr, mask, dir, proto, src_off, dst_off) 948 bpf_u_int32 addr; 949 bpf_u_int32 mask; 950 int dir, proto; 951 u_int src_off, dst_off; 952{ 953 struct block *b0, *b1; 954 u_int offset; --- 153 unchanged lines hidden (view full) --- 1108 gen_or(b0, b1); 1109 return b1; 1110 } 1111 abort(); 1112 /* NOTREACHED */ 1113} 1114 1115/* |
1116 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring) 1117 */ 1118static struct block * 1119gen_thostop(eaddr, dir) 1120 register const u_char *eaddr; 1121 register int dir; 1122{ 1123 register struct block *b0, *b1; 1124 1125 switch (dir) { 1126 case Q_SRC: 1127 return gen_bcmp(8, 6, eaddr); 1128 1129 case Q_DST: 1130 return gen_bcmp(2, 6, eaddr); 1131 1132 case Q_AND: 1133 b0 = gen_thostop(eaddr, Q_SRC); 1134 b1 = gen_thostop(eaddr, Q_DST); 1135 gen_and(b0, b1); 1136 return b1; 1137 1138 case Q_DEFAULT: 1139 case Q_OR: 1140 b0 = gen_thostop(eaddr, Q_SRC); 1141 b1 = gen_thostop(eaddr, Q_DST); 1142 gen_or(b0, b1); 1143 return b1; 1144 } 1145 abort(); 1146 /* NOTREACHED */ 1147} 1148 1149/* |
|
906 * This is quite tricky because there may be pad bytes in front of the 907 * DECNET header, and then there are two possible data packet formats that 908 * carry both src and dst addresses, plus 5 packet types in a format that 909 * carries only the src node, plus 2 types that use a different format and 910 * also carry just the src node. 911 * 912 * Yuck. 913 * --- 38 unchanged lines hidden (view full) --- 952 case Q_OR: 953 case Q_DEFAULT: 954 /* Inefficient because we do our Calvinball dance twice */ 955 b0 = gen_dnhostop(addr, Q_SRC, base_off); 956 b1 = gen_dnhostop(addr, Q_DST, base_off); 957 gen_or(b0, b1); 958 return b1; 959 | 1150 * This is quite tricky because there may be pad bytes in front of the 1151 * DECNET header, and then there are two possible data packet formats that 1152 * carry both src and dst addresses, plus 5 packet types in a format that 1153 * carries only the src node, plus 2 types that use a different format and 1154 * also carry just the src node. 1155 * 1156 * Yuck. 1157 * --- 38 unchanged lines hidden (view full) --- 1196 case Q_OR: 1197 case Q_DEFAULT: 1198 /* Inefficient because we do our Calvinball dance twice */ 1199 b0 = gen_dnhostop(addr, Q_SRC, base_off); 1200 b1 = gen_dnhostop(addr, Q_DST, base_off); 1201 gen_or(b0, b1); 1202 return b1; 1203 |
1204 case Q_ISO: 1205 bpf_error("ISO host filtering not implemented"); 1206 |
|
960 default: 961 abort(); 962 } 963 b0 = gen_linktype(ETHERTYPE_DN); 964 /* Check for pad = 1, long header case */ 965 tmp = gen_mcmp(base_off + 2, BPF_H, 966 (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF)); 967 b1 = gen_cmp(base_off + 2 + 1 + offset_lh, --- 30 unchanged lines hidden (view full) --- 998 int dir; 999{ 1000 struct block *b0, *b1; 1001 1002 switch (proto) { 1003 1004 case Q_DEFAULT: 1005 b0 = gen_host(addr, mask, Q_IP, dir); | 1207 default: 1208 abort(); 1209 } 1210 b0 = gen_linktype(ETHERTYPE_DN); 1211 /* Check for pad = 1, long header case */ 1212 tmp = gen_mcmp(base_off + 2, BPF_H, 1213 (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF)); 1214 b1 = gen_cmp(base_off + 2 + 1 + offset_lh, --- 30 unchanged lines hidden (view full) --- 1245 int dir; 1246{ 1247 struct block *b0, *b1; 1248 1249 switch (proto) { 1250 1251 case Q_DEFAULT: 1252 b0 = gen_host(addr, mask, Q_IP, dir); |
1006 b1 = gen_host(addr, mask, Q_ARP, dir); 1007 gen_or(b0, b1); 1008 b0 = gen_host(addr, mask, Q_RARP, dir); 1009 gen_or(b1, b0); | 1253 if (off_linktype != -1) { 1254 b1 = gen_host(addr, mask, Q_ARP, dir); 1255 gen_or(b0, b1); 1256 b0 = gen_host(addr, mask, Q_RARP, dir); 1257 gen_or(b1, b0); 1258 } |
1010 return b0; 1011 1012 case Q_IP: 1013 return gen_hostop(addr, mask, dir, ETHERTYPE_IP, 1014 off_nl + 12, off_nl + 16); 1015 1016 case Q_RARP: 1017 return gen_hostop(addr, mask, dir, ETHERTYPE_REVARP, --- 19 unchanged lines hidden (view full) --- 1037 bpf_error("'igrp' modifier applied to host"); 1038 1039 case Q_PIM: 1040 bpf_error("'pim' modifier applied to host"); 1041 1042 case Q_ATALK: 1043 bpf_error("ATALK host filtering not implemented"); 1044 | 1259 return b0; 1260 1261 case Q_IP: 1262 return gen_hostop(addr, mask, dir, ETHERTYPE_IP, 1263 off_nl + 12, off_nl + 16); 1264 1265 case Q_RARP: 1266 return gen_hostop(addr, mask, dir, ETHERTYPE_REVARP, --- 19 unchanged lines hidden (view full) --- 1286 bpf_error("'igrp' modifier applied to host"); 1287 1288 case Q_PIM: 1289 bpf_error("'pim' modifier applied to host"); 1290 1291 case Q_ATALK: 1292 bpf_error("ATALK host filtering not implemented"); 1293 |
1294 case Q_AARP: 1295 bpf_error("AARP host filtering not implemented"); 1296 |
|
1045 case Q_DECNET: 1046 return gen_dnhostop(addr, dir, off_nl); 1047 1048 case Q_SCA: 1049 bpf_error("SCA host filtering not implemented"); 1050 1051 case Q_LAT: 1052 bpf_error("LAT host filtering not implemented"); 1053 1054 case Q_MOPDL: 1055 bpf_error("MOPDL host filtering not implemented"); 1056 1057 case Q_MOPRC: 1058 bpf_error("MOPRC host filtering not implemented"); 1059 | 1297 case Q_DECNET: 1298 return gen_dnhostop(addr, dir, off_nl); 1299 1300 case Q_SCA: 1301 bpf_error("SCA host filtering not implemented"); 1302 1303 case Q_LAT: 1304 bpf_error("LAT host filtering not implemented"); 1305 1306 case Q_MOPDL: 1307 bpf_error("MOPDL host filtering not implemented"); 1308 1309 case Q_MOPRC: 1310 bpf_error("MOPRC host filtering not implemented"); 1311 |
1060 case Q_ISO: 1061 bpf_error("ISO host filtering not implemented"); 1062 | |
1063#ifdef INET6 1064 case Q_IPV6: 1065 bpf_error("'ip6' modifier applied to ip host"); 1066 1067 case Q_ICMPV6: 1068 bpf_error("'icmp6' modifier applied to host"); 1069#endif /* INET6 */ 1070 1071 case Q_AH: 1072 bpf_error("'ah' modifier applied to host"); 1073 1074 case Q_ESP: 1075 bpf_error("'esp' modifier applied to host"); 1076 | 1312#ifdef INET6 1313 case Q_IPV6: 1314 bpf_error("'ip6' modifier applied to ip host"); 1315 1316 case Q_ICMPV6: 1317 bpf_error("'icmp6' modifier applied to host"); 1318#endif /* INET6 */ 1319 1320 case Q_AH: 1321 bpf_error("'ah' modifier applied to host"); 1322 1323 case Q_ESP: 1324 bpf_error("'esp' modifier applied to host"); 1325 |
1326 case Q_ISO: 1327 bpf_error("ISO host filtering not implemented"); 1328 1329 case Q_ESIS: 1330 bpf_error("'esis' modifier applied to host"); 1331 1332 case Q_ISIS: 1333 bpf_error("'isis' modifier applied to host"); 1334 1335 case Q_CLNP: 1336 bpf_error("'clnp' modifier applied to host"); 1337 |
|
1077 default: 1078 abort(); 1079 } 1080 /* NOTREACHED */ 1081} 1082 1083#ifdef INET6 1084static struct block * 1085gen_host6(addr, mask, proto, dir) 1086 struct in6_addr *addr; 1087 struct in6_addr *mask; 1088 int proto; 1089 int dir; 1090{ | 1338 default: 1339 abort(); 1340 } 1341 /* NOTREACHED */ 1342} 1343 1344#ifdef INET6 1345static struct block * 1346gen_host6(addr, mask, proto, dir) 1347 struct in6_addr *addr; 1348 struct in6_addr *mask; 1349 int proto; 1350 int dir; 1351{ |
1091 struct block *b0, *b1; 1092 | |
1093 switch (proto) { 1094 1095 case Q_DEFAULT: 1096 return gen_host6(addr, mask, Q_IPV6, dir); 1097 1098 case Q_IP: 1099 bpf_error("'ip' modifier applied to ip6 host"); 1100 --- 19 unchanged lines hidden (view full) --- 1120 bpf_error("'igrp' modifier applied to host"); 1121 1122 case Q_PIM: 1123 bpf_error("'pim' modifier applied to host"); 1124 1125 case Q_ATALK: 1126 bpf_error("ATALK host filtering not implemented"); 1127 | 1352 switch (proto) { 1353 1354 case Q_DEFAULT: 1355 return gen_host6(addr, mask, Q_IPV6, dir); 1356 1357 case Q_IP: 1358 bpf_error("'ip' modifier applied to ip6 host"); 1359 --- 19 unchanged lines hidden (view full) --- 1379 bpf_error("'igrp' modifier applied to host"); 1380 1381 case Q_PIM: 1382 bpf_error("'pim' modifier applied to host"); 1383 1384 case Q_ATALK: 1385 bpf_error("ATALK host filtering not implemented"); 1386 |
1387 case Q_AARP: 1388 bpf_error("AARP host filtering not implemented"); 1389 |
|
1128 case Q_DECNET: 1129 bpf_error("'decnet' modifier applied to ip6 host"); 1130 1131 case Q_SCA: 1132 bpf_error("SCA host filtering not implemented"); 1133 1134 case Q_LAT: 1135 bpf_error("LAT host filtering not implemented"); --- 12 unchanged lines hidden (view full) --- 1148 bpf_error("'icmp6' modifier applied to host"); 1149 1150 case Q_AH: 1151 bpf_error("'ah' modifier applied to host"); 1152 1153 case Q_ESP: 1154 bpf_error("'esp' modifier applied to host"); 1155 | 1390 case Q_DECNET: 1391 bpf_error("'decnet' modifier applied to ip6 host"); 1392 1393 case Q_SCA: 1394 bpf_error("SCA host filtering not implemented"); 1395 1396 case Q_LAT: 1397 bpf_error("LAT host filtering not implemented"); --- 12 unchanged lines hidden (view full) --- 1410 bpf_error("'icmp6' modifier applied to host"); 1411 1412 case Q_AH: 1413 bpf_error("'ah' modifier applied to host"); 1414 1415 case Q_ESP: 1416 bpf_error("'esp' modifier applied to host"); 1417 |
1418 case Q_ISO: 1419 bpf_error("ISO host filtering not implemented"); 1420 1421 case Q_ESIS: 1422 bpf_error("'esis' modifier applied to host"); 1423 1424 case Q_ISIS: 1425 bpf_error("'isis' modifier applied to host"); 1426 1427 case Q_CLNP: 1428 bpf_error("'clnp' modifier applied to host"); 1429 |
|
1156 default: 1157 abort(); 1158 } 1159 /* NOTREACHED */ 1160} 1161#endif /*INET6*/ 1162 | 1430 default: 1431 abort(); 1432 } 1433 /* NOTREACHED */ 1434} 1435#endif /*INET6*/ 1436 |
1437#ifndef INET6 |
|
1163static struct block * 1164gen_gateway(eaddr, alist, proto, dir) 1165 const u_char *eaddr; 1166 bpf_u_int32 **alist; 1167 int proto; 1168 int dir; 1169{ 1170 struct block *b0, *b1, *tmp; --- 5 unchanged lines hidden (view full) --- 1176 case Q_DEFAULT: 1177 case Q_IP: 1178 case Q_ARP: 1179 case Q_RARP: 1180 if (linktype == DLT_EN10MB) 1181 b0 = gen_ehostop(eaddr, Q_OR); 1182 else if (linktype == DLT_FDDI) 1183 b0 = gen_fhostop(eaddr, Q_OR); | 1438static struct block * 1439gen_gateway(eaddr, alist, proto, dir) 1440 const u_char *eaddr; 1441 bpf_u_int32 **alist; 1442 int proto; 1443 int dir; 1444{ 1445 struct block *b0, *b1, *tmp; --- 5 unchanged lines hidden (view full) --- 1451 case Q_DEFAULT: 1452 case Q_IP: 1453 case Q_ARP: 1454 case Q_RARP: 1455 if (linktype == DLT_EN10MB) 1456 b0 = gen_ehostop(eaddr, Q_OR); 1457 else if (linktype == DLT_FDDI) 1458 b0 = gen_fhostop(eaddr, Q_OR); |
1459 else if (linktype == DLT_IEEE802) 1460 b0 = gen_thostop(eaddr, Q_OR); |
|
1184 else 1185 bpf_error( | 1461 else 1462 bpf_error( |
1186 "'gateway' supported only on ethernet or FDDI"); | 1463 "'gateway' supported only on ethernet, FDDI or token ring"); |
1187 1188 b1 = gen_host(**alist++, 0xffffffff, proto, Q_OR); 1189 while (*alist) { 1190 tmp = gen_host(**alist++, 0xffffffff, proto, Q_OR); 1191 gen_or(b1, tmp); 1192 b1 = tmp; 1193 } 1194 gen_not(b1); 1195 gen_and(b0, b1); 1196 return b1; 1197 } 1198 bpf_error("illegal modifier of 'gateway'"); 1199 /* NOTREACHED */ 1200} | 1464 1465 b1 = gen_host(**alist++, 0xffffffff, proto, Q_OR); 1466 while (*alist) { 1467 tmp = gen_host(**alist++, 0xffffffff, proto, Q_OR); 1468 gen_or(b1, tmp); 1469 b1 = tmp; 1470 } 1471 gen_not(b1); 1472 gen_and(b0, b1); 1473 return b1; 1474 } 1475 bpf_error("illegal modifier of 'gateway'"); 1476 /* NOTREACHED */ 1477} |
1478#endif |
|
1201 1202struct block * 1203gen_proto_abbrev(proto) 1204 int proto; 1205{ | 1479 1480struct block * 1481gen_proto_abbrev(proto) 1482 int proto; 1483{ |
1206 struct block *b0, *b1; | 1484#ifdef INET6 1485 struct block *b0; 1486#endif 1487 struct block *b1; |
1207 1208 switch (proto) { 1209 1210 case Q_TCP: 1211 b1 = gen_proto(IPPROTO_TCP, Q_IP, Q_DEFAULT); 1212#ifdef INET6 1213 b0 = gen_proto(IPPROTO_TCP, Q_IPV6, Q_DEFAULT); 1214 gen_or(b0, b1); --- 7 unchanged lines hidden (view full) --- 1222 gen_or(b0, b1); 1223#endif 1224 break; 1225 1226 case Q_ICMP: 1227 b1 = gen_proto(IPPROTO_ICMP, Q_IP, Q_DEFAULT); 1228 break; 1229 | 1488 1489 switch (proto) { 1490 1491 case Q_TCP: 1492 b1 = gen_proto(IPPROTO_TCP, Q_IP, Q_DEFAULT); 1493#ifdef INET6 1494 b0 = gen_proto(IPPROTO_TCP, Q_IPV6, Q_DEFAULT); 1495 gen_or(b0, b1); --- 7 unchanged lines hidden (view full) --- 1503 gen_or(b0, b1); 1504#endif 1505 break; 1506 1507 case Q_ICMP: 1508 b1 = gen_proto(IPPROTO_ICMP, Q_IP, Q_DEFAULT); 1509 break; 1510 |
1511#ifndef IPPROTO_IGMP 1512#define IPPROTO_IGMP 2 1513#endif 1514 |
|
1230 case Q_IGMP: | 1515 case Q_IGMP: |
1231 b1 = gen_proto(2, Q_IP, Q_DEFAULT); | 1516 b1 = gen_proto(IPPROTO_IGMP, Q_IP, Q_DEFAULT); |
1232 break; 1233 1234#ifndef IPPROTO_IGRP 1235#define IPPROTO_IGRP 9 1236#endif 1237 case Q_IGRP: 1238 b1 = gen_proto(IPPROTO_IGRP, Q_IP, Q_DEFAULT); 1239 break; --- 24 unchanged lines hidden (view full) --- 1264 1265 case Q_LINK: 1266 bpf_error("link layer applied in wrong context"); 1267 1268 case Q_ATALK: 1269 b1 = gen_linktype(ETHERTYPE_ATALK); 1270 break; 1271 | 1517 break; 1518 1519#ifndef IPPROTO_IGRP 1520#define IPPROTO_IGRP 9 1521#endif 1522 case Q_IGRP: 1523 b1 = gen_proto(IPPROTO_IGRP, Q_IP, Q_DEFAULT); 1524 break; --- 24 unchanged lines hidden (view full) --- 1549 1550 case Q_LINK: 1551 bpf_error("link layer applied in wrong context"); 1552 1553 case Q_ATALK: 1554 b1 = gen_linktype(ETHERTYPE_ATALK); 1555 break; 1556 |
1557 case Q_AARP: 1558 b1 = gen_linktype(ETHERTYPE_AARP); 1559 break; 1560 |
|
1272 case Q_DECNET: 1273 b1 = gen_linktype(ETHERTYPE_DN); 1274 break; 1275 1276 case Q_SCA: 1277 b1 = gen_linktype(ETHERTYPE_SCA); 1278 break; 1279 --- 51 unchanged lines hidden (view full) --- 1331 case Q_ESIS: 1332 b1 = gen_proto(ISO9542_ESIS, Q_ISO, Q_DEFAULT); 1333 break; 1334 1335 case Q_ISIS: 1336 b1 = gen_proto(ISO10589_ISIS, Q_ISO, Q_DEFAULT); 1337 break; 1338 | 1561 case Q_DECNET: 1562 b1 = gen_linktype(ETHERTYPE_DN); 1563 break; 1564 1565 case Q_SCA: 1566 b1 = gen_linktype(ETHERTYPE_SCA); 1567 break; 1568 --- 51 unchanged lines hidden (view full) --- 1620 case Q_ESIS: 1621 b1 = gen_proto(ISO9542_ESIS, Q_ISO, Q_DEFAULT); 1622 break; 1623 1624 case Q_ISIS: 1625 b1 = gen_proto(ISO10589_ISIS, Q_ISO, Q_DEFAULT); 1626 break; 1627 |
1628 case Q_CLNP: 1629 b1 = gen_proto(ISO8473_CLNP, Q_ISO, Q_DEFAULT); 1630 break; 1631 |
|
1339 default: 1340 abort(); 1341 } 1342 return b1; 1343} 1344 1345static struct block * 1346gen_ipfrag() --- 203 unchanged lines hidden (view full) --- 1550 1551 case Q_LINK: 1552 /* XXX should look up h/w protocol type based on linktype */ 1553 v = pcap_nametoeproto(name); 1554 if (v == PROTO_UNDEF) 1555 bpf_error("unknown ether proto '%s'", name); 1556 break; 1557 | 1632 default: 1633 abort(); 1634 } 1635 return b1; 1636} 1637 1638static struct block * 1639gen_ipfrag() --- 203 unchanged lines hidden (view full) --- 1843 1844 case Q_LINK: 1845 /* XXX should look up h/w protocol type based on linktype */ 1846 v = pcap_nametoeproto(name); 1847 if (v == PROTO_UNDEF) 1848 bpf_error("unknown ether proto '%s'", name); 1849 break; 1850 |
1851 case Q_ISO: 1852 if (strcmp(name, "esis") == 0) 1853 v = ISO9542_ESIS; 1854 else if (strcmp(name, "isis") == 0) 1855 v = ISO10589_ISIS; 1856 else if (strcmp(name, "clnp") == 0) 1857 v = ISO8473_CLNP; 1858 else 1859 bpf_error("unknown osi proto '%s'", name); 1860 break; 1861 |
|
1558 default: 1559 v = PROTO_UNDEF; 1560 break; 1561 } 1562 return v; 1563} 1564 | 1862 default: 1863 v = PROTO_UNDEF; 1864 break; 1865 } 1866 return v; 1867} 1868 |
1869#if 0 |
|
1565struct stmt * 1566gen_joinsp(s, n) 1567 struct stmt **s; 1568 int n; 1569{ | 1870struct stmt * 1871gen_joinsp(s, n) 1872 struct stmt **s; 1873 int n; 1874{ |
1875 return NULL; |
|
1570} | 1876} |
1877#endif |
|
1571 | 1878 |
1572struct block * | 1879static struct block * |
1573gen_protochain(v, proto, dir) 1574 int v; 1575 int proto; 1576 int dir; 1577{ 1578#ifdef NO_PROTOCHAIN 1579 return gen_proto(v, proto, dir); 1580#else 1581 struct block *b0, *b; | 1880gen_protochain(v, proto, dir) 1881 int v; 1882 int proto; 1883 int dir; 1884{ 1885#ifdef NO_PROTOCHAIN 1886 return gen_proto(v, proto, dir); 1887#else 1888 struct block *b0, *b; |
1582 struct slist *s[100], *sp; | 1889 struct slist *s[100]; |
1583 int fix2, fix3, fix4, fix5; 1584 int ahcheck, again, end; 1585 int i, max; | 1890 int fix2, fix3, fix4, fix5; 1891 int ahcheck, again, end; 1892 int i, max; |
1586 int reg1 = alloc_reg(); | |
1587 int reg2 = alloc_reg(); 1588 1589 memset(s, 0, sizeof(s)); 1590 fix2 = fix3 = fix4 = fix5 = 0; 1591 1592 switch (proto) { 1593 case Q_IP: 1594 case Q_IPV6: --- 105 unchanged lines hidden (view full) --- 1700 v6end = i; 1701 i++; 1702 1703 /* v6advance: */ 1704 v6advance = i; 1705 1706 /* 1707 * in short, | 1893 int reg2 = alloc_reg(); 1894 1895 memset(s, 0, sizeof(s)); 1896 fix2 = fix3 = fix4 = fix5 = 0; 1897 1898 switch (proto) { 1899 case Q_IP: 1900 case Q_IPV6: --- 105 unchanged lines hidden (view full) --- 2006 v6end = i; 2007 i++; 2008 2009 /* v6advance: */ 2010 v6advance = i; 2011 2012 /* 2013 * in short, |
1708 * A = P[X + 1]; 1709 * X = X + (P[X] + 1) * 8; | 2014 * A = P[X]; 2015 * X = X + (P[X + 1] + 1) * 8; |
1710 */ 1711 /* A = X */ 1712 s[i] = new_stmt(BPF_MISC|BPF_TXA); 1713 i++; | 2016 */ 2017 /* A = X */ 2018 s[i] = new_stmt(BPF_MISC|BPF_TXA); 2019 i++; |
1714 /* MEM[reg1] = A */ | 2020 /* A = P[X + packet head] */ 2021 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 2022 s[i]->s.k = off_nl; 2023 i++; 2024 /* MEM[reg2] = A */ |
1715 s[i] = new_stmt(BPF_ST); | 2025 s[i] = new_stmt(BPF_ST); |
1716 s[i]->s.k = reg1; | 2026 s[i]->s.k = reg2; |
1717 i++; | 2027 i++; |
2028 /* A = X */ 2029 s[i] = new_stmt(BPF_MISC|BPF_TXA); 2030 i++; |
|
1718 /* A += 1 */ 1719 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 1720 s[i]->s.k = 1; 1721 i++; 1722 /* X = A */ 1723 s[i] = new_stmt(BPF_MISC|BPF_TAX); 1724 i++; 1725 /* A = P[X + packet head]; */ 1726 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 1727 s[i]->s.k = off_nl; 1728 i++; | 2031 /* A += 1 */ 2032 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 2033 s[i]->s.k = 1; 2034 i++; 2035 /* X = A */ 2036 s[i] = new_stmt(BPF_MISC|BPF_TAX); 2037 i++; 2038 /* A = P[X + packet head]; */ 2039 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 2040 s[i]->s.k = off_nl; 2041 i++; |
1729 /* MEM[reg2] = A */ 1730 s[i] = new_stmt(BPF_ST); 1731 s[i]->s.k = reg2; 1732 i++; 1733 /* X = MEM[reg1] */ 1734 s[i] = new_stmt(BPF_LDX|BPF_MEM); 1735 s[i]->s.k = reg1; 1736 i++; 1737 /* A = P[X + packet head] */ 1738 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 1739 s[i]->s.k = off_nl; 1740 i++; | |
1741 /* A += 1 */ 1742 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 1743 s[i]->s.k = 1; 1744 i++; 1745 /* A *= 8 */ 1746 s[i] = new_stmt(BPF_ALU|BPF_MUL|BPF_K); 1747 s[i]->s.k = 8; 1748 i++; --- 33 unchanged lines hidden (view full) --- 1782 s[i]->s.k = IPPROTO_AH; 1783 if (fix3) 1784 s[fix3]->s.jf = s[ahcheck]; 1785 fix4 = i; 1786 i++; 1787 1788 /* 1789 * in short, | 2042 /* A += 1 */ 2043 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 2044 s[i]->s.k = 1; 2045 i++; 2046 /* A *= 8 */ 2047 s[i] = new_stmt(BPF_ALU|BPF_MUL|BPF_K); 2048 s[i]->s.k = 8; 2049 i++; --- 33 unchanged lines hidden (view full) --- 2083 s[i]->s.k = IPPROTO_AH; 2084 if (fix3) 2085 s[fix3]->s.jf = s[ahcheck]; 2086 fix4 = i; 2087 i++; 2088 2089 /* 2090 * in short, |
1790 * A = P[X + 1]; 1791 * X = X + (P[X] + 2) * 4; | 2091 * A = P[X]; 2092 * X = X + (P[X + 1] + 2) * 4; |
1792 */ 1793 /* A = X */ 1794 s[i - 1]->s.jt = s[i] = new_stmt(BPF_MISC|BPF_TXA); 1795 i++; | 2093 */ 2094 /* A = X */ 2095 s[i - 1]->s.jt = s[i] = new_stmt(BPF_MISC|BPF_TXA); 2096 i++; |
1796 /* MEM[reg1] = A */ 1797 s[i] = new_stmt(BPF_ST); 1798 s[i]->s.k = reg1; 1799 i++; 1800 /* A += 1 */ 1801 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 1802 s[i]->s.k = 1; 1803 i++; 1804 /* X = A */ 1805 s[i] = new_stmt(BPF_MISC|BPF_TAX); 1806 i++; | |
1807 /* A = P[X + packet head]; */ 1808 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 1809 s[i]->s.k = off_nl; 1810 i++; 1811 /* MEM[reg2] = A */ 1812 s[i] = new_stmt(BPF_ST); 1813 s[i]->s.k = reg2; 1814 i++; | 2097 /* A = P[X + packet head]; */ 2098 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 2099 s[i]->s.k = off_nl; 2100 i++; 2101 /* MEM[reg2] = A */ 2102 s[i] = new_stmt(BPF_ST); 2103 s[i]->s.k = reg2; 2104 i++; |
1815 /* X = MEM[reg1] */ 1816 s[i] = new_stmt(BPF_LDX|BPF_MEM); 1817 s[i]->s.k = reg1; | 2105 /* A = X */ 2106 s[i - 1]->s.jt = s[i] = new_stmt(BPF_MISC|BPF_TXA); |
1818 i++; | 2107 i++; |
2108 /* A += 1 */ 2109 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 2110 s[i]->s.k = 1; 2111 i++; 2112 /* X = A */ 2113 s[i] = new_stmt(BPF_MISC|BPF_TAX); 2114 i++; |
|
1819 /* A = P[X + packet head] */ 1820 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 1821 s[i]->s.k = off_nl; 1822 i++; 1823 /* A += 2 */ 1824 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 1825 s[i]->s.k = 2; 1826 i++; --- 33 unchanged lines hidden (view full) --- 1860 1861 /* 1862 * emit final check 1863 */ 1864 b = new_block(JMP(BPF_JEQ)); 1865 b->stmts = s[1]; /*remember, s[0] is dummy*/ 1866 b->s.k = v; 1867 | 2115 /* A = P[X + packet head] */ 2116 s[i] = new_stmt(BPF_LD|BPF_IND|BPF_B); 2117 s[i]->s.k = off_nl; 2118 i++; 2119 /* A += 2 */ 2120 s[i] = new_stmt(BPF_ALU|BPF_ADD|BPF_K); 2121 s[i]->s.k = 2; 2122 i++; --- 33 unchanged lines hidden (view full) --- 2156 2157 /* 2158 * emit final check 2159 */ 2160 b = new_block(JMP(BPF_JEQ)); 2161 b->stmts = s[1]; /*remember, s[0] is dummy*/ 2162 b->s.k = v; 2163 |
1868 free_reg(reg1); | |
1869 free_reg(reg2); 1870 1871 gen_and(b0, b); 1872 return b; 1873#endif 1874} 1875 1876static struct block * --- 124 unchanged lines hidden (view full) --- 2001gen_scode(name, q) 2002 register const char *name; 2003 struct qual q; 2004{ 2005 int proto = q.proto; 2006 int dir = q.dir; 2007 int tproto; 2008 u_char *eaddr; | 2164 free_reg(reg2); 2165 2166 gen_and(b0, b); 2167 return b; 2168#endif 2169} 2170 2171static struct block * --- 124 unchanged lines hidden (view full) --- 2296gen_scode(name, q) 2297 register const char *name; 2298 struct qual q; 2299{ 2300 int proto = q.proto; 2301 int dir = q.dir; 2302 int tproto; 2303 u_char *eaddr; |
2009 bpf_u_int32 mask, addr, **alist; 2010#ifdef INET6 | 2304 bpf_u_int32 mask, addr; 2305#ifndef INET6 2306 bpf_u_int32 **alist; 2307#else |
2011 int tproto6; 2012 struct sockaddr_in *sin; 2013 struct sockaddr_in6 *sin6; 2014 struct addrinfo *res, *res0; 2015 struct in6_addr mask128; 2016#endif /*INET6*/ 2017 struct block *b, *tmp; 2018 int port, real_proto; --- 26 unchanged lines hidden (view full) --- 2045 2046 case DLT_FDDI: 2047 eaddr = pcap_ether_hostton(name); 2048 if (eaddr == NULL) 2049 bpf_error( 2050 "unknown FDDI host '%s'", name); 2051 return gen_fhostop(eaddr, dir); 2052 | 2308 int tproto6; 2309 struct sockaddr_in *sin; 2310 struct sockaddr_in6 *sin6; 2311 struct addrinfo *res, *res0; 2312 struct in6_addr mask128; 2313#endif /*INET6*/ 2314 struct block *b, *tmp; 2315 int port, real_proto; --- 26 unchanged lines hidden (view full) --- 2342 2343 case DLT_FDDI: 2344 eaddr = pcap_ether_hostton(name); 2345 if (eaddr == NULL) 2346 bpf_error( 2347 "unknown FDDI host '%s'", name); 2348 return gen_fhostop(eaddr, dir); 2349 |
2350 case DLT_IEEE802: 2351 eaddr = pcap_ether_hostton(name); 2352 if (eaddr == NULL) 2353 bpf_error( 2354 "unknown token ring host '%s'", name); 2355 return gen_thostop(eaddr, dir); 2356 |
|
2053 default: 2054 bpf_error( | 2357 default: 2358 bpf_error( |
2055 "only ethernet/FDDI supports link-level host name"); | 2359 "only ethernet/FDDI/token ring supports link-level host name"); |
2056 break; 2057 } 2058 } else if (proto == Q_DECNET) { 2059 unsigned short dn_addr = __pcap_nametodnaddr(name); 2060 /* 2061 * I don't think DECNET hosts can be multihomed, so 2062 * there is no need to build up a list of addresses 2063 */ --- 11 unchanged lines hidden (view full) --- 2075 tmp = gen_host(**alist++, 0xffffffff, 2076 tproto, dir); 2077 gen_or(b, tmp); 2078 b = tmp; 2079 } 2080 return b; 2081#else 2082 memset(&mask128, 0xff, sizeof(mask128)); | 2360 break; 2361 } 2362 } else if (proto == Q_DECNET) { 2363 unsigned short dn_addr = __pcap_nametodnaddr(name); 2364 /* 2365 * I don't think DECNET hosts can be multihomed, so 2366 * there is no need to build up a list of addresses 2367 */ --- 11 unchanged lines hidden (view full) --- 2379 tmp = gen_host(**alist++, 0xffffffff, 2380 tproto, dir); 2381 gen_or(b, tmp); 2382 b = tmp; 2383 } 2384 return b; 2385#else 2386 memset(&mask128, 0xff, sizeof(mask128)); |
2083 res0 = res = pcap_nametoaddr(name); | 2387 res0 = res = pcap_nametoaddrinfo(name); |
2084 if (res == NULL) 2085 bpf_error("unknown host '%s'", name); 2086 b = tmp = NULL; 2087 tproto = tproto6 = proto; 2088 if (off_linktype == -1 && tproto == Q_DEFAULT) { 2089 tproto = Q_IP; 2090 tproto6 = Q_IPV6; 2091 } --- 237 unchanged lines hidden (view full) --- 2329 struct in6_addr *addr; 2330 struct in6_addr mask; 2331 struct block *b; 2332 u_int32_t *a, *m; 2333 2334 if (s2) 2335 bpf_error("no mask %s supported", s2); 2336 | 2388 if (res == NULL) 2389 bpf_error("unknown host '%s'", name); 2390 b = tmp = NULL; 2391 tproto = tproto6 = proto; 2392 if (off_linktype == -1 && tproto == Q_DEFAULT) { 2393 tproto = Q_IP; 2394 tproto6 = Q_IPV6; 2395 } --- 237 unchanged lines hidden (view full) --- 2633 struct in6_addr *addr; 2634 struct in6_addr mask; 2635 struct block *b; 2636 u_int32_t *a, *m; 2637 2638 if (s2) 2639 bpf_error("no mask %s supported", s2); 2640 |
2337 res = pcap_nametoaddr(s1); | 2641 res = pcap_nametoaddrinfo(s1); |
2338 if (!res) 2339 bpf_error("invalid ip6 address %s", s1); 2340 if (res->ai_next) 2341 bpf_error("%s resolved to multiple address", s1); 2342 addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 2343 2344 if (sizeof(mask) * 8 < masklen) 2345 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask) * 8)); --- 35 unchanged lines hidden (view full) --- 2381 register const u_char *eaddr; 2382 struct qual q; 2383{ 2384 if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { 2385 if (linktype == DLT_EN10MB) 2386 return gen_ehostop(eaddr, (int)q.dir); 2387 if (linktype == DLT_FDDI) 2388 return gen_fhostop(eaddr, (int)q.dir); | 2642 if (!res) 2643 bpf_error("invalid ip6 address %s", s1); 2644 if (res->ai_next) 2645 bpf_error("%s resolved to multiple address", s1); 2646 addr = &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 2647 2648 if (sizeof(mask) * 8 < masklen) 2649 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask) * 8)); --- 35 unchanged lines hidden (view full) --- 2685 register const u_char *eaddr; 2686 struct qual q; 2687{ 2688 if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { 2689 if (linktype == DLT_EN10MB) 2690 return gen_ehostop(eaddr, (int)q.dir); 2691 if (linktype == DLT_FDDI) 2692 return gen_fhostop(eaddr, (int)q.dir); |
2693 if (linktype == DLT_IEEE802) 2694 return gen_thostop(eaddr, (int)q.dir); 2695 bpf_error("ethernet addresses supported only on ethernet, FDDI or token ring"); |
|
2389 } 2390 bpf_error("ethernet address used in non-ether expression"); 2391 /* NOTREACHED */ 2392} 2393 2394void 2395sappend(s0, s1) 2396 struct slist *s0, *s1; --- 315 unchanged lines hidden (view full) --- 2712 int n; 2713{ 2714 return gen_len(BPF_JGE, n); 2715} 2716 2717/* 2718 * Actually, this is less than or equal. 2719 */ | 2696 } 2697 bpf_error("ethernet address used in non-ether expression"); 2698 /* NOTREACHED */ 2699} 2700 2701void 2702sappend(s0, s1) 2703 struct slist *s0, *s1; --- 315 unchanged lines hidden (view full) --- 3019 int n; 3020{ 3021 return gen_len(BPF_JGE, n); 3022} 3023 3024/* 3025 * Actually, this is less than or equal. 3026 */ |
2720 | |
2721struct block * 2722gen_less(n) 2723 int n; 2724{ 2725 struct block *b; 2726 2727 b = gen_len(BPF_JGT, n); 2728 gen_not(b); --- 53 unchanged lines hidden (view full) --- 2782 switch (proto) { 2783 2784 case Q_DEFAULT: 2785 case Q_LINK: 2786 if (linktype == DLT_EN10MB) 2787 return gen_ehostop(ebroadcast, Q_DST); 2788 if (linktype == DLT_FDDI) 2789 return gen_fhostop(ebroadcast, Q_DST); | 3027struct block * 3028gen_less(n) 3029 int n; 3030{ 3031 struct block *b; 3032 3033 b = gen_len(BPF_JGT, n); 3034 gen_not(b); --- 53 unchanged lines hidden (view full) --- 3088 switch (proto) { 3089 3090 case Q_DEFAULT: 3091 case Q_LINK: 3092 if (linktype == DLT_EN10MB) 3093 return gen_ehostop(ebroadcast, Q_DST); 3094 if (linktype == DLT_FDDI) 3095 return gen_fhostop(ebroadcast, Q_DST); |
3096 if (linktype == DLT_IEEE802) 3097 return gen_thostop(ebroadcast, Q_DST); |
|
2790 bpf_error("not a broadcast link"); 2791 break; 2792 2793 case Q_IP: 2794 b0 = gen_linktype(ETHERTYPE_IP); 2795 hostmask = ~netmask; 2796 b1 = gen_mcmp(off_nl + 16, BPF_W, (bpf_int32)0, hostmask); 2797 b2 = gen_mcmp(off_nl + 16, BPF_W, --- 31 unchanged lines hidden (view full) --- 2829 /* fddi[1] & 1 != 0 */ 2830 s = new_stmt(BPF_LD|BPF_B|BPF_ABS); 2831 s->s.k = 1; 2832 b0 = new_block(JMP(BPF_JSET)); 2833 b0->s.k = 1; 2834 b0->stmts = s; 2835 return b0; 2836 } | 3098 bpf_error("not a broadcast link"); 3099 break; 3100 3101 case Q_IP: 3102 b0 = gen_linktype(ETHERTYPE_IP); 3103 hostmask = ~netmask; 3104 b1 = gen_mcmp(off_nl + 16, BPF_W, (bpf_int32)0, hostmask); 3105 b2 = gen_mcmp(off_nl + 16, BPF_W, --- 31 unchanged lines hidden (view full) --- 3137 /* fddi[1] & 1 != 0 */ 3138 s = new_stmt(BPF_LD|BPF_B|BPF_ABS); 3139 s->s.k = 1; 3140 b0 = new_block(JMP(BPF_JSET)); 3141 b0->s.k = 1; 3142 b0->stmts = s; 3143 return b0; 3144 } |
3145 3146 /* TODO - check how token ring handles multicast */ 3147 /* if (linktype == DLT_IEEE802) ... */ 3148 |
|
2837 /* Link not known to support multicasts */ 2838 break; 2839 2840 case Q_IP: 2841 b0 = gen_linktype(ETHERTYPE_IP); 2842 b1 = gen_cmp(off_nl + 16, BPF_B, (bpf_int32)224); 2843 b1->s.code = JMP(BPF_JGE); 2844 gen_and(b0, b1); --- 16 unchanged lines hidden (view full) --- 2861 * = 1 implies "outbound". 2862 */ 2863struct block * 2864gen_inbound(dir) 2865 int dir; 2866{ 2867 register struct block *b0; 2868 | 3149 /* Link not known to support multicasts */ 3150 break; 3151 3152 case Q_IP: 3153 b0 = gen_linktype(ETHERTYPE_IP); 3154 b1 = gen_cmp(off_nl + 16, BPF_B, (bpf_int32)224); 3155 b1->s.code = JMP(BPF_JGE); 3156 gen_and(b0, b1); --- 16 unchanged lines hidden (view full) --- 3173 * = 1 implies "outbound". 3174 */ 3175struct block * 3176gen_inbound(dir) 3177 int dir; 3178{ 3179 register struct block *b0; 3180 |
2869 b0 = gen_relation(BPF_JEQ, | 3181 /* 3182 * Only some data link types support inbound/outbound qualifiers. 3183 */ 3184 switch (linktype) { 3185 case DLT_SLIP: 3186 case DLT_PPP: 3187 b0 = gen_relation(BPF_JEQ, |
2870 gen_load(Q_LINK, gen_loadi(0), 1), 2871 gen_loadi(0), 2872 dir); | 3188 gen_load(Q_LINK, gen_loadi(0), 1), 3189 gen_loadi(0), 3190 dir); |
3191 break; 3192 3193 default: 3194 bpf_error("inbound/outbound not supported on linktype %d\n", 3195 linktype); 3196 b0 = NULL; 3197 /* NOTREACHED */ 3198 } |
|
2873 return (b0); 2874} | 3199 return (b0); 3200} |
3201 3202/* 3203 * support IEEE 802.1Q VLAN trunk over ethernet 3204 */ 3205struct block * 3206gen_vlan(vlan_num) 3207 int vlan_num; 3208{ 3209 static u_int orig_linktype = -1, orig_nl = -1; 3210 struct block *b0; 3211 3212 /* 3213 * Change the offsets to point to the type and data fields within 3214 * the VLAN packet. This is somewhat of a kludge. 3215 */ 3216 if (orig_nl == (u_int)-1) { 3217 orig_linktype = off_linktype; /* save original values */ 3218 orig_nl = off_nl; 3219 3220 switch (linktype) { 3221 3222 case DLT_EN10MB: 3223 off_linktype = 16; 3224 off_nl = 18; 3225 break; 3226 3227 default: 3228 bpf_error("no VLAN support for data link type %d", 3229 linktype); 3230 /*NOTREACHED*/ 3231 } 3232 } 3233 3234 /* check for VLAN */ 3235 b0 = gen_cmp(orig_linktype, BPF_H, (bpf_int32)ETHERTYPE_8021Q); 3236 3237 /* If a specific VLAN is requested, check VLAN id */ 3238 if (vlan_num >= 0) { 3239 struct block *b1; 3240 3241 b1 = gen_cmp(orig_nl, BPF_H, (bpf_int32)vlan_num); 3242 gen_and(b0, b1); 3243 b0 = b1; 3244 } 3245 3246 return (b0); 3247} |
|