Commit Graph

84 Commits

Author SHA1 Message Date
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
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
46efa1bc47 Fix spaces 2018-09-03 15:18:19 +02:00
Francois-Xavier Le Bail
dc8ce203b3 NTP: Fix UTC/GMT timestamps printing according to RFC3339
Add the "Z" suffix for UTC.

According to the RFC3339:
      Z           A suffix which, when applied to a time, denotes a UTC
                  offset of 00:00; often spoken "Zulu" from the ICAO
                  phonetic alphabet representation of the letter "Z".

Update the output of some tests accordingly.
2018-08-14 14:12:56 +02:00
Francois-Xavier Le Bail
4938de657c NTP: Fix extracting the poll value
Use EXTRACT_S_1 for ppoll (signed).
2018-05-20 08:13:27 +02:00
Francois-Xavier Le Bail
45ecddd334 Fix space printing with istr[]
Because istr[] is assign to " (invalid)", avoid adding a space before it.

Moreover:
Avoid also useless '\n'
2018-05-18 10:03:59 +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
Guy Harris
a0f4e3003e Do time stamp deltas with unsigned arithmetic.
First, check whether the originate timestamp is greater than the other
timestamp and, if so, calculate (originate - other) and print a -
instead of a + before it.  This means we're not trying to stuff the
difference between two unsigned values into a signed value of the same
width (the result of which is undefined if the difference doesn't fit in
the signed variable).
2018-02-02 18:26:50 -08:00
Guy Harris
0dad1934af Have ip{6}addr_string take a u_char * as the second argument.
Fix warnings that introduces.
2018-01-31 00:43:45 -08:00
Francois-Xavier Le Bail
f2cccbe6ae NTP: Replace ND_TCHECK calls by ND_TCHECK_SIZE calls 2018-01-22 20:34:35 +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
10f1fe5fd8 Check against various modes explicitly.
This avoids a "comparison is always true" warning when checking whether
mode is >= MODE_UNSPEC.
2018-01-14 14:20:30 -08:00
Guy Harris
64677b0d78 Clean up signed vs. unsigned. 2018-01-11 11:52:30 -08:00
Francois-Xavier Le Bail
efe7986983 Remove unneeded '&' when getting a pointer to an nd_uintN_t type
They are arrays.
2018-01-08 16:45:59 +01:00
Francois-Xavier Le Bail
b079a3fa93 NTP: Use more ND_TCHECK_n() macros 2018-01-07 21:25:49 +01:00
Francois-Xavier Le Bail
e2982e7f6f Update ND_PRINT() as a variadic macro 2018-01-07 13:36:41 +01:00
Francois-Xavier Le Bail
8bd200e5a3 NTP: Replace ND_TCHECK2 calls by ND_TCHECK_LEN calls 2017-12-14 22:32:15 +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
76015fad3b C99 type, not BSD type; use uint8_t. 2017-12-13 09:39:43 -08:00
Francois-Xavier Le Bail
84ef17ac0e Replace ND_TTEST2()/ND_TCHECK2() macros by macros using pointers (1/n)
ND_TTEST2(var, l)  -> ND_TTEST_LEN(p, l)
ND_TCHECK2(var, l) -> ND_TCHECK_LEN(p, l)
2017-12-11 22:11:01 +01: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
893b1b1cfb Make the delta between 1970 and 1900 a 64-bit signed integral constant.
It doesn't fit in a 32-bit signed integral constant, so make sure it's
64-bit; the only use is to subtract it from a 64-bit signed integral
value.
2017-09-21 10:05:33 -07:00
Guy Harris
0aa9e5a417 Fix handling of NTP time stamps.
The seconds value in a 64-bit NTP timestamp is unsigned.  Treat it as
such.

When converting it to a UN*X seconds-since-the-Epoch, cast the 32-bit
seconds value from an NTP timestap to a 64-bit signed value (which is
always possible), and then subtract the signed delta between 1900 and
1970, giving a signed seconds-since-the-Epoch value.

Then assign that to a time_t; if that variable doesn't have the same
value as the calculated 64-bit value, we can't represent it in a time_t,
so just report it as unrepresentable.

Otherwise, use that resulting value in a gmtime() call - and make sure
gmtime() doesn't return NULL, which it can do with some versions of the
Microsoft C runtime.  If it does, report the time as unrepresentable,
otherwise report it as YYYY-MM-DDTHH:MM:SS.

This fixes the 32-bit vs. 64-bit issue for tests.

It also changes the test output, so update that.
2017-09-20 19:17:22 -07:00
Guy Harris
56f5180267 Actually, the UNALIGNED might not be necessary. 2017-09-20 11:20:36 -07:00
Denis Ovsienko
4d42441161 NTP: Remove some duplicate output.
In ntp_time_print() do not print the information already printed in
ntp_print(): mode, leap indicator, version (all part of the Status
header field) and length. Update the test case.
2017-09-20 14:40:18 +01:00
Guy Harris
c7b0738460 Try marking structures as UNALIGNED.
See if this fixes the crashes on the OpenCSW SPARC buildbots.  If so, it
means that the compiler may think that even structures made up of
nothing but bytes (char/unsigned char) and arrays of bytes are aligned,
even if there's no guarantee of that.

(Bad compiler!  No biscuit!)
2017-09-20 01:37:35 -07:00
Denis Ovsienko
80deba151a NTP: Add missing bounds checks.
This change adds checks that were missing from the recent NTP code and
could cause a buffer over-read vulnerability (see earlier commits for
rationale).
2017-09-04 12:40:36 +01:00
Denis Ovsienko
0dd013253d NTP: Update length checks after the recent commit.
Rename NTP_MSG_MINLEN to NTP_TIMEMSG_MINLEN for clarity and introduce and
use NTP_CTRLMSG_MINLEN. With this change ntp_control_print() can detect
invalid packets better.
2017-09-04 12:31:26 +01:00
Denis Ovsienko
60128eebca NTP: Use nd_XXXXX integer types in the structures.
This prevents alignment issues when the structures are used to access
the input buffer (see earlier commits for more detailed rationale).
2017-09-04 12:31:20 +01:00
Denis Ovsienko
febd0bc5aa NTP: Use tstr for truncation indicator.
This implements the same convention as in all other decoders.
2017-09-04 12:30:20 +01:00
Ulrich Windl
c2e2a18f27 print-ntp.c: Handle NTP Control Messages
In print-ntp.c:
Rename struct ntpdata into struct ntp_time_data and add new
struct ntp_control_data to map NTP Control messages.

Add figure of NTP Control Message Header as comment.

Add union ntpdata to provide a common view on NTP messages.

Rename ntp_print() to ntp_time_print(), using new structures.
Improve comment and re-arrange fields in ntp_print().

Add ntp_control_print() to handle NTP Control Messages.
Output R, E, M, OpCode, Sequence, Status, Assoc, Offset, and Count in
ntp_control_print().

A new ntp_print() will decode only the very basics (VN, LI and Mode)
to call ntp_time_print() or ntp_control_print(), depending on Mode.
2017-09-04 11:52:16 +01:00
Guy Harris
c78c621010 Squelch a warning.
poll() is a system API on UN*Xes, so calling a variable "poll" causes
"declaration of 'poll' shadows a global declaration" warnings in some
compilers.  Call the argument "poll_interval" instead.
2017-09-04 00:42:14 -07:00
Denis Ovsienko
0559dc9874 NTP: Improve length checks.
In ntp_print() add a missing length check to reject packets that are
declared too short, make the existing length checks easier to follow and
add a catch-all block after the known message layouts.

This fixes a bug where an invalid packet could be erroneously printed
like it is valid so long as the provided buffer was large enough. That
said, the bounds checks were done correctly so there was no over-read.
2017-08-30 13:53:56 +01:00
Miroslav Lichvar
bd3f9392a6 Print NTP MAC with 160-bit digest.
An NTP packet authenticated with a key using stronger hash function than
MD5 may have a 160-bit digest.
2017-08-30 12:57:17 +01:00
Ulrich Windl
99412d6d5a Print NTP timestamps as UTC, not local time
print-ntp.c: Change p_ntp_time() to print NTP timestamps in UTC instead
of local time.  This allows for consistent output for automatic testing
different time zones.  Also use an ISO 8601 (RFC3339) format for the
time stamps.
2017-08-29 14:47:51 +01:00
Ulrich Windl
1136bb5c53 Prepare print-ntp.c for NTP Control Messages
Add shift constants LEAPSHIFT(6) and MODESHIFT(0).
Rename MODE_RES1 to MODE_CONTROL, adjusting ntp_mode_values[].
2017-08-29 14:46:03 +01:00
Ulrich Windl
b1ee9bac52 print-ntp.c: Add and use VERSIONSHIFT
Add shift constant VERSIONSHIFT(3), and use it in ntp_print().
2017-08-29 14:45:24 +01:00
Denis Ovsienko
688ac7b668 NTP: For clarity use 0x with hexadecimal format. 2017-08-29 12:03:05 +01:00
Miroslav Lichvar
a4ea3caa57 Fix printing of NTP key-id.
The key-id in an NTP MAC is in big-endian format.
2017-08-29 12:42:10 +02:00
Miroslav Lichvar
d729c670fc Print NTP refid as hexadecimal number.
In NTPv4 (RFC 5905) the refid field for stratum > 1 is an IPv4 address
or first 32 bits of MD5 sum of an IPv6 address. It's not possible to
tell which of the two it actually is. Print the field as a hexadecimal
number in order to not confuse refids generated from IPv6 addresses with
IPv4 addresses.
2017-08-29 12:37:58 +02:00
Miroslav Lichvar
63c8c04ea7 Fix printing of NTP poll interval.
The poll value in an NTP packet is a signed integer. For negative values
print the interval as a fraction of second. Also, ignore values outside
of interval (-32, 32).
2017-08-29 12:37:58 +02:00
Francois-Xavier Le Bail
b38f324af9 Add a summary comment in all other printers
Moreover:
Remove some redundant comments
Update some summary comments
Update the specification URL for ATA over Ethernet (AoE) protocol
2016-08-15 22:42:38 +02: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
ff1df423b6 Use double rather than float.
That means we can fit a 32-bit integer into a floating-point value
without losing precision.

Also, put in explicit casts when we convert a floating-point value to an
integral value, to suppress compiler warnings.
2015-09-14 15:12:28 -07:00
Guy Harris
9883c76d12 Consistently use float constants. 2015-09-14 15:06:33 -07:00