]> The Tcpdump Group git mirrors - libpcap/blobdiff - gencode.h
CI: Call print_so_deps() on rpcapd in remote enabled build
[libpcap] / gencode.h
index 58828ecd5854b3f43eb28b4fed251a83278e0f33..3d17147bf3e9ec2a396f9c9c48ed1a07ebd62bfa 100644 (file)
--- a/gencode.h
+++ b/gencode.h
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#ifndef gencode_h
+#define gencode_h
+
 #include "pcap/funcattrs.h"
+/*
+ * pcap/bpf.h (a public header) needs u_char, u_short and u_int, which can be
+ * made available via either pcap-types.h (a private header) or pcap/pcap.h
+ * (a public header), none of which pcap/bpf.h includes.  Include the private
+ * header to keep things simple, this way this private header should compile
+ * even if included early from another file.
+ */
+#include "pcap-types.h"
+#include "pcap/bpf.h" /* bpf_u_int32 and BPF_MEMWORDS */
 
 /*
  * ATM support:
 #define Q_ISIS_L2       32
 /* PDU types */
 #define Q_ISIS_IIH      33
-#define Q_ISIS_LAN_IIH  34
-#define Q_ISIS_PTP_IIH  35
-#define Q_ISIS_SNP      36
-#define Q_ISIS_CSNP     37
-#define Q_ISIS_PSNP     38
-#define Q_ISIS_LSP      39
+#define Q_ISIS_SNP      34
+#define Q_ISIS_CSNP     35
+#define Q_ISIS_PSNP     36
+#define Q_ISIS_LSP      37
 
-#define Q_RADIO                40
+#define Q_RADIO                38
 
-#define Q_CARP         41
+#define Q_CARP         39
 
 /* Directional qualifiers. */
 
 #define A_OAM          28      /* OAM cells : F4 only */
 #define A_OAMF4                29      /* OAM F4 cells: Segment + End-to-end */
 #define A_LANE         30      /* LANE traffic */
-#define A_LLC          31      /* LLC-encapsulated traffic */
-
-/* Based on Q.2931 signalling protocol */
-#define A_SETUP                41      /* Setup message */
-#define A_CALLPROCEED  42      /* Call proceeding message */
-#define A_CONNECT      43      /* Connect message */
-#define A_CONNECTACK   44      /* Connect Ack message */
-#define A_RELEASE      45      /* Release message */
-#define A_RELEASE_DONE 46      /* Release message */
 
 /* ATM field types */
 #define A_VPI          51
 #define A_VCI          52
-#define A_PROTOTYPE    53
-#define A_MSGTYPE      54
-#define A_CALLREFTYPE  55
 
 #define A_CONNECTMSG   70      /* returns Q.2931 signalling messages for
                                   establishing and destroying switched
 
 struct slist;
 
+/*
+ * A single statement, corresponding to an instruction in a block.
+ */
 struct stmt {
-       int code;
-       struct slist *jt;       /*only for relative jump in block*/
-       struct slist *jf;       /*only for relative jump in block*/
-       bpf_int32 k;
+       int code;               /* opcode */
+       struct slist *jt;       /* only for relative jump in block */
+       struct slist *jf;       /* only for relative jump in block */
+       bpf_u_int32 k;          /* k field */
 };
 
 struct slist {
@@ -233,17 +234,27 @@ typedef bpf_u_int32 *uset;
  */
 #define N_ATOMS (BPF_MEMWORDS+2)
 
+/*
+ * Control flow graph of a program.
+ * This corresponds to an edge in the CFG.
+ * It's a directed graph, so an edge has a predecessor and a successor.
+ */
 struct edge {
-       int id;
-       int code;
+       u_int id;
+       int code;               /* opcode for branch corresponding to this edge */
        uset edom;
-       struct block *succ;
-       struct block *pred;
+       struct block *succ;     /* successor vertex */
+       struct block *pred;     /* predecessor vertex */
        struct edge *next;      /* link list of incoming edges for a node */
 };
 
+/*
+ * A block is a vertex in the CFG.
+ * It has a list of statements, with the final statement being a
+ * branch to successor blocks.
+ */
 struct block {
-       int id;
+       u_int id;
        struct slist *stmts;    /* side effect stmts */
        struct stmt s;          /* branch stmt */
        int mark;
@@ -252,18 +263,18 @@ struct block {
        int level;
        int offset;
        int sense;
-       struct edge et;
-       struct edge ef;
+       struct edge et;         /* edge corresponding to the jt branch */
+       struct edge ef;         /* edge corresponding to the jf branch */
        struct block *head;
        struct block *link;     /* link field used by optimizer */
        uset dom;
        uset closure;
-       struct edge *in_edges;
+       struct edge *in_edges;  /* first edge in the set (linked list) of edges with this as a successor */
        atomset def, kill;
        atomset in_use;
        atomset out_use;
-       int oval;
-       int val[N_ATOMS];
+       int oval;               /* value ID for value tested in branch stmt */
+       bpf_u_int32 val[N_ATOMS];
 };
 
 /*
@@ -288,8 +299,8 @@ struct _compiler_state;
 
 typedef struct _compiler_state compiler_state_t;
 
-struct arth *gen_loadi(compiler_state_t *, int);
-struct arth *gen_load(compiler_state_t *, int, struct arth *, int);
+struct arth *gen_loadi(compiler_state_t *, bpf_u_int32);
+struct arth *gen_load(compiler_state_t *, int, struct arth *, bpf_u_int32);
 struct arth *gen_loadlen(compiler_state_t *);
 struct arth *gen_neg(compiler_state_t *, struct arth *);
 struct arth *gen_arth(compiler_state_t *, int, struct arth *, struct arth *);
@@ -299,14 +310,12 @@ void gen_or(struct block *, struct block *);
 void gen_not(struct block *);
 
 struct block *gen_scode(compiler_state_t *, const char *, struct qual);
-struct block *gen_ecode(compiler_state_t *, const u_char *, struct qual);
-struct block *gen_acode(compiler_state_t *, const u_char *, struct qual);
+struct block *gen_ecode(compiler_state_t *, const char *, struct qual);
+struct block *gen_acode(compiler_state_t *, const char *, struct qual);
 struct block *gen_mcode(compiler_state_t *, const char *, const char *,
-    unsigned int, struct qual);
-#ifdef INET6
-struct block *gen_mcode6(compiler_state_t *, const char *, const char *,
-    unsigned int, struct qual);
-#endif
+    bpf_u_int32, struct qual);
+struct block *gen_mcode6(compiler_state_t *, const char *, bpf_u_int32,
+    struct qual);
 struct block *gen_ncode(compiler_state_t *, const char *, bpf_u_int32,
     struct qual);
 struct block *gen_proto_abbrev(compiler_state_t *, int);
@@ -314,10 +323,11 @@ struct block *gen_relation(compiler_state_t *, int, struct arth *,
     struct arth *, int);
 struct block *gen_less(compiler_state_t *, int);
 struct block *gen_greater(compiler_state_t *, int);
-struct block *gen_byteop(compiler_state_t *, int, int, int);
+struct block *gen_byteop(compiler_state_t *, int, int, bpf_u_int32);
 struct block *gen_broadcast(compiler_state_t *, int);
 struct block *gen_multicast(compiler_state_t *, int);
-struct block *gen_inbound(compiler_state_t *, int);
+struct block *gen_ifindex(compiler_state_t *, int);
+struct block *gen_inbound_outbound(compiler_state_t *, const int);
 
 struct block *gen_llc(compiler_state_t *);
 struct block *gen_llc_i(compiler_state_t *);
@@ -326,22 +336,23 @@ struct block *gen_llc_u(compiler_state_t *);
 struct block *gen_llc_s_subtype(compiler_state_t *, bpf_u_int32);
 struct block *gen_llc_u_subtype(compiler_state_t *, bpf_u_int32);
 
-struct block *gen_vlan(compiler_state_t *, int);
-struct block *gen_mpls(compiler_state_t *, int);
+struct block *gen_vlan(compiler_state_t *, bpf_u_int32, int);
+struct block *gen_mpls(compiler_state_t *, bpf_u_int32, int);
 
 struct block *gen_pppoed(compiler_state_t *);
-struct block *gen_pppoes(compiler_state_t *, int);
+struct block *gen_pppoes(compiler_state_t *, bpf_u_int32, int);
 
-struct block *gen_geneve(compiler_state_t *, int);
+struct block *gen_geneve(compiler_state_t *, bpf_u_int32, int);
+struct block *gen_vxlan(compiler_state_t *, bpf_u_int32, int);
 
-struct block *gen_atmfield_code(compiler_state_t *, int, bpf_int32,
-    bpf_u_int32, int);
-struct block *gen_atmtype_abbrev(compiler_state_t *, int type);
-struct block *gen_atmmulti_abbrev(compiler_state_t *, int type);
+struct block *gen_atmfield_code(compiler_state_t *, int, bpf_u_int32,
+    int, int);
+struct block *gen_atmtype_abbrev(compiler_state_t *, int);
+struct block *gen_atmmulti_abbrev(compiler_state_t *, int);
 
-struct block *gen_mtp2type_abbrev(compiler_state_t *, int type);
+struct block *gen_mtp2type_abbrev(compiler_state_t *, int);
 struct block *gen_mtp3field_code(compiler_state_t *, int, bpf_u_int32,
-    bpf_u_int32, int);
+    int, int);
 
 struct block *gen_pf_ifname(compiler_state_t *, const char *);
 struct block *gen_pf_rnr(compiler_state_t *, int);
@@ -350,8 +361,8 @@ struct block *gen_pf_ruleset(compiler_state_t *, char *);
 struct block *gen_pf_reason(compiler_state_t *, int);
 struct block *gen_pf_action(compiler_state_t *, int);
 
-struct block *gen_p80211_type(compiler_state_t *, int, int);
-struct block *gen_p80211_fcdir(compiler_state_t *, int);
+struct block *gen_p80211_type(compiler_state_t *, bpf_u_int32, bpf_u_int32);
+struct block *gen_p80211_fcdir(compiler_state_t *, bpf_u_int32);
 
 /*
  * Representation of a program as a tree of blocks, plus current mark.
@@ -368,16 +379,15 @@ struct icode {
        int cur_mark;
 };
 
-void bpf_optimize(compiler_state_t *, struct icode *ic);
-void bpf_syntax_error(compiler_state_t *, const char *);
-void PCAP_NORETURN bpf_error(compiler_state_t *, const char *, ...)
+int bpf_optimize(struct icode *, char *);
+void bpf_set_error(compiler_state_t *, const char *, ...)
     PCAP_PRINTFLIKE(2, 3);
 
-void finish_parse(compiler_state_t *, struct block *);
+int finish_parse(compiler_state_t *, struct block *);
 char *sdup(compiler_state_t *, const char *);
 
-struct bpf_insn *icode_to_fcode(compiler_state_t *, struct icode *,
-    struct block *, u_int *);
+struct bpf_insn *icode_to_fcode(struct icode *, struct block *, u_int *,
+    char *);
 void sappend(struct slist *, struct slist *);
 
 /*
@@ -389,3 +399,5 @@ int pcap_parse(void *, compiler_state_t *);
 /* XXX */
 #define JT(b)  ((b)->et.succ)
 #define JF(b)  ((b)->ef.succ)
+
+#endif /* gencode_h */