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 31*ee67461eSJoseph Mingrone #include <config.h> 323340d773SGleb Smirnoff 33*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 343340d773SGleb Smirnoff 353340d773SGleb Smirnoff #include <string.h> 363340d773SGleb Smirnoff 373340d773SGleb Smirnoff #include "netdissect.h" 383340d773SGleb Smirnoff #include "addrtoname.h" 393340d773SGleb Smirnoff #include "extract.h" 403340d773SGleb Smirnoff 413340d773SGleb Smirnoff static void 423340d773SGleb Smirnoff hncp_print_rec(netdissect_options *ndo, 433340d773SGleb Smirnoff const u_char *cp, u_int length, int indent); 443340d773SGleb Smirnoff 453340d773SGleb Smirnoff void 463340d773SGleb Smirnoff hncp_print(netdissect_options *ndo, 473340d773SGleb Smirnoff const u_char *cp, u_int length) 483340d773SGleb Smirnoff { 49*ee67461eSJoseph Mingrone ndo->ndo_protocol = "hncp"; 50*ee67461eSJoseph Mingrone ND_PRINT("hncp (%u)", length); 513340d773SGleb Smirnoff hncp_print_rec(ndo, cp, length, 1); 523340d773SGleb Smirnoff } 533340d773SGleb Smirnoff 543340d773SGleb Smirnoff /* RFC7787 */ 553340d773SGleb Smirnoff #define DNCP_REQUEST_NETWORK_STATE 1 563340d773SGleb Smirnoff #define DNCP_REQUEST_NODE_STATE 2 573340d773SGleb Smirnoff #define DNCP_NODE_ENDPOINT 3 583340d773SGleb Smirnoff #define DNCP_NETWORK_STATE 4 593340d773SGleb Smirnoff #define DNCP_NODE_STATE 5 603340d773SGleb Smirnoff #define DNCP_PEER 8 613340d773SGleb Smirnoff #define DNCP_KEEP_ALIVE_INTERVAL 9 623340d773SGleb Smirnoff #define DNCP_TRUST_VERDICT 10 633340d773SGleb Smirnoff 643340d773SGleb Smirnoff /* RFC7788 */ 653340d773SGleb Smirnoff #define HNCP_HNCP_VERSION 32 663340d773SGleb Smirnoff #define HNCP_EXTERNAL_CONNECTION 33 673340d773SGleb Smirnoff #define HNCP_DELEGATED_PREFIX 34 683340d773SGleb Smirnoff #define HNCP_PREFIX_POLICY 43 6939e421e8SCy Schubert #define HNCP_DHCPV4_DATA 37 /* This is correct, see RFC 7788 Errata ID 5113. */ 7039e421e8SCy Schubert #define HNCP_DHCPV6_DATA 38 /* idem */ 713340d773SGleb Smirnoff #define HNCP_ASSIGNED_PREFIX 35 723340d773SGleb Smirnoff #define HNCP_NODE_ADDRESS 36 733340d773SGleb Smirnoff #define HNCP_DNS_DELEGATED_ZONE 39 743340d773SGleb Smirnoff #define HNCP_DOMAIN_NAME 40 753340d773SGleb Smirnoff #define HNCP_NODE_NAME 41 763340d773SGleb Smirnoff #define HNCP_MANAGED_PSK 42 773340d773SGleb Smirnoff 783340d773SGleb Smirnoff /* See type_mask in hncp_print_rec below */ 793340d773SGleb Smirnoff #define RANGE_DNCP_RESERVED 0x10000 803340d773SGleb Smirnoff #define RANGE_HNCP_UNASSIGNED 0x10001 813340d773SGleb Smirnoff #define RANGE_DNCP_PRIVATE_USE 0x10002 823340d773SGleb Smirnoff #define RANGE_DNCP_FUTURE_USE 0x10003 833340d773SGleb Smirnoff 843340d773SGleb Smirnoff static const struct tok type_values[] = { 853340d773SGleb Smirnoff { DNCP_REQUEST_NETWORK_STATE, "Request network state" }, 863340d773SGleb Smirnoff { DNCP_REQUEST_NODE_STATE, "Request node state" }, 873340d773SGleb Smirnoff { DNCP_NODE_ENDPOINT, "Node endpoint" }, 883340d773SGleb Smirnoff { DNCP_NETWORK_STATE, "Network state" }, 893340d773SGleb Smirnoff { DNCP_NODE_STATE, "Node state" }, 903340d773SGleb Smirnoff { DNCP_PEER, "Peer" }, 913340d773SGleb Smirnoff { DNCP_KEEP_ALIVE_INTERVAL, "Keep-alive interval" }, 923340d773SGleb Smirnoff { DNCP_TRUST_VERDICT, "Trust-Verdict" }, 933340d773SGleb Smirnoff 943340d773SGleb Smirnoff { HNCP_HNCP_VERSION, "HNCP-Version" }, 953340d773SGleb Smirnoff { HNCP_EXTERNAL_CONNECTION, "External-Connection" }, 963340d773SGleb Smirnoff { HNCP_DELEGATED_PREFIX, "Delegated-Prefix" }, 973340d773SGleb Smirnoff { HNCP_PREFIX_POLICY, "Prefix-Policy" }, 983340d773SGleb Smirnoff { HNCP_DHCPV4_DATA, "DHCPv4-Data" }, 993340d773SGleb Smirnoff { HNCP_DHCPV6_DATA, "DHCPv6-Data" }, 1003340d773SGleb Smirnoff { HNCP_ASSIGNED_PREFIX, "Assigned-Prefix" }, 1013340d773SGleb Smirnoff { HNCP_NODE_ADDRESS, "Node-Address" }, 1023340d773SGleb Smirnoff { HNCP_DNS_DELEGATED_ZONE, "DNS-Delegated-Zone" }, 1033340d773SGleb Smirnoff { HNCP_DOMAIN_NAME, "Domain-Name" }, 1043340d773SGleb Smirnoff { HNCP_NODE_NAME, "Node-Name" }, 1053340d773SGleb Smirnoff { HNCP_MANAGED_PSK, "Managed-PSK" }, 1063340d773SGleb Smirnoff 1073340d773SGleb Smirnoff { RANGE_DNCP_RESERVED, "Reserved" }, 1083340d773SGleb Smirnoff { RANGE_HNCP_UNASSIGNED, "Unassigned" }, 1093340d773SGleb Smirnoff { RANGE_DNCP_PRIVATE_USE, "Private use" }, 1103340d773SGleb Smirnoff { RANGE_DNCP_FUTURE_USE, "Future use" }, 1113340d773SGleb Smirnoff 1123340d773SGleb Smirnoff { 0, NULL} 1133340d773SGleb Smirnoff }; 1143340d773SGleb Smirnoff 1153340d773SGleb Smirnoff #define DH4OPT_DNS_SERVERS 6 /* RFC2132 */ 1163340d773SGleb Smirnoff #define DH4OPT_NTP_SERVERS 42 /* RFC2132 */ 1173340d773SGleb Smirnoff #define DH4OPT_DOMAIN_SEARCH 119 /* RFC3397 */ 1183340d773SGleb Smirnoff 1193340d773SGleb Smirnoff static const struct tok dh4opt_str[] = { 1203340d773SGleb Smirnoff { DH4OPT_DNS_SERVERS, "DNS-server" }, 1213340d773SGleb Smirnoff { DH4OPT_NTP_SERVERS, "NTP-server"}, 1223340d773SGleb Smirnoff { DH4OPT_DOMAIN_SEARCH, "DNS-search" }, 1233340d773SGleb Smirnoff { 0, NULL } 1243340d773SGleb Smirnoff }; 1253340d773SGleb Smirnoff 1263340d773SGleb Smirnoff #define DH6OPT_DNS_SERVERS 23 /* RFC3646 */ 1273340d773SGleb Smirnoff #define DH6OPT_DOMAIN_LIST 24 /* RFC3646 */ 1283340d773SGleb Smirnoff #define DH6OPT_SNTP_SERVERS 31 /* RFC4075 */ 1293340d773SGleb Smirnoff 1303340d773SGleb Smirnoff static const struct tok dh6opt_str[] = { 1313340d773SGleb Smirnoff { DH6OPT_DNS_SERVERS, "DNS-server" }, 1323340d773SGleb Smirnoff { DH6OPT_DOMAIN_LIST, "DNS-search-list" }, 1333340d773SGleb Smirnoff { DH6OPT_SNTP_SERVERS, "SNTP-servers" }, 1343340d773SGleb Smirnoff { 0, NULL } 1353340d773SGleb Smirnoff }; 1363340d773SGleb Smirnoff 1373340d773SGleb Smirnoff /* 1383340d773SGleb Smirnoff * For IPv4-mapped IPv6 addresses, length of the prefix that precedes 1393340d773SGleb Smirnoff * the 4 bytes of IPv4 address at the end of the IPv6 address. 1403340d773SGleb Smirnoff */ 1413340d773SGleb Smirnoff #define IPV4_MAPPED_HEADING_LEN 12 1423340d773SGleb Smirnoff 1433340d773SGleb Smirnoff /* 1443340d773SGleb Smirnoff * Is an IPv6 address an IPv4-mapped address? 1453340d773SGleb Smirnoff */ 146*ee67461eSJoseph Mingrone static int 1473340d773SGleb Smirnoff is_ipv4_mapped_address(const u_char *addr) 1483340d773SGleb Smirnoff { 1493340d773SGleb Smirnoff /* The value of the prefix */ 1503340d773SGleb Smirnoff static const u_char ipv4_mapped_heading[IPV4_MAPPED_HEADING_LEN] = 1513340d773SGleb Smirnoff { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF }; 1523340d773SGleb Smirnoff 1533340d773SGleb Smirnoff return memcmp(addr, ipv4_mapped_heading, IPV4_MAPPED_HEADING_LEN) == 0; 1543340d773SGleb Smirnoff } 1553340d773SGleb Smirnoff 1563340d773SGleb Smirnoff static const char * 157*ee67461eSJoseph Mingrone format_nid(netdissect_options *ndo, const u_char *data) 1583340d773SGleb Smirnoff { 15939e421e8SCy Schubert static char buf[4][sizeof("01:01:01:01")]; 1603340d773SGleb Smirnoff static int i = 0; 1613340d773SGleb Smirnoff i = (i + 1) % 4; 16239e421e8SCy Schubert snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x", 163*ee67461eSJoseph Mingrone GET_U_1(data), GET_U_1(data + 1), GET_U_1(data + 2), 164*ee67461eSJoseph Mingrone GET_U_1(data + 3)); 1653340d773SGleb Smirnoff return buf[i]; 1663340d773SGleb Smirnoff } 1673340d773SGleb Smirnoff 1683340d773SGleb Smirnoff static const char * 169*ee67461eSJoseph Mingrone format_256(netdissect_options *ndo, const u_char *data) 1703340d773SGleb Smirnoff { 17139e421e8SCy Schubert static char buf[4][sizeof("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")]; 1723340d773SGleb Smirnoff static int i = 0; 1733340d773SGleb Smirnoff i = (i + 1) % 4; 17439e421e8SCy Schubert snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64, 175*ee67461eSJoseph Mingrone GET_BE_U_8(data), 176*ee67461eSJoseph Mingrone GET_BE_U_8(data + 8), 177*ee67461eSJoseph Mingrone GET_BE_U_8(data + 16), 178*ee67461eSJoseph Mingrone GET_BE_U_8(data + 24) 1793340d773SGleb Smirnoff ); 1803340d773SGleb Smirnoff return buf[i]; 1813340d773SGleb Smirnoff } 1823340d773SGleb Smirnoff 1833340d773SGleb Smirnoff static const char * 1843340d773SGleb Smirnoff format_interval(const uint32_t n) 1853340d773SGleb Smirnoff { 1863340d773SGleb Smirnoff static char buf[4][sizeof("0000000.000s")]; 1873340d773SGleb Smirnoff static int i = 0; 1883340d773SGleb Smirnoff i = (i + 1) % 4; 1893340d773SGleb Smirnoff snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000); 1903340d773SGleb Smirnoff return buf[i]; 1913340d773SGleb Smirnoff } 1923340d773SGleb Smirnoff 1933340d773SGleb Smirnoff static const char * 1943340d773SGleb Smirnoff format_ip6addr(netdissect_options *ndo, const u_char *cp) 1953340d773SGleb Smirnoff { 1963340d773SGleb Smirnoff if (is_ipv4_mapped_address(cp)) 197*ee67461eSJoseph Mingrone return GET_IPADDR_STRING(cp + IPV4_MAPPED_HEADING_LEN); 1983340d773SGleb Smirnoff else 199*ee67461eSJoseph Mingrone return GET_IP6ADDR_STRING(cp); 2003340d773SGleb Smirnoff } 2013340d773SGleb Smirnoff 2023340d773SGleb Smirnoff static int 2033340d773SGleb Smirnoff print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length) 2043340d773SGleb Smirnoff { 2053340d773SGleb Smirnoff int plenbytes; 2063340d773SGleb Smirnoff char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")]; 2073340d773SGleb Smirnoff 208*ee67461eSJoseph Mingrone if (GET_U_1(prefix) >= 96 && max_length >= IPV4_MAPPED_HEADING_LEN + 1 && 209*ee67461eSJoseph Mingrone is_ipv4_mapped_address(prefix + 1)) { 210*ee67461eSJoseph Mingrone nd_ipv4 addr; 2113340d773SGleb Smirnoff u_int plen; 2123340d773SGleb Smirnoff 213*ee67461eSJoseph Mingrone plen = GET_U_1(prefix) - 96; 2143340d773SGleb Smirnoff if (32 < plen) 2153340d773SGleb Smirnoff return -1; 2163340d773SGleb Smirnoff max_length -= 1; 2173340d773SGleb Smirnoff 2183340d773SGleb Smirnoff memset(&addr, 0, sizeof(addr)); 2193340d773SGleb Smirnoff plenbytes = (plen + 7) / 8; 2203340d773SGleb Smirnoff if (max_length < (u_int)plenbytes + IPV4_MAPPED_HEADING_LEN) 2213340d773SGleb Smirnoff return -3; 222*ee67461eSJoseph Mingrone memcpy(&addr, prefix + IPV4_MAPPED_HEADING_LEN + 1, plenbytes); 2233340d773SGleb Smirnoff if (plen % 8) { 2243340d773SGleb Smirnoff ((u_char *)&addr)[plenbytes - 1] &= 2253340d773SGleb Smirnoff ((0xff00 >> (plen % 8)) & 0xff); 2263340d773SGleb Smirnoff } 227*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() */ 2283340d773SGleb Smirnoff plenbytes += 1 + IPV4_MAPPED_HEADING_LEN; 2293340d773SGleb Smirnoff } else { 2303340d773SGleb Smirnoff plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf)); 23139e421e8SCy Schubert if (plenbytes < 0) 23239e421e8SCy Schubert return plenbytes; 2333340d773SGleb Smirnoff } 2343340d773SGleb Smirnoff 235*ee67461eSJoseph Mingrone ND_PRINT("%s", buf); 2363340d773SGleb Smirnoff return plenbytes; 2373340d773SGleb Smirnoff } 2383340d773SGleb Smirnoff 2393340d773SGleb Smirnoff static int 2403340d773SGleb Smirnoff print_dns_label(netdissect_options *ndo, 2413340d773SGleb Smirnoff const u_char *cp, u_int max_length, int print) 2423340d773SGleb Smirnoff { 2433340d773SGleb Smirnoff u_int length = 0; 2443340d773SGleb Smirnoff while (length < max_length) { 245*ee67461eSJoseph Mingrone u_int lab_length = GET_U_1(cp + length); 246*ee67461eSJoseph Mingrone length++; 2473340d773SGleb Smirnoff if (lab_length == 0) 2483340d773SGleb Smirnoff return (int)length; 2493340d773SGleb Smirnoff if (length > 1 && print) 250*ee67461eSJoseph Mingrone ND_PRINT("."); 2513340d773SGleb Smirnoff if (length+lab_length > max_length) { 2523340d773SGleb Smirnoff if (print) 253*ee67461eSJoseph Mingrone nd_printjnp(ndo, cp+length, max_length-length); 2543340d773SGleb Smirnoff break; 2553340d773SGleb Smirnoff } 2563340d773SGleb Smirnoff if (print) 257*ee67461eSJoseph Mingrone nd_printjnp(ndo, cp+length, lab_length); 2583340d773SGleb Smirnoff length += lab_length; 2593340d773SGleb Smirnoff } 2603340d773SGleb Smirnoff if (print) 261*ee67461eSJoseph Mingrone ND_PRINT("[|DNS]"); 2623340d773SGleb Smirnoff return -1; 2633340d773SGleb Smirnoff } 2643340d773SGleb Smirnoff 2653340d773SGleb Smirnoff static int 2663340d773SGleb Smirnoff dhcpv4_print(netdissect_options *ndo, 2673340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 2683340d773SGleb Smirnoff { 2693340d773SGleb Smirnoff u_int i, t; 270*ee67461eSJoseph Mingrone const uint8_t *tlv, *value; 2713340d773SGleb Smirnoff uint8_t type, optlen; 2723340d773SGleb Smirnoff 2733340d773SGleb Smirnoff i = 0; 2743340d773SGleb Smirnoff while (i < length) { 2750bff6a5aSEd Maste if (i + 2 > length) 2760bff6a5aSEd Maste return -1; 2773340d773SGleb Smirnoff tlv = cp + i; 278*ee67461eSJoseph Mingrone type = GET_U_1(tlv); 279*ee67461eSJoseph Mingrone optlen = GET_U_1(tlv + 1); 2803340d773SGleb Smirnoff value = tlv + 2; 2813340d773SGleb Smirnoff 282*ee67461eSJoseph Mingrone ND_PRINT("\n"); 2833340d773SGleb Smirnoff for (t = indent; t > 0; t--) 284*ee67461eSJoseph Mingrone ND_PRINT("\t"); 2853340d773SGleb Smirnoff 286*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(dh4opt_str, "Unknown", type)); 287*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", optlen + 2 ); 2880bff6a5aSEd Maste if (i + 2 + optlen > length) 2890bff6a5aSEd Maste return -1; 2903340d773SGleb Smirnoff 2913340d773SGleb Smirnoff switch (type) { 2923340d773SGleb Smirnoff case DH4OPT_DNS_SERVERS: 2933340d773SGleb Smirnoff case DH4OPT_NTP_SERVERS: { 2943340d773SGleb Smirnoff if (optlen < 4 || optlen % 4 != 0) { 2953340d773SGleb Smirnoff return -1; 2963340d773SGleb Smirnoff } 2973340d773SGleb Smirnoff for (t = 0; t < optlen; t += 4) 298*ee67461eSJoseph Mingrone ND_PRINT(" %s", GET_IPADDR_STRING(value + t)); 2993340d773SGleb Smirnoff } 3003340d773SGleb Smirnoff break; 3013340d773SGleb Smirnoff case DH4OPT_DOMAIN_SEARCH: { 3023340d773SGleb Smirnoff const u_char *tp = value; 3033340d773SGleb Smirnoff while (tp < value + optlen) { 304*ee67461eSJoseph Mingrone ND_PRINT(" "); 305*ee67461eSJoseph Mingrone if ((tp = fqdn_print(ndo, tp, value + optlen)) == NULL) 3063340d773SGleb Smirnoff return -1; 3073340d773SGleb Smirnoff } 3083340d773SGleb Smirnoff } 3093340d773SGleb Smirnoff break; 3103340d773SGleb Smirnoff } 3113340d773SGleb Smirnoff 3123340d773SGleb Smirnoff i += 2 + optlen; 3133340d773SGleb Smirnoff } 3143340d773SGleb Smirnoff return 0; 3153340d773SGleb Smirnoff } 3163340d773SGleb Smirnoff 3173340d773SGleb Smirnoff static int 3183340d773SGleb Smirnoff dhcpv6_print(netdissect_options *ndo, 3193340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 3203340d773SGleb Smirnoff { 3213340d773SGleb Smirnoff u_int i, t; 3223340d773SGleb Smirnoff const u_char *tlv, *value; 3233340d773SGleb Smirnoff uint16_t type, optlen; 3243340d773SGleb Smirnoff 3253340d773SGleb Smirnoff i = 0; 3263340d773SGleb Smirnoff while (i < length) { 3270bff6a5aSEd Maste if (i + 4 > length) 3280bff6a5aSEd Maste return -1; 3293340d773SGleb Smirnoff tlv = cp + i; 330*ee67461eSJoseph Mingrone type = GET_BE_U_2(tlv); 331*ee67461eSJoseph Mingrone optlen = GET_BE_U_2(tlv + 2); 3323340d773SGleb Smirnoff value = tlv + 4; 3333340d773SGleb Smirnoff 334*ee67461eSJoseph Mingrone ND_PRINT("\n"); 3353340d773SGleb Smirnoff for (t = indent; t > 0; t--) 336*ee67461eSJoseph Mingrone ND_PRINT("\t"); 3373340d773SGleb Smirnoff 338*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(dh6opt_str, "Unknown", type)); 339*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", optlen + 4 ); 3400bff6a5aSEd Maste if (i + 4 + optlen > length) 3410bff6a5aSEd Maste return -1; 3423340d773SGleb Smirnoff 3433340d773SGleb Smirnoff switch (type) { 3443340d773SGleb Smirnoff case DH6OPT_DNS_SERVERS: 3453340d773SGleb Smirnoff case DH6OPT_SNTP_SERVERS: { 3463340d773SGleb Smirnoff if (optlen % 16 != 0) { 347*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 3483340d773SGleb Smirnoff return -1; 3493340d773SGleb Smirnoff } 3503340d773SGleb Smirnoff for (t = 0; t < optlen; t += 16) 351*ee67461eSJoseph Mingrone ND_PRINT(" %s", GET_IP6ADDR_STRING(value + t)); 3523340d773SGleb Smirnoff } 3533340d773SGleb Smirnoff break; 3543340d773SGleb Smirnoff case DH6OPT_DOMAIN_LIST: { 3553340d773SGleb Smirnoff const u_char *tp = value; 3563340d773SGleb Smirnoff while (tp < value + optlen) { 357*ee67461eSJoseph Mingrone ND_PRINT(" "); 358*ee67461eSJoseph Mingrone if ((tp = fqdn_print(ndo, tp, value + optlen)) == NULL) 3593340d773SGleb Smirnoff return -1; 3603340d773SGleb Smirnoff } 3613340d773SGleb Smirnoff } 3623340d773SGleb Smirnoff break; 3633340d773SGleb Smirnoff } 3643340d773SGleb Smirnoff 3653340d773SGleb Smirnoff i += 4 + optlen; 3663340d773SGleb Smirnoff } 3673340d773SGleb Smirnoff return 0; 3683340d773SGleb Smirnoff } 3693340d773SGleb Smirnoff 3703340d773SGleb Smirnoff /* Determine in-line mode */ 3713340d773SGleb Smirnoff static int 3723340d773SGleb Smirnoff is_in_line(netdissect_options *ndo, int indent) 3733340d773SGleb Smirnoff { 3743340d773SGleb Smirnoff return indent - 1 >= ndo->ndo_vflag && ndo->ndo_vflag < 3; 3753340d773SGleb Smirnoff } 3763340d773SGleb Smirnoff 3773340d773SGleb Smirnoff static void 3783340d773SGleb Smirnoff print_type_in_line(netdissect_options *ndo, 3793340d773SGleb Smirnoff uint32_t type, int count, int indent, int *first_one) 3803340d773SGleb Smirnoff { 3813340d773SGleb Smirnoff if (count > 0) { 3823340d773SGleb Smirnoff if (*first_one) { 3833340d773SGleb Smirnoff *first_one = 0; 3843340d773SGleb Smirnoff if (indent > 1) { 3853340d773SGleb Smirnoff u_int t; 386*ee67461eSJoseph Mingrone ND_PRINT("\n"); 3873340d773SGleb Smirnoff for (t = indent; t > 0; t--) 388*ee67461eSJoseph Mingrone ND_PRINT("\t"); 3893340d773SGleb Smirnoff } else { 390*ee67461eSJoseph Mingrone ND_PRINT(" "); 3913340d773SGleb Smirnoff } 3923340d773SGleb Smirnoff } else { 393*ee67461eSJoseph Mingrone ND_PRINT(", "); 3943340d773SGleb Smirnoff } 395*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(type_values, "Easter Egg", type)); 3963340d773SGleb Smirnoff if (count > 1) 397*ee67461eSJoseph Mingrone ND_PRINT(" (x%d)", count); 3983340d773SGleb Smirnoff } 3993340d773SGleb Smirnoff } 4003340d773SGleb Smirnoff 401*ee67461eSJoseph Mingrone static void 4023340d773SGleb Smirnoff hncp_print_rec(netdissect_options *ndo, 4033340d773SGleb Smirnoff const u_char *cp, u_int length, int indent) 4043340d773SGleb Smirnoff { 4053340d773SGleb Smirnoff const int in_line = is_in_line(ndo, indent); 4063340d773SGleb Smirnoff int first_one = 1; 4073340d773SGleb Smirnoff 4083340d773SGleb Smirnoff u_int i, t; 4093340d773SGleb Smirnoff 4103340d773SGleb Smirnoff uint32_t last_type_mask = 0xffffffffU; 4113340d773SGleb Smirnoff int last_type_count = -1; 4123340d773SGleb Smirnoff 413*ee67461eSJoseph Mingrone const uint8_t *tlv, *value; 4143340d773SGleb Smirnoff uint16_t type, bodylen; 4153340d773SGleb Smirnoff uint32_t type_mask; 4163340d773SGleb Smirnoff 4173340d773SGleb Smirnoff i = 0; 4183340d773SGleb Smirnoff while (i < length) { 4193340d773SGleb Smirnoff tlv = cp + i; 4203340d773SGleb Smirnoff 4213340d773SGleb Smirnoff if (!in_line) { 422*ee67461eSJoseph Mingrone ND_PRINT("\n"); 4233340d773SGleb Smirnoff for (t = indent; t > 0; t--) 424*ee67461eSJoseph Mingrone ND_PRINT("\t"); 4253340d773SGleb Smirnoff } 4263340d773SGleb Smirnoff 427*ee67461eSJoseph Mingrone ND_TCHECK_4(tlv); 4283340d773SGleb Smirnoff if (i + 4 > length) 4293340d773SGleb Smirnoff goto invalid; 4303340d773SGleb Smirnoff 431*ee67461eSJoseph Mingrone type = GET_BE_U_2(tlv); 432*ee67461eSJoseph Mingrone bodylen = GET_BE_U_2(tlv + 2); 4333340d773SGleb Smirnoff value = tlv + 4; 434*ee67461eSJoseph Mingrone ND_TCHECK_LEN(value, bodylen); 4353340d773SGleb Smirnoff if (i + bodylen + 4 > length) 4363340d773SGleb Smirnoff goto invalid; 4373340d773SGleb Smirnoff 4383340d773SGleb Smirnoff type_mask = 4393340d773SGleb Smirnoff (type == 0) ? RANGE_DNCP_RESERVED: 4403340d773SGleb Smirnoff (44 <= type && type <= 511) ? RANGE_HNCP_UNASSIGNED: 4413340d773SGleb Smirnoff (768 <= type && type <= 1023) ? RANGE_DNCP_PRIVATE_USE: 4423340d773SGleb Smirnoff RANGE_DNCP_FUTURE_USE; 4433340d773SGleb Smirnoff if (type == 6 || type == 7) 4443340d773SGleb Smirnoff type_mask = RANGE_DNCP_FUTURE_USE; 4453340d773SGleb Smirnoff 4463340d773SGleb Smirnoff /* defined types */ 4473340d773SGleb Smirnoff { 4483340d773SGleb Smirnoff t = 0; 4493340d773SGleb Smirnoff while (1) { 4503340d773SGleb Smirnoff u_int key = type_values[t++].v; 4513340d773SGleb Smirnoff if (key > 0xffff) 4523340d773SGleb Smirnoff break; 4533340d773SGleb Smirnoff if (key == type) { 4543340d773SGleb Smirnoff type_mask = type; 4553340d773SGleb Smirnoff break; 4563340d773SGleb Smirnoff } 4573340d773SGleb Smirnoff } 4583340d773SGleb Smirnoff } 4593340d773SGleb Smirnoff 4603340d773SGleb Smirnoff if (in_line) { 4613340d773SGleb Smirnoff if (last_type_mask == type_mask) { 4623340d773SGleb Smirnoff last_type_count++; 4633340d773SGleb Smirnoff } else { 4643340d773SGleb Smirnoff print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one); 4653340d773SGleb Smirnoff last_type_mask = type_mask; 4663340d773SGleb Smirnoff last_type_count = 1; 4673340d773SGleb Smirnoff } 4683340d773SGleb Smirnoff 4693340d773SGleb Smirnoff goto skip_multiline; 4703340d773SGleb Smirnoff } 4713340d773SGleb Smirnoff 472*ee67461eSJoseph Mingrone ND_PRINT("%s", tok2str(type_values, "Easter Egg (42)", type_mask) ); 4733340d773SGleb Smirnoff if (type_mask > 0xffff) 474*ee67461eSJoseph Mingrone ND_PRINT(": type=%u", type ); 475*ee67461eSJoseph Mingrone ND_PRINT(" (%u)", bodylen + 4 ); 4763340d773SGleb Smirnoff 4773340d773SGleb Smirnoff switch (type_mask) { 4783340d773SGleb Smirnoff 4793340d773SGleb Smirnoff case DNCP_REQUEST_NETWORK_STATE: { 4803340d773SGleb Smirnoff if (bodylen != 0) 481*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 4823340d773SGleb Smirnoff } 4833340d773SGleb Smirnoff break; 4843340d773SGleb Smirnoff 4853340d773SGleb Smirnoff case DNCP_REQUEST_NODE_STATE: { 4863340d773SGleb Smirnoff const char *node_identifier; 4873340d773SGleb Smirnoff if (bodylen != 4) { 488*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 4893340d773SGleb Smirnoff break; 4903340d773SGleb Smirnoff } 491*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 492*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s", node_identifier); 4933340d773SGleb Smirnoff } 4943340d773SGleb Smirnoff break; 4953340d773SGleb Smirnoff 4963340d773SGleb Smirnoff case DNCP_NODE_ENDPOINT: { 4973340d773SGleb Smirnoff const char *node_identifier; 4983340d773SGleb Smirnoff uint32_t endpoint_identifier; 4993340d773SGleb Smirnoff if (bodylen != 8) { 500*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5013340d773SGleb Smirnoff break; 5023340d773SGleb Smirnoff } 503*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 504*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value + 4); 505*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s EPID: %08x", 5063340d773SGleb Smirnoff node_identifier, 5073340d773SGleb Smirnoff endpoint_identifier 508*ee67461eSJoseph Mingrone ); 5093340d773SGleb Smirnoff } 5103340d773SGleb Smirnoff break; 5113340d773SGleb Smirnoff 5123340d773SGleb Smirnoff case DNCP_NETWORK_STATE: { 5133340d773SGleb Smirnoff uint64_t hash; 5143340d773SGleb Smirnoff if (bodylen != 8) { 515*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5163340d773SGleb Smirnoff break; 5173340d773SGleb Smirnoff } 518*ee67461eSJoseph Mingrone hash = GET_BE_U_8(value); 519*ee67461eSJoseph Mingrone ND_PRINT(" hash: %016" PRIx64, hash); 5203340d773SGleb Smirnoff } 5213340d773SGleb Smirnoff break; 5223340d773SGleb Smirnoff 5233340d773SGleb Smirnoff case DNCP_NODE_STATE: { 5243340d773SGleb Smirnoff const char *node_identifier, *interval; 5253340d773SGleb Smirnoff uint32_t sequence_number; 5263340d773SGleb Smirnoff uint64_t hash; 5273340d773SGleb Smirnoff if (bodylen < 20) { 528*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5293340d773SGleb Smirnoff break; 5303340d773SGleb Smirnoff } 531*ee67461eSJoseph Mingrone node_identifier = format_nid(ndo, value); 532*ee67461eSJoseph Mingrone sequence_number = GET_BE_U_4(value + 4); 533*ee67461eSJoseph Mingrone interval = format_interval(GET_BE_U_4(value + 8)); 534*ee67461eSJoseph Mingrone hash = GET_BE_U_8(value + 12); 535*ee67461eSJoseph Mingrone ND_PRINT(" NID: %s seqno: %u %s hash: %016" PRIx64, 5363340d773SGleb Smirnoff node_identifier, 5373340d773SGleb Smirnoff sequence_number, 5383340d773SGleb Smirnoff interval, 5393340d773SGleb Smirnoff hash 540*ee67461eSJoseph Mingrone ); 5413340d773SGleb Smirnoff hncp_print_rec(ndo, value+20, bodylen-20, indent+1); 5423340d773SGleb Smirnoff } 5433340d773SGleb Smirnoff break; 5443340d773SGleb Smirnoff 5453340d773SGleb Smirnoff case DNCP_PEER: { 5463340d773SGleb Smirnoff const char *peer_node_identifier; 5473340d773SGleb Smirnoff uint32_t peer_endpoint_identifier, endpoint_identifier; 5483340d773SGleb Smirnoff if (bodylen != 12) { 549*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5503340d773SGleb Smirnoff break; 5513340d773SGleb Smirnoff } 552*ee67461eSJoseph Mingrone peer_node_identifier = format_nid(ndo, value); 553*ee67461eSJoseph Mingrone peer_endpoint_identifier = GET_BE_U_4(value + 4); 554*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value + 8); 555*ee67461eSJoseph Mingrone ND_PRINT(" Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x", 5563340d773SGleb Smirnoff peer_node_identifier, 5573340d773SGleb Smirnoff peer_endpoint_identifier, 5583340d773SGleb Smirnoff endpoint_identifier 559*ee67461eSJoseph Mingrone ); 5603340d773SGleb Smirnoff } 5613340d773SGleb Smirnoff break; 5623340d773SGleb Smirnoff 5633340d773SGleb Smirnoff case DNCP_KEEP_ALIVE_INTERVAL: { 5643340d773SGleb Smirnoff uint32_t endpoint_identifier; 5653340d773SGleb Smirnoff const char *interval; 5663340d773SGleb Smirnoff if (bodylen < 8) { 567*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5683340d773SGleb Smirnoff break; 5693340d773SGleb Smirnoff } 570*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value); 571*ee67461eSJoseph Mingrone interval = format_interval(GET_BE_U_4(value + 4)); 572*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x Interval: %s", 5733340d773SGleb Smirnoff endpoint_identifier, 5743340d773SGleb Smirnoff interval 575*ee67461eSJoseph Mingrone ); 5763340d773SGleb Smirnoff } 5773340d773SGleb Smirnoff break; 5783340d773SGleb Smirnoff 5793340d773SGleb Smirnoff case DNCP_TRUST_VERDICT: { 5803340d773SGleb Smirnoff if (bodylen <= 36) { 581*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5823340d773SGleb Smirnoff break; 5833340d773SGleb Smirnoff } 584*ee67461eSJoseph Mingrone ND_PRINT(" Verdict: %u Fingerprint: %s Common Name: ", 585*ee67461eSJoseph Mingrone GET_U_1(value), 586*ee67461eSJoseph Mingrone format_256(ndo, value + 4)); 587*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 36, bodylen - 36); 5883340d773SGleb Smirnoff } 5893340d773SGleb Smirnoff break; 5903340d773SGleb Smirnoff 5913340d773SGleb Smirnoff case HNCP_HNCP_VERSION: { 5923340d773SGleb Smirnoff uint16_t capabilities; 5933340d773SGleb Smirnoff uint8_t M, P, H, L; 5943340d773SGleb Smirnoff if (bodylen < 5) { 595*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 5963340d773SGleb Smirnoff break; 5973340d773SGleb Smirnoff } 598*ee67461eSJoseph Mingrone capabilities = GET_BE_U_2(value + 2); 5993340d773SGleb Smirnoff M = (uint8_t)((capabilities >> 12) & 0xf); 6003340d773SGleb Smirnoff P = (uint8_t)((capabilities >> 8) & 0xf); 6013340d773SGleb Smirnoff H = (uint8_t)((capabilities >> 4) & 0xf); 6023340d773SGleb Smirnoff L = (uint8_t)(capabilities & 0xf); 603*ee67461eSJoseph Mingrone ND_PRINT(" M: %u P: %u H: %u L: %u User-agent: ", 6043340d773SGleb Smirnoff M, P, H, L 605*ee67461eSJoseph Mingrone ); 606*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 4, bodylen - 4); 6073340d773SGleb Smirnoff } 6083340d773SGleb Smirnoff break; 6093340d773SGleb Smirnoff 6103340d773SGleb Smirnoff case HNCP_EXTERNAL_CONNECTION: { 6113340d773SGleb Smirnoff /* Container TLV */ 6123340d773SGleb Smirnoff hncp_print_rec(ndo, value, bodylen, indent+1); 6133340d773SGleb Smirnoff } 6143340d773SGleb Smirnoff break; 6153340d773SGleb Smirnoff 6163340d773SGleb Smirnoff case HNCP_DELEGATED_PREFIX: { 6173340d773SGleb Smirnoff int l; 618*ee67461eSJoseph Mingrone if (bodylen < 9 || bodylen < 9 + (GET_U_1(value + 8) + 7) / 8) { 619*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6203340d773SGleb Smirnoff break; 6213340d773SGleb Smirnoff } 622*ee67461eSJoseph Mingrone ND_PRINT(" VLSO: %s PLSO: %s Prefix: ", 623*ee67461eSJoseph Mingrone format_interval(GET_BE_U_4(value)), 624*ee67461eSJoseph Mingrone format_interval(GET_BE_U_4(value + 4)) 625*ee67461eSJoseph Mingrone ); 6263340d773SGleb Smirnoff l = print_prefix(ndo, value + 8, bodylen - 8); 6273340d773SGleb Smirnoff if (l == -1) { 628*ee67461eSJoseph Mingrone ND_PRINT("(length is invalid)"); 6293340d773SGleb Smirnoff break; 6303340d773SGleb Smirnoff } 6313340d773SGleb Smirnoff if (l < 0) { 6323340d773SGleb Smirnoff /* 6333340d773SGleb Smirnoff * We've already checked that we've captured the 6343340d773SGleb Smirnoff * entire TLV, based on its length, so this will 6353340d773SGleb Smirnoff * either be -1, meaning "the prefix length is 6363340d773SGleb Smirnoff * greater than the longest possible address of 6373340d773SGleb Smirnoff * that type" (i.e., > 32 for IPv4 or > 128 for 6383340d773SGleb Smirnoff * IPv6", or -3, meaning "the prefix runs past 6393340d773SGleb Smirnoff * the end of the TLV". 6403340d773SGleb Smirnoff */ 641*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6423340d773SGleb Smirnoff break; 6433340d773SGleb Smirnoff } 6443340d773SGleb Smirnoff l += 8 + (-l & 3); 6453340d773SGleb Smirnoff 6463340d773SGleb Smirnoff if (bodylen >= l) 6473340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 6483340d773SGleb Smirnoff } 6493340d773SGleb Smirnoff break; 6503340d773SGleb Smirnoff 6513340d773SGleb Smirnoff case HNCP_PREFIX_POLICY: { 6523340d773SGleb Smirnoff uint8_t policy; 6533340d773SGleb Smirnoff int l; 6543340d773SGleb Smirnoff if (bodylen < 1) { 655*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6563340d773SGleb Smirnoff break; 6573340d773SGleb Smirnoff } 658*ee67461eSJoseph Mingrone policy = GET_U_1(value); 659*ee67461eSJoseph Mingrone ND_PRINT(" type: "); 6603340d773SGleb Smirnoff if (policy == 0) { 6613340d773SGleb Smirnoff if (bodylen != 1) { 662*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6633340d773SGleb Smirnoff break; 6643340d773SGleb Smirnoff } 665*ee67461eSJoseph Mingrone ND_PRINT("Internet connectivity"); 6663340d773SGleb Smirnoff } else if (policy >= 1 && policy <= 128) { 667*ee67461eSJoseph Mingrone ND_PRINT("Dest-Prefix: "); 6683340d773SGleb Smirnoff l = print_prefix(ndo, value, bodylen); 6693340d773SGleb Smirnoff if (l == -1) { 670*ee67461eSJoseph Mingrone ND_PRINT("(length is invalid)"); 6713340d773SGleb Smirnoff break; 6723340d773SGleb Smirnoff } 6733340d773SGleb Smirnoff if (l < 0) { 6743340d773SGleb Smirnoff /* 6753340d773SGleb Smirnoff * We've already checked that we've captured the 6763340d773SGleb Smirnoff * entire TLV, based on its length, so this will 6773340d773SGleb Smirnoff * either be -1, meaning "the prefix length is 6783340d773SGleb Smirnoff * greater than the longest possible address of 6793340d773SGleb Smirnoff * that type" (i.e., > 32 for IPv4 or > 128 for 6803340d773SGleb Smirnoff * IPv6", or -3, meaning "the prefix runs past 6813340d773SGleb Smirnoff * the end of the TLV". 6823340d773SGleb Smirnoff */ 683*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6843340d773SGleb Smirnoff break; 6853340d773SGleb Smirnoff } 6863340d773SGleb Smirnoff } else if (policy == 129) { 687*ee67461eSJoseph Mingrone ND_PRINT("DNS domain: "); 6883340d773SGleb Smirnoff print_dns_label(ndo, value+1, bodylen-1, 1); 6893340d773SGleb Smirnoff } else if (policy == 130) { 690*ee67461eSJoseph Mingrone ND_PRINT("Opaque UTF-8: "); 691*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 1, bodylen - 1); 6923340d773SGleb Smirnoff } else if (policy == 131) { 6933340d773SGleb Smirnoff if (bodylen != 1) { 694*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 6953340d773SGleb Smirnoff break; 6963340d773SGleb Smirnoff } 697*ee67461eSJoseph Mingrone ND_PRINT("Restrictive assignment"); 6983340d773SGleb Smirnoff } else if (policy >= 132) { 699*ee67461eSJoseph Mingrone ND_PRINT("Unknown (%u)", policy); /* Reserved for future additions */ 7003340d773SGleb Smirnoff } 7013340d773SGleb Smirnoff } 7023340d773SGleb Smirnoff break; 7033340d773SGleb Smirnoff 7043340d773SGleb Smirnoff case HNCP_DHCPV4_DATA: { 7053340d773SGleb Smirnoff if (bodylen == 0) { 706*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7073340d773SGleb Smirnoff break; 7083340d773SGleb Smirnoff } 7093340d773SGleb Smirnoff if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0) 7103340d773SGleb Smirnoff goto invalid; 7113340d773SGleb Smirnoff } 7123340d773SGleb Smirnoff break; 7133340d773SGleb Smirnoff 7143340d773SGleb Smirnoff case HNCP_DHCPV6_DATA: { 7153340d773SGleb Smirnoff if (bodylen == 0) { 716*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7173340d773SGleb Smirnoff break; 7183340d773SGleb Smirnoff } 7193340d773SGleb Smirnoff if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0) { 720*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7213340d773SGleb Smirnoff break; 7223340d773SGleb Smirnoff } 7233340d773SGleb Smirnoff } 7243340d773SGleb Smirnoff break; 7253340d773SGleb Smirnoff 7263340d773SGleb Smirnoff case HNCP_ASSIGNED_PREFIX: { 7273340d773SGleb Smirnoff uint8_t prty; 7283340d773SGleb Smirnoff int l; 729*ee67461eSJoseph Mingrone if (bodylen < 6 || bodylen < 6 + (GET_U_1(value + 5) + 7) / 8) { 730*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7313340d773SGleb Smirnoff break; 7323340d773SGleb Smirnoff } 733*ee67461eSJoseph Mingrone prty = GET_U_1(value + 4) & 0xf; 734*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x Prty: %u", 735*ee67461eSJoseph Mingrone GET_BE_U_4(value), 7363340d773SGleb Smirnoff prty 737*ee67461eSJoseph Mingrone ); 738*ee67461eSJoseph Mingrone ND_PRINT(" Prefix: "); 7393340d773SGleb Smirnoff if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0) { 740*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7413340d773SGleb Smirnoff break; 7423340d773SGleb Smirnoff } 7433340d773SGleb Smirnoff l += 5; 7443340d773SGleb Smirnoff l += -l & 3; 7453340d773SGleb Smirnoff 7463340d773SGleb Smirnoff if (bodylen >= l) 7473340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 7483340d773SGleb Smirnoff } 7493340d773SGleb Smirnoff break; 7503340d773SGleb Smirnoff 7513340d773SGleb Smirnoff case HNCP_NODE_ADDRESS: { 7523340d773SGleb Smirnoff uint32_t endpoint_identifier; 7533340d773SGleb Smirnoff const char *ip_address; 7543340d773SGleb Smirnoff if (bodylen < 20) { 755*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7563340d773SGleb Smirnoff break; 7573340d773SGleb Smirnoff } 758*ee67461eSJoseph Mingrone endpoint_identifier = GET_BE_U_4(value); 7593340d773SGleb Smirnoff ip_address = format_ip6addr(ndo, value + 4); 760*ee67461eSJoseph Mingrone ND_PRINT(" EPID: %08x IP Address: %s", 7613340d773SGleb Smirnoff endpoint_identifier, 7623340d773SGleb Smirnoff ip_address 763*ee67461eSJoseph Mingrone ); 7643340d773SGleb Smirnoff 7653340d773SGleb Smirnoff hncp_print_rec(ndo, value + 20, bodylen - 20, indent+1); 7663340d773SGleb Smirnoff } 7673340d773SGleb Smirnoff break; 7683340d773SGleb Smirnoff 7693340d773SGleb Smirnoff case HNCP_DNS_DELEGATED_ZONE: { 7703340d773SGleb Smirnoff const char *ip_address; 7713340d773SGleb Smirnoff int len; 7723340d773SGleb Smirnoff if (bodylen < 17) { 773*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7743340d773SGleb Smirnoff break; 7753340d773SGleb Smirnoff } 7763340d773SGleb Smirnoff ip_address = format_ip6addr(ndo, value); 777*ee67461eSJoseph Mingrone ND_PRINT(" IP-Address: %s %c%c%c ", 7783340d773SGleb Smirnoff ip_address, 779*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 4) ? 'l' : '-', 780*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 2) ? 'b' : '-', 781*ee67461eSJoseph Mingrone (GET_U_1(value + 16) & 1) ? 's' : '-' 782*ee67461eSJoseph Mingrone ); 7833340d773SGleb Smirnoff len = print_dns_label(ndo, value+17, bodylen-17, 1); 7843340d773SGleb Smirnoff if (len < 0) { 785*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7863340d773SGleb Smirnoff break; 7873340d773SGleb Smirnoff } 7883340d773SGleb Smirnoff len += 17; 7893340d773SGleb Smirnoff len += -len & 3; 7903340d773SGleb Smirnoff if (bodylen >= len) 7913340d773SGleb Smirnoff hncp_print_rec(ndo, value+len, bodylen-len, indent+1); 7923340d773SGleb Smirnoff } 7933340d773SGleb Smirnoff break; 7943340d773SGleb Smirnoff 7953340d773SGleb Smirnoff case HNCP_DOMAIN_NAME: { 7963340d773SGleb Smirnoff if (bodylen == 0) { 797*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 7983340d773SGleb Smirnoff break; 7993340d773SGleb Smirnoff } 800*ee67461eSJoseph Mingrone ND_PRINT(" Domain: "); 8013340d773SGleb Smirnoff print_dns_label(ndo, value, bodylen, 1); 8023340d773SGleb Smirnoff } 8033340d773SGleb Smirnoff break; 8043340d773SGleb Smirnoff 8053340d773SGleb Smirnoff case HNCP_NODE_NAME: { 8063340d773SGleb Smirnoff u_int l; 8073340d773SGleb Smirnoff if (bodylen < 17) { 808*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8093340d773SGleb Smirnoff break; 8103340d773SGleb Smirnoff } 811*ee67461eSJoseph Mingrone l = GET_U_1(value + 16); 8123340d773SGleb Smirnoff if (bodylen < 17 + l) { 813*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8143340d773SGleb Smirnoff break; 8153340d773SGleb Smirnoff } 816*ee67461eSJoseph Mingrone ND_PRINT(" IP-Address: %s Name: ", 8173340d773SGleb Smirnoff format_ip6addr(ndo, value) 818*ee67461eSJoseph Mingrone ); 8193340d773SGleb Smirnoff if (l < 64) { 820*ee67461eSJoseph Mingrone ND_PRINT("\""); 821*ee67461eSJoseph Mingrone nd_printjnp(ndo, value + 17, l); 822*ee67461eSJoseph Mingrone ND_PRINT("\""); 8233340d773SGleb Smirnoff } else { 824*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8253340d773SGleb Smirnoff } 8263340d773SGleb Smirnoff l += 17; 827*ee67461eSJoseph Mingrone l = roundup2(l, 4); 8283340d773SGleb Smirnoff if (bodylen >= l) 8293340d773SGleb Smirnoff hncp_print_rec(ndo, value + l, bodylen - l, indent+1); 8303340d773SGleb Smirnoff } 8313340d773SGleb Smirnoff break; 8323340d773SGleb Smirnoff 8333340d773SGleb Smirnoff case HNCP_MANAGED_PSK: { 8343340d773SGleb Smirnoff if (bodylen < 32) { 835*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8363340d773SGleb Smirnoff break; 8373340d773SGleb Smirnoff } 838*ee67461eSJoseph Mingrone ND_PRINT(" PSK: %s", format_256(ndo, value)); 8393340d773SGleb Smirnoff hncp_print_rec(ndo, value + 32, bodylen - 32, indent+1); 8403340d773SGleb Smirnoff } 8413340d773SGleb Smirnoff break; 8423340d773SGleb Smirnoff 8433340d773SGleb Smirnoff case RANGE_DNCP_RESERVED: 8443340d773SGleb Smirnoff case RANGE_HNCP_UNASSIGNED: 8453340d773SGleb Smirnoff case RANGE_DNCP_PRIVATE_USE: 8463340d773SGleb Smirnoff case RANGE_DNCP_FUTURE_USE: 8473340d773SGleb Smirnoff break; 8483340d773SGleb Smirnoff 8493340d773SGleb Smirnoff } 8503340d773SGleb Smirnoff skip_multiline: 8513340d773SGleb Smirnoff 852*ee67461eSJoseph Mingrone i += 4 + roundup2(bodylen, 4); 8533340d773SGleb Smirnoff } 8543340d773SGleb Smirnoff print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one); 8553340d773SGleb Smirnoff 8563340d773SGleb Smirnoff return; 8573340d773SGleb Smirnoff 8583340d773SGleb Smirnoff trunc: 859*ee67461eSJoseph Mingrone nd_print_trunc(ndo); 8603340d773SGleb Smirnoff return; 8613340d773SGleb Smirnoff 8623340d773SGleb Smirnoff invalid: 863*ee67461eSJoseph Mingrone nd_print_invalid(ndo); 8643340d773SGleb Smirnoff } 865