]> The Tcpdump Group git mirrors - libpcap/commit
Expand abbreviations into "proto X" properly.
authorDenis Ovsienko <[email protected]>
Sun, 12 Jun 2022 16:19:46 +0000 (17:19 +0100)
committerDenis Ovsienko <[email protected]>
Sun, 12 Jun 2022 16:34:50 +0000 (17:34 +0100)
commitc93c8ff003091f78c2bc70422d71a68bf95e5bde
tree93746dc4bef5da1783f38740bd02aaeed520606c
parentdb3b00e9a0875edea808734640d84e035ae11357
Expand abbreviations into "proto X" properly.

Make the "ah", "esp", "pim", "sctp", "tcp" and "udp" abbreviations
compile exactly the same as what they expand into (as far as
pcap-filter(7) defines it).

Before commit 2ae1134 gen_proto_abbrev_internal() always generated the
IPv4 leg last; when IPv6 was enabled, it generated the IPv6 leg first
and ORed the two together;  gen_proto() always generated the IPv4 leg
first; when IPv6 was enabled, it generated the IPv6 leg last and ORed
the two together.  This way, with IPv6 enabled "ah" and "proto \ah"
produced different (although effectively equivalent) sequences of
statements.

After commit 2ae1134 the difference became unconditional and respective
code in gen_proto_abbrev_internal() effectively duplicated the code in
gen_proto().  Address that by calling the latter properly from the
former, so whatever the full syntax produces in the current revision,
the abbreviation always produces exactly the same.

The difference made it unnecessarily convoluted to compare compiled
filters when one filter used an abbreviation and the other used the full
syntax.  For example, without the source code and an up to date man page
trying to tell whether "sctp" and "proto \sctp" have the same effect is
as simple as the following:

$ tcpdump -y EN10MB -d 'proto \sctp'
(000) ldh      [12]
(001) jeq      #0x800           jt 2 jf 4
(002) ldb      [23]
(003) jeq      #0x84            jt 10 jf 11
(004) jeq      #0x86dd          jt 5 jf 11
(005) ldb      [20]
(006) jeq      #0x84            jt 10 jf 7
(007) jeq      #0x2c            jt 8 jf 11
(008) ldb      [54]
(009) jeq      #0x84            jt 10 jf 11
(010) ret      #262144
(011) ret      #0

$ tcpdump -y EN10MB -d 'sctp' # before this change
(000) ldh      [12]
(001) jeq      #0x86dd          jt 2 jf 7
(002) ldb      [20]
(003) jeq      #0x84            jt 10 jf 4
(004) jeq      #0x2c            jt 5 jf 11
(005) ldb      [54]
(006) jeq      #0x84            jt 10 jf 11
(007) jeq      #0x800           jt 8 jf 11
(008) ldb      [23]
(009) jeq      #0x84            jt 10 jf 11
(010) ret      #262144
(011) ret      #0

$ tcpdump -y EN10MB -d 'sctp' # after this change
(000) ldh      [12]
(001) jeq      #0x800           jt 2 jf 4
(002) ldb      [23]
(003) jeq      #0x84            jt 10 jf 11
(004) jeq      #0x86dd          jt 5 jf 11
(005) ldb      [20]
(006) jeq      #0x84            jt 10 jf 7
(007) jeq      #0x2c            jt 8 jf 11
(008) ldb      [54]
(009) jeq      #0x84            jt 10 jf 11
(010) ret      #262144
(011) ret      #0
CHANGES
gencode.c