]>
The Tcpdump Group git mirrors - libpcap/blob - gencode.c
4ada21b29b37ce2d7f95eda0a30d53adbad19088
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.171 2002-08-02 03:44:19 guy Exp $ (LBL)";
32 #include <pcap-stdinc.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
44 #include <sys/param.h>
47 struct mbuf
; /* Squelch compiler warnings on some platforms for */
48 struct rtentry
; /* declarations in <net/if.h> */
51 #include <netinet/in.h>
63 #include "ethertype.h"
68 #include "sunatmpos.h"
74 #include <netdb.h> /* for "struct addrinfo" */
77 #include <pcap-namedb.h>
82 #define IPPROTO_SCTP 132
85 #ifdef HAVE_OS_PROTO_H
89 #define JMP(c) ((c)|BPF_JMP|BPF_K)
92 static jmp_buf top_ctx
;
93 static pcap_t
*bpf_pcap
;
95 /* Hack for updating VLAN offsets. */
96 static u_int orig_linktype
= -1, orig_nl
= -1, orig_nl_nosnap
= -1;
100 int pcap_fddipad
= PCAP_FDDIPAD
;
107 bpf_error(const char *fmt
, ...)
113 if (bpf_pcap
!= NULL
)
114 (void)vsnprintf(pcap_geterr(bpf_pcap
), PCAP_ERRBUF_SIZE
,
121 static void init_linktype(int);
123 static int alloc_reg(void);
124 static void free_reg(int);
126 static struct block
*root
;
129 * We divy out chunks of memory rather than call malloc each time so
130 * we don't have to worry about leaking memory. It's probably
131 * not a big deal if all this memory was wasted but it this ever
132 * goes into a library that would probably not be a good idea.
135 #define CHUNK0SIZE 1024
141 static struct chunk chunks
[NCHUNKS
];
142 static int cur_chunk
;
144 static void *newchunk(u_int
);
145 static void freechunks(void);
146 static inline struct block
*new_block(int);
147 static inline struct slist
*new_stmt(int);
148 static struct block
*gen_retblk(int);
149 static inline void syntax(void);
151 static void backpatch(struct block
*, struct block
*);
152 static void merge(struct block
*, struct block
*);
153 static struct block
*gen_cmp(u_int
, u_int
, bpf_int32
);
154 static struct block
*gen_cmp_gt(u_int
, u_int
, bpf_int32
);
155 static struct block
*gen_mcmp(u_int
, u_int
, bpf_int32
, bpf_u_int32
);
156 static struct block
*gen_bcmp(u_int
, u_int
, const u_char
*);
157 static struct block
*gen_ncmp(bpf_u_int32
, bpf_u_int32
, bpf_u_int32
,
158 bpf_u_int32
, bpf_u_int32
, int);
159 static struct block
*gen_uncond(int);
160 static inline struct block
*gen_true(void);
161 static inline struct block
*gen_false(void);
162 static struct block
*gen_linktype(int);
163 static struct block
*gen_snap(bpf_u_int32
, bpf_u_int32
, u_int
);
164 static struct block
*gen_llc(int);
165 static struct block
*gen_hostop(bpf_u_int32
, bpf_u_int32
, int, int, u_int
, u_int
);
167 static struct block
*gen_hostop6(struct in6_addr
*, struct in6_addr
*, int, int, u_int
, u_int
);
169 static struct block
*gen_ahostop(const u_char
*, int);
170 static struct block
*gen_ehostop(const u_char
*, int);
171 static struct block
*gen_fhostop(const u_char
*, int);
172 static struct block
*gen_thostop(const u_char
*, int);
173 static struct block
*gen_dnhostop(bpf_u_int32
, int, u_int
);
174 static struct block
*gen_host(bpf_u_int32
, bpf_u_int32
, int, int);
176 static struct block
*gen_host6(struct in6_addr
*, struct in6_addr
*, int, int);
179 static struct block
*gen_gateway(const u_char
*, bpf_u_int32
**, int, int);
181 static struct block
*gen_ipfrag(void);
182 static struct block
*gen_portatom(int, bpf_int32
);
184 static struct block
*gen_portatom6(int, bpf_int32
);
186 struct block
*gen_portop(int, int, int);
187 static struct block
*gen_port(int, int, int);
189 struct block
*gen_portop6(int, int, int);
190 static struct block
*gen_port6(int, int, int);
192 static int lookup_proto(const char *, int);
193 static struct block
*gen_protochain(int, int, int);
194 static struct block
*gen_proto(int, int, int);
195 static struct slist
*xfer_to_x(struct arth
*);
196 static struct slist
*xfer_to_a(struct arth
*);
197 static struct block
*gen_len(int, int);
199 static struct block
*gen_msg_abbrev(int type
);
209 /* XXX Round up to nearest long. */
210 n
= (n
+ sizeof(long) - 1) & ~(sizeof(long) - 1);
212 /* XXX Round up to structure boundary. */
216 cp
= &chunks
[cur_chunk
];
217 if (n
> cp
->n_left
) {
218 ++cp
, k
= ++cur_chunk
;
220 bpf_error("out of memory");
221 size
= CHUNK0SIZE
<< k
;
222 cp
->m
= (void *)malloc(size
);
223 memset((char *)cp
->m
, 0, size
);
226 bpf_error("out of memory");
229 return (void *)((char *)cp
->m
+ cp
->n_left
);
238 for (i
= 0; i
< NCHUNKS
; ++i
)
239 if (chunks
[i
].m
!= NULL
) {
246 * A strdup whose allocations are freed after code generation is over.
250 register const char *s
;
252 int n
= strlen(s
) + 1;
253 char *cp
= newchunk(n
);
259 static inline struct block
*
265 p
= (struct block
*)newchunk(sizeof(*p
));
272 static inline struct slist
*
278 p
= (struct slist
*)newchunk(sizeof(*p
));
284 static struct block
*
288 struct block
*b
= new_block(BPF_RET
|BPF_K
);
297 bpf_error("syntax error in filter expression");
300 static bpf_u_int32 netmask
;
305 pcap_compile(pcap_t
*p
, struct bpf_program
*program
,
306 char *buf
, int optimize
, bpf_u_int32 mask
)
315 if (setjmp(top_ctx
)) {
323 snaplen
= pcap_snapshot(p
);
325 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
326 "snaplen of 0 rejects all packets");
330 lex_init(buf
? buf
: "");
331 init_linktype(pcap_datalink(p
));
338 root
= gen_retblk(snaplen
);
340 if (optimize
&& !no_optimize
) {
343 (root
->s
.code
== (BPF_RET
|BPF_K
) && root
->s
.k
== 0))
344 bpf_error("expression rejects all packets");
346 program
->bf_insns
= icode_to_fcode(root
, &len
);
347 program
->bf_len
= len
;
355 * entry point for using the compiler with no pcap open
356 * pass in all the stuff that is needed explicitly instead.
359 pcap_compile_nopcap(int snaplen_arg
, int linktype_arg
,
360 struct bpf_program
*program
,
361 char *buf
, int optimize
, bpf_u_int32 mask
)
366 p
= pcap_open_dead(linktype_arg
, snaplen_arg
);
369 ret
= pcap_compile(p
, program
, buf
, optimize
, mask
);
375 * Clean up a "struct bpf_program" by freeing all the memory allocated
379 pcap_freecode(struct bpf_program
*program
)
382 if (program
->bf_insns
!= NULL
) {
383 free((char *)program
->bf_insns
);
384 program
->bf_insns
= NULL
;
389 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
390 * which of the jt and jf fields has been resolved and which is a pointer
391 * back to another unresolved block (or nil). At least one of the fields
392 * in each block is already resolved.
395 backpatch(list
, target
)
396 struct block
*list
, *target
;
413 * Merge the lists in b0 and b1, using the 'sense' field to indicate
414 * which of jt and jf is the link.
418 struct block
*b0
, *b1
;
420 register struct block
**p
= &b0
;
422 /* Find end of list. */
424 p
= !((*p
)->sense
) ? &JT(*p
) : &JF(*p
);
426 /* Concatenate the lists. */
434 backpatch(p
, gen_retblk(snaplen
));
435 p
->sense
= !p
->sense
;
436 backpatch(p
, gen_retblk(0));
442 struct block
*b0
, *b1
;
444 backpatch(b0
, b1
->head
);
445 b0
->sense
= !b0
->sense
;
446 b1
->sense
= !b1
->sense
;
448 b1
->sense
= !b1
->sense
;
454 struct block
*b0
, *b1
;
456 b0
->sense
= !b0
->sense
;
457 backpatch(b0
, b1
->head
);
458 b0
->sense
= !b0
->sense
;
467 b
->sense
= !b
->sense
;
470 static struct block
*
471 gen_cmp(offset
, size
, v
)
478 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
481 b
= new_block(JMP(BPF_JEQ
));
488 static struct block
*
489 gen_cmp_gt(offset
, size
, v
)
496 s
= new_stmt(BPF_LD
|BPF_ABS
|size
);
499 b
= new_block(JMP(BPF_JGT
));
506 static struct block
*
507 gen_mcmp(offset
, size
, v
, mask
)
512 struct block
*b
= gen_cmp(offset
, size
, v
);
515 if (mask
!= 0xffffffff) {
516 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
523 static struct block
*
524 gen_bcmp(offset
, size
, v
)
525 register u_int offset
, size
;
526 register const u_char
*v
;
528 register struct block
*b
, *tmp
;
532 register const u_char
*p
= &v
[size
- 4];
533 bpf_int32 w
= ((bpf_int32
)p
[0] << 24) |
534 ((bpf_int32
)p
[1] << 16) | ((bpf_int32
)p
[2] << 8) | p
[3];
536 tmp
= gen_cmp(offset
+ size
- 4, BPF_W
, w
);
543 register const u_char
*p
= &v
[size
- 2];
544 bpf_int32 w
= ((bpf_int32
)p
[0] << 8) | p
[1];
546 tmp
= gen_cmp(offset
+ size
- 2, BPF_H
, w
);
553 tmp
= gen_cmp(offset
, BPF_B
, (bpf_int32
)v
[0]);
561 static struct block
*
562 gen_ncmp(datasize
, offset
, mask
, jtype
, jvalue
, reverse
)
563 bpf_u_int32 datasize
, offset
, mask
, jtype
, jvalue
;
569 s
= new_stmt(BPF_LD
|datasize
|BPF_ABS
);
572 if (mask
!= 0xffffffff) {
573 s
->next
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
577 b
= new_block(JMP(jtype
));
580 if (reverse
&& (jtype
== BPF_JGT
|| jtype
== BPF_JGE
))
586 * Various code constructs need to know the layout of the data link
587 * layer. These variables give the necessary offsets.
591 * "off_linktype" is the offset to information in the link-layer header
592 * giving the packet type.
594 * For Ethernet, it's the offset of the Ethernet type field.
596 * For link-layer types that always use 802.2 headers, it's the
597 * offset of the LLC header.
599 * For PPP, it's the offset of the PPP type field.
601 * For Cisco HDLC, it's the offset of the CHDLC type field.
603 * For BSD loopback, it's the offset of the AF_ value.
605 * For Linux cooked sockets, it's the offset of the type field.
607 * It's set to -1 for no encapsulation, in which case, IP is assumed.
609 static u_int off_linktype
;
612 * TRUE if the link layer includes an ATM pseudo-header.
614 static int is_atm
= 0;
617 * These are offsets for the ATM pseudo-header.
619 static u_int off_vpi
;
620 static u_int off_vci
;
621 static u_int off_proto
;
624 * This is the offset to the message type for Q.2931 messages.
626 static u_int off_msg_type
;
629 * These are offsets to the beginning of the network-layer header.
631 * If the link layer never uses 802.2 LLC:
633 * "off_nl" and "off_nl_nosnap" are the same.
635 * If the link layer always uses 802.2 LLC:
637 * "off_nl" is the offset if there's a SNAP header following
640 * "off_nl_nosnap" is the offset if there's no SNAP header.
642 * If the link layer is Ethernet:
644 * "off_nl" is the offset if the packet is an Ethernet II packet
645 * (we assume no 802.3+802.2+SNAP);
647 * "off_nl_nosnap" is the offset if the packet is an 802.3 packet
648 * with an 802.2 header following it.
651 static u_int off_nl_nosnap
;
662 * Assume it's not raw ATM with a pseudo-header, for now.
678 off_nl
= 6; /* XXX in reality, variable! */
679 off_nl_nosnap
= 6; /* no 802.2 LLC */
684 off_nl
= 14; /* Ethernet II */
685 off_nl_nosnap
= 17; /* 802.3+802.2 */
690 * SLIP doesn't have a link level type. The 16 byte
691 * header is hacked into our SLIP driver.
695 off_nl_nosnap
= 16; /* no 802.2 LLC */
699 /* XXX this may be the same as the DLT_PPP_BSDOS case */
703 off_nl_nosnap
= 24; /* no 802.2 LLC */
710 off_nl_nosnap
= 4; /* no 802.2 LLC */
714 case DLT_C_HDLC
: /* BSD/OS Cisco HDLC */
715 case DLT_PPP_SERIAL
: /* NetBSD sync/async serial PPP */
718 off_nl_nosnap
= 4; /* no 802.2 LLC */
723 * This does no include the Ethernet header, and
724 * only covers session state.
728 off_nl_nosnap
= 8; /* no 802.2 LLC */
734 off_nl_nosnap
= 24; /* no 802.2 LLC */
739 * FDDI doesn't really have a link-level type field.
740 * We set "off_linktype" to the offset of the LLC header.
742 * To check for Ethernet types, we assume that SSAP = SNAP
743 * is being used and pick out the encapsulated Ethernet type.
744 * XXX - should we generate code to check for SNAP?
748 off_linktype
+= pcap_fddipad
;
750 off_nl
= 21; /* FDDI+802.2+SNAP */
751 off_nl_nosnap
= 16; /* FDDI+802.2 */
753 off_nl
+= pcap_fddipad
;
754 off_nl_nosnap
+= pcap_fddipad
;
760 * Token Ring doesn't really have a link-level type field.
761 * We set "off_linktype" to the offset of the LLC header.
763 * To check for Ethernet types, we assume that SSAP = SNAP
764 * is being used and pick out the encapsulated Ethernet type.
765 * XXX - should we generate code to check for SNAP?
767 * XXX - the header is actually variable-length.
768 * Some various Linux patched versions gave 38
769 * as "off_linktype" and 40 as "off_nl"; however,
770 * if a token ring packet has *no* routing
771 * information, i.e. is not source-routed, the correct
772 * values are 20 and 22, as they are in the vanilla code.
774 * A packet is source-routed iff the uppermost bit
775 * of the first byte of the source address, at an
776 * offset of 8, has the uppermost bit set. If the
777 * packet is source-routed, the total number of bytes
778 * of routing information is 2 plus bits 0x1F00 of
779 * the 16-bit value at an offset of 14 (shifted right
780 * 8 - figure out which byte that is).
783 off_nl
= 22; /* Token Ring+802.2+SNAP */
784 off_nl_nosnap
= 17; /* Token Ring+802.2 */
789 * 802.11 doesn't really have a link-level type field.
790 * We set "off_linktype" to the offset of the LLC header.
792 * To check for Ethernet types, we assume that SSAP = SNAP
793 * is being used and pick out the encapsulated Ethernet type.
794 * XXX - should we generate code to check for SNAP?
796 * XXX - the header is actually variable-length. We
797 * assume a 24-byte link-layer header, as appears in
798 * data frames in networks with no bridges.
801 off_nl
= 32; /* 802.11+802.2+SNAP */
802 off_nl_nosnap
= 27; /* 802.22+802.2 */
805 case DLT_PRISM_HEADER
:
807 * Same as 802.11, but with an additional header before
808 * the 802.11 header, containing a bunch of additional
809 * information including radio-level information.
811 * The header is 144 bytes long.
813 * XXX - same variable-length header problem; at least
814 * the Prism header is fixed-length.
816 off_linktype
= 144+24;
817 off_nl
= 144+32; /* Prism+802.11+802.2+SNAP */
818 off_nl_nosnap
= 144+27; /* Prism+802.11+802.2 */
821 case DLT_ATM_RFC1483
:
822 case DLT_ATM_CLIP
: /* Linux ATM defines this */
824 * assume routed, non-ISO PDUs
825 * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00)
828 off_nl
= 8; /* 802.2+SNAP */
829 off_nl_nosnap
= 3; /* 802.2 */
834 * Full Frontal ATM; you get AALn PDUs with an ATM
838 off_linktype
= SUNATM_PKT_BEGIN_POS
;
839 off_vpi
= SUNATM_VPI_POS
;
840 off_vci
= SUNATM_VCI_POS
;
841 off_proto
= PROTO_POS
;
842 off_msg_type
= SUNATM_PKT_BEGIN_POS
+MSG_TYPE_POS
;
843 off_nl
= SUNATM_PKT_BEGIN_POS
+8; /* 802.2+SNAP */
844 off_nl_nosnap
= SUNATM_PKT_BEGIN_POS
+3; /* 802.2 */
850 off_nl_nosnap
= 0; /* no 802.2 LLC */
853 case DLT_LINUX_SLL
: /* fake header for Linux cooked socket */
856 off_nl_nosnap
= 16; /* no 802.2 LLC */
861 * LocalTalk does have a 1-byte type field in the LLAP header,
862 * but really it just indicates whether there is a "short" or
863 * "long" DDP packet following.
867 off_nl_nosnap
= 0; /* no 802.2 LLC */
872 * XXX - we should set this to handle SNAP-encapsulated
873 * frames (NLPID of 0x80).
877 off_nl_nosnap
= 0; /* no 802.2 LLC */
880 bpf_error("unknown data link type %d", linktype
);
884 static struct block
*
891 s
= new_stmt(BPF_LD
|BPF_IMM
);
893 b
= new_block(JMP(BPF_JEQ
));
899 static inline struct block
*
902 return gen_uncond(1);
905 static inline struct block
*
908 return gen_uncond(0);
912 * Byte-swap a 32-bit number.
913 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
914 * big-endian platforms.)
916 #define SWAPLONG(y) \
917 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
919 static struct block
*
923 struct block
*b0
, *b1
, *b2
;
932 * OSI protocols always use 802.2 encapsulation.
933 * XXX - should we check both the DSAP and the
934 * SSAP, like this, or should we check just the
937 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
939 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
940 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
946 * NetBEUI always uses 802.2 encapsulation.
947 * XXX - should we check both the DSAP and the
948 * SSAP, like this, or should we check just the
951 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
953 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
954 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
962 * Ethernet_II frames, which are Ethernet
963 * frames with a frame type of ETHERTYPE_IPX;
965 * Ethernet_802.3 frames, which are 802.3
966 * frames (i.e., the type/length field is
967 * a length field, <= ETHERMTU, rather than
968 * a type field) with the first two bytes
969 * after the Ethernet/802.3 header being
972 * Ethernet_802.2 frames, which are 802.3
973 * frames with an 802.2 LLC header and
974 * with the IPX LSAP as the DSAP in the LLC
977 * Ethernet_SNAP frames, which are 802.3
978 * frames with an LLC header and a SNAP
979 * header and with an OUI of 0x000000
980 * (encapsulated Ethernet) and a protocol
981 * ID of ETHERTYPE_IPX in the SNAP header.
983 * XXX - should we generate the same code both
984 * for tests for LLCSAP_IPX and for ETHERTYPE_IPX?
988 * This generates code to check both for the
989 * IPX LSAP (Ethernet_802.2) and for Ethernet_802.3.
991 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
992 (bpf_int32
)LLCSAP_IPX
);
993 b1
= gen_cmp(off_linktype
+ 2, BPF_H
,
998 * Now we add code to check for SNAP frames with
999 * ETHERTYPE_IPX, i.e. Ethernet_SNAP.
1001 b0
= gen_snap(0x000000, ETHERTYPE_IPX
, 14);
1005 * Now we generate code to check for 802.3
1006 * frames in general.
1008 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1012 * Now add the check for 802.3 frames before the
1013 * check for Ethernet_802.2 and Ethernet_802.3,
1014 * as those checks should only be done on 802.3
1015 * frames, not on Ethernet frames.
1020 * Now add the check for Ethernet_II frames, and
1021 * do that before checking for the other frame
1024 b0
= gen_cmp(off_linktype
, BPF_H
,
1025 (bpf_int32
)ETHERTYPE_IPX
);
1029 case ETHERTYPE_ATALK
:
1030 case ETHERTYPE_AARP
:
1032 * EtherTalk (AppleTalk protocols on Ethernet link
1033 * layer) may use 802.2 encapsulation.
1037 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1038 * we check for an Ethernet type field less than
1039 * 1500, which means it's an 802.3 length field.
1041 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1045 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1046 * SNAP packets with an organization code of
1047 * 0x080007 (Apple, for Appletalk) and a protocol
1048 * type of ETHERTYPE_ATALK (Appletalk).
1050 * 802.2-encapsulated ETHERTYPE_AARP packets are
1051 * SNAP packets with an organization code of
1052 * 0x000000 (encapsulated Ethernet) and a protocol
1053 * type of ETHERTYPE_AARP (Appletalk ARP).
1055 if (proto
== ETHERTYPE_ATALK
)
1056 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
, 14);
1057 else /* proto == ETHERTYPE_AARP */
1058 b1
= gen_snap(0x000000, ETHERTYPE_AARP
, 14);
1062 * Check for Ethernet encapsulation (Ethertalk
1063 * phase 1?); we just check for the Ethernet
1066 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1072 if (proto
<= ETHERMTU
) {
1074 * This is an LLC SAP value, so the frames
1075 * that match would be 802.2 frames.
1076 * Check that the frame is an 802.2 frame
1077 * (i.e., that the length/type field is
1078 * a length field, <= ETHERMTU) and
1079 * then check the DSAP.
1081 b0
= gen_cmp_gt(off_linktype
, BPF_H
, ETHERMTU
);
1083 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1089 * This is an Ethernet type, so compare
1090 * the length/type field with it (if
1091 * the frame is an 802.2 frame, the length
1092 * field will be <= ETHERMTU, and, as
1093 * "proto" is > ETHERMTU, this test
1094 * will fail and the frame won't match,
1095 * which is what we want).
1097 return gen_cmp(off_linktype
, BPF_H
,
1103 case DLT_IEEE802_11
:
1104 case DLT_PRISM_HEADER
:
1107 case DLT_ATM_RFC1483
:
1109 return gen_llc(proto
);
1114 * Check for LLC encapsulation and then check the protocol.
1115 * XXX - also check for LANE and then check for an Ethernet
1118 b0
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
1119 b1
= gen_llc(proto
);
1128 * OSI protocols always use 802.2 encapsulation.
1129 * XXX - should we check both the DSAP and the
1130 * LSAP, like this, or should we check just the
1133 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1134 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1135 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1139 case LLCSAP_NETBEUI
:
1141 * NetBEUI always uses 802.2 encapsulation.
1142 * XXX - should we check both the DSAP and the
1143 * LSAP, like this, or should we check just the
1146 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1147 b1
= gen_cmp(off_linktype
+ 2, BPF_H
, (bpf_int32
)
1148 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1154 * Ethernet_II frames, which are Ethernet
1155 * frames with a frame type of ETHERTYPE_IPX;
1157 * Ethernet_802.3 frames, which have a frame
1158 * type of LINUX_SLL_P_802_3;
1160 * Ethernet_802.2 frames, which are 802.3
1161 * frames with an 802.2 LLC header (i.e, have
1162 * a frame type of LINUX_SLL_P_802_2) and
1163 * with the IPX LSAP as the DSAP in the LLC
1166 * Ethernet_SNAP frames, which are 802.3
1167 * frames with an LLC header and a SNAP
1168 * header and with an OUI of 0x000000
1169 * (encapsulated Ethernet) and a protocol
1170 * ID of ETHERTYPE_IPX in the SNAP header.
1172 * First, do the checks on LINUX_SLL_P_802_2
1173 * frames; generate the check for either
1174 * Ethernet_802.2 or Ethernet_SNAP frames, and
1175 * then put a check for LINUX_SLL_P_802_2 frames
1178 b0
= gen_cmp(off_linktype
+ 2, BPF_B
,
1179 (bpf_int32
)LLCSAP_IPX
);
1180 b1
= gen_snap(0x000000, ETHERTYPE_IPX
,
1183 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1187 * Now check for 802.3 frames and OR that with
1188 * the previous test.
1190 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_3
);
1194 * Now add the check for Ethernet_II frames, and
1195 * do that before checking for the other frame
1198 b0
= gen_cmp(off_linktype
, BPF_H
,
1199 (bpf_int32
)ETHERTYPE_IPX
);
1203 case ETHERTYPE_ATALK
:
1204 case ETHERTYPE_AARP
:
1206 * EtherTalk (AppleTalk protocols on Ethernet link
1207 * layer) may use 802.2 encapsulation.
1211 * Check for 802.2 encapsulation (EtherTalk phase 2?);
1212 * we check for the 802.2 protocol type in the
1213 * "Ethernet type" field.
1215 b0
= gen_cmp(off_linktype
, BPF_H
, LINUX_SLL_P_802_2
);
1218 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1219 * SNAP packets with an organization code of
1220 * 0x080007 (Apple, for Appletalk) and a protocol
1221 * type of ETHERTYPE_ATALK (Appletalk).
1223 * 802.2-encapsulated ETHERTYPE_AARP packets are
1224 * SNAP packets with an organization code of
1225 * 0x000000 (encapsulated Ethernet) and a protocol
1226 * type of ETHERTYPE_AARP (Appletalk ARP).
1228 if (proto
== ETHERTYPE_ATALK
)
1229 b1
= gen_snap(0x080007, ETHERTYPE_ATALK
,
1231 else /* proto == ETHERTYPE_AARP */
1232 b1
= gen_snap(0x000000, ETHERTYPE_AARP
,
1237 * Check for Ethernet encapsulation (Ethertalk
1238 * phase 1?); we just check for the Ethernet
1241 b0
= gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1247 if (proto
<= ETHERMTU
) {
1249 * This is an LLC SAP value, so the frames
1250 * that match would be 802.2 frames.
1251 * Check for the 802.2 protocol type
1252 * in the "Ethernet type" field, and
1253 * then check the DSAP.
1255 b0
= gen_cmp(off_linktype
, BPF_H
,
1257 b1
= gen_cmp(off_linktype
+ 2, BPF_B
,
1263 * This is an Ethernet type, so compare
1264 * the length/type field with it (if
1265 * the frame is an 802.2 frame, the length
1266 * field will be <= ETHERMTU, and, as
1267 * "proto" is > ETHERMTU, this test
1268 * will fail and the frame won't match,
1269 * which is what we want).
1271 return gen_cmp(off_linktype
, BPF_H
,
1278 case DLT_SLIP_BSDOS
:
1281 * These types don't provide any type field; packets
1284 * XXX - for IPv4, check for a version number of 4, and,
1285 * for IPv6, check for a version number of 6?
1291 case ETHERTYPE_IPV6
:
1293 return gen_true(); /* always true */
1296 return gen_false(); /* always false */
1301 case DLT_PPP_SERIAL
:
1304 * We use Ethernet protocol types inside libpcap;
1305 * map them to the corresponding PPP protocol types.
1310 proto
= PPP_IP
; /* XXX was 0x21 */
1314 case ETHERTYPE_IPV6
:
1323 case ETHERTYPE_ATALK
:
1337 * I'm assuming the "Bridging PDU"s that go
1338 * over PPP are Spanning Tree Protocol
1352 * We use Ethernet protocol types inside libpcap;
1353 * map them to the corresponding PPP protocol types.
1358 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_IP
);
1359 b1
= gen_cmp(off_linktype
, BPF_H
, PPP_VJC
);
1361 b0
= gen_cmp(off_linktype
, BPF_H
, PPP_VJNC
);
1366 case ETHERTYPE_IPV6
:
1376 case ETHERTYPE_ATALK
:
1390 * I'm assuming the "Bridging PDU"s that go
1391 * over PPP are Spanning Tree Protocol
1406 * For DLT_NULL, the link-layer header is a 32-bit
1407 * word containing an AF_ value in *host* byte order.
1409 * In addition, if we're reading a saved capture file,
1410 * the host byte order in the capture may not be the
1411 * same as the host byte order on this machine.
1413 * For DLT_LOOP, the link-layer header is a 32-bit
1414 * word containing an AF_ value in *network* byte order.
1416 * XXX - AF_ values may, unfortunately, be platform-
1417 * dependent; for example, FreeBSD's AF_INET6 is 24
1418 * whilst NetBSD's and OpenBSD's is 26.
1420 * This means that, when reading a capture file, just
1421 * checking for our AF_INET6 value won't work if the
1422 * capture file came from another OS.
1431 case ETHERTYPE_IPV6
:
1438 * Not a type on which we support filtering.
1439 * XXX - support those that have AF_ values
1440 * #defined on this platform, at least?
1445 if (linktype
== DLT_NULL
) {
1447 * The AF_ value is in host byte order, but
1448 * the BPF interpreter will convert it to
1449 * network byte order.
1451 * If this is a save file, and it's from a
1452 * machine with the opposite byte order to
1453 * ours, we byte-swap the AF_ value.
1455 * Then we run it through "htonl()", and
1456 * generate code to compare against the result.
1458 if (bpf_pcap
->sf
.rfile
!= NULL
&&
1459 bpf_pcap
->sf
.swapped
)
1460 proto
= SWAPLONG(proto
);
1461 proto
= htonl(proto
);
1463 return (gen_cmp(0, BPF_W
, (bpf_int32
)proto
));
1467 * XXX should we check for first fragment if the protocol
1474 case ETHERTYPE_IPV6
:
1475 return(gen_cmp(2, BPF_B
,
1476 (bpf_int32
)htonl(ARCTYPE_INET6
)));
1479 b0
= gen_cmp(2, BPF_B
, (bpf_int32
)htonl(ARCTYPE_IP
));
1480 b1
= gen_cmp(2, BPF_B
,
1481 (bpf_int32
)htonl(ARCTYPE_IP_OLD
));
1485 b0
= gen_cmp(2, BPF_B
, (bpf_int32
)htonl(ARCTYPE_ARP
));
1486 b1
= gen_cmp(2, BPF_B
,
1487 (bpf_int32
)htonl(ARCTYPE_ARP_OLD
));
1490 case ETHERTYPE_REVARP
:
1491 return(gen_cmp(2, BPF_B
,
1492 (bpf_int32
)htonl(ARCTYPE_REVARP
)));
1493 case ETHERTYPE_ATALK
:
1494 return(gen_cmp(2, BPF_B
,
1495 (bpf_int32
)htonl(ARCTYPE_ATALK
)));
1501 case ETHERTYPE_ATALK
:
1510 * XXX - assumes a 2-byte Frame Relay header with
1511 * DLCI and flags. What if the address is longer?
1517 * Check for the special NLPID for IP.
1519 return gen_cmp(2, BPF_H
, (0x03<<8) | 0xcc);
1522 case ETHERTYPE_IPV6
:
1524 * Check for the special NLPID for IPv6.
1526 return gen_cmp(2, BPF_H
, (0x03<<8) | 0x8e);
1531 * Check for several OSI protocols.
1533 * Frame Relay packets typically have an OSI
1534 * NLPID at the beginning; we check for each
1537 * What we check for is the NLPID and a frame
1538 * control field of UI, i.e. 0x03 followed
1541 b0
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO8473_CLNP
);
1542 b1
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO9542_ESIS
);
1543 b2
= gen_cmp(2, BPF_H
, (0x03<<8) | ISO10589_ISIS
);
1555 * All the types that have no encapsulation should either be
1556 * handled as DLT_SLIP, DLT_SLIP_BSDOS, and DLT_RAW are, if
1557 * all packets are IP packets, or should be handled in some
1558 * special case, if none of them are (if some are and some
1559 * aren't, the lack of encapsulation is a problem, as we'd
1560 * have to find some other way of determining the packet type).
1562 * Therefore, if "off_linktype" is -1, there's an error.
1564 if (off_linktype
== -1)
1568 * Any type not handled above should always have an Ethernet
1569 * type at an offset of "off_linktype". (PPP is partially
1570 * handled above - the protocol type is mapped from the
1571 * Ethernet and LLC types we use internally to the corresponding
1572 * PPP type - but the PPP type is always specified by a value
1573 * at "off_linktype", so we don't have to do the code generation
1576 return gen_cmp(off_linktype
, BPF_H
, (bpf_int32
)proto
);
1580 * Check for an LLC SNAP packet with a given organization code and
1581 * protocol type; we check the entire contents of the 802.2 LLC and
1582 * snap headers, checking for DSAP and SSAP of SNAP and a control
1583 * field of 0x03 in the LLC header, and for the specified organization
1584 * code and protocol type in the SNAP header.
1586 static struct block
*
1587 gen_snap(orgcode
, ptype
, offset
)
1588 bpf_u_int32 orgcode
;
1592 u_char snapblock
[8];
1594 snapblock
[0] = LLCSAP_SNAP
; /* DSAP = SNAP */
1595 snapblock
[1] = LLCSAP_SNAP
; /* SSAP = SNAP */
1596 snapblock
[2] = 0x03; /* control = UI */
1597 snapblock
[3] = (orgcode
>> 16); /* upper 8 bits of organization code */
1598 snapblock
[4] = (orgcode
>> 8); /* middle 8 bits of organization code */
1599 snapblock
[5] = (orgcode
>> 0); /* lower 8 bits of organization code */
1600 snapblock
[6] = (ptype
>> 8); /* upper 8 bits of protocol type */
1601 snapblock
[7] = (ptype
>> 0); /* lower 8 bits of protocol type */
1602 return gen_bcmp(offset
, 8, snapblock
);
1606 * Check for a given protocol value assuming an 802.2 LLC header.
1608 static struct block
*
1613 * XXX - handle token-ring variable-length header.
1618 return gen_cmp(off_linktype
, BPF_H
, (long)
1619 ((LLCSAP_ISONS
<< 8) | LLCSAP_ISONS
));
1621 case LLCSAP_NETBEUI
:
1622 return gen_cmp(off_linktype
, BPF_H
, (long)
1623 ((LLCSAP_NETBEUI
<< 8) | LLCSAP_NETBEUI
));
1627 * XXX - are there ever SNAP frames for IPX on
1628 * non-Ethernet 802.x networks?
1630 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)LLCSAP_IPX
);
1632 case ETHERTYPE_ATALK
:
1634 * 802.2-encapsulated ETHERTYPE_ATALK packets are
1635 * SNAP packets with an organization code of
1636 * 0x080007 (Apple, for Appletalk) and a protocol
1637 * type of ETHERTYPE_ATALK (Appletalk).
1639 * XXX - check for an organization code of
1640 * encapsulated Ethernet as well?
1642 return gen_snap(0x080007, ETHERTYPE_ATALK
, off_linktype
);
1646 * XXX - we don't have to check for IPX 802.3
1647 * here, but should we check for the IPX Ethertype?
1649 if (proto
<= ETHERMTU
) {
1651 * This is an LLC SAP value, so check
1654 return gen_cmp(off_linktype
, BPF_B
, (bpf_int32
)proto
);
1657 * This is an Ethernet type; we assume that it's
1658 * unlikely that it'll appear in the right place
1659 * at random, and therefore check only the
1660 * location that would hold the Ethernet type
1661 * in a SNAP frame with an organization code of
1662 * 0x000000 (encapsulated Ethernet).
1664 * XXX - if we were to check for the SNAP DSAP and
1665 * LSAP, as per XXX, and were also to check for an
1666 * organization code of 0x000000 (encapsulated
1667 * Ethernet), we'd do
1669 * return gen_snap(0x000000, proto,
1672 * here; for now, we don't, as per the above.
1673 * I don't know whether it's worth the extra CPU
1674 * time to do the right check or not.
1676 return gen_cmp(off_linktype
+6, BPF_H
, (bpf_int32
)proto
);
1681 static struct block
*
1682 gen_hostop(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1686 u_int src_off
, dst_off
;
1688 struct block
*b0
, *b1
;
1702 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1703 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1709 b0
= gen_hostop(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1710 b1
= gen_hostop(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1717 b0
= gen_linktype(proto
);
1718 b1
= gen_mcmp(offset
, BPF_W
, (bpf_int32
)addr
, mask
);
1724 static struct block
*
1725 gen_hostop6(addr
, mask
, dir
, proto
, src_off
, dst_off
)
1726 struct in6_addr
*addr
;
1727 struct in6_addr
*mask
;
1729 u_int src_off
, dst_off
;
1731 struct block
*b0
, *b1
;
1746 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1747 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1753 b0
= gen_hostop6(addr
, mask
, Q_SRC
, proto
, src_off
, dst_off
);
1754 b1
= gen_hostop6(addr
, mask
, Q_DST
, proto
, src_off
, dst_off
);
1761 /* this order is important */
1762 a
= (u_int32_t
*)addr
;
1763 m
= (u_int32_t
*)mask
;
1764 b1
= gen_mcmp(offset
+ 12, BPF_W
, ntohl(a
[3]), ntohl(m
[3]));
1765 b0
= gen_mcmp(offset
+ 8, BPF_W
, ntohl(a
[2]), ntohl(m
[2]));
1767 b0
= gen_mcmp(offset
+ 4, BPF_W
, ntohl(a
[1]), ntohl(m
[1]));
1769 b0
= gen_mcmp(offset
+ 0, BPF_W
, ntohl(a
[0]), ntohl(m
[0]));
1771 b0
= gen_linktype(proto
);
1777 static struct block
*
1778 gen_ehostop(eaddr
, dir
)
1779 register const u_char
*eaddr
;
1782 register struct block
*b0
, *b1
;
1786 return gen_bcmp(6, 6, eaddr
);
1789 return gen_bcmp(0, 6, eaddr
);
1792 b0
= gen_ehostop(eaddr
, Q_SRC
);
1793 b1
= gen_ehostop(eaddr
, Q_DST
);
1799 b0
= gen_ehostop(eaddr
, Q_SRC
);
1800 b1
= gen_ehostop(eaddr
, Q_DST
);
1809 * Like gen_ehostop, but for DLT_FDDI
1811 static struct block
*
1812 gen_fhostop(eaddr
, dir
)
1813 register const u_char
*eaddr
;
1816 struct block
*b0
, *b1
;
1821 return gen_bcmp(6 + 1 + pcap_fddipad
, 6, eaddr
);
1823 return gen_bcmp(6 + 1, 6, eaddr
);
1828 return gen_bcmp(0 + 1 + pcap_fddipad
, 6, eaddr
);
1830 return gen_bcmp(0 + 1, 6, eaddr
);
1834 b0
= gen_fhostop(eaddr
, Q_SRC
);
1835 b1
= gen_fhostop(eaddr
, Q_DST
);
1841 b0
= gen_fhostop(eaddr
, Q_SRC
);
1842 b1
= gen_fhostop(eaddr
, Q_DST
);
1851 * Like gen_ehostop, but for DLT_IEEE802 (Token Ring)
1853 static struct block
*
1854 gen_thostop(eaddr
, dir
)
1855 register const u_char
*eaddr
;
1858 register struct block
*b0
, *b1
;
1862 return gen_bcmp(8, 6, eaddr
);
1865 return gen_bcmp(2, 6, eaddr
);
1868 b0
= gen_thostop(eaddr
, Q_SRC
);
1869 b1
= gen_thostop(eaddr
, Q_DST
);
1875 b0
= gen_thostop(eaddr
, Q_SRC
);
1876 b1
= gen_thostop(eaddr
, Q_DST
);
1885 * This is quite tricky because there may be pad bytes in front of the
1886 * DECNET header, and then there are two possible data packet formats that
1887 * carry both src and dst addresses, plus 5 packet types in a format that
1888 * carries only the src node, plus 2 types that use a different format and
1889 * also carry just the src node.
1893 * Instead of doing those all right, we just look for data packets with
1894 * 0 or 1 bytes of padding. If you want to look at other packets, that
1895 * will require a lot more hacking.
1897 * To add support for filtering on DECNET "areas" (network numbers)
1898 * one would want to add a "mask" argument to this routine. That would
1899 * make the filter even more inefficient, although one could be clever
1900 * and not generate masking instructions if the mask is 0xFFFF.
1902 static struct block
*
1903 gen_dnhostop(addr
, dir
, base_off
)
1908 struct block
*b0
, *b1
, *b2
, *tmp
;
1909 u_int offset_lh
; /* offset if long header is received */
1910 u_int offset_sh
; /* offset if short header is received */
1915 offset_sh
= 1; /* follows flags */
1916 offset_lh
= 7; /* flgs,darea,dsubarea,HIORD */
1920 offset_sh
= 3; /* follows flags, dstnode */
1921 offset_lh
= 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */
1925 /* Inefficient because we do our Calvinball dance twice */
1926 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
1927 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
1933 /* Inefficient because we do our Calvinball dance twice */
1934 b0
= gen_dnhostop(addr
, Q_SRC
, base_off
);
1935 b1
= gen_dnhostop(addr
, Q_DST
, base_off
);
1940 bpf_error("ISO host filtering not implemented");
1945 b0
= gen_linktype(ETHERTYPE_DN
);
1946 /* Check for pad = 1, long header case */
1947 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
1948 (bpf_int32
)ntohs(0x0681), (bpf_int32
)ntohs(0x07FF));
1949 b1
= gen_cmp(base_off
+ 2 + 1 + offset_lh
,
1950 BPF_H
, (bpf_int32
)ntohs(addr
));
1952 /* Check for pad = 0, long header case */
1953 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x06, (bpf_int32
)0x7);
1954 b2
= gen_cmp(base_off
+ 2 + offset_lh
, BPF_H
, (bpf_int32
)ntohs(addr
));
1957 /* Check for pad = 1, short header case */
1958 tmp
= gen_mcmp(base_off
+ 2, BPF_H
,
1959 (bpf_int32
)ntohs(0x0281), (bpf_int32
)ntohs(0x07FF));
1960 b2
= gen_cmp(base_off
+ 2 + 1 + offset_sh
,
1961 BPF_H
, (bpf_int32
)ntohs(addr
));
1964 /* Check for pad = 0, short header case */
1965 tmp
= gen_mcmp(base_off
+ 2, BPF_B
, (bpf_int32
)0x02, (bpf_int32
)0x7);
1966 b2
= gen_cmp(base_off
+ 2 + offset_sh
, BPF_H
, (bpf_int32
)ntohs(addr
));
1970 /* Combine with test for linktype */
1975 static struct block
*
1976 gen_host(addr
, mask
, proto
, dir
)
1982 struct block
*b0
, *b1
;
1987 b0
= gen_host(addr
, mask
, Q_IP
, dir
);
1988 if (off_linktype
!= -1) {
1989 b1
= gen_host(addr
, mask
, Q_ARP
, dir
);
1991 b0
= gen_host(addr
, mask
, Q_RARP
, dir
);
1997 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_IP
,
1998 off_nl
+ 12, off_nl
+ 16);
2001 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_REVARP
,
2002 off_nl
+ 14, off_nl
+ 24);
2005 return gen_hostop(addr
, mask
, dir
, ETHERTYPE_ARP
,
2006 off_nl
+ 14, off_nl
+ 24);
2009 bpf_error("'tcp' modifier applied to host");
2012 bpf_error("'sctp' modifier applied to host");
2015 bpf_error("'udp' modifier applied to host");
2018 bpf_error("'icmp' modifier applied to host");
2021 bpf_error("'igmp' modifier applied to host");
2024 bpf_error("'igrp' modifier applied to host");
2027 bpf_error("'pim' modifier applied to host");
2030 bpf_error("'vrrp' modifier applied to host");
2033 bpf_error("ATALK host filtering not implemented");
2036 bpf_error("AARP host filtering not implemented");
2039 return gen_dnhostop(addr
, dir
, off_nl
);
2042 bpf_error("SCA host filtering not implemented");
2045 bpf_error("LAT host filtering not implemented");
2048 bpf_error("MOPDL host filtering not implemented");
2051 bpf_error("MOPRC host filtering not implemented");
2055 bpf_error("'ip6' modifier applied to ip host");
2058 bpf_error("'icmp6' modifier applied to host");
2062 bpf_error("'ah' modifier applied to host");
2065 bpf_error("'esp' modifier applied to host");
2068 bpf_error("ISO host filtering not implemented");
2071 bpf_error("'esis' modifier applied to host");
2074 bpf_error("'isis' modifier applied to host");
2077 bpf_error("'clnp' modifier applied to host");
2080 bpf_error("'stp' modifier applied to host");
2083 bpf_error("IPX host filtering not implemented");
2086 bpf_error("'netbeui' modifier applied to host");
2095 static struct block
*
2096 gen_host6(addr
, mask
, proto
, dir
)
2097 struct in6_addr
*addr
;
2098 struct in6_addr
*mask
;
2105 return gen_host6(addr
, mask
, Q_IPV6
, dir
);
2108 bpf_error("'ip' modifier applied to ip6 host");
2111 bpf_error("'rarp' modifier applied to ip6 host");
2114 bpf_error("'arp' modifier applied to ip6 host");
2117 bpf_error("'sctp' modifier applied to host");
2120 bpf_error("'tcp' modifier applied to host");
2123 bpf_error("'udp' modifier applied to host");
2126 bpf_error("'icmp' modifier applied to host");
2129 bpf_error("'igmp' modifier applied to host");
2132 bpf_error("'igrp' modifier applied to host");
2135 bpf_error("'pim' modifier applied to host");
2138 bpf_error("'vrrp' modifier applied to host");
2141 bpf_error("ATALK host filtering not implemented");
2144 bpf_error("AARP host filtering not implemented");
2147 bpf_error("'decnet' modifier applied to ip6 host");
2150 bpf_error("SCA host filtering not implemented");
2153 bpf_error("LAT host filtering not implemented");
2156 bpf_error("MOPDL host filtering not implemented");
2159 bpf_error("MOPRC host filtering not implemented");
2162 return gen_hostop6(addr
, mask
, dir
, ETHERTYPE_IPV6
,
2163 off_nl
+ 8, off_nl
+ 24);
2166 bpf_error("'icmp6' modifier applied to host");
2169 bpf_error("'ah' modifier applied to host");
2172 bpf_error("'esp' modifier applied to host");
2175 bpf_error("ISO host filtering not implemented");
2178 bpf_error("'esis' modifier applied to host");
2181 bpf_error("'isis' modifier applied to host");
2184 bpf_error("'clnp' modifier applied to host");
2187 bpf_error("'stp' modifier applied to host");
2190 bpf_error("IPX host filtering not implemented");
2193 bpf_error("'netbeui' modifier applied to host");
2203 static struct block
*
2204 gen_gateway(eaddr
, alist
, proto
, dir
)
2205 const u_char
*eaddr
;
2206 bpf_u_int32
**alist
;
2210 struct block
*b0
, *b1
, *tmp
;
2213 bpf_error("direction applied to 'gateway'");
2220 if (linktype
== DLT_EN10MB
)
2221 b0
= gen_ehostop(eaddr
, Q_OR
);
2222 else if (linktype
== DLT_FDDI
)
2223 b0
= gen_fhostop(eaddr
, Q_OR
);
2224 else if (linktype
== DLT_IEEE802
)
2225 b0
= gen_thostop(eaddr
, Q_OR
);
2228 "'gateway' supported only on ethernet, FDDI or token ring");
2230 b1
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2232 tmp
= gen_host(**alist
++, 0xffffffff, proto
, Q_OR
);
2240 bpf_error("illegal modifier of 'gateway'");
2246 gen_proto_abbrev(proto
)
2257 b1
= gen_proto(IPPROTO_SCTP
, Q_IP
, Q_DEFAULT
);
2259 b0
= gen_proto(IPPROTO_SCTP
, Q_IPV6
, Q_DEFAULT
);
2265 b1
= gen_proto(IPPROTO_TCP
, Q_IP
, Q_DEFAULT
);
2267 b0
= gen_proto(IPPROTO_TCP
, Q_IPV6
, Q_DEFAULT
);
2273 b1
= gen_proto(IPPROTO_UDP
, Q_IP
, Q_DEFAULT
);
2275 b0
= gen_proto(IPPROTO_UDP
, Q_IPV6
, Q_DEFAULT
);
2281 b1
= gen_proto(IPPROTO_ICMP
, Q_IP
, Q_DEFAULT
);
2284 #ifndef IPPROTO_IGMP
2285 #define IPPROTO_IGMP 2
2289 b1
= gen_proto(IPPROTO_IGMP
, Q_IP
, Q_DEFAULT
);
2292 #ifndef IPPROTO_IGRP
2293 #define IPPROTO_IGRP 9
2296 b1
= gen_proto(IPPROTO_IGRP
, Q_IP
, Q_DEFAULT
);
2300 #define IPPROTO_PIM 103
2304 b1
= gen_proto(IPPROTO_PIM
, Q_IP
, Q_DEFAULT
);
2306 b0
= gen_proto(IPPROTO_PIM
, Q_IPV6
, Q_DEFAULT
);
2311 #ifndef IPPROTO_VRRP
2312 #define IPPROTO_VRRP 112
2316 b1
= gen_proto(IPPROTO_VRRP
, Q_IP
, Q_DEFAULT
);
2320 b1
= gen_linktype(ETHERTYPE_IP
);
2324 b1
= gen_linktype(ETHERTYPE_ARP
);
2328 b1
= gen_linktype(ETHERTYPE_REVARP
);
2332 bpf_error("link layer applied in wrong context");
2335 b1
= gen_linktype(ETHERTYPE_ATALK
);
2339 b1
= gen_linktype(ETHERTYPE_AARP
);
2343 b1
= gen_linktype(ETHERTYPE_DN
);
2347 b1
= gen_linktype(ETHERTYPE_SCA
);
2351 b1
= gen_linktype(ETHERTYPE_LAT
);
2355 b1
= gen_linktype(ETHERTYPE_MOPDL
);
2359 b1
= gen_linktype(ETHERTYPE_MOPRC
);
2364 b1
= gen_linktype(ETHERTYPE_IPV6
);
2367 #ifndef IPPROTO_ICMPV6
2368 #define IPPROTO_ICMPV6 58
2371 b1
= gen_proto(IPPROTO_ICMPV6
, Q_IPV6
, Q_DEFAULT
);
2376 #define IPPROTO_AH 51
2379 b1
= gen_proto(IPPROTO_AH
, Q_IP
, Q_DEFAULT
);
2381 b0
= gen_proto(IPPROTO_AH
, Q_IPV6
, Q_DEFAULT
);
2387 #define IPPROTO_ESP 50
2390 b1
= gen_proto(IPPROTO_ESP
, Q_IP
, Q_DEFAULT
);
2392 b0
= gen_proto(IPPROTO_ESP
, Q_IPV6
, Q_DEFAULT
);
2398 b1
= gen_linktype(LLCSAP_ISONS
);
2402 b1
= gen_proto(ISO9542_ESIS
, Q_ISO
, Q_DEFAULT
);
2406 b1
= gen_proto(ISO10589_ISIS
, Q_ISO
, Q_DEFAULT
);
2410 b1
= gen_proto(ISO8473_CLNP
, Q_ISO
, Q_DEFAULT
);
2414 b1
= gen_linktype(LLCSAP_8021D
);
2418 b1
= gen_linktype(LLCSAP_IPX
);
2422 b1
= gen_linktype(LLCSAP_NETBEUI
);
2431 static struct block
*
2438 s
= new_stmt(BPF_LD
|BPF_H
|BPF_ABS
);
2439 s
->s
.k
= off_nl
+ 6;
2440 b
= new_block(JMP(BPF_JSET
));
2448 static struct block
*
2449 gen_portatom(off
, v
)
2456 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
2459 s
->next
= new_stmt(BPF_LD
|BPF_IND
|BPF_H
);
2460 s
->next
->s
.k
= off_nl
+ off
;
2462 b
= new_block(JMP(BPF_JEQ
));
2470 static struct block
*
2471 gen_portatom6(off
, v
)
2475 return gen_cmp(off_nl
+ 40 + off
, BPF_H
, v
);
2480 gen_portop(port
, proto
, dir
)
2481 int port
, proto
, dir
;
2483 struct block
*b0
, *b1
, *tmp
;
2485 /* ip proto 'proto' */
2486 tmp
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)proto
);
2492 b1
= gen_portatom(0, (bpf_int32
)port
);
2496 b1
= gen_portatom(2, (bpf_int32
)port
);
2501 tmp
= gen_portatom(0, (bpf_int32
)port
);
2502 b1
= gen_portatom(2, (bpf_int32
)port
);
2507 tmp
= gen_portatom(0, (bpf_int32
)port
);
2508 b1
= gen_portatom(2, (bpf_int32
)port
);
2520 static struct block
*
2521 gen_port(port
, ip_proto
, dir
)
2526 struct block
*b0
, *b1
, *tmp
;
2528 /* ether proto ip */
2529 b0
= gen_linktype(ETHERTYPE_IP
);
2535 b1
= gen_portop(port
, ip_proto
, dir
);
2539 tmp
= gen_portop(port
, IPPROTO_TCP
, dir
);
2540 b1
= gen_portop(port
, IPPROTO_UDP
, dir
);
2542 tmp
= gen_portop(port
, IPPROTO_SCTP
, dir
);
2555 gen_portop6(port
, proto
, dir
)
2556 int port
, proto
, dir
;
2558 struct block
*b0
, *b1
, *tmp
;
2560 /* ip proto 'proto' */
2561 b0
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)proto
);
2565 b1
= gen_portatom6(0, (bpf_int32
)port
);
2569 b1
= gen_portatom6(2, (bpf_int32
)port
);
2574 tmp
= gen_portatom6(0, (bpf_int32
)port
);
2575 b1
= gen_portatom6(2, (bpf_int32
)port
);
2580 tmp
= gen_portatom6(0, (bpf_int32
)port
);
2581 b1
= gen_portatom6(2, (bpf_int32
)port
);
2593 static struct block
*
2594 gen_port6(port
, ip_proto
, dir
)
2599 struct block
*b0
, *b1
, *tmp
;
2601 /* ether proto ip */
2602 b0
= gen_linktype(ETHERTYPE_IPV6
);
2608 b1
= gen_portop6(port
, ip_proto
, dir
);
2612 tmp
= gen_portop6(port
, IPPROTO_TCP
, dir
);
2613 b1
= gen_portop6(port
, IPPROTO_UDP
, dir
);
2615 tmp
= gen_portop6(port
, IPPROTO_SCTP
, dir
);
2628 lookup_proto(name
, proto
)
2629 register const char *name
;
2639 v
= pcap_nametoproto(name
);
2640 if (v
== PROTO_UNDEF
)
2641 bpf_error("unknown ip proto '%s'", name
);
2645 /* XXX should look up h/w protocol type based on linktype */
2646 v
= pcap_nametoeproto(name
);
2647 if (v
== PROTO_UNDEF
)
2648 bpf_error("unknown ether proto '%s'", name
);
2652 if (strcmp(name
, "esis") == 0)
2654 else if (strcmp(name
, "isis") == 0)
2656 else if (strcmp(name
, "clnp") == 0)
2659 bpf_error("unknown osi proto '%s'", name
);
2679 static struct block
*
2680 gen_protochain(v
, proto
, dir
)
2685 #ifdef NO_PROTOCHAIN
2686 return gen_proto(v
, proto
, dir
);
2688 struct block
*b0
, *b
;
2689 struct slist
*s
[100];
2690 int fix2
, fix3
, fix4
, fix5
;
2691 int ahcheck
, again
, end
;
2693 int reg2
= alloc_reg();
2695 memset(s
, 0, sizeof(s
));
2696 fix2
= fix3
= fix4
= fix5
= 0;
2703 b0
= gen_protochain(v
, Q_IP
, dir
);
2704 b
= gen_protochain(v
, Q_IPV6
, dir
);
2708 bpf_error("bad protocol applied for 'protochain'");
2712 no_optimize
= 1; /*this code is not compatible with optimzer yet */
2715 * s[0] is a dummy entry to protect other BPF insn from damaged
2716 * by s[fix] = foo with uninitialized variable "fix". It is somewhat
2717 * hard to find interdependency made by jump table fixup.
2720 s
[i
] = new_stmt(0); /*dummy*/
2725 b0
= gen_linktype(ETHERTYPE_IP
);
2728 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2729 s
[i
]->s
.k
= off_nl
+ 9;
2731 /* X = ip->ip_hl << 2 */
2732 s
[i
] = new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
2738 b0
= gen_linktype(ETHERTYPE_IPV6
);
2740 /* A = ip6->ip_nxt */
2741 s
[i
] = new_stmt(BPF_LD
|BPF_ABS
|BPF_B
);
2742 s
[i
]->s
.k
= off_nl
+ 6;
2744 /* X = sizeof(struct ip6_hdr) */
2745 s
[i
] = new_stmt(BPF_LDX
|BPF_IMM
);
2751 bpf_error("unsupported proto to gen_protochain");
2755 /* again: if (A == v) goto end; else fall through; */
2757 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2759 s
[i
]->s
.jt
= NULL
; /*later*/
2760 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2764 #ifndef IPPROTO_NONE
2765 #define IPPROTO_NONE 59
2767 /* if (A == IPPROTO_NONE) goto end */
2768 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2769 s
[i
]->s
.jt
= NULL
; /*later*/
2770 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2771 s
[i
]->s
.k
= IPPROTO_NONE
;
2772 s
[fix5
]->s
.jf
= s
[i
];
2777 if (proto
== Q_IPV6
) {
2778 int v6start
, v6end
, v6advance
, j
;
2781 /* if (A == IPPROTO_HOPOPTS) goto v6advance */
2782 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2783 s
[i
]->s
.jt
= NULL
; /*later*/
2784 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2785 s
[i
]->s
.k
= IPPROTO_HOPOPTS
;
2786 s
[fix2
]->s
.jf
= s
[i
];
2788 /* if (A == IPPROTO_DSTOPTS) goto v6advance */
2789 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2790 s
[i
]->s
.jt
= NULL
; /*later*/
2791 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2792 s
[i
]->s
.k
= IPPROTO_DSTOPTS
;
2794 /* if (A == IPPROTO_ROUTING) goto v6advance */
2795 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2796 s
[i
]->s
.jt
= NULL
; /*later*/
2797 s
[i
]->s
.jf
= NULL
; /*update in next stmt*/
2798 s
[i
]->s
.k
= IPPROTO_ROUTING
;
2800 /* if (A == IPPROTO_FRAGMENT) goto v6advance; else goto ahcheck; */
2801 s
[i
- 1]->s
.jf
= s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2802 s
[i
]->s
.jt
= NULL
; /*later*/
2803 s
[i
]->s
.jf
= NULL
; /*later*/
2804 s
[i
]->s
.k
= IPPROTO_FRAGMENT
;
2815 * X = X + (P[X + 1] + 1) * 8;
2818 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2820 /* A = P[X + packet head] */
2821 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2825 s
[i
] = new_stmt(BPF_ST
);
2829 s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2832 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2836 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2838 /* A = P[X + packet head]; */
2839 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2843 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2847 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
2851 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2854 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
2858 /* goto again; (must use BPF_JA for backward jump) */
2859 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
2860 s
[i
]->s
.k
= again
- i
- 1;
2861 s
[i
- 1]->s
.jf
= s
[i
];
2865 for (j
= v6start
; j
<= v6end
; j
++)
2866 s
[j
]->s
.jt
= s
[v6advance
];
2871 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2873 s
[fix2
]->s
.jf
= s
[i
];
2879 /* if (A == IPPROTO_AH) then fall through; else goto end; */
2880 s
[i
] = new_stmt(BPF_JMP
|BPF_JEQ
|BPF_K
);
2881 s
[i
]->s
.jt
= NULL
; /*later*/
2882 s
[i
]->s
.jf
= NULL
; /*later*/
2883 s
[i
]->s
.k
= IPPROTO_AH
;
2885 s
[fix3
]->s
.jf
= s
[ahcheck
];
2892 * X = X + (P[X + 1] + 2) * 4;
2895 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2897 /* A = P[X + packet head]; */
2898 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2902 s
[i
] = new_stmt(BPF_ST
);
2906 s
[i
- 1]->s
.jt
= s
[i
] = new_stmt(BPF_MISC
|BPF_TXA
);
2909 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2913 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2915 /* A = P[X + packet head] */
2916 s
[i
] = new_stmt(BPF_LD
|BPF_IND
|BPF_B
);
2920 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2924 s
[i
] = new_stmt(BPF_ALU
|BPF_MUL
|BPF_K
);
2928 s
[i
] = new_stmt(BPF_MISC
|BPF_TAX
);
2931 s
[i
] = new_stmt(BPF_LD
|BPF_MEM
);
2935 /* goto again; (must use BPF_JA for backward jump) */
2936 s
[i
] = new_stmt(BPF_JMP
|BPF_JA
);
2937 s
[i
]->s
.k
= again
- i
- 1;
2942 s
[i
] = new_stmt(BPF_ALU
|BPF_ADD
|BPF_K
);
2944 s
[fix2
]->s
.jt
= s
[end
];
2945 s
[fix4
]->s
.jf
= s
[end
];
2946 s
[fix5
]->s
.jt
= s
[end
];
2953 for (i
= 0; i
< max
- 1; i
++)
2954 s
[i
]->next
= s
[i
+ 1];
2955 s
[max
- 1]->next
= NULL
;
2960 b
= new_block(JMP(BPF_JEQ
));
2961 b
->stmts
= s
[1]; /*remember, s[0] is dummy*/
2971 static struct block
*
2972 gen_proto(v
, proto
, dir
)
2977 struct block
*b0
, *b1
;
2979 if (dir
!= Q_DEFAULT
)
2980 bpf_error("direction applied to 'proto'");
2985 b0
= gen_proto(v
, Q_IP
, dir
);
2986 b1
= gen_proto(v
, Q_IPV6
, dir
);
2993 b0
= gen_linktype(ETHERTYPE_IP
);
2995 b1
= gen_cmp(off_nl
+ 9, BPF_B
, (bpf_int32
)v
);
2997 b1
= gen_protochain(v
, Q_IP
);
3007 * Frame Relay packets typically have an OSI
3008 * NLPID at the beginning; "gen_linktype(LLCSAP_ISONS)"
3009 * generates code to check for all the OSI
3010 * NLPIDs, so calling it and then adding a check
3011 * for the particular NLPID for which we're
3012 * looking is bogus, as we can just check for
3015 * What we check for is the NLPID and a frame
3016 * control field value of UI, i.e. 0x03 followed
3019 * XXX - assumes a 2-byte Frame Relay header with
3020 * DLCI and flags. What if the address is longer?
3022 * XXX - what about SNAP-encapsulated frames?
3024 return gen_cmp(2, BPF_H
, (0x03<<8) | v
);
3028 b0
= gen_linktype(LLCSAP_ISONS
);
3029 b1
= gen_cmp(off_nl_nosnap
, BPF_B
, (long)v
);
3035 bpf_error("arp does not encapsulate another protocol");
3039 bpf_error("rarp does not encapsulate another protocol");
3043 bpf_error("atalk encapsulation is not specifiable");
3047 bpf_error("decnet encapsulation is not specifiable");
3051 bpf_error("sca does not encapsulate another protocol");
3055 bpf_error("lat does not encapsulate another protocol");
3059 bpf_error("moprc does not encapsulate another protocol");
3063 bpf_error("mopdl does not encapsulate another protocol");
3067 return gen_linktype(v
);
3070 bpf_error("'udp proto' is bogus");
3074 bpf_error("'tcp proto' is bogus");
3078 bpf_error("'sctp proto' is bogus");
3082 bpf_error("'icmp proto' is bogus");
3086 bpf_error("'igmp proto' is bogus");
3090 bpf_error("'igrp proto' is bogus");
3094 bpf_error("'pim proto' is bogus");
3098 bpf_error("'vrrp proto' is bogus");
3103 b0
= gen_linktype(ETHERTYPE_IPV6
);
3105 b1
= gen_cmp(off_nl
+ 6, BPF_B
, (bpf_int32
)v
);
3107 b1
= gen_protochain(v
, Q_IPV6
);
3113 bpf_error("'icmp6 proto' is bogus");
3117 bpf_error("'ah proto' is bogus");
3120 bpf_error("'ah proto' is bogus");
3123 bpf_error("'stp proto' is bogus");
3126 bpf_error("'ipx proto' is bogus");
3129 bpf_error("'netbeui proto' is bogus");
3140 register const char *name
;
3143 int proto
= q
.proto
;
3147 bpf_u_int32 mask
, addr
;
3149 bpf_u_int32
**alist
;
3152 struct sockaddr_in
*sin
;
3153 struct sockaddr_in6
*sin6
;
3154 struct addrinfo
*res
, *res0
;
3155 struct in6_addr mask128
;
3157 struct block
*b
, *tmp
;
3158 int port
, real_proto
;
3163 addr
= pcap_nametonetaddr(name
);
3165 bpf_error("unknown network '%s'", name
);
3166 /* Left justify network addr and calculate its network mask */
3168 while (addr
&& (addr
& 0xff000000) == 0) {
3172 return gen_host(addr
, mask
, proto
, dir
);
3176 if (proto
== Q_LINK
) {
3180 eaddr
= pcap_ether_hostton(name
);
3183 "unknown ether host '%s'", name
);
3184 b
= gen_ehostop(eaddr
, dir
);
3189 eaddr
= pcap_ether_hostton(name
);
3192 "unknown FDDI host '%s'", name
);
3193 b
= gen_fhostop(eaddr
, dir
);
3198 eaddr
= pcap_ether_hostton(name
);
3201 "unknown token ring host '%s'", name
);
3202 b
= gen_thostop(eaddr
, dir
);
3208 "only ethernet/FDDI/token ring supports link-level host name");
3211 } else if (proto
== Q_DECNET
) {
3212 unsigned short dn_addr
= __pcap_nametodnaddr(name
);
3214 * I don't think DECNET hosts can be multihomed, so
3215 * there is no need to build up a list of addresses
3217 return (gen_host(dn_addr
, 0, proto
, dir
));
3220 alist
= pcap_nametoaddr(name
);
3221 if (alist
== NULL
|| *alist
== NULL
)
3222 bpf_error("unknown host '%s'", name
);
3224 if (off_linktype
== -1 && tproto
== Q_DEFAULT
)
3226 b
= gen_host(**alist
++, 0xffffffff, tproto
, dir
);
3228 tmp
= gen_host(**alist
++, 0xffffffff,
3235 memset(&mask128
, 0xff, sizeof(mask128
));
3236 res0
= res
= pcap_nametoaddrinfo(name
);
3238 bpf_error("unknown host '%s'", name
);
3240 tproto
= tproto6
= proto
;
3241 if (off_linktype
== -1 && tproto
== Q_DEFAULT
) {
3245 for (res
= res0
; res
; res
= res
->ai_next
) {
3246 switch (res
->ai_family
) {
3248 if (tproto
== Q_IPV6
)
3251 sin
= (struct sockaddr_in
*)
3253 tmp
= gen_host(ntohl(sin
->sin_addr
.s_addr
),
3254 0xffffffff, tproto
, dir
);
3257 if (tproto6
== Q_IP
)
3260 sin6
= (struct sockaddr_in6
*)
3262 tmp
= gen_host6(&sin6
->sin6_addr
,
3263 &mask128
, tproto6
, dir
);
3274 bpf_error("unknown host '%s'%s", name
,
3275 (proto
== Q_DEFAULT
)
3277 : " for specified address family");
3284 if (proto
!= Q_DEFAULT
&&
3285 proto
!= Q_UDP
&& proto
!= Q_TCP
&& proto
!= Q_SCTP
)
3286 bpf_error("illegal qualifier of 'port'");
3287 if (pcap_nametoport(name
, &port
, &real_proto
) == 0)
3288 bpf_error("unknown port '%s'", name
);
3289 if (proto
== Q_UDP
) {
3290 if (real_proto
== IPPROTO_TCP
)
3291 bpf_error("port '%s' is tcp", name
);
3292 else if (real_proto
== IPPROTO_SCTP
)
3293 bpf_error("port '%s' is sctp", name
);
3295 /* override PROTO_UNDEF */
3296 real_proto
= IPPROTO_UDP
;
3298 if (proto
== Q_TCP
) {
3299 if (real_proto
== IPPROTO_UDP
)
3300 bpf_error("port '%s' is udp", name
);
3302 else if (real_proto
== IPPROTO_SCTP
)
3303 bpf_error("port '%s' is sctp", name
);
3305 /* override PROTO_UNDEF */
3306 real_proto
= IPPROTO_TCP
;
3308 if (proto
== Q_SCTP
) {
3309 if (real_proto
== IPPROTO_UDP
)
3310 bpf_error("port '%s' is udp", name
);
3312 else if (real_proto
== IPPROTO_TCP
)
3313 bpf_error("port '%s' is tcp", name
);
3315 /* override PROTO_UNDEF */
3316 real_proto
= IPPROTO_SCTP
;
3319 return gen_port(port
, real_proto
, dir
);
3323 b
= gen_port(port
, real_proto
, dir
);
3324 gen_or(gen_port6(port
, real_proto
, dir
), b
);
3331 eaddr
= pcap_ether_hostton(name
);
3333 bpf_error("unknown ether host: %s", name
);
3335 alist
= pcap_nametoaddr(name
);
3336 if (alist
== NULL
|| *alist
== NULL
)
3337 bpf_error("unknown host '%s'", name
);
3338 b
= gen_gateway(eaddr
, alist
, proto
, dir
);
3342 bpf_error("'gateway' not supported in this configuration");
3346 real_proto
= lookup_proto(name
, proto
);
3347 if (real_proto
>= 0)
3348 return gen_proto(real_proto
, proto
, dir
);
3350 bpf_error("unknown protocol: %s", name
);
3353 real_proto
= lookup_proto(name
, proto
);
3354 if (real_proto
>= 0)
3355 return gen_protochain(real_proto
, proto
, dir
);
3357 bpf_error("unknown protocol: %s", name
);
3369 gen_mcode(s1
, s2
, masklen
, q
)
3370 register const char *s1
, *s2
;
3371 register int masklen
;
3374 register int nlen
, mlen
;
3377 nlen
= __pcap_atoin(s1
, &n
);
3378 /* Promote short ipaddr */
3382 mlen
= __pcap_atoin(s2
, &m
);
3383 /* Promote short ipaddr */
3386 bpf_error("non-network bits set in \"%s mask %s\"",
3389 /* Convert mask len to mask */
3391 bpf_error("mask length must be <= 32");
3392 m
= 0xffffffff << (32 - masklen
);
3394 bpf_error("non-network bits set in \"%s/%d\"",
3401 return gen_host(n
, m
, q
.proto
, q
.dir
);
3404 bpf_error("Mask syntax for networks only");
3411 register const char *s
;
3416 int proto
= q
.proto
;
3422 else if (q
.proto
== Q_DECNET
)
3423 vlen
= __pcap_atodn(s
, &v
);
3425 vlen
= __pcap_atoin(s
, &v
);
3432 if (proto
== Q_DECNET
)
3433 return gen_host(v
, 0, proto
, dir
);
3434 else if (proto
== Q_LINK
) {
3435 bpf_error("illegal link layer address");
3438 if (s
== NULL
&& q
.addr
== Q_NET
) {
3439 /* Promote short net number */
3440 while (v
&& (v
& 0xff000000) == 0) {
3445 /* Promote short ipaddr */
3449 return gen_host(v
, mask
, proto
, dir
);
3454 proto
= IPPROTO_UDP
;
3455 else if (proto
== Q_TCP
)
3456 proto
= IPPROTO_TCP
;
3457 else if (proto
== Q_SCTP
)
3458 proto
= IPPROTO_SCTP
;
3459 else if (proto
== Q_DEFAULT
)
3460 proto
= PROTO_UNDEF
;
3462 bpf_error("illegal qualifier of 'port'");
3465 return gen_port((int)v
, proto
, dir
);
3469 b
= gen_port((int)v
, proto
, dir
);
3470 gen_or(gen_port6((int)v
, proto
, dir
), b
);
3476 bpf_error("'gateway' requires a name");
3480 return gen_proto((int)v
, proto
, dir
);
3483 return gen_protochain((int)v
, proto
, dir
);
3498 gen_mcode6(s1
, s2
, masklen
, q
)
3499 register const char *s1
, *s2
;
3500 register int masklen
;
3503 struct addrinfo
*res
;
3504 struct in6_addr
*addr
;
3505 struct in6_addr mask
;
3510 bpf_error("no mask %s supported", s2
);
3512 res
= pcap_nametoaddrinfo(s1
);
3514 bpf_error("invalid ip6 address %s", s1
);
3516 bpf_error("%s resolved to multiple address", s1
);
3517 addr
= &((struct sockaddr_in6
*)res
->ai_addr
)->sin6_addr
;
3519 if (sizeof(mask
) * 8 < masklen
)
3520 bpf_error("mask length must be <= %u", (unsigned int)(sizeof(mask
) * 8));
3521 memset(&mask
, 0, sizeof(mask
));
3522 memset(&mask
, 0xff, masklen
/ 8);
3524 mask
.s6_addr
[masklen
/ 8] =
3525 (0xff << (8 - masklen
% 8)) & 0xff;
3528 a
= (u_int32_t
*)addr
;
3529 m
= (u_int32_t
*)&mask
;
3530 if ((a
[0] & ~m
[0]) || (a
[1] & ~m
[1])
3531 || (a
[2] & ~m
[2]) || (a
[3] & ~m
[3])) {
3532 bpf_error("non-network bits set in \"%s/%d\"", s1
, masklen
);
3540 bpf_error("Mask syntax for networks only");
3544 b
= gen_host6(addr
, &mask
, q
.proto
, q
.dir
);
3549 bpf_error("invalid qualifier against IPv6 address");
3557 register const u_char
*eaddr
;
3560 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
3561 if (linktype
== DLT_EN10MB
)
3562 return gen_ehostop(eaddr
, (int)q
.dir
);
3563 if (linktype
== DLT_FDDI
)
3564 return gen_fhostop(eaddr
, (int)q
.dir
);
3565 if (linktype
== DLT_IEEE802
)
3566 return gen_thostop(eaddr
, (int)q
.dir
);
3567 bpf_error("ethernet addresses supported only on ethernet, FDDI or token ring");
3569 bpf_error("ethernet address used in non-ether expression");
3575 struct slist
*s0
, *s1
;
3578 * This is definitely not the best way to do this, but the
3579 * lists will rarely get long.
3586 static struct slist
*
3592 s
= new_stmt(BPF_LDX
|BPF_MEM
);
3597 static struct slist
*
3603 s
= new_stmt(BPF_LD
|BPF_MEM
);
3609 gen_load(proto
, index
, size
)
3614 struct slist
*s
, *tmp
;
3616 int regno
= alloc_reg();
3618 free_reg(index
->regno
);
3622 bpf_error("data size must be 1, 2, or 4");
3638 bpf_error("unsupported index operation");
3641 s
= xfer_to_x(index
);
3642 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
3644 sappend(index
->s
, s
);
3659 /* XXX Note that we assume a fixed link header here. */
3660 s
= xfer_to_x(index
);
3661 tmp
= new_stmt(BPF_LD
|BPF_IND
|size
);
3664 sappend(index
->s
, s
);
3666 b
= gen_proto_abbrev(proto
);
3668 gen_and(index
->b
, b
);
3680 s
= new_stmt(BPF_LDX
|BPF_MSH
|BPF_B
);
3682 sappend(s
, xfer_to_a(index
));
3683 sappend(s
, new_stmt(BPF_ALU
|BPF_ADD
|BPF_X
));
3684 sappend(s
, new_stmt(BPF_MISC
|BPF_TAX
));
3685 sappend(s
, tmp
= new_stmt(BPF_LD
|BPF_IND
|size
));
3687 sappend(index
->s
, s
);
3689 gen_and(gen_proto_abbrev(proto
), b
= gen_ipfrag());
3691 gen_and(index
->b
, b
);
3693 gen_and(gen_proto_abbrev(Q_IP
), b
);
3699 bpf_error("IPv6 upper-layer protocol is not supported by proto[x]");
3703 index
->regno
= regno
;
3704 s
= new_stmt(BPF_ST
);
3706 sappend(index
->s
, s
);
3712 gen_relation(code
, a0
, a1
, reversed
)
3714 struct arth
*a0
, *a1
;
3717 struct slist
*s0
, *s1
, *s2
;
3718 struct block
*b
, *tmp
;
3722 if (code
== BPF_JEQ
) {
3723 s2
= new_stmt(BPF_ALU
|BPF_SUB
|BPF_X
);
3724 b
= new_block(JMP(code
));
3728 b
= new_block(BPF_JMP
|code
|BPF_X
);
3734 sappend(a0
->s
, a1
->s
);
3738 free_reg(a0
->regno
);
3739 free_reg(a1
->regno
);
3741 /* 'and' together protocol checks */
3744 gen_and(a0
->b
, tmp
= a1
->b
);
3760 int regno
= alloc_reg();
3761 struct arth
*a
= (struct arth
*)newchunk(sizeof(*a
));
3764 s
= new_stmt(BPF_LD
|BPF_LEN
);
3765 s
->next
= new_stmt(BPF_ST
);
3766 s
->next
->s
.k
= regno
;
3781 a
= (struct arth
*)newchunk(sizeof(*a
));
3785 s
= new_stmt(BPF_LD
|BPF_IMM
);
3787 s
->next
= new_stmt(BPF_ST
);
3803 s
= new_stmt(BPF_ALU
|BPF_NEG
);
3806 s
= new_stmt(BPF_ST
);
3814 gen_arth(code
, a0
, a1
)
3816 struct arth
*a0
, *a1
;
3818 struct slist
*s0
, *s1
, *s2
;
3822 s2
= new_stmt(BPF_ALU
|BPF_X
|code
);
3827 sappend(a0
->s
, a1
->s
);
3829 free_reg(a0
->regno
);
3830 free_reg(a1
->regno
);
3832 s0
= new_stmt(BPF_ST
);
3833 a0
->regno
= s0
->s
.k
= alloc_reg();
3840 * Here we handle simple allocation of the scratch registers.
3841 * If too many registers are alloc'd, the allocator punts.
3843 static int regused
[BPF_MEMWORDS
];
3847 * Return the next free register.
3852 int n
= BPF_MEMWORDS
;
3855 if (regused
[curreg
])
3856 curreg
= (curreg
+ 1) % BPF_MEMWORDS
;
3858 regused
[curreg
] = 1;
3862 bpf_error("too many registers needed to evaluate expression");
3867 * Return a register to the table so it can
3877 static struct block
*
3884 s
= new_stmt(BPF_LD
|BPF_LEN
);
3885 b
= new_block(JMP(jmp
));
3896 return gen_len(BPF_JGE
, n
);
3900 * Actually, this is less than or equal.
3908 b
= gen_len(BPF_JGT
, n
);
3915 gen_byteop(op
, idx
, val
)
3926 return gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3929 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3930 b
->s
.code
= JMP(BPF_JGE
);
3935 b
= gen_cmp((u_int
)idx
, BPF_B
, (bpf_int32
)val
);
3936 b
->s
.code
= JMP(BPF_JGT
);
3940 s
= new_stmt(BPF_ALU
|BPF_OR
|BPF_K
);
3944 s
= new_stmt(BPF_ALU
|BPF_AND
|BPF_K
);
3948 b
= new_block(JMP(BPF_JEQ
));
3955 static u_char abroadcast
[] = { 0x0 };
3958 gen_broadcast(proto
)
3961 bpf_u_int32 hostmask
;
3962 struct block
*b0
, *b1
, *b2
;
3963 static u_char ebroadcast
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3969 if (linktype
== DLT_ARCNET
)
3970 return gen_ahostop(abroadcast
, Q_DST
);
3971 if (linktype
== DLT_EN10MB
)
3972 return gen_ehostop(ebroadcast
, Q_DST
);
3973 if (linktype
== DLT_FDDI
)
3974 return gen_fhostop(ebroadcast
, Q_DST
);
3975 if (linktype
== DLT_IEEE802
)
3976 return gen_thostop(ebroadcast
, Q_DST
);
3977 bpf_error("not a broadcast link");
3981 b0
= gen_linktype(ETHERTYPE_IP
);
3982 hostmask
= ~netmask
;
3983 b1
= gen_mcmp(off_nl
+ 16, BPF_W
, (bpf_int32
)0, hostmask
);
3984 b2
= gen_mcmp(off_nl
+ 16, BPF_W
,
3985 (bpf_int32
)(~0 & hostmask
), hostmask
);
3990 bpf_error("only ether/ip broadcast filters supported");
3994 gen_multicast(proto
)
3997 register struct block
*b0
, *b1
;
3998 register struct slist
*s
;
4004 if (linktype
== DLT_ARCNET
)
4005 /* all ARCnet multicasts use the same address */
4006 return gen_ahostop(abroadcast
, Q_DST
);
4008 if (linktype
== DLT_EN10MB
) {
4009 /* ether[0] & 1 != 0 */
4010 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4012 b0
= new_block(JMP(BPF_JSET
));
4018 if (linktype
== DLT_FDDI
) {
4019 /* XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX */
4020 /* fddi[1] & 1 != 0 */
4021 s
= new_stmt(BPF_LD
|BPF_B
|BPF_ABS
);
4023 b0
= new_block(JMP(BPF_JSET
));
4029 /* TODO - check how token ring handles multicast */
4030 /* if (linktype == DLT_IEEE802) ... */
4032 /* Link not known to support multicasts */
4036 b0
= gen_linktype(ETHERTYPE_IP
);
4037 b1
= gen_cmp(off_nl
+ 16, BPF_B
, (bpf_int32
)224);
4038 b1
->s
.code
= JMP(BPF_JGE
);
4044 b0
= gen_linktype(ETHERTYPE_IPV6
);
4045 b1
= gen_cmp(off_nl
+ 24, BPF_B
, (bpf_int32
)255);
4050 bpf_error("only IP multicast filters supported on ethernet/FDDI");
4054 * generate command for inbound/outbound. It's here so we can
4055 * make it link-type specific. 'dir' = 0 implies "inbound",
4056 * = 1 implies "outbound".
4062 register struct block
*b0
;
4065 * Only some data link types support inbound/outbound qualifiers.
4070 b0
= gen_relation(BPF_JEQ
,
4071 gen_load(Q_LINK
, gen_loadi(0), 1),
4077 bpf_error("inbound/outbound not supported on linktype %d\n",
4087 register const u_char
*eaddr
;
4090 if ((q
.addr
== Q_HOST
|| q
.addr
== Q_DEFAULT
) && q
.proto
== Q_LINK
) {
4091 if (linktype
== DLT_ARCNET
)
4092 return gen_ahostop(eaddr
, (int)q
.dir
);
4094 bpf_error("ARCnet address used in non-arc expression");
4098 static struct block
*
4099 gen_ahostop(eaddr
, dir
)
4100 register const u_char
*eaddr
;
4103 register struct block
*b0
, *b1
;
4106 /* src comes first, different from Ethernet */
4108 return gen_bcmp(0, 1, eaddr
);
4111 return gen_bcmp(1, 1, eaddr
);
4114 b0
= gen_ahostop(eaddr
, Q_SRC
);
4115 b1
= gen_ahostop(eaddr
, Q_DST
);
4121 b0
= gen_ahostop(eaddr
, Q_SRC
);
4122 b1
= gen_ahostop(eaddr
, Q_DST
);
4131 * support IEEE 802.1Q VLAN trunk over ethernet
4140 * Change the offsets to point to the type and data fields within
4141 * the VLAN packet. This is somewhat of a kludge.
4143 if (orig_nl
== (u_int
)-1) {
4144 orig_linktype
= off_linktype
; /* save original values */
4146 orig_nl_nosnap
= off_nl_nosnap
;
4157 bpf_error("no VLAN support for data link type %d",
4163 /* check for VLAN */
4164 b0
= gen_cmp(orig_linktype
, BPF_H
, (bpf_int32
)ETHERTYPE_8021Q
);
4166 /* If a specific VLAN is requested, check VLAN id */
4167 if (vlan_num
>= 0) {
4170 b1
= gen_cmp(orig_nl
, BPF_H
, (bpf_int32
)vlan_num
);
4179 gen_atmfield_code(atmfield
, jvalue
, jtype
, reverse
)
4191 bpf_error("'vpi' supported only on raw ATM");
4194 b0
= gen_ncmp(BPF_B
, off_vpi
, 0xffffffff, (u_int
)jtype
,
4195 (u_int
)jvalue
, reverse
);
4200 bpf_error("'vci' supported only on raw ATM");
4203 b0
= gen_ncmp(BPF_H
, off_vci
, 0xffffffff, (u_int
)jtype
,
4204 (u_int
)jvalue
, reverse
);
4208 if (off_proto
== -1)
4209 abort(); /* XXX - this isn't on FreeBSD */
4210 b0
= gen_ncmp(BPF_B
, off_proto
, 0x0f, (u_int
)jtype
,
4211 (u_int
)jvalue
, reverse
);
4215 if (off_msg_type
== -1)
4217 b0
= gen_ncmp(BPF_B
, off_msg_type
, 0xffffffff,
4218 (u_int
)jtype
, (u_int
)jvalue
, reverse
);
4223 bpf_error("'callref' supported only on raw ATM");
4224 if (off_proto
== -1)
4226 b0
= gen_ncmp(BPF_B
, off_proto
, 0xffffffff, (u_int
)jtype
,
4227 (u_int
)jvalue
, reverse
);
4237 gen_atmtype_abbrev(type
)
4240 struct block
*b0
, *b1
;
4245 /* Get all packets in Meta signalling Circuit */
4247 bpf_error("'metac' supported only on raw ATM");
4248 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4249 b1
= gen_atmfield_code(A_VCI
, 1, BPF_JEQ
, 0);
4254 /* Get all packets in Broadcast Circuit*/
4256 bpf_error("'bcc' supported only on raw ATM");
4257 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4258 b1
= gen_atmfield_code(A_VCI
, 2, BPF_JEQ
, 0);
4263 /* Get all cells in Segment OAM F4 circuit*/
4265 bpf_error("'oam4sc' supported only on raw ATM");
4266 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4267 b1
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
4272 /* Get all cells in End-to-End OAM F4 Circuit*/
4274 bpf_error("'oam4ec' supported only on raw ATM");
4275 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4276 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
4281 /* Get all packets in connection Signalling Circuit */
4283 bpf_error("'sc' supported only on raw ATM");
4284 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4285 b1
= gen_atmfield_code(A_VCI
, 5, BPF_JEQ
, 0);
4290 /* Get all packets in ILMI Circuit */
4292 bpf_error("'ilmic' supported only on raw ATM");
4293 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4294 b1
= gen_atmfield_code(A_VCI
, 16, BPF_JEQ
, 0);
4299 /* Get all LANE packets */
4301 bpf_error("'lane' supported only on raw ATM");
4302 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LANE
, BPF_JEQ
, 0);
4306 /* Get all LLC-encapsulated packets */
4308 bpf_error("'llc' supported only on raw ATM");
4309 b1
= gen_atmfield_code(A_PROTOTYPE
, PT_LLC
, BPF_JEQ
, 0);
4319 static struct block
*
4320 gen_msg_abbrev(type
)
4326 * Q.2931 signalling protocol messages for handling virtual circuits
4327 * establishment and teardown
4332 b1
= gen_atmfield_code(A_MSGTYPE
, SETUP
, BPF_JEQ
, 0);
4336 b1
= gen_atmfield_code(A_MSGTYPE
, CALL_PROCEED
, BPF_JEQ
, 0);
4340 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT
, BPF_JEQ
, 0);
4344 b1
= gen_atmfield_code(A_MSGTYPE
, CONNECT_ACK
, BPF_JEQ
, 0);
4348 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE
, BPF_JEQ
, 0);
4351 case A_RELEASE_DONE
:
4352 b1
= gen_atmfield_code(A_MSGTYPE
, RELEASE_DONE
, BPF_JEQ
, 0);
4362 gen_atmmulti_abbrev(type
)
4365 struct block
*b0
, *b1
;
4371 bpf_error("'oam' supported only on raw ATM");
4372 b1
= gen_atmmulti_abbrev(A_OAMF4
);
4377 bpf_error("'oamf4' supported only on raw ATM");
4379 b0
= gen_atmfield_code(A_VCI
, 3, BPF_JEQ
, 0);
4380 b1
= gen_atmfield_code(A_VCI
, 4, BPF_JEQ
, 0);
4382 b0
= gen_atmfield_code(A_VPI
, 0, BPF_JEQ
, 0);
4388 * Get Q.2931 signalling messages for switched
4389 * virtual connection
4392 bpf_error("'connectmsg' supported only on raw ATM");
4393 b0
= gen_msg_abbrev(A_SETUP
);
4394 b1
= gen_msg_abbrev(A_CALLPROCEED
);
4396 b0
= gen_msg_abbrev(A_CONNECT
);
4398 b0
= gen_msg_abbrev(A_CONNECTACK
);
4400 b0
= gen_msg_abbrev(A_RELEASE
);
4402 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
4404 b0
= gen_atmtype_abbrev(A_SC
);
4410 bpf_error("'metaconnect' supported only on raw ATM");
4411 b0
= gen_msg_abbrev(A_SETUP
);
4412 b1
= gen_msg_abbrev(A_CALLPROCEED
);
4414 b0
= gen_msg_abbrev(A_CONNECT
);
4416 b0
= gen_msg_abbrev(A_RELEASE
);
4418 b0
= gen_msg_abbrev(A_RELEASE_DONE
);
4420 b0
= gen_atmtype_abbrev(A_METAC
);