blob: 53b96ef954c98478878dfaa489032b5dc1489dfd [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (C) 1998 and 1999 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29/*
30 * RFC3315: DHCPv6
Elliott Hughes892a68b2015-10-19 14:43:53 -070031 * supported DHCPv6 options:
JP Abgrall53f17a92014-02-12 14:02:41 -080032 * 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 * RFC5908: Network Time Protocol (NTP) Server Option for DHCPv6
40 * RFC6334: Dual-Stack Lite option,
The Android Open Source Project2949f582009-03-03 19:30:46 -080041 */
42
Elliott Hughes892a68b2015-10-19 14:43:53 -070043#define NETDISSECT_REWORKED
The Android Open Source Project2949f582009-03-03 19:30:46 -080044#ifdef HAVE_CONFIG_H
45#include "config.h"
46#endif
47
48#include <tcpdump-stdinc.h>
49
50#include <stdio.h>
51#include <string.h>
52
53#include "interface.h"
54#include "addrtoname.h"
55#include "extract.h"
56
57/* lease duration */
Elliott Hughes892a68b2015-10-19 14:43:53 -070058#define DHCP6_DURATION_INFINITE 0xffffffff
The Android Open Source Project2949f582009-03-03 19:30:46 -080059
60/* Error Values */
61#define DH6ERR_FAILURE 16
62#define DH6ERR_AUTHFAIL 17
63#define DH6ERR_POORLYFORMED 18
64#define DH6ERR_UNAVAIL 19
65#define DH6ERR_OPTUNAVAIL 20
66
67/* Message type */
68#define DH6_SOLICIT 1
69#define DH6_ADVERTISE 2
70#define DH6_REQUEST 3
71#define DH6_CONFIRM 4
72#define DH6_RENEW 5
73#define DH6_REBIND 6
74#define DH6_REPLY 7
75#define DH6_RELEASE 8
76#define DH6_DECLINE 9
77#define DH6_RECONFIGURE 10
78#define DH6_INFORM_REQ 11
79#define DH6_RELAY_FORW 12
80#define DH6_RELAY_REPLY 13
JP Abgrall53f17a92014-02-12 14:02:41 -080081#define DH6_LEASEQUERY 14
82#define DH6_LQ_REPLY 15
The Android Open Source Project2949f582009-03-03 19:30:46 -080083
Elliott Hughes892a68b2015-10-19 14:43:53 -070084static const struct tok dh6_msgtype_str[] = {
85 { DH6_SOLICIT, "solicit" },
86 { DH6_ADVERTISE, "advertise" },
87 { DH6_REQUEST, "request" },
88 { DH6_CONFIRM, "confirm" },
89 { DH6_RENEW, "renew" },
90 { DH6_REBIND, "rebind" },
91 { DH6_REPLY, "reply" },
92 { DH6_RELEASE, "release" },
93 { DH6_DECLINE, "decline" },
94 { DH6_RECONFIGURE, "reconfigure" },
95 { DH6_INFORM_REQ, "inf-req" },
96 { DH6_RELAY_FORW, "relay-fwd" },
97 { DH6_RELAY_REPLY, "relay-reply" },
98 { DH6_LEASEQUERY, "leasequery" },
99 { DH6_LQ_REPLY, "leasequery-reply" },
100 { 0, NULL }
101};
102
The Android Open Source Project2949f582009-03-03 19:30:46 -0800103/* DHCP6 base packet format */
104struct dhcp6 {
105 union {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700106 uint8_t m;
107 uint32_t x;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800108 } dh6_msgtypexid;
109 /* options follow */
110};
111#define dh6_msgtype dh6_msgtypexid.m
112#define dh6_xid dh6_msgtypexid.x
113#define DH6_XIDMASK 0x00ffffff
114
115/* DHCPv6 relay messages */
116struct dhcp6_relay {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700117 uint8_t dh6relay_msgtype;
118 uint8_t dh6relay_hcnt;
119 uint8_t dh6relay_linkaddr[16]; /* XXX: badly aligned */
120 uint8_t dh6relay_peeraddr[16];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800121 /* options follow */
122};
123
124/* options */
125#define DH6OPT_CLIENTID 1
126#define DH6OPT_SERVERID 2
127#define DH6OPT_IA_NA 3
128#define DH6OPT_IA_TA 4
129#define DH6OPT_IA_ADDR 5
130#define DH6OPT_ORO 6
131#define DH6OPT_PREFERENCE 7
132# define DH6OPT_PREF_MAX 255
133#define DH6OPT_ELAPSED_TIME 8
134#define DH6OPT_RELAY_MSG 9
135/*#define DH6OPT_SERVER_MSG 10 deprecated */
136#define DH6OPT_AUTH 11
137# define DH6OPT_AUTHPROTO_DELAYED 2
138# define DH6OPT_AUTHPROTO_RECONFIG 3
139# define DH6OPT_AUTHALG_HMACMD5 1
140# define DH6OPT_AUTHRDM_MONOCOUNTER 0
141# define DH6OPT_AUTHRECONFIG_KEY 1
142# define DH6OPT_AUTHRECONFIG_HMACMD5 2
143#define DH6OPT_UNICAST 12
144#define DH6OPT_STATUS_CODE 13
145# define DH6OPT_STCODE_SUCCESS 0
146# define DH6OPT_STCODE_UNSPECFAIL 1
147# define DH6OPT_STCODE_NOADDRAVAIL 2
148# define DH6OPT_STCODE_NOBINDING 3
149# define DH6OPT_STCODE_NOTONLINK 4
150# define DH6OPT_STCODE_USEMULTICAST 5
151# define DH6OPT_STCODE_NOPREFIXAVAIL 6
JP Abgrall53f17a92014-02-12 14:02:41 -0800152# define DH6OPT_STCODE_UNKNOWNQUERYTYPE 7
153# define DH6OPT_STCODE_MALFORMEDQUERY 8
154# define DH6OPT_STCODE_NOTCONFIGURED 9
155# define DH6OPT_STCODE_NOTALLOWED 10
The Android Open Source Project2949f582009-03-03 19:30:46 -0800156#define DH6OPT_RAPID_COMMIT 14
157#define DH6OPT_USER_CLASS 15
158#define DH6OPT_VENDOR_CLASS 16
159#define DH6OPT_VENDOR_OPTS 17
160#define DH6OPT_INTERFACE_ID 18
161#define DH6OPT_RECONF_MSG 19
162#define DH6OPT_RECONF_ACCEPT 20
163#define DH6OPT_SIP_SERVER_D 21
164#define DH6OPT_SIP_SERVER_A 22
JP Abgrall53f17a92014-02-12 14:02:41 -0800165#define DH6OPT_DNS_SERVERS 23
166#define DH6OPT_DOMAIN_LIST 24
The Android Open Source Project2949f582009-03-03 19:30:46 -0800167#define DH6OPT_IA_PD 25
168#define DH6OPT_IA_PD_PREFIX 26
169#define DH6OPT_NIS_SERVERS 27
170#define DH6OPT_NISP_SERVERS 28
171#define DH6OPT_NIS_NAME 29
172#define DH6OPT_NISP_NAME 30
JP Abgrall53f17a92014-02-12 14:02:41 -0800173#define DH6OPT_SNTP_SERVERS 31
The Android Open Source Project2949f582009-03-03 19:30:46 -0800174#define DH6OPT_LIFETIME 32
175#define DH6OPT_BCMCS_SERVER_D 33
176#define DH6OPT_BCMCS_SERVER_A 34
177#define DH6OPT_GEOCONF_CIVIC 36
178#define DH6OPT_REMOTE_ID 37
179#define DH6OPT_SUBSCRIBER_ID 38
180#define DH6OPT_CLIENT_FQDN 39
JP Abgrall53f17a92014-02-12 14:02:41 -0800181#define DH6OPT_PANA_AGENT 40
182#define DH6OPT_NEW_POSIX_TIMEZONE 41
183#define DH6OPT_NEW_TZDB_TIMEZONE 42
184#define DH6OPT_ERO 43
185#define DH6OPT_LQ_QUERY 44
186#define DH6OPT_CLIENT_DATA 45
187#define DH6OPT_CLT_TIME 46
188#define DH6OPT_LQ_RELAY_DATA 47
189#define DH6OPT_LQ_CLIENT_LINK 48
190#define DH6OPT_NTP_SERVER 56
191# define DH6OPT_NTP_SUBOPTION_SRV_ADDR 1
192# define DH6OPT_NTP_SUBOPTION_MC_ADDR 2
193# define DH6OPT_NTP_SUBOPTION_SRV_FQDN 3
194#define DH6OPT_AFTR_NAME 64
The Android Open Source Project2949f582009-03-03 19:30:46 -0800195
Elliott Hughes892a68b2015-10-19 14:43:53 -0700196static 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_AFTR_NAME, "AFTR-Name" },
245 { 0, NULL }
246};
247
248static const struct tok dh6opt_stcode_str[] = {
249 { DH6OPT_STCODE_SUCCESS, "success" },
250 { DH6OPT_STCODE_UNSPECFAIL, "unspec failure" },
251 { DH6OPT_STCODE_NOADDRAVAIL, "no addresses" },
252 { DH6OPT_STCODE_NOBINDING, "no binding" },
253 { DH6OPT_STCODE_NOTONLINK, "not on-link" },
254 { DH6OPT_STCODE_USEMULTICAST, "use multicast" },
255 { DH6OPT_STCODE_NOPREFIXAVAIL, "no prefixes" },
256 { DH6OPT_STCODE_UNKNOWNQUERYTYPE, "unknown query type" },
257 { DH6OPT_STCODE_MALFORMEDQUERY, "malformed query" },
258 { DH6OPT_STCODE_NOTCONFIGURED, "not configured" },
259 { DH6OPT_STCODE_NOTALLOWED, "not allowed" },
260 { 0, NULL }
261};
262
The Android Open Source Project2949f582009-03-03 19:30:46 -0800263struct dhcp6opt {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700264 uint16_t dh6opt_type;
265 uint16_t dh6opt_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800266 /* type-dependent data follows */
267};
268
The Android Open Source Project2949f582009-03-03 19:30:46 -0800269static const char *
Elliott Hughes892a68b2015-10-19 14:43:53 -0700270dhcp6stcode(const uint16_t code)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800271{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700272 return code > 255 ? "INVALID code" : tok2str(dh6opt_stcode_str, "code%u", code);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800273}
274
275static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700276dhcp6opt_print(netdissect_options *ndo,
277 const u_char *cp, const u_char *ep)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800278{
JP Abgrall53f17a92014-02-12 14:02:41 -0800279 const struct dhcp6opt *dh6o;
280 const u_char *tp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800281 size_t i;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700282 uint16_t opttype;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800283 size_t optlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700284 uint8_t auth_proto;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800285 u_int authinfolen, authrealmlen;
JP Abgrall53f17a92014-02-12 14:02:41 -0800286 int remain_len; /* Length of remaining options */
287 int label_len; /* Label length */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700288 uint16_t subopt_code;
289 uint16_t subopt_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800290
291 if (cp == ep)
292 return;
293 while (cp < ep) {
294 if (ep < cp + sizeof(*dh6o))
295 goto trunc;
296 dh6o = (struct dhcp6opt *)cp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700297 ND_TCHECK(*dh6o);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298 optlen = EXTRACT_16BITS(&dh6o->dh6opt_len);
299 if (ep < cp + sizeof(*dh6o) + optlen)
300 goto trunc;
301 opttype = EXTRACT_16BITS(&dh6o->dh6opt_type);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700302 ND_PRINT((ndo, " (%s", tok2str(dh6opt_str, "opt_%u", opttype)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303 switch (opttype) {
304 case DH6OPT_CLIENTID:
305 case DH6OPT_SERVERID:
306 if (optlen < 2) {
307 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800309 break;
310 }
311 tp = (u_char *)(dh6o + 1);
312 switch (EXTRACT_16BITS(tp)) {
313 case 1:
314 if (optlen >= 2 + 6) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315 ND_PRINT((ndo, " hwaddr/time type %u time %u ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800316 EXTRACT_16BITS(&tp[2]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700317 EXTRACT_32BITS(&tp[4])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800318 for (i = 8; i < optlen; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700319 ND_PRINT((ndo, "%02x", tp[i]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800320 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700321 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800322 } else {
323 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700324 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800325 }
326 break;
327 case 2:
328 if (optlen >= 2 + 8) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700329 ND_PRINT((ndo, " vid "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800330 for (i = 2; i < 2 + 8; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700331 ND_PRINT((ndo, "%02x", tp[i]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700333 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800334 } else {
335 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700336 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800337 }
338 break;
339 case 3:
340 if (optlen >= 2 + 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700341 ND_PRINT((ndo, " hwaddr type %u ",
342 EXTRACT_16BITS(&tp[2])));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800343 for (i = 4; i < optlen; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700344 ND_PRINT((ndo, "%02x", tp[i]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800345 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700346 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800347 } else {
348 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700349 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800350 }
351 break;
352 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700353 ND_PRINT((ndo, " type %d)", EXTRACT_16BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800354 break;
355 }
356 break;
357 case DH6OPT_IA_ADDR:
JP Abgrall53f17a92014-02-12 14:02:41 -0800358 if (optlen < 24) {
359 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700360 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800361 break;
362 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800363 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700364 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[0])));
365 ND_PRINT((ndo, " pltime:%u vltime:%u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800366 EXTRACT_32BITS(&tp[16]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700367 EXTRACT_32BITS(&tp[20])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800368 if (optlen > 24) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800369 /* there are sub-options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700370 dhcp6opt_print(ndo, tp + 24, tp + optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800371 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700372 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800373 break;
374 case DH6OPT_ORO:
JP Abgrall53f17a92014-02-12 14:02:41 -0800375 case DH6OPT_ERO:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800376 if (optlen % 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700377 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800378 break;
379 }
380 tp = (u_char *)(dh6o + 1);
381 for (i = 0; i < optlen; i += 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700382 ND_PRINT((ndo, " %s",
383 tok2str(dh6opt_str, "opt_%u", EXTRACT_16BITS(&tp[i]))));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800384 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700385 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800386 break;
387 case DH6OPT_PREFERENCE:
388 if (optlen != 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700389 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800390 break;
391 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800392 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700393 ND_PRINT((ndo, " %d)", *tp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800394 break;
395 case DH6OPT_ELAPSED_TIME:
396 if (optlen != 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700397 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800398 break;
399 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800400 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700401 ND_PRINT((ndo, " %d)", EXTRACT_16BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800402 break;
403 case DH6OPT_RELAY_MSG:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700404 ND_PRINT((ndo, " ("));
JP Abgrall53f17a92014-02-12 14:02:41 -0800405 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700406 dhcp6_print(ndo, tp, optlen);
407 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800408 break;
409 case DH6OPT_AUTH:
JP Abgrall53f17a92014-02-12 14:02:41 -0800410 if (optlen < 11) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700411 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800412 break;
413 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800414 tp = (u_char *)(dh6o + 1);
415 auth_proto = *tp;
416 switch (auth_proto) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800417 case DH6OPT_AUTHPROTO_DELAYED:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700418 ND_PRINT((ndo, " proto: delayed"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800419 break;
420 case DH6OPT_AUTHPROTO_RECONFIG:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700421 ND_PRINT((ndo, " proto: reconfigure"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800422 break;
423 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700424 ND_PRINT((ndo, " proto: %d", auth_proto));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425 break;
426 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800427 tp++;
428 switch (*tp) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800429 case DH6OPT_AUTHALG_HMACMD5:
430 /* XXX: may depend on the protocol */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700431 ND_PRINT((ndo, ", alg: HMAC-MD5"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800432 break;
433 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700434 ND_PRINT((ndo, ", alg: %d", *tp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800435 break;
436 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800437 tp++;
438 switch (*tp) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800439 case DH6OPT_AUTHRDM_MONOCOUNTER:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700440 ND_PRINT((ndo, ", RDM: mono"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800441 break;
442 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700443 ND_PRINT((ndo, ", RDM: %d", *tp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800444 break;
445 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800446 tp++;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700447 ND_PRINT((ndo, ", RD:"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800448 for (i = 0; i < 4; i++, tp += 2)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700449 ND_PRINT((ndo, " %04x", EXTRACT_16BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800450
451 /* protocol dependent part */
JP Abgrall53f17a92014-02-12 14:02:41 -0800452 authinfolen = optlen - 11;
453 switch (auth_proto) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800454 case DH6OPT_AUTHPROTO_DELAYED:
455 if (authinfolen == 0)
456 break;
457 if (authinfolen < 20) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700458 ND_PRINT((ndo, " ??"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800459 break;
460 }
461 authrealmlen = authinfolen - 20;
462 if (authrealmlen > 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700463 ND_PRINT((ndo, ", realm: "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800464 }
465 for (i = 0; i < authrealmlen; i++, tp++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700466 ND_PRINT((ndo, "%02x", *tp));
467 ND_PRINT((ndo, ", key ID: %08x", EXTRACT_32BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800468 tp += 4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700469 ND_PRINT((ndo, ", HMAC-MD5:"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800470 for (i = 0; i < 4; i++, tp+= 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700471 ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800472 break;
473 case DH6OPT_AUTHPROTO_RECONFIG:
474 if (authinfolen != 17) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700475 ND_PRINT((ndo, " ??"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800476 break;
477 }
478 switch (*tp++) {
479 case DH6OPT_AUTHRECONFIG_KEY:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700480 ND_PRINT((ndo, " reconfig-key"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800481 break;
482 case DH6OPT_AUTHRECONFIG_HMACMD5:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700483 ND_PRINT((ndo, " type: HMAC-MD5"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800484 break;
485 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700486 ND_PRINT((ndo, " type: ??"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800487 break;
488 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700489 ND_PRINT((ndo, " value:"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800490 for (i = 0; i < 4; i++, tp+= 4)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700491 ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800492 break;
493 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700494 ND_PRINT((ndo, " ??"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800495 break;
496 }
497
Elliott Hughes892a68b2015-10-19 14:43:53 -0700498 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800499 break;
500 case DH6OPT_RAPID_COMMIT: /* nothing todo */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700501 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800502 break;
503 case DH6OPT_INTERFACE_ID:
JP Abgrall53f17a92014-02-12 14:02:41 -0800504 case DH6OPT_SUBSCRIBER_ID:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800505 /*
506 * Since we cannot predict the encoding, print hex dump
507 * at most 10 characters.
508 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800509 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700510 ND_PRINT((ndo, " "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800511 for (i = 0; i < optlen && i < 10; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700512 ND_PRINT((ndo, "%02x", tp[i]));
513 ND_PRINT((ndo, "...)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800514 break;
515 case DH6OPT_RECONF_MSG:
516 tp = (u_char *)(dh6o + 1);
517 switch (*tp) {
518 case DH6_RENEW:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700519 ND_PRINT((ndo, " for renew)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800520 break;
521 case DH6_INFORM_REQ:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700522 ND_PRINT((ndo, " for inf-req)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800523 break;
524 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700525 ND_PRINT((ndo, " for ?\?\?(%02x))", *tp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800526 break;
527 }
528 break;
529 case DH6OPT_RECONF_ACCEPT: /* nothing todo */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700530 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800531 break;
532 case DH6OPT_SIP_SERVER_A:
JP Abgrall53f17a92014-02-12 14:02:41 -0800533 case DH6OPT_DNS_SERVERS:
534 case DH6OPT_SNTP_SERVERS:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800535 case DH6OPT_NIS_SERVERS:
536 case DH6OPT_NISP_SERVERS:
537 case DH6OPT_BCMCS_SERVER_A:
JP Abgrall53f17a92014-02-12 14:02:41 -0800538 case DH6OPT_PANA_AGENT:
539 case DH6OPT_LQ_CLIENT_LINK:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800540 if (optlen % 16) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700541 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800542 break;
543 }
544 tp = (u_char *)(dh6o + 1);
545 for (i = 0; i < optlen; i += 16)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700546 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[i])));
547 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548 break;
JP Abgrall53f17a92014-02-12 14:02:41 -0800549 case DH6OPT_SIP_SERVER_D:
550 case DH6OPT_DOMAIN_LIST:
551 tp = (u_char *)(dh6o + 1);
552 while (tp < cp + sizeof(*dh6o) + optlen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700553 ND_PRINT((ndo, " "));
554 if ((tp = ns_nprint(ndo, tp, cp + sizeof(*dh6o) + optlen)) == NULL)
JP Abgrall53f17a92014-02-12 14:02:41 -0800555 goto trunc;
556 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700557 ND_PRINT((ndo, ")"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800558 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800559 case DH6OPT_STATUS_CODE:
560 if (optlen < 2) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700561 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800562 break;
563 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800564 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700565 ND_PRINT((ndo, " %s)", dhcp6stcode(EXTRACT_16BITS(&tp[0]))));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800566 break;
567 case DH6OPT_IA_NA:
568 case DH6OPT_IA_PD:
JP Abgrall53f17a92014-02-12 14:02:41 -0800569 if (optlen < 12) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700570 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800571 break;
572 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800573 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700574 ND_PRINT((ndo, " IAID:%u T1:%u T2:%u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800575 EXTRACT_32BITS(&tp[0]),
576 EXTRACT_32BITS(&tp[4]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700577 EXTRACT_32BITS(&tp[8])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800578 if (optlen > 12) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800579 /* there are sub-options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700580 dhcp6opt_print(ndo, tp + 12, tp + optlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800581 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700582 ND_PRINT((ndo, ")"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800583 break;
584 case DH6OPT_IA_TA:
585 if (optlen < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700586 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800587 break;
588 }
589 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700590 ND_PRINT((ndo, " IAID:%u", EXTRACT_32BITS(tp)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800591 if (optlen > 4) {
592 /* there are sub-options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700593 dhcp6opt_print(ndo, tp + 4, tp + optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800594 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700595 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800596 break;
597 case DH6OPT_IA_PD_PREFIX:
JP Abgrall53f17a92014-02-12 14:02:41 -0800598 if (optlen < 25) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700599 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800600 break;
601 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800602 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700603 ND_PRINT((ndo, " %s/%d", ip6addr_string(ndo, &tp[9]), tp[8]));
604 ND_PRINT((ndo, " pltime:%u vltime:%u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800605 EXTRACT_32BITS(&tp[0]),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700606 EXTRACT_32BITS(&tp[4])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800607 if (optlen > 25) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800608 /* there are sub-options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700609 dhcp6opt_print(ndo, tp + 25, tp + optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800610 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700611 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800612 break;
613 case DH6OPT_LIFETIME:
JP Abgrall53f17a92014-02-12 14:02:41 -0800614 case DH6OPT_CLT_TIME:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800615 if (optlen != 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700616 ND_PRINT((ndo, " ?)"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800617 break;
618 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800619 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700620 ND_PRINT((ndo, " %d)", EXTRACT_32BITS(tp)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800621 break;
622 case DH6OPT_REMOTE_ID:
623 if (optlen < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700624 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800625 break;
626 }
627 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700628 ND_PRINT((ndo, " %d ", EXTRACT_32BITS(tp)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800629 /*
630 * Print hex dump first 10 characters.
631 */
632 for (i = 4; i < optlen && i < 14; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700633 ND_PRINT((ndo, "%02x", tp[i]));
634 ND_PRINT((ndo, "...)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800635 break;
636 case DH6OPT_LQ_QUERY:
637 if (optlen < 17) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700638 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800639 break;
640 }
641 tp = (u_char *)(dh6o + 1);
642 switch (*tp) {
643 case 1:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700644 ND_PRINT((ndo, " by-address"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800645 break;
646 case 2:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700647 ND_PRINT((ndo, " by-clientID"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800648 break;
649 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700650 ND_PRINT((ndo, " type_%d", (int)*tp));
JP Abgrall53f17a92014-02-12 14:02:41 -0800651 break;
652 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700653 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[1])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800654 if (optlen > 17) {
655 /* there are query-options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700656 dhcp6opt_print(ndo, tp + 17, tp + optlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800657 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700658 ND_PRINT((ndo, ")"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800659 break;
660 case DH6OPT_CLIENT_DATA:
661 tp = (u_char *)(dh6o + 1);
662 if (optlen > 0) {
663 /* there are encapsulated options */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700664 dhcp6opt_print(ndo, tp, tp + optlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800665 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700666 ND_PRINT((ndo, ")"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800667 break;
668 case DH6OPT_LQ_RELAY_DATA:
669 if (optlen < 16) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700670 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800671 break;
672 }
673 tp = (u_char *)(dh6o + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700674 ND_PRINT((ndo, " %s ", ip6addr_string(ndo, &tp[0])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800675 /*
676 * Print hex dump first 10 characters.
677 */
678 for (i = 16; i < optlen && i < 26; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700679 ND_PRINT((ndo, "%02x", tp[i]));
680 ND_PRINT((ndo, "...)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800681 break;
682 case DH6OPT_NTP_SERVER:
683 if (optlen < 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700684 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800685 break;
686 }
687 tp = (u_char *)(dh6o + 1);
688 while (tp < cp + sizeof(*dh6o) + optlen - 4) {
689 subopt_code = EXTRACT_16BITS(tp);
690 tp += 2;
691 subopt_len = EXTRACT_16BITS(tp);
692 tp += 2;
693 if (tp + subopt_len > cp + sizeof(*dh6o) + optlen)
694 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700695 ND_PRINT((ndo, " subopt:%d", subopt_code));
JP Abgrall53f17a92014-02-12 14:02:41 -0800696 switch (subopt_code) {
697 case DH6OPT_NTP_SUBOPTION_SRV_ADDR:
698 case DH6OPT_NTP_SUBOPTION_MC_ADDR:
699 if (subopt_len != 16) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700700 ND_PRINT((ndo, " ?"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800701 break;
702 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700703 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[0])));
JP Abgrall53f17a92014-02-12 14:02:41 -0800704 break;
705 case DH6OPT_NTP_SUBOPTION_SRV_FQDN:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700706 ND_PRINT((ndo, " "));
707 if (ns_nprint(ndo, tp, tp + subopt_len) == NULL)
JP Abgrall53f17a92014-02-12 14:02:41 -0800708 goto trunc;
709 break;
710 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700711 ND_PRINT((ndo, " ?"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800712 break;
713 }
714 tp += subopt_len;
715 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700716 ND_PRINT((ndo, ")"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800717 break;
718 case DH6OPT_AFTR_NAME:
719 if (optlen < 3) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700720 ND_PRINT((ndo, " ?)"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800721 break;
722 }
723 tp = (u_char *)(dh6o + 1);
724 remain_len = optlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700725 ND_PRINT((ndo, " "));
JP Abgrall53f17a92014-02-12 14:02:41 -0800726 /* Encoding is described in section 3.1 of RFC 1035 */
727 while (remain_len && *tp) {
728 label_len = *tp++;
729 if (label_len < remain_len - 1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700730 ND_PRINT((ndo, "%.*s", label_len, tp));
JP Abgrall53f17a92014-02-12 14:02:41 -0800731 tp += label_len;
732 remain_len -= (label_len + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700733 if(*tp) ND_PRINT((ndo, "."));
JP Abgrall53f17a92014-02-12 14:02:41 -0800734 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700735 ND_PRINT((ndo, " ?"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800736 break;
737 }
738 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700739 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800740 break;
741 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700742 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800743 break;
744 }
745
746 cp += sizeof(*dh6o) + optlen;
747 }
748 return;
749
750trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700751 ND_PRINT((ndo, "[|dhcp6ext]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800752}
753
754/*
755 * Print dhcp6 packets
756 */
757void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700758dhcp6_print(netdissect_options *ndo,
759 const u_char *cp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800760{
761 struct dhcp6 *dh6;
762 struct dhcp6_relay *dh6relay;
763 const u_char *ep;
764 u_char *extp;
765 const char *name;
766
Elliott Hughes892a68b2015-10-19 14:43:53 -0700767 ND_PRINT((ndo, "dhcp6"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800768
Elliott Hughes892a68b2015-10-19 14:43:53 -0700769 ep = (u_char *)ndo->ndo_snapend;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800770 if (cp + length < ep)
771 ep = cp + length;
772
773 dh6 = (struct dhcp6 *)cp;
774 dh6relay = (struct dhcp6_relay *)cp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700775 ND_TCHECK(dh6->dh6_xid);
776 name = tok2str(dh6_msgtype_str, "msgtype-%u", dh6->dh6_msgtype);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800777
Elliott Hughes892a68b2015-10-19 14:43:53 -0700778 if (!ndo->ndo_vflag) {
779 ND_PRINT((ndo, " %s", name));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800780 return;
781 }
782
783 /* XXX relay agent messages have to be handled differently */
784
Elliott Hughes892a68b2015-10-19 14:43:53 -0700785 ND_PRINT((ndo, " %s (", name)); /*)*/
The Android Open Source Project2949f582009-03-03 19:30:46 -0800786 if (dh6->dh6_msgtype != DH6_RELAY_FORW &&
787 dh6->dh6_msgtype != DH6_RELAY_REPLY) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700788 ND_PRINT((ndo, "xid=%x", EXTRACT_32BITS(&dh6->dh6_xid) & DH6_XIDMASK));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800789 extp = (u_char *)(dh6 + 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700790 dhcp6opt_print(ndo, extp, ep);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791 } else { /* relay messages */
792 struct in6_addr addr6;
793
Elliott Hughes892a68b2015-10-19 14:43:53 -0700794 ND_TCHECK(dh6relay->dh6relay_peeraddr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800795
796 memcpy(&addr6, dh6relay->dh6relay_linkaddr, sizeof (addr6));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700797 ND_PRINT((ndo, "linkaddr=%s", ip6addr_string(ndo, &addr6)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800798
799 memcpy(&addr6, dh6relay->dh6relay_peeraddr, sizeof (addr6));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700800 ND_PRINT((ndo, " peeraddr=%s", ip6addr_string(ndo, &addr6)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800801
Elliott Hughes892a68b2015-10-19 14:43:53 -0700802 dhcp6opt_print(ndo, (u_char *)(dh6relay + 1), ep);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800803 }
804 /*(*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700805 ND_PRINT((ndo, ")"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800806 return;
807
808trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700809 ND_PRINT((ndo, "[|dhcp6]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800810}