]>
The Tcpdump Group git mirrors - libpcap/blob - gencode.c
1 /*#define CHASE_CHAIN*/
3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
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)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
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
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.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.193 2003-08-18 22:09:30 guy Exp $ (LBL)";
32 #include <pcap-stdinc.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
40 * XXX - why was this included even on UNIX?
49 #include <sys/param.h>
52 #include <netinet/in.h>
64 #include "ethertype.h"
69 #include "sunatmpos.h"
76 #include <netdb.h> /* for "struct addrinfo" */
79 #include <pcap-namedb.h>
84 #define IPPROTO_SCTP 132
87 #ifdef HAVE_OS_PROTO_H
91 #define JMP(c) ((c)|BPF_JMP|BPF_K)
94 static jmp_buf top_ctx
;
95 static pcap_t
*bpf_pcap
;
97 /* Hack for updating VLAN offsets. */
98 static u_int orig_linktype
= -1, orig_nl
= -1, orig_nl_nosnap
= -1;
102 int pcap_fddipad
= PCAP_FDDIPAD
;
109 bpf_error(const char *fmt
, ...)
115 if (bpf_pcap
!= NULL
)
116 (void)vsnprintf(pcap_geterr(bpf_pcap
), PCAP_ERRBUF_SIZE
,
123 static void init_linktype(int);
125 static int alloc_reg(void);
126 static void free_reg(int);
128 static struct block
*root
;
131 * We divy out chunks of memory rather than call malloc each time so
132 * we don't have to worry about leaking memory. It's probably
133 * not a big deal if all this memory was wasted but it this ever
134 * goes into a library that would probably not be a good idea.
137 #define CHUNK0SIZE 1024
143 static struct chunk chunks
[NCHUNKS
];
144 static int cur_chunk
;
146 static void *newchunk(u_int
);
147 static void freechunks(void);
148 static inline struct block
*new_block(int);
149 static inline struct slist
*new_stmt(int);
150 static struct block
*gen_retblk(int);
151 static inline void syntax(void);
153 static void backpatch(struct block
*, struct block
*);
154 static void merge(struct block
*, struct block
*);
155 static struct block
*gen_cmp(u_int
, u_int
, bpf_int32
);
156 static struct block
*gen_cmp_gt(u_int
, u_int
, bpf_int32
);
157 static struct block
*gen_mcmp(u_int
, u_int
, bpf_int32
, bpf_u_int32
);
158 static struct block
*gen_bcmp(u_int
, u_int
, const u_char
*);
159 static struct block
*gen_ncmp(bpf_u_int32
, bpf_u_int32
, bpf_u_int32
,
160 bpf_u_int32
, bpf_u_int32
, int);
161 static struct block
*gen_uncond(int);
162 static inline struct block
*gen_true(void);
163 static inline struct block
*gen_false(void);
164 static struct block
*gen_ether_linktype(int);
165 static struct block
*gen_linktype(int);
166 static struct block
*gen_snap(bpf_u_int32
, bpf_u_int32
, u_int
);
167 static struct block
*gen_llc(int);
168 static struct block
*gen_hostop(bpf_u_int32
, bpf_u_int32
, int, int, u_int
, u_int
);
170 static struct block
*gen_hostop6(struct in6_addr
*, struct in6_addr
*, int, int, u_int
, u_int
);
172 static struct block
*gen_ahostop(const u_char
*, int);
173 static struct block
*gen_ehostop(const u_char
*, int);
174 static struct block
*gen_fhostop(const u_char
*, int);
175 static struct block
*gen_thostop(const u_char
*, int);
176 static struct block
*gen_wlanhostop(const u_char
*, int);
177 static struct block
*gen_ipfchostop(const u_char
*, int);
178 static struct block
*gen_dnhostop(bpf_u_int32
, int, u_int
);
179 static struct block
*gen_host(bpf_u_int32
, bpf_u_int32
, int, int);
181 static struct block
*gen_host6(struct in6_addr
*, struct in6_addr
*, int, int);
184 static struct block
*gen_gateway(const u_char
*, bpf_u_int32
**, int, int);
186 static struct block
*gen_ipfrag(void);
187 static struct block
*gen_portatom(int, bpf_int32
);
189 static struct block
*gen_portatom6(int, bpf_int32
);
191 struct block
*gen_portop(int, int, int);
192 static struct block
*gen_port(int, int, int);
194 struct block
*gen_portop6(int, int, int);
195 static struct block
*gen_port6(int, int, int);
197 static int lookup_proto(const char *, int);
198 static struct block
*gen_protochain(int, int, int);
199 static struct block
*gen_proto(int, int, int);
200 static struct slist
*xfer_to_x(struct arth
*);
201 static struct slist
*xfer_to_a(struct arth
*);
202 static struct block
*gen_mac_multicast(int);
203 static struct block
*gen_len(int, int);
205 static struct block
*gen_msg_abbrev(int type
);
216 /* XXX Round up to nearest long. */
217 n
= (n
+ sizeof(long) - 1) & ~(sizeof(long) - 1);
219 /* XXX Round up to structure boundary. */
223 cp
= &chunks
[cur_chunk
];
224 if (n
> cp
->n_left
) {
225 ++cp
, k
= ++cur_chunk
;
227 bpf_error("out of memory");
228 size
= CHUNK0SIZE
<< k
;
229 cp
->m
= (void *)malloc(size
);
231 bpf_error("out of memory");
232 memset((char *)cp
->m
, 0, size
);
235 bpf_error("out of memory");
238 return (void *)((char *)cp
->m
+ cp
->n_left
);
247 for (i
= 0; i
< NCHUNKS
; ++i
)
248 if (chunks
[i
].m
!= NULL
) {
255 * A strdup whose allocations are freed after code generation is over.
259 register const char *s
;
261 int n
= strlen(s
) + 1;
262 char *cp
= newchunk(n
);
268 static inline struct block
*
274 p
= (struct block
*)newchunk(sizeof(*p
));
281 static inline struct slist
*
287 p
= (struct slist
*)newchunk(sizeof(*p
));
293 static struct block
*
297 struct block
*b
= new_block(BPF_RET
|BPF_K
);
306 bpf_error("syntax error in filter expression");
309 static bpf_u_int32 netmask
;
314 pcap_compile(pcap_t
*p
, struct bpf_program
*program
,
315 char *buf
, int optimize
, bpf_u_int32 mask
)
324 if (setjmp(top_ctx
)) {
332 snaplen
= pcap_snapshot(p
);
334 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
335 "snaplen of 0 rejects all packets");
339 lex_init(buf
? buf
: "");
340 init_linktype(pcap_datalink(p
));
347 root
= gen_retblk(snaplen
);
349 if (optimize
&& !no_optimize
) {
352 (root
->s
.code
== (BPF_RET
|BPF_K
) && root
->s
.k
== 0))
353 bpf_error("expression rejects all packets");
355 program
->bf_insns
= icode_to_fcode(root
, &len
);
356 program
->bf_len
= len
;
364 * entry point for using the compiler with no pcap open
365 * pass in all the stuff that is needed explicitly instead.
368 pcap_compile_nopcap(int snaplen_arg
, int linktype_arg
,
369 struct bpf_program
*program
,
370 char *buf
, int optimize
, bpf_u_int32 mask
)
375 p
= pcap_open_dead(linktype_arg
, snaplen_arg
);
378 ret
= pcap_compile(p
, program
, buf
, optimize
, mask
);
384 * Clean up a "struct bpf_program" by freeing all the memory allocated
388 pcap_freecode(struct bpf_program
*program
)
391 if (program
->bf_insns
!= NULL
) {
392 free((char *)program
->bf_insns
);
393 program
->bf_insns
= NULL
;
398 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
399 * which of the jt and jf fields has been resolved and which is a pointer
400 * back to another unresolved block (or nil). At least one of the fields
401 * in each block is already resolved.
404 backpatch(list
, target
)
405 struct block
*list
, *target
;
422 * Merge the lists in b0 and b1, using the 'sense' field to indicate
423 * which of jt and jf is the link.
427 struct block
*b0
, *b1
;
429 register struct block
**p
= &b0
;
431 /* Find end of list. */
433 p
= !((*p
)->sense
) ? &JT(*p
) : &JF(*p
);
435 /* Concatenate the lists. */
443 backpatch(p
, gen_retblk(snaplen
));
444 p
->sense
= !p
->sense
;
445 backpatch(p
, gen_retblk(0));
451 struct block
*b0
, *b1
;
453 backpatch(b0
, b1
->head
);
454 b0
->sense
= !b0
->sense
;
455 b1
->sense
= !b1
->sense
;
457 b1
->sense
= !b1
->sense
;
463 struct block
*b0
, *b1
;
465 b0
->sense
= !b0
->sense
;
466 backpatch(b0
, b1
->head
);
467 b0
->sense
= !b0
->sense
;
476 b
->sense
= !b
->sense
;
479 static struct block
*
480 gen_cmp(offset
, size
, v
)
487 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
490 b
= new_block(JMP(BPF_JEQ
));
497 static struct block
*
498 gen_cmp_gt(offset
, size
, v
)
505 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
508 b
= new_block(JMP(BPF_JGT
));
515 static struct block
*
516 gen_mcmp(offset
, size
, v
, mask
)
521 struct block
*b
= gen_cmp(offset
, size
, v
);
524 if (mask
!= 0xffffffff) {
525 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
532 static struct block
*
533 gen_bcmp(offset
, size
, v
)
534 register u_int offset
, size
;
535 register const u_char
*v
;
537 register struct block
*b
, *tmp
;
541 register const u_char
*p
= &v
[size
- 4];
542 bpf_int32 w
= ((bpf_int32
)p
[0] << 24) |
543 ((bpf_int32
)p
[1] << 16) | ((bpf_int32
)p
[2] << 8) | p
[3];
545 tmp
= gen_cmp(offset
+ size
- 4, BPF_W
, w
);
552 register const u_char
*p
= &v
[size
- 2];
553 bpf_int32 w
= ((bpf_int32
)p
[0] << 8) | p
[1];
555 tmp
= gen_cmp(offset
+ size
- 2, BPF_H
, w
);
562 tmp
= gen_cmp(offset
, BPF_B
, (bpf_int32
)v
[0]);
570 static struct block
*
571 gen_ncmp(datasize
, offset
, mask
, jtype
, jvalue
, reverse
)
572 bpf_u_int32 datasize
, offset
, mask
, jtype
, jvalue
;
578 s
= new_stmt(BPF_LD
|datasize
|BPF_ABS
);
581 if (mask
!= 0xffffffff) {
582 s
->next
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
586 b
= new_block(JMP(jtype
));
589 if (reverse
&& (jtype
== BPF_JGT
|| jtype
== BPF_JGE
))
595 * Various code constructs need to know the layout of the data link
596 * layer. These variables give the necessary offsets.
600 * This is the offset of the beginning of the MAC-layer header.
601 * It's usually 0, except for ATM LANE.
603 static u_int off_mac
;
606 * "off_linktype" is the offset to information in the link-layer header
607 * giving the packet type.
609 * For Ethernet, it's the offset of the Ethernet type field.
611 * For link-layer types that always use 802.2 headers, it's the
612 * offset of the LLC header.
614 * For PPP, it's the offset of the PPP type field.
616 * For Cisco HDLC, it's the offset of the CHDLC type field.
618 * For BSD loopback, it's the offset of the AF_ value.
620 * For Linux cooked sockets, it's the offset of the type field.
622 * It's set to -1 for no encapsulation, in which case, IP is assumed.
624 static u_int off_linktype
;
627 * TRUE if the link layer includes an ATM pseudo-header.
629 static int is_atm
= 0;
632 * TRUE if "lane" appeared in the filter; it causes us to generate
633 * code that assumes LANE rather than LLC-encapsulated traffic in SunATM.
635 static int is_lane
= 0;
638 * These are offsets for the ATM pseudo-header.
640 static u_int off_vpi
;
641 static u_int off_vci
;
642 static u_int off_proto
;
645 * This is the offset of the first byte after the ATM pseudo_header,
646 * or -1 if there is no ATM pseudo-header.
648 static u_int off_payload
;
651 * These are offsets to the beginning of the network-layer header.
653 * If the link layer never uses 802.2 LLC:
655 * "off_nl" and "off_nl_nosnap" are the same.
657 * If the link layer always uses 802.2 LLC:
659 * "off_nl" is the offset if there's a SNAP header following
662 * "off_nl_nosnap" is the offset if there's no SNAP header.
664 * If the link layer is Ethernet:
666 * "off_nl" is the offset if the packet is an Ethernet II packet
667 * (we assume no 802.3+802.2+SNAP);
669 * "off_nl_nosnap" is the offset if the packet is an 802.3 packet
670 * with an 802.2 header following it.
673 static u_int off_nl_nosnap
;
684 * Assume it's not raw ATM with a pseudo-header, for now.
702 off_nl
= 6; /* XXX in reality, variable! */
703 off_nl_nosnap
= 6; /* no 802.2 LLC */
706 case DLT_ARCNET_LINUX
:
708 off_nl
= 8; /* XXX in reality, variable! */
709 off_nl_nosnap
= 8; /* no 802.2 LLC */
714 off_nl
= 14; /* Ethernet II */
715 off_nl_nosnap
= 17; /* 802.3+802.2 */
720 * SLIP doesn't have a link level type. The 16 byte
721 * header is hacked into our SLIP driver.
725 off_nl_nosnap
= 16; /* no 802.2 LLC */
729 /* XXX this may be the same as the DLT_PPP_BSDOS case */
733 off_nl_nosnap
= 24; /* no 802.2 LLC */
740 off_nl_nosnap
= 4; /* no 802.2 LLC */
746 off_nl_nosnap
= 12; /* no 802.2 LLC */
752 off_nl_nosnap
= 28; /* no 802.2 LLC */
756 case DLT_C_HDLC
: /* BSD/OS Cisco HDLC */
757 case DLT_PPP_SERIAL
: /* NetBSD sync/async serial PPP */
760 off_nl_nosnap
= 4; /* no 802.2 LLC */
765 * This does no include the Ethernet header, and
766 * only covers session state.
770 off_nl_nosnap
= 8; /* no 802.2 LLC */
776 off_nl_nosnap
= 24; /* no 802.2 LLC */
781 * FDDI doesn't really have a link-level type field.
782 * We set "off_linktype" to the offset of the LLC header.
784 * To check for Ethernet types, we assume that SSAP = SNAP
785 * is being used and pick out the encapsulated Ethernet type.
786 * XXX - should we generate code to check for SNAP?
790 off_linktype
+= pcap_fddipad
;
792 off_nl
= 21; /* FDDI+802.2+SNAP */
793 off_nl_nosnap
= 16; /* FDDI+802.2 */
795 off_nl
+= pcap_fddipad
;
796 off_nl_nosnap
+= pcap_fddipad
;
802 * Token Ring doesn't really have a link-level type field.
803 * We set "off_linktype" to the offset of the LLC header.
805 * To check for Ethernet types, we assume that SSAP = SNAP
806 * is being used and pick out the encapsulated Ethernet type.
807 * XXX - should we generate code to check for SNAP?
809 * XXX - the header is actually variable-length.
810 * Some various Linux patched versions gave 38
811 * as "off_linktype" and 40 as "off_nl"; however,
812 * if a token ring packet has *no* routing
813 * information, i.e. is not source-routed, the correct
814 * values are 20 and 22, as they are in the vanilla code.
816 * A packet is source-routed iff the uppermost bit
817 * of the first byte of the source address, at an
818 * offset of 8, has the uppermost bit set. If the
819 * packet is source-routed, the total number of bytes
820 * of routing information is 2 plus bits 0x1F00 of
821 * the 16-bit value at an offset of 14 (shifted right
822 * 8 - figure out which byte that is).
825 off_nl
= 22; /* Token Ring+802.2+SNAP */
826 off_nl_nosnap
= 17; /* Token Ring+802.2 */
831 * 802.11 doesn't really have a link-level type field.
832 * We set "off_linktype" to the offset of the LLC header.
834 * To check for Ethernet types, we assume that SSAP = SNAP
835 * is being used and pick out the encapsulated Ethernet type.
836 * XXX - should we generate code to check for SNAP?
838 * XXX - the header is actually variable-length. We
839 * assume a 24-byte link-layer header, as appears in
840 * data frames in networks with no bridges.
843 off_nl
= 32; /* 802.11+802.2+SNAP */
844 off_nl_nosnap
= 27; /* 802.11+802.2 */
847 case DLT_PRISM_HEADER
:
849 * Same as 802.11, but with an additional header before
850 * the 802.11 header, containing a bunch of additional
851 * information including radio-level information.
853 * The header is 144 bytes long.
855 * XXX - same variable-length header problem; at least
856 * the Prism header is fixed-length.
858 off_linktype
= 144+24;
859 off_nl
= 144+32; /* Prism+802.11+802.2+SNAP */
860 off_nl_nosnap
= 144+27; /* Prism+802.11+802.2 */
863 case DLT_IEEE802_11_RADIO
:
865 * Same as 802.11, but with an additional header before
866 * the 802.11 header, containing a bunch of additional
867 * information including radio-level information.
869 * The header is 64 bytes long.
871 * XXX - same variable-length header problem, only
872 * more so; this header is also variable-length,
873 * with the length being the 32-bit big-endian
874 * number at an offset of 4 from the beginning
875 * of the radio header.
877 off_linktype
= 64+24;
878 off_nl
= 64+32; /* Radio+802.11+802.2+SNAP */
879 off_nl_nosnap
= 64+27; /* Radio+802.11+802.2 */
882 case DLT_ATM_RFC1483
:
883 case DLT_ATM_CLIP
: /* Linux ATM defines this */
885 * assume routed, non-ISO PDUs
886 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
889 off_nl
= 8; /* 802.2+SNAP */
890 off_nl_nosnap
= 3; /* 802.2 */
895 * Full Frontal ATM; you get AALn PDUs with an ATM
899 off_vpi
= SUNATM_VPI_POS
;
900 off_vci
= SUNATM_VCI_POS
;
901 off_proto
= PROTO_POS
;
902 off_mac
= -1; /* LLC-encapsulated, so no MAC-layer header */
903 off_payload
= SUNATM_PKT_BEGIN_POS
;
904 off_linktype
= off_payload
;
905 off_nl
= off_payload
+8; /* 802.2+SNAP */
906 off_nl_nosnap
= off_payload
+3; /* 802.2 */
912 off_nl_nosnap
= 0; /* no 802.2 LLC */
915 case DLT_LINUX_SLL
: /* fake header for Linux cooked socket */
918 off_nl_nosnap
= 16; /* no 802.2 LLC */
923 * LocalTalk does have a 1-byte type field in the LLAP header,
924 * but really it just indicates whether there is a "short" or
925 * "long" DDP packet following.
929 off_nl_nosnap
= 0; /* no 802.2 LLC */
934 * RFC 2625 IP-over-Fibre-Channel doesn't really have a
935 * link-level type field. We set "off_linktype" to the
936 * offset of the LLC header.
938 * To check for Ethernet types, we assume that SSAP = SNAP
939 * is being used and pick out the encapsulated Ethernet type.
940 * XXX - should we generate code to check for SNAP? RFC
941 * 2625 says SNAP should be used.
944 off_nl
= 24; /* IPFC+802.2+SNAP */
945 off_nl_nosnap
= 19; /* IPFC+802.2 */
950 * XXX - we should set this to handle SNAP-encapsulated
951 * frames (NLPID of 0x80).
955 off_nl_nosnap
= 0; /* no 802.2 LLC */
958 bpf_error("unknown data link type %d", linktype
);
962 static struct block
*
969 s
= new_stmt(BPF_LD
|BPF_IMM
);
971 b
= new_block(JMP(BPF_JEQ
));
977 static inline struct block
*
980 return gen_uncond(1);
983 static inline struct block
*
986 return gen_uncond(0);
990 * Byte-swap a 32-bit number.
991 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
992 * big-endian platforms.)
994 #define SWAPLONG(y) \
995 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
997 static struct block
*
998 gen_ether_linktype(proto
)
1001 struct block
*b0
, *b1
;
1007 * OSI protocols always use 802.2 encapsulation.
1008 * XXX - should we check both the DSAP and the
1009 * SSAP, like this, or should we check just the
1012 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1014 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1015 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1020 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1022 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1023 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1027 case LLCSAP_NETBEUI
:
1029 * NetBEUI always uses 802.2 encapsulation.
1030 * XXX - should we check both the DSAP and the
1031 * SSAP, like this, or should we check just the
1034 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1036 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1037 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1045 * Ethernet_II frames, which are Ethernet
1046 * frames with a frame type of ETHERTYPE_IPX;
1048 * Ethernet_802.3 frames, which are 802.3
1049 * frames (i.e., the type/length field is
1050 * a length field, <= ETHERMTU, rather than
1051 * a type field) with the first two bytes
1052 * after the Ethernet/802.3 header being
1055 * Ethernet_802.2 frames, which are 802.3
1056 * frames with an 802.2 LLC header and
1057 * with the IPX LSAP as the DSAP in the LLC
1060 * Ethernet_SNAP frames, which are 802.3
1061 * frames with an LLC header and a SNAP
1062 * header and with an OUI of 0x000000
1063 * (encapsulated Ethernet) and a protocol
1064 * ID of ETHERTYPE_IPX in the SNAP header.
1066 * XXX - should we generate the same code both
1067 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
1071 * This generates code to check both for the
1072 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
1074 b0
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1075 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)0xFFFF);
1079 * Now we add code to check for SNAP frames with
1080 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1082 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1086 * Now we generate code to check for 802.3
1087 * frames in general.
1089 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1093 * Now add the check for 802.3 frames before the
1094 * check for Ethernet_802.2 and Ethernet_802.3,
1095 * as those checks should only be done on 802.3
1096 * frames, not on Ethernet frames.
1101 * Now add the check for Ethernet_II frames, and
1102 * do that before checking for the other frame
1105 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_IPX
);
1109 case ETHERTYPE_ATALK
:
1110 case ETHERTYPE_AARP
:
1112 * EtherTalk (AppleTalk protocols on Ethernet link
1113 * layer) may use 802.2 encapsulation.
1117 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1118 * we check for an Ethernet type field less than
1119 * 1500, which means it's an 802.3 length field.
1121 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1125 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1126 * SNAP packets with an organization code of
1127 * 0x080007 (Apple, for Appletalk) and a protocol
1128 * type of ETHERTYPE_ATALK (Appletalk).
1130 * 802.2-encapsulated ETHERTYPE_AARP packets are
1131 * SNAP packets with an organization code of
1132 * 0x000000 (encapsulated Ethernet) and a protocol
1133 * type of ETHERTYPE_AARP (Appletalk ARP).
1135 if (proto
== ETHERTYPE_ATALK
)
1136 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1137 else /* proto == ETHERTYPE_AARP */
1138 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1142 * Check for Ethernet encapsulation (Ethertalk
1143 * phase 1?); we just check for the Ethernet
1146 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1152 if (proto
<= ETHERMTU
) {
1154 * This is an LLC SAP value, so the frames
1155 * that match would be 802.2 frames.
1156 * Check that the frame is an 802.2 frame
1157 * (i.e., that the length/type field is
1158 * a length field, <= ETHERMTU) and
1159 * then check the DSAP.
1161 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1163 b1
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)proto
);
1168 * This is an Ethernet type, so compare
1169 * the length/type field with it (if
1170 * the frame is an 802.2 frame, the length
1171 * field will be <= ETHERMTU, and, as
1172 * "proto" is > ETHERMTU, this test
1173 * will fail and the frame won't match,
1174 * which is what we want).
1176 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1181 static struct block
*
1185 struct block
*b0
, *b1
, *b2
;
1190 return gen_ether_linktype(proto
);
1197 proto
= (proto
<< 8 | LLCSAP_ISONS
);
1201 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1206 case DLT_IEEE802_11
:
1207 case DLT_PRISM_HEADER
:
1208 case DLT_IEEE802_11_RADIO
:
1211 case DLT_ATM_RFC1483
:
1213 case DLT_IP_OVER_FC
:
1214 return gen_llc(proto
);
1219 * If "is_lane" is set, check for a LANE-encapsulated
1220 * version of this protocol, otherwise check for an
1221 * LLC-encapsulated version of this protocol.
1223 * We assume LANE means Ethernet, not Token Ring.
1227 * Check that the packet doesn't begin with an
1228 * LE Control marker. (We've already generated
1231 b0
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
1235 * Now generate an Ethernet test.
1237 b1
= gen_ether_linktype(proto
);
1242 * Check for LLC encapsulation and then check the
1245 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1246 b1
= gen_llc(proto
);
1255 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1256 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1257 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1263 * OSI protocols always use 802.2 encapsulation.
1264 * XXX - should we check both the DSAP and the
1265 * LSAP, like this, or should we check just the
1268 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1269 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1270 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1274 case LLCSAP_NETBEUI
:
1276 * NetBEUI always uses 802.2 encapsulation.
1277 * XXX - should we check both the DSAP and the
1278 * LSAP, like this, or should we check just the
1281 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1282 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1283 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1289 * Ethernet_II frames, which are Ethernet
1290 * frames with a frame type of ETHERTYPE_IPX;
1292 * Ethernet_802.3 frames, which have a frame
1293 * type of LINUX_SLL_P_802_3;
1295 * Ethernet_802.2 frames, which are 802.3
1296 * frames with an 802.2 LLC header (i.e, have
1297 * a frame type of LINUX_SLL_P_802_2) and
1298 * with the IPX LSAP as the DSAP in the LLC
1301 * Ethernet_SNAP frames, which are 802.3
1302 * frames with an LLC header and a SNAP
1303 * header and with an OUI of 0x000000
1304 * (encapsulated Ethernet) and a protocol
1305 * ID of ETHERTYPE_IPX in the SNAP header.
1307 * First, do the checks on LINUX_SLL_P_802_2
1308 * frames; generate the check for either
1309 * Ethernet_802.2 or Ethernet_SNAP frames, and
1310 * then put a check for LINUX_SLL_P_802_2 frames
1313 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1314 (bpf_int32
)LLCSAP_IPX
);
1315 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1318 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1322 * Now check for 802.3 frames and OR that with
1323 * the previous test.
1325 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1329 * Now add the check for Ethernet_II frames, and
1330 * do that before checking for the other frame
1333 b0
= gen_cmp(off_linktype
, BPF_H
,
1334 (bpf_int32
)ETHERTYPE_IPX
);
1338 case ETHERTYPE_ATALK
:
1339 case ETHERTYPE_AARP
:
1341 * EtherTalk (AppleTalk protocols on Ethernet link
1342 * layer) may use 802.2 encapsulation.
1346 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1347 * we check for the 802.2 protocol type in the
1348 * "Ethernet type" field.
1350 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1353 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1354 * SNAP packets with an organization code of
1355 * 0x080007 (Apple, for Appletalk) and a protocol
1356 * type of ETHERTYPE_ATALK (Appletalk).
1358 * 802.2-encapsulated ETHERTYPE_AARP packets are
1359 * SNAP packets with an organization code of
1360 * 0x000000 (encapsulated Ethernet) and a protocol
1361 * type of ETHERTYPE_AARP (Appletalk ARP).
1363 if (proto
== ETHERTYPE_ATALK
)
1364 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1366 else /* proto == ETHERTYPE_AARP */
1367 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1372 * Check for Ethernet encapsulation (Ethertalk
1373 * phase 1?); we just check for the Ethernet
1376 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1382 if (proto
<= ETHERMTU
) {
1384 * This is an LLC SAP value, so the frames
1385 * that match would be 802.2 frames.
1386 * Check for the 802.2 protocol type
1387 * in the "Ethernet type" field, and
1388 * then check the DSAP.
1390 b0
= gen_cmp(off_linktype
, BPF_H
,
1392 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1398 * This is an Ethernet type, so compare
1399 * the length/type field with it (if
1400 * the frame is an 802.2 frame, the length
1401 * field will be <= ETHERMTU, and, as
1402 * "proto" is > ETHERMTU, this test
1403 * will fail and the frame won't match,
1404 * which is what we want).
1406 return gen_cmp(off_linktype
, BPF_H
,
1413 case DLT_SLIP_BSDOS
:
1416 * These types don't provide any type field; packets
1419 * XXX - for IPv4, check for a version number of 4, and,
1420 * for IPv6, check for a version number of 6?
1426 case ETHERTYPE_IPV6
:
1428 return gen_true(); /* always true */
1431 return gen_false(); /* always false */
1436 case DLT_PPP_SERIAL
:
1439 * We use Ethernet protocol types inside libpcap;
1440 * map them to the corresponding PPP protocol types.
1449 case ETHERTYPE_IPV6
:
1458 case ETHERTYPE_ATALK
:
1472 * I'm assuming the "Bridging PDU"s that go
1473 * over PPP are Spanning Tree Protocol
1487 * We use Ethernet protocol types inside libpcap;
1488 * map them to the corresponding PPP protocol types.
1493 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1494 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1496 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1501 case ETHERTYPE_IPV6
:
1511 case ETHERTYPE_ATALK
:
1525 * I'm assuming the "Bridging PDU"s that go
1526 * over PPP are Spanning Tree Protocol
1543 * For DLT_NULL, the link-layer header is a 32-bit
1544 * word containing an AF_ value in *host* byte order,
1545 * and for DLT_ENC, the link-layer header begins
1546 * with a 32-bit work containing an AF_ value in
1549 * In addition, if we're reading a saved capture file,
1550 * the host byte order in the capture may not be the
1551 * same as the host byte order on this machine.
1553 * For DLT_LOOP, the link-layer header is a 32-bit
1554 * word containing an AF_ value in *network* byte order.
1556 * XXX - AF_ values may, unfortunately, be platform-
1557 * dependent; for example, FreeBSD's AF_INET6 is 24
1558 * whilst NetBSD's and OpenBSD's is 26.
1560 * This means that, when reading a capture file, just
1561 * checking for our AF_INET6 value won't work if the
1562 * capture file came from another OS.
1564 * XXX - what's the byte order for DLT_PFLOG?
1573 case ETHERTYPE_IPV6
:
1580 * Not a type on which we support filtering.
1581 * XXX - support those that have AF_ values
1582 * #defined on this platform, at least?
1587 if (linktype
== DLT_NULL
|| linktype
== DLT_ENC
) {
1589 * The AF_ value is in host byte order, but
1590 * the BPF interpreter will convert it to
1591 * network byte order.
1593 * If this is a save file, and it's from a
1594 * machine with the opposite byte order to
1595 * ours, we byte-swap the AF_ value.
1597 * Then we run it through "htonl()", and
1598 * generate code to compare against the result.
1600 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1601 bpf_pcap
->sf
.swapped
)
1602 proto
= SWAPLONG(proto
);
1603 proto
= htonl(proto
);
1605 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1608 case DLT_ARCNET_LINUX
:
1610 * XXX should we check for first fragment if the protocol
1619 case ETHERTYPE_IPV6
:
1620 return (gen_cmp(off_linktype
, BPF_B
,
1621 (bpf_int32
)ARCTYPE_INET6
));
1625 b0
= gen_cmp(off_linktype
, BPF_B
,
1626 (bpf_int32
)ARCTYPE_IP
);
1627 b1
= gen_cmp(off_linktype
, BPF_B
,
1628 (bpf_int32
)ARCTYPE_IP_OLD
);
1633 b0
= gen_cmp(off_linktype
, BPF_B
,
1634 (bpf_int32
)ARCTYPE_ARP
);
1635 b1
= gen_cmp(off_linktype
, BPF_B
,
1636 (bpf_int32
)ARCTYPE_ARP_OLD
);
1640 case ETHERTYPE_REVARP
:
1641 return (gen_cmp(off_linktype
, BPF_B
,
1642 (bpf_int32
)ARCTYPE_REVARP
));
1644 case ETHERTYPE_ATALK
:
1645 return (gen_cmp(off_linktype
, BPF_B
,
1646 (bpf_int32
)ARCTYPE_ATALK
));
1652 case ETHERTYPE_ATALK
:
1661 * XXX - assumes a 2-byte Frame Relay header with
1662 * DLCI and flags. What if the address is longer?
1668 * Check for the special NLPID for IP.
1670 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1673 case ETHERTYPE_IPV6
:
1675 * Check for the special NLPID for IPv6.
1677 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1682 * Check for several OSI protocols.
1684 * Frame Relay packets typically have an OSI
1685 * NLPID at the beginning; we check for each
1688 * What we check for is the NLPID and a frame
1689 * control field of UI, i.e. 0x03 followed
1692 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1693 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1694 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1706 * All the types that have no encapsulation should either be
1707 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1708 * all packets are IP packets, or should be handled in some
1709 * special case, if none of them are (if some are and some
1710 * aren't, the lack of encapsulation is a problem, as we'd
1711 * have to find some other way of determining the packet type).
1713 * Therefore, if "off_linktype" is -1, there's an error.
1715 if (off_linktype
== (u_int
)-1)
1719 * Any type not handled above should always have an Ethernet
1720 * type at an offset of "off_linktype". (PPP is partially
1721 * handled above - the protocol type is mapped from the
1722 * Ethernet and LLC types we use internally to the corresponding
1723 * PPP type - but the PPP type is always specified by a value
1724 * at "off_linktype", so we don't have to do the code generation
1727 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1731 * Check for an LLC SNAP packet with a given organization code and
1732 * protocol type; we check the entire contents of the 802.2 LLC and
1733 * snap headers, checking for DSAP and SSAP of SNAP and a control
1734 * field of 0x03 in the LLC header, and for the specified organization
1735 * code and protocol type in the SNAP header.
1737 static struct block
*
1738 gen_snap(orgcode
, ptype
, offset
)
1739 bpf_u_int32 orgcode
;
1743 u_char snapblock
[8];
1745 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1746 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1747 snapblock
[2] = 0x03; /* control = UI */
1748 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1749 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1750 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1751 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1752 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1753 return gen_bcmp(offset
, 8, snapblock
);
1757 * Check for a given protocol value assuming an 802.2 LLC header.
1759 static struct block
*
1764 * XXX - handle token-ring variable-length header.
1769 return gen_cmp(off_linktype
, BPF_H
, (long)
1770 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1773 return gen_cmp(off_linktype
, BPF_H
, (long)
1774 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1776 case LLCSAP_NETBEUI
:
1777 return gen_cmp(off_linktype
, BPF_H
, (long)
1778 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1782 * XXX - are there ever SNAP frames for IPX on
1783 * non-Ethernet 802.x networks?
1785 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1787 case ETHERTYPE_ATALK
:
1789 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1790 * SNAP packets with an organization code of
1791 * 0x080007 (Apple, for Appletalk) and a protocol
1792 * type of ETHERTYPE_ATALK (Appletalk).
1794 * XXX - check for an organization code of
1795 * encapsulated Ethernet as well?
1797 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1801 * XXX - we don't have to check for IPX 802.3
1802 * here, but should we check for the IPX Ethertype?
1804 if (proto
<= ETHERMTU
) {
1806 * This is an LLC SAP value, so check
1809 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1812 * This is an Ethernet type; we assume that it's
1813 * unlikely that it'll appear in the right place
1814 * at random, and therefore check only the
1815 * location that would hold the Ethernet type
1816 * in a SNAP frame with an organization code of
1817 * 0x000000 (encapsulated Ethernet).
1819 * XXX - if we were to check for the SNAP DSAP and
1820 * LSAP, as per XXX, and were also to check for an
1821 * organization code of 0x000000 (encapsulated
1822 * Ethernet), we'd do
1824 * return gen_snap(0x000000, proto,
1827 * here; for now, we don't, as per the above.
1828 * I don't know whether it's worth the extra CPU
1829 * time to do the right check or not.
1831 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1836 static struct block
*
1837 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1841 u_int src_off
, dst_off
;
1843 struct block
*b0
, *b1
;
1857 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1858 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1864 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1865 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1872 b0
= gen_linktype(proto
);
1873 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1879 static struct block
*
1880 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1881 struct in6_addr
*addr
;
1882 struct in6_addr
*mask
;
1884 u_int src_off
, dst_off
;
1886 struct block
*b0
, *b1
;
1901 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1902 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1908 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1909 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1916 /* this order is important */
1917 a
= (u_int32_t
*)addr
;
1918 m
= (u_int32_t
*)mask
;
1919 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1920 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1922 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1924 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1926 b0
= gen_linktype(proto
);
1932 static struct block
*
1933 gen_ehostop(eaddr
, dir
)
1934 register const u_char
*eaddr
;
1937 register struct block
*b0
, *b1
;
1941 return gen_bcmp(off_mac
+ 6, 6, eaddr
);
1944 return gen_bcmp(off_mac
+ 0, 6, eaddr
);
1947 b0
= gen_ehostop(eaddr
, Q_SRC
);
1948 b1
= gen_ehostop(eaddr
, Q_DST
);
1954 b0
= gen_ehostop(eaddr
, Q_SRC
);
1955 b1
= gen_ehostop(eaddr
, Q_DST
);
1964 * Like gen_ehostop, but for DLT_FDDI
1966 static struct block
*
1967 gen_fhostop(eaddr
, dir
)
1968 register const u_char
*eaddr
;
1971 struct block
*b0
, *b1
;
1976 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
1978 return gen_bcmp(6 + 1, 6, eaddr
);
1983 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
1985 return gen_bcmp(0 + 1, 6, eaddr
);
1989 b0
= gen_fhostop(eaddr
, Q_SRC
);
1990 b1
= gen_fhostop(eaddr
, Q_DST
);
1996 b0
= gen_fhostop(eaddr
, Q_SRC
);
1997 b1
= gen_fhostop(eaddr
, Q_DST
);
2006 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
2008 static struct block
*
2009 gen_thostop(eaddr
, dir
)
2010 register const u_char
*eaddr
;
2013 register struct block
*b0
, *b1
;
2017 return gen_bcmp(8, 6, eaddr
);
2020 return gen_bcmp(2, 6, eaddr
);
2023 b0
= gen_thostop(eaddr
, Q_SRC
);
2024 b1
= gen_thostop(eaddr
, Q_DST
);
2030 b0
= gen_thostop(eaddr
, Q_SRC
);
2031 b1
= gen_thostop(eaddr
, Q_DST
);
2040 * Like gen_ehostop, but for DLT_IEEE802_11 (802.11 wireless LAN)
2042 static struct block
*
2043 gen_wlanhostop(eaddr
, dir
)
2044 register const u_char
*eaddr
;
2047 register struct block
*b0
, *b1
, *b2
;
2048 register struct slist
*s
;
2055 * For control frames, there is no SA.
2057 * For management frames, SA is at an
2058 * offset of 10 from the beginning of
2061 * For data frames, SA is at an offset
2062 * of 10 from the beginning of the packet
2063 * if From DS is clear, at an offset of
2064 * 16 from the beginning of the packet
2065 * if From DS is set and To DS is clear,
2066 * and an offset of 24 from the beginning
2067 * of the packet if From DS is set and To DS
2072 * Generate the tests to be done for data frames
2075 * First, check for To DS set, i.e. check "link[1] & 0x01".
2077 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2079 b1
= new_block(JMP(BPF_JSET
));
2080 b1
->s
.k
= 0x01; /* To DS */
2084 * If To DS is set, the SA is at 24.
2086 b0
= gen_bcmp(24, 6, eaddr
);
2090 * Now, check for To DS not set, i.e. check
2091 * "!(link[1] & 0x01)".
2093 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2095 b2
= new_block(JMP(BPF_JSET
));
2096 b2
->s
.k
= 0x01; /* To DS */
2101 * If To DS is not set, the SA is at 16.
2103 b1
= gen_bcmp(16, 6, eaddr
);
2107 * Now OR together the last two checks. That gives
2108 * the complete set of checks for data frames with
2114 * Now check for From DS being set, and AND that with
2115 * the ORed-together checks.
2117 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2119 b1
= new_block(JMP(BPF_JSET
));
2120 b1
->s
.k
= 0x02; /* From DS */
2125 * Now check for data frames with From DS not set.
2127 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2129 b2
= new_block(JMP(BPF_JSET
));
2130 b2
->s
.k
= 0x02; /* From DS */
2135 * If From DS isn't set, the SA is at 10.
2137 b1
= gen_bcmp(10, 6, eaddr
);
2141 * Now OR together the checks for data frames with
2142 * From DS not set and for data frames with From DS
2143 * set; that gives the checks done for data frames.
2148 * Now check for a data frame.
2149 * I.e, check "link[0] & 0x08".
2151 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2153 b1
= new_block(JMP(BPF_JSET
));
2158 * AND that with the checks done for data frames.
2163 * If the high-order bit of the type value is 0, this
2164 * is a management frame.
2165 * I.e, check "!(link[0] & 0x08)".
2167 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2169 b2
= new_block(JMP(BPF_JSET
));
2175 * For management frames, the SA is at 10.
2177 b1
= gen_bcmp(10, 6, eaddr
);
2181 * OR that with the checks done for data frames.
2182 * That gives the checks done for management and
2188 * If the low-order bit of the type value is 1,
2189 * this is either a control frame or a frame
2190 * with a reserved type, and thus not a
2193 * I.e., check "!(link[0] & 0x04)".
2195 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2197 b1
= new_block(JMP(BPF_JSET
));
2203 * AND that with the checks for data and management
2213 * For control frames, there is no DA.
2215 * For management frames, DA is at an
2216 * offset of 4 from the beginning of
2219 * For data frames, DA is at an offset
2220 * of 4 from the beginning of the packet
2221 * if To DS is clear and at an offset of
2222 * 16 from the beginning of the packet
2227 * Generate the tests to be done for data frames.
2229 * First, check for To DS set, i.e. "link[1] & 0x01".
2231 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2233 b1
= new_block(JMP(BPF_JSET
));
2234 b1
->s
.k
= 0x01; /* To DS */
2238 * If To DS is set, the DA is at 16.
2240 b0
= gen_bcmp(16, 6, eaddr
);
2244 * Now, check for To DS not set, i.e. check
2245 * "!(link[1] & 0x01)".
2247 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2249 b2
= new_block(JMP(BPF_JSET
));
2250 b2
->s
.k
= 0x01; /* To DS */
2255 * If To DS is not set, the DA is at 4.
2257 b1
= gen_bcmp(4, 6, eaddr
);
2261 * Now OR together the last two checks. That gives
2262 * the complete set of checks for data frames.
2267 * Now check for a data frame.
2268 * I.e, check "link[0] & 0x08".
2270 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2272 b1
= new_block(JMP(BPF_JSET
));
2277 * AND that with the checks done for data frames.
2282 * If the high-order bit of the type value is 0, this
2283 * is a management frame.
2284 * I.e, check "!(link[0] & 0x08)".
2286 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2288 b2
= new_block(JMP(BPF_JSET
));
2294 * For management frames, the DA is at 4.
2296 b1
= gen_bcmp(4, 6, eaddr
);
2300 * OR that with the checks done for data frames.
2301 * That gives the checks done for management and
2307 * If the low-order bit of the type value is 1,
2308 * this is either a control frame or a frame
2309 * with a reserved type, and thus not a
2312 * I.e., check "!(link[0] & 0x04)".
2314 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2316 b1
= new_block(JMP(BPF_JSET
));
2322 * AND that with the checks for data and management
2329 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2330 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2336 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2337 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2346 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
2347 * (We assume that the addresses are IEEE 48-bit MAC addresses,
2348 * as the RFC states.)
2350 static struct block
*
2351 gen_ipfchostop(eaddr
, dir
)
2352 register const u_char
*eaddr
;
2355 register struct block
*b0
, *b1
;
2359 return gen_bcmp(10, 6, eaddr
);
2362 return gen_bcmp(2, 6, eaddr
);
2365 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2366 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2372 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2373 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2382 * This is quite tricky because there may be pad bytes in front of the
2383 * DECNET header, and then there are two possible data packet formats that
2384 * carry both src and dst addresses, plus 5 packet types in a format that
2385 * carries only the src node, plus 2 types that use a different format and
2386 * also carry just the src node.
2390 * Instead of doing those all right, we just look for data packets with
2391 * 0 or 1 bytes of padding. If you want to look at other packets, that
2392 * will require a lot more hacking.
2394 * To add support for filtering on DECNET "areas" (network numbers)
2395 * one would want to add a "mask" argument to this routine. That would
2396 * make the filter even more inefficient, although one could be clever
2397 * and not generate masking instructions if the mask is 0xFFFF.
2399 static struct block
*
2400 gen_dnhostop(addr
, dir
, base_off
)
2405 struct block
*b0
, *b1
, *b2
, *tmp
;
2406 u_int offset_lh
; /* offset if long header is received */
2407 u_int offset_sh
; /* offset if short header is received */
2412 offset_sh
= 1; /* follows flags */
2413 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
2417 offset_sh
= 3; /* follows flags, dstnode */
2418 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
2422 /* Inefficient because we do our Calvinball dance twice */
2423 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2424 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2430 /* Inefficient because we do our Calvinball dance twice */
2431 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2432 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2437 bpf_error("ISO host filtering not implemented");
2442 b0
= gen_linktype(ETHERTYPE_DN
);
2443 /* Check for pad = 1, long header case */
2444 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2445 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
2446 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
2447 BPF_H
, (bpf_int32
)ntohs(addr
));
2449 /* Check for pad = 0, long header case */
2450 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
2451 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2454 /* Check for pad = 1, short header case */
2455 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2456 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
2457 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
2458 BPF_H
, (bpf_int32
)ntohs(addr
));
2461 /* Check for pad = 0, short header case */
2462 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
2463 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2467 /* Combine with test for linktype */
2472 static struct block
*
2473 gen_host(addr
, mask
, proto
, dir
)
2479 struct block
*b0
, *b1
;
2484 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
2485 if (off_linktype
!= (u_int
)-1) {
2486 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
2488 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
2494 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
2495 off_nl
+ 12, off_nl
+ 16);
2498 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2499 off_nl
+ 14, off_nl
+ 24);
2502 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2503 off_nl
+ 14, off_nl
+ 24);
2506 bpf_error("'tcp' modifier applied to host");
2509 bpf_error("'sctp' modifier applied to host");
2512 bpf_error("'udp' modifier applied to host");
2515 bpf_error("'icmp' modifier applied to host");
2518 bpf_error("'igmp' modifier applied to host");
2521 bpf_error("'igrp' modifier applied to host");
2524 bpf_error("'pim' modifier applied to host");
2527 bpf_error("'vrrp' modifier applied to host");
2530 bpf_error("ATALK host filtering not implemented");
2533 bpf_error("AARP host filtering not implemented");
2536 return gen_dnhostop(addr
, dir
, off_nl
);
2539 bpf_error("SCA host filtering not implemented");
2542 bpf_error("LAT host filtering not implemented");
2545 bpf_error("MOPDL host filtering not implemented");
2548 bpf_error("MOPRC host filtering not implemented");
2552 bpf_error("'ip6' modifier applied to ip host");
2555 bpf_error("'icmp6' modifier applied to host");
2559 bpf_error("'ah' modifier applied to host");
2562 bpf_error("'esp' modifier applied to host");
2565 bpf_error("ISO host filtering not implemented");
2568 bpf_error("'esis' modifier applied to host");
2571 bpf_error("'isis' modifier applied to host");
2574 bpf_error("'clnp' modifier applied to host");
2577 bpf_error("'stp' modifier applied to host");
2580 bpf_error("IPX host filtering not implemented");
2583 bpf_error("'netbeui' modifier applied to host");
2592 static struct block
*
2593 gen_host6(addr
, mask
, proto
, dir
)
2594 struct in6_addr
*addr
;
2595 struct in6_addr
*mask
;
2602 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2605 bpf_error("'ip' modifier applied to ip6 host");
2608 bpf_error("'rarp' modifier applied to ip6 host");
2611 bpf_error("'arp' modifier applied to ip6 host");
2614 bpf_error("'sctp' modifier applied to host");
2617 bpf_error("'tcp' modifier applied to host");
2620 bpf_error("'udp' modifier applied to host");
2623 bpf_error("'icmp' modifier applied to host");
2626 bpf_error("'igmp' modifier applied to host");
2629 bpf_error("'igrp' modifier applied to host");
2632 bpf_error("'pim' modifier applied to host");
2635 bpf_error("'vrrp' modifier applied to host");
2638 bpf_error("ATALK host filtering not implemented");
2641 bpf_error("AARP host filtering not implemented");
2644 bpf_error("'decnet' modifier applied to ip6 host");
2647 bpf_error("SCA host filtering not implemented");
2650 bpf_error("LAT host filtering not implemented");
2653 bpf_error("MOPDL host filtering not implemented");
2656 bpf_error("MOPRC host filtering not implemented");
2659 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2660 off_nl
+ 8, off_nl
+ 24);
2663 bpf_error("'icmp6' modifier applied to host");
2666 bpf_error("'ah' modifier applied to host");
2669 bpf_error("'esp' modifier applied to host");
2672 bpf_error("ISO host filtering not implemented");
2675 bpf_error("'esis' modifier applied to host");
2678 bpf_error("'isis' modifier applied to host");
2681 bpf_error("'clnp' modifier applied to host");
2684 bpf_error("'stp' modifier applied to host");
2687 bpf_error("IPX host filtering not implemented");
2690 bpf_error("'netbeui' modifier applied to host");
2700 static struct block
*
2701 gen_gateway(eaddr
, alist
, proto
, dir
)
2702 const u_char
*eaddr
;
2703 bpf_u_int32
**alist
;
2707 struct block
*b0
, *b1
, *tmp
;
2710 bpf_error("direction applied to 'gateway'");
2717 if (linktype
== DLT_EN10MB
)
2718 b0
= gen_ehostop(eaddr
, Q_OR
);
2719 else if (linktype
== DLT_FDDI
)
2720 b0
= gen_fhostop(eaddr
, Q_OR
);
2721 else if (linktype
== DLT_IEEE802
)
2722 b0
= gen_thostop(eaddr
, Q_OR
);
2723 else if (linktype
== DLT_IEEE802_11
)
2724 b0
= gen_wlanhostop(eaddr
, Q_OR
);
2725 else if (linktype
== DLT_SUNATM
&& is_lane
) {
2727 * Check that the packet doesn't begin with an
2728 * LE Control marker. (We've already generated
2731 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
2735 * Now check the MAC address.
2737 b0
= gen_ehostop(eaddr
, Q_OR
);
2739 } else if (linktype
== DLT_IP_OVER_FC
)
2740 b0
= gen_ipfchostop(eaddr
, Q_OR
);
2743 "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel");
2745 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2747 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2755 bpf_error("illegal modifier of 'gateway'");
2761 gen_proto_abbrev(proto
)
2770 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2772 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2778 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2780 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2786 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2788 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2794 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2797 #ifndef IPPROTO_IGMP
2798 #define IPPROTO_IGMP 2
2802 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2805 #ifndef IPPROTO_IGRP
2806 #define IPPROTO_IGRP 9
2809 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2813 #define IPPROTO_PIM 103
2817 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2819 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2824 #ifndef IPPROTO_VRRP
2825 #define IPPROTO_VRRP 112
2829 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2833 b1
= gen_linktype(ETHERTYPE_IP
);
2837 b1
= gen_linktype(ETHERTYPE_ARP
);
2841 b1
= gen_linktype(ETHERTYPE_REVARP
);
2845 bpf_error("link layer applied in wrong context");
2848 b1
= gen_linktype(ETHERTYPE_ATALK
);
2852 b1
= gen_linktype(ETHERTYPE_AARP
);
2856 b1
= gen_linktype(ETHERTYPE_DN
);
2860 b1
= gen_linktype(ETHERTYPE_SCA
);
2864 b1
= gen_linktype(ETHERTYPE_LAT
);
2868 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2872 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2877 b1
= gen_linktype(ETHERTYPE_IPV6
);
2880 #ifndef IPPROTO_ICMPV6
2881 #define IPPROTO_ICMPV6 58
2884 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2889 #define IPPROTO_AH 51
2892 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2894 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2900 #define IPPROTO_ESP 50
2903 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2905 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2911 b1
= gen_linktype(LLCSAP_ISONS
);
2915 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2919 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2922 case Q_ISIS_L1
: /* all IS-IS Level1 PDU-Types */
2923 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2924 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2926 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2928 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2930 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2934 case Q_ISIS_L2
: /* all IS-IS Level2 PDU-Types */
2935 b0
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2936 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2938 b0
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2940 b0
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2942 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2946 case Q_ISIS_IIH
: /* all IS-IS Hello PDU-Types */
2947 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2948 b1
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2950 b0
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
);
2955 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2956 b1
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2961 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2962 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2964 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2966 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2971 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2972 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2977 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2978 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2983 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
2987 b1
= gen_linktype(LLCSAP_8021D
);
2991 b1
= gen_linktype(LLCSAP_IPX
);
2995 b1
= gen_linktype(LLCSAP_NETBEUI
);
3004 static struct block
*
3011 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
3012 s
->s
.k
= off_nl
+ 6;
3013 b
= new_block(JMP(BPF_JSET
));
3021 static struct block
*
3022 gen_portatom(off
, v
)
3029 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3032 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
3033 s
->next
->s
.k
= off_nl
+ off
;
3035 b
= new_block(JMP(BPF_JEQ
));
3043 static struct block
*
3044 gen_portatom6(off
, v
)
3048 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
3053 gen_portop(port
, proto
, dir
)
3054 int port
, proto
, dir
;
3056 struct block
*b0
, *b1
, *tmp
;
3058 /* ip proto 'proto' */
3059 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
3065 b1
= gen_portatom(0, (bpf_int32
)port
);
3069 b1
= gen_portatom(2, (bpf_int32
)port
);
3074 tmp
= gen_portatom(0, (bpf_int32
)port
);
3075 b1
= gen_portatom(2, (bpf_int32
)port
);
3080 tmp
= gen_portatom(0, (bpf_int32
)port
);
3081 b1
= gen_portatom(2, (bpf_int32
)port
);
3093 static struct block
*
3094 gen_port(port
, ip_proto
, dir
)
3099 struct block
*b0
, *b1
, *tmp
;
3104 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3105 * not LLC encapsulation with LLCSAP_IP.
3107 * For IEEE 802 networks - which includes 802.5 token ring
3108 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3109 * says that SNAP encapsulation is used, not LLC encapsulation
3112 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3113 * RFC 2225 say that SNAP encapsulation is used, not LLC
3114 * encapsulation with LLCSAP_IP.
3116 * So we always check for ETHERTYPE_IP.
3118 b0
= gen_linktype(ETHERTYPE_IP
);
3124 b1
= gen_portop(port
, ip_proto
, dir
);
3128 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
3129 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
3131 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
3144 gen_portop6(port
, proto
, dir
)
3145 int port
, proto
, dir
;
3147 struct block
*b0
, *b1
, *tmp
;
3149 /* ip proto 'proto' */
3150 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
3154 b1
= gen_portatom6(0, (bpf_int32
)port
);
3158 b1
= gen_portatom6(2, (bpf_int32
)port
);
3163 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3164 b1
= gen_portatom6(2, (bpf_int32
)port
);
3169 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3170 b1
= gen_portatom6(2, (bpf_int32
)port
);
3182 static struct block
*
3183 gen_port6(port
, ip_proto
, dir
)
3188 struct block
*b0
, *b1
, *tmp
;
3190 /* ether proto ip */
3191 b0
= gen_linktype(ETHERTYPE_IPV6
);
3197 b1
= gen_portop6(port
, ip_proto
, dir
);
3201 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
3202 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
3204 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
3217 lookup_proto(name
, proto
)
3218 register const char *name
;
3228 v
= pcap_nametoproto(name
);
3229 if (v
== PROTO_UNDEF
)
3230 bpf_error("unknown ip proto '%s'", name
);
3234 /* XXX should look up h/w protocol type based on linktype */
3235 v
= pcap_nametoeproto(name
);
3236 if (v
== PROTO_UNDEF
)
3237 bpf_error("unknown ether proto '%s'", name
);
3241 if (strcmp(name
, "esis") == 0)
3243 else if (strcmp(name
, "isis") == 0)
3245 else if (strcmp(name
, "clnp") == 0)
3248 bpf_error("unknown osi proto '%s'", name
);
3268 static struct block
*
3269 gen_protochain(v
, proto
, dir
)
3274 #ifdef NO_PROTOCHAIN
3275 return gen_proto(v
, proto
, dir
);
3277 struct block
*b0
, *b
;
3278 struct slist
*s
[100];
3279 int fix2
, fix3
, fix4
, fix5
;
3280 int ahcheck
, again
, end
;
3282 int reg2
= alloc_reg();
3284 memset(s
, 0, sizeof(s
));
3285 fix2
= fix3
= fix4
= fix5
= 0;
3292 b0
= gen_protochain(v
, Q_IP
, dir
);
3293 b
= gen_protochain(v
, Q_IPV6
, dir
);
3297 bpf_error("bad protocol applied for 'protochain'");
3301 no_optimize
= 1; /*this code is not compatible with optimzer yet */
3304 * s[0] is a dummy entry to protect other BPF insn from damaged
3305 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
3306 * hard to find interdependency made by jump table fixup.
3309 s
[i
] = new_stmt(0); /*dummy*/
3314 b0
= gen_linktype(ETHERTYPE_IP
);
3317 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3318 s
[i
]->s
.k
= off_nl
+ 9;
3320 /* X = ip->ip_hl << 2 */
3321 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3327 b0
= gen_linktype(ETHERTYPE_IPV6
);
3329 /* A = ip6->ip_nxt */
3330 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3331 s
[i
]->s
.k
= off_nl
+ 6;
3333 /* X = sizeof(struct ip6_hdr) */
3334 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
3340 bpf_error("unsupported proto to gen_protochain");
3344 /* again: if (A == v) goto end; else fall through; */
3346 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3348 s
[i
]->s
.jt
= NULL
; /*later*/
3349 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3353 #ifndef IPPROTO_NONE
3354 #define IPPROTO_NONE 59
3356 /* if (A == IPPROTO_NONE) goto end */
3357 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3358 s
[i
]->s
.jt
= NULL
; /*later*/
3359 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3360 s
[i
]->s
.k
= IPPROTO_NONE
;
3361 s
[fix5
]->s
.jf
= s
[i
];
3366 if (proto
== Q_IPV6
) {
3367 int v6start
, v6end
, v6advance
, j
;
3370 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
3371 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3372 s
[i
]->s
.jt
= NULL
; /*later*/
3373 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3374 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
3375 s
[fix2
]->s
.jf
= s
[i
];
3377 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
3378 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3379 s
[i
]->s
.jt
= NULL
; /*later*/
3380 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3381 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
3383 /* if (A == IPPROTO_ROUTING) goto v6advance */
3384 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3385 s
[i
]->s
.jt
= NULL
; /*later*/
3386 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3387 s
[i
]->s
.k
= IPPROTO_ROUTING
;
3389 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
3390 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3391 s
[i
]->s
.jt
= NULL
; /*later*/
3392 s
[i
]->s
.jf
= NULL
; /*later*/
3393 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
3404 * X = X + (P[X + 1] + 1) * 8;
3407 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3409 /* A = P[X + packet head] */
3410 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3414 s
[i
] = new_stmt(BPF_ST
);
3418 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3421 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3425 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3427 /* A = P[X + packet head]; */
3428 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3432 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3436 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3440 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3443 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3447 /* goto again; (must use BPF_JA for backward jump) */
3448 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3449 s
[i
]->s
.k
= again
- i
- 1;
3450 s
[i
- 1]->s
.jf
= s
[i
];
3454 for (j
= v6start
; j
<= v6end
; j
++)
3455 s
[j
]->s
.jt
= s
[v6advance
];
3460 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3462 s
[fix2
]->s
.jf
= s
[i
];
3468 /* if (A == IPPROTO_AH) then fall through; else goto end; */
3469 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3470 s
[i
]->s
.jt
= NULL
; /*later*/
3471 s
[i
]->s
.jf
= NULL
; /*later*/
3472 s
[i
]->s
.k
= IPPROTO_AH
;
3474 s
[fix3
]->s
.jf
= s
[ahcheck
];
3481 * X = X + (P[X + 1] + 2) * 4;
3484 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3486 /* A = P[X + packet head]; */
3487 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3491 s
[i
] = new_stmt(BPF_ST
);
3495 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3498 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3502 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3504 /* A = P[X + packet head] */
3505 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3509 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3513 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3517 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3520 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3524 /* goto again; (must use BPF_JA for backward jump) */
3525 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3526 s
[i
]->s
.k
= again
- i
- 1;
3531 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3533 s
[fix2
]->s
.jt
= s
[end
];
3534 s
[fix4
]->s
.jf
= s
[end
];
3535 s
[fix5
]->s
.jt
= s
[end
];
3542 for (i
= 0; i
< max
- 1; i
++)
3543 s
[i
]->next
= s
[i
+ 1];
3544 s
[max
- 1]->next
= NULL
;
3549 b
= new_block(JMP(BPF_JEQ
));
3550 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
3560 static struct block
*
3561 gen_proto(v
, proto
, dir
)
3566 struct block
*b0
, *b1
;
3568 if (dir
!= Q_DEFAULT
)
3569 bpf_error("direction applied to 'proto'");
3574 b0
= gen_proto(v
, Q_IP
, dir
);
3575 b1
= gen_proto(v
, Q_IPV6
, dir
);
3583 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3584 * not LLC encapsulation with LLCSAP_IP.
3586 * For IEEE 802 networks - which includes 802.5 token ring
3587 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3588 * says that SNAP encapsulation is used, not LLC encapsulation
3591 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3592 * RFC 2225 say that SNAP encapsulation is used, not LLC
3593 * encapsulation with LLCSAP_IP.
3595 * So we always check for ETHERTYPE_IP.
3597 b0
= gen_linktype(ETHERTYPE_IP
);
3599 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
3601 b1
= gen_protochain(v
, Q_IP
);
3611 * Frame Relay packets typically have an OSI
3612 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3613 * generates code to check for all the OSI
3614 * NLPIDs, so calling it and then adding a check
3615 * for the particular NLPID for which we're
3616 * looking is bogus, as we can just check for
3619 * What we check for is the NLPID and a frame
3620 * control field value of UI, i.e. 0x03 followed
3623 * XXX - assumes a 2-byte Frame Relay header with
3624 * DLCI and flags. What if the address is longer?
3626 * XXX - what about SNAP-encapsulated frames?
3628 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3633 * Cisco uses an Ethertype lookalike - for OSI,
3636 b0
= gen_linktype(LLCSAP_ISONS
<<8 | LLCSAP_ISONS
);
3637 /* OSI in C-HDLC is stuffed with a fudge byte */
3638 b1
= gen_cmp(off_nl_nosnap
+1, BPF_B
, (long)v
);
3643 b0
= gen_linktype(LLCSAP_ISONS
);
3644 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3650 b0
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
3652 * 4 is the offset of the PDU type relative to the IS-IS
3655 b1
= gen_cmp(off_nl_nosnap
+4, BPF_B
, (long)v
);
3660 bpf_error("arp does not encapsulate another protocol");
3664 bpf_error("rarp does not encapsulate another protocol");
3668 bpf_error("atalk encapsulation is not specifiable");
3672 bpf_error("decnet encapsulation is not specifiable");
3676 bpf_error("sca does not encapsulate another protocol");
3680 bpf_error("lat does not encapsulate another protocol");
3684 bpf_error("moprc does not encapsulate another protocol");
3688 bpf_error("mopdl does not encapsulate another protocol");
3692 return gen_linktype(v
);
3695 bpf_error("'udp proto' is bogus");
3699 bpf_error("'tcp proto' is bogus");
3703 bpf_error("'sctp proto' is bogus");
3707 bpf_error("'icmp proto' is bogus");
3711 bpf_error("'igmp proto' is bogus");
3715 bpf_error("'igrp proto' is bogus");
3719 bpf_error("'pim proto' is bogus");
3723 bpf_error("'vrrp proto' is bogus");
3728 b0
= gen_linktype(ETHERTYPE_IPV6
);
3730 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3732 b1
= gen_protochain(v
, Q_IPV6
);
3738 bpf_error("'icmp6 proto' is bogus");
3742 bpf_error("'ah proto' is bogus");
3745 bpf_error("'ah proto' is bogus");
3748 bpf_error("'stp proto' is bogus");
3751 bpf_error("'ipx proto' is bogus");
3754 bpf_error("'netbeui proto' is bogus");
3765 register const char *name
;
3768 int proto
= q
.proto
;
3772 bpf_u_int32 mask
, addr
;
3774 bpf_u_int32
**alist
;
3777 struct sockaddr_in
*sin
;
3778 struct sockaddr_in6
*sin6
;
3779 struct addrinfo
*res
, *res0
;
3780 struct in6_addr mask128
;
3782 struct block
*b
, *tmp
;
3783 int port
, real_proto
;
3788 addr
= pcap_nametonetaddr(name
);
3790 bpf_error("unknown network '%s'", name
);
3791 /* Left justify network addr and calculate its network mask */
3793 while (addr
&& (addr
& 0xff000000) == 0) {
3797 return gen_host(addr
, mask
, proto
, dir
);
3801 if (proto
== Q_LINK
) {
3805 eaddr
= pcap_ether_hostton(name
);
3808 "unknown ether host '%s'", name
);
3809 b
= gen_ehostop(eaddr
, dir
);
3814 eaddr
= pcap_ether_hostton(name
);
3817 "unknown FDDI host '%s'", name
);
3818 b
= gen_fhostop(eaddr
, dir
);
3823 eaddr
= pcap_ether_hostton(name
);
3826 "unknown token ring host '%s'", name
);
3827 b
= gen_thostop(eaddr
, dir
);
3831 case DLT_IEEE802_11
:
3832 eaddr
= pcap_ether_hostton(name
);
3835 "unknown 802.11 host '%s'", name
);
3836 b
= gen_wlanhostop(eaddr
, dir
);
3840 case DLT_IP_OVER_FC
:
3841 eaddr
= pcap_ether_hostton(name
);
3844 "unknown Fibre Channel host '%s'", name
);
3845 b
= gen_ipfchostop(eaddr
, dir
);
3854 * Check that the packet doesn't begin
3855 * with an LE Control marker. (We've
3856 * already generated a test for LANE.)
3858 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
,
3862 eaddr
= pcap_ether_hostton(name
);
3865 "unknown ether host '%s'", name
);
3866 b
= gen_ehostop(eaddr
, dir
);
3872 bpf_error("only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
3873 } else if (proto
== Q_DECNET
) {
3874 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3876 * I don't think DECNET hosts can be multihomed, so
3877 * there is no need to build up a list of addresses
3879 return (gen_host(dn_addr
, 0, proto
, dir
));
3882 alist
= pcap_nametoaddr(name
);
3883 if (alist
== NULL
|| *alist
== NULL
)
3884 bpf_error("unknown host '%s'", name
);
3886 if (off_linktype
== (u_int
)-1 && tproto
== Q_DEFAULT
)
3888 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3890 tmp
= gen_host(**alist
++, 0xffffffff,
3897 memset(&mask128
, 0xff, sizeof(mask128
));
3898 res0
= res
= pcap_nametoaddrinfo(name
);
3900 bpf_error("unknown host '%s'", name
);
3902 tproto
= tproto6
= proto
;
3903 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3907 for (res
= res0
; res
; res
= res
->ai_next
) {
3908 switch (res
->ai_family
) {
3910 if (tproto
== Q_IPV6
)
3913 sin
= (struct sockaddr_in
*)
3915 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3916 0xffffffff, tproto
, dir
);
3919 if (tproto6
== Q_IP
)
3922 sin6
= (struct sockaddr_in6
*)
3924 tmp
= gen_host6(&sin6
->sin6_addr
,
3925 &mask128
, tproto6
, dir
);
3936 bpf_error("unknown host '%s'%s", name
,
3937 (proto
== Q_DEFAULT
)
3939 : " for specified address family");
3946 if (proto
!= Q_DEFAULT
&&
3947 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3948 bpf_error("illegal qualifier of 'port'");
3949 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3950 bpf_error("unknown port '%s'", name
);
3951 if (proto
== Q_UDP
) {
3952 if (real_proto
== IPPROTO_TCP
)
3953 bpf_error("port '%s' is tcp", name
);
3954 else if (real_proto
== IPPROTO_SCTP
)
3955 bpf_error("port '%s' is sctp", name
);
3957 /* override PROTO_UNDEF */
3958 real_proto
= IPPROTO_UDP
;
3960 if (proto
== Q_TCP
) {
3961 if (real_proto
== IPPROTO_UDP
)
3962 bpf_error("port '%s' is udp", name
);
3964 else if (real_proto
== IPPROTO_SCTP
)
3965 bpf_error("port '%s' is sctp", name
);
3967 /* override PROTO_UNDEF */
3968 real_proto
= IPPROTO_TCP
;
3970 if (proto
== Q_SCTP
) {
3971 if (real_proto
== IPPROTO_UDP
)
3972 bpf_error("port '%s' is udp", name
);
3974 else if (real_proto
== IPPROTO_TCP
)
3975 bpf_error("port '%s' is tcp", name
);
3977 /* override PROTO_UNDEF */
3978 real_proto
= IPPROTO_SCTP
;
3981 return gen_port(port
, real_proto
, dir
);
3985 b
= gen_port(port
, real_proto
, dir
);
3986 gen_or(gen_port6(port
, real_proto
, dir
), b
);
3993 eaddr
= pcap_ether_hostton(name
);
3995 bpf_error("unknown ether host: %s", name
);
3997 alist
= pcap_nametoaddr(name
);
3998 if (alist
== NULL
|| *alist
== NULL
)
3999 bpf_error("unknown host '%s'", name
);
4000 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
4004 bpf_error("'gateway' not supported in this configuration");
4008 real_proto
= lookup_proto(name
, proto
);
4009 if (real_proto
>= 0)
4010 return gen_proto(real_proto
, proto
, dir
);
4012 bpf_error("unknown protocol: %s", name
);
4015 real_proto
= lookup_proto(name
, proto
);
4016 if (real_proto
>= 0)
4017 return gen_protochain(real_proto
, proto
, dir
);
4019 bpf_error("unknown protocol: %s", name
);
4031 gen_mcode(s1
, s2
, masklen
, q
)
4032 register const char *s1
, *s2
;
4033 register int masklen
;
4036 register int nlen
, mlen
;
4039 nlen
= __pcap_atoin(s1
, &n
);
4040 /* Promote short ipaddr */
4044 mlen
= __pcap_atoin(s2
, &m
);
4045 /* Promote short ipaddr */
4048 bpf_error("non-network bits set in \"%s mask %s\"",
4051 /* Convert mask len to mask */
4053 bpf_error("mask length must be <= 32");
4054 m
= 0xffffffff << (32 - masklen
);
4056 bpf_error("non-network bits set in \"%s/%d\"",
4063 return gen_host(n
, m
, q
.proto
, q
.dir
);
4066 bpf_error("Mask syntax for networks only");
4073 register const char *s
;
4078 int proto
= q
.proto
;
4084 else if (q
.proto
== Q_DECNET
)
4085 vlen
= __pcap_atodn(s
, &v
);
4087 vlen
= __pcap_atoin(s
, &v
);
4094 if (proto
== Q_DECNET
)
4095 return gen_host(v
, 0, proto
, dir
);
4096 else if (proto
== Q_LINK
) {
4097 bpf_error("illegal link layer address");
4100 if (s
== NULL
&& q
.addr
== Q_NET
) {
4101 /* Promote short net number */
4102 while (v
&& (v
& 0xff000000) == 0) {
4107 /* Promote short ipaddr */
4111 return gen_host(v
, mask
, proto
, dir
);
4116 proto
= IPPROTO_UDP
;
4117 else if (proto
== Q_TCP
)
4118 proto
= IPPROTO_TCP
;
4119 else if (proto
== Q_SCTP
)
4120 proto
= IPPROTO_SCTP
;
4121 else if (proto
== Q_DEFAULT
)
4122 proto
= PROTO_UNDEF
;
4124 bpf_error("illegal qualifier of 'port'");
4127 return gen_port((int)v
, proto
, dir
);
4131 b
= gen_port((int)v
, proto
, dir
);
4132 gen_or(gen_port6((int)v
, proto
, dir
), b
);
4138 bpf_error("'gateway' requires a name");
4142 return gen_proto((int)v
, proto
, dir
);
4145 return gen_protochain((int)v
, proto
, dir
);
4160 gen_mcode6(s1
, s2
, masklen
, q
)
4161 register const char *s1
, *s2
;
4162 register int masklen
;
4165 struct addrinfo
*res
;
4166 struct in6_addr
*addr
;
4167 struct in6_addr mask
;
4172 bpf_error("no mask %s supported", s2
);
4174 res
= pcap_nametoaddrinfo(s1
);
4176 bpf_error("invalid ip6 address %s", s1
);
4178 bpf_error("%s resolved to multiple address", s1
);
4179 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
4181 if (sizeof(mask
) * 8 < masklen
)
4182 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
4183 memset(&mask
, 0, sizeof(mask
));
4184 memset(&mask
, 0xff, masklen
/ 8);
4186 mask
.s6_addr
[masklen
/ 8] =
4187 (0xff << (8 - masklen
% 8)) & 0xff;
4190 a
= (u_int32_t
*)addr
;
4191 m
= (u_int32_t
*)&mask
;
4192 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
4193 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
4194 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
4202 bpf_error("Mask syntax for networks only");
4206 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
4211 bpf_error("invalid qualifier against IPv6 address");
4219 register const u_char
*eaddr
;
4222 struct block
*b
, *tmp
;
4224 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4225 if (linktype
== DLT_EN10MB
)
4226 return gen_ehostop(eaddr
, (int)q
.dir
);
4227 if (linktype
== DLT_FDDI
)
4228 return gen_fhostop(eaddr
, (int)q
.dir
);
4229 if (linktype
== DLT_IEEE802
)
4230 return gen_thostop(eaddr
, (int)q
.dir
);
4231 if (linktype
== DLT_IEEE802_11
)
4232 return gen_wlanhostop(eaddr
, (int)q
.dir
);
4233 if (linktype
== DLT_SUNATM
&& is_lane
) {
4235 * Check that the packet doesn't begin with an
4236 * LE Control marker. (We've already generated
4239 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4243 * Now check the MAC address.
4245 b
= gen_ehostop(eaddr
, (int)q
.dir
);
4249 if (linktype
== DLT_IP_OVER_FC
)
4250 return gen_ipfchostop(eaddr
, (int)q
.dir
);
4251 bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
4253 bpf_error("ethernet address used in non-ether expression");
4259 struct slist
*s0
, *s1
;
4262 * This is definitely not the best way to do this, but the
4263 * lists will rarely get long.
4270 static struct slist
*
4276 s
= new_stmt(BPF_LDX
|BPF_MEM
);
4281 static struct slist
*
4287 s
= new_stmt(BPF_LD
|BPF_MEM
);
4293 gen_load(proto
, index
, size
)
4298 struct slist
*s
, *tmp
;
4300 int regno
= alloc_reg();
4302 free_reg(index
->regno
);
4306 bpf_error("data size must be 1, 2, or 4");
4322 bpf_error("unsupported index operation");
4326 * XXX - what about ATM LANE? Should the index be
4327 * relative to the beginning of the AAL5 frame, so
4328 * that 0 refers to the beginning of the LE Control
4329 * field, or relative to the beginning of the LAN
4330 * frame, so that 0 refers, for Ethernet LANE, to
4331 * the beginning of the destination address?
4333 s
= xfer_to_x(index
);
4334 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4336 sappend(index
->s
, s
);
4351 /* XXX Note that we assume a fixed link header here. */
4352 s
= xfer_to_x(index
);
4353 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4356 sappend(index
->s
, s
);
4358 b
= gen_proto_abbrev(proto
);
4360 gen_and(index
->b
, b
);
4372 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
4374 sappend(s
, xfer_to_a(index
));
4375 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
4376 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
4377 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
4379 sappend(index
->s
, s
);
4381 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
4383 gen_and(index
->b
, b
);
4385 gen_and(gen_proto_abbrev(Q_IP
), b
);
4391 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
4395 index
->regno
= regno
;
4396 s
= new_stmt(BPF_ST
);
4398 sappend(index
->s
, s
);
4404 gen_relation(code
, a0
, a1
, reversed
)
4406 struct arth
*a0
, *a1
;
4409 struct slist
*s0
, *s1
, *s2
;
4410 struct block
*b
, *tmp
;
4414 if (code
== BPF_JEQ
) {
4415 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
4416 b
= new_block(JMP(code
));
4420 b
= new_block(BPF_JMP
|code
|BPF_X
);
4426 sappend(a0
->s
, a1
->s
);
4430 free_reg(a0
->regno
);
4431 free_reg(a1
->regno
);
4433 /* 'and' together protocol checks */
4436 gen_and(a0
->b
, tmp
= a1
->b
);
4452 int regno
= alloc_reg();
4453 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
4456 s
= new_stmt(BPF_LD
|BPF_LEN
);
4457 s
->next
= new_stmt(BPF_ST
);
4458 s
->next
->s
.k
= regno
;
4473 a
= (struct arth
*)newchunk(sizeof(*a
));
4477 s
= new_stmt(BPF_LD
|BPF_IMM
);
4479 s
->next
= new_stmt(BPF_ST
);
4495 s
= new_stmt(BPF_ALU
|BPF_NEG
);
4498 s
= new_stmt(BPF_ST
);
4506 gen_arth(code
, a0
, a1
)
4508 struct arth
*a0
, *a1
;
4510 struct slist
*s0
, *s1
, *s2
;
4514 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
4519 sappend(a0
->s
, a1
->s
);
4521 free_reg(a0
->regno
);
4522 free_reg(a1
->regno
);
4524 s0
= new_stmt(BPF_ST
);
4525 a0
->regno
= s0
->s
.k
= alloc_reg();
4532 * Here we handle simple allocation of the scratch registers.
4533 * If too many registers are alloc'd, the allocator punts.
4535 static int regused
[BPF_MEMWORDS
];
4539 * Return the next free register.
4544 int n
= BPF_MEMWORDS
;
4547 if (regused
[curreg
])
4548 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
4550 regused
[curreg
] = 1;
4554 bpf_error("too many registers needed to evaluate expression");
4559 * Return a register to the table so it can
4569 static struct block
*
4576 s
= new_stmt(BPF_LD
|BPF_LEN
);
4577 b
= new_block(JMP(jmp
));
4588 return gen_len(BPF_JGE
, n
);
4592 * Actually, this is less than or equal.
4600 b
= gen_len(BPF_JGT
, n
);
4607 gen_byteop(op
, idx
, val
)
4618 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4621 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4622 b
->s
.code
= JMP(BPF_JGE
);
4627 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4628 b
->s
.code
= JMP(BPF_JGT
);
4632 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
4636 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
4640 b
= new_block(JMP(BPF_JEQ
));
4647 static u_char abroadcast
[] = { 0x0 };
4650 gen_broadcast(proto
)
4653 bpf_u_int32 hostmask
;
4654 struct block
*b0
, *b1
, *b2
;
4655 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4661 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4662 return gen_ahostop(abroadcast
, Q_DST
);
4663 if (linktype
== DLT_EN10MB
)
4664 return gen_ehostop(ebroadcast
, Q_DST
);
4665 if (linktype
== DLT_FDDI
)
4666 return gen_fhostop(ebroadcast
, Q_DST
);
4667 if (linktype
== DLT_IEEE802
)
4668 return gen_thostop(ebroadcast
, Q_DST
);
4669 if (linktype
== DLT_IEEE802_11
)
4670 return gen_wlanhostop(ebroadcast
, Q_DST
);
4671 if (linktype
== DLT_IP_OVER_FC
)
4672 return gen_ipfchostop(ebroadcast
, Q_DST
);
4673 if (linktype
== DLT_SUNATM
&& is_lane
) {
4675 * Check that the packet doesn't begin with an
4676 * LE Control marker. (We've already generated
4679 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4683 * Now check the MAC address.
4685 b0
= gen_ehostop(ebroadcast
, Q_DST
);
4689 bpf_error("not a broadcast link");
4693 b0
= gen_linktype(ETHERTYPE_IP
);
4694 hostmask
= ~netmask
;
4695 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
4696 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
4697 (bpf_int32
)(~0 & hostmask
), hostmask
);
4702 bpf_error("only link-layer/IP broadcast filters supported");
4706 * Generate code to test the low-order bit of a MAC address (that's
4707 * the bottom bit of the *first* byte).
4709 static struct block
*
4710 gen_mac_multicast(offset
)
4713 register struct block
*b0
;
4714 register struct slist
*s
;
4716 /* link[offset] & 1 != 0 */
4717 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4719 b0
= new_block(JMP(BPF_JSET
));
4726 gen_multicast(proto
)
4729 register struct block
*b0
, *b1
, *b2
;
4730 register struct slist
*s
;
4736 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4737 /* all ARCnet multicasts use the same address */
4738 return gen_ahostop(abroadcast
, Q_DST
);
4740 if (linktype
== DLT_EN10MB
) {
4741 /* ether[0] & 1 != 0 */
4742 return gen_mac_multicast(0);
4745 if (linktype
== DLT_FDDI
) {
4747 * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX
4749 * XXX - was that referring to bit-order issues?
4751 /* fddi[1] & 1 != 0 */
4752 return gen_mac_multicast(1);
4755 if (linktype
== DLT_IEEE802
) {
4756 /* tr[2] & 1 != 0 */
4757 return gen_mac_multicast(2);
4760 if (linktype
== DLT_IEEE802_11
) {
4764 * For control frames, there is no DA.
4766 * For management frames, DA is at an
4767 * offset of 4 from the beginning of
4770 * For data frames, DA is at an offset
4771 * of 4 from the beginning of the packet
4772 * if To DS is clear and at an offset of
4773 * 16 from the beginning of the packet
4778 * Generate the tests to be done for data frames.
4780 * First, check for To DS set, i.e. "link[1] & 0x01".
4782 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4784 b1
= new_block(JMP(BPF_JSET
));
4785 b1
->s
.k
= 0x01; /* To DS */
4789 * If To DS is set, the DA is at 16.
4791 b0
= gen_mac_multicast(16);
4795 * Now, check for To DS not set, i.e. check
4796 * "!(link[1] & 0x01)".
4798 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4800 b2
= new_block(JMP(BPF_JSET
));
4801 b2
->s
.k
= 0x01; /* To DS */
4806 * If To DS is not set, the DA is at 4.
4808 b1
= gen_mac_multicast(4);
4812 * Now OR together the last two checks. That gives
4813 * the complete set of checks for data frames.
4818 * Now check for a data frame.
4819 * I.e, check "link[0] & 0x08".
4821 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4823 b1
= new_block(JMP(BPF_JSET
));
4828 * AND that with the checks done for data frames.
4833 * If the high-order bit of the type value is 0, this
4834 * is a management frame.
4835 * I.e, check "!(link[0] & 0x08)".
4837 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4839 b2
= new_block(JMP(BPF_JSET
));
4845 * For management frames, the DA is at 4.
4847 b1
= gen_mac_multicast(4);
4851 * OR that with the checks done for data frames.
4852 * That gives the checks done for management and
4858 * If the low-order bit of the type value is 1,
4859 * this is either a control frame or a frame
4860 * with a reserved type, and thus not a
4863 * I.e., check "!(link[0] & 0x04)".
4865 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4867 b1
= new_block(JMP(BPF_JSET
));
4873 * AND that with the checks for data and management
4880 if (linktype
== DLT_IP_OVER_FC
) {
4881 b0
= gen_mac_multicast(2);
4885 if (linktype
== DLT_SUNATM
&& is_lane
) {
4887 * Check that the packet doesn't begin with an
4888 * LE Control marker. (We've already generated
4891 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4894 /* ether[off_mac] & 1 != 0 */
4895 b0
= gen_mac_multicast(off_mac
);
4900 /* Link not known to support multicasts */
4904 b0
= gen_linktype(ETHERTYPE_IP
);
4905 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4906 b1
->s
.code
= JMP(BPF_JGE
);
4912 b0
= gen_linktype(ETHERTYPE_IPV6
);
4913 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4918 bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
4922 * generate command for inbound/outbound. It's here so we can
4923 * make it link-type specific. 'dir' = 0 implies "inbound",
4924 * = 1 implies "outbound".
4930 register struct block
*b0
;
4933 * Only some data link types support inbound/outbound qualifiers.
4937 b0
= gen_relation(BPF_JEQ
,
4938 gen_load(Q_LINK
, gen_loadi(0), 1),
4946 * Match packets sent by this machine.
4948 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_OUTGOING
);
4951 * Match packets sent to this machine.
4952 * (No broadcast or multicast packets, or
4953 * packets sent to some other machine and
4954 * received promiscuously.)
4956 * XXX - packets sent to other machines probably
4957 * shouldn't be matched, but what about broadcast
4958 * or multicast packets we received?
4960 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_HOST
);
4965 b0
= gen_cmp(26, BPF_H
,
4966 (bpf_int32
)((dir
== 0) ? PF_IN
: PF_OUT
));
4970 bpf_error("inbound/outbound not supported on linktype %d",
4978 /* PF firewall log matched interface */
4980 gen_pf_ifname(const char *ifname
)
4982 if (linktype
!= DLT_PFLOG
) {
4983 bpf_error("ifname supported only for DLT_PFLOG");
4986 if (strlen(ifname
) >= 16) {
4987 bpf_error("ifname interface names can't be larger than 16 characters");
4990 return (gen_bcmp(4, strlen(ifname
), (const u_char
*)ifname
));
4994 /* PF firewall log rule number */
4998 if (linktype
!= DLT_PFLOG
) {
4999 bpf_error("rnr supported only for DLT_PFLOG");
5003 return (gen_cmp(20, BPF_H
, (bpf_int32
)rnr
));
5006 /* PF firewall log reason code */
5008 gen_pf_reason(int reason
)
5010 if (linktype
!= DLT_PFLOG
) {
5011 bpf_error("reason supported only for DLT_PFLOG");
5015 return (gen_cmp(22, BPF_H
, (bpf_int32
)reason
));
5018 /* PF firewall log action */
5020 gen_pf_action(int action
)
5022 if (linktype
!= DLT_PFLOG
) {
5023 bpf_error("action supported only for DLT_PFLOG");
5027 return (gen_cmp(24, BPF_H
, (bpf_int32
)action
));
5032 register const u_char
*eaddr
;
5035 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
5036 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
5037 return gen_ahostop(eaddr
, (int)q
.dir
);
5039 bpf_error("ARCnet address used in non-arc expression");
5043 static struct block
*
5044 gen_ahostop(eaddr
, dir
)
5045 register const u_char
*eaddr
;
5048 register struct block
*b0
, *b1
;
5051 /* src comes first, different from Ethernet */
5053 return gen_bcmp(0, 1, eaddr
);
5056 return gen_bcmp(1, 1, eaddr
);
5059 b0
= gen_ahostop(eaddr
, Q_SRC
);
5060 b1
= gen_ahostop(eaddr
, Q_DST
);
5066 b0
= gen_ahostop(eaddr
, Q_SRC
);
5067 b1
= gen_ahostop(eaddr
, Q_DST
);
5076 * support IEEE 802.1Q VLAN trunk over ethernet
5085 * Change the offsets to point to the type and data fields within
5086 * the VLAN packet. This is somewhat of a kludge.
5088 if (orig_nl
== (u_int
)-1) {
5089 orig_linktype
= off_linktype
; /* save original values */
5091 orig_nl_nosnap
= off_nl_nosnap
;
5102 bpf_error("no VLAN support for data link type %d",
5108 /* check for VLAN */
5109 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
5111 /* If a specific VLAN is requested, check VLAN id */
5112 if (vlan_num
>= 0) {
5115 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
5124 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
5136 bpf_error("'vpi' supported only on raw ATM");
5137 if (off_vpi
== (u_int
)-1)
5139 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
5140 (u_int
)jvalue
, reverse
);
5145 bpf_error("'vci' supported only on raw ATM");
5146 if (off_vci
== (u_int
)-1)
5148 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
5149 (u_int
)jvalue
, reverse
);
5153 if (off_proto
== (u_int
)-1)
5154 abort(); /* XXX - this isn't on FreeBSD */
5155 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
5156 (u_int
)jvalue
, reverse
);
5160 if (off_payload
== (u_int
)-1)
5162 b0
= gen_ncmp(BPF_B
, off_payload
+ MSG_TYPE_POS
, 0xffffffff,
5163 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
5168 bpf_error("'callref' supported only on raw ATM");
5169 if (off_proto
== (u_int
)-1)
5171 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
5172 (u_int
)jvalue
, reverse
);
5182 gen_atmtype_abbrev(type
)
5185 struct block
*b0
, *b1
;
5190 /* Get all packets in Meta signalling Circuit */
5192 bpf_error("'metac' supported only on raw ATM");
5193 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5194 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
5199 /* Get all packets in Broadcast Circuit*/
5201 bpf_error("'bcc' supported only on raw ATM");
5202 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5203 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
5208 /* Get all cells in Segment OAM F4 circuit*/
5210 bpf_error("'oam4sc' supported only on raw ATM");
5211 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5212 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5217 /* Get all cells in End-to-End OAM F4 Circuit*/
5219 bpf_error("'oam4ec' supported only on raw ATM");
5220 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5221 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5226 /* Get all packets in connection Signalling Circuit */
5228 bpf_error("'sc' supported only on raw ATM");
5229 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5230 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
5235 /* Get all packets in ILMI Circuit */
5237 bpf_error("'ilmic' supported only on raw ATM");
5238 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5239 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
5244 /* Get all LANE packets */
5246 bpf_error("'lane' supported only on raw ATM");
5247 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
5250 * Arrange that all subsequent tests assume LANE
5251 * rather than LLC-encapsulated packets, and set
5252 * the offsets appropriately for LANE-encapsulated
5255 * "off_mac" is the offset of the Ethernet header,
5256 * which is 2 bytes past the ATM pseudo-header
5257 * (skipping the pseudo-header and 2-byte LE Client
5258 * field). The other offsets are Ethernet offsets
5259 * relative to "off_mac".
5262 off_mac
= off_payload
+ 2; /* MAC header */
5263 off_linktype
= off_mac
+ 12;
5264 off_nl
= off_mac
+ 14; /* Ethernet II */
5265 off_nl_nosnap
= off_mac
+ 17; /* 802.3+802.2 */
5269 /* Get all LLC-encapsulated packets */
5271 bpf_error("'llc' supported only on raw ATM");
5272 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
5283 static struct block
*
5284 gen_msg_abbrev(type
)
5290 * Q.2931 signalling protocol messages for handling virtual circuits
5291 * establishment and teardown
5296 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
5300 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
5304 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
5308 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
5312 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
5315 case A_RELEASE_DONE
:
5316 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
5326 gen_atmmulti_abbrev(type
)
5329 struct block
*b0
, *b1
;
5335 bpf_error("'oam' supported only on raw ATM");
5336 b1
= gen_atmmulti_abbrev(A_OAMF4
);
5341 bpf_error("'oamf4' supported only on raw ATM");
5343 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5344 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5346 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5352 * Get Q.2931 signalling messages for switched
5353 * virtual connection
5356 bpf_error("'connectmsg' supported only on raw ATM");
5357 b0
= gen_msg_abbrev(A_SETUP
);
5358 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5360 b0
= gen_msg_abbrev(A_CONNECT
);
5362 b0
= gen_msg_abbrev(A_CONNECTACK
);
5364 b0
= gen_msg_abbrev(A_RELEASE
);
5366 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5368 b0
= gen_atmtype_abbrev(A_SC
);
5374 bpf_error("'metaconnect' supported only on raw ATM");
5375 b0
= gen_msg_abbrev(A_SETUP
);
5376 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5378 b0
= gen_msg_abbrev(A_CONNECT
);
5380 b0
= gen_msg_abbrev(A_RELEASE
);
5382 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5384 b0
= gen_atmtype_abbrev(A_METAC
);