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. 20feb4ecdbSBruce M Simpson */ 21feb4ecdbSBruce M Simpson 2235af88c9SJoseph Mingrone #ifndef gencode_h 2335af88c9SJoseph Mingrone #define gencode_h 2435af88c9SJoseph Mingrone 25d109bf9eSHans Petter Selasky #include "pcap/funcattrs.h" 2635af88c9SJoseph Mingrone /* 2735af88c9SJoseph Mingrone * pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be 2835af88c9SJoseph Mingrone * made available via either pcap-types.h (a private header) or pcap/pcap.h 2935af88c9SJoseph Mingrone * (a public header), none of which pcap/bpf.h includes. Include the private 3035af88c9SJoseph Mingrone * header to keep things simple, this way this private header should compile 3135af88c9SJoseph Mingrone * even if included early from another file. 3235af88c9SJoseph Mingrone */ 3335af88c9SJoseph Mingrone #include "pcap-types.h" 3435af88c9SJoseph Mingrone #include "pcap/bpf.h" /* bpf_u_int32 and BPF_MEMWORDS */ 35d109bf9eSHans Petter Selasky 36feb4ecdbSBruce M Simpson /* 37feb4ecdbSBruce M Simpson * ATM support: 38feb4ecdbSBruce M Simpson * 39feb4ecdbSBruce M Simpson * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 40feb4ecdbSBruce M Simpson * All rights reserved. 41feb4ecdbSBruce M Simpson * 42feb4ecdbSBruce M Simpson * Redistribution and use in source and binary forms, with or without 43feb4ecdbSBruce M Simpson * modification, are permitted provided that the following conditions 44feb4ecdbSBruce M Simpson * are met: 45feb4ecdbSBruce M Simpson * 1. Redistributions of source code must retain the above copyright 46feb4ecdbSBruce M Simpson * notice, this list of conditions and the following disclaimer. 47feb4ecdbSBruce M Simpson * 2. Redistributions in binary form must reproduce the above copyright 48feb4ecdbSBruce M Simpson * notice, this list of conditions and the following disclaimer in the 49feb4ecdbSBruce M Simpson * documentation and/or other materials provided with the distribution. 50feb4ecdbSBruce M Simpson * 3. All advertising materials mentioning features or use of this software 51feb4ecdbSBruce M Simpson * must display the following acknowledgement: 52feb4ecdbSBruce M Simpson * This product includes software developed by Yen Yen Lim and 53feb4ecdbSBruce M Simpson * North Dakota State University 54feb4ecdbSBruce M Simpson * 4. The name of the author may not be used to endorse or promote products 55feb4ecdbSBruce M Simpson * derived from this software without specific prior written permission. 56feb4ecdbSBruce M Simpson * 57feb4ecdbSBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 58feb4ecdbSBruce M Simpson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 59feb4ecdbSBruce M Simpson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 60feb4ecdbSBruce M Simpson * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 61feb4ecdbSBruce M Simpson * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 62feb4ecdbSBruce M Simpson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 63feb4ecdbSBruce M Simpson * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64feb4ecdbSBruce M Simpson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65feb4ecdbSBruce M Simpson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 66feb4ecdbSBruce M Simpson * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 67feb4ecdbSBruce 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 778751327cSBill Fenner #define Q_PROTOCHAIN 6 78ee2dd488SSam 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 860a94d38fSBill Fenner #define Q_SCTP 5 870a94d38fSBill Fenner #define Q_TCP 6 880a94d38fSBill Fenner #define Q_UDP 7 890a94d38fSBill Fenner #define Q_ICMP 8 900a94d38fSBill Fenner #define Q_IGMP 9 910a94d38fSBill Fenner #define Q_IGRP 10 928cf6c252SPaul Traina 938cf6c252SPaul Traina 940a94d38fSBill Fenner #define Q_ATALK 11 950a94d38fSBill Fenner #define Q_DECNET 12 960a94d38fSBill Fenner #define Q_LAT 13 970a94d38fSBill Fenner #define Q_SCA 14 980a94d38fSBill Fenner #define Q_MOPRC 15 990a94d38fSBill Fenner #define Q_MOPDL 16 1008cf6c252SPaul Traina 1018751327cSBill Fenner 1020a94d38fSBill Fenner #define Q_IPV6 17 1030a94d38fSBill Fenner #define Q_ICMPV6 18 1040a94d38fSBill Fenner #define Q_AH 19 1050a94d38fSBill Fenner #define Q_ESP 20 1068751327cSBill Fenner 1070a94d38fSBill Fenner #define Q_PIM 21 1080a94d38fSBill Fenner #define Q_VRRP 22 1098751327cSBill Fenner 1100a94d38fSBill Fenner #define Q_AARP 23 111dc2c7305SBill Fenner 1120a94d38fSBill Fenner #define Q_ISO 24 1130a94d38fSBill Fenner #define Q_ESIS 25 1140a94d38fSBill Fenner #define Q_ISIS 26 1150a94d38fSBill Fenner #define Q_CLNP 27 1160a94d38fSBill Fenner 1170a94d38fSBill Fenner #define Q_STP 28 1180a94d38fSBill Fenner 1190a94d38fSBill Fenner #define Q_IPX 29 1200a94d38fSBill Fenner 1210a94d38fSBill Fenner #define Q_NETBEUI 30 122dc2c7305SBill Fenner 123feb4ecdbSBruce M Simpson /* IS-IS Levels */ 124feb4ecdbSBruce M Simpson #define Q_ISIS_L1 31 125feb4ecdbSBruce M Simpson #define Q_ISIS_L2 32 126feb4ecdbSBruce M Simpson /* PDU types */ 127feb4ecdbSBruce M Simpson #define Q_ISIS_IIH 33 12830a580a8SPhilip Paeps #define Q_ISIS_SNP 34 12930a580a8SPhilip Paeps #define Q_ISIS_CSNP 35 13030a580a8SPhilip Paeps #define Q_ISIS_PSNP 36 13130a580a8SPhilip Paeps #define Q_ISIS_LSP 37 132feb4ecdbSBruce M Simpson 13330a580a8SPhilip Paeps #define Q_RADIO 38 134ee2dd488SSam Leffler 13530a580a8SPhilip Paeps #define Q_CARP 39 13659f06eaaSGeorge V. Neville-Neil 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 143c6a6c5e2SRui Paulo #define Q_ADDR1 5 144c6a6c5e2SRui Paulo #define Q_ADDR2 6 145c6a6c5e2SRui Paulo #define Q_ADDR3 7 146c6a6c5e2SRui Paulo #define Q_ADDR4 8 14759f06eaaSGeorge V. Neville-Neil #define Q_RA 9 14859f06eaaSGeorge V. Neville-Neil #define Q_TA 10 1498cf6c252SPaul Traina 1508cf6c252SPaul Traina #define Q_DEFAULT 0 1518cf6c252SPaul Traina #define Q_UNDEF 255 1528cf6c252SPaul Traina 153feb4ecdbSBruce M Simpson /* ATM types */ 154feb4ecdbSBruce M Simpson #define A_METAC 22 /* Meta signalling Circuit */ 155feb4ecdbSBruce M Simpson #define A_BCC 23 /* Broadcast Circuit */ 156feb4ecdbSBruce M Simpson #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 157feb4ecdbSBruce M Simpson #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 158feb4ecdbSBruce M Simpson #define A_SC 26 /* Signalling Circuit*/ 159feb4ecdbSBruce M Simpson #define A_ILMIC 27 /* ILMI Circuit */ 160feb4ecdbSBruce M Simpson #define A_OAM 28 /* OAM cells : F4 only */ 161feb4ecdbSBruce M Simpson #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 162feb4ecdbSBruce M Simpson #define A_LANE 30 /* LANE traffic */ 163feb4ecdbSBruce M Simpson #define A_LLC 31 /* LLC-encapsulated traffic */ 164feb4ecdbSBruce M Simpson 165feb4ecdbSBruce M Simpson /* Based on Q.2931 signalling protocol */ 166feb4ecdbSBruce M Simpson #define A_SETUP 41 /* Setup message */ 167feb4ecdbSBruce M Simpson #define A_CALLPROCEED 42 /* Call proceeding message */ 168feb4ecdbSBruce M Simpson #define A_CONNECT 43 /* Connect message */ 169feb4ecdbSBruce M Simpson #define A_CONNECTACK 44 /* Connect Ack message */ 170feb4ecdbSBruce M Simpson #define A_RELEASE 45 /* Release message */ 171feb4ecdbSBruce M Simpson #define A_RELEASE_DONE 46 /* Release message */ 172feb4ecdbSBruce M Simpson 173feb4ecdbSBruce M Simpson /* ATM field types */ 174feb4ecdbSBruce M Simpson #define A_VPI 51 175feb4ecdbSBruce M Simpson #define A_VCI 52 176feb4ecdbSBruce M Simpson #define A_PROTOTYPE 53 177feb4ecdbSBruce M Simpson #define A_MSGTYPE 54 178feb4ecdbSBruce M Simpson #define A_CALLREFTYPE 55 179feb4ecdbSBruce M Simpson 180feb4ecdbSBruce M Simpson #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 181feb4ecdbSBruce M Simpson establishing and destroying switched 182feb4ecdbSBruce M Simpson virtual connection */ 183feb4ecdbSBruce M Simpson #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 184feb4ecdbSBruce M Simpson establishing and destroying predefined 185feb4ecdbSBruce M Simpson virtual circuits, such as broadcast 186feb4ecdbSBruce M Simpson circuit, oamf4 segment circuit, oamf4 187feb4ecdbSBruce M Simpson end-to-end circuits, ILMI circuits or 188feb4ecdbSBruce M Simpson connection signalling circuit. */ 189feb4ecdbSBruce M Simpson 190ef96d74fSMax Laier /* MTP2 types */ 191ef96d74fSMax Laier #define M_FISU 22 /* FISU */ 192ef96d74fSMax Laier #define M_LSSU 23 /* LSSU */ 193ef96d74fSMax Laier #define M_MSU 24 /* MSU */ 194ef96d74fSMax Laier 19550224b10SXin LI /* MTP2 HSL types */ 19650224b10SXin LI #define MH_FISU 25 /* FISU for HSL */ 19750224b10SXin LI #define MH_LSSU 26 /* LSSU */ 19850224b10SXin LI #define MH_MSU 27 /* MSU */ 19950224b10SXin LI 200ee2dd488SSam Leffler /* MTP3 field types */ 201ee2dd488SSam Leffler #define M_SIO 1 202ee2dd488SSam Leffler #define M_OPC 2 203ee2dd488SSam Leffler #define M_DPC 3 204ee2dd488SSam Leffler #define M_SLS 4 205ee2dd488SSam Leffler 20650224b10SXin LI /* MTP3 field types in case of MTP2 HSL */ 20750224b10SXin LI #define MH_SIO 5 20850224b10SXin LI #define MH_OPC 6 20950224b10SXin LI #define MH_DPC 7 21050224b10SXin LI #define MH_SLS 8 21150224b10SXin LI 212ee2dd488SSam Leffler 2138751327cSBill Fenner struct slist; 2148751327cSBill Fenner 21535af88c9SJoseph Mingrone /* 21635af88c9SJoseph Mingrone * A single statement, corresponding to an instruction in a block. 21735af88c9SJoseph Mingrone */ 2188cf6c252SPaul Traina struct stmt { 21935af88c9SJoseph Mingrone int code; /* opcode */ 2208751327cSBill Fenner struct slist *jt; /* only for relative jump in block */ 2218751327cSBill Fenner struct slist *jf; /* only for relative jump in block */ 22235af88c9SJoseph 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 24935af88c9SJoseph Mingrone /* 25035af88c9SJoseph Mingrone * Control flow graph of a program. 25135af88c9SJoseph Mingrone * This corresponds to an edge in the CFG. 25235af88c9SJoseph Mingrone * It's a directed graph, so an edge has a predecessor and a successor. 25335af88c9SJoseph Mingrone */ 2548cf6c252SPaul Traina struct edge { 25535af88c9SJoseph Mingrone u_int id; 25635af88c9SJoseph Mingrone int code; /* opcode for branch corresponding to this edge */ 2578cf6c252SPaul Traina uset edom; 25835af88c9SJoseph Mingrone struct block *succ; /* successor vertex */ 25935af88c9SJoseph Mingrone struct block *pred; /* predecessor vertex */ 2608cf6c252SPaul Traina struct edge *next; /* link list of incoming edges for a node */ 2618cf6c252SPaul Traina }; 2628cf6c252SPaul Traina 26335af88c9SJoseph Mingrone /* 26435af88c9SJoseph Mingrone * A block is a vertex in the CFG. 26535af88c9SJoseph Mingrone * It has a list of statements, with the final statement being a 26635af88c9SJoseph Mingrone * branch to successor blocks. 26735af88c9SJoseph Mingrone */ 2688cf6c252SPaul Traina struct block { 26935af88c9SJoseph Mingrone u_int id; 2708cf6c252SPaul Traina struct slist *stmts; /* side effect stmts */ 2718cf6c252SPaul Traina struct stmt s; /* branch stmt */ 2728cf6c252SPaul Traina int mark; 2733ca61f8bSXin LI u_int longjt; /* jt branch requires long jump */ 2743ca61f8bSXin LI u_int longjf; /* jf branch requires long jump */ 2758cf6c252SPaul Traina int level; 2768cf6c252SPaul Traina int offset; 2778cf6c252SPaul Traina int sense; 27835af88c9SJoseph Mingrone struct edge et; /* edge corresponding to the jt branch */ 27935af88c9SJoseph 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; 28435af88c9SJoseph 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; 28835af88c9SJoseph Mingrone int oval; /* value ID for value tested in branch stmt */ 28935af88c9SJoseph Mingrone bpf_u_int32 val[N_ATOMS]; 2908cf6c252SPaul Traina }; 2918cf6c252SPaul Traina 292d109bf9eSHans Petter Selasky /* 293d109bf9eSHans Petter Selasky * A value of 0 for val[i] means the value is unknown. 294d109bf9eSHans Petter Selasky */ 295d109bf9eSHans Petter Selasky #define VAL_UNKNOWN 0 296d109bf9eSHans 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 310c8c6d70eSXin LI struct _compiler_state; 311c8c6d70eSXin LI 312c8c6d70eSXin LI typedef struct _compiler_state compiler_state_t; 313c8c6d70eSXin LI 31435af88c9SJoseph Mingrone struct arth *gen_loadi(compiler_state_t *, bpf_u_int32); 31535af88c9SJoseph Mingrone struct arth *gen_load(compiler_state_t *, int, struct arth *, bpf_u_int32); 316c8c6d70eSXin LI struct arth *gen_loadlen(compiler_state_t *); 317c8c6d70eSXin LI struct arth *gen_neg(compiler_state_t *, struct arth *); 318c8c6d70eSXin 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 324c8c6d70eSXin LI struct block *gen_scode(compiler_state_t *, const char *, struct qual); 32530a580a8SPhilip Paeps struct block *gen_ecode(compiler_state_t *, const char *, struct qual); 32630a580a8SPhilip Paeps struct block *gen_acode(compiler_state_t *, const char *, struct qual); 327c8c6d70eSXin LI struct block *gen_mcode(compiler_state_t *, const char *, const char *, 32835af88c9SJoseph Mingrone bpf_u_int32, struct qual); 3298751327cSBill Fenner #ifdef INET6 330025be3f5SJoseph Mingrone struct block *gen_mcode6(compiler_state_t *, const char *, bpf_u_int32, 331025be3f5SJoseph Mingrone struct qual); 3328751327cSBill Fenner #endif 333c8c6d70eSXin LI struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32, 334c8c6d70eSXin LI struct qual); 335c8c6d70eSXin LI struct block *gen_proto_abbrev(compiler_state_t *, int); 336c8c6d70eSXin LI struct block *gen_relation(compiler_state_t *, int, struct arth *, 337c8c6d70eSXin LI struct arth *, int); 338c8c6d70eSXin LI struct block *gen_less(compiler_state_t *, int); 339c8c6d70eSXin LI struct block *gen_greater(compiler_state_t *, int); 34035af88c9SJoseph Mingrone struct block *gen_byteop(compiler_state_t *, int, int, bpf_u_int32); 341c8c6d70eSXin LI struct block *gen_broadcast(compiler_state_t *, int); 342c8c6d70eSXin LI struct block *gen_multicast(compiler_state_t *, int); 34335af88c9SJoseph Mingrone struct block *gen_ifindex(compiler_state_t *, int); 344c8c6d70eSXin LI struct block *gen_inbound(compiler_state_t *, int); 3458cf6c252SPaul Traina 346c8c6d70eSXin LI struct block *gen_llc(compiler_state_t *); 347c8c6d70eSXin LI struct block *gen_llc_i(compiler_state_t *); 348c8c6d70eSXin LI struct block *gen_llc_s(compiler_state_t *); 349c8c6d70eSXin LI struct block *gen_llc_u(compiler_state_t *); 350c8c6d70eSXin LI struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); 351c8c6d70eSXin LI struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); 35250224b10SXin LI 35330a580a8SPhilip Paeps struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int); 35430a580a8SPhilip Paeps struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int); 355dc2c7305SBill Fenner 356c8c6d70eSXin LI struct block *gen_pppoed(compiler_state_t *); 35730a580a8SPhilip Paeps struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int); 3585d18909fSSam Leffler 35930a580a8SPhilip Paeps struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int); 360feb4ecdbSBruce M Simpson 36135af88c9SJoseph Mingrone struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32, 36235af88c9SJoseph Mingrone int, int); 36335af88c9SJoseph Mingrone struct block *gen_atmtype_abbrev(compiler_state_t *, int); 36435af88c9SJoseph Mingrone struct block *gen_atmmulti_abbrev(compiler_state_t *, int); 365ee2dd488SSam Leffler 36635af88c9SJoseph Mingrone struct block *gen_mtp2type_abbrev(compiler_state_t *, int); 367c8c6d70eSXin LI struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, 36835af88c9SJoseph Mingrone int, int); 369feb4ecdbSBruce M Simpson 370c8c6d70eSXin LI struct block *gen_pf_ifname(compiler_state_t *, const char *); 371c8c6d70eSXin LI struct block *gen_pf_rnr(compiler_state_t *, int); 372c8c6d70eSXin LI struct block *gen_pf_srnr(compiler_state_t *, int); 373c8c6d70eSXin LI struct block *gen_pf_ruleset(compiler_state_t *, char *); 374c8c6d70eSXin LI struct block *gen_pf_reason(compiler_state_t *, int); 375c8c6d70eSXin LI struct block *gen_pf_action(compiler_state_t *, int); 376c6a6c5e2SRui Paulo 37735af88c9SJoseph Mingrone struct block *gen_p80211_type(compiler_state_t *, bpf_u_int32, bpf_u_int32); 37835af88c9SJoseph Mingrone struct block *gen_p80211_fcdir(compiler_state_t *, bpf_u_int32); 379c8c6d70eSXin LI 380c8c6d70eSXin LI /* 381c8c6d70eSXin LI * Representation of a program as a tree of blocks, plus current mark. 382c8c6d70eSXin LI * A block is marked if only if its mark equals the current mark. 383c8c6d70eSXin LI * Rather than traverse the code array, marking each item, 'cur_mark' 384c8c6d70eSXin LI * is incremented. This automatically makes each element unmarked. 385c8c6d70eSXin LI */ 386c8c6d70eSXin LI #define isMarked(icp, p) ((p)->mark == (icp)->cur_mark) 387c8c6d70eSXin LI #define unMarkAll(icp) (icp)->cur_mark += 1 388c8c6d70eSXin LI #define Mark(icp, p) ((p)->mark = (icp)->cur_mark) 389c8c6d70eSXin LI 390c8c6d70eSXin LI struct icode { 391c8c6d70eSXin LI struct block *root; 392c8c6d70eSXin LI int cur_mark; 393c8c6d70eSXin LI }; 394c8c6d70eSXin LI 39530a580a8SPhilip Paeps int bpf_optimize(struct icode *, char *); 39630a580a8SPhilip Paeps void bpf_set_error(compiler_state_t *, const char *, ...) 397d109bf9eSHans Petter Selasky PCAP_PRINTFLIKE(2, 3); 3988cf6c252SPaul Traina 39930a580a8SPhilip Paeps int finish_parse(compiler_state_t *, struct block *); 400c8c6d70eSXin LI char *sdup(compiler_state_t *, const char *); 4018cf6c252SPaul Traina 40230a580a8SPhilip Paeps struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, 40330a580a8SPhilip Paeps char *); 4048cf6c252SPaul Traina void sappend(struct slist *, struct slist *); 4058cf6c252SPaul Traina 406c8c6d70eSXin LI /* 407c8c6d70eSXin LI * Older versions of Bison don't put this declaration in 408c8c6d70eSXin LI * grammar.h. 409c8c6d70eSXin LI */ 410c8c6d70eSXin LI int pcap_parse(void *, compiler_state_t *); 411c8c6d70eSXin LI 4128cf6c252SPaul Traina /* XXX */ 4138cf6c252SPaul Traina #define JT(b) ((b)->et.succ) 4148cf6c252SPaul Traina #define JF(b) ((b)->ef.succ) 41535af88c9SJoseph Mingrone 41635af88c9SJoseph Mingrone #endif /* gencode_h */ 417