Commit Graph

128 Commits

Author SHA1 Message Date
Bill Fenner
f5877da285 ICMPv6: print RFC8335 PROBE extended echo/reply messages
The ICMP types are different, but everything else about
PROBE, including the RFC4884-based parsing, is the same,
so we share the implementation from print-icmp.c using the
new icmp.h.
2024-08-06 07:34:48 +00:00
Francois-Xavier Le Bail
5efa821c98 ICMP: Update a variable type
The length of ip_addr can be 4 octet (IPv4 address) if Address Family
Identifier (AFI) is 1 or 16 octets (IPv6 address) if AFI is 2.
2024-07-17 10:05:39 +02:00
Bill Fenner
498f33b5eb ICMP: print RFC8335 PROBE extended echo/reply messages
Add interface name, ifindex and IP address printing for Interface
Information Object, and use the newly-refactored object printing
to print the single object included in an RFC8335 PROBE message.

Include a test with several well-formed packets, and one test
with a truncated packet (truncated packet supplied by fuzzer).
2024-07-11 15:14:47 +00:00
Francois-Xavier Le Bail
94a3708f00 Include <config.h> unconditionally
Builds using Autotools or CMake generate config.h, thus remove the
'#ifdef HAVE_CONFIG_H'/'#endif'.

Remove also the 'add_definitions(-DHAVE_CONFIG_H)' in CMakeLists.txt.
2024-03-28 05:34:34 +00:00
Francois-Xavier Le Bail
07e0b558f4 Replace '> 0' with '!= 0' in some unsigned expression tests
Unsigned is always >= 0, so '> 0' and '!= 0' are identical.

This makes the tests a little clearer.
2024-02-28 10:16:14 +01:00
Denis Ovsienko
6cf3ea7d0f Fix compiling on GNU/Hurd. [skip appveyor]
GNU/Hurd does not define MAXHOSTNAMELEN because it does not define
HOST_NAME_MAX, even if __USE_POSIX is defined.  This causes the
following:

./print-bgp.c:1997:14: error: 'MAXHOSTNAMELEN' undeclared (first use in
  this function)
./print-bgp.c:2965:14: error: 'MAXHOSTNAMELEN' undeclared (first use in
  this function)
./print-icmp.c:502:11: error: 'MAXHOSTNAMELEN' undeclared (first use in
  this function)

However, the above code should not depend on this OS-specific detail to
size its temporary printing buffers, so just hard-code the sizes.
2024-02-04 15:43:34 +00:00
Bill Fenner
4bea9a6cd7 ICMP: refactor RFC4884 object printing
For a future change, we refactor RFC4884 object printing
into its own function.  This change just moves and
reindents the lines in question.
2024-01-18 02:01:06 +00:00
Francois-Xavier Le Bail
09fd9f02b7 ICMP: Fix Interface Information Object printing
s/Interface Identification Object/Interface Information Object/
(Reference: RFC5837. Interface Identification Object is in RFC8335.)
Also in some variable names.
Use IANA name for the 'ICMP Extension Object Classes' value 2.
This implies updates to avoid printing 'Object' twice.
Use texts from RFC '7. IANA Considerations' for Interface Roles.
Fix indentations in output.

Update some test outputs accordingly.

This is a follow-up to dbf0433fef.
2023-12-19 15:32:12 +01:00
Francois-Xavier Le Bail
b97d7389c4 ICMP: Modernize packet parsing
Remove the icmp_print() unused parameter 'bp2'.
Enable ND_LONGJMP_FROM_TCHECK and remove a 'trunc' label.
Remove some redundant ND_TCHECK_*().
Reduce the scope of some variables.
Fix some indentations.
Remove some extra blank lines.
2023-12-19 12:39:38 +00:00
Francois-Xavier Le Bail
5fefba15ae ICMP: Fix an undefined behavior for the Interface Name Sub-Object
Add a test for the Interface Name Sub-Object length == 0.
If inft_name_length_field == 0, nd_printjnp() was called with
inft_name_length_field - 1 == -1.

Add a test file.

The error was:
print-icmp.c:893:37: runtime error: implicit conversion from type 'int'
of value -1 (32-bit, signed) to type 'u_int' (aka 'unsigned int')
changed the value to 4294967295 (32-bit, unsigned)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior print-icmp.c:893:37
2023-12-18 18:34:09 +01:00
Guy Harris
6d3b0e4599 icmp: clean up the extension code and comments.
Remove remaining references to them as being MPLS-related;
draft-bonica-icmp-mpls-02 referred to them as "ICMP Extensions for
MultiProtocol Label Switching", but draft-bonica-internet-icmp-00
redefined it as a general extension mechanism, not MPLS-related, and
that draft eventually became RFC 4884.

draft-bonica-icmp-mpls-02 also defined class 2 objects as objects
containing the remaining packet information past the first 128 bytes;
that never became part of an RFC and class 2 was redefined as an
"Interface Information Object" in RFC 5837.

Give some of these details in comments, and move some
extension-related definitions among the rest of the extension stuff.
2022-03-19 22:17:43 -07:00
Francois-Xavier Le Bail
38ffa92e5f ICMP: Avoid printing non-ASCII characters in Interface Name
The "%.*s" format is a risk (no non-ASCII filtering), thus use
the nd_printjnp() function.
2022-02-07 19:02:48 +01:00
Francois-Xavier Le Bail
f30baa4292 ICMP: Fix printing the Interface Name Sub-Object
RFC 5837 - 4.3.  Interface Name Sub-Object
"The Interface Name Sub-Object MUST have a length that is a multiple
 of 4 octets and MUST NOT exceed 64 octets.

 The Length field represents the length of the Interface Name Sub-
 Object, including the length and the interface name in octets."

The length of the interface name to print is: (Length field) - 1.
The offset is only: Length field

Add sanity checks: Multiple of 4 octets, <= 64 octets.

Fix the icmp-rfc5837.pcap test.
The interface name length in octets is 63, thus the length field must be 64.
Update also the ICMP Multi-Part Extensions checksum.

Keep an invalid length field in icmp-cksum-oobr-2.pcap.

Update the output of two tests accordingly.
2022-02-07 19:02:48 +01:00
Francois-Xavier Le Bail
598981696f ICMP: Print the length field of the Interface Name Sub-Object
Update the output of two tests accordingly.

Moreover:
Fix indentation.
2022-02-07 19:02:48 +01:00
Francois-Xavier Le Bail
7a5c4fb610 ICMP: Fix indentation in parsing multi-part message extensions code
Use spaces like in other lines in this part of the code.

Moreover:
Remove some blank lines.
2022-02-07 13:42:42 +01:00
a1346054
afb52045dd Remove last remaining trailing whitespace 2021-09-04 07:52:28 +00:00
Francois-Xavier Le Bail
4adf2f462d Fix spaces
[skip ci]
2021-07-13 21:05:02 +02:00
ishaangandhi
dbf0433fef Add dissector for ICMP Interface Identification Object 2021-07-13 19:02:32 +00:00
ishaangandhi
572f2e7cdf Rename MPLS Extension to Multipart Extension 2021-07-13 19:02:32 +00:00
Francois-Xavier Le Bail
a29cd3e75e ICMP: Update the snapend for some nested IP packets
Update the snapend because extensions (MPLS, ...) may be present
after the IP packet. In this case the current (outer) packet's
snapend is not what ip_print() needs to decode an IP packet nested
in the middle of an ICMP payload.

This prevents that, in ip_print(), for the nested IP packet, the
remaining length < remaining caplen.

Moreover:
Reduce the scope of a variable.
Fix spaces
2021-01-25 11:17:37 +01:00
Denis Ovsienko
c518a9aab1 ICMP: Fix a typo in a comment. 2021-01-07 01:07:46 +00:00
Bill Fenner
5081474eb5 MPLS: rename the "exp" field to "tc"
RFC5462 (https://tools.ietf.org/html/rfc5462) renamed the
MPLS "EXP" field to "Traffic Class" in 2009.  Use "tc" as an
abbreviation for this field name.
2021-01-06 08:52:44 +00:00
Francois-Xavier Le Bail
d90dda7ef6 Fix some typos
[skip ci]
2020-12-12 16:10:46 +01:00
Francois-Xavier Le Bail
21b12733b6 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).
2020-09-10 14:06:40 +02:00
Francois-Xavier Le Bail
aad6ac30ce 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.
2020-09-08 14:14:13 +02:00
Francois-Xavier Le Bail
abc8c2d61c 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.
2020-09-06 20:22:29 +02:00
Guy Harris
306c2a0384 More bounds checking when fetching addresses and converting to strings.
Replace more calls to ipaddr_string()/ip6addr_string() with calls to
GET_IPADDR_STRING()/GET_IP6ADDR_STRING() macros performing bounds
checking.

Add similar bounds-checking inline functions and macros to wrap
linkaddr_string(), etheraddr_string(), and isonsap_string() and convert
calls to them to use the macros as well.

Shuffle the inline functions in addrtoname.h around a bit, so that the
inline functions, external declarations, and macros are all in the same
order.
2020-01-19 19:55:38 -08:00
Guy Harris
1ed63b5d06 Remove more old-compiler compensation.
We require an environment with a C99-compatible snprintf(), so we don't
need to work around older implementations.  Make the configuration
process fail if we don't have snprintf() and vsnprintf().

We require at least VS 2015, so we don't have to check for _MSC_VER >=
1400.  Make the build fail if we don't have at least VS 2015.

We apparently do, however, have to use __inline, as the VS 2015
documentation doesn't meaning plain old "inline".  Update a comment.
2019-08-08 23:21:35 -07:00
Guy Harris
8c296c6278 Don't generate formats on the fly.
Some compilers warn about that, because it prevents them from doing
format checks.
2019-04-17 21:01:06 -07:00
Guy Harris
bef667db65 Clean up types to squelch narrowing warnings. 2019-04-17 19:53:00 -07:00
Francois-Xavier Le Bail
ee68aa3646 Use the new GET_ macros instead of the EXTRACT_ ones
The exceptions are currently:
Some EXTRACT_ in print-juniper.c, not used on packet buffer pointer.
An EXTRACT_BE_U_3 in addrtoname.c, not always used on packet buffer
pointer.
2019-03-26 21:06:24 +01:00
Francois-Xavier Le Bail
2b4a3e6a63 ICMP: Fix an undefined behavior at runtime
The error was:
print-icmp.c:491:13: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'u_int' (aka 'unsigned int')
2019-03-08 12:48:59 +01:00
Antonin Décimo
0b3880c91e Fix small misspellings 2019-01-23 17:28:14 +01:00
Francois-Xavier Le Bail
d880293429 Add a nd_print_trunc() call
Update the output of some tests accordingly.

Moreover:
Add a ndo_protocol reassignment after ip_print() call.
2018-05-10 20:47:44 +02:00
Francois-Xavier Le Bail
56e6581c34 Remove useless comments 2018-03-19 15:16:32 +01:00
Francois-Xavier Le Bail
546558eabd Add the ndo_protocol field in the netdissect_options structure
Update this field in printer entry functions.
It will be used for some printings.
2018-03-16 19:44:47 +01:00
Francois-Xavier Le Bail
aa9960a2c3 ICMP: Replace a 'struct in_addr' member type with a 'nd_ipv4' one
In 'struct icmp'.
This avoid some 'undefined-behavior' warnings with clang and option
-fsanitize=undefined enabled.

Moreover:
Remove unneeded '&' when getting a pointer to a nd_ipv4 type.
Fix indentation.

The warnings were like:
print-icmp.c:355:2: runtime error: member access within misaligned address
0x61d00001eabe for type 'const struct icmp', which requires 4 byte alignment
0x61d00001eabe: note: pointer points here
 ef 01 02 03 08 00  90 e1 00 03 00 00 00 00  00 00 00 05 ed 60 ab cd  ab cd ab cd ab cd ab cd  ab cd
             ^
SUMMARY: AddressSanitizer: undefined-behavior print-icmp.c:355:2 in
2018-01-30 16:38:48 +01:00
Guy Harris
c499612a7f Add nd_{v}snprintf() routines/wrappers.
Some versions of the MSVC runtime library have a non-C99-compliant
vsnprintf(), which we want to avoid.  On Windows, use snprintf() and
vsnprintf() for VS 2015 and later, where they both exist in
C99-compliant forms, and wrap _{v}snprintf_s() otherwise (they're
guaranteed to do the null termination that we want).
2018-01-29 15:48:55 -08:00
Francois-Xavier Le Bail
d7efbc8f63 ICMP: Use more ND_TCHECK_n() macros 2018-01-24 08:44:27 +01:00
Guy Harris
fb2479d733 Always include <config.h> rather than "config.h".
This can prevent bizarre failures if, for example, you've done a
configuration in the top-level source directory, leaving behind one
config.h file, and then do an out-of-tree build in another directory,
with different configuration options.  This way, we always pick up the
same config.h, in the build directory.
2018-01-21 12:27:28 -08:00
Francois-Xavier Le Bail
513f782ae1 Use quoted include netdissect-stdinc.h instead of angle-bracketed one 2018-01-21 10:28:15 +01:00
Guy Harris
64677b0d78 Clean up signed vs. unsigned. 2018-01-11 11:52:30 -08:00
Francois-Xavier Le Bail
e8ff00c320 ICMP: Use more ND_TCHECK_n() macros 2018-01-08 10:17:48 +01:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
d526e47658 Use ND_TTEST_SIZE()/ND_TCHECK_SIZE() macros (1/n) 2018-01-03 21:32:07 +01:00
Guy Harris
58f2aa4b57 Use nd_ types, clean up ICMPv6 dissection.
Use nd_ types for various packet structures, and use EXTRACT_ macros as
necessary.  Get rid of & in EXTRACT_ macros if not necessary.

The 1-byte pad RPL suboption is called PAD1, not PAD0, in the RFC.

Rename rpl_dio_printopt() to rpl_printopts() because 1) it's for all RPL
messages and 2) it prints multiple options.  Clean up its processing
loop.

Pass rpl_print() the ICMPv6 code, not a pointer to the full header; all
it needs is the code.

Use %u to print unsigned values.

In Node Information node address lists, the TTL comes before the
address, as per the RFC.  Dissect it that way.
2017-12-18 21:41:18 -08:00
Francois-Xavier Le Bail
607d4a5c33 ICMP: Replace ND_TTEST2 calls by ND_TTEST_LEN calls 2017-12-14 22:16:55 +01:00
Francois-Xavier Le Bail
5cea270318 Remove all storage class specifier 'register'
Let the compiler do the optimizations (or not) based on build options.

Avoid 'value has been optimized out' messages in gdb using '-O0'.
2017-12-13 19:17:47 +01:00
Francois-Xavier Le Bail
84ef17ac0e Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)
ND_TTEST2(var, l)  -> ND_TTEST_LEN(p, l)
ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
2017-12-11 22:11:01 +01:00
Guy Harris
3f3f2505f2 Make nd_uint8_t and nd_int8_t arrays, to catch direct references.
This catches direct references, so we can change them to use EXTRACT_U_1
or EXTRACT_S_1.

Also, change some structures to use the nd_ types that weren't already
using them.

Then make the appropriate EXTRACT_{U,S}_1() changes.
2017-12-10 16:23:34 -08:00