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:
42 static const char rcsid
[] _U_
=
43 "@(#) $Header: /tcpdump/master/tcpdump/print-dhcp6.c,v 1.37 2008-02-06 10:26:09 guy Exp $";
50 #include <tcpdump-stdinc.h>
55 #include "interface.h"
56 #include "addrtoname.h"
60 #define DHCP6_DURATITION_INFINITE 0xffffffff
63 #define DH6ERR_FAILURE 16
64 #define DH6ERR_AUTHFAIL 17
65 #define DH6ERR_POORLYFORMED 18
66 #define DH6ERR_UNAVAIL 19
67 #define DH6ERR_OPTUNAVAIL 20
71 #define DH6_ADVERTISE 2
79 #define DH6_RECONFIGURE 10
80 #define DH6_INFORM_REQ 11
81 #define DH6_RELAY_FORW 12
82 #define DH6_RELAY_REPLY 13
83 #define DH6_LEASEQUERY 14
84 #define DH6_LQ_REPLY 15
86 /* DHCP6 base packet format */
94 #define dh6_msgtype dh6_msgtypexid.m
95 #define dh6_xid dh6_msgtypexid.x
96 #define DH6_XIDMASK 0x00ffffff
98 /* DHCPv6 relay messages */
100 u_int8_t dh6relay_msgtype
;
101 u_int8_t dh6relay_hcnt
;
102 u_int8_t dh6relay_linkaddr
[16]; /* XXX: badly aligned */
103 u_int8_t dh6relay_peeraddr
[16];
108 #define DH6OPT_CLIENTID 1
109 #define DH6OPT_SERVERID 2
110 #define DH6OPT_IA_NA 3
111 #define DH6OPT_IA_TA 4
112 #define DH6OPT_IA_ADDR 5
114 #define DH6OPT_PREFERENCE 7
115 # define DH6OPT_PREF_MAX 255
116 #define DH6OPT_ELAPSED_TIME 8
117 #define DH6OPT_RELAY_MSG 9
118 /*#define DH6OPT_SERVER_MSG 10 deprecated */
119 #define DH6OPT_AUTH 11
120 # define DH6OPT_AUTHPROTO_DELAYED 2
121 # define DH6OPT_AUTHPROTO_RECONFIG 3
122 # define DH6OPT_AUTHALG_HMACMD5 1
123 # define DH6OPT_AUTHRDM_MONOCOUNTER 0
124 # define DH6OPT_AUTHRECONFIG_KEY 1
125 # define DH6OPT_AUTHRECONFIG_HMACMD5 2
126 #define DH6OPT_UNICAST 12
127 #define DH6OPT_STATUS_CODE 13
128 # define DH6OPT_STCODE_SUCCESS 0
129 # define DH6OPT_STCODE_UNSPECFAIL 1
130 # define DH6OPT_STCODE_NOADDRAVAIL 2
131 # define DH6OPT_STCODE_NOBINDING 3
132 # define DH6OPT_STCODE_NOTONLINK 4
133 # define DH6OPT_STCODE_USEMULTICAST 5
134 # define DH6OPT_STCODE_NOPREFIXAVAIL 6
135 # define DH6OPT_STCODE_UNKNOWNQUERYTYPE 7
136 # define DH6OPT_STCODE_MALFORMEDQUERY 8
137 # define DH6OPT_STCODE_NOTCONFIGURED 9
138 # define DH6OPT_STCODE_NOTALLOWED 10
139 #define DH6OPT_RAPID_COMMIT 14
140 #define DH6OPT_USER_CLASS 15
141 #define DH6OPT_VENDOR_CLASS 16
142 #define DH6OPT_VENDOR_OPTS 17
143 #define DH6OPT_INTERFACE_ID 18
144 #define DH6OPT_RECONF_MSG 19
145 #define DH6OPT_RECONF_ACCEPT 20
146 #define DH6OPT_SIP_SERVER_D 21
147 #define DH6OPT_SIP_SERVER_A 22
148 #define DH6OPT_DNS 23
149 #define DH6OPT_DNSNAME 24
150 #define DH6OPT_IA_PD 25
151 #define DH6OPT_IA_PD_PREFIX 26
152 #define DH6OPT_NIS_SERVERS 27
153 #define DH6OPT_NISP_SERVERS 28
154 #define DH6OPT_NIS_NAME 29
155 #define DH6OPT_NISP_NAME 30
156 #define DH6OPT_NTP_SERVERS 31
157 #define DH6OPT_LIFETIME 32
158 #define DH6OPT_BCMCS_SERVER_D 33
159 #define DH6OPT_BCMCS_SERVER_A 34
160 #define DH6OPT_GEOCONF_CIVIC 36
161 #define DH6OPT_REMOTE_ID 37
162 #define DH6OPT_SUBSCRIBER_ID 38
163 #define DH6OPT_CLIENT_FQDN 39
164 #define DH6OPT_PANA_AGENT 40
165 #define DH6OPT_NEW_POSIX_TIMEZONE 41
166 #define DH6OPT_NEW_TZDB_TIMEZONE 42
167 #define DH6OPT_ERO 43
168 #define DH6OPT_LQ_QUERY 44
169 #define DH6OPT_CLIENT_DATA 45
170 #define DH6OPT_CLT_TIME 46
171 #define DH6OPT_LQ_RELAY_DATA 47
172 #define DH6OPT_LQ_CLIENT_LINK 48
175 u_int16_t dh6opt_type
;
176 u_int16_t dh6opt_len
;
177 /* type-dependent data follows */
181 dhcp6opt_name(int type
)
183 static char genstr
[sizeof("opt_65535") + 1]; /* XXX thread unsafe */
186 return "INVALID-option";
189 case DH6OPT_CLIENTID
:
191 case DH6OPT_SERVERID
:
200 return "option-request";
201 case DH6OPT_PREFERENCE
:
203 case DH6OPT_ELAPSED_TIME
:
204 return "elapsed-time";
205 case DH6OPT_RELAY_MSG
:
206 return "relay-message";
208 return "authentication";
210 return "server-unicast";
211 case DH6OPT_STATUS_CODE
:
212 return "status-code";
213 case DH6OPT_RAPID_COMMIT
:
214 return "rapid-commit";
215 case DH6OPT_USER_CLASS
:
217 case DH6OPT_VENDOR_CLASS
:
218 return "vendor-class";
219 case DH6OPT_VENDOR_OPTS
:
220 return "vendor-specific-info";
221 case DH6OPT_INTERFACE_ID
:
222 return "interface-ID";
223 case DH6OPT_RECONF_MSG
:
224 return "reconfigure-message";
225 case DH6OPT_RECONF_ACCEPT
:
226 return "reconfigure-accept";
227 case DH6OPT_SIP_SERVER_D
:
228 return "SIP-servers-domain";
229 case DH6OPT_SIP_SERVER_A
:
230 return "SIP-servers-address";
234 return "DNS-search-list";
237 case DH6OPT_IA_PD_PREFIX
:
238 return "IA_PD-prefix";
239 case DH6OPT_NTP_SERVERS
:
241 case DH6OPT_LIFETIME
:
243 case DH6OPT_NIS_SERVERS
:
245 case DH6OPT_NISP_SERVERS
:
246 return "NIS+-server";
247 case DH6OPT_NIS_NAME
:
248 return "NIS-domain-name";
249 case DH6OPT_NISP_NAME
:
250 return "NIS+-domain-name";
251 case DH6OPT_BCMCS_SERVER_D
:
252 return "BCMCS-domain-name";
253 case DH6OPT_BCMCS_SERVER_A
:
254 return "BCMCS-server";
255 case DH6OPT_GEOCONF_CIVIC
:
256 return "Geoconf-Civic";
257 case DH6OPT_REMOTE_ID
:
259 case DH6OPT_SUBSCRIBER_ID
:
260 return "Subscriber-ID";
261 case DH6OPT_CLIENT_FQDN
:
262 return "Client-FQDN";
263 case DH6OPT_PANA_AGENT
:
265 case DH6OPT_NEW_POSIX_TIMEZONE
:
266 return "POSIX-timezone";
267 case DH6OPT_NEW_TZDB_TIMEZONE
:
268 return "POSIX-tz-database";
270 return "Echo-request-option";
271 case DH6OPT_LQ_QUERY
:
272 return "Lease-query";
273 case DH6OPT_CLIENT_DATA
:
274 return "LQ-client-data";
275 case DH6OPT_CLT_TIME
:
277 case DH6OPT_LQ_RELAY_DATA
:
278 return "LQ-relay-data";
279 case DH6OPT_LQ_CLIENT_LINK
:
280 return "LQ-client-link";
282 snprintf(genstr
, sizeof(genstr
), "opt_%d", type
);
288 dhcp6stcode(int code
)
290 static char genstr
[sizeof("code255") + 1]; /* XXX thread unsafe */
293 return "INVALID code";
296 case DH6OPT_STCODE_SUCCESS
:
298 case DH6OPT_STCODE_UNSPECFAIL
:
299 return "unspec failure";
300 case DH6OPT_STCODE_NOADDRAVAIL
:
301 return "no addresses";
302 case DH6OPT_STCODE_NOBINDING
:
304 case DH6OPT_STCODE_NOTONLINK
:
305 return "not on-link";
306 case DH6OPT_STCODE_USEMULTICAST
:
307 return "use multicast";
308 case DH6OPT_STCODE_NOPREFIXAVAIL
:
309 return "no prefixes";
310 case DH6OPT_STCODE_UNKNOWNQUERYTYPE
:
311 return "unknown query type";
312 case DH6OPT_STCODE_MALFORMEDQUERY
:
313 return "malformed query";
314 case DH6OPT_STCODE_NOTCONFIGURED
:
315 return "not configured";
316 case DH6OPT_STCODE_NOTALLOWED
:
317 return "not allowed";
319 snprintf(genstr
, sizeof(genstr
), "code%d", code
);
325 dhcp6opt_print(const u_char
*cp
, const u_char
*ep
)
327 struct dhcp6opt
*dh6o
;
333 u_int authinfolen
, authrealmlen
;
338 if (ep
< cp
+ sizeof(*dh6o
))
340 dh6o
= (struct dhcp6opt
*)cp
;
341 optlen
= EXTRACT_16BITS(&dh6o
->dh6opt_len
);
342 if (ep
< cp
+ sizeof(*dh6o
) + optlen
)
344 opttype
= EXTRACT_16BITS(&dh6o
->dh6opt_type
);
345 printf(" (%s", dhcp6opt_name(opttype
));
347 case DH6OPT_CLIENTID
:
348 case DH6OPT_SERVERID
:
354 tp
= (u_char
*)(dh6o
+ 1);
355 switch (EXTRACT_16BITS(tp
)) {
357 if (optlen
>= 2 + 6) {
358 printf(" hwaddr/time type %u time %u ",
359 EXTRACT_16BITS(&tp
[2]),
360 EXTRACT_32BITS(&tp
[4]));
361 for (i
= 8; i
< optlen
; i
++)
362 printf("%02x", tp
[i
]);
371 if (optlen
>= 2 + 8) {
373 for (i
= 2; i
< 2 + 8; i
++)
374 printf("%02x", tp
[i
]);
383 if (optlen
>= 2 + 2) {
384 printf(" hwaddr type %u ",
385 EXTRACT_16BITS(&tp
[2]));
386 for (i
= 4; i
< optlen
; i
++)
387 printf("%02x", tp
[i
]);
396 printf(" type %d)", EXTRACT_16BITS(tp
));
406 tp
= (u_char
*)(dh6o
+ 1);
407 printf(" %s", ip6addr_string(&tp
[0]));
408 printf(" pltime:%u vltime:%u",
409 EXTRACT_32BITS(&tp
[16]),
410 EXTRACT_32BITS(&tp
[20]));
412 /* there are sub-options */
413 dhcp6opt_print(tp
+ 24, tp
+ 24 + optlen
);
423 tp
= (u_char
*)(dh6o
+ 1);
424 for (i
= 0; i
< optlen
; i
+= 2) {
426 dhcp6opt_name(EXTRACT_16BITS(&tp
[i
])));
430 case DH6OPT_PREFERENCE
:
435 tp
= (u_char
*)(dh6o
+ 1);
438 case DH6OPT_ELAPSED_TIME
:
443 tp
= (u_char
*)(dh6o
+ 1);
444 printf(" %d)", EXTRACT_16BITS(tp
));
446 case DH6OPT_RELAY_MSG
:
448 tp
= (u_char
*)(dh6o
+ 1);
449 dhcp6_print(tp
, optlen
);
457 tp
= (u_char
*)(dh6o
+ 1);
459 switch (auth_proto
) {
460 case DH6OPT_AUTHPROTO_DELAYED
:
461 printf(" proto: delayed");
463 case DH6OPT_AUTHPROTO_RECONFIG
:
464 printf(" proto: reconfigure");
467 printf(" proto: %d", auth_proto
);
472 case DH6OPT_AUTHALG_HMACMD5
:
473 /* XXX: may depend on the protocol */
474 printf(", alg: HMAC-MD5");
477 printf(", alg: %d", *tp
);
482 case DH6OPT_AUTHRDM_MONOCOUNTER
:
483 printf(", RDM: mono");
486 printf(", RDM: %d", *tp
);
491 for (i
= 0; i
< 4; i
++, tp
+= 2)
492 printf(" %04x", EXTRACT_16BITS(tp
));
494 /* protocol dependent part */
495 authinfolen
= optlen
- 11;
496 switch (auth_proto
) {
497 case DH6OPT_AUTHPROTO_DELAYED
:
498 if (authinfolen
== 0)
500 if (authinfolen
< 20) {
504 authrealmlen
= authinfolen
- 20;
505 if (authrealmlen
> 0) {
508 for (i
= 0; i
< authrealmlen
; i
++, tp
++)
510 printf(", key ID: %08x", EXTRACT_32BITS(tp
));
512 printf(", HMAC-MD5:");
513 for (i
= 0; i
< 4; i
++, tp
+= 4)
514 printf(" %08x", EXTRACT_32BITS(tp
));
516 case DH6OPT_AUTHPROTO_RECONFIG
:
517 if (authinfolen
!= 17) {
522 case DH6OPT_AUTHRECONFIG_KEY
:
523 printf(" reconfig-key");
525 case DH6OPT_AUTHRECONFIG_HMACMD5
:
526 printf(" type: HMAC-MD5");
533 for (i
= 0; i
< 4; i
++, tp
+= 4)
534 printf(" %08x", EXTRACT_32BITS(tp
));
543 case DH6OPT_RAPID_COMMIT
: /* nothing todo */
546 case DH6OPT_INTERFACE_ID
:
547 case DH6OPT_SUBSCRIBER_ID
:
549 * Since we cannot predict the encoding, print hex dump
550 * at most 10 characters.
552 tp
= (u_char
*)(dh6o
+ 1);
554 for (i
= 0; i
< optlen
&& i
< 10; i
++)
555 printf("%02x", tp
[i
]);
558 case DH6OPT_RECONF_MSG
:
559 tp
= (u_char
*)(dh6o
+ 1);
562 printf(" for renew)");
565 printf(" for inf-req)");
568 printf(" for ?\?\?(%02x))", *tp
);
572 case DH6OPT_RECONF_ACCEPT
: /* nothing todo */
575 case DH6OPT_SIP_SERVER_A
:
577 case DH6OPT_NTP_SERVERS
:
578 case DH6OPT_NIS_SERVERS
:
579 case DH6OPT_NISP_SERVERS
:
580 case DH6OPT_BCMCS_SERVER_A
:
581 case DH6OPT_PANA_AGENT
:
582 case DH6OPT_LQ_CLIENT_LINK
:
587 tp
= (u_char
*)(dh6o
+ 1);
588 for (i
= 0; i
< optlen
; i
+= 16)
589 printf(" %s", ip6addr_string(&tp
[i
]));
592 case DH6OPT_STATUS_CODE
:
597 tp
= (u_char
*)(dh6o
+ 1);
598 printf(" %s)", dhcp6stcode(EXTRACT_16BITS(&tp
[0])));
606 tp
= (u_char
*)(dh6o
+ 1);
607 printf(" IAID:%u T1:%u T2:%u",
608 EXTRACT_32BITS(&tp
[0]),
609 EXTRACT_32BITS(&tp
[4]),
610 EXTRACT_32BITS(&tp
[8]));
612 /* there are sub-options */
613 dhcp6opt_print(tp
+ 12, tp
+ 12 + optlen
);
622 tp
= (u_char
*)(dh6o
+ 1);
623 printf(" IAID:%u", EXTRACT_32BITS(tp
));
625 /* there are sub-options */
626 dhcp6opt_print(tp
+ 4, tp
+ 4 + optlen
);
630 case DH6OPT_IA_PD_PREFIX
:
635 tp
= (u_char
*)(dh6o
+ 1);
636 printf(" %s/%d", ip6addr_string(&tp
[9]), tp
[8]);
637 printf(" pltime:%u vltime:%u",
638 EXTRACT_32BITS(&tp
[0]),
639 EXTRACT_32BITS(&tp
[4]));
641 /* there are sub-options */
642 dhcp6opt_print(tp
+ 25, tp
+ 25 + optlen
);
646 case DH6OPT_LIFETIME
:
647 case DH6OPT_CLT_TIME
:
652 tp
= (u_char
*)(dh6o
+ 1);
653 printf(" %d)", EXTRACT_32BITS(tp
));
655 case DH6OPT_REMOTE_ID
:
660 tp
= (u_char
*)(dh6o
+ 1);
661 printf(" %d ", EXTRACT_32BITS(tp
));
663 * Print hex dump first 10 characters.
665 for (i
= 4; i
< optlen
&& i
< 14; i
++)
666 printf("%02x", tp
[i
]);
669 case DH6OPT_LQ_QUERY
:
674 tp
= (u_char
*)(dh6o
+ 1);
677 printf(" by-address");
680 printf(" by-clientID");
683 printf(" type_%d", (int)*tp
);
686 printf(" %s", ip6addr_string(&tp
[1]));
688 /* there are query-options */
689 dhcp6opt_print(tp
+ 17, tp
+ optlen
);
693 case DH6OPT_CLIENT_DATA
:
694 tp
= (u_char
*)(dh6o
+ 1);
696 /* there are encapsulated options */
697 dhcp6opt_print(tp
, tp
+ optlen
);
701 case DH6OPT_LQ_RELAY_DATA
:
706 tp
= (u_char
*)(dh6o
+ 1);
707 printf(" %s ", ip6addr_string(&tp
[0]));
709 * Print hex dump first 10 characters.
711 for (i
= 16; i
< optlen
&& i
< 26; i
++)
712 printf("%02x", tp
[i
]);
720 cp
+= sizeof(*dh6o
) + optlen
;
725 printf("[|dhcp6ext]");
729 * Print dhcp6 packets
732 dhcp6_print(const u_char
*cp
, u_int length
)
735 struct dhcp6_relay
*dh6relay
;
742 ep
= (u_char
*)snapend
;
743 if (cp
+ length
< ep
)
746 dh6
= (struct dhcp6
*)cp
;
747 dh6relay
= (struct dhcp6_relay
*)cp
;
748 TCHECK(dh6
->dh6_xid
);
749 switch (dh6
->dh6_msgtype
) {
777 case DH6_RECONFIGURE
:
778 name
= "reconfigure";
786 case DH6_RELAY_REPLY
:
793 name
= "leasequery-reply";
803 else if (dh6
->dh6_msgtype
!= DH6_RELAY_FORW
&&
804 dh6
->dh6_msgtype
!= DH6_RELAY_REPLY
) {
805 printf(" msgtype-%u", dh6
->dh6_msgtype
);
810 /* XXX relay agent messages have to be handled differently */
813 printf(" %s (", name
); /*)*/
815 printf(" msgtype-%u (", dh6
->dh6_msgtype
); /*)*/
816 if (dh6
->dh6_msgtype
!= DH6_RELAY_FORW
&&
817 dh6
->dh6_msgtype
!= DH6_RELAY_REPLY
) {
818 printf("xid=%x", EXTRACT_32BITS(&dh6
->dh6_xid
) & DH6_XIDMASK
);
819 extp
= (u_char
*)(dh6
+ 1);
820 dhcp6opt_print(extp
, ep
);
821 } else { /* relay messages */
822 struct in6_addr addr6
;
824 TCHECK(dh6relay
->dh6relay_peeraddr
);
826 memcpy(&addr6
, dh6relay
->dh6relay_linkaddr
, sizeof (addr6
));
827 printf("linkaddr=%s", ip6addr_string(&addr6
));
829 memcpy(&addr6
, dh6relay
->dh6relay_peeraddr
, sizeof (addr6
));
830 printf(" peeraddr=%s", ip6addr_string(&addr6
));
832 dhcp6opt_print((u_char
*)(dh6relay
+ 1), ep
);