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