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.
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).
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.
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.
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.
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.
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
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.
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.
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
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.
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).
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.
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.
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.
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.
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.
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
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).
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.
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.
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.