]> The Tcpdump Group git mirrors - tcpdump/log
tcpdump
4 years agoOpenFlow 1.3: Get OFPT_HELLO right.
Denis Ovsienko [Wed, 30 Sep 2020 13:41:45 +0000 (14:41 +0100)] 
OpenFlow 1.3: Get OFPT_HELLO right.

Decode the optional trailing data and update two tests.

4 years agoOpenFlow: Make one more function shared.
Denis Ovsienko [Wed, 30 Sep 2020 11:56:43 +0000 (12:56 +0100)] 
OpenFlow: Make one more function shared.

Rename of10_bitmap_print() to of_bitmap_print() and make it available
from print-openflow.c.

4 years agoIGMP: Remove all remaining ND_TCHECK*() cases.
Denis Ovsienko [Wed, 30 Sep 2020 02:46:47 +0000 (03:46 +0100)] 
IGMP: Remove all remaining ND_TCHECK*() cases.

In print_mtrace() the check was just before a GET that fetches the last
field of the structure. The other three checks tested exactly the space
from that GET_IPADDR_STRING() would fetch anyway.

4 years agoIGMP: Deduplicate multicast trace printing code.
Denis Ovsienko [Wed, 30 Sep 2020 02:36:06 +0000 (03:36 +0100)] 
IGMP: Deduplicate multicast trace printing code.

Instead of having two functions that differ only in the prefix they
print have one function that accepts the prefix as an additional
argument.

4 years agoZeroMQ: Use nd_trunc_longjmp()
Denis Ovsienko [Wed, 30 Sep 2020 02:17:59 +0000 (03:17 +0100)] 
ZeroMQ: Use nd_trunc_longjmp()

4 years agoM3UA: Lose all trunc labels.
Denis Ovsienko [Wed, 30 Sep 2020 02:11:20 +0000 (03:11 +0100)] 
M3UA: Lose all trunc labels.

Enable ND_LONGJMP_FROM_TCHECK, lose an excess ND_TCHECK_LEN() and factor
another one out.

4 years agoSYSLOG: Make a few cleanups.
Denis Ovsienko [Wed, 30 Sep 2020 01:51:28 +0000 (02:51 +0100)] 
SYSLOG: Make a few cleanups.

Add a comment to tell the specification. Untangle the PRI parsing code.
Replace a loop with nd_printn() to print a counted string.

4 years agoHSRP: Remove a few remaining old truncation props.
Denis Ovsienko [Wed, 30 Sep 2020 00:36:06 +0000 (01:36 +0100)] 
HSRP: Remove a few remaining old truncation props.

Let the string printing function guard the snapshot end and switch it to
the one appropriate for zero-padded strings. Update three tests.

4 years agoVRRP: Remove a few remaining old truncation props.
Denis Ovsienko [Wed, 30 Sep 2020 00:03:09 +0000 (01:03 +0100)] 
VRRP: Remove a few remaining old truncation props.

Remove the only remaining ND_TCHECK_1() and let the string printing
function guard the snapshot end. While at it, switch the latter to the
one that handles zero padding properly. This makes no difference in the
existing VRRP test, which uses a maximum length password. Lose the
trailing quote so the truncation label justly appears within the
authentication field, not after it.

4 years agoRX: Remove 1 now redundant ND_TCHECK_LEN(e, sizeof(uint64_t)) call
Francois-Xavier Le Bail [Wed, 30 Sep 2020 11:12:05 +0000 (13:12 +0200)] 
RX: Remove 1 now redundant ND_TCHECK_LEN(e, sizeof(uint64_t)) call

It is redundant because it is identical to ND_TCHECK_8(e), followed
by a GET_BE_U_8(e), same e, which do the bounds check.

4 years agoRX: Remove 1 now redundant ND_TCHECK_LEN(e, sizeof(uint32_t)) call
Francois-Xavier Le Bail [Wed, 30 Sep 2020 08:48:04 +0000 (10:48 +0200)] 
RX: Remove 1 now redundant ND_TCHECK_LEN(e, sizeof(uint32_t)) call

it is redundant because it is identical to ND_TCHECK_4(e), followed
by a GET_BE_U_4(e), same e, which do the bounds check.

4 years agoPGM: Remove 3 now redundant ND_TCHECK_LEN(e, sizeof(uint32_t)) calls
Francois-Xavier Le Bail [Wed, 30 Sep 2020 08:48:04 +0000 (10:48 +0200)] 
PGM: Remove 3 now redundant ND_TCHECK_LEN(e, sizeof(uint32_t)) calls

They are redundant because they are identical to ND_TCHECK_4(e), followed
by a GET_BE_U_4(e), same e, which do the bounds check.

4 years agoRemove 3 now redundant ND_TCHECK_LEN(e, sizeof(short)) calls
Francois-Xavier Le Bail [Wed, 30 Sep 2020 08:15:03 +0000 (10:15 +0200)] 
Remove 3 now redundant ND_TCHECK_LEN(e, sizeof(short)) calls

They are redundant because they are identical to ND_TCHECK_2(e), followed
by a GET_BE_U_2(e) or a GET_LE_U_2(e), same e, which do the bounds check.

4 years agoRemove useless 'return' at end of void functions (style)
Francois-Xavier Le Bail [Sun, 20 Sep 2020 16:23:55 +0000 (18:23 +0200)] 
Remove useless 'return' at end of void functions (style)

4 years agoOpenFlow: Fix a compiler error on Windows. [skip travis]
Denis Ovsienko [Mon, 28 Sep 2020 13:29:13 +0000 (14:29 +0100)] 
OpenFlow: Fix a compiler error on Windows. [skip travis]

print-openflow.c(110): error C2081: 'u_int16_t': name in formal
parameter list illegal

4 years agoOpenFlow 1.3: Add initial partial support.
Denis Ovsienko [Sun, 27 Sep 2020 22:17:56 +0000 (23:17 +0100)] 
OpenFlow 1.3: Add initial partial support.

This code processes only the simplest message types (9 out of the 30
defined).

Add a test from [1], which comes from [2], which comes from a
contributor in Ericsson (Zoltán Lajos Kis).

1: https://wiki.wireshark.org/SampleCaptures#OpenFlow
2: https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9283

4 years agoOpenFlow: Improve the common header dissection.
Denis Ovsienko [Sun, 27 Sep 2020 22:07:40 +0000 (23:07 +0100)] 
OpenFlow: Improve the common header dissection.

of_header_print() printed any version as "unknown", always printed the
type in hex only and printed the length with no remarks. If the header
was not good enough to proceed, openflow_print() would just print
"(invalid)" after it and be done with it.

Introduce of10_msgtype_str(). Rename of10_header_body_print() to
of10_message_print() and unburden it of all common header details. Add a
registry of all known OpenFlow version numbers. Merge of_header_print()
into openflow_print() and take the header apart one field at a time with
the captured and the declared lengths in mind, and indicate any anomalies
in version, type and length independently. Try to print the transaction
ID too before giving up on the header.

Among other changes, the header now shows the type as "unknown" when the
decoder does not know which types are valid for the version, and as
"invalid" when the type is definitely not valid for the version. Update
two tests.

4 years agoOpenFlow: Rename and move a function.
Denis Ovsienko [Sat, 26 Sep 2020 21:54:23 +0000 (22:54 +0100)] 
OpenFlow: Rename and move a function.

Rename of10_data_print() to of_data_print(), move it to print-openflow.c
and declare it in openflow.h.

4 years agoOpenFlow 1.0: Rewrite of10_error_print().
Denis Ovsienko [Sat, 26 Sep 2020 21:49:59 +0000 (22:49 +0100)] 
OpenFlow 1.0: Rewrite of10_error_print().

Replace a sequence of ternary operators with an array, lose empty_str[].

4 years agoOpenFlow 1.0: Update of10_header_body_print().
Denis Ovsienko [Sat, 26 Sep 2020 21:41:10 +0000 (22:41 +0100)] 
OpenFlow 1.0: Update of10_header_body_print().

Fix a field name for OFPT_QUEUE_GET_CONFIG_REQUEST and
OFPT_QUEUE_GET_CONFIG_REPLY. Update the tests. Use break instead of goto
inside the switch block and lose a label.

4 years agoRename nd_trunc() to nd_trunc_longjmp().
Denis Ovsienko [Sun, 27 Sep 2020 20:48:16 +0000 (21:48 +0100)] 
Rename nd_trunc() to nd_trunc_longjmp().

4 years agoIntroduce and use ND_LONGJMP_FROM_TCHECK.
Denis Ovsienko [Sun, 27 Sep 2020 20:43:16 +0000 (21:43 +0100)] 
Introduce and use ND_LONGJMP_FROM_TCHECK.

Apply this to the 4 the recently converted protocols.

HOW TO USE:

Define this in a print-*.c file before including netdissect.h to make
all its ND_TCHECK*() instances longjmp(). Only do this after verifying
that every ND_TCHECK*() in the file is correct and that in every
possible case it is safe to call longjmp() without incurring resource
leaks or any other problems. If it is not safe or feasible to convert
whole file, consider converting one function at a time.

4 years agoOpenFlow: Add an overshoot guard back.
Denis Ovsienko [Sun, 27 Sep 2020 19:24:13 +0000 (20:24 +0100)] 
OpenFlow: Add an overshoot guard back.

In openflow_print() terminate the loop if the downstream code managed
to run off the TCP payload end without running off the packet buffer
end (that's how the pointers worked before commit ad69daa2, but I got
the recent conversion to a decrementing unsigned length wrong in commit
4e2e9c24). Expand the comment further.

Declare OF_HEADER_FIXLEN as unsigned to squelch a signedness warning.

4 years agoAoE: Fix aoev1_issue_print(). [skip ci]
Denis Ovsienko [Thu, 24 Sep 2020 23:37:13 +0000 (00:37 +0100)] 
AoE: Fix aoev1_issue_print(). [skip ci]

Since commit 215c14cb len is decreasing as cp is increasing, get that
right.

4 years agoOpenFlow: Modernize packet parsing style.
Denis Ovsienko [Wed, 23 Sep 2020 16:02:44 +0000 (17:02 +0100)] 
OpenFlow: Modernize packet parsing style.

Most OpenFlow functions operated on the (cp, ep, len) tuple, returned a
pointer to tell the calling function where to decode next (which was not
a good idea because the calling functions had the values of cp and len in
the first place) and set the pointer to ep to indicate truncated data.
Change them to use the (cp, len) tuple, to be void and to use nd_trunc().
Update the header comment to explain this new convention.

Now if a low-level function gets an offset wrong, as in the bug recently
fixed in of10_queue_props_print(), and manages to return, the error will
not propagate into the calling function, which will be able to continue
the decoding.

Since cp does not have to be current anymore when the [void] function
returns, remove a number of cp increments just before the return.
Introduce OF_FWD(), which modifies both cp and len in sync, and
OF_CHK_FWD(), which also does a bounds check, and use these macros
instead of incrementing cp directly in every function that has both cp
and len arguments. Update the code to account for len that is
decrementing as cp is incrementing.

Commit ad69daa2 was fine for its time, but the introduction of the GET
macros had made it obsolete. Instead of reintroducing ep back merge
of_header_body_print() into openflow_print() to simplify the handling of
pointers, sizes and error conditions, all in the style above.

While at it, subtract OF_HEADER_FIXLEN from the declared OpenFlow message
length before passing it to of10_header_body_print() and make the latter
the only function that has to know about the common header size (clarify
it in the comment). This and the sufficiently current cp and len
disencumber the following functions of type-specific length calculations:
of10_features_reply_print(), of10_flow_mod_print(),
of10_stats_request_print(), of10_stats_reply_print(),
of10_packet_out_print(), of10_packet_in_print() and of10_error_print().

The resulting code in most cases addresses the not yet processed part of
the declared structure with just cp and len: nextfunc(ndo, cp, len) and
ND_TCHECK_LEN(cp, len) do the right thing regardless of how far the
current decoder has made it into the current structure. This makes all
the cp0 and len0 snapshot variables obsolete, so remove them too.

Update a test case output: the missing closing quote now correctly means
that the snapshot end is inside the "data" field of a BSN_SHELL_COMMAND
vendor message, not after it.

4 years agoOpenFlow 1.0: Refine bounds checking.
Denis Ovsienko [Wed, 23 Sep 2020 12:43:59 +0000 (13:43 +0100)] 
OpenFlow 1.0: Refine bounds checking.

In of10_data_print() make an existing pre-ndo_vflag ND_TCHECK_LEN() call
conditional to let hex_and_ascii_print() print the data that is within
the packet buffer.

In of10_packet_data_print() make an existing post-ndo_vflag
ND_TCHECK_LEN() call conditional to make bounds checks complete for the
current message if it is an early return and to let ether_print() print
the data that is within the packet buffer if it is not.

In of10_match_print() make an existing ND_TCHECK_2() call conditional
with a comment.

In of10_actions_print() add a conditional ND_TCHECK_2() call to have the
final OFPAT_OUTPUT action bounds fully checked even if it is not fully
decoded.

Lose a few ND_TCHECK calls on padding that is followed by an eventual
unconditional bounds check within the same structure/iteration.

Add a number of comments to tell that a bounds check (or an absence
thereof) is intentional.

4 years agoOpenFlow: Reorganize the length macros. [skip ci]
Denis Ovsienko [Wed, 23 Sep 2020 11:00:00 +0000 (12:00 +0100)] 
OpenFlow: Reorganize the length macros. [skip ci]

Lose unused items, lose _HEADER_ in all names except the common OpenFlow
header, always spell _REQUEST_ and _REPLY_ where they belong, spell
either _MINLEN or _FIXLEN everywhere. Denote the 2 mock octets once
again.

4 years agoOpenFlow 1.0: Fix queue properties decoding.
Denis Ovsienko [Wed, 23 Sep 2020 10:16:59 +0000 (11:16 +0100)] 
OpenFlow 1.0: Fix queue properties decoding.

In of10_queue_props_print() the "skip" branch tested and skipped 4 bytes
too many, so a malformed queue property would likely result in an odd
truncation or incorrect decoding of subsequent data (this is based on
code analysis only).

Get the offset and the size right and add a comment to explain it. Add
and update other comments to clarify a few similar subtleties that are
easy to get wrong.

4 years agoOpenFlow 1.0: Fix a few minor issues. [skip ci]
Denis Ovsienko [Wed, 23 Sep 2020 09:29:41 +0000 (10:29 +0100)] 
OpenFlow 1.0: Fix a few minor issues. [skip ci]

Update the specification URL. Reduce scope of some variables. Squelch a
cppcheck warning:

[print-openflow-1.0.c:732]: (style) Clarify calculation precedence for
'&' and '?'.

4 years agoLLDP: Replace some magic numbers
Francois-Xavier Le Bail [Thu, 24 Sep 2020 14:07:12 +0000 (16:07 +0200)] 
LLDP: Replace some magic numbers

4 years agoSUNRPC: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 18:06:21 +0000 (20:06 +0200)] 
SUNRPC: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoRemove a now inaccurate comment
Francois-Xavier Le Bail [Wed, 23 Sep 2020 17:45:52 +0000 (19:45 +0200)] 
Remove a now inaccurate comment

ipaddr_string() is no more a macro.

[skip ci]

4 years agoLLDP: Remove two now inaccurate comments
Francois-Xavier Le Bail [Wed, 23 Sep 2020 17:36:46 +0000 (19:36 +0200)] 
LLDP: Remove two now inaccurate comments

ipaddr_string() and ip6addr_string() are functions now.

[skip ci]

4 years agoSCTP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 15:17:08 +0000 (17:17 +0200)] 
SCTP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoPGM: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 15:07:49 +0000 (17:07 +0200)] 
PGM: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoDCCP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 14:46:30 +0000 (16:46 +0200)] 
DCCP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoUDP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 14:40:13 +0000 (16:40 +0200)] 
UDP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoTCP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls
Francois-Xavier Le Bail [Wed, 23 Sep 2020 14:28:52 +0000 (16:28 +0200)] 
TCP: Use GET_IPADDR_STRING()/GET_IP6ADDR_STRING() calls

Replace the calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

4 years agoUpdate for messages and TLVs defined in RFC4388
Bill Fenner [Tue, 15 Sep 2020 03:16:14 +0000 (20:16 -0700)] 
Update for messages and TLVs defined in RFC4388

4 years agoLSP ping: Fix testing of TimeStamp Received.
Denis Ovsienko [Sun, 20 Sep 2020 15:07:19 +0000 (16:07 +0100)] 
LSP ping: Fix testing of TimeStamp Received.

"(int_part != 0) && (fraction != 0)" matches a value that has both
seconds and seconds fraction set to a non-zero value, hence it leaves
zero seconds (0.123) and exact seconds (123.0) out. This bug originates
in commit d1b0faed from 2004.

Fix the expression and update a test that, although prints its only
Receiver Timestamp as 0.000000000, in fact has seconds set to 0 and
seconds fraction set to 2.

4 years agoUpdate LSP ping: timestamps are NTP int+fraction
Bill Fenner [Fri, 18 Sep 2020 02:01:01 +0000 (19:01 -0700)] 
Update LSP ping: timestamps are NTP int+fraction

During development of LSP ping, the embedded timestamps were
changed from struct timeval to NTP time, so update the printer
to match the RFC.

(Cherry-picked from GH #874.)

4 years agoIP: Revert the commit 38b7ae42 and partially the commit aad6ac30
Francois-Xavier Le Bail [Sun, 20 Sep 2020 14:43:19 +0000 (16:43 +0200)] 
IP: Revert the commit 38b7ae42 and partially the commit aad6ac30

Add back a ND_TCHECK_4() call to print the IP source and destination
addresses in truncation cases.

Add a comment to explain why the ND_TCHECK_4 is needed.

4 years agoIP: Update ip_printroute() to a void function
Francois-Xavier Le Bail [Sun, 20 Sep 2020 13:25:43 +0000 (15:25 +0200)] 
IP: Update ip_printroute() to a void function

The function no more return in case of truncation (longjmp() because
no more ND_TCHECK_4()).

This is a follow-up to commit aad6ac30.

4 years agoIP: Replace a magic number in the timestamp option processing
Francois-Xavier Le Bail [Sun, 20 Sep 2020 11:50:39 +0000 (13:50 +0200)] 
IP: Replace a magic number in the timestamp option processing

Remove the '2' value case absent from RFC 781.
Remove a comment.

4 years agoOpenFlow 1.0: Lose 4 more ND_TCHECK_LEN() calls.
Denis Ovsienko [Sat, 19 Sep 2020 01:24:12 +0000 (02:24 +0100)] 
OpenFlow 1.0: Lose 4 more ND_TCHECK_LEN() calls.

ND_TCHECK_LEN() just before an unconditional GET_ETHERADDR_STRING() is
excess. ND_TCHECK_LEN() just before a conditional GET_ETHERADDR_STRING()
can be removed where there is a subsequent unconditional GET_ call (this
is not specific to GET_ETHERADDR_STRING(), for example, unconditional
fetch of "dl_type" makes sure that it is safe to have the fetch of
"dl_vlan_pcp" conditional).

4 years agoUse MAC_ADDR_LEN in a few more places. [skip ci]
Denis Ovsienko [Sat, 19 Sep 2020 00:44:59 +0000 (01:44 +0100)] 
Use MAC_ADDR_LEN in a few more places. [skip ci]

4 years agoLoopback/CTP: Fixup loopback_print() declaration. [skip ci]
Denis Ovsienko [Fri, 18 Sep 2020 23:54:41 +0000 (00:54 +0100)] 
Loopback/CTP: Fixup loopback_print() declaration. [skip ci]

4 years agoAHCP: Modernize packet parsing style.
Denis Ovsienko [Fri, 18 Sep 2020 23:50:40 +0000 (00:50 +0100)] 
AHCP: Modernize packet parsing style.

Similarly to earlier commits, follow up from commit 19b51ded and make
changes along the same lines. Also make all functions void, lose a few
excess ND_TCHECK_LEN() instances, update comments, reduce scope for a
couple variables, rearrange some line breaks and call ND_TCHECK_LEN()
for unknown protocol versions.

4 years agoLSP ping: Put the RFC number right. [skip ci]
Denis Ovsienko [Fri, 18 Sep 2020 20:21:08 +0000 (21:21 +0100)] 
LSP ping: Put the RFC number right. [skip ci]

4 years agoAoE: Modernize packet parsing style.
Denis Ovsienko [Fri, 18 Sep 2020 03:05:04 +0000 (04:05 +0100)] 
AoE: Modernize packet parsing style.

Similarly to the previous commit, follow up from commit 5d938abe and
simplify the pointer and size arithmetics. Lose a ND_TCHECK_LEN() before
nd_printn() so the latter can print as much of the counted string as
possible. Use nd_trunc().

4 years agoLoopback/CTP: Modernize packet parsing style.
Denis Ovsienko [Fri, 18 Sep 2020 01:27:43 +0000 (02:27 +0100)] 
Loopback/CTP: Modernize packet parsing style.

The change made in commit bdd97f54 was safe, but was slightly incorrect.

Before the change the decoder used the _declared_ end of packet (the
initial "cp" + the initial "len") as the target of how much data to try
to decode, and whilst trying to do that it could cross the _captured_ end
of packet (ndo_snapend) and give up complaining, so the output would
correctly indicate there was supposed to be more data beyond the
unexpected snapshot end.

After the change the decoder started to use the captured end of packet to
tell where the packet ends, so it would never cross ndo_snapend, but it
would interpret the packet data as if the missing part was never supposed
to be there and would thus decode truncated packets incorrectly.

In order to eliminate this space for misinterpretation, remove the "ep"
pointer and change the code both to advance "cp" and to decrease "len" as
it is going through the protocol structures, so the part of the packet
that is supposed to be present but has not been decoded yet can be
addressed by just "cp" and "len" (like it is done in many functions
elsewhere). Let the GET_ macros guard the snapshot end and use nd_trunc()
to handle the remaining ND_TCHECK_LEN() instances.

Articulate the part of the message sized by skipCount.

4 years agoTravis CI: Disable some builds in matrix because they currently fail
Francois-Xavier Le Bail [Fri, 18 Sep 2020 18:30:42 +0000 (20:30 +0200)] 
Travis CI: Disable some builds in matrix because they currently fail

The 'BUILD_LIBPCAP=yes CMAKE=yes' builds currently fail.

See:
https://lists.sandelman.ca/pipermail/tcpdump-workers/2020-September/001512.html

4 years agoUse a switch to manage the setjmp() return values
Francois-Xavier Le Bail [Fri, 18 Sep 2020 11:17:39 +0000 (13:17 +0200)] 
Use a switch to manage the setjmp() return values

Also rename 'ndo_truncated' to 'ndo_early_end'.

The current case (truncated packet) uses ND_TRUNCATED value.

Prepare to add other cases when the current packet cannot be processed
any more ('Invalid' cases, etc.).

4 years agoIntroduce and use nd_trunc(). [skip ci]
Denis Ovsienko [Wed, 16 Sep 2020 22:46:20 +0000 (23:46 +0100)] 
Introduce and use nd_trunc(). [skip ci]

This new function is a part of item 2 of the longjmp() conversion plan
Francois-Xavier proposed on tcpdump-workers. As a noreturn function, it
can fit uniformly at the end of any decoder function, regardless if void
or not, for example:

const u_char *
something_print (netdissect_options *ndo, const u_char *cp, u_int len)
{
  /* (some normal decoding) */
  ND_TCHECK_2(cp);
  /* (some more normal decoding) */
  return cp + len;

trunc:
  nd_trunc(ndo);
  /* The compiler does not warn about a missing return. */
}

4 years agoOpenFlow 1.0: Lose 7 ND_TCHECK_LEN() calls.
Denis Ovsienko [Wed, 16 Sep 2020 00:38:07 +0000 (01:38 +0100)] 
OpenFlow 1.0: Lose 7 ND_TCHECK_LEN() calls.

Considering a protocol field that has a known size and contains a
zero-padded string, in a code of this particular form:

ND_TCHECK_LEN(field_start, field_length);
nd_print(ndo, field_start, field_start + field_length);

...the only effect of the ND_TCHECK_LEN() call is that when the protocol
field is not entirely within the packet buffer, the code before
triggering a longjmp() prints nothing instead of printing the part of
the field that is within the packet buffer. Thus remove these instances
of ND_TCHECK_LEN(), so the output better represents the captured data.

4 years agoWB: Reorder printing of wb-id messages.
Denis Ovsienko [Tue, 15 Sep 2020 14:53:08 +0000 (15:53 +0100)] 
WB: Reorder printing of wb-id messages.

As struct pkt_id informally notes it, the site name string follows
"seqptr's", which is a sequence of zero or more (as encoded in the "nid"
field) struct id_off items. Try to print the string after trying to
print the sequence, so the output makes as much sense as possible for
truncated packets. Also remove one ND_TTEST_LEN() before a nd_print() so
the latter prints as much data as is available and deals with the
snapshot end.

While at it, rename and retype a pointer for clarity and lose two excess
type casts, also add a length sanity check.

4 years agoAdd more "-v" detail to tcpdump(1) for GH #380. [skip ci]
Denis Ovsienko [Tue, 15 Sep 2020 10:54:18 +0000 (11:54 +0100)] 
Add more "-v" detail to tcpdump(1) for GH #380. [skip ci]

Capture what Guy has figured out so far.

4 years agoLose a forward declaration in print-ascii.c. [skip ci]
Denis Ovsienko [Sun, 13 Sep 2020 21:53:50 +0000 (22:53 +0100)] 
Lose a forward declaration in print-ascii.c. [skip ci]

4 years agoLose underscores in some macro names. [skip ci]
Denis Ovsienko [Sun, 13 Sep 2020 15:06:43 +0000 (16:06 +0100)] 
Lose underscores in some macro names. [skip ci]

4 years agoRemove a useless comment
Francois-Xavier Le Bail [Sat, 12 Sep 2020 12:06:11 +0000 (14:06 +0200)] 
Remove a useless comment

The tags file generated by Exuberant Ctags is the same after this change.

[skip ci]

4 years agoOpenFlow 1.0: Fixup some indentation. [skip ci]
Denis Ovsienko [Fri, 11 Sep 2020 20:14:40 +0000 (21:14 +0100)] 
OpenFlow 1.0: Fixup some indentation. [skip ci]

In this file an ASCII tab character means "one level of indentation,
whatever amount of whitespace an editor uses to _display_ it", and a
sequence of several spaces means "exactly this many spaces". Sometimes
they are mixed together for a specific purpose, which is easy to see in
conditional complex print statements: the ND_PRINT() line is one more
level of indentation deeper than the if(), and the wrapped remainder in
addition to that is as many spaces deeper as necessary to align with the
first argument. It is not the simplest thing to explain, but easy to see
how it works in the actual code.

Wrap and unwrap some lines to accommodate the code churn, assuming that
one level of indentation is worth at most 8 positions and that most lines
should look at most 80 characters long unless there is a good reason to
keep them longer.

4 years agoRevert partially the commit 21b1273
Francois-Xavier Le Bail [Fri, 11 Sep 2020 08:05:43 +0000 (10:05 +0200)] 
Revert partially the commit 21b1273

This change add back 4 ND_TCHECK_n() because their removal may be unsafe.
(via Denis comment)

4 years agoRT6: Remove one more redundant ND_TCHECK_1() call
Francois-Xavier Le Bail [Thu, 10 Sep 2020 15:37:28 +0000 (17:37 +0200)] 
RT6: Remove one more redundant ND_TCHECK_1() call

GET_U_1() is used.

4 years agoRT6: Print [Deprecated] for type 0 (RFC 5095)
Francois-Xavier Le Bail [Thu, 10 Sep 2020 15:23:11 +0000 (17:23 +0200)] 
RT6: Print [Deprecated] for type 0 (RFC 5095)

4 years agoRT6: Update some printings for coherency
Francois-Xavier Le Bail [Thu, 10 Sep 2020 13:49:09 +0000 (15:49 +0200)] 
RT6: Update some printings for coherency

s/srcrt/RT6/
In upper case (like 'IP6'), via a nd_print_protocol_caps() call.

Before: srcrt (len=48, type=0, segleft=48 [|rt6]
After:  RT6 (len=48, type=0, segleft=48 [|rt6]

rt6 choosen because it's in file name (print-rt6.c), function name
(rt6_print) and set in ndo->ndo_protocol ("rt6").

Moreover:
Print the protocol name even if the packet is truncated at the beginning.
Use nd_print_trunc().

4 years agoMake version and usage printing more consistent. [skip ci]
Denis Ovsienko [Thu, 10 Sep 2020 14:01:53 +0000 (15:01 +0100)] 
Make version and usage printing more consistent. [skip ci]

When there is an error, print to stderr and exit with a non-0 status.
Otherwise print to stdout and exit with a status 0. See also tcpslice
commit 5015245.

4 years agoRemove 15 now redundant ND_TCHECK_n() calls
Francois-Xavier Le Bail [Thu, 10 Sep 2020 11:24:28 +0000 (13:24 +0200)] 
Remove 15 now redundant ND_TCHECK_n() calls

ND_TCHECK_n(e).

They are redundant because they are followed by a GET_.*_n(e) call,
same n, same e, which do the bounds check.

Remove unused 'trunc' label(s) and most associated code(s).

4 years agoInstall into bindir, not sbindir. [skip ci]
Denis Ovsienko [Thu, 10 Sep 2020 11:54:41 +0000 (12:54 +0100)] 
Install into bindir, not sbindir. [skip ci]

As discussed on GitHub and on the mailing list, install tcpdump into
bindir because it can be useful to non-root users too, in ways that do
not involve doing live packet captures. Original idea by Guy Harris.

4 years agoForCES: Remove 12 more ND_TCHECK calls.
Denis Ovsienko [Thu, 10 Sep 2020 02:44:44 +0000 (03:44 +0100)] 
ForCES: Remove 12 more ND_TCHECK calls.

Remove ND_TCHECK_SIZE() immediately before two GET_BE_U_2() calls that
together fully cover a struct forces_tlv.

Ditto before two GET_BE_U_4() calls and a struct forces_ilv.

Remove ND_TCHECK_SIZE() immediately before ilv_valid(), which always
checks that forces_ilv->length is within bounds, which implies that
forces_ilv->type is also within bounds, which means the whole 8-byte
structure is within bounds.

Ditto before GET_BE_U_2() on the length field of a struct forces_tlv.

4 years agoRemove 7 more ND_TCHECK calls.
Denis Ovsienko [Tue, 8 Sep 2020 15:16:38 +0000 (16:16 +0100)] 
Remove 7 more ND_TCHECK calls.

4 years agoPIM: Remove an out-of-date comment. [skip ci]
Denis Ovsienko [Tue, 8 Sep 2020 15:07:38 +0000 (16:07 +0100)] 
PIM: Remove an out-of-date comment. [skip ci]

Speaking of struct pim, pim_print() indeed looks only into pim_typever,
but pimv2_print() among many other things covers the whole structure.

4 years agoAdd more entries to .mailmap. [skip ci]
Denis Ovsienko [Tue, 8 Sep 2020 14:59:53 +0000 (15:59 +0100)] 
Add more entries to .mailmap. [skip ci]

This revision covers all the commits generated with cvs2git in 2009 plus
one git author.

4 years agoRemove a now redundant ND_TCHECK_LEN() call
Francois-Xavier Le Bail [Tue, 8 Sep 2020 07:44:13 +0000 (09:44 +0200)] 
Remove a now redundant ND_TCHECK_LEN() call

It is redundant because it is followed by a GET_IPADDR_STRING().

4 years agoRemove some now redundant ND_TCHECK_LEN(e, sizeof(nd_ipv4)) calls
Francois-Xavier Le Bail [Mon, 7 Sep 2020 09:22:49 +0000 (11:22 +0200)] 
Remove some now redundant ND_TCHECK_LEN(e, sizeof(nd_ipv4)) calls

They are redundant because they are followed by a GET_IPADDR_STRING(e)
call, same e, which do the bounds check.

Remove unused 'trunc' label(s) and associated code(s).

4 years agoRemove some now redundant ND_TCHECK_4() calls
Francois-Xavier Le Bail [Sat, 5 Sep 2020 19:56:50 +0000 (21:56 +0200)] 
Remove some now redundant ND_TCHECK_4() calls

ND_TCHECK_4(e).

They are redundant because they are followed by a GET_IPADDR_STRING(e)
call, same e, which do the bounds check.

Remove unused 'trunc' labels and associated codes.

Update the output of a test accordingly.

4 years agoRemove a now redundant ND_TCHECK_LEN() call
Francois-Xavier Le Bail [Tue, 8 Sep 2020 10:01:28 +0000 (12:01 +0200)] 
Remove a now redundant ND_TCHECK_LEN() call

It is redundant because it is followed by a GET_IP6ADDR_STRING().

4 years agoFR: Fix a typo in a comment.
Denis Ovsienko [Tue, 8 Sep 2020 04:10:20 +0000 (05:10 +0100)] 
FR: Fix a typo in a comment.

4 years agoRemove 96 assorted ND_TCHECK calls.
Denis Ovsienko [Tue, 8 Sep 2020 04:04:58 +0000 (05:04 +0100)] 
Remove 96 assorted ND_TCHECK calls.

Remove a number of instances that do not match common patterns and have
the only substantial effect on the code flow that a truncated packet
triggers "goto trunc" instead of longjmp(). (In a few cases this change
can increase the number of fields printed before giving up.)

4 years agoRemove some now redundant ND_TCHECK_LEN(e, sizeof(nd_ipv6)) calls
Francois-Xavier Le Bail [Sat, 5 Sep 2020 21:25:16 +0000 (23:25 +0200)] 
Remove some now redundant ND_TCHECK_LEN(e, sizeof(nd_ipv6)) calls

They are redundant because they are followed by a GET_IP6ADDR_STRING(e)
call, same e, which do the bounds check.

Remove unused 'trunc' label(s) and associated code(s).

4 years agoRemove some now redundant ND_TCHECK_16() calls
Francois-Xavier Le Bail [Sat, 5 Sep 2020 19:40:32 +0000 (21:40 +0200)] 
Remove some now redundant ND_TCHECK_16() calls

ND_TCHECK_16(e).

They are redundant because they are followed by a GET_IP6ADDR_STRING(e)
call, same e, which do the bounds check.

4 years agoBGP: Add two comments
Francois-Xavier Le Bail [Mon, 7 Sep 2020 10:14:57 +0000 (12:14 +0200)] 
BGP: Add two comments

4 years agoApple IPoIEEE1394: Use a GET_LINKADDR_STRING() call
Francois-Xavier Le Bail [Mon, 7 Sep 2020 09:44:29 +0000 (11:44 +0200)] 
Apple IPoIEEE1394: Use a GET_LINKADDR_STRING() call

GET_LINKADDR_STRING do the bounds check.

4 years agoRemove now unused 'tests/TESTonce'
Francois-Xavier Le Bail [Sun, 6 Sep 2020 19:35:49 +0000 (21:35 +0200)] 
Remove now unused 'tests/TESTonce'

Update a comment.

4 years agoRemove many (762) now redundant ND_TCHECK_n() calls
Francois-Xavier Le Bail [Sat, 5 Sep 2020 17:40:32 +0000 (19:40 +0200)] 
Remove many (762) now redundant ND_TCHECK_n() calls

ND_TCHECK_n(e), n in { 1, 2, 3, 4, 8 }.

They are redundant because they are followed by a GET_.*_n(e) call,
same n, same e, which do the bounds check.

Remove unused 'trunc' labels and most associated codes.

Update the outputs of some tests accordingly.

4 years agoCirrus CI: Fix the FreeBSD 13 task. [skip travis] [skip appveyor]
Denis Ovsienko [Thu, 3 Sep 2020 13:25:53 +0000 (14:25 +0100)] 
Cirrus CI: Fix the FreeBSD 13 task. [skip travis] [skip appveyor]

Use FreeBSD 11.4-RELEASE and 12.1-RELEASE instead of 11.3-CURRENT and
12.1-CURRENT, this allows to drop "pkg update -f", which was a
workaround for 11.3-CURRENT (see commit 96c4db3), and which had later
broken in 13.0-CURRENT. Relates to cirruslabs/cirrus-ci-docs#695.

4 years agoAdd a .mailmap file. [skip ci]
Denis Ovsienko [Wed, 2 Sep 2020 13:27:34 +0000 (14:27 +0100)] 
Add a .mailmap file. [skip ci]

This first revision is loosely based on the output of
  git log | grep -E '^Author: ' | sort -u
and some heuristics. It does not cover every case, but it results in
more consistent output from "git blame" and "git log --use-mailmap".

4 years agoRADIUS: Update and comment registry arrays. [skip ci]
Denis Ovsienko [Tue, 1 Sep 2020 14:14:44 +0000 (15:14 +0100)] 
RADIUS: Update and comment registry arrays. [skip ci]

Add missing values, IANA registry URLs and some rulers. This change does
not change any tests or substantial code.

4 years agoUse more the nd_print_trunc() function
Francois-Xavier Le Bail [Mon, 31 Aug 2020 19:57:45 +0000 (21:57 +0200)] 
Use more the nd_print_trunc() function

4 years agoReport periodic stats only when safe to do so. [skip ci]
Denis Ovsienko [Sat, 29 Aug 2020 01:48:07 +0000 (02:48 +0100)] 
Report periodic stats only when safe to do so. [skip ci]

As explained in GH #155, when tcpdump is given -r, -w and -v and it
takes long enough to read from the input file (because it is stdin
connected through network or a pipe to stdout of another tcpdump doing
a live capture), pcap_loop() will error before long. One of the ways to
reproduce the fault is as follows:

$ tcpdump -i eno1 -w - | tcpdump -r - -w /tmp/tmp.pcap -v
tcpdump: listening on eno1, link-type EN10MB (Ethernet), snapshot length 262144 bytes
reading from file -, link-type EN10MB (Ethernet), snapshot length 262144
tcpdump: pcap_loop: error reading dump file: Interrupted system call

Skip the verbose_stats_dump() timer setup in this specific corner case
for the time being and document it.

4 years agoRADIUS: Redo the RFC 5580 test for Solaris. [skip ci]
Denis Ovsienko [Thu, 27 Aug 2020 22:04:49 +0000 (23:04 +0100)] 
RADIUS: Redo the RFC 5580 test for Solaris. [skip ci]

The file tests/RADIUS-RFC5580.pcap had all NTP timestamps set to
0x01234567.89abcdef seconds since year 1900, which on Linux and FreeBSD
produced "19088743.537777777 (1900-08-09T22:25:43Z)", but on Solaris 10
produced "(unrepresentable)". Increment Sighting Time by 120 nominal
years worth of seconds and make Time-to-Live and Retention Expires 12
and 48 hours later respectively.

4 years agoRADIUS: Fixup the previous commit. 706/head
Denis Ovsienko [Thu, 27 Aug 2020 12:48:08 +0000 (13:48 +0100)] 
RADIUS: Fixup the previous commit.

Use GET_ macros and C99 uint types. Use nd_printn() to print RADIUS
strings, which are not NUL-terminated (see RFC 2865 page 25). Use
p_ntp_time() to print NTP timestamps. In print_attr_location_data() print
the Location field as hex and add a comment to explain why. In
print_basic_location_policy_rules() display any non-zero MBZ bits in the
Flags field. Make output format more consistent. Update the test case.

4 years agoRADIUS: Add attributes from RFC5580. (GH #706)
Herwin Weststrate [Tue, 2 Oct 2018 18:17:42 +0000 (20:17 +0200)] 
RADIUS: Add attributes from RFC5580. (GH #706)

4 years agoRename min() and max() to ND_MIN() and ND_MAX(). [skip ci]
Denis Ovsienko [Mon, 24 Aug 2020 20:53:58 +0000 (21:53 +0100)] 
Rename min() and max() to ND_MIN() and ND_MAX(). [skip ci]

As discussed on tcpdump-workers, it was a place for a potential clash
with non-macros.

4 years agoFixup some letter case in the man page. [skip ci]
Denis Ovsienko [Sat, 22 Aug 2020 00:49:57 +0000 (01:49 +0100)] 
Fixup some letter case in the man page. [skip ci]

4 years agoCirrus CI: Allow FreeBSD 13 task to fail.
Denis Ovsienko [Fri, 21 Aug 2020 17:27:02 +0000 (18:27 +0100)] 
Cirrus CI: Allow FreeBSD 13 task to fail.

Implement the workaround suggested in cirruslabs/cirrus-ci-docs#695.

[skip ci]

4 years agoCirrus CI: Align with Travis CI config more.
Denis Ovsienko [Wed, 19 Aug 2020 00:40:03 +0000 (01:40 +0100)] 
Cirrus CI: Align with Travis CI config more.

Define MAKEFLAGS, move comments to the end of respective lines, run
"make install" and "make releasetar".

[skip ci]

4 years agoRemove an inexistant URL
Francois-Xavier Le Bail [Mon, 19 Aug 2019 14:06:10 +0000 (16:06 +0200)] 
Remove an inexistant URL

4 years agoBGP: Address a -Wformat-truncation= compiler warning
Francois-Xavier Le Bail [Fri, 14 Aug 2020 15:22:15 +0000 (17:22 +0200)] 
BGP: Address a -Wformat-truncation= compiler warning

The warning was:
./print-bgp.c: In function 'bgp_vpn_rd_print':
./print-bgp.c:797:65: warning: '%u' directive output may be truncated
writing between 1 and 3 bytes into a region of size between 2 and 31
[-Wformat-truncation=]
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |                                                                 ^~
./print-bgp.c:797:48: note: directive argument in the range [0, 255]
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~
./print-bgp.c:797:48: note: directive argument in the range [0, 65535]
./print-bgp.c:797:9: note: 'snprintf' output between 15 and 50 bytes
into a destination of size 41
  797 |         snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  798 |                     as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(pptr + 2)),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  799 |                     GET_BE_U_2(pptr + 6), GET_U_1(pptr + 2),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  800 |                     GET_U_1(pptr + 3), GET_U_1(pptr + 4),
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  801 |                     GET_U_1(pptr + 5), GET_BE_U_2(pptr + 6));
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4 years agoRx: Make UDP ports 16-bit to compile (GH #868).
Denis Ovsienko [Wed, 12 Aug 2020 23:59:44 +0000 (00:59 +0100)] 
Rx: Make UDP ports 16-bit to compile (GH #868).

Gisle Vanem reported that GCC 7.1 for DJGPP sees u_int and uint32_t as
two different types, hence the forward declaration for rx_cache_find()
was different from the actual function. UDP port numbers are 16-bit and
udp_print() appropriately uses uint16_t for them. Use the same type in
the downstream Rx-specific code to make things simpler and consistent.

4 years agoFix a typo
Francois-Xavier Le Bail [Mon, 10 Aug 2020 18:36:46 +0000 (20:36 +0200)] 
Fix a typo