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>
33 #include "interface.h"
34 #include "addrtoname.h"
39 static const char tstr
[] = " [|bootp]";
41 static void rfc1048_print(const u_char
*);
42 static void cmu_print(const u_char
*);
43 static char *client_fqdn_flags(u_int flags
);
45 static const struct tok bootp_flag_values
[] = {
46 { 0x8000, "Broadcast" },
50 static const struct tok bootp_op_values
[] = {
51 { BOOTPREQUEST
, "Request" },
52 { BOOTPREPLY
, "Reply" },
57 * Print bootp requests
60 bootp_print(register const u_char
*cp
, u_int length
)
62 register const struct bootp
*bp
;
63 static const u_char vm_cmu
[4] = VM_CMU
;
64 static const u_char vm_rfc1048
[4] = VM_RFC1048
;
66 bp
= (const struct bootp
*)cp
;
69 printf("BOOTP/DHCP, %s",
70 tok2str(bootp_op_values
, "unknown (0x%02x)", bp
->bp_op
));
72 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6 && bp
->bp_op
== BOOTPREQUEST
) {
73 TCHECK2(bp
->bp_chaddr
[0], 6);
74 printf(" from %s", etheraddr_string(bp
->bp_chaddr
));
77 printf(", length %u", length
);
84 /* The usual hardware address type is 1 (10Mb Ethernet) */
85 if (bp
->bp_htype
!= 1)
86 printf(", htype %d", bp
->bp_htype
);
88 /* The usual length for 10Mb Ethernet address is 6 bytes */
89 if (bp
->bp_htype
!= 1 || bp
->bp_hlen
!= 6)
90 printf(", hlen %d", bp
->bp_hlen
);
92 /* Only print interesting fields */
94 printf(", hops %d", bp
->bp_hops
);
96 printf(", xid 0x%x", EXTRACT_32BITS(&bp
->bp_xid
));
98 printf(", secs %d", EXTRACT_16BITS(&bp
->bp_secs
));
100 printf(", Flags [%s]",
101 bittok2str(bootp_flag_values
, "none", EXTRACT_16BITS(&bp
->bp_flags
)));
103 printf(" (0x%04x)", EXTRACT_16BITS(&bp
->bp_flags
));
105 /* Client's ip address */
106 TCHECK(bp
->bp_ciaddr
);
107 if (bp
->bp_ciaddr
.s_addr
)
108 printf("\n\t Client-IP %s", ipaddr_string(&bp
->bp_ciaddr
));
110 /* 'your' ip address (bootp client) */
111 TCHECK(bp
->bp_yiaddr
);
112 if (bp
->bp_yiaddr
.s_addr
)
113 printf("\n\t Your-IP %s", ipaddr_string(&bp
->bp_yiaddr
));
115 /* Server's ip address */
116 TCHECK(bp
->bp_siaddr
);
117 if (bp
->bp_siaddr
.s_addr
)
118 printf("\n\t Server-IP %s", ipaddr_string(&bp
->bp_siaddr
));
120 /* Gateway's ip address */
121 TCHECK(bp
->bp_giaddr
);
122 if (bp
->bp_giaddr
.s_addr
)
123 printf("\n\t Gateway-IP %s", ipaddr_string(&bp
->bp_giaddr
));
125 /* Client's Ethernet address */
126 if (bp
->bp_htype
== 1 && bp
->bp_hlen
== 6) {
127 TCHECK2(bp
->bp_chaddr
[0], 6);
128 printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp
->bp_chaddr
));
131 TCHECK2(bp
->bp_sname
[0], 1); /* check first char only */
133 printf("\n\t sname \"");
134 if (fn_print(bp
->bp_sname
, snapend
)) {
136 fputs(tstr
+ 1, stdout
);
141 TCHECK2(bp
->bp_file
[0], 1); /* check first char only */
143 printf("\n\t file \"");
144 if (fn_print(bp
->bp_file
, snapend
)) {
146 fputs(tstr
+ 1, stdout
);
152 /* Decode the vendor buffer */
153 TCHECK(bp
->bp_vend
[0]);
154 if (memcmp((const char *)bp
->bp_vend
, vm_rfc1048
,
155 sizeof(u_int32_t
)) == 0)
156 rfc1048_print(bp
->bp_vend
);
157 else if (memcmp((const char *)bp
->bp_vend
, vm_cmu
,
158 sizeof(u_int32_t
)) == 0)
159 cmu_print(bp
->bp_vend
);
163 ul
= EXTRACT_32BITS(&bp
->bp_vend
);
165 printf("\n\t Vendor-#0x%x", ul
);
174 * The first character specifies the format to print:
175 * i - ip address (32 bits)
176 * p - ip address pairs (32 bits + 32 bits)
178 * L - unsigned long (32 bits)
179 * s - short (16 bits)
180 * b - period-seperated decimal bytes (variable length)
181 * x - colon-seperated hex bytes (variable length)
182 * a - ascii string (variable length)
183 * B - on/off (8 bits)
184 * $ - special (explicit code to handle)
186 static const struct tok tag2str
[] = {
189 { TAG_SUBNET_MASK
, "iSubnet-Mask" }, /* subnet mask (RFC950) */
190 { TAG_TIME_OFFSET
, "LTime-Zone" }, /* seconds from UTC */
191 { TAG_GATEWAY
, "iDefault-Gateway" }, /* default gateway */
192 { TAG_TIME_SERVER
, "iTime-Server" }, /* time servers (RFC868) */
193 { TAG_NAME_SERVER
, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
194 { TAG_DOMAIN_SERVER
, "iDomain-Name-Server" }, /* domain name (RFC1035) */
195 { TAG_LOG_SERVER
, "iLOG" }, /* MIT log servers */
196 { TAG_COOKIE_SERVER
, "iCS" }, /* cookie servers (RFC865) */
197 { TAG_LPR_SERVER
, "iLPR-Server" }, /* lpr server (RFC1179) */
198 { TAG_IMPRESS_SERVER
, "iIM" }, /* impress servers (Imagen) */
199 { TAG_RLP_SERVER
, "iRL" }, /* resource location (RFC887) */
200 { TAG_HOSTNAME
, "aHostname" }, /* ascii hostname */
201 { TAG_BOOTSIZE
, "sBS" }, /* 512 byte blocks */
204 { TAG_DUMPPATH
, "aDP" },
205 { TAG_DOMAINNAME
, "aDomain-Name" },
206 { TAG_SWAP_SERVER
, "iSS" },
207 { TAG_ROOTPATH
, "aRP" },
208 { TAG_EXTPATH
, "aEP" },
210 { TAG_IP_FORWARD
, "BIPF" },
211 { TAG_NL_SRCRT
, "BSRT" },
212 { TAG_PFILTERS
, "pPF" },
213 { TAG_REASS_SIZE
, "sRSZ" },
214 { TAG_DEF_TTL
, "bTTL" },
215 { TAG_MTU_TIMEOUT
, "lMTU-Timeout" },
216 { TAG_MTU_TABLE
, "sMTU-Table" },
217 { TAG_INT_MTU
, "sMTU" },
218 { TAG_LOCAL_SUBNETS
, "BLSN" },
219 { TAG_BROAD_ADDR
, "iBR" },
220 { TAG_DO_MASK_DISC
, "BMD" },
221 { TAG_SUPPLY_MASK
, "BMS" },
222 { TAG_DO_RDISC
, "BRouter-Discovery" },
223 { TAG_RTR_SOL_ADDR
, "iRSA" },
224 { TAG_STATIC_ROUTE
, "pStatic-Route" },
225 { TAG_USE_TRAILERS
, "BUT" },
226 { TAG_ARP_TIMEOUT
, "lAT" },
227 { TAG_ETH_ENCAP
, "BIE" },
228 { TAG_TCP_TTL
, "bTT" },
229 { TAG_TCP_KEEPALIVE
, "lKI" },
230 { TAG_KEEPALIVE_GO
, "BKG" },
231 { TAG_NIS_DOMAIN
, "aYD" },
232 { TAG_NIS_SERVERS
, "iYS" },
233 { TAG_NTP_SERVERS
, "iNTP" },
234 { TAG_VENDOR_OPTS
, "bVendor-Option" },
235 { TAG_NETBIOS_NS
, "iNetbios-Name-Server" },
236 { TAG_NETBIOS_DDS
, "iWDD" },
237 { TAG_NETBIOS_NODE
, "$Netbios-Node" },
238 { TAG_NETBIOS_SCOPE
, "aNetbios-Scope" },
239 { TAG_XWIN_FS
, "iXFS" },
240 { TAG_XWIN_DM
, "iXDM" },
241 { TAG_NIS_P_DOMAIN
, "sN+D" },
242 { TAG_NIS_P_SERVERS
, "iN+S" },
243 { TAG_MOBILE_HOME
, "iMH" },
244 { TAG_SMPT_SERVER
, "iSMTP" },
245 { TAG_POP3_SERVER
, "iPOP3" },
246 { TAG_NNTP_SERVER
, "iNNTP" },
247 { TAG_WWW_SERVER
, "iWWW" },
248 { TAG_FINGER_SERVER
, "iFG" },
249 { TAG_IRC_SERVER
, "iIRC" },
250 { TAG_STREETTALK_SRVR
, "iSTS" },
251 { TAG_STREETTALK_STDA
, "iSTDA" },
252 { TAG_REQUESTED_IP
, "iRequested-IP" },
253 { TAG_IP_LEASE
, "lLease-Time" },
254 { TAG_OPT_OVERLOAD
, "$OO" },
255 { TAG_TFTP_SERVER
, "aTFTP" },
256 { TAG_BOOTFILENAME
, "aBF" },
257 { TAG_DHCP_MESSAGE
, " DHCP-Message" },
258 { TAG_SERVER_ID
, "iServer-ID" },
259 { TAG_PARM_REQUEST
, "bParameter-Request" },
260 { TAG_MESSAGE
, "aMSG" },
261 { TAG_MAX_MSG_SIZE
, "sMSZ" },
262 { TAG_RENEWAL_TIME
, "lRN" },
263 { TAG_REBIND_TIME
, "lRB" },
264 { TAG_VENDOR_CLASS
, "aVendor-Class" },
265 { TAG_CLIENT_ID
, "$Client-ID" },
267 { TAG_OPEN_GROUP_UAP
, "aUAP" },
269 { TAG_DISABLE_AUTOCONF
, "BNOAUTO" },
271 { TAG_SLP_DA
, "bSLP-DA" }, /*"b" is a little wrong */
272 { TAG_SLP_SCOPE
, "bSLP-SCOPE" }, /*"b" is a little wrong */
274 { TAG_NS_SEARCH
, "sNSSEARCH" }, /* XXX 's' */
276 { TAG_IP4_SUBNET_SELECT
, "iSUBNET" },
278 { TAG_CLASSLESS_STATIC_RT
, "$Classless-Static-Route" },
279 { TAG_CLASSLESS_STA_RT_MS
, "$Classless-Static-Route-Microsoft" },
280 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
281 { TAG_USER_CLASS
, "aCLASS" },
282 { TAG_SLP_NAMING_AUTH
, "aSLP-NA" },
283 { TAG_CLIENT_FQDN
, "$FQDN" },
284 { TAG_AGENT_CIRCUIT
, "$Agent-Information" },
285 { TAG_AGENT_REMOTE
, "bARMT" },
286 { TAG_AGENT_MASK
, "bAMSK" },
287 { TAG_TZ_STRING
, "aTZSTR" },
288 { TAG_FQDN_OPTION
, "bFQDNS" }, /* XXX 'b' */
289 { TAG_AUTH
, "bAUTH" }, /* XXX 'b' */
290 { TAG_VINES_SERVERS
, "iVINES" },
291 { TAG_SERVER_RANK
, "sRANK" },
292 { TAG_CLIENT_ARCH
, "sARCH" },
293 { TAG_CLIENT_NDI
, "bNDI" }, /* XXX 'b' */
294 { TAG_CLIENT_GUID
, "bGUID" }, /* XXX 'b' */
295 { TAG_LDAP_URL
, "aLDAP" },
296 { TAG_6OVER4
, "i6o4" },
297 { TAG_PRINTER_NAME
, "aPRTR" },
298 { TAG_MDHCP_SERVER
, "bMDHCP" }, /* XXX 'b' */
299 { TAG_IPX_COMPAT
, "bIPX" }, /* XXX 'b' */
300 { TAG_NETINFO_PARENT
, "iNI" },
301 { TAG_NETINFO_PARENT_TAG
, "aNITAG" },
303 { TAG_FAILOVER
, "bFAIL" }, /* XXX 'b' */
306 /* 2-byte extended tags */
307 static const struct tok xtag2str
[] = {
311 /* DHCP "options overload" types */
312 static const struct tok oo2str
[] = {
319 /* NETBIOS over TCP/IP node type options */
320 static const struct tok nbo2str
[] = {
328 /* ARP Hardware types, for Client-ID option */
329 static const struct tok arp2str
[] = {
335 { 0x18, "ieee1394" },
339 static const struct tok dhcp_msg_values
[] = {
340 { DHCPDISCOVER
, "Discover" },
341 { DHCPOFFER
, "Offer" },
342 { DHCPREQUEST
, "Request" },
343 { DHCPDECLINE
, "Decline" },
346 { DHCPRELEASE
, "Release" },
347 { DHCPINFORM
, "Inform" },
351 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
352 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
353 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
354 static const struct tok agent_suboption_values
[] = {
355 { AGENT_SUBOPTION_CIRCUIT_ID
, "Circuit-ID" },
356 { AGENT_SUBOPTION_REMOTE_ID
, "Remote-ID" },
357 { AGENT_SUBOPTION_SUBSCRIBER_ID
, "Subscriber-ID" },
363 rfc1048_print(register const u_char
*bp
)
365 register u_int16_t tag
;
367 register const char *cp
;
372 u_int8_t uc
, subopt
, suboptlen
;
374 printf("\n\t Vendor-rfc1048 Extensions");
376 /* Step over magic cookie */
377 printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp
));
378 bp
+= sizeof(int32_t);
380 /* Loop while we there is a tag left in the buffer */
381 while (TTEST2(*bp
, 1)) {
383 if (tag
== TAG_PAD
&& vflag
< 3)
385 if (tag
== TAG_END
&& vflag
< 3)
387 if (tag
== TAG_EXTENDED_OPTION
) {
388 TCHECK2(*(bp
+ 1), 2);
389 tag
= EXTRACT_16BITS(bp
+ 1);
390 /* XXX we don't know yet if the IANA will
391 * preclude overlap of 1-byte and 2-byte spaces.
392 * If not, we need to offset tag after this step.
394 cp
= tok2str(xtag2str
, "?xT%u", tag
);
396 cp
= tok2str(tag2str
, "?T%u", tag
);
399 if (tag
== TAG_PAD
|| tag
== TAG_END
)
402 /* Get the length; check for truncation */
407 printf("\n\t %s Option %u, length %u%s", cp
, tag
, len
,
408 len
> 0 ? ": " : "");
410 if (tag
== TAG_PAD
&& vflag
> 2) {
412 while (TTEST2(*bp
, 1) && *bp
== TAG_PAD
) {
417 printf(", occurs %u", ntag
);
420 if (!TTEST2(*bp
, len
)) {
421 printf("[|rfc1048 %u]", len
);
425 if (tag
== TAG_DHCP_MESSAGE
&& len
== 1) {
427 printf("%s", tok2str(dhcp_msg_values
, "Unknown (%u)", uc
));
431 if (tag
== TAG_PARM_REQUEST
) {
435 cp
= tok2str(tag2str
, "?Option %u", uc
);
440 printf("%s", cp
+ 1);
446 if (tag
== TAG_EXTENDED_REQUEST
) {
450 us
= EXTRACT_16BITS(bp
);
452 cp
= tok2str(xtag2str
, "?xT%u", us
);
455 printf("%s", cp
+ 1);
463 /* Base default formats for unknown tags on data size */
477 if (fn_printn(bp
, len
, snapend
)) {
489 /* ip addresses/32-bit words */
490 while (len
>= sizeof(ul
)) {
493 ul
= EXTRACT_32BITS(bp
);
496 printf("%s", ipaddr_string(&ul
));
508 /* IP address pairs */
509 while (len
>= 2*sizeof(ul
)) {
512 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
513 printf("(%s:", ipaddr_string(&ul
));
515 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
516 printf("%s)", ipaddr_string(&ul
));
525 while (len
>= sizeof(us
)) {
528 us
= EXTRACT_16BITS(bp
);
564 putchar(c
== 'x' ? ':' : '.');
576 /* Guys we can't handle with one of the usual cases */
579 case TAG_NETBIOS_NODE
:
580 /* this option should be at least 1 byte long */
582 printf("ERROR: option %u len %u < 1 bytes",
583 TAG_NETBIOS_NODE
, len
);
588 fputs(tok2str(nbo2str
, NULL
, tag
), stdout
);
591 case TAG_OPT_OVERLOAD
:
592 /* this option should be at least 1 byte long */
594 printf("ERROR: option %u len %u < 1 bytes",
595 TAG_OPT_OVERLOAD
, len
);
600 fputs(tok2str(oo2str
, NULL
, tag
), stdout
);
603 case TAG_CLIENT_FQDN
:
604 /* this option should be at least 3 bytes long */
606 printf("ERROR: option %u len %u < 3 bytes",
607 TAG_CLIENT_FQDN
, len
);
613 printf("[%s] ", client_fqdn_flags(*bp
));
616 printf("%u/%u ", *bp
, *(bp
+1));
619 if (fn_printn(bp
, len
- 3, snapend
)) {
631 /* this option should be at least 1 byte long */
633 printf("ERROR: option %u len %u < 1 bytes",
641 if (fn_printn(bp
, len
, snapend
)) {
650 printf("%s ", tok2str(arp2str
, "hardware-type %u,", type
));
663 case TAG_AGENT_CIRCUIT
:
668 if (suboptlen
> len
) {
669 printf("\n\t %s SubOption %u, length %u: length goes past end of option",
670 tok2str(agent_suboption_values
, "Unknown", subopt
),
677 printf("\n\t %s SubOption %u, length %u: ",
678 tok2str(agent_suboption_values
, "Unknown", subopt
),
683 case AGENT_SUBOPTION_CIRCUIT_ID
: /* fall through */
684 case AGENT_SUBOPTION_REMOTE_ID
:
685 case AGENT_SUBOPTION_SUBSCRIBER_ID
:
686 fn_printn(bp
, suboptlen
, NULL
);
690 print_unknown_data(gndo
,bp
, "\n\t\t", suboptlen
);
698 case TAG_CLASSLESS_STATIC_RT
:
699 case TAG_CLASSLESS_STA_RT_MS
:
701 u_int mask_width
, significant_octets
, i
;
703 /* this option should be at least 5 bytes long */
705 printf("ERROR: option %u len %u < 5 bytes",
706 TAG_CLASSLESS_STATIC_RT
, len
);
716 /* mask_width <= 32 */
717 if (mask_width
> 32) {
718 printf("[ERROR: Mask width (%d) > 32]", mask_width
);
723 significant_octets
= (mask_width
+ 7) / 8;
724 /* significant octets + router(4) */
725 if (len
< significant_octets
+ 4) {
726 printf("[ERROR: Remaining length (%u) < %u bytes]", len
, significant_octets
+ 4);
735 for (i
= 0; i
< significant_octets
; i
++) {
740 for (i
= significant_octets
; i
< 4 ; i
++)
742 printf("/%d", mask_width
);
744 memcpy((char *)&ul
, (const char *)bp
, sizeof(ul
));
745 printf(":%s)", ipaddr_string(&ul
));
747 len
-= (significant_octets
+ 4);
754 printf("[unknown special tag %u, size %u]",
762 /* Data left over? */
764 printf("\n\t trailing data length %u", len
);
770 printf("|[rfc1048]");
774 cmu_print(register const u_char
*bp
)
776 register const struct cmu_vend
*cmu
;
778 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
779 if (cmu->m.s_addr != 0) \
780 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
783 cmu
= (const struct cmu_vend
*)bp
;
785 /* Only print if there are unknown bits */
786 TCHECK(cmu
->v_flags
);
787 if ((cmu
->v_flags
& ~(VF_SMASK
)) != 0)
788 printf(" F:0x%x", cmu
->v_flags
);
789 PRINTCMUADDR(v_dgate
, "DG");
790 PRINTCMUADDR(v_smask
, cmu
->v_flags
& VF_SMASK
? "SM" : "SM*");
791 PRINTCMUADDR(v_dns1
, "NS1");
792 PRINTCMUADDR(v_dns2
, "NS2");
793 PRINTCMUADDR(v_ins1
, "IEN1");
794 PRINTCMUADDR(v_ins2
, "IEN2");
795 PRINTCMUADDR(v_ts1
, "TS1");
796 PRINTCMUADDR(v_ts2
, "TS2");
805 client_fqdn_flags(u_int flags
)
807 static char buf
[8+1];
810 if (flags
& CLIENT_FQDN_FLAGS_S
)
812 if (flags
& CLIENT_FQDN_FLAGS_O
)
814 if (flags
& CLIENT_FQDN_FLAGS_E
)
816 if (flags
& CLIENT_FQDN_FLAGS_N
)