1/* 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 *
| 1/* 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 *
|
21 * $FreeBSD: head/contrib/libpcap/gencode.h 75110 2001-04-03 04:32:48Z fenner $ 22 * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.47 2000/11/04 10:09:55 guy Exp $ (LBL)
| 21 * @(#) $Header: /tcpdump/master/libpcap/gencode.h,v 1.53 2001/05/10 14:48:02 fenner Exp $ (LBL) 22 * 23 * $FreeBSD: head/contrib/libpcap/gencode.h 98533 2002-06-21 01:38:14Z fenner $
|
23 */ 24 25/* Address qualifiers. */ 26 27#define Q_HOST 1 28#define Q_NET 2 29#define Q_PORT 3 30#define Q_GATEWAY 4 31#define Q_PROTO 5 32#define Q_PROTOCHAIN 6 33 34/* Protocol qualifiers. */ 35 36#define Q_LINK 1 37#define Q_IP 2 38#define Q_ARP 3 39#define Q_RARP 4
| 24 */ 25 26/* Address qualifiers. */ 27 28#define Q_HOST 1 29#define Q_NET 2 30#define Q_PORT 3 31#define Q_GATEWAY 4 32#define Q_PROTO 5 33#define Q_PROTOCHAIN 6 34 35/* Protocol qualifiers. */ 36 37#define Q_LINK 1 38#define Q_IP 2 39#define Q_ARP 3 40#define Q_RARP 4
|
40#define Q_TCP 5 41#define Q_UDP 6 42#define Q_ICMP 7 43#define Q_IGMP 8 44#define Q_IGRP 9
| 41#define Q_SCTP 5 42#define Q_TCP 6 43#define Q_UDP 7 44#define Q_ICMP 8 45#define Q_IGMP 9 46#define Q_IGRP 10
|
45 46
| 47 48
|
47#define Q_ATALK 10 48#define Q_DECNET 11 49#define Q_LAT 12 50#define Q_SCA 13 51#define Q_MOPRC 14 52#define Q_MOPDL 15
| 49#define Q_ATALK 11 50#define Q_DECNET 12 51#define Q_LAT 13 52#define Q_SCA 14 53#define Q_MOPRC 15 54#define Q_MOPDL 16
|
53 54
| 55 56
|
55#define Q_IPV6 16 56#define Q_ICMPV6 17 57#define Q_AH 18 58#define Q_ESP 19
| 57#define Q_IPV6 17 58#define Q_ICMPV6 18 59#define Q_AH 19 60#define Q_ESP 20
|
59
| 61
|
60#define Q_PIM 20
| 62#define Q_PIM 21 63#define Q_VRRP 22
|
61
| 64
|
62#define Q_AARP 21
| 65#define Q_AARP 23
|
63
| 66
|
64#define Q_ISO 22 65#define Q_ESIS 23 66#define Q_ISIS 24 67#define Q_CLNP 25
| 67#define Q_ISO 24 68#define Q_ESIS 25 69#define Q_ISIS 26 70#define Q_CLNP 27
|
68
| 71
|
| 72#define Q_STP 28 73 74#define Q_IPX 29 75 76#define Q_NETBEUI 30 77
|
69/* Directional qualifiers. */ 70 71#define Q_SRC 1 72#define Q_DST 2 73#define Q_OR 3 74#define Q_AND 4 75 76#define Q_DEFAULT 0 77#define Q_UNDEF 255 78 79struct slist; 80 81struct stmt { 82 int code; 83 struct slist *jt; /*only for relative jump in block*/ 84 struct slist *jf; /*only for relative jump in block*/ 85 bpf_int32 k; 86}; 87 88struct slist { 89 struct stmt s; 90 struct slist *next; 91}; 92 93/* 94 * A bit vector to represent definition sets. We assume TOT_REGISTERS 95 * is smaller than 8*sizeof(atomset). 96 */ 97typedef bpf_u_int32 atomset; 98#define ATOMMASK(n) (1 << (n)) 99#define ATOMELEM(d, n) (d & ATOMMASK(n)) 100 101/* 102 * An unbounded set. 103 */ 104typedef bpf_u_int32 *uset; 105 106/* 107 * Total number of atomic entities, including accumulator (A) and index (X). 108 * We treat all these guys similarly during flow analysis. 109 */ 110#define N_ATOMS (BPF_MEMWORDS+2) 111 112struct edge { 113 int id; 114 int code; 115 uset edom; 116 struct block *succ; 117 struct block *pred; 118 struct edge *next; /* link list of incoming edges for a node */ 119}; 120 121struct block { 122 int id; 123 struct slist *stmts; /* side effect stmts */ 124 struct stmt s; /* branch stmt */ 125 int mark; 126 int longjt; /* jt branch requires long jump */ 127 int longjf; /* jf branch requires long jump */ 128 int level; 129 int offset; 130 int sense; 131 struct edge et; 132 struct edge ef; 133 struct block *head; 134 struct block *link; /* link field used by optimizer */ 135 uset dom; 136 uset closure; 137 struct edge *in_edges; 138 atomset def, kill; 139 atomset in_use; 140 atomset out_use; 141 int oval; 142 int val[N_ATOMS]; 143}; 144 145struct arth { 146 struct block *b; /* protocol checks */ 147 struct slist *s; /* stmt list */ 148 int regno; /* virtual register number of result */ 149}; 150 151struct qual { 152 unsigned char addr; 153 unsigned char proto; 154 unsigned char dir; 155 unsigned char pad; 156}; 157 158struct arth *gen_loadi(int); 159struct arth *gen_load(int, struct arth *, int); 160struct arth *gen_loadlen(void); 161struct arth *gen_neg(struct arth *); 162struct arth *gen_arth(int, struct arth *, struct arth *); 163 164void gen_and(struct block *, struct block *); 165void gen_or(struct block *, struct block *); 166void gen_not(struct block *); 167 168struct block *gen_scode(const char *, struct qual); 169struct block *gen_ecode(const u_char *, struct qual);
| 78/* Directional qualifiers. */ 79 80#define Q_SRC 1 81#define Q_DST 2 82#define Q_OR 3 83#define Q_AND 4 84 85#define Q_DEFAULT 0 86#define Q_UNDEF 255 87 88struct slist; 89 90struct stmt { 91 int code; 92 struct slist *jt; /*only for relative jump in block*/ 93 struct slist *jf; /*only for relative jump in block*/ 94 bpf_int32 k; 95}; 96 97struct slist { 98 struct stmt s; 99 struct slist *next; 100}; 101 102/* 103 * A bit vector to represent definition sets. We assume TOT_REGISTERS 104 * is smaller than 8*sizeof(atomset). 105 */ 106typedef bpf_u_int32 atomset; 107#define ATOMMASK(n) (1 << (n)) 108#define ATOMELEM(d, n) (d & ATOMMASK(n)) 109 110/* 111 * An unbounded set. 112 */ 113typedef bpf_u_int32 *uset; 114 115/* 116 * Total number of atomic entities, including accumulator (A) and index (X). 117 * We treat all these guys similarly during flow analysis. 118 */ 119#define N_ATOMS (BPF_MEMWORDS+2) 120 121struct edge { 122 int id; 123 int code; 124 uset edom; 125 struct block *succ; 126 struct block *pred; 127 struct edge *next; /* link list of incoming edges for a node */ 128}; 129 130struct block { 131 int id; 132 struct slist *stmts; /* side effect stmts */ 133 struct stmt s; /* branch stmt */ 134 int mark; 135 int longjt; /* jt branch requires long jump */ 136 int longjf; /* jf branch requires long jump */ 137 int level; 138 int offset; 139 int sense; 140 struct edge et; 141 struct edge ef; 142 struct block *head; 143 struct block *link; /* link field used by optimizer */ 144 uset dom; 145 uset closure; 146 struct edge *in_edges; 147 atomset def, kill; 148 atomset in_use; 149 atomset out_use; 150 int oval; 151 int val[N_ATOMS]; 152}; 153 154struct arth { 155 struct block *b; /* protocol checks */ 156 struct slist *s; /* stmt list */ 157 int regno; /* virtual register number of result */ 158}; 159 160struct qual { 161 unsigned char addr; 162 unsigned char proto; 163 unsigned char dir; 164 unsigned char pad; 165}; 166 167struct arth *gen_loadi(int); 168struct arth *gen_load(int, struct arth *, int); 169struct arth *gen_loadlen(void); 170struct arth *gen_neg(struct arth *); 171struct arth *gen_arth(int, struct arth *, struct arth *); 172 173void gen_and(struct block *, struct block *); 174void gen_or(struct block *, struct block *); 175void gen_not(struct block *); 176 177struct block *gen_scode(const char *, struct qual); 178struct block *gen_ecode(const u_char *, struct qual);
|
| 179struct block *gen_acode(const u_char *, struct qual);
|
170struct block *gen_mcode(const char *, const char *, int, struct qual); 171#ifdef INET6 172struct block *gen_mcode6(const char *, const char *, int, struct qual); 173#endif 174struct block *gen_ncode(const char *, bpf_u_int32, struct qual); 175struct block *gen_proto_abbrev(int); 176struct block *gen_relation(int, struct arth *, struct arth *, int); 177struct block *gen_less(int); 178struct block *gen_greater(int); 179struct block *gen_byteop(int, int, int); 180struct block *gen_broadcast(int); 181struct block *gen_multicast(int); 182struct block *gen_inbound(int); 183 184struct block *gen_vlan(int); 185 186void bpf_optimize(struct block **); 187void bpf_error(const char *, ...) 188#if HAVE___ATTRIBUTE__ 189 __attribute__((noreturn, format (printf, 1, 2))) 190#endif 191; 192 193void finish_parse(struct block *); 194char *sdup(const char *); 195 196struct bpf_insn *icode_to_fcode(struct block *, int *); 197int pcap_parse(void); 198void lex_init(char *); 199void lex_cleanup(void); 200void sappend(struct slist *, struct slist *); 201 202/* XXX */ 203#define JT(b) ((b)->et.succ) 204#define JF(b) ((b)->ef.succ) 205 206extern int no_optimize;
| 180struct block *gen_mcode(const char *, const char *, int, struct qual); 181#ifdef INET6 182struct block *gen_mcode6(const char *, const char *, int, struct qual); 183#endif 184struct block *gen_ncode(const char *, bpf_u_int32, struct qual); 185struct block *gen_proto_abbrev(int); 186struct block *gen_relation(int, struct arth *, struct arth *, int); 187struct block *gen_less(int); 188struct block *gen_greater(int); 189struct block *gen_byteop(int, int, int); 190struct block *gen_broadcast(int); 191struct block *gen_multicast(int); 192struct block *gen_inbound(int); 193 194struct block *gen_vlan(int); 195 196void bpf_optimize(struct block **); 197void bpf_error(const char *, ...) 198#if HAVE___ATTRIBUTE__ 199 __attribute__((noreturn, format (printf, 1, 2))) 200#endif 201; 202 203void finish_parse(struct block *); 204char *sdup(const char *); 205 206struct bpf_insn *icode_to_fcode(struct block *, int *); 207int pcap_parse(void); 208void lex_init(char *); 209void lex_cleanup(void); 210void sappend(struct slist *, struct slist *); 211 212/* XXX */ 213#define JT(b) ((b)->et.succ) 214#define JF(b) ((b)->ef.succ) 215 216extern int no_optimize;
|