Commit Graph

291 Commits

Author SHA1 Message Date
Guy Harris
6da51b3ec9 Introduce a buffer stack, and use it for ESP decryption.
If a dissector has to process its input - decryption, decompression,
etc. - rather than dissect the raw input, it should push the processed
input onto the buffer stack.  As soon as the dissection is done, the
stack should be popped, to free the buffer into which the processing was
done, and restore the "pointer to packet data" and "pointer to end of
packet data" members of the netdissect_options structure, so the code
can go back to dissecting the original data.

The stack will get everything popped off it when dissection is done.

Use this mechanism in the ESP decryption code rather than scribbling on
top of the input packet data.
2019-03-30 19:26:06 -07:00
Guy Harris
48644533f2 Have esp_print() handle printing its payload.
That cleans things up a bit, including removing some duplicate code.

Clean up some other things, and add a length check, while we're at it.
2019-03-28 11:45:43 -07: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
176e182416 Apply the first step of the new way to fetch data with bounds checking
Add GET_{BE|HE|LE}_, GET_U_1, GET_S_1, GET_IPV4_TO_HOST_ORDER,
GET_IPV4_TO_NETWORK_ORDER macros and
get_{be|he|le}_, get_u_1, get_s_1, get_ipv4_to_host_order,
get_ipv4_to_network_order inline functions,
with setjmp/longjmp logic to do better and easier data fetch with
bounds checking.

Based on Guy Harris's idea and code.
2019-03-26 21:06:06 +01:00
Michael Richardson
35a1310799 Merge branch 'master' of https://github.com/kivinen/tcpdump into kivinen-master 2019-03-24 09:05:06 +01:00
Francois-Xavier Le Bail
1fabc59c13 Add the nd_print_protocol() function
Use the ndo->ndo_protocol field to print the protocol name.
2019-03-19 14:50:52 +01:00
Francois-Xavier Le Bail
9be45b2369 Use the ndo->ndo_protocol field instead of the protoname parameter
Moreover:
Fix a truncated string: "[!" is not the prefix for a truncated string.
Add two comments.
Clean up a whitespace.
2019-03-08 10:12:21 +01:00
James Ko
5cf83c2fce Handle DLT_IEEE802_15_4_TAP.
https://github.com/jkcko/ieee802.15.4-tap
2019-02-20 09:08:03 -08:00
Florian Fainelli
6eaebfe992 Add support for decoding Broadcom Ethernet switches tags
This adds support for decoding the Broadcom Ethernet switches tags which
are are 4byte in length and are located between the Ethernet MAC SA and
the Type/Length field (DSA_TAG_BRCM) as well as the pre-pended Broadcom
tag (DSA_TAG_BRCM_PREPEND) which are located in front of the standard
Ethernet header.

This makes use of the recently introduced ether_print_hdr_len() to allow
specifying the non-standard Ethernet header length of 12 + 4 + 2 bytes.
2019-01-28 10:56:18 -08:00
Florian Fainelli
48e290d807 Ethernet: Allow specifying non-standard Ethernet header length
A fair number of proprietary Ethernet switch tagging protocols, such as
Broadcom tags for instance, will place their tag between the MAC SA and
the Type/Length field.

Move the body of ether_print() into ether_print_hdr_len() and specify
the Ethernet header length as an argument to that function.
ether_print() calls ether_print_hdr_len() with a standard Ethernet
header lenght of 14 bytes, while other callers could specify an
arbitrary length. We still assume that the first Length/Type field to
parse is located 2 bytes before the end of that Ethernet header length.

This will be used in a subsequent commit to parse Broadcom tags.
2019-01-25 17:00:24 -08: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
Guy Harris
0259ae79db Umm, wrong. 2018-12-10 23:26:25 -08:00
Guy Harris
7df90fa2a2 Add, and use, macros to do locale-independent case mapping.
This means we get the same behavior in Turkish locales (where, if we
aren't in the C locale, we might get lower-case "i" mapped to upper-case
"I with dot" and upper-case "I" mapped to lower-case "i without dot),
and may also suppress some shortening warnings from MSVC.
2018-12-10 23:16:45 -08:00
Guy Harris
877753b5c8 Revert "Try to squelch a warning about non-constant format strings."
This reverts commit 76ed0bb392.

It doesn't help.

We may just want to suppress the warning, as in "trust us, we know what
we're doing", although it'd be nice if the format string passed to those
functions could be checked to make sure it is one that takes exactly one
integer argument.
2018-12-10 22:01:39 -08:00
Guy Harris
76ed0bb392 Try to squelch a warning about non-constant format strings.
Declare the format-string argument to tok2strbuf(), tok2str(),
bittok2str(), and bittok2str_nosep() as such, to see whether that gets
MSVC not to complain - or if it just gets upset because there's no "..."
argument list for it.
2018-12-10 21:53:58 -08:00
Tero Kivinen
32e24ead3b Updated 802.15.4 code 2018-11-18 04:35:46 +07:00
Guy Harris
83e419c628 Fix printing of Linux cooked captures with monitor-mode packets.
Apparently, if you have an interface in monitor mode, capturing on the
"any" device can get packets that have a SLL hatype of 803, which is the
ARPHRD_ value for radiotap, and with the payload containing a radiotap
header, followed by an 802.11 header, followed by the 802.11 payload.
Handle that.
2018-11-12 22:03:49 -08:00
Francois-Xavier Le Bail
dcea6d0284 Update a comment 2018-09-22 15:19:44 +02:00
Francois-Xavier Le Bail
77a49fcb6e Add the nd_print_invalid() function
It prints " (invalid)", used for malformed or corrupted packets.

Moreover:
Update CONTRIBUTING.
2018-09-11 13:09:05 +02:00
Francois-Xavier Le Bail
6a9b0468b6 Add the debug macro ND_DEBUG 2018-09-06 11:01:56 +02:00
Francois-Xavier Le Bail
d77ac851c7 Fix local time printing
Using seconds offset from GMT to local time to compute local time give
errors when printing times outside the same daylight saving time period.

Use the localtime() function for default and -tttt cases.
Use the gmtime() function for -ttt and -ttttt cases.

Rename ts_hmsfrac_print() to ts_date_hmsfrac_print().
Remove some variables now useless.
Update some comments.
2018-08-07 17:37:36 +02:00
Guy Harris
51c1da63e4 DLT_LINUX_SLL2 support. 2018-07-12 11:49:38 -07:00
Guy Harris
6e80fcdbe9 Make roundup2() generally available. 2018-06-22 11:18:20 -07:00
Francois-Xavier Le Bail
7187e01f8f Add the fn_print_str() function
This function print a null-terminated string, filtering out non-printable
characters.
DON'T USE IT with a pointer on the packet buffer because there is no
truncation check. For this use, see the nd_printX() functions.
2018-05-18 23:05:01 +02:00
Francois-Xavier Le Bail
53d1f7a25a Update hex_and_ascii_print_with_offset() to static 2018-05-10 16:48:48 +02:00
Francois-Xavier Le Bail
c45392de18 Add the nd_print_trunc() function
Use the ndo->ndo_protocol field to print a " [|protocol]" message.
2018-05-04 10:56:23 +02:00
Francois-Xavier Le Bail
e10fe19f45 Remove the safeputs() function
Use the nd_printzp() function instead.
2018-05-02 10:15:26 +02:00
Francois-Xavier Le Bail
0cced4fcdc Remove the safeputchar() function
Print the characters filtering out non-printable with fn_print_char().

Update the output of some tests accordingly.
2018-05-02 03:33:02 +02:00
Francois-Xavier Le Bail
3e3e6d2ef4 Rename the fn_printX() functions to nd_printX()
The functions are: nd_print, nd_printztn, nd_printn and nd_printzp.
Trying to make it clearer that they currently have to be used only on part
of the packet buffer.
Update some comments.
2018-04-30 13:35:06 +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
89649d6e81 Move some smb prototypes in smb.h
Moreover:
Add a const qualifier
2018-03-16 11:20:51 +01:00
Francois-Xavier Le Bail
ba857360fc Add some const qualifiers 2018-03-16 10:39:25 +01:00
Francois-Xavier Le Bail
a53605c61b Add a malloc/free process with garbage collector
Use it in the PPP printer.
2018-03-14 13:59:26 +01:00
Francois-Xavier Le Bail
5ae22f41a8 Add a status exit code to the function ndo_error()
The status are defined in an enum in status-exit-codes.h.

Moreover:
Use ndo_error() instead of ndo_warning() for malloc() errors in print-esp.c.
2018-02-25 20:58:27 +01:00
Francois-Xavier Le Bail
ef987f720c Rename some printer functions to *_print
Moreover:
Fix spaces.
2018-02-22 14:19:42 +01:00
Guy Harris
f727010777 Get rid of ND_UNALIGNED.
Structures that describe packet formats now all use nd_ types, none of
which require more than 1-byte alignment, so compilers shouldn't assume
that anything in those structures is aligned on any particular boundary,
even without a "this is unaligned" hint.
2018-02-14 14:03:41 -08: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
Guy Harris
b3703ed9cf Pick up Windows snprintf and strdup replacements from libpcap. 2018-01-28 20:57:15 -08:00
Guy Harris
a909db55eb Declare ND_UNALIGNED in netdissect.h.
It's netdissect-specific, and there are some files that include
netdissect.h, that don't include netdissect-stdinc.h, and that include
files that define structures using ND_UNALIGNED.
2018-01-28 20:16:36 -08:00
Francois-Xavier Le Bail
a8c1b2a339 No more need for ndo_invalid_header in struct netdissect_options
Because we now stop decoding packet when header length(s) is/are invalid,
there is no more need to keep the invalid header flag out of
pretty_print_packet function.
2018-01-25 15:12:24 +01:00
Francois-Xavier Le Bail
6f909486a3 Remove no more used ND_TCHECK() macro
And consequently ND_TCHECK2() and ND_TTEST2() macros.

The macros to use now are:
(Comments in netdissect.h)

ND_TCHECK_n(p), n in { 1, 2, 3, 4, 5, 6, 7, 8, 16 }
ND_TCHECK_SIZE(p)
ND_TCHECK_LEN(p, l)

ND_TTEST_n(p), n in { 1, 2, 3, 4, 5, 6, 7, 8, 16 }
ND_TTEST_SIZE(p)
ND_TTEST_LEN(p, l)
2018-01-24 19:08:31 +01:00
Guy Harris
45fc519a2a Don't test for __attribute__ in the configure script.
Instead, use compiler test macros to check whether *particular*
attributes are supported, and set various #defines appropriately, in
header files.

Rename the UNALIGNED structure attribute to ND_UNALIGNED, and ask
whether we still need it.
2018-01-21 17:57:20 -08:00
Francois-Xavier Le Bail
a15e52bb27 Remove no more used ND_TTEST() macro
The macros to use now are:
ND_TTEST_n(p), n in { 1, 2, 3, 4, 5, 6, 7, 8, 16 }
ND_TTEST_SIZE(p)
2018-01-21 19:57:03 +01:00
Francois-Xavier Le Bail
9e6ba479d8 Add sanity checks on packet header (packet length / capture length)
For a valid packet:
packet length != 0,
capture length != 0,
packet length >= capture length.

Update the output of some tests accordingly.
2018-01-16 08:32:52 +01:00
Guy Harris
64677b0d78 Clean up signed vs. unsigned. 2018-01-11 11:52:30 -08:00
Guy Harris
fe225c5518 Use nd_ types, add host-endian extract routines, clean up signed vs. unsigned.
We now define the structures for Linux USB headers in print-usb.c, so it
doesn't need to include <pcap/usb.h>; don't check for it.
2018-01-11 11:10:21 -08:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Guy Harris
39a7d38ee8 Clean up signed vs. unsigned.
Use unsigned for lengths.  Add additional length checks, as we can no
longer cheat and rely on "underflow turns the length negative, so just
check for > 0".

Show most NBT and SMB numerical fields as unsigned, as that's what they
are.  Have "d" and "D" treat the value as signed; add "u" and "U" for
unsigned values.
2018-01-06 22:18:00 -08:00
Francois-Xavier Le Bail
6e8e14d7fa Add ND_TTEST_SIZE() and ND_TCHECK_SIZE() macros
To replace in next steps:
ND_TTEST(var) -> ND_TTEST_SIZE(p)
ND_TCHECK(var) -> ND_TCHECK_SIZE(p)

Moreover:
Add a comment
2018-01-03 21:06:54 +01:00
Francois-Xavier Le Bail
b01a3f26ef Use 'u_char *' type for input buffer pointer like in most similar cases 2018-01-02 19:08:01 +01:00