Commit Graph

102 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
Guy Harris
b9811ef5bb ppp: use the buffer stack for the de-escaping buffer.
This both saves the buffer for freeing later and saves the packet
pointer and snapend to be restored when packet processing is complete,
even if an exception is thrown with longjmp.

This means that the hex/ASCII printing in pretty_print_packet()
processes the packet data as captured or read from the savefile, rather
than as modified by the PPP printer, so that the bounds checking is
correct.

That fixes CVE-2024-2397, which was caused by an exception being thrown
by the hex/ASCII printer (which should only happen if those routines are
called by a packet printer, not if they're called for the -X/-x/-A
flag), which jumps back to the setjmp() that surrounds the packet
printer.  Hilarity^Winfinite looping ensues.

Also, restore ndo->ndo_packetp before calling the hex/ASCII printing
routine, in case nd_pop_all_packet_info() didn't restore it.
2024-03-21 12:12:30 -07:00
Denis Ovsienko
1bec29abe6 Retire BSD/OS support.
The last release of BSD/OS was more than 20 years ago, so remove all
bits specific to building tcpdump on it, mainly ppp_bsdos_if_print(),
which has been a no-op on platforms other than BSD/OS.  Restoring the
function would not be practicable because in addition to the generic bit
rot it uses SLC_DIR, SLC_LLHL, SLC_BPFHDRLEN, SLC_CHL and struct
ppp_header, none of which appear in FreeBSD or illumos or Linux or
NetBSD or OpenBSD.  This is why protocol decoders should not depend on
OS-specific headers.

See also commit 4729260.
2024-01-28 12:52:57 +00:00
Francois-Xavier Le Bail
4c5bef9603 Add --lengths option to print the captured and original packet lengths
The lengths will be printed at the beginning of the line or after the
packet number, if any.

'caplen' is the captured length.
'len' is the original (on wire) length.

Examples
1) With -#n
    1  caplen 80 len 98 14:41:53.503612 IP 192.168.1.11.43966 > [...]
2) With -n
caplen 80 len 98 14:43:38.185603 IP 192.168.1.11.43966 > [...]

Add a test file with one packet not truncated, the other truncated.

[skip ci]
2023-12-26 12:50:38 +00:00
Denis Ovsienko
94f232c1ab Remove init_crc10_table() and the entourage.
As Guy Harris points out in bug report GH #1022, the function has been a
busy no-op since commit e6c39e6 in 2010.  While at it, fixup the Python
code to work on Python 3:

    for i in range(len(crc_table)/8):
TypeError: 'float' object cannot be interpreted as an integer
2023-01-14 22:55:27 +00: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
Guy Harris
be43281053 Make sure we don't set the snapend before the beginning of the packet.
If a caller attempts to set it after the current snapend, just silently
ignore the attempt.

If they try to set it before the beginning of the packet, report it as a
bug and quit dissection.  Add a new setjmp() return value meaning "bug"
rather than "truncated packet", add an "nd_bug_longjmp()" routine for
reporting bugs where we should quit dissecting, and use that in this
case.
2022-03-29 00:51:21 -07:00
Guy Harris
fe762c04a6 Handle DLT_PFLOG on all OSes.
Don't pad the pflog header with BPF_WORDALIGN(); round up to a multiple
of 4, instead, as that's what all but FreeBSD do, and FreeBSD used to do
that and should go back to doing so (kern/261566).

Don't rely on the OS's pflog include files to define direction types,
reason types, action types, or the layout of the header; instead, define
them ourselves in a header of our own, with #ifs to select the ones that
are only on some platforms.  That way, it'll handle some fields and
field values (the ones common to all OSes with pflog) on all OSes, even
ones without pflog.

That also expands the set of direction, reason, and action codes to what
various *BSDs and Darwin support.

Also, handle all the different AF_INET6 values in various *BSDs and
Darwin.
2022-01-29 22:30:33 -08:00
Francois-Xavier Le Bail
6d854639ea autoconf: Enhance the --enable-instrument-functions result output
It prints now, by default, also the static functions names.

To configure the printing of only the global functions names, as before:
$ make instrument_global

To go back to print all the functions names:
$ make instrument_all

In case of truncation, the indentation level is reset to its previous
level in pretty_print_packet().

[skip ci]
2022-01-22 13:19:33 +01:00
Francois-Xavier Le Bail
c6b7d41176 autoconf: Add the option to print functions names (entry and exit)
This should help some debugging processes.

Usage:
./configure --enable-instrument-functions

Generate instrumentation calls for entry and exit to functions.
Just after function entry and just before function exit, these
profiling functions are called and print the function names with
indentation and call level.

To instument a static function, remove temporarily the static specifier.

In case of truncation, the indentation level is reset currently to 1 in
pretty_print_packet(), main is level 0.
2022-01-17 20:48:57 +01:00
Nathan O'Sullivan
63b104dc5b Add --print-sampling option to print every Nth packet
New option `--print-sampling=NTH` will parse and print every NTH packet,
with all other packets producing no output. This option enables
`--print` and `-S` flags.

Print sampling is useful for real-time inspection of an interface with
a high packet rate, or initial inspection of large capture files.
2022-01-17 19:43:59 +00:00
Francois-Xavier Le Bail
88ffe242bd Assign ndo->ndo_packetp in pretty_print_packet()
Thus it can be used for debugging.
2021-11-01 10:56:02 +01:00
Denis Ovsienko
244754b3f0 Lose a few forward declarations in tcpdump.c.
Reinstate a few comments in print.c for consistency.
2021-03-29 11:23:21 +01:00
Denis Ovsienko
459fdf8fbd Lose a few forward declarations in print.c. 2021-03-28 13:22:48 +01:00
Denis Ovsienko
7e29aa3605 Squelch compiler warnings on OpenBSD.
With these changes tcpdump passes "CFLAGS=-Werror make" on OpenBSD 6.8
AMD64, so build.sh has one less reason to fail.

gcc (GCC) 4.2.1 20070719
(also from OpenBSD clang version 10.0.1 with different wording)

./addrtoname.c: In function 'etheraddr_string':
./addrtoname.c:605: warning: passing argument 2 of 'ether_ntohost'
discards qualifiers from pointer target type

./addrtoname.c: In function 'init_etherarray':
./addrtoname.c:980: warning: passing argument 2 of 'ether_ntohost'
discards qualifiers from pointer target type

./print.c: In function 'pretty_print_packet':
./print.c:389: warning: passing argument 2 of 'ts_print' from
incompatible pointer type

./bpf_dump.c:34: warning: no previous prototype for 'bpf_dump'
2021-03-17 11:55:17 +00:00
Francois-Xavier Le Bail
387c58edb5 Print the full packet with -x/-X options when truncated
including the link layer header.
2020-10-14 16:49:24 +02:00
Francois-Xavier Le Bail
a2a16f6b4c 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.).
2020-09-18 13:27:48 +02:00
Francois-Xavier Le Bail
f6bb0d6de2 Use more the nd_print_trunc() function 2020-08-31 21:58:31 +02:00
Francois-Xavier Le Bail
f5aa04085e Rename DLT_PPP_WITHDIRECTION to DLT_PPP_PPPD
In libpcap DLT_PPP_WITHDIRECTION was renamed to
DLT_LINUX_PPP_WITHDIRECTION and after to DLT_PPP_PPPD.

Rename other #defines to match.
2020-08-08 14:45:10 +02:00
Francois-Xavier Le Bail
b30f3843b9 Apply the last step of the new way to update the link-layer header length
All the link-layer dissectors are now void functions.

All the functions were moved to the void_printers[] array.
Rename this array to printers[].
Remove the uint_printers[] array, now empty.
Remove the 'ndo_void_printer' flag field, now useless, from
netdissect_options.
Remove other transitional code.
2020-08-06 22:55:05 +02:00
Francois-Xavier Le Bail
6855c11117 PFLOG: Update the link-layer dissector to a void function
Moreover:
Use GET_U_1() when needed.
Remove trailing "_if" from the protocol name.
2020-08-06 17:28:03 +02:00
Francois-Xavier Le Bail
b846e24423 AppleTalk: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-06 16:27:24 +02:00
Francois-Xavier Le Bail
5e9a51fdd5 CHDLC: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-06 16:27:24 +02:00
Francois-Xavier Le Bail
496c43c10b PPP: Update the link-layer dissectors to void functions
Moreover:
Remove trailing "_if" from some protocol names.
Update the outputs of two tests accordingly.
2020-08-06 16:25:52 +02:00
Francois-Xavier Le Bail
aa8bf0f527 Remove the unused DLT_LANE8023 link-layer dissector
DLT_LANE8023 was never defined in libpcap.
It was, perhaps, defined in some SuSE libpcap update, but no evidence
of this.
It is not defined in OpenSuSE Leap 15.2 (information from Guy).
2020-08-06 09:44:45 +02:00
Francois-Xavier Le Bail
4262b29164 FR: Update the link-layer dissectors to void functions
Moreover:
Remove trailing "_if" from the protocol name.
Add two comments.
2020-08-04 17:25:01 +02:00
Francois-Xavier Le Bail
b1327f7a88 ATM: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-02 22:11:51 +02:00
Francois-Xavier Le Bail
bdf7eacfa1 IPFC: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-02 22:11:51 +02:00
Francois-Xavier Le Bail
941452b132 Token Ring: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-02 22:11:51 +02:00
Francois-Xavier Le Bail
8cda025aed SLL: Update the link-layer dissectors to void functions
Moreover:
Fix two probably copy & paste errors (s/SLL_HDR_LEN/SLL2_HDR_LEN/).
Remove trailing "_if" from the protocol name.
2020-08-02 22:10:04 +02:00
Francois-Xavier Le Bail
770b67da76 FDDI: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-02 12:03:39 +02:00
Francois-Xavier Le Bail
e2e1906cff CIP: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from the protocol name.
2020-08-02 11:50:46 +02:00
Francois-Xavier Le Bail
006004fdda IEEE 802.15.4: Update the link-layer dissectors to void functions 2020-08-02 11:24:45 +02:00
Francois-Xavier Le Bail
dc8a38c289 IEEE 802.11: Update the link-layer dissectors to void functions 2020-08-02 10:35:09 +02:00
Francois-Xavier Le Bail
cab4799ee5 PPPoE: Update the link-layer dissector to a void function
Moreover:
Add a length check.
Fix a return.
Use nd_print_trunc().
Remove trailing "_if" from the protocol name.
Style.
2020-07-31 20:40:07 +02:00
Francois-Xavier Le Bail
962de080b0 Juniper: Update the link-layer dissectors to void functions 2020-07-27 19:20:02 +02:00
Francois-Xavier Le Bail
692e9d44a5 vsock: Update the link-layer dissector to a void function
Moreover:
Rename some variables/parameters from 'len' to 'caplen' because
they store the capture length.
2020-07-27 09:06:59 +02:00
Francois-Xavier Le Bail
7b96701040 IPoIB: Update the link-layer dissector to a void function 2020-07-25 16:55:45 +02:00
Francois-Xavier Le Bail
81dbf4a0b0 Update more link-layer dissectors to void functions
brcm_tag_if_print()
brcm_tag_prepend_if_print()
dsa_if_print()
edsa_if_print()
ether_if_print()
netanalyzer_if_print()
netanalyzer_transparent_if_print()

Update ether_print(), ether_common_print() and ether_switch_tag_print()
to void functions.

Add a flag parameter to ether_print(), ether_common_print() and
ether_switch_tag_print() to increment the link-layer header length field
of the netdissect_options when needed.
The calls use TRUE when the return value of the funtions was used.
The calls with FALSE avoid increments when the calls are nested.

Moreover:
Remove trailing "_if" from some protocol names.
2020-07-15 09:18:35 +02:00
Francois-Xavier Le Bail
96c60029b3 Rename a field of the netdissect_options structure 2020-07-14 17:35:57 +02:00
Francois-Xavier Le Bail
25687e1a31 Print packets for unsupported link-layer protocols in hexadecimal/ASCII
This avoids to get only:
tcpdump: packet printing is not supported for link type XYZ: use -w

The default printing is like:
18:45:52.723872 UNSUPPORTED
        0x0000:  001f 0000 0540 6078 725d 586d 4d66 4671  .....@`xr]XmMfFq
        0x0010:  6d58 4d5c 7159 5f71 565c 556c 4e71 7171  mXM\qY_qV\UlNqqq
        0x0020:  7171 7171 7171 7171 7171 7171 7171 5180  qqqqqqqqqqqqqqQ.
        0x0030:  7f7f                                     ..
18:45:52.755995 UNSUPPORTED
        0x0000:  001f 0000 0540 6043 7851 807f 7f         .....@`CxQ...
        [...]
2020-05-10 11:05:59 +02:00
Francois-Xavier Le Bail
5b52e5fa19 NFLOG: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
2020-05-04 16:14:14 +02:00
Francois-Xavier Le Bail
a881efab39 SLIP: Update the link-layer dissectors to void functions
Moreover:
Update the protocol names (sl_if -> slip and sl_bsdos_if -> slip_bsdos).
Update the output of some tests accordingly.
2020-04-30 15:18:16 +02:00
Francois-Xavier Le Bail
ddefbd82c9 ARCNET: Update the link-layer dissectors to void functions 2020-03-28 20:56:02 +01:00
Francois-Xavier Le Bail
a0d6dc5065 PKTAP: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
Update the output of a test accordingly.
2020-03-28 10:44:30 +01:00
Francois-Xavier Le Bail
a80bcdd550 PPI: Update the link-layer dissector to a void function
Moreover:
Merge ppi_if_print() and ppi_print() in one function.
Remove two useless ND_TCHECK_ tests (GET_ used).
Remove a no longer used 'trunc' label.
2020-03-28 08:50:00 +01:00
Francois-Xavier Le Bail
59cad18b62 IPNET: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
Remove a useless ND_TCHECK_1 test (GET_U_1 is used).
Remove a no longer used 'trunc' label.
2020-02-08 10:50:49 +01:00
Francois-Xavier Le Bail
c3f8e04764 ENC: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
Remove a no longer used 'out' label.
2020-02-07 20:36:41 +01:00
Francois-Xavier Le Bail
717095ab66 NULL/LOOP: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
Remove a useless ND_TCHECK_4 test (GET_HE_U_4 used).
Remove a no longer used 'trunc' label.
Use uint32_t type for family in null_hdr_print().
2020-02-07 20:36:34 +01:00
Francois-Xavier Le Bail
92a263b1b3 Raw IP: Update the link-layer dissector to a void function
Moreover:
Remove trailing "_if" from protocol name.
2020-02-07 20:36:30 +01:00