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.304 2007-12-29 02:34:23 guy Exp $ (LBL)";
32 #include <pcap-stdinc.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
39 * XXX - why was this included even on UNIX?
48 #include <sys/param.h>
51 #include <netinet/in.h>
67 #include "ethertype.h"
71 #include "ieee80211.h"
73 #include "sunatmpos.h"
77 #ifdef HAVE_NET_PFVAR_H
78 #include <sys/socket.h>
80 #include <net/pfvar.h>
81 #include <net/if_pflog.h>
84 #define offsetof(s, e) ((size_t)&((s *)0)->e)
88 #include <netdb.h> /* for "struct addrinfo" */
91 #include <pcap/namedb.h>
96 #define IPPROTO_SCTP 132
99 #ifdef HAVE_OS_PROTO_H
100 #include "os-proto.h"
103 #define JMP(c) ((c)|BPF_JMP|BPF_K)
106 static jmp_buf top_ctx
;
107 static pcap_t
*bpf_pcap
;
109 /* Hack for updating VLAN, MPLS, and PPPoE offsets. */
111 static u_int orig_linktype
= (u_int
)-1, orig_nl
= (u_int
)-1, label_stack_depth
= (u_int
)-1;
113 static u_int orig_linktype
= -1U, orig_nl
= -1U, label_stack_depth
= -1U;
118 static int pcap_fddipad
;
123 bpf_error(const char *fmt
, ...)
128 if (bpf_pcap
!= NULL
)
129 (void)vsnprintf(pcap_geterr(bpf_pcap
), PCAP_ERRBUF_SIZE
,
136 static void init_linktype(pcap_t
*);
138 static void init_regs(void);
139 static int alloc_reg(void);
140 static void free_reg(int);
142 static struct block
*root
;
145 * Value passed to gen_load_a() to indicate what the offset argument
149 OR_PACKET
, /* relative to the beginning of the packet */
150 OR_LINK
, /* relative to the beginning of the link-layer header */
151 OR_MACPL
, /* relative to the end of the MAC-layer header */
152 OR_NET
, /* relative to the network-layer header */
153 OR_NET_NOSNAP
, /* relative to the network-layer header, with no SNAP header at the link layer */
154 OR_TRAN_IPV4
, /* relative to the transport-layer header, with IPv4 network layer */
155 OR_TRAN_IPV6
/* relative to the transport-layer header, with IPv6 network layer */
159 * We divy out chunks of memory rather than call malloc each time so
160 * we don't have to worry about leaking memory. It's probably
161 * not a big deal if all this memory was wasted but if this ever
162 * goes into a library that would probably not be a good idea.
164 * XXX - this *is* in a library....
167 #define CHUNK0SIZE 1024
173 static struct chunk chunks
[NCHUNKS
];
174 static int cur_chunk
;
176 static void *newchunk(u_int
);
177 static void freechunks(void);
178 static inline struct block
*new_block(int);
179 static inline struct slist
*new_stmt(int);
180 static struct block
*gen_retblk(int);
181 static inline void syntax(void);
183 static void backpatch(struct block
*, struct block
*);
184 static void merge(struct block
*, struct block
*);
185 static struct block
*gen_cmp(enum e_offrel
, u_int
, u_int
, bpf_int32
);
186 static struct block
*gen_cmp_gt(enum e_offrel
, u_int
, u_int
, bpf_int32
);
187 static struct block
*gen_cmp_ge(enum e_offrel
, u_int
, u_int
, bpf_int32
);
188 static struct block
*gen_cmp_lt(enum e_offrel
, u_int
, u_int
, bpf_int32
);
189 static struct block
*gen_cmp_le(enum e_offrel
, u_int
, u_int
, bpf_int32
);
190 static struct block
*gen_mcmp(enum e_offrel
, u_int
, u_int
, bpf_int32
,
192 static struct block
*gen_bcmp(enum e_offrel
, u_int
, u_int
, const u_char
*);
193 static struct block
*gen_ncmp(enum e_offrel
, bpf_u_int32
, bpf_u_int32
,
194 bpf_u_int32
, bpf_u_int32
, int, bpf_int32
);
195 static struct slist
*gen_load_llrel(u_int
, u_int
);
196 static struct slist
*gen_load_macplrel(u_int
, u_int
);
197 static struct slist
*gen_load_a(enum e_offrel
, u_int
, u_int
);
198 static struct slist
*gen_loadx_iphdrlen(void);
199 static struct block
*gen_uncond(int);
200 static inline struct block
*gen_true(void);
201 static inline struct block
*gen_false(void);
202 static struct block
*gen_ether_linktype(int);
203 static struct block
*gen_linux_sll_linktype(int);
204 static struct slist
*gen_load_radiotap_llprefixlen(void);
205 static struct slist
*gen_load_ppi_llprefixlen(void);
206 static struct slist
*gen_load_avs_llprefixlen(void);
207 static void insert_compute_vloffsets(struct block
*);
208 static struct slist
*gen_llprefixlen(void);
209 static struct slist
*gen_off_macpl(void);
210 static int ethertype_to_ppptype(int);
211 static struct block
*gen_linktype(int);
212 static struct block
*gen_snap(bpf_u_int32
, bpf_u_int32
);
213 static struct block
*gen_llc_linktype(int);
214 static struct block
*gen_hostop(bpf_u_int32
, bpf_u_int32
, int, int, u_int
, u_int
);
216 static struct block
*gen_hostop6(struct in6_addr
*, struct in6_addr
*, int, int, u_int
, u_int
);
218 static struct block
*gen_ahostop(const u_char
*, int);
219 static struct block
*gen_ehostop(const u_char
*, int);
220 static struct block
*gen_fhostop(const u_char
*, int);
221 static struct block
*gen_thostop(const u_char
*, int);
222 static struct block
*gen_wlanhostop(const u_char
*, int);
223 static struct block
*gen_ipfchostop(const u_char
*, int);
224 static struct block
*gen_dnhostop(bpf_u_int32
, int);
225 static struct block
*gen_mpls_linktype(int);
226 static struct block
*gen_host(bpf_u_int32
, bpf_u_int32
, int, int, int);
228 static struct block
*gen_host6(struct in6_addr
*, struct in6_addr
*, int, int, int);
231 static struct block
*gen_gateway(const u_char
*, bpf_u_int32
**, int, int);
233 static struct block
*gen_ipfrag(void);
234 static struct block
*gen_portatom(int, bpf_int32
);
235 static struct block
*gen_portrangeatom(int, bpf_int32
, bpf_int32
);
237 static struct block
*gen_portatom6(int, bpf_int32
);
238 static struct block
*gen_portrangeatom6(int, bpf_int32
, bpf_int32
);
240 struct block
*gen_portop(int, int, int);
241 static struct block
*gen_port(int, int, int);
242 struct block
*gen_portrangeop(int, int, int, int);
243 static struct block
*gen_portrange(int, int, int, int);
245 struct block
*gen_portop6(int, int, int);
246 static struct block
*gen_port6(int, int, int);
247 struct block
*gen_portrangeop6(int, int, int, int);
248 static struct block
*gen_portrange6(int, int, int, int);
250 static int lookup_proto(const char *, int);
251 static struct block
*gen_protochain(int, int, int);
252 static struct block
*gen_proto(int, int, int);
253 static struct slist
*xfer_to_x(struct arth
*);
254 static struct slist
*xfer_to_a(struct arth
*);
255 static struct block
*gen_mac_multicast(int);
256 static struct block
*gen_len(int, int);
257 static struct block
*gen_check_802_11_data_frame(void);
259 static struct block
*gen_ppi_dlt_check(void);
260 static struct block
*gen_msg_abbrev(int type
);
271 /* XXX Round up to nearest long. */
272 n
= (n
+ sizeof(long) - 1) & ~(sizeof(long) - 1);
274 /* XXX Round up to structure boundary. */
278 cp
= &chunks
[cur_chunk
];
279 if (n
> cp
->n_left
) {
280 ++cp
, k
= ++cur_chunk
;
282 bpf_error("out of memory");
283 size
= CHUNK0SIZE
<< k
;
284 cp
->m
= (void *)malloc(size
);
286 bpf_error("out of memory");
287 memset((char *)cp
->m
, 0, size
);
290 bpf_error("out of memory");
293 return (void *)((char *)cp
->m
+ cp
->n_left
);
302 for (i
= 0; i
< NCHUNKS
; ++i
)
303 if (chunks
[i
].m
!= NULL
) {
310 * A strdup whose allocations are freed after code generation is over.
314 register const char *s
;
316 int n
= strlen(s
) + 1;
317 char *cp
= newchunk(n
);
323 static inline struct block
*
329 p
= (struct block
*)newchunk(sizeof(*p
));
336 static inline struct slist
*
342 p
= (struct slist
*)newchunk(sizeof(*p
));
348 static struct block
*
352 struct block
*b
= new_block(BPF_RET
|BPF_K
);
361 bpf_error("syntax error in filter expression");
364 static bpf_u_int32 netmask
;
369 pcap_compile(pcap_t
*p
, struct bpf_program
*program
,
370 const char *buf
, int optimize
, bpf_u_int32 mask
)
373 const char * volatile xbuf
= buf
;
381 if (setjmp(top_ctx
)) {
389 snaplen
= pcap_snapshot(p
);
391 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
392 "snaplen of 0 rejects all packets");
396 lex_init(xbuf
? xbuf
: "");
404 root
= gen_retblk(snaplen
);
406 if (optimize
&& !no_optimize
) {
409 (root
->s
.code
== (BPF_RET
|BPF_K
) && root
->s
.k
== 0))
410 bpf_error("expression rejects all packets");
412 program
->bf_insns
= icode_to_fcode(root
, &len
);
413 program
->bf_len
= len
;
421 * entry point for using the compiler with no pcap open
422 * pass in all the stuff that is needed explicitly instead.
425 pcap_compile_nopcap(int snaplen_arg
, int linktype_arg
,
426 struct bpf_program
*program
,
427 const char *buf
, int optimize
, bpf_u_int32 mask
)
432 p
= pcap_open_dead(linktype_arg
, snaplen_arg
);
435 ret
= pcap_compile(p
, program
, buf
, optimize
, mask
);
441 * Clean up a "struct bpf_program" by freeing all the memory allocated
445 pcap_freecode(struct bpf_program
*program
)
448 if (program
->bf_insns
!= NULL
) {
449 free((char *)program
->bf_insns
);
450 program
->bf_insns
= NULL
;
455 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
456 * which of the jt and jf fields has been resolved and which is a pointer
457 * back to another unresolved block (or nil). At least one of the fields
458 * in each block is already resolved.
461 backpatch(list
, target
)
462 struct block
*list
, *target
;
479 * Merge the lists in b0 and b1, using the 'sense' field to indicate
480 * which of jt and jf is the link.
484 struct block
*b0
, *b1
;
486 register struct block
**p
= &b0
;
488 /* Find end of list. */
490 p
= !((*p
)->sense
) ? &JT(*p
) : &JF(*p
);
492 /* Concatenate the lists. */
500 struct block
*ppi_dlt_check
;
503 * Insert before the statements of the first (root) block any
504 * statements needed to load the lengths of any variable-length
505 * headers into registers.
507 * XXX - a fancier strategy would be to insert those before the
508 * statements of all blocks that use those lengths and that
509 * have no predecessors that use them, so that we only compute
510 * the lengths if we need them. There might be even better
511 * approaches than that.
513 * However, those strategies would be more complicated, and
514 * as we don't generate code to compute a length if the
515 * program has no tests that use the length, and as most
516 * tests will probably use those lengths, we would just
517 * postpone computing the lengths so that it's not done
518 * for tests that fail early, and it's not clear that's
521 insert_compute_vloffsets(p
->head
);
524 * For DLT_PPI captures, generate a check of the per-packet
525 * DLT value to make sure it's DLT_IEEE802_11.
527 ppi_dlt_check
= gen_ppi_dlt_check();
528 if (ppi_dlt_check
!= NULL
)
529 gen_and(ppi_dlt_check
, p
);
531 backpatch(p
, gen_retblk(snaplen
));
532 p
->sense
= !p
->sense
;
533 backpatch(p
, gen_retblk(0));
539 struct block
*b0
, *b1
;
541 backpatch(b0
, b1
->head
);
542 b0
->sense
= !b0
->sense
;
543 b1
->sense
= !b1
->sense
;
545 b1
->sense
= !b1
->sense
;
551 struct block
*b0
, *b1
;
553 b0
->sense
= !b0
->sense
;
554 backpatch(b0
, b1
->head
);
555 b0
->sense
= !b0
->sense
;
564 b
->sense
= !b
->sense
;
567 static struct block
*
568 gen_cmp(offrel
, offset
, size
, v
)
569 enum e_offrel offrel
;
573 return gen_ncmp(offrel
, offset
, size
, 0xffffffff, BPF_JEQ
, 0, v
);
576 static struct block
*
577 gen_cmp_gt(offrel
, offset
, size
, v
)
578 enum e_offrel offrel
;
582 return gen_ncmp(offrel
, offset
, size
, 0xffffffff, BPF_JGT
, 0, v
);
585 static struct block
*
586 gen_cmp_ge(offrel
, offset
, size
, v
)
587 enum e_offrel offrel
;
591 return gen_ncmp(offrel
, offset
, size
, 0xffffffff, BPF_JGE
, 0, v
);
594 static struct block
*
595 gen_cmp_lt(offrel
, offset
, size
, v
)
596 enum e_offrel offrel
;
600 return gen_ncmp(offrel
, offset
, size
, 0xffffffff, BPF_JGE
, 1, v
);
603 static struct block
*
604 gen_cmp_le(offrel
, offset
, size
, v
)
605 enum e_offrel offrel
;
609 return gen_ncmp(offrel
, offset
, size
, 0xffffffff, BPF_JGT
, 1, v
);
612 static struct block
*
613 gen_mcmp(offrel
, offset
, size
, v
, mask
)
614 enum e_offrel offrel
;
619 return gen_ncmp(offrel
, offset
, size
, mask
, BPF_JEQ
, 0, v
);
622 static struct block
*
623 gen_bcmp(offrel
, offset
, size
, v
)
624 enum e_offrel offrel
;
625 register u_int offset
, size
;
626 register const u_char
*v
;
628 register struct block
*b
, *tmp
;
632 register const u_char
*p
= &v
[size
- 4];
633 bpf_int32 w
= ((bpf_int32
)p
[0] << 24) |
634 ((bpf_int32
)p
[1] << 16) | ((bpf_int32
)p
[2] << 8) | p
[3];
636 tmp
= gen_cmp(offrel
, offset
+ size
- 4, BPF_W
, w
);
643 register const u_char
*p
= &v
[size
- 2];
644 bpf_int32 w
= ((bpf_int32
)p
[0] << 8) | p
[1];
646 tmp
= gen_cmp(offrel
, offset
+ size
- 2, BPF_H
, w
);
653 tmp
= gen_cmp(offrel
, offset
, BPF_B
, (bpf_int32
)v
[0]);
662 * AND the field of size "size" at offset "offset" relative to the header
663 * specified by "offrel" with "mask", and compare it with the value "v"
664 * with the test specified by "jtype"; if "reverse" is true, the test
665 * should test the opposite of "jtype".
667 static struct block
*
668 gen_ncmp(offrel
, offset
, size
, mask
, jtype
, reverse
, v
)
669 enum e_offrel offrel
;
671 bpf_u_int32 offset
, size
, mask
, jtype
;
674 struct slist
*s
, *s2
;
677 s
= gen_load_a(offrel
, offset
, size
);
679 if (mask
!= 0xffffffff) {
680 s2
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
685 b
= new_block(JMP(jtype
));
688 if (reverse
&& (jtype
== BPF_JGT
|| jtype
== BPF_JGE
))
694 * Various code constructs need to know the layout of the data link
695 * layer. These variables give the necessary offsets from the beginning
696 * of the packet data.
700 * This is the offset of the beginning of the link-layer header from
701 * the beginning of the raw packet data.
703 * It's usually 0, except for 802.11 with a fixed-length radio header.
704 * (For 802.11 with a variable-length radio header, we have to generate
705 * code to compute that offset; off_ll is 0 in that case.)
710 * If there's a variable-length header preceding the link-layer header,
711 * "reg_off_ll" is the register number for a register containing the
712 * length of that header, and therefore the offset of the link-layer
713 * header from the beginning of the raw packet data. Otherwise,
714 * "reg_off_ll" is -1.
716 static int reg_off_ll
;
719 * This is the offset of the beginning of the MAC-layer header from
720 * the beginning of the link-layer header.
721 * It's usually 0, except for ATM LANE, where it's the offset, relative
722 * to the beginning of the raw packet data, of the Ethernet header.
724 static u_int off_mac
;
727 * This is the offset of the beginning of the MAC-layer payload,
728 * from the beginning of the raw packet data.
730 * I.e., it's the sum of the length of the link-layer header (without,
731 * for example, any 802.2 LLC header, so it's the MAC-layer
732 * portion of that header), plus any prefix preceding the
735 static u_int off_macpl
;
738 * This is 1 if the offset of the beginning of the MAC-layer payload
739 * from the beginning of the link-layer header is variable-length.
741 static int off_macpl_is_variable
;
744 * If the link layer has variable_length headers, "reg_off_macpl"
745 * is the register number for a register containing the length of the
746 * link-layer header plus the length of any variable-length header
747 * preceding the link-layer header. Otherwise, "reg_off_macpl"
750 static int reg_off_macpl
;
753 * "off_linktype" is the offset to information in the link-layer header
754 * giving the packet type. This offset is relative to the beginning
755 * of the link-layer header (i.e., it doesn't include off_ll).
757 * For Ethernet, it's the offset of the Ethernet type field.
759 * For link-layer types that always use 802.2 headers, it's the
760 * offset of the LLC header.
762 * For PPP, it's the offset of the PPP type field.
764 * For Cisco HDLC, it's the offset of the CHDLC type field.
766 * For BSD loopback, it's the offset of the AF_ value.
768 * For Linux cooked sockets, it's the offset of the type field.
770 * It's set to -1 for no encapsulation, in which case, IP is assumed.
772 static u_int off_linktype
;
775 * TRUE if "pppoes" appeared in the filter; it causes link-layer type
776 * checks to check the PPP header, assumed to follow a LAN-style link-
777 * layer header and a PPPoE session header.
779 static int is_pppoes
= 0;
782 * TRUE if the link layer includes an ATM pseudo-header.
784 static int is_atm
= 0;
787 * TRUE if "lane" appeared in the filter; it causes us to generate
788 * code that assumes LANE rather than LLC-encapsulated traffic in SunATM.
790 static int is_lane
= 0;
793 * These are offsets for the ATM pseudo-header.
795 static u_int off_vpi
;
796 static u_int off_vci
;
797 static u_int off_proto
;
800 * These are offsets for the MTP2 fields.
805 * These are offsets for the MTP3 fields.
807 static u_int off_sio
;
808 static u_int off_opc
;
809 static u_int off_dpc
;
810 static u_int off_sls
;
813 * This is the offset of the first byte after the ATM pseudo_header,
814 * or -1 if there is no ATM pseudo-header.
816 static u_int off_payload
;
819 * These are offsets to the beginning of the network-layer header.
820 * They are relative to the beginning of the MAC-layer payload (i.e.,
821 * they don't include off_ll or off_macpl).
823 * If the link layer never uses 802.2 LLC:
825 * "off_nl" and "off_nl_nosnap" are the same.
827 * If the link layer always uses 802.2 LLC:
829 * "off_nl" is the offset if there's a SNAP header following
832 * "off_nl_nosnap" is the offset if there's no SNAP header.
834 * If the link layer is Ethernet:
836 * "off_nl" is the offset if the packet is an Ethernet II packet
837 * (we assume no 802.3+802.2+SNAP);
839 * "off_nl_nosnap" is the offset if the packet is an 802.3 packet
840 * with an 802.2 header following it.
843 static u_int off_nl_nosnap
;
851 linktype
= pcap_datalink(p
);
853 pcap_fddipad
= p
->fddipad
;
857 * Assume it's not raw ATM with a pseudo-header, for now.
868 * And that we're not doing PPPoE.
873 * And assume we're not doing SS7.
882 * Also assume it's not 802.11.
886 off_macpl_is_variable
= 0;
890 label_stack_depth
= 0;
900 off_nl
= 0; /* XXX in reality, variable! */
901 off_nl_nosnap
= 0; /* no 802.2 LLC */
904 case DLT_ARCNET_LINUX
:
907 off_nl
= 0; /* XXX in reality, variable! */
908 off_nl_nosnap
= 0; /* no 802.2 LLC */
913 off_macpl
= 14; /* Ethernet header length */
914 off_nl
= 0; /* Ethernet II */
915 off_nl_nosnap
= 3; /* 802.3+802.2 */
920 * SLIP doesn't have a link level type. The 16 byte
921 * header is hacked into our SLIP driver.
926 off_nl_nosnap
= 0; /* no 802.2 LLC */
930 /* XXX this may be the same as the DLT_PPP_BSDOS case */
935 off_nl_nosnap
= 0; /* no 802.2 LLC */
943 off_nl_nosnap
= 0; /* no 802.2 LLC */
950 off_nl_nosnap
= 0; /* no 802.2 LLC */
955 case DLT_C_HDLC
: /* BSD/OS Cisco HDLC */
956 case DLT_PPP_SERIAL
: /* NetBSD sync/async serial PPP */
960 off_nl_nosnap
= 0; /* no 802.2 LLC */
965 * This does no include the Ethernet header, and
966 * only covers session state.
971 off_nl_nosnap
= 0; /* no 802.2 LLC */
978 off_nl_nosnap
= 0; /* no 802.2 LLC */
983 * FDDI doesn't really have a link-level type field.
984 * We set "off_linktype" to the offset of the LLC header.
986 * To check for Ethernet types, we assume that SSAP = SNAP
987 * is being used and pick out the encapsulated Ethernet type.
988 * XXX - should we generate code to check for SNAP?
992 off_linktype
+= pcap_fddipad
;
994 off_macpl
= 13; /* FDDI MAC header length */
996 off_macpl
+= pcap_fddipad
;
998 off_nl
= 8; /* 802.2+SNAP */
999 off_nl_nosnap
= 3; /* 802.2 */
1004 * Token Ring doesn't really have a link-level type field.
1005 * We set "off_linktype" to the offset of the LLC header.
1007 * To check for Ethernet types, we assume that SSAP = SNAP
1008 * is being used and pick out the encapsulated Ethernet type.
1009 * XXX - should we generate code to check for SNAP?
1011 * XXX - the header is actually variable-length.
1012 * Some various Linux patched versions gave 38
1013 * as "off_linktype" and 40 as "off_nl"; however,
1014 * if a token ring packet has *no* routing
1015 * information, i.e. is not source-routed, the correct
1016 * values are 20 and 22, as they are in the vanilla code.
1018 * A packet is source-routed iff the uppermost bit
1019 * of the first byte of the source address, at an
1020 * offset of 8, has the uppermost bit set. If the
1021 * packet is source-routed, the total number of bytes
1022 * of routing information is 2 plus bits 0x1F00 of
1023 * the 16-bit value at an offset of 14 (shifted right
1024 * 8 - figure out which byte that is).
1027 off_macpl
= 14; /* Token Ring MAC header length */
1028 off_nl
= 8; /* 802.2+SNAP */
1029 off_nl_nosnap
= 3; /* 802.2 */
1032 case DLT_IEEE802_11
:
1034 * 802.11 doesn't really have a link-level type field.
1035 * We set "off_linktype" to the offset of the LLC header.
1037 * To check for Ethernet types, we assume that SSAP = SNAP
1038 * is being used and pick out the encapsulated Ethernet type.
1039 * XXX - should we generate code to check for SNAP?
1041 * XXX - the header is actually variable-length. We
1042 * assume a 24-byte link-layer header, as appears in
1043 * data frames in networks with no bridges. If the
1044 * fromds and tods 802.11 header bits are both set,
1045 * it's actually supposed to be 30 bytes.
1048 off_macpl
= 0; /* link-layer header is variable-length */
1049 off_macpl_is_variable
= 1;
1050 off_nl
= 8; /* 802.2+SNAP */
1051 off_nl_nosnap
= 3; /* 802.2 */
1054 case DLT_PRISM_HEADER
:
1056 * Same as 802.11, but with an additional header before
1057 * the 802.11 header, containing a bunch of additional
1058 * information including radio-level information.
1060 * The header is 144 bytes long.
1062 * XXX - same variable-length header problem; at least
1063 * the Prism header is fixed-length.
1067 off_macpl
= 0; /* link-layer header is variable-length */
1068 off_macpl_is_variable
= 1;
1069 off_nl
= 8; /* 802.2+SNAP */
1070 off_nl_nosnap
= 3; /* 802.2 */
1073 case DLT_IEEE802_11_RADIO_AVS
:
1075 * Same as 802.11, but with an additional header before
1076 * the 802.11 header, containing a bunch of additional
1077 * information including radio-level information.
1079 * The radiotap header is variable length, and we
1080 * generate code to compute its length and store it
1081 * in a register. These offsets are relative to the
1082 * beginning of the 802.11 header.
1084 * XXX - in Linux, do any drivers that supply an AVS
1085 * header supply a link-layer type other than
1086 * ARPHRD_IEEE80211_PRISM? If so, we should map that
1087 * to DLT_IEEE802_11_RADIO_AVS; if not, or if there are
1088 * any drivers that supply an AVS header but supply
1089 * an ARPHRD value of ARPHRD_IEEE80211_PRISM, we'll
1090 * have to check the header in the generated code to
1091 * determine whether it's Prism or AVS.
1094 off_macpl
= 0; /* link-layer header is variable-length */
1095 off_macpl_is_variable
= 1;
1096 off_nl
= 8; /* 802.2+SNAP */
1097 off_nl_nosnap
= 3; /* 802.2 */
1101 * At the moment we treat PPI as normal Radiotap encoded
1102 * packets. The difference is in the function that generates
1103 * the code at the beginning to compute the header length.
1104 * Since this code generator of PPI supports bare 802.11
1105 * encapsulation only (i.e. the encapsulated DLT should be
1106 * DLT_IEEE802_11) we generate code to check for this too.
1109 case DLT_IEEE802_11_RADIO
:
1111 * Same as 802.11, but with an additional header before
1112 * the 802.11 header, containing a bunch of additional
1113 * information including radio-level information.
1115 * The radiotap header is variable length, and we
1116 * generate code to compute its length and store it
1117 * in a register. These offsets are relative to the
1118 * beginning of the 802.11 header.
1121 off_macpl
= 0; /* link-layer header is variable-length */
1122 off_macpl_is_variable
= 1;
1123 off_nl
= 8; /* 802.2+SNAP */
1124 off_nl_nosnap
= 3; /* 802.2 */
1127 case DLT_ATM_RFC1483
:
1128 case DLT_ATM_CLIP
: /* Linux ATM defines this */
1130 * assume routed, non-ISO PDUs
1131 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
1133 * XXX - what about ISO PDUs, e.g. CLNP, ISIS, ESIS,
1134 * or PPP with the PPP NLPID (e.g., PPPoA)? The
1135 * latter would presumably be treated the way PPPoE
1136 * should be, so you can do "pppoe and udp port 2049"
1137 * or "pppoa and tcp port 80" and have it check for
1138 * PPPo{A,E} and a PPP protocol of IP and....
1141 off_macpl
= 0; /* packet begins with LLC header */
1142 off_nl
= 8; /* 802.2+SNAP */
1143 off_nl_nosnap
= 3; /* 802.2 */
1148 * Full Frontal ATM; you get AALn PDUs with an ATM
1152 off_vpi
= SUNATM_VPI_POS
;
1153 off_vci
= SUNATM_VCI_POS
;
1154 off_proto
= PROTO_POS
;
1155 off_mac
= -1; /* assume LLC-encapsulated, so no MAC-layer header */
1156 off_payload
= SUNATM_PKT_BEGIN_POS
;
1157 off_linktype
= off_payload
;
1158 off_macpl
= off_payload
; /* if LLC-encapsulated */
1159 off_nl
= 8; /* 802.2+SNAP */
1160 off_nl_nosnap
= 3; /* 802.2 */
1167 off_nl_nosnap
= 0; /* no 802.2 LLC */
1170 case DLT_LINUX_SLL
: /* fake header for Linux cooked socket */
1174 off_nl_nosnap
= 0; /* no 802.2 LLC */
1179 * LocalTalk does have a 1-byte type field in the LLAP header,
1180 * but really it just indicates whether there is a "short" or
1181 * "long" DDP packet following.
1186 off_nl_nosnap
= 0; /* no 802.2 LLC */
1189 case DLT_IP_OVER_FC
:
1191 * RFC 2625 IP-over-Fibre-Channel doesn't really have a
1192 * link-level type field. We set "off_linktype" to the
1193 * offset of the LLC header.
1195 * To check for Ethernet types, we assume that SSAP = SNAP
1196 * is being used and pick out the encapsulated Ethernet type.
1197 * XXX - should we generate code to check for SNAP? RFC
1198 * 2625 says SNAP should be used.
1202 off_nl
= 8; /* 802.2+SNAP */
1203 off_nl_nosnap
= 3; /* 802.2 */
1208 * XXX - we should set this to handle SNAP-encapsulated
1209 * frames (NLPID of 0x80).
1214 off_nl_nosnap
= 0; /* no 802.2 LLC */
1218 * the only BPF-interesting FRF.16 frames are non-control frames;
1219 * Frame Relay has a variable length link-layer
1220 * so lets start with offset 4 for now and increments later on (FIXME);
1226 off_nl_nosnap
= 0; /* XXX - for now -> no 802.2 LLC */
1229 case DLT_APPLE_IP_OVER_IEEE1394
:
1233 off_nl_nosnap
= 0; /* no 802.2 LLC */
1236 case DLT_LINUX_IRDA
:
1238 * Currently, only raw "link[N:M]" filtering is supported.
1248 * Currently, only raw "link[N:M]" filtering is supported.
1256 case DLT_SYMANTEC_FIREWALL
:
1259 off_nl
= 0; /* Ethernet II */
1260 off_nl_nosnap
= 0; /* XXX - what does it do with 802.3 packets? */
1263 #ifdef HAVE_NET_PFVAR_H
1266 off_macpl
= PFLOG_HDRLEN
;
1268 off_nl_nosnap
= 0; /* no 802.2 LLC */
1272 case DLT_JUNIPER_MFR
:
1273 case DLT_JUNIPER_MLFR
:
1274 case DLT_JUNIPER_MLPPP
:
1275 case DLT_JUNIPER_PPP
:
1276 case DLT_JUNIPER_CHDLC
:
1277 case DLT_JUNIPER_FRELAY
:
1281 off_nl_nosnap
= -1; /* no 802.2 LLC */
1284 case DLT_JUNIPER_ATM1
:
1285 off_linktype
= 4; /* in reality variable between 4-8 */
1286 off_macpl
= 4; /* in reality variable between 4-8 */
1291 case DLT_JUNIPER_ATM2
:
1292 off_linktype
= 8; /* in reality variable between 8-12 */
1293 off_macpl
= 8; /* in reality variable between 8-12 */
1298 /* frames captured on a Juniper PPPoE service PIC
1299 * contain raw ethernet frames */
1300 case DLT_JUNIPER_PPPOE
:
1301 case DLT_JUNIPER_ETHER
:
1304 off_nl
= 18; /* Ethernet II */
1305 off_nl_nosnap
= 21; /* 802.3+802.2 */
1308 case DLT_JUNIPER_PPPOE_ATM
:
1312 off_nl_nosnap
= -1; /* no 802.2 LLC */
1315 case DLT_JUNIPER_GGSN
:
1319 off_nl_nosnap
= -1; /* no 802.2 LLC */
1322 case DLT_JUNIPER_ES
:
1324 off_macpl
= -1; /* not really a network layer but raw IP addresses */
1325 off_nl
= -1; /* not really a network layer but raw IP addresses */
1326 off_nl_nosnap
= -1; /* no 802.2 LLC */
1329 case DLT_JUNIPER_MONITOR
:
1332 off_nl
= 0; /* raw IP/IP6 header */
1333 off_nl_nosnap
= -1; /* no 802.2 LLC */
1336 case DLT_JUNIPER_SERVICES
:
1338 off_macpl
= -1; /* L3 proto location dep. on cookie type */
1339 off_nl
= -1; /* L3 proto location dep. on cookie type */
1340 off_nl_nosnap
= -1; /* no 802.2 LLC */
1343 case DLT_JUNIPER_VP
:
1350 case DLT_JUNIPER_ST
:
1357 case DLT_JUNIPER_ISM
:
1376 case DLT_MTP2_WITH_PHDR
:
1409 case DLT_LINUX_LAPD
:
1411 * Currently, only raw "link[N:M]" filtering is supported.
1421 * Currently, only raw "link[N:M]" filtering is supported.
1429 case DLT_BLUETOOTH_HCI_H4
:
1431 * Currently, only raw "link[N:M]" filtering is supported.
1441 * Currently, only raw "link[N:M]" filtering is supported.
1451 * Currently, only raw "link[N:M]" filtering is supported.
1459 case DLT_IEEE802_15_4_LINUX
:
1461 * Currently, only raw "link[N:M]" filtering is supported.
1469 case DLT_IEEE802_16_MAC_CPS_RADIO
:
1471 * Currently, only raw "link[N:M]" filtering is supported.
1479 case DLT_IEEE802_15_4
:
1481 * Currently, only raw "link[N:M]" filtering is supported.
1491 * Currently, only raw "link[N:M]" filtering is supported.
1501 * Currently, only raw "link[N:M]" filtering is supported.
1511 * Currently, only raw "link[N:M]" filtering is supported.
1519 case DLT_BLUETOOTH_HCI_H4_WITH_PHDR
:
1521 * Currently, only raw "link[N:M]" filtering is supported.
1531 * Currently, only raw "link[N:M]" filtering is supported.
1533 off_linktype
= -1; /* variable, min 15, max 71 steps of 7 */
1535 off_nl
= -1; /* variable, min 16, max 71 steps of 7 */
1536 off_nl_nosnap
= -1; /* no 802.2 LLC */
1537 off_mac
= 1; /* step over the kiss length byte */
1540 bpf_error("unknown data link type %d", linktype
);
1545 * Load a value relative to the beginning of the link-layer header.
1546 * The link-layer header doesn't necessarily begin at the beginning
1547 * of the packet data; there might be a variable-length prefix containing
1548 * radio information.
1550 static struct slist
*
1551 gen_load_llrel(offset
, size
)
1554 struct slist
*s
, *s2
;
1556 s
= gen_llprefixlen();
1559 * If "s" is non-null, it has code to arrange that the X register
1560 * contains the length of the prefix preceding the link-layer
1563 * Otherwise, the length of the prefix preceding the link-layer
1564 * header is "off_ll".
1568 * There's a variable-length prefix preceding the
1569 * link-layer header. "s" points to a list of statements
1570 * that put the length of that prefix into the X register.
1571 * do an indirect load, to use the X register as an offset.
1573 s2
= new_stmt(BPF_LD
|BPF_IND
|size
);
1578 * There is no variable-length header preceding the
1579 * link-layer header; add in off_ll, which, if there's
1580 * a fixed-length header preceding the link-layer header,
1581 * is the length of that header.
1583 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
1584 s
->s
.k
= offset
+ off_ll
;
1590 * Load a value relative to the beginning of the MAC-layer payload.
1592 static struct slist
*
1593 gen_load_macplrel(offset
, size
)
1596 struct slist
*s
, *s2
;
1598 s
= gen_off_macpl();
1601 * If s is non-null, the offset of the MAC-layer payload is
1602 * variable, and s points to a list of instructions that
1603 * arrange that the X register contains that offset.
1605 * Otherwise, the offset of the MAC-layer payload is constant,
1606 * and is in off_macpl.
1610 * The offset of the MAC-layer payload is in the X
1611 * register. Do an indirect load, to use the X register
1614 s2
= new_stmt(BPF_LD
|BPF_IND
|size
);
1619 * The offset of the MAC-layer payload is constant,
1620 * and is in off_macpl; load the value at that offset
1621 * plus the specified offset.
1623 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
1624 s
->s
.k
= off_macpl
+ offset
;
1630 * Load a value relative to the beginning of the specified header.
1632 static struct slist
*
1633 gen_load_a(offrel
, offset
, size
)
1634 enum e_offrel offrel
;
1637 struct slist
*s
, *s2
;
1642 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
1647 s
= gen_load_llrel(offset
, size
);
1651 s
= gen_load_macplrel(offset
, size
);
1655 s
= gen_load_macplrel(off_nl
+ offset
, size
);
1659 s
= gen_load_macplrel(off_nl_nosnap
+ offset
, size
);
1664 * Load the X register with the length of the IPv4 header
1665 * (plus the offset of the link-layer header, if it's
1666 * preceded by a variable-length header such as a radio
1667 * header), in bytes.
1669 s
= gen_loadx_iphdrlen();
1672 * Load the item at {offset of the MAC-layer payload} +
1673 * {offset, relative to the start of the MAC-layer
1674 * paylod, of the IPv4 header} + {length of the IPv4 header} +
1675 * {specified offset}.
1677 * (If the offset of the MAC-layer payload is variable,
1678 * it's included in the value in the X register, and
1681 s2
= new_stmt(BPF_LD
|BPF_IND
|size
);
1682 s2
->s
.k
= off_macpl
+ off_nl
+ offset
;
1687 s
= gen_load_macplrel(off_nl
+ 40 + offset
, size
);
1698 * Generate code to load into the X register the sum of the length of
1699 * the IPv4 header and any variable-length header preceding the link-layer
1702 static struct slist
*
1703 gen_loadx_iphdrlen()
1705 struct slist
*s
, *s2
;
1707 s
= gen_off_macpl();
1710 * There's a variable-length prefix preceding the
1711 * link-layer header, or the link-layer header is itself
1712 * variable-length. "s" points to a list of statements
1713 * that put the offset of the MAC-layer payload into
1716 * The 4*([k]&0xf) addressing mode can't be used, as we
1717 * don't have a constant offset, so we have to load the
1718 * value in question into the A register and add to it
1719 * the value from the X register.
1721 s2
= new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
1724 s2
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
1727 s2
= new_stmt(BPF_ALU
|BPF_LSH
|BPF_K
);
1732 * The A register now contains the length of the
1733 * IP header. We need to add to it the offset of
1734 * the MAC-layer payload, which is still in the X
1735 * register, and move the result into the X register.
1737 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
1738 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
1741 * There is no variable-length header preceding the
1742 * link-layer header, and the link-layer header is
1743 * fixed-length; load the length of the IPv4 header,
1744 * which is at an offset of off_nl from the beginning
1745 * of the MAC-layer payload, and thus at an offset
1746 * of off_mac_pl + off_nl from the beginning of the
1749 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
1750 s
->s
.k
= off_macpl
+ off_nl
;
1755 static struct block
*
1762 s
= new_stmt(BPF_LD
|BPF_IMM
);
1764 b
= new_block(JMP(BPF_JEQ
));
1770 static inline struct block
*
1773 return gen_uncond(1);
1776 static inline struct block
*
1779 return gen_uncond(0);
1783 * Byte-swap a 32-bit number.
1784 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
1785 * big-endian platforms.)
1787 #define SWAPLONG(y) \
1788 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
1791 * Generate code to match a particular packet type.
1793 * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
1794 * value, if <= ETHERMTU. We use that to determine whether to
1795 * match the type/length field or to check the type/length field for
1796 * a value <= ETHERMTU to see whether it's a type field and then do
1797 * the appropriate test.
1799 static struct block
*
1800 gen_ether_linktype(proto
)
1803 struct block
*b0
, *b1
;
1809 case LLCSAP_NETBEUI
:
1811 * OSI protocols and NetBEUI always use 802.2 encapsulation,
1812 * so we check the DSAP and SSAP.
1814 * LLCSAP_IP checks for IP-over-802.2, rather
1815 * than IP-over-Ethernet or IP-over-SNAP.
1817 * XXX - should we check both the DSAP and the
1818 * SSAP, like this, or should we check just the
1819 * DSAP, as we do for other types <= ETHERMTU
1820 * (i.e., other SAP values)?
1822 b0
= gen_cmp_gt(OR_LINK
, off_linktype
, BPF_H
, ETHERMTU
);
1824 b1
= gen_cmp(OR_MACPL
, 0, BPF_H
, (bpf_int32
)
1825 ((proto
<< 8) | proto
));
1833 * Ethernet_II frames, which are Ethernet
1834 * frames with a frame type of ETHERTYPE_IPX;
1836 * Ethernet_802.3 frames, which are 802.3
1837 * frames (i.e., the type/length field is
1838 * a length field, <= ETHERMTU, rather than
1839 * a type field) with the first two bytes
1840 * after the Ethernet/802.3 header being
1843 * Ethernet_802.2 frames, which are 802.3
1844 * frames with an 802.2 LLC header and
1845 * with the IPX LSAP as the DSAP in the LLC
1848 * Ethernet_SNAP frames, which are 802.3
1849 * frames with an LLC header and a SNAP
1850 * header and with an OUI of 0x000000
1851 * (encapsulated Ethernet) and a protocol
1852 * ID of ETHERTYPE_IPX in the SNAP header.
1854 * XXX - should we generate the same code both
1855 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
1859 * This generates code to check both for the
1860 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
1862 b0
= gen_cmp(OR_MACPL
, 0, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1863 b1
= gen_cmp(OR_MACPL
, 0, BPF_H
, (bpf_int32
)0xFFFF);
1867 * Now we add code to check for SNAP frames with
1868 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1870 b0
= gen_snap(0x000000, ETHERTYPE_IPX
);
1874 * Now we generate code to check for 802.3
1875 * frames in general.
1877 b0
= gen_cmp_gt(OR_LINK
, off_linktype
, BPF_H
, ETHERMTU
);
1881 * Now add the check for 802.3 frames before the
1882 * check for Ethernet_802.2 and Ethernet_802.3,
1883 * as those checks should only be done on 802.3
1884 * frames, not on Ethernet frames.
1889 * Now add the check for Ethernet_II frames, and
1890 * do that before checking for the other frame
1893 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
1894 (bpf_int32
)ETHERTYPE_IPX
);
1898 case ETHERTYPE_ATALK
:
1899 case ETHERTYPE_AARP
:
1901 * EtherTalk (AppleTalk protocols on Ethernet link
1902 * layer) may use 802.2 encapsulation.
1906 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1907 * we check for an Ethernet type field less than
1908 * 1500, which means it's an 802.3 length field.
1910 b0
= gen_cmp_gt(OR_LINK
, off_linktype
, BPF_H
, ETHERMTU
);
1914 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1915 * SNAP packets with an organization code of
1916 * 0x080007 (Apple, for Appletalk) and a protocol
1917 * type of ETHERTYPE_ATALK (Appletalk).
1919 * 802.2-encapsulated ETHERTYPE_AARP packets are
1920 * SNAP packets with an organization code of
1921 * 0x000000 (encapsulated Ethernet) and a protocol
1922 * type of ETHERTYPE_AARP (Appletalk ARP).
1924 if (proto
== ETHERTYPE_ATALK
)
1925 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
);
1926 else /* proto == ETHERTYPE_AARP */
1927 b1
= gen_snap(0x000000, ETHERTYPE_AARP
);
1931 * Check for Ethernet encapsulation (Ethertalk
1932 * phase 1?); we just check for the Ethernet
1935 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, (bpf_int32
)proto
);
1941 if (proto
<= ETHERMTU
) {
1943 * This is an LLC SAP value, so the frames
1944 * that match would be 802.2 frames.
1945 * Check that the frame is an 802.2 frame
1946 * (i.e., that the length/type field is
1947 * a length field, <= ETHERMTU) and
1948 * then check the DSAP.
1950 b0
= gen_cmp_gt(OR_LINK
, off_linktype
, BPF_H
, ETHERMTU
);
1952 b1
= gen_cmp(OR_LINK
, off_linktype
+ 2, BPF_B
,
1958 * This is an Ethernet type, so compare
1959 * the length/type field with it (if
1960 * the frame is an 802.2 frame, the length
1961 * field will be <= ETHERMTU, and, as
1962 * "proto" is > ETHERMTU, this test
1963 * will fail and the frame won't match,
1964 * which is what we want).
1966 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
1973 * Generate code to match a particular packet type.
1975 * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
1976 * value, if <= ETHERMTU. We use that to determine whether to
1977 * match the type field or to check the type field for the special
1978 * LINUX_SLL_P_802_2 value and then do the appropriate test.
1980 static struct block
*
1981 gen_linux_sll_linktype(proto
)
1984 struct block
*b0
, *b1
;
1990 case LLCSAP_NETBEUI
:
1992 * OSI protocols and NetBEUI always use 802.2 encapsulation,
1993 * so we check the DSAP and SSAP.
1995 * LLCSAP_IP checks for IP-over-802.2, rather
1996 * than IP-over-Ethernet or IP-over-SNAP.
1998 * XXX - should we check both the DSAP and the
1999 * SSAP, like this, or should we check just the
2000 * DSAP, as we do for other types <= ETHERMTU
2001 * (i.e., other SAP values)?
2003 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
2004 b1
= gen_cmp(OR_MACPL
, 0, BPF_H
, (bpf_int32
)
2005 ((proto
<< 8) | proto
));
2011 * Ethernet_II frames, which are Ethernet
2012 * frames with a frame type of ETHERTYPE_IPX;
2014 * Ethernet_802.3 frames, which have a frame
2015 * type of LINUX_SLL_P_802_3;
2017 * Ethernet_802.2 frames, which are 802.3
2018 * frames with an 802.2 LLC header (i.e, have
2019 * a frame type of LINUX_SLL_P_802_2) and
2020 * with the IPX LSAP as the DSAP in the LLC
2023 * Ethernet_SNAP frames, which are 802.3
2024 * frames with an LLC header and a SNAP
2025 * header and with an OUI of 0x000000
2026 * (encapsulated Ethernet) and a protocol
2027 * ID of ETHERTYPE_IPX in the SNAP header.
2029 * First, do the checks on LINUX_SLL_P_802_2
2030 * frames; generate the check for either
2031 * Ethernet_802.2 or Ethernet_SNAP frames, and
2032 * then put a check for LINUX_SLL_P_802_2 frames
2035 b0
= gen_cmp(OR_MACPL
, 0, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
2036 b1
= gen_snap(0x000000, ETHERTYPE_IPX
);
2038 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
2042 * Now check for 802.3 frames and OR that with
2043 * the previous test.
2045 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
2049 * Now add the check for Ethernet_II frames, and
2050 * do that before checking for the other frame
2053 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
2054 (bpf_int32
)ETHERTYPE_IPX
);
2058 case ETHERTYPE_ATALK
:
2059 case ETHERTYPE_AARP
:
2061 * EtherTalk (AppleTalk protocols on Ethernet link
2062 * layer) may use 802.2 encapsulation.
2066 * Check for 802.2 encapsulation (EtherTalk phase 2?);
2067 * we check for the 802.2 protocol type in the
2068 * "Ethernet type" field.
2070 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
2073 * 802.2-encapsulated ETHERTYPE_ATALK packets are
2074 * SNAP packets with an organization code of
2075 * 0x080007 (Apple, for Appletalk) and a protocol
2076 * type of ETHERTYPE_ATALK (Appletalk).
2078 * 802.2-encapsulated ETHERTYPE_AARP packets are
2079 * SNAP packets with an organization code of
2080 * 0x000000 (encapsulated Ethernet) and a protocol
2081 * type of ETHERTYPE_AARP (Appletalk ARP).
2083 if (proto
== ETHERTYPE_ATALK
)
2084 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
);
2085 else /* proto == ETHERTYPE_AARP */
2086 b1
= gen_snap(0x000000, ETHERTYPE_AARP
);
2090 * Check for Ethernet encapsulation (Ethertalk
2091 * phase 1?); we just check for the Ethernet
2094 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, (bpf_int32
)proto
);
2100 if (proto
<= ETHERMTU
) {
2102 * This is an LLC SAP value, so the frames
2103 * that match would be 802.2 frames.
2104 * Check for the 802.2 protocol type
2105 * in the "Ethernet type" field, and
2106 * then check the DSAP.
2108 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
2110 b1
= gen_cmp(OR_LINK
, off_macpl
, BPF_B
,
2116 * This is an Ethernet type, so compare
2117 * the length/type field with it (if
2118 * the frame is an 802.2 frame, the length
2119 * field will be <= ETHERMTU, and, as
2120 * "proto" is > ETHERMTU, this test
2121 * will fail and the frame won't match,
2122 * which is what we want).
2124 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
2130 static struct slist
*
2131 gen_load_radiotap_llprefixlen()
2133 struct slist
*s1
, *s2
;
2136 * Generate code to load the length of the radiotap header into
2137 * the register assigned to hold that length, if one has been
2138 * assigned. (If one hasn't been assigned, no code we've
2139 * generated uses that prefix, so we don't need to generate any
2142 if (reg_off_ll
!= -1) {
2144 * The 2 bytes at offsets of 2 and 3 from the beginning
2145 * of the radiotap header are the length of the radiotap
2146 * header; unfortunately, it's little-endian, so we have
2147 * to load it a byte at a time and construct the value.
2151 * Load the high-order byte, at an offset of 3, shift it
2152 * left a byte, and put the result in the X register.
2154 s1
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2156 s2
= new_stmt(BPF_ALU
|BPF_LSH
|BPF_K
);
2159 s2
= new_stmt(BPF_MISC
|BPF_TAX
);
2163 * Load the next byte, at an offset of 2, and OR the
2164 * value from the X register into it.
2166 s2
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2169 s2
= new_stmt(BPF_ALU
|BPF_OR
|BPF_X
);
2173 * Now allocate a register to hold that value and store
2176 s2
= new_stmt(BPF_ST
);
2177 s2
->s
.k
= reg_off_ll
;
2181 * Now move it into the X register.
2183 s2
= new_stmt(BPF_MISC
|BPF_TAX
);
2192 * At the moment we treat PPI as normal Radiotap encoded
2193 * packets. The difference is in the function that generates
2194 * the code at the beginning to compute the header length.
2195 * Since this code generator of PPI supports bare 802.11
2196 * encapsulation only (i.e. the encapsulated DLT should be
2197 * DLT_IEEE802_11) we generate code to check for this too;
2198 * that's done in finish_parse().
2200 static struct slist
*
2201 gen_load_ppi_llprefixlen()
2203 struct slist
*s1
, *s2
;
2206 * Generate code to load the length of the radiotap header
2207 * into the register assigned to hold that length, if one has
2210 if (reg_off_ll
!= -1) {
2212 * The 2 bytes at offsets of 2 and 3 from the beginning
2213 * of the radiotap header are the length of the radiotap
2214 * header; unfortunately, it's little-endian, so we have
2215 * to load it a byte at a time and construct the value.
2219 * Load the high-order byte, at an offset of 3, shift it
2220 * left a byte, and put the result in the X register.
2222 s1
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2224 s2
= new_stmt(BPF_ALU
|BPF_LSH
|BPF_K
);
2227 s2
= new_stmt(BPF_MISC
|BPF_TAX
);
2231 * Load the next byte, at an offset of 2, and OR the
2232 * value from the X register into it.
2234 s2
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
2237 s2
= new_stmt(BPF_ALU
|BPF_OR
|BPF_X
);
2241 * Now allocate a register to hold that value and store
2244 s2
= new_stmt(BPF_ST
);
2245 s2
->s
.k
= reg_off_ll
;
2249 * Now move it into the X register.
2251 s2
= new_stmt(BPF_MISC
|BPF_TAX
);
2259 static struct slist
*
2260 gen_load_avs_llprefixlen()
2262 struct slist
*s1
, *s2
;
2265 * Generate code to load the length of the AVS header into
2266 * the register assigned to hold that length, if one has been
2267 * assigned. (If one hasn't been assigned, no code we've
2268 * generated uses that prefix, so we don't need to generate any
2271 if (reg_off_ll
!= -1) {
2273 * The 4 bytes at an offset of 4 from the beginning of
2274 * the AVS header are the length of the AVS header.
2275 * That field is big-endian.
2277 s1
= new_stmt(BPF_LD
|BPF_W
|BPF_ABS
);
2281 * Now allocate a register to hold that value and store
2284 s2
= new_stmt(BPF_ST
);
2285 s2
->s
.k
= reg_off_ll
;
2289 * Now move it into the X register.
2291 s2
= new_stmt(BPF_MISC
|BPF_TAX
);
2300 * Load a value relative to the beginning of the link-layer header after the 802.11
2301 * header, i.e. LLC_SNAP.
2302 * The link-layer header doesn't necessarily begin at the beginning
2303 * of the packet data; there might be a variable-length prefix containing
2304 * radio information.
2306 static struct slist
*
2307 gen_load_802_11_header_len(struct slist
*s
, struct slist
*snext
)
2310 struct slist
*sjset_data_frame_1
;
2311 struct slist
*sjset_data_frame_2
;
2312 struct slist
*sjset_qos
;
2313 struct slist
*sjset_radiotap_flags
;
2314 struct slist
*sjset_radiotap_tsft
;
2315 struct slist
*sjset_tsft_datapad
, *sjset_notsft_datapad
;
2316 struct slist
*s_roundup
;
2318 if (reg_off_macpl
== -1) {
2320 * No register has been assigned to the offset of
2321 * the MAC-layer payload, which means nobody needs
2322 * it; don't bother computing it - just return
2323 * what we already have.
2329 * This code is not compatible with the optimizer, as
2330 * we are generating jmp instructions within a normal
2331 * slist of instructions
2336 * If "s" is non-null, it has code to arrange that the X register
2337 * contains the length of the prefix preceding the link-layer
2340 * Otherwise, the length of the prefix preceding the link-layer
2341 * header is "off_ll".
2345 * There is no variable-length header preceding the
2346 * link-layer header.
2348 * Load the length of the fixed-length prefix preceding
2349 * the link-layer header (if any) into the X register,
2350 * and store it in the reg_off_macpl register.
2351 * That length is off_ll.
2353 s
= new_stmt(BPF_LDX
|BPF_IMM
);
2358 * The X register contains the offset of the beginning of the
2359 * link-layer header; add 24, which is the minimum length
2360 * of the MAC header for a data frame, to that, and store it
2361 * in reg_off_macpl, and then load the Frame Control field,
2362 * which is at the offset in the X register, with an indexed load.
2364 s2
= new_stmt(BPF_MISC
|BPF_TXA
);
2366 s2
= new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2369 s2
= new_stmt(BPF_ST
);
2370 s2
->s
.k
= reg_off_macpl
;
2373 s2
= new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2378 * Check the Frame Control field to see if this is a data frame;
2379 * a data frame has the 0x08 bit (b3) in that field set and the
2380 * 0x04 bit (b2) clear.
2382 sjset_data_frame_1
= new_stmt(JMP(BPF_JSET
));
2383 sjset_data_frame_1
->s
.k
= 0x08;
2384 sappend(s
, sjset_data_frame_1
);
2387 * If b3 is set, test b2, otherwise go to the first statement of
2388 * the rest of the program.
2390 sjset_data_frame_1
->s
.jt
= sjset_data_frame_2
= new_stmt(JMP(BPF_JSET
));
2391 sjset_data_frame_2
->s
.k
= 0x04;
2392 sappend(s
, sjset_data_frame_2
);
2393 sjset_data_frame_1
->s
.jf
= snext
;
2396 * If b2 is not set, this is a data frame; test the QoS bit.
2397 * Otherwise, go to the first statement of the rest of the
2400 sjset_data_frame_2
->s
.jt
= snext
;
2401 sjset_data_frame_2
->s
.jf
= sjset_qos
= new_stmt(JMP(BPF_JSET
));
2402 sjset_qos
->s
.k
= 0x80; /* QoS bit */
2403 sappend(s
, sjset_qos
);
2406 * If it's set, add 2 to reg_off_macpl, to skip the QoS
2408 * Otherwise, go to the first statement of the rest of the
2411 sjset_qos
->s
.jt
= s2
= new_stmt(BPF_LD
|BPF_MEM
);
2412 s2
->s
.k
= reg_off_macpl
;
2414 s2
= new_stmt(BPF_ALU
|BPF_ADD
|BPF_IMM
);
2417 s2
= new_stmt(BPF_ST
);
2418 s2
->s
.k
= reg_off_macpl
;
2422 * If we have a radiotap header, look at it to see whether
2423 * there's Atheros padding between the MAC-layer header
2426 * Note: all of the fields in the radiotap header are
2427 * little-endian, so we byte-swap all of the values
2428 * we test against, as they will be loaded as big-endian
2431 if (linktype
== DLT_IEEE802_11_RADIO
) {
2433 * Is the IEEE80211_RADIOTAP_FLAGS bit (0x0000002) set
2434 * in the presence flag?
2436 sjset_qos
->s
.jf
= s2
= new_stmt(BPF_LD
|BPF_ABS
|BPF_W
);
2440 sjset_radiotap_flags
= new_stmt(JMP(BPF_JSET
));
2441 sjset_radiotap_flags
->s
.k
= SWAPLONG(0x00000002);
2442 sappend(s
, sjset_radiotap_flags
);
2445 * If not, skip all of this.
2447 sjset_radiotap_flags
->s
.jf
= snext
;
2450 * Otherwise, is the IEEE80211_RADIOTAP_TSFT bit set?
2452 sjset_radiotap_tsft
= sjset_radiotap_flags
->s
.jt
=
2453 new_stmt(JMP(BPF_JSET
));
2454 sjset_radiotap_tsft
->s
.k
= SWAPLONG(0x00000001);
2455 sappend(s
, sjset_radiotap_tsft
);
2458 * If IEEE80211_RADIOTAP_TSFT is set, the flags field is
2459 * at an offset of 16 from the beginning of the raw packet
2460 * data (8 bytes for the radiotap header and 8 bytes for
2463 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
2466 sjset_radiotap_tsft
->s
.jt
= s2
= new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2470 sjset_tsft_datapad
= new_stmt(JMP(BPF_JSET
));
2471 sjset_tsft_datapad
->s
.k
= 0x20;
2472 sappend(s
, sjset_tsft_datapad
);
2475 * If IEEE80211_RADIOTAP_TSFT is not set, the flags field is
2476 * at an offset of 8 from the beginning of the raw packet
2477 * data (8 bytes for the radiotap header).
2479 * Test whether the IEEE80211_RADIOTAP_F_DATAPAD bit (0x20)
2482 sjset_radiotap_tsft
->s
.jf
= s2
= new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2486 sjset_notsft_datapad
= new_stmt(JMP(BPF_JSET
));
2487 sjset_notsft_datapad
->s
.k
= 0x20;
2488 sappend(s
, sjset_notsft_datapad
);
2491 * In either case, if IEEE80211_RADIOTAP_F_DATAPAD is
2492 * set, round the length of the 802.11 header to
2493 * a multiple of 4. Do that by adding 3 and then
2494 * dividing by and multiplying by 4, which we do by
2497 s_roundup
= new_stmt(BPF_LD
|BPF_MEM
);
2498 s_roundup
->s
.k
= reg_off_macpl
;
2499 sappend(s
, s_roundup
);
2500 s2
= new_stmt(BPF_ALU
|BPF_ADD
|BPF_IMM
);
2503 s2
= new_stmt(BPF_ALU
|BPF_AND
|BPF_IMM
);
2506 s2
= new_stmt(BPF_ST
);
2507 s2
->s
.k
= reg_off_macpl
;
2510 sjset_tsft_datapad
->s
.jt
= s_roundup
;
2511 sjset_tsft_datapad
->s
.jf
= snext
;
2512 sjset_notsft_datapad
->s
.jt
= s_roundup
;
2513 sjset_notsft_datapad
->s
.jf
= snext
;
2515 sjset_qos
->s
.jf
= snext
;
2521 insert_compute_vloffsets(b
)
2527 * For link-layer types that have a variable-length header
2528 * preceding the link-layer header, generate code to load
2529 * the offset of the link-layer header into the register
2530 * assigned to that offset, if any.
2534 case DLT_IEEE802_11_RADIO
:
2535 s
= gen_load_radiotap_llprefixlen();
2539 s
= gen_load_ppi_llprefixlen();
2542 case DLT_IEEE802_11_RADIO_AVS
:
2543 s
= gen_load_avs_llprefixlen();
2552 * For link-layer types that have a variable-length link-layer
2553 * header, generate code to load the offset of the MAC-layer
2554 * payload into the register assigned to that offset, if any.
2558 case DLT_IEEE802_11
:
2559 case DLT_IEEE802_11_RADIO
:
2560 case DLT_IEEE802_11_RADIO_AVS
:
2561 case DLT_PRISM_HEADER
:
2563 s
= gen_load_802_11_header_len(s
, b
->stmts
);
2568 * If we have any offset-loading code, append all the
2569 * existing statements in the block to those statements,
2570 * and make the resulting list the list of statements
2574 sappend(s
, b
->stmts
);
2579 static struct block
*
2580 gen_ppi_dlt_check(void)
2582 struct slist
*s_load_dlt
;
2585 if (linktype
== DLT_PPI
)
2587 /* Create the statements that check for the DLT
2589 s_load_dlt
= new_stmt(BPF_LD
|BPF_W
|BPF_ABS
);
2590 s_load_dlt
->s
.k
= 4;
2592 b
= new_block(JMP(BPF_JEQ
));
2594 b
->stmts
= s_load_dlt
;
2595 b
->s
.k
= SWAPLONG(DLT_IEEE802_11
);
2605 static struct slist
*
2606 gen_radiotap_llprefixlen(void)
2610 if (reg_off_ll
== -1) {
2612 * We haven't yet assigned a register for the length
2613 * of the radiotap header; allocate one.
2615 reg_off_ll
= alloc_reg();
2619 * Load the register containing the radiotap length
2620 * into the X register.
2622 s
= new_stmt(BPF_LDX
|BPF_MEM
);
2623 s
->s
.k
= reg_off_ll
;
2628 * At the moment we treat PPI as normal Radiotap encoded
2629 * packets. The difference is in the function that generates
2630 * the code at the beginning to compute the header length.
2631 * Since this code generator of PPI supports bare 802.11
2632 * encapsulation only (i.e. the encapsulated DLT should be
2633 * DLT_IEEE802_11) we generate code to check for this too.
2635 static struct slist
*
2636 gen_ppi_llprefixlen(void)
2640 if (reg_off_ll
== -1) {
2642 * We haven't yet assigned a register for the length
2643 * of the radiotap header; allocate one.
2645 reg_off_ll
= alloc_reg();
2649 * Load the register containing the PPI length
2650 * into the X register.
2652 s
= new_stmt(BPF_LDX
|BPF_MEM
);
2653 s
->s
.k
= reg_off_ll
;
2657 static struct slist
*
2658 gen_avs_llprefixlen(void)
2662 if (reg_off_ll
== -1) {
2664 * We haven't yet assigned a register for the length
2665 * of the radiotap header; allocate one.
2667 reg_off_ll
= alloc_reg();
2671 * Load the register containing the AVS length
2672 * into the X register.
2674 s
= new_stmt(BPF_LDX
|BPF_MEM
);
2675 s
->s
.k
= reg_off_ll
;
2680 * Generate code to compute the link-layer header length, if necessary,
2681 * putting it into the X register, and to return either a pointer to a
2682 * "struct slist" for the list of statements in that code, or NULL if
2683 * no code is necessary.
2685 static struct slist
*
2686 gen_llprefixlen(void)
2691 return gen_ppi_llprefixlen();
2693 case DLT_IEEE802_11_RADIO
:
2694 return gen_radiotap_llprefixlen();
2696 case DLT_IEEE802_11_RADIO_AVS
:
2697 return gen_avs_llprefixlen();
2705 * Generate code to load the register containing the offset of the
2706 * MAC-layer payload into the X register; if no register for that offset
2707 * has been allocated, allocate it first.
2709 static struct slist
*
2714 if (off_macpl_is_variable
) {
2715 if (reg_off_macpl
== -1) {
2717 * We haven't yet assigned a register for the offset
2718 * of the MAC-layer payload; allocate one.
2720 reg_off_macpl
= alloc_reg();
2724 * Load the register containing the offset of the MAC-layer
2725 * payload into the X register.
2727 s
= new_stmt(BPF_LDX
|BPF_MEM
);
2728 s
->s
.k
= reg_off_macpl
;
2732 * That offset isn't variable, so we don't need to
2733 * generate any code.
2740 * Map an Ethernet type to the equivalent PPP type.
2743 ethertype_to_ppptype(proto
)
2753 case ETHERTYPE_IPV6
:
2762 case ETHERTYPE_ATALK
:
2776 * I'm assuming the "Bridging PDU"s that go
2777 * over PPP are Spanning Tree Protocol
2791 * Generate code to match a particular packet type by matching the
2792 * link-layer type field or fields in the 802.2 LLC header.
2794 * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
2795 * value, if <= ETHERMTU.
2797 static struct block
*
2801 struct block
*b0
, *b1
, *b2
;
2803 /* are we checking MPLS-encapsulated packets? */
2804 if (label_stack_depth
> 0) {
2808 /* FIXME add other L3 proto IDs */
2809 return gen_mpls_linktype(Q_IP
);
2811 case ETHERTYPE_IPV6
:
2813 /* FIXME add other L3 proto IDs */
2814 return gen_mpls_linktype(Q_IPV6
);
2817 bpf_error("unsupported protocol over mpls");
2823 * Are we testing PPPoE packets?
2827 * The PPPoE session header is part of the
2828 * MAC-layer payload, so all references
2829 * should be relative to the beginning of
2834 * We use Ethernet protocol types inside libpcap;
2835 * map them to the corresponding PPP protocol types.
2837 proto
= ethertype_to_ppptype(proto
);
2838 return gen_cmp(OR_MACPL
, off_linktype
, BPF_H
, (bpf_int32
)proto
);
2844 return gen_ether_linktype(proto
);
2852 proto
= (proto
<< 8 | LLCSAP_ISONS
);
2856 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
2864 case DLT_IEEE802_11
:
2865 case DLT_IEEE802_11_RADIO
:
2866 case DLT_IEEE802_11_RADIO_AVS
:
2867 case DLT_PRISM_HEADER
:
2869 * Check that we have a data frame.
2871 b0
= gen_check_802_11_data_frame();
2874 * Now check for the specified link-layer type.
2876 b1
= gen_llc_linktype(proto
);
2884 * XXX - check for asynchronous frames, as per RFC 1103.
2886 return gen_llc_linktype(proto
);
2892 * XXX - check for LLC PDUs, as per IEEE 802.5.
2894 return gen_llc_linktype(proto
);
2898 case DLT_ATM_RFC1483
:
2900 case DLT_IP_OVER_FC
:
2901 return gen_llc_linktype(proto
);
2907 * If "is_lane" is set, check for a LANE-encapsulated
2908 * version of this protocol, otherwise check for an
2909 * LLC-encapsulated version of this protocol.
2911 * We assume LANE means Ethernet, not Token Ring.
2915 * Check that the packet doesn't begin with an
2916 * LE Control marker. (We've already generated
2919 b0
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
, BPF_H
,
2924 * Now generate an Ethernet test.
2926 b1
= gen_ether_linktype(proto
);
2931 * Check for LLC encapsulation and then check the
2934 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
2935 b1
= gen_llc_linktype(proto
);
2943 return gen_linux_sll_linktype(proto
);
2948 case DLT_SLIP_BSDOS
:
2951 * These types don't provide any type field; packets
2952 * are always IPv4 or IPv6.
2954 * XXX - for IPv4, check for a version number of 4, and,
2955 * for IPv6, check for a version number of 6?
2960 /* Check for a version number of 4. */
2961 return gen_mcmp(OR_LINK
, 0, BPF_B
, 0x40, 0xF0);
2963 case ETHERTYPE_IPV6
:
2964 /* Check for a version number of 6. */
2965 return gen_mcmp(OR_LINK
, 0, BPF_B
, 0x60, 0xF0);
2969 return gen_false(); /* always false */
2976 case DLT_PPP_SERIAL
:
2979 * We use Ethernet protocol types inside libpcap;
2980 * map them to the corresponding PPP protocol types.
2982 proto
= ethertype_to_ppptype(proto
);
2983 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
, (bpf_int32
)proto
);
2989 * We use Ethernet protocol types inside libpcap;
2990 * map them to the corresponding PPP protocol types.
2996 * Also check for Van Jacobson-compressed IP.
2997 * XXX - do this for other forms of PPP?
2999 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, PPP_IP
);
3000 b1
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, PPP_VJC
);
3002 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
, PPP_VJNC
);
3007 proto
= ethertype_to_ppptype(proto
);
3008 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
3018 * For DLT_NULL, the link-layer header is a 32-bit
3019 * word containing an AF_ value in *host* byte order,
3020 * and for DLT_ENC, the link-layer header begins
3021 * with a 32-bit work containing an AF_ value in
3024 * In addition, if we're reading a saved capture file,
3025 * the host byte order in the capture may not be the
3026 * same as the host byte order on this machine.
3028 * For DLT_LOOP, the link-layer header is a 32-bit
3029 * word containing an AF_ value in *network* byte order.
3031 * XXX - AF_ values may, unfortunately, be platform-
3032 * dependent; for example, FreeBSD's AF_INET6 is 24
3033 * whilst NetBSD's and OpenBSD's is 26.
3035 * This means that, when reading a capture file, just
3036 * checking for our AF_INET6 value won't work if the
3037 * capture file came from another OS.
3046 case ETHERTYPE_IPV6
:
3053 * Not a type on which we support filtering.
3054 * XXX - support those that have AF_ values
3055 * #defined on this platform, at least?
3060 if (linktype
== DLT_NULL
|| linktype
== DLT_ENC
) {
3062 * The AF_ value is in host byte order, but
3063 * the BPF interpreter will convert it to
3064 * network byte order.
3066 * If this is a save file, and it's from a
3067 * machine with the opposite byte order to
3068 * ours, we byte-swap the AF_ value.
3070 * Then we run it through "htonl()", and
3071 * generate code to compare against the result.
3073 if (bpf_pcap
->sf
.rfile
!= NULL
&&
3074 bpf_pcap
->sf
.swapped
)
3075 proto
= SWAPLONG(proto
);
3076 proto
= htonl(proto
);
3078 return (gen_cmp(OR_LINK
, 0, BPF_W
, (bpf_int32
)proto
));
3080 #ifdef HAVE_NET_PFVAR_H
3083 * af field is host byte order in contrast to the rest of
3086 if (proto
== ETHERTYPE_IP
)
3087 return (gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, af
),
3088 BPF_B
, (bpf_int32
)AF_INET
));
3090 else if (proto
== ETHERTYPE_IPV6
)
3091 return (gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, af
),
3092 BPF_B
, (bpf_int32
)AF_INET6
));
3098 #endif /* HAVE_NET_PFVAR_H */
3101 case DLT_ARCNET_LINUX
:
3103 * XXX should we check for first fragment if the protocol
3112 case ETHERTYPE_IPV6
:
3113 return (gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3114 (bpf_int32
)ARCTYPE_INET6
));
3118 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3119 (bpf_int32
)ARCTYPE_IP
);
3120 b1
= gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3121 (bpf_int32
)ARCTYPE_IP_OLD
);
3126 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3127 (bpf_int32
)ARCTYPE_ARP
);
3128 b1
= gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3129 (bpf_int32
)ARCTYPE_ARP_OLD
);
3133 case ETHERTYPE_REVARP
:
3134 return (gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3135 (bpf_int32
)ARCTYPE_REVARP
));
3137 case ETHERTYPE_ATALK
:
3138 return (gen_cmp(OR_LINK
, off_linktype
, BPF_B
,
3139 (bpf_int32
)ARCTYPE_ATALK
));
3146 case ETHERTYPE_ATALK
:
3156 * XXX - assumes a 2-byte Frame Relay header with
3157 * DLCI and flags. What if the address is longer?
3163 * Check for the special NLPID for IP.
3165 return gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | 0xcc);
3168 case ETHERTYPE_IPV6
:
3170 * Check for the special NLPID for IPv6.
3172 return gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | 0x8e);
3177 * Check for several OSI protocols.
3179 * Frame Relay packets typically have an OSI
3180 * NLPID at the beginning; we check for each
3183 * What we check for is the NLPID and a frame
3184 * control field of UI, i.e. 0x03 followed
3187 b0
= gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
3188 b1
= gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
3189 b2
= gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
3201 bpf_error("Multi-link Frame Relay link-layer type filtering not implemented");
3203 case DLT_JUNIPER_MFR
:
3204 case DLT_JUNIPER_MLFR
:
3205 case DLT_JUNIPER_MLPPP
:
3206 case DLT_JUNIPER_ATM1
:
3207 case DLT_JUNIPER_ATM2
:
3208 case DLT_JUNIPER_PPPOE
:
3209 case DLT_JUNIPER_PPPOE_ATM
:
3210 case DLT_JUNIPER_GGSN
:
3211 case DLT_JUNIPER_ES
:
3212 case DLT_JUNIPER_MONITOR
:
3213 case DLT_JUNIPER_SERVICES
:
3214 case DLT_JUNIPER_ETHER
:
3215 case DLT_JUNIPER_PPP
:
3216 case DLT_JUNIPER_FRELAY
:
3217 case DLT_JUNIPER_CHDLC
:
3218 case DLT_JUNIPER_VP
:
3219 case DLT_JUNIPER_ST
:
3220 case DLT_JUNIPER_ISM
:
3221 /* just lets verify the magic number for now -
3222 * on ATM we may have up to 6 different encapsulations on the wire
3223 * and need a lot of heuristics to figure out that the payload
3226 * FIXME encapsulation specific BPF_ filters
3228 return gen_mcmp(OR_LINK
, 0, BPF_W
, 0x4d474300, 0xffffff00); /* compare the magic number */
3230 case DLT_LINUX_IRDA
:
3231 bpf_error("IrDA link-layer type filtering not implemented");
3234 bpf_error("DOCSIS link-layer type filtering not implemented");
3237 case DLT_MTP2_WITH_PHDR
:
3238 bpf_error("MTP2 link-layer type filtering not implemented");
3241 bpf_error("ERF link-layer type filtering not implemented");
3245 bpf_error("PFSYNC link-layer type filtering not implemented");
3248 case DLT_LINUX_LAPD
:
3249 bpf_error("LAPD link-layer type filtering not implemented");
3253 bpf_error("USB link-layer type filtering not implemented");
3255 case DLT_BLUETOOTH_HCI_H4
:
3256 case DLT_BLUETOOTH_HCI_H4_WITH_PHDR
:
3257 bpf_error("Bluetooth link-layer type filtering not implemented");
3260 bpf_error("CAN20B link-layer type filtering not implemented");
3262 case DLT_IEEE802_15_4
:
3263 case DLT_IEEE802_15_4_LINUX
:
3264 bpf_error("IEEE 802.15.4 link-layer type filtering not implemented");
3266 case DLT_IEEE802_16_MAC_CPS_RADIO
:
3267 bpf_error("IEEE 802.16 link-layer type filtering not implemented");
3270 bpf_error("SITA link-layer type filtering not implemented");
3273 bpf_error("RAIF1 link-layer type filtering not implemented");
3276 bpf_error("IPMB link-layer type filtering not implemented");
3279 bpf_error("AX.25 link-layer type filtering not implemented");
3283 * All the types that have no encapsulation should either be
3284 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
3285 * all packets are IP packets, or should be handled in some
3286 * special case, if none of them are (if some are and some
3287 * aren't, the lack of encapsulation is a problem, as we'd
3288 * have to find some other way of determining the packet type).
3290 * Therefore, if "off_linktype" is -1, there's an error.
3292 if (off_linktype
== (u_int
)-1)
3296 * Any type not handled above should always have an Ethernet
3297 * type at an offset of "off_linktype".
3299 return gen_cmp(OR_LINK
, off_linktype
, BPF_H
, (bpf_int32
)proto
);
3303 * Check for an LLC SNAP packet with a given organization code and
3304 * protocol type; we check the entire contents of the 802.2 LLC and
3305 * snap headers, checking for DSAP and SSAP of SNAP and a control
3306 * field of 0x03 in the LLC header, and for the specified organization
3307 * code and protocol type in the SNAP header.
3309 static struct block
*
3310 gen_snap(orgcode
, ptype
)
3311 bpf_u_int32 orgcode
;
3314 u_char snapblock
[8];
3316 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
3317 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
3318 snapblock
[2] = 0x03; /* control = UI */
3319 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
3320 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
3321 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
3322 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
3323 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
3324 return gen_bcmp(OR_MACPL
, 0, 8, snapblock
);
3328 * Generate code to match a particular packet type, for link-layer types
3329 * using 802.2 LLC headers.
3331 * This is *NOT* used for Ethernet; "gen_ether_linktype()" is used
3332 * for that - it handles the D/I/X Ethernet vs. 802.3+802.2 issues.
3334 * "proto" is an Ethernet type value, if > ETHERMTU, or an LLC SAP
3335 * value, if <= ETHERMTU. We use that to determine whether to
3336 * match the DSAP or both DSAP and LSAP or to check the OUI and
3337 * protocol ID in a SNAP header.
3339 static struct block
*
3340 gen_llc_linktype(proto
)
3344 * XXX - handle token-ring variable-length header.
3350 case LLCSAP_NETBEUI
:
3352 * XXX - should we check both the DSAP and the
3353 * SSAP, like this, or should we check just the
3354 * DSAP, as we do for other types <= ETHERMTU
3355 * (i.e., other SAP values)?
3357 return gen_cmp(OR_MACPL
, 0, BPF_H
, (bpf_u_int32
)
3358 ((proto
<< 8) | proto
));
3362 * XXX - are there ever SNAP frames for IPX on
3363 * non-Ethernet 802.x networks?
3365 return gen_cmp(OR_MACPL
, 0, BPF_B
,
3366 (bpf_int32
)LLCSAP_IPX
);
3368 case ETHERTYPE_ATALK
:
3370 * 802.2-encapsulated ETHERTYPE_ATALK packets are
3371 * SNAP packets with an organization code of
3372 * 0x080007 (Apple, for Appletalk) and a protocol
3373 * type of ETHERTYPE_ATALK (Appletalk).
3375 * XXX - check for an organization code of
3376 * encapsulated Ethernet as well?
3378 return gen_snap(0x080007, ETHERTYPE_ATALK
);
3382 * XXX - we don't have to check for IPX 802.3
3383 * here, but should we check for the IPX Ethertype?
3385 if (proto
<= ETHERMTU
) {
3387 * This is an LLC SAP value, so check
3390 return gen_cmp(OR_MACPL
, 0, BPF_B
, (bpf_int32
)proto
);
3393 * This is an Ethernet type; we assume that it's
3394 * unlikely that it'll appear in the right place
3395 * at random, and therefore check only the
3396 * location that would hold the Ethernet type
3397 * in a SNAP frame with an organization code of
3398 * 0x000000 (encapsulated Ethernet).
3400 * XXX - if we were to check for the SNAP DSAP and
3401 * LSAP, as per XXX, and were also to check for an
3402 * organization code of 0x000000 (encapsulated
3403 * Ethernet), we'd do
3405 * return gen_snap(0x000000, proto);
3407 * here; for now, we don't, as per the above.
3408 * I don't know whether it's worth the extra CPU
3409 * time to do the right check or not.
3411 return gen_cmp(OR_MACPL
, 6, BPF_H
, (bpf_int32
)proto
);
3416 static struct block
*
3417 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
3421 u_int src_off
, dst_off
;
3423 struct block
*b0
, *b1
;
3437 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
3438 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
3444 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
3445 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
3452 b0
= gen_linktype(proto
);
3453 b1
= gen_mcmp(OR_NET
, offset
, BPF_W
, (bpf_int32
)addr
, mask
);
3459 static struct block
*
3460 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
3461 struct in6_addr
*addr
;
3462 struct in6_addr
*mask
;
3464 u_int src_off
, dst_off
;
3466 struct block
*b0
, *b1
;
3481 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
3482 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
3488 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
3489 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
3496 /* this order is important */
3497 a
= (u_int32_t
*)addr
;
3498 m
= (u_int32_t
*)mask
;
3499 b1
= gen_mcmp(OR_NET
, offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
3500 b0
= gen_mcmp(OR_NET
, offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
3502 b0
= gen_mcmp(OR_NET
, offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
3504 b0
= gen_mcmp(OR_NET
, offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
3506 b0
= gen_linktype(proto
);
3512 static struct block
*
3513 gen_ehostop(eaddr
, dir
)
3514 register const u_char
*eaddr
;
3517 register struct block
*b0
, *b1
;
3521 return gen_bcmp(OR_LINK
, off_mac
+ 6, 6, eaddr
);
3524 return gen_bcmp(OR_LINK
, off_mac
+ 0, 6, eaddr
);
3527 b0
= gen_ehostop(eaddr
, Q_SRC
);
3528 b1
= gen_ehostop(eaddr
, Q_DST
);
3534 b0
= gen_ehostop(eaddr
, Q_SRC
);
3535 b1
= gen_ehostop(eaddr
, Q_DST
);
3544 * Like gen_ehostop, but for DLT_FDDI
3546 static struct block
*
3547 gen_fhostop(eaddr
, dir
)
3548 register const u_char
*eaddr
;
3551 struct block
*b0
, *b1
;
3556 return gen_bcmp(OR_LINK
, 6 + 1 + pcap_fddipad
, 6, eaddr
);
3558 return gen_bcmp(OR_LINK
, 6 + 1, 6, eaddr
);
3563 return gen_bcmp(OR_LINK
, 0 + 1 + pcap_fddipad
, 6, eaddr
);
3565 return gen_bcmp(OR_LINK
, 0 + 1, 6, eaddr
);
3569 b0
= gen_fhostop(eaddr
, Q_SRC
);
3570 b1
= gen_fhostop(eaddr
, Q_DST
);
3576 b0
= gen_fhostop(eaddr
, Q_SRC
);
3577 b1
= gen_fhostop(eaddr
, Q_DST
);
3586 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
3588 static struct block
*
3589 gen_thostop(eaddr
, dir
)
3590 register const u_char
*eaddr
;
3593 register struct block
*b0
, *b1
;
3597 return gen_bcmp(OR_LINK
, 8, 6, eaddr
);
3600 return gen_bcmp(OR_LINK
, 2, 6, eaddr
);
3603 b0
= gen_thostop(eaddr
, Q_SRC
);
3604 b1
= gen_thostop(eaddr
, Q_DST
);
3610 b0
= gen_thostop(eaddr
, Q_SRC
);
3611 b1
= gen_thostop(eaddr
, Q_DST
);
3620 * Like gen_ehostop, but for DLT_IEEE802_11 (802.11 wireless LAN) and
3621 * various 802.11 + radio headers.
3623 static struct block
*
3624 gen_wlanhostop(eaddr
, dir
)
3625 register const u_char
*eaddr
;
3628 register struct block
*b0
, *b1
, *b2
;
3629 register struct slist
*s
;
3631 #ifdef ENABLE_WLAN_FILTERING_PATCH
3634 * We need to disable the optimizer because the optimizer is buggy
3635 * and wipes out some LD instructions generated by the below
3636 * code to validate the Frame Control bits
3639 #endif /* ENABLE_WLAN_FILTERING_PATCH */
3646 * For control frames, there is no SA.
3648 * For management frames, SA is at an
3649 * offset of 10 from the beginning of
3652 * For data frames, SA is at an offset
3653 * of 10 from the beginning of the packet
3654 * if From DS is clear, at an offset of
3655 * 16 from the beginning of the packet
3656 * if From DS is set and To DS is clear,
3657 * and an offset of 24 from the beginning
3658 * of the packet if From DS is set and To DS
3663 * Generate the tests to be done for data frames
3666 * First, check for To DS set, i.e. check "link[1] & 0x01".
3668 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3669 b1
= new_block(JMP(BPF_JSET
));
3670 b1
->s
.k
= 0x01; /* To DS */
3674 * If To DS is set, the SA is at 24.
3676 b0
= gen_bcmp(OR_LINK
, 24, 6, eaddr
);
3680 * Now, check for To DS not set, i.e. check
3681 * "!(link[1] & 0x01)".
3683 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3684 b2
= new_block(JMP(BPF_JSET
));
3685 b2
->s
.k
= 0x01; /* To DS */
3690 * If To DS is not set, the SA is at 16.
3692 b1
= gen_bcmp(OR_LINK
, 16, 6, eaddr
);
3696 * Now OR together the last two checks. That gives
3697 * the complete set of checks for data frames with
3703 * Now check for From DS being set, and AND that with
3704 * the ORed-together checks.
3706 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3707 b1
= new_block(JMP(BPF_JSET
));
3708 b1
->s
.k
= 0x02; /* From DS */
3713 * Now check for data frames with From DS not set.
3715 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3716 b2
= new_block(JMP(BPF_JSET
));
3717 b2
->s
.k
= 0x02; /* From DS */
3722 * If From DS isn't set, the SA is at 10.
3724 b1
= gen_bcmp(OR_LINK
, 10, 6, eaddr
);
3728 * Now OR together the checks for data frames with
3729 * From DS not set and for data frames with From DS
3730 * set; that gives the checks done for data frames.
3735 * Now check for a data frame.
3736 * I.e, check "link[0] & 0x08".
3738 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3739 b1
= new_block(JMP(BPF_JSET
));
3744 * AND that with the checks done for data frames.
3749 * If the high-order bit of the type value is 0, this
3750 * is a management frame.
3751 * I.e, check "!(link[0] & 0x08)".
3753 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3754 b2
= new_block(JMP(BPF_JSET
));
3760 * For management frames, the SA is at 10.
3762 b1
= gen_bcmp(OR_LINK
, 10, 6, eaddr
);
3766 * OR that with the checks done for data frames.
3767 * That gives the checks done for management and
3773 * If the low-order bit of the type value is 1,
3774 * this is either a control frame or a frame
3775 * with a reserved type, and thus not a
3778 * I.e., check "!(link[0] & 0x04)".
3780 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3781 b1
= new_block(JMP(BPF_JSET
));
3787 * AND that with the checks for data and management
3797 * For control frames, there is no DA.
3799 * For management frames, DA is at an
3800 * offset of 4 from the beginning of
3803 * For data frames, DA is at an offset
3804 * of 4 from the beginning of the packet
3805 * if To DS is clear and at an offset of
3806 * 16 from the beginning of the packet
3811 * Generate the tests to be done for data frames.
3813 * First, check for To DS set, i.e. "link[1] & 0x01".
3815 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3816 b1
= new_block(JMP(BPF_JSET
));
3817 b1
->s
.k
= 0x01; /* To DS */
3821 * If To DS is set, the DA is at 16.
3823 b0
= gen_bcmp(OR_LINK
, 16, 6, eaddr
);
3827 * Now, check for To DS not set, i.e. check
3828 * "!(link[1] & 0x01)".
3830 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
3831 b2
= new_block(JMP(BPF_JSET
));
3832 b2
->s
.k
= 0x01; /* To DS */
3837 * If To DS is not set, the DA is at 4.
3839 b1
= gen_bcmp(OR_LINK
, 4, 6, eaddr
);
3843 * Now OR together the last two checks. That gives
3844 * the complete set of checks for data frames.
3849 * Now check for a data frame.
3850 * I.e, check "link[0] & 0x08".
3852 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3853 b1
= new_block(JMP(BPF_JSET
));
3858 * AND that with the checks done for data frames.
3863 * If the high-order bit of the type value is 0, this
3864 * is a management frame.
3865 * I.e, check "!(link[0] & 0x08)".
3867 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3868 b2
= new_block(JMP(BPF_JSET
));
3874 * For management frames, the DA is at 4.
3876 b1
= gen_bcmp(OR_LINK
, 4, 6, eaddr
);
3880 * OR that with the checks done for data frames.
3881 * That gives the checks done for management and
3887 * If the low-order bit of the type value is 1,
3888 * this is either a control frame or a frame
3889 * with a reserved type, and thus not a
3892 * I.e., check "!(link[0] & 0x04)".
3894 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
3895 b1
= new_block(JMP(BPF_JSET
));
3901 * AND that with the checks for data and management
3908 * XXX - add RA, TA, and BSSID keywords?
3911 return (gen_bcmp(OR_LINK
, 4, 6, eaddr
));
3915 * Not present in CTS or ACK control frames.
3917 b0
= gen_mcmp(OR_LINK
, 0, BPF_B
, IEEE80211_FC0_TYPE_CTL
,
3918 IEEE80211_FC0_TYPE_MASK
);
3920 b1
= gen_mcmp(OR_LINK
, 0, BPF_B
, IEEE80211_FC0_SUBTYPE_CTS
,
3921 IEEE80211_FC0_SUBTYPE_MASK
);
3923 b2
= gen_mcmp(OR_LINK
, 0, BPF_B
, IEEE80211_FC0_SUBTYPE_ACK
,
3924 IEEE80211_FC0_SUBTYPE_MASK
);
3928 b1
= gen_bcmp(OR_LINK
, 10, 6, eaddr
);
3934 * Not present in control frames.
3936 b0
= gen_mcmp(OR_LINK
, 0, BPF_B
, IEEE80211_FC0_TYPE_CTL
,
3937 IEEE80211_FC0_TYPE_MASK
);
3939 b1
= gen_bcmp(OR_LINK
, 16, 6, eaddr
);
3945 * Present only if the direction mask has both "From DS"
3946 * and "To DS" set. Neither control frames nor management
3947 * frames should have both of those set, so we don't
3948 * check the frame type.
3950 b0
= gen_mcmp(OR_LINK
, 1, BPF_B
,
3951 IEEE80211_FC1_DIR_DSTODS
, IEEE80211_FC1_DIR_MASK
);
3952 b1
= gen_bcmp(OR_LINK
, 24, 6, eaddr
);
3957 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
3958 b1
= gen_wlanhostop(eaddr
, Q_DST
);
3964 b0
= gen_wlanhostop(eaddr
, Q_SRC
);
3965 b1
= gen_wlanhostop(eaddr
, Q_DST
);
3974 * Like gen_ehostop, but for RFC 2625 IP-over-Fibre-Channel.
3975 * (We assume that the addresses are IEEE 48-bit MAC addresses,
3976 * as the RFC states.)
3978 static struct block
*
3979 gen_ipfchostop(eaddr
, dir
)
3980 register const u_char
*eaddr
;
3983 register struct block
*b0
, *b1
;
3987 return gen_bcmp(OR_LINK
, 10, 6, eaddr
);
3990 return gen_bcmp(OR_LINK
, 2, 6, eaddr
);
3993 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
3994 b1
= gen_ipfchostop(eaddr
, Q_DST
);
4000 b0
= gen_ipfchostop(eaddr
, Q_SRC
);
4001 b1
= gen_ipfchostop(eaddr
, Q_DST
);
4010 * This is quite tricky because there may be pad bytes in front of the
4011 * DECNET header, and then there are two possible data packet formats that
4012 * carry both src and dst addresses, plus 5 packet types in a format that
4013 * carries only the src node, plus 2 types that use a different format and
4014 * also carry just the src node.
4018 * Instead of doing those all right, we just look for data packets with
4019 * 0 or 1 bytes of padding. If you want to look at other packets, that
4020 * will require a lot more hacking.
4022 * To add support for filtering on DECNET "areas" (network numbers)
4023 * one would want to add a "mask" argument to this routine. That would
4024 * make the filter even more inefficient, although one could be clever
4025 * and not generate masking instructions if the mask is 0xFFFF.
4027 static struct block
*
4028 gen_dnhostop(addr
, dir
)
4032 struct block
*b0
, *b1
, *b2
, *tmp
;
4033 u_int offset_lh
; /* offset if long header is received */
4034 u_int offset_sh
; /* offset if short header is received */
4039 offset_sh
= 1; /* follows flags */
4040 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
4044 offset_sh
= 3; /* follows flags, dstnode */
4045 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
4049 /* Inefficient because we do our Calvinball dance twice */
4050 b0
= gen_dnhostop(addr
, Q_SRC
);
4051 b1
= gen_dnhostop(addr
, Q_DST
);
4057 /* Inefficient because we do our Calvinball dance twice */
4058 b0
= gen_dnhostop(addr
, Q_SRC
);
4059 b1
= gen_dnhostop(addr
, Q_DST
);
4064 bpf_error("ISO host filtering not implemented");
4069 b0
= gen_linktype(ETHERTYPE_DN
);
4070 /* Check for pad = 1, long header case */
4071 tmp
= gen_mcmp(OR_NET
, 2, BPF_H
,
4072 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
4073 b1
= gen_cmp(OR_NET
, 2 + 1 + offset_lh
,
4074 BPF_H
, (bpf_int32
)ntohs((u_short
)addr
));
4076 /* Check for pad = 0, long header case */
4077 tmp
= gen_mcmp(OR_NET
, 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
4078 b2
= gen_cmp(OR_NET
, 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs((u_short
)addr
));
4081 /* Check for pad = 1, short header case */
4082 tmp
= gen_mcmp(OR_NET
, 2, BPF_H
,
4083 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
4084 b2
= gen_cmp(OR_NET
, 2 + 1 + offset_sh
, BPF_H
, (bpf_int32
)ntohs((u_short
)addr
));
4087 /* Check for pad = 0, short header case */
4088 tmp
= gen_mcmp(OR_NET
, 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
4089 b2
= gen_cmp(OR_NET
, 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs((u_short
)addr
));
4093 /* Combine with test for linktype */
4099 * Generate a check for IPv4 or IPv6 for MPLS-encapsulated packets;
4100 * test the bottom-of-stack bit, and then check the version number
4101 * field in the IP header.
4103 static struct block
*
4104 gen_mpls_linktype(proto
)
4107 struct block
*b0
, *b1
;
4112 /* match the bottom-of-stack bit */
4113 b0
= gen_mcmp(OR_NET
, -2, BPF_B
, 0x01, 0x01);
4114 /* match the IPv4 version number */
4115 b1
= gen_mcmp(OR_NET
, 0, BPF_B
, 0x40, 0xf0);
4120 /* match the bottom-of-stack bit */
4121 b0
= gen_mcmp(OR_NET
, -2, BPF_B
, 0x01, 0x01);
4122 /* match the IPv4 version number */
4123 b1
= gen_mcmp(OR_NET
, 0, BPF_B
, 0x60, 0xf0);
4132 static struct block
*
4133 gen_host(addr
, mask
, proto
, dir
, type
)
4140 struct block
*b0
, *b1
;
4141 const char *typestr
;
4151 b0
= gen_host(addr
, mask
, Q_IP
, dir
, type
);
4153 * Only check for non-IPv4 addresses if we're not
4154 * checking MPLS-encapsulated packets.
4156 if (label_stack_depth
== 0) {
4157 b1
= gen_host(addr
, mask
, Q_ARP
, dir
, type
);
4159 b0
= gen_host(addr
, mask
, Q_RARP
, dir
, type
);
4165 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
, 12, 16);
4168 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
, 14, 24);
4171 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
, 14, 24);
4174 bpf_error("'tcp' modifier applied to %s", typestr
);
4177 bpf_error("'sctp' modifier applied to %s", typestr
);
4180 bpf_error("'udp' modifier applied to %s", typestr
);
4183 bpf_error("'icmp' modifier applied to %s", typestr
);
4186 bpf_error("'igmp' modifier applied to %s", typestr
);
4189 bpf_error("'igrp' modifier applied to %s", typestr
);
4192 bpf_error("'pim' modifier applied to %s", typestr
);
4195 bpf_error("'vrrp' modifier applied to %s", typestr
);
4198 bpf_error("ATALK host filtering not implemented");
4201 bpf_error("AARP host filtering not implemented");
4204 return gen_dnhostop(addr
, dir
);
4207 bpf_error("SCA host filtering not implemented");
4210 bpf_error("LAT host filtering not implemented");
4213 bpf_error("MOPDL host filtering not implemented");
4216 bpf_error("MOPRC host filtering not implemented");
4220 bpf_error("'ip6' modifier applied to ip host");
4223 bpf_error("'icmp6' modifier applied to %s", typestr
);
4227 bpf_error("'ah' modifier applied to %s", typestr
);
4230 bpf_error("'esp' modifier applied to %s", typestr
);
4233 bpf_error("ISO host filtering not implemented");
4236 bpf_error("'esis' modifier applied to %s", typestr
);
4239 bpf_error("'isis' modifier applied to %s", typestr
);
4242 bpf_error("'clnp' modifier applied to %s", typestr
);
4245 bpf_error("'stp' modifier applied to %s", typestr
);
4248 bpf_error("IPX host filtering not implemented");
4251 bpf_error("'netbeui' modifier applied to %s", typestr
);
4254 bpf_error("'radio' modifier applied to %s", typestr
);
4263 static struct block
*
4264 gen_host6(addr
, mask
, proto
, dir
, type
)
4265 struct in6_addr
*addr
;
4266 struct in6_addr
*mask
;
4271 const char *typestr
;
4281 return gen_host6(addr
, mask
, Q_IPV6
, dir
, type
);
4284 bpf_error("'ip' modifier applied to ip6 %s", typestr
);
4287 bpf_error("'rarp' modifier applied to ip6 %s", typestr
);
4290 bpf_error("'arp' modifier applied to ip6 %s", typestr
);
4293 bpf_error("'sctp' modifier applied to %s", typestr
);
4296 bpf_error("'tcp' modifier applied to %s", typestr
);
4299 bpf_error("'udp' modifier applied to %s", typestr
);
4302 bpf_error("'icmp' modifier applied to %s", typestr
);
4305 bpf_error("'igmp' modifier applied to %s", typestr
);
4308 bpf_error("'igrp' modifier applied to %s", typestr
);
4311 bpf_error("'pim' modifier applied to %s", typestr
);
4314 bpf_error("'vrrp' modifier applied to %s", typestr
);
4317 bpf_error("ATALK host filtering not implemented");
4320 bpf_error("AARP host filtering not implemented");
4323 bpf_error("'decnet' modifier applied to ip6 %s", typestr
);
4326 bpf_error("SCA host filtering not implemented");
4329 bpf_error("LAT host filtering not implemented");
4332 bpf_error("MOPDL host filtering not implemented");
4335 bpf_error("MOPRC host filtering not implemented");
4338 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
, 8, 24);
4341 bpf_error("'icmp6' modifier applied to %s", typestr
);
4344 bpf_error("'ah' modifier applied to %s", typestr
);
4347 bpf_error("'esp' modifier applied to %s", typestr
);
4350 bpf_error("ISO host filtering not implemented");
4353 bpf_error("'esis' modifier applied to %s", typestr
);
4356 bpf_error("'isis' modifier applied to %s", typestr
);
4359 bpf_error("'clnp' modifier applied to %s", typestr
);
4362 bpf_error("'stp' modifier applied to %s", typestr
);
4365 bpf_error("IPX host filtering not implemented");
4368 bpf_error("'netbeui' modifier applied to %s", typestr
);
4371 bpf_error("'radio' modifier applied to %s", typestr
);
4381 static struct block
*
4382 gen_gateway(eaddr
, alist
, proto
, dir
)
4383 const u_char
*eaddr
;
4384 bpf_u_int32
**alist
;
4388 struct block
*b0
, *b1
, *tmp
;
4391 bpf_error("direction applied to 'gateway'");
4400 b0
= gen_ehostop(eaddr
, Q_OR
);
4403 b0
= gen_fhostop(eaddr
, Q_OR
);
4406 b0
= gen_thostop(eaddr
, Q_OR
);
4408 case DLT_IEEE802_11
:
4409 case DLT_IEEE802_11_RADIO_AVS
:
4411 case DLT_IEEE802_11_RADIO
:
4412 case DLT_PRISM_HEADER
:
4413 b0
= gen_wlanhostop(eaddr
, Q_OR
);
4418 * Check that the packet doesn't begin with an
4419 * LE Control marker. (We've already generated
4422 b1
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
,
4427 * Now check the MAC address.
4429 b0
= gen_ehostop(eaddr
, Q_OR
);
4433 case DLT_IP_OVER_FC
:
4434 b0
= gen_ipfchostop(eaddr
, Q_OR
);
4438 "'gateway' supported only on ethernet/FDDI/token ring/802.11/Fibre Channel");
4440 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
, Q_HOST
);
4442 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
,
4451 bpf_error("illegal modifier of 'gateway'");
4457 gen_proto_abbrev(proto
)
4466 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
4468 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
4474 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
4476 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
4482 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
4484 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
4490 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
4493 #ifndef IPPROTO_IGMP
4494 #define IPPROTO_IGMP 2
4498 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
4501 #ifndef IPPROTO_IGRP
4502 #define IPPROTO_IGRP 9
4505 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
4509 #define IPPROTO_PIM 103
4513 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
4515 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
4520 #ifndef IPPROTO_VRRP
4521 #define IPPROTO_VRRP 112
4525 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
4529 b1
= gen_linktype(ETHERTYPE_IP
);
4533 b1
= gen_linktype(ETHERTYPE_ARP
);
4537 b1
= gen_linktype(ETHERTYPE_REVARP
);
4541 bpf_error("link layer applied in wrong context");
4544 b1
= gen_linktype(ETHERTYPE_ATALK
);
4548 b1
= gen_linktype(ETHERTYPE_AARP
);
4552 b1
= gen_linktype(ETHERTYPE_DN
);
4556 b1
= gen_linktype(ETHERTYPE_SCA
);
4560 b1
= gen_linktype(ETHERTYPE_LAT
);
4564 b1
= gen_linktype(ETHERTYPE_MOPDL
);
4568 b1
= gen_linktype(ETHERTYPE_MOPRC
);
4573 b1
= gen_linktype(ETHERTYPE_IPV6
);
4576 #ifndef IPPROTO_ICMPV6
4577 #define IPPROTO_ICMPV6 58
4580 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
4585 #define IPPROTO_AH 51
4588 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
4590 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
4596 #define IPPROTO_ESP 50
4599 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
4601 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
4607 b1
= gen_linktype(LLCSAP_ISONS
);
4611 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
4615 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
4618 case Q_ISIS_L1
: /* all IS-IS Level1 PDU-Types */
4619 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
4620 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
4622 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
4624 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
4626 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
4630 case Q_ISIS_L2
: /* all IS-IS Level2 PDU-Types */
4631 b0
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
4632 b1
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
); /* FIXME extract the circuit-type bits */
4634 b0
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
4636 b0
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
4638 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
4642 case Q_ISIS_IIH
: /* all IS-IS Hello PDU-Types */
4643 b0
= gen_proto(ISIS_L1_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
4644 b1
= gen_proto(ISIS_L2_LAN_IIH
, Q_ISIS
, Q_DEFAULT
);
4646 b0
= gen_proto(ISIS_PTP_IIH
, Q_ISIS
, Q_DEFAULT
);
4651 b0
= gen_proto(ISIS_L1_LSP
, Q_ISIS
, Q_DEFAULT
);
4652 b1
= gen_proto(ISIS_L2_LSP
, Q_ISIS
, Q_DEFAULT
);
4657 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
4658 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
4660 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
4662 b0
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
4667 b0
= gen_proto(ISIS_L1_CSNP
, Q_ISIS
, Q_DEFAULT
);
4668 b1
= gen_proto(ISIS_L2_CSNP
, Q_ISIS
, Q_DEFAULT
);
4673 b0
= gen_proto(ISIS_L1_PSNP
, Q_ISIS
, Q_DEFAULT
);
4674 b1
= gen_proto(ISIS_L2_PSNP
, Q_ISIS
, Q_DEFAULT
);
4679 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
4683 b1
= gen_linktype(LLCSAP_8021D
);
4687 b1
= gen_linktype(LLCSAP_IPX
);
4691 b1
= gen_linktype(LLCSAP_NETBEUI
);
4695 bpf_error("'radio' is not a valid protocol type");
4703 static struct block
*
4710 s
= gen_load_a(OR_NET
, 6, BPF_H
);
4711 b
= new_block(JMP(BPF_JSET
));
4720 * Generate a comparison to a port value in the transport-layer header
4721 * at the specified offset from the beginning of that header.
4723 * XXX - this handles a variable-length prefix preceding the link-layer
4724 * header, such as the radiotap or AVS radio prefix, but doesn't handle
4725 * variable-length link-layer headers (such as Token Ring or 802.11
4728 static struct block
*
4729 gen_portatom(off
, v
)
4733 return gen_cmp(OR_TRAN_IPV4
, off
, BPF_H
, v
);
4737 static struct block
*
4738 gen_portatom6(off
, v
)
4742 return gen_cmp(OR_TRAN_IPV6
, off
, BPF_H
, v
);
4747 gen_portop(port
, proto
, dir
)
4748 int port
, proto
, dir
;
4750 struct block
*b0
, *b1
, *tmp
;
4752 /* ip proto 'proto' */
4753 tmp
= gen_cmp(OR_NET
, 9, BPF_B
, (bpf_int32
)proto
);
4759 b1
= gen_portatom(0, (bpf_int32
)port
);
4763 b1
= gen_portatom(2, (bpf_int32
)port
);
4768 tmp
= gen_portatom(0, (bpf_int32
)port
);
4769 b1
= gen_portatom(2, (bpf_int32
)port
);
4774 tmp
= gen_portatom(0, (bpf_int32
)port
);
4775 b1
= gen_portatom(2, (bpf_int32
)port
);
4787 static struct block
*
4788 gen_port(port
, ip_proto
, dir
)
4793 struct block
*b0
, *b1
, *tmp
;
4798 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
4799 * not LLC encapsulation with LLCSAP_IP.
4801 * For IEEE 802 networks - which includes 802.5 token ring
4802 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
4803 * says that SNAP encapsulation is used, not LLC encapsulation
4806 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
4807 * RFC 2225 say that SNAP encapsulation is used, not LLC
4808 * encapsulation with LLCSAP_IP.
4810 * So we always check for ETHERTYPE_IP.
4812 b0
= gen_linktype(ETHERTYPE_IP
);
4818 b1
= gen_portop(port
, ip_proto
, dir
);
4822 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
4823 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
4825 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
4838 gen_portop6(port
, proto
, dir
)
4839 int port
, proto
, dir
;
4841 struct block
*b0
, *b1
, *tmp
;
4843 /* ip6 proto 'proto' */
4844 b0
= gen_cmp(OR_NET
, 6, BPF_B
, (bpf_int32
)proto
);
4848 b1
= gen_portatom6(0, (bpf_int32
)port
);
4852 b1
= gen_portatom6(2, (bpf_int32
)port
);
4857 tmp
= gen_portatom6(0, (bpf_int32
)port
);
4858 b1
= gen_portatom6(2, (bpf_int32
)port
);
4863 tmp
= gen_portatom6(0, (bpf_int32
)port
);
4864 b1
= gen_portatom6(2, (bpf_int32
)port
);
4876 static struct block
*
4877 gen_port6(port
, ip_proto
, dir
)
4882 struct block
*b0
, *b1
, *tmp
;
4884 /* link proto ip6 */
4885 b0
= gen_linktype(ETHERTYPE_IPV6
);
4891 b1
= gen_portop6(port
, ip_proto
, dir
);
4895 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
4896 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
4898 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
4910 /* gen_portrange code */
4911 static struct block
*
4912 gen_portrangeatom(off
, v1
, v2
)
4916 struct block
*b1
, *b2
;
4920 * Reverse the order of the ports, so v1 is the lower one.
4929 b1
= gen_cmp_ge(OR_TRAN_IPV4
, off
, BPF_H
, v1
);
4930 b2
= gen_cmp_le(OR_TRAN_IPV4
, off
, BPF_H
, v2
);
4938 gen_portrangeop(port1
, port2
, proto
, dir
)
4943 struct block
*b0
, *b1
, *tmp
;
4945 /* ip proto 'proto' */
4946 tmp
= gen_cmp(OR_NET
, 9, BPF_B
, (bpf_int32
)proto
);
4952 b1
= gen_portrangeatom(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
4956 b1
= gen_portrangeatom(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
4961 tmp
= gen_portrangeatom(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
4962 b1
= gen_portrangeatom(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
4967 tmp
= gen_portrangeatom(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
4968 b1
= gen_portrangeatom(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
4980 static struct block
*
4981 gen_portrange(port1
, port2
, ip_proto
, dir
)
4986 struct block
*b0
, *b1
, *tmp
;
4989 b0
= gen_linktype(ETHERTYPE_IP
);
4995 b1
= gen_portrangeop(port1
, port2
, ip_proto
, dir
);
4999 tmp
= gen_portrangeop(port1
, port2
, IPPROTO_TCP
, dir
);
5000 b1
= gen_portrangeop(port1
, port2
, IPPROTO_UDP
, dir
);
5002 tmp
= gen_portrangeop(port1
, port2
, IPPROTO_SCTP
, dir
);
5014 static struct block
*
5015 gen_portrangeatom6(off
, v1
, v2
)
5019 struct block
*b1
, *b2
;
5023 * Reverse the order of the ports, so v1 is the lower one.
5032 b1
= gen_cmp_ge(OR_TRAN_IPV6
, off
, BPF_H
, v1
);
5033 b2
= gen_cmp_le(OR_TRAN_IPV6
, off
, BPF_H
, v2
);
5041 gen_portrangeop6(port1
, port2
, proto
, dir
)
5046 struct block
*b0
, *b1
, *tmp
;
5048 /* ip6 proto 'proto' */
5049 b0
= gen_cmp(OR_NET
, 6, BPF_B
, (bpf_int32
)proto
);
5053 b1
= gen_portrangeatom6(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
5057 b1
= gen_portrangeatom6(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
5062 tmp
= gen_portrangeatom6(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
5063 b1
= gen_portrangeatom6(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
5068 tmp
= gen_portrangeatom6(0, (bpf_int32
)port1
, (bpf_int32
)port2
);
5069 b1
= gen_portrangeatom6(2, (bpf_int32
)port1
, (bpf_int32
)port2
);
5081 static struct block
*
5082 gen_portrange6(port1
, port2
, ip_proto
, dir
)
5087 struct block
*b0
, *b1
, *tmp
;
5089 /* link proto ip6 */
5090 b0
= gen_linktype(ETHERTYPE_IPV6
);
5096 b1
= gen_portrangeop6(port1
, port2
, ip_proto
, dir
);
5100 tmp
= gen_portrangeop6(port1
, port2
, IPPROTO_TCP
, dir
);
5101 b1
= gen_portrangeop6(port1
, port2
, IPPROTO_UDP
, dir
);
5103 tmp
= gen_portrangeop6(port1
, port2
, IPPROTO_SCTP
, dir
);
5116 lookup_proto(name
, proto
)
5117 register const char *name
;
5127 v
= pcap_nametoproto(name
);
5128 if (v
== PROTO_UNDEF
)
5129 bpf_error("unknown ip proto '%s'", name
);
5133 /* XXX should look up h/w protocol type based on linktype */
5134 v
= pcap_nametoeproto(name
);
5135 if (v
== PROTO_UNDEF
) {
5136 v
= pcap_nametollc(name
);
5137 if (v
== PROTO_UNDEF
)
5138 bpf_error("unknown ether proto '%s'", name
);
5143 if (strcmp(name
, "esis") == 0)
5145 else if (strcmp(name
, "isis") == 0)
5147 else if (strcmp(name
, "clnp") == 0)
5150 bpf_error("unknown osi proto '%s'", name
);
5170 static struct block
*
5171 gen_protochain(v
, proto
, dir
)
5176 #ifdef NO_PROTOCHAIN
5177 return gen_proto(v
, proto
, dir
);
5179 struct block
*b0
, *b
;
5180 struct slist
*s
[100];
5181 int fix2
, fix3
, fix4
, fix5
;
5182 int ahcheck
, again
, end
;
5184 int reg2
= alloc_reg();
5186 memset(s
, 0, sizeof(s
));
5187 fix2
= fix3
= fix4
= fix5
= 0;
5194 b0
= gen_protochain(v
, Q_IP
, dir
);
5195 b
= gen_protochain(v
, Q_IPV6
, dir
);
5199 bpf_error("bad protocol applied for 'protochain'");
5204 * We don't handle variable-length prefixes before the link-layer
5205 * header, or variable-length link-layer headers, here yet.
5206 * We might want to add BPF instructions to do the protochain
5207 * work, to simplify that and, on platforms that have a BPF
5208 * interpreter with the new instructions, let the filtering
5209 * be done in the kernel. (We already require a modified BPF
5210 * engine to do the protochain stuff, to support backward
5211 * branches, and backward branch support is unlikely to appear
5212 * in kernel BPF engines.)
5216 case DLT_IEEE802_11
:
5217 case DLT_IEEE802_11_RADIO
:
5218 case DLT_IEEE802_11_RADIO_AVS
:
5219 case DLT_PRISM_HEADER
:
5221 bpf_error("'protochain' not supported with 802.11");
5224 no_optimize
= 1; /*this code is not compatible with optimzer yet */
5227 * s[0] is a dummy entry to protect other BPF insn from damage
5228 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
5229 * hard to find interdependency made by jump table fixup.
5232 s
[i
] = new_stmt(0); /*dummy*/
5237 b0
= gen_linktype(ETHERTYPE_IP
);
5240 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
5241 s
[i
]->s
.k
= off_macpl
+ off_nl
+ 9;
5243 /* X = ip->ip_hl << 2 */
5244 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
5245 s
[i
]->s
.k
= off_macpl
+ off_nl
;
5250 b0
= gen_linktype(ETHERTYPE_IPV6
);
5252 /* A = ip6->ip_nxt */
5253 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
5254 s
[i
]->s
.k
= off_macpl
+ off_nl
+ 6;
5256 /* X = sizeof(struct ip6_hdr) */
5257 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
5263 bpf_error("unsupported proto to gen_protochain");
5267 /* again: if (A == v) goto end; else fall through; */
5269 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5271 s
[i
]->s
.jt
= NULL
; /*later*/
5272 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
5276 #ifndef IPPROTO_NONE
5277 #define IPPROTO_NONE 59
5279 /* if (A == IPPROTO_NONE) goto end */
5280 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5281 s
[i
]->s
.jt
= NULL
; /*later*/
5282 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
5283 s
[i
]->s
.k
= IPPROTO_NONE
;
5284 s
[fix5
]->s
.jf
= s
[i
];
5289 if (proto
== Q_IPV6
) {
5290 int v6start
, v6end
, v6advance
, j
;
5293 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
5294 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5295 s
[i
]->s
.jt
= NULL
; /*later*/
5296 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
5297 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
5298 s
[fix2
]->s
.jf
= s
[i
];
5300 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
5301 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5302 s
[i
]->s
.jt
= NULL
; /*later*/
5303 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
5304 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
5306 /* if (A == IPPROTO_ROUTING) goto v6advance */
5307 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5308 s
[i
]->s
.jt
= NULL
; /*later*/
5309 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
5310 s
[i
]->s
.k
= IPPROTO_ROUTING
;
5312 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
5313 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5314 s
[i
]->s
.jt
= NULL
; /*later*/
5315 s
[i
]->s
.jf
= NULL
; /*later*/
5316 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
5327 * X = X + (P[X + 1] + 1) * 8;
5330 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
5332 /* A = P[X + packet head] */
5333 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
5334 s
[i
]->s
.k
= off_macpl
+ off_nl
;
5337 s
[i
] = new_stmt(BPF_ST
);
5341 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
5344 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5348 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
5350 /* A = P[X + packet head]; */
5351 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
5352 s
[i
]->s
.k
= off_macpl
+ off_nl
;
5355 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5359 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
5363 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
5366 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
5370 /* goto again; (must use BPF_JA for backward jump) */
5371 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
5372 s
[i
]->s
.k
= again
- i
- 1;
5373 s
[i
- 1]->s
.jf
= s
[i
];
5377 for (j
= v6start
; j
<= v6end
; j
++)
5378 s
[j
]->s
.jt
= s
[v6advance
];
5383 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5385 s
[fix2
]->s
.jf
= s
[i
];
5391 /* if (A == IPPROTO_AH) then fall through; else goto end; */
5392 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
5393 s
[i
]->s
.jt
= NULL
; /*later*/
5394 s
[i
]->s
.jf
= NULL
; /*later*/
5395 s
[i
]->s
.k
= IPPROTO_AH
;
5397 s
[fix3
]->s
.jf
= s
[ahcheck
];
5404 * X = X + (P[X + 1] + 2) * 4;
5407 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
5409 /* A = P[X + packet head]; */
5410 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
5411 s
[i
]->s
.k
= off_macpl
+ off_nl
;
5414 s
[i
] = new_stmt(BPF_ST
);
5418 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
5421 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5425 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
5427 /* A = P[X + packet head] */
5428 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
5429 s
[i
]->s
.k
= off_macpl
+ off_nl
;
5432 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5436 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
5440 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
5443 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
5447 /* goto again; (must use BPF_JA for backward jump) */
5448 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
5449 s
[i
]->s
.k
= again
- i
- 1;
5454 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
5456 s
[fix2
]->s
.jt
= s
[end
];
5457 s
[fix4
]->s
.jf
= s
[end
];
5458 s
[fix5
]->s
.jt
= s
[end
];
5465 for (i
= 0; i
< max
- 1; i
++)
5466 s
[i
]->next
= s
[i
+ 1];
5467 s
[max
- 1]->next
= NULL
;
5472 b
= new_block(JMP(BPF_JEQ
));
5473 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
5483 static struct block
*
5484 gen_check_802_11_data_frame()
5487 struct block
*b0
, *b1
;
5490 * A data frame has the 0x08 bit (b3) in the frame control field set
5491 * and the 0x04 bit (b2) clear.
5493 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
5494 b0
= new_block(JMP(BPF_JSET
));
5498 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
5499 b1
= new_block(JMP(BPF_JSET
));
5510 * Generate code that checks whether the packet is a packet for protocol
5511 * <proto> and whether the type field in that protocol's header has
5512 * the value <v>, e.g. if <proto> is Q_IP, it checks whether it's an
5513 * IP packet and checks the protocol number in the IP header against <v>.
5515 * If <proto> is Q_DEFAULT, i.e. just "proto" was specified, it checks
5516 * against Q_IP and Q_IPV6.
5518 static struct block
*
5519 gen_proto(v
, proto
, dir
)
5524 struct block
*b0
, *b1
;
5526 if (dir
!= Q_DEFAULT
)
5527 bpf_error("direction applied to 'proto'");
5532 b0
= gen_proto(v
, Q_IP
, dir
);
5533 b1
= gen_proto(v
, Q_IPV6
, dir
);
5541 * For FDDI, RFC 1188 says that SNAP encapsulation is used,
5542 * not LLC encapsulation with LLCSAP_IP.
5544 * For IEEE 802 networks - which includes 802.5 token ring
5545 * (which is what DLT_IEEE802 means) and 802.11 - RFC 1042
5546 * says that SNAP encapsulation is used, not LLC encapsulation
5549 * For LLC-encapsulated ATM/"Classical IP", RFC 1483 and
5550 * RFC 2225 say that SNAP encapsulation is used, not LLC
5551 * encapsulation with LLCSAP_IP.
5553 * So we always check for ETHERTYPE_IP.
5555 b0
= gen_linktype(ETHERTYPE_IP
);
5557 b1
= gen_cmp(OR_NET
, 9, BPF_B
, (bpf_int32
)v
);
5559 b1
= gen_protochain(v
, Q_IP
);
5569 * Frame Relay packets typically have an OSI
5570 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
5571 * generates code to check for all the OSI
5572 * NLPIDs, so calling it and then adding a check
5573 * for the particular NLPID for which we're
5574 * looking is bogus, as we can just check for
5577 * What we check for is the NLPID and a frame
5578 * control field value of UI, i.e. 0x03 followed
5581 * XXX - assumes a 2-byte Frame Relay header with
5582 * DLCI and flags. What if the address is longer?
5584 * XXX - what about SNAP-encapsulated frames?
5586 return gen_cmp(OR_LINK
, 2, BPF_H
, (0x03<<8) | v
);
5592 * Cisco uses an Ethertype lookalike - for OSI,
5595 b0
= gen_linktype(LLCSAP_ISONS
<<8 | LLCSAP_ISONS
);
5596 /* OSI in C-HDLC is stuffed with a fudge byte */
5597 b1
= gen_cmp(OR_NET_NOSNAP
, 1, BPF_B
, (long)v
);
5602 b0
= gen_linktype(LLCSAP_ISONS
);
5603 b1
= gen_cmp(OR_NET_NOSNAP
, 0, BPF_B
, (long)v
);
5609 b0
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
5611 * 4 is the offset of the PDU type relative to the IS-IS
5614 b1
= gen_cmp(OR_NET_NOSNAP
, 4, BPF_B
, (long)v
);
5619 bpf_error("arp does not encapsulate another protocol");
5623 bpf_error("rarp does not encapsulate another protocol");
5627 bpf_error("atalk encapsulation is not specifiable");
5631 bpf_error("decnet encapsulation is not specifiable");
5635 bpf_error("sca does not encapsulate another protocol");
5639 bpf_error("lat does not encapsulate another protocol");
5643 bpf_error("moprc does not encapsulate another protocol");
5647 bpf_error("mopdl does not encapsulate another protocol");
5651 return gen_linktype(v
);
5654 bpf_error("'udp proto' is bogus");
5658 bpf_error("'tcp proto' is bogus");
5662 bpf_error("'sctp proto' is bogus");
5666 bpf_error("'icmp proto' is bogus");
5670 bpf_error("'igmp proto' is bogus");
5674 bpf_error("'igrp proto' is bogus");
5678 bpf_error("'pim proto' is bogus");
5682 bpf_error("'vrrp proto' is bogus");
5687 b0
= gen_linktype(ETHERTYPE_IPV6
);
5689 b1
= gen_cmp(OR_NET
, 6, BPF_B
, (bpf_int32
)v
);
5691 b1
= gen_protochain(v
, Q_IPV6
);
5697 bpf_error("'icmp6 proto' is bogus");
5701 bpf_error("'ah proto' is bogus");
5704 bpf_error("'ah proto' is bogus");
5707 bpf_error("'stp proto' is bogus");
5710 bpf_error("'ipx proto' is bogus");
5713 bpf_error("'netbeui proto' is bogus");
5716 bpf_error("'radio proto' is bogus");
5727 register const char *name
;
5730 int proto
= q
.proto
;
5734 bpf_u_int32 mask
, addr
;
5736 bpf_u_int32
**alist
;
5739 struct sockaddr_in
*sin4
;
5740 struct sockaddr_in6
*sin6
;
5741 struct addrinfo
*res
, *res0
;
5742 struct in6_addr mask128
;
5744 struct block
*b
, *tmp
;
5745 int port
, real_proto
;
5751 addr
= pcap_nametonetaddr(name
);
5753 bpf_error("unknown network '%s'", name
);
5754 /* Left justify network addr and calculate its network mask */
5756 while (addr
&& (addr
& 0xff000000) == 0) {
5760 return gen_host(addr
, mask
, proto
, dir
, q
.addr
);
5764 if (proto
== Q_LINK
) {
5768 eaddr
= pcap_ether_hostton(name
);
5771 "unknown ether host '%s'", name
);
5772 b
= gen_ehostop(eaddr
, dir
);
5777 eaddr
= pcap_ether_hostton(name
);
5780 "unknown FDDI host '%s'", name
);
5781 b
= gen_fhostop(eaddr
, dir
);
5786 eaddr
= pcap_ether_hostton(name
);
5789 "unknown token ring host '%s'", name
);
5790 b
= gen_thostop(eaddr
, dir
);
5794 case DLT_IEEE802_11
:
5795 case DLT_IEEE802_11_RADIO_AVS
:
5796 case DLT_IEEE802_11_RADIO
:
5797 case DLT_PRISM_HEADER
:
5799 eaddr
= pcap_ether_hostton(name
);
5802 "unknown 802.11 host '%s'", name
);
5803 b
= gen_wlanhostop(eaddr
, dir
);
5807 case DLT_IP_OVER_FC
:
5808 eaddr
= pcap_ether_hostton(name
);
5811 "unknown Fibre Channel host '%s'", name
);
5812 b
= gen_ipfchostop(eaddr
, dir
);
5821 * Check that the packet doesn't begin
5822 * with an LE Control marker. (We've
5823 * already generated a test for LANE.)
5825 tmp
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
,
5829 eaddr
= pcap_ether_hostton(name
);
5832 "unknown ether host '%s'", name
);
5833 b
= gen_ehostop(eaddr
, dir
);
5839 bpf_error("only ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel supports link-level host name");
5840 } else if (proto
== Q_DECNET
) {
5841 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
5843 * I don't think DECNET hosts can be multihomed, so
5844 * there is no need to build up a list of addresses
5846 return (gen_host(dn_addr
, 0, proto
, dir
, q
.addr
));
5849 alist
= pcap_nametoaddr(name
);
5850 if (alist
== NULL
|| *alist
== NULL
)
5851 bpf_error("unknown host '%s'", name
);
5853 if (off_linktype
== (u_int
)-1 && tproto
== Q_DEFAULT
)
5855 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
, q
.addr
);
5857 tmp
= gen_host(**alist
++, 0xffffffff,
5858 tproto
, dir
, q
.addr
);
5864 memset(&mask128
, 0xff, sizeof(mask128
));
5865 res0
= res
= pcap_nametoaddrinfo(name
);
5867 bpf_error("unknown host '%s'", name
);
5869 tproto
= tproto6
= proto
;
5870 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
5874 for (res
= res0
; res
; res
= res
->ai_next
) {
5875 switch (res
->ai_family
) {
5877 if (tproto
== Q_IPV6
)
5880 sin4
= (struct sockaddr_in
*)
5882 tmp
= gen_host(ntohl(sin4
->sin_addr
.s_addr
),
5883 0xffffffff, tproto
, dir
, q
.addr
);
5886 if (tproto6
== Q_IP
)
5889 sin6
= (struct sockaddr_in6
*)
5891 tmp
= gen_host6(&sin6
->sin6_addr
,
5892 &mask128
, tproto6
, dir
, q
.addr
);
5903 bpf_error("unknown host '%s'%s", name
,
5904 (proto
== Q_DEFAULT
)
5906 : " for specified address family");
5913 if (proto
!= Q_DEFAULT
&&
5914 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
5915 bpf_error("illegal qualifier of 'port'");
5916 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
5917 bpf_error("unknown port '%s'", name
);
5918 if (proto
== Q_UDP
) {
5919 if (real_proto
== IPPROTO_TCP
)
5920 bpf_error("port '%s' is tcp", name
);
5921 else if (real_proto
== IPPROTO_SCTP
)
5922 bpf_error("port '%s' is sctp", name
);
5924 /* override PROTO_UNDEF */
5925 real_proto
= IPPROTO_UDP
;
5927 if (proto
== Q_TCP
) {
5928 if (real_proto
== IPPROTO_UDP
)
5929 bpf_error("port '%s' is udp", name
);
5931 else if (real_proto
== IPPROTO_SCTP
)
5932 bpf_error("port '%s' is sctp", name
);
5934 /* override PROTO_UNDEF */
5935 real_proto
= IPPROTO_TCP
;
5937 if (proto
== Q_SCTP
) {
5938 if (real_proto
== IPPROTO_UDP
)
5939 bpf_error("port '%s' is udp", name
);
5941 else if (real_proto
== IPPROTO_TCP
)
5942 bpf_error("port '%s' is tcp", name
);
5944 /* override PROTO_UNDEF */
5945 real_proto
= IPPROTO_SCTP
;
5948 return gen_port(port
, real_proto
, dir
);
5950 b
= gen_port(port
, real_proto
, dir
);
5951 gen_or(gen_port6(port
, real_proto
, dir
), b
);
5956 if (proto
!= Q_DEFAULT
&&
5957 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
5958 bpf_error("illegal qualifier of 'portrange'");
5959 if (pcap_nametoportrange(name
, &port1
, &port2
, &real_proto
) == 0)
5960 bpf_error("unknown port in range '%s'", name
);
5961 if (proto
== Q_UDP
) {
5962 if (real_proto
== IPPROTO_TCP
)
5963 bpf_error("port in range '%s' is tcp", name
);
5964 else if (real_proto
== IPPROTO_SCTP
)
5965 bpf_error("port in range '%s' is sctp", name
);
5967 /* override PROTO_UNDEF */
5968 real_proto
= IPPROTO_UDP
;
5970 if (proto
== Q_TCP
) {
5971 if (real_proto
== IPPROTO_UDP
)
5972 bpf_error("port in range '%s' is udp", name
);
5973 else if (real_proto
== IPPROTO_SCTP
)
5974 bpf_error("port in range '%s' is sctp", name
);
5976 /* override PROTO_UNDEF */
5977 real_proto
= IPPROTO_TCP
;
5979 if (proto
== Q_SCTP
) {
5980 if (real_proto
== IPPROTO_UDP
)
5981 bpf_error("port in range '%s' is udp", name
);
5982 else if (real_proto
== IPPROTO_TCP
)
5983 bpf_error("port in range '%s' is tcp", name
);
5985 /* override PROTO_UNDEF */
5986 real_proto
= IPPROTO_SCTP
;
5989 return gen_portrange(port1
, port2
, real_proto
, dir
);
5991 b
= gen_portrange(port1
, port2
, real_proto
, dir
);
5992 gen_or(gen_portrange6(port1
, port2
, real_proto
, dir
), b
);
5998 eaddr
= pcap_ether_hostton(name
);
6000 bpf_error("unknown ether host: %s", name
);
6002 alist
= pcap_nametoaddr(name
);
6003 if (alist
== NULL
|| *alist
== NULL
)
6004 bpf_error("unknown host '%s'", name
);
6005 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
6009 bpf_error("'gateway' not supported in this configuration");
6013 real_proto
= lookup_proto(name
, proto
);
6014 if (real_proto
>= 0)
6015 return gen_proto(real_proto
, proto
, dir
);
6017 bpf_error("unknown protocol: %s", name
);
6020 real_proto
= lookup_proto(name
, proto
);
6021 if (real_proto
>= 0)
6022 return gen_protochain(real_proto
, proto
, dir
);
6024 bpf_error("unknown protocol: %s", name
);
6035 gen_mcode(s1
, s2
, masklen
, q
)
6036 register const char *s1
, *s2
;
6037 register int masklen
;
6040 register int nlen
, mlen
;
6043 nlen
= __pcap_atoin(s1
, &n
);
6044 /* Promote short ipaddr */
6048 mlen
= __pcap_atoin(s2
, &m
);
6049 /* Promote short ipaddr */
6052 bpf_error("non-network bits set in \"%s mask %s\"",
6055 /* Convert mask len to mask */
6057 bpf_error("mask length must be <= 32");
6060 * X << 32 is not guaranteed by C to be 0; it's
6065 m
= 0xffffffff << (32 - masklen
);
6067 bpf_error("non-network bits set in \"%s/%d\"",
6074 return gen_host(n
, m
, q
.proto
, q
.dir
, q
.addr
);
6077 bpf_error("Mask syntax for networks only");
6086 register const char *s
;
6091 int proto
= q
.proto
;
6097 else if (q
.proto
== Q_DECNET
)
6098 vlen
= __pcap_atodn(s
, &v
);
6100 vlen
= __pcap_atoin(s
, &v
);
6107 if (proto
== Q_DECNET
)
6108 return gen_host(v
, 0, proto
, dir
, q
.addr
);
6109 else if (proto
== Q_LINK
) {
6110 bpf_error("illegal link layer address");
6113 if (s
== NULL
&& q
.addr
== Q_NET
) {
6114 /* Promote short net number */
6115 while (v
&& (v
& 0xff000000) == 0) {
6120 /* Promote short ipaddr */
6124 return gen_host(v
, mask
, proto
, dir
, q
.addr
);
6129 proto
= IPPROTO_UDP
;
6130 else if (proto
== Q_TCP
)
6131 proto
= IPPROTO_TCP
;
6132 else if (proto
== Q_SCTP
)
6133 proto
= IPPROTO_SCTP
;
6134 else if (proto
== Q_DEFAULT
)
6135 proto
= PROTO_UNDEF
;
6137 bpf_error("illegal qualifier of 'port'");
6140 return gen_port((int)v
, proto
, dir
);
6144 b
= gen_port((int)v
, proto
, dir
);
6145 gen_or(gen_port6((int)v
, proto
, dir
), b
);
6152 proto
= IPPROTO_UDP
;
6153 else if (proto
== Q_TCP
)
6154 proto
= IPPROTO_TCP
;
6155 else if (proto
== Q_SCTP
)
6156 proto
= IPPROTO_SCTP
;
6157 else if (proto
== Q_DEFAULT
)
6158 proto
= PROTO_UNDEF
;
6160 bpf_error("illegal qualifier of 'portrange'");
6163 return gen_portrange((int)v
, (int)v
, proto
, dir
);
6167 b
= gen_portrange((int)v
, (int)v
, proto
, dir
);
6168 gen_or(gen_portrange6((int)v
, (int)v
, proto
, dir
), b
);
6174 bpf_error("'gateway' requires a name");
6178 return gen_proto((int)v
, proto
, dir
);
6181 return gen_protochain((int)v
, proto
, dir
);
6196 gen_mcode6(s1
, s2
, masklen
, q
)
6197 register const char *s1
, *s2
;
6198 register int masklen
;
6201 struct addrinfo
*res
;
6202 struct in6_addr
*addr
;
6203 struct in6_addr mask
;
6208 bpf_error("no mask %s supported", s2
);
6210 res
= pcap_nametoaddrinfo(s1
);
6212 bpf_error("invalid ip6 address %s", s1
);
6214 bpf_error("%s resolved to multiple address", s1
);
6215 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
6217 if (sizeof(mask
) * 8 < masklen
)
6218 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
6219 memset(&mask
, 0, sizeof(mask
));
6220 memset(&mask
, 0xff, masklen
/ 8);
6222 mask
.s6_addr
[masklen
/ 8] =
6223 (0xff << (8 - masklen
% 8)) & 0xff;
6226 a
= (u_int32_t
*)addr
;
6227 m
= (u_int32_t
*)&mask
;
6228 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
6229 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
6230 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
6238 bpf_error("Mask syntax for networks only");
6242 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
, q
.addr
);
6247 bpf_error("invalid qualifier against IPv6 address");
6256 register const u_char
*eaddr
;
6259 struct block
*b
, *tmp
;
6261 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
6264 return gen_ehostop(eaddr
, (int)q
.dir
);
6266 return gen_fhostop(eaddr
, (int)q
.dir
);
6268 return gen_thostop(eaddr
, (int)q
.dir
);
6269 case DLT_IEEE802_11
:
6270 case DLT_IEEE802_11_RADIO_AVS
:
6271 case DLT_IEEE802_11_RADIO
:
6272 case DLT_PRISM_HEADER
:
6274 return gen_wlanhostop(eaddr
, (int)q
.dir
);
6278 * Check that the packet doesn't begin with an
6279 * LE Control marker. (We've already generated
6282 tmp
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
, BPF_H
,
6287 * Now check the MAC address.
6289 b
= gen_ehostop(eaddr
, (int)q
.dir
);
6294 case DLT_IP_OVER_FC
:
6295 return gen_ipfchostop(eaddr
, (int)q
.dir
);
6297 bpf_error("ethernet addresses supported only on ethernet/FDDI/token ring/802.11/ATM LANE/Fibre Channel");
6301 bpf_error("ethernet address used in non-ether expression");
6308 struct slist
*s0
, *s1
;
6311 * This is definitely not the best way to do this, but the
6312 * lists will rarely get long.
6319 static struct slist
*
6325 s
= new_stmt(BPF_LDX
|BPF_MEM
);
6330 static struct slist
*
6336 s
= new_stmt(BPF_LD
|BPF_MEM
);
6342 * Modify "index" to use the value stored into its register as an
6343 * offset relative to the beginning of the header for the protocol
6344 * "proto", and allocate a register and put an item "size" bytes long
6345 * (1, 2, or 4) at that offset into that register, making it the register
6349 gen_load(proto
, inst
, size
)
6354 struct slist
*s
, *tmp
;
6356 int regno
= alloc_reg();
6358 free_reg(inst
->regno
);
6362 bpf_error("data size must be 1, 2, or 4");
6378 bpf_error("unsupported index operation");
6382 * The offset is relative to the beginning of the packet
6383 * data, if we have a radio header. (If we don't, this
6386 if (linktype
!= DLT_IEEE802_11_RADIO_AVS
&&
6387 linktype
!= DLT_IEEE802_11_RADIO
&&
6388 linktype
!= DLT_PRISM_HEADER
)
6389 bpf_error("radio information not present in capture");
6392 * Load into the X register the offset computed into the
6393 * register specifed by "index".
6395 s
= xfer_to_x(inst
);
6398 * Load the item at that offset.
6400 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
6402 sappend(inst
->s
, s
);
6407 * The offset is relative to the beginning of
6408 * the link-layer header.
6410 * XXX - what about ATM LANE? Should the index be
6411 * relative to the beginning of the AAL5 frame, so
6412 * that 0 refers to the beginning of the LE Control
6413 * field, or relative to the beginning of the LAN
6414 * frame, so that 0 refers, for Ethernet LANE, to
6415 * the beginning of the destination address?
6417 s
= gen_llprefixlen();
6420 * If "s" is non-null, it has code to arrange that the
6421 * X register contains the length of the prefix preceding
6422 * the link-layer header. Add to it the offset computed
6423 * into the register specified by "index", and move that
6424 * into the X register. Otherwise, just load into the X
6425 * register the offset computed into the register specifed
6429 sappend(s
, xfer_to_a(inst
));
6430 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
6431 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
6433 s
= xfer_to_x(inst
);
6436 * Load the item at the sum of the offset we've put in the
6437 * X register and the offset of the start of the link
6438 * layer header (which is 0 if the radio header is
6439 * variable-length; that header length is what we put
6440 * into the X register and then added to the index).
6442 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
6445 sappend(inst
->s
, s
);
6461 * The offset is relative to the beginning of
6462 * the network-layer header.
6463 * XXX - are there any cases where we want
6466 s
= gen_off_macpl();
6469 * If "s" is non-null, it has code to arrange that the
6470 * X register contains the offset of the MAC-layer
6471 * payload. Add to it the offset computed into the
6472 * register specified by "index", and move that into
6473 * the X register. Otherwise, just load into the X
6474 * register the offset computed into the register specifed
6478 sappend(s
, xfer_to_a(inst
));
6479 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
6480 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
6482 s
= xfer_to_x(inst
);
6485 * Load the item at the sum of the offset we've put in the
6486 * X register, the offset of the start of the network
6487 * layer header from the beginning of the MAC-layer
6488 * payload, and the purported offset of the start of the
6489 * MAC-layer payload (which might be 0 if there's a
6490 * variable-length prefix before the link-layer header
6491 * or the link-layer header itself is variable-length;
6492 * the variable-length offset of the start of the
6493 * MAC-layer payload is what we put into the X register
6494 * and then added to the index).
6496 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
6497 tmp
->s
.k
= off_macpl
+ off_nl
;
6499 sappend(inst
->s
, s
);
6502 * Do the computation only if the packet contains
6503 * the protocol in question.
6505 b
= gen_proto_abbrev(proto
);
6507 gen_and(inst
->b
, b
);
6520 * The offset is relative to the beginning of
6521 * the transport-layer header.
6523 * Load the X register with the length of the IPv4 header
6524 * (plus the offset of the link-layer header, if it's
6525 * a variable-length header), in bytes.
6527 * XXX - are there any cases where we want
6529 * XXX - we should, if we're built with
6530 * IPv6 support, generate code to load either
6531 * IPv4, IPv6, or both, as appropriate.
6533 s
= gen_loadx_iphdrlen();
6536 * The X register now contains the sum of the length
6537 * of any variable-length header preceding the link-layer
6538 * header, any variable-length link-layer header, and the
6539 * length of the network-layer header.
6541 * Load into the A register the offset relative to
6542 * the beginning of the transport layer header,
6543 * add the X register to that, move that to the
6544 * X register, and load with an offset from the
6545 * X register equal to the offset of the network
6546 * layer header relative to the beginning of
6547 * the MAC-layer payload plus the fixed-length
6548 * portion of the offset of the MAC-layer payload
6549 * from the beginning of the raw packet data.
6551 sappend(s
, xfer_to_a(inst
));
6552 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
6553 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
6554 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
6555 tmp
->s
.k
= off_macpl
+ off_nl
;
6556 sappend(inst
->s
, s
);
6559 * Do the computation only if the packet contains
6560 * the protocol in question - which is true only
6561 * if this is an IP datagram and is the first or
6562 * only fragment of that datagram.
6564 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
6566 gen_and(inst
->b
, b
);
6568 gen_and(gen_proto_abbrev(Q_IP
), b
);
6574 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
6578 inst
->regno
= regno
;
6579 s
= new_stmt(BPF_ST
);
6581 sappend(inst
->s
, s
);
6587 gen_relation(code
, a0
, a1
, reversed
)
6589 struct arth
*a0
, *a1
;
6592 struct slist
*s0
, *s1
, *s2
;
6593 struct block
*b
, *tmp
;
6597 if (code
== BPF_JEQ
) {
6598 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
6599 b
= new_block(JMP(code
));
6603 b
= new_block(BPF_JMP
|code
|BPF_X
);
6609 sappend(a0
->s
, a1
->s
);
6613 free_reg(a0
->regno
);
6614 free_reg(a1
->regno
);
6616 /* 'and' together protocol checks */
6619 gen_and(a0
->b
, tmp
= a1
->b
);
6635 int regno
= alloc_reg();
6636 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
6639 s
= new_stmt(BPF_LD
|BPF_LEN
);
6640 s
->next
= new_stmt(BPF_ST
);
6641 s
->next
->s
.k
= regno
;
6656 a
= (struct arth
*)newchunk(sizeof(*a
));
6660 s
= new_stmt(BPF_LD
|BPF_IMM
);
6662 s
->next
= new_stmt(BPF_ST
);
6678 s
= new_stmt(BPF_ALU
|BPF_NEG
);
6681 s
= new_stmt(BPF_ST
);
6689 gen_arth(code
, a0
, a1
)
6691 struct arth
*a0
, *a1
;
6693 struct slist
*s0
, *s1
, *s2
;
6697 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
6702 sappend(a0
->s
, a1
->s
);
6704 free_reg(a0
->regno
);
6705 free_reg(a1
->regno
);
6707 s0
= new_stmt(BPF_ST
);
6708 a0
->regno
= s0
->s
.k
= alloc_reg();
6715 * Here we handle simple allocation of the scratch registers.
6716 * If too many registers are alloc'd, the allocator punts.
6718 static int regused
[BPF_MEMWORDS
];
6722 * Initialize the table of used registers and the current register.
6728 memset(regused
, 0, sizeof regused
);
6732 * Return the next free register.
6737 int n
= BPF_MEMWORDS
;
6740 if (regused
[curreg
])
6741 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
6743 regused
[curreg
] = 1;
6747 bpf_error("too many registers needed to evaluate expression");
6753 * Return a register to the table so it can
6763 static struct block
*
6770 s
= new_stmt(BPF_LD
|BPF_LEN
);
6771 b
= new_block(JMP(jmp
));
6782 return gen_len(BPF_JGE
, n
);
6786 * Actually, this is less than or equal.
6794 b
= gen_len(BPF_JGT
, n
);
6801 * This is for "byte {idx} {op} {val}"; "idx" is treated as relative to
6802 * the beginning of the link-layer header.
6803 * XXX - that means you can't test values in the radiotap header, but
6804 * as that header is difficult if not impossible to parse generally
6805 * without a loop, that might not be a severe problem. A new keyword
6806 * "radio" could be added for that, although what you'd really want
6807 * would be a way of testing particular radio header values, which
6808 * would generate code appropriate to the radio header in question.
6811 gen_byteop(op
, idx
, val
)
6822 return gen_cmp(OR_LINK
, (u_int
)idx
, BPF_B
, (bpf_int32
)val
);
6825 b
= gen_cmp_lt(OR_LINK
, (u_int
)idx
, BPF_B
, (bpf_int32
)val
);
6829 b
= gen_cmp_gt(OR_LINK
, (u_int
)idx
, BPF_B
, (bpf_int32
)val
);
6833 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
6837 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
6841 b
= new_block(JMP(BPF_JEQ
));
6848 static u_char abroadcast
[] = { 0x0 };
6851 gen_broadcast(proto
)
6854 bpf_u_int32 hostmask
;
6855 struct block
*b0
, *b1
, *b2
;
6856 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
6864 case DLT_ARCNET_LINUX
:
6865 return gen_ahostop(abroadcast
, Q_DST
);
6867 return gen_ehostop(ebroadcast
, Q_DST
);
6869 return gen_fhostop(ebroadcast
, Q_DST
);
6871 return gen_thostop(ebroadcast
, Q_DST
);
6872 case DLT_IEEE802_11
:
6873 case DLT_IEEE802_11_RADIO_AVS
:
6874 case DLT_IEEE802_11_RADIO
:
6876 case DLT_PRISM_HEADER
:
6877 return gen_wlanhostop(ebroadcast
, Q_DST
);
6878 case DLT_IP_OVER_FC
:
6879 return gen_ipfchostop(ebroadcast
, Q_DST
);
6883 * Check that the packet doesn't begin with an
6884 * LE Control marker. (We've already generated
6887 b1
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
,
6892 * Now check the MAC address.
6894 b0
= gen_ehostop(ebroadcast
, Q_DST
);
6900 bpf_error("not a broadcast link");
6905 b0
= gen_linktype(ETHERTYPE_IP
);
6906 hostmask
= ~netmask
;
6907 b1
= gen_mcmp(OR_NET
, 16, BPF_W
, (bpf_int32
)0, hostmask
);
6908 b2
= gen_mcmp(OR_NET
, 16, BPF_W
,
6909 (bpf_int32
)(~0 & hostmask
), hostmask
);
6914 bpf_error("only link-layer/IP broadcast filters supported");
6920 * Generate code to test the low-order bit of a MAC address (that's
6921 * the bottom bit of the *first* byte).
6923 static struct block
*
6924 gen_mac_multicast(offset
)
6927 register struct block
*b0
;
6928 register struct slist
*s
;
6930 /* link[offset] & 1 != 0 */
6931 s
= gen_load_a(OR_LINK
, offset
, BPF_B
);
6932 b0
= new_block(JMP(BPF_JSET
));
6939 gen_multicast(proto
)
6942 register struct block
*b0
, *b1
, *b2
;
6943 register struct slist
*s
;
6951 case DLT_ARCNET_LINUX
:
6952 /* all ARCnet multicasts use the same address */
6953 return gen_ahostop(abroadcast
, Q_DST
);
6955 /* ether[0] & 1 != 0 */
6956 return gen_mac_multicast(0);
6959 * XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX
6961 * XXX - was that referring to bit-order issues?
6963 /* fddi[1] & 1 != 0 */
6964 return gen_mac_multicast(1);
6966 /* tr[2] & 1 != 0 */
6967 return gen_mac_multicast(2);
6968 case DLT_IEEE802_11
:
6969 case DLT_IEEE802_11_RADIO_AVS
:
6971 case DLT_IEEE802_11_RADIO
:
6972 case DLT_PRISM_HEADER
:
6976 * For control frames, there is no DA.
6978 * For management frames, DA is at an
6979 * offset of 4 from the beginning of
6982 * For data frames, DA is at an offset
6983 * of 4 from the beginning of the packet
6984 * if To DS is clear and at an offset of
6985 * 16 from the beginning of the packet
6990 * Generate the tests to be done for data frames.
6992 * First, check for To DS set, i.e. "link[1] & 0x01".
6994 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
6995 b1
= new_block(JMP(BPF_JSET
));
6996 b1
->s
.k
= 0x01; /* To DS */
7000 * If To DS is set, the DA is at 16.
7002 b0
= gen_mac_multicast(16);
7006 * Now, check for To DS not set, i.e. check
7007 * "!(link[1] & 0x01)".
7009 s
= gen_load_a(OR_LINK
, 1, BPF_B
);
7010 b2
= new_block(JMP(BPF_JSET
));
7011 b2
->s
.k
= 0x01; /* To DS */
7016 * If To DS is not set, the DA is at 4.
7018 b1
= gen_mac_multicast(4);
7022 * Now OR together the last two checks. That gives
7023 * the complete set of checks for data frames.
7028 * Now check for a data frame.
7029 * I.e, check "link[0] & 0x08".
7031 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
7032 b1
= new_block(JMP(BPF_JSET
));
7037 * AND that with the checks done for data frames.
7042 * If the high-order bit of the type value is 0, this
7043 * is a management frame.
7044 * I.e, check "!(link[0] & 0x08)".
7046 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
7047 b2
= new_block(JMP(BPF_JSET
));
7053 * For management frames, the DA is at 4.
7055 b1
= gen_mac_multicast(4);
7059 * OR that with the checks done for data frames.
7060 * That gives the checks done for management and
7066 * If the low-order bit of the type value is 1,
7067 * this is either a control frame or a frame
7068 * with a reserved type, and thus not a
7071 * I.e., check "!(link[0] & 0x04)".
7073 s
= gen_load_a(OR_LINK
, 0, BPF_B
);
7074 b1
= new_block(JMP(BPF_JSET
));
7080 * AND that with the checks for data and management
7085 case DLT_IP_OVER_FC
:
7086 b0
= gen_mac_multicast(2);
7091 * Check that the packet doesn't begin with an
7092 * LE Control marker. (We've already generated
7095 b1
= gen_cmp(OR_LINK
, SUNATM_PKT_BEGIN_POS
,
7099 /* ether[off_mac] & 1 != 0 */
7100 b0
= gen_mac_multicast(off_mac
);
7108 /* Link not known to support multicasts */
7112 b0
= gen_linktype(ETHERTYPE_IP
);
7113 b1
= gen_cmp_ge(OR_NET
, 16, BPF_B
, (bpf_int32
)224);
7119 b0
= gen_linktype(ETHERTYPE_IPV6
);
7120 b1
= gen_cmp(OR_NET
, 24, BPF_B
, (bpf_int32
)255);
7125 bpf_error("link-layer multicast filters supported only on ethernet/FDDI/token ring/ARCNET/802.11/ATM LANE/Fibre Channel");
7131 * generate command for inbound/outbound. It's here so we can
7132 * make it link-type specific. 'dir' = 0 implies "inbound",
7133 * = 1 implies "outbound".
7139 register struct block
*b0
;
7142 * Only some data link types support inbound/outbound qualifiers.
7146 b0
= gen_relation(BPF_JEQ
,
7147 gen_load(Q_LINK
, gen_loadi(0), 1),
7155 * Match packets sent by this machine.
7157 b0
= gen_cmp(OR_LINK
, 0, BPF_H
, LINUX_SLL_OUTGOING
);
7160 * Match packets sent to this machine.
7161 * (No broadcast or multicast packets, or
7162 * packets sent to some other machine and
7163 * received promiscuously.)
7165 * XXX - packets sent to other machines probably
7166 * shouldn't be matched, but what about broadcast
7167 * or multicast packets we received?
7169 b0
= gen_cmp(OR_LINK
, 0, BPF_H
, LINUX_SLL_HOST
);
7173 #ifdef HAVE_NET_PFVAR_H
7175 b0
= gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, dir
), BPF_B
,
7176 (bpf_int32
)((dir
== 0) ? PF_IN
: PF_OUT
));
7182 /* match outgoing packets */
7183 b0
= gen_cmp(OR_LINK
, 0, BPF_B
, PPP_PPPD_OUT
);
7185 /* match incoming packets */
7186 b0
= gen_cmp(OR_LINK
, 0, BPF_B
, PPP_PPPD_IN
);
7190 case DLT_JUNIPER_MFR
:
7191 case DLT_JUNIPER_MLFR
:
7192 case DLT_JUNIPER_MLPPP
:
7193 case DLT_JUNIPER_ATM1
:
7194 case DLT_JUNIPER_ATM2
:
7195 case DLT_JUNIPER_PPPOE
:
7196 case DLT_JUNIPER_PPPOE_ATM
:
7197 case DLT_JUNIPER_GGSN
:
7198 case DLT_JUNIPER_ES
:
7199 case DLT_JUNIPER_MONITOR
:
7200 case DLT_JUNIPER_SERVICES
:
7201 case DLT_JUNIPER_ETHER
:
7202 case DLT_JUNIPER_PPP
:
7203 case DLT_JUNIPER_FRELAY
:
7204 case DLT_JUNIPER_CHDLC
:
7205 case DLT_JUNIPER_VP
:
7206 case DLT_JUNIPER_ST
:
7207 case DLT_JUNIPER_ISM
:
7208 /* juniper flags (including direction) are stored
7209 * the byte after the 3-byte magic number */
7211 /* match outgoing packets */
7212 b0
= gen_mcmp(OR_LINK
, 3, BPF_B
, 0, 0x01);
7214 /* match incoming packets */
7215 b0
= gen_mcmp(OR_LINK
, 3, BPF_B
, 1, 0x01);
7220 bpf_error("inbound/outbound not supported on linktype %d",
7228 #ifdef HAVE_NET_PFVAR_H
7229 /* PF firewall log matched interface */
7231 gen_pf_ifname(const char *ifname
)
7236 if (linktype
!= DLT_PFLOG
) {
7237 bpf_error("ifname supported only on PF linktype");
7240 len
= sizeof(((struct pfloghdr
*)0)->ifname
);
7241 off
= offsetof(struct pfloghdr
, ifname
);
7242 if (strlen(ifname
) >= len
) {
7243 bpf_error("ifname interface names can only be %d characters",
7247 b0
= gen_bcmp(OR_LINK
, off
, strlen(ifname
), (const u_char
*)ifname
);
7251 /* PF firewall log ruleset name */
7253 gen_pf_ruleset(char *ruleset
)
7257 if (linktype
!= DLT_PFLOG
) {
7258 bpf_error("ruleset supported only on PF linktype");
7262 if (strlen(ruleset
) >= sizeof(((struct pfloghdr
*)0)->ruleset
)) {
7263 bpf_error("ruleset names can only be %ld characters",
7264 (long)(sizeof(((struct pfloghdr
*)0)->ruleset
) - 1));
7268 b0
= gen_bcmp(OR_LINK
, offsetof(struct pfloghdr
, ruleset
),
7269 strlen(ruleset
), (const u_char
*)ruleset
);
7273 /* PF firewall log rule number */
7279 if (linktype
!= DLT_PFLOG
) {
7280 bpf_error("rnr supported only on PF linktype");
7284 b0
= gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, rulenr
), BPF_W
,
7289 /* PF firewall log sub-rule number */
7291 gen_pf_srnr(int srnr
)
7295 if (linktype
!= DLT_PFLOG
) {
7296 bpf_error("srnr supported only on PF linktype");
7300 b0
= gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, subrulenr
), BPF_W
,
7305 /* PF firewall log reason code */
7307 gen_pf_reason(int reason
)
7311 if (linktype
!= DLT_PFLOG
) {
7312 bpf_error("reason supported only on PF linktype");
7316 b0
= gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, reason
), BPF_B
,
7321 /* PF firewall log action */
7323 gen_pf_action(int action
)
7327 if (linktype
!= DLT_PFLOG
) {
7328 bpf_error("action supported only on PF linktype");
7332 b0
= gen_cmp(OR_LINK
, offsetof(struct pfloghdr
, action
), BPF_B
,
7336 #else /* !HAVE_NET_PFVAR_H */
7338 gen_pf_ifname(const char *ifname
)
7340 bpf_error("libpcap was compiled without pf support");
7346 gen_pf_ruleset(char *ruleset
)
7348 bpf_error("libpcap was compiled on a machine without pf support");
7356 bpf_error("libpcap was compiled on a machine without pf support");
7362 gen_pf_srnr(int srnr
)
7364 bpf_error("libpcap was compiled on a machine without pf support");
7370 gen_pf_reason(int reason
)
7372 bpf_error("libpcap was compiled on a machine without pf support");
7378 gen_pf_action(int action
)
7380 bpf_error("libpcap was compiled on a machine without pf support");
7384 #endif /* HAVE_NET_PFVAR_H */
7386 /* IEEE 802.11 wireless header */
7388 gen_p80211_type(int type
, int mask
)
7394 case DLT_IEEE802_11
:
7395 case DLT_PRISM_HEADER
:
7396 case DLT_IEEE802_11_RADIO_AVS
:
7397 case DLT_IEEE802_11_RADIO
:
7398 b0
= gen_mcmp(OR_LINK
, 0, BPF_B
, (bpf_int32
)type
,
7403 bpf_error("802.11 link-layer types supported only on 802.11");
7411 gen_p80211_fcdir(int fcdir
)
7417 case DLT_IEEE802_11
:
7418 case DLT_IEEE802_11_RADIO_AVS
:
7419 case DLT_IEEE802_11_RADIO
:
7420 case DLT_PRISM_HEADER
:
7424 bpf_error("frame direction supported only with 802.11 headers");
7428 b0
= gen_mcmp(OR_LINK
, 1, BPF_B
, (bpf_int32
)fcdir
,
7429 (bpf_u_int32
)IEEE80211_FC1_DIR_MASK
);
7436 register const u_char
*eaddr
;
7442 case DLT_ARCNET_LINUX
:
7443 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) &&
7445 return (gen_ahostop(eaddr
, (int)q
.dir
));
7447 bpf_error("ARCnet address used in non-arc expression");
7453 bpf_error("aid supported only on ARCnet");
7456 bpf_error("ARCnet address used in non-arc expression");
7461 static struct block
*
7462 gen_ahostop(eaddr
, dir
)
7463 register const u_char
*eaddr
;
7466 register struct block
*b0
, *b1
;
7469 /* src comes first, different from Ethernet */
7471 return gen_bcmp(OR_LINK
, 0, 1, eaddr
);
7474 return gen_bcmp(OR_LINK
, 1, 1, eaddr
);
7477 b0
= gen_ahostop(eaddr
, Q_SRC
);
7478 b1
= gen_ahostop(eaddr
, Q_DST
);
7484 b0
= gen_ahostop(eaddr
, Q_SRC
);
7485 b1
= gen_ahostop(eaddr
, Q_DST
);
7494 * support IEEE 802.1Q VLAN trunk over ethernet
7500 struct block
*b0
, *b1
;
7502 /* can't check for VLAN-encapsulated packets inside MPLS */
7503 if (label_stack_depth
> 0)
7504 bpf_error("no VLAN match after MPLS");
7507 * Check for a VLAN packet, and then change the offsets to point
7508 * to the type and data fields within the VLAN packet. Just
7509 * increment the offsets, so that we can support a hierarchy, e.g.
7510 * "vlan 300 && vlan 200" to capture VLAN 200 encapsulated within
7513 * XXX - this is a bit of a kludge. If we were to split the
7514 * compiler into a parser that parses an expression and
7515 * generates an expression tree, and a code generator that
7516 * takes an expression tree (which could come from our
7517 * parser or from some other parser) and generates BPF code,
7518 * we could perhaps make the offsets parameters of routines
7519 * and, in the handler for an "AND" node, pass to subnodes
7520 * other than the VLAN node the adjusted offsets.
7522 * This would mean that "vlan" would, instead of changing the
7523 * behavior of *all* tests after it, change only the behavior
7524 * of tests ANDed with it. That would change the documented
7525 * semantics of "vlan", which might break some expressions.
7526 * However, it would mean that "(vlan and ip) or ip" would check
7527 * both for VLAN-encapsulated IP and IP-over-Ethernet, rather than
7528 * checking only for VLAN-encapsulated IP, so that could still
7529 * be considered worth doing; it wouldn't break expressions
7530 * that are of the form "vlan and ..." or "vlan N and ...",
7531 * which I suspect are the most common expressions involving
7532 * "vlan". "vlan or ..." doesn't necessarily do what the user
7533 * would really want, now, as all the "or ..." tests would
7534 * be done assuming a VLAN, even though the "or" could be viewed
7535 * as meaning "or, if this isn't a VLAN packet...".
7542 /* check for VLAN */
7543 b0
= gen_cmp(OR_LINK
, off_linktype
, BPF_H
,
7544 (bpf_int32
)ETHERTYPE_8021Q
);
7546 /* If a specific VLAN is requested, check VLAN id */
7547 if (vlan_num
>= 0) {
7548 b1
= gen_mcmp(OR_MACPL
, 0, BPF_H
,
7549 (bpf_int32
)vlan_num
, 0x0fff);
7563 bpf_error("no VLAN support for data link type %d",
7578 struct block
*b0
,*b1
;
7581 * Change the offsets to point to the type and data fields within
7582 * the MPLS packet. Just increment the offsets, so that we
7583 * can support a hierarchy, e.g. "mpls 100000 && mpls 1024" to
7584 * capture packets with an outer label of 100000 and an inner
7587 * XXX - this is a bit of a kludge. See comments in gen_vlan().
7591 if (label_stack_depth
> 0) {
7592 /* just match the bottom-of-stack bit clear */
7593 b0
= gen_mcmp(OR_MACPL
, orig_nl
-2, BPF_B
, 0, 0x01);
7596 * Indicate that we're checking MPLS-encapsulated headers,
7597 * to make sure higher level code generators don't try to
7598 * match against IP-related protocols such as Q_ARP, Q_RARP
7603 case DLT_C_HDLC
: /* fall through */
7605 b0
= gen_linktype(ETHERTYPE_MPLS
);
7609 b0
= gen_linktype(PPP_MPLS_UCAST
);
7612 /* FIXME add other DLT_s ...
7613 * for Frame-Relay/and ATM this may get messy due to SNAP headers
7614 * leave it for now */
7617 bpf_error("no MPLS support for data link type %d",
7625 /* If a specific MPLS label is requested, check it */
7626 if (label_num
>= 0) {
7627 label_num
= label_num
<< 12; /* label is shifted 12 bits on the wire */
7628 b1
= gen_mcmp(OR_MACPL
, orig_nl
, BPF_W
, (bpf_int32
)label_num
,
7629 0xfffff000); /* only compare the first 20 bits */
7636 label_stack_depth
++;
7641 * Support PPPOE discovery and session.
7646 /* check for PPPoE discovery */
7647 return gen_linktype((bpf_int32
)ETHERTYPE_PPPOED
);
7656 * Test against the PPPoE session link-layer type.
7658 b0
= gen_linktype((bpf_int32
)ETHERTYPE_PPPOES
);
7661 * Change the offsets to point to the type and data fields within
7662 * the PPP packet, and note that this is PPPoE rather than
7665 * XXX - this is a bit of a kludge. If we were to split the
7666 * compiler into a parser that parses an expression and
7667 * generates an expression tree, and a code generator that
7668 * takes an expression tree (which could come from our
7669 * parser or from some other parser) and generates BPF code,
7670 * we could perhaps make the offsets parameters of routines
7671 * and, in the handler for an "AND" node, pass to subnodes
7672 * other than the PPPoE node the adjusted offsets.
7674 * This would mean that "pppoes" would, instead of changing the
7675 * behavior of *all* tests after it, change only the behavior
7676 * of tests ANDed with it. That would change the documented
7677 * semantics of "pppoes", which might break some expressions.
7678 * However, it would mean that "(pppoes and ip) or ip" would check
7679 * both for VLAN-encapsulated IP and IP-over-Ethernet, rather than
7680 * checking only for VLAN-encapsulated IP, so that could still
7681 * be considered worth doing; it wouldn't break expressions
7682 * that are of the form "pppoes and ..." which I suspect are the
7683 * most common expressions involving "pppoes". "pppoes or ..."
7684 * doesn't necessarily do what the user would really want, now,
7685 * as all the "or ..." tests would be done assuming PPPoE, even
7686 * though the "or" could be viewed as meaning "or, if this isn't
7687 * a PPPoE packet...".
7689 orig_linktype
= off_linktype
; /* save original values */
7694 * The "network-layer" protocol is PPPoE, which has a 6-byte
7695 * PPPoE header, followed by a PPP packet.
7697 * There is no HDLC encapsulation for the PPP packet (it's
7698 * encapsulated in PPPoES instead), so the link-layer type
7699 * starts at the first byte of the PPP packet. For PPPoE,
7700 * that offset is relative to the beginning of the total
7701 * link-layer payload, including any 802.2 LLC header, so
7702 * it's 6 bytes past off_nl.
7704 off_linktype
= off_nl
+ 6;
7707 * The network-layer offsets are relative to the beginning
7708 * of the MAC-layer payload; that's past the 6-byte
7709 * PPPoE header and the 2-byte PPP header.
7712 off_nl_nosnap
= 6+2;
7718 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
7730 bpf_error("'vpi' supported only on raw ATM");
7731 if (off_vpi
== (u_int
)-1)
7733 b0
= gen_ncmp(OR_LINK
, off_vpi
, BPF_B
, 0xffffffff, jtype
,
7739 bpf_error("'vci' supported only on raw ATM");
7740 if (off_vci
== (u_int
)-1)
7742 b0
= gen_ncmp(OR_LINK
, off_vci
, BPF_H
, 0xffffffff, jtype
,
7747 if (off_proto
== (u_int
)-1)
7748 abort(); /* XXX - this isn't on FreeBSD */
7749 b0
= gen_ncmp(OR_LINK
, off_proto
, BPF_B
, 0x0f, jtype
,
7754 if (off_payload
== (u_int
)-1)
7756 b0
= gen_ncmp(OR_LINK
, off_payload
+ MSG_TYPE_POS
, BPF_B
,
7757 0xffffffff, jtype
, reverse
, jvalue
);
7762 bpf_error("'callref' supported only on raw ATM");
7763 if (off_proto
== (u_int
)-1)
7765 b0
= gen_ncmp(OR_LINK
, off_proto
, BPF_B
, 0xffffffff,
7766 jtype
, reverse
, jvalue
);
7776 gen_atmtype_abbrev(type
)
7779 struct block
*b0
, *b1
;
7784 /* Get all packets in Meta signalling Circuit */
7786 bpf_error("'metac' supported only on raw ATM");
7787 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7788 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
7793 /* Get all packets in Broadcast Circuit*/
7795 bpf_error("'bcc' supported only on raw ATM");
7796 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7797 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
7802 /* Get all cells in Segment OAM F4 circuit*/
7804 bpf_error("'oam4sc' supported only on raw ATM");
7805 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7806 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
7811 /* Get all cells in End-to-End OAM F4 Circuit*/
7813 bpf_error("'oam4ec' supported only on raw ATM");
7814 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7815 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
7820 /* Get all packets in connection Signalling Circuit */
7822 bpf_error("'sc' supported only on raw ATM");
7823 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7824 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
7829 /* Get all packets in ILMI Circuit */
7831 bpf_error("'ilmic' supported only on raw ATM");
7832 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
7833 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
7838 /* Get all LANE packets */
7840 bpf_error("'lane' supported only on raw ATM");
7841 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
7844 * Arrange that all subsequent tests assume LANE
7845 * rather than LLC-encapsulated packets, and set
7846 * the offsets appropriately for LANE-encapsulated
7849 * "off_mac" is the offset of the Ethernet header,
7850 * which is 2 bytes past the ATM pseudo-header
7851 * (skipping the pseudo-header and 2-byte LE Client
7852 * field). The other offsets are Ethernet offsets
7853 * relative to "off_mac".
7856 off_mac
= off_payload
+ 2; /* MAC header */
7857 off_linktype
= off_mac
+ 12;
7858 off_macpl
= off_mac
+ 14; /* Ethernet */
7859 off_nl
= 0; /* Ethernet II */
7860 off_nl_nosnap
= 3; /* 802.3+802.2 */
7864 /* Get all LLC-encapsulated packets */
7866 bpf_error("'llc' supported only on raw ATM");
7867 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
7878 * Filtering for MTP2 messages based on li value
7879 * FISU, length is null
7880 * LSSU, length is 1 or 2
7881 * MSU, length is 3 or more
7884 gen_mtp2type_abbrev(type
)
7887 struct block
*b0
, *b1
;
7892 if ( (linktype
!= DLT_MTP2
) &&
7893 (linktype
!= DLT_ERF
) &&
7894 (linktype
!= DLT_MTP2_WITH_PHDR
) )
7895 bpf_error("'fisu' supported only on MTP2");
7896 /* gen_ncmp(offrel, offset, size, mask, jtype, reverse, value) */
7897 b0
= gen_ncmp(OR_PACKET
, off_li
, BPF_B
, 0x3f, BPF_JEQ
, 0, 0);
7901 if ( (linktype
!= DLT_MTP2
) &&
7902 (linktype
!= DLT_ERF
) &&
7903 (linktype
!= DLT_MTP2_WITH_PHDR
) )
7904 bpf_error("'lssu' supported only on MTP2");
7905 b0
= gen_ncmp(OR_PACKET
, off_li
, BPF_B
, 0x3f, BPF_JGT
, 1, 2);
7906 b1
= gen_ncmp(OR_PACKET
, off_li
, BPF_B
, 0x3f, BPF_JGT
, 0, 0);
7911 if ( (linktype
!= DLT_MTP2
) &&
7912 (linktype
!= DLT_ERF
) &&
7913 (linktype
!= DLT_MTP2_WITH_PHDR
) )
7914 bpf_error("'msu' supported only on MTP2");
7915 b0
= gen_ncmp(OR_PACKET
, off_li
, BPF_B
, 0x3f, BPF_JGT
, 0, 2);
7925 gen_mtp3field_code(mtp3field
, jvalue
, jtype
, reverse
)
7932 bpf_u_int32 val1
, val2
, val3
;
7934 switch (mtp3field
) {
7937 if (off_sio
== (u_int
)-1)
7938 bpf_error("'sio' supported only on SS7");
7939 /* sio coded on 1 byte so max value 255 */
7941 bpf_error("sio value %u too big; max value = 255",
7943 b0
= gen_ncmp(OR_PACKET
, off_sio
, BPF_B
, 0xffffffff,
7944 (u_int
)jtype
, reverse
, (u_int
)jvalue
);
7948 if (off_opc
== (u_int
)-1)
7949 bpf_error("'opc' supported only on SS7");
7950 /* opc coded on 14 bits so max value 16383 */
7952 bpf_error("opc value %u too big; max value = 16383",
7954 /* the following instructions are made to convert jvalue
7955 * to the form used to write opc in an ss7 message*/
7956 val1
= jvalue
& 0x00003c00;
7958 val2
= jvalue
& 0x000003fc;
7960 val3
= jvalue
& 0x00000003;
7962 jvalue
= val1
+ val2
+ val3
;
7963 b0
= gen_ncmp(OR_PACKET
, off_opc
, BPF_W
, 0x00c0ff0f,
7964 (u_int
)jtype
, reverse
, (u_int
)jvalue
);
7968 if (off_dpc
== (u_int
)-1)
7969 bpf_error("'dpc' supported only on SS7");
7970 /* dpc coded on 14 bits so max value 16383 */
7972 bpf_error("dpc value %u too big; max value = 16383",
7974 /* the following instructions are made to convert jvalue
7975 * to the forme used to write dpc in an ss7 message*/
7976 val1
= jvalue
& 0x000000ff;
7978 val2
= jvalue
& 0x00003f00;
7980 jvalue
= val1
+ val2
;
7981 b0
= gen_ncmp(OR_PACKET
, off_dpc
, BPF_W
, 0xff3f0000,
7982 (u_int
)jtype
, reverse
, (u_int
)jvalue
);
7986 if (off_sls
== (u_int
)-1)
7987 bpf_error("'sls' supported only on SS7");
7988 /* sls coded on 4 bits so max value 15 */
7990 bpf_error("sls value %u too big; max value = 15",
7992 /* the following instruction is made to convert jvalue
7993 * to the forme used to write sls in an ss7 message*/
7994 jvalue
= jvalue
<< 4;
7995 b0
= gen_ncmp(OR_PACKET
, off_sls
, BPF_B
, 0xf0,
7996 (u_int
)jtype
,reverse
, (u_int
)jvalue
);
8005 static struct block
*
8006 gen_msg_abbrev(type
)
8012 * Q.2931 signalling protocol messages for handling virtual circuits
8013 * establishment and teardown
8018 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
8022 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
8026 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
8030 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
8034 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
8037 case A_RELEASE_DONE
:
8038 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
8048 gen_atmmulti_abbrev(type
)
8051 struct block
*b0
, *b1
;
8057 bpf_error("'oam' supported only on raw ATM");
8058 b1
= gen_atmmulti_abbrev(A_OAMF4
);
8063 bpf_error("'oamf4' supported only on raw ATM");
8065 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
8066 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
8068 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
8074 * Get Q.2931 signalling messages for switched
8075 * virtual connection
8078 bpf_error("'connectmsg' supported only on raw ATM");
8079 b0
= gen_msg_abbrev(A_SETUP
);
8080 b1
= gen_msg_abbrev(A_CALLPROCEED
);
8082 b0
= gen_msg_abbrev(A_CONNECT
);
8084 b0
= gen_msg_abbrev(A_CONNECTACK
);
8086 b0
= gen_msg_abbrev(A_RELEASE
);
8088 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
8090 b0
= gen_atmtype_abbrev(A_SC
);
8096 bpf_error("'metaconnect' supported only on raw ATM");
8097 b0
= gen_msg_abbrev(A_SETUP
);
8098 b1
= gen_msg_abbrev(A_CALLPROCEED
);
8100 b0
= gen_msg_abbrev(A_CONNECT
);
8102 b0
= gen_msg_abbrev(A_RELEASE
);
8104 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
8106 b0
= gen_atmtype_abbrev(A_METAC
);