Commit Graph

70 Commits

Author SHA1 Message Date
Denis Ovsienko
cfa9ab5f80 Try the new ND_LCHECK*() macros. [skip ci] 2021-01-17 23:11:19 +00:00
Denis Ovsienko
db3c742cd7 RIP: Modernize packet parsing style.
Enable ND_LONGJMP_FROM_TCHECK. Report invalid packets as invalid. Remove
two redundant ND_TCHECK_SIZE() instances and an improvised snapshot end
guard. Check bounds for the remaining part of the packet header after
printing version and command, not before. Lose one pointer and one
length variable in rip_print(), also account for the header size when
estimating the number of routes. Update two tests.
2021-01-14 03:48:28 +00:00
Denis Ovsienko
4352d30878 RIP: Make a couple trivial protocol updates.
Synchronize with the RIP Commands IANA registry and treat version 0 as
invalid.
2021-01-14 03:33:11 +00:00
Francois-Xavier Le Bail
d9893474ee RIP: Replace the 'if (nd_printzp()) return' by nd_printjnp() call 2020-12-10 22:24:04 +01:00
Denis Ovsienko
b5cbb4d2bb Lose some more unnecessary #include lines. [skip ci]
This trivial change compiles fine with GCC 7.5.0 on Linux and Clang
10.0.1 on FreeBSD, so let's not run the full round of CI this time.
2020-11-27 16:18:40 +00: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
Guy Harris
07a7f33ba3 Fix some narrowing warnings on LP64/LLP64 platforms.
Add a ND_BYTES_AVAILABLE_AFTER() macro to find the number of bytes
available in the captured data, starting at the byte pointed to by the
argument.  It returns a u_int rather than a ptrdiff_t, so it'll be
32 bits on LP64 and LLP64 platforms as well as on ILP32 platforms.  Use
that macro.

Make size-of-buffer arguments size_t.

Cast some size_t and ptrdiff_t values to u_int or int.
2019-04-18 10:13:49 -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
Francois-Xavier Le Bail
8270847a43 RIP: Update two error messages
Update the output of a test accordingly.
2019-03-20 13:49:53 +01:00
Francois-Xavier Le Bail
59868ef671 RIP: Fix two loops for undefined behavior at runtime
1) RIPv2
The error was:
print-rip.c:386:9: runtime error: unsigned integer overflow: 16 - 20
cannot be represented in type 'unsigned int'

Without this change the unsigned integer variable 'len' is assigned a
very high value, because of underflow, and the loop continue incorrectly.

Add a test case.

2) RIPv1
Same bugfix, based on a code inspection, so comes without a test case.
2019-03-09 15:13:51 +01:00
Francois-Xavier Le Bail
8e41caf1e7 RIP: Fix inaccurate variable names 2019-03-08 15:52:07 +01:00
Francois-Xavier Le Bail
45f96d1da2 Clean up whitespaces/indentation 2019-03-08 15:26:45 +01:00
Francois-Xavier Le Bail
f112cfa823 RIP: Add some bounds checks 2018-06-20 09:09:14 +02:00
Francois-Xavier Le Bail
ba8936b39b Print truncations with nd_print_trunc() instead of tstr[] strings
Remove the tstr[] strings.
Update the output of some tests accordingly.

Moreover:
Add or update some ndo_protocol fields.
2018-05-04 13:47:49 +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
77ece6d435 Remove unneeded '&' when getting a pointer to a nd_ipv4 type 2018-01-31 08:31:16 +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
7561a525e4 Change the way we dissect non-routing-entry entries.
This should fix Coverity CID 1427593.

It also uses fn_printzp() to print plain text passwords, rather than
rolling its own code, and doesn't try to print anything from versions
other than 1 and 2 other than the version number.
2018-01-15 11:00:45 -08:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Guy Harris
e022dd7799 Use nd_ types, add EXTRACT_ calls. 2017-12-30 18:22:28 -08: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
Francois-Xavier Le Bail
8094b3bdfb Use more the EXTRACT_U_1() macro (54/n) 2017-12-10 19:26:45 +01:00
Francois-Xavier Le Bail
7199dd316f Use more the EXTRACT_U_1() macro (38/n)
In some ND_ISPRINT() macro calls.
2017-12-01 10:27:42 +01:00
Francois-Xavier Le Bail
f085c93f59 Use more the EXTRACT_U_1() macro (31/n)
In ND_PRINT() macro call(s) (step 9).

*(p)
2017-11-27 20:57:24 +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
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
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
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
b638c78b40 Remove obsolete comments 2015-09-07 15:01:46 +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
Guy Harris
ed85e20e4d u_intN_t is dead, long live uintN_t.
And, as we require at least autoconf 2.61, and as autoconf 2.61 and
later have AC_TYPE_UINTn_T and AC_TYPE_INTn_T macros, we use them to
define the uintN_t and intN_t macros if the system doesn't define them
for us.

This lets us get rid of bitypes.h as well.
2014-04-23 00:20:40 -07: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
f274a23dc1 improve previous NDO conversions 2014-04-03 17:41:02 +04:00
Denis Ovsienko
17934c433e NDOize 7 bigger decoders
This change converts IGMP, IPv6 mobility options, LDP, Lightweight
Access Point, PGM, PPTP and RIP decoders.
2014-03-19 14:16:56 +04:00
Guy Harris
3454732513 Do our own isascii(), isprint(), isgraph(), and toascii().
We do *not* want the behavior of isprint() and isgraph() to be
locale-dependent - we want both of them to return "true" only for ASCII
characters.

We have to do our own isascii() and toascii() on non-UN*X systems
anyway, so let's just do all of them ourselves.
2014-02-02 15:17:06 -08: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
Michael Richardson
ac910c086e ndo-ize print-ascii: hex_print_with_offset() 2014-01-01 21:31:18 -05:00
Michael Richardson
a97fb2f3ae whitespace changes 2014-01-01 21:31:18 -05:00
Denis Ovsienko
d8acd8f5d0 make consistent use of the "tstr" idiom
For each decoder that has more than one instance of truncation signaling
and prints the same string in each instance make sure that the string is
declared as "static const char tstr[]" right after the initial includes
block. Where necessary, replace fputs(s, stdout) with equivalent
printf("%s", s).
2013-12-26 18:19:50 +04:00
Xin Li
16405d7d92 Use byte offset instead of rip_dest (a 32-bit field) to extract
16-bit field in order to avoid type punning.  This fixes compile
on IA64 platforms.
2013-05-31 13:53:40 -07:00
Denis Ovsienko
33808c6690 decode RIPv2 authentication up to RFC4822
This change addresses a few issues in rip_entry_print_v2() and
rip_print():

1. In the case of Simple Password (RFC2453) authentication the last
(16th) character of a password was never printed. Other password
characters were printed regardless of existing isprint() test.

2. In the case of Cryptographic (RFC4822) authentication there were no
details available for fixed-size auth header and variable-size auth
trailer.

3. Depending on particular hash function used, a normal authentication
trailer "RTE" may be 20 or more bytes long. Iteration over packet RTEs
should stop once a trailer is decoded. Exact number of RTEs in a message
cannot be told from message size any more.

Test cases are added for Request and Response messages with Simple
Password, Keyed-MD5, HMAC-SHA-1, HMAC-SHA-256, HMAC-SHA-384 and
HMAC-SHA-512 authentication modes. Earlier test case is updated to match
new "number of routes" output format.
2012-06-12 14:10:05 +04:00
Denis Ovsienko
c4830eb85e fix RIP Request/full table decoding issues
RIP Request and Response messages have the same structure. Update a
switch block in rip_print() to proceed with decoding of both.

A Request message may contain an AFI 0 RTE standing for a full table
request, normally sent on a router start. Update rip_entry_print_v1()
and rip_entry_print_v2() to treat IPv4 and AFI 0 as two valid,
distinguishable cases.
2012-06-12 13:59:06 +04:00
hannes
5636348412 move the BSD AF defs into af.h and make the null and rip printer make use of it 2006-03-23 14:58:44 +00:00
hannes
50b4920bc5 move AF specific stuff to dedicated files 2006-02-21 10:27:40 +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