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
31 * supported DHCPv6 options:
32 * RFC3319: Session Initiation Protocol (SIP) Servers options,
33 * RFC3633: IPv6 Prefix options,
34 * RFC3646: DNS Configuration options,
35 * RFC3898: Network Information Service (NIS) Configuration options,
36 * RFC4075: Simple Network Time Protocol (SNTP) Configuration option,
37 * RFC4242: Information Refresh Time option,
38 * RFC4280: Broadcast and Multicast Control Servers options,
39 * RFC6334: Dual-Stack Lite option,
43 static const char rcsid
[] _U_
=
44 "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.37 2008-02-06 10:26:09 guy Exp $";
51 #include <tcpdump-stdinc.h>
56 #include "interface.h"
57 #include "addrtoname.h"
61 #define DHCP6_DURATITION_INFINITE 0xffffffff
64 #define DH6ERR_FAILURE 16
65 #define DH6ERR_AUTHFAIL 17
66 #define DH6ERR_POORLYFORMED 18
67 #define DH6ERR_UNAVAIL 19
68 #define DH6ERR_OPTUNAVAIL 20
72 #define DH6_ADVERTISE 2
80 #define DH6_RECONFIGURE 10
81 #define DH6_INFORM_REQ 11
82 #define DH6_RELAY_FORW 12
83 #define DH6_RELAY_REPLY 13
84 #define DH6_LEASEQUERY 14
85 #define DH6_LQ_REPLY 15
87 /* DHCP6 base packet format */
95 #define dh6_msgtype dh6_msgtypexid.m
96 #define dh6_xid dh6_msgtypexid.x
97 #define DH6_XIDMASK 0x00ffffff
99 /* DHCPv6 relay messages */
101 u_int8_t dh6relay_msgtype
;
102 u_int8_t dh6relay_hcnt
;
103 u_int8_t dh6relay_linkaddr
[16]; /* XXX: badly aligned */
104 u_int8_t dh6relay_peeraddr
[16];
109 #define DH6OPT_CLIENTID 1
110 #define DH6OPT_SERVERID 2
111 #define DH6OPT_IA_NA 3
112 #define DH6OPT_IA_TA 4
113 #define DH6OPT_IA_ADDR 5
115 #define DH6OPT_PREFERENCE 7
116 # define DH6OPT_PREF_MAX 255
117 #define DH6OPT_ELAPSED_TIME 8
118 #define DH6OPT_RELAY_MSG 9
119 /*#define DH6OPT_SERVER_MSG 10 deprecated */
120 #define DH6OPT_AUTH 11
121 # define DH6OPT_AUTHPROTO_DELAYED 2
122 # define DH6OPT_AUTHPROTO_RECONFIG 3
123 # define DH6OPT_AUTHALG_HMACMD5 1
124 # define DH6OPT_AUTHRDM_MONOCOUNTER 0
125 # define DH6OPT_AUTHRECONFIG_KEY 1
126 # define DH6OPT_AUTHRECONFIG_HMACMD5 2
127 #define DH6OPT_UNICAST 12
128 #define DH6OPT_STATUS_CODE 13
129 # define DH6OPT_STCODE_SUCCESS 0
130 # define DH6OPT_STCODE_UNSPECFAIL 1
131 # define DH6OPT_STCODE_NOADDRAVAIL 2
132 # define DH6OPT_STCODE_NOBINDING 3
133 # define DH6OPT_STCODE_NOTONLINK 4
134 # define DH6OPT_STCODE_USEMULTICAST 5
135 # define DH6OPT_STCODE_NOPREFIXAVAIL 6
136 # define DH6OPT_STCODE_UNKNOWNQUERYTYPE 7
137 # define DH6OPT_STCODE_MALFORMEDQUERY 8
138 # define DH6OPT_STCODE_NOTCONFIGURED 9
139 # define DH6OPT_STCODE_NOTALLOWED 10
140 #define DH6OPT_RAPID_COMMIT 14
141 #define DH6OPT_USER_CLASS 15
142 #define DH6OPT_VENDOR_CLASS 16
143 #define DH6OPT_VENDOR_OPTS 17
144 #define DH6OPT_INTERFACE_ID 18
145 #define DH6OPT_RECONF_MSG 19
146 #define DH6OPT_RECONF_ACCEPT 20
147 #define DH6OPT_SIP_SERVER_D 21
148 #define DH6OPT_SIP_SERVER_A 22
149 #define DH6OPT_DNS 23
150 #define DH6OPT_DNSNAME 24
151 #define DH6OPT_IA_PD 25
152 #define DH6OPT_IA_PD_PREFIX 26
153 #define DH6OPT_NIS_SERVERS 27
154 #define DH6OPT_NISP_SERVERS 28
155 #define DH6OPT_NIS_NAME 29
156 #define DH6OPT_NISP_NAME 30
157 #define DH6OPT_NTP_SERVERS 31
158 #define DH6OPT_LIFETIME 32
159 #define DH6OPT_BCMCS_SERVER_D 33
160 #define DH6OPT_BCMCS_SERVER_A 34
161 #define DH6OPT_GEOCONF_CIVIC 36
162 #define DH6OPT_REMOTE_ID 37
163 #define DH6OPT_SUBSCRIBER_ID 38
164 #define DH6OPT_CLIENT_FQDN 39
165 #define DH6OPT_PANA_AGENT 40
166 #define DH6OPT_NEW_POSIX_TIMEZONE 41
167 #define DH6OPT_NEW_TZDB_TIMEZONE 42
168 #define DH6OPT_ERO 43
169 #define DH6OPT_LQ_QUERY 44
170 #define DH6OPT_CLIENT_DATA 45
171 #define DH6OPT_CLT_TIME 46
172 #define DH6OPT_LQ_RELAY_DATA 47
173 #define DH6OPT_LQ_CLIENT_LINK 48
174 #define DH6OPT_AFTR_NAME 64
177 u_int16_t dh6opt_type
;
178 u_int16_t dh6opt_len
;
179 /* type-dependent data follows */
183 dhcp6opt_name(int type
)
185 static char genstr
[sizeof("opt_65535") + 1]; /* XXX thread unsafe */
188 return "INVALID-option";
191 case DH6OPT_CLIENTID
:
193 case DH6OPT_SERVERID
:
202 return "option-request";
203 case DH6OPT_PREFERENCE
:
205 case DH6OPT_ELAPSED_TIME
:
206 return "elapsed-time";
207 case DH6OPT_RELAY_MSG
:
208 return "relay-message";
210 return "authentication";
212 return "server-unicast";
213 case DH6OPT_STATUS_CODE
:
214 return "status-code";
215 case DH6OPT_RAPID_COMMIT
:
216 return "rapid-commit";
217 case DH6OPT_USER_CLASS
:
219 case DH6OPT_VENDOR_CLASS
:
220 return "vendor-class";
221 case DH6OPT_VENDOR_OPTS
:
222 return "vendor-specific-info";
223 case DH6OPT_INTERFACE_ID
:
224 return "interface-ID";
225 case DH6OPT_RECONF_MSG
:
226 return "reconfigure-message";
227 case DH6OPT_RECONF_ACCEPT
:
228 return "reconfigure-accept";
229 case DH6OPT_SIP_SERVER_D
:
230 return "SIP-servers-domain";
231 case DH6OPT_SIP_SERVER_A
:
232 return "SIP-servers-address";
236 return "DNS-search-list";
239 case DH6OPT_IA_PD_PREFIX
:
240 return "IA_PD-prefix";
241 case DH6OPT_NTP_SERVERS
:
243 case DH6OPT_LIFETIME
:
245 case DH6OPT_NIS_SERVERS
:
247 case DH6OPT_NISP_SERVERS
:
248 return "NIS+-server";
249 case DH6OPT_NIS_NAME
:
250 return "NIS-domain-name";
251 case DH6OPT_NISP_NAME
:
252 return "NIS+-domain-name";
253 case DH6OPT_BCMCS_SERVER_D
:
254 return "BCMCS-domain-name";
255 case DH6OPT_BCMCS_SERVER_A
:
256 return "BCMCS-server";
257 case DH6OPT_GEOCONF_CIVIC
:
258 return "Geoconf-Civic";
259 case DH6OPT_REMOTE_ID
:
261 case DH6OPT_SUBSCRIBER_ID
:
262 return "Subscriber-ID";
263 case DH6OPT_CLIENT_FQDN
:
264 return "Client-FQDN";
265 case DH6OPT_PANA_AGENT
:
267 case DH6OPT_NEW_POSIX_TIMEZONE
:
268 return "POSIX-timezone";
269 case DH6OPT_NEW_TZDB_TIMEZONE
:
270 return "POSIX-tz-database";
272 return "Echo-request-option";
273 case DH6OPT_LQ_QUERY
:
274 return "Lease-query";
275 case DH6OPT_CLIENT_DATA
:
276 return "LQ-client-data";
277 case DH6OPT_CLT_TIME
:
279 case DH6OPT_LQ_RELAY_DATA
:
280 return "LQ-relay-data";
281 case DH6OPT_LQ_CLIENT_LINK
:
282 return "LQ-client-link";
283 case DH6OPT_AFTR_NAME
:
286 snprintf(genstr
, sizeof(genstr
), "opt_%d", type
);
292 dhcp6stcode(int code
)
294 static char genstr
[sizeof("code255") + 1]; /* XXX thread unsafe */
297 return "INVALID code";
300 case DH6OPT_STCODE_SUCCESS
:
302 case DH6OPT_STCODE_UNSPECFAIL
:
303 return "unspec failure";
304 case DH6OPT_STCODE_NOADDRAVAIL
:
305 return "no addresses";
306 case DH6OPT_STCODE_NOBINDING
:
308 case DH6OPT_STCODE_NOTONLINK
:
309 return "not on-link";
310 case DH6OPT_STCODE_USEMULTICAST
:
311 return "use multicast";
312 case DH6OPT_STCODE_NOPREFIXAVAIL
:
313 return "no prefixes";
314 case DH6OPT_STCODE_UNKNOWNQUERYTYPE
:
315 return "unknown query type";
316 case DH6OPT_STCODE_MALFORMEDQUERY
:
317 return "malformed query";
318 case DH6OPT_STCODE_NOTCONFIGURED
:
319 return "not configured";
320 case DH6OPT_STCODE_NOTALLOWED
:
321 return "not allowed";
323 snprintf(genstr
, sizeof(genstr
), "code%d", code
);
329 dhcp6opt_print(const u_char
*cp
, const u_char
*ep
)
331 struct dhcp6opt
*dh6o
;
337 u_int authinfolen
, authrealmlen
;
338 int remain_len
; /* Length of remaining options */
339 int label_len
; /* Label length */
344 if (ep
< cp
+ sizeof(*dh6o
))
346 dh6o
= (struct dhcp6opt
*)cp
;
348 optlen
= EXTRACT_16BITS(&dh6o
->dh6opt_len
);
349 if (ep
< cp
+ sizeof(*dh6o
) + optlen
)
351 opttype
= EXTRACT_16BITS(&dh6o
->dh6opt_type
);
352 printf(" (%s", dhcp6opt_name(opttype
));
354 case DH6OPT_CLIENTID
:
355 case DH6OPT_SERVERID
:
361 tp
= (u_char
*)(dh6o
+ 1);
362 switch (EXTRACT_16BITS(tp
)) {
364 if (optlen
>= 2 + 6) {
365 printf(" hwaddr/time type %u time %u ",
366 EXTRACT_16BITS(&tp
[2]),
367 EXTRACT_32BITS(&tp
[4]));
368 for (i
= 8; i
< optlen
; i
++)
369 printf("%02x", tp
[i
]);
378 if (optlen
>= 2 + 8) {
380 for (i
= 2; i
< 2 + 8; i
++)
381 printf("%02x", tp
[i
]);
390 if (optlen
>= 2 + 2) {
391 printf(" hwaddr type %u ",
392 EXTRACT_16BITS(&tp
[2]));
393 for (i
= 4; i
< optlen
; i
++)
394 printf("%02x", tp
[i
]);
403 printf(" type %d)", EXTRACT_16BITS(tp
));
413 tp
= (u_char
*)(dh6o
+ 1);
414 printf(" %s", ip6addr_string(&tp
[0]));
415 printf(" pltime:%u vltime:%u",
416 EXTRACT_32BITS(&tp
[16]),
417 EXTRACT_32BITS(&tp
[20]));
419 /* there are sub-options */
420 dhcp6opt_print(tp
+ 24, tp
+ optlen
);
430 tp
= (u_char
*)(dh6o
+ 1);
431 for (i
= 0; i
< optlen
; i
+= 2) {
433 dhcp6opt_name(EXTRACT_16BITS(&tp
[i
])));
437 case DH6OPT_PREFERENCE
:
442 tp
= (u_char
*)(dh6o
+ 1);
445 case DH6OPT_ELAPSED_TIME
:
450 tp
= (u_char
*)(dh6o
+ 1);
451 printf(" %d)", EXTRACT_16BITS(tp
));
453 case DH6OPT_RELAY_MSG
:
455 tp
= (u_char
*)(dh6o
+ 1);
456 dhcp6_print(tp
, optlen
);
464 tp
= (u_char
*)(dh6o
+ 1);
466 switch (auth_proto
) {
467 case DH6OPT_AUTHPROTO_DELAYED
:
468 printf(" proto: delayed");
470 case DH6OPT_AUTHPROTO_RECONFIG
:
471 printf(" proto: reconfigure");
474 printf(" proto: %d", auth_proto
);
479 case DH6OPT_AUTHALG_HMACMD5
:
480 /* XXX: may depend on the protocol */
481 printf(", alg: HMAC-MD5");
484 printf(", alg: %d", *tp
);
489 case DH6OPT_AUTHRDM_MONOCOUNTER
:
490 printf(", RDM: mono");
493 printf(", RDM: %d", *tp
);
498 for (i
= 0; i
< 4; i
++, tp
+= 2)
499 printf(" %04x", EXTRACT_16BITS(tp
));
501 /* protocol dependent part */
502 authinfolen
= optlen
- 11;
503 switch (auth_proto
) {
504 case DH6OPT_AUTHPROTO_DELAYED
:
505 if (authinfolen
== 0)
507 if (authinfolen
< 20) {
511 authrealmlen
= authinfolen
- 20;
512 if (authrealmlen
> 0) {
515 for (i
= 0; i
< authrealmlen
; i
++, tp
++)
517 printf(", key ID: %08x", EXTRACT_32BITS(tp
));
519 printf(", HMAC-MD5:");
520 for (i
= 0; i
< 4; i
++, tp
+= 4)
521 printf(" %08x", EXTRACT_32BITS(tp
));
523 case DH6OPT_AUTHPROTO_RECONFIG
:
524 if (authinfolen
!= 17) {
529 case DH6OPT_AUTHRECONFIG_KEY
:
530 printf(" reconfig-key");
532 case DH6OPT_AUTHRECONFIG_HMACMD5
:
533 printf(" type: HMAC-MD5");
540 for (i
= 0; i
< 4; i
++, tp
+= 4)
541 printf(" %08x", EXTRACT_32BITS(tp
));
550 case DH6OPT_RAPID_COMMIT
: /* nothing todo */
553 case DH6OPT_INTERFACE_ID
:
554 case DH6OPT_SUBSCRIBER_ID
:
556 * Since we cannot predict the encoding, print hex dump
557 * at most 10 characters.
559 tp
= (u_char
*)(dh6o
+ 1);
561 for (i
= 0; i
< optlen
&& i
< 10; i
++)
562 printf("%02x", tp
[i
]);
565 case DH6OPT_RECONF_MSG
:
566 tp
= (u_char
*)(dh6o
+ 1);
569 printf(" for renew)");
572 printf(" for inf-req)");
575 printf(" for ?\?\?(%02x))", *tp
);
579 case DH6OPT_RECONF_ACCEPT
: /* nothing todo */
582 case DH6OPT_SIP_SERVER_A
:
584 case DH6OPT_NTP_SERVERS
:
585 case DH6OPT_NIS_SERVERS
:
586 case DH6OPT_NISP_SERVERS
:
587 case DH6OPT_BCMCS_SERVER_A
:
588 case DH6OPT_PANA_AGENT
:
589 case DH6OPT_LQ_CLIENT_LINK
:
594 tp
= (u_char
*)(dh6o
+ 1);
595 for (i
= 0; i
< optlen
; i
+= 16)
596 printf(" %s", ip6addr_string(&tp
[i
]));
599 case DH6OPT_STATUS_CODE
:
604 tp
= (u_char
*)(dh6o
+ 1);
605 printf(" %s)", dhcp6stcode(EXTRACT_16BITS(&tp
[0])));
613 tp
= (u_char
*)(dh6o
+ 1);
614 printf(" IAID:%u T1:%u T2:%u",
615 EXTRACT_32BITS(&tp
[0]),
616 EXTRACT_32BITS(&tp
[4]),
617 EXTRACT_32BITS(&tp
[8]));
619 /* there are sub-options */
620 dhcp6opt_print(tp
+ 12, tp
+ optlen
);
629 tp
= (u_char
*)(dh6o
+ 1);
630 printf(" IAID:%u", EXTRACT_32BITS(tp
));
632 /* there are sub-options */
633 dhcp6opt_print(tp
+ 4, tp
+ optlen
);
637 case DH6OPT_IA_PD_PREFIX
:
642 tp
= (u_char
*)(dh6o
+ 1);
643 printf(" %s/%d", ip6addr_string(&tp
[9]), tp
[8]);
644 printf(" pltime:%u vltime:%u",
645 EXTRACT_32BITS(&tp
[0]),
646 EXTRACT_32BITS(&tp
[4]));
648 /* there are sub-options */
649 dhcp6opt_print(tp
+ 25, tp
+ optlen
);
653 case DH6OPT_LIFETIME
:
654 case DH6OPT_CLT_TIME
:
659 tp
= (u_char
*)(dh6o
+ 1);
660 printf(" %d)", EXTRACT_32BITS(tp
));
662 case DH6OPT_REMOTE_ID
:
667 tp
= (u_char
*)(dh6o
+ 1);
668 printf(" %d ", EXTRACT_32BITS(tp
));
670 * Print hex dump first 10 characters.
672 for (i
= 4; i
< optlen
&& i
< 14; i
++)
673 printf("%02x", tp
[i
]);
676 case DH6OPT_LQ_QUERY
:
681 tp
= (u_char
*)(dh6o
+ 1);
684 printf(" by-address");
687 printf(" by-clientID");
690 printf(" type_%d", (int)*tp
);
693 printf(" %s", ip6addr_string(&tp
[1]));
695 /* there are query-options */
696 dhcp6opt_print(tp
+ 17, tp
+ optlen
);
700 case DH6OPT_CLIENT_DATA
:
701 tp
= (u_char
*)(dh6o
+ 1);
703 /* there are encapsulated options */
704 dhcp6opt_print(tp
, tp
+ optlen
);
708 case DH6OPT_LQ_RELAY_DATA
:
713 tp
= (u_char
*)(dh6o
+ 1);
714 printf(" %s ", ip6addr_string(&tp
[0]));
716 * Print hex dump first 10 characters.
718 for (i
= 16; i
< optlen
&& i
< 26; i
++)
719 printf("%02x", tp
[i
]);
722 case DH6OPT_AFTR_NAME
:
727 tp
= (u_char
*)(dh6o
+ 1);
730 /* Encoding is described in section 3.1 of RFC 1035 */
731 while (remain_len
&& *tp
) {
733 if (label_len
< remain_len
- 1) {
734 printf("%.*s", label_len
, tp
);
736 remain_len
-= (label_len
+ 1);
750 cp
+= sizeof(*dh6o
) + optlen
;
755 printf("[|dhcp6ext]");
759 * Print dhcp6 packets
762 dhcp6_print(const u_char
*cp
, u_int length
)
765 struct dhcp6_relay
*dh6relay
;
772 ep
= (u_char
*)snapend
;
773 if (cp
+ length
< ep
)
776 dh6
= (struct dhcp6
*)cp
;
777 dh6relay
= (struct dhcp6_relay
*)cp
;
778 TCHECK(dh6
->dh6_xid
);
779 switch (dh6
->dh6_msgtype
) {
807 case DH6_RECONFIGURE
:
808 name
= "reconfigure";
816 case DH6_RELAY_REPLY
:
823 name
= "leasequery-reply";
833 else if (dh6
->dh6_msgtype
!= DH6_RELAY_FORW
&&
834 dh6
->dh6_msgtype
!= DH6_RELAY_REPLY
) {
835 printf(" msgtype-%u", dh6
->dh6_msgtype
);
840 /* XXX relay agent messages have to be handled differently */
843 printf(" %s (", name
); /*)*/
845 printf(" msgtype-%u (", dh6
->dh6_msgtype
); /*)*/
846 if (dh6
->dh6_msgtype
!= DH6_RELAY_FORW
&&
847 dh6
->dh6_msgtype
!= DH6_RELAY_REPLY
) {
848 printf("xid=%x", EXTRACT_32BITS(&dh6
->dh6_xid
) & DH6_XIDMASK
);
849 extp
= (u_char
*)(dh6
+ 1);
850 dhcp6opt_print(extp
, ep
);
851 } else { /* relay messages */
852 struct in6_addr addr6
;
854 TCHECK(dh6relay
->dh6relay_peeraddr
);
856 memcpy(&addr6
, dh6relay
->dh6relay_linkaddr
, sizeof (addr6
));
857 printf("linkaddr=%s", ip6addr_string(&addr6
));
859 memcpy(&addr6
, dh6relay
->dh6relay_peeraddr
, sizeof (addr6
));
860 printf(" peeraddr=%s", ip6addr_string(&addr6
));
862 dhcp6opt_print((u_char
*)(dh6relay
+ 1), ep
);