]> The Tcpdump Group git mirrors - tcpdump/blob - print-hncp.c
Add a summary comment in all other printers
[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 uint16_t n)
167 {
168 static char buf[4][sizeof("000.00s")];
169 static int i = 0;
170 i = (i + 1) % 4;
171 if (n == 0)
172 return "0.0s (bogus)";
173 snprintf(buf[i], sizeof(buf[i]), "%u.%02us", n / 100, n % 100);
174 return buf[i];
175 }
176
177 static const char *
178 format_ip6addr(netdissect_options *ndo, const u_char *cp)
179 {
180 if (EXTRACT_64BITS(cp) == 0x0 && EXTRACT_32BITS(cp+8) == 0xffff)
181 return ipaddr_string(ndo, cp + 12);
182 else
183 return ip6addr_string(ndo, cp);
184 }
185
186 static int
187 print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
188 {
189 int plenbytes;
190 static char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")];
191 static u_char prefix_v4[5];
192 if (prefix[0] >= 96 && max_length >= 13 && EXTRACT_64BITS(prefix+1) == 0x0 && EXTRACT_32BITS(prefix+9) == 0xffff) {
193 prefix_v4[0] = prefix[0]-96;
194 prefix_v4[1] = prefix[13];
195 prefix_v4[2] = prefix[14];
196 prefix_v4[3] = prefix[15];
197 prefix_v4[4] = prefix[16];
198 plenbytes = 12 + decode_prefix4(ndo, (const u_char *)prefix_v4, max_length-12, buf, 45);
199 } else {
200 plenbytes = decode_prefix6(ndo, prefix, max_length, buf, 45);
201 }
202
203 safeputs(ndo, (const u_char*)buf, 45);
204 return plenbytes;
205 }
206
207 static int
208 print_dns_label(netdissect_options *ndo,
209 const u_char *cp, u_int max_length, int print)
210 {
211 u_int length = 0;
212 while (length < max_length) {
213 u_int lab_length = cp[length++];
214 if (lab_length == 0)
215 return (int)length;
216 if (length > 1 && print)
217 safeputchar(ndo, '.');
218 if (length+lab_length > max_length) {
219 if (print)
220 safeputs(ndo, cp+length, max_length-length);
221 break;
222 }
223 if (print)
224 safeputs(ndo, cp+length, lab_length);
225 length += lab_length;
226 }
227 if (print)
228 ND_PRINT((ndo, "[|DNS]"));
229 return -1;
230 }
231
232 static int
233 dhcpv4_print(netdissect_options *ndo,
234 const u_char *cp, u_int length, int indent)
235 {
236 u_int i, t;
237 const u_char *tlv, *value;
238 uint8_t type, optlen;
239
240 i = 0;
241 while (i < length) {
242 tlv = cp + i;
243 type = (uint8_t)tlv[0];
244 optlen = (uint8_t)tlv[1];
245 value = tlv + 2;
246
247 ND_PRINT((ndo, "\n"));
248 for (t = indent; t > 0; t--)
249 ND_PRINT((ndo, "\t"));
250
251 ND_PRINT((ndo, "%s", tok2str(dh4opt_str, "Unknown", type)));
252 ND_PRINT((ndo," (%u)", optlen + 2 ));
253
254 switch (type) {
255 case DH4OPT_DNS_SERVERS:
256 case DH4OPT_NTP_SERVERS: {
257 if (optlen < 4 || optlen % 4 != 0) {
258 return -1;
259 }
260 for (t = 0; t < optlen; t += 4)
261 ND_PRINT((ndo, " %s", ipaddr_string(ndo, value + t)));
262 }
263 break;
264 case DH4OPT_DOMAIN_SEARCH: {
265 const u_char *tp = value;
266 while (tp < value + optlen) {
267 ND_PRINT((ndo, " "));
268 if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
269 return -1;
270 }
271 }
272 break;
273 }
274
275 i += 2 + optlen;
276 }
277 return 0;
278 }
279
280 static int
281 dhcpv6_print(netdissect_options *ndo,
282 const u_char *cp, u_int length, int indent)
283 {
284 u_int i, t;
285 const u_char *tlv, *value;
286 uint16_t type, optlen;
287
288 i = 0;
289 while (i < length) {
290 tlv = cp + i;
291 type = EXTRACT_16BITS(tlv);
292 optlen = EXTRACT_16BITS(tlv + 2);
293 value = tlv + 4;
294
295 ND_PRINT((ndo, "\n"));
296 for (t = indent; t > 0; t--)
297 ND_PRINT((ndo, "\t"));
298
299 ND_PRINT((ndo, "%s", tok2str(dh6opt_str, "Unknown", type)));
300 ND_PRINT((ndo," (%u)", optlen + 4 ));
301
302 switch (type) {
303 case DH6OPT_DNS_SERVERS:
304 case DH6OPT_SNTP_SERVERS: {
305 if (optlen % 16 != 0) {
306 ND_PRINT((ndo, " %s", istr));
307 return -1;
308 }
309 for (t = 0; t < optlen; t += 16)
310 ND_PRINT((ndo, " %s", ip6addr_string(ndo, value + t)));
311 }
312 break;
313 case DH6OPT_DOMAIN_LIST: {
314 const u_char *tp = value;
315 while (tp < value + optlen) {
316 ND_PRINT((ndo, " "));
317 if ((tp = ns_nprint(ndo, tp, value + optlen)) == NULL)
318 return -1;
319 }
320 }
321 break;
322 }
323
324 i += 4 + optlen;
325 }
326 return 0;
327 }
328
329 /* Determine in-line mode */
330 static int
331 is_in_line(netdissect_options *ndo, int indent)
332 {
333 return indent - 1 >= ndo->ndo_vflag && ndo->ndo_vflag < 3;
334 }
335
336 static void
337 print_type_in_line(netdissect_options *ndo,
338 uint32_t type, int count, int indent, int *first_one)
339 {
340 if (count > 0) {
341 if (*first_one) {
342 *first_one = 0;
343 if (indent > 1) {
344 u_int t;
345 ND_PRINT((ndo, "\n"));
346 for (t = indent; t > 0; t--)
347 ND_PRINT((ndo, "\t"));
348 } else {
349 ND_PRINT((ndo, " "));
350 }
351 } else {
352 ND_PRINT((ndo, ", "));
353 }
354 ND_PRINT((ndo, "%s", tok2str(type_values, "Easter Egg", type)));
355 if (count > 1)
356 ND_PRINT((ndo, " (x%d)", count));
357 }
358 }
359
360 void
361 hncp_print_rec(netdissect_options *ndo,
362 const u_char *cp, u_int length, int indent)
363 {
364 const int in_line = is_in_line(ndo, indent);
365 int first_one = 1;
366
367 u_int i, t;
368
369 uint32_t last_type_mask = 0xffffffffU;
370 int last_type_count = -1;
371
372 const u_char *tlv, *value;
373 uint16_t type, bodylen;
374 uint32_t type_mask;
375
376 i = 0;
377 while (i < length) {
378 tlv = cp + i;
379
380 if (!in_line) {
381 ND_PRINT((ndo, "\n"));
382 for (t = indent; t > 0; t--)
383 ND_PRINT((ndo, "\t"));
384 }
385
386 ND_TCHECK2(*tlv, 4);
387 if (i + 4 > length)
388 goto invalid;
389
390 type = EXTRACT_16BITS(tlv);
391 bodylen = EXTRACT_16BITS(tlv + 2);
392 value = tlv + 4;
393 ND_TCHECK2(*value, bodylen);
394 if (i + bodylen + 4 > length)
395 goto invalid;
396
397 type_mask =
398 (type == 0) ? RANGE_DNCP_RESERVED:
399 (44 <= type && type <= 511) ? RANGE_HNCP_UNASSIGNED:
400 (768 <= type && type <= 1023) ? RANGE_DNCP_PRIVATE_USE:
401 RANGE_DNCP_FUTURE_USE;
402 if (type == 6 || type == 7)
403 type_mask = RANGE_DNCP_FUTURE_USE;
404
405 /* defined types */
406 {
407 t = 0;
408 while (1) {
409 u_int key = type_values[t++].v;
410 if (key > 0xffff)
411 break;
412 if (key == type) {
413 type_mask = type;
414 break;
415 }
416 }
417 }
418
419 if (in_line) {
420 if (last_type_mask == type_mask) {
421 last_type_count++;
422 } else {
423 print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
424 last_type_mask = type_mask;
425 last_type_count = 1;
426 }
427
428 goto skip_multiline;
429 }
430
431 ND_PRINT((ndo,"%s", tok2str(type_values, "Easter Egg (42)", type_mask) ));
432 if (type_mask > 0xffff)
433 ND_PRINT((ndo,": type=%u", type ));
434 ND_PRINT((ndo," (%u)", bodylen + 4 ));
435
436 switch (type_mask) {
437
438 case DNCP_REQUEST_NETWORK_STATE: {
439 if (bodylen != 0)
440 ND_PRINT((ndo, " %s", istr));
441 }
442 break;
443
444 case DNCP_REQUEST_NODE_STATE: {
445 const char *node_identifier;
446 if (bodylen != 4)
447 goto invalid;
448 node_identifier = format_nid(value);
449 ND_PRINT((ndo, " NID: %s", node_identifier));
450 }
451 break;
452
453 case DNCP_NODE_ENDPOINT: {
454 const char *node_identifier;
455 uint32_t endpoint_identifier;
456 if (bodylen != 8)
457 goto invalid;
458 node_identifier = format_nid(value);
459 endpoint_identifier = EXTRACT_32BITS(value + 4);
460 ND_PRINT((ndo, " NID: %s EPID: %08x",
461 node_identifier,
462 endpoint_identifier
463 ));
464 }
465 break;
466
467 case DNCP_NETWORK_STATE: {
468 uint64_t hash;
469 if (bodylen != 8)
470 goto invalid;
471 hash = EXTRACT_64BITS(value);
472 ND_PRINT((ndo, " hash: %016" PRIx64, hash));
473 }
474 break;
475
476 case DNCP_NODE_STATE: {
477 const char *node_identifier, *interval;
478 uint32_t sequence_number;
479 uint64_t hash;
480 if (bodylen < 20)
481 goto invalid;
482 node_identifier = format_nid(value);
483 sequence_number = EXTRACT_32BITS(value + 4);
484 interval = format_interval(EXTRACT_32BITS(value + 8));
485 hash = EXTRACT_64BITS(value + 12);
486 ND_PRINT((ndo, " NID: %s seqno: %u %s hash: %016" PRIx64,
487 node_identifier,
488 sequence_number,
489 interval,
490 hash
491 ));
492 hncp_print_rec(ndo, value+20, bodylen-20, indent+1);
493 }
494 break;
495
496 case DNCP_PEER: {
497 const char *peer_node_identifier;
498 uint32_t peer_endpoint_identifier, endpoint_identifier;
499 if (bodylen != 12)
500 goto invalid;
501 peer_node_identifier = format_nid(value);
502 peer_endpoint_identifier = EXTRACT_32BITS(value + 4);
503 endpoint_identifier = EXTRACT_32BITS(value + 8);
504 ND_PRINT((ndo, " Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x",
505 peer_node_identifier,
506 peer_endpoint_identifier,
507 endpoint_identifier
508 ));
509 }
510 break;
511
512 case DNCP_KEEP_ALIVE_INTERVAL: {
513 uint32_t endpoint_identifier;
514 const char *interval;
515 if (bodylen < 8)
516 goto invalid;
517 endpoint_identifier = EXTRACT_32BITS(value);
518 interval = format_interval(EXTRACT_32BITS(value + 4));
519 ND_PRINT((ndo, " EPID: %08x Interval: %s",
520 endpoint_identifier,
521 interval
522 ));
523 }
524 break;
525
526 case DNCP_TRUST_VERDICT: {
527 if (bodylen <= 36)
528 goto invalid;
529 ND_PRINT((ndo, " Verdict: %u Fingerprint: %s Common Name: ",
530 *value,
531 format_256(value + 4)));
532 safeputs(ndo, value + 36, bodylen - 36);
533 }
534 break;
535
536 case HNCP_HNCP_VERSION: {
537 uint16_t capabilities;
538 uint8_t M, P, H, L;
539 if (bodylen < 5)
540 goto invalid;
541 capabilities = EXTRACT_16BITS(value + 2);
542 M = (uint8_t)((capabilities >> 12) & 0xf);
543 P = (uint8_t)((capabilities >> 8) & 0xf);
544 H = (uint8_t)((capabilities >> 4) & 0xf);
545 L = (uint8_t)(capabilities & 0xf);
546 ND_PRINT((ndo, " M: %u P: %u H: %u L: %u User-agent: ",
547 M, P, H, L
548 ));
549 safeputs(ndo, value + 4, bodylen - 4);
550 }
551 break;
552
553 case HNCP_EXTERNAL_CONNECTION: {
554 /* Container TLV */
555 hncp_print_rec(ndo, value, bodylen, indent+1);
556 }
557 break;
558
559 case HNCP_DELEGATED_PREFIX: {
560 int l;
561 if (bodylen < 9 || bodylen < 9 + (value[8] + 7) / 8)
562 goto invalid;
563 ND_PRINT((ndo, " VLSO: %s PLSO: %s Prefix: ",
564 format_interval(EXTRACT_32BITS(value)),
565 format_interval(EXTRACT_32BITS(value + 4))
566 ));
567 if ((l = print_prefix(ndo, value + 8, bodylen - 8)) < 0)
568 goto invalid;
569 l += 8 + (-l & 3);
570
571 if (bodylen >= l)
572 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
573 }
574 break;
575
576 case HNCP_PREFIX_POLICY: {
577 uint8_t policy;
578 if (bodylen < 1)
579 goto invalid;
580 policy = value[0];
581 ND_PRINT((ndo, " type: "));
582 if (policy == 0) {
583 if (bodylen != 1)
584 goto invalid;
585 ND_PRINT((ndo, "Internet connectivity"));
586 } else if (policy >= 1 && policy <= 128) {
587 ND_PRINT((ndo, "Dest-Prefix: "));
588 print_prefix(ndo, value, bodylen);
589 } else if (policy == 129) {
590 ND_PRINT((ndo, "DNS domain: "));
591 print_dns_label(ndo, value+1, bodylen-1, 1);
592 } else if (policy == 130) {
593 ND_PRINT((ndo, "Opaque UTF-8: "));
594 safeputs(ndo, value + 1, bodylen - 1);
595 } else if (policy == 131) {
596 if (bodylen != 1)
597 goto invalid;
598 ND_PRINT((ndo, "Restrictive assignment"));
599 } else if (policy >= 132) {
600 ND_PRINT((ndo, "Unknown (%u)", policy)); /* Reserved for future additions */
601 }
602 }
603 break;
604
605 case HNCP_DHCPV4_DATA: {
606 if (bodylen == 0)
607 goto invalid;
608 if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0)
609 goto invalid;
610 }
611 break;
612
613 case HNCP_DHCPV6_DATA: {
614 if (bodylen == 0)
615 goto invalid;
616 if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0)
617 goto invalid;
618 }
619 break;
620
621 case HNCP_ASSIGNED_PREFIX: {
622 uint8_t prty;
623 int l;
624 if (bodylen < 6 || bodylen < 6 + (value[5] + 7) / 8)
625 goto invalid;
626 prty = (uint8_t)(value[4] & 0xf);
627 ND_PRINT((ndo, " EPID: %08x Prty: %u",
628 EXTRACT_32BITS(value),
629 prty
630 ));
631 ND_PRINT((ndo, " Prefix: "));
632 if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0)
633 goto invalid;
634 l += 5;
635 l += -l & 3;
636
637 if (bodylen >= l)
638 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
639 }
640 break;
641
642 case HNCP_NODE_ADDRESS: {
643 uint32_t endpoint_identifier;
644 const char *ip_address;
645 if (bodylen < 20)
646 goto invalid;
647 endpoint_identifier = EXTRACT_32BITS(value);
648 ip_address = format_ip6addr(ndo, value + 4);
649 ND_PRINT((ndo, " EPID: %08x IP Address: %s",
650 endpoint_identifier,
651 ip_address
652 ));
653
654 hncp_print_rec(ndo, value + 20, bodylen - 20, indent+1);
655 }
656 break;
657
658 case HNCP_DNS_DELEGATED_ZONE: {
659 const char *ip_address;
660 int len;
661 if (bodylen < 17)
662 goto invalid;
663 ip_address = format_ip6addr(ndo, value);
664 ND_PRINT((ndo, " IP-Address: %s %c%c%c ",
665 ip_address,
666 (value[16] & 4) ? 'l' : '-',
667 (value[16] & 2) ? 'b' : '-',
668 (value[16] & 1) ? 's' : '-'
669 ));
670 len = print_dns_label(ndo, value+17, bodylen-17, 1);
671 if (len < 0)
672 goto invalid;
673 len += 17;
674 len += -len & 3;
675 if (bodylen >= len)
676 hncp_print_rec(ndo, value+len, bodylen-len, indent+1);
677 }
678 break;
679
680 case HNCP_DOMAIN_NAME: {
681 if (bodylen == 0)
682 goto invalid;
683 ND_PRINT((ndo, " Domain: "));
684 print_dns_label(ndo, value, bodylen, 1);
685 }
686 break;
687
688 case HNCP_NODE_NAME: {
689 u_int l;
690 if (bodylen < 17)
691 goto invalid;
692 l = value[16];
693 if (bodylen < 17 + l)
694 goto invalid;
695 ND_PRINT((ndo, " IP-Address: %s Name: ",
696 format_ip6addr(ndo, value)
697 ));
698 if (l < 64) {
699 safeputchar(ndo, '"');
700 safeputs(ndo, value + 17, l);
701 safeputchar(ndo, '"');
702 } else {
703 ND_PRINT((ndo, "%s", istr));
704 }
705 l += 17;
706 l += -l & 3;
707 if (bodylen >= l)
708 hncp_print_rec(ndo, value + l, bodylen - l, indent+1);
709 }
710 break;
711
712 case HNCP_MANAGED_PSK: {
713 if (bodylen < 32)
714 goto invalid;
715 ND_PRINT((ndo, " PSK: %s", format_256(value)));
716 hncp_print_rec(ndo, value + 32, bodylen - 32, indent+1);
717 }
718 break;
719
720 case RANGE_DNCP_RESERVED:
721 case RANGE_HNCP_UNASSIGNED:
722 case RANGE_DNCP_PRIVATE_USE:
723 case RANGE_DNCP_FUTURE_USE:
724 break;
725
726 }
727 skip_multiline:
728
729 i += 4 + bodylen + (-bodylen & 3);
730 }
731 print_type_in_line(ndo, last_type_mask, last_type_count, indent, &first_one);
732
733 return;
734
735 trunc:
736 ND_PRINT((ndo, "%s", "[|hncp]"));
737 return;
738
739 invalid:
740 ND_PRINT((ndo, "%s", istr));
741 return;
742 }