2 * Copyright (C) 1998 and 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 /* \summary: IPv6 DHCP printer */
34 * supported DHCPv6 options:
35 * RFC3319: Session Initiation Protocol (SIP) Servers options,
36 * RFC3633: IPv6 Prefix options,
37 * RFC3646: DNS Configuration options,
38 * RFC3898: Network Information Service (NIS) Configuration options,
39 * RFC4075: Simple Network Time Protocol (SNTP) Configuration option,
40 * RFC4242: Information Refresh Time option,
41 * RFC4280: Broadcast and Multicast Control Servers options,
42 * RFC5908: Network Time Protocol (NTP) Server Option for DHCPv6
43 * RFC6334: Dual-Stack Lite option,
50 #include "netdissect-stdinc.h"
52 #include "netdissect.h"
53 #include "addrtoname.h"
57 #define DHCP6_DURATION_INFINITE 0xffffffff
60 #define DH6ERR_FAILURE 16
61 #define DH6ERR_AUTHFAIL 17
62 #define DH6ERR_POORLYFORMED 18
63 #define DH6ERR_UNAVAIL 19
64 #define DH6ERR_OPTUNAVAIL 20
68 #define DH6_ADVERTISE 2
76 #define DH6_RECONFIGURE 10
77 #define DH6_INFORM_REQ 11
78 #define DH6_RELAY_FORW 12
79 #define DH6_RELAY_REPLY 13
80 #define DH6_LEASEQUERY 14
81 #define DH6_LQ_REPLY 15
83 static const struct tok dh6_msgtype_str
[] = {
84 { DH6_SOLICIT
, "solicit" },
85 { DH6_ADVERTISE
, "advertise" },
86 { DH6_REQUEST
, "request" },
87 { DH6_CONFIRM
, "confirm" },
88 { DH6_RENEW
, "renew" },
89 { DH6_REBIND
, "rebind" },
90 { DH6_REPLY
, "reply" },
91 { DH6_RELEASE
, "release" },
92 { DH6_DECLINE
, "decline" },
93 { DH6_RECONFIGURE
, "reconfigure" },
94 { DH6_INFORM_REQ
, "inf-req" },
95 { DH6_RELAY_FORW
, "relay-fwd" },
96 { DH6_RELAY_REPLY
, "relay-reply" },
97 { DH6_LEASEQUERY
, "leasequery" },
98 { DH6_LQ_REPLY
, "leasequery-reply" },
102 /* DHCP6 base packet format */
110 #define DH6_XIDMASK 0x00ffffff
112 /* DHCPv6 relay messages */
114 nd_uint8_t dh6relay_msgtype
;
115 nd_uint8_t dh6relay_hcnt
;
116 nd_ipv6 dh6relay_linkaddr
; /* XXX: badly aligned */
117 nd_ipv6 dh6relay_peeraddr
;
122 #define DH6OPT_CLIENTID 1
123 #define DH6OPT_SERVERID 2
124 #define DH6OPT_IA_NA 3
125 #define DH6OPT_IA_TA 4
126 #define DH6OPT_IA_ADDR 5
128 #define DH6OPT_PREFERENCE 7
129 # define DH6OPT_PREF_MAX 255
130 #define DH6OPT_ELAPSED_TIME 8
131 #define DH6OPT_RELAY_MSG 9
132 /*#define DH6OPT_SERVER_MSG 10 deprecated */
133 #define DH6OPT_AUTH 11
134 # define DH6OPT_AUTHPROTO_DELAYED 2
135 # define DH6OPT_AUTHPROTO_RECONFIG 3
136 # define DH6OPT_AUTHALG_HMACMD5 1
137 # define DH6OPT_AUTHRDM_MONOCOUNTER 0
138 # define DH6OPT_AUTHRECONFIG_KEY 1
139 # define DH6OPT_AUTHRECONFIG_HMACMD5 2
140 #define DH6OPT_UNICAST 12
141 #define DH6OPT_STATUS_CODE 13
142 # define DH6OPT_STCODE_SUCCESS 0
143 # define DH6OPT_STCODE_UNSPECFAIL 1
144 # define DH6OPT_STCODE_NOADDRAVAIL 2
145 # define DH6OPT_STCODE_NOBINDING 3
146 # define DH6OPT_STCODE_NOTONLINK 4
147 # define DH6OPT_STCODE_USEMULTICAST 5
148 # define DH6OPT_STCODE_NOPREFIXAVAIL 6
149 # define DH6OPT_STCODE_UNKNOWNQUERYTYPE 7
150 # define DH6OPT_STCODE_MALFORMEDQUERY 8
151 # define DH6OPT_STCODE_NOTCONFIGURED 9
152 # define DH6OPT_STCODE_NOTALLOWED 10
153 #define DH6OPT_RAPID_COMMIT 14
154 #define DH6OPT_USER_CLASS 15
155 #define DH6OPT_VENDOR_CLASS 16
156 #define DH6OPT_VENDOR_OPTS 17
157 #define DH6OPT_INTERFACE_ID 18
158 #define DH6OPT_RECONF_MSG 19
159 #define DH6OPT_RECONF_ACCEPT 20
160 #define DH6OPT_SIP_SERVER_D 21
161 #define DH6OPT_SIP_SERVER_A 22
162 #define DH6OPT_DNS_SERVERS 23
163 #define DH6OPT_DOMAIN_LIST 24
164 #define DH6OPT_IA_PD 25
165 #define DH6OPT_IA_PD_PREFIX 26
166 #define DH6OPT_NIS_SERVERS 27
167 #define DH6OPT_NISP_SERVERS 28
168 #define DH6OPT_NIS_NAME 29
169 #define DH6OPT_NISP_NAME 30
170 #define DH6OPT_SNTP_SERVERS 31
171 #define DH6OPT_LIFETIME 32
172 #define DH6OPT_BCMCS_SERVER_D 33
173 #define DH6OPT_BCMCS_SERVER_A 34
174 #define DH6OPT_GEOCONF_CIVIC 36
175 #define DH6OPT_REMOTE_ID 37
176 #define DH6OPT_SUBSCRIBER_ID 38
177 #define DH6OPT_CLIENT_FQDN 39
178 #define DH6OPT_PANA_AGENT 40
179 #define DH6OPT_NEW_POSIX_TIMEZONE 41
180 #define DH6OPT_NEW_TZDB_TIMEZONE 42
181 #define DH6OPT_ERO 43
182 #define DH6OPT_LQ_QUERY 44
183 #define DH6OPT_CLIENT_DATA 45
184 #define DH6OPT_CLT_TIME 46
185 #define DH6OPT_LQ_RELAY_DATA 47
186 #define DH6OPT_LQ_CLIENT_LINK 48
187 #define DH6OPT_NTP_SERVER 56
188 # define DH6OPT_NTP_SUBOPTION_SRV_ADDR 1
189 # define DH6OPT_NTP_SUBOPTION_MC_ADDR 2
190 # define DH6OPT_NTP_SUBOPTION_SRV_FQDN 3
191 #define DH6OPT_BOOTFILE_URL 59 /* RFC5970 */
192 #define DH6OPT_AFTR_NAME 64
193 #define DH6OPT_MUDURL 112
194 #define DH6OPT_SZTP_REDIRECT 136 /* RFC8572 */
196 static const struct tok dh6opt_str
[] = {
197 { DH6OPT_CLIENTID
, "client-ID" },
198 { DH6OPT_SERVERID
, "server-ID" },
199 { DH6OPT_IA_NA
, "IA_NA" },
200 { DH6OPT_IA_TA
, "IA_TA" },
201 { DH6OPT_IA_ADDR
, "IA_ADDR" },
202 { DH6OPT_ORO
, "option-request" },
203 { DH6OPT_PREFERENCE
, "preference" },
204 { DH6OPT_ELAPSED_TIME
, "elapsed-time" },
205 { DH6OPT_RELAY_MSG
, "relay-message" },
206 { DH6OPT_AUTH
, "authentication" },
207 { DH6OPT_UNICAST
, "server-unicast" },
208 { DH6OPT_STATUS_CODE
, "status-code" },
209 { DH6OPT_RAPID_COMMIT
, "rapid-commit" },
210 { DH6OPT_USER_CLASS
, "user-class" },
211 { DH6OPT_VENDOR_CLASS
, "vendor-class" },
212 { DH6OPT_VENDOR_OPTS
, "vendor-specific-info" },
213 { DH6OPT_INTERFACE_ID
, "interface-ID" },
214 { DH6OPT_RECONF_MSG
, "reconfigure-message" },
215 { DH6OPT_RECONF_ACCEPT
, "reconfigure-accept" },
216 { DH6OPT_SIP_SERVER_D
, "SIP-servers-domain" },
217 { DH6OPT_SIP_SERVER_A
, "SIP-servers-address" },
218 { DH6OPT_DNS_SERVERS
, "DNS-server" },
219 { DH6OPT_DOMAIN_LIST
, "DNS-search-list" },
220 { DH6OPT_IA_PD
, "IA_PD" },
221 { DH6OPT_IA_PD_PREFIX
, "IA_PD-prefix" },
222 { DH6OPT_SNTP_SERVERS
, "SNTP-servers" },
223 { DH6OPT_LIFETIME
, "lifetime" },
224 { DH6OPT_NIS_SERVERS
, "NIS-server" },
225 { DH6OPT_NISP_SERVERS
, "NIS+-server" },
226 { DH6OPT_NIS_NAME
, "NIS-domain-name" },
227 { DH6OPT_NISP_NAME
, "NIS+-domain-name" },
228 { DH6OPT_BCMCS_SERVER_D
, "BCMCS-domain-name" },
229 { DH6OPT_BCMCS_SERVER_A
, "BCMCS-server" },
230 { DH6OPT_GEOCONF_CIVIC
, "Geoconf-Civic" },
231 { DH6OPT_REMOTE_ID
, "Remote-ID" },
232 { DH6OPT_SUBSCRIBER_ID
, "Subscriber-ID" },
233 { DH6OPT_CLIENT_FQDN
, "Client-FQDN" },
234 { DH6OPT_PANA_AGENT
, "PANA-agent" },
235 { DH6OPT_NEW_POSIX_TIMEZONE
, "POSIX-timezone" },
236 { DH6OPT_NEW_TZDB_TIMEZONE
, "POSIX-tz-database" },
237 { DH6OPT_ERO
, "Echo-request-option" },
238 { DH6OPT_LQ_QUERY
, "Lease-query" },
239 { DH6OPT_CLIENT_DATA
, "LQ-client-data" },
240 { DH6OPT_CLT_TIME
, "Clt-time" },
241 { DH6OPT_LQ_RELAY_DATA
, "LQ-relay-data" },
242 { DH6OPT_LQ_CLIENT_LINK
, "LQ-client-link" },
243 { DH6OPT_NTP_SERVER
, "NTP-server" },
244 { DH6OPT_BOOTFILE_URL
, "Bootfile-URL" },
245 { DH6OPT_AFTR_NAME
, "AFTR-Name" },
246 { DH6OPT_MUDURL
, "MUD-URL" },
247 { DH6OPT_SZTP_REDIRECT
, "SZTP-redirect" },
251 static const struct tok dh6opt_stcode_str
[] = {
252 { DH6OPT_STCODE_SUCCESS
, "Success" }, /* RFC3315 */
253 { DH6OPT_STCODE_UNSPECFAIL
, "UnspecFail" }, /* RFC3315 */
254 { DH6OPT_STCODE_NOADDRAVAIL
, "NoAddrsAvail" }, /* RFC3315 */
255 { DH6OPT_STCODE_NOBINDING
, "NoBinding" }, /* RFC3315 */
256 { DH6OPT_STCODE_NOTONLINK
, "NotOnLink" }, /* RFC3315 */
257 { DH6OPT_STCODE_USEMULTICAST
, "UseMulticast" }, /* RFC3315 */
258 { DH6OPT_STCODE_NOPREFIXAVAIL
, "NoPrefixAvail" }, /* RFC3633 */
259 { DH6OPT_STCODE_UNKNOWNQUERYTYPE
, "UnknownQueryType" }, /* RFC5007 */
260 { DH6OPT_STCODE_MALFORMEDQUERY
, "MalformedQuery" }, /* RFC5007 */
261 { DH6OPT_STCODE_NOTCONFIGURED
, "NotConfigured" }, /* RFC5007 */
262 { DH6OPT_STCODE_NOTALLOWED
, "NotAllowed" }, /* RFC5007 */
267 nd_uint16_t dh6opt_type
;
268 nd_uint16_t dh6opt_len
;
269 /* type-dependent data follows */
273 dhcp6stcode(const uint16_t code
)
275 return code
> 255 ? "INVALID code" : tok2str(dh6opt_stcode_str
, "code%u", code
);
279 dhcp6opt_print(netdissect_options
*ndo
,
280 const u_char
*cp
, const u_char
*ep
)
282 const struct dhcp6opt
*dh6o
;
290 u_int authinfolen
, authrealmlen
;
291 u_int remain_len
; /* Length of remaining options */
292 u_int label_len
; /* Label length */
293 uint16_t subopt_code
;
295 uint8_t dh6_reconf_type
;
296 uint8_t dh6_lq_query_type
;
297 u_int first_list_value
;
298 uint16_t remainder_len
;
303 if (ep
< cp
+ sizeof(*dh6o
))
305 dh6o
= (const struct dhcp6opt
*)cp
;
306 ND_TCHECK_SIZE(dh6o
);
307 optlen
= GET_BE_U_2(dh6o
->dh6opt_len
);
308 if (ep
< cp
+ sizeof(*dh6o
) + optlen
)
310 opttype
= GET_BE_U_2(dh6o
->dh6opt_type
);
311 ND_PRINT(" (%s", tok2str(dh6opt_str
, "opt_%u", opttype
));
312 ND_TCHECK_LEN(cp
+ sizeof(*dh6o
), optlen
);
314 case DH6OPT_CLIENTID
:
315 case DH6OPT_SERVERID
:
321 tp
= (const u_char
*)(dh6o
+ 1);
322 switch (GET_BE_U_2(tp
)) {
324 if (optlen
>= 2 + 6) {
325 ND_PRINT(" hwaddr/time type %u time %u ",
328 for (i
= 8; i
< optlen
; i
++)
339 if (optlen
>= 2 + 8) {
341 for (i
= 2; i
< 2 + 8; i
++)
352 if (optlen
>= 2 + 2) {
353 ND_PRINT(" hwaddr type %u ",
355 for (i
= 4; i
< optlen
; i
++)
366 ND_PRINT(" type %u)", GET_BE_U_2(tp
));
376 tp
= (const u_char
*)(dh6o
+ 1);
377 ND_PRINT(" %s", GET_IP6ADDR_STRING(tp
));
378 ND_PRINT(" pltime:%u vltime:%u",
380 GET_BE_U_4(tp
+ 20));
382 /* there are sub-options */
383 dhcp6opt_print(ndo
, tp
+ 24, tp
+ optlen
);
393 tp
= (const u_char
*)(dh6o
+ 1);
394 for (i
= 0; i
< optlen
; i
+= 2) {
396 tok2str(dh6opt_str
, "opt_%u", GET_BE_U_2(tp
+ i
)));
400 case DH6OPT_PREFERENCE
:
405 tp
= (const u_char
*)(dh6o
+ 1);
406 ND_PRINT(" %u)", GET_U_1(tp
));
408 case DH6OPT_ELAPSED_TIME
:
413 tp
= (const u_char
*)(dh6o
+ 1);
414 ND_PRINT(" %u)", GET_BE_U_2(tp
));
416 case DH6OPT_RELAY_MSG
:
418 const u_char
*snapend_save
;
421 tp
= (const u_char
*)(dh6o
+ 1);
423 * Update the snapend to the end of the option before
424 * calling recursively dhcp6_print() for the nested
425 * packet. Other options may be present after the
426 * nested DHCPv6 packet. This prevents that, in
427 * dhcp6_print(), for the nested DHCPv6 packet, the
428 * remaining length < remaining caplen.
430 snapend_save
= ndo
->ndo_snapend
;
431 ndo
->ndo_snapend
= ND_MIN(tp
+ optlen
, ndo
->ndo_snapend
);
432 dhcp6_print(ndo
, tp
, optlen
);
433 ndo
->ndo_snapend
= snapend_save
;
442 tp
= (const u_char
*)(dh6o
+ 1);
443 auth_proto
= GET_U_1(tp
);
444 switch (auth_proto
) {
445 case DH6OPT_AUTHPROTO_DELAYED
:
446 ND_PRINT(" proto: delayed");
448 case DH6OPT_AUTHPROTO_RECONFIG
:
449 ND_PRINT(" proto: reconfigure");
452 ND_PRINT(" proto: %u", auth_proto
);
456 auth_alg
= GET_U_1(tp
);
458 case DH6OPT_AUTHALG_HMACMD5
:
459 /* XXX: may depend on the protocol */
460 ND_PRINT(", alg: HMAC-MD5");
463 ND_PRINT(", alg: %u", auth_alg
);
467 auth_rdm
= GET_U_1(tp
);
469 case DH6OPT_AUTHRDM_MONOCOUNTER
:
470 ND_PRINT(", RDM: mono");
473 ND_PRINT(", RDM: %u", auth_rdm
);
478 for (i
= 0; i
< 4; i
++, tp
+= 2)
479 ND_PRINT(" %04x", GET_BE_U_2(tp
));
481 /* protocol dependent part */
482 authinfolen
= optlen
- 11;
483 switch (auth_proto
) {
484 case DH6OPT_AUTHPROTO_DELAYED
:
485 if (authinfolen
== 0)
487 if (authinfolen
< 20) {
491 authrealmlen
= authinfolen
- 20;
492 if (authrealmlen
> 0) {
493 ND_PRINT(", realm: ");
495 for (i
= 0; i
< authrealmlen
; i
++, tp
++)
496 ND_PRINT("%02x", GET_U_1(tp
));
497 ND_PRINT(", key ID: %08x", GET_BE_U_4(tp
));
499 ND_PRINT(", HMAC-MD5:");
500 for (i
= 0; i
< 4; i
++, tp
+= 4)
501 ND_PRINT(" %08x", GET_BE_U_4(tp
));
503 case DH6OPT_AUTHPROTO_RECONFIG
:
504 if (authinfolen
!= 17) {
508 switch (GET_U_1(tp
)) {
509 case DH6OPT_AUTHRECONFIG_KEY
:
510 ND_PRINT(" reconfig-key");
512 case DH6OPT_AUTHRECONFIG_HMACMD5
:
513 ND_PRINT(" type: HMAC-MD5");
516 ND_PRINT(" type: ??");
521 for (i
= 0; i
< 4; i
++, tp
+= 4)
522 ND_PRINT(" %08x", GET_BE_U_4(tp
));
531 case DH6OPT_RAPID_COMMIT
: /* nothing todo */
534 case DH6OPT_INTERFACE_ID
:
535 case DH6OPT_SUBSCRIBER_ID
:
537 * Since we cannot predict the encoding, print hex dump
538 * at most 10 characters.
540 tp
= (const u_char
*)(dh6o
+ 1);
542 for (i
= 0; i
< optlen
&& i
< 10; i
++)
543 ND_PRINT("%02x", GET_U_1(tp
+ i
));
546 case DH6OPT_RECONF_MSG
:
551 tp
= (const u_char
*)(dh6o
+ 1);
552 dh6_reconf_type
= GET_U_1(tp
);
553 switch (dh6_reconf_type
) {
555 ND_PRINT(" for renew)");
558 ND_PRINT(" for inf-req)");
561 ND_PRINT(" for ?\?\?(%02x))", dh6_reconf_type
);
565 case DH6OPT_RECONF_ACCEPT
: /* nothing todo */
568 case DH6OPT_SIP_SERVER_A
:
569 case DH6OPT_DNS_SERVERS
:
570 case DH6OPT_SNTP_SERVERS
:
571 case DH6OPT_NIS_SERVERS
:
572 case DH6OPT_NISP_SERVERS
:
573 case DH6OPT_BCMCS_SERVER_A
:
574 case DH6OPT_PANA_AGENT
:
575 case DH6OPT_LQ_CLIENT_LINK
:
580 tp
= (const u_char
*)(dh6o
+ 1);
581 for (i
= 0; i
< optlen
; i
+= 16)
582 ND_PRINT(" %s", GET_IP6ADDR_STRING(tp
+ i
));
585 case DH6OPT_SIP_SERVER_D
:
586 case DH6OPT_DOMAIN_LIST
:
587 tp
= (const u_char
*)(dh6o
+ 1);
588 while (tp
< cp
+ sizeof(*dh6o
) + optlen
) {
590 if ((tp
= fqdn_print(ndo
, tp
, cp
+ sizeof(*dh6o
) + optlen
)) == NULL
)
595 case DH6OPT_STATUS_CODE
:
600 tp
= (const u_char
*)(dh6o
+ 1);
601 ND_PRINT(" %s)", dhcp6stcode(GET_BE_U_2(tp
)));
609 tp
= (const u_char
*)(dh6o
+ 1);
610 ND_PRINT(" IAID:%u T1:%u T2:%u",
615 /* there are sub-options */
616 dhcp6opt_print(ndo
, tp
+ 12, tp
+ optlen
);
625 tp
= (const u_char
*)(dh6o
+ 1);
626 ND_PRINT(" IAID:%u", GET_BE_U_4(tp
));
628 /* there are sub-options */
629 dhcp6opt_print(ndo
, tp
+ 4, tp
+ optlen
);
633 case DH6OPT_IA_PD_PREFIX
:
638 tp
= (const u_char
*)(dh6o
+ 1);
639 ND_PRINT(" %s/%u", GET_IP6ADDR_STRING(tp
+ 9),
641 ND_PRINT(" pltime:%u vltime:%u",
645 /* there are sub-options */
646 dhcp6opt_print(ndo
, tp
+ 25, tp
+ optlen
);
650 case DH6OPT_LIFETIME
:
651 case DH6OPT_CLT_TIME
:
656 tp
= (const u_char
*)(dh6o
+ 1);
657 ND_PRINT(" %u)", GET_BE_U_4(tp
));
659 case DH6OPT_REMOTE_ID
:
664 tp
= (const u_char
*)(dh6o
+ 1);
665 ND_PRINT(" %u ", GET_BE_U_4(tp
));
667 * Print hex dump first 10 characters.
669 for (i
= 4; i
< optlen
&& i
< 14; i
++)
670 ND_PRINT("%02x", GET_U_1(tp
+ i
));
673 case DH6OPT_LQ_QUERY
:
678 tp
= (const u_char
*)(dh6o
+ 1);
679 dh6_lq_query_type
= GET_U_1(tp
);
680 switch (dh6_lq_query_type
) {
682 ND_PRINT(" by-address");
685 ND_PRINT(" by-clientID");
688 ND_PRINT(" type_%u", dh6_lq_query_type
);
691 ND_PRINT(" %s", GET_IP6ADDR_STRING(tp
+ 1));
693 /* there are query-options */
694 dhcp6opt_print(ndo
, tp
+ 17, tp
+ optlen
);
698 case DH6OPT_CLIENT_DATA
:
699 tp
= (const u_char
*)(dh6o
+ 1);
701 /* there are encapsulated options */
702 dhcp6opt_print(ndo
, tp
, tp
+ optlen
);
706 case DH6OPT_LQ_RELAY_DATA
:
711 tp
= (const u_char
*)(dh6o
+ 1);
712 ND_PRINT(" %s ", GET_IP6ADDR_STRING(tp
));
714 * Print hex dump first 10 characters.
716 for (i
= 16; i
< optlen
&& i
< 26; i
++)
717 ND_PRINT("%02x", GET_U_1(tp
+ i
));
720 case DH6OPT_NTP_SERVER
:
725 tp
= (const u_char
*)(dh6o
+ 1);
726 while (tp
< cp
+ sizeof(*dh6o
) + optlen
- 4) {
727 subopt_code
= GET_BE_U_2(tp
);
729 subopt_len
= GET_BE_U_2(tp
);
731 if (tp
+ subopt_len
> cp
+ sizeof(*dh6o
) + optlen
)
733 ND_PRINT(" subopt:%u", subopt_code
);
734 switch (subopt_code
) {
735 case DH6OPT_NTP_SUBOPTION_SRV_ADDR
:
736 case DH6OPT_NTP_SUBOPTION_MC_ADDR
:
737 if (subopt_len
!= 16) {
741 ND_PRINT(" %s", GET_IP6ADDR_STRING(tp
));
743 case DH6OPT_NTP_SUBOPTION_SRV_FQDN
:
745 if (fqdn_print(ndo
, tp
, tp
+ subopt_len
) == NULL
)
756 case DH6OPT_AFTR_NAME
:
761 tp
= (const u_char
*)(dh6o
+ 1);
764 /* Encoding is described in section 3.1 of RFC 1035 */
765 while (remain_len
&& GET_U_1(tp
)) {
766 label_len
= GET_U_1(tp
);
768 if (label_len
< remain_len
- 1) {
769 nd_printjnp(ndo
, tp
, label_len
);
771 remain_len
-= (label_len
+ 1);
772 if(GET_U_1(tp
)) ND_PRINT(".");
780 case DH6OPT_NEW_POSIX_TIMEZONE
: /* all three of these options */
781 case DH6OPT_NEW_TZDB_TIMEZONE
: /* are encoded similarly */
782 case DH6OPT_MUDURL
: /* although GMT might not work */
787 tp
= (const u_char
*)(dh6o
+ 1);
789 nd_printjnp(ndo
, tp
, optlen
);
793 case DH6OPT_BOOTFILE_URL
:
794 tp
= (const u_char
*)(dh6o
+ 1);
796 nd_printjn(ndo
, tp
, optlen
);
800 case DH6OPT_SZTP_REDIRECT
:
801 case DH6OPT_USER_CLASS
:
803 tp
= (const u_char
*)(dh6o
+ 1);
804 first_list_value
= TRUE
;
805 remainder_len
= optlen
;
806 while (remainder_len
>= 2) {
807 if (first_list_value
== FALSE
) {
810 first_list_value
= FALSE
;
811 subopt_len
= GET_BE_U_2(tp
);
812 if (subopt_len
> remainder_len
-2) {
816 nd_printjn(ndo
, tp
, subopt_len
);
818 remainder_len
-= (subopt_len
+2);
820 if (remainder_len
!= 0 ) {
831 cp
+= sizeof(*dh6o
) + optlen
;
840 * Print dhcp6 packets
843 dhcp6_print(netdissect_options
*ndo
,
844 const u_char
*cp
, u_int length
)
846 const struct dhcp6
*dh6
;
847 const struct dhcp6_relay
*dh6relay
;
853 ndo
->ndo_protocol
= "dhcp6";
854 nd_print_protocol(ndo
);
856 ep
= ndo
->ndo_snapend
;
857 if (cp
+ length
< ep
)
860 dh6
= (const struct dhcp6
*)cp
;
861 dh6relay
= (const struct dhcp6_relay
*)cp
;
862 ND_TCHECK_4(dh6
->dh6_msgtypexid
.xid
);
863 msgtype
= GET_U_1(dh6
->dh6_msgtypexid
.msgtype
);
864 name
= tok2str(dh6_msgtype_str
, "msgtype-%u", msgtype
);
866 if (!ndo
->ndo_vflag
) {
867 ND_PRINT(" %s", name
);
871 /* XXX relay agent messages have to be handled differently */
873 ND_PRINT(" %s (", name
); /*)*/
874 if (msgtype
!= DH6_RELAY_FORW
&& msgtype
!= DH6_RELAY_REPLY
) {
876 GET_BE_U_4(dh6
->dh6_msgtypexid
.xid
) & DH6_XIDMASK
);
877 extp
= (const u_char
*)(dh6
+ 1);
878 dhcp6opt_print(ndo
, extp
, ep
);
879 } else { /* relay messages */
880 ND_PRINT("linkaddr=%s", GET_IP6ADDR_STRING(dh6relay
->dh6relay_linkaddr
));
882 ND_PRINT(" peeraddr=%s", GET_IP6ADDR_STRING(dh6relay
->dh6relay_peeraddr
));
884 dhcp6opt_print(ndo
, (const u_char
*)(dh6relay
+ 1), ep
);