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. 20eb9f0330SBruce M Simpson */ 21eb9f0330SBruce M Simpson 226f9cba8fSJoseph Mingrone #ifndef gencode_h 236f9cba8fSJoseph Mingrone #define gencode_h 246f9cba8fSJoseph Mingrone 25b00ab754SHans Petter Selasky #include "pcap/funcattrs.h" 266f9cba8fSJoseph Mingrone /* 276f9cba8fSJoseph Mingrone * pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be 286f9cba8fSJoseph Mingrone * made available via either pcap-types.h (a private header) or pcap/pcap.h 296f9cba8fSJoseph Mingrone * (a public header), none of which pcap/bpf.h includes. Include the private 306f9cba8fSJoseph Mingrone * header to keep things simple, this way this private header should compile 316f9cba8fSJoseph Mingrone * even if included early from another file. 326f9cba8fSJoseph Mingrone */ 336f9cba8fSJoseph Mingrone #include "pcap-types.h" 346f9cba8fSJoseph Mingrone #include "pcap/bpf.h" /* bpf_u_int32 and BPF_MEMWORDS */ 35b00ab754SHans Petter Selasky 36eb9f0330SBruce M Simpson /* 37eb9f0330SBruce M Simpson * ATM support: 38eb9f0330SBruce M Simpson * 39eb9f0330SBruce M Simpson * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 40eb9f0330SBruce M Simpson * All rights reserved. 41eb9f0330SBruce M Simpson * 42eb9f0330SBruce M Simpson * Redistribution and use in source and binary forms, with or without 43eb9f0330SBruce M Simpson * modification, are permitted provided that the following conditions 44eb9f0330SBruce M Simpson * are met: 45eb9f0330SBruce M Simpson * 1. Redistributions of source code must retain the above copyright 46eb9f0330SBruce M Simpson * notice, this list of conditions and the following disclaimer. 47eb9f0330SBruce M Simpson * 2. Redistributions in binary form must reproduce the above copyright 48eb9f0330SBruce M Simpson * notice, this list of conditions and the following disclaimer in the 49eb9f0330SBruce M Simpson * documentation and/or other materials provided with the distribution. 50eb9f0330SBruce M Simpson * 3. All advertising materials mentioning features or use of this software 51eb9f0330SBruce M Simpson * must display the following acknowledgement: 52eb9f0330SBruce M Simpson * This product includes software developed by Yen Yen Lim and 53eb9f0330SBruce M Simpson * North Dakota State University 54eb9f0330SBruce M Simpson * 4. The name of the author may not be used to endorse or promote products 55eb9f0330SBruce M Simpson * derived from this software without specific prior written permission. 56eb9f0330SBruce M Simpson * 57eb9f0330SBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 58eb9f0330SBruce M Simpson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 59eb9f0330SBruce M Simpson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 60eb9f0330SBruce M Simpson * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 61eb9f0330SBruce M Simpson * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 62eb9f0330SBruce M Simpson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 63eb9f0330SBruce M Simpson * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64eb9f0330SBruce M Simpson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65eb9f0330SBruce M Simpson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 66eb9f0330SBruce M Simpson * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 67eb9f0330SBruce M Simpson * POSSIBILITY OF SUCH DAMAGE. 688cf6c252SPaul Traina */ 698cf6c252SPaul Traina 708cf6c252SPaul Traina /* Address qualifiers. */ 718cf6c252SPaul Traina 728cf6c252SPaul Traina #define Q_HOST 1 738cf6c252SPaul Traina #define Q_NET 2 748cf6c252SPaul Traina #define Q_PORT 3 758cf6c252SPaul Traina #define Q_GATEWAY 4 768cf6c252SPaul Traina #define Q_PROTO 5 77fae05455SBill Fenner #define Q_PROTOCHAIN 6 784238c2cdSSam Leffler #define Q_PORTRANGE 7 798cf6c252SPaul Traina 808cf6c252SPaul Traina /* Protocol qualifiers. */ 818cf6c252SPaul Traina 828cf6c252SPaul Traina #define Q_LINK 1 838cf6c252SPaul Traina #define Q_IP 2 848cf6c252SPaul Traina #define Q_ARP 3 858cf6c252SPaul Traina #define Q_RARP 4 86c0653930SBill Fenner #define Q_SCTP 5 87c0653930SBill Fenner #define Q_TCP 6 88c0653930SBill Fenner #define Q_UDP 7 89c0653930SBill Fenner #define Q_ICMP 8 90c0653930SBill Fenner #define Q_IGMP 9 91c0653930SBill Fenner #define Q_IGRP 10 928cf6c252SPaul Traina 938cf6c252SPaul Traina 94c0653930SBill Fenner #define Q_ATALK 11 95c0653930SBill Fenner #define Q_DECNET 12 96c0653930SBill Fenner #define Q_LAT 13 97c0653930SBill Fenner #define Q_SCA 14 98c0653930SBill Fenner #define Q_MOPRC 15 99c0653930SBill Fenner #define Q_MOPDL 16 100fae05455SBill Fenner 1018e1481d1SBill Fenner 102c0653930SBill Fenner #define Q_IPV6 17 103c0653930SBill Fenner #define Q_ICMPV6 18 104c0653930SBill Fenner #define Q_AH 19 105c0653930SBill Fenner #define Q_ESP 20 106fae05455SBill Fenner 107c0653930SBill Fenner #define Q_PIM 21 108c0653930SBill Fenner #define Q_VRRP 22 109fae05455SBill Fenner 110c0653930SBill Fenner #define Q_AARP 23 1118e1481d1SBill Fenner 112c0653930SBill Fenner #define Q_ISO 24 113c0653930SBill Fenner #define Q_ESIS 25 114c0653930SBill Fenner #define Q_ISIS 26 115c0653930SBill Fenner #define Q_CLNP 27 116c0653930SBill Fenner 117c0653930SBill Fenner #define Q_STP 28 118c0653930SBill Fenner 119c0653930SBill Fenner #define Q_IPX 29 120c0653930SBill Fenner 121c0653930SBill Fenner #define Q_NETBEUI 30 1228cf6c252SPaul Traina 123eb9f0330SBruce M Simpson /* IS-IS Levels */ 124eb9f0330SBruce M Simpson #define Q_ISIS_L1 31 125eb9f0330SBruce M Simpson #define Q_ISIS_L2 32 126eb9f0330SBruce M Simpson /* PDU types */ 127eb9f0330SBruce M Simpson #define Q_ISIS_IIH 33 12857e22627SCy Schubert #define Q_ISIS_SNP 34 12957e22627SCy Schubert #define Q_ISIS_CSNP 35 13057e22627SCy Schubert #define Q_ISIS_PSNP 36 13157e22627SCy Schubert #define Q_ISIS_LSP 37 132eb9f0330SBruce M Simpson 13357e22627SCy Schubert #define Q_RADIO 38 1344238c2cdSSam Leffler 13557e22627SCy Schubert #define Q_CARP 39 136d1e87331SXin LI 1378cf6c252SPaul Traina /* Directional qualifiers. */ 1388cf6c252SPaul Traina 1398cf6c252SPaul Traina #define Q_SRC 1 1408cf6c252SPaul Traina #define Q_DST 2 1418cf6c252SPaul Traina #define Q_OR 3 1428cf6c252SPaul Traina #define Q_AND 4 143a8e07101SRui Paulo #define Q_ADDR1 5 144a8e07101SRui Paulo #define Q_ADDR2 6 145a8e07101SRui Paulo #define Q_ADDR3 7 146a8e07101SRui Paulo #define Q_ADDR4 8 147d1e87331SXin LI #define Q_RA 9 148d1e87331SXin LI #define Q_TA 10 1498cf6c252SPaul Traina 1508cf6c252SPaul Traina #define Q_DEFAULT 0 1518cf6c252SPaul Traina #define Q_UNDEF 255 1528cf6c252SPaul Traina 153eb9f0330SBruce M Simpson /* ATM types */ 154eb9f0330SBruce M Simpson #define A_METAC 22 /* Meta signalling Circuit */ 155eb9f0330SBruce M Simpson #define A_BCC 23 /* Broadcast Circuit */ 156eb9f0330SBruce M Simpson #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 157eb9f0330SBruce M Simpson #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 158eb9f0330SBruce M Simpson #define A_SC 26 /* Signalling Circuit*/ 159eb9f0330SBruce M Simpson #define A_ILMIC 27 /* ILMI Circuit */ 160eb9f0330SBruce M Simpson #define A_OAM 28 /* OAM cells : F4 only */ 161eb9f0330SBruce M Simpson #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 162eb9f0330SBruce M Simpson #define A_LANE 30 /* LANE traffic */ 163eb9f0330SBruce M Simpson #define A_LLC 31 /* LLC-encapsulated traffic */ 164eb9f0330SBruce M Simpson 165eb9f0330SBruce M Simpson /* Based on Q.2931 signalling protocol */ 166eb9f0330SBruce M Simpson #define A_SETUP 41 /* Setup message */ 167eb9f0330SBruce M Simpson #define A_CALLPROCEED 42 /* Call proceeding message */ 168eb9f0330SBruce M Simpson #define A_CONNECT 43 /* Connect message */ 169eb9f0330SBruce M Simpson #define A_CONNECTACK 44 /* Connect Ack message */ 170eb9f0330SBruce M Simpson #define A_RELEASE 45 /* Release message */ 171eb9f0330SBruce M Simpson #define A_RELEASE_DONE 46 /* Release message */ 172eb9f0330SBruce M Simpson 173eb9f0330SBruce M Simpson /* ATM field types */ 174eb9f0330SBruce M Simpson #define A_VPI 51 175eb9f0330SBruce M Simpson #define A_VCI 52 176eb9f0330SBruce M Simpson #define A_PROTOTYPE 53 177eb9f0330SBruce M Simpson #define A_MSGTYPE 54 178eb9f0330SBruce M Simpson #define A_CALLREFTYPE 55 179eb9f0330SBruce M Simpson 180eb9f0330SBruce M Simpson #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 181eb9f0330SBruce M Simpson establishing and destroying switched 182eb9f0330SBruce M Simpson virtual connection */ 183eb9f0330SBruce M Simpson #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 184eb9f0330SBruce M Simpson establishing and destroying predefined 185eb9f0330SBruce M Simpson virtual circuits, such as broadcast 186eb9f0330SBruce M Simpson circuit, oamf4 segment circuit, oamf4 187eb9f0330SBruce M Simpson end-to-end circuits, ILMI circuits or 188eb9f0330SBruce M Simpson connection signalling circuit. */ 189eb9f0330SBruce M Simpson 1905357e0feSMax Laier /* MTP2 types */ 1915357e0feSMax Laier #define M_FISU 22 /* FISU */ 1925357e0feSMax Laier #define M_LSSU 23 /* LSSU */ 1935357e0feSMax Laier #define M_MSU 24 /* MSU */ 1945357e0feSMax Laier 195681ed54cSXin LI /* MTP2 HSL types */ 196681ed54cSXin LI #define MH_FISU 25 /* FISU for HSL */ 197681ed54cSXin LI #define MH_LSSU 26 /* LSSU */ 198681ed54cSXin LI #define MH_MSU 27 /* MSU */ 199681ed54cSXin LI 2004238c2cdSSam Leffler /* MTP3 field types */ 2014238c2cdSSam Leffler #define M_SIO 1 2024238c2cdSSam Leffler #define M_OPC 2 2034238c2cdSSam Leffler #define M_DPC 3 2044238c2cdSSam Leffler #define M_SLS 4 2054238c2cdSSam Leffler 206681ed54cSXin LI /* MTP3 field types in case of MTP2 HSL */ 207681ed54cSXin LI #define MH_SIO 5 208681ed54cSXin LI #define MH_OPC 6 209681ed54cSXin LI #define MH_DPC 7 210681ed54cSXin LI #define MH_SLS 8 211681ed54cSXin LI 2124238c2cdSSam Leffler 213fae05455SBill Fenner struct slist; 214fae05455SBill Fenner 2156f9cba8fSJoseph Mingrone /* 2166f9cba8fSJoseph Mingrone * A single statement, corresponding to an instruction in a block. 2176f9cba8fSJoseph Mingrone */ 2188cf6c252SPaul Traina struct stmt { 2196f9cba8fSJoseph Mingrone int code; /* opcode */ 220fae05455SBill Fenner struct slist *jt; /* only for relative jump in block */ 221fae05455SBill Fenner struct slist *jf; /* only for relative jump in block */ 2226f9cba8fSJoseph Mingrone bpf_u_int32 k; /* k field */ 2238cf6c252SPaul Traina }; 2248cf6c252SPaul Traina 2258cf6c252SPaul Traina struct slist { 2268cf6c252SPaul Traina struct stmt s; 2278cf6c252SPaul Traina struct slist *next; 2288cf6c252SPaul Traina }; 2298cf6c252SPaul Traina 2308cf6c252SPaul Traina /* 2318cf6c252SPaul Traina * A bit vector to represent definition sets. We assume TOT_REGISTERS 2328cf6c252SPaul Traina * is smaller than 8*sizeof(atomset). 2338cf6c252SPaul Traina */ 2348cf6c252SPaul Traina typedef bpf_u_int32 atomset; 2358cf6c252SPaul Traina #define ATOMMASK(n) (1 << (n)) 2368cf6c252SPaul Traina #define ATOMELEM(d, n) (d & ATOMMASK(n)) 2378cf6c252SPaul Traina 2388cf6c252SPaul Traina /* 2398cf6c252SPaul Traina * An unbounded set. 2408cf6c252SPaul Traina */ 2418cf6c252SPaul Traina typedef bpf_u_int32 *uset; 2428cf6c252SPaul Traina 2438cf6c252SPaul Traina /* 2448cf6c252SPaul Traina * Total number of atomic entities, including accumulator (A) and index (X). 2458cf6c252SPaul Traina * We treat all these guys similarly during flow analysis. 2468cf6c252SPaul Traina */ 2478cf6c252SPaul Traina #define N_ATOMS (BPF_MEMWORDS+2) 2488cf6c252SPaul Traina 2496f9cba8fSJoseph Mingrone /* 2506f9cba8fSJoseph Mingrone * Control flow graph of a program. 2516f9cba8fSJoseph Mingrone * This corresponds to an edge in the CFG. 2526f9cba8fSJoseph Mingrone * It's a directed graph, so an edge has a predecessor and a successor. 2536f9cba8fSJoseph Mingrone */ 2548cf6c252SPaul Traina struct edge { 2556f9cba8fSJoseph Mingrone u_int id; 2566f9cba8fSJoseph Mingrone int code; /* opcode for branch corresponding to this edge */ 2578cf6c252SPaul Traina uset edom; 2586f9cba8fSJoseph Mingrone struct block *succ; /* successor vertex */ 2596f9cba8fSJoseph Mingrone struct block *pred; /* predecessor vertex */ 2608cf6c252SPaul Traina struct edge *next; /* link list of incoming edges for a node */ 2618cf6c252SPaul Traina }; 2628cf6c252SPaul Traina 2636f9cba8fSJoseph Mingrone /* 2646f9cba8fSJoseph Mingrone * A block is a vertex in the CFG. 2656f9cba8fSJoseph Mingrone * It has a list of statements, with the final statement being a 2666f9cba8fSJoseph Mingrone * branch to successor blocks. 2676f9cba8fSJoseph Mingrone */ 2688cf6c252SPaul Traina struct block { 2696f9cba8fSJoseph Mingrone u_int id; 2708cf6c252SPaul Traina struct slist *stmts; /* side effect stmts */ 2718cf6c252SPaul Traina struct stmt s; /* branch stmt */ 2728cf6c252SPaul Traina int mark; 27315752fa8SXin LI u_int longjt; /* jt branch requires long jump */ 27415752fa8SXin LI u_int longjf; /* jf branch requires long jump */ 2758cf6c252SPaul Traina int level; 2768cf6c252SPaul Traina int offset; 2778cf6c252SPaul Traina int sense; 2786f9cba8fSJoseph Mingrone struct edge et; /* edge corresponding to the jt branch */ 2796f9cba8fSJoseph Mingrone struct edge ef; /* edge corresponding to the jf branch */ 2808cf6c252SPaul Traina struct block *head; 2818cf6c252SPaul Traina struct block *link; /* link field used by optimizer */ 2828cf6c252SPaul Traina uset dom; 2838cf6c252SPaul Traina uset closure; 2846f9cba8fSJoseph Mingrone struct edge *in_edges; /* first edge in the set (linked list) of edges with this as a successor */ 2858cf6c252SPaul Traina atomset def, kill; 2868cf6c252SPaul Traina atomset in_use; 2878cf6c252SPaul Traina atomset out_use; 2886f9cba8fSJoseph Mingrone int oval; /* value ID for value tested in branch stmt */ 2896f9cba8fSJoseph Mingrone bpf_u_int32 val[N_ATOMS]; 2908cf6c252SPaul Traina }; 2918cf6c252SPaul Traina 292b00ab754SHans Petter Selasky /* 293b00ab754SHans Petter Selasky * A value of 0 for val[i] means the value is unknown. 294b00ab754SHans Petter Selasky */ 295b00ab754SHans Petter Selasky #define VAL_UNKNOWN 0 296b00ab754SHans Petter Selasky 2978cf6c252SPaul Traina struct arth { 2988cf6c252SPaul Traina struct block *b; /* protocol checks */ 2998cf6c252SPaul Traina struct slist *s; /* stmt list */ 3008cf6c252SPaul Traina int regno; /* virtual register number of result */ 3018cf6c252SPaul Traina }; 3028cf6c252SPaul Traina 3038cf6c252SPaul Traina struct qual { 3048cf6c252SPaul Traina unsigned char addr; 3058cf6c252SPaul Traina unsigned char proto; 3068cf6c252SPaul Traina unsigned char dir; 3078cf6c252SPaul Traina unsigned char pad; 3088cf6c252SPaul Traina }; 3098cf6c252SPaul Traina 310ada6f083SXin LI struct _compiler_state; 311ada6f083SXin LI 312ada6f083SXin LI typedef struct _compiler_state compiler_state_t; 313ada6f083SXin LI 3146f9cba8fSJoseph Mingrone struct arth *gen_loadi(compiler_state_t *, bpf_u_int32); 3156f9cba8fSJoseph Mingrone struct arth *gen_load(compiler_state_t *, int, struct arth *, bpf_u_int32); 316ada6f083SXin LI struct arth *gen_loadlen(compiler_state_t *); 317ada6f083SXin LI struct arth *gen_neg(compiler_state_t *, struct arth *); 318ada6f083SXin LI struct arth *gen_arth(compiler_state_t *, int, struct arth *, struct arth *); 3198cf6c252SPaul Traina 3208cf6c252SPaul Traina void gen_and(struct block *, struct block *); 3218cf6c252SPaul Traina void gen_or(struct block *, struct block *); 3228cf6c252SPaul Traina void gen_not(struct block *); 3238cf6c252SPaul Traina 324ada6f083SXin LI struct block *gen_scode(compiler_state_t *, const char *, struct qual); 32557e22627SCy Schubert struct block *gen_ecode(compiler_state_t *, const char *, struct qual); 32657e22627SCy Schubert struct block *gen_acode(compiler_state_t *, const char *, struct qual); 327ada6f083SXin LI struct block *gen_mcode(compiler_state_t *, const char *, const char *, 3286f9cba8fSJoseph Mingrone bpf_u_int32, struct qual); 329fae05455SBill Fenner #ifdef INET6 330*afdbf109SJoseph Mingrone struct block *gen_mcode6(compiler_state_t *, const char *, bpf_u_int32, 331*afdbf109SJoseph Mingrone struct qual); 332fae05455SBill Fenner #endif 333ada6f083SXin LI struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32, 334ada6f083SXin LI struct qual); 335ada6f083SXin LI struct block *gen_proto_abbrev(compiler_state_t *, int); 336ada6f083SXin LI struct block *gen_relation(compiler_state_t *, int, struct arth *, 337ada6f083SXin LI struct arth *, int); 338ada6f083SXin LI struct block *gen_less(compiler_state_t *, int); 339ada6f083SXin LI struct block *gen_greater(compiler_state_t *, int); 3406f9cba8fSJoseph Mingrone struct block *gen_byteop(compiler_state_t *, int, int, bpf_u_int32); 341ada6f083SXin LI struct block *gen_broadcast(compiler_state_t *, int); 342ada6f083SXin LI struct block *gen_multicast(compiler_state_t *, int); 3436f9cba8fSJoseph Mingrone struct block *gen_ifindex(compiler_state_t *, int); 344ada6f083SXin LI struct block *gen_inbound(compiler_state_t *, int); 3458cf6c252SPaul Traina 346ada6f083SXin LI struct block *gen_llc(compiler_state_t *); 347ada6f083SXin LI struct block *gen_llc_i(compiler_state_t *); 348ada6f083SXin LI struct block *gen_llc_s(compiler_state_t *); 349ada6f083SXin LI struct block *gen_llc_u(compiler_state_t *); 350ada6f083SXin LI struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); 351ada6f083SXin LI struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); 352681ed54cSXin LI 35357e22627SCy Schubert struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int); 35457e22627SCy Schubert struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int); 3558e1481d1SBill Fenner 356ada6f083SXin LI struct block *gen_pppoed(compiler_state_t *); 35757e22627SCy Schubert struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int); 358ff252dbeSSam Leffler 35957e22627SCy Schubert struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int); 360eb9f0330SBruce M Simpson 3616f9cba8fSJoseph Mingrone struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32, 3626f9cba8fSJoseph Mingrone int, int); 3636f9cba8fSJoseph Mingrone struct block *gen_atmtype_abbrev(compiler_state_t *, int); 3646f9cba8fSJoseph Mingrone struct block *gen_atmmulti_abbrev(compiler_state_t *, int); 3654238c2cdSSam Leffler 3666f9cba8fSJoseph Mingrone struct block *gen_mtp2type_abbrev(compiler_state_t *, int); 367ada6f083SXin LI struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, 3686f9cba8fSJoseph Mingrone int, int); 369eb9f0330SBruce M Simpson 370ada6f083SXin LI struct block *gen_pf_ifname(compiler_state_t *, const char *); 371ada6f083SXin LI struct block *gen_pf_rnr(compiler_state_t *, int); 372ada6f083SXin LI struct block *gen_pf_srnr(compiler_state_t *, int); 373ada6f083SXin LI struct block *gen_pf_ruleset(compiler_state_t *, char *); 374ada6f083SXin LI struct block *gen_pf_reason(compiler_state_t *, int); 375ada6f083SXin LI struct block *gen_pf_action(compiler_state_t *, int); 376a8e07101SRui Paulo 3776f9cba8fSJoseph Mingrone struct block *gen_p80211_type(compiler_state_t *, bpf_u_int32, bpf_u_int32); 3786f9cba8fSJoseph Mingrone struct block *gen_p80211_fcdir(compiler_state_t *, bpf_u_int32); 379ada6f083SXin LI 380ada6f083SXin LI /* 381ada6f083SXin LI * Representation of a program as a tree of blocks, plus current mark. 382ada6f083SXin LI * A block is marked if only if its mark equals the current mark. 383ada6f083SXin LI * Rather than traverse the code array, marking each item, 'cur_mark' 384ada6f083SXin LI * is incremented. This automatically makes each element unmarked. 385ada6f083SXin LI */ 386ada6f083SXin LI #define isMarked(icp, p) ((p)->mark == (icp)->cur_mark) 387ada6f083SXin LI #define unMarkAll(icp) (icp)->cur_mark += 1 388ada6f083SXin LI #define Mark(icp, p) ((p)->mark = (icp)->cur_mark) 389ada6f083SXin LI 390ada6f083SXin LI struct icode { 391ada6f083SXin LI struct block *root; 392ada6f083SXin LI int cur_mark; 393ada6f083SXin LI }; 394ada6f083SXin LI 39557e22627SCy Schubert int bpf_optimize(struct icode *, char *); 39657e22627SCy Schubert void bpf_set_error(compiler_state_t *, const char *, ...) 397b00ab754SHans Petter Selasky PCAP_PRINTFLIKE(2, 3); 3988cf6c252SPaul Traina 39957e22627SCy Schubert int finish_parse(compiler_state_t *, struct block *); 400ada6f083SXin LI char *sdup(compiler_state_t *, const char *); 4018cf6c252SPaul Traina 40257e22627SCy Schubert struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, 40357e22627SCy Schubert char *); 4048cf6c252SPaul Traina void sappend(struct slist *, struct slist *); 4058cf6c252SPaul Traina 406ada6f083SXin LI /* 407ada6f083SXin LI * Older versions of Bison don't put this declaration in 408ada6f083SXin LI * grammar.h. 409ada6f083SXin LI */ 410ada6f083SXin LI int pcap_parse(void *, compiler_state_t *); 411ada6f083SXin LI 4128cf6c252SPaul Traina /* XXX */ 4138cf6c252SPaul Traina #define JT(b) ((b)->et.succ) 4148cf6c252SPaul Traina #define JF(b) ((b)->ef.succ) 4156f9cba8fSJoseph Mingrone 4166f9cba8fSJoseph Mingrone #endif /* gencode_h */ 417