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