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 221077d0bdSPeter Avalos /* 231077d0bdSPeter Avalos * ATM support: 241077d0bdSPeter Avalos * 251077d0bdSPeter Avalos * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 261077d0bdSPeter Avalos * All rights reserved. 271077d0bdSPeter Avalos * 281077d0bdSPeter Avalos * Redistribution and use in source and binary forms, with or without 291077d0bdSPeter Avalos * modification, are permitted provided that the following conditions 301077d0bdSPeter Avalos * are met: 311077d0bdSPeter Avalos * 1. Redistributions of source code must retain the above copyright 321077d0bdSPeter Avalos * notice, this list of conditions and the following disclaimer. 331077d0bdSPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 341077d0bdSPeter Avalos * notice, this list of conditions and the following disclaimer in the 351077d0bdSPeter Avalos * documentation and/or other materials provided with the distribution. 361077d0bdSPeter Avalos * 3. All advertising materials mentioning features or use of this software 371077d0bdSPeter Avalos * must display the following acknowledgement: 381077d0bdSPeter Avalos * This product includes software developed by Yen Yen Lim and 391077d0bdSPeter Avalos * North Dakota State University 401077d0bdSPeter Avalos * 4. The name of the author may not be used to endorse or promote products 411077d0bdSPeter Avalos * derived from this software without specific prior written permission. 421077d0bdSPeter Avalos * 431077d0bdSPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 441077d0bdSPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 451077d0bdSPeter Avalos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 461077d0bdSPeter Avalos * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 471077d0bdSPeter Avalos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 481077d0bdSPeter Avalos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 491077d0bdSPeter Avalos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 501077d0bdSPeter Avalos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 511077d0bdSPeter Avalos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 521077d0bdSPeter Avalos * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 531077d0bdSPeter Avalos * POSSIBILITY OF SUCH DAMAGE. 541077d0bdSPeter Avalos */ 551077d0bdSPeter Avalos 561077d0bdSPeter Avalos #ifndef HAVE___ATTRIBUTE__ 571077d0bdSPeter Avalos #define __attribute__(x) 581077d0bdSPeter Avalos #endif /* HAVE___ATTRIBUTE__ */ 591077d0bdSPeter Avalos 601077d0bdSPeter Avalos /* Address qualifiers. */ 611077d0bdSPeter Avalos 621077d0bdSPeter Avalos #define Q_HOST 1 631077d0bdSPeter Avalos #define Q_NET 2 641077d0bdSPeter Avalos #define Q_PORT 3 651077d0bdSPeter Avalos #define Q_GATEWAY 4 661077d0bdSPeter Avalos #define Q_PROTO 5 671077d0bdSPeter Avalos #define Q_PROTOCHAIN 6 681077d0bdSPeter Avalos #define Q_PORTRANGE 7 691077d0bdSPeter Avalos 701077d0bdSPeter Avalos /* Protocol qualifiers. */ 711077d0bdSPeter Avalos 721077d0bdSPeter Avalos #define Q_LINK 1 731077d0bdSPeter Avalos #define Q_IP 2 741077d0bdSPeter Avalos #define Q_ARP 3 751077d0bdSPeter Avalos #define Q_RARP 4 761077d0bdSPeter Avalos #define Q_SCTP 5 771077d0bdSPeter Avalos #define Q_TCP 6 781077d0bdSPeter Avalos #define Q_UDP 7 791077d0bdSPeter Avalos #define Q_ICMP 8 801077d0bdSPeter Avalos #define Q_IGMP 9 811077d0bdSPeter Avalos #define Q_IGRP 10 821077d0bdSPeter Avalos 831077d0bdSPeter Avalos 841077d0bdSPeter Avalos #define Q_ATALK 11 851077d0bdSPeter Avalos #define Q_DECNET 12 861077d0bdSPeter Avalos #define Q_LAT 13 871077d0bdSPeter Avalos #define Q_SCA 14 881077d0bdSPeter Avalos #define Q_MOPRC 15 891077d0bdSPeter Avalos #define Q_MOPDL 16 901077d0bdSPeter Avalos 911077d0bdSPeter Avalos 921077d0bdSPeter Avalos #define Q_IPV6 17 931077d0bdSPeter Avalos #define Q_ICMPV6 18 941077d0bdSPeter Avalos #define Q_AH 19 951077d0bdSPeter Avalos #define Q_ESP 20 961077d0bdSPeter Avalos 971077d0bdSPeter Avalos #define Q_PIM 21 981077d0bdSPeter Avalos #define Q_VRRP 22 991077d0bdSPeter Avalos 1001077d0bdSPeter Avalos #define Q_AARP 23 1011077d0bdSPeter Avalos 1021077d0bdSPeter Avalos #define Q_ISO 24 1031077d0bdSPeter Avalos #define Q_ESIS 25 1041077d0bdSPeter Avalos #define Q_ISIS 26 1051077d0bdSPeter Avalos #define Q_CLNP 27 1061077d0bdSPeter Avalos 1071077d0bdSPeter Avalos #define Q_STP 28 1081077d0bdSPeter Avalos 1091077d0bdSPeter Avalos #define Q_IPX 29 1101077d0bdSPeter Avalos 1111077d0bdSPeter Avalos #define Q_NETBEUI 30 1121077d0bdSPeter Avalos 1131077d0bdSPeter Avalos /* IS-IS Levels */ 1141077d0bdSPeter Avalos #define Q_ISIS_L1 31 1151077d0bdSPeter Avalos #define Q_ISIS_L2 32 1161077d0bdSPeter Avalos /* PDU types */ 1171077d0bdSPeter Avalos #define Q_ISIS_IIH 33 1181077d0bdSPeter Avalos #define Q_ISIS_LAN_IIH 34 1191077d0bdSPeter Avalos #define Q_ISIS_PTP_IIH 35 1201077d0bdSPeter Avalos #define Q_ISIS_SNP 36 1211077d0bdSPeter Avalos #define Q_ISIS_CSNP 37 1221077d0bdSPeter Avalos #define Q_ISIS_PSNP 38 1231077d0bdSPeter Avalos #define Q_ISIS_LSP 39 1241077d0bdSPeter Avalos 1251077d0bdSPeter Avalos #define Q_RADIO 40 1261077d0bdSPeter Avalos 127a85e14b0SPeter Avalos #define Q_CARP 41 128a85e14b0SPeter Avalos 1291077d0bdSPeter Avalos /* Directional qualifiers. */ 1301077d0bdSPeter Avalos 1311077d0bdSPeter Avalos #define Q_SRC 1 1321077d0bdSPeter Avalos #define Q_DST 2 1331077d0bdSPeter Avalos #define Q_OR 3 1341077d0bdSPeter Avalos #define Q_AND 4 135de0d3203SPeter Avalos #define Q_ADDR1 5 136de0d3203SPeter Avalos #define Q_ADDR2 6 137de0d3203SPeter Avalos #define Q_ADDR3 7 138de0d3203SPeter Avalos #define Q_ADDR4 8 139a85e14b0SPeter Avalos #define Q_RA 9 140a85e14b0SPeter Avalos #define Q_TA 10 1411077d0bdSPeter Avalos 1421077d0bdSPeter Avalos #define Q_DEFAULT 0 1431077d0bdSPeter Avalos #define Q_UNDEF 255 1441077d0bdSPeter Avalos 1451077d0bdSPeter Avalos /* ATM types */ 1461077d0bdSPeter Avalos #define A_METAC 22 /* Meta signalling Circuit */ 1471077d0bdSPeter Avalos #define A_BCC 23 /* Broadcast Circuit */ 1481077d0bdSPeter Avalos #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 1491077d0bdSPeter Avalos #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 1501077d0bdSPeter Avalos #define A_SC 26 /* Signalling Circuit*/ 1511077d0bdSPeter Avalos #define A_ILMIC 27 /* ILMI Circuit */ 1521077d0bdSPeter Avalos #define A_OAM 28 /* OAM cells : F4 only */ 1531077d0bdSPeter Avalos #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 1541077d0bdSPeter Avalos #define A_LANE 30 /* LANE traffic */ 1551077d0bdSPeter Avalos #define A_LLC 31 /* LLC-encapsulated traffic */ 1561077d0bdSPeter Avalos 1571077d0bdSPeter Avalos /* Based on Q.2931 signalling protocol */ 1581077d0bdSPeter Avalos #define A_SETUP 41 /* Setup message */ 1591077d0bdSPeter Avalos #define A_CALLPROCEED 42 /* Call proceeding message */ 1601077d0bdSPeter Avalos #define A_CONNECT 43 /* Connect message */ 1611077d0bdSPeter Avalos #define A_CONNECTACK 44 /* Connect Ack message */ 1621077d0bdSPeter Avalos #define A_RELEASE 45 /* Release message */ 1631077d0bdSPeter Avalos #define A_RELEASE_DONE 46 /* Release message */ 1641077d0bdSPeter Avalos 1651077d0bdSPeter Avalos /* ATM field types */ 1661077d0bdSPeter Avalos #define A_VPI 51 1671077d0bdSPeter Avalos #define A_VCI 52 1681077d0bdSPeter Avalos #define A_PROTOTYPE 53 1691077d0bdSPeter Avalos #define A_MSGTYPE 54 1701077d0bdSPeter Avalos #define A_CALLREFTYPE 55 1711077d0bdSPeter Avalos 1721077d0bdSPeter Avalos #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 1731077d0bdSPeter Avalos establishing and destroying switched 1741077d0bdSPeter Avalos virtual connection */ 1751077d0bdSPeter Avalos #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 1761077d0bdSPeter Avalos establishing and destroying predefined 1771077d0bdSPeter Avalos virtual circuits, such as broadcast 1781077d0bdSPeter Avalos circuit, oamf4 segment circuit, oamf4 1791077d0bdSPeter Avalos end-to-end circuits, ILMI circuits or 1801077d0bdSPeter Avalos connection signalling circuit. */ 1811077d0bdSPeter Avalos 1821077d0bdSPeter Avalos /* MTP2 types */ 1831077d0bdSPeter Avalos #define M_FISU 22 /* FISU */ 1841077d0bdSPeter Avalos #define M_LSSU 23 /* LSSU */ 1851077d0bdSPeter Avalos #define M_MSU 24 /* MSU */ 1861077d0bdSPeter Avalos 187*97a9217aSAntonio Huete Jimenez /* MTP2 HSL types */ 188*97a9217aSAntonio Huete Jimenez #define MH_FISU 25 /* FISU for HSL */ 189*97a9217aSAntonio Huete Jimenez #define MH_LSSU 26 /* LSSU */ 190*97a9217aSAntonio Huete Jimenez #define MH_MSU 27 /* MSU */ 191*97a9217aSAntonio Huete Jimenez 1921077d0bdSPeter Avalos /* MTP3 field types */ 1931077d0bdSPeter Avalos #define M_SIO 1 1941077d0bdSPeter Avalos #define M_OPC 2 1951077d0bdSPeter Avalos #define M_DPC 3 1961077d0bdSPeter Avalos #define M_SLS 4 1971077d0bdSPeter Avalos 198*97a9217aSAntonio Huete Jimenez /* MTP3 field types in case of MTP2 HSL */ 199*97a9217aSAntonio Huete Jimenez #define MH_SIO 5 200*97a9217aSAntonio Huete Jimenez #define MH_OPC 6 201*97a9217aSAntonio Huete Jimenez #define MH_DPC 7 202*97a9217aSAntonio Huete Jimenez #define MH_SLS 8 203*97a9217aSAntonio Huete Jimenez 2041077d0bdSPeter Avalos 2051077d0bdSPeter Avalos struct slist; 2061077d0bdSPeter Avalos 2071077d0bdSPeter Avalos struct stmt { 2081077d0bdSPeter Avalos int code; 2091077d0bdSPeter Avalos struct slist *jt; /*only for relative jump in block*/ 2101077d0bdSPeter Avalos struct slist *jf; /*only for relative jump in block*/ 2111077d0bdSPeter Avalos bpf_int32 k; 2121077d0bdSPeter Avalos }; 2131077d0bdSPeter Avalos 2141077d0bdSPeter Avalos struct slist { 2151077d0bdSPeter Avalos struct stmt s; 2161077d0bdSPeter Avalos struct slist *next; 2171077d0bdSPeter Avalos }; 2181077d0bdSPeter Avalos 2191077d0bdSPeter Avalos /* 2201077d0bdSPeter Avalos * A bit vector to represent definition sets. We assume TOT_REGISTERS 2211077d0bdSPeter Avalos * is smaller than 8*sizeof(atomset). 2221077d0bdSPeter Avalos */ 2231077d0bdSPeter Avalos typedef bpf_u_int32 atomset; 2241077d0bdSPeter Avalos #define ATOMMASK(n) (1 << (n)) 2251077d0bdSPeter Avalos #define ATOMELEM(d, n) (d & ATOMMASK(n)) 2261077d0bdSPeter Avalos 2271077d0bdSPeter Avalos /* 2281077d0bdSPeter Avalos * An unbounded set. 2291077d0bdSPeter Avalos */ 2301077d0bdSPeter Avalos typedef bpf_u_int32 *uset; 2311077d0bdSPeter Avalos 2321077d0bdSPeter Avalos /* 2331077d0bdSPeter Avalos * Total number of atomic entities, including accumulator (A) and index (X). 2341077d0bdSPeter Avalos * We treat all these guys similarly during flow analysis. 2351077d0bdSPeter Avalos */ 2361077d0bdSPeter Avalos #define N_ATOMS (BPF_MEMWORDS+2) 2371077d0bdSPeter Avalos 2381077d0bdSPeter Avalos struct edge { 2391077d0bdSPeter Avalos int id; 2401077d0bdSPeter Avalos int code; 2411077d0bdSPeter Avalos uset edom; 2421077d0bdSPeter Avalos struct block *succ; 2431077d0bdSPeter Avalos struct block *pred; 2441077d0bdSPeter Avalos struct edge *next; /* link list of incoming edges for a node */ 2451077d0bdSPeter Avalos }; 2461077d0bdSPeter Avalos 2471077d0bdSPeter Avalos struct block { 2481077d0bdSPeter Avalos int id; 2491077d0bdSPeter Avalos struct slist *stmts; /* side effect stmts */ 2501077d0bdSPeter Avalos struct stmt s; /* branch stmt */ 2511077d0bdSPeter Avalos int mark; 2520e1eae1fSPeter Avalos u_int longjt; /* jt branch requires long jump */ 2530e1eae1fSPeter Avalos u_int longjf; /* jf branch requires long jump */ 2541077d0bdSPeter Avalos int level; 2551077d0bdSPeter Avalos int offset; 2561077d0bdSPeter Avalos int sense; 2571077d0bdSPeter Avalos struct edge et; 2581077d0bdSPeter Avalos struct edge ef; 2591077d0bdSPeter Avalos struct block *head; 2601077d0bdSPeter Avalos struct block *link; /* link field used by optimizer */ 2611077d0bdSPeter Avalos uset dom; 2621077d0bdSPeter Avalos uset closure; 2631077d0bdSPeter Avalos struct edge *in_edges; 2641077d0bdSPeter Avalos atomset def, kill; 2651077d0bdSPeter Avalos atomset in_use; 2661077d0bdSPeter Avalos atomset out_use; 2671077d0bdSPeter Avalos int oval; 2681077d0bdSPeter Avalos int val[N_ATOMS]; 2691077d0bdSPeter Avalos }; 2701077d0bdSPeter Avalos 2711077d0bdSPeter Avalos struct arth { 2721077d0bdSPeter Avalos struct block *b; /* protocol checks */ 2731077d0bdSPeter Avalos struct slist *s; /* stmt list */ 2741077d0bdSPeter Avalos int regno; /* virtual register number of result */ 2751077d0bdSPeter Avalos }; 2761077d0bdSPeter Avalos 2771077d0bdSPeter Avalos struct qual { 2781077d0bdSPeter Avalos unsigned char addr; 2791077d0bdSPeter Avalos unsigned char proto; 2801077d0bdSPeter Avalos unsigned char dir; 2811077d0bdSPeter Avalos unsigned char pad; 2821077d0bdSPeter Avalos }; 2831077d0bdSPeter Avalos 284*97a9217aSAntonio Huete Jimenez struct _compiler_state; 285*97a9217aSAntonio Huete Jimenez 286*97a9217aSAntonio Huete Jimenez typedef struct _compiler_state compiler_state_t; 287*97a9217aSAntonio Huete Jimenez 288*97a9217aSAntonio Huete Jimenez struct arth *gen_loadi(compiler_state_t *, int); 289*97a9217aSAntonio Huete Jimenez struct arth *gen_load(compiler_state_t *, int, struct arth *, int); 290*97a9217aSAntonio Huete Jimenez struct arth *gen_loadlen(compiler_state_t *); 291*97a9217aSAntonio Huete Jimenez struct arth *gen_neg(compiler_state_t *, struct arth *); 292*97a9217aSAntonio Huete Jimenez struct arth *gen_arth(compiler_state_t *, int, struct arth *, struct arth *); 2931077d0bdSPeter Avalos 2941077d0bdSPeter Avalos void gen_and(struct block *, struct block *); 2951077d0bdSPeter Avalos void gen_or(struct block *, struct block *); 2961077d0bdSPeter Avalos void gen_not(struct block *); 2971077d0bdSPeter Avalos 298*97a9217aSAntonio Huete Jimenez struct block *gen_scode(compiler_state_t *, const char *, struct qual); 299*97a9217aSAntonio Huete Jimenez struct block *gen_ecode(compiler_state_t *, const u_char *, struct qual); 300*97a9217aSAntonio Huete Jimenez struct block *gen_acode(compiler_state_t *, const u_char *, struct qual); 301*97a9217aSAntonio Huete Jimenez struct block *gen_mcode(compiler_state_t *, const char *, const char *, 302*97a9217aSAntonio Huete Jimenez unsigned int, struct qual); 3031077d0bdSPeter Avalos #ifdef INET6 304*97a9217aSAntonio Huete Jimenez struct block *gen_mcode6(compiler_state_t *, const char *, const char *, 305*97a9217aSAntonio Huete Jimenez unsigned int, struct qual); 3061077d0bdSPeter Avalos #endif 307*97a9217aSAntonio Huete Jimenez struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32, 308*97a9217aSAntonio Huete Jimenez struct qual); 309*97a9217aSAntonio Huete Jimenez struct block *gen_proto_abbrev(compiler_state_t *, int); 310*97a9217aSAntonio Huete Jimenez struct block *gen_relation(compiler_state_t *, int, struct arth *, 311*97a9217aSAntonio Huete Jimenez struct arth *, int); 312*97a9217aSAntonio Huete Jimenez struct block *gen_less(compiler_state_t *, int); 313*97a9217aSAntonio Huete Jimenez struct block *gen_greater(compiler_state_t *, int); 314*97a9217aSAntonio Huete Jimenez struct block *gen_byteop(compiler_state_t *, int, int, int); 315*97a9217aSAntonio Huete Jimenez struct block *gen_broadcast(compiler_state_t *, int); 316*97a9217aSAntonio Huete Jimenez struct block *gen_multicast(compiler_state_t *, int); 317*97a9217aSAntonio Huete Jimenez struct block *gen_inbound(compiler_state_t *, int); 3181077d0bdSPeter Avalos 319*97a9217aSAntonio Huete Jimenez struct block *gen_llc(compiler_state_t *); 320*97a9217aSAntonio Huete Jimenez struct block *gen_llc_i(compiler_state_t *); 321*97a9217aSAntonio Huete Jimenez struct block *gen_llc_s(compiler_state_t *); 322*97a9217aSAntonio Huete Jimenez struct block *gen_llc_u(compiler_state_t *); 323*97a9217aSAntonio Huete Jimenez struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); 324*97a9217aSAntonio Huete Jimenez struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); 3251077d0bdSPeter Avalos 326*97a9217aSAntonio Huete Jimenez struct block *gen_vlan(compiler_state_t *, int); 327*97a9217aSAntonio Huete Jimenez struct block *gen_mpls(compiler_state_t *, int); 3281077d0bdSPeter Avalos 329*97a9217aSAntonio Huete Jimenez struct block *gen_pppoed(compiler_state_t *); 330*97a9217aSAntonio Huete Jimenez struct block *gen_pppoes(compiler_state_t *, int); 3311077d0bdSPeter Avalos 332*97a9217aSAntonio Huete Jimenez struct block *gen_geneve(compiler_state_t *, int); 3331077d0bdSPeter Avalos 334*97a9217aSAntonio Huete Jimenez struct block *gen_atmfield_code(compiler_state_t *, int, bpf_int32, 335*97a9217aSAntonio Huete Jimenez bpf_u_int32, int); 336*97a9217aSAntonio Huete Jimenez struct block *gen_atmtype_abbrev(compiler_state_t *, int type); 337*97a9217aSAntonio Huete Jimenez struct block *gen_atmmulti_abbrev(compiler_state_t *, int type); 3381077d0bdSPeter Avalos 339*97a9217aSAntonio Huete Jimenez struct block *gen_mtp2type_abbrev(compiler_state_t *, int type); 340*97a9217aSAntonio Huete Jimenez struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, 341*97a9217aSAntonio Huete Jimenez bpf_u_int32, int); 342de0d3203SPeter Avalos 343*97a9217aSAntonio Huete Jimenez struct block *gen_pf_ifname(compiler_state_t *, const char *); 344*97a9217aSAntonio Huete Jimenez struct block *gen_pf_rnr(compiler_state_t *, int); 345*97a9217aSAntonio Huete Jimenez struct block *gen_pf_srnr(compiler_state_t *, int); 346*97a9217aSAntonio Huete Jimenez struct block *gen_pf_ruleset(compiler_state_t *, char *); 347*97a9217aSAntonio Huete Jimenez struct block *gen_pf_reason(compiler_state_t *, int); 348*97a9217aSAntonio Huete Jimenez struct block *gen_pf_action(compiler_state_t *, int); 3491077d0bdSPeter Avalos 350*97a9217aSAntonio Huete Jimenez struct block *gen_p80211_type(compiler_state_t *, int, int); 351*97a9217aSAntonio Huete Jimenez struct block *gen_p80211_fcdir(compiler_state_t *, int); 3521077d0bdSPeter Avalos 353*97a9217aSAntonio Huete Jimenez /* 354*97a9217aSAntonio Huete Jimenez * Representation of a program as a tree of blocks, plus current mark. 355*97a9217aSAntonio Huete Jimenez * A block is marked if only if its mark equals the current mark. 356*97a9217aSAntonio Huete Jimenez * Rather than traverse the code array, marking each item, 'cur_mark' 357*97a9217aSAntonio Huete Jimenez * is incremented. This automatically makes each element unmarked. 358*97a9217aSAntonio Huete Jimenez */ 359*97a9217aSAntonio Huete Jimenez #define isMarked(icp, p) ((p)->mark == (icp)->cur_mark) 360*97a9217aSAntonio Huete Jimenez #define unMarkAll(icp) (icp)->cur_mark += 1 361*97a9217aSAntonio Huete Jimenez #define Mark(icp, p) ((p)->mark = (icp)->cur_mark) 362*97a9217aSAntonio Huete Jimenez 363*97a9217aSAntonio Huete Jimenez struct icode { 364*97a9217aSAntonio Huete Jimenez struct block *root; 365*97a9217aSAntonio Huete Jimenez int cur_mark; 366*97a9217aSAntonio Huete Jimenez }; 367*97a9217aSAntonio Huete Jimenez 368*97a9217aSAntonio Huete Jimenez void bpf_optimize(compiler_state_t *, struct icode *ic); 369*97a9217aSAntonio Huete Jimenez void bpf_syntax_error(compiler_state_t *, const char *); 370*97a9217aSAntonio Huete Jimenez void bpf_error(compiler_state_t *, const char *, ...) 371*97a9217aSAntonio Huete Jimenez __attribute__((noreturn)) 372*97a9217aSAntonio Huete Jimenez #ifdef __ATTRIBUTE___FORMAT_OK 373*97a9217aSAntonio Huete Jimenez __attribute__((format (printf, 2, 3))) 374*97a9217aSAntonio Huete Jimenez #endif /* __ATTRIBUTE___FORMAT_OK */ 375*97a9217aSAntonio Huete Jimenez ; 376*97a9217aSAntonio Huete Jimenez 377*97a9217aSAntonio Huete Jimenez void finish_parse(compiler_state_t *, struct block *); 378*97a9217aSAntonio Huete Jimenez char *sdup(compiler_state_t *, const char *); 379*97a9217aSAntonio Huete Jimenez 380*97a9217aSAntonio Huete Jimenez struct _opt_state; 381*97a9217aSAntonio Huete Jimenez typedef struct _opt_state opt_state_t; 382*97a9217aSAntonio Huete Jimenez 383*97a9217aSAntonio Huete Jimenez struct bpf_insn *icode_to_fcode(compiler_state_t *, struct icode *, 384*97a9217aSAntonio Huete Jimenez struct block *, u_int *); 3851077d0bdSPeter Avalos void sappend(struct slist *, struct slist *); 3861077d0bdSPeter Avalos 387*97a9217aSAntonio Huete Jimenez /* 388*97a9217aSAntonio Huete Jimenez * Older versions of Bison don't put this declaration in 389*97a9217aSAntonio Huete Jimenez * grammar.h. 390*97a9217aSAntonio Huete Jimenez */ 391*97a9217aSAntonio Huete Jimenez int pcap_parse(void *, compiler_state_t *); 392*97a9217aSAntonio Huete Jimenez 3931077d0bdSPeter Avalos /* XXX */ 3941077d0bdSPeter Avalos #define JT(b) ((b)->et.succ) 3951077d0bdSPeter Avalos #define JF(b) ((b)->ef.succ) 396