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