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 * 21fae05455SBill Fenner * $FreeBSD$ 22ff252dbeSSam Leffler * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.60.2.6 2005/09/05 09:08:06 guy Exp $ (LBL) 23eb9f0330SBruce M Simpson */ 24eb9f0330SBruce M Simpson 25eb9f0330SBruce M Simpson /* 26eb9f0330SBruce M Simpson * ATM support: 27eb9f0330SBruce M Simpson * 28eb9f0330SBruce M Simpson * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 29eb9f0330SBruce M Simpson * All rights reserved. 30eb9f0330SBruce M Simpson * 31eb9f0330SBruce M Simpson * Redistribution and use in source and binary forms, with or without 32eb9f0330SBruce M Simpson * modification, are permitted provided that the following conditions 33eb9f0330SBruce M Simpson * are met: 34eb9f0330SBruce M Simpson * 1. Redistributions of source code must retain the above copyright 35eb9f0330SBruce M Simpson * notice, this list of conditions and the following disclaimer. 36eb9f0330SBruce M Simpson * 2. Redistributions in binary form must reproduce the above copyright 37eb9f0330SBruce M Simpson * notice, this list of conditions and the following disclaimer in the 38eb9f0330SBruce M Simpson * documentation and/or other materials provided with the distribution. 39eb9f0330SBruce M Simpson * 3. All advertising materials mentioning features or use of this software 40eb9f0330SBruce M Simpson * must display the following acknowledgement: 41eb9f0330SBruce M Simpson * This product includes software developed by Yen Yen Lim and 42eb9f0330SBruce M Simpson * North Dakota State University 43eb9f0330SBruce M Simpson * 4. The name of the author may not be used to endorse or promote products 44eb9f0330SBruce M Simpson * derived from this software without specific prior written permission. 45eb9f0330SBruce M Simpson * 46eb9f0330SBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47eb9f0330SBruce M Simpson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 48eb9f0330SBruce M Simpson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 49eb9f0330SBruce M Simpson * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 50eb9f0330SBruce M Simpson * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 51eb9f0330SBruce M Simpson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 52eb9f0330SBruce M Simpson * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53eb9f0330SBruce M Simpson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 54eb9f0330SBruce M Simpson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 55eb9f0330SBruce M Simpson * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 56eb9f0330SBruce M Simpson * POSSIBILITY OF SUCH DAMAGE. 578cf6c252SPaul Traina */ 588cf6c252SPaul Traina 594238c2cdSSam Leffler #ifndef HAVE___ATTRIBUTE__ 604238c2cdSSam Leffler #define __attribute__(x) 614238c2cdSSam Leffler #endif /* HAVE___ATTRIBUTE__ */ 624238c2cdSSam Leffler 638cf6c252SPaul Traina /* Address qualifiers. */ 648cf6c252SPaul Traina 658cf6c252SPaul Traina #define Q_HOST 1 668cf6c252SPaul Traina #define Q_NET 2 678cf6c252SPaul Traina #define Q_PORT 3 688cf6c252SPaul Traina #define Q_GATEWAY 4 698cf6c252SPaul Traina #define Q_PROTO 5 70fae05455SBill Fenner #define Q_PROTOCHAIN 6 714238c2cdSSam Leffler #define Q_PORTRANGE 7 728cf6c252SPaul Traina 738cf6c252SPaul Traina /* Protocol qualifiers. */ 748cf6c252SPaul Traina 758cf6c252SPaul Traina #define Q_LINK 1 768cf6c252SPaul Traina #define Q_IP 2 778cf6c252SPaul Traina #define Q_ARP 3 788cf6c252SPaul Traina #define Q_RARP 4 79c0653930SBill Fenner #define Q_SCTP 5 80c0653930SBill Fenner #define Q_TCP 6 81c0653930SBill Fenner #define Q_UDP 7 82c0653930SBill Fenner #define Q_ICMP 8 83c0653930SBill Fenner #define Q_IGMP 9 84c0653930SBill Fenner #define Q_IGRP 10 858cf6c252SPaul Traina 868cf6c252SPaul Traina 87c0653930SBill Fenner #define Q_ATALK 11 88c0653930SBill Fenner #define Q_DECNET 12 89c0653930SBill Fenner #define Q_LAT 13 90c0653930SBill Fenner #define Q_SCA 14 91c0653930SBill Fenner #define Q_MOPRC 15 92c0653930SBill Fenner #define Q_MOPDL 16 93fae05455SBill Fenner 948e1481d1SBill Fenner 95c0653930SBill Fenner #define Q_IPV6 17 96c0653930SBill Fenner #define Q_ICMPV6 18 97c0653930SBill Fenner #define Q_AH 19 98c0653930SBill Fenner #define Q_ESP 20 99fae05455SBill Fenner 100c0653930SBill Fenner #define Q_PIM 21 101c0653930SBill Fenner #define Q_VRRP 22 102fae05455SBill Fenner 103c0653930SBill Fenner #define Q_AARP 23 1048e1481d1SBill Fenner 105c0653930SBill Fenner #define Q_ISO 24 106c0653930SBill Fenner #define Q_ESIS 25 107c0653930SBill Fenner #define Q_ISIS 26 108c0653930SBill Fenner #define Q_CLNP 27 109c0653930SBill Fenner 110c0653930SBill Fenner #define Q_STP 28 111c0653930SBill Fenner 112c0653930SBill Fenner #define Q_IPX 29 113c0653930SBill Fenner 114c0653930SBill Fenner #define Q_NETBEUI 30 1158cf6c252SPaul Traina 116eb9f0330SBruce M Simpson /* IS-IS Levels */ 117eb9f0330SBruce M Simpson #define Q_ISIS_L1 31 118eb9f0330SBruce M Simpson #define Q_ISIS_L2 32 119eb9f0330SBruce M Simpson /* PDU types */ 120eb9f0330SBruce M Simpson #define Q_ISIS_IIH 33 121eb9f0330SBruce M Simpson #define Q_ISIS_LAN_IIH 34 122eb9f0330SBruce M Simpson #define Q_ISIS_PTP_IIH 35 123eb9f0330SBruce M Simpson #define Q_ISIS_SNP 36 124eb9f0330SBruce M Simpson #define Q_ISIS_CSNP 37 125eb9f0330SBruce M Simpson #define Q_ISIS_PSNP 38 126eb9f0330SBruce M Simpson #define Q_ISIS_LSP 39 127eb9f0330SBruce M Simpson 1284238c2cdSSam Leffler #define Q_RADIO 40 1294238c2cdSSam Leffler 1308cf6c252SPaul Traina /* Directional qualifiers. */ 1318cf6c252SPaul Traina 1328cf6c252SPaul Traina #define Q_SRC 1 1338cf6c252SPaul Traina #define Q_DST 2 1348cf6c252SPaul Traina #define Q_OR 3 1358cf6c252SPaul Traina #define Q_AND 4 1368cf6c252SPaul Traina 1378cf6c252SPaul Traina #define Q_DEFAULT 0 1388cf6c252SPaul Traina #define Q_UNDEF 255 1398cf6c252SPaul Traina 140eb9f0330SBruce M Simpson /* ATM types */ 141eb9f0330SBruce M Simpson #define A_METAC 22 /* Meta signalling Circuit */ 142eb9f0330SBruce M Simpson #define A_BCC 23 /* Broadcast Circuit */ 143eb9f0330SBruce M Simpson #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 144eb9f0330SBruce M Simpson #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 145eb9f0330SBruce M Simpson #define A_SC 26 /* Signalling Circuit*/ 146eb9f0330SBruce M Simpson #define A_ILMIC 27 /* ILMI Circuit */ 147eb9f0330SBruce M Simpson #define A_OAM 28 /* OAM cells : F4 only */ 148eb9f0330SBruce M Simpson #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 149eb9f0330SBruce M Simpson #define A_LANE 30 /* LANE traffic */ 150eb9f0330SBruce M Simpson #define A_LLC 31 /* LLC-encapsulated traffic */ 151eb9f0330SBruce M Simpson 152eb9f0330SBruce M Simpson /* Based on Q.2931 signalling protocol */ 153eb9f0330SBruce M Simpson #define A_SETUP 41 /* Setup message */ 154eb9f0330SBruce M Simpson #define A_CALLPROCEED 42 /* Call proceeding message */ 155eb9f0330SBruce M Simpson #define A_CONNECT 43 /* Connect message */ 156eb9f0330SBruce M Simpson #define A_CONNECTACK 44 /* Connect Ack message */ 157eb9f0330SBruce M Simpson #define A_RELEASE 45 /* Release message */ 158eb9f0330SBruce M Simpson #define A_RELEASE_DONE 46 /* Release message */ 159eb9f0330SBruce M Simpson 160eb9f0330SBruce M Simpson /* ATM field types */ 161eb9f0330SBruce M Simpson #define A_VPI 51 162eb9f0330SBruce M Simpson #define A_VCI 52 163eb9f0330SBruce M Simpson #define A_PROTOTYPE 53 164eb9f0330SBruce M Simpson #define A_MSGTYPE 54 165eb9f0330SBruce M Simpson #define A_CALLREFTYPE 55 166eb9f0330SBruce M Simpson 167eb9f0330SBruce M Simpson #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 168eb9f0330SBruce M Simpson establishing and destroying switched 169eb9f0330SBruce M Simpson virtual connection */ 170eb9f0330SBruce M Simpson #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 171eb9f0330SBruce M Simpson establishing and destroying predefined 172eb9f0330SBruce M Simpson virtual circuits, such as broadcast 173eb9f0330SBruce M Simpson circuit, oamf4 segment circuit, oamf4 174eb9f0330SBruce M Simpson end-to-end circuits, ILMI circuits or 175eb9f0330SBruce M Simpson connection signalling circuit. */ 176eb9f0330SBruce M Simpson 1774238c2cdSSam Leffler /*MTP3 field types */ 1784238c2cdSSam Leffler #define M_SIO 1 1794238c2cdSSam Leffler #define M_OPC 2 1804238c2cdSSam Leffler #define M_DPC 3 1814238c2cdSSam Leffler #define M_SLS 4 1824238c2cdSSam Leffler 1834238c2cdSSam Leffler 184fae05455SBill Fenner struct slist; 185fae05455SBill Fenner 1868cf6c252SPaul Traina struct stmt { 1878cf6c252SPaul Traina int code; 188fae05455SBill Fenner struct slist *jt; /*only for relative jump in block*/ 189fae05455SBill Fenner struct slist *jf; /*only for relative jump in block*/ 1908cf6c252SPaul Traina bpf_int32 k; 1918cf6c252SPaul Traina }; 1928cf6c252SPaul Traina 1938cf6c252SPaul Traina struct slist { 1948cf6c252SPaul Traina struct stmt s; 1958cf6c252SPaul Traina struct slist *next; 1968cf6c252SPaul Traina }; 1978cf6c252SPaul Traina 1988cf6c252SPaul Traina /* 1998cf6c252SPaul Traina * A bit vector to represent definition sets. We assume TOT_REGISTERS 2008cf6c252SPaul Traina * is smaller than 8*sizeof(atomset). 2018cf6c252SPaul Traina */ 2028cf6c252SPaul Traina typedef bpf_u_int32 atomset; 2038cf6c252SPaul Traina #define ATOMMASK(n) (1 << (n)) 2048cf6c252SPaul Traina #define ATOMELEM(d, n) (d & ATOMMASK(n)) 2058cf6c252SPaul Traina 2068cf6c252SPaul Traina /* 2078cf6c252SPaul Traina * An unbounded set. 2088cf6c252SPaul Traina */ 2098cf6c252SPaul Traina typedef bpf_u_int32 *uset; 2108cf6c252SPaul Traina 2118cf6c252SPaul Traina /* 2128cf6c252SPaul Traina * Total number of atomic entities, including accumulator (A) and index (X). 2138cf6c252SPaul Traina * We treat all these guys similarly during flow analysis. 2148cf6c252SPaul Traina */ 2158cf6c252SPaul Traina #define N_ATOMS (BPF_MEMWORDS+2) 2168cf6c252SPaul Traina 2178cf6c252SPaul Traina struct edge { 2188cf6c252SPaul Traina int id; 2198cf6c252SPaul Traina int code; 2208cf6c252SPaul Traina uset edom; 2218cf6c252SPaul Traina struct block *succ; 2228cf6c252SPaul Traina struct block *pred; 2238cf6c252SPaul Traina struct edge *next; /* link list of incoming edges for a node */ 2248cf6c252SPaul Traina }; 2258cf6c252SPaul Traina 2268cf6c252SPaul Traina struct block { 2278cf6c252SPaul Traina int id; 2288cf6c252SPaul Traina struct slist *stmts; /* side effect stmts */ 2298cf6c252SPaul Traina struct stmt s; /* branch stmt */ 2308cf6c252SPaul Traina int mark; 2318cf6c252SPaul Traina int longjt; /* jt branch requires long jump */ 2328cf6c252SPaul Traina int longjf; /* jf branch requires long jump */ 2338cf6c252SPaul Traina int level; 2348cf6c252SPaul Traina int offset; 2358cf6c252SPaul Traina int sense; 2368cf6c252SPaul Traina struct edge et; 2378cf6c252SPaul Traina struct edge ef; 2388cf6c252SPaul Traina struct block *head; 2398cf6c252SPaul Traina struct block *link; /* link field used by optimizer */ 2408cf6c252SPaul Traina uset dom; 2418cf6c252SPaul Traina uset closure; 2428cf6c252SPaul Traina struct edge *in_edges; 2438cf6c252SPaul Traina atomset def, kill; 2448cf6c252SPaul Traina atomset in_use; 2458cf6c252SPaul Traina atomset out_use; 2468cf6c252SPaul Traina int oval; 2478cf6c252SPaul Traina int val[N_ATOMS]; 2488cf6c252SPaul Traina }; 2498cf6c252SPaul Traina 2508cf6c252SPaul Traina struct arth { 2518cf6c252SPaul Traina struct block *b; /* protocol checks */ 2528cf6c252SPaul Traina struct slist *s; /* stmt list */ 2538cf6c252SPaul Traina int regno; /* virtual register number of result */ 2548cf6c252SPaul Traina }; 2558cf6c252SPaul Traina 2568cf6c252SPaul Traina struct qual { 2578cf6c252SPaul Traina unsigned char addr; 2588cf6c252SPaul Traina unsigned char proto; 2598cf6c252SPaul Traina unsigned char dir; 2608cf6c252SPaul Traina unsigned char pad; 2618cf6c252SPaul Traina }; 2628cf6c252SPaul Traina 2638cf6c252SPaul Traina struct arth *gen_loadi(int); 2648cf6c252SPaul Traina struct arth *gen_load(int, struct arth *, int); 2658cf6c252SPaul Traina struct arth *gen_loadlen(void); 2668cf6c252SPaul Traina struct arth *gen_neg(struct arth *); 2678cf6c252SPaul Traina struct arth *gen_arth(int, struct arth *, struct arth *); 2688cf6c252SPaul Traina 2698cf6c252SPaul Traina void gen_and(struct block *, struct block *); 2708cf6c252SPaul Traina void gen_or(struct block *, struct block *); 2718cf6c252SPaul Traina void gen_not(struct block *); 2728cf6c252SPaul Traina 2738cf6c252SPaul Traina struct block *gen_scode(const char *, struct qual); 2748cf6c252SPaul Traina struct block *gen_ecode(const u_char *, struct qual); 275c0653930SBill Fenner struct block *gen_acode(const u_char *, struct qual); 2768cf6c252SPaul Traina struct block *gen_mcode(const char *, const char *, int, struct qual); 277fae05455SBill Fenner #ifdef INET6 278fae05455SBill Fenner struct block *gen_mcode6(const char *, const char *, int, struct qual); 279fae05455SBill Fenner #endif 2808cf6c252SPaul Traina struct block *gen_ncode(const char *, bpf_u_int32, struct qual); 2818cf6c252SPaul Traina struct block *gen_proto_abbrev(int); 2828cf6c252SPaul Traina struct block *gen_relation(int, struct arth *, struct arth *, int); 2838cf6c252SPaul Traina struct block *gen_less(int); 2848cf6c252SPaul Traina struct block *gen_greater(int); 2858cf6c252SPaul Traina struct block *gen_byteop(int, int, int); 2868cf6c252SPaul Traina struct block *gen_broadcast(int); 2878cf6c252SPaul Traina struct block *gen_multicast(int); 2888cf6c252SPaul Traina struct block *gen_inbound(int); 2898cf6c252SPaul Traina 2908e1481d1SBill Fenner struct block *gen_vlan(int); 291c761ebcbSSam Leffler struct block *gen_mpls(int); 2928e1481d1SBill Fenner 293ff252dbeSSam Leffler struct block *gen_pppoed(void); 294ff252dbeSSam Leffler struct block *gen_pppoes(void); 295ff252dbeSSam Leffler 2964238c2cdSSam Leffler struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse); 297eb9f0330SBruce M Simpson struct block *gen_atmtype_abbrev(int type); 298eb9f0330SBruce M Simpson struct block *gen_atmmulti_abbrev(int type); 299eb9f0330SBruce M Simpson 3004238c2cdSSam Leffler struct block *gen_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse); 3014238c2cdSSam Leffler 302eb9f0330SBruce M Simpson struct block *gen_pf_ifname(const char *); 303eb9f0330SBruce M Simpson struct block *gen_pf_rnr(int); 304eb9f0330SBruce M Simpson struct block *gen_pf_srnr(int); 305eb9f0330SBruce M Simpson struct block *gen_pf_ruleset(char *); 306eb9f0330SBruce M Simpson struct block *gen_pf_reason(int); 307eb9f0330SBruce M Simpson struct block *gen_pf_action(int); 308eb9f0330SBruce M Simpson struct block *gen_pf_dir(int); 309eb9f0330SBruce M Simpson 3108cf6c252SPaul Traina void bpf_optimize(struct block **); 3118e1481d1SBill Fenner void bpf_error(const char *, ...) 3124238c2cdSSam Leffler __attribute__((noreturn, format (printf, 1, 2))); 3138cf6c252SPaul Traina 3148cf6c252SPaul Traina void finish_parse(struct block *); 3158cf6c252SPaul Traina char *sdup(const char *); 3168cf6c252SPaul Traina 3178cf6c252SPaul Traina struct bpf_insn *icode_to_fcode(struct block *, int *); 3188cf6c252SPaul Traina int pcap_parse(void); 3198cf6c252SPaul Traina void lex_init(char *); 3208e1481d1SBill Fenner void lex_cleanup(void); 3218cf6c252SPaul Traina void sappend(struct slist *, struct slist *); 3228cf6c252SPaul Traina 3238cf6c252SPaul Traina /* XXX */ 3248cf6c252SPaul Traina #define JT(b) ((b)->et.succ) 3258cf6c252SPaul Traina #define JF(b) ((b)->ef.succ) 326fae05455SBill Fenner 327fae05455SBill Fenner extern int no_optimize; 328