]>
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.196 2004-01-14 01:09:03 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.
969 * Currently, only raw "link[N:M]" filtering is supported.
976 bpf_error("unknown data link type %d", linktype
);
980 static struct block
*
987 s
= new_stmt(BPF_LD
|BPF_IMM
);
989 b
= new_block(JMP(BPF_JEQ
));
995 static inline struct block
*
998 return gen_uncond(1);
1001 static inline struct block
*
1004 return gen_uncond(0);
1008 * Byte-swap a 32-bit number.
1009 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
1010 * big-endian platforms.)
1012 #define SWAPLONG(y) \
1013 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
1015 static struct block
*
1016 gen_ether_linktype(proto
)
1019 struct block
*b0
, *b1
;
1025 * OSI protocols always use 802.2 encapsulation.
1026 * XXX - should we check both the DSAP and the
1027 * SSAP, like this, or should we check just the
1030 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1032 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1033 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1038 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1040 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1041 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1045 case LLCSAP_NETBEUI
:
1047 * NetBEUI always uses 802.2 encapsulation.
1048 * XXX - should we check both the DSAP and the
1049 * SSAP, like this, or should we check just the
1052 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1054 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1055 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1063 * Ethernet_II frames, which are Ethernet
1064 * frames with a frame type of ETHERTYPE_IPX;
1066 * Ethernet_802.3 frames, which are 802.3
1067 * frames (i.e., the type/length field is
1068 * a length field, <= ETHERMTU, rather than
1069 * a type field) with the first two bytes
1070 * after the Ethernet/802.3 header being
1073 * Ethernet_802.2 frames, which are 802.3
1074 * frames with an 802.2 LLC header and
1075 * with the IPX LSAP as the DSAP in the LLC
1078 * Ethernet_SNAP frames, which are 802.3
1079 * frames with an LLC header and a SNAP
1080 * header and with an OUI of 0x000000
1081 * (encapsulated Ethernet) and a protocol
1082 * ID of ETHERTYPE_IPX in the SNAP header.
1084 * XXX - should we generate the same code both
1085 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
1089 * This generates code to check both for the
1090 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
1092 b0
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1093 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)0xFFFF);
1097 * Now we add code to check for SNAP frames with
1098 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1100 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1104 * Now we generate code to check for 802.3
1105 * frames in general.
1107 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1111 * Now add the check for 802.3 frames before the
1112 * check for Ethernet_802.2 and Ethernet_802.3,
1113 * as those checks should only be done on 802.3
1114 * frames, not on Ethernet frames.
1119 * Now add the check for Ethernet_II frames, and
1120 * do that before checking for the other frame
1123 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_IPX
);
1127 case ETHERTYPE_ATALK
:
1128 case ETHERTYPE_AARP
:
1130 * EtherTalk (AppleTalk protocols on Ethernet link
1131 * layer) may use 802.2 encapsulation.
1135 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1136 * we check for an Ethernet type field less than
1137 * 1500, which means it's an 802.3 length field.
1139 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1143 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1144 * SNAP packets with an organization code of
1145 * 0x080007 (Apple, for Appletalk) and a protocol
1146 * type of ETHERTYPE_ATALK (Appletalk).
1148 * 802.2-encapsulated ETHERTYPE_AARP packets are
1149 * SNAP packets with an organization code of
1150 * 0x000000 (encapsulated Ethernet) and a protocol
1151 * type of ETHERTYPE_AARP (Appletalk ARP).
1153 if (proto
== ETHERTYPE_ATALK
)
1154 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1155 else /* proto == ETHERTYPE_AARP */
1156 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1160 * Check for Ethernet encapsulation (Ethertalk
1161 * phase 1?); we just check for the Ethernet
1164 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1170 if (proto
<= ETHERMTU
) {
1172 * This is an LLC SAP value, so the frames
1173 * that match would be 802.2 frames.
1174 * Check that the frame is an 802.2 frame
1175 * (i.e., that the length/type field is
1176 * a length field, <= ETHERMTU) and
1177 * then check the DSAP.
1179 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1181 b1
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)proto
);
1186 * This is an Ethernet type, so compare
1187 * the length/type field with it (if
1188 * the frame is an 802.2 frame, the length
1189 * field will be <= ETHERMTU, and, as
1190 * "proto" is > ETHERMTU, this test
1191 * will fail and the frame won't match,
1192 * which is what we want).
1194 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1199 static struct block
*
1203 struct block
*b0
, *b1
, *b2
;
1208 return gen_ether_linktype(proto
);
1215 proto
= (proto
<< 8 | LLCSAP_ISONS
);
1219 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1224 case DLT_IEEE802_11
:
1225 case DLT_PRISM_HEADER
:
1226 case DLT_IEEE802_11_RADIO
:
1229 case DLT_ATM_RFC1483
:
1231 case DLT_IP_OVER_FC
:
1232 return gen_llc(proto
);
1237 * If "is_lane" is set, check for a LANE-encapsulated
1238 * version of this protocol, otherwise check for an
1239 * LLC-encapsulated version of this protocol.
1241 * We assume LANE means Ethernet, not Token Ring.
1245 * Check that the packet doesn't begin with an
1246 * LE Control marker. (We've already generated
1249 b0
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
1253 * Now generate an Ethernet test.
1255 b1
= gen_ether_linktype(proto
);
1260 * Check for LLC encapsulation and then check the
1263 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1264 b1
= gen_llc(proto
);
1273 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1274 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1275 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1281 * OSI protocols always use 802.2 encapsulation.
1282 * XXX - should we check both the DSAP and the
1283 * LSAP, like this, or should we check just the
1286 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1287 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1288 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1292 case LLCSAP_NETBEUI
:
1294 * NetBEUI always uses 802.2 encapsulation.
1295 * XXX - should we check both the DSAP and the
1296 * LSAP, like this, or should we check just the
1299 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1300 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1301 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1307 * Ethernet_II frames, which are Ethernet
1308 * frames with a frame type of ETHERTYPE_IPX;
1310 * Ethernet_802.3 frames, which have a frame
1311 * type of LINUX_SLL_P_802_3;
1313 * Ethernet_802.2 frames, which are 802.3
1314 * frames with an 802.2 LLC header (i.e, have
1315 * a frame type of LINUX_SLL_P_802_2) and
1316 * with the IPX LSAP as the DSAP in the LLC
1319 * Ethernet_SNAP frames, which are 802.3
1320 * frames with an LLC header and a SNAP
1321 * header and with an OUI of 0x000000
1322 * (encapsulated Ethernet) and a protocol
1323 * ID of ETHERTYPE_IPX in the SNAP header.
1325 * First, do the checks on LINUX_SLL_P_802_2
1326 * frames; generate the check for either
1327 * Ethernet_802.2 or Ethernet_SNAP frames, and
1328 * then put a check for LINUX_SLL_P_802_2 frames
1331 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1332 (bpf_int32
)LLCSAP_IPX
);
1333 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1336 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1340 * Now check for 802.3 frames and OR that with
1341 * the previous test.
1343 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1347 * Now add the check for Ethernet_II frames, and
1348 * do that before checking for the other frame
1351 b0
= gen_cmp(off_linktype
, BPF_H
,
1352 (bpf_int32
)ETHERTYPE_IPX
);
1356 case ETHERTYPE_ATALK
:
1357 case ETHERTYPE_AARP
:
1359 * EtherTalk (AppleTalk protocols on Ethernet link
1360 * layer) may use 802.2 encapsulation.
1364 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1365 * we check for the 802.2 protocol type in the
1366 * "Ethernet type" field.
1368 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1371 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1372 * SNAP packets with an organization code of
1373 * 0x080007 (Apple, for Appletalk) and a protocol
1374 * type of ETHERTYPE_ATALK (Appletalk).
1376 * 802.2-encapsulated ETHERTYPE_AARP packets are
1377 * SNAP packets with an organization code of
1378 * 0x000000 (encapsulated Ethernet) and a protocol
1379 * type of ETHERTYPE_AARP (Appletalk ARP).
1381 if (proto
== ETHERTYPE_ATALK
)
1382 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1384 else /* proto == ETHERTYPE_AARP */
1385 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1390 * Check for Ethernet encapsulation (Ethertalk
1391 * phase 1?); we just check for the Ethernet
1394 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1400 if (proto
<= ETHERMTU
) {
1402 * This is an LLC SAP value, so the frames
1403 * that match would be 802.2 frames.
1404 * Check for the 802.2 protocol type
1405 * in the "Ethernet type" field, and
1406 * then check the DSAP.
1408 b0
= gen_cmp(off_linktype
, BPF_H
,
1410 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1416 * This is an Ethernet type, so compare
1417 * the length/type field with it (if
1418 * the frame is an 802.2 frame, the length
1419 * field will be <= ETHERMTU, and, as
1420 * "proto" is > ETHERMTU, this test
1421 * will fail and the frame won't match,
1422 * which is what we want).
1424 return gen_cmp(off_linktype
, BPF_H
,
1431 case DLT_SLIP_BSDOS
:
1434 * These types don't provide any type field; packets
1437 * XXX - for IPv4, check for a version number of 4, and,
1438 * for IPv6, check for a version number of 6?
1444 case ETHERTYPE_IPV6
:
1446 return gen_true(); /* always true */
1449 return gen_false(); /* always false */
1454 case DLT_PPP_SERIAL
:
1457 * We use Ethernet protocol types inside libpcap;
1458 * map them to the corresponding PPP protocol types.
1467 case ETHERTYPE_IPV6
:
1476 case ETHERTYPE_ATALK
:
1490 * I'm assuming the "Bridging PDU"s that go
1491 * over PPP are Spanning Tree Protocol
1505 * We use Ethernet protocol types inside libpcap;
1506 * map them to the corresponding PPP protocol types.
1511 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1512 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1514 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1519 case ETHERTYPE_IPV6
:
1529 case ETHERTYPE_ATALK
:
1543 * I'm assuming the "Bridging PDU"s that go
1544 * over PPP are Spanning Tree Protocol
1561 * For DLT_NULL, the link-layer header is a 32-bit
1562 * word containing an AF_ value in *host* byte order,
1563 * and for DLT_ENC, the link-layer header begins
1564 * with a 32-bit work containing an AF_ value in
1567 * In addition, if we're reading a saved capture file,
1568 * the host byte order in the capture may not be the
1569 * same as the host byte order on this machine.
1571 * For DLT_LOOP, the link-layer header is a 32-bit
1572 * word containing an AF_ value in *network* byte order.
1574 * XXX - AF_ values may, unfortunately, be platform-
1575 * dependent; for example, FreeBSD's AF_INET6 is 24
1576 * whilst NetBSD's and OpenBSD's is 26.
1578 * This means that, when reading a capture file, just
1579 * checking for our AF_INET6 value won't work if the
1580 * capture file came from another OS.
1582 * XXX - what's the byte order for DLT_PFLOG?
1591 case ETHERTYPE_IPV6
:
1598 * Not a type on which we support filtering.
1599 * XXX - support those that have AF_ values
1600 * #defined on this platform, at least?
1605 if (linktype
== DLT_NULL
|| linktype
== DLT_ENC
) {
1607 * The AF_ value is in host byte order, but
1608 * the BPF interpreter will convert it to
1609 * network byte order.
1611 * If this is a save file, and it's from a
1612 * machine with the opposite byte order to
1613 * ours, we byte-swap the AF_ value.
1615 * Then we run it through "htonl()", and
1616 * generate code to compare against the result.
1618 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1619 bpf_pcap
->sf
.swapped
)
1620 proto
= SWAPLONG(proto
);
1621 proto
= htonl(proto
);
1623 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1626 case DLT_ARCNET_LINUX
:
1628 * XXX should we check for first fragment if the protocol
1637 case ETHERTYPE_IPV6
:
1638 return (gen_cmp(off_linktype
, BPF_B
,
1639 (bpf_int32
)ARCTYPE_INET6
));
1643 b0
= gen_cmp(off_linktype
, BPF_B
,
1644 (bpf_int32
)ARCTYPE_IP
);
1645 b1
= gen_cmp(off_linktype
, BPF_B
,
1646 (bpf_int32
)ARCTYPE_IP_OLD
);
1651 b0
= gen_cmp(off_linktype
, BPF_B
,
1652 (bpf_int32
)ARCTYPE_ARP
);
1653 b1
= gen_cmp(off_linktype
, BPF_B
,
1654 (bpf_int32
)ARCTYPE_ARP_OLD
);
1658 case ETHERTYPE_REVARP
:
1659 return (gen_cmp(off_linktype
, BPF_B
,
1660 (bpf_int32
)ARCTYPE_REVARP
));
1662 case ETHERTYPE_ATALK
:
1663 return (gen_cmp(off_linktype
, BPF_B
,
1664 (bpf_int32
)ARCTYPE_ATALK
));
1670 case ETHERTYPE_ATALK
:
1679 * XXX - assumes a 2-byte Frame Relay header with
1680 * DLCI and flags. What if the address is longer?
1686 * Check for the special NLPID for IP.
1688 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1691 case ETHERTYPE_IPV6
:
1693 * Check for the special NLPID for IPv6.
1695 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1700 * Check for several OSI protocols.
1702 * Frame Relay packets typically have an OSI
1703 * NLPID at the beginning; we check for each
1706 * What we check for is the NLPID and a frame
1707 * control field of UI, i.e. 0x03 followed
1710 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1711 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1712 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1722 case DLT_LINUX_IRDA
:
1723 bpf_error("IrDA link-layer type filtering not implemented");
1726 bpf_error("DOCSIS link-layer type filtering not implemented");
1730 * All the types that have no encapsulation should either be
1731 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1732 * all packets are IP packets, or should be handled in some
1733 * special case, if none of them are (if some are and some
1734 * aren't, the lack of encapsulation is a problem, as we'd
1735 * have to find some other way of determining the packet type).
1737 * Therefore, if "off_linktype" is -1, there's an error.
1739 if (off_linktype
== (u_int
)-1)
1743 * Any type not handled above should always have an Ethernet
1744 * type at an offset of "off_linktype". (PPP is partially
1745 * handled above - the protocol type is mapped from the
1746 * Ethernet and LLC types we use internally to the corresponding
1747 * PPP type - but the PPP type is always specified by a value
1748 * at "off_linktype", so we don't have to do the code generation
1751 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1755 * Check for an LLC SNAP packet with a given organization code and
1756 * protocol type; we check the entire contents of the 802.2 LLC and
1757 * snap headers, checking for DSAP and SSAP of SNAP and a control
1758 * field of 0x03 in the LLC header, and for the specified organization
1759 * code and protocol type in the SNAP header.
1761 static struct block
*
1762 gen_snap(orgcode
, ptype
, offset
)
1763 bpf_u_int32 orgcode
;
1767 u_char snapblock
[8];
1769 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1770 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1771 snapblock
[2] = 0x03; /* control = UI */
1772 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1773 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1774 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1775 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1776 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1777 return gen_bcmp(offset
, 8, snapblock
);
1781 * Check for a given protocol value assuming an 802.2 LLC header.
1783 static struct block
*
1788 * XXX - handle token-ring variable-length header.
1793 return gen_cmp(off_linktype
, BPF_H
, (long)
1794 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1797 return gen_cmp(off_linktype
, BPF_H
, (long)
1798 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1800 case LLCSAP_NETBEUI
:
1801 return gen_cmp(off_linktype
, BPF_H
, (long)
1802 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1806 * XXX - are there ever SNAP frames for IPX on
1807 * non-Ethernet 802.x networks?
1809 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1811 case ETHERTYPE_ATALK
:
1813 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1814 * SNAP packets with an organization code of
1815 * 0x080007 (Apple, for Appletalk) and a protocol
1816 * type of ETHERTYPE_ATALK (Appletalk).
1818 * XXX - check for an organization code of
1819 * encapsulated Ethernet as well?
1821 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1825 * XXX - we don't have to check for IPX 802.3
1826 * here, but should we check for the IPX Ethertype?
1828 if (proto
<= ETHERMTU
) {
1830 * This is an LLC SAP value, so check
1833 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1836 * This is an Ethernet type; we assume that it's
1837 * unlikely that it'll appear in the right place
1838 * at random, and therefore check only the
1839 * location that would hold the Ethernet type
1840 * in a SNAP frame with an organization code of
1841 * 0x000000 (encapsulated Ethernet).
1843 * XXX - if we were to check for the SNAP DSAP and
1844 * LSAP, as per XXX, and were also to check for an
1845 * organization code of 0x000000 (encapsulated
1846 * Ethernet), we'd do
1848 * return gen_snap(0x000000, proto,
1851 * here; for now, we don't, as per the above.
1852 * I don't know whether it's worth the extra CPU
1853 * time to do the right check or not.
1855 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1860 static struct block
*
1861 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1865 u_int src_off
, dst_off
;
1867 struct block
*b0
, *b1
;
1881 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1882 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1888 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1889 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1896 b0
= gen_linktype(proto
);
1897 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1903 static struct block
*
1904 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1905 struct in6_addr
*addr
;
1906 struct in6_addr
*mask
;
1908 u_int src_off
, dst_off
;
1910 struct block
*b0
, *b1
;
1925 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1926 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1932 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1933 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1940 /* this order is important */
1941 a
= (u_int32_t
*)addr
;
1942 m
= (u_int32_t
*)mask
;
1943 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1944 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1946 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1948 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1950 b0
= gen_linktype(proto
);
1956 static struct block
*
1957 gen_ehostop(eaddr
, dir
)
1958 register const u_char
*eaddr
;
1961 register struct block
*b0
, *b1
;
1965 return gen_bcmp(off_mac
+ 6, 6, eaddr
);
1968 return gen_bcmp(off_mac
+ 0, 6, eaddr
);
1971 b0
= gen_ehostop(eaddr
, Q_SRC
);
1972 b1
= gen_ehostop(eaddr
, Q_DST
);
1978 b0
= gen_ehostop(eaddr
, Q_SRC
);
1979 b1
= gen_ehostop(eaddr
, Q_DST
);
1988 * Like gen_ehostop, but for DLT_FDDI
1990 static struct block
*
1991 gen_fhostop(eaddr
, dir
)
1992 register const u_char
*eaddr
;
1995 struct block
*b0
, *b1
;
2000 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
2002 return gen_bcmp(6 + 1, 6, eaddr
);
2007 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
2009 return gen_bcmp(0 + 1, 6, eaddr
);
2013 b0
= gen_fhostop(eaddr
, Q_SRC
);
2014 b1
= gen_fhostop(eaddr
, Q_DST
);
2020 b0
= gen_fhostop(eaddr
, Q_SRC
);
2021 b1
= gen_fhostop(eaddr
, Q_DST
);
2030 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
2032 static struct block
*
2033 gen_thostop(eaddr
, dir
)
2034 register const u_char
*eaddr
;
2037 register struct block
*b0
, *b1
;
2041 return gen_bcmp(8, 6, eaddr
);
2044 return gen_bcmp(2, 6, eaddr
);
2047 b0
= gen_thostop(eaddr
, Q_SRC
);
2048 b1
= gen_thostop(eaddr
, Q_DST
);
2054 b0
= gen_thostop(eaddr
, Q_SRC
);
2055 b1
= gen_thostop(eaddr
, Q_DST
);
2064 * Like gen_ehostop, but for DLT_IEEE802_11 (802.11 wireless LAN)
2066 static struct block
*
2067 gen_wlanhostop(eaddr
, dir
)
2068 register const u_char
*eaddr
;
2071 register struct block
*b0
, *b1
, *b2
;
2072 register struct slist
*s
;
2079 * For control frames, there is no SA.
2081 * For management frames, SA is at an
2082 * offset of 10 from the beginning of
2085 * For data frames, SA is at an offset
2086 * of 10 from the beginning of the packet
2087 * if From DS is clear, at an offset of
2088 * 16 from the beginning of the packet
2089 * if From DS is set and To DS is clear,
2090 * and an offset of 24 from the beginning
2091 * of the packet if From DS is set and To DS
2096 * Generate the tests to be done for data frames
2099 * First, check for To DS set, i.e. check "link[1] & 0x01".
2101 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2103 b1
= new_block(JMP(BPF_JSET
));
2104 b1
->s
.k
= 0x01; /* To DS */
2108 * If To DS is set, the SA is at 24.
2110 b0
= gen_bcmp(24, 6, eaddr
);
2114 * Now, check for To DS not set, i.e. check
2115 * "!(link[1] & 0x01)".
2117 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2119 b2
= new_block(JMP(BPF_JSET
));
2120 b2
->s
.k
= 0x01; /* To DS */
2125 * If To DS is not set, the SA is at 16.
2127 b1
= gen_bcmp(16, 6, eaddr
);
2131 * Now OR together the last two checks. That gives
2132 * the complete set of checks for data frames with
2138 * Now check for From DS being set, and AND that with
2139 * the ORed-together checks.
2141 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2143 b1
= new_block(JMP(BPF_JSET
));
2144 b1
->s
.k
= 0x02; /* From DS */
2149 * Now check for data frames with From DS not set.
2151 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2153 b2
= new_block(JMP(BPF_JSET
));
2154 b2
->s
.k
= 0x02; /* From DS */
2159 * If From DS isn't set, the SA is at 10.
2161 b1
= gen_bcmp(10, 6, eaddr
);
2165 * Now OR together the checks for data frames with
2166 * From DS not set and for data frames with From DS
2167 * set; that gives the checks done for data frames.
2172 * Now check for a data frame.
2173 * I.e, check "link[0] & 0x08".
2175 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2177 b1
= new_block(JMP(BPF_JSET
));
2182 * AND that with the checks done for data frames.
2187 * If the high-order bit of the type value is 0, this
2188 * is a management frame.
2189 * I.e, check "!(link[0] & 0x08)".
2191 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2193 b2
= new_block(JMP(BPF_JSET
));
2199 * For management frames, the SA is at 10.
2201 b1
= gen_bcmp(10, 6, eaddr
);
2205 * OR that with the checks done for data frames.
2206 * That gives the checks done for management and
2212 * If the low-order bit of the type value is 1,
2213 * this is either a control frame or a frame
2214 * with a reserved type, and thus not a
2217 * I.e., check "!(link[0] & 0x04)".
2219 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2221 b1
= new_block(JMP(BPF_JSET
));
2227 * AND that with the checks for data and management
2237 * For control frames, there is no DA.
2239 * For management frames, DA is at an
2240 * offset of 4 from the beginning of
2243 * For data frames, DA is at an offset
2244 * of 4 from the beginning of the packet
2245 * if To DS is clear and at an offset of
2246 * 16 from the beginning of the packet
2251 * Generate the tests to be done for data frames.
2253 * First, check for To DS set, i.e. "link[1] & 0x01".
2255 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2257 b1
= new_block(JMP(BPF_JSET
));
2258 b1
->s
.k
= 0x01; /* To DS */
2262 * If To DS is set, the DA is at 16.
2264 b0
= gen_bcmp(16, 6, eaddr
);
2268 * Now, check for To DS not set, i.e. check
2269 * "!(link[1] & 0x01)".
2271 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2273 b2
= new_block(JMP(BPF_JSET
));
2274 b2
->s
.k
= 0x01; /* To DS */
2279 * If To DS is not set, the DA is at 4.
2281 b1
= gen_bcmp(4, 6, eaddr
);
2285 * Now OR together the last two checks. That gives
2286 * the complete set of checks for data frames.
2291 * Now check for a data frame.
2292 * I.e, check "link[0] & 0x08".
2294 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2296 b1
= new_block(JMP(BPF_JSET
));
2301 * AND that with the checks done for data frames.
2306 * If the high-order bit of the type value is 0, this
2307 * is a management frame.
2308 * I.e, check "!(link[0] & 0x08)".
2310 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2312 b2
= new_block(JMP(BPF_JSET
));
2318 * For management frames, the DA is at 4.
2320 b1
= gen_bcmp(4, 6, eaddr
);
2324 * OR that with the checks done for data frames.
2325 * That gives the checks done for management and
2331 * If the low-order bit of the type value is 1,
2332 * this is either a control frame or a frame
2333 * with a reserved type, and thus not a
2336 * I.e., check "!(link[0] & 0x04)".
2338 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2340 b1
= new_block(JMP(BPF_JSET
));
2346 * AND that with the checks for data and management
2353 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2354 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2360 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2361 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2370 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
2371 * (We assume that the addresses are IEEE 48-bit MAC addresses,
2372 * as the RFC states.)
2374 static struct block
*
2375 gen_ipfchostop(eaddr
, dir
)
2376 register const u_char
*eaddr
;
2379 register struct block
*b0
, *b1
;
2383 return gen_bcmp(10, 6, eaddr
);
2386 return gen_bcmp(2, 6, eaddr
);
2389 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2390 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2396 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2397 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2406 * This is quite tricky because there may be pad bytes in front of the
2407 * DECNET header, and then there are two possible data packet formats that
2408 * carry both src and dst addresses, plus 5 packet types in a format that
2409 * carries only the src node, plus 2 types that use a different format and
2410 * also carry just the src node.
2414 * Instead of doing those all right, we just look for data packets with
2415 * 0 or 1 bytes of padding. If you want to look at other packets, that
2416 * will require a lot more hacking.
2418 * To add support for filtering on DECNET "areas" (network numbers)
2419 * one would want to add a "mask" argument to this routine. That would
2420 * make the filter even more inefficient, although one could be clever
2421 * and not generate masking instructions if the mask is 0xFFFF.
2423 static struct block
*
2424 gen_dnhostop(addr
, dir
, base_off
)
2429 struct block
*b0
, *b1
, *b2
, *tmp
;
2430 u_int offset_lh
; /* offset if long header is received */
2431 u_int offset_sh
; /* offset if short header is received */
2436 offset_sh
= 1; /* follows flags */
2437 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
2441 offset_sh
= 3; /* follows flags, dstnode */
2442 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
2446 /* Inefficient because we do our Calvinball dance twice */
2447 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2448 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2454 /* Inefficient because we do our Calvinball dance twice */
2455 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2456 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2461 bpf_error("ISO host filtering not implemented");
2466 b0
= gen_linktype(ETHERTYPE_DN
);
2467 /* Check for pad = 1, long header case */
2468 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2469 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
2470 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
2471 BPF_H
, (bpf_int32
)ntohs(addr
));
2473 /* Check for pad = 0, long header case */
2474 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
2475 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2478 /* Check for pad = 1, short header case */
2479 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2480 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
2481 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
2482 BPF_H
, (bpf_int32
)ntohs(addr
));
2485 /* Check for pad = 0, short header case */
2486 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
2487 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2491 /* Combine with test for linktype */
2496 static struct block
*
2497 gen_host(addr
, mask
, proto
, dir
)
2503 struct block
*b0
, *b1
;
2508 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
2509 if (off_linktype
!= (u_int
)-1) {
2510 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
2512 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
2518 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
2519 off_nl
+ 12, off_nl
+ 16);
2522 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2523 off_nl
+ 14, off_nl
+ 24);
2526 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2527 off_nl
+ 14, off_nl
+ 24);
2530 bpf_error("'tcp' modifier applied to host");
2533 bpf_error("'sctp' modifier applied to host");
2536 bpf_error("'udp' modifier applied to host");
2539 bpf_error("'icmp' modifier applied to host");
2542 bpf_error("'igmp' modifier applied to host");
2545 bpf_error("'igrp' modifier applied to host");
2548 bpf_error("'pim' modifier applied to host");
2551 bpf_error("'vrrp' modifier applied to host");
2554 bpf_error("ATALK host filtering not implemented");
2557 bpf_error("AARP host filtering not implemented");
2560 return gen_dnhostop(addr
, dir
, off_nl
);
2563 bpf_error("SCA host filtering not implemented");
2566 bpf_error("LAT host filtering not implemented");
2569 bpf_error("MOPDL host filtering not implemented");
2572 bpf_error("MOPRC host filtering not implemented");
2576 bpf_error("'ip6' modifier applied to ip host");
2579 bpf_error("'icmp6' modifier applied to host");
2583 bpf_error("'ah' modifier applied to host");
2586 bpf_error("'esp' modifier applied to host");
2589 bpf_error("ISO host filtering not implemented");
2592 bpf_error("'esis' modifier applied to host");
2595 bpf_error("'isis' modifier applied to host");
2598 bpf_error("'clnp' modifier applied to host");
2601 bpf_error("'stp' modifier applied to host");
2604 bpf_error("IPX host filtering not implemented");
2607 bpf_error("'netbeui' modifier applied to host");
2616 static struct block
*
2617 gen_host6(addr
, mask
, proto
, dir
)
2618 struct in6_addr
*addr
;
2619 struct in6_addr
*mask
;
2626 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2629 bpf_error("'ip' modifier applied to ip6 host");
2632 bpf_error("'rarp' modifier applied to ip6 host");
2635 bpf_error("'arp' modifier applied to ip6 host");
2638 bpf_error("'sctp' modifier applied to host");
2641 bpf_error("'tcp' modifier applied to host");
2644 bpf_error("'udp' modifier applied to host");
2647 bpf_error("'icmp' modifier applied to host");
2650 bpf_error("'igmp' modifier applied to host");
2653 bpf_error("'igrp' modifier applied to host");
2656 bpf_error("'pim' modifier applied to host");
2659 bpf_error("'vrrp' modifier applied to host");
2662 bpf_error("ATALK host filtering not implemented");
2665 bpf_error("AARP host filtering not implemented");
2668 bpf_error("'decnet' modifier applied to ip6 host");
2671 bpf_error("SCA host filtering not implemented");
2674 bpf_error("LAT host filtering not implemented");
2677 bpf_error("MOPDL host filtering not implemented");
2680 bpf_error("MOPRC host filtering not implemented");
2683 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2684 off_nl
+ 8, off_nl
+ 24);
2687 bpf_error("'icmp6' modifier applied to host");
2690 bpf_error("'ah' modifier applied to host");
2693 bpf_error("'esp' modifier applied to host");
2696 bpf_error("ISO host filtering not implemented");
2699 bpf_error("'esis' modifier applied to host");
2702 bpf_error("'isis' modifier applied to host");
2705 bpf_error("'clnp' modifier applied to host");
2708 bpf_error("'stp' modifier applied to host");
2711 bpf_error("IPX host filtering not implemented");
2714 bpf_error("'netbeui' modifier applied to host");
2724 static struct block
*
2725 gen_gateway(eaddr
, alist
, proto
, dir
)
2726 const u_char
*eaddr
;
2727 bpf_u_int32
**alist
;
2731 struct block
*b0
, *b1
, *tmp
;
2734 bpf_error("direction applied to 'gateway'");
2741 if (linktype
== DLT_EN10MB
)
2742 b0
= gen_ehostop(eaddr
, Q_OR
);
2743 else if (linktype
== DLT_FDDI
)
2744 b0
= gen_fhostop(eaddr
, Q_OR
);
2745 else if (linktype
== DLT_IEEE802
)
2746 b0
= gen_thostop(eaddr
, Q_OR
);
2747 else if (linktype
== DLT_IEEE802_11
)
2748 b0
= gen_wlanhostop(eaddr
, Q_OR
);
2749 else if (linktype
== DLT_SUNATM
&& is_lane
) {
2751 * Check that the packet doesn't begin with an
2752 * LE Control marker. (We've already generated
2755 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
2759 * Now check the MAC address.
2761 b0
= gen_ehostop(eaddr
, Q_OR
);
2763 } else if (linktype
== DLT_IP_OVER_FC
)
2764 b0
= gen_ipfchostop(eaddr
, Q_OR
);
2767 "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel");
2769 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2771 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2779 bpf_error("illegal modifier of 'gateway'");
2785 gen_proto_abbrev(proto
)
2794 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2796 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2802 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2804 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2810 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2812 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2818 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2821 #ifndef IPPROTO_IGMP
2822 #define IPPROTO_IGMP 2
2826 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2829 #ifndef IPPROTO_IGRP
2830 #define IPPROTO_IGRP 9
2833 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2837 #define IPPROTO_PIM 103
2841 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2843 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2848 #ifndef IPPROTO_VRRP
2849 #define IPPROTO_VRRP 112
2853 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2857 b1
= gen_linktype(ETHERTYPE_IP
);
2861 b1
= gen_linktype(ETHERTYPE_ARP
);
2865 b1
= gen_linktype(ETHERTYPE_REVARP
);
2869 bpf_error("link layer applied in wrong context");
2872 b1
= gen_linktype(ETHERTYPE_ATALK
);
2876 b1
= gen_linktype(ETHERTYPE_AARP
);
2880 b1
= gen_linktype(ETHERTYPE_DN
);
2884 b1
= gen_linktype(ETHERTYPE_SCA
);
2888 b1
= gen_linktype(ETHERTYPE_LAT
);
2892 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2896 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2901 b1
= gen_linktype(ETHERTYPE_IPV6
);
2904 #ifndef IPPROTO_ICMPV6
2905 #define IPPROTO_ICMPV6 58
2908 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2913 #define IPPROTO_AH 51
2916 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2918 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2924 #define IPPROTO_ESP 50
2927 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2929 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2935 b1
= gen_linktype(LLCSAP_ISONS
);
2939 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2943 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2946 case Q_ISIS_L1
: /* all IS-IS Level1 PDU-Types */
2947 b0
= gen_proto(ISIS_L1_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_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2952 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2954 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2958 case Q_ISIS_L2
: /* all IS-IS Level2 PDU-Types */
2959 b0
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2960 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2962 b0
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2964 b0
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2966 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2970 case Q_ISIS_IIH
: /* all IS-IS Hello PDU-Types */
2971 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2972 b1
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2974 b0
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
);
2979 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2980 b1
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2985 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2986 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2988 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2990 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2995 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2996 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
3001 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
3002 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
3007 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
3011 b1
= gen_linktype(LLCSAP_8021D
);
3015 b1
= gen_linktype(LLCSAP_IPX
);
3019 b1
= gen_linktype(LLCSAP_NETBEUI
);
3028 static struct block
*
3035 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
3036 s
->s
.k
= off_nl
+ 6;
3037 b
= new_block(JMP(BPF_JSET
));
3045 static struct block
*
3046 gen_portatom(off
, v
)
3053 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3056 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
3057 s
->next
->s
.k
= off_nl
+ off
;
3059 b
= new_block(JMP(BPF_JEQ
));
3067 static struct block
*
3068 gen_portatom6(off
, v
)
3072 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
3077 gen_portop(port
, proto
, dir
)
3078 int port
, proto
, dir
;
3080 struct block
*b0
, *b1
, *tmp
;
3082 /* ip proto 'proto' */
3083 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
3089 b1
= gen_portatom(0, (bpf_int32
)port
);
3093 b1
= gen_portatom(2, (bpf_int32
)port
);
3098 tmp
= gen_portatom(0, (bpf_int32
)port
);
3099 b1
= gen_portatom(2, (bpf_int32
)port
);
3104 tmp
= gen_portatom(0, (bpf_int32
)port
);
3105 b1
= gen_portatom(2, (bpf_int32
)port
);
3117 static struct block
*
3118 gen_port(port
, ip_proto
, dir
)
3123 struct block
*b0
, *b1
, *tmp
;
3128 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3129 * not LLC encapsulation with LLCSAP_IP.
3131 * For IEEE 802 networks - which includes 802.5 token ring
3132 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3133 * says that SNAP encapsulation is used, not LLC encapsulation
3136 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3137 * RFC 2225 say that SNAP encapsulation is used, not LLC
3138 * encapsulation with LLCSAP_IP.
3140 * So we always check for ETHERTYPE_IP.
3142 b0
= gen_linktype(ETHERTYPE_IP
);
3148 b1
= gen_portop(port
, ip_proto
, dir
);
3152 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
3153 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
3155 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
3168 gen_portop6(port
, proto
, dir
)
3169 int port
, proto
, dir
;
3171 struct block
*b0
, *b1
, *tmp
;
3173 /* ip proto 'proto' */
3174 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
3178 b1
= gen_portatom6(0, (bpf_int32
)port
);
3182 b1
= gen_portatom6(2, (bpf_int32
)port
);
3187 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3188 b1
= gen_portatom6(2, (bpf_int32
)port
);
3193 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3194 b1
= gen_portatom6(2, (bpf_int32
)port
);
3206 static struct block
*
3207 gen_port6(port
, ip_proto
, dir
)
3212 struct block
*b0
, *b1
, *tmp
;
3214 /* ether proto ip */
3215 b0
= gen_linktype(ETHERTYPE_IPV6
);
3221 b1
= gen_portop6(port
, ip_proto
, dir
);
3225 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
3226 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
3228 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
3241 lookup_proto(name
, proto
)
3242 register const char *name
;
3252 v
= pcap_nametoproto(name
);
3253 if (v
== PROTO_UNDEF
)
3254 bpf_error("unknown ip proto '%s'", name
);
3258 /* XXX should look up h/w protocol type based on linktype */
3259 v
= pcap_nametoeproto(name
);
3260 if (v
== PROTO_UNDEF
)
3261 bpf_error("unknown ether proto '%s'", name
);
3265 if (strcmp(name
, "esis") == 0)
3267 else if (strcmp(name
, "isis") == 0)
3269 else if (strcmp(name
, "clnp") == 0)
3272 bpf_error("unknown osi proto '%s'", name
);
3292 static struct block
*
3293 gen_protochain(v
, proto
, dir
)
3298 #ifdef NO_PROTOCHAIN
3299 return gen_proto(v
, proto
, dir
);
3301 struct block
*b0
, *b
;
3302 struct slist
*s
[100];
3303 int fix2
, fix3
, fix4
, fix5
;
3304 int ahcheck
, again
, end
;
3306 int reg2
= alloc_reg();
3308 memset(s
, 0, sizeof(s
));
3309 fix2
= fix3
= fix4
= fix5
= 0;
3316 b0
= gen_protochain(v
, Q_IP
, dir
);
3317 b
= gen_protochain(v
, Q_IPV6
, dir
);
3321 bpf_error("bad protocol applied for 'protochain'");
3325 no_optimize
= 1; /*this code is not compatible with optimzer yet */
3328 * s[0] is a dummy entry to protect other BPF insn from damaged
3329 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
3330 * hard to find interdependency made by jump table fixup.
3333 s
[i
] = new_stmt(0); /*dummy*/
3338 b0
= gen_linktype(ETHERTYPE_IP
);
3341 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3342 s
[i
]->s
.k
= off_nl
+ 9;
3344 /* X = ip->ip_hl << 2 */
3345 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3351 b0
= gen_linktype(ETHERTYPE_IPV6
);
3353 /* A = ip6->ip_nxt */
3354 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3355 s
[i
]->s
.k
= off_nl
+ 6;
3357 /* X = sizeof(struct ip6_hdr) */
3358 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
3364 bpf_error("unsupported proto to gen_protochain");
3368 /* again: if (A == v) goto end; else fall through; */
3370 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3372 s
[i
]->s
.jt
= NULL
; /*later*/
3373 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3377 #ifndef IPPROTO_NONE
3378 #define IPPROTO_NONE 59
3380 /* if (A == IPPROTO_NONE) goto end */
3381 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3382 s
[i
]->s
.jt
= NULL
; /*later*/
3383 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3384 s
[i
]->s
.k
= IPPROTO_NONE
;
3385 s
[fix5
]->s
.jf
= s
[i
];
3390 if (proto
== Q_IPV6
) {
3391 int v6start
, v6end
, v6advance
, j
;
3394 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
3395 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3396 s
[i
]->s
.jt
= NULL
; /*later*/
3397 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3398 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
3399 s
[fix2
]->s
.jf
= s
[i
];
3401 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
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
; /*update in next stmt*/
3405 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
3407 /* if (A == IPPROTO_ROUTING) goto v6advance */
3408 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3409 s
[i
]->s
.jt
= NULL
; /*later*/
3410 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3411 s
[i
]->s
.k
= IPPROTO_ROUTING
;
3413 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
3414 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3415 s
[i
]->s
.jt
= NULL
; /*later*/
3416 s
[i
]->s
.jf
= NULL
; /*later*/
3417 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
3428 * X = X + (P[X + 1] + 1) * 8;
3431 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3433 /* A = P[X + packet head] */
3434 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3438 s
[i
] = new_stmt(BPF_ST
);
3442 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3445 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3449 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3451 /* A = P[X + packet head]; */
3452 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3456 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3460 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3464 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3467 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3471 /* goto again; (must use BPF_JA for backward jump) */
3472 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3473 s
[i
]->s
.k
= again
- i
- 1;
3474 s
[i
- 1]->s
.jf
= s
[i
];
3478 for (j
= v6start
; j
<= v6end
; j
++)
3479 s
[j
]->s
.jt
= s
[v6advance
];
3484 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3486 s
[fix2
]->s
.jf
= s
[i
];
3492 /* if (A == IPPROTO_AH) then fall through; else goto end; */
3493 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3494 s
[i
]->s
.jt
= NULL
; /*later*/
3495 s
[i
]->s
.jf
= NULL
; /*later*/
3496 s
[i
]->s
.k
= IPPROTO_AH
;
3498 s
[fix3
]->s
.jf
= s
[ahcheck
];
3505 * X = X + (P[X + 1] + 2) * 4;
3508 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3510 /* A = P[X + packet head]; */
3511 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3515 s
[i
] = new_stmt(BPF_ST
);
3519 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3522 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3526 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3528 /* A = P[X + packet head] */
3529 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3533 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3537 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3541 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3544 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3548 /* goto again; (must use BPF_JA for backward jump) */
3549 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3550 s
[i
]->s
.k
= again
- i
- 1;
3555 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3557 s
[fix2
]->s
.jt
= s
[end
];
3558 s
[fix4
]->s
.jf
= s
[end
];
3559 s
[fix5
]->s
.jt
= s
[end
];
3566 for (i
= 0; i
< max
- 1; i
++)
3567 s
[i
]->next
= s
[i
+ 1];
3568 s
[max
- 1]->next
= NULL
;
3573 b
= new_block(JMP(BPF_JEQ
));
3574 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
3584 static struct block
*
3585 gen_proto(v
, proto
, dir
)
3590 struct block
*b0
, *b1
;
3592 if (dir
!= Q_DEFAULT
)
3593 bpf_error("direction applied to 'proto'");
3598 b0
= gen_proto(v
, Q_IP
, dir
);
3599 b1
= gen_proto(v
, Q_IPV6
, dir
);
3607 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3608 * not LLC encapsulation with LLCSAP_IP.
3610 * For IEEE 802 networks - which includes 802.5 token ring
3611 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3612 * says that SNAP encapsulation is used, not LLC encapsulation
3615 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3616 * RFC 2225 say that SNAP encapsulation is used, not LLC
3617 * encapsulation with LLCSAP_IP.
3619 * So we always check for ETHERTYPE_IP.
3621 b0
= gen_linktype(ETHERTYPE_IP
);
3623 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
3625 b1
= gen_protochain(v
, Q_IP
);
3635 * Frame Relay packets typically have an OSI
3636 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3637 * generates code to check for all the OSI
3638 * NLPIDs, so calling it and then adding a check
3639 * for the particular NLPID for which we're
3640 * looking is bogus, as we can just check for
3643 * What we check for is the NLPID and a frame
3644 * control field value of UI, i.e. 0x03 followed
3647 * XXX - assumes a 2-byte Frame Relay header with
3648 * DLCI and flags. What if the address is longer?
3650 * XXX - what about SNAP-encapsulated frames?
3652 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3657 * Cisco uses an Ethertype lookalike - for OSI,
3660 b0
= gen_linktype(LLCSAP_ISONS
<<8 | LLCSAP_ISONS
);
3661 /* OSI in C-HDLC is stuffed with a fudge byte */
3662 b1
= gen_cmp(off_nl_nosnap
+1, BPF_B
, (long)v
);
3667 b0
= gen_linktype(LLCSAP_ISONS
);
3668 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3674 b0
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
3676 * 4 is the offset of the PDU type relative to the IS-IS
3679 b1
= gen_cmp(off_nl_nosnap
+4, BPF_B
, (long)v
);
3684 bpf_error("arp does not encapsulate another protocol");
3688 bpf_error("rarp does not encapsulate another protocol");
3692 bpf_error("atalk encapsulation is not specifiable");
3696 bpf_error("decnet encapsulation is not specifiable");
3700 bpf_error("sca does not encapsulate another protocol");
3704 bpf_error("lat does not encapsulate another protocol");
3708 bpf_error("moprc does not encapsulate another protocol");
3712 bpf_error("mopdl does not encapsulate another protocol");
3716 return gen_linktype(v
);
3719 bpf_error("'udp proto' is bogus");
3723 bpf_error("'tcp proto' is bogus");
3727 bpf_error("'sctp proto' is bogus");
3731 bpf_error("'icmp proto' is bogus");
3735 bpf_error("'igmp proto' is bogus");
3739 bpf_error("'igrp proto' is bogus");
3743 bpf_error("'pim proto' is bogus");
3747 bpf_error("'vrrp proto' is bogus");
3752 b0
= gen_linktype(ETHERTYPE_IPV6
);
3754 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3756 b1
= gen_protochain(v
, Q_IPV6
);
3762 bpf_error("'icmp6 proto' is bogus");
3766 bpf_error("'ah proto' is bogus");
3769 bpf_error("'ah proto' is bogus");
3772 bpf_error("'stp proto' is bogus");
3775 bpf_error("'ipx proto' is bogus");
3778 bpf_error("'netbeui proto' is bogus");
3789 register const char *name
;
3792 int proto
= q
.proto
;
3796 bpf_u_int32 mask
, addr
;
3798 bpf_u_int32
**alist
;
3801 struct sockaddr_in
*sin
;
3802 struct sockaddr_in6
*sin6
;
3803 struct addrinfo
*res
, *res0
;
3804 struct in6_addr mask128
;
3806 struct block
*b
, *tmp
;
3807 int port
, real_proto
;
3812 addr
= pcap_nametonetaddr(name
);
3814 bpf_error("unknown network '%s'", name
);
3815 /* Left justify network addr and calculate its network mask */
3817 while (addr
&& (addr
& 0xff000000) == 0) {
3821 return gen_host(addr
, mask
, proto
, dir
);
3825 if (proto
== Q_LINK
) {
3829 eaddr
= pcap_ether_hostton(name
);
3832 "unknown ether host '%s'", name
);
3833 b
= gen_ehostop(eaddr
, dir
);
3838 eaddr
= pcap_ether_hostton(name
);
3841 "unknown FDDI host '%s'", name
);
3842 b
= gen_fhostop(eaddr
, dir
);
3847 eaddr
= pcap_ether_hostton(name
);
3850 "unknown token ring host '%s'", name
);
3851 b
= gen_thostop(eaddr
, dir
);
3855 case DLT_IEEE802_11
:
3856 eaddr
= pcap_ether_hostton(name
);
3859 "unknown 802.11 host '%s'", name
);
3860 b
= gen_wlanhostop(eaddr
, dir
);
3864 case DLT_IP_OVER_FC
:
3865 eaddr
= pcap_ether_hostton(name
);
3868 "unknown Fibre Channel host '%s'", name
);
3869 b
= gen_ipfchostop(eaddr
, dir
);
3878 * Check that the packet doesn't begin
3879 * with an LE Control marker. (We've
3880 * already generated a test for LANE.)
3882 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
,
3886 eaddr
= pcap_ether_hostton(name
);
3889 "unknown ether host '%s'", name
);
3890 b
= gen_ehostop(eaddr
, dir
);
3896 bpf_error("only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
3897 } else if (proto
== Q_DECNET
) {
3898 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3900 * I don't think DECNET hosts can be multihomed, so
3901 * there is no need to build up a list of addresses
3903 return (gen_host(dn_addr
, 0, proto
, dir
));
3906 alist
= pcap_nametoaddr(name
);
3907 if (alist
== NULL
|| *alist
== NULL
)
3908 bpf_error("unknown host '%s'", name
);
3910 if (off_linktype
== (u_int
)-1 && tproto
== Q_DEFAULT
)
3912 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3914 tmp
= gen_host(**alist
++, 0xffffffff,
3921 memset(&mask128
, 0xff, sizeof(mask128
));
3922 res0
= res
= pcap_nametoaddrinfo(name
);
3924 bpf_error("unknown host '%s'", name
);
3926 tproto
= tproto6
= proto
;
3927 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3931 for (res
= res0
; res
; res
= res
->ai_next
) {
3932 switch (res
->ai_family
) {
3934 if (tproto
== Q_IPV6
)
3937 sin
= (struct sockaddr_in
*)
3939 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3940 0xffffffff, tproto
, dir
);
3943 if (tproto6
== Q_IP
)
3946 sin6
= (struct sockaddr_in6
*)
3948 tmp
= gen_host6(&sin6
->sin6_addr
,
3949 &mask128
, tproto6
, dir
);
3960 bpf_error("unknown host '%s'%s", name
,
3961 (proto
== Q_DEFAULT
)
3963 : " for specified address family");
3970 if (proto
!= Q_DEFAULT
&&
3971 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3972 bpf_error("illegal qualifier of 'port'");
3973 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3974 bpf_error("unknown port '%s'", name
);
3975 if (proto
== Q_UDP
) {
3976 if (real_proto
== IPPROTO_TCP
)
3977 bpf_error("port '%s' is tcp", name
);
3978 else if (real_proto
== IPPROTO_SCTP
)
3979 bpf_error("port '%s' is sctp", name
);
3981 /* override PROTO_UNDEF */
3982 real_proto
= IPPROTO_UDP
;
3984 if (proto
== Q_TCP
) {
3985 if (real_proto
== IPPROTO_UDP
)
3986 bpf_error("port '%s' is udp", name
);
3988 else if (real_proto
== IPPROTO_SCTP
)
3989 bpf_error("port '%s' is sctp", name
);
3991 /* override PROTO_UNDEF */
3992 real_proto
= IPPROTO_TCP
;
3994 if (proto
== Q_SCTP
) {
3995 if (real_proto
== IPPROTO_UDP
)
3996 bpf_error("port '%s' is udp", name
);
3998 else if (real_proto
== IPPROTO_TCP
)
3999 bpf_error("port '%s' is tcp", name
);
4001 /* override PROTO_UNDEF */
4002 real_proto
= IPPROTO_SCTP
;
4005 return gen_port(port
, real_proto
, dir
);
4009 b
= gen_port(port
, real_proto
, dir
);
4010 gen_or(gen_port6(port
, real_proto
, dir
), b
);
4017 eaddr
= pcap_ether_hostton(name
);
4019 bpf_error("unknown ether host: %s", name
);
4021 alist
= pcap_nametoaddr(name
);
4022 if (alist
== NULL
|| *alist
== NULL
)
4023 bpf_error("unknown host '%s'", name
);
4024 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
4028 bpf_error("'gateway' not supported in this configuration");
4032 real_proto
= lookup_proto(name
, proto
);
4033 if (real_proto
>= 0)
4034 return gen_proto(real_proto
, proto
, dir
);
4036 bpf_error("unknown protocol: %s", name
);
4039 real_proto
= lookup_proto(name
, proto
);
4040 if (real_proto
>= 0)
4041 return gen_protochain(real_proto
, proto
, dir
);
4043 bpf_error("unknown protocol: %s", name
);
4055 gen_mcode(s1
, s2
, masklen
, q
)
4056 register const char *s1
, *s2
;
4057 register int masklen
;
4060 register int nlen
, mlen
;
4063 nlen
= __pcap_atoin(s1
, &n
);
4064 /* Promote short ipaddr */
4068 mlen
= __pcap_atoin(s2
, &m
);
4069 /* Promote short ipaddr */
4072 bpf_error("non-network bits set in \"%s mask %s\"",
4075 /* Convert mask len to mask */
4077 bpf_error("mask length must be <= 32");
4078 m
= 0xffffffff << (32 - masklen
);
4080 bpf_error("non-network bits set in \"%s/%d\"",
4087 return gen_host(n
, m
, q
.proto
, q
.dir
);
4090 bpf_error("Mask syntax for networks only");
4097 register const char *s
;
4102 int proto
= q
.proto
;
4108 else if (q
.proto
== Q_DECNET
)
4109 vlen
= __pcap_atodn(s
, &v
);
4111 vlen
= __pcap_atoin(s
, &v
);
4118 if (proto
== Q_DECNET
)
4119 return gen_host(v
, 0, proto
, dir
);
4120 else if (proto
== Q_LINK
) {
4121 bpf_error("illegal link layer address");
4124 if (s
== NULL
&& q
.addr
== Q_NET
) {
4125 /* Promote short net number */
4126 while (v
&& (v
& 0xff000000) == 0) {
4131 /* Promote short ipaddr */
4135 return gen_host(v
, mask
, proto
, dir
);
4140 proto
= IPPROTO_UDP
;
4141 else if (proto
== Q_TCP
)
4142 proto
= IPPROTO_TCP
;
4143 else if (proto
== Q_SCTP
)
4144 proto
= IPPROTO_SCTP
;
4145 else if (proto
== Q_DEFAULT
)
4146 proto
= PROTO_UNDEF
;
4148 bpf_error("illegal qualifier of 'port'");
4151 return gen_port((int)v
, proto
, dir
);
4155 b
= gen_port((int)v
, proto
, dir
);
4156 gen_or(gen_port6((int)v
, proto
, dir
), b
);
4162 bpf_error("'gateway' requires a name");
4166 return gen_proto((int)v
, proto
, dir
);
4169 return gen_protochain((int)v
, proto
, dir
);
4184 gen_mcode6(s1
, s2
, masklen
, q
)
4185 register const char *s1
, *s2
;
4186 register int masklen
;
4189 struct addrinfo
*res
;
4190 struct in6_addr
*addr
;
4191 struct in6_addr mask
;
4196 bpf_error("no mask %s supported", s2
);
4198 res
= pcap_nametoaddrinfo(s1
);
4200 bpf_error("invalid ip6 address %s", s1
);
4202 bpf_error("%s resolved to multiple address", s1
);
4203 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
4205 if (sizeof(mask
) * 8 < masklen
)
4206 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
4207 memset(&mask
, 0, sizeof(mask
));
4208 memset(&mask
, 0xff, masklen
/ 8);
4210 mask
.s6_addr
[masklen
/ 8] =
4211 (0xff << (8 - masklen
% 8)) & 0xff;
4214 a
= (u_int32_t
*)addr
;
4215 m
= (u_int32_t
*)&mask
;
4216 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
4217 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
4218 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
4226 bpf_error("Mask syntax for networks only");
4230 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
4235 bpf_error("invalid qualifier against IPv6 address");
4243 register const u_char
*eaddr
;
4246 struct block
*b
, *tmp
;
4248 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4249 if (linktype
== DLT_EN10MB
)
4250 return gen_ehostop(eaddr
, (int)q
.dir
);
4251 if (linktype
== DLT_FDDI
)
4252 return gen_fhostop(eaddr
, (int)q
.dir
);
4253 if (linktype
== DLT_IEEE802
)
4254 return gen_thostop(eaddr
, (int)q
.dir
);
4255 if (linktype
== DLT_IEEE802_11
)
4256 return gen_wlanhostop(eaddr
, (int)q
.dir
);
4257 if (linktype
== DLT_SUNATM
&& is_lane
) {
4259 * Check that the packet doesn't begin with an
4260 * LE Control marker. (We've already generated
4263 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4267 * Now check the MAC address.
4269 b
= gen_ehostop(eaddr
, (int)q
.dir
);
4273 if (linktype
== DLT_IP_OVER_FC
)
4274 return gen_ipfchostop(eaddr
, (int)q
.dir
);
4275 bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
4277 bpf_error("ethernet address used in non-ether expression");
4283 struct slist
*s0
, *s1
;
4286 * This is definitely not the best way to do this, but the
4287 * lists will rarely get long.
4294 static struct slist
*
4300 s
= new_stmt(BPF_LDX
|BPF_MEM
);
4305 static struct slist
*
4311 s
= new_stmt(BPF_LD
|BPF_MEM
);
4317 gen_load(proto
, index
, size
)
4322 struct slist
*s
, *tmp
;
4324 int regno
= alloc_reg();
4326 free_reg(index
->regno
);
4330 bpf_error("data size must be 1, 2, or 4");
4346 bpf_error("unsupported index operation");
4350 * XXX - what about ATM LANE? Should the index be
4351 * relative to the beginning of the AAL5 frame, so
4352 * that 0 refers to the beginning of the LE Control
4353 * field, or relative to the beginning of the LAN
4354 * frame, so that 0 refers, for Ethernet LANE, to
4355 * the beginning of the destination address?
4357 s
= xfer_to_x(index
);
4358 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4360 sappend(index
->s
, s
);
4375 /* XXX Note that we assume a fixed link header here. */
4376 s
= xfer_to_x(index
);
4377 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4380 sappend(index
->s
, s
);
4382 b
= gen_proto_abbrev(proto
);
4384 gen_and(index
->b
, b
);
4396 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
4398 sappend(s
, xfer_to_a(index
));
4399 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
4400 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
4401 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
4403 sappend(index
->s
, s
);
4405 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
4407 gen_and(index
->b
, b
);
4409 gen_and(gen_proto_abbrev(Q_IP
), b
);
4415 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
4419 index
->regno
= regno
;
4420 s
= new_stmt(BPF_ST
);
4422 sappend(index
->s
, s
);
4428 gen_relation(code
, a0
, a1
, reversed
)
4430 struct arth
*a0
, *a1
;
4433 struct slist
*s0
, *s1
, *s2
;
4434 struct block
*b
, *tmp
;
4438 if (code
== BPF_JEQ
) {
4439 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
4440 b
= new_block(JMP(code
));
4444 b
= new_block(BPF_JMP
|code
|BPF_X
);
4450 sappend(a0
->s
, a1
->s
);
4454 free_reg(a0
->regno
);
4455 free_reg(a1
->regno
);
4457 /* 'and' together protocol checks */
4460 gen_and(a0
->b
, tmp
= a1
->b
);
4476 int regno
= alloc_reg();
4477 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
4480 s
= new_stmt(BPF_LD
|BPF_LEN
);
4481 s
->next
= new_stmt(BPF_ST
);
4482 s
->next
->s
.k
= regno
;
4497 a
= (struct arth
*)newchunk(sizeof(*a
));
4501 s
= new_stmt(BPF_LD
|BPF_IMM
);
4503 s
->next
= new_stmt(BPF_ST
);
4519 s
= new_stmt(BPF_ALU
|BPF_NEG
);
4522 s
= new_stmt(BPF_ST
);
4530 gen_arth(code
, a0
, a1
)
4532 struct arth
*a0
, *a1
;
4534 struct slist
*s0
, *s1
, *s2
;
4538 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
4543 sappend(a0
->s
, a1
->s
);
4545 free_reg(a0
->regno
);
4546 free_reg(a1
->regno
);
4548 s0
= new_stmt(BPF_ST
);
4549 a0
->regno
= s0
->s
.k
= alloc_reg();
4556 * Here we handle simple allocation of the scratch registers.
4557 * If too many registers are alloc'd, the allocator punts.
4559 static int regused
[BPF_MEMWORDS
];
4563 * Return the next free register.
4568 int n
= BPF_MEMWORDS
;
4571 if (regused
[curreg
])
4572 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
4574 regused
[curreg
] = 1;
4578 bpf_error("too many registers needed to evaluate expression");
4583 * Return a register to the table so it can
4593 static struct block
*
4600 s
= new_stmt(BPF_LD
|BPF_LEN
);
4601 b
= new_block(JMP(jmp
));
4612 return gen_len(BPF_JGE
, n
);
4616 * Actually, this is less than or equal.
4624 b
= gen_len(BPF_JGT
, n
);
4631 gen_byteop(op
, idx
, val
)
4642 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4645 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4646 b
->s
.code
= JMP(BPF_JGE
);
4651 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4652 b
->s
.code
= JMP(BPF_JGT
);
4656 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
4660 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
4664 b
= new_block(JMP(BPF_JEQ
));
4671 static u_char abroadcast
[] = { 0x0 };
4674 gen_broadcast(proto
)
4677 bpf_u_int32 hostmask
;
4678 struct block
*b0
, *b1
, *b2
;
4679 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4685 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4686 return gen_ahostop(abroadcast
, Q_DST
);
4687 if (linktype
== DLT_EN10MB
)
4688 return gen_ehostop(ebroadcast
, Q_DST
);
4689 if (linktype
== DLT_FDDI
)
4690 return gen_fhostop(ebroadcast
, Q_DST
);
4691 if (linktype
== DLT_IEEE802
)
4692 return gen_thostop(ebroadcast
, Q_DST
);
4693 if (linktype
== DLT_IEEE802_11
)
4694 return gen_wlanhostop(ebroadcast
, Q_DST
);
4695 if (linktype
== DLT_IP_OVER_FC
)
4696 return gen_ipfchostop(ebroadcast
, Q_DST
);
4697 if (linktype
== DLT_SUNATM
&& is_lane
) {
4699 * Check that the packet doesn't begin with an
4700 * LE Control marker. (We've already generated
4703 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4707 * Now check the MAC address.
4709 b0
= gen_ehostop(ebroadcast
, Q_DST
);
4713 bpf_error("not a broadcast link");
4717 b0
= gen_linktype(ETHERTYPE_IP
);
4718 hostmask
= ~netmask
;
4719 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
4720 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
4721 (bpf_int32
)(~0 & hostmask
), hostmask
);
4726 bpf_error("only link-layer/IP broadcast filters supported");
4730 * Generate code to test the low-order bit of a MAC address (that's
4731 * the bottom bit of the *first* byte).
4733 static struct block
*
4734 gen_mac_multicast(offset
)
4737 register struct block
*b0
;
4738 register struct slist
*s
;
4740 /* link[offset] & 1 != 0 */
4741 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4743 b0
= new_block(JMP(BPF_JSET
));
4750 gen_multicast(proto
)
4753 register struct block
*b0
, *b1
, *b2
;
4754 register struct slist
*s
;
4760 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4761 /* all ARCnet multicasts use the same address */
4762 return gen_ahostop(abroadcast
, Q_DST
);
4764 if (linktype
== DLT_EN10MB
) {
4765 /* ether[0] & 1 != 0 */
4766 return gen_mac_multicast(0);
4769 if (linktype
== DLT_FDDI
) {
4771 * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX
4773 * XXX - was that referring to bit-order issues?
4775 /* fddi[1] & 1 != 0 */
4776 return gen_mac_multicast(1);
4779 if (linktype
== DLT_IEEE802
) {
4780 /* tr[2] & 1 != 0 */
4781 return gen_mac_multicast(2);
4784 if (linktype
== DLT_IEEE802_11
) {
4788 * For control frames, there is no DA.
4790 * For management frames, DA is at an
4791 * offset of 4 from the beginning of
4794 * For data frames, DA is at an offset
4795 * of 4 from the beginning of the packet
4796 * if To DS is clear and at an offset of
4797 * 16 from the beginning of the packet
4802 * Generate the tests to be done for data frames.
4804 * First, check for To DS set, i.e. "link[1] & 0x01".
4806 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4808 b1
= new_block(JMP(BPF_JSET
));
4809 b1
->s
.k
= 0x01; /* To DS */
4813 * If To DS is set, the DA is at 16.
4815 b0
= gen_mac_multicast(16);
4819 * Now, check for To DS not set, i.e. check
4820 * "!(link[1] & 0x01)".
4822 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4824 b2
= new_block(JMP(BPF_JSET
));
4825 b2
->s
.k
= 0x01; /* To DS */
4830 * If To DS is not set, the DA is at 4.
4832 b1
= gen_mac_multicast(4);
4836 * Now OR together the last two checks. That gives
4837 * the complete set of checks for data frames.
4842 * Now check for a data frame.
4843 * I.e, check "link[0] & 0x08".
4845 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4847 b1
= new_block(JMP(BPF_JSET
));
4852 * AND that with the checks done for data frames.
4857 * If the high-order bit of the type value is 0, this
4858 * is a management frame.
4859 * I.e, check "!(link[0] & 0x08)".
4861 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4863 b2
= new_block(JMP(BPF_JSET
));
4869 * For management frames, the DA is at 4.
4871 b1
= gen_mac_multicast(4);
4875 * OR that with the checks done for data frames.
4876 * That gives the checks done for management and
4882 * If the low-order bit of the type value is 1,
4883 * this is either a control frame or a frame
4884 * with a reserved type, and thus not a
4887 * I.e., check "!(link[0] & 0x04)".
4889 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4891 b1
= new_block(JMP(BPF_JSET
));
4897 * AND that with the checks for data and management
4904 if (linktype
== DLT_IP_OVER_FC
) {
4905 b0
= gen_mac_multicast(2);
4909 if (linktype
== DLT_SUNATM
&& is_lane
) {
4911 * Check that the packet doesn't begin with an
4912 * LE Control marker. (We've already generated
4915 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4918 /* ether[off_mac] & 1 != 0 */
4919 b0
= gen_mac_multicast(off_mac
);
4924 /* Link not known to support multicasts */
4928 b0
= gen_linktype(ETHERTYPE_IP
);
4929 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4930 b1
->s
.code
= JMP(BPF_JGE
);
4936 b0
= gen_linktype(ETHERTYPE_IPV6
);
4937 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4942 bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
4946 * generate command for inbound/outbound. It's here so we can
4947 * make it link-type specific. 'dir' = 0 implies "inbound",
4948 * = 1 implies "outbound".
4954 register struct block
*b0
;
4957 * Only some data link types support inbound/outbound qualifiers.
4961 b0
= gen_relation(BPF_JEQ
,
4962 gen_load(Q_LINK
, gen_loadi(0), 1),
4970 * Match packets sent by this machine.
4972 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_OUTGOING
);
4975 * Match packets sent to this machine.
4976 * (No broadcast or multicast packets, or
4977 * packets sent to some other machine and
4978 * received promiscuously.)
4980 * XXX - packets sent to other machines probably
4981 * shouldn't be matched, but what about broadcast
4982 * or multicast packets we received?
4984 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_HOST
);
4989 b0
= gen_cmp(26, BPF_H
,
4990 (bpf_int32
)((dir
== 0) ? PF_IN
: PF_OUT
));
4994 bpf_error("inbound/outbound not supported on linktype %d",
5002 /* PF firewall log matched interface */
5004 gen_pf_ifname(const char *ifname
)
5006 if (linktype
!= DLT_PFLOG
) {
5007 bpf_error("ifname supported only for DLT_PFLOG");
5010 if (strlen(ifname
) >= 16) {
5011 bpf_error("ifname interface names can't be larger than 16 characters");
5014 return (gen_bcmp(4, strlen(ifname
), (const u_char
*)ifname
));
5018 /* PF firewall log rule number */
5022 if (linktype
!= DLT_PFLOG
) {
5023 bpf_error("rnr supported only for DLT_PFLOG");
5027 return (gen_cmp(20, BPF_H
, (bpf_int32
)rnr
));
5030 /* PF firewall log reason code */
5032 gen_pf_reason(int reason
)
5034 if (linktype
!= DLT_PFLOG
) {
5035 bpf_error("reason supported only for DLT_PFLOG");
5039 return (gen_cmp(22, BPF_H
, (bpf_int32
)reason
));
5042 /* PF firewall log action */
5044 gen_pf_action(int action
)
5046 if (linktype
!= DLT_PFLOG
) {
5047 bpf_error("action supported only for DLT_PFLOG");
5051 return (gen_cmp(24, BPF_H
, (bpf_int32
)action
));
5056 register const u_char
*eaddr
;
5059 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
5060 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
5061 return gen_ahostop(eaddr
, (int)q
.dir
);
5063 bpf_error("ARCnet address used in non-arc expression");
5067 static struct block
*
5068 gen_ahostop(eaddr
, dir
)
5069 register const u_char
*eaddr
;
5072 register struct block
*b0
, *b1
;
5075 /* src comes first, different from Ethernet */
5077 return gen_bcmp(0, 1, eaddr
);
5080 return gen_bcmp(1, 1, eaddr
);
5083 b0
= gen_ahostop(eaddr
, Q_SRC
);
5084 b1
= gen_ahostop(eaddr
, Q_DST
);
5090 b0
= gen_ahostop(eaddr
, Q_SRC
);
5091 b1
= gen_ahostop(eaddr
, Q_DST
);
5100 * support IEEE 802.1Q VLAN trunk over ethernet
5109 * Change the offsets to point to the type and data fields within
5110 * the VLAN packet. This is somewhat of a kludge.
5112 if (orig_nl
== (u_int
)-1) {
5113 orig_linktype
= off_linktype
; /* save original values */
5115 orig_nl_nosnap
= off_nl_nosnap
;
5126 bpf_error("no VLAN support for data link type %d",
5132 /* check for VLAN */
5133 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
5135 /* If a specific VLAN is requested, check VLAN id */
5136 if (vlan_num
>= 0) {
5139 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
5148 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
5160 bpf_error("'vpi' supported only on raw ATM");
5161 if (off_vpi
== (u_int
)-1)
5163 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
5164 (u_int
)jvalue
, reverse
);
5169 bpf_error("'vci' supported only on raw ATM");
5170 if (off_vci
== (u_int
)-1)
5172 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
5173 (u_int
)jvalue
, reverse
);
5177 if (off_proto
== (u_int
)-1)
5178 abort(); /* XXX - this isn't on FreeBSD */
5179 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
5180 (u_int
)jvalue
, reverse
);
5184 if (off_payload
== (u_int
)-1)
5186 b0
= gen_ncmp(BPF_B
, off_payload
+ MSG_TYPE_POS
, 0xffffffff,
5187 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
5192 bpf_error("'callref' supported only on raw ATM");
5193 if (off_proto
== (u_int
)-1)
5195 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
5196 (u_int
)jvalue
, reverse
);
5206 gen_atmtype_abbrev(type
)
5209 struct block
*b0
, *b1
;
5214 /* Get all packets in Meta signalling Circuit */
5216 bpf_error("'metac' supported only on raw ATM");
5217 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5218 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
5223 /* Get all packets in Broadcast Circuit*/
5225 bpf_error("'bcc' supported only on raw ATM");
5226 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5227 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
5232 /* Get all cells in Segment OAM F4 circuit*/
5234 bpf_error("'oam4sc' supported only on raw ATM");
5235 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5236 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5241 /* Get all cells in End-to-End OAM F4 Circuit*/
5243 bpf_error("'oam4ec' supported only on raw ATM");
5244 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5245 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5250 /* Get all packets in connection Signalling Circuit */
5252 bpf_error("'sc' supported only on raw ATM");
5253 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5254 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
5259 /* Get all packets in ILMI Circuit */
5261 bpf_error("'ilmic' supported only on raw ATM");
5262 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5263 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
5268 /* Get all LANE packets */
5270 bpf_error("'lane' supported only on raw ATM");
5271 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
5274 * Arrange that all subsequent tests assume LANE
5275 * rather than LLC-encapsulated packets, and set
5276 * the offsets appropriately for LANE-encapsulated
5279 * "off_mac" is the offset of the Ethernet header,
5280 * which is 2 bytes past the ATM pseudo-header
5281 * (skipping the pseudo-header and 2-byte LE Client
5282 * field). The other offsets are Ethernet offsets
5283 * relative to "off_mac".
5286 off_mac
= off_payload
+ 2; /* MAC header */
5287 off_linktype
= off_mac
+ 12;
5288 off_nl
= off_mac
+ 14; /* Ethernet II */
5289 off_nl_nosnap
= off_mac
+ 17; /* 802.3+802.2 */
5293 /* Get all LLC-encapsulated packets */
5295 bpf_error("'llc' supported only on raw ATM");
5296 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
5307 static struct block
*
5308 gen_msg_abbrev(type
)
5314 * Q.2931 signalling protocol messages for handling virtual circuits
5315 * establishment and teardown
5320 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
5324 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
5328 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
5332 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
5336 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
5339 case A_RELEASE_DONE
:
5340 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
5350 gen_atmmulti_abbrev(type
)
5353 struct block
*b0
, *b1
;
5359 bpf_error("'oam' supported only on raw ATM");
5360 b1
= gen_atmmulti_abbrev(A_OAMF4
);
5365 bpf_error("'oamf4' supported only on raw ATM");
5367 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5368 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5370 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5376 * Get Q.2931 signalling messages for switched
5377 * virtual connection
5380 bpf_error("'connectmsg' supported only on raw ATM");
5381 b0
= gen_msg_abbrev(A_SETUP
);
5382 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5384 b0
= gen_msg_abbrev(A_CONNECT
);
5386 b0
= gen_msg_abbrev(A_CONNECTACK
);
5388 b0
= gen_msg_abbrev(A_RELEASE
);
5390 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5392 b0
= gen_atmtype_abbrev(A_SC
);
5398 bpf_error("'metaconnect' supported only on raw ATM");
5399 b0
= gen_msg_abbrev(A_SETUP
);
5400 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5402 b0
= gen_msg_abbrev(A_CONNECT
);
5404 b0
= gen_msg_abbrev(A_RELEASE
);
5406 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5408 b0
= gen_atmtype_abbrev(A_METAC
);