]> The Tcpdump Group git mirrors - libpcap/commitdiff
Lose the no-op dir qualifier in gen_gateway() and gen_proto(). 1491/head
authorDenis Ovsienko <[email protected]>
Fri, 21 Mar 2025 22:13:41 +0000 (22:13 +0000)
committerDenis Ovsienko <[email protected]>
Sun, 23 Mar 2025 20:53:32 +0000 (20:53 +0000)
The grammar defines "gateway" and "proto" without a dir qualifier, so an
attempt to use one is an early syntax error, so in every invocation of
these two functions dir == Q_DEFAULT and respecive checks are dead code.
For gen_protochain() this has already been done in commit 81d760f.

gencode.c

index b6a837aedf76df77cc2d58d6a22720556b226d97..a2795b65a25278a1330500c41af4e5dbfcbc1e9a 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -680,7 +680,7 @@ static struct block *gen_host6(compiler_state_t *, struct in6_addr *,
 #endif
 #ifndef INET6
 static struct block *gen_gateway(compiler_state_t *, const u_char *,
-    struct addrinfo *, int, int);
+    struct addrinfo *, int);
 #endif
 static struct block *gen_ipfrag(compiler_state_t *);
 static struct block *gen_portatom(compiler_state_t *, int, bpf_u_int32);
@@ -703,7 +703,7 @@ static int lookup_proto(compiler_state_t *, const char *, int);
 #if !defined(NO_PROTOCHAIN)
 static struct block *gen_protochain(compiler_state_t *, bpf_u_int32, int);
 #endif /* !defined(NO_PROTOCHAIN) */
-static struct block *gen_proto(compiler_state_t *, bpf_u_int32, int, int);
+static struct block *gen_proto(compiler_state_t *, bpf_u_int32, int);
 static struct slist *xfer_to_x(compiler_state_t *, struct arth *);
 static struct slist *xfer_to_a(compiler_state_t *, struct arth *);
 static struct block *gen_mac_multicast(compiler_state_t *, int);
@@ -5350,17 +5350,18 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
 #endif
 
 #ifndef INET6
+/*
+ * This primitive is non-directional by design, so the grammar does not allow
+ * to qualify it with a direction.
+ */
 static struct block *
 gen_gateway(compiler_state_t *cstate, const u_char *eaddr,
-    struct addrinfo *alist, int proto, int dir)
+    struct addrinfo *alist, int proto)
 {
        struct block *b0, *b1, *tmp;
        struct addrinfo *ai;
        struct sockaddr_in *sin;
 
-       if (dir != 0)
-               bpf_error(cstate, "direction applied to 'gateway'");
-
        switch (proto) {
        case Q_DEFAULT:
        case Q_IP:
@@ -5463,19 +5464,19 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
        switch (proto) {
 
        case Q_SCTP:
-               b1 = gen_proto(cstate, IPPROTO_SCTP, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_SCTP, Q_DEFAULT);
                break;
 
        case Q_TCP:
-               b1 = gen_proto(cstate, IPPROTO_TCP, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_TCP, Q_DEFAULT);
                break;
 
        case Q_UDP:
-               b1 = gen_proto(cstate, IPPROTO_UDP, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_UDP, Q_DEFAULT);
                break;
 
        case Q_ICMP:
-               b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_ICMP, Q_IP);
                break;
 
 #ifndef        IPPROTO_IGMP
@@ -5483,14 +5484,14 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
 #endif
 
        case Q_IGMP:
-               b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_IGMP, Q_IP);
                break;
 
 #ifndef        IPPROTO_IGRP
 #define        IPPROTO_IGRP    9
 #endif
        case Q_IGRP:
-               b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_IGRP, Q_IP);
                break;
 
 #ifndef IPPROTO_PIM
@@ -5498,7 +5499,7 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
 #endif
 
        case Q_PIM:
-               b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_PIM, Q_DEFAULT);
                break;
 
 #ifndef IPPROTO_VRRP
@@ -5506,7 +5507,7 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
 #endif
 
        case Q_VRRP:
-               b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_VRRP, Q_IP);
                break;
 
 #ifndef IPPROTO_CARP
@@ -5514,7 +5515,7 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
 #endif
 
        case Q_CARP:
-               b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_CARP, Q_IP);
                break;
 
        case Q_IP:
@@ -5568,21 +5569,21 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
 #define IPPROTO_ICMPV6 58
 #endif
        case Q_ICMPV6:
-               b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_ICMPV6, Q_IPV6);
                break;
 
 #ifndef IPPROTO_AH
 #define IPPROTO_AH     51
 #endif
        case Q_AH:
-               b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_AH, Q_DEFAULT);
                break;
 
 #ifndef IPPROTO_ESP
 #define IPPROTO_ESP    50
 #endif
        case Q_ESP:
-               b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT, Q_DEFAULT);
+               b1 = gen_proto(cstate, IPPROTO_ESP, Q_DEFAULT);
                break;
 
        case Q_ISO:
@@ -5590,75 +5591,75 @@ gen_proto_abbrev_internal(compiler_state_t *cstate, int proto)
                break;
 
        case Q_ESIS:
-               b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO, Q_DEFAULT);
+               b1 = gen_proto(cstate, ISO9542_ESIS, Q_ISO);
                break;
 
        case Q_ISIS:
-               b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
+               b1 = gen_proto(cstate, ISO10589_ISIS, Q_ISO);
                break;
 
        case Q_ISIS_L1: /* all IS-IS Level1 PDU-Types */
-               b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */
+               b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS); /* FIXME extract the circuit-type bits */
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_L2: /* all IS-IS Level2 PDU-Types */
-               b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT); /* FIXME extract the circuit-type bits */
+               b0 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS); /* FIXME extract the circuit-type bits */
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_IIH: /* all IS-IS Hello PDU-Types */
-               b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_LAN_IIH, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_L2_LAN_IIH, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_PTP_IIH, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_LSP:
-               b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_LSP, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_L2_LSP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_SNP:
-               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS);
                gen_or(b0, b1);
-               b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_CSNP:
-               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_CSNP, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_L2_CSNP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_ISIS_PSNP:
-               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS, Q_DEFAULT);
-               b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISIS_L1_PSNP, Q_ISIS);
+               b1 = gen_proto(cstate, ISIS_L2_PSNP, Q_ISIS);
                gen_or(b0, b1);
                break;
 
        case Q_CLNP:
-               b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO, Q_DEFAULT);
+               b1 = gen_proto(cstate, ISO8473_CLNP, Q_ISO);
                break;
 
        case Q_STP:
@@ -6149,6 +6150,10 @@ lookup_proto(compiler_state_t *cstate, const char *name, int proto)
 }
 
 #if !defined(NO_PROTOCHAIN)
+/*
+ * This primitive is non-directional by design, so the grammar does not allow
+ * to qualify it with a direction.
+ */
 static struct block *
 gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
 {
@@ -6456,20 +6461,20 @@ gen_protochain(compiler_state_t *cstate, bpf_u_int32 v, int proto)
  *
  * If <proto> is Q_DEFAULT, i.e. just "proto" was specified, it checks
  * against Q_IP and Q_IPV6.
+ *
+ * This primitive is non-directional by design, so the grammar does not allow
+ * to qualify it with a direction.
  */
 static struct block *
-gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
+gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto)
 {
        struct block *b0, *b1;
        struct block *b2;
 
-       if (dir != Q_DEFAULT)
-               bpf_error(cstate, "direction applied to 'proto'");
-
        switch (proto) {
        case Q_DEFAULT:
-               b0 = gen_proto(cstate, v, Q_IP, dir);
-               b1 = gen_proto(cstate, v, Q_IPV6, dir);
+               b0 = gen_proto(cstate, v, Q_IP);
+               b1 = gen_proto(cstate, v, Q_IPV6);
                gen_or(b0, b1);
                return b1;
 
@@ -6583,7 +6588,7 @@ gen_proto(compiler_state_t *cstate, bpf_u_int32 v, int proto, int dir)
                break; // invalid qualifier
 
        case Q_ISIS:
-               b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO, Q_DEFAULT);
+               b0 = gen_proto(cstate, ISO10589_ISIS, Q_ISO);
                /*
                 * 4 is the offset of the PDU type relative to the IS-IS
                 * header.
@@ -7143,7 +7148,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
                cstate->ai = res;
                if (res == NULL)
                        bpf_error(cstate, "unknown host '%s'", name);
-               b = gen_gateway(cstate, eaddr, res, proto, dir);
+               b = gen_gateway(cstate, eaddr, res, proto);
                cstate->ai = NULL;
                freeaddrinfo(res);
                free(eaddr);
@@ -7157,7 +7162,7 @@ gen_scode(compiler_state_t *cstate, const char *name, struct qual q)
        case Q_PROTO:
                real_proto = lookup_proto(cstate, name, proto);
                if (real_proto >= 0)
-                       return gen_proto(cstate, real_proto, proto, dir);
+                       return gen_proto(cstate, real_proto, proto);
                else
                        bpf_error(cstate, "unknown protocol: %s", name);
 
@@ -7340,7 +7345,7 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q)
                /*NOTREACHED*/
 
        case Q_PROTO:
-               return gen_proto(cstate, v, proto, dir);
+               return gen_proto(cstate, v, proto);
 
 #if !defined(NO_PROTOCHAIN)
        case Q_PROTOCHAIN: