2016-07-29 03:09:41 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Antonin Décimo, Jean-Raphaël Gaglione
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-08-15 21:27:28 +08:00
|
|
|
/* \summary: Home Networking Control Protocol (HNCP) printer */
|
|
|
|
|
2016-07-29 03:09:41 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2016-07-29 03:09:41 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2016-07-29 03:09:41 +08:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "netdissect.h"
|
|
|
|
#include "addrtoname.h"
|
|
|
|
#include "extract.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
hncp_print_rec(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int length, int indent);
|
|
|
|
|
|
|
|
void
|
|
|
|
hncp_print(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int length)
|
|
|
|
{
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "hncp";
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("hncp (%u)", length);
|
2016-07-29 03:09:41 +08:00
|
|
|
hncp_print_rec(ndo, cp, length, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RFC7787 */
|
|
|
|
#define DNCP_REQUEST_NETWORK_STATE 1
|
|
|
|
#define DNCP_REQUEST_NODE_STATE 2
|
|
|
|
#define DNCP_NODE_ENDPOINT 3
|
|
|
|
#define DNCP_NETWORK_STATE 4
|
|
|
|
#define DNCP_NODE_STATE 5
|
|
|
|
#define DNCP_PEER 8
|
|
|
|
#define DNCP_KEEP_ALIVE_INTERVAL 9
|
|
|
|
#define DNCP_TRUST_VERDICT 10
|
|
|
|
|
|
|
|
/* RFC7788 */
|
|
|
|
#define HNCP_HNCP_VERSION 32
|
|
|
|
#define HNCP_EXTERNAL_CONNECTION 33
|
|
|
|
#define HNCP_DELEGATED_PREFIX 34
|
|
|
|
#define HNCP_PREFIX_POLICY 43
|
2017-09-14 03:43:00 +08:00
|
|
|
#define HNCP_DHCPV4_DATA 37 /* This is correct, see RFC 7788 Errata ID 5113. */
|
|
|
|
#define HNCP_DHCPV6_DATA 38 /* idem */
|
2016-07-29 03:09:41 +08:00
|
|
|
#define HNCP_ASSIGNED_PREFIX 35
|
|
|
|
#define HNCP_NODE_ADDRESS 36
|
|
|
|
#define HNCP_DNS_DELEGATED_ZONE 39
|
|
|
|
#define HNCP_DOMAIN_NAME 40
|
|
|
|
#define HNCP_NODE_NAME 41
|
|
|
|
#define HNCP_MANAGED_PSK 42
|
|
|
|
|
|
|
|
/* See type_mask in hncp_print_rec below */
|
|
|
|
#define RANGE_DNCP_RESERVED 0x10000
|
|
|
|
#define RANGE_HNCP_UNASSIGNED 0x10001
|
|
|
|
#define RANGE_DNCP_PRIVATE_USE 0x10002
|
|
|
|
#define RANGE_DNCP_FUTURE_USE 0x10003
|
|
|
|
|
|
|
|
static const struct tok type_values[] = {
|
|
|
|
{ DNCP_REQUEST_NETWORK_STATE, "Request network state" },
|
|
|
|
{ DNCP_REQUEST_NODE_STATE, "Request node state" },
|
|
|
|
{ DNCP_NODE_ENDPOINT, "Node endpoint" },
|
|
|
|
{ DNCP_NETWORK_STATE, "Network state" },
|
|
|
|
{ DNCP_NODE_STATE, "Node state" },
|
|
|
|
{ DNCP_PEER, "Peer" },
|
|
|
|
{ DNCP_KEEP_ALIVE_INTERVAL, "Keep-alive interval" },
|
|
|
|
{ DNCP_TRUST_VERDICT, "Trust-Verdict" },
|
|
|
|
|
|
|
|
{ HNCP_HNCP_VERSION, "HNCP-Version" },
|
|
|
|
{ HNCP_EXTERNAL_CONNECTION, "External-Connection" },
|
|
|
|
{ HNCP_DELEGATED_PREFIX, "Delegated-Prefix" },
|
|
|
|
{ HNCP_PREFIX_POLICY, "Prefix-Policy" },
|
|
|
|
{ HNCP_DHCPV4_DATA, "DHCPv4-Data" },
|
|
|
|
{ HNCP_DHCPV6_DATA, "DHCPv6-Data" },
|
|
|
|
{ HNCP_ASSIGNED_PREFIX, "Assigned-Prefix" },
|
|
|
|
{ HNCP_NODE_ADDRESS, "Node-Address" },
|
|
|
|
{ HNCP_DNS_DELEGATED_ZONE, "DNS-Delegated-Zone" },
|
|
|
|
{ HNCP_DOMAIN_NAME, "Domain-Name" },
|
|
|
|
{ HNCP_NODE_NAME, "Node-Name" },
|
|
|
|
{ HNCP_MANAGED_PSK, "Managed-PSK" },
|
|
|
|
|
|
|
|
{ RANGE_DNCP_RESERVED, "Reserved" },
|
|
|
|
{ RANGE_HNCP_UNASSIGNED, "Unassigned" },
|
|
|
|
{ RANGE_DNCP_PRIVATE_USE, "Private use" },
|
|
|
|
{ RANGE_DNCP_FUTURE_USE, "Future use" },
|
|
|
|
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DH4OPT_DNS_SERVERS 6 /* RFC2132 */
|
|
|
|
#define DH4OPT_NTP_SERVERS 42 /* RFC2132 */
|
|
|
|
#define DH4OPT_DOMAIN_SEARCH 119 /* RFC3397 */
|
|
|
|
|
|
|
|
static const struct tok dh4opt_str[] = {
|
|
|
|
{ DH4OPT_DNS_SERVERS, "DNS-server" },
|
|
|
|
{ DH4OPT_NTP_SERVERS, "NTP-server"},
|
|
|
|
{ DH4OPT_DOMAIN_SEARCH, "DNS-search" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DH6OPT_DNS_SERVERS 23 /* RFC3646 */
|
|
|
|
#define DH6OPT_DOMAIN_LIST 24 /* RFC3646 */
|
|
|
|
#define DH6OPT_SNTP_SERVERS 31 /* RFC4075 */
|
|
|
|
|
|
|
|
static const struct tok dh6opt_str[] = {
|
|
|
|
{ DH6OPT_DNS_SERVERS, "DNS-server" },
|
|
|
|
{ DH6OPT_DOMAIN_LIST, "DNS-search-list" },
|
|
|
|
{ DH6OPT_SNTP_SERVERS, "SNTP-servers" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2016-10-31 02:15:40 +08:00
|
|
|
/*
|
|
|
|
* For IPv4-mapped IPv6 addresses, length of the prefix that precedes
|
|
|
|
* the 4 bytes of IPv4 address at the end of the IPv6 address.
|
|
|
|
*/
|
|
|
|
#define IPV4_MAPPED_HEADING_LEN 12
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is an IPv6 address an IPv4-mapped address?
|
|
|
|
*/
|
2018-01-26 22:15:58 +08:00
|
|
|
static int
|
2016-10-31 02:15:40 +08:00
|
|
|
is_ipv4_mapped_address(const u_char *addr)
|
|
|
|
{
|
|
|
|
/* The value of the prefix */
|
|
|
|
static const u_char ipv4_mapped_heading[IPV4_MAPPED_HEADING_LEN] =
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF };
|
|
|
|
|
|
|
|
return memcmp(addr, ipv4_mapped_heading, IPV4_MAPPED_HEADING_LEN) == 0;
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:09:41 +08:00
|
|
|
static const char *
|
|
|
|
format_nid(const u_char *data)
|
|
|
|
{
|
HNCP: refine snprintf() buffers sizing
This squelches a warning in format_256(), make a similar change to
format_nid() while at it.
$ gcc --version
gcc (GCC) 7.1.1 20170622 (Red Hat 7.1.1-3)
./print-hncp.c: In function ‘format_256’:
./print-hncp.c:175:26: warning: ‘%016lx’ directive output truncated writing 16 bytes into a region of size 12 [-Wformat-truncation=]
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~
./print-hncp.c:175:41: note: format string is defined here
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
./print-hncp.c:175:5: note: ‘snprintf’ output 65 bytes into a destination of size 28
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data),
~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 8),
~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 16),
~~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 24)
~~~~~~~~~~~~~~~~~~~~~~~~~
);
~
2017-07-21 03:58:06 +08:00
|
|
|
static char buf[4][sizeof("01:01:01:01")];
|
2016-07-29 03:09:41 +08:00
|
|
|
static int i = 0;
|
|
|
|
i = (i + 1) % 4;
|
2018-01-30 07:48:55 +08:00
|
|
|
nd_snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x",
|
2017-12-01 22:19:56 +08:00
|
|
|
EXTRACT_U_1(data), EXTRACT_U_1(data + 1), EXTRACT_U_1(data + 2),
|
|
|
|
EXTRACT_U_1(data + 3));
|
2016-07-29 03:09:41 +08:00
|
|
|
return buf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
format_256(const u_char *data)
|
|
|
|
{
|
HNCP: refine snprintf() buffers sizing
This squelches a warning in format_256(), make a similar change to
format_nid() while at it.
$ gcc --version
gcc (GCC) 7.1.1 20170622 (Red Hat 7.1.1-3)
./print-hncp.c: In function ‘format_256’:
./print-hncp.c:175:26: warning: ‘%016lx’ directive output truncated writing 16 bytes into a region of size 12 [-Wformat-truncation=]
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~
./print-hncp.c:175:41: note: format string is defined here
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
./print-hncp.c:175:26: note: using the range [0, 18446744073709551615] for directive argument
./print-hncp.c:175:5: note: ‘snprintf’ output 65 bytes into a destination of size 28
snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data),
~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 8),
~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 16),
~~~~~~~~~~~~~~~~~~~~~~~~~~
EXTRACT_64BITS(data + 24)
~~~~~~~~~~~~~~~~~~~~~~~~~
);
~
2017-07-21 03:58:06 +08:00
|
|
|
static char buf[4][sizeof("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")];
|
2016-07-29 03:09:41 +08:00
|
|
|
static int i = 0;
|
|
|
|
i = (i + 1) % 4;
|
2018-01-30 07:48:55 +08:00
|
|
|
nd_snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_8(data),
|
|
|
|
EXTRACT_BE_U_8(data + 8),
|
|
|
|
EXTRACT_BE_U_8(data + 16),
|
|
|
|
EXTRACT_BE_U_8(data + 24)
|
2016-07-29 03:09:41 +08:00
|
|
|
);
|
|
|
|
return buf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2016-08-18 22:02:16 +08:00
|
|
|
format_interval(const uint32_t n)
|
2016-07-29 03:09:41 +08:00
|
|
|
{
|
2016-08-18 22:02:16 +08:00
|
|
|
static char buf[4][sizeof("0000000.000s")];
|
2016-07-29 03:09:41 +08:00
|
|
|
static int i = 0;
|
|
|
|
i = (i + 1) % 4;
|
2018-01-30 07:48:55 +08:00
|
|
|
nd_snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000);
|
2016-07-29 03:09:41 +08:00
|
|
|
return buf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
format_ip6addr(netdissect_options *ndo, const u_char *cp)
|
|
|
|
{
|
2016-10-31 02:15:40 +08:00
|
|
|
if (is_ipv4_mapped_address(cp))
|
|
|
|
return ipaddr_string(ndo, cp + IPV4_MAPPED_HEADING_LEN);
|
2016-07-29 03:09:41 +08:00
|
|
|
else
|
|
|
|
return ip6addr_string(ndo, cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
|
|
|
|
{
|
|
|
|
int plenbytes;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")];
|
|
|
|
|
2017-12-04 04:12:03 +08:00
|
|
|
if (EXTRACT_U_1(prefix) >= 96 && max_length >= IPV4_MAPPED_HEADING_LEN + 1 &&
|
2017-11-26 00:14:34 +08:00
|
|
|
is_ipv4_mapped_address(prefix + 1)) {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
struct in_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
2017-12-10 00:15:55 +08:00
|
|
|
plen = EXTRACT_U_1(prefix) - 96;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (32 < plen)
|
|
|
|
return -1;
|
|
|
|
max_length -= 1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
plenbytes = (plen + 7) / 8;
|
2016-10-31 02:15:40 +08:00
|
|
|
if (max_length < (u_int)plenbytes + IPV4_MAPPED_HEADING_LEN)
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
return -3;
|
2017-12-02 21:56:12 +08:00
|
|
|
memcpy(&addr, prefix + IPV4_MAPPED_HEADING_LEN + 1, plenbytes);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (plen % 8) {
|
|
|
|
((u_char *)&addr)[plenbytes - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
2018-01-31 16:43:45 +08:00
|
|
|
nd_snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), plen);
|
2016-10-31 02:15:40 +08:00
|
|
|
plenbytes += 1 + IPV4_MAPPED_HEADING_LEN;
|
2016-07-29 03:09:41 +08:00
|
|
|
} else {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf));
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", buf);
|
2016-07-29 03:09:41 +08:00
|
|
|
return plenbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_dns_label(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int max_length, int print)
|
|
|
|
{
|
|
|
|
u_int length = 0;
|
|
|
|
while (length < max_length) {
|
2017-12-09 19:32:00 +08:00
|
|
|
u_int lab_length = EXTRACT_U_1(cp + length);
|
|
|
|
length++;
|
2016-07-29 03:09:41 +08:00
|
|
|
if (lab_length == 0)
|
|
|
|
return (int)length;
|
|
|
|
if (length > 1 && print)
|
|
|
|
safeputchar(ndo, '.');
|
|
|
|
if (length+lab_length > max_length) {
|
|
|
|
if (print)
|
|
|
|
safeputs(ndo, cp+length, max_length-length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (print)
|
|
|
|
safeputs(ndo, cp+length, lab_length);
|
|
|
|
length += lab_length;
|
|
|
|
}
|
|
|
|
if (print)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[|DNS]");
|
2016-07-29 03:09:41 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dhcpv4_print(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int length, int indent)
|
|
|
|
{
|
|
|
|
u_int i, t;
|
2017-09-15 18:57:50 +08:00
|
|
|
const uint8_t *tlv, *value;
|
2016-07-29 03:09:41 +08:00
|
|
|
uint8_t type, optlen;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < length) {
|
2017-07-30 04:45:35 +08:00
|
|
|
if (i + 2 > length)
|
|
|
|
return -1;
|
2016-07-29 03:09:41 +08:00
|
|
|
tlv = cp + i;
|
2017-12-09 19:32:00 +08:00
|
|
|
type = EXTRACT_U_1(tlv);
|
|
|
|
optlen = EXTRACT_U_1(tlv + 1);
|
2016-07-29 03:09:41 +08:00
|
|
|
value = tlv + 2;
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n");
|
2016-07-29 03:09:41 +08:00
|
|
|
for (t = indent; t > 0; t--)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\t");
|
2016-07-29 03:09:41 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", tok2str(dh4opt_str, "Unknown", type));
|
|
|
|
ND_PRINT(" (%u)", optlen + 2 );
|
2017-07-30 04:45:35 +08:00
|
|
|
if (i + 2 + optlen > length)
|
|
|
|
return -1;
|
2016-07-29 03:09:41 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DH4OPT_DNS_SERVERS:
|
|
|
|
case DH4OPT_NTP_SERVERS: {
|
|
|
|
if (optlen < 4 || optlen % 4 != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (t = 0; t < optlen; t += 4)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", ipaddr_string(ndo, value + t));
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DH4OPT_DOMAIN_SEARCH: {
|
|
|
|
const u_char *tp = value;
|
|
|
|
while (tp < value + optlen) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2016-07-29 03:09:41 +08:00
|
|
|
if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 2 + optlen;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dhcpv6_print(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int length, int indent)
|
|
|
|
{
|
|
|
|
u_int i, t;
|
|
|
|
const u_char *tlv, *value;
|
|
|
|
uint16_t type, optlen;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < length) {
|
2017-07-30 01:52:38 +08:00
|
|
|
if (i + 4 > length)
|
|
|
|
return -1;
|
2016-07-29 03:09:41 +08:00
|
|
|
tlv = cp + i;
|
2017-11-23 06:54:09 +08:00
|
|
|
type = EXTRACT_BE_U_2(tlv);
|
|
|
|
optlen = EXTRACT_BE_U_2(tlv + 2);
|
2016-07-29 03:09:41 +08:00
|
|
|
value = tlv + 4;
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n");
|
2016-07-29 03:09:41 +08:00
|
|
|
for (t = indent; t > 0; t--)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\t");
|
2016-07-29 03:09:41 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", tok2str(dh6opt_str, "Unknown", type));
|
|
|
|
ND_PRINT(" (%u)", optlen + 4 );
|
2017-07-30 01:52:38 +08:00
|
|
|
if (i + 4 + optlen > length)
|
|
|
|
return -1;
|
2016-07-29 03:09:41 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DH6OPT_DNS_SERVERS:
|
|
|
|
case DH6OPT_SNTP_SERVERS: {
|
|
|
|
if (optlen % 16 != 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
2016-07-29 03:09:41 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (t = 0; t < optlen; t += 16)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", ip6addr_string(ndo, value + t));
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DH6OPT_DOMAIN_LIST: {
|
|
|
|
const u_char *tp = value;
|
|
|
|
while (tp < value + optlen) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2016-07-29 03:09:41 +08:00
|
|
|
if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 4 + optlen;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine in-line mode */
|
|
|
|
static int
|
|
|
|
is_in_line(netdissect_options *ndo, int indent)
|
|
|
|
{
|
|
|
|
return indent - 1 >= ndo->ndo_vflag && ndo->ndo_vflag < 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_type_in_line(netdissect_options *ndo,
|
|
|
|
uint32_t type, int count, int indent, int *first_one)
|
|
|
|
{
|
|
|
|
if (count > 0) {
|
|
|
|
if (*first_one) {
|
|
|
|
*first_one = 0;
|
|
|
|
if (indent > 1) {
|
|
|
|
u_int t;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n");
|
2016-07-29 03:09:41 +08:00
|
|
|
for (t = indent; t > 0; t--)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\t");
|
2016-07-29 03:09:41 +08:00
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", ");
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", tok2str(type_values, "Easter Egg", type));
|
2016-07-29 03:09:41 +08:00
|
|
|
if (count > 1)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (x%d)", count);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:09:34 +08:00
|
|
|
static void
|
2016-07-29 03:09:41 +08:00
|
|
|
hncp_print_rec(netdissect_options *ndo,
|
|
|
|
const u_char *cp, u_int length, int indent)
|
|
|
|
{
|
|
|
|
const int in_line = is_in_line(ndo, indent);
|
|
|
|
int first_one = 1;
|
|
|
|
|
|
|
|
u_int i, t;
|
|
|
|
|
2016-08-10 21:41:20 +08:00
|
|
|
uint32_t last_type_mask = 0xffffffffU;
|
2016-07-29 03:09:41 +08:00
|
|
|
int last_type_count = -1;
|
|
|
|
|
2017-09-15 18:57:50 +08:00
|
|
|
const uint8_t *tlv, *value;
|
2016-07-29 03:09:41 +08:00
|
|
|
uint16_t type, bodylen;
|
|
|
|
uint32_t type_mask;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < length) {
|
|
|
|
tlv = cp + i;
|
|
|
|
|
|
|
|
if (!in_line) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n");
|
2016-07-29 03:09:41 +08:00
|
|
|
for (t = indent; t > 0; t--)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\t");
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
|
2017-11-25 03:44:53 +08:00
|
|
|
ND_TCHECK_4(tlv);
|
2016-07-29 03:09:41 +08:00
|
|
|
if (i + 4 > length)
|
|
|
|
goto invalid;
|
|
|
|
|
2017-11-23 06:54:09 +08:00
|
|
|
type = EXTRACT_BE_U_2(tlv);
|
|
|
|
bodylen = EXTRACT_BE_U_2(tlv + 2);
|
2016-07-29 03:09:41 +08:00
|
|
|
value = tlv + 4;
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(value, bodylen);
|
2016-07-29 03:09:41 +08:00
|
|
|
if (i + bodylen + 4 > length)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
type_mask =
|
|
|
|
(type == 0) ? RANGE_DNCP_RESERVED:
|
|
|
|
(44 <= type && type <= 511) ? RANGE_HNCP_UNASSIGNED:
|
|
|
|
(768 <= type && type <= 1023) ? RANGE_DNCP_PRIVATE_USE:
|
|
|
|
RANGE_DNCP_FUTURE_USE;
|
|
|
|
if (type == 6 || type == 7)
|
|
|
|
type_mask = RANGE_DNCP_FUTURE_USE;
|
|
|
|
|
|
|
|
/* defined types */
|
|
|
|
{
|
|
|
|
t = 0;
|
|
|
|
while (1) {
|
|
|
|
u_int key = type_values[t++].v;
|
|
|
|
if (key > 0xffff)
|
|
|
|
break;
|
|
|
|
if (key == type) {
|
|
|
|
type_mask = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_line) {
|
|
|
|
if (last_type_mask == type_mask) {
|
|
|
|
last_type_count++;
|
|
|
|
} else {
|
|
|
|
print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
|
|
|
|
last_type_mask = type_mask;
|
|
|
|
last_type_count = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto skip_multiline;
|
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", tok2str(type_values, "Easter Egg (42)", type_mask) );
|
2016-07-29 03:09:41 +08:00
|
|
|
if (type_mask > 0xffff)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(": type=%u", type );
|
|
|
|
ND_PRINT(" (%u)", bodylen + 4 );
|
2016-07-29 03:09:41 +08:00
|
|
|
|
|
|
|
switch (type_mask) {
|
|
|
|
|
|
|
|
case DNCP_REQUEST_NETWORK_STATE: {
|
|
|
|
if (bodylen != 0)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_REQUEST_NODE_STATE: {
|
|
|
|
const char *node_identifier;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 4) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
node_identifier = format_nid(value);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" NID: %s", node_identifier);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_NODE_ENDPOINT: {
|
|
|
|
const char *node_identifier;
|
|
|
|
uint32_t endpoint_identifier;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
node_identifier = format_nid(value);
|
2017-11-23 06:54:09 +08:00
|
|
|
endpoint_identifier = EXTRACT_BE_U_4(value + 4);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" NID: %s EPID: %08x",
|
2016-07-29 03:09:41 +08:00
|
|
|
node_identifier,
|
|
|
|
endpoint_identifier
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_NETWORK_STATE: {
|
|
|
|
uint64_t hash;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-11-23 06:54:09 +08:00
|
|
|
hash = EXTRACT_BE_U_8(value);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" hash: %016" PRIx64, hash);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_NODE_STATE: {
|
2016-08-03 03:59:47 +08:00
|
|
|
const char *node_identifier, *interval;
|
2016-07-29 03:09:41 +08:00
|
|
|
uint32_t sequence_number;
|
|
|
|
uint64_t hash;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 20) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
node_identifier = format_nid(value);
|
2017-11-23 06:54:09 +08:00
|
|
|
sequence_number = EXTRACT_BE_U_4(value + 4);
|
|
|
|
interval = format_interval(EXTRACT_BE_U_4(value + 8));
|
|
|
|
hash = EXTRACT_BE_U_8(value + 12);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" NID: %s seqno: %u %s hash: %016" PRIx64,
|
2016-07-29 03:09:41 +08:00
|
|
|
node_identifier,
|
|
|
|
sequence_number,
|
2016-08-03 03:59:47 +08:00
|
|
|
interval,
|
2016-07-29 03:09:41 +08:00
|
|
|
hash
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
hncp_print_rec(ndo, value+20, bodylen-20, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_PEER: {
|
|
|
|
const char *peer_node_identifier;
|
|
|
|
uint32_t peer_endpoint_identifier, endpoint_identifier;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 12) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
peer_node_identifier = format_nid(value);
|
2017-11-23 06:54:09 +08:00
|
|
|
peer_endpoint_identifier = EXTRACT_BE_U_4(value + 4);
|
|
|
|
endpoint_identifier = EXTRACT_BE_U_4(value + 8);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x",
|
2016-07-29 03:09:41 +08:00
|
|
|
peer_node_identifier,
|
|
|
|
peer_endpoint_identifier,
|
|
|
|
endpoint_identifier
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_KEEP_ALIVE_INTERVAL: {
|
|
|
|
uint32_t endpoint_identifier;
|
|
|
|
const char *interval;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-11-23 06:54:09 +08:00
|
|
|
endpoint_identifier = EXTRACT_BE_U_4(value);
|
|
|
|
interval = format_interval(EXTRACT_BE_U_4(value + 4));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" EPID: %08x Interval: %s",
|
2016-07-29 03:09:41 +08:00
|
|
|
endpoint_identifier,
|
|
|
|
interval
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DNCP_TRUST_VERDICT: {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen <= 36) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" Verdict: %u Fingerprint: %s Common Name: ",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_U_1(value),
|
2018-01-07 18:47:30 +08:00
|
|
|
format_256(value + 4));
|
2016-07-29 03:09:41 +08:00
|
|
|
safeputs(ndo, value + 36, bodylen - 36);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_HNCP_VERSION: {
|
|
|
|
uint16_t capabilities;
|
|
|
|
uint8_t M, P, H, L;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 5) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-11-23 06:54:09 +08:00
|
|
|
capabilities = EXTRACT_BE_U_2(value + 2);
|
2016-07-29 03:09:41 +08:00
|
|
|
M = (uint8_t)((capabilities >> 12) & 0xf);
|
|
|
|
P = (uint8_t)((capabilities >> 8) & 0xf);
|
|
|
|
H = (uint8_t)((capabilities >> 4) & 0xf);
|
|
|
|
L = (uint8_t)(capabilities & 0xf);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" M: %u P: %u H: %u L: %u User-agent: ",
|
2016-07-29 03:09:41 +08:00
|
|
|
M, P, H, L
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
safeputs(ndo, value + 4, bodylen - 4);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_EXTERNAL_CONNECTION: {
|
|
|
|
/* Container TLV */
|
|
|
|
hncp_print_rec(ndo, value, bodylen, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_DELEGATED_PREFIX: {
|
|
|
|
int l;
|
2017-12-02 21:19:13 +08:00
|
|
|
if (bodylen < 9 || bodylen < 9 + (EXTRACT_U_1(value + 8) + 7) / 8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" VLSO: %s PLSO: %s Prefix: ",
|
2017-11-23 06:54:09 +08:00
|
|
|
format_interval(EXTRACT_BE_U_4(value)),
|
|
|
|
format_interval(EXTRACT_BE_U_4(value + 4))
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
l = print_prefix(ndo, value + 8, bodylen - 8);
|
|
|
|
if (l == -1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("(length is invalid)");
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (l < 0) {
|
|
|
|
/*
|
|
|
|
* We've already checked that we've captured the
|
|
|
|
* entire TLV, based on its length, so this will
|
|
|
|
* either be -1, meaning "the prefix length is
|
|
|
|
* greater than the longest possible address of
|
|
|
|
* that type" (i.e., > 32 for IPv4 or > 128 for
|
|
|
|
* IPv6", or -3, meaning "the prefix runs past
|
|
|
|
* the end of the TLV".
|
|
|
|
*/
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
l += 8 + (-l & 3);
|
|
|
|
|
|
|
|
if (bodylen >= l)
|
|
|
|
hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_PREFIX_POLICY: {
|
|
|
|
uint8_t policy;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
int l;
|
|
|
|
if (bodylen < 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-12-09 19:32:00 +08:00
|
|
|
policy = EXTRACT_U_1(value);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" type: ");
|
2016-07-29 03:09:41 +08:00
|
|
|
if (policy == 0) {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Internet connectivity");
|
2016-07-29 03:09:41 +08:00
|
|
|
} else if (policy >= 1 && policy <= 128) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Dest-Prefix: ");
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
l = print_prefix(ndo, value, bodylen);
|
|
|
|
if (l == -1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("(length is invalid)");
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (l < 0) {
|
|
|
|
/*
|
|
|
|
* We've already checked that we've captured the
|
|
|
|
* entire TLV, based on its length, so this will
|
|
|
|
* either be -1, meaning "the prefix length is
|
|
|
|
* greater than the longest possible address of
|
|
|
|
* that type" (i.e., > 32 for IPv4 or > 128 for
|
|
|
|
* IPv6", or -3, meaning "the prefix runs past
|
|
|
|
* the end of the TLV".
|
|
|
|
*/
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
} else if (policy == 129) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("DNS domain: ");
|
2016-07-29 03:09:41 +08:00
|
|
|
print_dns_label(ndo, value+1, bodylen-1, 1);
|
|
|
|
} else if (policy == 130) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Opaque UTF-8: ");
|
2016-07-29 03:09:41 +08:00
|
|
|
safeputs(ndo, value + 1, bodylen - 1);
|
|
|
|
} else if (policy == 131) {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen != 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Restrictive assignment");
|
2016-07-29 03:09:41 +08:00
|
|
|
} else if (policy >= 132) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("Unknown (%u)", policy); /* Reserved for future additions */
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_DHCPV4_DATA: {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen == 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0)
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_DHCPV6_DATA: {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen == 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_ASSIGNED_PREFIX: {
|
|
|
|
uint8_t prty;
|
|
|
|
int l;
|
2017-12-02 21:19:13 +08:00
|
|
|
if (bodylen < 6 || bodylen < 6 + (EXTRACT_U_1(value + 5) + 7) / 8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-12-10 00:15:55 +08:00
|
|
|
prty = EXTRACT_U_1(value + 4) & 0xf;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" EPID: %08x Prty: %u",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_4(value),
|
2016-07-29 03:09:41 +08:00
|
|
|
prty
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
|
|
|
ND_PRINT(" Prefix: ");
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
l += 5;
|
|
|
|
l += -l & 3;
|
|
|
|
|
|
|
|
if (bodylen >= l)
|
|
|
|
hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_NODE_ADDRESS: {
|
|
|
|
uint32_t endpoint_identifier;
|
|
|
|
const char *ip_address;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 20) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-11-23 06:54:09 +08:00
|
|
|
endpoint_identifier = EXTRACT_BE_U_4(value);
|
2016-07-29 03:09:41 +08:00
|
|
|
ip_address = format_ip6addr(ndo, value + 4);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" EPID: %08x IP Address: %s",
|
2016-07-29 03:09:41 +08:00
|
|
|
endpoint_identifier,
|
|
|
|
ip_address
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
|
|
|
|
hncp_print_rec(ndo, value + 20, bodylen - 20, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_DNS_DELEGATED_ZONE: {
|
|
|
|
const char *ip_address;
|
|
|
|
int len;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 17) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
ip_address = format_ip6addr(ndo, value);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" IP-Address: %s %c%c%c ",
|
2016-07-29 03:09:41 +08:00
|
|
|
ip_address,
|
2017-11-26 20:02:48 +08:00
|
|
|
(EXTRACT_U_1(value + 16) & 4) ? 'l' : '-',
|
|
|
|
(EXTRACT_U_1(value + 16) & 2) ? 'b' : '-',
|
|
|
|
(EXTRACT_U_1(value + 16) & 1) ? 's' : '-'
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
len = print_dns_label(ndo, value+17, bodylen-17, 1);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (len < 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-07-29 03:09:41 +08:00
|
|
|
len += 17;
|
|
|
|
len += -len & 3;
|
|
|
|
if (bodylen >= len)
|
|
|
|
hncp_print_rec(ndo, value+len, bodylen-len, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_DOMAIN_NAME: {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen == 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" Domain: ");
|
2016-07-29 03:09:41 +08:00
|
|
|
print_dns_label(ndo, value, bodylen, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_NODE_NAME: {
|
|
|
|
u_int l;
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 17) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-12-09 19:32:00 +08:00
|
|
|
l = EXTRACT_U_1(value + 16);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 17 + l) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" IP-Address: %s Name: ",
|
2016-07-29 03:09:41 +08:00
|
|
|
format_ip6addr(ndo, value)
|
2018-01-07 18:47:30 +08:00
|
|
|
);
|
2016-07-29 03:09:41 +08:00
|
|
|
if (l < 64) {
|
|
|
|
safeputchar(ndo, '"');
|
|
|
|
safeputs(ndo, value + 17, l);
|
|
|
|
safeputchar(ndo, '"');
|
|
|
|
} else {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", istr);
|
2016-07-29 03:09:41 +08:00
|
|
|
}
|
|
|
|
l += 17;
|
|
|
|
l += -l & 3;
|
|
|
|
if (bodylen >= l)
|
|
|
|
hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HNCP_MANAGED_PSK: {
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
if (bodylen < 32) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", istr);
|
Fix handling of IPv4 prefixes.
Do *NOT* just use decode_prefix4(); it assumes that the data is in the
packet buffer, and does ND_TCHECK() on it, which is not guaranteed to
work if it's *not* in the packet buffer. Instead, do something similar
to what decode_prefix4() does, but on an HNCP-style prefix. Also, when
calling decode_prefix6(), pass it the actual size of the buffer we fill
in.
That buffer, BTW, does not need to be static, so it shouldn't be static.
Make sure we check *all* of the first 12 bytes of the prefix; just use
one memcmp call to check for 10 bytes of 0 followed by 2 bytes of 0xFF.
Don't use safeputs() on the formatted string for the prefix; it's
guaranteed 1) not to have any strange characters and 2) to be
null-terminated.
For invalid body lengths for a TLV, just report a error for that TLV,
but keep processing TLVs.
Handle "the prefix length is invalid" and "the prefix runs past the end
of the packet" differently.
2016-10-30 17:37:56 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" PSK: %s", format_256(value));
|
2016-07-29 03:09:41 +08:00
|
|
|
hncp_print_rec(ndo, value + 32, bodylen - 32, indent+1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RANGE_DNCP_RESERVED:
|
|
|
|
case RANGE_HNCP_UNASSIGNED:
|
|
|
|
case RANGE_DNCP_PRIVATE_USE:
|
|
|
|
case RANGE_DNCP_FUTURE_USE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
skip_multiline:
|
|
|
|
|
|
|
|
i += 4 + bodylen + (-bodylen & 3);
|
|
|
|
}
|
|
|
|
print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", "[|hncp]");
|
2016-07-29 03:09:41 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%s", istr);
|
2016-07-29 03:09:41 +08:00
|
|
|
return;
|
|
|
|
}
|