]> The Tcpdump Group git mirrors - libpcap/commit
Use a 16-bit comparison for "dpc". 1449/head
authorDenis Ovsienko <[email protected]>
Tue, 28 Jan 2025 11:37:19 +0000 (11:37 +0000)
committerDenis Ovsienko <[email protected]>
Thu, 30 Jan 2025 19:45:58 +0000 (19:45 +0000)
commit2aebf4663140f23be614a4c06ad9b98577ede91d
tree4c0285f038483fa6cbd5342309d563b370fd3556
parent62979bf245c74f5f450e3b49c75d4dd8a9b79f77
Use a 16-bit comparison for "dpc".

In gen_mtp3field_code_internal() it is not immediately clear what the
OPC value processing code does and whether it does it correctly.  I have
verified that it combines byte swapping and bit shifting and indeed
processes the value consistently with the specification.  To make it
easier to follow in future, replace the custom code and the custom
bitmask with a combination of SWAPLONG() and a bitwise shift.  The
resulting bytecode remains intact (thus no OPC tests change).

The DPC value processing code is plain byte swapping with no bitwise
shift.  The comparison uses BPF_W, but DPC spans only two adjacent
bytes, so change it to BPF_H and use SWAPSHORT(), similar to the above.
The resulting bytecode has the same effect (no DPC apply tests change),
but the SNR becomes better, which is the only change in the
corresponding DPC accept tests, e.g.:

-(000) ld       [4]
-(001) and      #0xff3f0000
-(002) jeq      #0xd6310000      jt 3    jf 4
+(000) ldh      [4]
+(001) and      #0xff3f
+(002) jeq      #0xd631          jt 3    jf 4

The SLS value processing code already uses BPF_B, so just reformat it
along the same lines.  The resulting bytecode remains intact (thus no
SLS tests change).

All of the above applies the same to the HSL variants ("hdpc", "hopc"
and "hsls"), which differ by the field offsets only.  Add comments to
explain the updated code and replace several hard-coded values with
named constants.
gencode.c
testprogs/TESTrun