]> The Tcpdump Group git mirrors - libpcap/commitdiff
Mind all-zeroes IPv6 netmask in gen_host6(). 1498/head
authorDenis Ovsienko <[email protected]>
Sat, 29 Mar 2025 14:11:54 +0000 (14:11 +0000)
committerDenis Ovsienko <[email protected]>
Tue, 8 Apr 2025 10:38:17 +0000 (11:38 +0100)
Apply the same logc as in gen_host().  Now the unoptimized filter
program for "ip6 dst net ::/0" has no always-true comparisons and is the
same as the optimized one.

gencode.c
testprogs/TESTrun

index 0f6866f84acf403602868c2d1eb6c0b58ab01bcf..92b3968211a3d3f745c2d4055c19bc2be1341a2e 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -5236,6 +5236,12 @@ gen_host6(compiler_state_t *cstate, struct in6_addr *addr,
        case Q_DEFAULT:
        case Q_IPV6:
                b0 = gen_linktype(cstate, ETHERTYPE_IPV6);
+               // Same as the Q_IP case in gen_host().
+               if (
+                       ! memcmp(mask, &in6addr_any, sizeof(struct in6_addr)) &&
+                       ! memcmp(addr, &in6addr_any, sizeof(struct in6_addr))
+               )
+                       return b0;
                b1 = gen_hostop6(cstate, addr, mask, dir, 8, 24);
                gen_and(b0, b1);
                return b1;
index d671042f699b6cd23b9480e6693bf6fc637f7446..77d926f1b585ce552847a2ee1438b2b79bd2a98e 100755 (executable)
@@ -11615,22 +11615,13 @@ my @accept_blocks = (
                skip => skip_config_undef ('INET6'),
                DLT => 'RAW',
                aliases => ['ip6 dst net ::/0'],
-               opt => '
+               unopt => '
                        (000) ldb      [0]
                        (001) and      #0xf0
                        (002) jeq      #0x60            jt 3    jf 4
                        (003) ret      #262144
                        (004) ret      #0
                        ',
-               unopt => '
-                       (000) ldb      [0]
-                       (001) and      #0xf0
-                       (002) jeq      #0x60            jt 3    jf 6
-                       (003) ld       #0x0
-                       (004) jeq      #0x0             jt 5    jf 6
-                       (005) ret      #262144
-                       (006) ret      #0
-                       ',
        }, # ip6_dst_net_0
        {
                name => 'ip6_dst_net_8',