Commit Graph

227 Commits

Author SHA1 Message Date
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
Guy Harris
fe1c2f0d7f Clean up RX dissector.
Use uintN_t and intN_t types rather than u_short and u_int.

Use uint32_t rather than unsigned long, as that's what's intended.

Most fields in RX are unsigned, according to the OpenAFS source; make it
so.  Use EXTRACT_BE_INT32() to extract the one field that isn't.

The length and port numbers passed in from the UDP dissector are
unsigned; make the arguments unsigned.

Use ND_TTEST2 rather than a hand-rolled test.

Use ND_TCHECK_nBITS() rather than ND_TCHECK2() in some cases.
2017-11-21 12:33:55 -08:00
Guy Harris
8eecfc382e More EXTRACT_8BITS() changes. Use ND_CHECK_nBITS() more as well. 2017-11-19 21:02:54 -08:00
Guy Harris
b48e7d7f4d Expand, and update, a comment. 2017-11-19 11:34:23 -08:00
Francois-Xavier Le Bail
dc6a6ac392 ZMTP: Rename a printer function
Its name must end with '_print'
2017-11-16 14:17:26 +01:00
Francois-Xavier Le Bail
6151e2190b NFS: Rename two printer functions
Their names must end with '_print'
2017-11-16 13:59:17 +01:00
Francois-Xavier Le Bail
62af1ac58c SUNRPC: Rename entry function
Most printer entry functions are based on the file name (without print-).
Do the same for SUNRPC (sunrpcrequest_print -> sunrpc_print).

This change allows easier update by script.
2017-11-16 10:18:43 +01:00
Francois-Xavier Le Bail
e037e16d6d DNS: Rename entry function
Most printer entry functions are based on the file name (without print-).
Do the same for DNS (ns_print -> domain_print)

This change allows easier update by script.
2017-11-16 10:09:23 +01:00
Francois-Xavier Le Bail
51d034f45b Rename some link-layer dissector entry functions
Most of them are already named *_if_print.
Update the others to have the same prefix.

This change allow easier identification.
2017-11-16 07:22:41 +01:00
Guy Harris
2b9bfa05b6 Check for unaligned memory access support at compile time.
Don't test at configure time; that doesn't work when cross-compiling and
may be a pain to do with CMake.
2017-10-16 01:39:10 -07:00
Francois-Xavier Le Bail
48abded133 Fix a comment 2017-09-20 20:45:37 +02:00
Guy Harris
1dcd10acea CVE-2017-12897/ISO CLNS: Use ND_TTEST() for the bounds checks in isoclns_print().
This fixes a buffer over-read discovered by Kamil Frankowicz.

Don't pass the remaining caplen - that's too hard to get right, and we
were getting it wrong in at least one case; just use ND_TTEST().

Add a test using the capture file supplied by the reporter(s).
2017-09-13 12:25:44 +01:00
Guy Harris
3dc736d939 Handle attributes for function pointers by checking the compiler version.
Handle attributes for function pointers the same way we handle
attributes for functions, by explicitly checking for the compiler
version with #if rather than with a configure script check.  That's one
fewer thing that, if you're not using autoconf, has to be done in some
other fashion.

While we're at it, put NORETURN in the right place to have it work with
Microsoft Visual Studio as well as various UN*X compilers.
2017-08-19 11:25:24 -07:00
Guy Harris
141c1c6f49 Suppress UBSan warnings from EXTRACT_.
Yes, the behavior of an access with an improperly-aligned pointer is
undefined according to the C standard, but if we're doing that in an
EXTRACT_ function/macro, we're doing it because we know it's safe and
because it's faster than picking the bytes out one by one and assembling
them, so suppress those warnings.

Pull over libpcap's funcattrs.h and use it to do a bunch of checks for
various function attributes; that defines __has_attribute(), so we can
use it to check for the "suppress sanitizer warnings" attribute.

While we're at it, use other things it defines to specify "this function
never returns", "this function is printf-like", and "this function
argument is a printf-style format argument", rather than using various
configure-script checks.  That should let us declare some function
attributes with Microsoft Visual Studio's compilers.
2017-08-18 20:11:43 -07:00
Denis Ovsienko
3951a87cbe spell ASCII in uppercase 2017-08-10 09:52:46 +01:00
Guy Harris
449682d899 With no -s, or with -s 0, don't specify the snapshot length with newer versions of libpcap.
That leaves it up to libpcap to choose an appropriate snapshot length,
which it'll do.  With upcoming versions, it'll choose, when capturing on
a D-Bus interface, a very large snapshot length, to handle the maximum
D-Bus message size of 128MB.

(For older versions, we still use 262144, as those versions won't pick a
default value.)
2017-06-02 21:50:45 -07:00
Denis Ovsienko
cae54f4d94 CVE-2016-7985,7986/fixup medsa_print()
The code in medsa_print() assumed that the MEDSA packet always follows
an Ethernet header that is inside the allocated memory buffer. But
this is not always the case, see commit 6bc4429 for rationale.

Eliminate the Ethernet header pointer and just pass on the struct
lladdr_info arguments provided.
2017-01-18 18:24:53 +00:00
Guy Harris
d07e352f5a CVE-2016-7993/Clean up relative time stamp printing.
Have separate routines for signed and unsigned relative time stamps.
Have the routine for signed time stamps handle the case of -2^31, where
you can't negate it and have the result fit in a 32-bit signed integer.

There are currently no users of the signed relative time stamp routine,
but it's there in case anybody needs it (and is passing 32-bit
quantitites, so that there's a risk that a packet might contain -2^31 as
the time stamp).

Fixes an array overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:38 +01:00
Guy Harris
7bf069c251 CVE-2016-7983,7984/Don't use strchr() to scan packet data.
It can't be told to stop at the end of the packet data.  Add a
fn_printztn() that prints null-terminated strings, with a length check,
and which returns the number of bytes processed, or 0 if we ran out of
data.  That means it does the scanning we need, but safely.

Use it in the TFTP and BOOTP printers.

Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:37 +01:00
Guy Harris
406b0e3e92 Stop processing IPPROTO_ values once we hit IPPROTO_IPCOMP.
It's not like, for example, AH or ESP, where, following the header for
that protocol, there's another protocol with its own payload.
2017-01-18 09:16:37 +01:00
Guy Harris
d9dbb118f2 CVE-2016-7924/Add some bounds checks.
Fixes a heap overflow found with American Fuzzy Lop by Hanno Böck.

Also, get rid of the return value for oam_print(), as it's not used and
not useful.
2017-01-18 09:16:36 +01:00
Guy Harris
6bc44295cf CVE-2016-7985,7986/Change the way protocols print link-layer addresses.
If a protocol that runs under a link-layer protocol would print the
link-layer addresses for the packet as source and destination addresses
for the packet, don't have it blithely assume those link-layer addresses
are present or are at a particular offset from the beginning of that
protocol's data; Ethertypes, for example, are used by a number of
protocols, not all of which have Ethernet headers and not all of which
have any MAC headers.

Instead, pass the printers for those protocols structures with a pointer
to the address data and a pointer to a routine that prints the address.

Fixes some heap overflows found with American Fuzzy Lop by Hanno Böck.
2017-01-18 09:16:36 +01:00
Guy Harris
6080cff326 Move more libsmi stuff to netdissect.c.
Have the call to smiLoadModule() be in a nd_load_smi_module() routine.
Have it set a *global* flag indicating whether a module has been loaded;
that's not per-netdissect_options.  Use that global flag in print-snmp.c
- and don't test it once per loop iteration, it's not going to change
while the loop is running.

Have a routine to return the version of the library if we're built with
it or NULL if we're not.

That removes the last of the code that tests USE_LIBSMI or uses libsmi
from tcpdump.c.
2016-08-04 14:35:35 -07:00
Guy Harris
91e08f888d Move some code around.
Move stuff to initialize and clean up libraries that are used by
netdissect code into nd_init() and nd_cleanup() routines in
libnetdissect; this includes Winsock (which is used on Windows by, for
example, the code to get names for IP addresses) and libsmi.

Call nd_init() when tcpdump starts up, and call nd_cleanup() when it
exits.

Move util.c routines to tcpdump.c, and make them static.

Use ndo->ndo_error to report a failure to open a file in print-esp.c.
2016-08-04 13:19:57 -07:00
Jean-Raphaël GAGLIONE
75b7aeef9c Printer for HNCP (RFCs 7787 and 7788).
This is joint work with Antonin Décimo.
2016-07-28 21:09:41 +02:00
Andrew Darqui
fc213645d4 Initial support for the REdis Serialization Protocol known as RESP.
This commit adds support for RESP as defined in: http://redis.io/topics/protocol.
It also supports inline commands and pipelining. Due to the popularity of RESP,
numerous services are emerging that use this protocol. You may decode RESP packets
on arbitrary ports using the "-T resp" option.

Example captures can be found in tests/resp_*.

A simple way to test this parser is to start redis-server and then run
redis-cli commands such as "redis-cli set key value".

Traditionally, redis-cli monitor is used to debug redis. Unfortunately,
the "monitor" command can cause significant load on a redis-server in
production. This parser may be used as a non-invasive alternative to
redis-cli monitor.
2016-04-26 11:00:21 +02:00
Francois-Xavier Le Bail
f0b959c53e Restore alphabetical order in Makefile.in and netdissect.h 2016-03-22 17:23:40 +01:00
bugyo
ba8a8cd5a3 Add printing function for Generic Protocol Extension for VXLAN
and Network Service Header.

This code stands for following internet drafts:

- VXLAN GPE: draft-ietf-nvo3-vxlan-gpe-01
- NSH: draft-ietf-sfc-nsh-01
2016-03-22 16:59:03 +01: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
Francois-Xavier Le Bail
436ced3bd8 Change istr[] (for invalid string) to be global 2016-01-28 14:24:19 +01:00
Francois-Xavier Le Bail
f25ed1f812 Harmonize TCP source or destination ports tests with UDP ones 2015-12-14 20:28:14 +01:00
Francois-Xavier Le Bail
4df36ab95d CDP: Filter out non-printable characters
Add a fn_print_char() to do filtering.
2015-11-09 16:29:32 +01:00
Guy Harris
bfe9582ec6 Use the nd_uintN_t types more.
Define them in netdissect.h.

Use them in ip.h, and *don't* mark the structures as UNALIGNED; that
should no longer be necessary.

Add a new nd_ipv4 type to use as an IPv4 address; it represents the 4
bytes of IPv4 address as an array of unsigned chars, so that its natural
alignment is only on a byte boundary.

Those changes found some places where we weren't using
UNALIGNED_MEMCPY() to extract IPv4 addresses from packets; use it.
2015-10-07 00:14:20 -07:00
ritsz
823644a72d Initial commit for support of Type 3 and Type 4 LISP packets.
Fixing Travis CI build for LISP commit

Adding testcases for lisp notify and register

Fixing build warnings

Added ND_TCHECK for relevant headers

Fixing ND_TCHECK2 issues

Adding support for multiple LOC records for same EID entry

Fixing review issues, adding detailed tests

Adding support for verbose outputs

Adding RFC information for UDP PORT defination

Removing Spaces in type names

Print EID record related flags in verbose mode

Using tok2str

Fixing -Wpedantic issues

Negative testcases, Packet structure comments, verbose mode flag printing

Printing Map Version

Print auth_data, decouple type and xtr_present extraction, handle malformed packets correctly

Tests for latest code changes

Printing useful info incase not built with IPv6 support
2015-10-04 12:47:13 +02:00
Francois-Xavier Le Bail
0fb8e69adb Reorganize netdissect.h
Group together:
- DLT printers (sorted)
- other printers (sorted)
- utilities
2015-09-18 15:14:31 +02:00
Francois-Xavier Le Bail
817bdfede2 Rename print_data() to smb_print_data() 2015-09-18 13:04:24 +02: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
5c72fe1e4f Remove non-dissection related fields from struct netdissect_options
Remove 'ndo_dlt' and 'ndo_dltname' from netdissect_options, only
used is frontend.
Use instead 'yflag_dlt' and 'yflag_dlt_name' variables in frontend.

Moreover:
Fix style
2015-09-14 19:39:57 +02:00
Francois-Xavier Le Bail
a9728e5f8a Remove a non-dissection related field from struct netdissect_options
Remove 'ndo_immediate' from netdissect_options, only used is frontend.
Use instead 'immediate_mode' variable in frontend.
2015-09-14 17:16:26 +02:00
Francois-Xavier Le Bail
f0ff49cc4d Move if_printer to structure netdissect_options
The structure 'netdissect_options' can hold if_printer.
Thus the structure 'print_info' is useless now.

Moreover:
Delete useless blank lines
Fix indent
2015-09-14 15:54:54 +02:00
Francois-Xavier Le Bail
f5fe14663d libnetdissect code must include 'netdissect.h', not 'interface.h'
Moreover:
Remove netdissect.h include in interface.h
Move thiszone declaration in netdissect.h
Update a comment
2015-09-11 13:22:56 +02:00
Francois-Xavier Le Bail
a306c9e7be Update a ndo flag name
Even if frontend/backend separation is ongoing, keep coherence between
option name and flag name at the moment.
Option name is 'm', thus s/ndo_sflag/ndo_mflag/.
2015-09-09 13:32:20 +02:00
Francois-Xavier Le Bail
02c218bf32 Update a comment 2015-09-08 22:37:54 +02:00
Francois-Xavier Le Bail
78689f7b24 Remove obsolete comment 2015-09-08 12:26:38 +02:00
Francois-Xavier Le Bail
bf657452ef Remove no longer used option 'R' 2015-09-08 09:14:13 +02:00
Francois-Xavier Le Bail
0845bc813c Add program_name field in the netdissect_options structure
A program that use the library should set it. Done for tcpdump.
ndo_error() and ndo_warning() print now 'ndo->program_name'.

Moreover:
Fix indent
2015-09-07 19:13:42 +02:00
Francois-Xavier Le Bail
9ea43350e0 Fix a comment 2015-09-06 22:03:23 +02:00
Francois-Xavier Le Bail
71d0745d3d Printers must use ndo_error() function (via ndo->ndo_error) 2015-09-05 20:20:57 +02:00
Francois-Xavier Le Bail
2a59f8ece9 interface.h,netdissect.h: Cleaning unused items 2015-07-03 11:57:31 +02:00