2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * Format and print bootp packets.
28 #include <tcpdump-stdinc.h>
32 #include "netdissect.h"
33 #include "addrtoname.h"
36 static const char tstr
[] = " [|bootp]";
39 * Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
41 * This file specifies the "implementation-independent" BOOTP protocol
42 * information which is common to both client and server.
44 * Copyright 1988 by Carnegie Mellon.
46 * Permission to use, copy, modify, and distribute this program for any
47 * purpose and without fee is hereby granted, provided that this copyright
48 * and permission notice appear on all copies and supporting documentation,
49 * the name of Carnegie Mellon not be used in advertising or publicity
50 * pertaining to distribution of the program without specific prior
51 * permission, and notice be given in supporting documentation that copying
52 * and distribution is by permission of Carnegie Mellon and Stanford
53 * University. Carnegie Mellon makes no representations about the
54 * suitability of this software for any purpose. It is provided "as is"
55 * without express or implied warranty.
59 uint8_t bp_op
; /* packet opcode type */
60 uint8_t bp_htype
; /* hardware addr type */
61 uint8_t bp_hlen
; /* hardware addr length */
62 uint8_t bp_hops
; /* gateway hops */
63 uint32_t bp_xid
; /* transaction ID */
64 uint16_t bp_secs
; /* seconds since boot began */
65 uint16_t bp_flags
; /* flags - see bootp_flag_values[]
67 struct in_addr bp_ciaddr
; /* client IP address */
68 struct in_addr bp_yiaddr
; /* 'your' IP address */
69 struct in_addr bp_siaddr
; /* server IP address */
70 struct in_addr bp_giaddr
; /* gateway IP address */
71 uint8_t bp_chaddr
[16]; /* client hardware address */
72 uint8_t bp_sname
[64]; /* server host name */
73 uint8_t bp_file
[128]; /* boot file name */
74 uint8_t bp_vend
[64]; /* vendor-specific area */
78 #define BOOTPREQUEST 1
81 * Vendor magic cookie (v_magic) for CMU
86 * Vendor magic cookie (v_magic) for RFC1048
88 #define VM_RFC1048 { 99, 130, 83, 99 }
91 * RFC1048 tag values used to specify what information is being supplied in
92 * the vendor field of the packet.
95 #define TAG_PAD ((uint8_t) 0)
96 #define TAG_SUBNET_MASK ((uint8_t) 1)
97 #define TAG_TIME_OFFSET ((uint8_t) 2)
98 #define TAG_GATEWAY ((uint8_t) 3)
99 #define TAG_TIME_SERVER ((uint8_t) 4)
100 #define TAG_NAME_SERVER ((uint8_t) 5)
101 #define TAG_DOMAIN_SERVER ((uint8_t) 6)
102 #define TAG_LOG_SERVER ((uint8_t) 7)
103 #define TAG_COOKIE_SERVER ((uint8_t) 8)
104 #define TAG_LPR_SERVER ((uint8_t) 9)
105 #define TAG_IMPRESS_SERVER ((uint8_t) 10)
106 #define TAG_RLP_SERVER ((uint8_t) 11)
107 #define TAG_HOSTNAME ((uint8_t) 12)
108 #define TAG_BOOTSIZE ((uint8_t) 13)
109 #define TAG_END ((uint8_t) 255)
111 #define TAG_DUMPPATH ((uint8_t) 14)
112 #define TAG_DOMAINNAME ((uint8_t) 15)
113 #define TAG_SWAP_SERVER ((uint8_t) 16)
114 #define TAG_ROOTPATH ((uint8_t) 17)
115 #define TAG_EXTPATH ((uint8_t) 18)
117 #define TAG_IP_FORWARD ((uint8_t) 19)
118 #define TAG_NL_SRCRT ((uint8_t) 20)
119 #define TAG_PFILTERS ((uint8_t) 21)
120 #define TAG_REASS_SIZE ((uint8_t) 22)
121 #define TAG_DEF_TTL ((uint8_t) 23)
122 #define TAG_MTU_TIMEOUT ((uint8_t) 24)
123 #define TAG_MTU_TABLE ((uint8_t) 25)
124 #define TAG_INT_MTU ((uint8_t) 26)
125 #define TAG_LOCAL_SUBNETS ((uint8_t) 27)
126 #define TAG_BROAD_ADDR ((uint8_t) 28)
127 #define TAG_DO_MASK_DISC ((uint8_t) 29)
128 #define TAG_SUPPLY_MASK ((uint8_t) 30)
129 #define TAG_DO_RDISC ((uint8_t) 31)
130 #define TAG_RTR_SOL_ADDR ((uint8_t) 32)
131 #define TAG_STATIC_ROUTE ((uint8_t) 33)
132 #define TAG_USE_TRAILERS ((uint8_t) 34)
133 #define TAG_ARP_TIMEOUT ((uint8_t) 35)
134 #define TAG_ETH_ENCAP ((uint8_t) 36)
135 #define TAG_TCP_TTL ((uint8_t) 37)
136 #define TAG_TCP_KEEPALIVE ((uint8_t) 38)
137 #define TAG_KEEPALIVE_GO ((uint8_t) 39)
138 #define TAG_NIS_DOMAIN ((uint8_t) 40)
139 #define TAG_NIS_SERVERS ((uint8_t) 41)
140 #define TAG_NTP_SERVERS ((uint8_t) 42)
141 #define TAG_VENDOR_OPTS ((uint8_t) 43)
142 #define TAG_NETBIOS_NS ((uint8_t) 44)
143 #define TAG_NETBIOS_DDS ((uint8_t) 45)
144 #define TAG_NETBIOS_NODE ((uint8_t) 46)
145 #define TAG_NETBIOS_SCOPE ((uint8_t) 47)
146 #define TAG_XWIN_FS ((uint8_t) 48)
147 #define TAG_XWIN_DM ((uint8_t) 49)
148 #define TAG_NIS_P_DOMAIN ((uint8_t) 64)
149 #define TAG_NIS_P_SERVERS ((uint8_t) 65)
150 #define TAG_MOBILE_HOME ((uint8_t) 68)
151 #define TAG_SMPT_SERVER ((uint8_t) 69)
152 #define TAG_POP3_SERVER ((uint8_t) 70)
153 #define TAG_NNTP_SERVER ((uint8_t) 71)
154 #define TAG_WWW_SERVER ((uint8_t) 72)
155 #define TAG_FINGER_SERVER ((uint8_t) 73)
156 #define TAG_IRC_SERVER ((uint8_t) 74)
157 #define TAG_STREETTALK_SRVR ((uint8_t) 75)
158 #define TAG_STREETTALK_STDA ((uint8_t) 76)
160 #define TAG_REQUESTED_IP ((uint8_t) 50)
161 #define TAG_IP_LEASE ((uint8_t) 51)
162 #define TAG_OPT_OVERLOAD ((uint8_t) 52)
163 #define TAG_TFTP_SERVER ((uint8_t) 66)
164 #define TAG_BOOTFILENAME ((uint8_t) 67)
165 #define TAG_DHCP_MESSAGE ((uint8_t) 53)
166 #define TAG_SERVER_ID ((uint8_t) 54)
167 #define TAG_PARM_REQUEST ((uint8_t) 55)
168 #define TAG_MESSAGE ((uint8_t) 56)
169 #define TAG_MAX_MSG_SIZE ((uint8_t) 57)
170 #define TAG_RENEWAL_TIME ((uint8_t) 58)
171 #define TAG_REBIND_TIME ((uint8_t) 59)
172 #define TAG_VENDOR_CLASS ((uint8_t) 60)
173 #define TAG_CLIENT_ID ((uint8_t) 61)
175 #define TAG_NDS_SERVERS ((uint8_t) 85)
176 #define TAG_NDS_TREE_NAME ((uint8_t) 86)
177 #define TAG_NDS_CONTEXT ((uint8_t) 87)
179 #define TAG_NDS_IPDOMAIN ((uint8_t) 62)
180 #define TAG_NDS_IPINFO ((uint8_t) 63)
182 #define TAG_OPEN_GROUP_UAP ((uint8_t) 98)
184 #define TAG_DISABLE_AUTOCONF ((uint8_t) 116)
186 #define TAG_SLP_DA ((uint8_t) 78)
187 #define TAG_SLP_SCOPE ((uint8_t) 79)
189 #define TAG_NS_SEARCH ((uint8_t) 117)
190 /* RFC 3004 - The User Class Option for DHCP */
191 #define TAG_USER_CLASS ((uint8_t) 77)
193 #define TAG_IP4_SUBNET_SELECT ((uint8_t) 118)
195 #define TAG_CLASSLESS_STATIC_RT ((uint8_t) 121)
196 #define TAG_CLASSLESS_STA_RT_MS ((uint8_t) 249)
197 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
198 #define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
199 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
200 #define TAG_SLP_NAMING_AUTH ((uint8_t) 80)
201 #define TAG_CLIENT_FQDN ((uint8_t) 81)
202 #define TAG_AGENT_CIRCUIT ((uint8_t) 82)
203 #define TAG_AGENT_REMOTE ((uint8_t) 83)
204 #define TAG_AGENT_MASK ((uint8_t) 84)
205 #define TAG_TZ_STRING ((uint8_t) 88)
206 #define TAG_FQDN_OPTION ((uint8_t) 89)
207 #define TAG_AUTH ((uint8_t) 90)
208 #define TAG_VINES_SERVERS ((uint8_t) 91)
209 #define TAG_SERVER_RANK ((uint8_t) 92)
210 #define TAG_CLIENT_ARCH ((uint8_t) 93)
211 #define TAG_CLIENT_NDI ((uint8_t) 94)
212 #define TAG_CLIENT_GUID ((uint8_t) 97)
213 #define TAG_LDAP_URL ((uint8_t) 95)
214 #define TAG_6OVER4 ((uint8_t) 96)
215 #define TAG_PRINTER_NAME ((uint8_t) 100)
216 #define TAG_MDHCP_SERVER ((uint8_t) 101)
217 #define TAG_IPX_COMPAT ((uint8_t) 110)
218 #define TAG_NETINFO_PARENT ((uint8_t) 112)
219 #define TAG_NETINFO_PARENT_TAG ((uint8_t) 113)
220 #define TAG_URL ((uint8_t) 114)
221 #define TAG_FAILOVER ((uint8_t) 115)
222 #define TAG_EXTENDED_REQUEST ((uint8_t) 126)
223 #define TAG_EXTENDED_OPTION ((uint8_t) 127)
225 /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
226 #define DHCPDISCOVER 1
228 #define DHCPREQUEST 3
229 #define DHCPDECLINE 4
232 #define DHCPRELEASE 7
236 * "vendor" data permitted for CMU bootp clients.
240 uint8_t v_magic
[4]; /* magic number */
241 uint32_t v_flags
; /* flags/opcodes, etc. */
242 struct in_addr v_smask
; /* Subnet mask */
243 struct in_addr v_dgate
; /* Default gateway */
244 struct in_addr v_dns1
, v_dns2
; /* Domain name servers */
245 struct in_addr v_ins1
, v_ins2
; /* IEN-116 name servers */
246 struct in_addr v_ts1
, v_ts2
; /* Time servers */
247 uint8_t v_unused
[24]; /* currently unused */
252 #define VF_SMASK 1 /* Subnet mask field contains valid data */
254 /* RFC 4702 DHCP Client FQDN Option */
256 #define CLIENT_FQDN_FLAGS_S 0x01
257 #define CLIENT_FQDN_FLAGS_O 0x02
258 #define CLIENT_FQDN_FLAGS_E 0x04
259 #define CLIENT_FQDN_FLAGS_N 0x08
260 /* end of original bootp.h */
262 static void rfc1048_print(netdissect_options
*, const u_char
*);
263 static void cmu_print(netdissect_options
*, const u_char
*);
264 static char *client_fqdn_flags(u_int flags
);
266 static const struct tok bootp_flag_values
[] = {
267 { 0x8000, "Broadcast" },
271 static const struct tok bootp_op_values
[] = {
272 { BOOTPREQUEST
, "Request" },
273 { BOOTPREPLY
, "Reply" },
278 * Print bootp requests
281 bootp_print(netdissect_options
*ndo
,
282 register const u_char
*cp
, u_int length
)
284 register const struct bootp
*bp
;
285 static const u_char vm_cmu
[4] = VM_CMU
;
286 static const u_char vm_rfc1048
[4] = VM_RFC1048
;
288 bp
= (const struct bootp
*)cp
;
289 ND_TCHECK(bp
->bp_op
);
291 ND_PRINT((ndo
, "BOOTP/DHCP, %s",
292 tok2str(bootp_op_values
, "unknown (0x%02x)", bp
->bp_op
)));
294 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6 && bp
->bp_op
== BOOTPREQUEST
) {
295 ND_TCHECK2(bp
->bp_chaddr
[0], 6);
296 ND_PRINT((ndo
, " from %s", etheraddr_string(ndo
, bp
->bp_chaddr
)));
299 ND_PRINT((ndo
, ", length %u", length
));
304 ND_TCHECK(bp
->bp_secs
);
306 /* The usual hardware address type is 1 (10Mb Ethernet) */
307 if (bp
->bp_htype
!= 1)
308 ND_PRINT((ndo
, ", htype %d", bp
->bp_htype
));
310 /* The usual length for 10Mb Ethernet address is 6 bytes */
311 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
312 ND_PRINT((ndo
, ", hlen %d", bp
->bp_hlen
));
314 /* Only print interesting fields */
316 ND_PRINT((ndo
, ", hops %d", bp
->bp_hops
));
317 if (EXTRACT_32BITS(&bp
->bp_xid
))
318 ND_PRINT((ndo
, ", xid 0x%x", EXTRACT_32BITS(&bp
->bp_xid
)));
319 if (EXTRACT_16BITS(&bp
->bp_secs
))
320 ND_PRINT((ndo
, ", secs %d", EXTRACT_16BITS(&bp
->bp_secs
)));
322 ND_PRINT((ndo
, ", Flags [%s]",
323 bittok2str(bootp_flag_values
, "none", EXTRACT_16BITS(&bp
->bp_flags
))));
324 if (ndo
->ndo_vflag
> 1)
325 ND_PRINT((ndo
, " (0x%04x)", EXTRACT_16BITS(&bp
->bp_flags
)));
327 /* Client's ip address */
328 ND_TCHECK(bp
->bp_ciaddr
);
329 if (EXTRACT_32BITS(&bp
->bp_ciaddr
.s_addr
))
330 ND_PRINT((ndo
, "\n\t Client-IP %s", ipaddr_string(ndo
, &bp
->bp_ciaddr
)));
332 /* 'your' ip address (bootp client) */
333 ND_TCHECK(bp
->bp_yiaddr
);
334 if (EXTRACT_32BITS(&bp
->bp_yiaddr
.s_addr
))
335 ND_PRINT((ndo
, "\n\t Your-IP %s", ipaddr_string(ndo
, &bp
->bp_yiaddr
)));
337 /* Server's ip address */
338 ND_TCHECK(bp
->bp_siaddr
);
339 if (EXTRACT_32BITS(&bp
->bp_siaddr
.s_addr
))
340 ND_PRINT((ndo
, "\n\t Server-IP %s", ipaddr_string(ndo
, &bp
->bp_siaddr
)));
342 /* Gateway's ip address */
343 ND_TCHECK(bp
->bp_giaddr
);
344 if (EXTRACT_32BITS(&bp
->bp_giaddr
.s_addr
))
345 ND_PRINT((ndo
, "\n\t Gateway-IP %s", ipaddr_string(ndo
, &bp
->bp_giaddr
)));
347 /* Client's Ethernet address */
348 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
349 ND_TCHECK2(bp
->bp_chaddr
[0], 6);
350 ND_PRINT((ndo
, "\n\t Client-Ethernet-Address %s", etheraddr_string(ndo
, bp
->bp_chaddr
)));
353 ND_TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
355 ND_PRINT((ndo
, "\n\t sname \""));
356 if (fn_print(ndo
, bp
->bp_sname
, ndo
->ndo_snapend
)) {
357 ND_PRINT((ndo
, "\""));
358 ND_PRINT((ndo
, "%s", tstr
+ 1));
361 ND_PRINT((ndo
, "\""));
363 ND_TCHECK2(bp
->bp_file
[0], 1); /* check first char only */
365 ND_PRINT((ndo
, "\n\t file \""));
366 if (fn_print(ndo
, bp
->bp_file
, ndo
->ndo_snapend
)) {
367 ND_PRINT((ndo
, "\""));
368 ND_PRINT((ndo
, "%s", tstr
+ 1));
371 ND_PRINT((ndo
, "\""));
374 /* Decode the vendor buffer */
375 ND_TCHECK(bp
->bp_vend
[0]);
376 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
377 sizeof(uint32_t)) == 0)
378 rfc1048_print(ndo
, bp
->bp_vend
);
379 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
380 sizeof(uint32_t)) == 0)
381 cmu_print(ndo
, bp
->bp_vend
);
385 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
387 ND_PRINT((ndo
, "\n\t Vendor-#0x%x", ul
));
392 ND_PRINT((ndo
, "%s", tstr
));
396 * The first character specifies the format to print:
397 * i - ip address (32 bits)
398 * p - ip address pairs (32 bits + 32 bits)
400 * L - unsigned long (32 bits)
401 * s - short (16 bits)
402 * b - period-seperated decimal bytes (variable length)
403 * x - colon-seperated hex bytes (variable length)
404 * a - ascii string (variable length)
405 * B - on/off (8 bits)
406 * $ - special (explicit code to handle)
408 static const struct tok tag2str
[] = {
411 { TAG_SUBNET_MASK
, "iSubnet-Mask" }, /* subnet mask (RFC950) */
412 { TAG_TIME_OFFSET
, "LTime-Zone" }, /* seconds from UTC */
413 { TAG_GATEWAY
, "iDefault-Gateway" }, /* default gateway */
414 { TAG_TIME_SERVER
, "iTime-Server" }, /* time servers (RFC868) */
415 { TAG_NAME_SERVER
, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
416 { TAG_DOMAIN_SERVER
, "iDomain-Name-Server" }, /* domain name (RFC1035) */
417 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
418 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
419 { TAG_LPR_SERVER
, "iLPR-Server" }, /* lpr server (RFC1179) */
420 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
421 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
422 { TAG_HOSTNAME
, "aHostname" }, /* ascii hostname */
423 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
426 { TAG_DUMPPATH
, "aDP" },
427 { TAG_DOMAINNAME
, "aDomain-Name" },
428 { TAG_SWAP_SERVER
, "iSS" },
429 { TAG_ROOTPATH
, "aRP" },
430 { TAG_EXTPATH
, "aEP" },
432 { TAG_IP_FORWARD
, "BIPF" },
433 { TAG_NL_SRCRT
, "BSRT" },
434 { TAG_PFILTERS
, "pPF" },
435 { TAG_REASS_SIZE
, "sRSZ" },
436 { TAG_DEF_TTL
, "bTTL" },
437 { TAG_MTU_TIMEOUT
, "lMTU-Timeout" },
438 { TAG_MTU_TABLE
, "sMTU-Table" },
439 { TAG_INT_MTU
, "sMTU" },
440 { TAG_LOCAL_SUBNETS
, "BLSN" },
441 { TAG_BROAD_ADDR
, "iBR" },
442 { TAG_DO_MASK_DISC
, "BMD" },
443 { TAG_SUPPLY_MASK
, "BMS" },
444 { TAG_DO_RDISC
, "BRouter-Discovery" },
445 { TAG_RTR_SOL_ADDR
, "iRSA" },
446 { TAG_STATIC_ROUTE
, "pStatic-Route" },
447 { TAG_USE_TRAILERS
, "BUT" },
448 { TAG_ARP_TIMEOUT
, "lAT" },
449 { TAG_ETH_ENCAP
, "BIE" },
450 { TAG_TCP_TTL
, "bTT" },
451 { TAG_TCP_KEEPALIVE
, "lKI" },
452 { TAG_KEEPALIVE_GO
, "BKG" },
453 { TAG_NIS_DOMAIN
, "aYD" },
454 { TAG_NIS_SERVERS
, "iYS" },
455 { TAG_NTP_SERVERS
, "iNTP" },
456 { TAG_VENDOR_OPTS
, "bVendor-Option" },
457 { TAG_NETBIOS_NS
, "iNetbios-Name-Server" },
458 { TAG_NETBIOS_DDS
, "iWDD" },
459 { TAG_NETBIOS_NODE
, "$Netbios-Node" },
460 { TAG_NETBIOS_SCOPE
, "aNetbios-Scope" },
461 { TAG_XWIN_FS
, "iXFS" },
462 { TAG_XWIN_DM
, "iXDM" },
463 { TAG_NIS_P_DOMAIN
, "sN+D" },
464 { TAG_NIS_P_SERVERS
, "iN+S" },
465 { TAG_MOBILE_HOME
, "iMH" },
466 { TAG_SMPT_SERVER
, "iSMTP" },
467 { TAG_POP3_SERVER
, "iPOP3" },
468 { TAG_NNTP_SERVER
, "iNNTP" },
469 { TAG_WWW_SERVER
, "iWWW" },
470 { TAG_FINGER_SERVER
, "iFG" },
471 { TAG_IRC_SERVER
, "iIRC" },
472 { TAG_STREETTALK_SRVR
, "iSTS" },
473 { TAG_STREETTALK_STDA
, "iSTDA" },
474 { TAG_REQUESTED_IP
, "iRequested-IP" },
475 { TAG_IP_LEASE
, "lLease-Time" },
476 { TAG_OPT_OVERLOAD
, "$OO" },
477 { TAG_TFTP_SERVER
, "aTFTP" },
478 { TAG_BOOTFILENAME
, "aBF" },
479 { TAG_DHCP_MESSAGE
, " DHCP-Message" },
480 { TAG_SERVER_ID
, "iServer-ID" },
481 { TAG_PARM_REQUEST
, "bParameter-Request" },
482 { TAG_MESSAGE
, "aMSG" },
483 { TAG_MAX_MSG_SIZE
, "sMSZ" },
484 { TAG_RENEWAL_TIME
, "lRN" },
485 { TAG_REBIND_TIME
, "lRB" },
486 { TAG_VENDOR_CLASS
, "aVendor-Class" },
487 { TAG_CLIENT_ID
, "$Client-ID" },
489 { TAG_OPEN_GROUP_UAP
, "aUAP" },
491 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
493 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
494 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
496 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
497 /* RFC 3004 - The User Class Option for DHCP */
498 { TAG_USER_CLASS
, "$User-Class" },
500 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
502 { TAG_CLASSLESS_STATIC_RT
, "$Classless-Static-Route" },
503 { TAG_CLASSLESS_STA_RT_MS
, "$Classless-Static-Route-Microsoft" },
504 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
505 { TAG_TFTP_SERVER_ADDRESS
, "iTFTP-Server-Address" },
506 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
507 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
508 { TAG_CLIENT_FQDN
, "$FQDN" },
509 { TAG_AGENT_CIRCUIT
, "$Agent-Information" },
510 { TAG_AGENT_REMOTE
, "bARMT" },
511 { TAG_AGENT_MASK
, "bAMSK" },
512 { TAG_TZ_STRING
, "aTZSTR" },
513 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
514 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
515 { TAG_VINES_SERVERS
, "iVINES" },
516 { TAG_SERVER_RANK
, "sRANK" },
517 { TAG_CLIENT_ARCH
, "sARCH" },
518 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
519 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
520 { TAG_LDAP_URL
, "aLDAP" },
521 { TAG_6OVER4
, "i6o4" },
522 { TAG_PRINTER_NAME
, "aPRTR" },
523 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
524 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
525 { TAG_NETINFO_PARENT
, "iNI" },
526 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
528 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
531 /* 2-byte extended tags */
532 static const struct tok xtag2str
[] = {
536 /* DHCP "options overload" types */
537 static const struct tok oo2str
[] = {
544 /* NETBIOS over TCP/IP node type options */
545 static const struct tok nbo2str
[] = {
553 /* ARP Hardware types, for Client-ID option */
554 static const struct tok arp2str
[] = {
560 { 0x18, "ieee1394" },
564 static const struct tok dhcp_msg_values
[] = {
565 { DHCPDISCOVER
, "Discover" },
566 { DHCPOFFER
, "Offer" },
567 { DHCPREQUEST
, "Request" },
568 { DHCPDECLINE
, "Decline" },
571 { DHCPRELEASE
, "Release" },
572 { DHCPINFORM
, "Inform" },
576 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
577 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
578 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
579 static const struct tok agent_suboption_values
[] = {
580 { AGENT_SUBOPTION_CIRCUIT_ID
, "Circuit-ID" },
581 { AGENT_SUBOPTION_REMOTE_ID
, "Remote-ID" },
582 { AGENT_SUBOPTION_SUBSCRIBER_ID
, "Subscriber-ID" },
588 rfc1048_print(netdissect_options
*ndo
,
589 register const u_char
*bp
)
591 register uint16_t tag
;
593 register const char *cp
;
598 uint8_t uc
, subopt
, suboptlen
;
600 ND_PRINT((ndo
, "\n\t Vendor-rfc1048 Extensions"));
602 /* Step over magic cookie */
603 ND_PRINT((ndo
, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp
)));
604 bp
+= sizeof(int32_t);
606 /* Loop while we there is a tag left in the buffer */
607 while (ND_TTEST2(*bp
, 1)) {
609 if (tag
== TAG_PAD
&& ndo
->ndo_vflag
< 3)
611 if (tag
== TAG_END
&& ndo
->ndo_vflag
< 3)
613 if (tag
== TAG_EXTENDED_OPTION
) {
614 ND_TCHECK2(*(bp
+ 1), 2);
615 tag
= EXTRACT_16BITS(bp
+ 1);
616 /* XXX we don't know yet if the IANA will
617 * preclude overlap of 1-byte and 2-byte spaces.
618 * If not, we need to offset tag after this step.
620 cp
= tok2str(xtag2str
, "?xT%u", tag
);
622 cp
= tok2str(tag2str
, "?T%u", tag
);
625 if (tag
== TAG_PAD
|| tag
== TAG_END
)
628 /* Get the length; check for truncation */
633 ND_PRINT((ndo
, "\n\t %s Option %u, length %u%s", cp
, tag
, len
,
634 len
> 0 ? ": " : ""));
636 if (tag
== TAG_PAD
&& ndo
->ndo_vflag
> 2) {
638 while (ND_TTEST2(*bp
, 1) && *bp
== TAG_PAD
) {
643 ND_PRINT((ndo
, ", occurs %u", ntag
));
646 if (!ND_TTEST2(*bp
, len
)) {
647 ND_PRINT((ndo
, "[|rfc1048 %u]", len
));
651 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
653 ND_PRINT((ndo
, "%s", tok2str(dhcp_msg_values
, "Unknown (%u)", uc
)));
657 if (tag
== TAG_PARM_REQUEST
) {
661 cp
= tok2str(tag2str
, "?Option %u", uc
);
663 ND_PRINT((ndo
, "\n\t "));
665 ND_PRINT((ndo
, ", "));
666 ND_PRINT((ndo
, "%s", cp
+ 1));
672 if (tag
== TAG_EXTENDED_REQUEST
) {
676 us
= EXTRACT_16BITS(bp
);
678 cp
= tok2str(xtag2str
, "?xT%u", us
);
680 ND_PRINT((ndo
, "+"));
681 ND_PRINT((ndo
, "%s", cp
+ 1));
689 /* Base default formats for unknown tags on data size */
702 ND_PRINT((ndo
, "\""));
703 if (fn_printn(ndo
, bp
, len
, ndo
->ndo_snapend
)) {
704 ND_PRINT((ndo
, "\""));
707 ND_PRINT((ndo
, "\""));
715 /* ip addresses/32-bit words */
716 while (len
>= sizeof(ul
)) {
718 ND_PRINT((ndo
, ","));
719 ul
= EXTRACT_32BITS(bp
);
722 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, &ul
)));
724 ND_PRINT((ndo
, "%d", ul
));
726 ND_PRINT((ndo
, "%u", ul
));
734 /* IP address pairs */
735 while (len
>= 2*sizeof(ul
)) {
737 ND_PRINT((ndo
, ","));
738 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
739 ND_PRINT((ndo
, "(%s:", ipaddr_string(ndo
, &ul
)));
741 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
742 ND_PRINT((ndo
, "%s)", ipaddr_string(ndo
, &ul
)));
751 while (len
>= sizeof(us
)) {
753 ND_PRINT((ndo
, ","));
754 us
= EXTRACT_16BITS(bp
);
755 ND_PRINT((ndo
, "%u", us
));
766 ND_PRINT((ndo
, ","));
769 ND_PRINT((ndo
, "N"));
772 ND_PRINT((ndo
, "Y"));
775 ND_PRINT((ndo
, "%u?", *bp
));
790 ND_PRINT((ndo
, c
== 'x' ? ":" : "."));
792 ND_PRINT((ndo
, "%02x", *bp
));
794 ND_PRINT((ndo
, "%u", *bp
));
802 /* Guys we can't handle with one of the usual cases */
805 case TAG_NETBIOS_NODE
:
806 /* this option should be at least 1 byte long */
808 ND_PRINT((ndo
, "ERROR: length < 1 bytes"));
813 ND_PRINT((ndo
, "%s", tok2str(nbo2str
, NULL
, tag
)));
816 case TAG_OPT_OVERLOAD
:
817 /* this option should be at least 1 byte long */
819 ND_PRINT((ndo
, "ERROR: length < 1 bytes"));
824 ND_PRINT((ndo
, "%s", tok2str(oo2str
, NULL
, tag
)));
827 case TAG_CLIENT_FQDN
:
828 /* this option should be at least 3 bytes long */
830 ND_PRINT((ndo
, "ERROR: length < 3 bytes"));
836 ND_PRINT((ndo
, "[%s] ", client_fqdn_flags(*bp
)));
839 ND_PRINT((ndo
, "%u/%u ", *bp
, *(bp
+1)));
841 ND_PRINT((ndo
, "\""));
842 if (fn_printn(ndo
, bp
, len
- 3, ndo
->ndo_snapend
)) {
843 ND_PRINT((ndo
, "\""));
846 ND_PRINT((ndo
, "\""));
855 /* this option should be at least 1 byte long */
857 ND_PRINT((ndo
, "ERROR: length < 1 bytes"));
863 ND_PRINT((ndo
, "\""));
864 if (fn_printn(ndo
, bp
, len
, ndo
->ndo_snapend
)) {
865 ND_PRINT((ndo
, "\""));
868 ND_PRINT((ndo
, "\""));
873 ND_PRINT((ndo
, "%s ", tok2str(arp2str
, "hardware-type %u,", type
)));
876 ND_PRINT((ndo
, ":"));
877 ND_PRINT((ndo
, "%02x", *bp
));
886 case TAG_AGENT_CIRCUIT
:
891 if (suboptlen
> len
) {
892 ND_PRINT((ndo
, "\n\t %s SubOption %u, length %u: length goes past end of option",
893 tok2str(agent_suboption_values
, "Unknown", subopt
),
900 ND_PRINT((ndo
, "\n\t %s SubOption %u, length %u: ",
901 tok2str(agent_suboption_values
, "Unknown", subopt
),
906 case AGENT_SUBOPTION_CIRCUIT_ID
: /* fall through */
907 case AGENT_SUBOPTION_REMOTE_ID
:
908 case AGENT_SUBOPTION_SUBSCRIBER_ID
:
909 if (fn_printn(ndo
, bp
, suboptlen
, ndo
->ndo_snapend
))
914 print_unknown_data(ndo
, bp
, "\n\t\t", suboptlen
);
922 case TAG_CLASSLESS_STATIC_RT
:
923 case TAG_CLASSLESS_STA_RT_MS
:
925 u_int mask_width
, significant_octets
, i
;
927 /* this option should be at least 5 bytes long */
929 ND_PRINT((ndo
, "ERROR: length < 5 bytes"));
936 ND_PRINT((ndo
, ","));
939 /* mask_width <= 32 */
940 if (mask_width
> 32) {
941 ND_PRINT((ndo
, "[ERROR: Mask width (%d) > 32]", mask_width
));
946 significant_octets
= (mask_width
+ 7) / 8;
947 /* significant octets + router(4) */
948 if (len
< significant_octets
+ 4) {
949 ND_PRINT((ndo
, "[ERROR: Remaining length (%u) < %u bytes]", len
, significant_octets
+ 4));
954 ND_PRINT((ndo
, "("));
956 ND_PRINT((ndo
, "default"));
958 for (i
= 0; i
< significant_octets
; i
++) {
960 ND_PRINT((ndo
, "."));
961 ND_PRINT((ndo
, "%d", *bp
++));
963 for (i
= significant_octets
; i
< 4 ; i
++)
964 ND_PRINT((ndo
, ".0"));
965 ND_PRINT((ndo
, "/%d", mask_width
));
967 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
968 ND_PRINT((ndo
, ":%s)", ipaddr_string(ndo
, &ul
)));
970 len
-= (significant_octets
+ 4);
978 u_int suboptnumber
= 1;
982 ND_PRINT((ndo
, "ERROR: length < 2 bytes"));
990 ND_PRINT((ndo
, "\n\t "));
991 ND_PRINT((ndo
, "instance#%u: ", suboptnumber
));
992 if (suboptlen
== 0) {
993 ND_PRINT((ndo
, "ERROR: suboption length must be non-zero"));
998 if (len
< suboptlen
) {
999 ND_PRINT((ndo
, "ERROR: invalid option"));
1004 ND_PRINT((ndo
, "\""));
1005 if (fn_printn(ndo
, bp
, suboptlen
, ndo
->ndo_snapend
)) {
1006 ND_PRINT((ndo
, "\""));
1009 ND_PRINT((ndo
, "\""));
1010 ND_PRINT((ndo
, ", length %d", suboptlen
));
1019 ND_PRINT((ndo
, "[unknown special tag %u, size %u]",
1027 /* Data left over? */
1029 ND_PRINT((ndo
, "\n\t trailing data length %u", len
));
1035 ND_PRINT((ndo
, "|[rfc1048]"));
1039 cmu_print(netdissect_options
*ndo
,
1040 register const u_char
*bp
)
1042 register const struct cmu_vend
*cmu
;
1044 #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \
1045 if (cmu->m.s_addr != 0) \
1046 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); }
1048 ND_PRINT((ndo
, " vend-cmu"));
1049 cmu
= (const struct cmu_vend
*)bp
;
1051 /* Only print if there are unknown bits */
1052 ND_TCHECK(cmu
->v_flags
);
1053 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
1054 ND_PRINT((ndo
, " F:0x%x", cmu
->v_flags
));
1055 PRINTCMUADDR(v_dgate
, "DG");
1056 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
1057 PRINTCMUADDR(v_dns1
, "NS1");
1058 PRINTCMUADDR(v_dns2
, "NS2");
1059 PRINTCMUADDR(v_ins1
, "IEN1");
1060 PRINTCMUADDR(v_ins2
, "IEN2");
1061 PRINTCMUADDR(v_ts1
, "TS1");
1062 PRINTCMUADDR(v_ts2
, "TS2");
1066 ND_PRINT((ndo
, "%s", tstr
));
1071 client_fqdn_flags(u_int flags
)
1073 static char buf
[8+1];
1076 if (flags
& CLIENT_FQDN_FLAGS_S
)
1078 if (flags
& CLIENT_FQDN_FLAGS_O
)
1080 if (flags
& CLIENT_FQDN_FLAGS_E
)
1082 if (flags
& CLIENT_FQDN_FLAGS_N
)