xref: /freebsd/contrib/libpcap/gencode.h (revision d1e8733132ce92d068898e4b3fe25ce17d634590)
18cf6c252SPaul Traina /*
28cf6c252SPaul Traina  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
38cf6c252SPaul Traina  *	The Regents of the University of California.  All rights reserved.
48cf6c252SPaul Traina  *
58cf6c252SPaul Traina  * Redistribution and use in source and binary forms, with or without
68cf6c252SPaul Traina  * modification, are permitted provided that: (1) source code distributions
78cf6c252SPaul Traina  * retain the above copyright notice and this paragraph in its entirety, (2)
88cf6c252SPaul Traina  * distributions including binary code include the above copyright notice and
98cf6c252SPaul Traina  * this paragraph in its entirety in the documentation or other materials
108cf6c252SPaul Traina  * provided with the distribution, and (3) all advertising materials mentioning
118cf6c252SPaul Traina  * features or use of this software display the following acknowledgement:
128cf6c252SPaul Traina  * ``This product includes software developed by the University of California,
138cf6c252SPaul Traina  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
148cf6c252SPaul Traina  * the University nor the names of its contributors may be used to endorse
158cf6c252SPaul Traina  * or promote products derived from this software without specific prior
168cf6c252SPaul Traina  * written permission.
178cf6c252SPaul Traina  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
188cf6c252SPaul Traina  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
198cf6c252SPaul Traina  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
208cf6c252SPaul Traina  *
21a0ee43a1SRui Paulo  * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.71 2007-11-18 02:03:52 guy Exp $ (LBL)
22eb9f0330SBruce M Simpson  */
23eb9f0330SBruce M Simpson 
24eb9f0330SBruce M Simpson /*
25eb9f0330SBruce M Simpson  * ATM support:
26eb9f0330SBruce M Simpson  *
27eb9f0330SBruce M Simpson  * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
28eb9f0330SBruce M Simpson  * All rights reserved.
29eb9f0330SBruce M Simpson  *
30eb9f0330SBruce M Simpson  * Redistribution and use in source and binary forms, with or without
31eb9f0330SBruce M Simpson  * modification, are permitted provided that the following conditions
32eb9f0330SBruce M Simpson  * are met:
33eb9f0330SBruce M Simpson  * 1. Redistributions of source code must retain the above copyright
34eb9f0330SBruce M Simpson  *    notice, this list of conditions and the following disclaimer.
35eb9f0330SBruce M Simpson  * 2. Redistributions in binary form must reproduce the above copyright
36eb9f0330SBruce M Simpson  *    notice, this list of conditions and the following disclaimer in the
37eb9f0330SBruce M Simpson  *    documentation and/or other materials provided with the distribution.
38eb9f0330SBruce M Simpson  * 3. All advertising materials mentioning features or use of this software
39eb9f0330SBruce M Simpson  *    must display the following acknowledgement:
40eb9f0330SBruce M Simpson  *      This product includes software developed by Yen Yen Lim and
41eb9f0330SBruce M Simpson  *      North Dakota State University
42eb9f0330SBruce M Simpson  * 4. The name of the author may not be used to endorse or promote products
43eb9f0330SBruce M Simpson  *    derived from this software without specific prior written permission.
44eb9f0330SBruce M Simpson  *
45eb9f0330SBruce M Simpson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46eb9f0330SBruce M Simpson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47eb9f0330SBruce M Simpson  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48eb9f0330SBruce M Simpson  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
49eb9f0330SBruce M Simpson  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50eb9f0330SBruce M Simpson  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51eb9f0330SBruce M Simpson  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52eb9f0330SBruce M Simpson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53eb9f0330SBruce M Simpson  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
54eb9f0330SBruce M Simpson  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55eb9f0330SBruce M Simpson  * POSSIBILITY OF SUCH DAMAGE.
568cf6c252SPaul Traina  */
578cf6c252SPaul Traina 
584238c2cdSSam Leffler #ifndef HAVE___ATTRIBUTE__
594238c2cdSSam Leffler #define __attribute__(x)
604238c2cdSSam Leffler #endif /* HAVE___ATTRIBUTE__ */
614238c2cdSSam Leffler 
628cf6c252SPaul Traina /* Address qualifiers. */
638cf6c252SPaul Traina 
648cf6c252SPaul Traina #define Q_HOST		1
658cf6c252SPaul Traina #define Q_NET		2
668cf6c252SPaul Traina #define Q_PORT		3
678cf6c252SPaul Traina #define Q_GATEWAY	4
688cf6c252SPaul Traina #define Q_PROTO		5
69fae05455SBill Fenner #define Q_PROTOCHAIN	6
704238c2cdSSam Leffler #define Q_PORTRANGE	7
718cf6c252SPaul Traina 
728cf6c252SPaul Traina /* Protocol qualifiers. */
738cf6c252SPaul Traina 
748cf6c252SPaul Traina #define Q_LINK		1
758cf6c252SPaul Traina #define Q_IP		2
768cf6c252SPaul Traina #define Q_ARP		3
778cf6c252SPaul Traina #define Q_RARP		4
78c0653930SBill Fenner #define Q_SCTP		5
79c0653930SBill Fenner #define Q_TCP		6
80c0653930SBill Fenner #define Q_UDP		7
81c0653930SBill Fenner #define Q_ICMP		8
82c0653930SBill Fenner #define Q_IGMP		9
83c0653930SBill Fenner #define Q_IGRP		10
848cf6c252SPaul Traina 
858cf6c252SPaul Traina 
86c0653930SBill Fenner #define	Q_ATALK		11
87c0653930SBill Fenner #define	Q_DECNET	12
88c0653930SBill Fenner #define	Q_LAT		13
89c0653930SBill Fenner #define Q_SCA		14
90c0653930SBill Fenner #define	Q_MOPRC		15
91c0653930SBill Fenner #define	Q_MOPDL		16
92fae05455SBill Fenner 
938e1481d1SBill Fenner 
94c0653930SBill Fenner #define Q_IPV6		17
95c0653930SBill Fenner #define Q_ICMPV6	18
96c0653930SBill Fenner #define Q_AH		19
97c0653930SBill Fenner #define Q_ESP		20
98fae05455SBill Fenner 
99c0653930SBill Fenner #define Q_PIM		21
100c0653930SBill Fenner #define Q_VRRP		22
101fae05455SBill Fenner 
102c0653930SBill Fenner #define Q_AARP		23
1038e1481d1SBill Fenner 
104c0653930SBill Fenner #define Q_ISO		24
105c0653930SBill Fenner #define Q_ESIS		25
106c0653930SBill Fenner #define Q_ISIS		26
107c0653930SBill Fenner #define Q_CLNP		27
108c0653930SBill Fenner 
109c0653930SBill Fenner #define Q_STP		28
110c0653930SBill Fenner 
111c0653930SBill Fenner #define Q_IPX		29
112c0653930SBill Fenner 
113c0653930SBill Fenner #define Q_NETBEUI	30
1148cf6c252SPaul Traina 
115eb9f0330SBruce M Simpson /* IS-IS Levels */
116eb9f0330SBruce M Simpson #define Q_ISIS_L1       31
117eb9f0330SBruce M Simpson #define Q_ISIS_L2       32
118eb9f0330SBruce M Simpson /* PDU types */
119eb9f0330SBruce M Simpson #define Q_ISIS_IIH      33
120eb9f0330SBruce M Simpson #define Q_ISIS_LAN_IIH  34
121eb9f0330SBruce M Simpson #define Q_ISIS_PTP_IIH  35
122eb9f0330SBruce M Simpson #define Q_ISIS_SNP      36
123eb9f0330SBruce M Simpson #define Q_ISIS_CSNP     37
124eb9f0330SBruce M Simpson #define Q_ISIS_PSNP     38
125eb9f0330SBruce M Simpson #define Q_ISIS_LSP      39
126eb9f0330SBruce M Simpson 
1274238c2cdSSam Leffler #define Q_RADIO		40
1284238c2cdSSam Leffler 
129*d1e87331SXin LI #define Q_CARP		41
130*d1e87331SXin LI 
1318cf6c252SPaul Traina /* Directional qualifiers. */
1328cf6c252SPaul Traina 
1338cf6c252SPaul Traina #define Q_SRC		1
1348cf6c252SPaul Traina #define Q_DST		2
1358cf6c252SPaul Traina #define Q_OR		3
1368cf6c252SPaul Traina #define Q_AND		4
137a8e07101SRui Paulo #define Q_ADDR1		5
138a8e07101SRui Paulo #define Q_ADDR2		6
139a8e07101SRui Paulo #define Q_ADDR3		7
140a8e07101SRui Paulo #define Q_ADDR4		8
141*d1e87331SXin LI #define Q_RA		9
142*d1e87331SXin LI #define Q_TA		10
1438cf6c252SPaul Traina 
1448cf6c252SPaul Traina #define Q_DEFAULT	0
1458cf6c252SPaul Traina #define Q_UNDEF		255
1468cf6c252SPaul Traina 
147eb9f0330SBruce M Simpson /* ATM types */
148eb9f0330SBruce M Simpson #define A_METAC		22	/* Meta signalling Circuit */
149eb9f0330SBruce M Simpson #define A_BCC		23	/* Broadcast Circuit */
150eb9f0330SBruce M Simpson #define A_OAMF4SC	24	/* Segment OAM F4 Circuit */
151eb9f0330SBruce M Simpson #define A_OAMF4EC	25	/* End-to-End OAM F4 Circuit */
152eb9f0330SBruce M Simpson #define A_SC		26	/* Signalling Circuit*/
153eb9f0330SBruce M Simpson #define A_ILMIC		27	/* ILMI Circuit */
154eb9f0330SBruce M Simpson #define A_OAM		28	/* OAM cells : F4 only */
155eb9f0330SBruce M Simpson #define A_OAMF4		29	/* OAM F4 cells: Segment + End-to-end */
156eb9f0330SBruce M Simpson #define A_LANE		30	/* LANE traffic */
157eb9f0330SBruce M Simpson #define A_LLC		31	/* LLC-encapsulated traffic */
158eb9f0330SBruce M Simpson 
159eb9f0330SBruce M Simpson /* Based on Q.2931 signalling protocol */
160eb9f0330SBruce M Simpson #define A_SETUP		41	/* Setup message */
161eb9f0330SBruce M Simpson #define A_CALLPROCEED	42	/* Call proceeding message */
162eb9f0330SBruce M Simpson #define A_CONNECT	43	/* Connect message */
163eb9f0330SBruce M Simpson #define A_CONNECTACK	44	/* Connect Ack message */
164eb9f0330SBruce M Simpson #define A_RELEASE	45	/* Release message */
165eb9f0330SBruce M Simpson #define A_RELEASE_DONE	46	/* Release message */
166eb9f0330SBruce M Simpson 
167eb9f0330SBruce M Simpson /* ATM field types */
168eb9f0330SBruce M Simpson #define A_VPI		51
169eb9f0330SBruce M Simpson #define A_VCI		52
170eb9f0330SBruce M Simpson #define A_PROTOTYPE	53
171eb9f0330SBruce M Simpson #define A_MSGTYPE	54
172eb9f0330SBruce M Simpson #define A_CALLREFTYPE	55
173eb9f0330SBruce M Simpson 
174eb9f0330SBruce M Simpson #define A_CONNECTMSG	70	/* returns Q.2931 signalling messages for
175eb9f0330SBruce M Simpson 				   establishing and destroying switched
176eb9f0330SBruce M Simpson 				   virtual connection */
177eb9f0330SBruce M Simpson #define A_METACONNECT	71	/* returns Q.2931 signalling messages for
178eb9f0330SBruce M Simpson 				   establishing and destroying predefined
179eb9f0330SBruce M Simpson 				   virtual circuits, such as broadcast
180eb9f0330SBruce M Simpson 				   circuit, oamf4 segment circuit, oamf4
181eb9f0330SBruce M Simpson 				   end-to-end circuits, ILMI circuits or
182eb9f0330SBruce M Simpson 				   connection signalling circuit. */
183eb9f0330SBruce M Simpson 
1845357e0feSMax Laier /* MTP2 types */
1855357e0feSMax Laier #define M_FISU		22	/* FISU */
1865357e0feSMax Laier #define M_LSSU		23	/* LSSU */
1875357e0feSMax Laier #define M_MSU		24	/* MSU */
1885357e0feSMax Laier 
1894238c2cdSSam Leffler /* MTP3 field types */
1904238c2cdSSam Leffler #define M_SIO		1
1914238c2cdSSam Leffler #define M_OPC		2
1924238c2cdSSam Leffler #define M_DPC		3
1934238c2cdSSam Leffler #define M_SLS		4
1944238c2cdSSam Leffler 
1954238c2cdSSam Leffler 
196fae05455SBill Fenner struct slist;
197fae05455SBill Fenner 
1988cf6c252SPaul Traina struct stmt {
1998cf6c252SPaul Traina 	int code;
200fae05455SBill Fenner 	struct slist *jt;	/*only for relative jump in block*/
201fae05455SBill Fenner 	struct slist *jf;	/*only for relative jump in block*/
2028cf6c252SPaul Traina 	bpf_int32 k;
2038cf6c252SPaul Traina };
2048cf6c252SPaul Traina 
2058cf6c252SPaul Traina struct slist {
2068cf6c252SPaul Traina 	struct stmt s;
2078cf6c252SPaul Traina 	struct slist *next;
2088cf6c252SPaul Traina };
2098cf6c252SPaul Traina 
2108cf6c252SPaul Traina /*
2118cf6c252SPaul Traina  * A bit vector to represent definition sets.  We assume TOT_REGISTERS
2128cf6c252SPaul Traina  * is smaller than 8*sizeof(atomset).
2138cf6c252SPaul Traina  */
2148cf6c252SPaul Traina typedef bpf_u_int32 atomset;
2158cf6c252SPaul Traina #define ATOMMASK(n) (1 << (n))
2168cf6c252SPaul Traina #define ATOMELEM(d, n) (d & ATOMMASK(n))
2178cf6c252SPaul Traina 
2188cf6c252SPaul Traina /*
2198cf6c252SPaul Traina  * An unbounded set.
2208cf6c252SPaul Traina  */
2218cf6c252SPaul Traina typedef bpf_u_int32 *uset;
2228cf6c252SPaul Traina 
2238cf6c252SPaul Traina /*
2248cf6c252SPaul Traina  * Total number of atomic entities, including accumulator (A) and index (X).
2258cf6c252SPaul Traina  * We treat all these guys similarly during flow analysis.
2268cf6c252SPaul Traina  */
2278cf6c252SPaul Traina #define N_ATOMS (BPF_MEMWORDS+2)
2288cf6c252SPaul Traina 
2298cf6c252SPaul Traina struct edge {
2308cf6c252SPaul Traina 	int id;
2318cf6c252SPaul Traina 	int code;
2328cf6c252SPaul Traina 	uset edom;
2338cf6c252SPaul Traina 	struct block *succ;
2348cf6c252SPaul Traina 	struct block *pred;
2358cf6c252SPaul Traina 	struct edge *next;	/* link list of incoming edges for a node */
2368cf6c252SPaul Traina };
2378cf6c252SPaul Traina 
2388cf6c252SPaul Traina struct block {
2398cf6c252SPaul Traina 	int id;
2408cf6c252SPaul Traina 	struct slist *stmts;	/* side effect stmts */
2418cf6c252SPaul Traina 	struct stmt s;		/* branch stmt */
2428cf6c252SPaul Traina 	int mark;
2438cf6c252SPaul Traina 	int longjt;		/* jt branch requires long jump */
2448cf6c252SPaul Traina 	int longjf;		/* jf branch requires long jump */
2458cf6c252SPaul Traina 	int level;
2468cf6c252SPaul Traina 	int offset;
2478cf6c252SPaul Traina 	int sense;
2488cf6c252SPaul Traina 	struct edge et;
2498cf6c252SPaul Traina 	struct edge ef;
2508cf6c252SPaul Traina 	struct block *head;
2518cf6c252SPaul Traina 	struct block *link;	/* link field used by optimizer */
2528cf6c252SPaul Traina 	uset dom;
2538cf6c252SPaul Traina 	uset closure;
2548cf6c252SPaul Traina 	struct edge *in_edges;
2558cf6c252SPaul Traina 	atomset def, kill;
2568cf6c252SPaul Traina 	atomset in_use;
2578cf6c252SPaul Traina 	atomset out_use;
2588cf6c252SPaul Traina 	int oval;
2598cf6c252SPaul Traina 	int val[N_ATOMS];
2608cf6c252SPaul Traina };
2618cf6c252SPaul Traina 
2628cf6c252SPaul Traina struct arth {
2638cf6c252SPaul Traina 	struct block *b;	/* protocol checks */
2648cf6c252SPaul Traina 	struct slist *s;	/* stmt list */
2658cf6c252SPaul Traina 	int regno;		/* virtual register number of result */
2668cf6c252SPaul Traina };
2678cf6c252SPaul Traina 
2688cf6c252SPaul Traina struct qual {
2698cf6c252SPaul Traina 	unsigned char addr;
2708cf6c252SPaul Traina 	unsigned char proto;
2718cf6c252SPaul Traina 	unsigned char dir;
2728cf6c252SPaul Traina 	unsigned char pad;
2738cf6c252SPaul Traina };
2748cf6c252SPaul Traina 
2758cf6c252SPaul Traina struct arth *gen_loadi(int);
2768cf6c252SPaul Traina struct arth *gen_load(int, struct arth *, int);
2778cf6c252SPaul Traina struct arth *gen_loadlen(void);
2788cf6c252SPaul Traina struct arth *gen_neg(struct arth *);
2798cf6c252SPaul Traina struct arth *gen_arth(int, struct arth *, struct arth *);
2808cf6c252SPaul Traina 
2818cf6c252SPaul Traina void gen_and(struct block *, struct block *);
2828cf6c252SPaul Traina void gen_or(struct block *, struct block *);
2838cf6c252SPaul Traina void gen_not(struct block *);
2848cf6c252SPaul Traina 
2858cf6c252SPaul Traina struct block *gen_scode(const char *, struct qual);
2868cf6c252SPaul Traina struct block *gen_ecode(const u_char *, struct qual);
287c0653930SBill Fenner struct block *gen_acode(const u_char *, struct qual);
2888cf6c252SPaul Traina struct block *gen_mcode(const char *, const char *, int, struct qual);
289fae05455SBill Fenner #ifdef INET6
290fae05455SBill Fenner struct block *gen_mcode6(const char *, const char *, int, struct qual);
291fae05455SBill Fenner #endif
2928cf6c252SPaul Traina struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
2938cf6c252SPaul Traina struct block *gen_proto_abbrev(int);
2948cf6c252SPaul Traina struct block *gen_relation(int, struct arth *, struct arth *, int);
2958cf6c252SPaul Traina struct block *gen_less(int);
2968cf6c252SPaul Traina struct block *gen_greater(int);
2978cf6c252SPaul Traina struct block *gen_byteop(int, int, int);
2988cf6c252SPaul Traina struct block *gen_broadcast(int);
2998cf6c252SPaul Traina struct block *gen_multicast(int);
3008cf6c252SPaul Traina struct block *gen_inbound(int);
3018cf6c252SPaul Traina 
3028e1481d1SBill Fenner struct block *gen_vlan(int);
303c761ebcbSSam Leffler struct block *gen_mpls(int);
3048e1481d1SBill Fenner 
305ff252dbeSSam Leffler struct block *gen_pppoed(void);
306ff252dbeSSam Leffler struct block *gen_pppoes(void);
307ff252dbeSSam Leffler 
3084238c2cdSSam Leffler struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse);
309eb9f0330SBruce M Simpson struct block *gen_atmtype_abbrev(int type);
310eb9f0330SBruce M Simpson struct block *gen_atmmulti_abbrev(int type);
311eb9f0330SBruce M Simpson 
3125357e0feSMax Laier struct block *gen_mtp2type_abbrev(int type);
3134238c2cdSSam Leffler struct block *gen_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse);
3144238c2cdSSam Leffler 
315eb9f0330SBruce M Simpson struct block *gen_pf_ifname(const char *);
316eb9f0330SBruce M Simpson struct block *gen_pf_rnr(int);
317eb9f0330SBruce M Simpson struct block *gen_pf_srnr(int);
318eb9f0330SBruce M Simpson struct block *gen_pf_ruleset(char *);
319eb9f0330SBruce M Simpson struct block *gen_pf_reason(int);
320eb9f0330SBruce M Simpson struct block *gen_pf_action(int);
321eb9f0330SBruce M Simpson struct block *gen_pf_dir(int);
322eb9f0330SBruce M Simpson 
323a8e07101SRui Paulo struct block *gen_p80211_type(int, int);
324a8e07101SRui Paulo struct block *gen_p80211_fcdir(int);
325a8e07101SRui Paulo 
3268cf6c252SPaul Traina void bpf_optimize(struct block **);
3278e1481d1SBill Fenner void bpf_error(const char *, ...)
3284238c2cdSSam Leffler     __attribute__((noreturn, format (printf, 1, 2)));
3298cf6c252SPaul Traina 
3308cf6c252SPaul Traina void finish_parse(struct block *);
3318cf6c252SPaul Traina char *sdup(const char *);
3328cf6c252SPaul Traina 
3338cf6c252SPaul Traina struct bpf_insn *icode_to_fcode(struct block *, int *);
3348cf6c252SPaul Traina int pcap_parse(void);
3355357e0feSMax Laier void lex_init(const char *);
3368e1481d1SBill Fenner void lex_cleanup(void);
3378cf6c252SPaul Traina void sappend(struct slist *, struct slist *);
3388cf6c252SPaul Traina 
3398cf6c252SPaul Traina /* XXX */
3408cf6c252SPaul Traina #define JT(b)  ((b)->et.succ)
3418cf6c252SPaul Traina #define JF(b)  ((b)->ef.succ)
342fae05455SBill Fenner 
343fae05455SBill Fenner extern int no_optimize;
344