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.6 2015/03/31 21:59:35 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 42 static const char tstr[] = " [|bootp]"; 43 44 /* 45 * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. 46 * 47 * This file specifies the "implementation-independent" BOOTP protocol 48 * information which is common to both client and server. 49 * 50 * Copyright 1988 by Carnegie Mellon. 51 * 52 * Permission to use, copy, modify, and distribute this program for any 53 * purpose and without fee is hereby granted, provided that this copyright 54 * and permission notice appear on all copies and supporting documentation, 55 * the name of Carnegie Mellon not be used in advertising or publicity 56 * pertaining to distribution of the program without specific prior 57 * permission, and notice be given in supporting documentation that copying 58 * and distribution is by permission of Carnegie Mellon and Stanford 59 * University. Carnegie Mellon makes no representations about the 60 * suitability of this software for any purpose. It is provided "as is" 61 * without express or implied warranty. 62 */ 63 64 struct bootp { 65 uint8_t bp_op; /* packet opcode type */ 66 uint8_t bp_htype; /* hardware addr type */ 67 uint8_t bp_hlen; /* hardware addr length */ 68 uint8_t bp_hops; /* gateway hops */ 69 uint32_t bp_xid; /* transaction ID */ 70 uint16_t bp_secs; /* seconds since boot began */ 71 uint16_t bp_flags; /* flags - see bootp_flag_values[] 72 in print-bootp.c */ 73 struct in_addr bp_ciaddr; /* client IP address */ 74 struct in_addr bp_yiaddr; /* 'your' IP address */ 75 struct in_addr bp_siaddr; /* server IP address */ 76 struct in_addr bp_giaddr; /* gateway IP address */ 77 uint8_t bp_chaddr[16]; /* client hardware address */ 78 uint8_t bp_sname[64]; /* server host name */ 79 uint8_t bp_file[128]; /* boot file name */ 80 uint8_t bp_vend[64]; /* vendor-specific area */ 81 } UNALIGNED; 82 83 #define BOOTPREPLY 2 84 #define BOOTPREQUEST 1 85 86 /* 87 * Vendor magic cookie (v_magic) for CMU 88 */ 89 #define VM_CMU "CMU" 90 91 /* 92 * Vendor magic cookie (v_magic) for RFC1048 93 */ 94 #define VM_RFC1048 { 99, 130, 83, 99 } 95 96 /* 97 * RFC1048 tag values used to specify what information is being supplied in 98 * the vendor field of the packet. 99 */ 100 101 #define TAG_PAD ((uint8_t) 0) 102 #define TAG_SUBNET_MASK ((uint8_t) 1) 103 #define TAG_TIME_OFFSET ((uint8_t) 2) 104 #define TAG_GATEWAY ((uint8_t) 3) 105 #define TAG_TIME_SERVER ((uint8_t) 4) 106 #define TAG_NAME_SERVER ((uint8_t) 5) 107 #define TAG_DOMAIN_SERVER ((uint8_t) 6) 108 #define TAG_LOG_SERVER ((uint8_t) 7) 109 #define TAG_COOKIE_SERVER ((uint8_t) 8) 110 #define TAG_LPR_SERVER ((uint8_t) 9) 111 #define TAG_IMPRESS_SERVER ((uint8_t) 10) 112 #define TAG_RLP_SERVER ((uint8_t) 11) 113 #define TAG_HOSTNAME ((uint8_t) 12) 114 #define TAG_BOOTSIZE ((uint8_t) 13) 115 #define TAG_END ((uint8_t) 255) 116 /* RFC1497 tags */ 117 #define TAG_DUMPPATH ((uint8_t) 14) 118 #define TAG_DOMAINNAME ((uint8_t) 15) 119 #define TAG_SWAP_SERVER ((uint8_t) 16) 120 #define TAG_ROOTPATH ((uint8_t) 17) 121 #define TAG_EXTPATH ((uint8_t) 18) 122 /* RFC2132 */ 123 #define TAG_IP_FORWARD ((uint8_t) 19) 124 #define TAG_NL_SRCRT ((uint8_t) 20) 125 #define TAG_PFILTERS ((uint8_t) 21) 126 #define TAG_REASS_SIZE ((uint8_t) 22) 127 #define TAG_DEF_TTL ((uint8_t) 23) 128 #define TAG_MTU_TIMEOUT ((uint8_t) 24) 129 #define TAG_MTU_TABLE ((uint8_t) 25) 130 #define TAG_INT_MTU ((uint8_t) 26) 131 #define TAG_LOCAL_SUBNETS ((uint8_t) 27) 132 #define TAG_BROAD_ADDR ((uint8_t) 28) 133 #define TAG_DO_MASK_DISC ((uint8_t) 29) 134 #define TAG_SUPPLY_MASK ((uint8_t) 30) 135 #define TAG_DO_RDISC ((uint8_t) 31) 136 #define TAG_RTR_SOL_ADDR ((uint8_t) 32) 137 #define TAG_STATIC_ROUTE ((uint8_t) 33) 138 #define TAG_USE_TRAILERS ((uint8_t) 34) 139 #define TAG_ARP_TIMEOUT ((uint8_t) 35) 140 #define TAG_ETH_ENCAP ((uint8_t) 36) 141 #define TAG_TCP_TTL ((uint8_t) 37) 142 #define TAG_TCP_KEEPALIVE ((uint8_t) 38) 143 #define TAG_KEEPALIVE_GO ((uint8_t) 39) 144 #define TAG_NIS_DOMAIN ((uint8_t) 40) 145 #define TAG_NIS_SERVERS ((uint8_t) 41) 146 #define TAG_NTP_SERVERS ((uint8_t) 42) 147 #define TAG_VENDOR_OPTS ((uint8_t) 43) 148 #define TAG_NETBIOS_NS ((uint8_t) 44) 149 #define TAG_NETBIOS_DDS ((uint8_t) 45) 150 #define TAG_NETBIOS_NODE ((uint8_t) 46) 151 #define TAG_NETBIOS_SCOPE ((uint8_t) 47) 152 #define TAG_XWIN_FS ((uint8_t) 48) 153 #define TAG_XWIN_DM ((uint8_t) 49) 154 #define TAG_NIS_P_DOMAIN ((uint8_t) 64) 155 #define TAG_NIS_P_SERVERS ((uint8_t) 65) 156 #define TAG_MOBILE_HOME ((uint8_t) 68) 157 #define TAG_SMPT_SERVER ((uint8_t) 69) 158 #define TAG_POP3_SERVER ((uint8_t) 70) 159 #define TAG_NNTP_SERVER ((uint8_t) 71) 160 #define TAG_WWW_SERVER ((uint8_t) 72) 161 #define TAG_FINGER_SERVER ((uint8_t) 73) 162 #define TAG_IRC_SERVER ((uint8_t) 74) 163 #define TAG_STREETTALK_SRVR ((uint8_t) 75) 164 #define TAG_STREETTALK_STDA ((uint8_t) 76) 165 /* DHCP options */ 166 #define TAG_REQUESTED_IP ((uint8_t) 50) 167 #define TAG_IP_LEASE ((uint8_t) 51) 168 #define TAG_OPT_OVERLOAD ((uint8_t) 52) 169 #define TAG_TFTP_SERVER ((uint8_t) 66) 170 #define TAG_BOOTFILENAME ((uint8_t) 67) 171 #define TAG_DHCP_MESSAGE ((uint8_t) 53) 172 #define TAG_SERVER_ID ((uint8_t) 54) 173 #define TAG_PARM_REQUEST ((uint8_t) 55) 174 #define TAG_MESSAGE ((uint8_t) 56) 175 #define TAG_MAX_MSG_SIZE ((uint8_t) 57) 176 #define TAG_RENEWAL_TIME ((uint8_t) 58) 177 #define TAG_REBIND_TIME ((uint8_t) 59) 178 #define TAG_VENDOR_CLASS ((uint8_t) 60) 179 #define TAG_CLIENT_ID ((uint8_t) 61) 180 /* RFC 2241 */ 181 #define TAG_NDS_SERVERS ((uint8_t) 85) 182 #define TAG_NDS_TREE_NAME ((uint8_t) 86) 183 #define TAG_NDS_CONTEXT ((uint8_t) 87) 184 /* RFC 2242 */ 185 #define TAG_NDS_IPDOMAIN ((uint8_t) 62) 186 #define TAG_NDS_IPINFO ((uint8_t) 63) 187 /* RFC 2485 */ 188 #define TAG_OPEN_GROUP_UAP ((uint8_t) 98) 189 /* RFC 2563 */ 190 #define TAG_DISABLE_AUTOCONF ((uint8_t) 116) 191 /* RFC 2610 */ 192 #define TAG_SLP_DA ((uint8_t) 78) 193 #define TAG_SLP_SCOPE ((uint8_t) 79) 194 /* RFC 2937 */ 195 #define TAG_NS_SEARCH ((uint8_t) 117) 196 /* RFC 3004 - The User Class Option for DHCP */ 197 #define TAG_USER_CLASS ((uint8_t) 77) 198 /* RFC 3011 */ 199 #define TAG_IP4_SUBNET_SELECT ((uint8_t) 118) 200 /* RFC 3442 */ 201 #define TAG_CLASSLESS_STATIC_RT ((uint8_t) 121) 202 #define TAG_CLASSLESS_STA_RT_MS ((uint8_t) 249) 203 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */ 204 #define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150) 205 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */ 206 #define TAG_SLP_NAMING_AUTH ((uint8_t) 80) 207 #define TAG_CLIENT_FQDN ((uint8_t) 81) 208 #define TAG_AGENT_CIRCUIT ((uint8_t) 82) 209 #define TAG_AGENT_REMOTE ((uint8_t) 83) 210 #define TAG_AGENT_MASK ((uint8_t) 84) 211 #define TAG_TZ_STRING ((uint8_t) 88) 212 #define TAG_FQDN_OPTION ((uint8_t) 89) 213 #define TAG_AUTH ((uint8_t) 90) 214 #define TAG_VINES_SERVERS ((uint8_t) 91) 215 #define TAG_SERVER_RANK ((uint8_t) 92) 216 #define TAG_CLIENT_ARCH ((uint8_t) 93) 217 #define TAG_CLIENT_NDI ((uint8_t) 94) 218 #define TAG_CLIENT_GUID ((uint8_t) 97) 219 #define TAG_LDAP_URL ((uint8_t) 95) 220 #define TAG_6OVER4 ((uint8_t) 96) 221 #define TAG_PRINTER_NAME ((uint8_t) 100) 222 #define TAG_MDHCP_SERVER ((uint8_t) 101) 223 #define TAG_IPX_COMPAT ((uint8_t) 110) 224 #define TAG_NETINFO_PARENT ((uint8_t) 112) 225 #define TAG_NETINFO_PARENT_TAG ((uint8_t) 113) 226 #define TAG_URL ((uint8_t) 114) 227 #define TAG_FAILOVER ((uint8_t) 115) 228 #define TAG_EXTENDED_REQUEST ((uint8_t) 126) 229 #define TAG_EXTENDED_OPTION ((uint8_t) 127) 230 231 /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */ 232 #define DHCPDISCOVER 1 233 #define DHCPOFFER 2 234 #define DHCPREQUEST 3 235 #define DHCPDECLINE 4 236 #define DHCPACK 5 237 #define DHCPNAK 6 238 #define DHCPRELEASE 7 239 #define DHCPINFORM 8 240 241 /* 242 * "vendor" data permitted for CMU bootp clients. 243 */ 244 245 struct cmu_vend { 246 uint8_t v_magic[4]; /* magic number */ 247 uint32_t v_flags; /* flags/opcodes, etc. */ 248 struct in_addr v_smask; /* Subnet mask */ 249 struct in_addr v_dgate; /* Default gateway */ 250 struct in_addr v_dns1, v_dns2; /* Domain name servers */ 251 struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */ 252 struct in_addr v_ts1, v_ts2; /* Time servers */ 253 uint8_t v_unused[24]; /* currently unused */ 254 } UNALIGNED; 255 256 257 /* v_flags values */ 258 #define VF_SMASK 1 /* Subnet mask field contains valid data */ 259 260 /* RFC 4702 DHCP Client FQDN Option */ 261 262 #define CLIENT_FQDN_FLAGS_S 0x01 263 #define CLIENT_FQDN_FLAGS_O 0x02 264 #define CLIENT_FQDN_FLAGS_E 0x04 265 #define CLIENT_FQDN_FLAGS_N 0x08 266 /* end of original bootp.h */ 267 268 static void rfc1048_print(netdissect_options *, const u_char *); 269 static void cmu_print(netdissect_options *, const u_char *); 270 static char *client_fqdn_flags(u_int flags); 271 272 static const struct tok bootp_flag_values[] = { 273 { 0x8000, "Broadcast" }, 274 { 0, NULL} 275 }; 276 277 static const struct tok bootp_op_values[] = { 278 { BOOTPREQUEST, "Request" }, 279 { BOOTPREPLY, "Reply" }, 280 { 0, NULL} 281 }; 282 283 /* 284 * Print bootp requests 285 */ 286 void 287 bootp_print(netdissect_options *ndo, 288 register const u_char *cp, u_int length) 289 { 290 register const struct bootp *bp; 291 static const u_char vm_cmu[4] = VM_CMU; 292 static const u_char vm_rfc1048[4] = VM_RFC1048; 293 294 bp = (const struct bootp *)cp; 295 ND_TCHECK(bp->bp_op); 296 297 ND_PRINT((ndo, "BOOTP/DHCP, %s", 298 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op))); 299 300 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) { 301 ND_TCHECK2(bp->bp_chaddr[0], 6); 302 ND_PRINT((ndo, " from %s", etheraddr_string(ndo, bp->bp_chaddr))); 303 } 304 305 ND_PRINT((ndo, ", length %u", length)); 306 307 if (!ndo->ndo_vflag) 308 return; 309 310 ND_TCHECK(bp->bp_secs); 311 312 /* The usual hardware address type is 1 (10Mb Ethernet) */ 313 if (bp->bp_htype != 1) 314 ND_PRINT((ndo, ", htype %d", bp->bp_htype)); 315 316 /* The usual length for 10Mb Ethernet address is 6 bytes */ 317 if (bp->bp_htype != 1 || bp->bp_hlen != 6) 318 ND_PRINT((ndo, ", hlen %d", bp->bp_hlen)); 319 320 /* Only print interesting fields */ 321 if (bp->bp_hops) 322 ND_PRINT((ndo, ", hops %d", bp->bp_hops)); 323 if (EXTRACT_32BITS(&bp->bp_xid)) 324 ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid))); 325 if (EXTRACT_16BITS(&bp->bp_secs)) 326 ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs))); 327 328 ND_PRINT((ndo, ", Flags [%s]", 329 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)))); 330 if (ndo->ndo_vflag > 1) 331 ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags))); 332 333 /* Client's ip address */ 334 ND_TCHECK(bp->bp_ciaddr); 335 if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr)) 336 ND_PRINT((ndo, "\n\t Client-IP %s", ipaddr_string(ndo, &bp->bp_ciaddr))); 337 338 /* 'your' ip address (bootp client) */ 339 ND_TCHECK(bp->bp_yiaddr); 340 if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr)) 341 ND_PRINT((ndo, "\n\t Your-IP %s", ipaddr_string(ndo, &bp->bp_yiaddr))); 342 343 /* Server's ip address */ 344 ND_TCHECK(bp->bp_siaddr); 345 if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr)) 346 ND_PRINT((ndo, "\n\t Server-IP %s", ipaddr_string(ndo, &bp->bp_siaddr))); 347 348 /* Gateway's ip address */ 349 ND_TCHECK(bp->bp_giaddr); 350 if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr)) 351 ND_PRINT((ndo, "\n\t Gateway-IP %s", ipaddr_string(ndo, &bp->bp_giaddr))); 352 353 /* Client's Ethernet address */ 354 if (bp->bp_htype == 1 && bp->bp_hlen == 6) { 355 ND_TCHECK2(bp->bp_chaddr[0], 6); 356 ND_PRINT((ndo, "\n\t Client-Ethernet-Address %s", etheraddr_string(ndo, bp->bp_chaddr))); 357 } 358 359 ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */ 360 if (*bp->bp_sname) { 361 ND_PRINT((ndo, "\n\t sname \"")); 362 if (fn_print(ndo, bp->bp_sname, ndo->ndo_snapend)) { 363 ND_PRINT((ndo, "\"")); 364 ND_PRINT((ndo, "%s", tstr + 1)); 365 return; 366 } 367 ND_PRINT((ndo, "\"")); 368 } 369 ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */ 370 if (*bp->bp_file) { 371 ND_PRINT((ndo, "\n\t file \"")); 372 if (fn_print(ndo, bp->bp_file, ndo->ndo_snapend)) { 373 ND_PRINT((ndo, "\"")); 374 ND_PRINT((ndo, "%s", tstr + 1)); 375 return; 376 } 377 ND_PRINT((ndo, "\"")); 378 } 379 380 /* Decode the vendor buffer */ 381 ND_TCHECK(bp->bp_vend[0]); 382 if (memcmp((const char *)bp->bp_vend, vm_rfc1048, 383 sizeof(uint32_t)) == 0) 384 rfc1048_print(ndo, bp->bp_vend); 385 else if (memcmp((const char *)bp->bp_vend, vm_cmu, 386 sizeof(uint32_t)) == 0) 387 cmu_print(ndo, bp->bp_vend); 388 else { 389 uint32_t ul; 390 391 ul = EXTRACT_32BITS(&bp->bp_vend); 392 if (ul != 0) 393 ND_PRINT((ndo, "\n\t Vendor-#0x%x", ul)); 394 } 395 396 return; 397 trunc: 398 ND_PRINT((ndo, "%s", tstr)); 399 } 400 401 /* 402 * The first character specifies the format to print: 403 * i - ip address (32 bits) 404 * p - ip address pairs (32 bits + 32 bits) 405 * l - long (32 bits) 406 * L - unsigned long (32 bits) 407 * s - short (16 bits) 408 * b - period-seperated decimal bytes (variable length) 409 * x - colon-seperated hex bytes (variable length) 410 * a - ascii string (variable length) 411 * B - on/off (8 bits) 412 * $ - special (explicit code to handle) 413 */ 414 static const struct tok tag2str[] = { 415 /* RFC1048 tags */ 416 { TAG_PAD, " PAD" }, 417 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */ 418 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */ 419 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */ 420 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */ 421 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */ 422 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */ 423 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */ 424 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */ 425 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */ 426 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */ 427 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */ 428 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */ 429 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */ 430 { TAG_END, " END" }, 431 /* RFC1497 tags */ 432 { TAG_DUMPPATH, "aDP" }, 433 { TAG_DOMAINNAME, "aDomain-Name" }, 434 { TAG_SWAP_SERVER, "iSS" }, 435 { TAG_ROOTPATH, "aRP" }, 436 { TAG_EXTPATH, "aEP" }, 437 /* RFC2132 tags */ 438 { TAG_IP_FORWARD, "BIPF" }, 439 { TAG_NL_SRCRT, "BSRT" }, 440 { TAG_PFILTERS, "pPF" }, 441 { TAG_REASS_SIZE, "sRSZ" }, 442 { TAG_DEF_TTL, "bTTL" }, 443 { TAG_MTU_TIMEOUT, "lMTU-Timeout" }, 444 { TAG_MTU_TABLE, "sMTU-Table" }, 445 { TAG_INT_MTU, "sMTU" }, 446 { TAG_LOCAL_SUBNETS, "BLSN" }, 447 { TAG_BROAD_ADDR, "iBR" }, 448 { TAG_DO_MASK_DISC, "BMD" }, 449 { TAG_SUPPLY_MASK, "BMS" }, 450 { TAG_DO_RDISC, "BRouter-Discovery" }, 451 { TAG_RTR_SOL_ADDR, "iRSA" }, 452 { TAG_STATIC_ROUTE, "pStatic-Route" }, 453 { TAG_USE_TRAILERS, "BUT" }, 454 { TAG_ARP_TIMEOUT, "lAT" }, 455 { TAG_ETH_ENCAP, "BIE" }, 456 { TAG_TCP_TTL, "bTT" }, 457 { TAG_TCP_KEEPALIVE, "lKI" }, 458 { TAG_KEEPALIVE_GO, "BKG" }, 459 { TAG_NIS_DOMAIN, "aYD" }, 460 { TAG_NIS_SERVERS, "iYS" }, 461 { TAG_NTP_SERVERS, "iNTP" }, 462 { TAG_VENDOR_OPTS, "bVendor-Option" }, 463 { TAG_NETBIOS_NS, "iNetbios-Name-Server" }, 464 { TAG_NETBIOS_DDS, "iWDD" }, 465 { TAG_NETBIOS_NODE, "$Netbios-Node" }, 466 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" }, 467 { TAG_XWIN_FS, "iXFS" }, 468 { TAG_XWIN_DM, "iXDM" }, 469 { TAG_NIS_P_DOMAIN, "sN+D" }, 470 { TAG_NIS_P_SERVERS, "iN+S" }, 471 { TAG_MOBILE_HOME, "iMH" }, 472 { TAG_SMPT_SERVER, "iSMTP" }, 473 { TAG_POP3_SERVER, "iPOP3" }, 474 { TAG_NNTP_SERVER, "iNNTP" }, 475 { TAG_WWW_SERVER, "iWWW" }, 476 { TAG_FINGER_SERVER, "iFG" }, 477 { TAG_IRC_SERVER, "iIRC" }, 478 { TAG_STREETTALK_SRVR, "iSTS" }, 479 { TAG_STREETTALK_STDA, "iSTDA" }, 480 { TAG_REQUESTED_IP, "iRequested-IP" }, 481 { TAG_IP_LEASE, "lLease-Time" }, 482 { TAG_OPT_OVERLOAD, "$OO" }, 483 { TAG_TFTP_SERVER, "aTFTP" }, 484 { TAG_BOOTFILENAME, "aBF" }, 485 { TAG_DHCP_MESSAGE, " DHCP-Message" }, 486 { TAG_SERVER_ID, "iServer-ID" }, 487 { TAG_PARM_REQUEST, "bParameter-Request" }, 488 { TAG_MESSAGE, "aMSG" }, 489 { TAG_MAX_MSG_SIZE, "sMSZ" }, 490 { TAG_RENEWAL_TIME, "lRN" }, 491 { TAG_REBIND_TIME, "lRB" }, 492 { TAG_VENDOR_CLASS, "aVendor-Class" }, 493 { TAG_CLIENT_ID, "$Client-ID" }, 494 /* RFC 2485 */ 495 { TAG_OPEN_GROUP_UAP, "aUAP" }, 496 /* RFC 2563 */ 497 { TAG_DISABLE_AUTOCONF, "BNOAUTO" }, 498 /* RFC 2610 */ 499 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */ 500 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */ 501 /* RFC 2937 */ 502 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ 503 /* RFC 3004 - The User Class Option for DHCP */ 504 { TAG_USER_CLASS, "$User-Class" }, 505 /* RFC 3011 */ 506 { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, 507 /* RFC 3442 */ 508 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" }, 509 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" }, 510 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */ 511 { TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" }, 512 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */ 513 { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, 514 { TAG_CLIENT_FQDN, "$FQDN" }, 515 { TAG_AGENT_CIRCUIT, "$Agent-Information" }, 516 { TAG_AGENT_REMOTE, "bARMT" }, 517 { TAG_AGENT_MASK, "bAMSK" }, 518 { TAG_TZ_STRING, "aTZSTR" }, 519 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */ 520 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */ 521 { TAG_VINES_SERVERS, "iVINES" }, 522 { TAG_SERVER_RANK, "sRANK" }, 523 { TAG_CLIENT_ARCH, "sARCH" }, 524 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */ 525 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */ 526 { TAG_LDAP_URL, "aLDAP" }, 527 { TAG_6OVER4, "i6o4" }, 528 { TAG_PRINTER_NAME, "aPRTR" }, 529 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */ 530 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */ 531 { TAG_NETINFO_PARENT, "iNI" }, 532 { TAG_NETINFO_PARENT_TAG, "aNITAG" }, 533 { TAG_URL, "aURL" }, 534 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */ 535 { 0, NULL } 536 }; 537 /* 2-byte extended tags */ 538 static const struct tok xtag2str[] = { 539 { 0, NULL } 540 }; 541 542 /* DHCP "options overload" types */ 543 static const struct tok oo2str[] = { 544 { 1, "file" }, 545 { 2, "sname" }, 546 { 3, "file+sname" }, 547 { 0, NULL } 548 }; 549 550 /* NETBIOS over TCP/IP node type options */ 551 static const struct tok nbo2str[] = { 552 { 0x1, "b-node" }, 553 { 0x2, "p-node" }, 554 { 0x4, "m-node" }, 555 { 0x8, "h-node" }, 556 { 0, NULL } 557 }; 558 559 /* ARP Hardware types, for Client-ID option */ 560 static const struct tok arp2str[] = { 561 { 0x1, "ether" }, 562 { 0x6, "ieee802" }, 563 { 0x7, "arcnet" }, 564 { 0xf, "frelay" }, 565 { 0x17, "strip" }, 566 { 0x18, "ieee1394" }, 567 { 0, NULL } 568 }; 569 570 static const struct tok dhcp_msg_values[] = { 571 { DHCPDISCOVER, "Discover" }, 572 { DHCPOFFER, "Offer" }, 573 { DHCPREQUEST, "Request" }, 574 { DHCPDECLINE, "Decline" }, 575 { DHCPACK, "ACK" }, 576 { DHCPNAK, "NACK" }, 577 { DHCPRELEASE, "Release" }, 578 { DHCPINFORM, "Inform" }, 579 { 0, NULL } 580 }; 581 582 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */ 583 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */ 584 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */ 585 static const struct tok agent_suboption_values[] = { 586 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" }, 587 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" }, 588 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" }, 589 { 0, NULL } 590 }; 591 592 593 static void 594 rfc1048_print(netdissect_options *ndo, 595 register const u_char *bp) 596 { 597 register uint16_t tag; 598 register u_int len; 599 register const char *cp; 600 register char c; 601 int first, idx; 602 uint32_t ul; 603 uint16_t us; 604 uint8_t uc, subopt, suboptlen; 605 606 ND_PRINT((ndo, "\n\t Vendor-rfc1048 Extensions")); 607 608 /* Step over magic cookie */ 609 ND_PRINT((ndo, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp))); 610 bp += sizeof(int32_t); 611 612 /* Loop while we there is a tag left in the buffer */ 613 while (ND_TTEST2(*bp, 1)) { 614 tag = *bp++; 615 if (tag == TAG_PAD && ndo->ndo_vflag < 3) 616 continue; 617 if (tag == TAG_END && ndo->ndo_vflag < 3) 618 return; 619 if (tag == TAG_EXTENDED_OPTION) { 620 ND_TCHECK2(*(bp + 1), 2); 621 tag = EXTRACT_16BITS(bp + 1); 622 /* XXX we don't know yet if the IANA will 623 * preclude overlap of 1-byte and 2-byte spaces. 624 * If not, we need to offset tag after this step. 625 */ 626 cp = tok2str(xtag2str, "?xT%u", tag); 627 } else 628 cp = tok2str(tag2str, "?T%u", tag); 629 c = *cp++; 630 631 if (tag == TAG_PAD || tag == TAG_END) 632 len = 0; 633 else { 634 /* Get the length; check for truncation */ 635 ND_TCHECK2(*bp, 1); 636 len = *bp++; 637 } 638 639 ND_PRINT((ndo, "\n\t %s Option %u, length %u%s", cp, tag, len, 640 len > 0 ? ": " : "")); 641 642 if (tag == TAG_PAD && ndo->ndo_vflag > 2) { 643 u_int ntag = 1; 644 while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) { 645 bp++; 646 ntag++; 647 } 648 if (ntag > 1) 649 ND_PRINT((ndo, ", occurs %u", ntag)); 650 } 651 652 if (!ND_TTEST2(*bp, len)) { 653 ND_PRINT((ndo, "[|rfc1048 %u]", len)); 654 return; 655 } 656 657 if (tag == TAG_DHCP_MESSAGE && len == 1) { 658 uc = *bp++; 659 ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc))); 660 continue; 661 } 662 663 if (tag == TAG_PARM_REQUEST) { 664 idx = 0; 665 while (len-- > 0) { 666 uc = *bp++; 667 cp = tok2str(tag2str, "?Option %u", uc); 668 if (idx % 4 == 0) 669 ND_PRINT((ndo, "\n\t ")); 670 else 671 ND_PRINT((ndo, ", ")); 672 ND_PRINT((ndo, "%s", cp + 1)); 673 idx++; 674 } 675 continue; 676 } 677 678 if (tag == TAG_EXTENDED_REQUEST) { 679 first = 1; 680 while (len > 1) { 681 len -= 2; 682 us = EXTRACT_16BITS(bp); 683 bp += 2; 684 cp = tok2str(xtag2str, "?xT%u", us); 685 if (!first) 686 ND_PRINT((ndo, "+")); 687 ND_PRINT((ndo, "%s", cp + 1)); 688 first = 0; 689 } 690 continue; 691 } 692 693 /* Print data */ 694 if (c == '?') { 695 /* Base default formats for unknown tags on data size */ 696 if (len & 1) 697 c = 'b'; 698 else if (len & 2) 699 c = 's'; 700 else 701 c = 'l'; 702 } 703 first = 1; 704 switch (c) { 705 706 case 'a': 707 /* ascii strings */ 708 ND_PRINT((ndo, "\"")); 709 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { 710 ND_PRINT((ndo, "\"")); 711 goto trunc; 712 } 713 ND_PRINT((ndo, "\"")); 714 bp += len; 715 len = 0; 716 break; 717 718 case 'i': 719 case 'l': 720 case 'L': 721 /* ip addresses/32-bit words */ 722 while (len >= sizeof(ul)) { 723 if (!first) 724 ND_PRINT((ndo, ",")); 725 ul = EXTRACT_32BITS(bp); 726 if (c == 'i') { 727 ul = htonl(ul); 728 ND_PRINT((ndo, "%s", ipaddr_string(ndo, &ul))); 729 } else if (c == 'L') 730 ND_PRINT((ndo, "%d", ul)); 731 else 732 ND_PRINT((ndo, "%u", ul)); 733 bp += sizeof(ul); 734 len -= sizeof(ul); 735 first = 0; 736 } 737 break; 738 739 case 'p': 740 /* IP address pairs */ 741 while (len >= 2*sizeof(ul)) { 742 if (!first) 743 ND_PRINT((ndo, ",")); 744 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 745 ND_PRINT((ndo, "(%s:", ipaddr_string(ndo, &ul))); 746 bp += sizeof(ul); 747 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 748 ND_PRINT((ndo, "%s)", ipaddr_string(ndo, &ul))); 749 bp += sizeof(ul); 750 len -= 2*sizeof(ul); 751 first = 0; 752 } 753 break; 754 755 case 's': 756 /* shorts */ 757 while (len >= sizeof(us)) { 758 if (!first) 759 ND_PRINT((ndo, ",")); 760 us = EXTRACT_16BITS(bp); 761 ND_PRINT((ndo, "%u", us)); 762 bp += sizeof(us); 763 len -= sizeof(us); 764 first = 0; 765 } 766 break; 767 768 case 'B': 769 /* boolean */ 770 while (len > 0) { 771 if (!first) 772 ND_PRINT((ndo, ",")); 773 switch (*bp) { 774 case 0: 775 ND_PRINT((ndo, "N")); 776 break; 777 case 1: 778 ND_PRINT((ndo, "Y")); 779 break; 780 default: 781 ND_PRINT((ndo, "%u?", *bp)); 782 break; 783 } 784 ++bp; 785 --len; 786 first = 0; 787 } 788 break; 789 790 case 'b': 791 case 'x': 792 default: 793 /* Bytes */ 794 while (len > 0) { 795 if (!first) 796 ND_PRINT((ndo, c == 'x' ? ":" : ".")); 797 if (c == 'x') 798 ND_PRINT((ndo, "%02x", *bp)); 799 else 800 ND_PRINT((ndo, "%u", *bp)); 801 ++bp; 802 --len; 803 first = 0; 804 } 805 break; 806 807 case '$': 808 /* Guys we can't handle with one of the usual cases */ 809 switch (tag) { 810 811 case TAG_NETBIOS_NODE: 812 /* this option should be at least 1 byte long */ 813 if (len < 1) { 814 ND_PRINT((ndo, "ERROR: length < 1 bytes")); 815 break; 816 } 817 tag = *bp++; 818 --len; 819 ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag))); 820 break; 821 822 case TAG_OPT_OVERLOAD: 823 /* this option should be at least 1 byte long */ 824 if (len < 1) { 825 ND_PRINT((ndo, "ERROR: length < 1 bytes")); 826 break; 827 } 828 tag = *bp++; 829 --len; 830 ND_PRINT((ndo, "%s", tok2str(oo2str, NULL, tag))); 831 break; 832 833 case TAG_CLIENT_FQDN: 834 /* this option should be at least 3 bytes long */ 835 if (len < 3) { 836 ND_PRINT((ndo, "ERROR: length < 3 bytes")); 837 bp += len; 838 len = 0; 839 break; 840 } 841 if (*bp) 842 ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp))); 843 bp++; 844 if (*bp || *(bp+1)) 845 ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1))); 846 bp += 2; 847 ND_PRINT((ndo, "\"")); 848 if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) { 849 ND_PRINT((ndo, "\"")); 850 goto trunc; 851 } 852 ND_PRINT((ndo, "\"")); 853 bp += len - 3; 854 len = 0; 855 break; 856 857 case TAG_CLIENT_ID: 858 { 859 int type; 860 861 /* this option should be at least 1 byte long */ 862 if (len < 1) { 863 ND_PRINT((ndo, "ERROR: length < 1 bytes")); 864 break; 865 } 866 type = *bp++; 867 len--; 868 if (type == 0) { 869 ND_PRINT((ndo, "\"")); 870 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) { 871 ND_PRINT((ndo, "\"")); 872 goto trunc; 873 } 874 ND_PRINT((ndo, "\"")); 875 bp += len; 876 len = 0; 877 break; 878 } else { 879 ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type))); 880 while (len > 0) { 881 if (!first) 882 ND_PRINT((ndo, ":")); 883 ND_PRINT((ndo, "%02x", *bp)); 884 ++bp; 885 --len; 886 first = 0; 887 } 888 } 889 break; 890 } 891 892 case TAG_AGENT_CIRCUIT: 893 while (len >= 2) { 894 subopt = *bp++; 895 suboptlen = *bp++; 896 len -= 2; 897 if (suboptlen > len) { 898 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: length goes past end of option", 899 tok2str(agent_suboption_values, "Unknown", subopt), 900 subopt, 901 suboptlen)); 902 bp += len; 903 len = 0; 904 break; 905 } 906 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: ", 907 tok2str(agent_suboption_values, "Unknown", subopt), 908 subopt, 909 suboptlen)); 910 switch (subopt) { 911 912 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */ 913 case AGENT_SUBOPTION_REMOTE_ID: 914 case AGENT_SUBOPTION_SUBSCRIBER_ID: 915 if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) 916 goto trunc; 917 break; 918 919 default: 920 print_unknown_data(ndo, bp, "\n\t\t", suboptlen); 921 } 922 923 len -= suboptlen; 924 bp += suboptlen; 925 } 926 break; 927 928 case TAG_CLASSLESS_STATIC_RT: 929 case TAG_CLASSLESS_STA_RT_MS: 930 { 931 u_int mask_width, significant_octets, i; 932 933 /* this option should be at least 5 bytes long */ 934 if (len < 5) { 935 ND_PRINT((ndo, "ERROR: length < 5 bytes")); 936 bp += len; 937 len = 0; 938 break; 939 } 940 while (len > 0) { 941 if (!first) 942 ND_PRINT((ndo, ",")); 943 mask_width = *bp++; 944 len--; 945 /* mask_width <= 32 */ 946 if (mask_width > 32) { 947 ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width)); 948 bp += len; 949 len = 0; 950 break; 951 } 952 significant_octets = (mask_width + 7) / 8; 953 /* significant octets + router(4) */ 954 if (len < significant_octets + 4) { 955 ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4)); 956 bp += len; 957 len = 0; 958 break; 959 } 960 ND_PRINT((ndo, "(")); 961 if (mask_width == 0) 962 ND_PRINT((ndo, "default")); 963 else { 964 for (i = 0; i < significant_octets ; i++) { 965 if (i > 0) 966 ND_PRINT((ndo, ".")); 967 ND_PRINT((ndo, "%d", *bp++)); 968 } 969 for (i = significant_octets ; i < 4 ; i++) 970 ND_PRINT((ndo, ".0")); 971 ND_PRINT((ndo, "/%d", mask_width)); 972 } 973 memcpy((char *)&ul, (const char *)bp, sizeof(ul)); 974 ND_PRINT((ndo, ":%s)", ipaddr_string(ndo, &ul))); 975 bp += sizeof(ul); 976 len -= (significant_octets + 4); 977 first = 0; 978 } 979 break; 980 } 981 982 case TAG_USER_CLASS: 983 { 984 u_int suboptnumber = 1; 985 986 first = 1; 987 if (len < 2) { 988 ND_PRINT((ndo, "ERROR: length < 2 bytes")); 989 bp += len; 990 len = 0; 991 break; 992 } 993 while (len > 0) { 994 suboptlen = *bp++; 995 len--; 996 ND_PRINT((ndo, "\n\t ")); 997 ND_PRINT((ndo, "instance#%u: ", suboptnumber)); 998 if (suboptlen == 0) { 999 ND_PRINT((ndo, "ERROR: suboption length must be non-zero")); 1000 bp += len; 1001 len = 0; 1002 break; 1003 } 1004 if (len < suboptlen) { 1005 ND_PRINT((ndo, "ERROR: malformed option")); 1006 bp += len; 1007 len = 0; 1008 break; 1009 } 1010 ND_PRINT((ndo, "\"")); 1011 if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) { 1012 ND_PRINT((ndo, "\"")); 1013 goto trunc; 1014 } 1015 ND_PRINT((ndo, "\"")); 1016 ND_PRINT((ndo, ", length %d", suboptlen)); 1017 suboptnumber++; 1018 len -= suboptlen; 1019 bp += suboptlen; 1020 } 1021 break; 1022 } 1023 1024 default: 1025 ND_PRINT((ndo, "[unknown special tag %u, size %u]", 1026 tag, len)); 1027 bp += len; 1028 len = 0; 1029 break; 1030 } 1031 break; 1032 } 1033 /* Data left over? */ 1034 if (len) { 1035 ND_PRINT((ndo, "\n\t trailing data length %u", len)); 1036 bp += len; 1037 } 1038 } 1039 return; 1040 trunc: 1041 ND_PRINT((ndo, "|[rfc1048]")); 1042 } 1043 1044 static void 1045 cmu_print(netdissect_options *ndo, 1046 register const u_char *bp) 1047 { 1048 register const struct cmu_vend *cmu; 1049 1050 #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \ 1051 if (cmu->m.s_addr != 0) \ 1052 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); } 1053 1054 ND_PRINT((ndo, " vend-cmu")); 1055 cmu = (const struct cmu_vend *)bp; 1056 1057 /* Only print if there are unknown bits */ 1058 ND_TCHECK(cmu->v_flags); 1059 if ((cmu->v_flags & ~(VF_SMASK)) != 0) 1060 ND_PRINT((ndo, " F:0x%x", cmu->v_flags)); 1061 PRINTCMUADDR(v_dgate, "DG"); 1062 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*"); 1063 PRINTCMUADDR(v_dns1, "NS1"); 1064 PRINTCMUADDR(v_dns2, "NS2"); 1065 PRINTCMUADDR(v_ins1, "IEN1"); 1066 PRINTCMUADDR(v_ins2, "IEN2"); 1067 PRINTCMUADDR(v_ts1, "TS1"); 1068 PRINTCMUADDR(v_ts2, "TS2"); 1069 return; 1070 1071 trunc: 1072 ND_PRINT((ndo, "%s", tstr)); 1073 #undef PRINTCMUADDR 1074 } 1075 1076 static char * 1077 client_fqdn_flags(u_int flags) 1078 { 1079 static char buf[8+1]; 1080 int i = 0; 1081 1082 if (flags & CLIENT_FQDN_FLAGS_S) 1083 buf[i++] = 'S'; 1084 if (flags & CLIENT_FQDN_FLAGS_O) 1085 buf[i++] = 'O'; 1086 if (flags & CLIENT_FQDN_FLAGS_E) 1087 buf[i++] = 'E'; 1088 if (flags & CLIENT_FQDN_FLAGS_N) 1089 buf[i++] = 'N'; 1090 buf[i] = '\0'; 1091 1092 return buf; 1093 } 1094