]> The Tcpdump Group git mirrors - libpcap/commit
Fix DECnet packet filtering on big-endian hosts.
authorDenis Ovsienko <[email protected]>
Tue, 10 Dec 2024 01:27:23 +0000 (01:27 +0000)
committerDenis Ovsienko <[email protected]>
Tue, 10 Dec 2024 11:57:11 +0000 (11:57 +0000)
commit6bf6fb56ffc7b76ed3c0463e6e6c83813baeb8e7
tree12dcd0ed15c50886639511ac7e104d71e667c253
parent7ed2012c21111fe5e8b35c4232bab3927be71b4c
Fix DECnet packet filtering on big-endian hosts.

DECnet address matching works on little-endian hosts only:

$ arch
OpenBSD.amd64
$ tcpdump -nr tests/DECnet_Phone.pcap -c 1 'decnet src 1.1' | wc -l
reading from file tests/DECnet_Phone.pcap, link-type EN10MB (Ethernet),
  snapshot length 65535
       1

$ arch
OpenBSD.mips64
$ tcpdump -nr tests/DECnet_Phone.pcap -c 1 'decnet src 1.1' | wc -l
reading from file tests/DECnet_Phone.pcap, link-type EN10MB (Ethernet),
  snapshot length 65535
       0

Although the savefile is the same, the bytecode is different: in the
latter case gen_dnhostop() generates 8 statements out of 20 with 16-bit
literal values byte-swapped, e.g.:

-(006) jeq      #0x104           jt 22 jf 7
+(006) jeq      #0x401           jt 22 jf 7

For one half of those statements the root cause is feeding the provided
16-bit big-endian DECnet address, which always needs to be converted to
little-endian to match the packet encoding, to ntohs(), which leaves the
value intact on a big-endian host.  Fix this by using SWAPSHORT()
instead.

For the other half the root cause is treating two adjacent independent
bytes of the packet as a 16-bit value, hard-coding it and its 16-bit
mask byte-swapped and feeding these values to ntohs(), which on a
big-endian host does not cancel the hard-coded byte swap out.  Fix this
by hard-coding the two bytes and the bit mask as big-endian in the first
place.

Remove a number of unnecessary type casts and add a comment to explain
the packet encoding and the code logic.
CHANGES
gencode.c