13340d773SGleb Smirnoff /* 23340d773SGleb Smirnoff * Copyright (c) 2016 Antonin Décimo, Jean-Raphaël Gaglione 33340d773SGleb Smirnoff * 43340d773SGleb Smirnoff * Redistribution and use in source and binary forms, with or without 53340d773SGleb Smirnoff * modification, are permitted provided that the following conditions 63340d773SGleb Smirnoff * are met: 73340d773SGleb Smirnoff * 1. Redistributions of source code must retain the above copyright 83340d773SGleb Smirnoff * notice, this list of conditions and the following disclaimer. 93340d773SGleb Smirnoff * 2. Redistributions in binary form must reproduce the above copyright 103340d773SGleb Smirnoff * notice, this list of conditions and the following disclaimer in the 113340d773SGleb Smirnoff * documentation and/or other materials provided with the distribution. 123340d773SGleb Smirnoff * 3. Neither the name of the project nor the names of its contributors 133340d773SGleb Smirnoff * may be used to endorse or promote products derived from this software 143340d773SGleb Smirnoff * without specific prior written permission. 153340d773SGleb Smirnoff * 163340d773SGleb Smirnoff * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 173340d773SGleb Smirnoff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 183340d773SGleb Smirnoff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 193340d773SGleb Smirnoff * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 203340d773SGleb Smirnoff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 213340d773SGleb Smirnoff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 223340d773SGleb Smirnoff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 233340d773SGleb Smirnoff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 243340d773SGleb Smirnoff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 253340d773SGleb Smirnoff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 263340d773SGleb Smirnoff * SUCH DAMAGE. 273340d773SGleb Smirnoff */ 283340d773SGleb Smirnoff 293340d773SGleb Smirnoff /* \summary: Home Networking Control Protocol (HNCP) printer */ 303340d773SGleb Smirnoff 313340d773SGleb Smirnoff #ifdef HAVE_CONFIG_H 32*ee67461eSJoseph Mingrone #include <config.h> 333340d773SGleb Smirnoff #endif 343340d773SGleb Smirnoff 35*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 363340d773SGleb Smirnoff 373340d773SGleb Smirnoff #include <string.h> 383340d773SGleb Smirnoff 393340d773SGleb Smirnoff #include "netdissect.h" 403340d773SGleb Smirnoff #include "addrtoname.h" 413340d773SGleb Smirnoff #include "extract.h" 423340d773SGleb Smirnoff 433340d773SGleb Smirnoff static void 443340d773SGleb Smirnoff hncp_print_rec(netdissect_options *ndo, 453340d773SGleb Smirnoff const u_char *cp, u_int length, int indent); 463340d773SGleb Smirnoff 473340d773SGleb Smirnoff void 483340d773SGleb Smirnoff hncp_print(netdissect_options *ndo, 493340d773SGleb Smirnoff const u_char *cp, u_int length) 503340d773SGleb Smirnoff { 51*ee67461eSJoseph Mingrone ndo->ndo_protocol = "hncp"; 52*ee67461eSJoseph Mingrone ND_PRINT("hncp (%u)", length); 533340d773SGleb Smirnoff hncp_print_rec(ndo, cp, length, 1); 543340d773SGleb Smirnoff } 553340d773SGleb Smirnoff 563340d773SGleb Smirnoff /* RFC7787 */ 573340d773SGleb Smirnoff #define DNCP_REQUEST_NETWORK_STATE 1 583340d773SGleb Smirnoff #define DNCP_REQUEST_NODE_STATE 2 593340d773SGleb Smirnoff #define DNCP_NODE_ENDPOINT 3 603340d773SGleb Smirnoff #define DNCP_NETWORK_STATE 4 613340d773SGleb Smirnoff #define DNCP_NODE_STATE 5 623340d773SGleb Smirnoff #define DNCP_PEER 8 633340d773SGleb Smirnoff #define DNCP_KEEP_ALIVE_INTERVAL 9 643340d773SGleb Smirnoff #define DNCP_TRUST_VERDICT 10 653340d773SGleb Smirnoff 663340d773SGleb Smirnoff /* RFC7788 */ 673340d773SGleb Smirnoff #define HNCP_HNCP_VERSION 32 683340d773SGleb Smirnoff #define HNCP_EXTERNAL_CONNECTION 33 693340d773SGleb Smirnoff #define HNCP_DELEGATED_PREFIX 34 703340d773SGleb Smirnoff #define HNCP_PREFIX_POLICY 43 7139e421e8SCy Schubert #define HNCP_DHCPV4_DATA 37 /* This is correct, see RFC 7788 Errata ID 5113. */ 7239e421e8SCy Schubert #define HNCP_DHCPV6_DATA 38 /* idem */ 733340d773SGleb Smirnoff #define HNCP_ASSIGNED_PREFIX 35 743340d773SGleb Smirnoff #define HNCP_NODE_ADDRESS 36 753340d773SGleb Smirnoff #define HNCP_DNS_DELEGATED_ZONE 39 763340d773SGleb Smirnoff #define HNCP_DOMAIN_NAME 40 773340d773SGleb Smirnoff #define HNCP_NODE_NAME 41 783340d773SGleb Smirnoff #define HNCP_MANAGED_PSK 42 793340d773SGleb Smirnoff 803340d773SGleb Smirnoff /* See type_mask in hncp_print_rec below */ 813340d773SGleb Smirnoff #define RANGE_DNCP_RESERVED 0x10000 823340d773SGleb Smirnoff #define RANGE_HNCP_UNASSIGNED 0x10001 833340d773SGleb Smirnoff #define RANGE_DNCP_PRIVATE_USE 0x10002 843340d773SGleb Smirnoff #define RANGE_DNCP_FUTURE_USE 0x10003 853340d773SGleb Smirnoff 863340d773SGleb Smirnoff static const struct tok type_values[] = { 873340d773SGleb Smirnoff { DNCP_REQUEST_NETWORK_STATE, "Request network state" }, 883340d773SGleb Smirnoff { DNCP_REQUEST_NODE_STATE, "Request node state" }, 893340d773SGleb Smirnoff { DNCP_NODE_ENDPOINT, "Node endpoint" }, 903340d773SGleb Smirnoff { DNCP_NETWORK_STATE, "Network state" }, 913340d773SGleb Smirnoff { DNCP_NODE_STATE, "Node state" }, 923340d773SGleb Smirnoff { DNCP_PEER, "Peer" }, 933340d773SGleb Smirnoff { DNCP_KEEP_ALIVE_INTERVAL, "Keep-alive interval" }, 943340d773SGleb Smirnoff { DNCP_TRUST_VERDICT, "Trust-Verdict" }, 953340d773SGleb Smirnoff 963340d773SGleb Smirnoff { HNCP_HNCP_VERSION, "HNCP-Version" }, 973340d773SGleb Smirnoff { HNCP_EXTERNAL_CONNECTION, "External-Connection" }, 983340d773SGleb Smirnoff { HNCP_DELEGATED_PREFIX, "Delegated-Prefix" }, 993340d773SGleb Smirnoff { HNCP_PREFIX_POLICY, "Prefix-Policy" }, 1003340d773SGleb Smirnoff { HNCP_DHCPV4_DATA, "DHCPv4-Data" }, 1013340d773SGleb Smirnoff { HNCP_DHCPV6_DATA, "DHCPv6-Data" }, 1023340d773SGleb Smirnoff { HNCP_ASSIGNED_PREFIX, "Assigned-Prefix" }, 1033340d773SGleb Smirnoff { HNCP_NODE_ADDRESS, "Node-Address" }, 1043340d773SGleb Smirnoff { HNCP_DNS_DELEGATED_ZONE, "DNS-Delegated-Zone" }, 1053340d773SGleb Smirnoff { HNCP_DOMAIN_NAME, "Domain-Name" }, 1063340d773SGleb Smirnoff { HNCP_NODE_NAME, "Node-Name" }, 1073340d773SGleb Smirnoff { HNCP_MANAGED_PSK, "Managed-PSK" }, 1083340d773SGleb Smirnoff 1093340d773SGleb Smirnoff { RANGE_DNCP_RESERVED, "Reserved" }, 1103340d773SGleb Smirnoff { RANGE_HNCP_UNASSIGNED, "Unassigned" }, 1113340d773SGleb Smirnoff { RANGE_DNCP_PRIVATE_USE, "Private use" }, 1123340d773SGleb Smirnoff { RANGE_DNCP_FUTURE_USE, "Future use" }, 1133340d773SGleb Smirnoff 1143340d773SGleb Smirnoff { 0, NULL} 1153340d773SGleb Smirnoff }; 1163340d773SGleb Smirnoff 1173340d773SGleb Smirnoff #define DH4OPT_DNS_SERVERS 6 /* RFC2132 */ 1183340d773SGleb Smirnoff #define DH4OPT_NTP_SERVERS 42 /* RFC2132 */ 1193340d773SGleb Smirnoff #define DH4OPT_DOMAIN_SEARCH 119 /* RFC3397 */ 1203340d773SGleb Smirnoff 1213340d773SGleb Smirnoff static const struct tok dh4opt_str[] = { 1223340d773SGleb Smirnoff { DH4OPT_DNS_SERVERS, "DNS-server" }, 1233340d773SGleb Smirnoff { DH4OPT_NTP_SERVERS, "NTP-server"}, 1243340d773SGleb Smirnoff { DH4OPT_DOMAIN_SEARCH, "DNS-search" }, 1253340d773SGleb Smirnoff { 0, NULL } 1263340d773SGleb Smirnoff }; 1273340d773SGleb Smirnoff 1283340d773SGleb Smirnoff #define DH6OPT_DNS_SERVERS 23 /* RFC3646 */ 1293340d773SGleb Smirnoff #define DH6OPT_DOMAIN_LIST 24 /* RFC3646 */ 1303340d773SGleb Smirnoff #define DH6OPT_SNTP_SERVERS 31 /* RFC4075 */ 1313340d773SGleb Smirnoff 1323340d773SGleb Smirnoff static const struct tok dh6opt_str[] = { 1333340d773SGleb Smirnoff { DH6OPT_DNS_SERVERS, "DNS-server" }, 1343340d773SGleb Smirnoff { DH6OPT_DOMAIN_LIST, "DNS-search-list" }, 1353340d773SGleb Smirnoff { DH6OPT_SNTP_SERVERS, "SNTP-servers" }, 1363340d773SGleb Smirnoff { 0, NULL } 1373340d773SGleb Smirnoff }; 1383340d773SGleb Smirnoff 1393340d773SGleb Smirnoff /* 1403340d773SGleb Smirnoff * For IPv4-mapped IPv6 addresses, length of the prefix that precedes 1413340d773SGleb Smirnoff * the 4 bytes of IPv4 address at the end of the IPv6 address. 1423340d773SGleb Smirnoff */ 1433340d773SGleb Smirnoff #define IPV4_MAPPED_HEADING_LEN 12 1443340d773SGleb Smirnoff 1453340d773SGleb Smirnoff /* 1463340d773SGleb Smirnoff * Is an IPv6 address an IPv4-mapped address? 1473340d773SGleb Smirnoff */ 148*ee67461eSJoseph Mingrone static int 1493340d773SGleb Smirnoff is_ipv4_mapped_address(const u_char *addr) 1503340d773SGleb Smirnoff { 1513340d773SGleb Smirnoff /* The value of the prefix */ 1523340d773SGleb Smirnoff static const u_char ipv4_mapped_heading[IPV4_MAPPED_HEADING_LEN] = 1533340d773SGleb Smirnoff { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF }; 1543340d773SGleb Smirnoff 1553340d773SGleb Smirnoff return memcmp(addr, ipv4_mapped_heading, IPV4_MAPPED_HEADING_LEN) == 0; 1563340d773SGleb Smirnoff } 1573340d773SGleb Smirnoff 1583340d773SGleb Smirnoff static const char * 159*ee67461eSJoseph Mingrone format_nid(netdissect_options *ndo, const u_char *data) 1603340d773SGleb Smirnoff { 16139e421e8SCy Schubert static char buf[4][sizeof("01:01:01:01")]; 1623340d773SGleb Smirnoff static int i = 0; 1633340d773SGleb Smirnoff i = (i + 1) % 4; 16439e421e8SCy Schubert snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x", 165*ee67461eSJoseph Mingrone GET_U_1(data), GET_U_1(data + 1), GET_U_1(data + 2), 166*ee67461eSJoseph Mingrone GET_U_1(data + 3)); 1673340d773SGleb Smirnoff return buf[i]; 1683340d773SGleb Smirnoff } 1693340d773SGleb Smirnoff 1703340d773SGleb Smirnoff static const char * 171*ee67461eSJoseph Mingrone format_256(netdissect_options *ndo, const u_char *data) 1723340d773SGleb Smirnoff { 17339e421e8SCy Schubert static char buf[4][sizeof("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")]; 1743340d773SGleb Smirnoff static int i = 0; 1753340d773SGleb Smirnoff i = (i + 1) % 4; 17639e421e8SCy Schubert snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64, 177*ee67461eSJoseph Mingrone GET_BE_U_8(data), 178*ee67461eSJoseph Mingrone GET_BE_U_8(data + 8), 179*ee67461eSJoseph Mingrone GET_BE_U_8(data + 16), 180*ee67461eSJoseph Mingrone GET_BE_U_8(data + 24) 1813340d773SGleb Smirnoff ); 1823340d773SGleb Smirnoff return buf[i]; 1833340d773SGleb Smirnoff } 1843340d773SGleb Smirnoff 1853340d773SGleb Smirnoff static const char * 1863340d773SGleb Smirnoff format_interval(const uint32_t n) 1873340d773SGleb Smirnoff { 1883340d773SGleb Smirnoff static char buf[4][sizeof("0000000.000s")]; 1893340d773SGleb Smirnoff static int i = 0; 1903340d773SGleb Smirnoff i = (i + 1) % 4; 1913340d773SGleb Smirnoff snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000); 1923340d773SGleb Smirnoff return buf[i]; 1933340d773SGleb Smirnoff } 1943340d773SGleb Smirnoff 1953340d773SGleb Smirnoff static const char * 1963340d773SGleb Smirnoff format_ip6addr(netdissect_options *ndo, const u_char *cp) 1973340d773SGleb Smirnoff { 1983340d773SGleb Smirnoff if (is_ipv4_mapped_address(cp)) 199*ee67461eSJoseph Mingrone return GET_IPADDR_STRING(cp + IPV4_MAPPED_HEADING_LEN); 2003340d773SGleb Smirnoff else 201*ee67461eSJoseph Mingrone return GET_IP6ADDR_STRING(cp); 2023340d773SGleb Smirnoff } 2033340d773SGleb Smirnoff 2043340d773SGleb Smirnoff static int 2053340d773SGleb Smirnoff print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length) 2063340d773SGleb Smirnoff { 2073340d773SGleb Smirnoff int plenbytes; 2083340d773SGleb Smirnoff char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")]; 2093340d773SGleb Smirnoff 210*ee67461eSJoseph Mingrone if (GET_U_1(prefix) >= 96 && max_length >= IPV4_MAPPED_HEADING_LEN + 1 && 211*ee67461eSJoseph Mingrone is_ipv4_mapped_address(prefix + 1)) { 212*ee67461eSJoseph Mingrone nd_ipv4 addr; 2133340d773SGleb Smirnoff u_int plen; 2143340d773SGleb Smirnoff 215*ee67461eSJoseph Mingrone plen = GET_U_1(prefix) - 96; 2163340d773SGleb Smirnoff if (32 < plen) 2173340d773SGleb Smirnoff return -1; 2183340d773SGleb Smirnoff max_length -= 1; 2193340d773SGleb Smirnoff 2203340d773SGleb Smirnoff memset(&addr, 0, sizeof(addr)); 2213340d773SGleb Smirnoff plenbytes = (plen + 7) / 8; 2223340d773SGleb Smirnoff if (max_length < (u_int)plenbytes + IPV4_MAPPED_HEADING_LEN) 2233340d773SGleb Smirnoff return -3; 224*ee67461eSJoseph Mingrone memcpy(&addr, prefix + IPV4_MAPPED_HEADING_LEN + 1, plenbytes); 2253340d773SGleb Smirnoff if (plen % 8) { 2263340d773SGleb Smirnoff ((u_char *)&addr)[plenbytes - 1] &= 2273340d773SGleb Smirnoff ((0xff00 >> (plen % 8)) & 0xff); 2283340d773SGleb Smirnoff } 229*ee67461eSJoseph Mingrone snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), plen); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */ 2303340d773SGleb Smirnoff plenbytes += 1 + IPV4_MAPPED_HEADING_LEN; 2313340d773SGleb Smirnoff } else { 2323340d773SGleb Smirnoff plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf)); 23339e421e8SCy Schubert if (plenbytes < 0) 23439e421e8SCy Schubert return plenbytes; 2353340d773SGleb Smirnoff } 2363340d773SGleb Smirnoff 237*ee67461eSJoseph Mingrone ND_PRINT("%s", buf); 2383340d773SGleb Smirnoff return plenbytes; 2393340d773SGleb Smirnoff } 2403340d773SGleb Smirnoff 2413340d773SGleb Smirnoff static int 2423340d773SGleb Smirnoff print_dns_label(netdissect_options *ndo, 2433340d773SGleb Smirnoff const u_char *cp, u_int max_length, int print) 2443340d773SGleb Smirnoff { 2453340d773SGleb Smirnoff u_int length = 0; 2463340d773SGleb Smirnoff while (length < max_length) { 247*ee67461eSJoseph Mingrone u_int lab_length = GET_U_1(cp + length); 248*ee67461eSJoseph Mingrone length++; 2493340d773SGleb Smirnoff if (lab_length == 0) 2503340d773SGleb Smirnoff return (int)length; 2513340d773SGleb Smirnoff if (length > 1 && print) 252*ee67461eSJoseph Mingrone ND_PRINT("."); 2533340d773SGleb Smirnoff if (length+lab_length > max_length) { 2543340d773SGleb Smirnoff if (print) 255*ee67461eSJoseph Mingrone nd_printjnp(ndo, cp+length, max_length-length); 2563340d773SGleb Smirnoff break; 2573340d773SGleb Smirnoff } 2583340d773SGleb Smirnoff if (print) 259*ee67461eSJoseph Mingrone nd_printjnp(ndo, cp+length, lab_length); 2603340d773SGleb Smirnoff length += lab_length; 2613340d773SGleb Smirnoff } 2623340d773SGleb Smirnoff if (print) 263*ee67461eSJoseph Mingrone ND_PRINT("[|DNS]"); 2643340d773SGleb Smirnoff return -1; 2653340d773SGleb Smirnoff } 2663340d773SGleb Smirnoff 2673340d773SGleb Smirnoff static int 2683340d773SGleb Smirnoff dhcpv4_print(netdissect_options *ndo, 2693340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 2703340d773SGleb Smirnoff { 2713340d773SGleb Smirnoff u_int i, t; 272*ee67461eSJoseph Mingrone const uint8_t *tlv, *value; 2733340d773SGleb Smirnoff uint8_t type, optlen; 2743340d773SGleb Smirnoff 2753340d773SGleb Smirnoff i = 0; 2763340d773SGleb Smirnoff while (i < length) { 2770bff6a5aSEd Maste if (i + 2 > length) 2780bff6a5aSEd Maste return -1; 2793340d773SGleb Smirnoff tlv = cp + i; 280*ee67461eSJoseph Mingrone type = GET_U_1(tlv); 281*ee67461eSJoseph Mingrone optlen = GET_U_1(tlv + 1); 2823340d773SGleb Smirnoff value = tlv + 2; 2833340d773SGleb Smirnoff 284*ee67461eSJoseph Mingrone ND_PRINT("\n"); 2853340d773SGleb Smirnoff for (t = indent; t > 0; t--) 286*ee67461eSJoseph Mingrone ND_PRINT("\t"); 2873340d773SGleb Smirnoff 288*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(dh4opt_str, "Unknown", type)); 289*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", optlen + 2 ); 2900bff6a5aSEd Maste if (i + 2 + optlen > length) 2910bff6a5aSEd Maste return -1; 2923340d773SGleb Smirnoff 2933340d773SGleb Smirnoff switch (type) { 2943340d773SGleb Smirnoff case DH4OPT_DNS_SERVERS: 2953340d773SGleb Smirnoff case DH4OPT_NTP_SERVERS: { 2963340d773SGleb Smirnoff if (optlen < 4 || optlen % 4 != 0) { 2973340d773SGleb Smirnoff return -1; 2983340d773SGleb Smirnoff } 2993340d773SGleb Smirnoff for (t = 0; t < optlen; t += 4) 300*ee67461eSJoseph Mingrone ND_PRINT(" %s", GET_IPADDR_STRING(value + t)); 3013340d773SGleb Smirnoff } 3023340d773SGleb Smirnoff break; 3033340d773SGleb Smirnoff case DH4OPT_DOMAIN_SEARCH: { 3043340d773SGleb Smirnoff const u_char *tp = value; 3053340d773SGleb Smirnoff while (tp < value + optlen) { 306*ee67461eSJoseph Mingrone ND_PRINT(" "); 307*ee67461eSJoseph Mingrone if ((tp = fqdn_print(ndo, tp, value + optlen)) == NULL) 3083340d773SGleb Smirnoff return -1; 3093340d773SGleb Smirnoff } 3103340d773SGleb Smirnoff } 3113340d773SGleb Smirnoff break; 3123340d773SGleb Smirnoff } 3133340d773SGleb Smirnoff 3143340d773SGleb Smirnoff i += 2 + optlen; 3153340d773SGleb Smirnoff } 3163340d773SGleb Smirnoff return 0; 3173340d773SGleb Smirnoff } 3183340d773SGleb Smirnoff 3193340d773SGleb Smirnoff static int 3203340d773SGleb Smirnoff dhcpv6_print(netdissect_options *ndo, 3213340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 3223340d773SGleb Smirnoff { 3233340d773SGleb Smirnoff u_int i, t; 3243340d773SGleb Smirnoff const u_char *tlv, *value; 3253340d773SGleb Smirnoff uint16_t type, optlen; 3263340d773SGleb Smirnoff 3273340d773SGleb Smirnoff i = 0; 3283340d773SGleb Smirnoff while (i < length) { 3290bff6a5aSEd Maste if (i + 4 > length) 3300bff6a5aSEd Maste return -1; 3313340d773SGleb Smirnoff tlv = cp + i; 332*ee67461eSJoseph Mingrone type = GET_BE_U_2(tlv); 333*ee67461eSJoseph Mingrone optlen = GET_BE_U_2(tlv + 2); 3343340d773SGleb Smirnoff value = tlv + 4; 3353340d773SGleb Smirnoff 336*ee67461eSJoseph Mingrone ND_PRINT("\n"); 3373340d773SGleb Smirnoff for (t = indent; t > 0; t--) 338*ee67461eSJoseph Mingrone ND_PRINT("\t"); 3393340d773SGleb Smirnoff 340*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(dh6opt_str, "Unknown", type)); 341*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", optlen + 4 ); 3420bff6a5aSEd Maste if (i + 4 + optlen > length) 3430bff6a5aSEd Maste return -1; 3443340d773SGleb Smirnoff 3453340d773SGleb Smirnoff switch (type) { 3463340d773SGleb Smirnoff case DH6OPT_DNS_SERVERS: 3473340d773SGleb Smirnoff case DH6OPT_SNTP_SERVERS: { 3483340d773SGleb Smirnoff if (optlen % 16 != 0) { 349*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 3503340d773SGleb Smirnoff return -1; 3513340d773SGleb Smirnoff } 3523340d773SGleb Smirnoff for (t = 0; t < optlen; t += 16) 353*ee67461eSJoseph Mingrone ND_PRINT(" %s", GET_IP6ADDR_STRING(value + t)); 3543340d773SGleb Smirnoff } 3553340d773SGleb Smirnoff break; 3563340d773SGleb Smirnoff case DH6OPT_DOMAIN_LIST: { 3573340d773SGleb Smirnoff const u_char *tp = value; 3583340d773SGleb Smirnoff while (tp < value + optlen) { 359*ee67461eSJoseph Mingrone ND_PRINT(" "); 360*ee67461eSJoseph Mingrone if ((tp = fqdn_print(ndo, tp, value + optlen)) == NULL) 3613340d773SGleb Smirnoff return -1; 3623340d773SGleb Smirnoff } 3633340d773SGleb Smirnoff } 3643340d773SGleb Smirnoff break; 3653340d773SGleb Smirnoff } 3663340d773SGleb Smirnoff 3673340d773SGleb Smirnoff i += 4 + optlen; 3683340d773SGleb Smirnoff } 3693340d773SGleb Smirnoff return 0; 3703340d773SGleb Smirnoff } 3713340d773SGleb Smirnoff 3723340d773SGleb Smirnoff /* Determine in-line mode */ 3733340d773SGleb Smirnoff static int 3743340d773SGleb Smirnoff is_in_line(netdissect_options *ndo, int indent) 3753340d773SGleb Smirnoff { 3763340d773SGleb Smirnoff return indent - 1 >= ndo->ndo_vflag && ndo->ndo_vflag < 3; 3773340d773SGleb Smirnoff } 3783340d773SGleb Smirnoff 3793340d773SGleb Smirnoff static void 3803340d773SGleb Smirnoff print_type_in_line(netdissect_options *ndo, 3813340d773SGleb Smirnoff uint32_t type, int count, int indent, int *first_one) 3823340d773SGleb Smirnoff { 3833340d773SGleb Smirnoff if (count > 0) { 3843340d773SGleb Smirnoff if (*first_one) { 3853340d773SGleb Smirnoff *first_one = 0; 3863340d773SGleb Smirnoff if (indent > 1) { 3873340d773SGleb Smirnoff u_int t; 388*ee67461eSJoseph Mingrone ND_PRINT("\n"); 3893340d773SGleb Smirnoff for (t = indent; t > 0; t--) 390*ee67461eSJoseph Mingrone ND_PRINT("\t"); 3913340d773SGleb Smirnoff } else { 392*ee67461eSJoseph Mingrone ND_PRINT(" "); 3933340d773SGleb Smirnoff } 3943340d773SGleb Smirnoff } else { 395*ee67461eSJoseph Mingrone ND_PRINT(", "); 3963340d773SGleb Smirnoff } 397*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(type_values, "Easter Egg", type)); 3983340d773SGleb Smirnoff if (count > 1) 399*ee67461eSJoseph Mingrone ND_PRINT(" (x%d)", count); 4003340d773SGleb Smirnoff } 4013340d773SGleb Smirnoff } 4023340d773SGleb Smirnoff 403*ee67461eSJoseph Mingrone static void 4043340d773SGleb Smirnoff hncp_print_rec(netdissect_options *ndo, 4053340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 4063340d773SGleb Smirnoff { 4073340d773SGleb Smirnoff const int in_line = is_in_line(ndo, indent); 4083340d773SGleb Smirnoff int first_one = 1; 4093340d773SGleb Smirnoff 4103340d773SGleb Smirnoff u_int i, t; 4113340d773SGleb Smirnoff 4123340d773SGleb Smirnoff uint32_t last_type_mask = 0xffffffffU; 4133340d773SGleb Smirnoff int last_type_count = -1; 4143340d773SGleb Smirnoff 415*ee67461eSJoseph Mingrone const uint8_t *tlv, *value; 4163340d773SGleb Smirnoff uint16_t type, bodylen; 4173340d773SGleb Smirnoff uint32_t type_mask; 4183340d773SGleb Smirnoff 4193340d773SGleb Smirnoff i = 0; 4203340d773SGleb Smirnoff while (i < length) { 4213340d773SGleb Smirnoff tlv = cp + i; 4223340d773SGleb Smirnoff 4233340d773SGleb Smirnoff if (!in_line) { 424*ee67461eSJoseph Mingrone ND_PRINT("\n"); 4253340d773SGleb Smirnoff for (t = indent; t > 0; t--) 426*ee67461eSJoseph Mingrone ND_PRINT("\t"); 4273340d773SGleb Smirnoff } 4283340d773SGleb Smirnoff 429*ee67461eSJoseph Mingrone ND_TCHECK_4(tlv); 4303340d773SGleb Smirnoff if (i + 4 > length) 4313340d773SGleb Smirnoff goto invalid; 4323340d773SGleb Smirnoff 433*ee67461eSJoseph Mingrone type = GET_BE_U_2(tlv); 434*ee67461eSJoseph Mingrone bodylen = GET_BE_U_2(tlv + 2); 4353340d773SGleb Smirnoff value = tlv + 4; 436*ee67461eSJoseph Mingrone ND_TCHECK_LEN(value, bodylen); 4373340d773SGleb Smirnoff if (i + bodylen + 4 > length) 4383340d773SGleb Smirnoff goto invalid; 4393340d773SGleb Smirnoff 4403340d773SGleb Smirnoff type_mask = 4413340d773SGleb Smirnoff (type == 0) ? RANGE_DNCP_RESERVED: 4423340d773SGleb Smirnoff (44 <= type && type <= 511) ? RANGE_HNCP_UNASSIGNED: 4433340d773SGleb Smirnoff (768 <= type && type <= 1023) ? RANGE_DNCP_PRIVATE_USE: 4443340d773SGleb Smirnoff RANGE_DNCP_FUTURE_USE; 4453340d773SGleb Smirnoff if (type == 6 || type == 7) 4463340d773SGleb Smirnoff type_mask = RANGE_DNCP_FUTURE_USE; 4473340d773SGleb Smirnoff 4483340d773SGleb Smirnoff /* defined types */ 4493340d773SGleb Smirnoff { 4503340d773SGleb Smirnoff t = 0; 4513340d773SGleb Smirnoff while (1) { 4523340d773SGleb Smirnoff u_int key = type_values[t++].v; 4533340d773SGleb Smirnoff if (key > 0xffff) 4543340d773SGleb Smirnoff break; 4553340d773SGleb Smirnoff if (key == type) { 4563340d773SGleb Smirnoff type_mask = type; 4573340d773SGleb Smirnoff break; 4583340d773SGleb Smirnoff } 4593340d773SGleb Smirnoff } 4603340d773SGleb Smirnoff } 4613340d773SGleb Smirnoff 4623340d773SGleb Smirnoff if (in_line) { 4633340d773SGleb Smirnoff if (last_type_mask == type_mask) { 4643340d773SGleb Smirnoff last_type_count++; 4653340d773SGleb Smirnoff } else { 4663340d773SGleb Smirnoff print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one); 4673340d773SGleb Smirnoff last_type_mask = type_mask; 4683340d773SGleb Smirnoff last_type_count = 1; 4693340d773SGleb Smirnoff } 4703340d773SGleb Smirnoff 4713340d773SGleb Smirnoff goto skip_multiline; 4723340d773SGleb Smirnoff } 4733340d773SGleb Smirnoff 474*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(type_values, "Easter Egg (42)", type_mask) ); 4753340d773SGleb Smirnoff if (type_mask > 0xffff) 476*ee67461eSJoseph Mingrone ND_PRINT(": type=%u", type ); 477*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", bodylen + 4 ); 4783340d773SGleb Smirnoff 4793340d773SGleb Smirnoff switch (type_mask) { 4803340d773SGleb Smirnoff 4813340d773SGleb Smirnoff case DNCP_REQUEST_NETWORK_STATE: { 4823340d773SGleb Smirnoff if (bodylen != 0) 483*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 4843340d773SGleb Smirnoff } 4853340d773SGleb Smirnoff break; 4863340d773SGleb Smirnoff 4873340d773SGleb Smirnoff case DNCP_REQUEST_NODE_STATE: { 4883340d773SGleb Smirnoff const char *node_identifier; 4893340d773SGleb Smirnoff if (bodylen != 4) { 490*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 4913340d773SGleb Smirnoff break; 4923340d773SGleb Smirnoff } 493*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 494*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s", node_identifier); 4953340d773SGleb Smirnoff } 4963340d773SGleb Smirnoff break; 4973340d773SGleb Smirnoff 4983340d773SGleb Smirnoff case DNCP_NODE_ENDPOINT: { 4993340d773SGleb Smirnoff const char *node_identifier; 5003340d773SGleb Smirnoff uint32_t endpoint_identifier; 5013340d773SGleb Smirnoff if (bodylen != 8) { 502*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5033340d773SGleb Smirnoff break; 5043340d773SGleb Smirnoff } 505*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 506*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value + 4); 507*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s EPID: %08x", 5083340d773SGleb Smirnoff node_identifier, 5093340d773SGleb Smirnoff endpoint_identifier 510*ee67461eSJoseph Mingrone ); 5113340d773SGleb Smirnoff } 5123340d773SGleb Smirnoff break; 5133340d773SGleb Smirnoff 5143340d773SGleb Smirnoff case DNCP_NETWORK_STATE: { 5153340d773SGleb Smirnoff uint64_t hash; 5163340d773SGleb Smirnoff if (bodylen != 8) { 517*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5183340d773SGleb Smirnoff break; 5193340d773SGleb Smirnoff } 520*ee67461eSJoseph Mingrone hash = GET_BE_U_8(value); 521*ee67461eSJoseph Mingrone ND_PRINT(" hash: %016" PRIx64, hash); 5223340d773SGleb Smirnoff } 5233340d773SGleb Smirnoff break; 5243340d773SGleb Smirnoff 5253340d773SGleb Smirnoff case DNCP_NODE_STATE: { 5263340d773SGleb Smirnoff const char *node_identifier, *interval; 5273340d773SGleb Smirnoff uint32_t sequence_number; 5283340d773SGleb Smirnoff uint64_t hash; 5293340d773SGleb Smirnoff if (bodylen < 20) { 530*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5313340d773SGleb Smirnoff break; 5323340d773SGleb Smirnoff } 533*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 534*ee67461eSJoseph Mingrone sequence_number = GET_BE_U_4(value + 4); 535*ee67461eSJoseph Mingrone interval = format_interval(GET_BE_U_4(value + 8)); 536*ee67461eSJoseph Mingrone hash = GET_BE_U_8(value + 12); 537*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s seqno: %u %s hash: %016" PRIx64, 5383340d773SGleb Smirnoff node_identifier, 5393340d773SGleb Smirnoff sequence_number, 5403340d773SGleb Smirnoff interval, 5413340d773SGleb Smirnoff hash 542*ee67461eSJoseph Mingrone ); 5433340d773SGleb Smirnoff hncp_print_rec(ndo, value+20, bodylen-20, indent+1); 5443340d773SGleb Smirnoff } 5453340d773SGleb Smirnoff break; 5463340d773SGleb Smirnoff 5473340d773SGleb Smirnoff case DNCP_PEER: { 5483340d773SGleb Smirnoff const char *peer_node_identifier; 5493340d773SGleb Smirnoff uint32_t peer_endpoint_identifier, endpoint_identifier; 5503340d773SGleb Smirnoff if (bodylen != 12) { 551*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5523340d773SGleb Smirnoff break; 5533340d773SGleb Smirnoff } 554*ee67461eSJoseph Mingrone peer_node_identifier = format_nid(ndo, value); 555*ee67461eSJoseph Mingrone peer_endpoint_identifier = GET_BE_U_4(value + 4); 556*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value + 8); 557*ee67461eSJoseph Mingrone ND_PRINT(" Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x", 5583340d773SGleb Smirnoff peer_node_identifier, 5593340d773SGleb Smirnoff peer_endpoint_identifier, 5603340d773SGleb Smirnoff endpoint_identifier 561*ee67461eSJoseph Mingrone ); 5623340d773SGleb Smirnoff } 5633340d773SGleb Smirnoff break; 5643340d773SGleb Smirnoff 5653340d773SGleb Smirnoff case DNCP_KEEP_ALIVE_INTERVAL: { 5663340d773SGleb Smirnoff uint32_t endpoint_identifier; 5673340d773SGleb Smirnoff const char *interval; 5683340d773SGleb Smirnoff if (bodylen < 8) { 569*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5703340d773SGleb Smirnoff break; 5713340d773SGleb Smirnoff } 572*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value); 573*ee67461eSJoseph Mingrone interval = format_interval(GET_BE_U_4(value + 4)); 574*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x Interval: %s", 5753340d773SGleb Smirnoff endpoint_identifier, 5763340d773SGleb Smirnoff interval 577*ee67461eSJoseph Mingrone ); 5783340d773SGleb Smirnoff } 5793340d773SGleb Smirnoff break; 5803340d773SGleb Smirnoff 5813340d773SGleb Smirnoff case DNCP_TRUST_VERDICT: { 5823340d773SGleb Smirnoff if (bodylen <= 36) { 583*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5843340d773SGleb Smirnoff break; 5853340d773SGleb Smirnoff } 586*ee67461eSJoseph Mingrone ND_PRINT(" Verdict: %u Fingerprint: %s Common Name: ", 587*ee67461eSJoseph Mingrone GET_U_1(value), 588*ee67461eSJoseph Mingrone format_256(ndo, value + 4)); 589*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 36, bodylen - 36); 5903340d773SGleb Smirnoff } 5913340d773SGleb Smirnoff break; 5923340d773SGleb Smirnoff 5933340d773SGleb Smirnoff case HNCP_HNCP_VERSION: { 5943340d773SGleb Smirnoff uint16_t capabilities; 5953340d773SGleb Smirnoff uint8_t M, P, H, L; 5963340d773SGleb Smirnoff if (bodylen < 5) { 597*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5983340d773SGleb Smirnoff break; 5993340d773SGleb Smirnoff } 600*ee67461eSJoseph Mingrone capabilities = GET_BE_U_2(value + 2); 6013340d773SGleb Smirnoff M = (uint8_t)((capabilities >> 12) & 0xf); 6023340d773SGleb Smirnoff P = (uint8_t)((capabilities >> 8) & 0xf); 6033340d773SGleb Smirnoff H = (uint8_t)((capabilities >> 4) & 0xf); 6043340d773SGleb Smirnoff L = (uint8_t)(capabilities & 0xf); 605*ee67461eSJoseph Mingrone ND_PRINT(" M: %u P: %u H: %u L: %u User-agent: ", 6063340d773SGleb Smirnoff M, P, H, L 607*ee67461eSJoseph Mingrone ); 608*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 4, bodylen - 4); 6093340d773SGleb Smirnoff } 6103340d773SGleb Smirnoff break; 6113340d773SGleb Smirnoff 6123340d773SGleb Smirnoff case HNCP_EXTERNAL_CONNECTION: { 6133340d773SGleb Smirnoff /* Container TLV */ 6143340d773SGleb Smirnoff hncp_print_rec(ndo, value, bodylen, indent+1); 6153340d773SGleb Smirnoff } 6163340d773SGleb Smirnoff break; 6173340d773SGleb Smirnoff 6183340d773SGleb Smirnoff case HNCP_DELEGATED_PREFIX: { 6193340d773SGleb Smirnoff int l; 620*ee67461eSJoseph Mingrone if (bodylen < 9 || bodylen < 9 + (GET_U_1(value + 8) + 7) / 8) { 621*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6223340d773SGleb Smirnoff break; 6233340d773SGleb Smirnoff } 624*ee67461eSJoseph Mingrone ND_PRINT(" VLSO: %s PLSO: %s Prefix: ", 625*ee67461eSJoseph Mingrone format_interval(GET_BE_U_4(value)), 626*ee67461eSJoseph Mingrone format_interval(GET_BE_U_4(value + 4)) 627*ee67461eSJoseph Mingrone ); 6283340d773SGleb Smirnoff l = print_prefix(ndo, value + 8, bodylen - 8); 6293340d773SGleb Smirnoff if (l == -1) { 630*ee67461eSJoseph Mingrone ND_PRINT("(length is invalid)"); 6313340d773SGleb Smirnoff break; 6323340d773SGleb Smirnoff } 6333340d773SGleb Smirnoff if (l < 0) { 6343340d773SGleb Smirnoff /* 6353340d773SGleb Smirnoff * We've already checked that we've captured the 6363340d773SGleb Smirnoff * entire TLV, based on its length, so this will 6373340d773SGleb Smirnoff * either be -1, meaning "the prefix length is 6383340d773SGleb Smirnoff * greater than the longest possible address of 6393340d773SGleb Smirnoff * that type" (i.e., > 32 for IPv4 or > 128 for 6403340d773SGleb Smirnoff * IPv6", or -3, meaning "the prefix runs past 6413340d773SGleb Smirnoff * the end of the TLV". 6423340d773SGleb Smirnoff */ 643*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6443340d773SGleb Smirnoff break; 6453340d773SGleb Smirnoff } 6463340d773SGleb Smirnoff l += 8 + (-l & 3); 6473340d773SGleb Smirnoff 6483340d773SGleb Smirnoff if (bodylen >= l) 6493340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 6503340d773SGleb Smirnoff } 6513340d773SGleb Smirnoff break; 6523340d773SGleb Smirnoff 6533340d773SGleb Smirnoff case HNCP_PREFIX_POLICY: { 6543340d773SGleb Smirnoff uint8_t policy; 6553340d773SGleb Smirnoff int l; 6563340d773SGleb Smirnoff if (bodylen < 1) { 657*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6583340d773SGleb Smirnoff break; 6593340d773SGleb Smirnoff } 660*ee67461eSJoseph Mingrone policy = GET_U_1(value); 661*ee67461eSJoseph Mingrone ND_PRINT(" type: "); 6623340d773SGleb Smirnoff if (policy == 0) { 6633340d773SGleb Smirnoff if (bodylen != 1) { 664*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6653340d773SGleb Smirnoff break; 6663340d773SGleb Smirnoff } 667*ee67461eSJoseph Mingrone ND_PRINT("Internet connectivity"); 6683340d773SGleb Smirnoff } else if (policy >= 1 && policy <= 128) { 669*ee67461eSJoseph Mingrone ND_PRINT("Dest-Prefix: "); 6703340d773SGleb Smirnoff l = print_prefix(ndo, value, bodylen); 6713340d773SGleb Smirnoff if (l == -1) { 672*ee67461eSJoseph Mingrone ND_PRINT("(length is invalid)"); 6733340d773SGleb Smirnoff break; 6743340d773SGleb Smirnoff } 6753340d773SGleb Smirnoff if (l < 0) { 6763340d773SGleb Smirnoff /* 6773340d773SGleb Smirnoff * We've already checked that we've captured the 6783340d773SGleb Smirnoff * entire TLV, based on its length, so this will 6793340d773SGleb Smirnoff * either be -1, meaning "the prefix length is 6803340d773SGleb Smirnoff * greater than the longest possible address of 6813340d773SGleb Smirnoff * that type" (i.e., > 32 for IPv4 or > 128 for 6823340d773SGleb Smirnoff * IPv6", or -3, meaning "the prefix runs past 6833340d773SGleb Smirnoff * the end of the TLV". 6843340d773SGleb Smirnoff */ 685*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6863340d773SGleb Smirnoff break; 6873340d773SGleb Smirnoff } 6883340d773SGleb Smirnoff } else if (policy == 129) { 689*ee67461eSJoseph Mingrone ND_PRINT("DNS domain: "); 6903340d773SGleb Smirnoff print_dns_label(ndo, value+1, bodylen-1, 1); 6913340d773SGleb Smirnoff } else if (policy == 130) { 692*ee67461eSJoseph Mingrone ND_PRINT("Opaque UTF-8: "); 693*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 1, bodylen - 1); 6943340d773SGleb Smirnoff } else if (policy == 131) { 6953340d773SGleb Smirnoff if (bodylen != 1) { 696*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6973340d773SGleb Smirnoff break; 6983340d773SGleb Smirnoff } 699*ee67461eSJoseph Mingrone ND_PRINT("Restrictive assignment"); 7003340d773SGleb Smirnoff } else if (policy >= 132) { 701*ee67461eSJoseph Mingrone ND_PRINT("Unknown (%u)", policy); /* Reserved for future additions */ 7023340d773SGleb Smirnoff } 7033340d773SGleb Smirnoff } 7043340d773SGleb Smirnoff break; 7053340d773SGleb Smirnoff 7063340d773SGleb Smirnoff case HNCP_DHCPV4_DATA: { 7073340d773SGleb Smirnoff if (bodylen == 0) { 708*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7093340d773SGleb Smirnoff break; 7103340d773SGleb Smirnoff } 7113340d773SGleb Smirnoff if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0) 7123340d773SGleb Smirnoff goto invalid; 7133340d773SGleb Smirnoff } 7143340d773SGleb Smirnoff break; 7153340d773SGleb Smirnoff 7163340d773SGleb Smirnoff case HNCP_DHCPV6_DATA: { 7173340d773SGleb Smirnoff if (bodylen == 0) { 718*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7193340d773SGleb Smirnoff break; 7203340d773SGleb Smirnoff } 7213340d773SGleb Smirnoff if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0) { 722*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7233340d773SGleb Smirnoff break; 7243340d773SGleb Smirnoff } 7253340d773SGleb Smirnoff } 7263340d773SGleb Smirnoff break; 7273340d773SGleb Smirnoff 7283340d773SGleb Smirnoff case HNCP_ASSIGNED_PREFIX: { 7293340d773SGleb Smirnoff uint8_t prty; 7303340d773SGleb Smirnoff int l; 731*ee67461eSJoseph Mingrone if (bodylen < 6 || bodylen < 6 + (GET_U_1(value + 5) + 7) / 8) { 732*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7333340d773SGleb Smirnoff break; 7343340d773SGleb Smirnoff } 735*ee67461eSJoseph Mingrone prty = GET_U_1(value + 4) & 0xf; 736*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x Prty: %u", 737*ee67461eSJoseph Mingrone GET_BE_U_4(value), 7383340d773SGleb Smirnoff prty 739*ee67461eSJoseph Mingrone ); 740*ee67461eSJoseph Mingrone ND_PRINT(" Prefix: "); 7413340d773SGleb Smirnoff if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0) { 742*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7433340d773SGleb Smirnoff break; 7443340d773SGleb Smirnoff } 7453340d773SGleb Smirnoff l += 5; 7463340d773SGleb Smirnoff l += -l & 3; 7473340d773SGleb Smirnoff 7483340d773SGleb Smirnoff if (bodylen >= l) 7493340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 7503340d773SGleb Smirnoff } 7513340d773SGleb Smirnoff break; 7523340d773SGleb Smirnoff 7533340d773SGleb Smirnoff case HNCP_NODE_ADDRESS: { 7543340d773SGleb Smirnoff uint32_t endpoint_identifier; 7553340d773SGleb Smirnoff const char *ip_address; 7563340d773SGleb Smirnoff if (bodylen < 20) { 757*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7583340d773SGleb Smirnoff break; 7593340d773SGleb Smirnoff } 760*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value); 7613340d773SGleb Smirnoff ip_address = format_ip6addr(ndo, value + 4); 762*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x IP Address: %s", 7633340d773SGleb Smirnoff endpoint_identifier, 7643340d773SGleb Smirnoff ip_address 765*ee67461eSJoseph Mingrone ); 7663340d773SGleb Smirnoff 7673340d773SGleb Smirnoff hncp_print_rec(ndo, value + 20, bodylen - 20, indent+1); 7683340d773SGleb Smirnoff } 7693340d773SGleb Smirnoff break; 7703340d773SGleb Smirnoff 7713340d773SGleb Smirnoff case HNCP_DNS_DELEGATED_ZONE: { 7723340d773SGleb Smirnoff const char *ip_address; 7733340d773SGleb Smirnoff int len; 7743340d773SGleb Smirnoff if (bodylen < 17) { 775*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7763340d773SGleb Smirnoff break; 7773340d773SGleb Smirnoff } 7783340d773SGleb Smirnoff ip_address = format_ip6addr(ndo, value); 779*ee67461eSJoseph Mingrone ND_PRINT(" IP-Address: %s %c%c%c ", 7803340d773SGleb Smirnoff ip_address, 781*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 4) ? 'l' : '-', 782*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 2) ? 'b' : '-', 783*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 1) ? 's' : '-' 784*ee67461eSJoseph Mingrone ); 7853340d773SGleb Smirnoff len = print_dns_label(ndo, value+17, bodylen-17, 1); 7863340d773SGleb Smirnoff if (len < 0) { 787*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7883340d773SGleb Smirnoff break; 7893340d773SGleb Smirnoff } 7903340d773SGleb Smirnoff len += 17; 7913340d773SGleb Smirnoff len += -len & 3; 7923340d773SGleb Smirnoff if (bodylen >= len) 7933340d773SGleb Smirnoff hncp_print_rec(ndo, value+len, bodylen-len, indent+1); 7943340d773SGleb Smirnoff } 7953340d773SGleb Smirnoff break; 7963340d773SGleb Smirnoff 7973340d773SGleb Smirnoff case HNCP_DOMAIN_NAME: { 7983340d773SGleb Smirnoff if (bodylen == 0) { 799*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8003340d773SGleb Smirnoff break; 8013340d773SGleb Smirnoff } 802*ee67461eSJoseph Mingrone ND_PRINT(" Domain: "); 8033340d773SGleb Smirnoff print_dns_label(ndo, value, bodylen, 1); 8043340d773SGleb Smirnoff } 8053340d773SGleb Smirnoff break; 8063340d773SGleb Smirnoff 8073340d773SGleb Smirnoff case HNCP_NODE_NAME: { 8083340d773SGleb Smirnoff u_int l; 8093340d773SGleb Smirnoff if (bodylen < 17) { 810*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8113340d773SGleb Smirnoff break; 8123340d773SGleb Smirnoff } 813*ee67461eSJoseph Mingrone l = GET_U_1(value + 16); 8143340d773SGleb Smirnoff if (bodylen < 17 + l) { 815*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8163340d773SGleb Smirnoff break; 8173340d773SGleb Smirnoff } 818*ee67461eSJoseph Mingrone ND_PRINT(" IP-Address: %s Name: ", 8193340d773SGleb Smirnoff format_ip6addr(ndo, value) 820*ee67461eSJoseph Mingrone ); 8213340d773SGleb Smirnoff if (l < 64) { 822*ee67461eSJoseph Mingrone ND_PRINT("\""); 823*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 17, l); 824*ee67461eSJoseph Mingrone ND_PRINT("\""); 8253340d773SGleb Smirnoff } else { 826*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8273340d773SGleb Smirnoff } 8283340d773SGleb Smirnoff l += 17; 829*ee67461eSJoseph Mingrone l = roundup2(l, 4); 8303340d773SGleb Smirnoff if (bodylen >= l) 8313340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 8323340d773SGleb Smirnoff } 8333340d773SGleb Smirnoff break; 8343340d773SGleb Smirnoff 8353340d773SGleb Smirnoff case HNCP_MANAGED_PSK: { 8363340d773SGleb Smirnoff if (bodylen < 32) { 837*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8383340d773SGleb Smirnoff break; 8393340d773SGleb Smirnoff } 840*ee67461eSJoseph Mingrone ND_PRINT(" PSK: %s", format_256(ndo, value)); 8413340d773SGleb Smirnoff hncp_print_rec(ndo, value + 32, bodylen - 32, indent+1); 8423340d773SGleb Smirnoff } 8433340d773SGleb Smirnoff break; 8443340d773SGleb Smirnoff 8453340d773SGleb Smirnoff case RANGE_DNCP_RESERVED: 8463340d773SGleb Smirnoff case RANGE_HNCP_UNASSIGNED: 8473340d773SGleb Smirnoff case RANGE_DNCP_PRIVATE_USE: 8483340d773SGleb Smirnoff case RANGE_DNCP_FUTURE_USE: 8493340d773SGleb Smirnoff break; 8503340d773SGleb Smirnoff 8513340d773SGleb Smirnoff } 8523340d773SGleb Smirnoff skip_multiline: 8533340d773SGleb Smirnoff 854*ee67461eSJoseph Mingrone i += 4 + roundup2(bodylen, 4); 8553340d773SGleb Smirnoff } 8563340d773SGleb Smirnoff print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one); 8573340d773SGleb Smirnoff 8583340d773SGleb Smirnoff return; 8593340d773SGleb Smirnoff 8603340d773SGleb Smirnoff trunc: 861*ee67461eSJoseph Mingrone nd_print_trunc(ndo); 8623340d773SGleb Smirnoff return; 8633340d773SGleb Smirnoff 8643340d773SGleb Smirnoff invalid: 865*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8663340d773SGleb Smirnoff } 867