]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
Add more nd_print_trunc() calls
[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
37 /*
38 * Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
39 *
40 * This file specifies the "implementation-independent" BOOTP protocol
41 * information which is common to both client and server.
42 *
43 * Copyright 1988 by Carnegie Mellon.
44 *
45 * Permission to use, copy, modify, and distribute this program for any
46 * purpose and without fee is hereby granted, provided that this copyright
47 * and permission notice appear on all copies and supporting documentation,
48 * the name of Carnegie Mellon not be used in advertising or publicity
49 * pertaining to distribution of the program without specific prior
50 * permission, and notice be given in supporting documentation that copying
51 * and distribution is by permission of Carnegie Mellon and Stanford
52 * University. Carnegie Mellon makes no representations about the
53 * suitability of this software for any purpose. It is provided "as is"
54 * without express or implied warranty.
55 */
56
57 struct bootp {
58 nd_uint8_t bp_op; /* packet opcode type */
59 nd_uint8_t bp_htype; /* hardware addr type */
60 nd_uint8_t bp_hlen; /* hardware addr length */
61 nd_uint8_t bp_hops; /* gateway hops */
62 nd_uint32_t bp_xid; /* transaction ID */
63 nd_uint16_t bp_secs; /* seconds since boot began */
64 nd_uint16_t bp_flags; /* flags - see bootp_flag_values[]
65 in print-bootp.c */
66 nd_ipv4 bp_ciaddr; /* client IP address */
67 nd_ipv4 bp_yiaddr; /* 'your' IP address */
68 nd_ipv4 bp_siaddr; /* server IP address */
69 nd_ipv4 bp_giaddr; /* gateway IP address */
70 nd_byte bp_chaddr[16]; /* client hardware address */
71 nd_byte bp_sname[64]; /* server host name */
72 nd_byte bp_file[128]; /* boot file name */
73 nd_byte bp_vend[64]; /* vendor-specific area */
74 };
75
76 #define BOOTPREPLY 2
77 #define BOOTPREQUEST 1
78
79 /*
80 * Vendor magic cookie (v_magic) for CMU
81 */
82 #define VM_CMU "CMU"
83
84 /*
85 * Vendor magic cookie (v_magic) for RFC1048
86 */
87 #define VM_RFC1048 { 99, 130, 83, 99 }
88
89 /*
90 * RFC1048 tag values used to specify what information is being supplied in
91 * the vendor field of the packet.
92 */
93
94 #define TAG_PAD ((uint8_t) 0)
95 #define TAG_SUBNET_MASK ((uint8_t) 1)
96 #define TAG_TIME_OFFSET ((uint8_t) 2)
97 #define TAG_GATEWAY ((uint8_t) 3)
98 #define TAG_TIME_SERVER ((uint8_t) 4)
99 #define TAG_NAME_SERVER ((uint8_t) 5)
100 #define TAG_DOMAIN_SERVER ((uint8_t) 6)
101 #define TAG_LOG_SERVER ((uint8_t) 7)
102 #define TAG_COOKIE_SERVER ((uint8_t) 8)
103 #define TAG_LPR_SERVER ((uint8_t) 9)
104 #define TAG_IMPRESS_SERVER ((uint8_t) 10)
105 #define TAG_RLP_SERVER ((uint8_t) 11)
106 #define TAG_HOSTNAME ((uint8_t) 12)
107 #define TAG_BOOTSIZE ((uint8_t) 13)
108 #define TAG_END ((uint8_t) 255)
109 /* RFC1497 tags */
110 #define TAG_DUMPPATH ((uint8_t) 14)
111 #define TAG_DOMAINNAME ((uint8_t) 15)
112 #define TAG_SWAP_SERVER ((uint8_t) 16)
113 #define TAG_ROOTPATH ((uint8_t) 17)
114 #define TAG_EXTPATH ((uint8_t) 18)
115 /* RFC2132 */
116 #define TAG_IP_FORWARD ((uint8_t) 19)
117 #define TAG_NL_SRCRT ((uint8_t) 20)
118 #define TAG_PFILTERS ((uint8_t) 21)
119 #define TAG_REASS_SIZE ((uint8_t) 22)
120 #define TAG_DEF_TTL ((uint8_t) 23)
121 #define TAG_MTU_TIMEOUT ((uint8_t) 24)
122 #define TAG_MTU_TABLE ((uint8_t) 25)
123 #define TAG_INT_MTU ((uint8_t) 26)
124 #define TAG_LOCAL_SUBNETS ((uint8_t) 27)
125 #define TAG_BROAD_ADDR ((uint8_t) 28)
126 #define TAG_DO_MASK_DISC ((uint8_t) 29)
127 #define TAG_SUPPLY_MASK ((uint8_t) 30)
128 #define TAG_DO_RDISC ((uint8_t) 31)
129 #define TAG_RTR_SOL_ADDR ((uint8_t) 32)
130 #define TAG_STATIC_ROUTE ((uint8_t) 33)
131 #define TAG_USE_TRAILERS ((uint8_t) 34)
132 #define TAG_ARP_TIMEOUT ((uint8_t) 35)
133 #define TAG_ETH_ENCAP ((uint8_t) 36)
134 #define TAG_TCP_TTL ((uint8_t) 37)
135 #define TAG_TCP_KEEPALIVE ((uint8_t) 38)
136 #define TAG_KEEPALIVE_GO ((uint8_t) 39)
137 #define TAG_NIS_DOMAIN ((uint8_t) 40)
138 #define TAG_NIS_SERVERS ((uint8_t) 41)
139 #define TAG_NTP_SERVERS ((uint8_t) 42)
140 #define TAG_VENDOR_OPTS ((uint8_t) 43)
141 #define TAG_NETBIOS_NS ((uint8_t) 44)
142 #define TAG_NETBIOS_DDS ((uint8_t) 45)
143 #define TAG_NETBIOS_NODE ((uint8_t) 46)
144 #define TAG_NETBIOS_SCOPE ((uint8_t) 47)
145 #define TAG_XWIN_FS ((uint8_t) 48)
146 #define TAG_XWIN_DM ((uint8_t) 49)
147 #define TAG_NIS_P_DOMAIN ((uint8_t) 64)
148 #define TAG_NIS_P_SERVERS ((uint8_t) 65)
149 #define TAG_MOBILE_HOME ((uint8_t) 68)
150 #define TAG_SMPT_SERVER ((uint8_t) 69)
151 #define TAG_POP3_SERVER ((uint8_t) 70)
152 #define TAG_NNTP_SERVER ((uint8_t) 71)
153 #define TAG_WWW_SERVER ((uint8_t) 72)
154 #define TAG_FINGER_SERVER ((uint8_t) 73)
155 #define TAG_IRC_SERVER ((uint8_t) 74)
156 #define TAG_STREETTALK_SRVR ((uint8_t) 75)
157 #define TAG_STREETTALK_STDA ((uint8_t) 76)
158 /* DHCP options */
159 #define TAG_REQUESTED_IP ((uint8_t) 50)
160 #define TAG_IP_LEASE ((uint8_t) 51)
161 #define TAG_OPT_OVERLOAD ((uint8_t) 52)
162 #define TAG_TFTP_SERVER ((uint8_t) 66)
163 #define TAG_BOOTFILENAME ((uint8_t) 67)
164 #define TAG_DHCP_MESSAGE ((uint8_t) 53)
165 #define TAG_SERVER_ID ((uint8_t) 54)
166 #define TAG_PARM_REQUEST ((uint8_t) 55)
167 #define TAG_MESSAGE ((uint8_t) 56)
168 #define TAG_MAX_MSG_SIZE ((uint8_t) 57)
169 #define TAG_RENEWAL_TIME ((uint8_t) 58)
170 #define TAG_REBIND_TIME ((uint8_t) 59)
171 #define TAG_VENDOR_CLASS ((uint8_t) 60)
172 #define TAG_CLIENT_ID ((uint8_t) 61)
173 /* RFC 2241 */
174 #define TAG_NDS_SERVERS ((uint8_t) 85)
175 #define TAG_NDS_TREE_NAME ((uint8_t) 86)
176 #define TAG_NDS_CONTEXT ((uint8_t) 87)
177 /* RFC 2242 */
178 #define TAG_NDS_IPDOMAIN ((uint8_t) 62)
179 #define TAG_NDS_IPINFO ((uint8_t) 63)
180 /* RFC 2485 */
181 #define TAG_OPEN_GROUP_UAP ((uint8_t) 98)
182 /* RFC 2563 */
183 #define TAG_DISABLE_AUTOCONF ((uint8_t) 116)
184 /* RFC 2610 */
185 #define TAG_SLP_DA ((uint8_t) 78)
186 #define TAG_SLP_SCOPE ((uint8_t) 79)
187 /* RFC 2937 */
188 #define TAG_NS_SEARCH ((uint8_t) 117)
189 /* RFC 3004 - The User Class Option for DHCP */
190 #define TAG_USER_CLASS ((uint8_t) 77)
191 /* RFC 3011 */
192 #define TAG_IP4_SUBNET_SELECT ((uint8_t) 118)
193 /* RFC 3442 */
194 #define TAG_CLASSLESS_STATIC_RT ((uint8_t) 121)
195 #define TAG_CLASSLESS_STA_RT_MS ((uint8_t) 249)
196 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
197 #define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
198 /* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
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 /* RFC 4833, TZ codes */
215 #define TAG_TZ_PCODE ((uint8_t) 100)
216 #define TAG_TZ_TCODE ((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 #define TAG_MUDURL ((uint8_t) 161)
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 * "vendor" data permitted for CMU bootp clients.
238 */
239
240 struct cmu_vend {
241 nd_byte v_magic[4]; /* magic number */
242 nd_uint32_t v_flags; /* flags/opcodes, etc. */
243 nd_ipv4 v_smask; /* Subnet mask */
244 nd_ipv4 v_dgate; /* Default gateway */
245 nd_ipv4 v_dns1, v_dns2; /* Domain name servers */
246 nd_ipv4 v_ins1, v_ins2; /* IEN-116 name servers */
247 nd_ipv4 v_ts1, v_ts2; /* Time servers */
248 nd_byte v_unused[24]; /* currently unused */
249 };
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 const u_char *cp, u_int length)
284 {
285 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 uint8_t bp_op, bp_htype, bp_hlen;
289
290 ndo->ndo_protocol = "bootp";
291 bp = (const struct bootp *)cp;
292 ND_TCHECK_1(bp->bp_op);
293 bp_op = EXTRACT_U_1(bp->bp_op);
294 ND_PRINT("BOOTP/DHCP, %s",
295 tok2str(bootp_op_values, "unknown (0x%02x)", bp_op));
296
297 ND_TCHECK_1(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_6(bp->bp_chaddr);
302 ND_PRINT(" from %s", etheraddr_string(ndo, bp->bp_chaddr));
303 }
304
305 ND_PRINT(", length %u", length);
306
307 if (!ndo->ndo_vflag)
308 return;
309
310 ND_TCHECK_2(bp->bp_secs);
311
312 /* The usual hardware address type is 1 (10Mb Ethernet) */
313 if (bp_htype != 1)
314 ND_PRINT(", htype %u", 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(", hlen %u", bp_hlen);
319
320 /* Only print interesting fields */
321 if (EXTRACT_U_1(bp->bp_hops))
322 ND_PRINT(", hops %u", EXTRACT_U_1(bp->bp_hops));
323 if (EXTRACT_BE_U_4(bp->bp_xid))
324 ND_PRINT(", xid 0x%x", EXTRACT_BE_U_4(bp->bp_xid));
325 if (EXTRACT_BE_U_2(bp->bp_secs))
326 ND_PRINT(", secs %u", EXTRACT_BE_U_2(bp->bp_secs));
327
328 ND_TCHECK_2(bp->bp_flags);
329 ND_PRINT(", Flags [%s]",
330 bittok2str(bootp_flag_values, "none", EXTRACT_BE_U_2(bp->bp_flags)));
331 if (ndo->ndo_vflag > 1)
332 ND_PRINT(" (0x%04x)", EXTRACT_BE_U_2(bp->bp_flags));
333
334 /* Client's ip address */
335 ND_TCHECK_4(bp->bp_ciaddr);
336 if (EXTRACT_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
337 ND_PRINT("\n\t Client-IP %s", ipaddr_string(ndo, bp->bp_ciaddr));
338
339 /* 'your' ip address (bootp client) */
340 ND_TCHECK_4(bp->bp_yiaddr);
341 if (EXTRACT_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
342 ND_PRINT("\n\t Your-IP %s", ipaddr_string(ndo, bp->bp_yiaddr));
343
344 /* Server's ip address */
345 ND_TCHECK_4(bp->bp_siaddr);
346 if (EXTRACT_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
347 ND_PRINT("\n\t Server-IP %s", ipaddr_string(ndo, bp->bp_siaddr));
348
349 /* Gateway's ip address */
350 ND_TCHECK_4(bp->bp_giaddr);
351 if (EXTRACT_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
352 ND_PRINT("\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_6(bp->bp_chaddr);
357 ND_PRINT("\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("\n\t sname \"");
363 if (nd_printztn(ndo, bp->bp_sname, (u_int)sizeof(bp->bp_sname),
364 ndo->ndo_snapend)) {
365 ND_PRINT("\"");
366 nd_print_trunc(ndo);
367 return;
368 }
369 ND_PRINT("\"");
370 }
371 ND_TCHECK_1(bp->bp_file); /* check first char only */
372 if (EXTRACT_U_1(bp->bp_file)) {
373 ND_PRINT("\n\t file \"");
374 if (nd_printztn(ndo, bp->bp_file, (u_int)sizeof(bp->bp_file),
375 ndo->ndo_snapend)) {
376 ND_PRINT("\"");
377 nd_print_trunc(ndo);
378 return;
379 }
380 ND_PRINT("\"");
381 }
382
383 /* Decode the vendor buffer */
384 ND_TCHECK_4(bp->bp_vend);
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("\n\t Vendor-#0x%x", ul);
397 }
398
399 return;
400 trunc:
401 nd_print_trunc(ndo);
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 uint8_t subopt, suboptlen;
607
608 ND_PRINT("\n\t Vendor-rfc1048 Extensions");
609
610 /* Step over magic cookie */
611 ND_PRINT("\n\t Magic Cookie 0x%08x", EXTRACT_BE_U_4(bp));
612 bp += sizeof(int32_t);
613
614 /* Loop while we there is a tag left in the buffer */
615 while (ND_TTEST_1(bp)) {
616 tag = EXTRACT_U_1(bp);
617 bp++;
618 if (tag == TAG_PAD && ndo->ndo_vflag < 3)
619 continue;
620 if (tag == TAG_END && ndo->ndo_vflag < 3)
621 return;
622 if (tag == TAG_EXTENDED_OPTION) {
623 ND_TCHECK_2(bp + 1);
624 tag = EXTRACT_BE_U_2(bp + 1);
625 /* XXX we don't know yet if the IANA will
626 * preclude overlap of 1-byte and 2-byte spaces.
627 * If not, we need to offset tag after this step.
628 */
629 cp = tok2str(xtag2str, "?xT%u", tag);
630 } else
631 cp = tok2str(tag2str, "?T%u", tag);
632 c = *cp++;
633
634 if (tag == TAG_PAD || tag == TAG_END)
635 len = 0;
636 else {
637 /* Get the length; check for truncation */
638 ND_TCHECK_1(bp);
639 len = EXTRACT_U_1(bp);
640 bp++;
641 }
642
643 ND_PRINT("\n\t %s Option %u, length %u%s", cp, tag, len,
644 len > 0 ? ": " : "");
645
646 if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
647 u_int ntag = 1;
648 while (ND_TTEST_1(bp) &&
649 EXTRACT_U_1(bp) == TAG_PAD) {
650 bp++;
651 ntag++;
652 }
653 if (ntag > 1)
654 ND_PRINT(", occurs %u", ntag);
655 }
656
657 if (!ND_TTEST_LEN(bp, len)) {
658 ND_PRINT("[|rfc1048 %u]", len);
659 return;
660 }
661
662 if (tag == TAG_DHCP_MESSAGE && len == 1) {
663 ND_PRINT("%s", tok2str(dhcp_msg_values, "Unknown (%u)", EXTRACT_U_1(bp)));
664 bp++;
665 continue;
666 }
667
668 if (tag == TAG_PARM_REQUEST) {
669 idx = 0;
670 while (len > 0) {
671 cp = tok2str(tag2str, "?Option %u", EXTRACT_U_1(bp));
672 bp++;
673 len--;
674 if (idx % 4 == 0)
675 ND_PRINT("\n\t ");
676 else
677 ND_PRINT(", ");
678 ND_PRINT("%s", cp + 1);
679 idx++;
680 }
681 continue;
682 }
683
684 if (tag == TAG_EXTENDED_REQUEST) {
685 first = 1;
686 while (len > 1) {
687 cp = tok2str(xtag2str, "?xT%u", EXTRACT_BE_U_2(bp));
688 bp += 2;
689 len -= 2;
690 if (!first)
691 ND_PRINT("+");
692 ND_PRINT("%s", cp + 1);
693 first = 0;
694 }
695 continue;
696 }
697
698 /* Print data */
699 if (c == '?') {
700 /* Base default formats for unknown tags on data size */
701 if (len & 1)
702 c = 'b';
703 else if (len & 2)
704 c = 's';
705 else
706 c = 'l';
707 }
708 first = 1;
709 switch (c) {
710
711 case 'a':
712 /* ASCII strings */
713 ND_PRINT("\"");
714 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
715 ND_PRINT("\"");
716 goto trunc;
717 }
718 ND_PRINT("\"");
719 bp += len;
720 len = 0;
721 break;
722
723 case 'i':
724 case 'l':
725 case 'L':
726 /* ip addresses/32-bit words */
727 while (len >= 4) {
728 if (!first)
729 ND_PRINT(",");
730 if (c == 'i')
731 ND_PRINT("%s", ipaddr_string(ndo, bp));
732 else if (c == 'L')
733 ND_PRINT("%d", EXTRACT_BE_S_4(bp));
734 else
735 ND_PRINT("%u", EXTRACT_BE_U_4(bp));
736 bp += 4;
737 len -= 4;
738 first = 0;
739 }
740 break;
741
742 case 'p':
743 /* IP address pairs */
744 while (len >= 2*4) {
745 if (!first)
746 ND_PRINT(",");
747 ND_PRINT("(%s:", ipaddr_string(ndo, bp));
748 bp += 4;
749 len -= 4;
750 ND_PRINT("%s)", ipaddr_string(ndo, bp));
751 bp += 4;
752 len -= 4;
753 first = 0;
754 }
755 break;
756
757 case 's':
758 /* shorts */
759 while (len >= 2) {
760 if (!first)
761 ND_PRINT(",");
762 ND_PRINT("%u", EXTRACT_BE_U_2(bp));
763 bp += 2;
764 len -= 2;
765 first = 0;
766 }
767 break;
768
769 case 'B':
770 /* boolean */
771 while (len > 0) {
772 uint8_t bool_value;
773 if (!first)
774 ND_PRINT(",");
775 bool_value = EXTRACT_U_1(bp);
776 switch (bool_value) {
777 case 0:
778 ND_PRINT("N");
779 break;
780 case 1:
781 ND_PRINT("Y");
782 break;
783 default:
784 ND_PRINT("%u?", bool_value);
785 break;
786 }
787 ++bp;
788 --len;
789 first = 0;
790 }
791 break;
792
793 case 'b':
794 case 'x':
795 default:
796 /* Bytes */
797 while (len > 0) {
798 uint8_t byte_value;
799 if (!first)
800 ND_PRINT(c == 'x' ? ":" : ".");
801 byte_value = EXTRACT_U_1(bp);
802 if (c == 'x')
803 ND_PRINT("%02x", byte_value);
804 else
805 ND_PRINT("%u", byte_value);
806 ++bp;
807 --len;
808 first = 0;
809 }
810 break;
811
812 case '$':
813 /* Guys we can't handle with one of the usual cases */
814 switch (tag) {
815
816 case TAG_NETBIOS_NODE:
817 /* this option should be at least 1 byte long */
818 if (len < 1) {
819 ND_PRINT("ERROR: length < 1 bytes");
820 break;
821 }
822 tag = EXTRACT_U_1(bp);
823 ++bp;
824 --len;
825 ND_PRINT("%s", tok2str(nbo2str, NULL, tag));
826 break;
827
828 case TAG_OPT_OVERLOAD:
829 /* this option should be at least 1 byte long */
830 if (len < 1) {
831 ND_PRINT("ERROR: length < 1 bytes");
832 break;
833 }
834 tag = EXTRACT_U_1(bp);
835 ++bp;
836 --len;
837 ND_PRINT("%s", tok2str(oo2str, NULL, tag));
838 break;
839
840 case TAG_CLIENT_FQDN:
841 /* this option should be at least 3 bytes long */
842 if (len < 3) {
843 ND_PRINT("ERROR: length < 3 bytes");
844 bp += len;
845 len = 0;
846 break;
847 }
848 if (EXTRACT_U_1(bp))
849 ND_PRINT("[%s] ", client_fqdn_flags(EXTRACT_U_1(bp)));
850 bp++;
851 if (EXTRACT_U_1(bp) || EXTRACT_U_1(bp + 1))
852 ND_PRINT("%u/%u ", EXTRACT_U_1(bp), EXTRACT_U_1(bp + 1));
853 bp += 2;
854 ND_PRINT("\"");
855 if (nd_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
856 ND_PRINT("\"");
857 goto trunc;
858 }
859 ND_PRINT("\"");
860 bp += len - 3;
861 len = 0;
862 break;
863
864 case TAG_CLIENT_ID:
865 {
866 int type;
867
868 /* this option should be at least 1 byte long */
869 if (len < 1) {
870 ND_PRINT("ERROR: length < 1 bytes");
871 break;
872 }
873 type = EXTRACT_U_1(bp);
874 bp++;
875 len--;
876 if (type == 0) {
877 ND_PRINT("\"");
878 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
879 ND_PRINT("\"");
880 goto trunc;
881 }
882 ND_PRINT("\"");
883 bp += len;
884 len = 0;
885 break;
886 } else {
887 ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type));
888 while (len > 0) {
889 if (!first)
890 ND_PRINT(":");
891 ND_PRINT("%02x", EXTRACT_U_1(bp));
892 ++bp;
893 --len;
894 first = 0;
895 }
896 }
897 break;
898 }
899
900 case TAG_AGENT_CIRCUIT:
901 while (len >= 2) {
902 subopt = EXTRACT_U_1(bp);
903 suboptlen = EXTRACT_U_1(bp + 1);
904 bp += 2;
905 len -= 2;
906 if (suboptlen > len) {
907 ND_PRINT("\n\t %s SubOption %u, length %u: length goes past end of option",
908 tok2str(agent_suboption_values, "Unknown", subopt),
909 subopt,
910 suboptlen);
911 bp += len;
912 len = 0;
913 break;
914 }
915 ND_PRINT("\n\t %s SubOption %u, length %u: ",
916 tok2str(agent_suboption_values, "Unknown", subopt),
917 subopt,
918 suboptlen);
919 switch (subopt) {
920
921 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
922 case AGENT_SUBOPTION_REMOTE_ID:
923 case AGENT_SUBOPTION_SUBSCRIBER_ID:
924 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
925 goto trunc;
926 break;
927
928 default:
929 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
930 }
931
932 len -= suboptlen;
933 bp += suboptlen;
934 }
935 break;
936
937 case TAG_CLASSLESS_STATIC_RT:
938 case TAG_CLASSLESS_STA_RT_MS:
939 {
940 u_int mask_width, significant_octets, i;
941
942 /* this option should be at least 5 bytes long */
943 if (len < 5) {
944 ND_PRINT("ERROR: length < 5 bytes");
945 bp += len;
946 len = 0;
947 break;
948 }
949 while (len > 0) {
950 if (!first)
951 ND_PRINT(",");
952 mask_width = EXTRACT_U_1(bp);
953 bp++;
954 len--;
955 /* mask_width <= 32 */
956 if (mask_width > 32) {
957 ND_PRINT("[ERROR: Mask width (%u) > 32]", mask_width);
958 bp += len;
959 len = 0;
960 break;
961 }
962 significant_octets = (mask_width + 7) / 8;
963 /* significant octets + router(4) */
964 if (len < significant_octets + 4) {
965 ND_PRINT("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
966 bp += len;
967 len = 0;
968 break;
969 }
970 ND_PRINT("(");
971 if (mask_width == 0)
972 ND_PRINT("default");
973 else {
974 for (i = 0; i < significant_octets ; i++) {
975 if (i > 0)
976 ND_PRINT(".");
977 ND_PRINT("%u", EXTRACT_U_1(bp));
978 bp++;
979 }
980 for (i = significant_octets ; i < 4 ; i++)
981 ND_PRINT(".0");
982 ND_PRINT("/%u", mask_width);
983 }
984 ND_PRINT(":%s)", ipaddr_string(ndo, bp));
985 bp += 4;
986 len -= (significant_octets + 4);
987 first = 0;
988 }
989 break;
990 }
991
992 case TAG_USER_CLASS:
993 {
994 u_int suboptnumber = 1;
995
996 first = 1;
997 if (len < 2) {
998 ND_PRINT("ERROR: length < 2 bytes");
999 bp += len;
1000 len = 0;
1001 break;
1002 }
1003 while (len > 0) {
1004 suboptlen = EXTRACT_U_1(bp);
1005 bp++;
1006 len--;
1007 ND_PRINT("\n\t ");
1008 ND_PRINT("instance#%u: ", suboptnumber);
1009 if (suboptlen == 0) {
1010 ND_PRINT("ERROR: suboption length must be non-zero");
1011 bp += len;
1012 len = 0;
1013 break;
1014 }
1015 if (len < suboptlen) {
1016 ND_PRINT("ERROR: invalid option");
1017 bp += len;
1018 len = 0;
1019 break;
1020 }
1021 ND_PRINT("\"");
1022 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
1023 ND_PRINT("\"");
1024 goto trunc;
1025 }
1026 ND_PRINT("\"");
1027 ND_PRINT(", length %u", suboptlen);
1028 suboptnumber++;
1029 len -= suboptlen;
1030 bp += suboptlen;
1031 }
1032 break;
1033 }
1034
1035 default:
1036 ND_PRINT("[unknown special tag %u, size %u]",
1037 tag, len);
1038 bp += len;
1039 len = 0;
1040 break;
1041 }
1042 break;
1043 }
1044 /* Data left over? */
1045 if (len) {
1046 ND_PRINT("\n\t trailing data length %u", len);
1047 bp += len;
1048 }
1049 }
1050 return;
1051 trunc:
1052 ND_PRINT("|[rfc1048]");
1053 }
1054
1055 #define PRINTCMUADDR(m, s) { ND_TCHECK_4(&cmu->m); \
1056 if (EXTRACT_IPV4_TO_NETWORK_ORDER(cmu->m) != 0) \
1057 ND_PRINT(" %s:%s", s, ipaddr_string(ndo, cmu->m)); }
1058
1059 static void
1060 cmu_print(netdissect_options *ndo,
1061 const u_char *bp)
1062 {
1063 const struct cmu_vend *cmu;
1064 uint8_t v_flags;
1065
1066 ND_PRINT(" vend-cmu");
1067 cmu = (const struct cmu_vend *)bp;
1068
1069 /* Only print if there are unknown bits */
1070 ND_TCHECK_4(cmu->v_flags);
1071 v_flags = EXTRACT_U_1(cmu->v_flags);
1072 if ((v_flags & ~(VF_SMASK)) != 0)
1073 ND_PRINT(" F:0x%x", v_flags);
1074 PRINTCMUADDR(v_dgate, "DG");
1075 PRINTCMUADDR(v_smask, v_flags & VF_SMASK ? "SM" : "SM*");
1076 PRINTCMUADDR(v_dns1, "NS1");
1077 PRINTCMUADDR(v_dns2, "NS2");
1078 PRINTCMUADDR(v_ins1, "IEN1");
1079 PRINTCMUADDR(v_ins2, "IEN2");
1080 PRINTCMUADDR(v_ts1, "TS1");
1081 PRINTCMUADDR(v_ts2, "TS2");
1082 return;
1083
1084 trunc:
1085 nd_print_trunc(ndo);
1086 }
1087
1088 #undef PRINTCMUADDR
1089
1090 static char *
1091 client_fqdn_flags(u_int flags)
1092 {
1093 static char buf[8+1];
1094 int i = 0;
1095
1096 if (flags & CLIENT_FQDN_FLAGS_S)
1097 buf[i++] = 'S';
1098 if (flags & CLIENT_FQDN_FLAGS_O)
1099 buf[i++] = 'O';
1100 if (flags & CLIENT_FQDN_FLAGS_E)
1101 buf[i++] = 'E';
1102 if (flags & CLIENT_FQDN_FLAGS_N)
1103 buf[i++] = 'N';
1104 buf[i] = '\0';
1105
1106 return buf;
1107 }