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