1 /* 2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 * 21 * Format and print bootp packets. 22 */ 23 24 #include <sys/cdefs.h> 25 #ifndef lint 26 __RCSID("$NetBSD: print-bootp.c,v 1.5 2014/11/20 03:05:03 christos Exp $"); 27 #endif 28 29 #define NETDISSECT_REWORKED 30 #ifdef HAVE_CONFIG_H 31 #include "config.h" 32 #endif 33 34 #include <tcpdump-stdinc.h> 35 36 #include <string.h> 37 38 #include "interface.h" 39 #include "addrtoname.h" 40 #include "extract.h" 41 #include "bootp.h" 42 43 static const char tstr[] = " [|bootp]"; 44 45 static void rfc1048_print(netdissect_options *, const u_char *); 46 static void cmu_print(netdissect_options *, const u_char *); 47 static char *client_fqdn_flags(u_int flags); 48 49 static const struct tok bootp_flag_values[] = { 50 { 0x8000, "Broadcast" }, 51 { 0, NULL} 52 }; 53 54 static const struct tok bootp_op_values[] = { 55 { BOOTPREQUEST, "Request" }, 56 { BOOTPREPLY, "Reply" }, 57 { 0, NULL} 58 }; 59 60 /* 61 * Print bootp requests 62 */ 63 void 64 bootp_print(netdissect_options *ndo, 65 register const u_char *cp, u_int length) 66 { 67 register const struct bootp *bp; 68 static const u_char vm_cmu[4] = VM_CMU; 69 static const u_char vm_rfc1048[4] = VM_RFC1048; 70 71 bp = (const struct bootp *)cp; 72 ND_TCHECK(bp->bp_op); 73 74 ND_PRINT((ndo, "BOOTP/DHCP, %s", 75 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op))); 76 77 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) { 78 ND_TCHECK2(bp->bp_chaddr[0], 6); 79 ND_PRINT((ndo, " from %s", etheraddr_string(ndo, bp->bp_chaddr))); 80 } 81 82 ND_PRINT((ndo, ", length %u", length)); 83 84 if (!ndo->ndo_vflag) 85 return; 86 87 ND_TCHECK(bp->bp_secs); 88 89 /* The usual hardware address type is 1 (10Mb Ethernet) */ 90 if (bp->bp_htype != 1) 91 ND_PRINT((ndo, ", htype %d", bp->bp_htype)); 92 93 /* The usual length for 10Mb Ethernet address is 6 bytes */ 94 if (bp->bp_htype != 1 || bp->bp_hlen != 6) 95 ND_PRINT((ndo, ", hlen %d", bp->bp_hlen)); 96 97 /* Only print interesting fields */ 98 if (bp->bp_hops) 99 ND_PRINT((ndo, ", hops %d", bp->bp_hops)); 100 if (EXTRACT_32BITS(&bp->bp_xid)) 101 ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid))); 102 if (EXTRACT_16BITS(&bp->bp_secs)) 103 ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs))); 104 105 ND_PRINT((ndo, ", Flags [%s]", 106 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)))); 107 if (ndo->ndo_vflag > 1) 108 ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags))); 109 110 /* Client's ip address */ 111 ND_TCHECK(bp->bp_ciaddr); 112 if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr)) 113 ND_PRINT((ndo, "\n\t Client-IP %s", ipaddr_string(ndo, &bp->bp_ciaddr))); 114 115 /* 'your' ip address (bootp client) */ 116 ND_TCHECK(bp->bp_yiaddr); 117 if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr)) 118 ND_PRINT((ndo, "\n\t Your-IP %s", ipaddr_string(ndo, &bp->bp_yiaddr))); 119 120 /* Server's ip address */ 121 ND_TCHECK(bp->bp_siaddr); 122 if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr)) 123 ND_PRINT((ndo, "\n\t Server-IP %s", ipaddr_string(ndo, &bp->bp_siaddr))); 124 125 /* Gateway's ip address */ 126 ND_TCHECK(bp->bp_giaddr); 127 if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr)) 128 ND_PRINT((ndo, "\n\t Gateway-IP %s", ipaddr_string(ndo, &bp->bp_giaddr))); 129 130 /* Client's Ethernet address */ 131 if (bp->bp_htype == 1 && bp->bp_hlen == 6) { 132 ND_TCHECK2(bp->bp_chaddr[0], 6); 133 ND_PRINT((ndo, "\n\t Client-Ethernet-Address %s", etheraddr_string(ndo, bp->bp_chaddr))); 134 } 135 136 ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */ 137 if (*bp->bp_sname) { 138 ND_PRINT((ndo, "\n\t sname \"")); 139 if (fn_print(ndo, bp->bp_sname, ndo->ndo_snapend)) { 140 ND_PRINT((ndo, "\"")); 141 ND_PRINT((ndo, "%s", tstr + 1)); 142 return; 143 } 144 ND_PRINT((ndo, "\"")); 145 } 146 ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */ 147 if (*bp->bp_file) { 148 ND_PRINT((ndo, "\n\t file \"")); 149 if (fn_print(ndo, bp->bp_file, ndo->ndo_snapend)) { 150 ND_PRINT((ndo, "\"")); 151 ND_PRINT((ndo, "%s", tstr + 1)); 152 return; 153 } 154 ND_PRINT((ndo, "\"")); 155 } 156 157 /* Decode the vendor buffer */ 158 ND_TCHECK(bp->bp_vend[0]); 159 if (memcmp((const char *)bp->bp_vend, vm_rfc1048, 160 sizeof(uint32_t)) == 0) 161 rfc1048_print(ndo, bp->bp_vend); 162 else if (memcmp((const char *)bp->bp_vend, vm_cmu, 163 sizeof(uint32_t)) == 0) 164 cmu_print(ndo, bp->bp_vend); 165 else { 166 uint32_t ul; 167 168 ul = EXTRACT_32BITS(&bp->bp_vend); 169 if (ul != 0) 170 ND_PRINT((ndo, "\n\t Vendor-#0x%x", ul)); 171 } 172 173 return; 174 trunc: 175 ND_PRINT((ndo, "%s", tstr)); 176 } 177 178 /* 179 * The first character specifies the format to print: 180 * i - ip address (32 bits) 181 * p - ip address pairs (32 bits + 32 bits) 182 * l - long (32 bits) 183 * L - unsigned long (32 bits) 184 * s - short (16 bits) 185 * b - period-seperated decimal bytes (variable length) 186 * x - colon-seperated hex bytes (variable length) 187 * a - ascii string (variable length) 188 * B - on/off (8 bits) 189 * $ - special (explicit code to handle) 190 */ 191 static const struct tok tag2str[] = { 192 /* RFC1048 tags */ 193 { TAG_PAD, " PAD" }, 194 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */ 195 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */ 196 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */ 197 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */ 198 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */ 199 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */ 200 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */ 201 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */ 202 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */ 203 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */ 204 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */ 205 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */ 206 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */ 207 { TAG_END, " END" }, 208 /* RFC1497 tags */ 209 { TAG_DUMPPATH, "aDP" }, 210 { TAG_DOMAINNAME, "aDomain-Name" }, 211 { TAG_SWAP_SERVER, "iSS" }, 212 { TAG_ROOTPATH, "aRP" }, 213 { TAG_EXTPATH, "aEP" }, 214 /* RFC2132 tags */ 215 { TAG_IP_FORWARD, "BIPF" }, 216 { TAG_NL_SRCRT, "BSRT" }, 217 { TAG_PFILTERS, "pPF" }, 218 { TAG_REASS_SIZE, "sRSZ" }, 219 { TAG_DEF_TTL, "bTTL" }, 220 { TAG_MTU_TIMEOUT, "lMTU-Timeout" }, 221 { TAG_MTU_TABLE, "sMTU-Table" }, 222 { TAG_INT_MTU, "sMTU" }, 223 { TAG_LOCAL_SUBNETS, "BLSN" }, 224 { TAG_BROAD_ADDR, "iBR" }, 225 { TAG_DO_MASK_DISC, "BMD" }, 226 { TAG_SUPPLY_MASK, "BMS" }, 227 { TAG_DO_RDISC, "BRouter-Discovery" }, 228 { TAG_RTR_SOL_ADDR, "iRSA" }, 229 { TAG_STATIC_ROUTE, "pStatic-Route" }, 230 { TAG_USE_TRAILERS, "BUT" }, 231 { TAG_ARP_TIMEOUT, "lAT" }, 232 { TAG_ETH_ENCAP, "BIE" }, 233 { TAG_TCP_TTL, "bTT" }, 234 { TAG_TCP_KEEPALIVE, "lKI" }, 235 { TAG_KEEPALIVE_GO, "BKG" }, 236 { TAG_NIS_DOMAIN, "aYD" }, 237 { TAG_NIS_SERVERS, "iYS" }, 238 { TAG_NTP_SERVERS, "iNTP" }, 239 { TAG_VENDOR_OPTS, "bVendor-Option" }, 240 { TAG_NETBIOS_NS, "iNetbios-Name-Server" }, 241 { TAG_NETBIOS_DDS, "iWDD" }, 242 { TAG_NETBIOS_NODE, "$Netbios-Node" }, 243 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" }, 244 { TAG_XWIN_FS, "iXFS" }, 245 { TAG_XWIN_DM, "iXDM" }, 246 { TAG_NIS_P_DOMAIN, "sN+D" }, 247 { TAG_NIS_P_SERVERS, "iN+S" }, 248 { TAG_MOBILE_HOME, "iMH" }, 249 { TAG_SMPT_SERVER, "iSMTP" }, 250 { TAG_POP3_SERVER, "iPOP3" }, 251 { TAG_NNTP_SERVER, "iNNTP" }, 252 { TAG_WWW_SERVER, "iWWW" }, 253 { TAG_FINGER_SERVER, "iFG" }, 254 { TAG_IRC_SERVER, "iIRC" }, 255 { TAG_STREETTALK_SRVR, "iSTS" }, 256 { TAG_STREETTALK_STDA, "iSTDA" }, 257 { TAG_REQUESTED_IP, "iRequested-IP" }, 258 { TAG_IP_LEASE, "lLease-Time" }, 259 { TAG_OPT_OVERLOAD, "$OO" }, 260 { TAG_TFTP_SERVER, "aTFTP" }, 261 { TAG_BOOTFILENAME, "aBF" }, 262 { TAG_DHCP_MESSAGE, " DHCP-Message" }, 263 { TAG_SERVER_ID, "iServer-ID" }, 264 { TAG_PARM_REQUEST, "bParameter-Request" }, 265 { TAG_MESSAGE, "aMSG" }, 266 { TAG_MAX_MSG_SIZE, "sMSZ" }, 267 { TAG_RENEWAL_TIME, "lRN" }, 268 { TAG_REBIND_TIME, "lRB" }, 269 { TAG_VENDOR_CLASS, "aVendor-Class" }, 270 { TAG_CLIENT_ID, "$Client-ID" }, 271 /* RFC 2485 */ 272 { TAG_OPEN_GROUP_UAP, "aUAP" }, 273 /* RFC 2563 */ 274 { TAG_DISABLE_AUTOCONF, "BNOAUTO" }, 275 /* RFC 2610 */ 276 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */ 277 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */ 278 /* RFC 2937 */ 279 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ 280 /* RFC 3011 */ 281 { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, 282 /* RFC 3442 */ 283 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" }, 284 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" }, 285 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */ 286 { TAG_USER_CLASS, "aCLASS" }, 287 { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, 288 { TAG_CLIENT_FQDN, "$FQDN" }, 289 { TAG_AGENT_CIRCUIT, "$Agent-Information" }, 290 { TAG_AGENT_REMOTE, "bARMT" }, 291 { TAG_AGENT_MASK, "bAMSK" }, 292 { TAG_TZ_STRING, "aTZSTR" }, 293 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */ 294 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */ 295 { TAG_VINES_SERVERS, "iVINES" }, 296 { TAG_SERVER_RANK, "sRANK" }, 297 { TAG_CLIENT_ARCH, "sARCH" }, 298 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */ 299 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */ 300 { TAG_LDAP_URL, "aLDAP" }, 301 { TAG_6OVER4, "i6o4" }, 302 { TAG_PRINTER_NAME, "aPRTR" }, 303 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */ 304 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */ 305 { TAG_NETINFO_PARENT, "iNI" }, 306 { TAG_NETINFO_PARENT_TAG, "aNITAG" }, 307 { TAG_URL, "aURL" }, 308 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */ 309 { 0, NULL } 310 }; 311 /* 2-byte extended tags */ 312 static const struct tok xtag2str[] = { 313 { 0, NULL } 314 }; 315 316 /* DHCP "options overload" types */ 317 static const struct tok oo2str[] = { 318 { 1, "file" }, 319 { 2, "sname" }, 320 { 3, "file+sname" }, 321 { 0, NULL } 322 }; 323 324 /* NETBIOS over TCP/IP node type options */ 325 static const struct tok nbo2str[] = { 326 { 0x1, "b-node" }, 327 { 0x2, "p-node" }, 328 { 0x4, "m-node" }, 329 { 0x8, "h-node" }, 330 { 0, NULL } 331 }; 332 333 /* ARP Hardware types, for Client-ID option */ 334 static const struct tok arp2str[] = { 335 { 0x1, "ether" }, 336 { 0x6, "ieee802" }, 337 { 0x7, "arcnet" }, 338 { 0xf, "frelay" }, 339 { 0x17, "strip" }, 340 { 0x18, "ieee1394" }, 341 { 0, NULL } 342 }; 343 344 static const struct tok dhcp_msg_values[] = { 345 { DHCPDISCOVER, "Discover" }, 346 { DHCPOFFER, "Offer" }, 347 { DHCPREQUEST, "Request" }, 348 { DHCPDECLINE, "Decline" }, 349 { DHCPACK, "ACK" }, 350 { DHCPNAK, "NACK" }, 351 { DHCPRELEASE, "Release" }, 352 { DHCPINFORM, "Inform" }, 353 { 0, NULL } 354 }; 355 356 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */ 357 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */ 358 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */ 359 static const struct tok agent_suboption_values[] = { 360 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" }, 361 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" }, 362 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" }, 363 { 0, NULL } 364 }; 365 366 367 static void 368 rfc1048_print(netdissect_options *ndo, 369 register const u_char *bp) 370 { 371 register uint16_t tag; 372 register u_int len; 373 register const char *cp; 374 register char c; 375 int first, idx; 376 uint32_t ul; 377 uint16_t us; 378 uint8_t uc, subopt, suboptlen; 379 380 ND_PRINT((ndo, "\n\t Vendor-rfc1048 Extensions")); 381 382 /* Step over magic cookie */ 383 ND_PRINT((ndo, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp))); 384 bp += sizeof(int32_t); 385 386 /* Loop while we there is a tag left in the buffer */ 387 while (ND_TTEST2(*bp, 1)) { 388 tag = *bp++; 389 if (tag == TAG_PAD && ndo->ndo_vflag < 3) 390 continue; 391 if (tag == TAG_END && ndo->ndo_vflag < 3) 392 return; 393 if (tag == TAG_EXTENDED_OPTION) { 394 ND_TCHECK2(*(bp + 1), 2); 395 tag = EXTRACT_16BITS(bp + 1); 396 /* XXX we don't know yet if the IANA will 397 * preclude overlap of 1-byte and 2-byte spaces. 398 * If not, we need to offset tag after this step. 399 */ 400 cp = tok2str(xtag2str, "?xT%u", tag); 401 } else 402 cp = tok2str(tag2str, "?T%u", tag); 403 c = *cp++; 404 405 if (tag == TAG_PAD || tag == TAG_END) 406 len = 0; 407 else { 408 /* Get the length; check for truncation */ 409 ND_TCHECK2(*bp, 1); 410 len = *bp++; 411 } 412 413 ND_PRINT((ndo, "\n\t %s Option %u, length %u%s", cp, tag, len, 414 len > 0 ? ": " : "")); 415 416 if (tag == TAG_PAD && ndo->ndo_vflag > 2) { 417 u_int ntag = 1; 418 while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) { 419 bp++; 420 ntag++; 421 } 422 if (ntag > 1) 423 ND_PRINT((ndo, ", occurs %u", ntag)); 424 } 425 426 if (!ND_TTEST2(*bp, len)) { 427 ND_PRINT((ndo, "[|rfc1048 %u]", len)); 428 return; 429 } 430 431 if (tag == TAG_DHCP_MESSAGE && len == 1) { 432 uc = *bp++; 433 ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc))); 434 continue; 435 } 436 437 if (tag == TAG_PARM_REQUEST) { 438 idx = 0; 439 while (len-- > 0) { 440 uc = *bp++; 441 cp = tok2str(tag2str, "?Option %u", uc); 442 if (idx % 4 == 0) 443 ND_PRINT((ndo, "\n\t ")); 444 else 445 ND_PRINT((ndo, ", ")); 446 ND_PRINT((ndo, "%s", cp + 1)); 447 idx++; 448 } 449 continue; 450 } 451 452 if (tag == TAG_EXTENDED_REQUEST) { 453 first = 1; 454 while (len > 1) { 455 len -= 2; 456 us = EXTRACT_16BITS(bp); 457 bp += 2; 458 cp = tok2str(xtag2str, "?xT%u", us); 459 if (!first) 460 ND_PRINT((ndo, "+")); 461 ND_PRINT((ndo, "%s", cp + 1)); 462 first = 0; 463 } 464 continue; 465 } 466 467 /* Print data */ 468 if (c == '?') { 469 /* Base default formats for unknown tags on data size */ 470 if (len & 1) 471 c = 'b'; 472 else if (len & 2) 473 c = 's'; 474 else 475 c = 'l'; 476 } 477 first = 1; 478 switch (c) { 479 480 case 'a': 481 /* ascii strings */ 482 ND_PRINT((ndo, "\"")); 483 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { 484 ND_PRINT((ndo, "\"")); 485 goto trunc; 486 } 487 ND_PRINT((ndo, "\"")); 488 bp += len; 489 len = 0; 490 break; 491 492 case 'i': 493 case 'l': 494 case 'L': 495 /* ip addresses/32-bit words */ 496 while (len >= sizeof(ul)) { 497 if (!first) 498 ND_PRINT((ndo, ",")); 499 ul = EXTRACT_32BITS(bp); 500 if (c == 'i') { 501 ul = htonl(ul); 502 ND_PRINT((ndo, "%s", ipaddr_string(ndo, &ul))); 503 } else if (c == 'L') 504 ND_PRINT((ndo, "%d", ul)); 505 else 506 ND_PRINT((ndo, "%u", ul)); 507 bp += sizeof(ul); 508 len -= sizeof(ul); 509 first = 0; 510 } 511 break; 512 513 case 'p': 514 /* IP address pairs */ 515 while (len >= 2*sizeof(ul)) { 516 if (!first) 517 ND_PRINT((ndo, ",")); 518 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 519 ND_PRINT((ndo, "(%s:", ipaddr_string(ndo, &ul))); 520 bp += sizeof(ul); 521 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 522 ND_PRINT((ndo, "%s)", ipaddr_string(ndo, &ul))); 523 bp += sizeof(ul); 524 len -= 2*sizeof(ul); 525 first = 0; 526 } 527 break; 528 529 case 's': 530 /* shorts */ 531 while (len >= sizeof(us)) { 532 if (!first) 533 ND_PRINT((ndo, ",")); 534 us = EXTRACT_16BITS(bp); 535 ND_PRINT((ndo, "%u", us)); 536 bp += sizeof(us); 537 len -= sizeof(us); 538 first = 0; 539 } 540 break; 541 542 case 'B': 543 /* boolean */ 544 while (len > 0) { 545 if (!first) 546 ND_PRINT((ndo, ",")); 547 switch (*bp) { 548 case 0: 549 ND_PRINT((ndo, "N")); 550 break; 551 case 1: 552 ND_PRINT((ndo, "Y")); 553 break; 554 default: 555 ND_PRINT((ndo, "%u?", *bp)); 556 break; 557 } 558 ++bp; 559 --len; 560 first = 0; 561 } 562 break; 563 564 case 'b': 565 case 'x': 566 default: 567 /* Bytes */ 568 while (len > 0) { 569 if (!first) 570 ND_PRINT((ndo, c == 'x' ? ":" : ".")); 571 if (c == 'x') 572 ND_PRINT((ndo, "%02x", *bp)); 573 else 574 ND_PRINT((ndo, "%u", *bp)); 575 ++bp; 576 --len; 577 first = 0; 578 } 579 break; 580 581 case '$': 582 /* Guys we can't handle with one of the usual cases */ 583 switch (tag) { 584 585 case TAG_NETBIOS_NODE: 586 /* this option should be at least 1 byte long */ 587 if (len < 1) { 588 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes", 589 TAG_NETBIOS_NODE, len)); 590 break; 591 } 592 tag = *bp++; 593 --len; 594 ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag))); 595 break; 596 597 case TAG_OPT_OVERLOAD: 598 /* this option should be at least 1 byte long */ 599 if (len < 1) { 600 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes", 601 TAG_OPT_OVERLOAD, len)); 602 break; 603 } 604 tag = *bp++; 605 --len; 606 ND_PRINT((ndo, "%s", tok2str(oo2str, NULL, tag))); 607 break; 608 609 case TAG_CLIENT_FQDN: 610 /* this option should be at least 3 bytes long */ 611 if (len < 3) { 612 ND_PRINT((ndo, "ERROR: option %u len %u < 3 bytes", 613 TAG_CLIENT_FQDN, len)); 614 bp += len; 615 len = 0; 616 break; 617 } 618 if (*bp) 619 ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp))); 620 bp++; 621 if (*bp || *(bp+1)) 622 ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1))); 623 bp += 2; 624 ND_PRINT((ndo, "\"")); 625 if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) { 626 ND_PRINT((ndo, "\"")); 627 goto trunc; 628 } 629 ND_PRINT((ndo, "\"")); 630 bp += len - 3; 631 len = 0; 632 break; 633 634 case TAG_CLIENT_ID: 635 { int type; 636 637 /* this option should be at least 1 byte long */ 638 if (len < 1) { 639 ND_PRINT((ndo, "ERROR: option %u len %u < 1 bytes", 640 TAG_CLIENT_ID, len)); 641 break; 642 } 643 type = *bp++; 644 len--; 645 if (type == 0) { 646 ND_PRINT((ndo, "\"")); 647 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { 648 ND_PRINT((ndo, "\"")); 649 goto trunc; 650 } 651 ND_PRINT((ndo, "\"")); 652 bp += len; 653 len = 0; 654 break; 655 } else { 656 ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type))); 657 while (len > 0) { 658 if (!first) 659 ND_PRINT((ndo, ":")); 660 ND_PRINT((ndo, "%02x", *bp)); 661 ++bp; 662 --len; 663 first = 0; 664 } 665 } 666 break; 667 } 668 669 case TAG_AGENT_CIRCUIT: 670 while (len >= 2) { 671 subopt = *bp++; 672 suboptlen = *bp++; 673 len -= 2; 674 if (suboptlen > len) { 675 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: length goes past end of option", 676 tok2str(agent_suboption_values, "Unknown", subopt), 677 subopt, 678 suboptlen)); 679 bp += len; 680 len = 0; 681 break; 682 } 683 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: ", 684 tok2str(agent_suboption_values, "Unknown", subopt), 685 subopt, 686 suboptlen)); 687 switch (subopt) { 688 689 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */ 690 case AGENT_SUBOPTION_REMOTE_ID: 691 case AGENT_SUBOPTION_SUBSCRIBER_ID: 692 fn_printn(ndo, bp, suboptlen, NULL); 693 break; 694 695 default: 696 print_unknown_data(ndo, bp, "\n\t\t", suboptlen); 697 } 698 699 len -= suboptlen; 700 bp += suboptlen; 701 } 702 break; 703 704 case TAG_CLASSLESS_STATIC_RT: 705 case TAG_CLASSLESS_STA_RT_MS: 706 { 707 u_int mask_width, significant_octets, i; 708 709 /* this option should be at least 5 bytes long */ 710 if (len < 5) { 711 ND_PRINT((ndo, "ERROR: option %u len %u < 5 bytes", 712 TAG_CLASSLESS_STATIC_RT, len)); 713 bp += len; 714 len = 0; 715 break; 716 } 717 while (len > 0) { 718 if (!first) 719 ND_PRINT((ndo, ",")); 720 mask_width = *bp++; 721 len--; 722 /* mask_width <= 32 */ 723 if (mask_width > 32) { 724 ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width)); 725 bp += len; 726 len = 0; 727 break; 728 } 729 significant_octets = (mask_width + 7) / 8; 730 /* significant octets + router(4) */ 731 if (len < significant_octets + 4) { 732 ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4)); 733 bp += len; 734 len = 0; 735 break; 736 } 737 ND_PRINT((ndo, "(")); 738 if (mask_width == 0) 739 ND_PRINT((ndo, "default")); 740 else { 741 for (i = 0; i < significant_octets ; i++) { 742 if (i > 0) 743 ND_PRINT((ndo, ".")); 744 ND_PRINT((ndo, "%d", *bp++)); 745 } 746 for (i = significant_octets ; i < 4 ; i++) 747 ND_PRINT((ndo, ".0")); 748 ND_PRINT((ndo, "/%d", mask_width)); 749 } 750 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 751 ND_PRINT((ndo, ":%s)", ipaddr_string(ndo, &ul))); 752 bp += sizeof(ul); 753 len -= (significant_octets + 4); 754 first = 0; 755 } 756 } 757 break; 758 759 default: 760 ND_PRINT((ndo, "[unknown special tag %u, size %u]", 761 tag, len)); 762 bp += len; 763 len = 0; 764 break; 765 } 766 break; 767 } 768 /* Data left over? */ 769 if (len) { 770 ND_PRINT((ndo, "\n\t trailing data length %u", len)); 771 bp += len; 772 } 773 } 774 return; 775 trunc: 776 ND_PRINT((ndo, "|[rfc1048]")); 777 } 778 779 static void 780 cmu_print(netdissect_options *ndo, 781 register const u_char *bp) 782 { 783 register const struct cmu_vend *cmu; 784 785 #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \ 786 if (cmu->m.s_addr != 0) \ 787 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); } 788 789 ND_PRINT((ndo, " vend-cmu")); 790 cmu = (const struct cmu_vend *)bp; 791 792 /* Only print if there are unknown bits */ 793 ND_TCHECK(cmu->v_flags); 794 if ((cmu->v_flags & ~(VF_SMASK)) != 0) 795 ND_PRINT((ndo, " F:0x%x", cmu->v_flags)); 796 PRINTCMUADDR(v_dgate, "DG"); 797 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*"); 798 PRINTCMUADDR(v_dns1, "NS1"); 799 PRINTCMUADDR(v_dns2, "NS2"); 800 PRINTCMUADDR(v_ins1, "IEN1"); 801 PRINTCMUADDR(v_ins2, "IEN2"); 802 PRINTCMUADDR(v_ts1, "TS1"); 803 PRINTCMUADDR(v_ts2, "TS2"); 804 return; 805 806 trunc: 807 ND_PRINT((ndo, "%s", tstr)); 808 #undef PRINTCMUADDR 809 } 810 811 static char * 812 client_fqdn_flags(u_int flags) 813 { 814 static char buf[8+1]; 815 int i = 0; 816 817 if (flags & CLIENT_FQDN_FLAGS_S) 818 buf[i++] = 'S'; 819 if (flags & CLIENT_FQDN_FLAGS_O) 820 buf[i++] = 'O'; 821 if (flags & CLIENT_FQDN_FLAGS_E) 822 buf[i++] = 'E'; 823 if (flags & CLIENT_FQDN_FLAGS_N) 824 buf[i++] = 'N'; 825 buf[i] = '\0'; 826 827 return buf; 828 } 829