1*8b26181fSAndroid Build Coastguard Worker /* 2*8b26181fSAndroid Build Coastguard Worker * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 3*8b26181fSAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved. 4*8b26181fSAndroid Build Coastguard Worker * 5*8b26181fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*8b26181fSAndroid Build Coastguard Worker * modification, are permitted provided that: (1) source code distributions 7*8b26181fSAndroid Build Coastguard Worker * retain the above copyright notice and this paragraph in its entirety, (2) 8*8b26181fSAndroid Build Coastguard Worker * distributions including binary code include the above copyright notice and 9*8b26181fSAndroid Build Coastguard Worker * this paragraph in its entirety in the documentation or other materials 10*8b26181fSAndroid Build Coastguard Worker * provided with the distribution, and (3) all advertising materials mentioning 11*8b26181fSAndroid Build Coastguard Worker * features or use of this software display the following acknowledgement: 12*8b26181fSAndroid Build Coastguard Worker * ``This product includes software developed by the University of California, 13*8b26181fSAndroid Build Coastguard Worker * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14*8b26181fSAndroid Build Coastguard Worker * the University nor the names of its contributors may be used to endorse 15*8b26181fSAndroid Build Coastguard Worker * or promote products derived from this software without specific prior 16*8b26181fSAndroid Build Coastguard Worker * written permission. 17*8b26181fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18*8b26181fSAndroid Build Coastguard Worker * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19*8b26181fSAndroid Build Coastguard Worker * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20*8b26181fSAndroid Build Coastguard Worker */ 21*8b26181fSAndroid Build Coastguard Worker 22*8b26181fSAndroid Build Coastguard Worker #ifndef gencode_h 23*8b26181fSAndroid Build Coastguard Worker #define gencode_h 24*8b26181fSAndroid Build Coastguard Worker 25*8b26181fSAndroid Build Coastguard Worker #include "pcap/funcattrs.h" 26*8b26181fSAndroid Build Coastguard Worker /* 27*8b26181fSAndroid Build Coastguard Worker * pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be 28*8b26181fSAndroid Build Coastguard Worker * made available via either pcap-types.h (a private header) or pcap/pcap.h 29*8b26181fSAndroid Build Coastguard Worker * (a public header), none of which pcap/bpf.h includes. Include the private 30*8b26181fSAndroid Build Coastguard Worker * header to keep things simple, this way this private header should compile 31*8b26181fSAndroid Build Coastguard Worker * even if included early from another file. 32*8b26181fSAndroid Build Coastguard Worker */ 33*8b26181fSAndroid Build Coastguard Worker #include "pcap-types.h" 34*8b26181fSAndroid Build Coastguard Worker #include "pcap/bpf.h" /* bpf_u_int32 and BPF_MEMWORDS */ 35*8b26181fSAndroid Build Coastguard Worker 36*8b26181fSAndroid Build Coastguard Worker /* 37*8b26181fSAndroid Build Coastguard Worker * ATM support: 38*8b26181fSAndroid Build Coastguard Worker * 39*8b26181fSAndroid Build Coastguard Worker * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 40*8b26181fSAndroid Build Coastguard Worker * All rights reserved. 41*8b26181fSAndroid Build Coastguard Worker * 42*8b26181fSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 43*8b26181fSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 44*8b26181fSAndroid Build Coastguard Worker * are met: 45*8b26181fSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 46*8b26181fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 47*8b26181fSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 48*8b26181fSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 49*8b26181fSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 50*8b26181fSAndroid Build Coastguard Worker * 3. All advertising materials mentioning features or use of this software 51*8b26181fSAndroid Build Coastguard Worker * must display the following acknowledgement: 52*8b26181fSAndroid Build Coastguard Worker * This product includes software developed by Yen Yen Lim and 53*8b26181fSAndroid Build Coastguard Worker * North Dakota State University 54*8b26181fSAndroid Build Coastguard Worker * 4. The name of the author may not be used to endorse or promote products 55*8b26181fSAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 56*8b26181fSAndroid Build Coastguard Worker * 57*8b26181fSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 58*8b26181fSAndroid Build Coastguard Worker * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 59*8b26181fSAndroid Build Coastguard Worker * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 60*8b26181fSAndroid Build Coastguard Worker * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 61*8b26181fSAndroid Build Coastguard Worker * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 62*8b26181fSAndroid Build Coastguard Worker * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 63*8b26181fSAndroid Build Coastguard Worker * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64*8b26181fSAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 65*8b26181fSAndroid Build Coastguard Worker * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 66*8b26181fSAndroid Build Coastguard Worker * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 67*8b26181fSAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE. 68*8b26181fSAndroid Build Coastguard Worker */ 69*8b26181fSAndroid Build Coastguard Worker 70*8b26181fSAndroid Build Coastguard Worker /* Address qualifiers. */ 71*8b26181fSAndroid Build Coastguard Worker 72*8b26181fSAndroid Build Coastguard Worker #define Q_HOST 1 73*8b26181fSAndroid Build Coastguard Worker #define Q_NET 2 74*8b26181fSAndroid Build Coastguard Worker #define Q_PORT 3 75*8b26181fSAndroid Build Coastguard Worker #define Q_GATEWAY 4 76*8b26181fSAndroid Build Coastguard Worker #define Q_PROTO 5 77*8b26181fSAndroid Build Coastguard Worker #define Q_PROTOCHAIN 6 78*8b26181fSAndroid Build Coastguard Worker #define Q_PORTRANGE 7 79*8b26181fSAndroid Build Coastguard Worker 80*8b26181fSAndroid Build Coastguard Worker /* Protocol qualifiers. */ 81*8b26181fSAndroid Build Coastguard Worker 82*8b26181fSAndroid Build Coastguard Worker #define Q_LINK 1 83*8b26181fSAndroid Build Coastguard Worker #define Q_IP 2 84*8b26181fSAndroid Build Coastguard Worker #define Q_ARP 3 85*8b26181fSAndroid Build Coastguard Worker #define Q_RARP 4 86*8b26181fSAndroid Build Coastguard Worker #define Q_SCTP 5 87*8b26181fSAndroid Build Coastguard Worker #define Q_TCP 6 88*8b26181fSAndroid Build Coastguard Worker #define Q_UDP 7 89*8b26181fSAndroid Build Coastguard Worker #define Q_ICMP 8 90*8b26181fSAndroid Build Coastguard Worker #define Q_IGMP 9 91*8b26181fSAndroid Build Coastguard Worker #define Q_IGRP 10 92*8b26181fSAndroid Build Coastguard Worker 93*8b26181fSAndroid Build Coastguard Worker 94*8b26181fSAndroid Build Coastguard Worker #define Q_ATALK 11 95*8b26181fSAndroid Build Coastguard Worker #define Q_DECNET 12 96*8b26181fSAndroid Build Coastguard Worker #define Q_LAT 13 97*8b26181fSAndroid Build Coastguard Worker #define Q_SCA 14 98*8b26181fSAndroid Build Coastguard Worker #define Q_MOPRC 15 99*8b26181fSAndroid Build Coastguard Worker #define Q_MOPDL 16 100*8b26181fSAndroid Build Coastguard Worker 101*8b26181fSAndroid Build Coastguard Worker 102*8b26181fSAndroid Build Coastguard Worker #define Q_IPV6 17 103*8b26181fSAndroid Build Coastguard Worker #define Q_ICMPV6 18 104*8b26181fSAndroid Build Coastguard Worker #define Q_AH 19 105*8b26181fSAndroid Build Coastguard Worker #define Q_ESP 20 106*8b26181fSAndroid Build Coastguard Worker 107*8b26181fSAndroid Build Coastguard Worker #define Q_PIM 21 108*8b26181fSAndroid Build Coastguard Worker #define Q_VRRP 22 109*8b26181fSAndroid Build Coastguard Worker 110*8b26181fSAndroid Build Coastguard Worker #define Q_AARP 23 111*8b26181fSAndroid Build Coastguard Worker 112*8b26181fSAndroid Build Coastguard Worker #define Q_ISO 24 113*8b26181fSAndroid Build Coastguard Worker #define Q_ESIS 25 114*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS 26 115*8b26181fSAndroid Build Coastguard Worker #define Q_CLNP 27 116*8b26181fSAndroid Build Coastguard Worker 117*8b26181fSAndroid Build Coastguard Worker #define Q_STP 28 118*8b26181fSAndroid Build Coastguard Worker 119*8b26181fSAndroid Build Coastguard Worker #define Q_IPX 29 120*8b26181fSAndroid Build Coastguard Worker 121*8b26181fSAndroid Build Coastguard Worker #define Q_NETBEUI 30 122*8b26181fSAndroid Build Coastguard Worker 123*8b26181fSAndroid Build Coastguard Worker /* IS-IS Levels */ 124*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_L1 31 125*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_L2 32 126*8b26181fSAndroid Build Coastguard Worker /* PDU types */ 127*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_IIH 33 128*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_SNP 34 129*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_CSNP 35 130*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_PSNP 36 131*8b26181fSAndroid Build Coastguard Worker #define Q_ISIS_LSP 37 132*8b26181fSAndroid Build Coastguard Worker 133*8b26181fSAndroid Build Coastguard Worker #define Q_RADIO 38 134*8b26181fSAndroid Build Coastguard Worker 135*8b26181fSAndroid Build Coastguard Worker #define Q_CARP 39 136*8b26181fSAndroid Build Coastguard Worker 137*8b26181fSAndroid Build Coastguard Worker /* Directional qualifiers. */ 138*8b26181fSAndroid Build Coastguard Worker 139*8b26181fSAndroid Build Coastguard Worker #define Q_SRC 1 140*8b26181fSAndroid Build Coastguard Worker #define Q_DST 2 141*8b26181fSAndroid Build Coastguard Worker #define Q_OR 3 142*8b26181fSAndroid Build Coastguard Worker #define Q_AND 4 143*8b26181fSAndroid Build Coastguard Worker #define Q_ADDR1 5 144*8b26181fSAndroid Build Coastguard Worker #define Q_ADDR2 6 145*8b26181fSAndroid Build Coastguard Worker #define Q_ADDR3 7 146*8b26181fSAndroid Build Coastguard Worker #define Q_ADDR4 8 147*8b26181fSAndroid Build Coastguard Worker #define Q_RA 9 148*8b26181fSAndroid Build Coastguard Worker #define Q_TA 10 149*8b26181fSAndroid Build Coastguard Worker 150*8b26181fSAndroid Build Coastguard Worker #define Q_DEFAULT 0 151*8b26181fSAndroid Build Coastguard Worker #define Q_UNDEF 255 152*8b26181fSAndroid Build Coastguard Worker 153*8b26181fSAndroid Build Coastguard Worker /* ATM types */ 154*8b26181fSAndroid Build Coastguard Worker #define A_METAC 22 /* Meta signalling Circuit */ 155*8b26181fSAndroid Build Coastguard Worker #define A_BCC 23 /* Broadcast Circuit */ 156*8b26181fSAndroid Build Coastguard Worker #define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 157*8b26181fSAndroid Build Coastguard Worker #define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 158*8b26181fSAndroid Build Coastguard Worker #define A_SC 26 /* Signalling Circuit*/ 159*8b26181fSAndroid Build Coastguard Worker #define A_ILMIC 27 /* ILMI Circuit */ 160*8b26181fSAndroid Build Coastguard Worker #define A_OAM 28 /* OAM cells : F4 only */ 161*8b26181fSAndroid Build Coastguard Worker #define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 162*8b26181fSAndroid Build Coastguard Worker #define A_LANE 30 /* LANE traffic */ 163*8b26181fSAndroid Build Coastguard Worker #define A_LLC 31 /* LLC-encapsulated traffic */ 164*8b26181fSAndroid Build Coastguard Worker 165*8b26181fSAndroid Build Coastguard Worker /* Based on Q.2931 signalling protocol */ 166*8b26181fSAndroid Build Coastguard Worker #define A_SETUP 41 /* Setup message */ 167*8b26181fSAndroid Build Coastguard Worker #define A_CALLPROCEED 42 /* Call proceeding message */ 168*8b26181fSAndroid Build Coastguard Worker #define A_CONNECT 43 /* Connect message */ 169*8b26181fSAndroid Build Coastguard Worker #define A_CONNECTACK 44 /* Connect Ack message */ 170*8b26181fSAndroid Build Coastguard Worker #define A_RELEASE 45 /* Release message */ 171*8b26181fSAndroid Build Coastguard Worker #define A_RELEASE_DONE 46 /* Release message */ 172*8b26181fSAndroid Build Coastguard Worker 173*8b26181fSAndroid Build Coastguard Worker /* ATM field types */ 174*8b26181fSAndroid Build Coastguard Worker #define A_VPI 51 175*8b26181fSAndroid Build Coastguard Worker #define A_VCI 52 176*8b26181fSAndroid Build Coastguard Worker #define A_PROTOTYPE 53 177*8b26181fSAndroid Build Coastguard Worker #define A_MSGTYPE 54 178*8b26181fSAndroid Build Coastguard Worker #define A_CALLREFTYPE 55 179*8b26181fSAndroid Build Coastguard Worker 180*8b26181fSAndroid Build Coastguard Worker #define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 181*8b26181fSAndroid Build Coastguard Worker establishing and destroying switched 182*8b26181fSAndroid Build Coastguard Worker virtual connection */ 183*8b26181fSAndroid Build Coastguard Worker #define A_METACONNECT 71 /* returns Q.2931 signalling messages for 184*8b26181fSAndroid Build Coastguard Worker establishing and destroying predefined 185*8b26181fSAndroid Build Coastguard Worker virtual circuits, such as broadcast 186*8b26181fSAndroid Build Coastguard Worker circuit, oamf4 segment circuit, oamf4 187*8b26181fSAndroid Build Coastguard Worker end-to-end circuits, ILMI circuits or 188*8b26181fSAndroid Build Coastguard Worker connection signalling circuit. */ 189*8b26181fSAndroid Build Coastguard Worker 190*8b26181fSAndroid Build Coastguard Worker /* MTP2 types */ 191*8b26181fSAndroid Build Coastguard Worker #define M_FISU 22 /* FISU */ 192*8b26181fSAndroid Build Coastguard Worker #define M_LSSU 23 /* LSSU */ 193*8b26181fSAndroid Build Coastguard Worker #define M_MSU 24 /* MSU */ 194*8b26181fSAndroid Build Coastguard Worker 195*8b26181fSAndroid Build Coastguard Worker /* MTP2 HSL types */ 196*8b26181fSAndroid Build Coastguard Worker #define MH_FISU 25 /* FISU for HSL */ 197*8b26181fSAndroid Build Coastguard Worker #define MH_LSSU 26 /* LSSU */ 198*8b26181fSAndroid Build Coastguard Worker #define MH_MSU 27 /* MSU */ 199*8b26181fSAndroid Build Coastguard Worker 200*8b26181fSAndroid Build Coastguard Worker /* MTP3 field types */ 201*8b26181fSAndroid Build Coastguard Worker #define M_SIO 1 202*8b26181fSAndroid Build Coastguard Worker #define M_OPC 2 203*8b26181fSAndroid Build Coastguard Worker #define M_DPC 3 204*8b26181fSAndroid Build Coastguard Worker #define M_SLS 4 205*8b26181fSAndroid Build Coastguard Worker 206*8b26181fSAndroid Build Coastguard Worker /* MTP3 field types in case of MTP2 HSL */ 207*8b26181fSAndroid Build Coastguard Worker #define MH_SIO 5 208*8b26181fSAndroid Build Coastguard Worker #define MH_OPC 6 209*8b26181fSAndroid Build Coastguard Worker #define MH_DPC 7 210*8b26181fSAndroid Build Coastguard Worker #define MH_SLS 8 211*8b26181fSAndroid Build Coastguard Worker 212*8b26181fSAndroid Build Coastguard Worker 213*8b26181fSAndroid Build Coastguard Worker struct slist; 214*8b26181fSAndroid Build Coastguard Worker 215*8b26181fSAndroid Build Coastguard Worker /* 216*8b26181fSAndroid Build Coastguard Worker * A single statement, corresponding to an instruction in a block. 217*8b26181fSAndroid Build Coastguard Worker */ 218*8b26181fSAndroid Build Coastguard Worker struct stmt { 219*8b26181fSAndroid Build Coastguard Worker int code; /* opcode */ 220*8b26181fSAndroid Build Coastguard Worker struct slist *jt; /* only for relative jump in block */ 221*8b26181fSAndroid Build Coastguard Worker struct slist *jf; /* only for relative jump in block */ 222*8b26181fSAndroid Build Coastguard Worker bpf_u_int32 k; /* k field */ 223*8b26181fSAndroid Build Coastguard Worker }; 224*8b26181fSAndroid Build Coastguard Worker 225*8b26181fSAndroid Build Coastguard Worker struct slist { 226*8b26181fSAndroid Build Coastguard Worker struct stmt s; 227*8b26181fSAndroid Build Coastguard Worker struct slist *next; 228*8b26181fSAndroid Build Coastguard Worker }; 229*8b26181fSAndroid Build Coastguard Worker 230*8b26181fSAndroid Build Coastguard Worker /* 231*8b26181fSAndroid Build Coastguard Worker * A bit vector to represent definition sets. We assume TOT_REGISTERS 232*8b26181fSAndroid Build Coastguard Worker * is smaller than 8*sizeof(atomset). 233*8b26181fSAndroid Build Coastguard Worker */ 234*8b26181fSAndroid Build Coastguard Worker typedef bpf_u_int32 atomset; 235*8b26181fSAndroid Build Coastguard Worker #define ATOMMASK(n) (1 << (n)) 236*8b26181fSAndroid Build Coastguard Worker #define ATOMELEM(d, n) (d & ATOMMASK(n)) 237*8b26181fSAndroid Build Coastguard Worker 238*8b26181fSAndroid Build Coastguard Worker /* 239*8b26181fSAndroid Build Coastguard Worker * An unbounded set. 240*8b26181fSAndroid Build Coastguard Worker */ 241*8b26181fSAndroid Build Coastguard Worker typedef bpf_u_int32 *uset; 242*8b26181fSAndroid Build Coastguard Worker 243*8b26181fSAndroid Build Coastguard Worker /* 244*8b26181fSAndroid Build Coastguard Worker * Total number of atomic entities, including accumulator (A) and index (X). 245*8b26181fSAndroid Build Coastguard Worker * We treat all these guys similarly during flow analysis. 246*8b26181fSAndroid Build Coastguard Worker */ 247*8b26181fSAndroid Build Coastguard Worker #define N_ATOMS (BPF_MEMWORDS+2) 248*8b26181fSAndroid Build Coastguard Worker 249*8b26181fSAndroid Build Coastguard Worker /* 250*8b26181fSAndroid Build Coastguard Worker * Control flow graph of a program. 251*8b26181fSAndroid Build Coastguard Worker * This corresponds to an edge in the CFG. 252*8b26181fSAndroid Build Coastguard Worker * It's a directed graph, so an edge has a predecessor and a successor. 253*8b26181fSAndroid Build Coastguard Worker */ 254*8b26181fSAndroid Build Coastguard Worker struct edge { 255*8b26181fSAndroid Build Coastguard Worker u_int id; 256*8b26181fSAndroid Build Coastguard Worker int code; /* opcode for branch corresponding to this edge */ 257*8b26181fSAndroid Build Coastguard Worker uset edom; 258*8b26181fSAndroid Build Coastguard Worker struct block *succ; /* successor vertex */ 259*8b26181fSAndroid Build Coastguard Worker struct block *pred; /* predecessor vertex */ 260*8b26181fSAndroid Build Coastguard Worker struct edge *next; /* link list of incoming edges for a node */ 261*8b26181fSAndroid Build Coastguard Worker }; 262*8b26181fSAndroid Build Coastguard Worker 263*8b26181fSAndroid Build Coastguard Worker /* 264*8b26181fSAndroid Build Coastguard Worker * A block is a vertex in the CFG. 265*8b26181fSAndroid Build Coastguard Worker * It has a list of statements, with the final statement being a 266*8b26181fSAndroid Build Coastguard Worker * branch to successor blocks. 267*8b26181fSAndroid Build Coastguard Worker */ 268*8b26181fSAndroid Build Coastguard Worker struct block { 269*8b26181fSAndroid Build Coastguard Worker u_int id; 270*8b26181fSAndroid Build Coastguard Worker struct slist *stmts; /* side effect stmts */ 271*8b26181fSAndroid Build Coastguard Worker struct stmt s; /* branch stmt */ 272*8b26181fSAndroid Build Coastguard Worker int mark; 273*8b26181fSAndroid Build Coastguard Worker u_int longjt; /* jt branch requires long jump */ 274*8b26181fSAndroid Build Coastguard Worker u_int longjf; /* jf branch requires long jump */ 275*8b26181fSAndroid Build Coastguard Worker int level; 276*8b26181fSAndroid Build Coastguard Worker int offset; 277*8b26181fSAndroid Build Coastguard Worker int sense; 278*8b26181fSAndroid Build Coastguard Worker struct edge et; /* edge corresponding to the jt branch */ 279*8b26181fSAndroid Build Coastguard Worker struct edge ef; /* edge corresponding to the jf branch */ 280*8b26181fSAndroid Build Coastguard Worker struct block *head; 281*8b26181fSAndroid Build Coastguard Worker struct block *link; /* link field used by optimizer */ 282*8b26181fSAndroid Build Coastguard Worker uset dom; 283*8b26181fSAndroid Build Coastguard Worker uset closure; 284*8b26181fSAndroid Build Coastguard Worker struct edge *in_edges; /* first edge in the set (linked list) of edges with this as a successor */ 285*8b26181fSAndroid Build Coastguard Worker atomset def, kill; 286*8b26181fSAndroid Build Coastguard Worker atomset in_use; 287*8b26181fSAndroid Build Coastguard Worker atomset out_use; 288*8b26181fSAndroid Build Coastguard Worker int oval; /* value ID for value tested in branch stmt */ 289*8b26181fSAndroid Build Coastguard Worker bpf_u_int32 val[N_ATOMS]; 290*8b26181fSAndroid Build Coastguard Worker }; 291*8b26181fSAndroid Build Coastguard Worker 292*8b26181fSAndroid Build Coastguard Worker /* 293*8b26181fSAndroid Build Coastguard Worker * A value of 0 for val[i] means the value is unknown. 294*8b26181fSAndroid Build Coastguard Worker */ 295*8b26181fSAndroid Build Coastguard Worker #define VAL_UNKNOWN 0 296*8b26181fSAndroid Build Coastguard Worker 297*8b26181fSAndroid Build Coastguard Worker struct arth { 298*8b26181fSAndroid Build Coastguard Worker struct block *b; /* protocol checks */ 299*8b26181fSAndroid Build Coastguard Worker struct slist *s; /* stmt list */ 300*8b26181fSAndroid Build Coastguard Worker int regno; /* virtual register number of result */ 301*8b26181fSAndroid Build Coastguard Worker }; 302*8b26181fSAndroid Build Coastguard Worker 303*8b26181fSAndroid Build Coastguard Worker struct qual { 304*8b26181fSAndroid Build Coastguard Worker unsigned char addr; 305*8b26181fSAndroid Build Coastguard Worker unsigned char proto; 306*8b26181fSAndroid Build Coastguard Worker unsigned char dir; 307*8b26181fSAndroid Build Coastguard Worker unsigned char pad; 308*8b26181fSAndroid Build Coastguard Worker }; 309*8b26181fSAndroid Build Coastguard Worker 310*8b26181fSAndroid Build Coastguard Worker struct _compiler_state; 311*8b26181fSAndroid Build Coastguard Worker 312*8b26181fSAndroid Build Coastguard Worker typedef struct _compiler_state compiler_state_t; 313*8b26181fSAndroid Build Coastguard Worker 314*8b26181fSAndroid Build Coastguard Worker struct arth *gen_loadi(compiler_state_t *, bpf_u_int32); 315*8b26181fSAndroid Build Coastguard Worker struct arth *gen_load(compiler_state_t *, int, struct arth *, bpf_u_int32); 316*8b26181fSAndroid Build Coastguard Worker struct arth *gen_loadlen(compiler_state_t *); 317*8b26181fSAndroid Build Coastguard Worker struct arth *gen_neg(compiler_state_t *, struct arth *); 318*8b26181fSAndroid Build Coastguard Worker struct arth *gen_arth(compiler_state_t *, int, struct arth *, struct arth *); 319*8b26181fSAndroid Build Coastguard Worker 320*8b26181fSAndroid Build Coastguard Worker void gen_and(struct block *, struct block *); 321*8b26181fSAndroid Build Coastguard Worker void gen_or(struct block *, struct block *); 322*8b26181fSAndroid Build Coastguard Worker void gen_not(struct block *); 323*8b26181fSAndroid Build Coastguard Worker 324*8b26181fSAndroid Build Coastguard Worker struct block *gen_scode(compiler_state_t *, const char *, struct qual); 325*8b26181fSAndroid Build Coastguard Worker struct block *gen_ecode(compiler_state_t *, const char *, struct qual); 326*8b26181fSAndroid Build Coastguard Worker struct block *gen_acode(compiler_state_t *, const char *, struct qual); 327*8b26181fSAndroid Build Coastguard Worker struct block *gen_mcode(compiler_state_t *, const char *, const char *, 328*8b26181fSAndroid Build Coastguard Worker bpf_u_int32, struct qual); 329*8b26181fSAndroid Build Coastguard Worker #ifdef INET6 330*8b26181fSAndroid Build Coastguard Worker struct block *gen_mcode6(compiler_state_t *, const char *, const char *, 331*8b26181fSAndroid Build Coastguard Worker bpf_u_int32, struct qual); 332*8b26181fSAndroid Build Coastguard Worker #endif 333*8b26181fSAndroid Build Coastguard Worker struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32, 334*8b26181fSAndroid Build Coastguard Worker struct qual); 335*8b26181fSAndroid Build Coastguard Worker struct block *gen_proto_abbrev(compiler_state_t *, int); 336*8b26181fSAndroid Build Coastguard Worker struct block *gen_relation(compiler_state_t *, int, struct arth *, 337*8b26181fSAndroid Build Coastguard Worker struct arth *, int); 338*8b26181fSAndroid Build Coastguard Worker struct block *gen_less(compiler_state_t *, int); 339*8b26181fSAndroid Build Coastguard Worker struct block *gen_greater(compiler_state_t *, int); 340*8b26181fSAndroid Build Coastguard Worker struct block *gen_byteop(compiler_state_t *, int, int, bpf_u_int32); 341*8b26181fSAndroid Build Coastguard Worker struct block *gen_broadcast(compiler_state_t *, int); 342*8b26181fSAndroid Build Coastguard Worker struct block *gen_multicast(compiler_state_t *, int); 343*8b26181fSAndroid Build Coastguard Worker struct block *gen_ifindex(compiler_state_t *, int); 344*8b26181fSAndroid Build Coastguard Worker struct block *gen_inbound(compiler_state_t *, int); 345*8b26181fSAndroid Build Coastguard Worker 346*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc(compiler_state_t *); 347*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc_i(compiler_state_t *); 348*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc_s(compiler_state_t *); 349*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc_u(compiler_state_t *); 350*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32); 351*8b26181fSAndroid Build Coastguard Worker struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32); 352*8b26181fSAndroid Build Coastguard Worker 353*8b26181fSAndroid Build Coastguard Worker struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int); 354*8b26181fSAndroid Build Coastguard Worker struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int); 355*8b26181fSAndroid Build Coastguard Worker 356*8b26181fSAndroid Build Coastguard Worker struct block *gen_pppoed(compiler_state_t *); 357*8b26181fSAndroid Build Coastguard Worker struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int); 358*8b26181fSAndroid Build Coastguard Worker 359*8b26181fSAndroid Build Coastguard Worker struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int); 360*8b26181fSAndroid Build Coastguard Worker 361*8b26181fSAndroid Build Coastguard Worker struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32, 362*8b26181fSAndroid Build Coastguard Worker int, int); 363*8b26181fSAndroid Build Coastguard Worker struct block *gen_atmtype_abbrev(compiler_state_t *, int); 364*8b26181fSAndroid Build Coastguard Worker struct block *gen_atmmulti_abbrev(compiler_state_t *, int); 365*8b26181fSAndroid Build Coastguard Worker 366*8b26181fSAndroid Build Coastguard Worker struct block *gen_mtp2type_abbrev(compiler_state_t *, int); 367*8b26181fSAndroid Build Coastguard Worker struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32, 368*8b26181fSAndroid Build Coastguard Worker int, int); 369*8b26181fSAndroid Build Coastguard Worker 370*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_ifname(compiler_state_t *, const char *); 371*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_rnr(compiler_state_t *, int); 372*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_srnr(compiler_state_t *, int); 373*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_ruleset(compiler_state_t *, char *); 374*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_reason(compiler_state_t *, int); 375*8b26181fSAndroid Build Coastguard Worker struct block *gen_pf_action(compiler_state_t *, int); 376*8b26181fSAndroid Build Coastguard Worker 377*8b26181fSAndroid Build Coastguard Worker struct block *gen_p80211_type(compiler_state_t *, bpf_u_int32, bpf_u_int32); 378*8b26181fSAndroid Build Coastguard Worker struct block *gen_p80211_fcdir(compiler_state_t *, bpf_u_int32); 379*8b26181fSAndroid Build Coastguard Worker 380*8b26181fSAndroid Build Coastguard Worker /* 381*8b26181fSAndroid Build Coastguard Worker * Representation of a program as a tree of blocks, plus current mark. 382*8b26181fSAndroid Build Coastguard Worker * A block is marked if only if its mark equals the current mark. 383*8b26181fSAndroid Build Coastguard Worker * Rather than traverse the code array, marking each item, 'cur_mark' 384*8b26181fSAndroid Build Coastguard Worker * is incremented. This automatically makes each element unmarked. 385*8b26181fSAndroid Build Coastguard Worker */ 386*8b26181fSAndroid Build Coastguard Worker #define isMarked(icp, p) ((p)->mark == (icp)->cur_mark) 387*8b26181fSAndroid Build Coastguard Worker #define unMarkAll(icp) (icp)->cur_mark += 1 388*8b26181fSAndroid Build Coastguard Worker #define Mark(icp, p) ((p)->mark = (icp)->cur_mark) 389*8b26181fSAndroid Build Coastguard Worker 390*8b26181fSAndroid Build Coastguard Worker struct icode { 391*8b26181fSAndroid Build Coastguard Worker struct block *root; 392*8b26181fSAndroid Build Coastguard Worker int cur_mark; 393*8b26181fSAndroid Build Coastguard Worker }; 394*8b26181fSAndroid Build Coastguard Worker 395*8b26181fSAndroid Build Coastguard Worker int bpf_optimize(struct icode *, char *); 396*8b26181fSAndroid Build Coastguard Worker void bpf_set_error(compiler_state_t *, const char *, ...) 397*8b26181fSAndroid Build Coastguard Worker PCAP_PRINTFLIKE(2, 3); 398*8b26181fSAndroid Build Coastguard Worker 399*8b26181fSAndroid Build Coastguard Worker int finish_parse(compiler_state_t *, struct block *); 400*8b26181fSAndroid Build Coastguard Worker char *sdup(compiler_state_t *, const char *); 401*8b26181fSAndroid Build Coastguard Worker 402*8b26181fSAndroid Build Coastguard Worker struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *, 403*8b26181fSAndroid Build Coastguard Worker char *); 404*8b26181fSAndroid Build Coastguard Worker void sappend(struct slist *, struct slist *); 405*8b26181fSAndroid Build Coastguard Worker 406*8b26181fSAndroid Build Coastguard Worker /* 407*8b26181fSAndroid Build Coastguard Worker * Older versions of Bison don't put this declaration in 408*8b26181fSAndroid Build Coastguard Worker * grammar.h. 409*8b26181fSAndroid Build Coastguard Worker */ 410*8b26181fSAndroid Build Coastguard Worker int pcap_parse(void *, compiler_state_t *); 411*8b26181fSAndroid Build Coastguard Worker 412*8b26181fSAndroid Build Coastguard Worker /* XXX */ 413*8b26181fSAndroid Build Coastguard Worker #define JT(b) ((b)->et.succ) 414*8b26181fSAndroid Build Coastguard Worker #define JF(b) ((b)->ef.succ) 415*8b26181fSAndroid Build Coastguard Worker 416*8b26181fSAndroid Build Coastguard Worker #endif /* gencode_h */ 417