gencode.h revision 190225
117683Spst/* 217683Spst * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 317683Spst * The Regents of the University of California. All rights reserved. 417683Spst * 517683Spst * Redistribution and use in source and binary forms, with or without 617683Spst * modification, are permitted provided that: (1) source code distributions 717683Spst * retain the above copyright notice and this paragraph in its entirety, (2) 817683Spst * distributions including binary code include the above copyright notice and 917683Spst * this paragraph in its entirety in the documentation or other materials 1017683Spst * provided with the distribution, and (3) all advertising materials mentioning 1117683Spst * features or use of this software display the following acknowledgement: 1217683Spst * ``This product includes software developed by the University of California, 1317683Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 1417683Spst * the University nor the names of its contributors may be used to endorse 1517683Spst * or promote products derived from this software without specific prior 1617683Spst * written permission. 1717683Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 1817683Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 1917683Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2017683Spst * 2156891Sfenner * $FreeBSD: head/contrib/libpcap/gencode.h 190225 2009-03-21 22:58:08Z rpaulo $ 22190225Srpaulo * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.70.2.1 2007/11/18 02:04:55 guy Exp $ (LBL) 2317683Spst */ 2417683Spst 25127667Sbms/* 26127667Sbms * ATM support: 27127667Sbms * 28127667Sbms * Copyright (c) 1997 Yen Yen Lim and North Dakota State University 29127667Sbms * All rights reserved. 30127667Sbms * 31127667Sbms * Redistribution and use in source and binary forms, with or without 32127667Sbms * modification, are permitted provided that the following conditions 33127667Sbms * are met: 34127667Sbms * 1. Redistributions of source code must retain the above copyright 35127667Sbms * notice, this list of conditions and the following disclaimer. 36127667Sbms * 2. Redistributions in binary form must reproduce the above copyright 37127667Sbms * notice, this list of conditions and the following disclaimer in the 38127667Sbms * documentation and/or other materials provided with the distribution. 39127667Sbms * 3. All advertising materials mentioning features or use of this software 40127667Sbms * must display the following acknowledgement: 41127667Sbms * This product includes software developed by Yen Yen Lim and 42127667Sbms * North Dakota State University 43127667Sbms * 4. The name of the author may not be used to endorse or promote products 44127667Sbms * derived from this software without specific prior written permission. 45127667Sbms * 46127667Sbms * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 47127667Sbms * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 48127667Sbms * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 49127667Sbms * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 50127667Sbms * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 51127667Sbms * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 52127667Sbms * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53127667Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 54127667Sbms * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 55127667Sbms * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 56127667Sbms * POSSIBILITY OF SUCH DAMAGE. 57127667Sbms */ 58127667Sbms 59147897Ssam#ifndef HAVE___ATTRIBUTE__ 60147897Ssam#define __attribute__(x) 61147897Ssam#endif /* HAVE___ATTRIBUTE__ */ 62147897Ssam 6317683Spst/* Address qualifiers. */ 6417683Spst 6517683Spst#define Q_HOST 1 6617683Spst#define Q_NET 2 6717683Spst#define Q_PORT 3 6817683Spst#define Q_GATEWAY 4 6917683Spst#define Q_PROTO 5 7056891Sfenner#define Q_PROTOCHAIN 6 71147897Ssam#define Q_PORTRANGE 7 7217683Spst 7317683Spst/* Protocol qualifiers. */ 7417683Spst 7517683Spst#define Q_LINK 1 7617683Spst#define Q_IP 2 7717683Spst#define Q_ARP 3 7817683Spst#define Q_RARP 4 7998533Sfenner#define Q_SCTP 5 8098533Sfenner#define Q_TCP 6 8198533Sfenner#define Q_UDP 7 8298533Sfenner#define Q_ICMP 8 8398533Sfenner#define Q_IGMP 9 8498533Sfenner#define Q_IGRP 10 8517683Spst 8617683Spst 8798533Sfenner#define Q_ATALK 11 8898533Sfenner#define Q_DECNET 12 8998533Sfenner#define Q_LAT 13 9098533Sfenner#define Q_SCA 14 9198533Sfenner#define Q_MOPRC 15 9298533Sfenner#define Q_MOPDL 16 9317683Spst 9475110Sfenner 9598533Sfenner#define Q_IPV6 17 9698533Sfenner#define Q_ICMPV6 18 9798533Sfenner#define Q_AH 19 9898533Sfenner#define Q_ESP 20 9956891Sfenner 10098533Sfenner#define Q_PIM 21 10198533Sfenner#define Q_VRRP 22 10256891Sfenner 10398533Sfenner#define Q_AARP 23 10456891Sfenner 10598533Sfenner#define Q_ISO 24 10698533Sfenner#define Q_ESIS 25 10798533Sfenner#define Q_ISIS 26 10898533Sfenner#define Q_CLNP 27 10975110Sfenner 11098533Sfenner#define Q_STP 28 11198533Sfenner 11298533Sfenner#define Q_IPX 29 11398533Sfenner 11498533Sfenner#define Q_NETBEUI 30 11598533Sfenner 116127667Sbms/* IS-IS Levels */ 117127667Sbms#define Q_ISIS_L1 31 118127667Sbms#define Q_ISIS_L2 32 119127667Sbms/* PDU types */ 120127667Sbms#define Q_ISIS_IIH 33 121127667Sbms#define Q_ISIS_LAN_IIH 34 122127667Sbms#define Q_ISIS_PTP_IIH 35 123127667Sbms#define Q_ISIS_SNP 36 124127667Sbms#define Q_ISIS_CSNP 37 125127667Sbms#define Q_ISIS_PSNP 38 126127667Sbms#define Q_ISIS_LSP 39 127127667Sbms 128147897Ssam#define Q_RADIO 40 129147897Ssam 13017683Spst/* Directional qualifiers. */ 13117683Spst 13217683Spst#define Q_SRC 1 13317683Spst#define Q_DST 2 13417683Spst#define Q_OR 3 13517683Spst#define Q_AND 4 136190225Srpaulo#define Q_ADDR1 5 137190225Srpaulo#define Q_ADDR2 6 138190225Srpaulo#define Q_ADDR3 7 139190225Srpaulo#define Q_ADDR4 8 14017683Spst 14117683Spst#define Q_DEFAULT 0 14217683Spst#define Q_UNDEF 255 14317683Spst 144127667Sbms/* ATM types */ 145127667Sbms#define A_METAC 22 /* Meta signalling Circuit */ 146127667Sbms#define A_BCC 23 /* Broadcast Circuit */ 147127667Sbms#define A_OAMF4SC 24 /* Segment OAM F4 Circuit */ 148127667Sbms#define A_OAMF4EC 25 /* End-to-End OAM F4 Circuit */ 149127667Sbms#define A_SC 26 /* Signalling Circuit*/ 150127667Sbms#define A_ILMIC 27 /* ILMI Circuit */ 151127667Sbms#define A_OAM 28 /* OAM cells : F4 only */ 152127667Sbms#define A_OAMF4 29 /* OAM F4 cells: Segment + End-to-end */ 153127667Sbms#define A_LANE 30 /* LANE traffic */ 154127667Sbms#define A_LLC 31 /* LLC-encapsulated traffic */ 155127667Sbms 156127667Sbms/* Based on Q.2931 signalling protocol */ 157127667Sbms#define A_SETUP 41 /* Setup message */ 158127667Sbms#define A_CALLPROCEED 42 /* Call proceeding message */ 159127667Sbms#define A_CONNECT 43 /* Connect message */ 160127667Sbms#define A_CONNECTACK 44 /* Connect Ack message */ 161127667Sbms#define A_RELEASE 45 /* Release message */ 162127667Sbms#define A_RELEASE_DONE 46 /* Release message */ 163127667Sbms 164127667Sbms/* ATM field types */ 165127667Sbms#define A_VPI 51 166127667Sbms#define A_VCI 52 167127667Sbms#define A_PROTOTYPE 53 168127667Sbms#define A_MSGTYPE 54 169127667Sbms#define A_CALLREFTYPE 55 170127667Sbms 171127667Sbms#define A_CONNECTMSG 70 /* returns Q.2931 signalling messages for 172127667Sbms establishing and destroying switched 173127667Sbms virtual connection */ 174127667Sbms#define A_METACONNECT 71 /* returns Q.2931 signalling messages for 175127667Sbms establishing and destroying predefined 176127667Sbms virtual circuits, such as broadcast 177127667Sbms circuit, oamf4 segment circuit, oamf4 178127667Sbms end-to-end circuits, ILMI circuits or 179127667Sbms connection signalling circuit. */ 180127667Sbms 181172680Smlaier/* MTP2 types */ 182172680Smlaier#define M_FISU 22 /* FISU */ 183172680Smlaier#define M_LSSU 23 /* LSSU */ 184172680Smlaier#define M_MSU 24 /* MSU */ 185147897Ssam 186172680Smlaier/* MTP3 field types */ 187172680Smlaier#define M_SIO 1 188172680Smlaier#define M_OPC 2 189172680Smlaier#define M_DPC 3 190172680Smlaier#define M_SLS 4 191147897Ssam 192172680Smlaier 19356891Sfennerstruct slist; 19456891Sfenner 19517683Spststruct stmt { 19617683Spst int code; 19756891Sfenner struct slist *jt; /*only for relative jump in block*/ 19856891Sfenner struct slist *jf; /*only for relative jump in block*/ 19917683Spst bpf_int32 k; 20017683Spst}; 20117683Spst 20217683Spststruct slist { 20317683Spst struct stmt s; 20417683Spst struct slist *next; 20517683Spst}; 20617683Spst 207127667Sbms/* 20817683Spst * A bit vector to represent definition sets. We assume TOT_REGISTERS 20917683Spst * is smaller than 8*sizeof(atomset). 21017683Spst */ 21117683Spsttypedef bpf_u_int32 atomset; 21217683Spst#define ATOMMASK(n) (1 << (n)) 21317683Spst#define ATOMELEM(d, n) (d & ATOMMASK(n)) 21417683Spst 21517683Spst/* 21617683Spst * An unbounded set. 21717683Spst */ 21817683Spsttypedef bpf_u_int32 *uset; 21917683Spst 22017683Spst/* 22117683Spst * Total number of atomic entities, including accumulator (A) and index (X). 22217683Spst * We treat all these guys similarly during flow analysis. 22317683Spst */ 22417683Spst#define N_ATOMS (BPF_MEMWORDS+2) 22517683Spst 22617683Spststruct edge { 22717683Spst int id; 22817683Spst int code; 22917683Spst uset edom; 23017683Spst struct block *succ; 23117683Spst struct block *pred; 23217683Spst struct edge *next; /* link list of incoming edges for a node */ 23317683Spst}; 23417683Spst 23517683Spststruct block { 23617683Spst int id; 23717683Spst struct slist *stmts; /* side effect stmts */ 23817683Spst struct stmt s; /* branch stmt */ 23917683Spst int mark; 24017683Spst int longjt; /* jt branch requires long jump */ 24117683Spst int longjf; /* jf branch requires long jump */ 24217683Spst int level; 24317683Spst int offset; 24417683Spst int sense; 24517683Spst struct edge et; 24617683Spst struct edge ef; 24717683Spst struct block *head; 24817683Spst struct block *link; /* link field used by optimizer */ 24917683Spst uset dom; 25017683Spst uset closure; 25117683Spst struct edge *in_edges; 25217683Spst atomset def, kill; 25317683Spst atomset in_use; 25417683Spst atomset out_use; 25517683Spst int oval; 25617683Spst int val[N_ATOMS]; 25717683Spst}; 25817683Spst 25917683Spststruct arth { 26017683Spst struct block *b; /* protocol checks */ 26117683Spst struct slist *s; /* stmt list */ 26217683Spst int regno; /* virtual register number of result */ 26317683Spst}; 26417683Spst 26517683Spststruct qual { 26617683Spst unsigned char addr; 26717683Spst unsigned char proto; 26817683Spst unsigned char dir; 26917683Spst unsigned char pad; 27017683Spst}; 27117683Spst 27217683Spststruct arth *gen_loadi(int); 27317683Spststruct arth *gen_load(int, struct arth *, int); 27417683Spststruct arth *gen_loadlen(void); 27517683Spststruct arth *gen_neg(struct arth *); 27617683Spststruct arth *gen_arth(int, struct arth *, struct arth *); 27717683Spst 27817683Spstvoid gen_and(struct block *, struct block *); 27917683Spstvoid gen_or(struct block *, struct block *); 28017683Spstvoid gen_not(struct block *); 28117683Spst 28217683Spststruct block *gen_scode(const char *, struct qual); 28317683Spststruct block *gen_ecode(const u_char *, struct qual); 28498533Sfennerstruct block *gen_acode(const u_char *, struct qual); 28517683Spststruct block *gen_mcode(const char *, const char *, int, struct qual); 28656891Sfenner#ifdef INET6 28756891Sfennerstruct block *gen_mcode6(const char *, const char *, int, struct qual); 28856891Sfenner#endif 28917683Spststruct block *gen_ncode(const char *, bpf_u_int32, struct qual); 29017683Spststruct block *gen_proto_abbrev(int); 29117683Spststruct block *gen_relation(int, struct arth *, struct arth *, int); 29217683Spststruct block *gen_less(int); 29317683Spststruct block *gen_greater(int); 29417683Spststruct block *gen_byteop(int, int, int); 29517683Spststruct block *gen_broadcast(int); 29617683Spststruct block *gen_multicast(int); 29717683Spststruct block *gen_inbound(int); 29817683Spst 29975110Sfennerstruct block *gen_vlan(int); 300146771Ssamstruct block *gen_mpls(int); 30175110Sfenner 302162015Ssamstruct block *gen_pppoed(void); 303162015Ssamstruct block *gen_pppoes(void); 304162015Ssam 305147897Ssamstruct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse); 306127667Sbmsstruct block *gen_atmtype_abbrev(int type); 307127667Sbmsstruct block *gen_atmmulti_abbrev(int type); 308127667Sbms 309172680Smlaierstruct block *gen_mtp2type_abbrev(int type); 310147897Ssamstruct block *gen_mtp3field_code(int mtp3field, bpf_u_int32 jvalue, bpf_u_int32 jtype, int reverse); 311147897Ssam 312127667Sbmsstruct block *gen_pf_ifname(const char *); 313127667Sbmsstruct block *gen_pf_rnr(int); 314127667Sbmsstruct block *gen_pf_srnr(int); 315127667Sbmsstruct block *gen_pf_ruleset(char *); 316127667Sbmsstruct block *gen_pf_reason(int); 317127667Sbmsstruct block *gen_pf_action(int); 318127667Sbmsstruct block *gen_pf_dir(int); 319127667Sbms 320190225Srpaulostruct block *gen_p80211_type(int, int); 321190225Srpaulostruct block *gen_p80211_fcdir(int); 322190225Srpaulo 32317683Spstvoid bpf_optimize(struct block **); 32475110Sfennervoid bpf_error(const char *, ...) 325147897Ssam __attribute__((noreturn, format (printf, 1, 2))); 32617683Spst 32717683Spstvoid finish_parse(struct block *); 32817683Spstchar *sdup(const char *); 32917683Spst 33017683Spststruct bpf_insn *icode_to_fcode(struct block *, int *); 33117683Spstint pcap_parse(void); 332172680Smlaiervoid lex_init(const char *); 33375110Sfennervoid lex_cleanup(void); 33417683Spstvoid sappend(struct slist *, struct slist *); 33517683Spst 33617683Spst/* XXX */ 33717683Spst#define JT(b) ((b)->et.succ) 33817683Spst#define JF(b) ((b)->ef.succ) 33956891Sfenner 34056891Sfennerextern int no_optimize; 341