Commit Graph

146 Commits

Author SHA1 Message Date
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
440d155f24 IPv6: Use "header+payload length" in two messages
It seems a more logical order than "payload+header".

It is not in current release 4.99.4, will be in 4.99.5.

Update some test outputs accordingly.
2024-03-04 14:05:27 +01:00
Francois-Xavier Le Bail
f6ae03e299 IPv6: Print some header fields, even if the header is incomplete
Add a test file with a 39-byte header.

Moreover:
Fix an indentation.
2023-08-27 13:28:12 +02:00
Francois-Xavier Le Bail
7830dc93c7 IPv6: Report another invalid case as invalid, not truncated
This is in the jumbo case.

When the payload+header length is > (original) length, output example:
  [payload+header length 65577 > length 65576] (invalid)

We treat this as a warning and so don't stop decoding (as before).

Add a test file.

Update two test outputs accordingly.
2023-08-26 21:36:09 +02:00
Francois-Xavier Le Bail
e570e6b04e IPv6: Report another invalid case as invalid, not truncated
When the payload+header length is > (original) length, output example:
  [payload+header length 105 > length 104] (invalid)

We treat this as a warning and so don't stop decoding (as before).

Add a test file.

Update a test output accordingly.
2023-08-26 14:10:24 +02:00
Francois-Xavier Le Bail
0a035a4380 IPv6: Use ND_ICHECKMSG_U() to print an invalid version
Update a test output accordingly.
2023-08-25 19:03:43 +02:00
Francois-Xavier Le Bail
a69b0d5618 IPv6: Report some invalid packets as invalid, not truncated
When the (original) length is < length of the header, output example:
  [length 39 < 40] (invalid)
(The IPv6 header must be 40 bytes in length.)

Place the 'length' test before the 'version' test.

Add a test file.
2023-08-25 19:03:43 +02:00
Francois-Xavier Le Bail
4da3308f27 IPv6: Print the protocol name before any test
Use nd_print_protocol_caps().
IP6_VERSION() uses GET_U_1(), so there's no need for ND_TCHECK_*()
beforehand.
2023-07-31 12:33:41 +02:00
Francois-Xavier Le Bail
bbcd77cdee IPv6: Add a check for the Jumbo Payload Hop-by-Hop option 2022-08-22 18:04:09 +02:00
Francois-Xavier Le Bail
c3e79e8c4c IPv6: Add some checks for the Hop-by-Hop Options header
The Hop-by-Hop Options header, when present, must immediately follow
the IPv6 header (RFC 8200).
2022-08-13 18:27:12 +02:00
Francois-Xavier Le Bail
7d2bc7fcb5 Fix some typos
[skip ci]
2022-07-04 14:03:15 +02:00
Guy Harris
e84f58700f Fail if nd_push_buffer() or nd_push_snaplen() fails.
Always call ndo->ndo_error with a memory-allocation error if they fail.

Add WARN_UNUSED_RESULT for compilers that support it, and use it for
those routines, so that any future code that doesn't check for failure
gets a warning.
2022-04-01 15:28:33 -07:00
Guy Harris
6a681e6a16 Have routines that set the snapend take a buffer pointer and length as args.
Have nd_push_buffer() take a snapshot length, not a snapshot end, as
its last argument.

Replace nd_push_snapend() and nd_change_snapend() with nd_push_snaplen()
and nd_change_snaplen(), both of which take a pointer into the packet
buffer and snapshot length relative to that pointer as arguments.  Have
those routines check the snapshot length to make sure it's not bigger
than the number of bytes in the packet past the pointer, and silently
ignore the requst if it is.

Using a length rather than a pointer avoids the possibility of the
calculation of the snapshot end overflowing and resulting in a snapshot
end *before* the point in the buffer.

Add a test for this, with a capture file containing an IPv6 packet with
an extremely large "jumbo" packet size.

Revert the "Make sure we don't set the snapend before the beginning of
the packet." changes, as they no longer apply with this change (which
also makes sure we don't set the snapend before the beginning of the
packet).
2022-03-31 02:29:19 -07:00
Francois-Xavier Le Bail
5830e58aa0 IPv6: Remove an obsolete code in an always-false #if wrapper
RFC 1883 is obsolete.

Moreover:
Fix indentation.
2022-01-15 14:50:01 +01:00
Denis Ovsienko
ca71c84728 Fix some spelling. [skip ci] 2020-10-09 13:19:10 +01:00
Denis Ovsienko
51e180c4fb 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.)
2020-09-08 05:04:58 +01: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
Francois-Xavier Le Bail
c995e07d30 IPv6: Fix indentation
[skip ci]
2020-04-15 15:40:10 +02:00
Francois-Xavier Le Bail
6a66f11096 IPv4/IPv6 demux: Rename a printer
Rename ip_print_demux() to ip_demux_print(), with _print suffix like
in most similar cases.

Moreover:
Rename a test.
2020-03-08 14:07:37 +01: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
Francois-Xavier Le Bail
b745735205 IPv6: Use GET_CPY_BYTES macro calls to add bounds checks 2019-09-12 15:23:43 +02:00
Francois-Xavier Le Bail
0c9cfdcb0d Use nd_ipv6 rather than struct in6_addr 2019-06-10 15:32:20 +02:00
Guy Harris
2055e39f2a Add more checks.
Check that the payload specified in a Jumbo Payload option isn't smaller
than the total number of bytes worth of extension headers; if it is,
report truncation.

Check that:

1) we don't have more than one Jumbo Payload option;
2) we don't have a Jumbo Payload option if the payload length in the
IPv6 header was non-zero;
3) we don't have a Jumbo Payload option with a value < 65536.
2019-05-03 11:11:58 -07:00
Guy Harris
db7a7633e6 Handle the IPv6 Jumbo Payload option.
If we see one when processing the hop-by-hop extension header, use it to
set the payload length.

In UDP, if we have a zero length field in the UDP header, and the length
of the data handed to us is > 65535, treat that as a Jumbo Payload
packet.
2019-05-02 20:01:08 -07:00
Guy Harris
b7b72b7c63 Treat the length field in an Ethernet header as such.
If we have an Ethernet packet where the last 2 octets of the header are
a length rather than an Ethernet type, and it's less than the remaining
length of the packet, shorten the length and captured length, update the
snapshot end.

Turn the buffer stack into a "packet information" stack, so that, if we
*do* update the snapshot end, we push the old end onto the stack, and
pop it off as soon as we're done dissecting the Ethernet packet, in case
there's more data in the packet after the Ethernet packet.

Use the stack when we use the IPv4 and IPv6 length fields as well.
2019-04-22 23:49:02 -07:00
Guy Harris
dc9744f7c6 Squelch more warnings. 2019-04-17 20:21:53 -07:00
Guy Harris
bef667db65 Clean up types to squelch narrowing warnings. 2019-04-17 19:53:00 -07:00
Ahmed Abdelsalam
a87d6a0448 Fix checksum calculation for IPv6 Segment Routing (SRv6) traffic
The checksum calculation for IPv6 packets is based on a pseudo
header that includes the packet's final Destination Address (DA).

If the IPv6 packet contains a Routing header, the final DA is the
last element of the Routing header [RFC8200].

Currently, tcpdump supports Routing header types 0 and 2.

IPv6 Segment Routing Header (SRH) is a new Routing header type (4).
SRH is defined in draft-ietf-6man-segment-routing-header [1].

This patch fix the checksum calculation for SRv6 packets. It allows
tcpdump to get the final DA value from SRv6 packets.

[1] https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-17
2019-03-29 12:04:21 +01:00
Guy Harris
202051bb55 Put IPv4/IPv6 protocol demultiplexing into a common routine.
That means less duplication of functionality - and less chance that
XXX-over-IPv4 will be handled but XXX-over-IPv6 won't be handled, or
*vice versa*.  (CARP and VRRP were being handled over IPv4 but not over
IPv6; this fixes that.)
2019-03-27 19:58:26 -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
Guy Harris
2de3a27ab7 Have all Internet-checksum computing routines return a uint16_t.
Those checksums are 16-bit; change the return types of those routines
appropriately.
2018-12-11 00:50:15 -08:00
Francois-Xavier Le Bail
6daf3a543e Add a nd_print_trunc() call
Update the output of a test accordingly.

Moreover:
Add a ndo_protocol reassignment after xxx_print() calls.
2018-05-10 21:17:35 +02: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
0ee15606e2 Remove unneeded '&' when getting a pointer to a nd_ipv6 type 2018-01-31 16:43:50 +01:00
Guy Harris
0dad1934af Have ip{6}addr_string take a u_char * as the second argument.
Fix warnings that introduces.
2018-01-31 00:43:45 -08:00
Guy Harris
3db38df8ed Use nd_ipv6 rather than struct in6_addr in packet-layout structures.
Also, use it, and nd_ipv4, in sizeof() operations.
2018-01-30 17:29:33 -08:00
Francois-Xavier Le Bail
7755951df7 RT6: Replace 'struct in6_addr' members type with a 'nd_ipv6' one
In 'struct ip6_hdr', 'struct ip6_rthdr0' and 'struct ip6_srh'.
This avoid some 'undefined-behavior' warnings with clang and option
-fsanitize=undefined enabled.

print-rt6.c:66:3: runtime error: member access within misaligned address
0x61d00001eab6 for type 'const struct ip6_rthdr0', which requires 4 byte
alignment
0x61d00001eab6: note: pointer points here
 00 00 00 04 3a 02  00 01 00 00 00 00 22 00  00 00 00 00 02 10 00 02  00 00 00 00 00 04 80 00  d3 ab
             ^
SUMMARY: AddressSanitizer: undefined-behavior print-rt6.c:66:3 in
2018-01-30 22:17:36 +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
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
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
Guy Harris
a95802aa0d Use nd_ types in the IPv6 structures.
And add the EXTRACT_U_1() calls as needed.

Change some other EXTRACT_ calls that no longer need an & operator.
2017-12-11 19:38:35 -08:00
Francois-Xavier Le Bail
3a7639e545 Use more the EXTRACT_U_1() macro (49/n)
Assignment, *(p)
2017-12-09 09:56:29 +01:00
Francois-Xavier Le Bail
451ac4c753 Use more the ND_TCHECK_1() macro 2017-12-04 21:00:57 +01:00
Francois-Xavier Le Bail
39c8c55aa9 Use more ND_TCHECK_n()/ND_TTEST_n() macros 2017-11-24 22:48:55 +01:00
Francois-Xavier Le Bail
da20bc56d6 Rename EXTRACT_ macros
Now all the macros have a name meaning a count in bytes.

With _S_: signed, _U_: unsigned

e.g.:
EXTRACT_BE_32BITS -> EXTRACT_BE_U_4
EXTRACT_LE_32BITS -> EXTRACT_LE_U_4
...
EXTRACT_BE_INT32 -> EXTRACT_BE_S_4

and have:
EXTRACT_8BITS -> EXTRACT_U_1
EXTRACT_INT8  -> EXTRACT_S_1
2017-11-22 23:54:09 +01:00
Guy Harris
c0679b38a3 More EXTRACT_8BITS() and other cleanups.
Get rid of casts to (int) that aren't needed or wanted.

If a field is unsigned, use an unsigned variable for it, print it with
%u, not %d, and don't cast it to int.

Replace a static variable in print-dvmrp.c with a local variable in
dvmrp_print() and a parameter to print_neighbors2().
2017-11-22 10:15:49 -08:00
Francois-Xavier Le Bail
577621026d Rename EXTRACT_nBITS() macros to EXTRACT_BE_nBITS()
It indicates clearly that these macros are used to extract big-endian
integral values.
2017-11-18 13:56:40 +01:00