]> The Tcpdump Group git mirrors - tcpdump/blob - print-hncp.c
Fix handling of IPv4 prefixes.
[tcpdump] / print-hncp.c
1 /*
2 * Copyright (c) 2016 Antonin Décimo, Jean-Raphaël Gaglione
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the project nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /* \summary: Home Networking Control Protocol (HNCP) printer */
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #include <netdissect-stdinc.h>
36
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "netdissect.h"
41 #include "addrtoname.h"
42 #include "extract.h"
43
44 static void
45 hncp_print_rec(netdissect_options *ndo,
46 const u_char *cp, u_int length, int indent);
47
48 void
49 hncp_print(netdissect_options *ndo,
50 const u_char *cp, u_int length)
51 {
52 ND_PRINT((ndo, "hncp (%d)", length));
53 hncp_print_rec(ndo, cp, length, 1);
54 }
55
56 /* RFC7787 */
57 #define DNCP_REQUEST_NETWORK_STATE 1
58 #define DNCP_REQUEST_NODE_STATE 2
59 #define DNCP_NODE_ENDPOINT 3
60 #define DNCP_NETWORK_STATE 4
61 #define DNCP_NODE_STATE 5
62 #define DNCP_PEER 8
63 #define DNCP_KEEP_ALIVE_INTERVAL 9
64 #define DNCP_TRUST_VERDICT 10
65
66 /* RFC7788 */
67 #define HNCP_HNCP_VERSION 32
68 #define HNCP_EXTERNAL_CONNECTION 33
69 #define HNCP_DELEGATED_PREFIX 34
70 #define HNCP_PREFIX_POLICY 43
71 #define HNCP_DHCPV4_DATA 37
72 #define HNCP_DHCPV6_DATA 38
73 #define HNCP_ASSIGNED_PREFIX 35
74 #define HNCP_NODE_ADDRESS 36
75 #define HNCP_DNS_DELEGATED_ZONE 39
76 #define HNCP_DOMAIN_NAME 40
77 #define HNCP_NODE_NAME 41
78 #define HNCP_MANAGED_PSK 42
79
80 /* See type_mask in hncp_print_rec below */
81 #define RANGE_DNCP_RESERVED 0x10000
82 #define RANGE_HNCP_UNASSIGNED 0x10001
83 #define RANGE_DNCP_PRIVATE_USE 0x10002
84 #define RANGE_DNCP_FUTURE_USE 0x10003
85
86 static const struct tok type_values[] = {
87 { DNCP_REQUEST_NETWORK_STATE, "Request network state" },
88 { DNCP_REQUEST_NODE_STATE, "Request node state" },
89 { DNCP_NODE_ENDPOINT, "Node endpoint" },
90 { DNCP_NETWORK_STATE, "Network state" },
91 { DNCP_NODE_STATE, "Node state" },
92 { DNCP_PEER, "Peer" },
93 { DNCP_KEEP_ALIVE_INTERVAL, "Keep-alive interval" },
94 { DNCP_TRUST_VERDICT, "Trust-Verdict" },
95
96 { HNCP_HNCP_VERSION, "HNCP-Version" },
97 { HNCP_EXTERNAL_CONNECTION, "External-Connection" },
98 { HNCP_DELEGATED_PREFIX, "Delegated-Prefix" },
99 { HNCP_PREFIX_POLICY, "Prefix-Policy" },
100 { HNCP_DHCPV4_DATA, "DHCPv4-Data" },
101 { HNCP_DHCPV6_DATA, "DHCPv6-Data" },
102 { HNCP_ASSIGNED_PREFIX, "Assigned-Prefix" },
103 { HNCP_NODE_ADDRESS, "Node-Address" },
104 { HNCP_DNS_DELEGATED_ZONE, "DNS-Delegated-Zone" },
105 { HNCP_DOMAIN_NAME, "Domain-Name" },
106 { HNCP_NODE_NAME, "Node-Name" },
107 { HNCP_MANAGED_PSK, "Managed-PSK" },
108
109 { RANGE_DNCP_RESERVED, "Reserved" },
110 { RANGE_HNCP_UNASSIGNED, "Unassigned" },
111 { RANGE_DNCP_PRIVATE_USE, "Private use" },
112 { RANGE_DNCP_FUTURE_USE, "Future use" },
113
114 { 0, NULL}
115 };
116
117 #define DH4OPT_DNS_SERVERS 6 /* RFC2132 */
118 #define DH4OPT_NTP_SERVERS 42 /* RFC2132 */
119 #define DH4OPT_DOMAIN_SEARCH 119 /* RFC3397 */
120
121 static const struct tok dh4opt_str[] = {
122 { DH4OPT_DNS_SERVERS, "DNS-server" },
123 { DH4OPT_NTP_SERVERS, "NTP-server"},
124 { DH4OPT_DOMAIN_SEARCH, "DNS-search" },
125 { 0, NULL }
126 };
127
128 #define DH6OPT_DNS_SERVERS 23 /* RFC3646 */
129 #define DH6OPT_DOMAIN_LIST 24 /* RFC3646 */
130 #define DH6OPT_SNTP_SERVERS 31 /* RFC4075 */
131
132 static const struct tok dh6opt_str[] = {
133 { DH6OPT_DNS_SERVERS, "DNS-server" },
134 { DH6OPT_DOMAIN_LIST, "DNS-search-list" },
135 { DH6OPT_SNTP_SERVERS, "SNTP-servers" },
136 { 0, NULL }
137 };
138
139 static const char *
140 format_nid(const u_char *data)
141 {
142 static char buf[4][11+5];
143 static int i = 0;
144 i = (i + 1) % 4;
145 snprintf(buf[i], 16, "%02x:%02x:%02x:%02x",
146 data[0], data[1], data[2], data[3]);
147 return buf[i];
148 }
149
150 static const char *
151 format_256(const u_char *data)
152 {
153 static char buf[4][64+5];
154 static int i = 0;
155 i = (i + 1) % 4;
156 snprintf(buf[i], 28, "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
157 EXTRACT_64BITS(data),
158 EXTRACT_64BITS(data + 8),
159 EXTRACT_64BITS(data + 16),
160 EXTRACT_64BITS(data + 24)
161 );
162 return buf[i];
163 }
164
165 static const char *
166 format_interval(const uint32_t n)
167 {
168 static char buf[4][sizeof("0000000.000s")];
169 static int i = 0;
170 i = (i + 1) % 4;
171 snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000);
172 return buf[i];
173 }
174
175 static const char *
176 format_ip6addr(netdissect_options *ndo, const u_char *cp)
177 {
178 if (EXTRACT_64BITS(cp) == 0x0 && EXTRACT_32BITS(cp+8) == 0xffff)
179 return ipaddr_string(ndo, cp + 12);
180 else
181 return ip6addr_string(ndo, cp);
182 }
183
184 static int
185 print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
186 {
187 int plenbytes;
188 char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")];
189 /* First 12 bytes of an IPv4-mapped IPv6 address */
190 static const u_char ipv4_mapped_heading[12] =
191 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF };
192
193 if (prefix[0] >= 96 && max_length >= 13 && memcmp(prefix+1, ipv4_mapped_heading, 12) == 0) {
194 struct in_addr addr;
195 u_int plen;
196
197 plen = prefix[0]-96;
198 if (32 < plen)
199 return -1;
200 max_length -= 1;
201
202 memset(&addr, 0, sizeof(addr));
203 plenbytes = (plen + 7) / 8;
204 if (max_length < (u_int)plenbytes)
205 return -3;
206 memcpy(&addr, &prefix[13], plenbytes);
207 if (plen % 8) {
208 ((u_char *)&addr)[plenbytes - 1] &=
209 ((0xff00 >> (plen % 8)) & 0xff);
210 }
211 snprintf(buf, sizeof(buf), "%s/%d", ipaddr_string(ndo, &addr), plen);
212 plenbytes += 13;
213 } else {
214 plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf));
215 }
216
217 ND_PRINT((ndo, "%s", buf));
218 return plenbytes;
219 }
220
221 static int
222 print_dns_label(netdissect_options *ndo,
223 const u_char *cp, u_int max_length, int print)
224 {
225 u_int length = 0;
226 while (length < max_length) {
227 u_int lab_length = cp[length++];
228 if (lab_length == 0)
229 return (int)length;
230 if (length > 1 && print)
231 safeputchar(ndo, '.');
232 if (length+lab_length > max_length) {
233 if (print)
234 safeputs(ndo, cp+length, max_length-length);
235 break;
236 }
237 if (print)
238 safeputs(ndo, cp+length, lab_length);
239 length += lab_length;
240 }
241 if (print)
242 ND_PRINT((ndo, "[|DNS]"));
243 return -1;
244 }
245
246 static int
247 dhcpv4_print(netdissect_options *ndo,
248 const u_char *cp, u_int length, int indent)
249 {
250 u_int i, t;
251 const u_char *tlv, *value;
252 uint8_t type, optlen;
253
254 i = 0;
255 while (i < length) {
256 tlv = cp + i;
257 type = (uint8_t)tlv[0];
258 optlen = (uint8_t)tlv[1];
259 value = tlv + 2;
260
261 ND_PRINT((ndo, "\n"));
262 for (t = indent; t > 0; t--)
263 ND_PRINT((ndo, "\t"));
264
265 ND_PRINT((ndo, "%s", tok2str(dh4opt_str, "Unknown", type)));
266 ND_PRINT((ndo," (%u)", optlen + 2 ));
267
268 switch (type) {
269 case DH4OPT_DNS_SERVERS:
270 case DH4OPT_NTP_SERVERS: {
271 if (optlen < 4 || optlen % 4 != 0) {
272 return -1;
273 }
274 for (t = 0; t < optlen; t += 4)
275 ND_PRINT((ndo, " %s", ipaddr_string(ndo, value + t)));
276 }
277 break;
278 case DH4OPT_DOMAIN_SEARCH: {
279 const u_char *tp = value;
280 while (tp < value + optlen) {
281 ND_PRINT((ndo, " "));
282 if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
283 return -1;
284 }
285 }
286 break;
287 }
288
289 i += 2 + optlen;
290 }
291 return 0;
292 }
293
294 static int
295 dhcpv6_print(netdissect_options *ndo,
296 const u_char *cp, u_int length, int indent)
297 {
298 u_int i, t;
299 const u_char *tlv, *value;
300 uint16_t type, optlen;
301
302 i = 0;
303 while (i < length) {
304 tlv = cp + i;
305 type = EXTRACT_16BITS(tlv);
306 optlen = EXTRACT_16BITS(tlv + 2);
307 value = tlv + 4;
308
309 ND_PRINT((ndo, "\n"));
310 for (t = indent; t > 0; t--)
311 ND_PRINT((ndo, "\t"));
312
313 ND_PRINT((ndo, "%s", tok2str(dh6opt_str, "Unknown", type)));
314 ND_PRINT((ndo," (%u)", optlen + 4 ));
315
316 switch (type) {
317 case DH6OPT_DNS_SERVERS:
318 case DH6OPT_SNTP_SERVERS: {
319 if (optlen % 16 != 0) {
320 ND_PRINT((ndo, " %s", istr));
321 return -1;
322 }
323 for (t = 0; t < optlen; t += 16)
324 ND_PRINT((ndo, " %s", ip6addr_string(ndo, value + t)));
325 }
326 break;
327 case DH6OPT_DOMAIN_LIST: {
328 const u_char *tp = value;
329 while (tp < value + optlen) {
330 ND_PRINT((ndo, " "));
331 if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
332 return -1;
333 }
334 }
335 break;
336 }
337
338 i += 4 + optlen;
339 }
340 return 0;
341 }
342
343 /* Determine in-line mode */
344 static int
345 is_in_line(netdissect_options *ndo, int indent)
346 {
347 return indent - 1 >= ndo->ndo_vflag && ndo->ndo_vflag < 3;
348 }
349
350 static void
351 print_type_in_line(netdissect_options *ndo,
352 uint32_t type, int count, int indent, int *first_one)
353 {
354 if (count > 0) {
355 if (*first_one) {
356 *first_one = 0;
357 if (indent > 1) {
358 u_int t;
359 ND_PRINT((ndo, "\n"));
360 for (t = indent; t > 0; t--)
361 ND_PRINT((ndo, "\t"));
362 } else {
363 ND_PRINT((ndo, " "));
364 }
365 } else {
366 ND_PRINT((ndo, ", "));
367 }
368 ND_PRINT((ndo, "%s", tok2str(type_values, "Easter Egg", type)));
369 if (count > 1)
370 ND_PRINT((ndo, " (x%d)", count));
371 }
372 }
373
374 void
375 hncp_print_rec(netdissect_options *ndo,
376 const u_char *cp, u_int length, int indent)
377 {
378 const int in_line = is_in_line(ndo, indent);
379 int first_one = 1;
380
381 u_int i, t;
382
383 uint32_t last_type_mask = 0xffffffffU;
384 int last_type_count = -1;
385
386 const u_char *tlv, *value;
387 uint16_t type, bodylen;
388 uint32_t type_mask;
389
390 i = 0;
391 while (i < length) {
392 tlv = cp + i;
393
394 if (!in_line) {
395 ND_PRINT((ndo, "\n"));
396 for (t = indent; t > 0; t--)
397 ND_PRINT((ndo, "\t"));
398 }
399
400 ND_TCHECK2(*tlv, 4);
401 if (i + 4 > length)
402 goto invalid;
403
404 type = EXTRACT_16BITS(tlv);
405 bodylen = EXTRACT_16BITS(tlv + 2);
406 value = tlv + 4;
407 ND_TCHECK2(*value, bodylen);
408 if (i + bodylen + 4 > length)
409 goto invalid;
410
411 type_mask =
412 (type == 0) ? RANGE_DNCP_RESERVED:
413 (44 <= type && type <= 511) ? RANGE_HNCP_UNASSIGNED:
414 (768 <= type && type <= 1023) ? RANGE_DNCP_PRIVATE_USE:
415 RANGE_DNCP_FUTURE_USE;
416 if (type == 6 || type == 7)
417 type_mask = RANGE_DNCP_FUTURE_USE;
418
419 /* defined types */
420 {
421 t = 0;
422 while (1) {
423 u_int key = type_values[t++].v;
424 if (key > 0xffff)
425 break;
426 if (key == type) {
427 type_mask = type;
428 break;
429 }
430 }
431 }
432
433 if (in_line) {
434 if (last_type_mask == type_mask) {
435 last_type_count++;
436 } else {
437 print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
438 last_type_mask = type_mask;
439 last_type_count = 1;
440 }
441
442 goto skip_multiline;
443 }
444
445 ND_PRINT((ndo,"%s", tok2str(type_values, "Easter Egg (42)", type_mask) ));
446 if (type_mask > 0xffff)
447 ND_PRINT((ndo,": type=%u", type ));
448 ND_PRINT((ndo," (%u)", bodylen + 4 ));
449
450 switch (type_mask) {
451
452 case DNCP_REQUEST_NETWORK_STATE: {
453 if (bodylen != 0)
454 ND_PRINT((ndo, " %s", istr));
455 }
456 break;
457
458 case DNCP_REQUEST_NODE_STATE: {
459 const char *node_identifier;
460 if (bodylen != 4) {
461 ND_PRINT((ndo, " %s", istr));
462 break;
463 }
464 node_identifier = format_nid(value);
465 ND_PRINT((ndo, " NID: %s", node_identifier));
466 }
467 break;
468
469 case DNCP_NODE_ENDPOINT: {
470 const char *node_identifier;
471 uint32_t endpoint_identifier;
472 if (bodylen != 8) {
473 ND_PRINT((ndo, " %s", istr));
474 break;
475 }
476 node_identifier = format_nid(value);
477 endpoint_identifier = EXTRACT_32BITS(value + 4);
478 ND_PRINT((ndo, " NID: %s EPID: %08x",
479 node_identifier,
480 endpoint_identifier
481 ));
482 }
483 break;
484
485 case DNCP_NETWORK_STATE: {
486 uint64_t hash;
487 if (bodylen != 8) {
488 ND_PRINT((ndo, " %s", istr));
489 break;
490 }
491 hash = EXTRACT_64BITS(value);
492 ND_PRINT((ndo, " hash: %016" PRIx64, hash));
493 }
494 break;
495
496 case DNCP_NODE_STATE: {
497 const char *node_identifier, *interval;
498 uint32_t sequence_number;
499 uint64_t hash;
500 if (bodylen < 20) {
501 ND_PRINT((ndo, " %s", istr));
502 break;
503 }
504 node_identifier = format_nid(value);
505 sequence_number = EXTRACT_32BITS(value + 4);
506 interval = format_interval(EXTRACT_32BITS(value + 8));
507 hash = EXTRACT_64BITS(value + 12);
508 ND_PRINT((ndo, " NID: %s seqno: %u %s hash: %016" PRIx64,
509 node_identifier,
510 sequence_number,
511 interval,
512 hash
513 ));
514 hncp_print_rec(ndo, value+20, bodylen-20, indent+1);
515 }
516 break;
517
518 case DNCP_PEER: {
519 const char *peer_node_identifier;
520 uint32_t peer_endpoint_identifier, endpoint_identifier;
521 if (bodylen != 12) {
522 ND_PRINT((ndo, " %s", istr));
523 break;
524 }
525 peer_node_identifier = format_nid(value);
526 peer_endpoint_identifier = EXTRACT_32BITS(value + 4);
527 endpoint_identifier = EXTRACT_32BITS(value + 8);
528 ND_PRINT((ndo, " Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x",
529 peer_node_identifier,
530 peer_endpoint_identifier,
531 endpoint_identifier
532 ));
533 }
534 break;
535
536 case DNCP_KEEP_ALIVE_INTERVAL: {
537 uint32_t endpoint_identifier;
538 const char *interval;
539 if (bodylen < 8) {
540 ND_PRINT((ndo, " %s", istr));
541 break;
542 }
543 endpoint_identifier = EXTRACT_32BITS(value);
544 interval = format_interval(EXTRACT_32BITS(value + 4));
545 ND_PRINT((ndo, " EPID: %08x Interval: %s",
546 endpoint_identifier,
547 interval
548 ));
549 }
550 break;
551
552 case DNCP_TRUST_VERDICT: {
553 if (bodylen <= 36) {
554 ND_PRINT((ndo, " %s", istr));
555 break;
556 }
557 ND_PRINT((ndo, " Verdict: %u Fingerprint: %s Common Name: ",
558 *value,
559 format_256(value + 4)));
560 safeputs(ndo, value + 36, bodylen - 36);
561 }
562 break;
563
564 case HNCP_HNCP_VERSION: {
565 uint16_t capabilities;
566 uint8_t M, P, H, L;
567 if (bodylen < 5) {
568 ND_PRINT((ndo, " %s", istr));
569 break;
570 }
571 capabilities = EXTRACT_16BITS(value + 2);
572 M = (uint8_t)((capabilities >> 12) & 0xf);
573 P = (uint8_t)((capabilities >> 8) & 0xf);
574 H = (uint8_t)((capabilities >> 4) & 0xf);
575 L = (uint8_t)(capabilities & 0xf);
576 ND_PRINT((ndo, " M: %u P: %u H: %u L: %u User-agent: ",
577 M, P, H, L
578 ));
579 safeputs(ndo, value + 4, bodylen - 4);
580 }
581 break;
582
583 case HNCP_EXTERNAL_CONNECTION: {
584 /* Container TLV */
585 hncp_print_rec(ndo, value, bodylen, indent+1);
586 }
587 break;
588
589 case HNCP_DELEGATED_PREFIX: {
590 int l;
591 if (bodylen < 9 || bodylen < 9 + (value[8] + 7) / 8) {
592 ND_PRINT((ndo, " %s", istr));
593 break;
594 }
595 ND_PRINT((ndo, " VLSO: %s PLSO: %s Prefix: ",
596 format_interval(EXTRACT_32BITS(value)),
597 format_interval(EXTRACT_32BITS(value + 4))
598 ));
599 l = print_prefix(ndo, value + 8, bodylen - 8);
600 if (l == -1) {
601 ND_PRINT((ndo, "(length is invalid)"));
602 break;
603 }
604 if (l < 0) {
605 /*
606 * We've already checked that we've captured the
607 * entire TLV, based on its length, so this will
608 * either be -1, meaning "the prefix length is
609 * greater than the longest possible address of
610 * that type" (i.e., > 32 for IPv4 or > 128 for
611 * IPv6", or -3, meaning "the prefix runs past
612 * the end of the TLV".
613 */
614 ND_PRINT((ndo, " %s", istr));
615 break;
616 }
617 l += 8 + (-l & 3);
618
619 if (bodylen >= l)
620 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
621 }
622 break;
623
624 case HNCP_PREFIX_POLICY: {
625 uint8_t policy;
626 int l;
627 if (bodylen < 1) {
628 ND_PRINT((ndo, " %s", istr));
629 break;
630 }
631 policy = value[0];
632 ND_PRINT((ndo, " type: "));
633 if (policy == 0) {
634 if (bodylen != 1) {
635 ND_PRINT((ndo, " %s", istr));
636 break;
637 }
638 ND_PRINT((ndo, "Internet connectivity"));
639 } else if (policy >= 1 && policy <= 128) {
640 ND_PRINT((ndo, "Dest-Prefix: "));
641 l = print_prefix(ndo, value, bodylen);
642 if (l == -1) {
643 ND_PRINT((ndo, "(length is invalid)"));
644 break;
645 }
646 if (l < 0) {
647 /*
648 * We've already checked that we've captured the
649 * entire TLV, based on its length, so this will
650 * either be -1, meaning "the prefix length is
651 * greater than the longest possible address of
652 * that type" (i.e., > 32 for IPv4 or > 128 for
653 * IPv6", or -3, meaning "the prefix runs past
654 * the end of the TLV".
655 */
656 ND_PRINT((ndo, " %s", istr));
657 break;
658 }
659 } else if (policy == 129) {
660 ND_PRINT((ndo, "DNS domain: "));
661 print_dns_label(ndo, value+1, bodylen-1, 1);
662 } else if (policy == 130) {
663 ND_PRINT((ndo, "Opaque UTF-8: "));
664 safeputs(ndo, value + 1, bodylen - 1);
665 } else if (policy == 131) {
666 if (bodylen != 1) {
667 ND_PRINT((ndo, " %s", istr));
668 break;
669 }
670 ND_PRINT((ndo, "Restrictive assignment"));
671 } else if (policy >= 132) {
672 ND_PRINT((ndo, "Unknown (%u)", policy)); /* Reserved for future additions */
673 }
674 }
675 break;
676
677 case HNCP_DHCPV4_DATA: {
678 if (bodylen == 0) {
679 ND_PRINT((ndo, " %s", istr));
680 break;
681 }
682 if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0)
683 goto invalid;
684 }
685 break;
686
687 case HNCP_DHCPV6_DATA: {
688 if (bodylen == 0) {
689 ND_PRINT((ndo, " %s", istr));
690 break;
691 }
692 if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0) {
693 ND_PRINT((ndo, " %s", istr));
694 break;
695 }
696 }
697 break;
698
699 case HNCP_ASSIGNED_PREFIX: {
700 uint8_t prty;
701 int l;
702 if (bodylen < 6 || bodylen < 6 + (value[5] + 7) / 8) {
703 ND_PRINT((ndo, " %s", istr));
704 break;
705 }
706 prty = (uint8_t)(value[4] & 0xf);
707 ND_PRINT((ndo, " EPID: %08x Prty: %u",
708 EXTRACT_32BITS(value),
709 prty
710 ));
711 ND_PRINT((ndo, " Prefix: "));
712 if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0) {
713 ND_PRINT((ndo, " %s", istr));
714 break;
715 }
716 l += 5;
717 l += -l & 3;
718
719 if (bodylen >= l)
720 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
721 }
722 break;
723
724 case HNCP_NODE_ADDRESS: {
725 uint32_t endpoint_identifier;
726 const char *ip_address;
727 if (bodylen < 20) {
728 ND_PRINT((ndo, " %s", istr));
729 break;
730 }
731 endpoint_identifier = EXTRACT_32BITS(value);
732 ip_address = format_ip6addr(ndo, value + 4);
733 ND_PRINT((ndo, " EPID: %08x IP Address: %s",
734 endpoint_identifier,
735 ip_address
736 ));
737
738 hncp_print_rec(ndo, value + 20, bodylen - 20, indent+1);
739 }
740 break;
741
742 case HNCP_DNS_DELEGATED_ZONE: {
743 const char *ip_address;
744 int len;
745 if (bodylen < 17) {
746 ND_PRINT((ndo, " %s", istr));
747 break;
748 }
749 ip_address = format_ip6addr(ndo, value);
750 ND_PRINT((ndo, " IP-Address: %s %c%c%c ",
751 ip_address,
752 (value[16] & 4) ? 'l' : '-',
753 (value[16] & 2) ? 'b' : '-',
754 (value[16] & 1) ? 's' : '-'
755 ));
756 len = print_dns_label(ndo, value+17, bodylen-17, 1);
757 if (len < 0) {
758 ND_PRINT((ndo, " %s", istr));
759 break;
760 }
761 len += 17;
762 len += -len & 3;
763 if (bodylen >= len)
764 hncp_print_rec(ndo, value+len, bodylen-len, indent+1);
765 }
766 break;
767
768 case HNCP_DOMAIN_NAME: {
769 if (bodylen == 0) {
770 ND_PRINT((ndo, " %s", istr));
771 break;
772 }
773 ND_PRINT((ndo, " Domain: "));
774 print_dns_label(ndo, value, bodylen, 1);
775 }
776 break;
777
778 case HNCP_NODE_NAME: {
779 u_int l;
780 if (bodylen < 17) {
781 ND_PRINT((ndo, " %s", istr));
782 break;
783 }
784 l = value[16];
785 if (bodylen < 17 + l) {
786 ND_PRINT((ndo, " %s", istr));
787 break;
788 }
789 ND_PRINT((ndo, " IP-Address: %s Name: ",
790 format_ip6addr(ndo, value)
791 ));
792 if (l < 64) {
793 safeputchar(ndo, '"');
794 safeputs(ndo, value + 17, l);
795 safeputchar(ndo, '"');
796 } else {
797 ND_PRINT((ndo, "%s", istr));
798 }
799 l += 17;
800 l += -l & 3;
801 if (bodylen >= l)
802 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
803 }
804 break;
805
806 case HNCP_MANAGED_PSK: {
807 if (bodylen < 32) {
808 ND_PRINT((ndo, " %s", istr));
809 break;
810 }
811 ND_PRINT((ndo, " PSK: %s", format_256(value)));
812 hncp_print_rec(ndo, value + 32, bodylen - 32, indent+1);
813 }
814 break;
815
816 case RANGE_DNCP_RESERVED:
817 case RANGE_HNCP_UNASSIGNED:
818 case RANGE_DNCP_PRIVATE_USE:
819 case RANGE_DNCP_FUTURE_USE:
820 break;
821
822 }
823 skip_multiline:
824
825 i += 4 + bodylen + (-bodylen & 3);
826 }
827 print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
828
829 return;
830
831 trunc:
832 ND_PRINT((ndo, "%s", "[|hncp]"));
833 return;
834
835 invalid:
836 ND_PRINT((ndo, "%s", istr));
837 return;
838 }