]> The Tcpdump Group git mirrors - libpcap/commit
Have "outbound" mean Tx only for DLT_SLIP.
authorDenis Ovsienko <[email protected]>
Wed, 26 Feb 2025 13:49:49 +0000 (13:49 +0000)
committerDenis Ovsienko <[email protected]>
Thu, 27 Feb 2025 20:34:08 +0000 (20:34 +0000)
commit127435bf8c1e3eb08166a6004b74d638e5afd4fb
tree740524e722a9eb9223c62c762fe70926087e9c23
parent66941d599aa6e93754f10dd9404715aaa345ac5b
Have "outbound" mean Tx only for DLT_SLIP.

In DLT_SLIP packet direction is the first and the only byte of the
link-layer header, so it ought to be trivial to test, which the
optimized filter program seems to implement:

$ ./testprogs/filtertest SLIP outbound
(000) ldb      [0]
(001) jeq      #0x0             jt 2 jf 3
(002) ret      #0
(003) ret      #262144

However, the C code in gen_inbound_outbound() looks more complicated
than the above requires: since libpcap 0.0 (June 1994) it has been a
combination of four functions, and the unoptimized filter program it
produces looks more complicated than it needs to be:

$ ./testprogs/filtertest -O SLIP outbound
(000) ld       #0x0
(001) st       M[1]
(002) ldx      M[1]
(003) ldb      [x + 0]
(004) st       M[2]
(005) ld       #0x0
(006) st       M[0]
(007) ldx      M[0]
(008) ld       M[2]
(009) sub      x
(010) jeq      #0x0             jt 11 jf 12
(011) ret      #0
(012) ret      #262144

The C code means loading 1 byte from offset 0 of the link-layer header,
testing it to be equal to 0 and reversing the result if testing for
"outbound".  The test for "inbound" correctly matches direction value 0
(received packets).  The test for "outbound" matches direction value 1
(transmitted packets), as well as any other non-zero direction value,
which is invalid in DLT_SLIP.

Replace the custom code with gen_cmp() consistently with the other cases
in the same switch block.  This makes the unoptimized and the optimized
filter programs identical, also fixes "outbound" to match Tx packets
only.  Update the affected filter tests to reflect these developments.
CHANGES
gencode.c
testprogs/TESTrun