tcpdump mailing list archives

Re: net net/len (0.0.0.0)


From: Felipe Kellermann <stdfk () terra com br>
Date: Sun, 28 May 2006 02:19:18 -0300 (BRT)

On Sun, 28 May 2006 12:26am  -0300, Felipe Kellermann wrote:

I noticed 'net 0.0.0.0/0' filter compiles to a BPF code that differs from 
the alternative 'net mask' filter. All the others net filters I tried 
produced the same BPF code. Still haven't looked at the code -- is this 
resulting code known/intentional? Using pcap 0.9.4,

src net 0.0.0.0 mask 0.0.0.0:
(000) ldh      [12]
(001) jeq      #0x800           jt 4    jf 2
(002) jeq      #0x806           jt 4    jf 3
(003) jeq      #0x8035          jt 4    jf 5
(004) ret      #96
(005) ret      #0

I've decided to debug the code. gencode.c:gen_mcode is *strangely* passing 
(m = 0xffffffff) to gen_host even when masklen == 0 (s2 == NULL). The code 
in gen_mcode is obviously correct: 0xffffffff << (32 - 0) == 0. Strangely, 
this is not what is happening.

I even thought this could be a GCC problem. I tried turning optimization 
off, changing the object types and writing a test-case - unfortunately I 
couldn't so far reproduce what I'm seeing in gen_mcode.

Fixed the problem here in the wrong way forcing m = 0 when masklen == 0.

This fixes the problem to me. Does anyone know why 0xffffffff << (32 - 0) 
is resulting in 0xffffffff in mcode? Can anyone reproduce this? With this 
patch I get consistent results both using net/len and net/mask.

--- libpcap-0.9.4/gencode.c     2005-09-05 06:08:04.000000000 -0300
+++ libpcap-0.9.4-felipek/gencode.c     2006-05-28 02:03:24.000000000 -0300
@@ -4975,7 +4975,7 @@ gen_mcode(s1, s2, masklen, q)
                /* Convert mask len to mask */
                if (masklen > 32)
                        bpf_error("mask length must be <= 32");
-               m = 0xffffffff << (32 - masklen);
+               m = masklen ? (0xffffffff << (32 - masklen)) : 0;
                if ((n & ~m) != 0)
                        bpf_error("non-network bits set in \"%s/%d\"",
                            s1, masklen);

-- 
Felipe Kellermann
-
This is the tcpdump-workers list.
Visit https://lists.sandelman.ca/ to unsubscribe.


Current thread: