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