Commit Graph

70 Commits

Author SHA1 Message Date
Francois-Xavier Le Bail
cc59ecca5c RT6: Update an error message
This change will avoid having the keyword "invalid" twice as:
(invalid length nnn) (invalid)
2023-05-15 09:44:27 +02:00
Francois-Xavier Le Bail
89b68e1a5f RT6: Print SRH TLV HMAC "reserved" field if non zero in verbose mode
reserved: MUST be 0 (MBZ).
2023-04-18 19:14:18 +02:00
Francois-Xavier Le Bail
c7fd6445c6 RT6: Declare the struct tok srh_tlv_type "static"
This should avoid error like:
./print-rt6.c:36:18: error: no previous extern declaration for
non-static variable 'srh_tlv_type' [-Werror,-Wmissing-variable-declarations]
const struct tok srh_tlv_type[] = {
                 ^
./print-rt6.c:36:7: note: declare 'static' if the variable is not
intended to be used outside of this translation unit
const struct tok srh_tlv_type[] = {
      ^
2023-04-18 18:04:49 +02:00
Francois-Xavier Le Bail
f119045227 RT6: Use a "struct tok" for the SRH TLV type
Moreover:
Factorise "ND_PRINT(", TLV-len=%u", tlv_len);"
2023-04-18 17:42:13 +02:00
giulio-sido
e69972a8ef rt6: parse TLV
Parse Type Length Values (TLV) in IPv6 Routing Header as specified by
RFC 8754 [1].

[1] https://datatracker.ietf.org/doc/html/rfc8754

Signed-off-by: Giulio Sidoretti <giulio.sidoretti@uniroma2.it>
2023-04-18 14:36:06 +02:00
Denis Ovsienko
0c0fca776b IPv6 Routing Header: Modernize packet parsing style.
Report an invalid packet as invalid with a reason, not truncated.
2020-10-17 17:55:37 +01:00
Denis Ovsienko
9169e4e194 Include <string.h> only if required. 2020-10-17 17:55:37 +01:00
Francois-Xavier Le Bail
a520beed73 RT6: Remove one more redundant ND_TCHECK_1() call
GET_U_1() is used.
2020-09-10 17:38:20 +02:00
Francois-Xavier Le Bail
706012eefc RT6: Print [Deprecated] for type 0 (RFC 5095) 2020-09-10 17:23:11 +02:00
Francois-Xavier Le Bail
8a776c2410 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().
2020-09-10 17:19:52 +02:00
Francois-Xavier Le Bail
7ae1579954 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.
2020-09-07 18:36:18 +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
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
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
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
245fa19308 RT6: Use more ND_TCHECK_n() macros, add missing bounds checks 2018-01-08 23:09:12 +01:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Ahmed Abdelsalam
9c33608cb2 Add support for IPv6 routing header type 4
IPv6 routing header type 4 is known as Segment Routing Header (SRH).
It is used by Segment Routing (SR) to steer a packet through a
controlled set of instructions, called segments. It is described in
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07

An extension is added to allow tcpdump to print SRH information.
2017-12-29 17:43:35 +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
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
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
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
Guy Harris
93493458ca ip6r0_reserved is an array of octets; extract the value from it.
dp0->ip6r0_reserved evaluates to a pointer to the first element of the
array, which is always non-null, so it doesn't test whether the *value*
of the field is non-zero.  Call EXTRACT_32BITS() on it to check whether
the value is zero.
2017-09-13 12:25:44 +01:00
Francois-Xavier Le Bail
1ead603da6 RT6: Fix alignment issue with Solaris Studio 12.3 on Solaris 10 SPARC
Fix the 'Bus Error - core dumped' issue with the 'ipv6-routing-header' test
when '-m64' compiling option is used.

Fix with the method described in commit 1376682.

/opt/solarisstudio12.3/bin/cc -V
gives:
cc: Sun C 5.12 SunOS_sparc Patch 148917-09 2016/08/02
2017-09-13 12:25:44 +01:00
Guy Harris
3c4d7c0ee3 CVE-2017-13725/IPv6 R.H.: Check for the existence of all fields before fetching them.
Don't fetch the length field from the header until after we've checked
for the existence of a field at or after that field.

(Found by code inspection, not by a capture.)
2017-09-13 12:25:44 +01:00
Francois-Xavier Le Bail
11d3a01319 Move the printer summaries from INSTALL.txt to each printer
with the tag '\summary:' for greping.
Remark: Currently some printers have no summary line.

Moreover:
Summarize all printers with a single line in INSTALL.txt
2016-08-14 17:03:43 +02:00
Guy Harris
2398aa233d Get rid of set-but-not-used variable. 2016-04-13 18:54:11 -07:00
Guy Harris
83b356e177 Don't overwrite the destination IPv6 address for routing headers.
If we have a routing header, instead of overwriting the packet's IPv6
destination address in the packet with the final destination, so that
the next protocol's checksum routine can use it, we do as we do for
IPv4, and, in the "next protocol checksum" routine, scan the headers
looking for a routing header and, if we find one, copy the final
destination from it.

While we're at it, clean up a few things.
2016-02-12 20:26:39 -08:00
Guy Harris
11f73ad248 Don't require IPv6 library support in order to support IPv6 addresses.
Have our own routines to convert between IPv4/IPv6 addresses and
strings; that helps if, for example, we want to build binary versions of
tcpdump for Windows that can run both on NT 5 (W2K/WXP), which doesn't
have inet_ntop() or inet_pton(), and NT 6 (Vista/7/8/10), which do.  It
also means that we don't require IPv6 library support on UN*X to print
addresses (if somebody wants to build tcpdump for older UN*Xes lacking
IPv6 support in the system library or in add-on libraries).

Get rid of files in the missing directory that we don't need, and
various no-longer-necessary autoconf tests.
2015-09-17 14:56:44 -07:00
Francois-Xavier Le Bail
99c91c3aec Rename 'tcpdump-stdinc.h' to 'netdissect-stdinc.h'
Get the full log via: git log --follow netdissect-stdinc.h
2015-09-10 08:50:40 +02:00
Francois-Xavier Le Bail
c1c3c77463 Printers must include 'netdissect.h', not 'interface.h' 2015-09-05 23:35:58 +02:00
Guy Harris
69cb46af91 Fix a bunch of de-constifications. 2015-04-26 17:24:42 -07:00
Denis Ovsienko
38700c7f24 dismiss NETDISSECT_REWORKED macro
The purpose of this macro was to enable the file-by-file switch to NDO,
after which only tcpdump.c had a use of it and the definitions guarded
by it. Update tcpdump.c not to require them any more and dismiss the
unused definitions.
2015-03-22 10:06:15 +00:00
Francois-Xavier Le Bail
7141a856c5 fix incorrect IPv6 UDP and ICMPv6 checksums with routing headers
- in this case the destination address used in the pseudo-header is
  that of the final destination : the last address of the routing header

- add a pcap file
2014-04-17 15:18:41 +02:00
Guy Harris
1cde6435df Netdissectify the to-name resolution routines.
Have them take a netdissect_options * argument, and get the "no name
resolution" flag from it.

Move the declaration of dnaddr_string to addrtoname.h, along with the
other XXX-to-string routines.
2014-04-04 00:43:46 -07:00
Denis Ovsienko
1fe6e66ece make use of NETDISSECT_REWORKED
Update the already converted decoders to define the macro and to include
interface.h instead of netdissect.h. Fix incurred compile errors.
2014-03-15 14:19:49 +04:00
Denis Ovsienko
ce1fc8263d NDOize more small decoders
This change converts decoders for: DLT_RAW, IPv6 routing header, USB,
Symantec firewall and cHDLC.
2014-03-12 20:02:32 +04:00
Denis Ovsienko
fe3253b9b8 remove tcpdump's own CVS keywords
Remove lots of $Header's and a few $Id's that all belong to the former
CVS repository of tcpdump itself. These keywords have been frozen since
the migration to git in late 2008.
2014-01-03 00:59:08 +04:00
guy
a4d5ec5902 Get rid of an unused variable. 2005-04-20 22:33:06 +00:00
guy
988cd2bb0e Have various routines for printing non-final headers for IPv4/IPv6
return -1 if they run out of data.

Have the IPv4 and IPv6 dissectors check for non-positive return values
from those routines and quit if they see one.
2003-11-19 00:36:06 +00:00
guy
bbc1cfa669 Have the configure script arrange that the Makefile define _U_
appropriately, and that GNUmakefile and the MSVC++ project file define
it apppriately, as we do with libpcap, rather than defining it in
"interface.h".

Undo the rcsid-shuffling and addition of extra #includes, as we no
longer need to arrange that "interface.h" be included before using _U_
in an RCS ID or copyright.
2003-11-16 09:36:07 +00:00
guy
3824a6c041 From Neil Spring:
use "_U_" in the definitions of "rcsid[]", to eliminate
	complaints about those variables being unused;

	move the definitions after the include of "interface.h", or add
	an include of "interface.h", so that "_U_" is defined.

Include "config.h" before including "tcpdump-stdinc.h" in
"missing/datalinks.c".
2003-11-15 00:39:12 +00:00
guy
c243fe7be4 From Kazushi Sugyo: update to draft-ietf-mobileip-ipv6-20. 2003-02-05 02:36:25 +00:00
guy
fcc82f451d The "__attribute__((packed))" tag on structures causes some files not to
compile with Sun C, as "interface.h" isn't being included before the
structures are being declared.

Furthermore, in the files that Sun C *can* compile, it doesn't cause Sun
C to generate code that's safe with unaligned accesses, as
"__attribute__" is defined as a do-nothing macro with compilers that
don't support it.

Therefore, we get rid of that tag on the structures to which it was
added, and instead use "EXTRACT_16BIT()" and "EXTRACT_32BIT()" to fetch
16-bit and 32-bit big-endian quantities from packets.  We also fix some
other references to multi-byte quantities to get rid of code that tries
to do unaligned loads on platforms that don't support them.

We also throw in a hack that makes those macros use
"__attribute__((packed))" on structures containing only one 16-bit or
32-bit integer to get the compiler to generate unaligned-safe code
rather than doing it by hand.  (GCC on SPARC produces the same code that
doing it by hand does; I don't know if GCC on any other big-endian
strict-alignment processor generates better code for that case.  On
little-endian processors, as "ntohs()" and "ntohl()" might be functions,
that might actually produce worse code.)

Fix some places to use "%u" rather than "%d" to print unsigned
quantities.
2002-12-11 07:13:49 +00:00
risso
3d932490b8 Added support for Win32, based on WinPcap. 2002-08-01 08:52:55 +00:00