]>
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
[] _U_
=
24 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.195 2003-12-18 20:36:11 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 */
960 * Currently, only raw "link[N:M]" filtering is supported.
967 bpf_error("unknown data link type %d", linktype
);
971 static struct block
*
978 s
= new_stmt(BPF_LD
|BPF_IMM
);
980 b
= new_block(JMP(BPF_JEQ
));
986 static inline struct block
*
989 return gen_uncond(1);
992 static inline struct block
*
995 return gen_uncond(0);
999 * Byte-swap a 32-bit number.
1000 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
1001 * big-endian platforms.)
1003 #define SWAPLONG(y) \
1004 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
1006 static struct block
*
1007 gen_ether_linktype(proto
)
1010 struct block
*b0
, *b1
;
1016 * OSI protocols always use 802.2 encapsulation.
1017 * XXX - should we check both the DSAP and the
1018 * SSAP, like this, or should we check just the
1021 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1023 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1024 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1029 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1031 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1032 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1036 case LLCSAP_NETBEUI
:
1038 * NetBEUI always uses 802.2 encapsulation.
1039 * XXX - should we check both the DSAP and the
1040 * SSAP, like this, or should we check just the
1043 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1045 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1046 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1054 * Ethernet_II frames, which are Ethernet
1055 * frames with a frame type of ETHERTYPE_IPX;
1057 * Ethernet_802.3 frames, which are 802.3
1058 * frames (i.e., the type/length field is
1059 * a length field, <= ETHERMTU, rather than
1060 * a type field) with the first two bytes
1061 * after the Ethernet/802.3 header being
1064 * Ethernet_802.2 frames, which are 802.3
1065 * frames with an 802.2 LLC header and
1066 * with the IPX LSAP as the DSAP in the LLC
1069 * Ethernet_SNAP frames, which are 802.3
1070 * frames with an LLC header and a SNAP
1071 * header and with an OUI of 0x000000
1072 * (encapsulated Ethernet) and a protocol
1073 * ID of ETHERTYPE_IPX in the SNAP header.
1075 * XXX - should we generate the same code both
1076 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
1080 * This generates code to check both for the
1081 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
1083 b0
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1084 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)0xFFFF);
1088 * Now we add code to check for SNAP frames with
1089 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1091 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1095 * Now we generate code to check for 802.3
1096 * frames in general.
1098 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1102 * Now add the check for 802.3 frames before the
1103 * check for Ethernet_802.2 and Ethernet_802.3,
1104 * as those checks should only be done on 802.3
1105 * frames, not on Ethernet frames.
1110 * Now add the check for Ethernet_II frames, and
1111 * do that before checking for the other frame
1114 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_IPX
);
1118 case ETHERTYPE_ATALK
:
1119 case ETHERTYPE_AARP
:
1121 * EtherTalk (AppleTalk protocols on Ethernet link
1122 * layer) may use 802.2 encapsulation.
1126 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1127 * we check for an Ethernet type field less than
1128 * 1500, which means it's an 802.3 length field.
1130 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1134 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1135 * SNAP packets with an organization code of
1136 * 0x080007 (Apple, for Appletalk) and a protocol
1137 * type of ETHERTYPE_ATALK (Appletalk).
1139 * 802.2-encapsulated ETHERTYPE_AARP packets are
1140 * SNAP packets with an organization code of
1141 * 0x000000 (encapsulated Ethernet) and a protocol
1142 * type of ETHERTYPE_AARP (Appletalk ARP).
1144 if (proto
== ETHERTYPE_ATALK
)
1145 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1146 else /* proto == ETHERTYPE_AARP */
1147 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1151 * Check for Ethernet encapsulation (Ethertalk
1152 * phase 1?); we just check for the Ethernet
1155 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1161 if (proto
<= ETHERMTU
) {
1163 * This is an LLC SAP value, so the frames
1164 * that match would be 802.2 frames.
1165 * Check that the frame is an 802.2 frame
1166 * (i.e., that the length/type field is
1167 * a length field, <= ETHERMTU) and
1168 * then check the DSAP.
1170 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1172 b1
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)proto
);
1177 * This is an Ethernet type, so compare
1178 * the length/type field with it (if
1179 * the frame is an 802.2 frame, the length
1180 * field will be <= ETHERMTU, and, as
1181 * "proto" is > ETHERMTU, this test
1182 * will fail and the frame won't match,
1183 * which is what we want).
1185 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1190 static struct block
*
1194 struct block
*b0
, *b1
, *b2
;
1199 return gen_ether_linktype(proto
);
1206 proto
= (proto
<< 8 | LLCSAP_ISONS
);
1210 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1215 case DLT_IEEE802_11
:
1216 case DLT_PRISM_HEADER
:
1217 case DLT_IEEE802_11_RADIO
:
1220 case DLT_ATM_RFC1483
:
1222 case DLT_IP_OVER_FC
:
1223 return gen_llc(proto
);
1228 * If "is_lane" is set, check for a LANE-encapsulated
1229 * version of this protocol, otherwise check for an
1230 * LLC-encapsulated version of this protocol.
1232 * We assume LANE means Ethernet, not Token Ring.
1236 * Check that the packet doesn't begin with an
1237 * LE Control marker. (We've already generated
1240 b0
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
1244 * Now generate an Ethernet test.
1246 b1
= gen_ether_linktype(proto
);
1251 * Check for LLC encapsulation and then check the
1254 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1255 b1
= gen_llc(proto
);
1264 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1265 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1266 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1272 * OSI protocols always use 802.2 encapsulation.
1273 * XXX - should we check both the DSAP and the
1274 * LSAP, like this, or should we check just the
1277 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1278 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1279 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1283 case LLCSAP_NETBEUI
:
1285 * NetBEUI always uses 802.2 encapsulation.
1286 * XXX - should we check both the DSAP and the
1287 * LSAP, like this, or should we check just the
1290 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1291 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1292 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1298 * Ethernet_II frames, which are Ethernet
1299 * frames with a frame type of ETHERTYPE_IPX;
1301 * Ethernet_802.3 frames, which have a frame
1302 * type of LINUX_SLL_P_802_3;
1304 * Ethernet_802.2 frames, which are 802.3
1305 * frames with an 802.2 LLC header (i.e, have
1306 * a frame type of LINUX_SLL_P_802_2) and
1307 * with the IPX LSAP as the DSAP in the LLC
1310 * Ethernet_SNAP frames, which are 802.3
1311 * frames with an LLC header and a SNAP
1312 * header and with an OUI of 0x000000
1313 * (encapsulated Ethernet) and a protocol
1314 * ID of ETHERTYPE_IPX in the SNAP header.
1316 * First, do the checks on LINUX_SLL_P_802_2
1317 * frames; generate the check for either
1318 * Ethernet_802.2 or Ethernet_SNAP frames, and
1319 * then put a check for LINUX_SLL_P_802_2 frames
1322 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1323 (bpf_int32
)LLCSAP_IPX
);
1324 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1327 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1331 * Now check for 802.3 frames and OR that with
1332 * the previous test.
1334 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1338 * Now add the check for Ethernet_II frames, and
1339 * do that before checking for the other frame
1342 b0
= gen_cmp(off_linktype
, BPF_H
,
1343 (bpf_int32
)ETHERTYPE_IPX
);
1347 case ETHERTYPE_ATALK
:
1348 case ETHERTYPE_AARP
:
1350 * EtherTalk (AppleTalk protocols on Ethernet link
1351 * layer) may use 802.2 encapsulation.
1355 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1356 * we check for the 802.2 protocol type in the
1357 * "Ethernet type" field.
1359 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1362 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1363 * SNAP packets with an organization code of
1364 * 0x080007 (Apple, for Appletalk) and a protocol
1365 * type of ETHERTYPE_ATALK (Appletalk).
1367 * 802.2-encapsulated ETHERTYPE_AARP packets are
1368 * SNAP packets with an organization code of
1369 * 0x000000 (encapsulated Ethernet) and a protocol
1370 * type of ETHERTYPE_AARP (Appletalk ARP).
1372 if (proto
== ETHERTYPE_ATALK
)
1373 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1375 else /* proto == ETHERTYPE_AARP */
1376 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1381 * Check for Ethernet encapsulation (Ethertalk
1382 * phase 1?); we just check for the Ethernet
1385 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1391 if (proto
<= ETHERMTU
) {
1393 * This is an LLC SAP value, so the frames
1394 * that match would be 802.2 frames.
1395 * Check for the 802.2 protocol type
1396 * in the "Ethernet type" field, and
1397 * then check the DSAP.
1399 b0
= gen_cmp(off_linktype
, BPF_H
,
1401 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1407 * This is an Ethernet type, so compare
1408 * the length/type field with it (if
1409 * the frame is an 802.2 frame, the length
1410 * field will be <= ETHERMTU, and, as
1411 * "proto" is > ETHERMTU, this test
1412 * will fail and the frame won't match,
1413 * which is what we want).
1415 return gen_cmp(off_linktype
, BPF_H
,
1422 case DLT_SLIP_BSDOS
:
1425 * These types don't provide any type field; packets
1428 * XXX - for IPv4, check for a version number of 4, and,
1429 * for IPv6, check for a version number of 6?
1435 case ETHERTYPE_IPV6
:
1437 return gen_true(); /* always true */
1440 return gen_false(); /* always false */
1445 case DLT_PPP_SERIAL
:
1448 * We use Ethernet protocol types inside libpcap;
1449 * map them to the corresponding PPP protocol types.
1458 case ETHERTYPE_IPV6
:
1467 case ETHERTYPE_ATALK
:
1481 * I'm assuming the "Bridging PDU"s that go
1482 * over PPP are Spanning Tree Protocol
1496 * We use Ethernet protocol types inside libpcap;
1497 * map them to the corresponding PPP protocol types.
1502 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1503 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1505 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1510 case ETHERTYPE_IPV6
:
1520 case ETHERTYPE_ATALK
:
1534 * I'm assuming the "Bridging PDU"s that go
1535 * over PPP are Spanning Tree Protocol
1552 * For DLT_NULL, the link-layer header is a 32-bit
1553 * word containing an AF_ value in *host* byte order,
1554 * and for DLT_ENC, the link-layer header begins
1555 * with a 32-bit work containing an AF_ value in
1558 * In addition, if we're reading a saved capture file,
1559 * the host byte order in the capture may not be the
1560 * same as the host byte order on this machine.
1562 * For DLT_LOOP, the link-layer header is a 32-bit
1563 * word containing an AF_ value in *network* byte order.
1565 * XXX - AF_ values may, unfortunately, be platform-
1566 * dependent; for example, FreeBSD's AF_INET6 is 24
1567 * whilst NetBSD's and OpenBSD's is 26.
1569 * This means that, when reading a capture file, just
1570 * checking for our AF_INET6 value won't work if the
1571 * capture file came from another OS.
1573 * XXX - what's the byte order for DLT_PFLOG?
1582 case ETHERTYPE_IPV6
:
1589 * Not a type on which we support filtering.
1590 * XXX - support those that have AF_ values
1591 * #defined on this platform, at least?
1596 if (linktype
== DLT_NULL
|| linktype
== DLT_ENC
) {
1598 * The AF_ value is in host byte order, but
1599 * the BPF interpreter will convert it to
1600 * network byte order.
1602 * If this is a save file, and it's from a
1603 * machine with the opposite byte order to
1604 * ours, we byte-swap the AF_ value.
1606 * Then we run it through "htonl()", and
1607 * generate code to compare against the result.
1609 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1610 bpf_pcap
->sf
.swapped
)
1611 proto
= SWAPLONG(proto
);
1612 proto
= htonl(proto
);
1614 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1617 case DLT_ARCNET_LINUX
:
1619 * XXX should we check for first fragment if the protocol
1628 case ETHERTYPE_IPV6
:
1629 return (gen_cmp(off_linktype
, BPF_B
,
1630 (bpf_int32
)ARCTYPE_INET6
));
1634 b0
= gen_cmp(off_linktype
, BPF_B
,
1635 (bpf_int32
)ARCTYPE_IP
);
1636 b1
= gen_cmp(off_linktype
, BPF_B
,
1637 (bpf_int32
)ARCTYPE_IP_OLD
);
1642 b0
= gen_cmp(off_linktype
, BPF_B
,
1643 (bpf_int32
)ARCTYPE_ARP
);
1644 b1
= gen_cmp(off_linktype
, BPF_B
,
1645 (bpf_int32
)ARCTYPE_ARP_OLD
);
1649 case ETHERTYPE_REVARP
:
1650 return (gen_cmp(off_linktype
, BPF_B
,
1651 (bpf_int32
)ARCTYPE_REVARP
));
1653 case ETHERTYPE_ATALK
:
1654 return (gen_cmp(off_linktype
, BPF_B
,
1655 (bpf_int32
)ARCTYPE_ATALK
));
1661 case ETHERTYPE_ATALK
:
1670 * XXX - assumes a 2-byte Frame Relay header with
1671 * DLCI and flags. What if the address is longer?
1677 * Check for the special NLPID for IP.
1679 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1682 case ETHERTYPE_IPV6
:
1684 * Check for the special NLPID for IPv6.
1686 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1691 * Check for several OSI protocols.
1693 * Frame Relay packets typically have an OSI
1694 * NLPID at the beginning; we check for each
1697 * What we check for is the NLPID and a frame
1698 * control field of UI, i.e. 0x03 followed
1701 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1702 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1703 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1713 case DLT_LINUX_IRDA
:
1714 bpf_error("IrDA link-layer type filtering not implemented");
1718 * All the types that have no encapsulation should either be
1719 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1720 * all packets are IP packets, or should be handled in some
1721 * special case, if none of them are (if some are and some
1722 * aren't, the lack of encapsulation is a problem, as we'd
1723 * have to find some other way of determining the packet type).
1725 * Therefore, if "off_linktype" is -1, there's an error.
1727 if (off_linktype
== (u_int
)-1)
1731 * Any type not handled above should always have an Ethernet
1732 * type at an offset of "off_linktype". (PPP is partially
1733 * handled above - the protocol type is mapped from the
1734 * Ethernet and LLC types we use internally to the corresponding
1735 * PPP type - but the PPP type is always specified by a value
1736 * at "off_linktype", so we don't have to do the code generation
1739 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1743 * Check for an LLC SNAP packet with a given organization code and
1744 * protocol type; we check the entire contents of the 802.2 LLC and
1745 * snap headers, checking for DSAP and SSAP of SNAP and a control
1746 * field of 0x03 in the LLC header, and for the specified organization
1747 * code and protocol type in the SNAP header.
1749 static struct block
*
1750 gen_snap(orgcode
, ptype
, offset
)
1751 bpf_u_int32 orgcode
;
1755 u_char snapblock
[8];
1757 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1758 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1759 snapblock
[2] = 0x03; /* control = UI */
1760 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1761 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1762 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1763 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1764 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1765 return gen_bcmp(offset
, 8, snapblock
);
1769 * Check for a given protocol value assuming an 802.2 LLC header.
1771 static struct block
*
1776 * XXX - handle token-ring variable-length header.
1781 return gen_cmp(off_linktype
, BPF_H
, (long)
1782 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1785 return gen_cmp(off_linktype
, BPF_H
, (long)
1786 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1788 case LLCSAP_NETBEUI
:
1789 return gen_cmp(off_linktype
, BPF_H
, (long)
1790 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1794 * XXX - are there ever SNAP frames for IPX on
1795 * non-Ethernet 802.x networks?
1797 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1799 case ETHERTYPE_ATALK
:
1801 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1802 * SNAP packets with an organization code of
1803 * 0x080007 (Apple, for Appletalk) and a protocol
1804 * type of ETHERTYPE_ATALK (Appletalk).
1806 * XXX - check for an organization code of
1807 * encapsulated Ethernet as well?
1809 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1813 * XXX - we don't have to check for IPX 802.3
1814 * here, but should we check for the IPX Ethertype?
1816 if (proto
<= ETHERMTU
) {
1818 * This is an LLC SAP value, so check
1821 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1824 * This is an Ethernet type; we assume that it's
1825 * unlikely that it'll appear in the right place
1826 * at random, and therefore check only the
1827 * location that would hold the Ethernet type
1828 * in a SNAP frame with an organization code of
1829 * 0x000000 (encapsulated Ethernet).
1831 * XXX - if we were to check for the SNAP DSAP and
1832 * LSAP, as per XXX, and were also to check for an
1833 * organization code of 0x000000 (encapsulated
1834 * Ethernet), we'd do
1836 * return gen_snap(0x000000, proto,
1839 * here; for now, we don't, as per the above.
1840 * I don't know whether it's worth the extra CPU
1841 * time to do the right check or not.
1843 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1848 static struct block
*
1849 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1853 u_int src_off
, dst_off
;
1855 struct block
*b0
, *b1
;
1869 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1870 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1876 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1877 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1884 b0
= gen_linktype(proto
);
1885 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1891 static struct block
*
1892 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1893 struct in6_addr
*addr
;
1894 struct in6_addr
*mask
;
1896 u_int src_off
, dst_off
;
1898 struct block
*b0
, *b1
;
1913 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1914 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1920 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1921 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1928 /* this order is important */
1929 a
= (u_int32_t
*)addr
;
1930 m
= (u_int32_t
*)mask
;
1931 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1932 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1934 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1936 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1938 b0
= gen_linktype(proto
);
1944 static struct block
*
1945 gen_ehostop(eaddr
, dir
)
1946 register const u_char
*eaddr
;
1949 register struct block
*b0
, *b1
;
1953 return gen_bcmp(off_mac
+ 6, 6, eaddr
);
1956 return gen_bcmp(off_mac
+ 0, 6, eaddr
);
1959 b0
= gen_ehostop(eaddr
, Q_SRC
);
1960 b1
= gen_ehostop(eaddr
, Q_DST
);
1966 b0
= gen_ehostop(eaddr
, Q_SRC
);
1967 b1
= gen_ehostop(eaddr
, Q_DST
);
1976 * Like gen_ehostop, but for DLT_FDDI
1978 static struct block
*
1979 gen_fhostop(eaddr
, dir
)
1980 register const u_char
*eaddr
;
1983 struct block
*b0
, *b1
;
1988 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
1990 return gen_bcmp(6 + 1, 6, eaddr
);
1995 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
1997 return gen_bcmp(0 + 1, 6, eaddr
);
2001 b0
= gen_fhostop(eaddr
, Q_SRC
);
2002 b1
= gen_fhostop(eaddr
, Q_DST
);
2008 b0
= gen_fhostop(eaddr
, Q_SRC
);
2009 b1
= gen_fhostop(eaddr
, Q_DST
);
2018 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
2020 static struct block
*
2021 gen_thostop(eaddr
, dir
)
2022 register const u_char
*eaddr
;
2025 register struct block
*b0
, *b1
;
2029 return gen_bcmp(8, 6, eaddr
);
2032 return gen_bcmp(2, 6, eaddr
);
2035 b0
= gen_thostop(eaddr
, Q_SRC
);
2036 b1
= gen_thostop(eaddr
, Q_DST
);
2042 b0
= gen_thostop(eaddr
, Q_SRC
);
2043 b1
= gen_thostop(eaddr
, Q_DST
);
2052 * Like gen_ehostop, but for DLT_IEEE802_11 (802.11 wireless LAN)
2054 static struct block
*
2055 gen_wlanhostop(eaddr
, dir
)
2056 register const u_char
*eaddr
;
2059 register struct block
*b0
, *b1
, *b2
;
2060 register struct slist
*s
;
2067 * For control frames, there is no SA.
2069 * For management frames, SA is at an
2070 * offset of 10 from the beginning of
2073 * For data frames, SA is at an offset
2074 * of 10 from the beginning of the packet
2075 * if From DS is clear, at an offset of
2076 * 16 from the beginning of the packet
2077 * if From DS is set and To DS is clear,
2078 * and an offset of 24 from the beginning
2079 * of the packet if From DS is set and To DS
2084 * Generate the tests to be done for data frames
2087 * First, check for To DS set, i.e. check "link[1] & 0x01".
2089 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2091 b1
= new_block(JMP(BPF_JSET
));
2092 b1
->s
.k
= 0x01; /* To DS */
2096 * If To DS is set, the SA is at 24.
2098 b0
= gen_bcmp(24, 6, eaddr
);
2102 * Now, check for To DS not set, i.e. check
2103 * "!(link[1] & 0x01)".
2105 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2107 b2
= new_block(JMP(BPF_JSET
));
2108 b2
->s
.k
= 0x01; /* To DS */
2113 * If To DS is not set, the SA is at 16.
2115 b1
= gen_bcmp(16, 6, eaddr
);
2119 * Now OR together the last two checks. That gives
2120 * the complete set of checks for data frames with
2126 * Now check for From DS being set, and AND that with
2127 * the ORed-together checks.
2129 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2131 b1
= new_block(JMP(BPF_JSET
));
2132 b1
->s
.k
= 0x02; /* From DS */
2137 * Now check for data frames with From DS not set.
2139 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2141 b2
= new_block(JMP(BPF_JSET
));
2142 b2
->s
.k
= 0x02; /* From DS */
2147 * If From DS isn't set, the SA is at 10.
2149 b1
= gen_bcmp(10, 6, eaddr
);
2153 * Now OR together the checks for data frames with
2154 * From DS not set and for data frames with From DS
2155 * set; that gives the checks done for data frames.
2160 * Now check for a data frame.
2161 * I.e, check "link[0] & 0x08".
2163 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2165 b1
= new_block(JMP(BPF_JSET
));
2170 * AND that with the checks done for data frames.
2175 * If the high-order bit of the type value is 0, this
2176 * is a management frame.
2177 * I.e, check "!(link[0] & 0x08)".
2179 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2181 b2
= new_block(JMP(BPF_JSET
));
2187 * For management frames, the SA is at 10.
2189 b1
= gen_bcmp(10, 6, eaddr
);
2193 * OR that with the checks done for data frames.
2194 * That gives the checks done for management and
2200 * If the low-order bit of the type value is 1,
2201 * this is either a control frame or a frame
2202 * with a reserved type, and thus not a
2205 * I.e., check "!(link[0] & 0x04)".
2207 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2209 b1
= new_block(JMP(BPF_JSET
));
2215 * AND that with the checks for data and management
2225 * For control frames, there is no DA.
2227 * For management frames, DA is at an
2228 * offset of 4 from the beginning of
2231 * For data frames, DA is at an offset
2232 * of 4 from the beginning of the packet
2233 * if To DS is clear and at an offset of
2234 * 16 from the beginning of the packet
2239 * Generate the tests to be done for data frames.
2241 * First, check for To DS set, i.e. "link[1] & 0x01".
2243 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2245 b1
= new_block(JMP(BPF_JSET
));
2246 b1
->s
.k
= 0x01; /* To DS */
2250 * If To DS is set, the DA is at 16.
2252 b0
= gen_bcmp(16, 6, eaddr
);
2256 * Now, check for To DS not set, i.e. check
2257 * "!(link[1] & 0x01)".
2259 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2261 b2
= new_block(JMP(BPF_JSET
));
2262 b2
->s
.k
= 0x01; /* To DS */
2267 * If To DS is not set, the DA is at 4.
2269 b1
= gen_bcmp(4, 6, eaddr
);
2273 * Now OR together the last two checks. That gives
2274 * the complete set of checks for data frames.
2279 * Now check for a data frame.
2280 * I.e, check "link[0] & 0x08".
2282 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2284 b1
= new_block(JMP(BPF_JSET
));
2289 * AND that with the checks done for data frames.
2294 * If the high-order bit of the type value is 0, this
2295 * is a management frame.
2296 * I.e, check "!(link[0] & 0x08)".
2298 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2300 b2
= new_block(JMP(BPF_JSET
));
2306 * For management frames, the DA is at 4.
2308 b1
= gen_bcmp(4, 6, eaddr
);
2312 * OR that with the checks done for data frames.
2313 * That gives the checks done for management and
2319 * If the low-order bit of the type value is 1,
2320 * this is either a control frame or a frame
2321 * with a reserved type, and thus not a
2324 * I.e., check "!(link[0] & 0x04)".
2326 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2328 b1
= new_block(JMP(BPF_JSET
));
2334 * AND that with the checks for data and management
2341 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2342 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2348 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2349 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2358 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
2359 * (We assume that the addresses are IEEE 48-bit MAC addresses,
2360 * as the RFC states.)
2362 static struct block
*
2363 gen_ipfchostop(eaddr
, dir
)
2364 register const u_char
*eaddr
;
2367 register struct block
*b0
, *b1
;
2371 return gen_bcmp(10, 6, eaddr
);
2374 return gen_bcmp(2, 6, eaddr
);
2377 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2378 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2384 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2385 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2394 * This is quite tricky because there may be pad bytes in front of the
2395 * DECNET header, and then there are two possible data packet formats that
2396 * carry both src and dst addresses, plus 5 packet types in a format that
2397 * carries only the src node, plus 2 types that use a different format and
2398 * also carry just the src node.
2402 * Instead of doing those all right, we just look for data packets with
2403 * 0 or 1 bytes of padding. If you want to look at other packets, that
2404 * will require a lot more hacking.
2406 * To add support for filtering on DECNET "areas" (network numbers)
2407 * one would want to add a "mask" argument to this routine. That would
2408 * make the filter even more inefficient, although one could be clever
2409 * and not generate masking instructions if the mask is 0xFFFF.
2411 static struct block
*
2412 gen_dnhostop(addr
, dir
, base_off
)
2417 struct block
*b0
, *b1
, *b2
, *tmp
;
2418 u_int offset_lh
; /* offset if long header is received */
2419 u_int offset_sh
; /* offset if short header is received */
2424 offset_sh
= 1; /* follows flags */
2425 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
2429 offset_sh
= 3; /* follows flags, dstnode */
2430 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
2434 /* Inefficient because we do our Calvinball dance twice */
2435 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2436 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2442 /* Inefficient because we do our Calvinball dance twice */
2443 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2444 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2449 bpf_error("ISO host filtering not implemented");
2454 b0
= gen_linktype(ETHERTYPE_DN
);
2455 /* Check for pad = 1, long header case */
2456 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2457 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
2458 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
2459 BPF_H
, (bpf_int32
)ntohs(addr
));
2461 /* Check for pad = 0, long header case */
2462 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
2463 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2466 /* Check for pad = 1, short header case */
2467 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2468 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
2469 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
2470 BPF_H
, (bpf_int32
)ntohs(addr
));
2473 /* Check for pad = 0, short header case */
2474 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
2475 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2479 /* Combine with test for linktype */
2484 static struct block
*
2485 gen_host(addr
, mask
, proto
, dir
)
2491 struct block
*b0
, *b1
;
2496 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
2497 if (off_linktype
!= (u_int
)-1) {
2498 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
2500 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
2506 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
2507 off_nl
+ 12, off_nl
+ 16);
2510 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2511 off_nl
+ 14, off_nl
+ 24);
2514 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2515 off_nl
+ 14, off_nl
+ 24);
2518 bpf_error("'tcp' modifier applied to host");
2521 bpf_error("'sctp' modifier applied to host");
2524 bpf_error("'udp' modifier applied to host");
2527 bpf_error("'icmp' modifier applied to host");
2530 bpf_error("'igmp' modifier applied to host");
2533 bpf_error("'igrp' modifier applied to host");
2536 bpf_error("'pim' modifier applied to host");
2539 bpf_error("'vrrp' modifier applied to host");
2542 bpf_error("ATALK host filtering not implemented");
2545 bpf_error("AARP host filtering not implemented");
2548 return gen_dnhostop(addr
, dir
, off_nl
);
2551 bpf_error("SCA host filtering not implemented");
2554 bpf_error("LAT host filtering not implemented");
2557 bpf_error("MOPDL host filtering not implemented");
2560 bpf_error("MOPRC host filtering not implemented");
2564 bpf_error("'ip6' modifier applied to ip host");
2567 bpf_error("'icmp6' modifier applied to host");
2571 bpf_error("'ah' modifier applied to host");
2574 bpf_error("'esp' modifier applied to host");
2577 bpf_error("ISO host filtering not implemented");
2580 bpf_error("'esis' modifier applied to host");
2583 bpf_error("'isis' modifier applied to host");
2586 bpf_error("'clnp' modifier applied to host");
2589 bpf_error("'stp' modifier applied to host");
2592 bpf_error("IPX host filtering not implemented");
2595 bpf_error("'netbeui' modifier applied to host");
2604 static struct block
*
2605 gen_host6(addr
, mask
, proto
, dir
)
2606 struct in6_addr
*addr
;
2607 struct in6_addr
*mask
;
2614 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2617 bpf_error("'ip' modifier applied to ip6 host");
2620 bpf_error("'rarp' modifier applied to ip6 host");
2623 bpf_error("'arp' modifier applied to ip6 host");
2626 bpf_error("'sctp' modifier applied to host");
2629 bpf_error("'tcp' modifier applied to host");
2632 bpf_error("'udp' modifier applied to host");
2635 bpf_error("'icmp' modifier applied to host");
2638 bpf_error("'igmp' modifier applied to host");
2641 bpf_error("'igrp' modifier applied to host");
2644 bpf_error("'pim' modifier applied to host");
2647 bpf_error("'vrrp' modifier applied to host");
2650 bpf_error("ATALK host filtering not implemented");
2653 bpf_error("AARP host filtering not implemented");
2656 bpf_error("'decnet' modifier applied to ip6 host");
2659 bpf_error("SCA host filtering not implemented");
2662 bpf_error("LAT host filtering not implemented");
2665 bpf_error("MOPDL host filtering not implemented");
2668 bpf_error("MOPRC host filtering not implemented");
2671 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2672 off_nl
+ 8, off_nl
+ 24);
2675 bpf_error("'icmp6' modifier applied to host");
2678 bpf_error("'ah' modifier applied to host");
2681 bpf_error("'esp' modifier applied to host");
2684 bpf_error("ISO host filtering not implemented");
2687 bpf_error("'esis' modifier applied to host");
2690 bpf_error("'isis' modifier applied to host");
2693 bpf_error("'clnp' modifier applied to host");
2696 bpf_error("'stp' modifier applied to host");
2699 bpf_error("IPX host filtering not implemented");
2702 bpf_error("'netbeui' modifier applied to host");
2712 static struct block
*
2713 gen_gateway(eaddr
, alist
, proto
, dir
)
2714 const u_char
*eaddr
;
2715 bpf_u_int32
**alist
;
2719 struct block
*b0
, *b1
, *tmp
;
2722 bpf_error("direction applied to 'gateway'");
2729 if (linktype
== DLT_EN10MB
)
2730 b0
= gen_ehostop(eaddr
, Q_OR
);
2731 else if (linktype
== DLT_FDDI
)
2732 b0
= gen_fhostop(eaddr
, Q_OR
);
2733 else if (linktype
== DLT_IEEE802
)
2734 b0
= gen_thostop(eaddr
, Q_OR
);
2735 else if (linktype
== DLT_IEEE802_11
)
2736 b0
= gen_wlanhostop(eaddr
, Q_OR
);
2737 else if (linktype
== DLT_SUNATM
&& is_lane
) {
2739 * Check that the packet doesn't begin with an
2740 * LE Control marker. (We've already generated
2743 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
2747 * Now check the MAC address.
2749 b0
= gen_ehostop(eaddr
, Q_OR
);
2751 } else if (linktype
== DLT_IP_OVER_FC
)
2752 b0
= gen_ipfchostop(eaddr
, Q_OR
);
2755 "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel");
2757 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2759 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2767 bpf_error("illegal modifier of 'gateway'");
2773 gen_proto_abbrev(proto
)
2782 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2784 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2790 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2792 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2798 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2800 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2806 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2809 #ifndef IPPROTO_IGMP
2810 #define IPPROTO_IGMP 2
2814 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2817 #ifndef IPPROTO_IGRP
2818 #define IPPROTO_IGRP 9
2821 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2825 #define IPPROTO_PIM 103
2829 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2831 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2836 #ifndef IPPROTO_VRRP
2837 #define IPPROTO_VRRP 112
2841 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2845 b1
= gen_linktype(ETHERTYPE_IP
);
2849 b1
= gen_linktype(ETHERTYPE_ARP
);
2853 b1
= gen_linktype(ETHERTYPE_REVARP
);
2857 bpf_error("link layer applied in wrong context");
2860 b1
= gen_linktype(ETHERTYPE_ATALK
);
2864 b1
= gen_linktype(ETHERTYPE_AARP
);
2868 b1
= gen_linktype(ETHERTYPE_DN
);
2872 b1
= gen_linktype(ETHERTYPE_SCA
);
2876 b1
= gen_linktype(ETHERTYPE_LAT
);
2880 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2884 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2889 b1
= gen_linktype(ETHERTYPE_IPV6
);
2892 #ifndef IPPROTO_ICMPV6
2893 #define IPPROTO_ICMPV6 58
2896 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2901 #define IPPROTO_AH 51
2904 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2906 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2912 #define IPPROTO_ESP 50
2915 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2917 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2923 b1
= gen_linktype(LLCSAP_ISONS
);
2927 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2931 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2934 case Q_ISIS_L1
: /* all IS-IS Level1 PDU-Types */
2935 b0
= gen_proto(ISIS_L1_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_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2940 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2942 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2946 case Q_ISIS_L2
: /* all IS-IS Level2 PDU-Types */
2947 b0
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2948 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2950 b0
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2952 b0
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2954 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2958 case Q_ISIS_IIH
: /* all IS-IS Hello PDU-Types */
2959 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2960 b1
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2962 b0
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
);
2967 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2968 b1
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2973 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2974 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2976 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2978 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2983 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2984 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2989 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2990 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2995 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
2999 b1
= gen_linktype(LLCSAP_8021D
);
3003 b1
= gen_linktype(LLCSAP_IPX
);
3007 b1
= gen_linktype(LLCSAP_NETBEUI
);
3016 static struct block
*
3023 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
3024 s
->s
.k
= off_nl
+ 6;
3025 b
= new_block(JMP(BPF_JSET
));
3033 static struct block
*
3034 gen_portatom(off
, v
)
3041 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3044 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
3045 s
->next
->s
.k
= off_nl
+ off
;
3047 b
= new_block(JMP(BPF_JEQ
));
3055 static struct block
*
3056 gen_portatom6(off
, v
)
3060 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
3065 gen_portop(port
, proto
, dir
)
3066 int port
, proto
, dir
;
3068 struct block
*b0
, *b1
, *tmp
;
3070 /* ip proto 'proto' */
3071 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
3077 b1
= gen_portatom(0, (bpf_int32
)port
);
3081 b1
= gen_portatom(2, (bpf_int32
)port
);
3086 tmp
= gen_portatom(0, (bpf_int32
)port
);
3087 b1
= gen_portatom(2, (bpf_int32
)port
);
3092 tmp
= gen_portatom(0, (bpf_int32
)port
);
3093 b1
= gen_portatom(2, (bpf_int32
)port
);
3105 static struct block
*
3106 gen_port(port
, ip_proto
, dir
)
3111 struct block
*b0
, *b1
, *tmp
;
3116 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3117 * not LLC encapsulation with LLCSAP_IP.
3119 * For IEEE 802 networks - which includes 802.5 token ring
3120 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3121 * says that SNAP encapsulation is used, not LLC encapsulation
3124 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3125 * RFC 2225 say that SNAP encapsulation is used, not LLC
3126 * encapsulation with LLCSAP_IP.
3128 * So we always check for ETHERTYPE_IP.
3130 b0
= gen_linktype(ETHERTYPE_IP
);
3136 b1
= gen_portop(port
, ip_proto
, dir
);
3140 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
3141 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
3143 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
3156 gen_portop6(port
, proto
, dir
)
3157 int port
, proto
, dir
;
3159 struct block
*b0
, *b1
, *tmp
;
3161 /* ip proto 'proto' */
3162 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
3166 b1
= gen_portatom6(0, (bpf_int32
)port
);
3170 b1
= gen_portatom6(2, (bpf_int32
)port
);
3175 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3176 b1
= gen_portatom6(2, (bpf_int32
)port
);
3181 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3182 b1
= gen_portatom6(2, (bpf_int32
)port
);
3194 static struct block
*
3195 gen_port6(port
, ip_proto
, dir
)
3200 struct block
*b0
, *b1
, *tmp
;
3202 /* ether proto ip */
3203 b0
= gen_linktype(ETHERTYPE_IPV6
);
3209 b1
= gen_portop6(port
, ip_proto
, dir
);
3213 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
3214 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
3216 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
3229 lookup_proto(name
, proto
)
3230 register const char *name
;
3240 v
= pcap_nametoproto(name
);
3241 if (v
== PROTO_UNDEF
)
3242 bpf_error("unknown ip proto '%s'", name
);
3246 /* XXX should look up h/w protocol type based on linktype */
3247 v
= pcap_nametoeproto(name
);
3248 if (v
== PROTO_UNDEF
)
3249 bpf_error("unknown ether proto '%s'", name
);
3253 if (strcmp(name
, "esis") == 0)
3255 else if (strcmp(name
, "isis") == 0)
3257 else if (strcmp(name
, "clnp") == 0)
3260 bpf_error("unknown osi proto '%s'", name
);
3280 static struct block
*
3281 gen_protochain(v
, proto
, dir
)
3286 #ifdef NO_PROTOCHAIN
3287 return gen_proto(v
, proto
, dir
);
3289 struct block
*b0
, *b
;
3290 struct slist
*s
[100];
3291 int fix2
, fix3
, fix4
, fix5
;
3292 int ahcheck
, again
, end
;
3294 int reg2
= alloc_reg();
3296 memset(s
, 0, sizeof(s
));
3297 fix2
= fix3
= fix4
= fix5
= 0;
3304 b0
= gen_protochain(v
, Q_IP
, dir
);
3305 b
= gen_protochain(v
, Q_IPV6
, dir
);
3309 bpf_error("bad protocol applied for 'protochain'");
3313 no_optimize
= 1; /*this code is not compatible with optimzer yet */
3316 * s[0] is a dummy entry to protect other BPF insn from damaged
3317 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
3318 * hard to find interdependency made by jump table fixup.
3321 s
[i
] = new_stmt(0); /*dummy*/
3326 b0
= gen_linktype(ETHERTYPE_IP
);
3329 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3330 s
[i
]->s
.k
= off_nl
+ 9;
3332 /* X = ip->ip_hl << 2 */
3333 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3339 b0
= gen_linktype(ETHERTYPE_IPV6
);
3341 /* A = ip6->ip_nxt */
3342 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3343 s
[i
]->s
.k
= off_nl
+ 6;
3345 /* X = sizeof(struct ip6_hdr) */
3346 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
3352 bpf_error("unsupported proto to gen_protochain");
3356 /* again: if (A == v) goto end; else fall through; */
3358 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3360 s
[i
]->s
.jt
= NULL
; /*later*/
3361 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3365 #ifndef IPPROTO_NONE
3366 #define IPPROTO_NONE 59
3368 /* if (A == IPPROTO_NONE) goto end */
3369 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3370 s
[i
]->s
.jt
= NULL
; /*later*/
3371 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3372 s
[i
]->s
.k
= IPPROTO_NONE
;
3373 s
[fix5
]->s
.jf
= s
[i
];
3378 if (proto
== Q_IPV6
) {
3379 int v6start
, v6end
, v6advance
, j
;
3382 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
3383 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3384 s
[i
]->s
.jt
= NULL
; /*later*/
3385 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3386 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
3387 s
[fix2
]->s
.jf
= s
[i
];
3389 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
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
; /*update in next stmt*/
3393 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
3395 /* if (A == IPPROTO_ROUTING) goto v6advance */
3396 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3397 s
[i
]->s
.jt
= NULL
; /*later*/
3398 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3399 s
[i
]->s
.k
= IPPROTO_ROUTING
;
3401 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
3402 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3403 s
[i
]->s
.jt
= NULL
; /*later*/
3404 s
[i
]->s
.jf
= NULL
; /*later*/
3405 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
3416 * X = X + (P[X + 1] + 1) * 8;
3419 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3421 /* A = P[X + packet head] */
3422 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3426 s
[i
] = new_stmt(BPF_ST
);
3430 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3433 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3437 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3439 /* A = P[X + packet head]; */
3440 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3444 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3448 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3452 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3455 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3459 /* goto again; (must use BPF_JA for backward jump) */
3460 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3461 s
[i
]->s
.k
= again
- i
- 1;
3462 s
[i
- 1]->s
.jf
= s
[i
];
3466 for (j
= v6start
; j
<= v6end
; j
++)
3467 s
[j
]->s
.jt
= s
[v6advance
];
3472 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3474 s
[fix2
]->s
.jf
= s
[i
];
3480 /* if (A == IPPROTO_AH) then fall through; else goto end; */
3481 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3482 s
[i
]->s
.jt
= NULL
; /*later*/
3483 s
[i
]->s
.jf
= NULL
; /*later*/
3484 s
[i
]->s
.k
= IPPROTO_AH
;
3486 s
[fix3
]->s
.jf
= s
[ahcheck
];
3493 * X = X + (P[X + 1] + 2) * 4;
3496 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3498 /* A = P[X + packet head]; */
3499 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3503 s
[i
] = new_stmt(BPF_ST
);
3507 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3510 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3514 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3516 /* A = P[X + packet head] */
3517 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3521 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3525 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3529 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3532 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3536 /* goto again; (must use BPF_JA for backward jump) */
3537 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3538 s
[i
]->s
.k
= again
- i
- 1;
3543 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3545 s
[fix2
]->s
.jt
= s
[end
];
3546 s
[fix4
]->s
.jf
= s
[end
];
3547 s
[fix5
]->s
.jt
= s
[end
];
3554 for (i
= 0; i
< max
- 1; i
++)
3555 s
[i
]->next
= s
[i
+ 1];
3556 s
[max
- 1]->next
= NULL
;
3561 b
= new_block(JMP(BPF_JEQ
));
3562 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
3572 static struct block
*
3573 gen_proto(v
, proto
, dir
)
3578 struct block
*b0
, *b1
;
3580 if (dir
!= Q_DEFAULT
)
3581 bpf_error("direction applied to 'proto'");
3586 b0
= gen_proto(v
, Q_IP
, dir
);
3587 b1
= gen_proto(v
, Q_IPV6
, dir
);
3595 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3596 * not LLC encapsulation with LLCSAP_IP.
3598 * For IEEE 802 networks - which includes 802.5 token ring
3599 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3600 * says that SNAP encapsulation is used, not LLC encapsulation
3603 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3604 * RFC 2225 say that SNAP encapsulation is used, not LLC
3605 * encapsulation with LLCSAP_IP.
3607 * So we always check for ETHERTYPE_IP.
3609 b0
= gen_linktype(ETHERTYPE_IP
);
3611 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
3613 b1
= gen_protochain(v
, Q_IP
);
3623 * Frame Relay packets typically have an OSI
3624 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3625 * generates code to check for all the OSI
3626 * NLPIDs, so calling it and then adding a check
3627 * for the particular NLPID for which we're
3628 * looking is bogus, as we can just check for
3631 * What we check for is the NLPID and a frame
3632 * control field value of UI, i.e. 0x03 followed
3635 * XXX - assumes a 2-byte Frame Relay header with
3636 * DLCI and flags. What if the address is longer?
3638 * XXX - what about SNAP-encapsulated frames?
3640 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3645 * Cisco uses an Ethertype lookalike - for OSI,
3648 b0
= gen_linktype(LLCSAP_ISONS
<<8 | LLCSAP_ISONS
);
3649 /* OSI in C-HDLC is stuffed with a fudge byte */
3650 b1
= gen_cmp(off_nl_nosnap
+1, BPF_B
, (long)v
);
3655 b0
= gen_linktype(LLCSAP_ISONS
);
3656 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3662 b0
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
3664 * 4 is the offset of the PDU type relative to the IS-IS
3667 b1
= gen_cmp(off_nl_nosnap
+4, BPF_B
, (long)v
);
3672 bpf_error("arp does not encapsulate another protocol");
3676 bpf_error("rarp does not encapsulate another protocol");
3680 bpf_error("atalk encapsulation is not specifiable");
3684 bpf_error("decnet encapsulation is not specifiable");
3688 bpf_error("sca does not encapsulate another protocol");
3692 bpf_error("lat does not encapsulate another protocol");
3696 bpf_error("moprc does not encapsulate another protocol");
3700 bpf_error("mopdl does not encapsulate another protocol");
3704 return gen_linktype(v
);
3707 bpf_error("'udp proto' is bogus");
3711 bpf_error("'tcp proto' is bogus");
3715 bpf_error("'sctp proto' is bogus");
3719 bpf_error("'icmp proto' is bogus");
3723 bpf_error("'igmp proto' is bogus");
3727 bpf_error("'igrp proto' is bogus");
3731 bpf_error("'pim proto' is bogus");
3735 bpf_error("'vrrp proto' is bogus");
3740 b0
= gen_linktype(ETHERTYPE_IPV6
);
3742 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3744 b1
= gen_protochain(v
, Q_IPV6
);
3750 bpf_error("'icmp6 proto' is bogus");
3754 bpf_error("'ah proto' is bogus");
3757 bpf_error("'ah proto' is bogus");
3760 bpf_error("'stp proto' is bogus");
3763 bpf_error("'ipx proto' is bogus");
3766 bpf_error("'netbeui proto' is bogus");
3777 register const char *name
;
3780 int proto
= q
.proto
;
3784 bpf_u_int32 mask
, addr
;
3786 bpf_u_int32
**alist
;
3789 struct sockaddr_in
*sin
;
3790 struct sockaddr_in6
*sin6
;
3791 struct addrinfo
*res
, *res0
;
3792 struct in6_addr mask128
;
3794 struct block
*b
, *tmp
;
3795 int port
, real_proto
;
3800 addr
= pcap_nametonetaddr(name
);
3802 bpf_error("unknown network '%s'", name
);
3803 /* Left justify network addr and calculate its network mask */
3805 while (addr
&& (addr
& 0xff000000) == 0) {
3809 return gen_host(addr
, mask
, proto
, dir
);
3813 if (proto
== Q_LINK
) {
3817 eaddr
= pcap_ether_hostton(name
);
3820 "unknown ether host '%s'", name
);
3821 b
= gen_ehostop(eaddr
, dir
);
3826 eaddr
= pcap_ether_hostton(name
);
3829 "unknown FDDI host '%s'", name
);
3830 b
= gen_fhostop(eaddr
, dir
);
3835 eaddr
= pcap_ether_hostton(name
);
3838 "unknown token ring host '%s'", name
);
3839 b
= gen_thostop(eaddr
, dir
);
3843 case DLT_IEEE802_11
:
3844 eaddr
= pcap_ether_hostton(name
);
3847 "unknown 802.11 host '%s'", name
);
3848 b
= gen_wlanhostop(eaddr
, dir
);
3852 case DLT_IP_OVER_FC
:
3853 eaddr
= pcap_ether_hostton(name
);
3856 "unknown Fibre Channel host '%s'", name
);
3857 b
= gen_ipfchostop(eaddr
, dir
);
3866 * Check that the packet doesn't begin
3867 * with an LE Control marker. (We've
3868 * already generated a test for LANE.)
3870 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
,
3874 eaddr
= pcap_ether_hostton(name
);
3877 "unknown ether host '%s'", name
);
3878 b
= gen_ehostop(eaddr
, dir
);
3884 bpf_error("only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
3885 } else if (proto
== Q_DECNET
) {
3886 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3888 * I don't think DECNET hosts can be multihomed, so
3889 * there is no need to build up a list of addresses
3891 return (gen_host(dn_addr
, 0, proto
, dir
));
3894 alist
= pcap_nametoaddr(name
);
3895 if (alist
== NULL
|| *alist
== NULL
)
3896 bpf_error("unknown host '%s'", name
);
3898 if (off_linktype
== (u_int
)-1 && tproto
== Q_DEFAULT
)
3900 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3902 tmp
= gen_host(**alist
++, 0xffffffff,
3909 memset(&mask128
, 0xff, sizeof(mask128
));
3910 res0
= res
= pcap_nametoaddrinfo(name
);
3912 bpf_error("unknown host '%s'", name
);
3914 tproto
= tproto6
= proto
;
3915 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3919 for (res
= res0
; res
; res
= res
->ai_next
) {
3920 switch (res
->ai_family
) {
3922 if (tproto
== Q_IPV6
)
3925 sin
= (struct sockaddr_in
*)
3927 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3928 0xffffffff, tproto
, dir
);
3931 if (tproto6
== Q_IP
)
3934 sin6
= (struct sockaddr_in6
*)
3936 tmp
= gen_host6(&sin6
->sin6_addr
,
3937 &mask128
, tproto6
, dir
);
3948 bpf_error("unknown host '%s'%s", name
,
3949 (proto
== Q_DEFAULT
)
3951 : " for specified address family");
3958 if (proto
!= Q_DEFAULT
&&
3959 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3960 bpf_error("illegal qualifier of 'port'");
3961 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3962 bpf_error("unknown port '%s'", name
);
3963 if (proto
== Q_UDP
) {
3964 if (real_proto
== IPPROTO_TCP
)
3965 bpf_error("port '%s' is tcp", name
);
3966 else if (real_proto
== IPPROTO_SCTP
)
3967 bpf_error("port '%s' is sctp", name
);
3969 /* override PROTO_UNDEF */
3970 real_proto
= IPPROTO_UDP
;
3972 if (proto
== Q_TCP
) {
3973 if (real_proto
== IPPROTO_UDP
)
3974 bpf_error("port '%s' is udp", name
);
3976 else if (real_proto
== IPPROTO_SCTP
)
3977 bpf_error("port '%s' is sctp", name
);
3979 /* override PROTO_UNDEF */
3980 real_proto
= IPPROTO_TCP
;
3982 if (proto
== Q_SCTP
) {
3983 if (real_proto
== IPPROTO_UDP
)
3984 bpf_error("port '%s' is udp", name
);
3986 else if (real_proto
== IPPROTO_TCP
)
3987 bpf_error("port '%s' is tcp", name
);
3989 /* override PROTO_UNDEF */
3990 real_proto
= IPPROTO_SCTP
;
3993 return gen_port(port
, real_proto
, dir
);
3997 b
= gen_port(port
, real_proto
, dir
);
3998 gen_or(gen_port6(port
, real_proto
, dir
), b
);
4005 eaddr
= pcap_ether_hostton(name
);
4007 bpf_error("unknown ether host: %s", name
);
4009 alist
= pcap_nametoaddr(name
);
4010 if (alist
== NULL
|| *alist
== NULL
)
4011 bpf_error("unknown host '%s'", name
);
4012 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
4016 bpf_error("'gateway' not supported in this configuration");
4020 real_proto
= lookup_proto(name
, proto
);
4021 if (real_proto
>= 0)
4022 return gen_proto(real_proto
, proto
, dir
);
4024 bpf_error("unknown protocol: %s", name
);
4027 real_proto
= lookup_proto(name
, proto
);
4028 if (real_proto
>= 0)
4029 return gen_protochain(real_proto
, proto
, dir
);
4031 bpf_error("unknown protocol: %s", name
);
4043 gen_mcode(s1
, s2
, masklen
, q
)
4044 register const char *s1
, *s2
;
4045 register int masklen
;
4048 register int nlen
, mlen
;
4051 nlen
= __pcap_atoin(s1
, &n
);
4052 /* Promote short ipaddr */
4056 mlen
= __pcap_atoin(s2
, &m
);
4057 /* Promote short ipaddr */
4060 bpf_error("non-network bits set in \"%s mask %s\"",
4063 /* Convert mask len to mask */
4065 bpf_error("mask length must be <= 32");
4066 m
= 0xffffffff << (32 - masklen
);
4068 bpf_error("non-network bits set in \"%s/%d\"",
4075 return gen_host(n
, m
, q
.proto
, q
.dir
);
4078 bpf_error("Mask syntax for networks only");
4085 register const char *s
;
4090 int proto
= q
.proto
;
4096 else if (q
.proto
== Q_DECNET
)
4097 vlen
= __pcap_atodn(s
, &v
);
4099 vlen
= __pcap_atoin(s
, &v
);
4106 if (proto
== Q_DECNET
)
4107 return gen_host(v
, 0, proto
, dir
);
4108 else if (proto
== Q_LINK
) {
4109 bpf_error("illegal link layer address");
4112 if (s
== NULL
&& q
.addr
== Q_NET
) {
4113 /* Promote short net number */
4114 while (v
&& (v
& 0xff000000) == 0) {
4119 /* Promote short ipaddr */
4123 return gen_host(v
, mask
, proto
, dir
);
4128 proto
= IPPROTO_UDP
;
4129 else if (proto
== Q_TCP
)
4130 proto
= IPPROTO_TCP
;
4131 else if (proto
== Q_SCTP
)
4132 proto
= IPPROTO_SCTP
;
4133 else if (proto
== Q_DEFAULT
)
4134 proto
= PROTO_UNDEF
;
4136 bpf_error("illegal qualifier of 'port'");
4139 return gen_port((int)v
, proto
, dir
);
4143 b
= gen_port((int)v
, proto
, dir
);
4144 gen_or(gen_port6((int)v
, proto
, dir
), b
);
4150 bpf_error("'gateway' requires a name");
4154 return gen_proto((int)v
, proto
, dir
);
4157 return gen_protochain((int)v
, proto
, dir
);
4172 gen_mcode6(s1
, s2
, masklen
, q
)
4173 register const char *s1
, *s2
;
4174 register int masklen
;
4177 struct addrinfo
*res
;
4178 struct in6_addr
*addr
;
4179 struct in6_addr mask
;
4184 bpf_error("no mask %s supported", s2
);
4186 res
= pcap_nametoaddrinfo(s1
);
4188 bpf_error("invalid ip6 address %s", s1
);
4190 bpf_error("%s resolved to multiple address", s1
);
4191 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
4193 if (sizeof(mask
) * 8 < masklen
)
4194 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
4195 memset(&mask
, 0, sizeof(mask
));
4196 memset(&mask
, 0xff, masklen
/ 8);
4198 mask
.s6_addr
[masklen
/ 8] =
4199 (0xff << (8 - masklen
% 8)) & 0xff;
4202 a
= (u_int32_t
*)addr
;
4203 m
= (u_int32_t
*)&mask
;
4204 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
4205 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
4206 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
4214 bpf_error("Mask syntax for networks only");
4218 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
4223 bpf_error("invalid qualifier against IPv6 address");
4231 register const u_char
*eaddr
;
4234 struct block
*b
, *tmp
;
4236 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4237 if (linktype
== DLT_EN10MB
)
4238 return gen_ehostop(eaddr
, (int)q
.dir
);
4239 if (linktype
== DLT_FDDI
)
4240 return gen_fhostop(eaddr
, (int)q
.dir
);
4241 if (linktype
== DLT_IEEE802
)
4242 return gen_thostop(eaddr
, (int)q
.dir
);
4243 if (linktype
== DLT_IEEE802_11
)
4244 return gen_wlanhostop(eaddr
, (int)q
.dir
);
4245 if (linktype
== DLT_SUNATM
&& is_lane
) {
4247 * Check that the packet doesn't begin with an
4248 * LE Control marker. (We've already generated
4251 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4255 * Now check the MAC address.
4257 b
= gen_ehostop(eaddr
, (int)q
.dir
);
4261 if (linktype
== DLT_IP_OVER_FC
)
4262 return gen_ipfchostop(eaddr
, (int)q
.dir
);
4263 bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
4265 bpf_error("ethernet address used in non-ether expression");
4271 struct slist
*s0
, *s1
;
4274 * This is definitely not the best way to do this, but the
4275 * lists will rarely get long.
4282 static struct slist
*
4288 s
= new_stmt(BPF_LDX
|BPF_MEM
);
4293 static struct slist
*
4299 s
= new_stmt(BPF_LD
|BPF_MEM
);
4305 gen_load(proto
, index
, size
)
4310 struct slist
*s
, *tmp
;
4312 int regno
= alloc_reg();
4314 free_reg(index
->regno
);
4318 bpf_error("data size must be 1, 2, or 4");
4334 bpf_error("unsupported index operation");
4338 * XXX - what about ATM LANE? Should the index be
4339 * relative to the beginning of the AAL5 frame, so
4340 * that 0 refers to the beginning of the LE Control
4341 * field, or relative to the beginning of the LAN
4342 * frame, so that 0 refers, for Ethernet LANE, to
4343 * the beginning of the destination address?
4345 s
= xfer_to_x(index
);
4346 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4348 sappend(index
->s
, s
);
4363 /* XXX Note that we assume a fixed link header here. */
4364 s
= xfer_to_x(index
);
4365 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4368 sappend(index
->s
, s
);
4370 b
= gen_proto_abbrev(proto
);
4372 gen_and(index
->b
, b
);
4384 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
4386 sappend(s
, xfer_to_a(index
));
4387 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
4388 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
4389 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
4391 sappend(index
->s
, s
);
4393 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
4395 gen_and(index
->b
, b
);
4397 gen_and(gen_proto_abbrev(Q_IP
), b
);
4403 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
4407 index
->regno
= regno
;
4408 s
= new_stmt(BPF_ST
);
4410 sappend(index
->s
, s
);
4416 gen_relation(code
, a0
, a1
, reversed
)
4418 struct arth
*a0
, *a1
;
4421 struct slist
*s0
, *s1
, *s2
;
4422 struct block
*b
, *tmp
;
4426 if (code
== BPF_JEQ
) {
4427 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
4428 b
= new_block(JMP(code
));
4432 b
= new_block(BPF_JMP
|code
|BPF_X
);
4438 sappend(a0
->s
, a1
->s
);
4442 free_reg(a0
->regno
);
4443 free_reg(a1
->regno
);
4445 /* 'and' together protocol checks */
4448 gen_and(a0
->b
, tmp
= a1
->b
);
4464 int regno
= alloc_reg();
4465 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
4468 s
= new_stmt(BPF_LD
|BPF_LEN
);
4469 s
->next
= new_stmt(BPF_ST
);
4470 s
->next
->s
.k
= regno
;
4485 a
= (struct arth
*)newchunk(sizeof(*a
));
4489 s
= new_stmt(BPF_LD
|BPF_IMM
);
4491 s
->next
= new_stmt(BPF_ST
);
4507 s
= new_stmt(BPF_ALU
|BPF_NEG
);
4510 s
= new_stmt(BPF_ST
);
4518 gen_arth(code
, a0
, a1
)
4520 struct arth
*a0
, *a1
;
4522 struct slist
*s0
, *s1
, *s2
;
4526 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
4531 sappend(a0
->s
, a1
->s
);
4533 free_reg(a0
->regno
);
4534 free_reg(a1
->regno
);
4536 s0
= new_stmt(BPF_ST
);
4537 a0
->regno
= s0
->s
.k
= alloc_reg();
4544 * Here we handle simple allocation of the scratch registers.
4545 * If too many registers are alloc'd, the allocator punts.
4547 static int regused
[BPF_MEMWORDS
];
4551 * Return the next free register.
4556 int n
= BPF_MEMWORDS
;
4559 if (regused
[curreg
])
4560 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
4562 regused
[curreg
] = 1;
4566 bpf_error("too many registers needed to evaluate expression");
4571 * Return a register to the table so it can
4581 static struct block
*
4588 s
= new_stmt(BPF_LD
|BPF_LEN
);
4589 b
= new_block(JMP(jmp
));
4600 return gen_len(BPF_JGE
, n
);
4604 * Actually, this is less than or equal.
4612 b
= gen_len(BPF_JGT
, n
);
4619 gen_byteop(op
, idx
, val
)
4630 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4633 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4634 b
->s
.code
= JMP(BPF_JGE
);
4639 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4640 b
->s
.code
= JMP(BPF_JGT
);
4644 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
4648 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
4652 b
= new_block(JMP(BPF_JEQ
));
4659 static u_char abroadcast
[] = { 0x0 };
4662 gen_broadcast(proto
)
4665 bpf_u_int32 hostmask
;
4666 struct block
*b0
, *b1
, *b2
;
4667 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4673 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4674 return gen_ahostop(abroadcast
, Q_DST
);
4675 if (linktype
== DLT_EN10MB
)
4676 return gen_ehostop(ebroadcast
, Q_DST
);
4677 if (linktype
== DLT_FDDI
)
4678 return gen_fhostop(ebroadcast
, Q_DST
);
4679 if (linktype
== DLT_IEEE802
)
4680 return gen_thostop(ebroadcast
, Q_DST
);
4681 if (linktype
== DLT_IEEE802_11
)
4682 return gen_wlanhostop(ebroadcast
, Q_DST
);
4683 if (linktype
== DLT_IP_OVER_FC
)
4684 return gen_ipfchostop(ebroadcast
, Q_DST
);
4685 if (linktype
== DLT_SUNATM
&& is_lane
) {
4687 * Check that the packet doesn't begin with an
4688 * LE Control marker. (We've already generated
4691 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4695 * Now check the MAC address.
4697 b0
= gen_ehostop(ebroadcast
, Q_DST
);
4701 bpf_error("not a broadcast link");
4705 b0
= gen_linktype(ETHERTYPE_IP
);
4706 hostmask
= ~netmask
;
4707 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
4708 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
4709 (bpf_int32
)(~0 & hostmask
), hostmask
);
4714 bpf_error("only link-layer/IP broadcast filters supported");
4718 * Generate code to test the low-order bit of a MAC address (that's
4719 * the bottom bit of the *first* byte).
4721 static struct block
*
4722 gen_mac_multicast(offset
)
4725 register struct block
*b0
;
4726 register struct slist
*s
;
4728 /* link[offset] & 1 != 0 */
4729 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4731 b0
= new_block(JMP(BPF_JSET
));
4738 gen_multicast(proto
)
4741 register struct block
*b0
, *b1
, *b2
;
4742 register struct slist
*s
;
4748 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4749 /* all ARCnet multicasts use the same address */
4750 return gen_ahostop(abroadcast
, Q_DST
);
4752 if (linktype
== DLT_EN10MB
) {
4753 /* ether[0] & 1 != 0 */
4754 return gen_mac_multicast(0);
4757 if (linktype
== DLT_FDDI
) {
4759 * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX
4761 * XXX - was that referring to bit-order issues?
4763 /* fddi[1] & 1 != 0 */
4764 return gen_mac_multicast(1);
4767 if (linktype
== DLT_IEEE802
) {
4768 /* tr[2] & 1 != 0 */
4769 return gen_mac_multicast(2);
4772 if (linktype
== DLT_IEEE802_11
) {
4776 * For control frames, there is no DA.
4778 * For management frames, DA is at an
4779 * offset of 4 from the beginning of
4782 * For data frames, DA is at an offset
4783 * of 4 from the beginning of the packet
4784 * if To DS is clear and at an offset of
4785 * 16 from the beginning of the packet
4790 * Generate the tests to be done for data frames.
4792 * First, check for To DS set, i.e. "link[1] & 0x01".
4794 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4796 b1
= new_block(JMP(BPF_JSET
));
4797 b1
->s
.k
= 0x01; /* To DS */
4801 * If To DS is set, the DA is at 16.
4803 b0
= gen_mac_multicast(16);
4807 * Now, check for To DS not set, i.e. check
4808 * "!(link[1] & 0x01)".
4810 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4812 b2
= new_block(JMP(BPF_JSET
));
4813 b2
->s
.k
= 0x01; /* To DS */
4818 * If To DS is not set, the DA is at 4.
4820 b1
= gen_mac_multicast(4);
4824 * Now OR together the last two checks. That gives
4825 * the complete set of checks for data frames.
4830 * Now check for a data frame.
4831 * I.e, check "link[0] & 0x08".
4833 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4835 b1
= new_block(JMP(BPF_JSET
));
4840 * AND that with the checks done for data frames.
4845 * If the high-order bit of the type value is 0, this
4846 * is a management frame.
4847 * I.e, check "!(link[0] & 0x08)".
4849 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4851 b2
= new_block(JMP(BPF_JSET
));
4857 * For management frames, the DA is at 4.
4859 b1
= gen_mac_multicast(4);
4863 * OR that with the checks done for data frames.
4864 * That gives the checks done for management and
4870 * If the low-order bit of the type value is 1,
4871 * this is either a control frame or a frame
4872 * with a reserved type, and thus not a
4875 * I.e., check "!(link[0] & 0x04)".
4877 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4879 b1
= new_block(JMP(BPF_JSET
));
4885 * AND that with the checks for data and management
4892 if (linktype
== DLT_IP_OVER_FC
) {
4893 b0
= gen_mac_multicast(2);
4897 if (linktype
== DLT_SUNATM
&& is_lane
) {
4899 * Check that the packet doesn't begin with an
4900 * LE Control marker. (We've already generated
4903 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4906 /* ether[off_mac] & 1 != 0 */
4907 b0
= gen_mac_multicast(off_mac
);
4912 /* Link not known to support multicasts */
4916 b0
= gen_linktype(ETHERTYPE_IP
);
4917 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4918 b1
->s
.code
= JMP(BPF_JGE
);
4924 b0
= gen_linktype(ETHERTYPE_IPV6
);
4925 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4930 bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
4934 * generate command for inbound/outbound. It's here so we can
4935 * make it link-type specific. 'dir' = 0 implies "inbound",
4936 * = 1 implies "outbound".
4942 register struct block
*b0
;
4945 * Only some data link types support inbound/outbound qualifiers.
4949 b0
= gen_relation(BPF_JEQ
,
4950 gen_load(Q_LINK
, gen_loadi(0), 1),
4958 * Match packets sent by this machine.
4960 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_OUTGOING
);
4963 * Match packets sent to this machine.
4964 * (No broadcast or multicast packets, or
4965 * packets sent to some other machine and
4966 * received promiscuously.)
4968 * XXX - packets sent to other machines probably
4969 * shouldn't be matched, but what about broadcast
4970 * or multicast packets we received?
4972 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_HOST
);
4977 b0
= gen_cmp(26, BPF_H
,
4978 (bpf_int32
)((dir
== 0) ? PF_IN
: PF_OUT
));
4982 bpf_error("inbound/outbound not supported on linktype %d",
4990 /* PF firewall log matched interface */
4992 gen_pf_ifname(const char *ifname
)
4994 if (linktype
!= DLT_PFLOG
) {
4995 bpf_error("ifname supported only for DLT_PFLOG");
4998 if (strlen(ifname
) >= 16) {
4999 bpf_error("ifname interface names can't be larger than 16 characters");
5002 return (gen_bcmp(4, strlen(ifname
), (const u_char
*)ifname
));
5006 /* PF firewall log rule number */
5010 if (linktype
!= DLT_PFLOG
) {
5011 bpf_error("rnr supported only for DLT_PFLOG");
5015 return (gen_cmp(20, BPF_H
, (bpf_int32
)rnr
));
5018 /* PF firewall log reason code */
5020 gen_pf_reason(int reason
)
5022 if (linktype
!= DLT_PFLOG
) {
5023 bpf_error("reason supported only for DLT_PFLOG");
5027 return (gen_cmp(22, BPF_H
, (bpf_int32
)reason
));
5030 /* PF firewall log action */
5032 gen_pf_action(int action
)
5034 if (linktype
!= DLT_PFLOG
) {
5035 bpf_error("action supported only for DLT_PFLOG");
5039 return (gen_cmp(24, BPF_H
, (bpf_int32
)action
));
5044 register const u_char
*eaddr
;
5047 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
5048 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
5049 return gen_ahostop(eaddr
, (int)q
.dir
);
5051 bpf_error("ARCnet address used in non-arc expression");
5055 static struct block
*
5056 gen_ahostop(eaddr
, dir
)
5057 register const u_char
*eaddr
;
5060 register struct block
*b0
, *b1
;
5063 /* src comes first, different from Ethernet */
5065 return gen_bcmp(0, 1, eaddr
);
5068 return gen_bcmp(1, 1, eaddr
);
5071 b0
= gen_ahostop(eaddr
, Q_SRC
);
5072 b1
= gen_ahostop(eaddr
, Q_DST
);
5078 b0
= gen_ahostop(eaddr
, Q_SRC
);
5079 b1
= gen_ahostop(eaddr
, Q_DST
);
5088 * support IEEE 802.1Q VLAN trunk over ethernet
5097 * Change the offsets to point to the type and data fields within
5098 * the VLAN packet. This is somewhat of a kludge.
5100 if (orig_nl
== (u_int
)-1) {
5101 orig_linktype
= off_linktype
; /* save original values */
5103 orig_nl_nosnap
= off_nl_nosnap
;
5114 bpf_error("no VLAN support for data link type %d",
5120 /* check for VLAN */
5121 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
5123 /* If a specific VLAN is requested, check VLAN id */
5124 if (vlan_num
>= 0) {
5127 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
5136 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
5148 bpf_error("'vpi' supported only on raw ATM");
5149 if (off_vpi
== (u_int
)-1)
5151 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
5152 (u_int
)jvalue
, reverse
);
5157 bpf_error("'vci' supported only on raw ATM");
5158 if (off_vci
== (u_int
)-1)
5160 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
5161 (u_int
)jvalue
, reverse
);
5165 if (off_proto
== (u_int
)-1)
5166 abort(); /* XXX - this isn't on FreeBSD */
5167 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
5168 (u_int
)jvalue
, reverse
);
5172 if (off_payload
== (u_int
)-1)
5174 b0
= gen_ncmp(BPF_B
, off_payload
+ MSG_TYPE_POS
, 0xffffffff,
5175 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
5180 bpf_error("'callref' supported only on raw ATM");
5181 if (off_proto
== (u_int
)-1)
5183 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
5184 (u_int
)jvalue
, reverse
);
5194 gen_atmtype_abbrev(type
)
5197 struct block
*b0
, *b1
;
5202 /* Get all packets in Meta signalling Circuit */
5204 bpf_error("'metac' supported only on raw ATM");
5205 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5206 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
5211 /* Get all packets in Broadcast Circuit*/
5213 bpf_error("'bcc' supported only on raw ATM");
5214 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5215 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
5220 /* Get all cells in Segment OAM F4 circuit*/
5222 bpf_error("'oam4sc' supported only on raw ATM");
5223 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5224 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5229 /* Get all cells in End-to-End OAM F4 Circuit*/
5231 bpf_error("'oam4ec' supported only on raw ATM");
5232 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5233 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5238 /* Get all packets in connection Signalling Circuit */
5240 bpf_error("'sc' supported only on raw ATM");
5241 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5242 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
5247 /* Get all packets in ILMI Circuit */
5249 bpf_error("'ilmic' supported only on raw ATM");
5250 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5251 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
5256 /* Get all LANE packets */
5258 bpf_error("'lane' supported only on raw ATM");
5259 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
5262 * Arrange that all subsequent tests assume LANE
5263 * rather than LLC-encapsulated packets, and set
5264 * the offsets appropriately for LANE-encapsulated
5267 * "off_mac" is the offset of the Ethernet header,
5268 * which is 2 bytes past the ATM pseudo-header
5269 * (skipping the pseudo-header and 2-byte LE Client
5270 * field). The other offsets are Ethernet offsets
5271 * relative to "off_mac".
5274 off_mac
= off_payload
+ 2; /* MAC header */
5275 off_linktype
= off_mac
+ 12;
5276 off_nl
= off_mac
+ 14; /* Ethernet II */
5277 off_nl_nosnap
= off_mac
+ 17; /* 802.3+802.2 */
5281 /* Get all LLC-encapsulated packets */
5283 bpf_error("'llc' supported only on raw ATM");
5284 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
5295 static struct block
*
5296 gen_msg_abbrev(type
)
5302 * Q.2931 signalling protocol messages for handling virtual circuits
5303 * establishment and teardown
5308 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
5312 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
5316 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
5320 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
5324 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
5327 case A_RELEASE_DONE
:
5328 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
5338 gen_atmmulti_abbrev(type
)
5341 struct block
*b0
, *b1
;
5347 bpf_error("'oam' supported only on raw ATM");
5348 b1
= gen_atmmulti_abbrev(A_OAMF4
);
5353 bpf_error("'oamf4' supported only on raw ATM");
5355 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5356 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5358 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5364 * Get Q.2931 signalling messages for switched
5365 * virtual connection
5368 bpf_error("'connectmsg' supported only on raw ATM");
5369 b0
= gen_msg_abbrev(A_SETUP
);
5370 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5372 b0
= gen_msg_abbrev(A_CONNECT
);
5374 b0
= gen_msg_abbrev(A_CONNECTACK
);
5376 b0
= gen_msg_abbrev(A_RELEASE
);
5378 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5380 b0
= gen_atmtype_abbrev(A_SC
);
5386 bpf_error("'metaconnect' supported only on raw ATM");
5387 b0
= gen_msg_abbrev(A_SETUP
);
5388 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5390 b0
= gen_msg_abbrev(A_CONNECT
);
5392 b0
= gen_msg_abbrev(A_RELEASE
);
5394 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5396 b0
= gen_atmtype_abbrev(A_METAC
);