]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
Merge remote-tracking branch 'github/master'
[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 3004 - The User Class Option for DHCP */
193 #define TAG_USER_CLASS ((uint8_t) 77)
194 /* RFC 3011 */
195 #define TAG_IP4_SUBNET_SELECT ((uint8_t) 118)
196 /* RFC 3442 */
197 #define TAG_CLASSLESS_STATIC_RT ((uint8_t) 121)
198 #define TAG_CLASSLESS_STA_RT_MS ((uint8_t) 249)
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)
224
225
226 /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
227 #define DHCPDISCOVER 1
228 #define DHCPOFFER 2
229 #define DHCPREQUEST 3
230 #define DHCPDECLINE 4
231 #define DHCPACK 5
232 #define DHCPNAK 6
233 #define DHCPRELEASE 7
234 #define DHCPINFORM 8
235
236
237 /*
238 * "vendor" data permitted for CMU bootp clients.
239 */
240
241 struct cmu_vend {
242 uint8_t v_magic[4]; /* magic number */
243 uint32_t v_flags; /* flags/opcodes, etc. */
244 struct in_addr v_smask; /* Subnet mask */
245 struct in_addr v_dgate; /* Default gateway */
246 struct in_addr v_dns1, v_dns2; /* Domain name servers */
247 struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
248 struct in_addr v_ts1, v_ts2; /* Time servers */
249 uint8_t v_unused[24]; /* currently unused */
250 } UNALIGNED;
251
252
253 /* v_flags values */
254 #define VF_SMASK 1 /* Subnet mask field contains valid data */
255
256 /* RFC 4702 DHCP Client FQDN Option */
257
258 #define CLIENT_FQDN_FLAGS_S 0x01
259 #define CLIENT_FQDN_FLAGS_O 0x02
260 #define CLIENT_FQDN_FLAGS_E 0x04
261 #define CLIENT_FQDN_FLAGS_N 0x08
262 /* end of original bootp.h */
263
264 static void rfc1048_print(netdissect_options *, const u_char *);
265 static void cmu_print(netdissect_options *, const u_char *);
266 static char *client_fqdn_flags(u_int flags);
267
268 static const struct tok bootp_flag_values[] = {
269 { 0x8000, "Broadcast" },
270 { 0, NULL}
271 };
272
273 static const struct tok bootp_op_values[] = {
274 { BOOTPREQUEST, "Request" },
275 { BOOTPREPLY, "Reply" },
276 { 0, NULL}
277 };
278
279 /*
280 * Print bootp requests
281 */
282 void
283 bootp_print(netdissect_options *ndo,
284 register const u_char *cp, u_int length)
285 {
286 register const struct bootp *bp;
287 static const u_char vm_cmu[4] = VM_CMU;
288 static const u_char vm_rfc1048[4] = VM_RFC1048;
289
290 bp = (const struct bootp *)cp;
291 ND_TCHECK(bp->bp_op);
292
293 ND_PRINT((ndo, "BOOTP/DHCP, %s",
294 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)));
295
296 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
297 ND_TCHECK2(bp->bp_chaddr[0], 6);
298 ND_PRINT((ndo, " from %s", etheraddr_string(ndo, bp->bp_chaddr)));
299 }
300
301 ND_PRINT((ndo, ", length %u", length));
302
303 if (!ndo->ndo_vflag)
304 return;
305
306 ND_TCHECK(bp->bp_secs);
307
308 /* The usual hardware address type is 1 (10Mb Ethernet) */
309 if (bp->bp_htype != 1)
310 ND_PRINT((ndo, ", htype %d", bp->bp_htype));
311
312 /* The usual length for 10Mb Ethernet address is 6 bytes */
313 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
314 ND_PRINT((ndo, ", hlen %d", bp->bp_hlen));
315
316 /* Only print interesting fields */
317 if (bp->bp_hops)
318 ND_PRINT((ndo, ", hops %d", bp->bp_hops));
319 if (EXTRACT_32BITS(&bp->bp_xid))
320 ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid)));
321 if (EXTRACT_16BITS(&bp->bp_secs))
322 ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs)));
323
324 ND_PRINT((ndo, ", Flags [%s]",
325 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))));
326 if (ndo->ndo_vflag > 1)
327 ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)));
328
329 /* Client's ip address */
330 ND_TCHECK(bp->bp_ciaddr);
331 if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr))
332 ND_PRINT((ndo, "\n\t Client-IP %s", ipaddr_string(ndo, &bp->bp_ciaddr)));
333
334 /* 'your' ip address (bootp client) */
335 ND_TCHECK(bp->bp_yiaddr);
336 if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr))
337 ND_PRINT((ndo, "\n\t Your-IP %s", ipaddr_string(ndo, &bp->bp_yiaddr)));
338
339 /* Server's ip address */
340 ND_TCHECK(bp->bp_siaddr);
341 if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr))
342 ND_PRINT((ndo, "\n\t Server-IP %s", ipaddr_string(ndo, &bp->bp_siaddr)));
343
344 /* Gateway's ip address */
345 ND_TCHECK(bp->bp_giaddr);
346 if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr))
347 ND_PRINT((ndo, "\n\t Gateway-IP %s", ipaddr_string(ndo, &bp->bp_giaddr)));
348
349 /* Client's Ethernet address */
350 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
351 ND_TCHECK2(bp->bp_chaddr[0], 6);
352 ND_PRINT((ndo, "\n\t Client-Ethernet-Address %s", etheraddr_string(ndo, bp->bp_chaddr)));
353 }
354
355 ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */
356 if (*bp->bp_sname) {
357 ND_PRINT((ndo, "\n\t sname \""));
358 if (fn_print(ndo, bp->bp_sname, ndo->ndo_snapend)) {
359 ND_PRINT((ndo, "\""));
360 ND_PRINT((ndo, "%s", tstr + 1));
361 return;
362 }
363 ND_PRINT((ndo, "\""));
364 }
365 ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */
366 if (*bp->bp_file) {
367 ND_PRINT((ndo, "\n\t file \""));
368 if (fn_print(ndo, bp->bp_file, ndo->ndo_snapend)) {
369 ND_PRINT((ndo, "\""));
370 ND_PRINT((ndo, "%s", tstr + 1));
371 return;
372 }
373 ND_PRINT((ndo, "\""));
374 }
375
376 /* Decode the vendor buffer */
377 ND_TCHECK(bp->bp_vend[0]);
378 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
379 sizeof(uint32_t)) == 0)
380 rfc1048_print(ndo, bp->bp_vend);
381 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
382 sizeof(uint32_t)) == 0)
383 cmu_print(ndo, bp->bp_vend);
384 else {
385 uint32_t ul;
386
387 ul = EXTRACT_32BITS(&bp->bp_vend);
388 if (ul != 0)
389 ND_PRINT((ndo, "\n\t Vendor-#0x%x", ul));
390 }
391
392 return;
393 trunc:
394 ND_PRINT((ndo, "%s", tstr));
395 }
396
397 /*
398 * The first character specifies the format to print:
399 * i - ip address (32 bits)
400 * p - ip address pairs (32 bits + 32 bits)
401 * l - long (32 bits)
402 * L - unsigned long (32 bits)
403 * s - short (16 bits)
404 * b - period-seperated decimal bytes (variable length)
405 * x - colon-seperated hex bytes (variable length)
406 * a - ascii string (variable length)
407 * B - on/off (8 bits)
408 * $ - special (explicit code to handle)
409 */
410 static const struct tok tag2str[] = {
411 /* RFC1048 tags */
412 { TAG_PAD, " PAD" },
413 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
414 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
415 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
416 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
417 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
418 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
419 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
420 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
421 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
422 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
423 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
424 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
425 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
426 { TAG_END, " END" },
427 /* RFC1497 tags */
428 { TAG_DUMPPATH, "aDP" },
429 { TAG_DOMAINNAME, "aDomain-Name" },
430 { TAG_SWAP_SERVER, "iSS" },
431 { TAG_ROOTPATH, "aRP" },
432 { TAG_EXTPATH, "aEP" },
433 /* RFC2132 tags */
434 { TAG_IP_FORWARD, "BIPF" },
435 { TAG_NL_SRCRT, "BSRT" },
436 { TAG_PFILTERS, "pPF" },
437 { TAG_REASS_SIZE, "sRSZ" },
438 { TAG_DEF_TTL, "bTTL" },
439 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
440 { TAG_MTU_TABLE, "sMTU-Table" },
441 { TAG_INT_MTU, "sMTU" },
442 { TAG_LOCAL_SUBNETS, "BLSN" },
443 { TAG_BROAD_ADDR, "iBR" },
444 { TAG_DO_MASK_DISC, "BMD" },
445 { TAG_SUPPLY_MASK, "BMS" },
446 { TAG_DO_RDISC, "BRouter-Discovery" },
447 { TAG_RTR_SOL_ADDR, "iRSA" },
448 { TAG_STATIC_ROUTE, "pStatic-Route" },
449 { TAG_USE_TRAILERS, "BUT" },
450 { TAG_ARP_TIMEOUT, "lAT" },
451 { TAG_ETH_ENCAP, "BIE" },
452 { TAG_TCP_TTL, "bTT" },
453 { TAG_TCP_KEEPALIVE, "lKI" },
454 { TAG_KEEPALIVE_GO, "BKG" },
455 { TAG_NIS_DOMAIN, "aYD" },
456 { TAG_NIS_SERVERS, "iYS" },
457 { TAG_NTP_SERVERS, "iNTP" },
458 { TAG_VENDOR_OPTS, "bVendor-Option" },
459 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
460 { TAG_NETBIOS_DDS, "iWDD" },
461 { TAG_NETBIOS_NODE, "$Netbios-Node" },
462 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
463 { TAG_XWIN_FS, "iXFS" },
464 { TAG_XWIN_DM, "iXDM" },
465 { TAG_NIS_P_DOMAIN, "sN+D" },
466 { TAG_NIS_P_SERVERS, "iN+S" },
467 { TAG_MOBILE_HOME, "iMH" },
468 { TAG_SMPT_SERVER, "iSMTP" },
469 { TAG_POP3_SERVER, "iPOP3" },
470 { TAG_NNTP_SERVER, "iNNTP" },
471 { TAG_WWW_SERVER, "iWWW" },
472 { TAG_FINGER_SERVER, "iFG" },
473 { TAG_IRC_SERVER, "iIRC" },
474 { TAG_STREETTALK_SRVR, "iSTS" },
475 { TAG_STREETTALK_STDA, "iSTDA" },
476 { TAG_REQUESTED_IP, "iRequested-IP" },
477 { TAG_IP_LEASE, "lLease-Time" },
478 { TAG_OPT_OVERLOAD, "$OO" },
479 { TAG_TFTP_SERVER, "aTFTP" },
480 { TAG_BOOTFILENAME, "aBF" },
481 { TAG_DHCP_MESSAGE, " DHCP-Message" },
482 { TAG_SERVER_ID, "iServer-ID" },
483 { TAG_PARM_REQUEST, "bParameter-Request" },
484 { TAG_MESSAGE, "aMSG" },
485 { TAG_MAX_MSG_SIZE, "sMSZ" },
486 { TAG_RENEWAL_TIME, "lRN" },
487 { TAG_REBIND_TIME, "lRB" },
488 { TAG_VENDOR_CLASS, "aVendor-Class" },
489 { TAG_CLIENT_ID, "$Client-ID" },
490 /* RFC 2485 */
491 { TAG_OPEN_GROUP_UAP, "aUAP" },
492 /* RFC 2563 */
493 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
494 /* RFC 2610 */
495 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
496 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
497 /* RFC 2937 */
498 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
499 /* RFC 3004 - The User Class Option for DHCP */
500 { TAG_USER_CLASS, "$User-Class" },
501 /* RFC 3011 */
502 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
503 /* RFC 3442 */
504 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
505 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
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" },
527 { TAG_URL, "aURL" },
528 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
529 { 0, NULL }
530 };
531 /* 2-byte extended tags */
532 static const struct tok xtag2str[] = {
533 { 0, NULL }
534 };
535
536 /* DHCP "options overload" types */
537 static const struct tok oo2str[] = {
538 { 1, "file" },
539 { 2, "sname" },
540 { 3, "file+sname" },
541 { 0, NULL }
542 };
543
544 /* NETBIOS over TCP/IP node type options */
545 static const struct tok nbo2str[] = {
546 { 0x1, "b-node" },
547 { 0x2, "p-node" },
548 { 0x4, "m-node" },
549 { 0x8, "h-node" },
550 { 0, NULL }
551 };
552
553 /* ARP Hardware types, for Client-ID option */
554 static const struct tok arp2str[] = {
555 { 0x1, "ether" },
556 { 0x6, "ieee802" },
557 { 0x7, "arcnet" },
558 { 0xf, "frelay" },
559 { 0x17, "strip" },
560 { 0x18, "ieee1394" },
561 { 0, NULL }
562 };
563
564 static const struct tok dhcp_msg_values[] = {
565 { DHCPDISCOVER, "Discover" },
566 { DHCPOFFER, "Offer" },
567 { DHCPREQUEST, "Request" },
568 { DHCPDECLINE, "Decline" },
569 { DHCPACK, "ACK" },
570 { DHCPNAK, "NACK" },
571 { DHCPRELEASE, "Release" },
572 { DHCPINFORM, "Inform" },
573 { 0, NULL }
574 };
575
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" },
583 { 0, NULL }
584 };
585
586
587 static void
588 rfc1048_print(netdissect_options *ndo,
589 register const u_char *bp)
590 {
591 register uint16_t tag;
592 register u_int len;
593 register const char *cp;
594 register char c;
595 int first, idx;
596 uint32_t ul;
597 uint16_t us;
598 uint8_t uc, subopt, suboptlen;
599
600 ND_PRINT((ndo, "\n\t Vendor-rfc1048 Extensions"));
601
602 /* Step over magic cookie */
603 ND_PRINT((ndo, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp)));
604 bp += sizeof(int32_t);
605
606 /* Loop while we there is a tag left in the buffer */
607 while (ND_TTEST2(*bp, 1)) {
608 tag = *bp++;
609 if (tag == TAG_PAD && ndo->ndo_vflag < 3)
610 continue;
611 if (tag == TAG_END && ndo->ndo_vflag < 3)
612 return;
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.
619 */
620 cp = tok2str(xtag2str, "?xT%u", tag);
621 } else
622 cp = tok2str(tag2str, "?T%u", tag);
623 c = *cp++;
624
625 if (tag == TAG_PAD || tag == TAG_END)
626 len = 0;
627 else {
628 /* Get the length; check for truncation */
629 ND_TCHECK2(*bp, 1);
630 len = *bp++;
631 }
632
633 ND_PRINT((ndo, "\n\t %s Option %u, length %u%s", cp, tag, len,
634 len > 0 ? ": " : ""));
635
636 if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
637 u_int ntag = 1;
638 while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) {
639 bp++;
640 ntag++;
641 }
642 if (ntag > 1)
643 ND_PRINT((ndo, ", occurs %u", ntag));
644 }
645
646 if (!ND_TTEST2(*bp, len)) {
647 ND_PRINT((ndo, "[|rfc1048 %u]", len));
648 return;
649 }
650
651 if (tag == TAG_DHCP_MESSAGE && len == 1) {
652 uc = *bp++;
653 ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc)));
654 continue;
655 }
656
657 if (tag == TAG_PARM_REQUEST) {
658 idx = 0;
659 while (len-- > 0) {
660 uc = *bp++;
661 cp = tok2str(tag2str, "?Option %u", uc);
662 if (idx % 4 == 0)
663 ND_PRINT((ndo, "\n\t "));
664 else
665 ND_PRINT((ndo, ", "));
666 ND_PRINT((ndo, "%s", cp + 1));
667 idx++;
668 }
669 continue;
670 }
671
672 if (tag == TAG_EXTENDED_REQUEST) {
673 first = 1;
674 while (len > 1) {
675 len -= 2;
676 us = EXTRACT_16BITS(bp);
677 bp += 2;
678 cp = tok2str(xtag2str, "?xT%u", us);
679 if (!first)
680 ND_PRINT((ndo, "+"));
681 ND_PRINT((ndo, "%s", cp + 1));
682 first = 0;
683 }
684 continue;
685 }
686
687 /* Print data */
688 if (c == '?') {
689 /* Base default formats for unknown tags on data size */
690 if (len & 1)
691 c = 'b';
692 else if (len & 2)
693 c = 's';
694 else
695 c = 'l';
696 }
697 first = 1;
698 switch (c) {
699
700 case 'a':
701 /* ascii strings */
702 ND_PRINT((ndo, "\""));
703 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
704 ND_PRINT((ndo, "\""));
705 goto trunc;
706 }
707 ND_PRINT((ndo, "\""));
708 bp += len;
709 len = 0;
710 break;
711
712 case 'i':
713 case 'l':
714 case 'L':
715 /* ip addresses/32-bit words */
716 while (len >= sizeof(ul)) {
717 if (!first)
718 ND_PRINT((ndo, ","));
719 ul = EXTRACT_32BITS(bp);
720 if (c == 'i') {
721 ul = htonl(ul);
722 ND_PRINT((ndo, "%s", ipaddr_string(ndo, &ul)));
723 } else if (c == 'L')
724 ND_PRINT((ndo, "%d", ul));
725 else
726 ND_PRINT((ndo, "%u", ul));
727 bp += sizeof(ul);
728 len -= sizeof(ul);
729 first = 0;
730 }
731 break;
732
733 case 'p':
734 /* IP address pairs */
735 while (len >= 2*sizeof(ul)) {
736 if (!first)
737 ND_PRINT((ndo, ","));
738 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
739 ND_PRINT((ndo, "(%s:", ipaddr_string(ndo, &ul)));
740 bp += sizeof(ul);
741 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
742 ND_PRINT((ndo, "%s)", ipaddr_string(ndo, &ul)));
743 bp += sizeof(ul);
744 len -= 2*sizeof(ul);
745 first = 0;
746 }
747 break;
748
749 case 's':
750 /* shorts */
751 while (len >= sizeof(us)) {
752 if (!first)
753 ND_PRINT((ndo, ","));
754 us = EXTRACT_16BITS(bp);
755 ND_PRINT((ndo, "%u", us));
756 bp += sizeof(us);
757 len -= sizeof(us);
758 first = 0;
759 }
760 break;
761
762 case 'B':
763 /* boolean */
764 while (len > 0) {
765 if (!first)
766 ND_PRINT((ndo, ","));
767 switch (*bp) {
768 case 0:
769 ND_PRINT((ndo, "N"));
770 break;
771 case 1:
772 ND_PRINT((ndo, "Y"));
773 break;
774 default:
775 ND_PRINT((ndo, "%u?", *bp));
776 break;
777 }
778 ++bp;
779 --len;
780 first = 0;
781 }
782 break;
783
784 case 'b':
785 case 'x':
786 default:
787 /* Bytes */
788 while (len > 0) {
789 if (!first)
790 ND_PRINT((ndo, c == 'x' ? ":" : "."));
791 if (c == 'x')
792 ND_PRINT((ndo, "%02x", *bp));
793 else
794 ND_PRINT((ndo, "%u", *bp));
795 ++bp;
796 --len;
797 first = 0;
798 }
799 break;
800
801 case '$':
802 /* Guys we can't handle with one of the usual cases */
803 switch (tag) {
804
805 case TAG_NETBIOS_NODE:
806 /* this option should be at least 1 byte long */
807 if (len < 1) {
808 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
809 break;
810 }
811 tag = *bp++;
812 --len;
813 ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag)));
814 break;
815
816 case TAG_OPT_OVERLOAD:
817 /* this option should be at least 1 byte long */
818 if (len < 1) {
819 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
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: length < 3 bytes"));
831 bp += len;
832 len = 0;
833 break;
834 }
835 if (*bp)
836 ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp)));
837 bp++;
838 if (*bp || *(bp+1))
839 ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1)));
840 bp += 2;
841 ND_PRINT((ndo, "\""));
842 if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
843 ND_PRINT((ndo, "\""));
844 goto trunc;
845 }
846 ND_PRINT((ndo, "\""));
847 bp += len - 3;
848 len = 0;
849 break;
850
851 case TAG_CLIENT_ID:
852 { int type;
853
854 /* this option should be at least 1 byte long */
855 if (len < 1) {
856 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
857 break;
858 }
859 type = *bp++;
860 len--;
861 if (type == 0) {
862 ND_PRINT((ndo, "\""));
863 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
864 ND_PRINT((ndo, "\""));
865 goto trunc;
866 }
867 ND_PRINT((ndo, "\""));
868 bp += len;
869 len = 0;
870 break;
871 } else {
872 ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type)));
873 while (len > 0) {
874 if (!first)
875 ND_PRINT((ndo, ":"));
876 ND_PRINT((ndo, "%02x", *bp));
877 ++bp;
878 --len;
879 first = 0;
880 }
881 }
882 break;
883 }
884
885 case TAG_AGENT_CIRCUIT:
886 while (len >= 2) {
887 subopt = *bp++;
888 suboptlen = *bp++;
889 len -= 2;
890 if (suboptlen > len) {
891 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: length goes past end of option",
892 tok2str(agent_suboption_values, "Unknown", subopt),
893 subopt,
894 suboptlen));
895 bp += len;
896 len = 0;
897 break;
898 }
899 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: ",
900 tok2str(agent_suboption_values, "Unknown", subopt),
901 subopt,
902 suboptlen));
903 switch (subopt) {
904
905 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
906 case AGENT_SUBOPTION_REMOTE_ID:
907 case AGENT_SUBOPTION_SUBSCRIBER_ID:
908 fn_printn(ndo, bp, suboptlen, NULL);
909 break;
910
911 default:
912 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
913 }
914
915 len -= suboptlen;
916 bp += suboptlen;
917 }
918 break;
919
920 case TAG_CLASSLESS_STATIC_RT:
921 case TAG_CLASSLESS_STA_RT_MS:
922 {
923 u_int mask_width, significant_octets, i;
924
925 /* this option should be at least 5 bytes long */
926 if (len < 5) {
927 ND_PRINT((ndo, "ERROR: length < 5 bytes"));
928 bp += len;
929 len = 0;
930 break;
931 }
932 while (len > 0) {
933 if (!first)
934 ND_PRINT((ndo, ","));
935 mask_width = *bp++;
936 len--;
937 /* mask_width <= 32 */
938 if (mask_width > 32) {
939 ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width));
940 bp += len;
941 len = 0;
942 break;
943 }
944 significant_octets = (mask_width + 7) / 8;
945 /* significant octets + router(4) */
946 if (len < significant_octets + 4) {
947 ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4));
948 bp += len;
949 len = 0;
950 break;
951 }
952 ND_PRINT((ndo, "("));
953 if (mask_width == 0)
954 ND_PRINT((ndo, "default"));
955 else {
956 for (i = 0; i < significant_octets ; i++) {
957 if (i > 0)
958 ND_PRINT((ndo, "."));
959 ND_PRINT((ndo, "%d", *bp++));
960 }
961 for (i = significant_octets ; i < 4 ; i++)
962 ND_PRINT((ndo, ".0"));
963 ND_PRINT((ndo, "/%d", mask_width));
964 }
965 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
966 ND_PRINT((ndo, ":%s)", ipaddr_string(ndo, &ul)));
967 bp += sizeof(ul);
968 len -= (significant_octets + 4);
969 first = 0;
970 }
971 }
972 break;
973
974 case TAG_USER_CLASS:
975 {
976 u_int suboptnumber = 1;
977
978 first = 1;
979 if (len < 2) {
980 ND_PRINT((ndo, "ERROR: length < 2 bytes"));
981 bp += len;
982 len = 0;
983 break;
984 }
985 while (len > 0) {
986 suboptlen = *bp++;
987 len--;
988 ND_PRINT((ndo, "\n\t "));
989 ND_PRINT((ndo, "instance#%u: ", suboptnumber));
990 if (suboptlen == 0) {
991 ND_PRINT((ndo, "ERROR: suboption length must be non-zero"));
992 bp += len;
993 len = 0;
994 break;
995 }
996 if (len < suboptlen) {
997 ND_PRINT((ndo, "ERROR: malformed option"));
998 bp += len;
999 len = 0;
1000 break;
1001 }
1002 ND_PRINT((ndo, "\""));
1003 if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
1004 ND_PRINT((ndo, "\""));
1005 goto trunc;
1006 }
1007 ND_PRINT((ndo, "\""));
1008 ND_PRINT((ndo, ", length %d", suboptlen));
1009 suboptnumber++;
1010 len -= suboptlen;
1011 bp += suboptlen;
1012 }
1013 }
1014 break;
1015
1016 default:
1017 ND_PRINT((ndo, "[unknown special tag %u, size %u]",
1018 tag, len));
1019 bp += len;
1020 len = 0;
1021 break;
1022 }
1023 break;
1024 }
1025 /* Data left over? */
1026 if (len) {
1027 ND_PRINT((ndo, "\n\t trailing data length %u", len));
1028 bp += len;
1029 }
1030 }
1031 return;
1032 trunc:
1033 ND_PRINT((ndo, "|[rfc1048]"));
1034 }
1035
1036 static void
1037 cmu_print(netdissect_options *ndo,
1038 register const u_char *bp)
1039 {
1040 register const struct cmu_vend *cmu;
1041
1042 #define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \
1043 if (cmu->m.s_addr != 0) \
1044 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); }
1045
1046 ND_PRINT((ndo, " vend-cmu"));
1047 cmu = (const struct cmu_vend *)bp;
1048
1049 /* Only print if there are unknown bits */
1050 ND_TCHECK(cmu->v_flags);
1051 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
1052 ND_PRINT((ndo, " F:0x%x", cmu->v_flags));
1053 PRINTCMUADDR(v_dgate, "DG");
1054 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
1055 PRINTCMUADDR(v_dns1, "NS1");
1056 PRINTCMUADDR(v_dns2, "NS2");
1057 PRINTCMUADDR(v_ins1, "IEN1");
1058 PRINTCMUADDR(v_ins2, "IEN2");
1059 PRINTCMUADDR(v_ts1, "TS1");
1060 PRINTCMUADDR(v_ts2, "TS2");
1061 return;
1062
1063 trunc:
1064 ND_PRINT((ndo, "%s", tstr));
1065 #undef PRINTCMUADDR
1066 }
1067
1068 static char *
1069 client_fqdn_flags(u_int flags)
1070 {
1071 static char buf[8+1];
1072 int i = 0;
1073
1074 if (flags & CLIENT_FQDN_FLAGS_S)
1075 buf[i++] = 'S';
1076 if (flags & CLIENT_FQDN_FLAGS_O)
1077 buf[i++] = 'O';
1078 if (flags & CLIENT_FQDN_FLAGS_E)
1079 buf[i++] = 'E';
1080 if (flags & CLIENT_FQDN_FLAGS_N)
1081 buf[i++] = 'N';
1082 buf[i] = '\0';
1083
1084 return buf;
1085 }