]>
The Tcpdump Group git mirrors - libpcap/blob - gencode.c
1 /*#define CHASE_CHAIN*/
3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.190 2003-03-28 08:09:48 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
);
215 /* XXX Round up to nearest long. */
216 n
= (n
+ sizeof(long) - 1) & ~(sizeof(long) - 1);
218 /* XXX Round up to structure boundary. */
222 cp
= &chunks
[cur_chunk
];
223 if (n
> cp
->n_left
) {
224 ++cp
, k
= ++cur_chunk
;
226 bpf_error("out of memory");
227 size
= CHUNK0SIZE
<< k
;
228 cp
->m
= (void *)malloc(size
);
230 bpf_error("out of memory");
231 memset((char *)cp
->m
, 0, size
);
234 bpf_error("out of memory");
237 return (void *)((char *)cp
->m
+ cp
->n_left
);
246 for (i
= 0; i
< NCHUNKS
; ++i
)
247 if (chunks
[i
].m
!= NULL
) {
254 * A strdup whose allocations are freed after code generation is over.
258 register const char *s
;
260 int n
= strlen(s
) + 1;
261 char *cp
= newchunk(n
);
267 static inline struct block
*
273 p
= (struct block
*)newchunk(sizeof(*p
));
280 static inline struct slist
*
286 p
= (struct slist
*)newchunk(sizeof(*p
));
292 static struct block
*
296 struct block
*b
= new_block(BPF_RET
|BPF_K
);
305 bpf_error("syntax error in filter expression");
308 static bpf_u_int32 netmask
;
313 pcap_compile(pcap_t
*p
, struct bpf_program
*program
,
314 char *buf
, int optimize
, bpf_u_int32 mask
)
323 if (setjmp(top_ctx
)) {
331 snaplen
= pcap_snapshot(p
);
333 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
334 "snaplen of 0 rejects all packets");
338 lex_init(buf
? buf
: "");
339 init_linktype(pcap_datalink(p
));
346 root
= gen_retblk(snaplen
);
348 if (optimize
&& !no_optimize
) {
351 (root
->s
.code
== (BPF_RET
|BPF_K
) && root
->s
.k
== 0))
352 bpf_error("expression rejects all packets");
354 program
->bf_insns
= icode_to_fcode(root
, &len
);
355 program
->bf_len
= len
;
363 * entry point for using the compiler with no pcap open
364 * pass in all the stuff that is needed explicitly instead.
367 pcap_compile_nopcap(int snaplen_arg
, int linktype_arg
,
368 struct bpf_program
*program
,
369 char *buf
, int optimize
, bpf_u_int32 mask
)
374 p
= pcap_open_dead(linktype_arg
, snaplen_arg
);
377 ret
= pcap_compile(p
, program
, buf
, optimize
, mask
);
383 * Clean up a "struct bpf_program" by freeing all the memory allocated
387 pcap_freecode(struct bpf_program
*program
)
390 if (program
->bf_insns
!= NULL
) {
391 free((char *)program
->bf_insns
);
392 program
->bf_insns
= NULL
;
397 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
398 * which of the jt and jf fields has been resolved and which is a pointer
399 * back to another unresolved block (or nil). At least one of the fields
400 * in each block is already resolved.
403 backpatch(list
, target
)
404 struct block
*list
, *target
;
421 * Merge the lists in b0 and b1, using the 'sense' field to indicate
422 * which of jt and jf is the link.
426 struct block
*b0
, *b1
;
428 register struct block
**p
= &b0
;
430 /* Find end of list. */
432 p
= !((*p
)->sense
) ? &JT(*p
) : &JF(*p
);
434 /* Concatenate the lists. */
442 backpatch(p
, gen_retblk(snaplen
));
443 p
->sense
= !p
->sense
;
444 backpatch(p
, gen_retblk(0));
450 struct block
*b0
, *b1
;
452 backpatch(b0
, b1
->head
);
453 b0
->sense
= !b0
->sense
;
454 b1
->sense
= !b1
->sense
;
456 b1
->sense
= !b1
->sense
;
462 struct block
*b0
, *b1
;
464 b0
->sense
= !b0
->sense
;
465 backpatch(b0
, b1
->head
);
466 b0
->sense
= !b0
->sense
;
475 b
->sense
= !b
->sense
;
478 static struct block
*
479 gen_cmp(offset
, size
, v
)
486 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
489 b
= new_block(JMP(BPF_JEQ
));
496 static struct block
*
497 gen_cmp_gt(offset
, size
, v
)
504 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
507 b
= new_block(JMP(BPF_JGT
));
514 static struct block
*
515 gen_mcmp(offset
, size
, v
, mask
)
520 struct block
*b
= gen_cmp(offset
, size
, v
);
523 if (mask
!= 0xffffffff) {
524 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
531 static struct block
*
532 gen_bcmp(offset
, size
, v
)
533 register u_int offset
, size
;
534 register const u_char
*v
;
536 register struct block
*b
, *tmp
;
540 register const u_char
*p
= &v
[size
- 4];
541 bpf_int32 w
= ((bpf_int32
)p
[0] << 24) |
542 ((bpf_int32
)p
[1] << 16) | ((bpf_int32
)p
[2] << 8) | p
[3];
544 tmp
= gen_cmp(offset
+ size
- 4, BPF_W
, w
);
551 register const u_char
*p
= &v
[size
- 2];
552 bpf_int32 w
= ((bpf_int32
)p
[0] << 8) | p
[1];
554 tmp
= gen_cmp(offset
+ size
- 2, BPF_H
, w
);
561 tmp
= gen_cmp(offset
, BPF_B
, (bpf_int32
)v
[0]);
569 static struct block
*
570 gen_ncmp(datasize
, offset
, mask
, jtype
, jvalue
, reverse
)
571 bpf_u_int32 datasize
, offset
, mask
, jtype
, jvalue
;
577 s
= new_stmt(BPF_LD
|datasize
|BPF_ABS
);
580 if (mask
!= 0xffffffff) {
581 s
->next
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
585 b
= new_block(JMP(jtype
));
588 if (reverse
&& (jtype
== BPF_JGT
|| jtype
== BPF_JGE
))
594 * Various code constructs need to know the layout of the data link
595 * layer. These variables give the necessary offsets.
599 * This is the offset of the beginning of the MAC-layer header.
600 * It's usually 0, except for ATM LANE.
602 static u_int off_mac
;
605 * "off_linktype" is the offset to information in the link-layer header
606 * giving the packet type.
608 * For Ethernet, it's the offset of the Ethernet type field.
610 * For link-layer types that always use 802.2 headers, it's the
611 * offset of the LLC header.
613 * For PPP, it's the offset of the PPP type field.
615 * For Cisco HDLC, it's the offset of the CHDLC type field.
617 * For BSD loopback, it's the offset of the AF_ value.
619 * For Linux cooked sockets, it's the offset of the type field.
621 * It's set to -1 for no encapsulation, in which case, IP is assumed.
623 static u_int off_linktype
;
626 * TRUE if the link layer includes an ATM pseudo-header.
628 static int is_atm
= 0;
631 * TRUE if "lane" appeared in the filter; it causes us to generate
632 * code that assumes LANE rather than LLC-encapsulated traffic in SunATM.
634 static int is_lane
= 0;
637 * These are offsets for the ATM pseudo-header.
639 static u_int off_vpi
;
640 static u_int off_vci
;
641 static u_int off_proto
;
644 * This is the offset of the first byte after the ATM pseudo_header,
645 * or -1 if there is no ATM pseudo-header.
647 static u_int off_payload
;
650 * These are offsets to the beginning of the network-layer header.
652 * If the link layer never uses 802.2 LLC:
654 * "off_nl" and "off_nl_nosnap" are the same.
656 * If the link layer always uses 802.2 LLC:
658 * "off_nl" is the offset if there's a SNAP header following
661 * "off_nl_nosnap" is the offset if there's no SNAP header.
663 * If the link layer is Ethernet:
665 * "off_nl" is the offset if the packet is an Ethernet II packet
666 * (we assume no 802.3+802.2+SNAP);
668 * "off_nl_nosnap" is the offset if the packet is an 802.3 packet
669 * with an 802.2 header following it.
672 static u_int off_nl_nosnap
;
683 * Assume it's not raw ATM with a pseudo-header, for now.
701 off_nl
= 6; /* XXX in reality, variable! */
702 off_nl_nosnap
= 6; /* no 802.2 LLC */
705 case DLT_ARCNET_LINUX
:
707 off_nl
= 8; /* XXX in reality, variable! */
708 off_nl_nosnap
= 8; /* no 802.2 LLC */
713 off_nl
= 14; /* Ethernet II */
714 off_nl_nosnap
= 17; /* 802.3+802.2 */
719 * SLIP doesn't have a link level type. The 16 byte
720 * header is hacked into our SLIP driver.
724 off_nl_nosnap
= 16; /* no 802.2 LLC */
728 /* XXX this may be the same as the DLT_PPP_BSDOS case */
732 off_nl_nosnap
= 24; /* no 802.2 LLC */
739 off_nl_nosnap
= 4; /* no 802.2 LLC */
745 off_nl_nosnap
= 12; /* no 802.2 LLC */
751 off_nl_nosnap
= 28; /* no 802.2 LLC */
755 case DLT_C_HDLC
: /* BSD/OS Cisco HDLC */
756 case DLT_PPP_SERIAL
: /* NetBSD sync/async serial PPP */
759 off_nl_nosnap
= 4; /* no 802.2 LLC */
764 * This does no include the Ethernet header, and
765 * only covers session state.
769 off_nl_nosnap
= 8; /* no 802.2 LLC */
775 off_nl_nosnap
= 24; /* no 802.2 LLC */
780 * FDDI doesn't really have a link-level type field.
781 * We set "off_linktype" to the offset of the LLC header.
783 * To check for Ethernet types, we assume that SSAP = SNAP
784 * is being used and pick out the encapsulated Ethernet type.
785 * XXX - should we generate code to check for SNAP?
789 off_linktype
+= pcap_fddipad
;
791 off_nl
= 21; /* FDDI+802.2+SNAP */
792 off_nl_nosnap
= 16; /* FDDI+802.2 */
794 off_nl
+= pcap_fddipad
;
795 off_nl_nosnap
+= pcap_fddipad
;
801 * Token Ring doesn't really have a link-level type field.
802 * We set "off_linktype" to the offset of the LLC header.
804 * To check for Ethernet types, we assume that SSAP = SNAP
805 * is being used and pick out the encapsulated Ethernet type.
806 * XXX - should we generate code to check for SNAP?
808 * XXX - the header is actually variable-length.
809 * Some various Linux patched versions gave 38
810 * as "off_linktype" and 40 as "off_nl"; however,
811 * if a token ring packet has *no* routing
812 * information, i.e. is not source-routed, the correct
813 * values are 20 and 22, as they are in the vanilla code.
815 * A packet is source-routed iff the uppermost bit
816 * of the first byte of the source address, at an
817 * offset of 8, has the uppermost bit set. If the
818 * packet is source-routed, the total number of bytes
819 * of routing information is 2 plus bits 0x1F00 of
820 * the 16-bit value at an offset of 14 (shifted right
821 * 8 - figure out which byte that is).
824 off_nl
= 22; /* Token Ring+802.2+SNAP */
825 off_nl_nosnap
= 17; /* Token Ring+802.2 */
830 * 802.11 doesn't really have a link-level type field.
831 * We set "off_linktype" to the offset of the LLC header.
833 * To check for Ethernet types, we assume that SSAP = SNAP
834 * is being used and pick out the encapsulated Ethernet type.
835 * XXX - should we generate code to check for SNAP?
837 * XXX - the header is actually variable-length. We
838 * assume a 24-byte link-layer header, as appears in
839 * data frames in networks with no bridges.
842 off_nl
= 32; /* 802.11+802.2+SNAP */
843 off_nl_nosnap
= 27; /* 802.11+802.2 */
846 case DLT_PRISM_HEADER
:
848 * Same as 802.11, but with an additional header before
849 * the 802.11 header, containing a bunch of additional
850 * information including radio-level information.
852 * The header is 144 bytes long.
854 * XXX - same variable-length header problem; at least
855 * the Prism header is fixed-length.
857 off_linktype
= 144+24;
858 off_nl
= 144+32; /* Prism+802.11+802.2+SNAP */
859 off_nl_nosnap
= 144+27; /* Prism+802.11+802.2 */
862 case DLT_IEEE802_11_RADIO
:
864 * Same as 802.11, but with an additional header before
865 * the 802.11 header, containing a bunch of additional
866 * information including radio-level information.
868 * The header is 64 bytes long.
870 * XXX - same variable-length header problem, only
871 * more so; this header is also variable-length,
872 * with the length being the 32-bit big-endian
873 * number at an offset of 4 from the beginning
874 * of the radio header.
876 off_linktype
= 64+24;
877 off_nl
= 64+32; /* Radio+802.11+802.2+SNAP */
878 off_nl_nosnap
= 64+27; /* Radio+802.11+802.2 */
881 case DLT_ATM_RFC1483
:
882 case DLT_ATM_CLIP
: /* Linux ATM defines this */
884 * assume routed, non-ISO PDUs
885 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
888 off_nl
= 8; /* 802.2+SNAP */
889 off_nl_nosnap
= 3; /* 802.2 */
894 * Full Frontal ATM; you get AALn PDUs with an ATM
898 off_vpi
= SUNATM_VPI_POS
;
899 off_vci
= SUNATM_VCI_POS
;
900 off_proto
= PROTO_POS
;
901 off_mac
= -1; /* LLC-encapsulated, so no MAC-layer header */
902 off_payload
= SUNATM_PKT_BEGIN_POS
;
903 off_linktype
= off_payload
;
904 off_nl
= off_payload
+8; /* 802.2+SNAP */
905 off_nl_nosnap
= off_payload
+3; /* 802.2 */
911 off_nl_nosnap
= 0; /* no 802.2 LLC */
914 case DLT_LINUX_SLL
: /* fake header for Linux cooked socket */
917 off_nl_nosnap
= 16; /* no 802.2 LLC */
922 * LocalTalk does have a 1-byte type field in the LLAP header,
923 * but really it just indicates whether there is a "short" or
924 * "long" DDP packet following.
928 off_nl_nosnap
= 0; /* no 802.2 LLC */
933 * RFC 2625 IP-over-Fibre-Channel doesn't really have a
934 * link-level type field. We set "off_linktype" to the
935 * offset of the LLC header.
937 * To check for Ethernet types, we assume that SSAP = SNAP
938 * is being used and pick out the encapsulated Ethernet type.
939 * XXX - should we generate code to check for SNAP? RFC
940 * 2625 says SNAP should be used.
943 off_nl
= 24; /* IPFC+802.2+SNAP */
944 off_nl_nosnap
= 19; /* IPFC+802.2 */
949 * XXX - we should set this to handle SNAP-encapsulated
950 * frames (NLPID of 0x80).
954 off_nl_nosnap
= 0; /* no 802.2 LLC */
957 bpf_error("unknown data link type %d", linktype
);
961 static struct block
*
968 s
= new_stmt(BPF_LD
|BPF_IMM
);
970 b
= new_block(JMP(BPF_JEQ
));
976 static inline struct block
*
979 return gen_uncond(1);
982 static inline struct block
*
985 return gen_uncond(0);
989 * Byte-swap a 32-bit number.
990 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
991 * big-endian platforms.)
993 #define SWAPLONG(y) \
994 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
996 static struct block
*
997 gen_ether_linktype(proto
)
1000 struct block
*b0
, *b1
;
1006 * OSI protocols always use 802.2 encapsulation.
1007 * XXX - should we check both the DSAP and the
1008 * SSAP, like this, or should we check just the
1011 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1013 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1014 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1019 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1021 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1022 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1026 case LLCSAP_NETBEUI
:
1028 * NetBEUI always uses 802.2 encapsulation.
1029 * XXX - should we check both the DSAP and the
1030 * SSAP, like this, or should we check just the
1033 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1035 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1036 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1044 * Ethernet_II frames, which are Ethernet
1045 * frames with a frame type of ETHERTYPE_IPX;
1047 * Ethernet_802.3 frames, which are 802.3
1048 * frames (i.e., the type/length field is
1049 * a length field, <= ETHERMTU, rather than
1050 * a type field) with the first two bytes
1051 * after the Ethernet/802.3 header being
1054 * Ethernet_802.2 frames, which are 802.3
1055 * frames with an 802.2 LLC header and
1056 * with the IPX LSAP as the DSAP in the LLC
1059 * Ethernet_SNAP frames, which are 802.3
1060 * frames with an LLC header and a SNAP
1061 * header and with an OUI of 0x000000
1062 * (encapsulated Ethernet) and a protocol
1063 * ID of ETHERTYPE_IPX in the SNAP header.
1065 * XXX - should we generate the same code both
1066 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
1070 * This generates code to check both for the
1071 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
1073 b0
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1074 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)0xFFFF);
1078 * Now we add code to check for SNAP frames with
1079 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1081 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1085 * Now we generate code to check for 802.3
1086 * frames in general.
1088 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1092 * Now add the check for 802.3 frames before the
1093 * check for Ethernet_802.2 and Ethernet_802.3,
1094 * as those checks should only be done on 802.3
1095 * frames, not on Ethernet frames.
1100 * Now add the check for Ethernet_II frames, and
1101 * do that before checking for the other frame
1104 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_IPX
);
1108 case ETHERTYPE_ATALK
:
1109 case ETHERTYPE_AARP
:
1111 * EtherTalk (AppleTalk protocols on Ethernet link
1112 * layer) may use 802.2 encapsulation.
1116 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1117 * we check for an Ethernet type field less than
1118 * 1500, which means it's an 802.3 length field.
1120 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1124 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1125 * SNAP packets with an organization code of
1126 * 0x080007 (Apple, for Appletalk) and a protocol
1127 * type of ETHERTYPE_ATALK (Appletalk).
1129 * 802.2-encapsulated ETHERTYPE_AARP packets are
1130 * SNAP packets with an organization code of
1131 * 0x000000 (encapsulated Ethernet) and a protocol
1132 * type of ETHERTYPE_AARP (Appletalk ARP).
1134 if (proto
== ETHERTYPE_ATALK
)
1135 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1136 else /* proto == ETHERTYPE_AARP */
1137 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1141 * Check for Ethernet encapsulation (Ethertalk
1142 * phase 1?); we just check for the Ethernet
1145 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1151 if (proto
<= ETHERMTU
) {
1153 * This is an LLC SAP value, so the frames
1154 * that match would be 802.2 frames.
1155 * Check that the frame is an 802.2 frame
1156 * (i.e., that the length/type field is
1157 * a length field, <= ETHERMTU) and
1158 * then check the DSAP.
1160 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1162 b1
= gen_cmp(off_linktype
+ 2, BPF_B
, (bpf_int32
)proto
);
1167 * This is an Ethernet type, so compare
1168 * the length/type field with it (if
1169 * the frame is an 802.2 frame, the length
1170 * field will be <= ETHERMTU, and, as
1171 * "proto" is > ETHERMTU, this test
1172 * will fail and the frame won't match,
1173 * which is what we want).
1175 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1180 static struct block
*
1184 struct block
*b0
, *b1
, *b2
;
1189 return gen_ether_linktype(proto
);
1196 proto
= (proto
<< 8 | LLCSAP_ISONS
);
1200 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1205 case DLT_IEEE802_11
:
1206 case DLT_PRISM_HEADER
:
1207 case DLT_IEEE802_11_RADIO
:
1210 case DLT_ATM_RFC1483
:
1212 case DLT_IP_OVER_FC
:
1213 return gen_llc(proto
);
1218 * If "is_lane" is set, check for a LANE-encapsulated
1219 * version of this protocol, otherwise check for an
1220 * LLC-encapsulated version of this protocol.
1222 * We assume LANE means Ethernet, not Token Ring.
1226 * Check that the packet doesn't begin with an
1227 * LE Control marker. (We've already generated
1230 b0
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
1234 * Now generate an Ethernet test.
1236 b1
= gen_ether_linktype(proto
);
1241 * Check for LLC encapsulation and then check the
1244 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1245 b1
= gen_llc(proto
);
1254 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1255 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1256 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1262 * OSI protocols always use 802.2 encapsulation.
1263 * XXX - should we check both the DSAP and the
1264 * LSAP, like this, or should we check just the
1267 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1268 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1269 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1273 case LLCSAP_NETBEUI
:
1275 * NetBEUI always uses 802.2 encapsulation.
1276 * XXX - should we check both the DSAP and the
1277 * LSAP, like this, or should we check just the
1280 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1281 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1282 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1288 * Ethernet_II frames, which are Ethernet
1289 * frames with a frame type of ETHERTYPE_IPX;
1291 * Ethernet_802.3 frames, which have a frame
1292 * type of LINUX_SLL_P_802_3;
1294 * Ethernet_802.2 frames, which are 802.3
1295 * frames with an 802.2 LLC header (i.e, have
1296 * a frame type of LINUX_SLL_P_802_2) and
1297 * with the IPX LSAP as the DSAP in the LLC
1300 * Ethernet_SNAP frames, which are 802.3
1301 * frames with an LLC header and a SNAP
1302 * header and with an OUI of 0x000000
1303 * (encapsulated Ethernet) and a protocol
1304 * ID of ETHERTYPE_IPX in the SNAP header.
1306 * First, do the checks on LINUX_SLL_P_802_2
1307 * frames; generate the check for either
1308 * Ethernet_802.2 or Ethernet_SNAP frames, and
1309 * then put a check for LINUX_SLL_P_802_2 frames
1312 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1313 (bpf_int32
)LLCSAP_IPX
);
1314 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1317 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1321 * Now check for 802.3 frames and OR that with
1322 * the previous test.
1324 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1328 * Now add the check for Ethernet_II frames, and
1329 * do that before checking for the other frame
1332 b0
= gen_cmp(off_linktype
, BPF_H
,
1333 (bpf_int32
)ETHERTYPE_IPX
);
1337 case ETHERTYPE_ATALK
:
1338 case ETHERTYPE_AARP
:
1340 * EtherTalk (AppleTalk protocols on Ethernet link
1341 * layer) may use 802.2 encapsulation.
1345 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1346 * we check for the 802.2 protocol type in the
1347 * "Ethernet type" field.
1349 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1352 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1353 * SNAP packets with an organization code of
1354 * 0x080007 (Apple, for Appletalk) and a protocol
1355 * type of ETHERTYPE_ATALK (Appletalk).
1357 * 802.2-encapsulated ETHERTYPE_AARP packets are
1358 * SNAP packets with an organization code of
1359 * 0x000000 (encapsulated Ethernet) and a protocol
1360 * type of ETHERTYPE_AARP (Appletalk ARP).
1362 if (proto
== ETHERTYPE_ATALK
)
1363 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1365 else /* proto == ETHERTYPE_AARP */
1366 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1371 * Check for Ethernet encapsulation (Ethertalk
1372 * phase 1?); we just check for the Ethernet
1375 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1381 if (proto
<= ETHERMTU
) {
1383 * This is an LLC SAP value, so the frames
1384 * that match would be 802.2 frames.
1385 * Check for the 802.2 protocol type
1386 * in the "Ethernet type" field, and
1387 * then check the DSAP.
1389 b0
= gen_cmp(off_linktype
, BPF_H
,
1391 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1397 * This is an Ethernet type, so compare
1398 * the length/type field with it (if
1399 * the frame is an 802.2 frame, the length
1400 * field will be <= ETHERMTU, and, as
1401 * "proto" is > ETHERMTU, this test
1402 * will fail and the frame won't match,
1403 * which is what we want).
1405 return gen_cmp(off_linktype
, BPF_H
,
1412 case DLT_SLIP_BSDOS
:
1415 * These types don't provide any type field; packets
1418 * XXX - for IPv4, check for a version number of 4, and,
1419 * for IPv6, check for a version number of 6?
1425 case ETHERTYPE_IPV6
:
1427 return gen_true(); /* always true */
1430 return gen_false(); /* always false */
1435 case DLT_PPP_SERIAL
:
1438 * We use Ethernet protocol types inside libpcap;
1439 * map them to the corresponding PPP protocol types.
1448 case ETHERTYPE_IPV6
:
1457 case ETHERTYPE_ATALK
:
1471 * I'm assuming the "Bridging PDU"s that go
1472 * over PPP are Spanning Tree Protocol
1486 * We use Ethernet protocol types inside libpcap;
1487 * map them to the corresponding PPP protocol types.
1492 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1493 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1495 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1500 case ETHERTYPE_IPV6
:
1510 case ETHERTYPE_ATALK
:
1524 * I'm assuming the "Bridging PDU"s that go
1525 * over PPP are Spanning Tree Protocol
1542 * For DLT_NULL, the link-layer header is a 32-bit
1543 * word containing an AF_ value in *host* byte order,
1544 * and for DLT_ENC, the link-layer header begins
1545 * with a 32-bit work containing an AF_ value in
1548 * In addition, if we're reading a saved capture file,
1549 * the host byte order in the capture may not be the
1550 * same as the host byte order on this machine.
1552 * For DLT_LOOP, the link-layer header is a 32-bit
1553 * word containing an AF_ value in *network* byte order.
1555 * XXX - AF_ values may, unfortunately, be platform-
1556 * dependent; for example, FreeBSD's AF_INET6 is 24
1557 * whilst NetBSD's and OpenBSD's is 26.
1559 * This means that, when reading a capture file, just
1560 * checking for our AF_INET6 value won't work if the
1561 * capture file came from another OS.
1563 * XXX - what's the byte order for DLT_PFLOG?
1572 case ETHERTYPE_IPV6
:
1579 * Not a type on which we support filtering.
1580 * XXX - support those that have AF_ values
1581 * #defined on this platform, at least?
1586 if (linktype
== DLT_NULL
|| linktype
== DLT_ENC
) {
1588 * The AF_ value is in host byte order, but
1589 * the BPF interpreter will convert it to
1590 * network byte order.
1592 * If this is a save file, and it's from a
1593 * machine with the opposite byte order to
1594 * ours, we byte-swap the AF_ value.
1596 * Then we run it through "htonl()", and
1597 * generate code to compare against the result.
1599 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1600 bpf_pcap
->sf
.swapped
)
1601 proto
= SWAPLONG(proto
);
1602 proto
= htonl(proto
);
1604 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1607 case DLT_ARCNET_LINUX
:
1609 * XXX should we check for first fragment if the protocol
1618 case ETHERTYPE_IPV6
:
1619 return (gen_cmp(off_linktype
, BPF_B
,
1620 (bpf_int32
)ARCTYPE_INET6
));
1624 b0
= gen_cmp(off_linktype
, BPF_B
,
1625 (bpf_int32
)ARCTYPE_IP
);
1626 b1
= gen_cmp(off_linktype
, BPF_B
,
1627 (bpf_int32
)ARCTYPE_IP_OLD
);
1632 b0
= gen_cmp(off_linktype
, BPF_B
,
1633 (bpf_int32
)ARCTYPE_ARP
);
1634 b1
= gen_cmp(off_linktype
, BPF_B
,
1635 (bpf_int32
)ARCTYPE_ARP_OLD
);
1639 case ETHERTYPE_REVARP
:
1640 return (gen_cmp(off_linktype
, BPF_B
,
1641 (bpf_int32
)ARCTYPE_REVARP
));
1643 case ETHERTYPE_ATALK
:
1644 return (gen_cmp(off_linktype
, BPF_B
,
1645 (bpf_int32
)ARCTYPE_ATALK
));
1651 case ETHERTYPE_ATALK
:
1660 * XXX - assumes a 2-byte Frame Relay header with
1661 * DLCI and flags. What if the address is longer?
1667 * Check for the special NLPID for IP.
1669 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1672 case ETHERTYPE_IPV6
:
1674 * Check for the special NLPID for IPv6.
1676 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1681 * Check for several OSI protocols.
1683 * Frame Relay packets typically have an OSI
1684 * NLPID at the beginning; we check for each
1687 * What we check for is the NLPID and a frame
1688 * control field of UI, i.e. 0x03 followed
1691 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1692 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1693 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1705 * All the types that have no encapsulation should either be
1706 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1707 * all packets are IP packets, or should be handled in some
1708 * special case, if none of them are (if some are and some
1709 * aren't, the lack of encapsulation is a problem, as we'd
1710 * have to find some other way of determining the packet type).
1712 * Therefore, if "off_linktype" is -1, there's an error.
1714 if (off_linktype
== -1)
1718 * Any type not handled above should always have an Ethernet
1719 * type at an offset of "off_linktype". (PPP is partially
1720 * handled above - the protocol type is mapped from the
1721 * Ethernet and LLC types we use internally to the corresponding
1722 * PPP type - but the PPP type is always specified by a value
1723 * at "off_linktype", so we don't have to do the code generation
1726 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1730 * Check for an LLC SNAP packet with a given organization code and
1731 * protocol type; we check the entire contents of the 802.2 LLC and
1732 * snap headers, checking for DSAP and SSAP of SNAP and a control
1733 * field of 0x03 in the LLC header, and for the specified organization
1734 * code and protocol type in the SNAP header.
1736 static struct block
*
1737 gen_snap(orgcode
, ptype
, offset
)
1738 bpf_u_int32 orgcode
;
1742 u_char snapblock
[8];
1744 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1745 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1746 snapblock
[2] = 0x03; /* control = UI */
1747 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1748 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1749 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1750 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1751 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1752 return gen_bcmp(offset
, 8, snapblock
);
1756 * Check for a given protocol value assuming an 802.2 LLC header.
1758 static struct block
*
1763 * XXX - handle token-ring variable-length header.
1768 return gen_cmp(off_linktype
, BPF_H
, (long)
1769 ((LLCSAP_IP
<< 8) | LLCSAP_IP
));
1772 return gen_cmp(off_linktype
, BPF_H
, (long)
1773 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1775 case LLCSAP_NETBEUI
:
1776 return gen_cmp(off_linktype
, BPF_H
, (long)
1777 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1781 * XXX - are there ever SNAP frames for IPX on
1782 * non-Ethernet 802.x networks?
1784 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1786 case ETHERTYPE_ATALK
:
1788 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1789 * SNAP packets with an organization code of
1790 * 0x080007 (Apple, for Appletalk) and a protocol
1791 * type of ETHERTYPE_ATALK (Appletalk).
1793 * XXX - check for an organization code of
1794 * encapsulated Ethernet as well?
1796 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1800 * XXX - we don't have to check for IPX 802.3
1801 * here, but should we check for the IPX Ethertype?
1803 if (proto
<= ETHERMTU
) {
1805 * This is an LLC SAP value, so check
1808 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1811 * This is an Ethernet type; we assume that it's
1812 * unlikely that it'll appear in the right place
1813 * at random, and therefore check only the
1814 * location that would hold the Ethernet type
1815 * in a SNAP frame with an organization code of
1816 * 0x000000 (encapsulated Ethernet).
1818 * XXX - if we were to check for the SNAP DSAP and
1819 * LSAP, as per XXX, and were also to check for an
1820 * organization code of 0x000000 (encapsulated
1821 * Ethernet), we'd do
1823 * return gen_snap(0x000000, proto,
1826 * here; for now, we don't, as per the above.
1827 * I don't know whether it's worth the extra CPU
1828 * time to do the right check or not.
1830 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1835 static struct block
*
1836 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1840 u_int src_off
, dst_off
;
1842 struct block
*b0
, *b1
;
1856 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1857 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1863 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1864 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1871 b0
= gen_linktype(proto
);
1872 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1878 static struct block
*
1879 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1880 struct in6_addr
*addr
;
1881 struct in6_addr
*mask
;
1883 u_int src_off
, dst_off
;
1885 struct block
*b0
, *b1
;
1900 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1901 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1907 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1908 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1915 /* this order is important */
1916 a
= (u_int32_t
*)addr
;
1917 m
= (u_int32_t
*)mask
;
1918 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1919 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1921 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1923 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1925 b0
= gen_linktype(proto
);
1931 static struct block
*
1932 gen_ehostop(eaddr
, dir
)
1933 register const u_char
*eaddr
;
1936 register struct block
*b0
, *b1
;
1940 return gen_bcmp(off_mac
+ 6, 6, eaddr
);
1943 return gen_bcmp(off_mac
+ 0, 6, eaddr
);
1946 b0
= gen_ehostop(eaddr
, Q_SRC
);
1947 b1
= gen_ehostop(eaddr
, Q_DST
);
1953 b0
= gen_ehostop(eaddr
, Q_SRC
);
1954 b1
= gen_ehostop(eaddr
, Q_DST
);
1963 * Like gen_ehostop, but for DLT_FDDI
1965 static struct block
*
1966 gen_fhostop(eaddr
, dir
)
1967 register const u_char
*eaddr
;
1970 struct block
*b0
, *b1
;
1975 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
1977 return gen_bcmp(6 + 1, 6, eaddr
);
1982 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
1984 return gen_bcmp(0 + 1, 6, eaddr
);
1988 b0
= gen_fhostop(eaddr
, Q_SRC
);
1989 b1
= gen_fhostop(eaddr
, Q_DST
);
1995 b0
= gen_fhostop(eaddr
, Q_SRC
);
1996 b1
= gen_fhostop(eaddr
, Q_DST
);
2005 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
2007 static struct block
*
2008 gen_thostop(eaddr
, dir
)
2009 register const u_char
*eaddr
;
2012 register struct block
*b0
, *b1
;
2016 return gen_bcmp(8, 6, eaddr
);
2019 return gen_bcmp(2, 6, eaddr
);
2022 b0
= gen_thostop(eaddr
, Q_SRC
);
2023 b1
= gen_thostop(eaddr
, Q_DST
);
2029 b0
= gen_thostop(eaddr
, Q_SRC
);
2030 b1
= gen_thostop(eaddr
, Q_DST
);
2039 * Like gen_ehostop, but for DLT_IEEE802_11 (802.11 wireless LAN)
2041 static struct block
*
2042 gen_wlanhostop(eaddr
, dir
)
2043 register const u_char
*eaddr
;
2046 register struct block
*b0
, *b1
, *b2
;
2047 register struct slist
*s
;
2054 * For control frames, there is no SA.
2056 * For management frames, SA is at an
2057 * offset of 10 from the beginning of
2060 * For data frames, SA is at an offset
2061 * of 10 from the beginning of the packet
2062 * if From DS is clear, at an offset of
2063 * 16 from the beginning of the packet
2064 * if From DS is set and To DS is clear,
2065 * and an offset of 24 from the beginning
2066 * of the packet if From DS is set and To DS
2071 * Generate the tests to be done for data frames
2074 * First, check for To DS set, i.e. check "link[1] & 0x01".
2076 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2078 b1
= new_block(JMP(BPF_JSET
));
2079 b1
->s
.k
= 0x01; /* To DS */
2083 * If To DS is set, the SA is at 24.
2085 b0
= gen_bcmp(24, 6, eaddr
);
2089 * Now, check for To DS not set, i.e. check
2090 * "!(link[1] & 0x01)".
2092 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2094 b2
= new_block(JMP(BPF_JSET
));
2095 b2
->s
.k
= 0x01; /* To DS */
2100 * If To DS is not set, the SA is at 16.
2102 b1
= gen_bcmp(16, 6, eaddr
);
2106 * Now OR together the last two checks. That gives
2107 * the complete set of checks for data frames with
2113 * Now check for From DS being set, and AND that with
2114 * the ORed-together checks.
2116 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2118 b1
= new_block(JMP(BPF_JSET
));
2119 b1
->s
.k
= 0x02; /* From DS */
2124 * Now check for data frames with From DS not set.
2126 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2128 b2
= new_block(JMP(BPF_JSET
));
2129 b2
->s
.k
= 0x02; /* From DS */
2134 * If From DS isn't set, the SA is at 10.
2136 b1
= gen_bcmp(10, 6, eaddr
);
2140 * Now OR together the checks for data frames with
2141 * From DS not set and for data frames with From DS
2142 * set; that gives the checks done for data frames.
2147 * Now check for a data frame.
2148 * I.e, check "link[0] & 0x08".
2150 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2152 b1
= new_block(JMP(BPF_JSET
));
2157 * AND that with the checks done for data frames.
2162 * If the high-order bit of the type value is 0, this
2163 * is a management frame.
2164 * I.e, check "!(link[0] & 0x08)".
2166 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2168 b2
= new_block(JMP(BPF_JSET
));
2174 * For management frames, the SA is at 10.
2176 b1
= gen_bcmp(10, 6, eaddr
);
2180 * OR that with the checks done for data frames.
2181 * That gives the checks done for management and
2187 * If the low-order bit of the type value is 1,
2188 * this is either a control frame or a frame
2189 * with a reserved type, and thus not a
2192 * I.e., check "!(link[0] & 0x04)".
2194 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2196 b1
= new_block(JMP(BPF_JSET
));
2202 * AND that with the checks for data and management
2212 * For control frames, there is no DA.
2214 * For management frames, DA is at an
2215 * offset of 4 from the beginning of
2218 * For data frames, DA is at an offset
2219 * of 4 from the beginning of the packet
2220 * if To DS is clear and at an offset of
2221 * 16 from the beginning of the packet
2226 * Generate the tests to be done for data frames.
2228 * First, check for To DS set, i.e. "link[1] & 0x01".
2230 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2232 b1
= new_block(JMP(BPF_JSET
));
2233 b1
->s
.k
= 0x01; /* To DS */
2237 * If To DS is set, the DA is at 16.
2239 b0
= gen_bcmp(16, 6, eaddr
);
2243 * Now, check for To DS not set, i.e. check
2244 * "!(link[1] & 0x01)".
2246 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2248 b2
= new_block(JMP(BPF_JSET
));
2249 b2
->s
.k
= 0x01; /* To DS */
2254 * If To DS is not set, the DA is at 4.
2256 b1
= gen_bcmp(4, 6, eaddr
);
2260 * Now OR together the last two checks. That gives
2261 * the complete set of checks for data frames.
2266 * Now check for a data frame.
2267 * I.e, check "link[0] & 0x08".
2269 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2271 b1
= new_block(JMP(BPF_JSET
));
2276 * AND that with the checks done for data frames.
2281 * If the high-order bit of the type value is 0, this
2282 * is a management frame.
2283 * I.e, check "!(link[0] & 0x08)".
2285 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2287 b2
= new_block(JMP(BPF_JSET
));
2293 * For management frames, the DA is at 4.
2295 b1
= gen_bcmp(4, 6, eaddr
);
2299 * OR that with the checks done for data frames.
2300 * That gives the checks done for management and
2306 * If the low-order bit of the type value is 1,
2307 * this is either a control frame or a frame
2308 * with a reserved type, and thus not a
2311 * I.e., check "!(link[0] & 0x04)".
2313 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2315 b1
= new_block(JMP(BPF_JSET
));
2321 * AND that with the checks for data and management
2328 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2329 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2335 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
2336 b1
= gen_wlanhostop(eaddr
, Q_DST
);
2345 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
2346 * (We assume that the addresses are IEEE 48-bit MAC addresses,
2347 * as the RFC states.)
2349 static struct block
*
2350 gen_ipfchostop(eaddr
, dir
)
2351 register const u_char
*eaddr
;
2354 register struct block
*b0
, *b1
;
2358 return gen_bcmp(10, 6, eaddr
);
2361 return gen_bcmp(2, 6, eaddr
);
2364 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2365 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2371 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
2372 b1
= gen_ipfchostop(eaddr
, Q_DST
);
2381 * This is quite tricky because there may be pad bytes in front of the
2382 * DECNET header, and then there are two possible data packet formats that
2383 * carry both src and dst addresses, plus 5 packet types in a format that
2384 * carries only the src node, plus 2 types that use a different format and
2385 * also carry just the src node.
2389 * Instead of doing those all right, we just look for data packets with
2390 * 0 or 1 bytes of padding. If you want to look at other packets, that
2391 * will require a lot more hacking.
2393 * To add support for filtering on DECNET "areas" (network numbers)
2394 * one would want to add a "mask" argument to this routine. That would
2395 * make the filter even more inefficient, although one could be clever
2396 * and not generate masking instructions if the mask is 0xFFFF.
2398 static struct block
*
2399 gen_dnhostop(addr
, dir
, base_off
)
2404 struct block
*b0
, *b1
, *b2
, *tmp
;
2405 u_int offset_lh
; /* offset if long header is received */
2406 u_int offset_sh
; /* offset if short header is received */
2411 offset_sh
= 1; /* follows flags */
2412 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
2416 offset_sh
= 3; /* follows flags, dstnode */
2417 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
2421 /* Inefficient because we do our Calvinball dance twice */
2422 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2423 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2429 /* Inefficient because we do our Calvinball dance twice */
2430 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
2431 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
2436 bpf_error("ISO host filtering not implemented");
2441 b0
= gen_linktype(ETHERTYPE_DN
);
2442 /* Check for pad = 1, long header case */
2443 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2444 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
2445 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
2446 BPF_H
, (bpf_int32
)ntohs(addr
));
2448 /* Check for pad = 0, long header case */
2449 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
2450 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2453 /* Check for pad = 1, short header case */
2454 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
2455 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
2456 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
2457 BPF_H
, (bpf_int32
)ntohs(addr
));
2460 /* Check for pad = 0, short header case */
2461 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
2462 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
2466 /* Combine with test for linktype */
2471 static struct block
*
2472 gen_host(addr
, mask
, proto
, dir
)
2478 struct block
*b0
, *b1
;
2483 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
2484 if (off_linktype
!= -1) {
2485 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
2487 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
2493 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
2494 off_nl
+ 12, off_nl
+ 16);
2497 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2498 off_nl
+ 14, off_nl
+ 24);
2501 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2502 off_nl
+ 14, off_nl
+ 24);
2505 bpf_error("'tcp' modifier applied to host");
2508 bpf_error("'sctp' modifier applied to host");
2511 bpf_error("'udp' modifier applied to host");
2514 bpf_error("'icmp' modifier applied to host");
2517 bpf_error("'igmp' modifier applied to host");
2520 bpf_error("'igrp' modifier applied to host");
2523 bpf_error("'pim' modifier applied to host");
2526 bpf_error("'vrrp' modifier applied to host");
2529 bpf_error("ATALK host filtering not implemented");
2532 bpf_error("AARP host filtering not implemented");
2535 return gen_dnhostop(addr
, dir
, off_nl
);
2538 bpf_error("SCA host filtering not implemented");
2541 bpf_error("LAT host filtering not implemented");
2544 bpf_error("MOPDL host filtering not implemented");
2547 bpf_error("MOPRC host filtering not implemented");
2551 bpf_error("'ip6' modifier applied to ip host");
2554 bpf_error("'icmp6' modifier applied to host");
2558 bpf_error("'ah' modifier applied to host");
2561 bpf_error("'esp' modifier applied to host");
2564 bpf_error("ISO host filtering not implemented");
2567 bpf_error("'esis' modifier applied to host");
2570 bpf_error("'isis' modifier applied to host");
2573 bpf_error("'clnp' modifier applied to host");
2576 bpf_error("'stp' modifier applied to host");
2579 bpf_error("IPX host filtering not implemented");
2582 bpf_error("'netbeui' modifier applied to host");
2591 static struct block
*
2592 gen_host6(addr
, mask
, proto
, dir
)
2593 struct in6_addr
*addr
;
2594 struct in6_addr
*mask
;
2601 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2604 bpf_error("'ip' modifier applied to ip6 host");
2607 bpf_error("'rarp' modifier applied to ip6 host");
2610 bpf_error("'arp' modifier applied to ip6 host");
2613 bpf_error("'sctp' modifier applied to host");
2616 bpf_error("'tcp' modifier applied to host");
2619 bpf_error("'udp' modifier applied to host");
2622 bpf_error("'icmp' modifier applied to host");
2625 bpf_error("'igmp' modifier applied to host");
2628 bpf_error("'igrp' modifier applied to host");
2631 bpf_error("'pim' modifier applied to host");
2634 bpf_error("'vrrp' modifier applied to host");
2637 bpf_error("ATALK host filtering not implemented");
2640 bpf_error("AARP host filtering not implemented");
2643 bpf_error("'decnet' modifier applied to ip6 host");
2646 bpf_error("SCA host filtering not implemented");
2649 bpf_error("LAT host filtering not implemented");
2652 bpf_error("MOPDL host filtering not implemented");
2655 bpf_error("MOPRC host filtering not implemented");
2658 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2659 off_nl
+ 8, off_nl
+ 24);
2662 bpf_error("'icmp6' modifier applied to host");
2665 bpf_error("'ah' modifier applied to host");
2668 bpf_error("'esp' modifier applied to host");
2671 bpf_error("ISO host filtering not implemented");
2674 bpf_error("'esis' modifier applied to host");
2677 bpf_error("'isis' modifier applied to host");
2680 bpf_error("'clnp' modifier applied to host");
2683 bpf_error("'stp' modifier applied to host");
2686 bpf_error("IPX host filtering not implemented");
2689 bpf_error("'netbeui' modifier applied to host");
2699 static struct block
*
2700 gen_gateway(eaddr
, alist
, proto
, dir
)
2701 const u_char
*eaddr
;
2702 bpf_u_int32
**alist
;
2706 struct block
*b0
, *b1
, *tmp
;
2709 bpf_error("direction applied to 'gateway'");
2716 if (linktype
== DLT_EN10MB
)
2717 b0
= gen_ehostop(eaddr
, Q_OR
);
2718 else if (linktype
== DLT_FDDI
)
2719 b0
= gen_fhostop(eaddr
, Q_OR
);
2720 else if (linktype
== DLT_IEEE802
)
2721 b0
= gen_thostop(eaddr
, Q_OR
);
2722 else if (linktype
== DLT_IEEE802_11
)
2723 b0
= gen_wlanhostop(eaddr
, Q_OR
);
2724 else if (linktype
== DLT_SUNATM
&& is_lane
) {
2726 * Check that the packet doesn't begin with an
2727 * LE Control marker. (We've already generated
2730 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
2734 * Now check the MAC address.
2736 b0
= gen_ehostop(eaddr
, Q_OR
);
2738 } else if (linktype
== DLT_IP_OVER_FC
)
2739 b0
= gen_ipfchostop(eaddr
, Q_OR
);
2742 "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel");
2744 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2746 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2754 bpf_error("illegal modifier of 'gateway'");
2760 gen_proto_abbrev(proto
)
2769 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2771 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2777 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2779 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2785 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2787 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2793 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2796 #ifndef IPPROTO_IGMP
2797 #define IPPROTO_IGMP 2
2801 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2804 #ifndef IPPROTO_IGRP
2805 #define IPPROTO_IGRP 9
2808 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2812 #define IPPROTO_PIM 103
2816 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2818 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2823 #ifndef IPPROTO_VRRP
2824 #define IPPROTO_VRRP 112
2828 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2832 b1
= gen_linktype(ETHERTYPE_IP
);
2836 b1
= gen_linktype(ETHERTYPE_ARP
);
2840 b1
= gen_linktype(ETHERTYPE_REVARP
);
2844 bpf_error("link layer applied in wrong context");
2847 b1
= gen_linktype(ETHERTYPE_ATALK
);
2851 b1
= gen_linktype(ETHERTYPE_AARP
);
2855 b1
= gen_linktype(ETHERTYPE_DN
);
2859 b1
= gen_linktype(ETHERTYPE_SCA
);
2863 b1
= gen_linktype(ETHERTYPE_LAT
);
2867 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2871 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2876 b1
= gen_linktype(ETHERTYPE_IPV6
);
2879 #ifndef IPPROTO_ICMPV6
2880 #define IPPROTO_ICMPV6 58
2883 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2888 #define IPPROTO_AH 51
2891 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2893 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2899 #define IPPROTO_ESP 50
2902 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2904 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2910 b1
= gen_linktype(LLCSAP_ISONS
);
2914 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2918 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2921 case Q_ISIS_L1
: /* all IS-IS Level1 PDU-Types */
2922 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2923 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2925 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2927 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2929 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2933 case Q_ISIS_L2
: /* all IS-IS Level2 PDU-Types */
2934 b0
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2935 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
2937 b0
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2939 b0
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2941 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2945 case Q_ISIS_IIH
: /* all IS-IS Hello PDU-Types */
2946 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2947 b1
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
2949 b0
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
);
2954 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
2955 b1
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
2960 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
2961 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
2963 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2965 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2970 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2971 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2976 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
2977 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
2982 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
2986 b1
= gen_linktype(LLCSAP_8021D
);
2990 b1
= gen_linktype(LLCSAP_IPX
);
2994 b1
= gen_linktype(LLCSAP_NETBEUI
);
3003 static struct block
*
3010 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
3011 s
->s
.k
= off_nl
+ 6;
3012 b
= new_block(JMP(BPF_JSET
));
3020 static struct block
*
3021 gen_portatom(off
, v
)
3028 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3031 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
3032 s
->next
->s
.k
= off_nl
+ off
;
3034 b
= new_block(JMP(BPF_JEQ
));
3042 static struct block
*
3043 gen_portatom6(off
, v
)
3047 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
3052 gen_portop(port
, proto
, dir
)
3053 int port
, proto
, dir
;
3055 struct block
*b0
, *b1
, *tmp
;
3057 /* ip proto 'proto' */
3058 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
3064 b1
= gen_portatom(0, (bpf_int32
)port
);
3068 b1
= gen_portatom(2, (bpf_int32
)port
);
3073 tmp
= gen_portatom(0, (bpf_int32
)port
);
3074 b1
= gen_portatom(2, (bpf_int32
)port
);
3079 tmp
= gen_portatom(0, (bpf_int32
)port
);
3080 b1
= gen_portatom(2, (bpf_int32
)port
);
3092 static struct block
*
3093 gen_port(port
, ip_proto
, dir
)
3098 struct block
*b0
, *b1
, *tmp
;
3103 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3104 * not LLC encapsulation with LLCSAP_IP.
3106 * For IEEE 802 networks - which includes 802.5 token ring
3107 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3108 * says that SNAP encapsulation is used, not LLC encapsulation
3111 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3112 * RFC 2225 say that SNAP encapsulation is used, not LLC
3113 * encapsulation with LLCSAP_IP.
3115 * So we always check for ETHERTYPE_IP.
3117 b0
= gen_linktype(ETHERTYPE_IP
);
3123 b1
= gen_portop(port
, ip_proto
, dir
);
3127 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
3128 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
3130 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
3143 gen_portop6(port
, proto
, dir
)
3144 int port
, proto
, dir
;
3146 struct block
*b0
, *b1
, *tmp
;
3148 /* ip proto 'proto' */
3149 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
3153 b1
= gen_portatom6(0, (bpf_int32
)port
);
3157 b1
= gen_portatom6(2, (bpf_int32
)port
);
3162 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3163 b1
= gen_portatom6(2, (bpf_int32
)port
);
3168 tmp
= gen_portatom6(0, (bpf_int32
)port
);
3169 b1
= gen_portatom6(2, (bpf_int32
)port
);
3181 static struct block
*
3182 gen_port6(port
, ip_proto
, dir
)
3187 struct block
*b0
, *b1
, *tmp
;
3189 /* ether proto ip */
3190 b0
= gen_linktype(ETHERTYPE_IPV6
);
3196 b1
= gen_portop6(port
, ip_proto
, dir
);
3200 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
3201 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
3203 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
3216 lookup_proto(name
, proto
)
3217 register const char *name
;
3227 v
= pcap_nametoproto(name
);
3228 if (v
== PROTO_UNDEF
)
3229 bpf_error("unknown ip proto '%s'", name
);
3233 /* XXX should look up h/w protocol type based on linktype */
3234 v
= pcap_nametoeproto(name
);
3235 if (v
== PROTO_UNDEF
)
3236 bpf_error("unknown ether proto '%s'", name
);
3240 if (strcmp(name
, "esis") == 0)
3242 else if (strcmp(name
, "isis") == 0)
3244 else if (strcmp(name
, "clnp") == 0)
3247 bpf_error("unknown osi proto '%s'", name
);
3267 static struct block
*
3268 gen_protochain(v
, proto
, dir
)
3273 #ifdef NO_PROTOCHAIN
3274 return gen_proto(v
, proto
, dir
);
3276 struct block
*b0
, *b
;
3277 struct slist
*s
[100];
3278 int fix2
, fix3
, fix4
, fix5
;
3279 int ahcheck
, again
, end
;
3281 int reg2
= alloc_reg();
3283 memset(s
, 0, sizeof(s
));
3284 fix2
= fix3
= fix4
= fix5
= 0;
3291 b0
= gen_protochain(v
, Q_IP
, dir
);
3292 b
= gen_protochain(v
, Q_IPV6
, dir
);
3296 bpf_error("bad protocol applied for 'protochain'");
3300 no_optimize
= 1; /*this code is not compatible with optimzer yet */
3303 * s[0] is a dummy entry to protect other BPF insn from damaged
3304 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
3305 * hard to find interdependency made by jump table fixup.
3308 s
[i
] = new_stmt(0); /*dummy*/
3313 b0
= gen_linktype(ETHERTYPE_IP
);
3316 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3317 s
[i
]->s
.k
= off_nl
+ 9;
3319 /* X = ip->ip_hl << 2 */
3320 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3326 b0
= gen_linktype(ETHERTYPE_IPV6
);
3328 /* A = ip6->ip_nxt */
3329 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
3330 s
[i
]->s
.k
= off_nl
+ 6;
3332 /* X = sizeof(struct ip6_hdr) */
3333 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
3339 bpf_error("unsupported proto to gen_protochain");
3343 /* again: if (A == v) goto end; else fall through; */
3345 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3347 s
[i
]->s
.jt
= NULL
; /*later*/
3348 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3352 #ifndef IPPROTO_NONE
3353 #define IPPROTO_NONE 59
3355 /* if (A == IPPROTO_NONE) goto end */
3356 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3357 s
[i
]->s
.jt
= NULL
; /*later*/
3358 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3359 s
[i
]->s
.k
= IPPROTO_NONE
;
3360 s
[fix5
]->s
.jf
= s
[i
];
3365 if (proto
== Q_IPV6
) {
3366 int v6start
, v6end
, v6advance
, j
;
3369 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
3370 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3371 s
[i
]->s
.jt
= NULL
; /*later*/
3372 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3373 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
3374 s
[fix2
]->s
.jf
= s
[i
];
3376 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
3377 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3378 s
[i
]->s
.jt
= NULL
; /*later*/
3379 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3380 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
3382 /* if (A == IPPROTO_ROUTING) goto v6advance */
3383 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3384 s
[i
]->s
.jt
= NULL
; /*later*/
3385 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
3386 s
[i
]->s
.k
= IPPROTO_ROUTING
;
3388 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
3389 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3390 s
[i
]->s
.jt
= NULL
; /*later*/
3391 s
[i
]->s
.jf
= NULL
; /*later*/
3392 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
3403 * X = X + (P[X + 1] + 1) * 8;
3406 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3408 /* A = P[X + packet head] */
3409 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3413 s
[i
] = new_stmt(BPF_ST
);
3417 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3420 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3424 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3426 /* A = P[X + packet head]; */
3427 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3431 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3435 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3439 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3442 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3446 /* goto again; (must use BPF_JA for backward jump) */
3447 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3448 s
[i
]->s
.k
= again
- i
- 1;
3449 s
[i
- 1]->s
.jf
= s
[i
];
3453 for (j
= v6start
; j
<= v6end
; j
++)
3454 s
[j
]->s
.jt
= s
[v6advance
];
3459 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3461 s
[fix2
]->s
.jf
= s
[i
];
3467 /* if (A == IPPROTO_AH) then fall through; else goto end; */
3468 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
3469 s
[i
]->s
.jt
= NULL
; /*later*/
3470 s
[i
]->s
.jf
= NULL
; /*later*/
3471 s
[i
]->s
.k
= IPPROTO_AH
;
3473 s
[fix3
]->s
.jf
= s
[ahcheck
];
3480 * X = X + (P[X + 1] + 2) * 4;
3483 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3485 /* A = P[X + packet head]; */
3486 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3490 s
[i
] = new_stmt(BPF_ST
);
3494 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
3497 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3501 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3503 /* A = P[X + packet head] */
3504 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
3508 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3512 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
3516 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
3519 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
3523 /* goto again; (must use BPF_JA for backward jump) */
3524 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
3525 s
[i
]->s
.k
= again
- i
- 1;
3530 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
3532 s
[fix2
]->s
.jt
= s
[end
];
3533 s
[fix4
]->s
.jf
= s
[end
];
3534 s
[fix5
]->s
.jt
= s
[end
];
3541 for (i
= 0; i
< max
- 1; i
++)
3542 s
[i
]->next
= s
[i
+ 1];
3543 s
[max
- 1]->next
= NULL
;
3548 b
= new_block(JMP(BPF_JEQ
));
3549 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
3559 static struct block
*
3560 gen_proto(v
, proto
, dir
)
3565 struct block
*b0
, *b1
;
3567 if (dir
!= Q_DEFAULT
)
3568 bpf_error("direction applied to 'proto'");
3573 b0
= gen_proto(v
, Q_IP
, dir
);
3574 b1
= gen_proto(v
, Q_IPV6
, dir
);
3582 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
3583 * not LLC encapsulation with LLCSAP_IP.
3585 * For IEEE 802 networks - which includes 802.5 token ring
3586 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
3587 * says that SNAP encapsulation is used, not LLC encapsulation
3590 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
3591 * RFC 2225 say that SNAP encapsulation is used, not LLC
3592 * encapsulation with LLCSAP_IP.
3594 * So we always check for ETHERTYPE_IP.
3596 b0
= gen_linktype(ETHERTYPE_IP
);
3598 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
3600 b1
= gen_protochain(v
, Q_IP
);
3610 * Frame Relay packets typically have an OSI
3611 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3612 * generates code to check for all the OSI
3613 * NLPIDs, so calling it and then adding a check
3614 * for the particular NLPID for which we're
3615 * looking is bogus, as we can just check for
3618 * What we check for is the NLPID and a frame
3619 * control field value of UI, i.e. 0x03 followed
3622 * XXX - assumes a 2-byte Frame Relay header with
3623 * DLCI and flags. What if the address is longer?
3625 * XXX - what about SNAP-encapsulated frames?
3627 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3632 * Cisco uses an Ethertype lookalike - for OSI,
3635 b0
= gen_linktype(LLCSAP_ISONS
<<8 | LLCSAP_ISONS
);
3636 /* OSI in C-HDLC is stuffed with a fudge byte */
3637 b1
= gen_cmp(off_nl_nosnap
+1, BPF_B
, (long)v
);
3642 b0
= gen_linktype(LLCSAP_ISONS
);
3643 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3649 b0
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
3651 * 4 is the offset of the PDU type relative to the IS-IS
3654 b1
= gen_cmp(off_nl_nosnap
+4, BPF_B
, (long)v
);
3659 bpf_error("arp does not encapsulate another protocol");
3663 bpf_error("rarp does not encapsulate another protocol");
3667 bpf_error("atalk encapsulation is not specifiable");
3671 bpf_error("decnet encapsulation is not specifiable");
3675 bpf_error("sca does not encapsulate another protocol");
3679 bpf_error("lat does not encapsulate another protocol");
3683 bpf_error("moprc does not encapsulate another protocol");
3687 bpf_error("mopdl does not encapsulate another protocol");
3691 return gen_linktype(v
);
3694 bpf_error("'udp proto' is bogus");
3698 bpf_error("'tcp proto' is bogus");
3702 bpf_error("'sctp proto' is bogus");
3706 bpf_error("'icmp proto' is bogus");
3710 bpf_error("'igmp proto' is bogus");
3714 bpf_error("'igrp proto' is bogus");
3718 bpf_error("'pim proto' is bogus");
3722 bpf_error("'vrrp proto' is bogus");
3727 b0
= gen_linktype(ETHERTYPE_IPV6
);
3729 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3731 b1
= gen_protochain(v
, Q_IPV6
);
3737 bpf_error("'icmp6 proto' is bogus");
3741 bpf_error("'ah proto' is bogus");
3744 bpf_error("'ah proto' is bogus");
3747 bpf_error("'stp proto' is bogus");
3750 bpf_error("'ipx proto' is bogus");
3753 bpf_error("'netbeui proto' is bogus");
3764 register const char *name
;
3767 int proto
= q
.proto
;
3771 bpf_u_int32 mask
, addr
;
3773 bpf_u_int32
**alist
;
3776 struct sockaddr_in
*sin
;
3777 struct sockaddr_in6
*sin6
;
3778 struct addrinfo
*res
, *res0
;
3779 struct in6_addr mask128
;
3781 struct block
*b
, *tmp
;
3782 int port
, real_proto
;
3787 addr
= pcap_nametonetaddr(name
);
3789 bpf_error("unknown network '%s'", name
);
3790 /* Left justify network addr and calculate its network mask */
3792 while (addr
&& (addr
& 0xff000000) == 0) {
3796 return gen_host(addr
, mask
, proto
, dir
);
3800 if (proto
== Q_LINK
) {
3804 eaddr
= pcap_ether_hostton(name
);
3807 "unknown ether host '%s'", name
);
3808 b
= gen_ehostop(eaddr
, dir
);
3813 eaddr
= pcap_ether_hostton(name
);
3816 "unknown FDDI host '%s'", name
);
3817 b
= gen_fhostop(eaddr
, dir
);
3822 eaddr
= pcap_ether_hostton(name
);
3825 "unknown token ring host '%s'", name
);
3826 b
= gen_thostop(eaddr
, dir
);
3830 case DLT_IEEE802_11
:
3831 eaddr
= pcap_ether_hostton(name
);
3834 "unknown 802.11 host '%s'", name
);
3835 b
= gen_wlanhostop(eaddr
, dir
);
3839 case DLT_IP_OVER_FC
:
3840 eaddr
= pcap_ether_hostton(name
);
3843 "unknown Fibre Channel host '%s'", name
);
3844 b
= gen_ipfchostop(eaddr
, dir
);
3853 * Check that the packet doesn't begin
3854 * with an LE Control marker. (We've
3855 * already generated a test for LANE.)
3857 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
,
3861 eaddr
= pcap_ether_hostton(name
);
3864 "unknown ether host '%s'", name
);
3865 b
= gen_ehostop(eaddr
, dir
);
3871 bpf_error("only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
3872 } else if (proto
== Q_DECNET
) {
3873 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3875 * I don't think DECNET hosts can be multihomed, so
3876 * there is no need to build up a list of addresses
3878 return (gen_host(dn_addr
, 0, proto
, dir
));
3881 alist
= pcap_nametoaddr(name
);
3882 if (alist
== NULL
|| *alist
== NULL
)
3883 bpf_error("unknown host '%s'", name
);
3885 if (off_linktype
== -1 && tproto
== Q_DEFAULT
)
3887 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3889 tmp
= gen_host(**alist
++, 0xffffffff,
3896 memset(&mask128
, 0xff, sizeof(mask128
));
3897 res0
= res
= pcap_nametoaddrinfo(name
);
3899 bpf_error("unknown host '%s'", name
);
3901 tproto
= tproto6
= proto
;
3902 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3906 for (res
= res0
; res
; res
= res
->ai_next
) {
3907 switch (res
->ai_family
) {
3909 if (tproto
== Q_IPV6
)
3912 sin
= (struct sockaddr_in
*)
3914 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3915 0xffffffff, tproto
, dir
);
3918 if (tproto6
== Q_IP
)
3921 sin6
= (struct sockaddr_in6
*)
3923 tmp
= gen_host6(&sin6
->sin6_addr
,
3924 &mask128
, tproto6
, dir
);
3935 bpf_error("unknown host '%s'%s", name
,
3936 (proto
== Q_DEFAULT
)
3938 : " for specified address family");
3945 if (proto
!= Q_DEFAULT
&&
3946 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3947 bpf_error("illegal qualifier of 'port'");
3948 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3949 bpf_error("unknown port '%s'", name
);
3950 if (proto
== Q_UDP
) {
3951 if (real_proto
== IPPROTO_TCP
)
3952 bpf_error("port '%s' is tcp", name
);
3953 else if (real_proto
== IPPROTO_SCTP
)
3954 bpf_error("port '%s' is sctp", name
);
3956 /* override PROTO_UNDEF */
3957 real_proto
= IPPROTO_UDP
;
3959 if (proto
== Q_TCP
) {
3960 if (real_proto
== IPPROTO_UDP
)
3961 bpf_error("port '%s' is udp", name
);
3963 else if (real_proto
== IPPROTO_SCTP
)
3964 bpf_error("port '%s' is sctp", name
);
3966 /* override PROTO_UNDEF */
3967 real_proto
= IPPROTO_TCP
;
3969 if (proto
== Q_SCTP
) {
3970 if (real_proto
== IPPROTO_UDP
)
3971 bpf_error("port '%s' is udp", name
);
3973 else if (real_proto
== IPPROTO_TCP
)
3974 bpf_error("port '%s' is tcp", name
);
3976 /* override PROTO_UNDEF */
3977 real_proto
= IPPROTO_SCTP
;
3980 return gen_port(port
, real_proto
, dir
);
3984 b
= gen_port(port
, real_proto
, dir
);
3985 gen_or(gen_port6(port
, real_proto
, dir
), b
);
3992 eaddr
= pcap_ether_hostton(name
);
3994 bpf_error("unknown ether host: %s", name
);
3996 alist
= pcap_nametoaddr(name
);
3997 if (alist
== NULL
|| *alist
== NULL
)
3998 bpf_error("unknown host '%s'", name
);
3999 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
4003 bpf_error("'gateway' not supported in this configuration");
4007 real_proto
= lookup_proto(name
, proto
);
4008 if (real_proto
>= 0)
4009 return gen_proto(real_proto
, proto
, dir
);
4011 bpf_error("unknown protocol: %s", name
);
4014 real_proto
= lookup_proto(name
, proto
);
4015 if (real_proto
>= 0)
4016 return gen_protochain(real_proto
, proto
, dir
);
4018 bpf_error("unknown protocol: %s", name
);
4030 gen_mcode(s1
, s2
, masklen
, q
)
4031 register const char *s1
, *s2
;
4032 register int masklen
;
4035 register int nlen
, mlen
;
4038 nlen
= __pcap_atoin(s1
, &n
);
4039 /* Promote short ipaddr */
4043 mlen
= __pcap_atoin(s2
, &m
);
4044 /* Promote short ipaddr */
4047 bpf_error("non-network bits set in \"%s mask %s\"",
4050 /* Convert mask len to mask */
4052 bpf_error("mask length must be <= 32");
4053 m
= 0xffffffff << (32 - masklen
);
4055 bpf_error("non-network bits set in \"%s/%d\"",
4062 return gen_host(n
, m
, q
.proto
, q
.dir
);
4065 bpf_error("Mask syntax for networks only");
4072 register const char *s
;
4077 int proto
= q
.proto
;
4083 else if (q
.proto
== Q_DECNET
)
4084 vlen
= __pcap_atodn(s
, &v
);
4086 vlen
= __pcap_atoin(s
, &v
);
4093 if (proto
== Q_DECNET
)
4094 return gen_host(v
, 0, proto
, dir
);
4095 else if (proto
== Q_LINK
) {
4096 bpf_error("illegal link layer address");
4099 if (s
== NULL
&& q
.addr
== Q_NET
) {
4100 /* Promote short net number */
4101 while (v
&& (v
& 0xff000000) == 0) {
4106 /* Promote short ipaddr */
4110 return gen_host(v
, mask
, proto
, dir
);
4115 proto
= IPPROTO_UDP
;
4116 else if (proto
== Q_TCP
)
4117 proto
= IPPROTO_TCP
;
4118 else if (proto
== Q_SCTP
)
4119 proto
= IPPROTO_SCTP
;
4120 else if (proto
== Q_DEFAULT
)
4121 proto
= PROTO_UNDEF
;
4123 bpf_error("illegal qualifier of 'port'");
4126 return gen_port((int)v
, proto
, dir
);
4130 b
= gen_port((int)v
, proto
, dir
);
4131 gen_or(gen_port6((int)v
, proto
, dir
), b
);
4137 bpf_error("'gateway' requires a name");
4141 return gen_proto((int)v
, proto
, dir
);
4144 return gen_protochain((int)v
, proto
, dir
);
4159 gen_mcode6(s1
, s2
, masklen
, q
)
4160 register const char *s1
, *s2
;
4161 register int masklen
;
4164 struct addrinfo
*res
;
4165 struct in6_addr
*addr
;
4166 struct in6_addr mask
;
4171 bpf_error("no mask %s supported", s2
);
4173 res
= pcap_nametoaddrinfo(s1
);
4175 bpf_error("invalid ip6 address %s", s1
);
4177 bpf_error("%s resolved to multiple address", s1
);
4178 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
4180 if (sizeof(mask
) * 8 < masklen
)
4181 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
4182 memset(&mask
, 0, sizeof(mask
));
4183 memset(&mask
, 0xff, masklen
/ 8);
4185 mask
.s6_addr
[masklen
/ 8] =
4186 (0xff << (8 - masklen
% 8)) & 0xff;
4189 a
= (u_int32_t
*)addr
;
4190 m
= (u_int32_t
*)&mask
;
4191 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
4192 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
4193 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
4201 bpf_error("Mask syntax for networks only");
4205 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
4210 bpf_error("invalid qualifier against IPv6 address");
4218 register const u_char
*eaddr
;
4221 struct block
*b
, *tmp
;
4223 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4224 if (linktype
== DLT_EN10MB
)
4225 return gen_ehostop(eaddr
, (int)q
.dir
);
4226 if (linktype
== DLT_FDDI
)
4227 return gen_fhostop(eaddr
, (int)q
.dir
);
4228 if (linktype
== DLT_IEEE802
)
4229 return gen_thostop(eaddr
, (int)q
.dir
);
4230 if (linktype
== DLT_IEEE802_11
)
4231 return gen_wlanhostop(eaddr
, (int)q
.dir
);
4232 if (linktype
== DLT_SUNATM
&& is_lane
) {
4234 * Check that the packet doesn't begin with an
4235 * LE Control marker. (We've already generated
4238 tmp
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4242 * Now check the MAC address.
4244 b
= gen_ehostop(eaddr
, (int)q
.dir
);
4248 if (linktype
== DLT_IP_OVER_FC
)
4249 return gen_ipfchostop(eaddr
, (int)q
.dir
);
4250 bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
4252 bpf_error("ethernet address used in non-ether expression");
4258 struct slist
*s0
, *s1
;
4261 * This is definitely not the best way to do this, but the
4262 * lists will rarely get long.
4269 static struct slist
*
4275 s
= new_stmt(BPF_LDX
|BPF_MEM
);
4280 static struct slist
*
4286 s
= new_stmt(BPF_LD
|BPF_MEM
);
4292 gen_load(proto
, index
, size
)
4297 struct slist
*s
, *tmp
;
4299 int regno
= alloc_reg();
4301 free_reg(index
->regno
);
4305 bpf_error("data size must be 1, 2, or 4");
4321 bpf_error("unsupported index operation");
4325 * XXX - what about ATM LANE? Should the index be
4326 * relative to the beginning of the AAL5 frame, so
4327 * that 0 refers to the beginning of the LE Control
4328 * field, or relative to the beginning of the LAN
4329 * frame, so that 0 refers, for Ethernet LANE, to
4330 * the beginning of the destination address?
4332 s
= xfer_to_x(index
);
4333 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4335 sappend(index
->s
, s
);
4350 /* XXX Note that we assume a fixed link header here. */
4351 s
= xfer_to_x(index
);
4352 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
4355 sappend(index
->s
, s
);
4357 b
= gen_proto_abbrev(proto
);
4359 gen_and(index
->b
, b
);
4371 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
4373 sappend(s
, xfer_to_a(index
));
4374 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
4375 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
4376 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
4378 sappend(index
->s
, s
);
4380 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
4382 gen_and(index
->b
, b
);
4384 gen_and(gen_proto_abbrev(Q_IP
), b
);
4390 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
4394 index
->regno
= regno
;
4395 s
= new_stmt(BPF_ST
);
4397 sappend(index
->s
, s
);
4403 gen_relation(code
, a0
, a1
, reversed
)
4405 struct arth
*a0
, *a1
;
4408 struct slist
*s0
, *s1
, *s2
;
4409 struct block
*b
, *tmp
;
4413 if (code
== BPF_JEQ
) {
4414 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
4415 b
= new_block(JMP(code
));
4419 b
= new_block(BPF_JMP
|code
|BPF_X
);
4425 sappend(a0
->s
, a1
->s
);
4429 free_reg(a0
->regno
);
4430 free_reg(a1
->regno
);
4432 /* 'and' together protocol checks */
4435 gen_and(a0
->b
, tmp
= a1
->b
);
4451 int regno
= alloc_reg();
4452 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
4455 s
= new_stmt(BPF_LD
|BPF_LEN
);
4456 s
->next
= new_stmt(BPF_ST
);
4457 s
->next
->s
.k
= regno
;
4472 a
= (struct arth
*)newchunk(sizeof(*a
));
4476 s
= new_stmt(BPF_LD
|BPF_IMM
);
4478 s
->next
= new_stmt(BPF_ST
);
4494 s
= new_stmt(BPF_ALU
|BPF_NEG
);
4497 s
= new_stmt(BPF_ST
);
4505 gen_arth(code
, a0
, a1
)
4507 struct arth
*a0
, *a1
;
4509 struct slist
*s0
, *s1
, *s2
;
4513 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
4518 sappend(a0
->s
, a1
->s
);
4520 free_reg(a0
->regno
);
4521 free_reg(a1
->regno
);
4523 s0
= new_stmt(BPF_ST
);
4524 a0
->regno
= s0
->s
.k
= alloc_reg();
4531 * Here we handle simple allocation of the scratch registers.
4532 * If too many registers are alloc'd, the allocator punts.
4534 static int regused
[BPF_MEMWORDS
];
4538 * Return the next free register.
4543 int n
= BPF_MEMWORDS
;
4546 if (regused
[curreg
])
4547 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
4549 regused
[curreg
] = 1;
4553 bpf_error("too many registers needed to evaluate expression");
4558 * Return a register to the table so it can
4568 static struct block
*
4575 s
= new_stmt(BPF_LD
|BPF_LEN
);
4576 b
= new_block(JMP(jmp
));
4587 return gen_len(BPF_JGE
, n
);
4591 * Actually, this is less than or equal.
4599 b
= gen_len(BPF_JGT
, n
);
4606 gen_byteop(op
, idx
, val
)
4617 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4620 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4621 b
->s
.code
= JMP(BPF_JGE
);
4626 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
4627 b
->s
.code
= JMP(BPF_JGT
);
4631 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
4635 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
4639 b
= new_block(JMP(BPF_JEQ
));
4646 static u_char abroadcast
[] = { 0x0 };
4649 gen_broadcast(proto
)
4652 bpf_u_int32 hostmask
;
4653 struct block
*b0
, *b1
, *b2
;
4654 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4660 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4661 return gen_ahostop(abroadcast
, Q_DST
);
4662 if (linktype
== DLT_EN10MB
)
4663 return gen_ehostop(ebroadcast
, Q_DST
);
4664 if (linktype
== DLT_FDDI
)
4665 return gen_fhostop(ebroadcast
, Q_DST
);
4666 if (linktype
== DLT_IEEE802
)
4667 return gen_thostop(ebroadcast
, Q_DST
);
4668 if (linktype
== DLT_IEEE802_11
)
4669 return gen_wlanhostop(ebroadcast
, Q_DST
);
4670 if (linktype
== DLT_IP_OVER_FC
)
4671 return gen_ipfchostop(ebroadcast
, Q_DST
);
4672 if (linktype
== DLT_SUNATM
&& is_lane
) {
4674 * Check that the packet doesn't begin with an
4675 * LE Control marker. (We've already generated
4678 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4682 * Now check the MAC address.
4684 b0
= gen_ehostop(ebroadcast
, Q_DST
);
4688 bpf_error("not a broadcast link");
4692 b0
= gen_linktype(ETHERTYPE_IP
);
4693 hostmask
= ~netmask
;
4694 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
4695 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
4696 (bpf_int32
)(~0 & hostmask
), hostmask
);
4701 bpf_error("only link-layer/IP broadcast filters supported");
4705 * Generate code to test the low-order bit of a MAC address (that's
4706 * the bottom bit of the *first* byte).
4708 static struct block
*
4709 gen_mac_multicast(offset
)
4712 register struct block
*b0
;
4713 register struct slist
*s
;
4715 /* link[offset] & 1 != 0 */
4716 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4718 b0
= new_block(JMP(BPF_JSET
));
4725 gen_multicast(proto
)
4728 register struct block
*b0
, *b1
, *b2
;
4729 register struct slist
*s
;
4735 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
4736 /* all ARCnet multicasts use the same address */
4737 return gen_ahostop(abroadcast
, Q_DST
);
4739 if (linktype
== DLT_EN10MB
) {
4740 /* ether[0] & 1 != 0 */
4741 return gen_mac_multicast(0);
4744 if (linktype
== DLT_FDDI
) {
4746 * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX
4748 * XXX - was that referring to bit-order issues?
4750 /* fddi[1] & 1 != 0 */
4751 return gen_mac_multicast(1);
4754 if (linktype
== DLT_IEEE802
) {
4755 /* tr[2] & 1 != 0 */
4756 return gen_mac_multicast(2);
4759 if (linktype
== DLT_IEEE802_11
) {
4763 * For control frames, there is no DA.
4765 * For management frames, DA is at an
4766 * offset of 4 from the beginning of
4769 * For data frames, DA is at an offset
4770 * of 4 from the beginning of the packet
4771 * if To DS is clear and at an offset of
4772 * 16 from the beginning of the packet
4777 * Generate the tests to be done for data frames.
4779 * First, check for To DS set, i.e. "link[1] & 0x01".
4781 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4783 b1
= new_block(JMP(BPF_JSET
));
4784 b1
->s
.k
= 0x01; /* To DS */
4788 * If To DS is set, the DA is at 16.
4790 b0
= gen_mac_multicast(16);
4794 * Now, check for To DS not set, i.e. check
4795 * "!(link[1] & 0x01)".
4797 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4799 b2
= new_block(JMP(BPF_JSET
));
4800 b2
->s
.k
= 0x01; /* To DS */
4805 * If To DS is not set, the DA is at 4.
4807 b1
= gen_mac_multicast(4);
4811 * Now OR together the last two checks. That gives
4812 * the complete set of checks for data frames.
4817 * Now check for a data frame.
4818 * I.e, check "link[0] & 0x08".
4820 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4822 b1
= new_block(JMP(BPF_JSET
));
4827 * AND that with the checks done for data frames.
4832 * If the high-order bit of the type value is 0, this
4833 * is a management frame.
4834 * I.e, check "!(link[0] & 0x08)".
4836 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4838 b2
= new_block(JMP(BPF_JSET
));
4844 * For management frames, the DA is at 4.
4846 b1
= gen_mac_multicast(4);
4850 * OR that with the checks done for data frames.
4851 * That gives the checks done for management and
4857 * If the low-order bit of the type value is 1,
4858 * this is either a control frame or a frame
4859 * with a reserved type, and thus not a
4862 * I.e., check "!(link[0] & 0x04)".
4864 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4866 b1
= new_block(JMP(BPF_JSET
));
4872 * AND that with the checks for data and management
4879 if (linktype
== DLT_IP_OVER_FC
) {
4880 b0
= gen_mac_multicast(2);
4884 if (linktype
== DLT_SUNATM
&& is_lane
) {
4886 * Check that the packet doesn't begin with an
4887 * LE Control marker. (We've already generated
4890 b1
= gen_cmp(SUNATM_PKT_BEGIN_POS
, BPF_H
, 0xFF00);
4893 /* ether[off_mac] & 1 != 0 */
4894 b0
= gen_mac_multicast(off_mac
);
4899 /* Link not known to support multicasts */
4903 b0
= gen_linktype(ETHERTYPE_IP
);
4904 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4905 b1
->s
.code
= JMP(BPF_JGE
);
4911 b0
= gen_linktype(ETHERTYPE_IPV6
);
4912 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4917 bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
4921 * generate command for inbound/outbound. It's here so we can
4922 * make it link-type specific. 'dir' = 0 implies "inbound",
4923 * = 1 implies "outbound".
4929 register struct block
*b0
;
4932 * Only some data link types support inbound/outbound qualifiers.
4936 b0
= gen_relation(BPF_JEQ
,
4937 gen_load(Q_LINK
, gen_loadi(0), 1),
4945 * Match packets sent by this machine.
4947 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_OUTGOING
);
4950 * Match packets sent to this machine.
4951 * (No broadcast or multicast packets, or
4952 * packets sent to some other machine and
4953 * received promiscuously.)
4955 * XXX - packets sent to other machines probably
4956 * shouldn't be matched, but what about broadcast
4957 * or multicast packets we received?
4959 b0
= gen_cmp(0, BPF_H
, LINUX_SLL_HOST
);
4964 b0
= gen_cmp(26, BPF_H
,
4965 (bpf_int32
)((dir
== 0) ? PF_IN
: PF_OUT
));
4969 bpf_error("inbound/outbound not supported on linktype %d",
4977 /* PF firewall log matched interface */
4979 gen_pf_ifname(char *ifname
)
4981 if (linktype
!= DLT_PFLOG
) {
4982 bpf_error("ifname supported only for DLT_PFLOG");
4985 if (strlen(ifname
) >= 16) {
4986 bpf_error("ifname interface names can't be larger than 16 characters");
4989 return (gen_bcmp(4, strlen(ifname
), ifname
));
4993 /* PF firewall log rule number */
4997 if (linktype
!= DLT_PFLOG
) {
4998 bpf_error("rnr supported only for DLT_PFLOG");
5002 return (gen_cmp(20, BPF_H
, (bpf_int32
)rnr
));
5005 /* PF firewall log reason code */
5007 gen_pf_reason(int reason
)
5009 if (linktype
!= DLT_PFLOG
) {
5010 bpf_error("reason supported only for DLT_PFLOG");
5014 return (gen_cmp(22, BPF_H
, (bpf_int32
)reason
));
5017 /* PF firewall log action */
5019 gen_pf_action(int action
)
5021 if (linktype
!= DLT_PFLOG
) {
5022 bpf_error("action supported only for DLT_PFLOG");
5026 return (gen_cmp(24, BPF_H
, (bpf_int32
)action
));
5031 register const u_char
*eaddr
;
5034 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
5035 if (linktype
== DLT_ARCNET
|| linktype
== DLT_ARCNET_LINUX
)
5036 return gen_ahostop(eaddr
, (int)q
.dir
);
5038 bpf_error("ARCnet address used in non-arc expression");
5042 static struct block
*
5043 gen_ahostop(eaddr
, dir
)
5044 register const u_char
*eaddr
;
5047 register struct block
*b0
, *b1
;
5050 /* src comes first, different from Ethernet */
5052 return gen_bcmp(0, 1, eaddr
);
5055 return gen_bcmp(1, 1, eaddr
);
5058 b0
= gen_ahostop(eaddr
, Q_SRC
);
5059 b1
= gen_ahostop(eaddr
, Q_DST
);
5065 b0
= gen_ahostop(eaddr
, Q_SRC
);
5066 b1
= gen_ahostop(eaddr
, Q_DST
);
5075 * support IEEE 802.1Q VLAN trunk over ethernet
5084 * Change the offsets to point to the type and data fields within
5085 * the VLAN packet. This is somewhat of a kludge.
5087 if (orig_nl
== (u_int
)-1) {
5088 orig_linktype
= off_linktype
; /* save original values */
5090 orig_nl_nosnap
= off_nl_nosnap
;
5101 bpf_error("no VLAN support for data link type %d",
5107 /* check for VLAN */
5108 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
5110 /* If a specific VLAN is requested, check VLAN id */
5111 if (vlan_num
>= 0) {
5114 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
5123 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
5135 bpf_error("'vpi' supported only on raw ATM");
5138 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
5139 (u_int
)jvalue
, reverse
);
5144 bpf_error("'vci' supported only on raw ATM");
5147 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
5148 (u_int
)jvalue
, reverse
);
5152 if (off_proto
== -1)
5153 abort(); /* XXX - this isn't on FreeBSD */
5154 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
5155 (u_int
)jvalue
, reverse
);
5159 if (off_payload
== -1)
5161 b0
= gen_ncmp(BPF_B
, off_payload
+ MSG_TYPE_POS
, 0xffffffff,
5162 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
5167 bpf_error("'callref' supported only on raw ATM");
5168 if (off_proto
== -1)
5170 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
5171 (u_int
)jvalue
, reverse
);
5181 gen_atmtype_abbrev(type
)
5184 struct block
*b0
, *b1
;
5189 /* Get all packets in Meta signalling Circuit */
5191 bpf_error("'metac' supported only on raw ATM");
5192 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5193 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
5198 /* Get all packets in Broadcast Circuit*/
5200 bpf_error("'bcc' supported only on raw ATM");
5201 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5202 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
5207 /* Get all cells in Segment OAM F4 circuit*/
5209 bpf_error("'oam4sc' supported only on raw ATM");
5210 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5211 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5216 /* Get all cells in End-to-End OAM F4 Circuit*/
5218 bpf_error("'oam4ec' supported only on raw ATM");
5219 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5220 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5225 /* Get all packets in connection Signalling Circuit */
5227 bpf_error("'sc' supported only on raw ATM");
5228 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5229 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
5234 /* Get all packets in ILMI Circuit */
5236 bpf_error("'ilmic' supported only on raw ATM");
5237 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5238 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
5243 /* Get all LANE packets */
5245 bpf_error("'lane' supported only on raw ATM");
5246 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
5249 * Arrange that all subsequent tests assume LANE
5250 * rather than LLC-encapsulated packets, and set
5251 * the offsets appropriately for LANE-encapsulated
5254 * "off_mac" is the offset of the Ethernet header,
5255 * which is 2 bytes past the ATM pseudo-header
5256 * (skipping the pseudo-header and 2-byte LE Client
5257 * field). The other offsets are Ethernet offsets
5258 * relative to "off_mac".
5261 off_mac
= off_payload
+ 2; /* MAC header */
5262 off_linktype
= off_mac
+ 12;
5263 off_nl
= off_mac
+ 14; /* Ethernet II */
5264 off_nl_nosnap
= off_mac
+ 17; /* 802.3+802.2 */
5268 /* Get all LLC-encapsulated packets */
5270 bpf_error("'llc' supported only on raw ATM");
5271 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
5282 static struct block
*
5283 gen_msg_abbrev(type
)
5289 * Q.2931 signalling protocol messages for handling virtual circuits
5290 * establishment and teardown
5295 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
5299 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
5303 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
5307 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
5311 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
5314 case A_RELEASE_DONE
:
5315 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
5325 gen_atmmulti_abbrev(type
)
5328 struct block
*b0
, *b1
;
5334 bpf_error("'oam' supported only on raw ATM");
5335 b1
= gen_atmmulti_abbrev(A_OAMF4
);
5340 bpf_error("'oamf4' supported only on raw ATM");
5342 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
5343 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
5345 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
5351 * Get Q.2931 signalling messages for switched
5352 * virtual connection
5355 bpf_error("'connectmsg' supported only on raw ATM");
5356 b0
= gen_msg_abbrev(A_SETUP
);
5357 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5359 b0
= gen_msg_abbrev(A_CONNECT
);
5361 b0
= gen_msg_abbrev(A_CONNECTACK
);
5363 b0
= gen_msg_abbrev(A_RELEASE
);
5365 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5367 b0
= gen_atmtype_abbrev(A_SC
);
5373 bpf_error("'metaconnect' supported only on raw ATM");
5374 b0
= gen_msg_abbrev(A_SETUP
);
5375 b1
= gen_msg_abbrev(A_CALLPROCEED
);
5377 b0
= gen_msg_abbrev(A_CONNECT
);
5379 b0
= gen_msg_abbrev(A_RELEASE
);
5381 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
5383 b0
= gen_atmtype_abbrev(A_METAC
);