]>
The Tcpdump Group git mirrors - libpcap/blob - gencode.c
60fb3276fb138827ae988be64e02c66451fcb49b
1 /*#define CHASE_CHAIN*/
3 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] =
24 "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.172 2002-08-02 05:53:53 guy Exp $ (LBL)";
32 #include <pcap-stdinc.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
40 * XXX - why was this included even on UNIX?
49 #include <sys/param.h>
52 struct mbuf
; /* Squelch compiler warnings on some platforms for */
53 struct rtentry
; /* declarations in <net/if.h> */
56 #include <netinet/in.h>
68 #include "ethertype.h"
73 #include "sunatmpos.h"
79 #include <netdb.h> /* for "struct addrinfo" */
82 #include <pcap-namedb.h>
87 #define IPPROTO_SCTP 132
90 #ifdef HAVE_OS_PROTO_H
94 #define JMP(c) ((c)|BPF_JMP|BPF_K)
97 static jmp_buf top_ctx
;
98 static pcap_t
*bpf_pcap
;
100 /* Hack for updating VLAN offsets. */
101 static u_int orig_linktype
= -1, orig_nl
= -1, orig_nl_nosnap
= -1;
105 int pcap_fddipad
= PCAP_FDDIPAD
;
112 bpf_error(const char *fmt
, ...)
118 if (bpf_pcap
!= NULL
)
119 (void)vsnprintf(pcap_geterr(bpf_pcap
), PCAP_ERRBUF_SIZE
,
126 static void init_linktype(int);
128 static int alloc_reg(void);
129 static void free_reg(int);
131 static struct block
*root
;
134 * We divy out chunks of memory rather than call malloc each time so
135 * we don't have to worry about leaking memory. It's probably
136 * not a big deal if all this memory was wasted but it this ever
137 * goes into a library that would probably not be a good idea.
140 #define CHUNK0SIZE 1024
146 static struct chunk chunks
[NCHUNKS
];
147 static int cur_chunk
;
149 static void *newchunk(u_int
);
150 static void freechunks(void);
151 static inline struct block
*new_block(int);
152 static inline struct slist
*new_stmt(int);
153 static struct block
*gen_retblk(int);
154 static inline void syntax(void);
156 static void backpatch(struct block
*, struct block
*);
157 static void merge(struct block
*, struct block
*);
158 static struct block
*gen_cmp(u_int
, u_int
, bpf_int32
);
159 static struct block
*gen_cmp_gt(u_int
, u_int
, bpf_int32
);
160 static struct block
*gen_mcmp(u_int
, u_int
, bpf_int32
, bpf_u_int32
);
161 static struct block
*gen_bcmp(u_int
, u_int
, const u_char
*);
162 static struct block
*gen_ncmp(bpf_u_int32
, bpf_u_int32
, bpf_u_int32
,
163 bpf_u_int32
, bpf_u_int32
, int);
164 static struct block
*gen_uncond(int);
165 static inline struct block
*gen_true(void);
166 static inline struct block
*gen_false(void);
167 static struct block
*gen_linktype(int);
168 static struct block
*gen_snap(bpf_u_int32
, bpf_u_int32
, u_int
);
169 static struct block
*gen_llc(int);
170 static struct block
*gen_hostop(bpf_u_int32
, bpf_u_int32
, int, int, u_int
, u_int
);
172 static struct block
*gen_hostop6(struct in6_addr
*, struct in6_addr
*, int, int, u_int
, u_int
);
174 static struct block
*gen_ahostop(const u_char
*, int);
175 static struct block
*gen_ehostop(const u_char
*, int);
176 static struct block
*gen_fhostop(const u_char
*, int);
177 static struct block
*gen_thostop(const u_char
*, int);
178 static struct block
*gen_dnhostop(bpf_u_int32
, int, u_int
);
179 static struct block
*gen_host(bpf_u_int32
, bpf_u_int32
, int, int);
181 static struct block
*gen_host6(struct in6_addr
*, struct in6_addr
*, int, int);
184 static struct block
*gen_gateway(const u_char
*, bpf_u_int32
**, int, int);
186 static struct block
*gen_ipfrag(void);
187 static struct block
*gen_portatom(int, bpf_int32
);
189 static struct block
*gen_portatom6(int, bpf_int32
);
191 struct block
*gen_portop(int, int, int);
192 static struct block
*gen_port(int, int, int);
194 struct block
*gen_portop6(int, int, int);
195 static struct block
*gen_port6(int, int, int);
197 static int lookup_proto(const char *, int);
198 static struct block
*gen_protochain(int, int, int);
199 static struct block
*gen_proto(int, int, int);
200 static struct slist
*xfer_to_x(struct arth
*);
201 static struct slist
*xfer_to_a(struct arth
*);
202 static struct block
*gen_len(int, int);
204 static struct block
*gen_msg_abbrev(int type
);
214 /* XXX Round up to nearest long. */
215 n
= (n
+ sizeof(long) - 1) & ~(sizeof(long) - 1);
217 /* XXX Round up to structure boundary. */
221 cp
= &chunks
[cur_chunk
];
222 if (n
> cp
->n_left
) {
223 ++cp
, k
= ++cur_chunk
;
225 bpf_error("out of memory");
226 size
= CHUNK0SIZE
<< k
;
227 cp
->m
= (void *)malloc(size
);
228 memset((char *)cp
->m
, 0, size
);
231 bpf_error("out of memory");
234 return (void *)((char *)cp
->m
+ cp
->n_left
);
243 for (i
= 0; i
< NCHUNKS
; ++i
)
244 if (chunks
[i
].m
!= NULL
) {
251 * A strdup whose allocations are freed after code generation is over.
255 register const char *s
;
257 int n
= strlen(s
) + 1;
258 char *cp
= newchunk(n
);
264 static inline struct block
*
270 p
= (struct block
*)newchunk(sizeof(*p
));
277 static inline struct slist
*
283 p
= (struct slist
*)newchunk(sizeof(*p
));
289 static struct block
*
293 struct block
*b
= new_block(BPF_RET
|BPF_K
);
302 bpf_error("syntax error in filter expression");
305 static bpf_u_int32 netmask
;
310 pcap_compile(pcap_t
*p
, struct bpf_program
*program
,
311 char *buf
, int optimize
, bpf_u_int32 mask
)
320 if (setjmp(top_ctx
)) {
328 snaplen
= pcap_snapshot(p
);
330 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
331 "snaplen of 0 rejects all packets");
335 lex_init(buf
? buf
: "");
336 init_linktype(pcap_datalink(p
));
343 root
= gen_retblk(snaplen
);
345 if (optimize
&& !no_optimize
) {
348 (root
->s
.code
== (BPF_RET
|BPF_K
) && root
->s
.k
== 0))
349 bpf_error("expression rejects all packets");
351 program
->bf_insns
= icode_to_fcode(root
, &len
);
352 program
->bf_len
= len
;
360 * entry point for using the compiler with no pcap open
361 * pass in all the stuff that is needed explicitly instead.
364 pcap_compile_nopcap(int snaplen_arg
, int linktype_arg
,
365 struct bpf_program
*program
,
366 char *buf
, int optimize
, bpf_u_int32 mask
)
371 p
= pcap_open_dead(linktype_arg
, snaplen_arg
);
374 ret
= pcap_compile(p
, program
, buf
, optimize
, mask
);
380 * Clean up a "struct bpf_program" by freeing all the memory allocated
384 pcap_freecode(struct bpf_program
*program
)
387 if (program
->bf_insns
!= NULL
) {
388 free((char *)program
->bf_insns
);
389 program
->bf_insns
= NULL
;
394 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
395 * which of the jt and jf fields has been resolved and which is a pointer
396 * back to another unresolved block (or nil). At least one of the fields
397 * in each block is already resolved.
400 backpatch(list
, target
)
401 struct block
*list
, *target
;
418 * Merge the lists in b0 and b1, using the 'sense' field to indicate
419 * which of jt and jf is the link.
423 struct block
*b0
, *b1
;
425 register struct block
**p
= &b0
;
427 /* Find end of list. */
429 p
= !((*p
)->sense
) ? &JT(*p
) : &JF(*p
);
431 /* Concatenate the lists. */
439 backpatch(p
, gen_retblk(snaplen
));
440 p
->sense
= !p
->sense
;
441 backpatch(p
, gen_retblk(0));
447 struct block
*b0
, *b1
;
449 backpatch(b0
, b1
->head
);
450 b0
->sense
= !b0
->sense
;
451 b1
->sense
= !b1
->sense
;
453 b1
->sense
= !b1
->sense
;
459 struct block
*b0
, *b1
;
461 b0
->sense
= !b0
->sense
;
462 backpatch(b0
, b1
->head
);
463 b0
->sense
= !b0
->sense
;
472 b
->sense
= !b
->sense
;
475 static struct block
*
476 gen_cmp(offset
, size
, v
)
483 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
486 b
= new_block(JMP(BPF_JEQ
));
493 static struct block
*
494 gen_cmp_gt(offset
, size
, v
)
501 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
504 b
= new_block(JMP(BPF_JGT
));
511 static struct block
*
512 gen_mcmp(offset
, size
, v
, mask
)
517 struct block
*b
= gen_cmp(offset
, size
, v
);
520 if (mask
!= 0xffffffff) {
521 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
528 static struct block
*
529 gen_bcmp(offset
, size
, v
)
530 register u_int offset
, size
;
531 register const u_char
*v
;
533 register struct block
*b
, *tmp
;
537 register const u_char
*p
= &v
[size
- 4];
538 bpf_int32 w
= ((bpf_int32
)p
[0] << 24) |
539 ((bpf_int32
)p
[1] << 16) | ((bpf_int32
)p
[2] << 8) | p
[3];
541 tmp
= gen_cmp(offset
+ size
- 4, BPF_W
, w
);
548 register const u_char
*p
= &v
[size
- 2];
549 bpf_int32 w
= ((bpf_int32
)p
[0] << 8) | p
[1];
551 tmp
= gen_cmp(offset
+ size
- 2, BPF_H
, w
);
558 tmp
= gen_cmp(offset
, BPF_B
, (bpf_int32
)v
[0]);
566 static struct block
*
567 gen_ncmp(datasize
, offset
, mask
, jtype
, jvalue
, reverse
)
568 bpf_u_int32 datasize
, offset
, mask
, jtype
, jvalue
;
574 s
= new_stmt(BPF_LD
|datasize
|BPF_ABS
);
577 if (mask
!= 0xffffffff) {
578 s
->next
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
582 b
= new_block(JMP(jtype
));
585 if (reverse
&& (jtype
== BPF_JGT
|| jtype
== BPF_JGE
))
591 * Various code constructs need to know the layout of the data link
592 * layer. These variables give the necessary offsets.
596 * "off_linktype" is the offset to information in the link-layer header
597 * giving the packet type.
599 * For Ethernet, it's the offset of the Ethernet type field.
601 * For link-layer types that always use 802.2 headers, it's the
602 * offset of the LLC header.
604 * For PPP, it's the offset of the PPP type field.
606 * For Cisco HDLC, it's the offset of the CHDLC type field.
608 * For BSD loopback, it's the offset of the AF_ value.
610 * For Linux cooked sockets, it's the offset of the type field.
612 * It's set to -1 for no encapsulation, in which case, IP is assumed.
614 static u_int off_linktype
;
617 * TRUE if the link layer includes an ATM pseudo-header.
619 static int is_atm
= 0;
622 * These are offsets for the ATM pseudo-header.
624 static u_int off_vpi
;
625 static u_int off_vci
;
626 static u_int off_proto
;
629 * This is the offset to the message type for Q.2931 messages.
631 static u_int off_msg_type
;
634 * These are offsets to the beginning of the network-layer header.
636 * If the link layer never uses 802.2 LLC:
638 * "off_nl" and "off_nl_nosnap" are the same.
640 * If the link layer always uses 802.2 LLC:
642 * "off_nl" is the offset if there's a SNAP header following
645 * "off_nl_nosnap" is the offset if there's no SNAP header.
647 * If the link layer is Ethernet:
649 * "off_nl" is the offset if the packet is an Ethernet II packet
650 * (we assume no 802.3+802.2+SNAP);
652 * "off_nl_nosnap" is the offset if the packet is an 802.3 packet
653 * with an 802.2 header following it.
656 static u_int off_nl_nosnap
;
667 * Assume it's not raw ATM with a pseudo-header, for now.
683 off_nl
= 6; /* XXX in reality, variable! */
684 off_nl_nosnap
= 6; /* no 802.2 LLC */
689 off_nl
= 14; /* Ethernet II */
690 off_nl_nosnap
= 17; /* 802.3+802.2 */
695 * SLIP doesn't have a link level type. The 16 byte
696 * header is hacked into our SLIP driver.
700 off_nl_nosnap
= 16; /* no 802.2 LLC */
704 /* XXX this may be the same as the DLT_PPP_BSDOS case */
708 off_nl_nosnap
= 24; /* no 802.2 LLC */
715 off_nl_nosnap
= 4; /* no 802.2 LLC */
719 case DLT_C_HDLC
: /* BSD/OS Cisco HDLC */
720 case DLT_PPP_SERIAL
: /* NetBSD sync/async serial PPP */
723 off_nl_nosnap
= 4; /* no 802.2 LLC */
728 * This does no include the Ethernet header, and
729 * only covers session state.
733 off_nl_nosnap
= 8; /* no 802.2 LLC */
739 off_nl_nosnap
= 24; /* no 802.2 LLC */
744 * FDDI doesn't really have a link-level type field.
745 * We set "off_linktype" to the offset of the LLC header.
747 * To check for Ethernet types, we assume that SSAP = SNAP
748 * is being used and pick out the encapsulated Ethernet type.
749 * XXX - should we generate code to check for SNAP?
753 off_linktype
+= pcap_fddipad
;
755 off_nl
= 21; /* FDDI+802.2+SNAP */
756 off_nl_nosnap
= 16; /* FDDI+802.2 */
758 off_nl
+= pcap_fddipad
;
759 off_nl_nosnap
+= pcap_fddipad
;
765 * Token Ring doesn't really have a link-level type field.
766 * We set "off_linktype" to the offset of the LLC header.
768 * To check for Ethernet types, we assume that SSAP = SNAP
769 * is being used and pick out the encapsulated Ethernet type.
770 * XXX - should we generate code to check for SNAP?
772 * XXX - the header is actually variable-length.
773 * Some various Linux patched versions gave 38
774 * as "off_linktype" and 40 as "off_nl"; however,
775 * if a token ring packet has *no* routing
776 * information, i.e. is not source-routed, the correct
777 * values are 20 and 22, as they are in the vanilla code.
779 * A packet is source-routed iff the uppermost bit
780 * of the first byte of the source address, at an
781 * offset of 8, has the uppermost bit set. If the
782 * packet is source-routed, the total number of bytes
783 * of routing information is 2 plus bits 0x1F00 of
784 * the 16-bit value at an offset of 14 (shifted right
785 * 8 - figure out which byte that is).
788 off_nl
= 22; /* Token Ring+802.2+SNAP */
789 off_nl_nosnap
= 17; /* Token Ring+802.2 */
794 * 802.11 doesn't really have a link-level type field.
795 * We set "off_linktype" to the offset of the LLC header.
797 * To check for Ethernet types, we assume that SSAP = SNAP
798 * is being used and pick out the encapsulated Ethernet type.
799 * XXX - should we generate code to check for SNAP?
801 * XXX - the header is actually variable-length. We
802 * assume a 24-byte link-layer header, as appears in
803 * data frames in networks with no bridges.
806 off_nl
= 32; /* 802.11+802.2+SNAP */
807 off_nl_nosnap
= 27; /* 802.22+802.2 */
810 case DLT_PRISM_HEADER
:
812 * Same as 802.11, but with an additional header before
813 * the 802.11 header, containing a bunch of additional
814 * information including radio-level information.
816 * The header is 144 bytes long.
818 * XXX - same variable-length header problem; at least
819 * the Prism header is fixed-length.
821 off_linktype
= 144+24;
822 off_nl
= 144+32; /* Prism+802.11+802.2+SNAP */
823 off_nl_nosnap
= 144+27; /* Prism+802.11+802.2 */
826 case DLT_ATM_RFC1483
:
827 case DLT_ATM_CLIP
: /* Linux ATM defines this */
829 * assume routed, non-ISO PDUs
830 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
833 off_nl
= 8; /* 802.2+SNAP */
834 off_nl_nosnap
= 3; /* 802.2 */
839 * Full Frontal ATM; you get AALn PDUs with an ATM
843 off_linktype
= SUNATM_PKT_BEGIN_POS
;
844 off_vpi
= SUNATM_VPI_POS
;
845 off_vci
= SUNATM_VCI_POS
;
846 off_proto
= PROTO_POS
;
847 off_msg_type
= SUNATM_PKT_BEGIN_POS
+MSG_TYPE_POS
;
848 off_nl
= SUNATM_PKT_BEGIN_POS
+8; /* 802.2+SNAP */
849 off_nl_nosnap
= SUNATM_PKT_BEGIN_POS
+3; /* 802.2 */
855 off_nl_nosnap
= 0; /* no 802.2 LLC */
858 case DLT_LINUX_SLL
: /* fake header for Linux cooked socket */
861 off_nl_nosnap
= 16; /* no 802.2 LLC */
866 * LocalTalk does have a 1-byte type field in the LLAP header,
867 * but really it just indicates whether there is a "short" or
868 * "long" DDP packet following.
872 off_nl_nosnap
= 0; /* no 802.2 LLC */
877 * XXX - we should set this to handle SNAP-encapsulated
878 * frames (NLPID of 0x80).
882 off_nl_nosnap
= 0; /* no 802.2 LLC */
885 bpf_error("unknown data link type %d", linktype
);
889 static struct block
*
896 s
= new_stmt(BPF_LD
|BPF_IMM
);
898 b
= new_block(JMP(BPF_JEQ
));
904 static inline struct block
*
907 return gen_uncond(1);
910 static inline struct block
*
913 return gen_uncond(0);
917 * Byte-swap a 32-bit number.
918 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
919 * big-endian platforms.)
921 #define SWAPLONG(y) \
922 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
924 static struct block
*
928 struct block
*b0
, *b1
, *b2
;
937 * OSI protocols always use 802.2 encapsulation.
938 * XXX - should we check both the DSAP and the
939 * SSAP, like this, or should we check just the
942 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
944 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
945 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
951 * NetBEUI always uses 802.2 encapsulation.
952 * XXX - should we check both the DSAP and the
953 * SSAP, like this, or should we check just the
956 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
958 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
959 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
967 * Ethernet_II frames, which are Ethernet
968 * frames with a frame type of ETHERTYPE_IPX;
970 * Ethernet_802.3 frames, which are 802.3
971 * frames (i.e., the type/length field is
972 * a length field, <= ETHERMTU, rather than
973 * a type field) with the first two bytes
974 * after the Ethernet/802.3 header being
977 * Ethernet_802.2 frames, which are 802.3
978 * frames with an 802.2 LLC header and
979 * with the IPX LSAP as the DSAP in the LLC
982 * Ethernet_SNAP frames, which are 802.3
983 * frames with an LLC header and a SNAP
984 * header and with an OUI of 0x000000
985 * (encapsulated Ethernet) and a protocol
986 * ID of ETHERTYPE_IPX in the SNAP header.
988 * XXX - should we generate the same code both
989 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
993 * This generates code to check both for the
994 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
996 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
997 (bpf_int32
)LLCSAP_IPX
);
998 b1
= gen_cmp(off_linktype
+ 2, BPF_H
,
1003 * Now we add code to check for SNAP frames with
1004 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1006 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1010 * Now we generate code to check for 802.3
1011 * frames in general.
1013 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1017 * Now add the check for 802.3 frames before the
1018 * check for Ethernet_802.2 and Ethernet_802.3,
1019 * as those checks should only be done on 802.3
1020 * frames, not on Ethernet frames.
1025 * Now add the check for Ethernet_II frames, and
1026 * do that before checking for the other frame
1029 b0
= gen_cmp(off_linktype
, BPF_H
,
1030 (bpf_int32
)ETHERTYPE_IPX
);
1034 case ETHERTYPE_ATALK
:
1035 case ETHERTYPE_AARP
:
1037 * EtherTalk (AppleTalk protocols on Ethernet link
1038 * layer) may use 802.2 encapsulation.
1042 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1043 * we check for an Ethernet type field less than
1044 * 1500, which means it's an 802.3 length field.
1046 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1050 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1051 * SNAP packets with an organization code of
1052 * 0x080007 (Apple, for Appletalk) and a protocol
1053 * type of ETHERTYPE_ATALK (Appletalk).
1055 * 802.2-encapsulated ETHERTYPE_AARP packets are
1056 * SNAP packets with an organization code of
1057 * 0x000000 (encapsulated Ethernet) and a protocol
1058 * type of ETHERTYPE_AARP (Appletalk ARP).
1060 if (proto
== ETHERTYPE_ATALK
)
1061 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1062 else /* proto == ETHERTYPE_AARP */
1063 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1067 * Check for Ethernet encapsulation (Ethertalk
1068 * phase 1?); we just check for the Ethernet
1071 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1077 if (proto
<= ETHERMTU
) {
1079 * This is an LLC SAP value, so the frames
1080 * that match would be 802.2 frames.
1081 * Check that the frame is an 802.2 frame
1082 * (i.e., that the length/type field is
1083 * a length field, <= ETHERMTU) and
1084 * then check the DSAP.
1086 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1088 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1094 * This is an Ethernet type, so compare
1095 * the length/type field with it (if
1096 * the frame is an 802.2 frame, the length
1097 * field will be <= ETHERMTU, and, as
1098 * "proto" is > ETHERMTU, this test
1099 * will fail and the frame won't match,
1100 * which is what we want).
1102 return gen_cmp(off_linktype
, BPF_H
,
1108 case DLT_IEEE802_11
:
1109 case DLT_PRISM_HEADER
:
1112 case DLT_ATM_RFC1483
:
1114 return gen_llc(proto
);
1119 * Check for LLC encapsulation and then check the protocol.
1120 * XXX - also check for LANE and then check for an Ethernet
1123 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1124 b1
= gen_llc(proto
);
1133 * OSI protocols always use 802.2 encapsulation.
1134 * XXX - should we check both the DSAP and the
1135 * LSAP, like this, or should we check just the
1138 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1139 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1140 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1144 case LLCSAP_NETBEUI
:
1146 * NetBEUI always uses 802.2 encapsulation.
1147 * XXX - should we check both the DSAP and the
1148 * LSAP, like this, or should we check just the
1151 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1152 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1153 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1159 * Ethernet_II frames, which are Ethernet
1160 * frames with a frame type of ETHERTYPE_IPX;
1162 * Ethernet_802.3 frames, which have a frame
1163 * type of LINUX_SLL_P_802_3;
1165 * Ethernet_802.2 frames, which are 802.3
1166 * frames with an 802.2 LLC header (i.e, have
1167 * a frame type of LINUX_SLL_P_802_2) and
1168 * with the IPX LSAP as the DSAP in the LLC
1171 * Ethernet_SNAP frames, which are 802.3
1172 * frames with an LLC header and a SNAP
1173 * header and with an OUI of 0x000000
1174 * (encapsulated Ethernet) and a protocol
1175 * ID of ETHERTYPE_IPX in the SNAP header.
1177 * First, do the checks on LINUX_SLL_P_802_2
1178 * frames; generate the check for either
1179 * Ethernet_802.2 or Ethernet_SNAP frames, and
1180 * then put a check for LINUX_SLL_P_802_2 frames
1183 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1184 (bpf_int32
)LLCSAP_IPX
);
1185 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1188 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1192 * Now check for 802.3 frames and OR that with
1193 * the previous test.
1195 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1199 * Now add the check for Ethernet_II frames, and
1200 * do that before checking for the other frame
1203 b0
= gen_cmp(off_linktype
, BPF_H
,
1204 (bpf_int32
)ETHERTYPE_IPX
);
1208 case ETHERTYPE_ATALK
:
1209 case ETHERTYPE_AARP
:
1211 * EtherTalk (AppleTalk protocols on Ethernet link
1212 * layer) may use 802.2 encapsulation.
1216 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1217 * we check for the 802.2 protocol type in the
1218 * "Ethernet type" field.
1220 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1223 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1224 * SNAP packets with an organization code of
1225 * 0x080007 (Apple, for Appletalk) and a protocol
1226 * type of ETHERTYPE_ATALK (Appletalk).
1228 * 802.2-encapsulated ETHERTYPE_AARP packets are
1229 * SNAP packets with an organization code of
1230 * 0x000000 (encapsulated Ethernet) and a protocol
1231 * type of ETHERTYPE_AARP (Appletalk ARP).
1233 if (proto
== ETHERTYPE_ATALK
)
1234 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1236 else /* proto == ETHERTYPE_AARP */
1237 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1242 * Check for Ethernet encapsulation (Ethertalk
1243 * phase 1?); we just check for the Ethernet
1246 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1252 if (proto
<= ETHERMTU
) {
1254 * This is an LLC SAP value, so the frames
1255 * that match would be 802.2 frames.
1256 * Check for the 802.2 protocol type
1257 * in the "Ethernet type" field, and
1258 * then check the DSAP.
1260 b0
= gen_cmp(off_linktype
, BPF_H
,
1262 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1268 * This is an Ethernet type, so compare
1269 * the length/type field with it (if
1270 * the frame is an 802.2 frame, the length
1271 * field will be <= ETHERMTU, and, as
1272 * "proto" is > ETHERMTU, this test
1273 * will fail and the frame won't match,
1274 * which is what we want).
1276 return gen_cmp(off_linktype
, BPF_H
,
1283 case DLT_SLIP_BSDOS
:
1286 * These types don't provide any type field; packets
1289 * XXX - for IPv4, check for a version number of 4, and,
1290 * for IPv6, check for a version number of 6?
1296 case ETHERTYPE_IPV6
:
1298 return gen_true(); /* always true */
1301 return gen_false(); /* always false */
1306 case DLT_PPP_SERIAL
:
1309 * We use Ethernet protocol types inside libpcap;
1310 * map them to the corresponding PPP protocol types.
1315 proto
= PPP_IP
; /* XXX was 0x21 */
1319 case ETHERTYPE_IPV6
:
1328 case ETHERTYPE_ATALK
:
1342 * I'm assuming the "Bridging PDU"s that go
1343 * over PPP are Spanning Tree Protocol
1357 * We use Ethernet protocol types inside libpcap;
1358 * map them to the corresponding PPP protocol types.
1363 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1364 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1366 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1371 case ETHERTYPE_IPV6
:
1381 case ETHERTYPE_ATALK
:
1395 * I'm assuming the "Bridging PDU"s that go
1396 * over PPP are Spanning Tree Protocol
1411 * For DLT_NULL, the link-layer header is a 32-bit
1412 * word containing an AF_ value in *host* byte order.
1414 * In addition, if we're reading a saved capture file,
1415 * the host byte order in the capture may not be the
1416 * same as the host byte order on this machine.
1418 * For DLT_LOOP, the link-layer header is a 32-bit
1419 * word containing an AF_ value in *network* byte order.
1421 * XXX - AF_ values may, unfortunately, be platform-
1422 * dependent; for example, FreeBSD's AF_INET6 is 24
1423 * whilst NetBSD's and OpenBSD's is 26.
1425 * This means that, when reading a capture file, just
1426 * checking for our AF_INET6 value won't work if the
1427 * capture file came from another OS.
1436 case ETHERTYPE_IPV6
:
1443 * Not a type on which we support filtering.
1444 * XXX - support those that have AF_ values
1445 * #defined on this platform, at least?
1450 if (linktype
== DLT_NULL
) {
1452 * The AF_ value is in host byte order, but
1453 * the BPF interpreter will convert it to
1454 * network byte order.
1456 * If this is a save file, and it's from a
1457 * machine with the opposite byte order to
1458 * ours, we byte-swap the AF_ value.
1460 * Then we run it through "htonl()", and
1461 * generate code to compare against the result.
1463 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1464 bpf_pcap
->sf
.swapped
)
1465 proto
= SWAPLONG(proto
);
1466 proto
= htonl(proto
);
1468 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1472 * XXX should we check for first fragment if the protocol
1479 case ETHERTYPE_IPV6
:
1480 return(gen_cmp(2, BPF_B
,
1481 (bpf_int32
)htonl(ARCTYPE_INET6
)));
1484 b0
= gen_cmp(2, BPF_B
, (bpf_int32
)htonl(ARCTYPE_IP
));
1485 b1
= gen_cmp(2, BPF_B
,
1486 (bpf_int32
)htonl(ARCTYPE_IP_OLD
));
1490 b0
= gen_cmp(2, BPF_B
, (bpf_int32
)htonl(ARCTYPE_ARP
));
1491 b1
= gen_cmp(2, BPF_B
,
1492 (bpf_int32
)htonl(ARCTYPE_ARP_OLD
));
1495 case ETHERTYPE_REVARP
:
1496 return(gen_cmp(2, BPF_B
,
1497 (bpf_int32
)htonl(ARCTYPE_REVARP
)));
1498 case ETHERTYPE_ATALK
:
1499 return(gen_cmp(2, BPF_B
,
1500 (bpf_int32
)htonl(ARCTYPE_ATALK
)));
1506 case ETHERTYPE_ATALK
:
1515 * XXX - assumes a 2-byte Frame Relay header with
1516 * DLCI and flags. What if the address is longer?
1522 * Check for the special NLPID for IP.
1524 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1527 case ETHERTYPE_IPV6
:
1529 * Check for the special NLPID for IPv6.
1531 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1536 * Check for several OSI protocols.
1538 * Frame Relay packets typically have an OSI
1539 * NLPID at the beginning; we check for each
1542 * What we check for is the NLPID and a frame
1543 * control field of UI, i.e. 0x03 followed
1546 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1547 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1548 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1560 * All the types that have no encapsulation should either be
1561 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1562 * all packets are IP packets, or should be handled in some
1563 * special case, if none of them are (if some are and some
1564 * aren't, the lack of encapsulation is a problem, as we'd
1565 * have to find some other way of determining the packet type).
1567 * Therefore, if "off_linktype" is -1, there's an error.
1569 if (off_linktype
== -1)
1573 * Any type not handled above should always have an Ethernet
1574 * type at an offset of "off_linktype". (PPP is partially
1575 * handled above - the protocol type is mapped from the
1576 * Ethernet and LLC types we use internally to the corresponding
1577 * PPP type - but the PPP type is always specified by a value
1578 * at "off_linktype", so we don't have to do the code generation
1581 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1585 * Check for an LLC SNAP packet with a given organization code and
1586 * protocol type; we check the entire contents of the 802.2 LLC and
1587 * snap headers, checking for DSAP and SSAP of SNAP and a control
1588 * field of 0x03 in the LLC header, and for the specified organization
1589 * code and protocol type in the SNAP header.
1591 static struct block
*
1592 gen_snap(orgcode
, ptype
, offset
)
1593 bpf_u_int32 orgcode
;
1597 u_char snapblock
[8];
1599 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1600 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1601 snapblock
[2] = 0x03; /* control = UI */
1602 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1603 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1604 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1605 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1606 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1607 return gen_bcmp(offset
, 8, snapblock
);
1611 * Check for a given protocol value assuming an 802.2 LLC header.
1613 static struct block
*
1618 * XXX - handle token-ring variable-length header.
1623 return gen_cmp(off_linktype
, BPF_H
, (long)
1624 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1626 case LLCSAP_NETBEUI
:
1627 return gen_cmp(off_linktype
, BPF_H
, (long)
1628 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1632 * XXX - are there ever SNAP frames for IPX on
1633 * non-Ethernet 802.x networks?
1635 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1637 case ETHERTYPE_ATALK
:
1639 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1640 * SNAP packets with an organization code of
1641 * 0x080007 (Apple, for Appletalk) and a protocol
1642 * type of ETHERTYPE_ATALK (Appletalk).
1644 * XXX - check for an organization code of
1645 * encapsulated Ethernet as well?
1647 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1651 * XXX - we don't have to check for IPX 802.3
1652 * here, but should we check for the IPX Ethertype?
1654 if (proto
<= ETHERMTU
) {
1656 * This is an LLC SAP value, so check
1659 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1662 * This is an Ethernet type; we assume that it's
1663 * unlikely that it'll appear in the right place
1664 * at random, and therefore check only the
1665 * location that would hold the Ethernet type
1666 * in a SNAP frame with an organization code of
1667 * 0x000000 (encapsulated Ethernet).
1669 * XXX - if we were to check for the SNAP DSAP and
1670 * LSAP, as per XXX, and were also to check for an
1671 * organization code of 0x000000 (encapsulated
1672 * Ethernet), we'd do
1674 * return gen_snap(0x000000, proto,
1677 * here; for now, we don't, as per the above.
1678 * I don't know whether it's worth the extra CPU
1679 * time to do the right check or not.
1681 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1686 static struct block
*
1687 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1691 u_int src_off
, dst_off
;
1693 struct block
*b0
, *b1
;
1707 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1708 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1714 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1715 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1722 b0
= gen_linktype(proto
);
1723 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1729 static struct block
*
1730 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1731 struct in6_addr
*addr
;
1732 struct in6_addr
*mask
;
1734 u_int src_off
, dst_off
;
1736 struct block
*b0
, *b1
;
1751 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1752 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1758 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1759 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1766 /* this order is important */
1767 a
= (u_int32_t
*)addr
;
1768 m
= (u_int32_t
*)mask
;
1769 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1770 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1772 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1774 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1776 b0
= gen_linktype(proto
);
1782 static struct block
*
1783 gen_ehostop(eaddr
, dir
)
1784 register const u_char
*eaddr
;
1787 register struct block
*b0
, *b1
;
1791 return gen_bcmp(6, 6, eaddr
);
1794 return gen_bcmp(0, 6, eaddr
);
1797 b0
= gen_ehostop(eaddr
, Q_SRC
);
1798 b1
= gen_ehostop(eaddr
, Q_DST
);
1804 b0
= gen_ehostop(eaddr
, Q_SRC
);
1805 b1
= gen_ehostop(eaddr
, Q_DST
);
1814 * Like gen_ehostop, but for DLT_FDDI
1816 static struct block
*
1817 gen_fhostop(eaddr
, dir
)
1818 register const u_char
*eaddr
;
1821 struct block
*b0
, *b1
;
1826 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
1828 return gen_bcmp(6 + 1, 6, eaddr
);
1833 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
1835 return gen_bcmp(0 + 1, 6, eaddr
);
1839 b0
= gen_fhostop(eaddr
, Q_SRC
);
1840 b1
= gen_fhostop(eaddr
, Q_DST
);
1846 b0
= gen_fhostop(eaddr
, Q_SRC
);
1847 b1
= gen_fhostop(eaddr
, Q_DST
);
1856 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
1858 static struct block
*
1859 gen_thostop(eaddr
, dir
)
1860 register const u_char
*eaddr
;
1863 register struct block
*b0
, *b1
;
1867 return gen_bcmp(8, 6, eaddr
);
1870 return gen_bcmp(2, 6, eaddr
);
1873 b0
= gen_thostop(eaddr
, Q_SRC
);
1874 b1
= gen_thostop(eaddr
, Q_DST
);
1880 b0
= gen_thostop(eaddr
, Q_SRC
);
1881 b1
= gen_thostop(eaddr
, Q_DST
);
1890 * This is quite tricky because there may be pad bytes in front of the
1891 * DECNET header, and then there are two possible data packet formats that
1892 * carry both src and dst addresses, plus 5 packet types in a format that
1893 * carries only the src node, plus 2 types that use a different format and
1894 * also carry just the src node.
1898 * Instead of doing those all right, we just look for data packets with
1899 * 0 or 1 bytes of padding. If you want to look at other packets, that
1900 * will require a lot more hacking.
1902 * To add support for filtering on DECNET "areas" (network numbers)
1903 * one would want to add a "mask" argument to this routine. That would
1904 * make the filter even more inefficient, although one could be clever
1905 * and not generate masking instructions if the mask is 0xFFFF.
1907 static struct block
*
1908 gen_dnhostop(addr
, dir
, base_off
)
1913 struct block
*b0
, *b1
, *b2
, *tmp
;
1914 u_int offset_lh
; /* offset if long header is received */
1915 u_int offset_sh
; /* offset if short header is received */
1920 offset_sh
= 1; /* follows flags */
1921 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
1925 offset_sh
= 3; /* follows flags, dstnode */
1926 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
1930 /* Inefficient because we do our Calvinball dance twice */
1931 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
1932 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
1938 /* Inefficient because we do our Calvinball dance twice */
1939 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
1940 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
1945 bpf_error("ISO host filtering not implemented");
1950 b0
= gen_linktype(ETHERTYPE_DN
);
1951 /* Check for pad = 1, long header case */
1952 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
1953 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
1954 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
1955 BPF_H
, (bpf_int32
)ntohs(addr
));
1957 /* Check for pad = 0, long header case */
1958 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
1959 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
1962 /* Check for pad = 1, short header case */
1963 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
1964 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
1965 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
1966 BPF_H
, (bpf_int32
)ntohs(addr
));
1969 /* Check for pad = 0, short header case */
1970 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
1971 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
1975 /* Combine with test for linktype */
1980 static struct block
*
1981 gen_host(addr
, mask
, proto
, dir
)
1987 struct block
*b0
, *b1
;
1992 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
1993 if (off_linktype
!= -1) {
1994 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
1996 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
2002 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
2003 off_nl
+ 12, off_nl
+ 16);
2006 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2007 off_nl
+ 14, off_nl
+ 24);
2010 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2011 off_nl
+ 14, off_nl
+ 24);
2014 bpf_error("'tcp' modifier applied to host");
2017 bpf_error("'sctp' modifier applied to host");
2020 bpf_error("'udp' modifier applied to host");
2023 bpf_error("'icmp' modifier applied to host");
2026 bpf_error("'igmp' modifier applied to host");
2029 bpf_error("'igrp' modifier applied to host");
2032 bpf_error("'pim' modifier applied to host");
2035 bpf_error("'vrrp' modifier applied to host");
2038 bpf_error("ATALK host filtering not implemented");
2041 bpf_error("AARP host filtering not implemented");
2044 return gen_dnhostop(addr
, dir
, off_nl
);
2047 bpf_error("SCA host filtering not implemented");
2050 bpf_error("LAT host filtering not implemented");
2053 bpf_error("MOPDL host filtering not implemented");
2056 bpf_error("MOPRC host filtering not implemented");
2060 bpf_error("'ip6' modifier applied to ip host");
2063 bpf_error("'icmp6' modifier applied to host");
2067 bpf_error("'ah' modifier applied to host");
2070 bpf_error("'esp' modifier applied to host");
2073 bpf_error("ISO host filtering not implemented");
2076 bpf_error("'esis' modifier applied to host");
2079 bpf_error("'isis' modifier applied to host");
2082 bpf_error("'clnp' modifier applied to host");
2085 bpf_error("'stp' modifier applied to host");
2088 bpf_error("IPX host filtering not implemented");
2091 bpf_error("'netbeui' modifier applied to host");
2100 static struct block
*
2101 gen_host6(addr
, mask
, proto
, dir
)
2102 struct in6_addr
*addr
;
2103 struct in6_addr
*mask
;
2110 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2113 bpf_error("'ip' modifier applied to ip6 host");
2116 bpf_error("'rarp' modifier applied to ip6 host");
2119 bpf_error("'arp' modifier applied to ip6 host");
2122 bpf_error("'sctp' modifier applied to host");
2125 bpf_error("'tcp' modifier applied to host");
2128 bpf_error("'udp' modifier applied to host");
2131 bpf_error("'icmp' modifier applied to host");
2134 bpf_error("'igmp' modifier applied to host");
2137 bpf_error("'igrp' modifier applied to host");
2140 bpf_error("'pim' modifier applied to host");
2143 bpf_error("'vrrp' modifier applied to host");
2146 bpf_error("ATALK host filtering not implemented");
2149 bpf_error("AARP host filtering not implemented");
2152 bpf_error("'decnet' modifier applied to ip6 host");
2155 bpf_error("SCA host filtering not implemented");
2158 bpf_error("LAT host filtering not implemented");
2161 bpf_error("MOPDL host filtering not implemented");
2164 bpf_error("MOPRC host filtering not implemented");
2167 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2168 off_nl
+ 8, off_nl
+ 24);
2171 bpf_error("'icmp6' modifier applied to host");
2174 bpf_error("'ah' modifier applied to host");
2177 bpf_error("'esp' modifier applied to host");
2180 bpf_error("ISO host filtering not implemented");
2183 bpf_error("'esis' modifier applied to host");
2186 bpf_error("'isis' modifier applied to host");
2189 bpf_error("'clnp' modifier applied to host");
2192 bpf_error("'stp' modifier applied to host");
2195 bpf_error("IPX host filtering not implemented");
2198 bpf_error("'netbeui' modifier applied to host");
2208 static struct block
*
2209 gen_gateway(eaddr
, alist
, proto
, dir
)
2210 const u_char
*eaddr
;
2211 bpf_u_int32
**alist
;
2215 struct block
*b0
, *b1
, *tmp
;
2218 bpf_error("direction applied to 'gateway'");
2225 if (linktype
== DLT_EN10MB
)
2226 b0
= gen_ehostop(eaddr
, Q_OR
);
2227 else if (linktype
== DLT_FDDI
)
2228 b0
= gen_fhostop(eaddr
, Q_OR
);
2229 else if (linktype
== DLT_IEEE802
)
2230 b0
= gen_thostop(eaddr
, Q_OR
);
2233 "'gateway' supported only on ethernet, FDDI or token ring");
2235 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2237 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2245 bpf_error("illegal modifier of 'gateway'");
2251 gen_proto_abbrev(proto
)
2262 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2264 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2270 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2272 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2278 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2280 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2286 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2289 #ifndef IPPROTO_IGMP
2290 #define IPPROTO_IGMP 2
2294 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2297 #ifndef IPPROTO_IGRP
2298 #define IPPROTO_IGRP 9
2301 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2305 #define IPPROTO_PIM 103
2309 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2311 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2316 #ifndef IPPROTO_VRRP
2317 #define IPPROTO_VRRP 112
2321 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2325 b1
= gen_linktype(ETHERTYPE_IP
);
2329 b1
= gen_linktype(ETHERTYPE_ARP
);
2333 b1
= gen_linktype(ETHERTYPE_REVARP
);
2337 bpf_error("link layer applied in wrong context");
2340 b1
= gen_linktype(ETHERTYPE_ATALK
);
2344 b1
= gen_linktype(ETHERTYPE_AARP
);
2348 b1
= gen_linktype(ETHERTYPE_DN
);
2352 b1
= gen_linktype(ETHERTYPE_SCA
);
2356 b1
= gen_linktype(ETHERTYPE_LAT
);
2360 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2364 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2369 b1
= gen_linktype(ETHERTYPE_IPV6
);
2372 #ifndef IPPROTO_ICMPV6
2373 #define IPPROTO_ICMPV6 58
2376 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2381 #define IPPROTO_AH 51
2384 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2386 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2392 #define IPPROTO_ESP 50
2395 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2397 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2403 b1
= gen_linktype(LLCSAP_ISONS
);
2407 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2411 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2415 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
2419 b1
= gen_linktype(LLCSAP_8021D
);
2423 b1
= gen_linktype(LLCSAP_IPX
);
2427 b1
= gen_linktype(LLCSAP_NETBEUI
);
2436 static struct block
*
2443 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
2444 s
->s
.k
= off_nl
+ 6;
2445 b
= new_block(JMP(BPF_JSET
));
2453 static struct block
*
2454 gen_portatom(off
, v
)
2461 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
2464 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
2465 s
->next
->s
.k
= off_nl
+ off
;
2467 b
= new_block(JMP(BPF_JEQ
));
2475 static struct block
*
2476 gen_portatom6(off
, v
)
2480 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
2485 gen_portop(port
, proto
, dir
)
2486 int port
, proto
, dir
;
2488 struct block
*b0
, *b1
, *tmp
;
2490 /* ip proto 'proto' */
2491 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
2497 b1
= gen_portatom(0, (bpf_int32
)port
);
2501 b1
= gen_portatom(2, (bpf_int32
)port
);
2506 tmp
= gen_portatom(0, (bpf_int32
)port
);
2507 b1
= gen_portatom(2, (bpf_int32
)port
);
2512 tmp
= gen_portatom(0, (bpf_int32
)port
);
2513 b1
= gen_portatom(2, (bpf_int32
)port
);
2525 static struct block
*
2526 gen_port(port
, ip_proto
, dir
)
2531 struct block
*b0
, *b1
, *tmp
;
2533 /* ether proto ip */
2534 b0
= gen_linktype(ETHERTYPE_IP
);
2540 b1
= gen_portop(port
, ip_proto
, dir
);
2544 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
2545 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
2547 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
2560 gen_portop6(port
, proto
, dir
)
2561 int port
, proto
, dir
;
2563 struct block
*b0
, *b1
, *tmp
;
2565 /* ip proto 'proto' */
2566 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
2570 b1
= gen_portatom6(0, (bpf_int32
)port
);
2574 b1
= gen_portatom6(2, (bpf_int32
)port
);
2579 tmp
= gen_portatom6(0, (bpf_int32
)port
);
2580 b1
= gen_portatom6(2, (bpf_int32
)port
);
2585 tmp
= gen_portatom6(0, (bpf_int32
)port
);
2586 b1
= gen_portatom6(2, (bpf_int32
)port
);
2598 static struct block
*
2599 gen_port6(port
, ip_proto
, dir
)
2604 struct block
*b0
, *b1
, *tmp
;
2606 /* ether proto ip */
2607 b0
= gen_linktype(ETHERTYPE_IPV6
);
2613 b1
= gen_portop6(port
, ip_proto
, dir
);
2617 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
2618 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
2620 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
2633 lookup_proto(name
, proto
)
2634 register const char *name
;
2644 v
= pcap_nametoproto(name
);
2645 if (v
== PROTO_UNDEF
)
2646 bpf_error("unknown ip proto '%s'", name
);
2650 /* XXX should look up h/w protocol type based on linktype */
2651 v
= pcap_nametoeproto(name
);
2652 if (v
== PROTO_UNDEF
)
2653 bpf_error("unknown ether proto '%s'", name
);
2657 if (strcmp(name
, "esis") == 0)
2659 else if (strcmp(name
, "isis") == 0)
2661 else if (strcmp(name
, "clnp") == 0)
2664 bpf_error("unknown osi proto '%s'", name
);
2684 static struct block
*
2685 gen_protochain(v
, proto
, dir
)
2690 #ifdef NO_PROTOCHAIN
2691 return gen_proto(v
, proto
, dir
);
2693 struct block
*b0
, *b
;
2694 struct slist
*s
[100];
2695 int fix2
, fix3
, fix4
, fix5
;
2696 int ahcheck
, again
, end
;
2698 int reg2
= alloc_reg();
2700 memset(s
, 0, sizeof(s
));
2701 fix2
= fix3
= fix4
= fix5
= 0;
2708 b0
= gen_protochain(v
, Q_IP
, dir
);
2709 b
= gen_protochain(v
, Q_IPV6
, dir
);
2713 bpf_error("bad protocol applied for 'protochain'");
2717 no_optimize
= 1; /*this code is not compatible with optimzer yet */
2720 * s[0] is a dummy entry to protect other BPF insn from damaged
2721 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
2722 * hard to find interdependency made by jump table fixup.
2725 s
[i
] = new_stmt(0); /*dummy*/
2730 b0
= gen_linktype(ETHERTYPE_IP
);
2733 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2734 s
[i
]->s
.k
= off_nl
+ 9;
2736 /* X = ip->ip_hl << 2 */
2737 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
2743 b0
= gen_linktype(ETHERTYPE_IPV6
);
2745 /* A = ip6->ip_nxt */
2746 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2747 s
[i
]->s
.k
= off_nl
+ 6;
2749 /* X = sizeof(struct ip6_hdr) */
2750 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
2756 bpf_error("unsupported proto to gen_protochain");
2760 /* again: if (A == v) goto end; else fall through; */
2762 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2764 s
[i
]->s
.jt
= NULL
; /*later*/
2765 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2769 #ifndef IPPROTO_NONE
2770 #define IPPROTO_NONE 59
2772 /* if (A == IPPROTO_NONE) goto end */
2773 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2774 s
[i
]->s
.jt
= NULL
; /*later*/
2775 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2776 s
[i
]->s
.k
= IPPROTO_NONE
;
2777 s
[fix5
]->s
.jf
= s
[i
];
2782 if (proto
== Q_IPV6
) {
2783 int v6start
, v6end
, v6advance
, j
;
2786 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
2787 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2788 s
[i
]->s
.jt
= NULL
; /*later*/
2789 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2790 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
2791 s
[fix2
]->s
.jf
= s
[i
];
2793 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
2794 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2795 s
[i
]->s
.jt
= NULL
; /*later*/
2796 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2797 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
2799 /* if (A == IPPROTO_ROUTING) goto v6advance */
2800 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2801 s
[i
]->s
.jt
= NULL
; /*later*/
2802 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2803 s
[i
]->s
.k
= IPPROTO_ROUTING
;
2805 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
2806 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2807 s
[i
]->s
.jt
= NULL
; /*later*/
2808 s
[i
]->s
.jf
= NULL
; /*later*/
2809 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
2820 * X = X + (P[X + 1] + 1) * 8;
2823 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2825 /* A = P[X + packet head] */
2826 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2830 s
[i
] = new_stmt(BPF_ST
);
2834 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2837 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2841 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2843 /* A = P[X + packet head]; */
2844 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2848 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2852 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
2856 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2859 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
2863 /* goto again; (must use BPF_JA for backward jump) */
2864 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
2865 s
[i
]->s
.k
= again
- i
- 1;
2866 s
[i
- 1]->s
.jf
= s
[i
];
2870 for (j
= v6start
; j
<= v6end
; j
++)
2871 s
[j
]->s
.jt
= s
[v6advance
];
2876 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2878 s
[fix2
]->s
.jf
= s
[i
];
2884 /* if (A == IPPROTO_AH) then fall through; else goto end; */
2885 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2886 s
[i
]->s
.jt
= NULL
; /*later*/
2887 s
[i
]->s
.jf
= NULL
; /*later*/
2888 s
[i
]->s
.k
= IPPROTO_AH
;
2890 s
[fix3
]->s
.jf
= s
[ahcheck
];
2897 * X = X + (P[X + 1] + 2) * 4;
2900 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2902 /* A = P[X + packet head]; */
2903 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2907 s
[i
] = new_stmt(BPF_ST
);
2911 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2914 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2918 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2920 /* A = P[X + packet head] */
2921 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2925 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2929 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
2933 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2936 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
2940 /* goto again; (must use BPF_JA for backward jump) */
2941 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
2942 s
[i
]->s
.k
= again
- i
- 1;
2947 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2949 s
[fix2
]->s
.jt
= s
[end
];
2950 s
[fix4
]->s
.jf
= s
[end
];
2951 s
[fix5
]->s
.jt
= s
[end
];
2958 for (i
= 0; i
< max
- 1; i
++)
2959 s
[i
]->next
= s
[i
+ 1];
2960 s
[max
- 1]->next
= NULL
;
2965 b
= new_block(JMP(BPF_JEQ
));
2966 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
2976 static struct block
*
2977 gen_proto(v
, proto
, dir
)
2982 struct block
*b0
, *b1
;
2984 if (dir
!= Q_DEFAULT
)
2985 bpf_error("direction applied to 'proto'");
2990 b0
= gen_proto(v
, Q_IP
, dir
);
2991 b1
= gen_proto(v
, Q_IPV6
, dir
);
2998 b0
= gen_linktype(ETHERTYPE_IP
);
3000 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
3002 b1
= gen_protochain(v
, Q_IP
);
3012 * Frame Relay packets typically have an OSI
3013 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3014 * generates code to check for all the OSI
3015 * NLPIDs, so calling it and then adding a check
3016 * for the particular NLPID for which we're
3017 * looking is bogus, as we can just check for
3020 * What we check for is the NLPID and a frame
3021 * control field value of UI, i.e. 0x03 followed
3024 * XXX - assumes a 2-byte Frame Relay header with
3025 * DLCI and flags. What if the address is longer?
3027 * XXX - what about SNAP-encapsulated frames?
3029 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3033 b0
= gen_linktype(LLCSAP_ISONS
);
3034 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3040 bpf_error("arp does not encapsulate another protocol");
3044 bpf_error("rarp does not encapsulate another protocol");
3048 bpf_error("atalk encapsulation is not specifiable");
3052 bpf_error("decnet encapsulation is not specifiable");
3056 bpf_error("sca does not encapsulate another protocol");
3060 bpf_error("lat does not encapsulate another protocol");
3064 bpf_error("moprc does not encapsulate another protocol");
3068 bpf_error("mopdl does not encapsulate another protocol");
3072 return gen_linktype(v
);
3075 bpf_error("'udp proto' is bogus");
3079 bpf_error("'tcp proto' is bogus");
3083 bpf_error("'sctp proto' is bogus");
3087 bpf_error("'icmp proto' is bogus");
3091 bpf_error("'igmp proto' is bogus");
3095 bpf_error("'igrp proto' is bogus");
3099 bpf_error("'pim proto' is bogus");
3103 bpf_error("'vrrp proto' is bogus");
3108 b0
= gen_linktype(ETHERTYPE_IPV6
);
3110 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3112 b1
= gen_protochain(v
, Q_IPV6
);
3118 bpf_error("'icmp6 proto' is bogus");
3122 bpf_error("'ah proto' is bogus");
3125 bpf_error("'ah proto' is bogus");
3128 bpf_error("'stp proto' is bogus");
3131 bpf_error("'ipx proto' is bogus");
3134 bpf_error("'netbeui proto' is bogus");
3145 register const char *name
;
3148 int proto
= q
.proto
;
3152 bpf_u_int32 mask
, addr
;
3154 bpf_u_int32
**alist
;
3157 struct sockaddr_in
*sin
;
3158 struct sockaddr_in6
*sin6
;
3159 struct addrinfo
*res
, *res0
;
3160 struct in6_addr mask128
;
3162 struct block
*b
, *tmp
;
3163 int port
, real_proto
;
3168 addr
= pcap_nametonetaddr(name
);
3170 bpf_error("unknown network '%s'", name
);
3171 /* Left justify network addr and calculate its network mask */
3173 while (addr
&& (addr
& 0xff000000) == 0) {
3177 return gen_host(addr
, mask
, proto
, dir
);
3181 if (proto
== Q_LINK
) {
3185 eaddr
= pcap_ether_hostton(name
);
3188 "unknown ether host '%s'", name
);
3189 b
= gen_ehostop(eaddr
, dir
);
3194 eaddr
= pcap_ether_hostton(name
);
3197 "unknown FDDI host '%s'", name
);
3198 b
= gen_fhostop(eaddr
, dir
);
3203 eaddr
= pcap_ether_hostton(name
);
3206 "unknown token ring host '%s'", name
);
3207 b
= gen_thostop(eaddr
, dir
);
3213 "only ethernet/FDDI/token ring supports link-level host name");
3216 } else if (proto
== Q_DECNET
) {
3217 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3219 * I don't think DECNET hosts can be multihomed, so
3220 * there is no need to build up a list of addresses
3222 return (gen_host(dn_addr
, 0, proto
, dir
));
3225 alist
= pcap_nametoaddr(name
);
3226 if (alist
== NULL
|| *alist
== NULL
)
3227 bpf_error("unknown host '%s'", name
);
3229 if (off_linktype
== -1 && tproto
== Q_DEFAULT
)
3231 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3233 tmp
= gen_host(**alist
++, 0xffffffff,
3240 memset(&mask128
, 0xff, sizeof(mask128
));
3241 res0
= res
= pcap_nametoaddrinfo(name
);
3243 bpf_error("unknown host '%s'", name
);
3245 tproto
= tproto6
= proto
;
3246 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3250 for (res
= res0
; res
; res
= res
->ai_next
) {
3251 switch (res
->ai_family
) {
3253 if (tproto
== Q_IPV6
)
3256 sin
= (struct sockaddr_in
*)
3258 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3259 0xffffffff, tproto
, dir
);
3262 if (tproto6
== Q_IP
)
3265 sin6
= (struct sockaddr_in6
*)
3267 tmp
= gen_host6(&sin6
->sin6_addr
,
3268 &mask128
, tproto6
, dir
);
3279 bpf_error("unknown host '%s'%s", name
,
3280 (proto
== Q_DEFAULT
)
3282 : " for specified address family");
3289 if (proto
!= Q_DEFAULT
&&
3290 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3291 bpf_error("illegal qualifier of 'port'");
3292 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3293 bpf_error("unknown port '%s'", name
);
3294 if (proto
== Q_UDP
) {
3295 if (real_proto
== IPPROTO_TCP
)
3296 bpf_error("port '%s' is tcp", name
);
3297 else if (real_proto
== IPPROTO_SCTP
)
3298 bpf_error("port '%s' is sctp", name
);
3300 /* override PROTO_UNDEF */
3301 real_proto
= IPPROTO_UDP
;
3303 if (proto
== Q_TCP
) {
3304 if (real_proto
== IPPROTO_UDP
)
3305 bpf_error("port '%s' is udp", name
);
3307 else if (real_proto
== IPPROTO_SCTP
)
3308 bpf_error("port '%s' is sctp", name
);
3310 /* override PROTO_UNDEF */
3311 real_proto
= IPPROTO_TCP
;
3313 if (proto
== Q_SCTP
) {
3314 if (real_proto
== IPPROTO_UDP
)
3315 bpf_error("port '%s' is udp", name
);
3317 else if (real_proto
== IPPROTO_TCP
)
3318 bpf_error("port '%s' is tcp", name
);
3320 /* override PROTO_UNDEF */
3321 real_proto
= IPPROTO_SCTP
;
3324 return gen_port(port
, real_proto
, dir
);
3328 b
= gen_port(port
, real_proto
, dir
);
3329 gen_or(gen_port6(port
, real_proto
, dir
), b
);
3336 eaddr
= pcap_ether_hostton(name
);
3338 bpf_error("unknown ether host: %s", name
);
3340 alist
= pcap_nametoaddr(name
);
3341 if (alist
== NULL
|| *alist
== NULL
)
3342 bpf_error("unknown host '%s'", name
);
3343 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
3347 bpf_error("'gateway' not supported in this configuration");
3351 real_proto
= lookup_proto(name
, proto
);
3352 if (real_proto
>= 0)
3353 return gen_proto(real_proto
, proto
, dir
);
3355 bpf_error("unknown protocol: %s", name
);
3358 real_proto
= lookup_proto(name
, proto
);
3359 if (real_proto
>= 0)
3360 return gen_protochain(real_proto
, proto
, dir
);
3362 bpf_error("unknown protocol: %s", name
);
3374 gen_mcode(s1
, s2
, masklen
, q
)
3375 register const char *s1
, *s2
;
3376 register int masklen
;
3379 register int nlen
, mlen
;
3382 nlen
= __pcap_atoin(s1
, &n
);
3383 /* Promote short ipaddr */
3387 mlen
= __pcap_atoin(s2
, &m
);
3388 /* Promote short ipaddr */
3391 bpf_error("non-network bits set in \"%s mask %s\"",
3394 /* Convert mask len to mask */
3396 bpf_error("mask length must be <= 32");
3397 m
= 0xffffffff << (32 - masklen
);
3399 bpf_error("non-network bits set in \"%s/%d\"",
3406 return gen_host(n
, m
, q
.proto
, q
.dir
);
3409 bpf_error("Mask syntax for networks only");
3416 register const char *s
;
3421 int proto
= q
.proto
;
3427 else if (q
.proto
== Q_DECNET
)
3428 vlen
= __pcap_atodn(s
, &v
);
3430 vlen
= __pcap_atoin(s
, &v
);
3437 if (proto
== Q_DECNET
)
3438 return gen_host(v
, 0, proto
, dir
);
3439 else if (proto
== Q_LINK
) {
3440 bpf_error("illegal link layer address");
3443 if (s
== NULL
&& q
.addr
== Q_NET
) {
3444 /* Promote short net number */
3445 while (v
&& (v
& 0xff000000) == 0) {
3450 /* Promote short ipaddr */
3454 return gen_host(v
, mask
, proto
, dir
);
3459 proto
= IPPROTO_UDP
;
3460 else if (proto
== Q_TCP
)
3461 proto
= IPPROTO_TCP
;
3462 else if (proto
== Q_SCTP
)
3463 proto
= IPPROTO_SCTP
;
3464 else if (proto
== Q_DEFAULT
)
3465 proto
= PROTO_UNDEF
;
3467 bpf_error("illegal qualifier of 'port'");
3470 return gen_port((int)v
, proto
, dir
);
3474 b
= gen_port((int)v
, proto
, dir
);
3475 gen_or(gen_port6((int)v
, proto
, dir
), b
);
3481 bpf_error("'gateway' requires a name");
3485 return gen_proto((int)v
, proto
, dir
);
3488 return gen_protochain((int)v
, proto
, dir
);
3503 gen_mcode6(s1
, s2
, masklen
, q
)
3504 register const char *s1
, *s2
;
3505 register int masklen
;
3508 struct addrinfo
*res
;
3509 struct in6_addr
*addr
;
3510 struct in6_addr mask
;
3515 bpf_error("no mask %s supported", s2
);
3517 res
= pcap_nametoaddrinfo(s1
);
3519 bpf_error("invalid ip6 address %s", s1
);
3521 bpf_error("%s resolved to multiple address", s1
);
3522 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
3524 if (sizeof(mask
) * 8 < masklen
)
3525 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
3526 memset(&mask
, 0, sizeof(mask
));
3527 memset(&mask
, 0xff, masklen
/ 8);
3529 mask
.s6_addr
[masklen
/ 8] =
3530 (0xff << (8 - masklen
% 8)) & 0xff;
3533 a
= (u_int32_t
*)addr
;
3534 m
= (u_int32_t
*)&mask
;
3535 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
3536 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
3537 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
3545 bpf_error("Mask syntax for networks only");
3549 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
3554 bpf_error("invalid qualifier against IPv6 address");
3562 register const u_char
*eaddr
;
3565 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
3566 if (linktype
== DLT_EN10MB
)
3567 return gen_ehostop(eaddr
, (int)q
.dir
);
3568 if (linktype
== DLT_FDDI
)
3569 return gen_fhostop(eaddr
, (int)q
.dir
);
3570 if (linktype
== DLT_IEEE802
)
3571 return gen_thostop(eaddr
, (int)q
.dir
);
3572 bpf_error("ethernet addresses supported only on ethernet, FDDI or token ring");
3574 bpf_error("ethernet address used in non-ether expression");
3580 struct slist
*s0
, *s1
;
3583 * This is definitely not the best way to do this, but the
3584 * lists will rarely get long.
3591 static struct slist
*
3597 s
= new_stmt(BPF_LDX
|BPF_MEM
);
3602 static struct slist
*
3608 s
= new_stmt(BPF_LD
|BPF_MEM
);
3614 gen_load(proto
, index
, size
)
3619 struct slist
*s
, *tmp
;
3621 int regno
= alloc_reg();
3623 free_reg(index
->regno
);
3627 bpf_error("data size must be 1, 2, or 4");
3643 bpf_error("unsupported index operation");
3646 s
= xfer_to_x(index
);
3647 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
3649 sappend(index
->s
, s
);
3664 /* XXX Note that we assume a fixed link header here. */
3665 s
= xfer_to_x(index
);
3666 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
3669 sappend(index
->s
, s
);
3671 b
= gen_proto_abbrev(proto
);
3673 gen_and(index
->b
, b
);
3685 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3687 sappend(s
, xfer_to_a(index
));
3688 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
3689 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
3690 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
3692 sappend(index
->s
, s
);
3694 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
3696 gen_and(index
->b
, b
);
3698 gen_and(gen_proto_abbrev(Q_IP
), b
);
3704 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
3708 index
->regno
= regno
;
3709 s
= new_stmt(BPF_ST
);
3711 sappend(index
->s
, s
);
3717 gen_relation(code
, a0
, a1
, reversed
)
3719 struct arth
*a0
, *a1
;
3722 struct slist
*s0
, *s1
, *s2
;
3723 struct block
*b
, *tmp
;
3727 if (code
== BPF_JEQ
) {
3728 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
3729 b
= new_block(JMP(code
));
3733 b
= new_block(BPF_JMP
|code
|BPF_X
);
3739 sappend(a0
->s
, a1
->s
);
3743 free_reg(a0
->regno
);
3744 free_reg(a1
->regno
);
3746 /* 'and' together protocol checks */
3749 gen_and(a0
->b
, tmp
= a1
->b
);
3765 int regno
= alloc_reg();
3766 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
3769 s
= new_stmt(BPF_LD
|BPF_LEN
);
3770 s
->next
= new_stmt(BPF_ST
);
3771 s
->next
->s
.k
= regno
;
3786 a
= (struct arth
*)newchunk(sizeof(*a
));
3790 s
= new_stmt(BPF_LD
|BPF_IMM
);
3792 s
->next
= new_stmt(BPF_ST
);
3808 s
= new_stmt(BPF_ALU
|BPF_NEG
);
3811 s
= new_stmt(BPF_ST
);
3819 gen_arth(code
, a0
, a1
)
3821 struct arth
*a0
, *a1
;
3823 struct slist
*s0
, *s1
, *s2
;
3827 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
3832 sappend(a0
->s
, a1
->s
);
3834 free_reg(a0
->regno
);
3835 free_reg(a1
->regno
);
3837 s0
= new_stmt(BPF_ST
);
3838 a0
->regno
= s0
->s
.k
= alloc_reg();
3845 * Here we handle simple allocation of the scratch registers.
3846 * If too many registers are alloc'd, the allocator punts.
3848 static int regused
[BPF_MEMWORDS
];
3852 * Return the next free register.
3857 int n
= BPF_MEMWORDS
;
3860 if (regused
[curreg
])
3861 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
3863 regused
[curreg
] = 1;
3867 bpf_error("too many registers needed to evaluate expression");
3872 * Return a register to the table so it can
3882 static struct block
*
3889 s
= new_stmt(BPF_LD
|BPF_LEN
);
3890 b
= new_block(JMP(jmp
));
3901 return gen_len(BPF_JGE
, n
);
3905 * Actually, this is less than or equal.
3913 b
= gen_len(BPF_JGT
, n
);
3920 gen_byteop(op
, idx
, val
)
3931 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3934 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3935 b
->s
.code
= JMP(BPF_JGE
);
3940 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3941 b
->s
.code
= JMP(BPF_JGT
);
3945 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
3949 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
3953 b
= new_block(JMP(BPF_JEQ
));
3960 static u_char abroadcast
[] = { 0x0 };
3963 gen_broadcast(proto
)
3966 bpf_u_int32 hostmask
;
3967 struct block
*b0
, *b1
, *b2
;
3968 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3974 if (linktype
== DLT_ARCNET
)
3975 return gen_ahostop(abroadcast
, Q_DST
);
3976 if (linktype
== DLT_EN10MB
)
3977 return gen_ehostop(ebroadcast
, Q_DST
);
3978 if (linktype
== DLT_FDDI
)
3979 return gen_fhostop(ebroadcast
, Q_DST
);
3980 if (linktype
== DLT_IEEE802
)
3981 return gen_thostop(ebroadcast
, Q_DST
);
3982 bpf_error("not a broadcast link");
3986 b0
= gen_linktype(ETHERTYPE_IP
);
3987 hostmask
= ~netmask
;
3988 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
3989 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
3990 (bpf_int32
)(~0 & hostmask
), hostmask
);
3995 bpf_error("only ether/ip broadcast filters supported");
3999 gen_multicast(proto
)
4002 register struct block
*b0
, *b1
;
4003 register struct slist
*s
;
4009 if (linktype
== DLT_ARCNET
)
4010 /* all ARCnet multicasts use the same address */
4011 return gen_ahostop(abroadcast
, Q_DST
);
4013 if (linktype
== DLT_EN10MB
) {
4014 /* ether[0] & 1 != 0 */
4015 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4017 b0
= new_block(JMP(BPF_JSET
));
4023 if (linktype
== DLT_FDDI
) {
4024 /* XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX */
4025 /* fddi[1] & 1 != 0 */
4026 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4028 b0
= new_block(JMP(BPF_JSET
));
4034 /* TODO - check how token ring handles multicast */
4035 /* if (linktype == DLT_IEEE802) ... */
4037 /* Link not known to support multicasts */
4041 b0
= gen_linktype(ETHERTYPE_IP
);
4042 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4043 b1
->s
.code
= JMP(BPF_JGE
);
4049 b0
= gen_linktype(ETHERTYPE_IPV6
);
4050 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4055 bpf_error("only IP multicast filters supported on ethernet/FDDI");
4059 * generate command for inbound/outbound. It's here so we can
4060 * make it link-type specific. 'dir' = 0 implies "inbound",
4061 * = 1 implies "outbound".
4067 register struct block
*b0
;
4070 * Only some data link types support inbound/outbound qualifiers.
4075 b0
= gen_relation(BPF_JEQ
,
4076 gen_load(Q_LINK
, gen_loadi(0), 1),
4082 bpf_error("inbound/outbound not supported on linktype %d\n",
4092 register const u_char
*eaddr
;
4095 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4096 if (linktype
== DLT_ARCNET
)
4097 return gen_ahostop(eaddr
, (int)q
.dir
);
4099 bpf_error("ARCnet address used in non-arc expression");
4103 static struct block
*
4104 gen_ahostop(eaddr
, dir
)
4105 register const u_char
*eaddr
;
4108 register struct block
*b0
, *b1
;
4111 /* src comes first, different from Ethernet */
4113 return gen_bcmp(0, 1, eaddr
);
4116 return gen_bcmp(1, 1, eaddr
);
4119 b0
= gen_ahostop(eaddr
, Q_SRC
);
4120 b1
= gen_ahostop(eaddr
, Q_DST
);
4126 b0
= gen_ahostop(eaddr
, Q_SRC
);
4127 b1
= gen_ahostop(eaddr
, Q_DST
);
4136 * support IEEE 802.1Q VLAN trunk over ethernet
4145 * Change the offsets to point to the type and data fields within
4146 * the VLAN packet. This is somewhat of a kludge.
4148 if (orig_nl
== (u_int
)-1) {
4149 orig_linktype
= off_linktype
; /* save original values */
4151 orig_nl_nosnap
= off_nl_nosnap
;
4162 bpf_error("no VLAN support for data link type %d",
4168 /* check for VLAN */
4169 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
4171 /* If a specific VLAN is requested, check VLAN id */
4172 if (vlan_num
>= 0) {
4175 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
4184 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
4196 bpf_error("'vpi' supported only on raw ATM");
4199 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
4200 (u_int
)jvalue
, reverse
);
4205 bpf_error("'vci' supported only on raw ATM");
4208 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
4209 (u_int
)jvalue
, reverse
);
4213 if (off_proto
== -1)
4214 abort(); /* XXX - this isn't on FreeBSD */
4215 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
4216 (u_int
)jvalue
, reverse
);
4220 if (off_msg_type
== -1)
4222 b0
= gen_ncmp(BPF_B
, off_msg_type
, 0xffffffff,
4223 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
4228 bpf_error("'callref' supported only on raw ATM");
4229 if (off_proto
== -1)
4231 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
4232 (u_int
)jvalue
, reverse
);
4242 gen_atmtype_abbrev(type
)
4245 struct block
*b0
, *b1
;
4250 /* Get all packets in Meta signalling Circuit */
4252 bpf_error("'metac' supported only on raw ATM");
4253 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4254 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
4259 /* Get all packets in Broadcast Circuit*/
4261 bpf_error("'bcc' supported only on raw ATM");
4262 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4263 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
4268 /* Get all cells in Segment OAM F4 circuit*/
4270 bpf_error("'oam4sc' supported only on raw ATM");
4271 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4272 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
4277 /* Get all cells in End-to-End OAM F4 Circuit*/
4279 bpf_error("'oam4ec' supported only on raw ATM");
4280 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4281 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
4286 /* Get all packets in connection Signalling Circuit */
4288 bpf_error("'sc' supported only on raw ATM");
4289 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4290 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
4295 /* Get all packets in ILMI Circuit */
4297 bpf_error("'ilmic' supported only on raw ATM");
4298 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4299 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
4304 /* Get all LANE packets */
4306 bpf_error("'lane' supported only on raw ATM");
4307 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
4311 /* Get all LLC-encapsulated packets */
4313 bpf_error("'llc' supported only on raw ATM");
4314 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
4324 static struct block
*
4325 gen_msg_abbrev(type
)
4331 * Q.2931 signalling protocol messages for handling virtual circuits
4332 * establishment and teardown
4337 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
4341 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
4345 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
4349 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
4353 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
4356 case A_RELEASE_DONE
:
4357 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
4367 gen_atmmulti_abbrev(type
)
4370 struct block
*b0
, *b1
;
4376 bpf_error("'oam' supported only on raw ATM");
4377 b1
= gen_atmmulti_abbrev(A_OAMF4
);
4382 bpf_error("'oamf4' supported only on raw ATM");
4384 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
4385 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
4387 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4393 * Get Q.2931 signalling messages for switched
4394 * virtual connection
4397 bpf_error("'connectmsg' supported only on raw ATM");
4398 b0
= gen_msg_abbrev(A_SETUP
);
4399 b1
= gen_msg_abbrev(A_CALLPROCEED
);
4401 b0
= gen_msg_abbrev(A_CONNECT
);
4403 b0
= gen_msg_abbrev(A_CONNECTACK
);
4405 b0
= gen_msg_abbrev(A_RELEASE
);
4407 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
4409 b0
= gen_atmtype_abbrev(A_SC
);
4415 bpf_error("'metaconnect' supported only on raw ATM");
4416 b0
= gen_msg_abbrev(A_SETUP
);
4417 b1
= gen_msg_abbrev(A_CALLPROCEED
);
4419 b0
= gen_msg_abbrev(A_CONNECT
);
4421 b0
= gen_msg_abbrev(A_RELEASE
);
4423 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
4425 b0
= gen_atmtype_abbrev(A_METAC
);