1 /* 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 /* \summary: IPv6 DHCP printer */ 31 32 /* 33 * RFC3315: DHCPv6 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, 44 */ 45 46 #ifdef HAVE_CONFIG_H 47 #include "config.h" 48 #endif 49 50 #include <netdissect-stdinc.h> 51 52 #include <stdio.h> 53 #include <string.h> 54 55 #include "netdissect.h" 56 #include "addrtoname.h" 57 #include "extract.h" 58 59 /* lease duration */ 60 #define DHCP6_DURATION_INFINITE 0xffffffff 61 62 /* Error Values */ 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 68 69 /* Message type */ 70 #define DH6_SOLICIT 1 71 #define DH6_ADVERTISE 2 72 #define DH6_REQUEST 3 73 #define DH6_CONFIRM 4 74 #define DH6_RENEW 5 75 #define DH6_REBIND 6 76 #define DH6_REPLY 7 77 #define DH6_RELEASE 8 78 #define DH6_DECLINE 9 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 85 86 static const struct tok dh6_msgtype_str[] = { 87 { DH6_SOLICIT, "solicit" }, 88 { DH6_ADVERTISE, "advertise" }, 89 { DH6_REQUEST, "request" }, 90 { DH6_CONFIRM, "confirm" }, 91 { DH6_RENEW, "renew" }, 92 { DH6_REBIND, "rebind" }, 93 { DH6_REPLY, "reply" }, 94 { DH6_RELEASE, "release" }, 95 { DH6_DECLINE, "decline" }, 96 { DH6_RECONFIGURE, "reconfigure" }, 97 { DH6_INFORM_REQ, "inf-req" }, 98 { DH6_RELAY_FORW, "relay-fwd" }, 99 { DH6_RELAY_REPLY, "relay-reply" }, 100 { DH6_LEASEQUERY, "leasequery" }, 101 { DH6_LQ_REPLY, "leasequery-reply" }, 102 { 0, NULL } 103 }; 104 105 /* DHCP6 base packet format */ 106 struct dhcp6 { 107 union { 108 nd_uint8_t m; 109 nd_uint32_t x; 110 } dh6_msgtypexid; 111 /* options follow */ 112 }; 113 #define dh6_msgtype dh6_msgtypexid.m 114 #define dh6_xid dh6_msgtypexid.x 115 #define DH6_XIDMASK 0x00ffffff 116 117 /* DHCPv6 relay messages */ 118 struct dhcp6_relay { 119 nd_uint8_t dh6relay_msgtype; 120 nd_uint8_t dh6relay_hcnt; 121 nd_uint8_t dh6relay_linkaddr[16]; /* XXX: badly aligned */ 122 nd_uint8_t dh6relay_peeraddr[16]; 123 /* options follow */ 124 }; 125 126 /* options */ 127 #define DH6OPT_CLIENTID 1 128 #define DH6OPT_SERVERID 2 129 #define DH6OPT_IA_NA 3 130 #define DH6OPT_IA_TA 4 131 #define DH6OPT_IA_ADDR 5 132 #define DH6OPT_ORO 6 133 #define DH6OPT_PREFERENCE 7 134 # define DH6OPT_PREF_MAX 255 135 #define DH6OPT_ELAPSED_TIME 8 136 #define DH6OPT_RELAY_MSG 9 137 /*#define DH6OPT_SERVER_MSG 10 deprecated */ 138 #define DH6OPT_AUTH 11 139 # define DH6OPT_AUTHPROTO_DELAYED 2 140 # define DH6OPT_AUTHPROTO_RECONFIG 3 141 # define DH6OPT_AUTHALG_HMACMD5 1 142 # define DH6OPT_AUTHRDM_MONOCOUNTER 0 143 # define DH6OPT_AUTHRECONFIG_KEY 1 144 # define DH6OPT_AUTHRECONFIG_HMACMD5 2 145 #define DH6OPT_UNICAST 12 146 #define DH6OPT_STATUS_CODE 13 147 # define DH6OPT_STCODE_SUCCESS 0 148 # define DH6OPT_STCODE_UNSPECFAIL 1 149 # define DH6OPT_STCODE_NOADDRAVAIL 2 150 # define DH6OPT_STCODE_NOBINDING 3 151 # define DH6OPT_STCODE_NOTONLINK 4 152 # define DH6OPT_STCODE_USEMULTICAST 5 153 # define DH6OPT_STCODE_NOPREFIXAVAIL 6 154 # define DH6OPT_STCODE_UNKNOWNQUERYTYPE 7 155 # define DH6OPT_STCODE_MALFORMEDQUERY 8 156 # define DH6OPT_STCODE_NOTCONFIGURED 9 157 # define DH6OPT_STCODE_NOTALLOWED 10 158 #define DH6OPT_RAPID_COMMIT 14 159 #define DH6OPT_USER_CLASS 15 160 #define DH6OPT_VENDOR_CLASS 16 161 #define DH6OPT_VENDOR_OPTS 17 162 #define DH6OPT_INTERFACE_ID 18 163 #define DH6OPT_RECONF_MSG 19 164 #define DH6OPT_RECONF_ACCEPT 20 165 #define DH6OPT_SIP_SERVER_D 21 166 #define DH6OPT_SIP_SERVER_A 22 167 #define DH6OPT_DNS_SERVERS 23 168 #define DH6OPT_DOMAIN_LIST 24 169 #define DH6OPT_IA_PD 25 170 #define DH6OPT_IA_PD_PREFIX 26 171 #define DH6OPT_NIS_SERVERS 27 172 #define DH6OPT_NISP_SERVERS 28 173 #define DH6OPT_NIS_NAME 29 174 #define DH6OPT_NISP_NAME 30 175 #define DH6OPT_SNTP_SERVERS 31 176 #define DH6OPT_LIFETIME 32 177 #define DH6OPT_BCMCS_SERVER_D 33 178 #define DH6OPT_BCMCS_SERVER_A 34 179 #define DH6OPT_GEOCONF_CIVIC 36 180 #define DH6OPT_REMOTE_ID 37 181 #define DH6OPT_SUBSCRIBER_ID 38 182 #define DH6OPT_CLIENT_FQDN 39 183 #define DH6OPT_PANA_AGENT 40 184 #define DH6OPT_NEW_POSIX_TIMEZONE 41 185 #define DH6OPT_NEW_TZDB_TIMEZONE 42 186 #define DH6OPT_ERO 43 187 #define DH6OPT_LQ_QUERY 44 188 #define DH6OPT_CLIENT_DATA 45 189 #define DH6OPT_CLT_TIME 46 190 #define DH6OPT_LQ_RELAY_DATA 47 191 #define DH6OPT_LQ_CLIENT_LINK 48 192 #define DH6OPT_NTP_SERVER 56 193 # define DH6OPT_NTP_SUBOPTION_SRV_ADDR 1 194 # define DH6OPT_NTP_SUBOPTION_MC_ADDR 2 195 # define DH6OPT_NTP_SUBOPTION_SRV_FQDN 3 196 #define DH6OPT_AFTR_NAME 64 197 #define DH6OPT_MUDURL 112 198 199 static const struct tok dh6opt_str[] = { 200 { DH6OPT_CLIENTID, "client-ID" }, 201 { DH6OPT_SERVERID, "server-ID" }, 202 { DH6OPT_IA_NA, "IA_NA" }, 203 { DH6OPT_IA_TA, "IA_TA" }, 204 { DH6OPT_IA_ADDR, "IA_ADDR" }, 205 { DH6OPT_ORO, "option-request" }, 206 { DH6OPT_PREFERENCE, "preference" }, 207 { DH6OPT_ELAPSED_TIME, "elapsed-time" }, 208 { DH6OPT_RELAY_MSG, "relay-message" }, 209 { DH6OPT_AUTH, "authentication" }, 210 { DH6OPT_UNICAST, "server-unicast" }, 211 { DH6OPT_STATUS_CODE, "status-code" }, 212 { DH6OPT_RAPID_COMMIT, "rapid-commit" }, 213 { DH6OPT_USER_CLASS, "user-class" }, 214 { DH6OPT_VENDOR_CLASS, "vendor-class" }, 215 { DH6OPT_VENDOR_OPTS, "vendor-specific-info" }, 216 { DH6OPT_INTERFACE_ID, "interface-ID" }, 217 { DH6OPT_RECONF_MSG, "reconfigure-message" }, 218 { DH6OPT_RECONF_ACCEPT, "reconfigure-accept" }, 219 { DH6OPT_SIP_SERVER_D, "SIP-servers-domain" }, 220 { DH6OPT_SIP_SERVER_A, "SIP-servers-address" }, 221 { DH6OPT_DNS_SERVERS, "DNS-server" }, 222 { DH6OPT_DOMAIN_LIST, "DNS-search-list" }, 223 { DH6OPT_IA_PD, "IA_PD" }, 224 { DH6OPT_IA_PD_PREFIX, "IA_PD-prefix" }, 225 { DH6OPT_SNTP_SERVERS, "SNTP-servers" }, 226 { DH6OPT_LIFETIME, "lifetime" }, 227 { DH6OPT_NIS_SERVERS, "NIS-server" }, 228 { DH6OPT_NISP_SERVERS, "NIS+-server" }, 229 { DH6OPT_NIS_NAME, "NIS-domain-name" }, 230 { DH6OPT_NISP_NAME, "NIS+-domain-name" }, 231 { DH6OPT_BCMCS_SERVER_D, "BCMCS-domain-name" }, 232 { DH6OPT_BCMCS_SERVER_A, "BCMCS-server" }, 233 { DH6OPT_GEOCONF_CIVIC, "Geoconf-Civic" }, 234 { DH6OPT_REMOTE_ID, "Remote-ID" }, 235 { DH6OPT_SUBSCRIBER_ID, "Subscriber-ID" }, 236 { DH6OPT_CLIENT_FQDN, "Client-FQDN" }, 237 { DH6OPT_PANA_AGENT, "PANA-agent" }, 238 { DH6OPT_NEW_POSIX_TIMEZONE, "POSIX-timezone" }, 239 { DH6OPT_NEW_TZDB_TIMEZONE, "POSIX-tz-database" }, 240 { DH6OPT_ERO, "Echo-request-option" }, 241 { DH6OPT_LQ_QUERY, "Lease-query" }, 242 { DH6OPT_CLIENT_DATA, "LQ-client-data" }, 243 { DH6OPT_CLT_TIME, "Clt-time" }, 244 { DH6OPT_LQ_RELAY_DATA, "LQ-relay-data" }, 245 { DH6OPT_LQ_CLIENT_LINK, "LQ-client-link" }, 246 { DH6OPT_NTP_SERVER, "NTP-server" }, 247 { DH6OPT_AFTR_NAME, "AFTR-Name" }, 248 { DH6OPT_MUDURL, "MUD-URL" }, 249 { 0, NULL } 250 }; 251 252 static const struct tok dh6opt_stcode_str[] = { 253 { DH6OPT_STCODE_SUCCESS, "Success" }, /* RFC3315 */ 254 { DH6OPT_STCODE_UNSPECFAIL, "UnspecFail" }, /* RFC3315 */ 255 { DH6OPT_STCODE_NOADDRAVAIL, "NoAddrsAvail" }, /* RFC3315 */ 256 { DH6OPT_STCODE_NOBINDING, "NoBinding" }, /* RFC3315 */ 257 { DH6OPT_STCODE_NOTONLINK, "NotOnLink" }, /* RFC3315 */ 258 { DH6OPT_STCODE_USEMULTICAST, "UseMulticast" }, /* RFC3315 */ 259 { DH6OPT_STCODE_NOPREFIXAVAIL, "NoPrefixAvail" }, /* RFC3633 */ 260 { DH6OPT_STCODE_UNKNOWNQUERYTYPE, "UnknownQueryType" }, /* RFC5007 */ 261 { DH6OPT_STCODE_MALFORMEDQUERY, "MalformedQuery" }, /* RFC5007 */ 262 { DH6OPT_STCODE_NOTCONFIGURED, "NotConfigured" }, /* RFC5007 */ 263 { DH6OPT_STCODE_NOTALLOWED, "NotAllowed" }, /* RFC5007 */ 264 { 0, NULL } 265 }; 266 267 struct dhcp6opt { 268 nd_uint16_t dh6opt_type; 269 nd_uint16_t dh6opt_len; 270 /* type-dependent data follows */ 271 }; 272 273 static const char * 274 dhcp6stcode(const uint16_t code) 275 { 276 return code > 255 ? "INVALID code" : tok2str(dh6opt_stcode_str, "code%u", code); 277 } 278 279 static void 280 dhcp6opt_print(netdissect_options *ndo, 281 const u_char *cp, const u_char *ep) 282 { 283 const struct dhcp6opt *dh6o; 284 const u_char *tp; 285 size_t i; 286 uint16_t opttype; 287 size_t optlen; 288 uint8_t auth_proto; 289 u_int authinfolen, authrealmlen; 290 int remain_len; /* Length of remaining options */ 291 int label_len; /* Label length */ 292 uint16_t subopt_code; 293 uint16_t subopt_len; 294 295 if (cp == ep) 296 return; 297 while (cp < ep) { 298 if (ep < cp + sizeof(*dh6o)) 299 goto trunc; 300 dh6o = (const struct dhcp6opt *)cp; 301 ND_TCHECK(*dh6o); 302 optlen = EXTRACT_16BITS(&dh6o->dh6opt_len); 303 if (ep < cp + sizeof(*dh6o) + optlen) 304 goto trunc; 305 opttype = EXTRACT_16BITS(&dh6o->dh6opt_type); 306 ND_PRINT((ndo, " (%s", tok2str(dh6opt_str, "opt_%u", opttype))); 307 ND_TCHECK2(*(cp + sizeof(*dh6o)), optlen); 308 switch (opttype) { 309 case DH6OPT_CLIENTID: 310 case DH6OPT_SERVERID: 311 if (optlen < 2) { 312 /*(*/ 313 ND_PRINT((ndo, " ?)")); 314 break; 315 } 316 tp = (const u_char *)(dh6o + 1); 317 switch (EXTRACT_16BITS(tp)) { 318 case 1: 319 if (optlen >= 2 + 6) { 320 ND_PRINT((ndo, " hwaddr/time type %u time %u ", 321 EXTRACT_16BITS(&tp[2]), 322 EXTRACT_32BITS(&tp[4]))); 323 for (i = 8; i < optlen; i++) 324 ND_PRINT((ndo, "%02x", tp[i])); 325 /*(*/ 326 ND_PRINT((ndo, ")")); 327 } else { 328 /*(*/ 329 ND_PRINT((ndo, " ?)")); 330 } 331 break; 332 case 2: 333 if (optlen >= 2 + 8) { 334 ND_PRINT((ndo, " vid ")); 335 for (i = 2; i < 2 + 8; i++) 336 ND_PRINT((ndo, "%02x", tp[i])); 337 /*(*/ 338 ND_PRINT((ndo, ")")); 339 } else { 340 /*(*/ 341 ND_PRINT((ndo, " ?)")); 342 } 343 break; 344 case 3: 345 if (optlen >= 2 + 2) { 346 ND_PRINT((ndo, " hwaddr type %u ", 347 EXTRACT_16BITS(&tp[2]))); 348 for (i = 4; i < optlen; i++) 349 ND_PRINT((ndo, "%02x", tp[i])); 350 /*(*/ 351 ND_PRINT((ndo, ")")); 352 } else { 353 /*(*/ 354 ND_PRINT((ndo, " ?)")); 355 } 356 break; 357 default: 358 ND_PRINT((ndo, " type %d)", EXTRACT_16BITS(tp))); 359 break; 360 } 361 break; 362 case DH6OPT_IA_ADDR: 363 if (optlen < 24) { 364 /*(*/ 365 ND_PRINT((ndo, " ?)")); 366 break; 367 } 368 tp = (const u_char *)(dh6o + 1); 369 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[0]))); 370 ND_PRINT((ndo, " pltime:%u vltime:%u", 371 EXTRACT_32BITS(&tp[16]), 372 EXTRACT_32BITS(&tp[20]))); 373 if (optlen > 24) { 374 /* there are sub-options */ 375 dhcp6opt_print(ndo, tp + 24, tp + optlen); 376 } 377 ND_PRINT((ndo, ")")); 378 break; 379 case DH6OPT_ORO: 380 case DH6OPT_ERO: 381 if (optlen % 2) { 382 ND_PRINT((ndo, " ?)")); 383 break; 384 } 385 tp = (const u_char *)(dh6o + 1); 386 for (i = 0; i < optlen; i += 2) { 387 ND_PRINT((ndo, " %s", 388 tok2str(dh6opt_str, "opt_%u", EXTRACT_16BITS(&tp[i])))); 389 } 390 ND_PRINT((ndo, ")")); 391 break; 392 case DH6OPT_PREFERENCE: 393 if (optlen != 1) { 394 ND_PRINT((ndo, " ?)")); 395 break; 396 } 397 tp = (const u_char *)(dh6o + 1); 398 ND_PRINT((ndo, " %d)", *tp)); 399 break; 400 case DH6OPT_ELAPSED_TIME: 401 if (optlen != 2) { 402 ND_PRINT((ndo, " ?)")); 403 break; 404 } 405 tp = (const u_char *)(dh6o + 1); 406 ND_PRINT((ndo, " %d)", EXTRACT_16BITS(tp))); 407 break; 408 case DH6OPT_RELAY_MSG: 409 ND_PRINT((ndo, " (")); 410 tp = (const u_char *)(dh6o + 1); 411 dhcp6_print(ndo, tp, optlen); 412 ND_PRINT((ndo, ")")); 413 break; 414 case DH6OPT_AUTH: 415 if (optlen < 11) { 416 ND_PRINT((ndo, " ?)")); 417 break; 418 } 419 tp = (const u_char *)(dh6o + 1); 420 auth_proto = *tp; 421 switch (auth_proto) { 422 case DH6OPT_AUTHPROTO_DELAYED: 423 ND_PRINT((ndo, " proto: delayed")); 424 break; 425 case DH6OPT_AUTHPROTO_RECONFIG: 426 ND_PRINT((ndo, " proto: reconfigure")); 427 break; 428 default: 429 ND_PRINT((ndo, " proto: %d", auth_proto)); 430 break; 431 } 432 tp++; 433 switch (*tp) { 434 case DH6OPT_AUTHALG_HMACMD5: 435 /* XXX: may depend on the protocol */ 436 ND_PRINT((ndo, ", alg: HMAC-MD5")); 437 break; 438 default: 439 ND_PRINT((ndo, ", alg: %d", *tp)); 440 break; 441 } 442 tp++; 443 switch (*tp) { 444 case DH6OPT_AUTHRDM_MONOCOUNTER: 445 ND_PRINT((ndo, ", RDM: mono")); 446 break; 447 default: 448 ND_PRINT((ndo, ", RDM: %d", *tp)); 449 break; 450 } 451 tp++; 452 ND_PRINT((ndo, ", RD:")); 453 for (i = 0; i < 4; i++, tp += 2) 454 ND_PRINT((ndo, " %04x", EXTRACT_16BITS(tp))); 455 456 /* protocol dependent part */ 457 authinfolen = optlen - 11; 458 switch (auth_proto) { 459 case DH6OPT_AUTHPROTO_DELAYED: 460 if (authinfolen == 0) 461 break; 462 if (authinfolen < 20) { 463 ND_PRINT((ndo, " ??")); 464 break; 465 } 466 authrealmlen = authinfolen - 20; 467 if (authrealmlen > 0) { 468 ND_PRINT((ndo, ", realm: ")); 469 } 470 for (i = 0; i < authrealmlen; i++, tp++) 471 ND_PRINT((ndo, "%02x", *tp)); 472 ND_PRINT((ndo, ", key ID: %08x", EXTRACT_32BITS(tp))); 473 tp += 4; 474 ND_PRINT((ndo, ", HMAC-MD5:")); 475 for (i = 0; i < 4; i++, tp+= 4) 476 ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp))); 477 break; 478 case DH6OPT_AUTHPROTO_RECONFIG: 479 if (authinfolen != 17) { 480 ND_PRINT((ndo, " ??")); 481 break; 482 } 483 switch (*tp++) { 484 case DH6OPT_AUTHRECONFIG_KEY: 485 ND_PRINT((ndo, " reconfig-key")); 486 break; 487 case DH6OPT_AUTHRECONFIG_HMACMD5: 488 ND_PRINT((ndo, " type: HMAC-MD5")); 489 break; 490 default: 491 ND_PRINT((ndo, " type: ??")); 492 break; 493 } 494 ND_PRINT((ndo, " value:")); 495 for (i = 0; i < 4; i++, tp+= 4) 496 ND_PRINT((ndo, " %08x", EXTRACT_32BITS(tp))); 497 break; 498 default: 499 ND_PRINT((ndo, " ??")); 500 break; 501 } 502 503 ND_PRINT((ndo, ")")); 504 break; 505 case DH6OPT_RAPID_COMMIT: /* nothing todo */ 506 ND_PRINT((ndo, ")")); 507 break; 508 case DH6OPT_INTERFACE_ID: 509 case DH6OPT_SUBSCRIBER_ID: 510 /* 511 * Since we cannot predict the encoding, print hex dump 512 * at most 10 characters. 513 */ 514 tp = (const u_char *)(dh6o + 1); 515 ND_PRINT((ndo, " ")); 516 for (i = 0; i < optlen && i < 10; i++) 517 ND_PRINT((ndo, "%02x", tp[i])); 518 ND_PRINT((ndo, "...)")); 519 break; 520 case DH6OPT_RECONF_MSG: 521 tp = (const u_char *)(dh6o + 1); 522 switch (*tp) { 523 case DH6_RENEW: 524 ND_PRINT((ndo, " for renew)")); 525 break; 526 case DH6_INFORM_REQ: 527 ND_PRINT((ndo, " for inf-req)")); 528 break; 529 default: 530 ND_PRINT((ndo, " for ?\?\?(%02x))", *tp)); 531 break; 532 } 533 break; 534 case DH6OPT_RECONF_ACCEPT: /* nothing todo */ 535 ND_PRINT((ndo, ")")); 536 break; 537 case DH6OPT_SIP_SERVER_A: 538 case DH6OPT_DNS_SERVERS: 539 case DH6OPT_SNTP_SERVERS: 540 case DH6OPT_NIS_SERVERS: 541 case DH6OPT_NISP_SERVERS: 542 case DH6OPT_BCMCS_SERVER_A: 543 case DH6OPT_PANA_AGENT: 544 case DH6OPT_LQ_CLIENT_LINK: 545 if (optlen % 16) { 546 ND_PRINT((ndo, " ?)")); 547 break; 548 } 549 tp = (const u_char *)(dh6o + 1); 550 for (i = 0; i < optlen; i += 16) 551 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[i]))); 552 ND_PRINT((ndo, ")")); 553 break; 554 case DH6OPT_SIP_SERVER_D: 555 case DH6OPT_DOMAIN_LIST: 556 tp = (const u_char *)(dh6o + 1); 557 while (tp < cp + sizeof(*dh6o) + optlen) { 558 ND_PRINT((ndo, " ")); 559 if ((tp = ns_nprint(ndo, tp, cp + sizeof(*dh6o) + optlen)) == NULL) 560 goto trunc; 561 } 562 ND_PRINT((ndo, ")")); 563 break; 564 case DH6OPT_STATUS_CODE: 565 if (optlen < 2) { 566 ND_PRINT((ndo, " ?)")); 567 break; 568 } 569 tp = (const u_char *)(dh6o + 1); 570 ND_PRINT((ndo, " %s)", dhcp6stcode(EXTRACT_16BITS(&tp[0])))); 571 break; 572 case DH6OPT_IA_NA: 573 case DH6OPT_IA_PD: 574 if (optlen < 12) { 575 ND_PRINT((ndo, " ?)")); 576 break; 577 } 578 tp = (const u_char *)(dh6o + 1); 579 ND_PRINT((ndo, " IAID:%u T1:%u T2:%u", 580 EXTRACT_32BITS(&tp[0]), 581 EXTRACT_32BITS(&tp[4]), 582 EXTRACT_32BITS(&tp[8]))); 583 if (optlen > 12) { 584 /* there are sub-options */ 585 dhcp6opt_print(ndo, tp + 12, tp + optlen); 586 } 587 ND_PRINT((ndo, ")")); 588 break; 589 case DH6OPT_IA_TA: 590 if (optlen < 4) { 591 ND_PRINT((ndo, " ?)")); 592 break; 593 } 594 tp = (const u_char *)(dh6o + 1); 595 ND_PRINT((ndo, " IAID:%u", EXTRACT_32BITS(tp))); 596 if (optlen > 4) { 597 /* there are sub-options */ 598 dhcp6opt_print(ndo, tp + 4, tp + optlen); 599 } 600 ND_PRINT((ndo, ")")); 601 break; 602 case DH6OPT_IA_PD_PREFIX: 603 if (optlen < 25) { 604 ND_PRINT((ndo, " ?)")); 605 break; 606 } 607 tp = (const u_char *)(dh6o + 1); 608 ND_PRINT((ndo, " %s/%d", ip6addr_string(ndo, &tp[9]), tp[8])); 609 ND_PRINT((ndo, " pltime:%u vltime:%u", 610 EXTRACT_32BITS(&tp[0]), 611 EXTRACT_32BITS(&tp[4]))); 612 if (optlen > 25) { 613 /* there are sub-options */ 614 dhcp6opt_print(ndo, tp + 25, tp + optlen); 615 } 616 ND_PRINT((ndo, ")")); 617 break; 618 case DH6OPT_LIFETIME: 619 case DH6OPT_CLT_TIME: 620 if (optlen != 4) { 621 ND_PRINT((ndo, " ?)")); 622 break; 623 } 624 tp = (const u_char *)(dh6o + 1); 625 ND_PRINT((ndo, " %d)", EXTRACT_32BITS(tp))); 626 break; 627 case DH6OPT_REMOTE_ID: 628 if (optlen < 4) { 629 ND_PRINT((ndo, " ?)")); 630 break; 631 } 632 tp = (const u_char *)(dh6o + 1); 633 ND_PRINT((ndo, " %d ", EXTRACT_32BITS(tp))); 634 /* 635 * Print hex dump first 10 characters. 636 */ 637 for (i = 4; i < optlen && i < 14; i++) 638 ND_PRINT((ndo, "%02x", tp[i])); 639 ND_PRINT((ndo, "...)")); 640 break; 641 case DH6OPT_LQ_QUERY: 642 if (optlen < 17) { 643 ND_PRINT((ndo, " ?)")); 644 break; 645 } 646 tp = (const u_char *)(dh6o + 1); 647 switch (*tp) { 648 case 1: 649 ND_PRINT((ndo, " by-address")); 650 break; 651 case 2: 652 ND_PRINT((ndo, " by-clientID")); 653 break; 654 default: 655 ND_PRINT((ndo, " type_%d", (int)*tp)); 656 break; 657 } 658 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[1]))); 659 if (optlen > 17) { 660 /* there are query-options */ 661 dhcp6opt_print(ndo, tp + 17, tp + optlen); 662 } 663 ND_PRINT((ndo, ")")); 664 break; 665 case DH6OPT_CLIENT_DATA: 666 tp = (const u_char *)(dh6o + 1); 667 if (optlen > 0) { 668 /* there are encapsulated options */ 669 dhcp6opt_print(ndo, tp, tp + optlen); 670 } 671 ND_PRINT((ndo, ")")); 672 break; 673 case DH6OPT_LQ_RELAY_DATA: 674 if (optlen < 16) { 675 ND_PRINT((ndo, " ?)")); 676 break; 677 } 678 tp = (const u_char *)(dh6o + 1); 679 ND_PRINT((ndo, " %s ", ip6addr_string(ndo, &tp[0]))); 680 /* 681 * Print hex dump first 10 characters. 682 */ 683 for (i = 16; i < optlen && i < 26; i++) 684 ND_PRINT((ndo, "%02x", tp[i])); 685 ND_PRINT((ndo, "...)")); 686 break; 687 case DH6OPT_NTP_SERVER: 688 if (optlen < 4) { 689 ND_PRINT((ndo, " ?)")); 690 break; 691 } 692 tp = (const u_char *)(dh6o + 1); 693 while (tp < cp + sizeof(*dh6o) + optlen - 4) { 694 subopt_code = EXTRACT_16BITS(tp); 695 tp += 2; 696 subopt_len = EXTRACT_16BITS(tp); 697 tp += 2; 698 if (tp + subopt_len > cp + sizeof(*dh6o) + optlen) 699 goto trunc; 700 ND_PRINT((ndo, " subopt:%d", subopt_code)); 701 switch (subopt_code) { 702 case DH6OPT_NTP_SUBOPTION_SRV_ADDR: 703 case DH6OPT_NTP_SUBOPTION_MC_ADDR: 704 if (subopt_len != 16) { 705 ND_PRINT((ndo, " ?")); 706 break; 707 } 708 ND_PRINT((ndo, " %s", ip6addr_string(ndo, &tp[0]))); 709 break; 710 case DH6OPT_NTP_SUBOPTION_SRV_FQDN: 711 ND_PRINT((ndo, " ")); 712 if (ns_nprint(ndo, tp, tp + subopt_len) == NULL) 713 goto trunc; 714 break; 715 default: 716 ND_PRINT((ndo, " ?")); 717 break; 718 } 719 tp += subopt_len; 720 } 721 ND_PRINT((ndo, ")")); 722 break; 723 case DH6OPT_AFTR_NAME: 724 if (optlen < 3) { 725 ND_PRINT((ndo, " ?)")); 726 break; 727 } 728 tp = (const u_char *)(dh6o + 1); 729 remain_len = optlen; 730 ND_PRINT((ndo, " ")); 731 /* Encoding is described in section 3.1 of RFC 1035 */ 732 while (remain_len && *tp) { 733 label_len = *tp++; 734 if (label_len < remain_len - 1) { 735 (void)fn_printn(ndo, tp, label_len, NULL); 736 tp += label_len; 737 remain_len -= (label_len + 1); 738 if(*tp) ND_PRINT((ndo, ".")); 739 } else { 740 ND_PRINT((ndo, " ?")); 741 break; 742 } 743 } 744 ND_PRINT((ndo, ")")); 745 break; 746 case DH6OPT_NEW_POSIX_TIMEZONE: /* all three of these options */ 747 case DH6OPT_NEW_TZDB_TIMEZONE: /* are encoded similarly */ 748 case DH6OPT_MUDURL: /* although GMT might not work */ 749 if (optlen < 5) { 750 ND_PRINT((ndo, " ?)")); 751 break; 752 } 753 tp = (const u_char *)(dh6o + 1); 754 ND_PRINT((ndo, "=")); 755 (void)fn_printn(ndo, tp, (u_int)optlen, NULL); 756 ND_PRINT((ndo, ")")); 757 break; 758 759 default: 760 ND_PRINT((ndo, ")")); 761 break; 762 } 763 764 cp += sizeof(*dh6o) + optlen; 765 } 766 return; 767 768 trunc: 769 ND_PRINT((ndo, "[|dhcp6ext]")); 770 } 771 772 /* 773 * Print dhcp6 packets 774 */ 775 void 776 dhcp6_print(netdissect_options *ndo, 777 const u_char *cp, u_int length) 778 { 779 const struct dhcp6 *dh6; 780 const struct dhcp6_relay *dh6relay; 781 const u_char *ep; 782 const u_char *extp; 783 const char *name; 784 785 ND_PRINT((ndo, "dhcp6")); 786 787 ep = (const u_char *)ndo->ndo_snapend; 788 if (cp + length < ep) 789 ep = cp + length; 790 791 dh6 = (const struct dhcp6 *)cp; 792 dh6relay = (const struct dhcp6_relay *)cp; 793 ND_TCHECK(dh6->dh6_xid); 794 name = tok2str(dh6_msgtype_str, "msgtype-%u", dh6->dh6_msgtype); 795 796 if (!ndo->ndo_vflag) { 797 ND_PRINT((ndo, " %s", name)); 798 return; 799 } 800 801 /* XXX relay agent messages have to be handled differently */ 802 803 ND_PRINT((ndo, " %s (", name)); /*)*/ 804 if (dh6->dh6_msgtype != DH6_RELAY_FORW && 805 dh6->dh6_msgtype != DH6_RELAY_REPLY) { 806 ND_PRINT((ndo, "xid=%x", EXTRACT_32BITS(&dh6->dh6_xid) & DH6_XIDMASK)); 807 extp = (const u_char *)(dh6 + 1); 808 dhcp6opt_print(ndo, extp, ep); 809 } else { /* relay messages */ 810 struct in6_addr addr6; 811 812 ND_TCHECK(dh6relay->dh6relay_peeraddr); 813 814 memcpy(&addr6, dh6relay->dh6relay_linkaddr, sizeof (addr6)); 815 ND_PRINT((ndo, "linkaddr=%s", ip6addr_string(ndo, &addr6))); 816 817 memcpy(&addr6, dh6relay->dh6relay_peeraddr, sizeof (addr6)); 818 ND_PRINT((ndo, " peeraddr=%s", ip6addr_string(ndo, &addr6))); 819 820 dhcp6opt_print(ndo, (const u_char *)(dh6relay + 1), ep); 821 } 822 /*(*/ 823 ND_PRINT((ndo, ")")); 824 return; 825 826 trunc: 827 ND_PRINT((ndo, "[|dhcp6]")); 828 } 829