11077d0bdSPeter Avalos /* 21077d0bdSPeter Avalos * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 31077d0bdSPeter Avalos * The Regents of the University of California. All rights reserved. 41077d0bdSPeter Avalos * 51077d0bdSPeter Avalos * Redistribution and use in source and binary forms, with or without 61077d0bdSPeter Avalos * modification, are permitted provided that: (1) source code distributions 71077d0bdSPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2) 81077d0bdSPeter Avalos * distributions including binary code include the above copyright notice and 91077d0bdSPeter Avalos * this paragraph in its entirety in the documentation or other materials 101077d0bdSPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning 111077d0bdSPeter Avalos * features or use of this software display the following acknowledgement: 121077d0bdSPeter Avalos * ``This product includes software developed by the University of California, 131077d0bdSPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 141077d0bdSPeter Avalos * the University nor the names of its contributors may be used to endorse 151077d0bdSPeter Avalos * or promote products derived from this software without specific prior 161077d0bdSPeter Avalos * written permission. 171077d0bdSPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 181077d0bdSPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 191077d0bdSPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 201077d0bdSPeter Avalos */ 211077d0bdSPeter Avalos 223a289941SAaron LI #include "pcap/funcattrs.h" 233a289941SAaron LI 241077d0bdSPeter Avalos /* 251077d0bdSPeter Avalos * ATM support: 261077d0bdSPeter Avalos * 271077d0bdSPeter Avalos * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 281077d0bdSPeter Avalos * All rights reserved. 291077d0bdSPeter Avalos * 301077d0bdSPeter Avalos * Redistribution and use in source and binary forms, with or without 311077d0bdSPeter Avalos * modification, are permitted provided that the following conditions 321077d0bdSPeter Avalos * are met: 331077d0bdSPeter Avalos * 1. Redistributions of source code must retain the above copyright 341077d0bdSPeter Avalos * notice, this list of conditions and the following disclaimer. 351077d0bdSPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 361077d0bdSPeter Avalos * notice, this list of conditions and the following disclaimer in the 371077d0bdSPeter Avalos * documentation and/or other materials provided with the distribution. 381077d0bdSPeter Avalos * 3. All advertising materials mentioning features or use of this software 391077d0bdSPeter Avalos * must display the following acknowledgement: 401077d0bdSPeter Avalos * This product includes software developed by Yen Yen Lim and 411077d0bdSPeter Avalos * North Dakota State University 421077d0bdSPeter Avalos * 4. The name of the author may not be used to endorse or promote products 431077d0bdSPeter Avalos * derived from this software without specific prior written permission. 441077d0bdSPeter Avalos * 451077d0bdSPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 461077d0bdSPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 471077d0bdSPeter Avalos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 481077d0bdSPeter Avalos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 491077d0bdSPeter Avalos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 501077d0bdSPeter Avalos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 511077d0bdSPeter Avalos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 521077d0bdSPeter Avalos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 531077d0bdSPeter Avalos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 541077d0bdSPeter Avalos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 551077d0bdSPeter Avalos * POSSIBILITY OF SUCH DAMAGE. 561077d0bdSPeter Avalos */ 571077d0bdSPeter Avalos 581077d0bdSPeter Avalos /* Address qualifiers. */ 591077d0bdSPeter Avalos 601077d0bdSPeter Avalos #define Q_HOST 1 611077d0bdSPeter Avalos #define Q_NET 2 621077d0bdSPeter Avalos #define Q_PORT 3 631077d0bdSPeter Avalos #define Q_GATEWAY 4 641077d0bdSPeter Avalos #define Q_PROTO 5 651077d0bdSPeter Avalos #define Q_PROTOCHAIN 6 661077d0bdSPeter Avalos #define Q_PORTRANGE 7 671077d0bdSPeter Avalos 681077d0bdSPeter Avalos /* Protocol qualifiers. */ 691077d0bdSPeter Avalos 701077d0bdSPeter Avalos #define Q_LINK 1 711077d0bdSPeter Avalos #define Q_IP 2 721077d0bdSPeter Avalos #define Q_ARP 3 731077d0bdSPeter Avalos #define Q_RARP 4 741077d0bdSPeter Avalos #define Q_SCTP 5 751077d0bdSPeter Avalos #define Q_TCP 6 761077d0bdSPeter Avalos #define Q_UDP 7 771077d0bdSPeter Avalos #define Q_ICMP 8 781077d0bdSPeter Avalos #define Q_IGMP 9 791077d0bdSPeter Avalos #define Q_IGRP 10 801077d0bdSPeter Avalos 811077d0bdSPeter Avalos 821077d0bdSPeter Avalos #define Q_ATALK 11 831077d0bdSPeter Avalos #define Q_DECNET 12 841077d0bdSPeter Avalos #define Q_LAT 13 851077d0bdSPeter Avalos #define Q_SCA 14 861077d0bdSPeter Avalos #define Q_MOPRC 15 871077d0bdSPeter Avalos #define Q_MOPDL 16 881077d0bdSPeter Avalos 891077d0bdSPeter Avalos 901077d0bdSPeter Avalos #define Q_IPV6 17 911077d0bdSPeter Avalos #define Q_ICMPV6 18 921077d0bdSPeter Avalos #define Q_AH 19 931077d0bdSPeter Avalos #define Q_ESP 20 941077d0bdSPeter Avalos 951077d0bdSPeter Avalos #define Q_PIM 21 961077d0bdSPeter Avalos #define Q_VRRP 22 971077d0bdSPeter Avalos 981077d0bdSPeter Avalos #define Q_AARP 23 991077d0bdSPeter Avalos 1001077d0bdSPeter Avalos #define Q_ISO 24 1011077d0bdSPeter Avalos #define Q_ESIS 25 1021077d0bdSPeter Avalos #define Q_ISIS 26 1031077d0bdSPeter Avalos #define Q_CLNP 27 1041077d0bdSPeter Avalos 1051077d0bdSPeter Avalos #define Q_STP 28 1061077d0bdSPeter Avalos 1071077d0bdSPeter Avalos #define Q_IPX 29 1081077d0bdSPeter Avalos 1091077d0bdSPeter Avalos #define Q_NETBEUI 30 1101077d0bdSPeter Avalos 1111077d0bdSPeter Avalos /* IS-IS Levels */ 1121077d0bdSPeter Avalos #define Q_ISIS_L1 31 1131077d0bdSPeter Avalos #define Q_ISIS_L2 32 1141077d0bdSPeter Avalos /* PDU types */ 1151077d0bdSPeter Avalos #define Q_ISIS_IIH 33 1163a289941SAaron LI #define Q_ISIS_SNP 34 1173a289941SAaron LI #define Q_ISIS_CSNP 35 1183a289941SAaron LI #define Q_ISIS_PSNP 36 1193a289941SAaron LI #define Q_ISIS_LSP 37 1201077d0bdSPeter Avalos 1213a289941SAaron LI #define Q_RADIO 38 1221077d0bdSPeter Avalos 1233a289941SAaron LI #define Q_CARP 39 124a85e14b0SPeter Avalos 1251077d0bdSPeter Avalos /* Directional qualifiers. */ 1261077d0bdSPeter Avalos 1271077d0bdSPeter Avalos #define Q_SRC 1 1281077d0bdSPeter Avalos #define Q_DST 2 1291077d0bdSPeter Avalos #define Q_OR 3 1301077d0bdSPeter Avalos #define Q_AND 4 131de0d3203SPeter Avalos #define Q_ADDR1 5 132de0d3203SPeter Avalos #define Q_ADDR2 6 133de0d3203SPeter Avalos #define Q_ADDR3 7 134de0d3203SPeter Avalos #define Q_ADDR4 8 135a85e14b0SPeter Avalos #define Q_RA 9 136a85e14b0SPeter Avalos #define Q_TA 10 1371077d0bdSPeter Avalos 1381077d0bdSPeter Avalos #define Q_DEFAULT 0 1391077d0bdSPeter Avalos #define Q_UNDEF 255 1401077d0bdSPeter Avalos 1411077d0bdSPeter Avalos /* ATM types */ 1421077d0bdSPeter Avalos #define A_METAC 22 /* Meta signalling Circuit */ 1431077d0bdSPeter Avalos #define A_BCC 23 /* Broadcast Circuit */ 1441077d0bdSPeter Avalos #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 1451077d0bdSPeter Avalos #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 1461077d0bdSPeter Avalos #define A_SC 26 /* Signalling Circuit*/ 1471077d0bdSPeter Avalos #define A_ILMIC 27 /* ILMI Circuit */ 1481077d0bdSPeter Avalos #define A_OAM 28 /* OAM cells : F4 only */ 1491077d0bdSPeter Avalos #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 1501077d0bdSPeter Avalos #define A_LANE 30 /* LANE traffic */ 1511077d0bdSPeter Avalos #define A_LLC 31 /* LLC-encapsulated traffic */ 1521077d0bdSPeter Avalos 1531077d0bdSPeter Avalos /* Based on Q.2931 signalling protocol */ 1541077d0bdSPeter Avalos #define A_SETUP 41 /* Setup message */ 1551077d0bdSPeter Avalos #define A_CALLPROCEED 42 /* Call proceeding message */ 1561077d0bdSPeter Avalos #define A_CONNECT 43 /* Connect message */ 1571077d0bdSPeter Avalos #define A_CONNECTACK 44 /* Connect Ack message */ 1581077d0bdSPeter Avalos #define A_RELEASE 45 /* Release message */ 1591077d0bdSPeter Avalos #define A_RELEASE_DONE 46 /* Release message */ 1601077d0bdSPeter Avalos 1611077d0bdSPeter Avalos /* ATM field types */ 1621077d0bdSPeter Avalos #define A_VPI 51 1631077d0bdSPeter Avalos #define A_VCI 52 1641077d0bdSPeter Avalos #define A_PROTOTYPE 53 1651077d0bdSPeter Avalos #define A_MSGTYPE 54 1661077d0bdSPeter Avalos #define A_CALLREFTYPE 55 1671077d0bdSPeter Avalos 1681077d0bdSPeter Avalos #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 1691077d0bdSPeter Avalos establishing and destroying switched 1701077d0bdSPeter Avalos virtual connection */ 1711077d0bdSPeter Avalos #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 1721077d0bdSPeter Avalos establishing and destroying predefined 1731077d0bdSPeter Avalos virtual circuits, such as broadcast 1741077d0bdSPeter Avalos circuit, oamf4 segment circuit, oamf4 1751077d0bdSPeter Avalos end-to-end circuits, ILMI circuits or 1761077d0bdSPeter Avalos connection signalling circuit. */ 1771077d0bdSPeter Avalos 1781077d0bdSPeter Avalos /* MTP2 types */ 1791077d0bdSPeter Avalos #define M_FISU 22 /* FISU */ 1801077d0bdSPeter Avalos #define M_LSSU 23 /* LSSU */ 1811077d0bdSPeter Avalos #define M_MSU 24 /* MSU */ 1821077d0bdSPeter Avalos 18397a9217aSAntonio Huete Jimenez /* MTP2 HSL types */ 18497a9217aSAntonio Huete Jimenez #define MH_FISU 25 /* FISU for HSL */ 18597a9217aSAntonio Huete Jimenez #define MH_LSSU 26 /* LSSU */ 18697a9217aSAntonio Huete Jimenez #define MH_MSU 27 /* MSU */ 18797a9217aSAntonio Huete Jimenez 1881077d0bdSPeter Avalos /* MTP3 field types */ 1891077d0bdSPeter Avalos #define M_SIO 1 1901077d0bdSPeter Avalos #define M_OPC 2 1911077d0bdSPeter Avalos #define M_DPC 3 1921077d0bdSPeter Avalos #define M_SLS 4 1931077d0bdSPeter Avalos 19497a9217aSAntonio Huete Jimenez /* MTP3 field types in case of MTP2 HSL */ 19597a9217aSAntonio Huete Jimenez #define MH_SIO 5 19697a9217aSAntonio Huete Jimenez #define MH_OPC 6 19797a9217aSAntonio Huete Jimenez #define MH_DPC 7 19897a9217aSAntonio Huete Jimenez #define MH_SLS 8 19997a9217aSAntonio Huete Jimenez 2001077d0bdSPeter Avalos 2011077d0bdSPeter Avalos struct slist; 2021077d0bdSPeter Avalos 203*ea16f64eSAntonio Huete Jimenez /* 204*ea16f64eSAntonio Huete Jimenez * A single statement, corresponding to an instruction in a block. 205*ea16f64eSAntonio Huete Jimenez */ 2061077d0bdSPeter Avalos struct stmt { 207*ea16f64eSAntonio Huete Jimenez int code; /* opcode */ 2081077d0bdSPeter Avalos struct slist *jt; /* only for relative jump in block */ 2091077d0bdSPeter Avalos struct slist *jf; /* only for relative jump in block */ 210*ea16f64eSAntonio Huete Jimenez bpf_u_int32 k; /* k field */ 2111077d0bdSPeter Avalos }; 2121077d0bdSPeter Avalos 2131077d0bdSPeter Avalos struct slist { 2141077d0bdSPeter Avalos struct stmt s; 2151077d0bdSPeter Avalos struct slist *next; 2161077d0bdSPeter Avalos }; 2171077d0bdSPeter Avalos 2181077d0bdSPeter Avalos /* 2191077d0bdSPeter Avalos * A bit vector to represent definition sets. We assume TOT_REGISTERS 2201077d0bdSPeter Avalos * is smaller than 8*sizeof(atomset). 2211077d0bdSPeter Avalos */ 2221077d0bdSPeter Avalos typedef bpf_u_int32 atomset; 2231077d0bdSPeter Avalos #define ATOMMASK(n) (1 << (n)) 2241077d0bdSPeter Avalos #define ATOMELEM(d, n) (d & ATOMMASK(n)) 2251077d0bdSPeter Avalos 2261077d0bdSPeter Avalos /* 2271077d0bdSPeter Avalos * An unbounded set. 2281077d0bdSPeter Avalos */ 2291077d0bdSPeter Avalos typedef bpf_u_int32 *uset; 2301077d0bdSPeter Avalos 2311077d0bdSPeter Avalos /* 2321077d0bdSPeter Avalos * Total number of atomic entities, including accumulator (A) and index (X). 2331077d0bdSPeter Avalos * We treat all these guys similarly during flow analysis. 2341077d0bdSPeter Avalos */ 2351077d0bdSPeter Avalos #define N_ATOMS (BPF_MEMWORDS+2) 2361077d0bdSPeter Avalos 237*ea16f64eSAntonio Huete Jimenez /* 238*ea16f64eSAntonio Huete Jimenez * Control flow graph of a program. 239*ea16f64eSAntonio Huete Jimenez * This corresponds to an edge in the CFG. 240*ea16f64eSAntonio Huete Jimenez * It's a directed graph, so an edge has a predecessor and a successor. 241*ea16f64eSAntonio Huete Jimenez */ 2421077d0bdSPeter Avalos struct edge { 243*ea16f64eSAntonio Huete Jimenez u_int id; 244*ea16f64eSAntonio Huete Jimenez int code; /* opcode for branch corresponding to this edge */ 2451077d0bdSPeter Avalos uset edom; 246*ea16f64eSAntonio Huete Jimenez struct block *succ; /* successor vertex */ 247*ea16f64eSAntonio Huete Jimenez struct block *pred; /* predecessor vertex */ 2481077d0bdSPeter Avalos struct edge *next; /* link list of incoming edges for a node */ 2491077d0bdSPeter Avalos }; 2501077d0bdSPeter Avalos 251*ea16f64eSAntonio Huete Jimenez /* 252*ea16f64eSAntonio Huete Jimenez * A block is a vertex in the CFG. 253*ea16f64eSAntonio Huete Jimenez * It has a list of statements, with the final statement being a 254*ea16f64eSAntonio Huete Jimenez * branch to successor blocks. 255*ea16f64eSAntonio Huete Jimenez */ 2561077d0bdSPeter Avalos struct block { 257*ea16f64eSAntonio Huete Jimenez u_int id; 2581077d0bdSPeter Avalos struct slist *stmts; /* side effect stmts */ 2591077d0bdSPeter Avalos struct stmt s; /* branch stmt */ 2601077d0bdSPeter Avalos int mark; 2610e1eae1fSPeter Avalos u_int longjt; /* jt branch requires long jump */ 2620e1eae1fSPeter Avalos u_int longjf; /* jf branch requires long jump */ 2631077d0bdSPeter Avalos int level; 2641077d0bdSPeter Avalos int offset; 2651077d0bdSPeter Avalos int sense; 266*ea16f64eSAntonio Huete Jimenez struct edge et; /* edge corresponding to the jt branch */ 267*ea16f64eSAntonio Huete Jimenez struct edge ef; /* edge corresponding to the jf branch */ 2681077d0bdSPeter Avalos struct block *head; 2691077d0bdSPeter Avalos struct block *link; /* link field used by optimizer */ 2701077d0bdSPeter Avalos uset dom; 2711077d0bdSPeter Avalos uset closure; 272*ea16f64eSAntonio Huete Jimenez struct edge *in_edges; /* first edge in the set (linked list) of edges with this as a successor */ 2731077d0bdSPeter Avalos atomset def, kill; 2741077d0bdSPeter Avalos atomset in_use; 2751077d0bdSPeter Avalos atomset out_use; 276*ea16f64eSAntonio Huete Jimenez int oval; /* value ID for value tested in branch stmt */ 277*ea16f64eSAntonio Huete Jimenez bpf_u_int32 val[N_ATOMS]; 2781077d0bdSPeter Avalos }; 2791077d0bdSPeter Avalos 2803a289941SAaron LI /* 2813a289941SAaron LI * A value of 0 for val[i] means the value is unknown. 2823a289941SAaron LI */ 2833a289941SAaron LI #define VAL_UNKNOWN 0 2843a289941SAaron LI 2851077d0bdSPeter Avalos struct arth { 2861077d0bdSPeter Avalos struct block *b; /* protocol checks */ 2871077d0bdSPeter Avalos struct slist *s; /* stmt list */ 2881077d0bdSPeter Avalos int regno; /* virtual register number of result */ 2891077d0bdSPeter Avalos }; 2901077d0bdSPeter Avalos 2911077d0bdSPeter Avalos struct qual { 2921077d0bdSPeter Avalos unsigned char addr; 2931077d0bdSPeter Avalos unsigned char proto; 2941077d0bdSPeter Avalos unsigned char dir; 2951077d0bdSPeter Avalos unsigned char pad; 2961077d0bdSPeter Avalos }; 2971077d0bdSPeter Avalos 29897a9217aSAntonio Huete Jimenez struct _compiler_state; 29997a9217aSAntonio Huete Jimenez 30097a9217aSAntonio Huete Jimenez typedef struct _compiler_state compiler_state_t; 30197a9217aSAntonio Huete Jimenez 302*ea16f64eSAntonio Huete Jimenez struct arth *gen_loadi(compiler_state_t *, bpf_u_int32); 303*ea16f64eSAntonio Huete Jimenez struct arth *gen_load(compiler_state_t *, int, struct arth *, bpf_u_int32); 30497a9217aSAntonio Huete Jimenez struct arth *gen_loadlen(compiler_state_t *); 30597a9217aSAntonio Huete Jimenez struct arth *gen_neg(compiler_state_t *, struct arth *); 30697a9217aSAntonio Huete Jimenez struct arth *gen_arth(compiler_state_t *, int, struct arth *, struct arth *); 3071077d0bdSPeter Avalos 3081077d0bdSPeter Avalos void gen_and(struct block *, struct block *); 3091077d0bdSPeter Avalos void gen_or(struct block *, struct block *); 3101077d0bdSPeter Avalos void gen_not(struct block *); 3111077d0bdSPeter Avalos 31297a9217aSAntonio Huete Jimenez struct block *gen_scode(compiler_state_t *, const char *, struct qual); 3133a289941SAaron LI struct block *gen_ecode(compiler_state_t *, const char *, struct qual); 3143a289941SAaron LI struct block *gen_acode(compiler_state_t *, const char *, struct qual); 31597a9217aSAntonio Huete Jimenez struct block *gen_mcode(compiler_state_t *, const char *, const char *, 316*ea16f64eSAntonio Huete Jimenez bpf_u_int32, struct qual); 3171077d0bdSPeter Avalos #ifdef INET6 31897a9217aSAntonio Huete Jimenez struct block *gen_mcode6(compiler_state_t *, const char *, const char *, 319*ea16f64eSAntonio Huete Jimenez bpf_u_int32, struct qual); 3201077d0bdSPeter Avalos #endif 32197a9217aSAntonio Huete Jimenez struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32, 32297a9217aSAntonio Huete Jimenez struct qual); 32397a9217aSAntonio Huete Jimenez struct block *gen_proto_abbrev(compiler_state_t *, int); 32497a9217aSAntonio Huete Jimenez struct block *gen_relation(compiler_state_t *, int, struct arth *, 32597a9217aSAntonio Huete Jimenez struct arth *, int); 32697a9217aSAntonio Huete Jimenez struct block *gen_less(compiler_state_t *, int); 32797a9217aSAntonio Huete Jimenez struct block *gen_greater(compiler_state_t *, int); 328*ea16f64eSAntonio Huete Jimenez struct block *gen_byteop(compiler_state_t *, int, int, bpf_u_int32); 32997a9217aSAntonio Huete Jimenez struct block *gen_broadcast(compiler_state_t *, int); 33097a9217aSAntonio Huete Jimenez struct block *gen_multicast(compiler_state_t *, int); 331*ea16f64eSAntonio Huete Jimenez struct block *gen_ifindex(compiler_state_t *, int); 33297a9217aSAntonio Huete Jimenez struct block *gen_inbound(compiler_state_t *, int); 3331077d0bdSPeter Avalos 33497a9217aSAntonio Huete Jimenez struct block *gen_llc(compiler_state_t *); 33597a9217aSAntonio Huete Jimenez struct block *gen_llc_i(compiler_state_t *); 33697a9217aSAntonio Huete Jimenez struct block *gen_llc_s(compiler_state_t *); 33797a9217aSAntonio Huete Jimenez struct block *gen_llc_u(compiler_state_t *); 33897a9217aSAntonio Huete Jimenez struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); 33997a9217aSAntonio Huete Jimenez struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); 3401077d0bdSPeter Avalos 3413a289941SAaron LI struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int); 3423a289941SAaron LI struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int); 3431077d0bdSPeter Avalos 34497a9217aSAntonio Huete Jimenez struct block *gen_pppoed(compiler_state_t *); 3453a289941SAaron LI struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int); 3461077d0bdSPeter Avalos 3473a289941SAaron LI struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int); 3481077d0bdSPeter Avalos 349*ea16f64eSAntonio Huete Jimenez struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32, 350*ea16f64eSAntonio Huete Jimenez int, int); 351*ea16f64eSAntonio Huete Jimenez struct block *gen_atmtype_abbrev(compiler_state_t *, int); 352*ea16f64eSAntonio Huete Jimenez struct block *gen_atmmulti_abbrev(compiler_state_t *, int); 3531077d0bdSPeter Avalos 354*ea16f64eSAntonio Huete Jimenez struct block *gen_mtp2type_abbrev(compiler_state_t *, int); 35597a9217aSAntonio Huete Jimenez struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, 356*ea16f64eSAntonio Huete Jimenez int, int); 357de0d3203SPeter Avalos 35897a9217aSAntonio Huete Jimenez struct block *gen_pf_ifname(compiler_state_t *, const char *); 35997a9217aSAntonio Huete Jimenez struct block *gen_pf_rnr(compiler_state_t *, int); 36097a9217aSAntonio Huete Jimenez struct block *gen_pf_srnr(compiler_state_t *, int); 36197a9217aSAntonio Huete Jimenez struct block *gen_pf_ruleset(compiler_state_t *, char *); 36297a9217aSAntonio Huete Jimenez struct block *gen_pf_reason(compiler_state_t *, int); 36397a9217aSAntonio Huete Jimenez struct block *gen_pf_action(compiler_state_t *, int); 3641077d0bdSPeter Avalos 365*ea16f64eSAntonio Huete Jimenez struct block *gen_p80211_type(compiler_state_t *, bpf_u_int32, bpf_u_int32); 366*ea16f64eSAntonio Huete Jimenez struct block *gen_p80211_fcdir(compiler_state_t *, bpf_u_int32); 3671077d0bdSPeter Avalos 36897a9217aSAntonio Huete Jimenez /* 36997a9217aSAntonio Huete Jimenez * Representation of a program as a tree of blocks, plus current mark. 37097a9217aSAntonio Huete Jimenez * A block is marked if only if its mark equals the current mark. 37197a9217aSAntonio Huete Jimenez * Rather than traverse the code array, marking each item, 'cur_mark' 37297a9217aSAntonio Huete Jimenez * is incremented. This automatically makes each element unmarked. 37397a9217aSAntonio Huete Jimenez */ 37497a9217aSAntonio Huete Jimenez #define isMarked(icp, p) ((p)->mark == (icp)->cur_mark) 37597a9217aSAntonio Huete Jimenez #define unMarkAll(icp) (icp)->cur_mark += 1 37697a9217aSAntonio Huete Jimenez #define Mark(icp, p) ((p)->mark = (icp)->cur_mark) 37797a9217aSAntonio Huete Jimenez 37897a9217aSAntonio Huete Jimenez struct icode { 37997a9217aSAntonio Huete Jimenez struct block *root; 38097a9217aSAntonio Huete Jimenez int cur_mark; 38197a9217aSAntonio Huete Jimenez }; 38297a9217aSAntonio Huete Jimenez 3833a289941SAaron LI int bpf_optimize(struct icode *, char *); 3843a289941SAaron LI void bpf_set_error(compiler_state_t *, const char *, ...) 3853a289941SAaron LI PCAP_PRINTFLIKE(2, 3); 38697a9217aSAntonio Huete Jimenez 3873a289941SAaron LI int finish_parse(compiler_state_t *, struct block *); 38897a9217aSAntonio Huete Jimenez char *sdup(compiler_state_t *, const char *); 38997a9217aSAntonio Huete Jimenez 3903a289941SAaron LI struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, 3913a289941SAaron LI char *); 3921077d0bdSPeter Avalos void sappend(struct slist *, struct slist *); 3931077d0bdSPeter Avalos 39497a9217aSAntonio Huete Jimenez /* 39597a9217aSAntonio Huete Jimenez * Older versions of Bison don't put this declaration in 39697a9217aSAntonio Huete Jimenez * grammar.h. 39797a9217aSAntonio Huete Jimenez */ 39897a9217aSAntonio Huete Jimenez int pcap_parse(void *, compiler_state_t *); 39997a9217aSAntonio Huete Jimenez 4001077d0bdSPeter Avalos /* XXX */ 4011077d0bdSPeter Avalos #define JT(b) ((b)->et.succ) 4021077d0bdSPeter Avalos #define JF(b) ((b)->ef.succ) 403