]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
Include <fcntl.h> unconditionally
[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_SMTP_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 /* RFC8572 */
197 #define TAG_SZTP_REDIRECT ((uint8_t) 143)
198 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
199 #define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
200 /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml */
201 #define TAG_SLP_NAMING_AUTH ((uint8_t) 80)
202 #define TAG_CLIENT_FQDN ((uint8_t) 81)
203 #define TAG_AGENT_CIRCUIT ((uint8_t) 82)
204 #define TAG_AGENT_REMOTE ((uint8_t) 83)
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_CLIENT_LAST_TRANSACTION_TIME ((uint8_t) 91)
209 #define TAG_ASSOCIATED_IP ((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 /* RFC 4833, TZ codes */
215 #define TAG_TZ_PCODE ((uint8_t) 100)
216 #define TAG_TZ_TCODE ((uint8_t) 101)
217 #define TAG_NETINFO_PARENT ((uint8_t) 112)
218 #define TAG_NETINFO_PARENT_TAG ((uint8_t) 113)
219 #define TAG_URL ((uint8_t) 114)
220 #define TAG_MUDURL ((uint8_t) 161)
221
222 /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
223 #define DHCPDISCOVER 1
224 #define DHCPOFFER 2
225 #define DHCPREQUEST 3
226 #define DHCPDECLINE 4
227 #define DHCPACK 5
228 #define DHCPNAK 6
229 #define DHCPRELEASE 7
230 #define DHCPINFORM 8
231 /* Defined in RFC4388 */
232 #define DHCPLEASEQUERY 10
233 #define DHCPLEASEUNASSIGNED 11
234 #define DHCPLEASEUNKNOWN 12
235 #define DHCPLEASEACTIVE 13
236
237
238 /*
239 * "vendor" data permitted for CMU bootp clients.
240 */
241
242 struct cmu_vend {
243 nd_byte v_magic[4]; /* magic number */
244 nd_uint32_t v_flags; /* flags/opcodes, etc. */
245 nd_ipv4 v_smask; /* Subnet mask */
246 nd_ipv4 v_dgate; /* Default gateway */
247 nd_ipv4 v_dns1, v_dns2; /* Domain name servers */
248 nd_ipv4 v_ins1, v_ins2; /* IEN-116 name servers */
249 nd_ipv4 v_ts1, v_ts2; /* Time servers */
250 nd_byte v_unused[24]; /* currently unused */
251 };
252
253
254 /* v_flags values */
255 #define VF_SMASK 1 /* Subnet mask field contains valid data */
256
257 /* RFC 4702 DHCP Client FQDN Option */
258
259 #define CLIENT_FQDN_FLAGS_S 0x01
260 #define CLIENT_FQDN_FLAGS_O 0x02
261 #define CLIENT_FQDN_FLAGS_E 0x04
262 #define CLIENT_FQDN_FLAGS_N 0x08
263 /* end of original bootp.h */
264
265 static void rfc1048_print(netdissect_options *, const u_char *);
266 static void cmu_print(netdissect_options *, const u_char *);
267 static char *client_fqdn_flags(u_int flags);
268
269 static const struct tok bootp_flag_values[] = {
270 { 0x8000, "Broadcast" },
271 { 0, NULL}
272 };
273
274 static const struct tok bootp_op_values[] = {
275 { BOOTPREQUEST, "Request" },
276 { BOOTPREPLY, "Reply" },
277 { 0, NULL}
278 };
279
280 /*
281 * Print bootp requests
282 */
283 void
284 bootp_print(netdissect_options *ndo,
285 const u_char *cp, u_int length)
286 {
287 const struct bootp *bp;
288 static const u_char vm_cmu[4] = VM_CMU;
289 static const u_char vm_rfc1048[4] = VM_RFC1048;
290 uint8_t bp_op, bp_htype, bp_hlen;
291
292 ndo->ndo_protocol = "bootp";
293 bp = (const struct bootp *)cp;
294 bp_op = GET_U_1(bp->bp_op);
295 ND_PRINT("BOOTP/DHCP, %s",
296 tok2str(bootp_op_values, "unknown (0x%02x)", bp_op));
297
298 bp_htype = GET_U_1(bp->bp_htype);
299 bp_hlen = GET_U_1(bp->bp_hlen);
300 if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN && bp_op == BOOTPREQUEST) {
301 ND_PRINT(" from %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
302 }
303
304 ND_PRINT(", length %u", length);
305
306 if (!ndo->ndo_vflag)
307 return;
308
309 ND_TCHECK_2(bp->bp_secs);
310
311 /* The usual hardware address type is 1 (10Mb Ethernet) */
312 if (bp_htype != 1)
313 ND_PRINT(", htype %u", bp_htype);
314
315 /* The usual length for 10Mb Ethernet address is 6 bytes */
316 if (bp_htype != 1 || bp_hlen != MAC_ADDR_LEN)
317 ND_PRINT(", hlen %u", bp_hlen);
318
319 /* Only print interesting fields */
320 if (GET_U_1(bp->bp_hops))
321 ND_PRINT(", hops %u", GET_U_1(bp->bp_hops));
322 if (GET_BE_U_4(bp->bp_xid))
323 ND_PRINT(", xid 0x%x", GET_BE_U_4(bp->bp_xid));
324 if (GET_BE_U_2(bp->bp_secs))
325 ND_PRINT(", secs %u", GET_BE_U_2(bp->bp_secs));
326
327 ND_PRINT(", Flags [%s]",
328 bittok2str(bootp_flag_values, "none", GET_BE_U_2(bp->bp_flags)));
329 if (ndo->ndo_vflag > 1)
330 ND_PRINT(" (0x%04x)", GET_BE_U_2(bp->bp_flags));
331
332 /* Client's ip address */
333 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
334 ND_PRINT("\n\t Client-IP %s", GET_IPADDR_STRING(bp->bp_ciaddr));
335
336 /* 'your' ip address (bootp client) */
337 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
338 ND_PRINT("\n\t Your-IP %s", GET_IPADDR_STRING(bp->bp_yiaddr));
339
340 /* Server's ip address */
341 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
342 ND_PRINT("\n\t Server-IP %s", GET_IPADDR_STRING(bp->bp_siaddr));
343
344 /* Gateway's ip address */
345 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
346 ND_PRINT("\n\t Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
347
348 /* Client's Ethernet address */
349 if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN) {
350 ND_PRINT("\n\t Client-Ethernet-Address %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
351 }
352
353 if (GET_U_1(bp->bp_sname)) { /* get first char only */
354 ND_PRINT("\n\t sname \"");
355 if (nd_printztn(ndo, bp->bp_sname, (u_int)sizeof(bp->bp_sname),
356 ndo->ndo_snapend) == 0) {
357 ND_PRINT("\"");
358 nd_print_trunc(ndo);
359 return;
360 }
361 ND_PRINT("\"");
362 }
363 if (GET_U_1(bp->bp_file)) { /* get first char only */
364 ND_PRINT("\n\t file \"");
365 if (nd_printztn(ndo, bp->bp_file, (u_int)sizeof(bp->bp_file),
366 ndo->ndo_snapend) == 0) {
367 ND_PRINT("\"");
368 nd_print_trunc(ndo);
369 return;
370 }
371 ND_PRINT("\"");
372 }
373
374 /* Decode the vendor buffer */
375 ND_TCHECK_4(bp->bp_vend);
376 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
377 sizeof(uint32_t)) == 0)
378 rfc1048_print(ndo, bp->bp_vend);
379 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
380 sizeof(uint32_t)) == 0)
381 cmu_print(ndo, bp->bp_vend);
382 else {
383 uint32_t ul;
384
385 ul = GET_BE_U_4(bp->bp_vend);
386 if (ul != 0)
387 ND_PRINT("\n\t Vendor-#0x%x", ul);
388 }
389
390 return;
391 trunc:
392 nd_print_trunc(ndo);
393 }
394
395 /*
396 * The first character specifies the format to print:
397 * i - ip address (32 bits)
398 * p - ip address pairs (32 bits + 32 bits)
399 * l - long (32 bits)
400 * L - unsigned long (32 bits)
401 * s - short (16 bits)
402 * b - period-separated decimal bytes (variable length)
403 * x - colon-separated hex bytes (variable length)
404 * a - ASCII string (variable length)
405 * B - on/off (8 bits)
406 * $ - special (explicit code to handle)
407 */
408 static const struct tok tag2str[] = {
409 /* RFC1048 tags */
410 { TAG_PAD, " PAD" },
411 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
412 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
413 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
414 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
415 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
416 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
417 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
418 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
419 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
420 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
421 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
422 { TAG_HOSTNAME, "aHostname" }, /* ASCII hostname */
423 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
424 { TAG_END, " END" },
425 /* RFC1497 tags */
426 { TAG_DUMPPATH, "aDP" },
427 { TAG_DOMAINNAME, "aDomain-Name" },
428 { TAG_SWAP_SERVER, "iSS" },
429 { TAG_ROOTPATH, "aRP" },
430 { TAG_EXTPATH, "aEP" },
431 /* RFC2132 tags */
432 { TAG_IP_FORWARD, "BIPF" },
433 { TAG_NL_SRCRT, "BSRT" },
434 { TAG_PFILTERS, "pPF" },
435 { TAG_REASS_SIZE, "sRSZ" },
436 { TAG_DEF_TTL, "bTTL" },
437 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
438 { TAG_MTU_TABLE, "sMTU-Table" },
439 { TAG_INT_MTU, "sMTU" },
440 { TAG_LOCAL_SUBNETS, "BLSN" },
441 { TAG_BROAD_ADDR, "iBR" },
442 { TAG_DO_MASK_DISC, "BMD" },
443 { TAG_SUPPLY_MASK, "BMS" },
444 { TAG_DO_RDISC, "BRouter-Discovery" },
445 { TAG_RTR_SOL_ADDR, "iRSA" },
446 { TAG_STATIC_ROUTE, "pStatic-Route" },
447 { TAG_USE_TRAILERS, "BUT" },
448 { TAG_ARP_TIMEOUT, "lAT" },
449 { TAG_ETH_ENCAP, "BIE" },
450 { TAG_TCP_TTL, "bTT" },
451 { TAG_TCP_KEEPALIVE, "lKI" },
452 { TAG_KEEPALIVE_GO, "BKG" },
453 { TAG_NIS_DOMAIN, "aYD" },
454 { TAG_NIS_SERVERS, "iYS" },
455 { TAG_NTP_SERVERS, "iNTP" },
456 { TAG_VENDOR_OPTS, "bVendor-Option" },
457 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
458 { TAG_NETBIOS_DDS, "iWDD" },
459 { TAG_NETBIOS_NODE, "$Netbios-Node" },
460 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
461 { TAG_XWIN_FS, "iXFS" },
462 { TAG_XWIN_DM, "iXDM" },
463 { TAG_NIS_P_DOMAIN, "sN+D" },
464 { TAG_NIS_P_SERVERS, "iN+S" },
465 { TAG_MOBILE_HOME, "iMH" },
466 { TAG_SMTP_SERVER, "iSMTP" },
467 { TAG_POP3_SERVER, "iPOP3" },
468 { TAG_NNTP_SERVER, "iNNTP" },
469 { TAG_WWW_SERVER, "iWWW" },
470 { TAG_FINGER_SERVER, "iFG" },
471 { TAG_IRC_SERVER, "iIRC" },
472 { TAG_STREETTALK_SRVR, "iSTS" },
473 { TAG_STREETTALK_STDA, "iSTDA" },
474 { TAG_REQUESTED_IP, "iRequested-IP" },
475 { TAG_IP_LEASE, "lLease-Time" },
476 { TAG_OPT_OVERLOAD, "$OO" },
477 { TAG_TFTP_SERVER, "aTFTP" },
478 { TAG_BOOTFILENAME, "aBF" },
479 { TAG_DHCP_MESSAGE, " DHCP-Message" },
480 { TAG_SERVER_ID, "iServer-ID" },
481 { TAG_PARM_REQUEST, "bParameter-Request" },
482 { TAG_MESSAGE, "aMSG" },
483 { TAG_MAX_MSG_SIZE, "sMSZ" },
484 { TAG_RENEWAL_TIME, "lRN" },
485 { TAG_REBIND_TIME, "lRB" },
486 { TAG_VENDOR_CLASS, "aVendor-Class" },
487 { TAG_CLIENT_ID, "$Client-ID" },
488 /* RFC 2485 */
489 { TAG_OPEN_GROUP_UAP, "aUAP" },
490 /* RFC 2563 */
491 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
492 /* RFC 2610 */
493 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
494 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
495 /* RFC 2937 */
496 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
497 /* RFC 3004 - The User Class Option for DHCP */
498 { TAG_USER_CLASS, "$User-Class" },
499 /* RFC 3011 */
500 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
501 /* RFC 3442 */
502 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
503 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
504 /* RFC 8572 */
505 { TAG_SZTP_REDIRECT, "$SZTP-Redirect" },
506 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
507 { TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
508 /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#options */
509 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
510 { TAG_CLIENT_FQDN, "$FQDN" },
511 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
512 { TAG_AGENT_REMOTE, "bARMT" },
513 { TAG_TZ_STRING, "aTZSTR" },
514 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
515 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
516 { TAG_CLIENT_LAST_TRANSACTION_TIME, "LLast-Transaction-Time" },
517 { TAG_ASSOCIATED_IP, "iAssociated-IP" },
518 { TAG_CLIENT_ARCH, "sARCH" },
519 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
520 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
521 { TAG_LDAP_URL, "aLDAP" },
522 { TAG_TZ_PCODE, "aPOSIX-TZ" },
523 { TAG_TZ_TCODE, "aTZ-Name" },
524 { TAG_NETINFO_PARENT, "iNI" },
525 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
526 { TAG_URL, "aURL" },
527 { TAG_MUDURL, "aMUD-URL" },
528 { 0, NULL }
529 };
530
531 /* DHCP "options overload" types */
532 static const struct tok oo2str[] = {
533 { 1, "file" },
534 { 2, "sname" },
535 { 3, "file+sname" },
536 { 0, NULL }
537 };
538
539 /* NETBIOS over TCP/IP node type options */
540 static const struct tok nbo2str[] = {
541 { 0x1, "b-node" },
542 { 0x2, "p-node" },
543 { 0x4, "m-node" },
544 { 0x8, "h-node" },
545 { 0, NULL }
546 };
547
548 /* ARP Hardware types, for Client-ID option */
549 static const struct tok arp2str[] = {
550 { 0x1, "ether" },
551 { 0x6, "ieee802" },
552 { 0x7, "arcnet" },
553 { 0xf, "frelay" },
554 { 0x17, "strip" },
555 { 0x18, "ieee1394" },
556 { 0, NULL }
557 };
558
559 static const struct tok dhcp_msg_values[] = {
560 { DHCPDISCOVER, "Discover" },
561 { DHCPOFFER, "Offer" },
562 { DHCPREQUEST, "Request" },
563 { DHCPDECLINE, "Decline" },
564 { DHCPACK, "ACK" },
565 { DHCPNAK, "NACK" },
566 { DHCPRELEASE, "Release" },
567 { DHCPINFORM, "Inform" },
568 { DHCPLEASEQUERY, "LeaseQuery" },
569 { DHCPLEASEUNASSIGNED, "LeaseUnassigned" },
570 { DHCPLEASEUNKNOWN, "LeaseUnknown" },
571 { DHCPLEASEACTIVE, "LeaseActive" },
572 { 0, NULL }
573 };
574
575 #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
576 #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
577 #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
578 static const struct tok agent_suboption_values[] = {
579 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
580 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" },
581 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
582 { 0, NULL }
583 };
584
585
586 static void
587 rfc1048_print(netdissect_options *ndo,
588 const u_char *bp)
589 {
590 uint16_t tag;
591 u_int len;
592 const char *cp;
593 char c;
594 int first, idx;
595 uint8_t subopt, suboptlen;
596
597 ND_PRINT("\n\t Vendor-rfc1048 Extensions");
598
599 /* Step over magic cookie */
600 ND_PRINT("\n\t Magic Cookie 0x%08x", GET_BE_U_4(bp));
601 bp += sizeof(int32_t);
602
603 /* Loop while we there is a tag left in the buffer */
604 while (ND_TTEST_1(bp)) {
605 tag = GET_U_1(bp);
606 bp++;
607 if (tag == TAG_PAD && ndo->ndo_vflag < 3)
608 continue;
609 if (tag == TAG_END && ndo->ndo_vflag < 3)
610 return;
611 cp = tok2str(tag2str, "?Unknown", tag);
612 c = *cp++;
613
614 if (tag == TAG_PAD || tag == TAG_END)
615 len = 0;
616 else {
617 /* Get the length; check for truncation */
618 len = GET_U_1(bp);
619 bp++;
620 }
621
622 ND_PRINT("\n\t %s (%u), length %u%s", cp, tag, len,
623 len > 0 ? ": " : "");
624
625 if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
626 u_int ntag = 1;
627 while (ND_TTEST_1(bp) &&
628 GET_U_1(bp) == TAG_PAD) {
629 bp++;
630 ntag++;
631 }
632 if (ntag > 1)
633 ND_PRINT(", occurs %u", ntag);
634 }
635
636 ND_TCHECK_LEN(bp, len);
637
638 if (tag == TAG_DHCP_MESSAGE && len == 1) {
639 ND_PRINT("%s",
640 tok2str(dhcp_msg_values, "Unknown (%u)", GET_U_1(bp)));
641 bp++;
642 continue;
643 }
644
645 if (tag == TAG_PARM_REQUEST) {
646 idx = 0;
647 while (len > 0) {
648 uint8_t innertag = GET_U_1(bp);
649 bp++;
650 len--;
651 cp = tok2str(tag2str, "?Unknown", innertag);
652 if (idx % 4 == 0)
653 ND_PRINT("\n\t ");
654 else
655 ND_PRINT(", ");
656 ND_PRINT("%s (%u)", cp + 1, innertag);
657 idx++;
658 }
659 continue;
660 }
661
662 /* Print data */
663 if (c == '?') {
664 /* Base default formats for unknown tags on data size */
665 if (len & 1)
666 c = 'b';
667 else if (len & 2)
668 c = 's';
669 else
670 c = 'l';
671 }
672 first = 1;
673 switch (c) {
674
675 case 'a':
676 /* ASCII strings */
677 ND_PRINT("\"");
678 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
679 ND_PRINT("\"");
680 goto trunc;
681 }
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 client_fqdn_flags(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 if (nd_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
826 ND_PRINT("\"");
827 goto trunc;
828 }
829 ND_PRINT("\"");
830 bp += len - 3;
831 len = 0;
832 break;
833
834 case TAG_CLIENT_ID:
835 {
836 int type;
837
838 /* this option should be at least 1 byte long */
839 if (len < 1) {
840 ND_PRINT("[ERROR: length < 1 bytes]");
841 break;
842 }
843 type = GET_U_1(bp);
844 bp++;
845 len--;
846 if (type == 0) {
847 ND_PRINT("\"");
848 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
849 ND_PRINT("\"");
850 goto trunc;
851 }
852 ND_PRINT("\"");
853 bp += len;
854 len = 0;
855 break;
856 } else {
857 ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type));
858 while (len > 0) {
859 if (!first)
860 ND_PRINT(":");
861 ND_PRINT("%02x", GET_U_1(bp));
862 ++bp;
863 --len;
864 first = 0;
865 }
866 }
867 break;
868 }
869
870 case TAG_AGENT_CIRCUIT:
871 while (len >= 2) {
872 subopt = GET_U_1(bp);
873 suboptlen = GET_U_1(bp + 1);
874 bp += 2;
875 len -= 2;
876 if (suboptlen > len) {
877 ND_PRINT("\n\t %s SubOption %u, length %u: length goes past end of option",
878 tok2str(agent_suboption_values, "Unknown", subopt),
879 subopt,
880 suboptlen);
881 bp += len;
882 len = 0;
883 break;
884 }
885 ND_PRINT("\n\t %s SubOption %u, length %u: ",
886 tok2str(agent_suboption_values, "Unknown", subopt),
887 subopt,
888 suboptlen);
889 switch (subopt) {
890
891 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
892 case AGENT_SUBOPTION_REMOTE_ID:
893 case AGENT_SUBOPTION_SUBSCRIBER_ID:
894 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
895 goto trunc;
896 break;
897
898 default:
899 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
900 }
901
902 len -= suboptlen;
903 bp += suboptlen;
904 }
905 break;
906
907 case TAG_CLASSLESS_STATIC_RT:
908 case TAG_CLASSLESS_STA_RT_MS:
909 {
910 u_int mask_width, significant_octets, i;
911
912 /* this option should be at least 5 bytes long */
913 if (len < 5) {
914 ND_PRINT("[ERROR: length < 5 bytes]");
915 bp += len;
916 len = 0;
917 break;
918 }
919 while (len > 0) {
920 if (!first)
921 ND_PRINT(",");
922 mask_width = GET_U_1(bp);
923 bp++;
924 len--;
925 /* mask_width <= 32 */
926 if (mask_width > 32) {
927 ND_PRINT("[ERROR: Mask width (%u) > 32]", mask_width);
928 bp += len;
929 len = 0;
930 break;
931 }
932 significant_octets = (mask_width + 7) / 8;
933 /* significant octets + router(4) */
934 if (len < significant_octets + 4) {
935 ND_PRINT("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
936 bp += len;
937 len = 0;
938 break;
939 }
940 ND_PRINT("(");
941 if (mask_width == 0)
942 ND_PRINT("default");
943 else {
944 for (i = 0; i < significant_octets ; i++) {
945 if (i > 0)
946 ND_PRINT(".");
947 ND_PRINT("%u",
948 GET_U_1(bp));
949 bp++;
950 }
951 for (i = significant_octets ; i < 4 ; i++)
952 ND_PRINT(".0");
953 ND_PRINT("/%u", mask_width);
954 }
955 ND_PRINT(":%s)", GET_IPADDR_STRING(bp));
956 bp += 4;
957 len -= (significant_octets + 4);
958 first = 0;
959 }
960 break;
961 }
962
963 case TAG_USER_CLASS:
964 {
965 u_int suboptnumber = 1;
966
967 first = 1;
968 if (len < 2) {
969 ND_PRINT("[ERROR: length < 2 bytes]");
970 bp += len;
971 len = 0;
972 break;
973 }
974 while (len > 0) {
975 suboptlen = GET_U_1(bp);
976 bp++;
977 len--;
978 ND_PRINT("\n\t ");
979 ND_PRINT("instance#%u: ", suboptnumber);
980 if (suboptlen == 0) {
981 ND_PRINT("[ERROR: suboption length must be non-zero]");
982 bp += len;
983 len = 0;
984 break;
985 }
986 if (len < suboptlen) {
987 ND_PRINT("[ERROR: invalid option]");
988 bp += len;
989 len = 0;
990 break;
991 }
992 ND_PRINT("\"");
993 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
994 ND_PRINT("\"");
995 goto trunc;
996 }
997 ND_PRINT("\"");
998 ND_PRINT(", length %u", suboptlen);
999 suboptnumber++;
1000 len -= suboptlen;
1001 bp += suboptlen;
1002 }
1003 break;
1004 }
1005
1006
1007 case TAG_SZTP_REDIRECT:
1008 /* as per https://datatracker.ietf.org/doc/html/rfc8572#section-8.3
1009 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1010 | uri-length | URI |
1011 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1012
1013 * uri-length: 2 octets long; specifies the length of the URI data.
1014 * URI: URI of the SZTP bootstrap server.
1015 */
1016 while (len >= 2) {
1017 suboptlen = GET_BE_U_2(bp);
1018 bp += 2;
1019 len -= 2;
1020 ND_PRINT("\n\t ");
1021 ND_PRINT("length %u: ", suboptlen);
1022 if (len < suboptlen) {
1023 ND_PRINT("length goes past end of option");
1024 bp += len;
1025 len = 0;
1026 break;
1027 }
1028 ND_PRINT("\"");
1029 nd_printjn(ndo, bp, suboptlen);
1030 ND_PRINT("\"");
1031 len -= suboptlen;
1032 bp += suboptlen;
1033 }
1034 if (len != 0) {
1035 ND_PRINT("[ERROR: length < 2 bytes]");
1036 }
1037 break;
1038
1039 default:
1040 ND_PRINT("[unknown special tag %u, size %u]",
1041 tag, len);
1042 bp += len;
1043 len = 0;
1044 break;
1045 }
1046 break;
1047 }
1048 /* Data left over? */
1049 if (len) {
1050 ND_PRINT("\n\t trailing data length %u", len);
1051 bp += len;
1052 }
1053 }
1054 return;
1055 trunc:
1056 nd_print_trunc(ndo);
1057 }
1058
1059 #define PRINTCMUADDR(m, s) { ND_TCHECK_4(cmu->m); \
1060 if (GET_IPV4_TO_NETWORK_ORDER(cmu->m) != 0) \
1061 ND_PRINT(" %s:%s", s, GET_IPADDR_STRING(cmu->m)); }
1062
1063 static void
1064 cmu_print(netdissect_options *ndo,
1065 const u_char *bp)
1066 {
1067 const struct cmu_vend *cmu;
1068 uint8_t v_flags;
1069
1070 ND_PRINT(" vend-cmu");
1071 cmu = (const struct cmu_vend *)bp;
1072
1073 /* Only print if there are unknown bits */
1074 ND_TCHECK_4(cmu->v_flags);
1075 v_flags = GET_U_1(cmu->v_flags);
1076 if ((v_flags & ~(VF_SMASK)) != 0)
1077 ND_PRINT(" F:0x%x", v_flags);
1078 PRINTCMUADDR(v_dgate, "DG");
1079 PRINTCMUADDR(v_smask, v_flags & VF_SMASK ? "SM" : "SM*");
1080 PRINTCMUADDR(v_dns1, "NS1");
1081 PRINTCMUADDR(v_dns2, "NS2");
1082 PRINTCMUADDR(v_ins1, "IEN1");
1083 PRINTCMUADDR(v_ins2, "IEN2");
1084 PRINTCMUADDR(v_ts1, "TS1");
1085 PRINTCMUADDR(v_ts2, "TS2");
1086 return;
1087
1088 trunc:
1089 nd_print_trunc(ndo);
1090 }
1091
1092 #undef PRINTCMUADDR
1093
1094 static char *
1095 client_fqdn_flags(u_int flags)
1096 {
1097 static char buf[8+1];
1098 int i = 0;
1099
1100 if (flags & CLIENT_FQDN_FLAGS_S)
1101 buf[i++] = 'S';
1102 if (flags & CLIENT_FQDN_FLAGS_O)
1103 buf[i++] = 'O';
1104 if (flags & CLIENT_FQDN_FLAGS_E)
1105 buf[i++] = 'E';
1106 if (flags & CLIENT_FQDN_FLAGS_N)
1107 buf[i++] = 'N';
1108 buf[i] = '\0';
1109
1110 return buf;
1111 }