print-bootp.c revision 1.13 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 #include <sys/cdefs.h>
25 #ifndef lint
26 __RCSID("$NetBSD: print-bootp.c,v 1.13 2026/03/19 00:05:13 christos Exp $");
27 #endif
28
29 #include <config.h>
30
31 #include "netdissect-stdinc.h"
32
33 #include <string.h>
34
35 #include "netdissect.h"
36 #include "addrtoname.h"
37 #include "extract.h"
38
39
40 /*
41 * Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
42 *
43 * This file specifies the "implementation-independent" BOOTP protocol
44 * information which is common to both client and server.
45 *
46 * Copyright 1988 by Carnegie Mellon.
47 *
48 * Permission to use, copy, modify, and distribute this program for any
49 * purpose and without fee is hereby granted, provided that this copyright
50 * and permission notice appear on all copies and supporting documentation,
51 * the name of Carnegie Mellon not be used in advertising or publicity
52 * pertaining to distribution of the program without specific prior
53 * permission, and notice be given in supporting documentation that copying
54 * and distribution is by permission of Carnegie Mellon and Stanford
55 * University. Carnegie Mellon makes no representations about the
56 * suitability of this software for any purpose. It is provided "as is"
57 * without express or implied warranty.
58 */
59
60 struct bootp {
61 nd_uint8_t bp_op; /* packet opcode type */
62 nd_uint8_t bp_htype; /* hardware addr type */
63 nd_uint8_t bp_hlen; /* hardware addr length */
64 nd_uint8_t bp_hops; /* gateway hops */
65 nd_uint32_t bp_xid; /* transaction ID */
66 nd_uint16_t bp_secs; /* seconds since boot began */
67 nd_uint16_t bp_flags; /* flags - see bootp_flag_values[]
68 in print-bootp.c */
69 nd_ipv4 bp_ciaddr; /* client IP address */
70 nd_ipv4 bp_yiaddr; /* 'your' IP address */
71 nd_ipv4 bp_siaddr; /* server IP address */
72 nd_ipv4 bp_giaddr; /* gateway IP address */
73 nd_byte bp_chaddr[16]; /* client hardware address */
74 nd_byte bp_sname[64]; /* server host name */
75 nd_byte bp_file[128]; /* boot file name */
76 nd_byte bp_vend[64]; /* vendor-specific area */
77 };
78
79 #define BOOTPREPLY 2
80 #define BOOTPREQUEST 1
81
82 /*
83 * Vendor magic cookie (v_magic) for CMU
84 */
85 #define VM_CMU "CMU"
86
87 /*
88 * Vendor magic cookie (v_magic) for RFC1048
89 */
90 #define VM_RFC1048 { 99, 130, 83, 99 }
91
92 /*
93 * RFC1048 tag values used to specify what information is being supplied in
94 * the vendor field of the packet.
95 */
96
97 #define TAG_PAD ((uint8_t) 0)
98 #define TAG_SUBNET_MASK ((uint8_t) 1)
99 #define TAG_TIME_OFFSET ((uint8_t) 2)
100 #define TAG_GATEWAY ((uint8_t) 3)
101 #define TAG_TIME_SERVER ((uint8_t) 4)
102 #define TAG_NAME_SERVER ((uint8_t) 5)
103 #define TAG_DOMAIN_SERVER ((uint8_t) 6)
104 #define TAG_LOG_SERVER ((uint8_t) 7)
105 #define TAG_COOKIE_SERVER ((uint8_t) 8)
106 #define TAG_LPR_SERVER ((uint8_t) 9)
107 #define TAG_IMPRESS_SERVER ((uint8_t) 10)
108 #define TAG_RLP_SERVER ((uint8_t) 11)
109 #define TAG_HOSTNAME ((uint8_t) 12)
110 #define TAG_BOOTSIZE ((uint8_t) 13)
111 #define TAG_END ((uint8_t) 255)
112 /* RFC1497 tags */
113 #define TAG_DUMPPATH ((uint8_t) 14)
114 #define TAG_DOMAINNAME ((uint8_t) 15)
115 #define TAG_SWAP_SERVER ((uint8_t) 16)
116 #define TAG_ROOTPATH ((uint8_t) 17)
117 #define TAG_EXTPATH ((uint8_t) 18)
118 /* RFC2132 */
119 #define TAG_IP_FORWARD ((uint8_t) 19)
120 #define TAG_NL_SRCRT ((uint8_t) 20)
121 #define TAG_PFILTERS ((uint8_t) 21)
122 #define TAG_REASS_SIZE ((uint8_t) 22)
123 #define TAG_DEF_TTL ((uint8_t) 23)
124 #define TAG_MTU_TIMEOUT ((uint8_t) 24)
125 #define TAG_MTU_TABLE ((uint8_t) 25)
126 #define TAG_INT_MTU ((uint8_t) 26)
127 #define TAG_LOCAL_SUBNETS ((uint8_t) 27)
128 #define TAG_BROAD_ADDR ((uint8_t) 28)
129 #define TAG_DO_MASK_DISC ((uint8_t) 29)
130 #define TAG_SUPPLY_MASK ((uint8_t) 30)
131 #define TAG_DO_RDISC ((uint8_t) 31)
132 #define TAG_RTR_SOL_ADDR ((uint8_t) 32)
133 #define TAG_STATIC_ROUTE ((uint8_t) 33)
134 #define TAG_USE_TRAILERS ((uint8_t) 34)
135 #define TAG_ARP_TIMEOUT ((uint8_t) 35)
136 #define TAG_ETH_ENCAP ((uint8_t) 36)
137 #define TAG_TCP_TTL ((uint8_t) 37)
138 #define TAG_TCP_KEEPALIVE ((uint8_t) 38)
139 #define TAG_KEEPALIVE_GO ((uint8_t) 39)
140 #define TAG_NIS_DOMAIN ((uint8_t) 40)
141 #define TAG_NIS_SERVERS ((uint8_t) 41)
142 #define TAG_NTP_SERVERS ((uint8_t) 42)
143 #define TAG_VENDOR_OPTS ((uint8_t) 43)
144 #define TAG_NETBIOS_NS ((uint8_t) 44)
145 #define TAG_NETBIOS_DDS ((uint8_t) 45)
146 #define TAG_NETBIOS_NODE ((uint8_t) 46)
147 #define TAG_NETBIOS_SCOPE ((uint8_t) 47)
148 #define TAG_XWIN_FS ((uint8_t) 48)
149 #define TAG_XWIN_DM ((uint8_t) 49)
150 #define TAG_NIS_P_DOMAIN ((uint8_t) 64)
151 #define TAG_NIS_P_SERVERS ((uint8_t) 65)
152 #define TAG_MOBILE_HOME ((uint8_t) 68)
153 #define TAG_SMTP_SERVER ((uint8_t) 69)
154 #define TAG_POP3_SERVER ((uint8_t) 70)
155 #define TAG_NNTP_SERVER ((uint8_t) 71)
156 #define TAG_WWW_SERVER ((uint8_t) 72)
157 #define TAG_FINGER_SERVER ((uint8_t) 73)
158 #define TAG_IRC_SERVER ((uint8_t) 74)
159 #define TAG_STREETTALK_SRVR ((uint8_t) 75)
160 #define TAG_STREETTALK_STDA ((uint8_t) 76)
161 /* DHCP options */
162 #define TAG_REQUESTED_IP ((uint8_t) 50)
163 #define TAG_IP_LEASE ((uint8_t) 51)
164 #define TAG_OPT_OVERLOAD ((uint8_t) 52)
165 #define TAG_TFTP_SERVER ((uint8_t) 66)
166 #define TAG_BOOTFILENAME ((uint8_t) 67)
167 #define TAG_DHCP_MESSAGE ((uint8_t) 53)
168 #define TAG_SERVER_ID ((uint8_t) 54)
169 #define TAG_PARM_REQUEST ((uint8_t) 55)
170 #define TAG_MESSAGE ((uint8_t) 56)
171 #define TAG_MAX_MSG_SIZE ((uint8_t) 57)
172 #define TAG_RENEWAL_TIME ((uint8_t) 58)
173 #define TAG_REBIND_TIME ((uint8_t) 59)
174 #define TAG_VENDOR_CLASS ((uint8_t) 60)
175 #define TAG_CLIENT_ID ((uint8_t) 61)
176 /* RFC 2241 */
177 #define TAG_NDS_SERVERS ((uint8_t) 85)
178 #define TAG_NDS_TREE_NAME ((uint8_t) 86)
179 #define TAG_NDS_CONTEXT ((uint8_t) 87)
180 /* RFC 2242 */
181 #define TAG_NDS_IPDOMAIN ((uint8_t) 62)
182 #define TAG_NDS_IPINFO ((uint8_t) 63)
183 /* RFC 2485 */
184 #define TAG_OPEN_GROUP_UAP ((uint8_t) 98)
185 /* RFC 2563 */
186 #define TAG_AUTO_CONFIGURE ((uint8_t) 116)
187 /* RFC 2610 */
188 #define TAG_SLP_DA ((uint8_t) 78)
189 #define TAG_SLP_SCOPE ((uint8_t) 79)
190 /* RFC 2937 */
191 #define TAG_NS_SEARCH ((uint8_t) 117)
192 /* RFC 3004 - The User Class Option for DHCP */
193 #define TAG_USER_CLASS ((uint8_t) 77)
194 /* RFC 3011 */
195 #define TAG_IP4_SUBNET_SELECT ((uint8_t) 118)
196 /* RFC 3442 */
197 #define TAG_CLASSLESS_STATIC_RT ((uint8_t) 121)
198 #define TAG_CLASSLESS_STA_RT_MS ((uint8_t) 249)
199 /* RFC8572 */
200 #define TAG_SZTP_REDIRECT ((uint8_t) 143)
201 /* RFC 5859 - TFTP Server Address Option for DHCPv4 */
202 #define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
203 /* https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml */
204 #define TAG_SLP_NAMING_AUTH ((uint8_t) 80)
205 #define TAG_CLIENT_FQDN ((uint8_t) 81)
206 #define TAG_AGENT_CIRCUIT ((uint8_t) 82)
207 #define TAG_AGENT_REMOTE ((uint8_t) 83)
208 #define TAG_TZ_STRING ((uint8_t) 88)
209 #define TAG_FQDN_OPTION ((uint8_t) 89)
210 #define TAG_AUTH ((uint8_t) 90)
211 #define TAG_CLIENT_LAST_TRANSACTION_TIME ((uint8_t) 91)
212 #define TAG_ASSOCIATED_IP ((uint8_t) 92)
213 #define TAG_CLIENT_ARCH ((uint8_t) 93)
214 #define TAG_CLIENT_NDI ((uint8_t) 94)
215 #define TAG_CLIENT_GUID ((uint8_t) 97)
216 #define TAG_LDAP_URL ((uint8_t) 95)
217 /* RFC 4833, TZ codes */
218 #define TAG_TZ_PCODE ((uint8_t) 100)
219 #define TAG_TZ_TCODE ((uint8_t) 101)
220 #define TAG_NETINFO_PARENT ((uint8_t) 112)
221 #define TAG_NETINFO_PARENT_TAG ((uint8_t) 113)
222 #define TAG_URL ((uint8_t) 114)
223 #define TAG_MUDURL ((uint8_t) 161)
224
225 /* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
226 #define DHCPDISCOVER 1
227 #define DHCPOFFER 2
228 #define DHCPREQUEST 3
229 #define DHCPDECLINE 4
230 #define DHCPACK 5
231 #define DHCPNAK 6
232 #define DHCPRELEASE 7
233 #define DHCPINFORM 8
234 /* Defined in RFC4388 */
235 #define DHCPLEASEQUERY 10
236 #define DHCPLEASEUNASSIGNED 11
237 #define DHCPLEASEUNKNOWN 12
238 #define DHCPLEASEACTIVE 13
239
240
241 /*
242 * "vendor" data permitted for CMU bootp clients.
243 */
244
245 struct cmu_vend {
246 nd_byte v_magic[4]; /* magic number */
247 nd_uint32_t v_flags; /* flags/opcodes, etc. */
248 nd_ipv4 v_smask; /* Subnet mask */
249 nd_ipv4 v_dgate; /* Default gateway */
250 nd_ipv4 v_dns1, v_dns2; /* Domain name servers */
251 nd_ipv4 v_ins1, v_ins2; /* IEN-116 name servers */
252 nd_ipv4 v_ts1, v_ts2; /* Time servers */
253 nd_byte v_unused[24]; /* currently unused */
254 };
255
256
257 /* v_flags values */
258 #define VF_SMASK 1 /* Subnet mask field contains valid data */
259
260 /* RFC 4702 DHCP Client FQDN Option */
261
262 #define CLIENT_FQDN_FLAGS_S 0x01
263 #define CLIENT_FQDN_FLAGS_O 0x02
264 #define CLIENT_FQDN_FLAGS_E 0x04
265 #define CLIENT_FQDN_FLAGS_N 0x08
266 /* end of original bootp.h */
267
268 static void rfc1048_print(netdissect_options *, const u_char *);
269 static void cmu_print(netdissect_options *, const u_char *);
270 static char *client_fqdn_flags(u_int flags);
271
272 static const struct tok bootp_flag_values[] = {
273 { 0x8000, "Broadcast" },
274 { 0, NULL}
275 };
276
277 static const struct tok bootp_op_values[] = {
278 { BOOTPREQUEST, "Request" },
279 { BOOTPREPLY, "Reply" },
280 { 0, NULL}
281 };
282
283 /*
284 * Print bootp requests
285 */
286 void
287 bootp_print(netdissect_options *ndo,
288 const u_char *cp, u_int length)
289 {
290 const struct bootp *bp;
291 static const u_char vm_cmu[4] = VM_CMU;
292 static const u_char vm_rfc1048[4] = VM_RFC1048;
293 uint8_t bp_op, bp_htype, bp_hlen;
294
295 ndo->ndo_protocol = "bootp";
296 bp = (const struct bootp *)cp;
297 bp_op = GET_U_1(bp->bp_op);
298 ND_PRINT("BOOTP/DHCP, %s",
299 tok2str(bootp_op_values, "unknown (0x%02x)", bp_op));
300
301 bp_htype = GET_U_1(bp->bp_htype);
302 bp_hlen = GET_U_1(bp->bp_hlen);
303 if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN && bp_op == BOOTPREQUEST) {
304 ND_PRINT(" from %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
305 }
306
307 ND_PRINT(", length %u", length);
308
309 if (!ndo->ndo_vflag)
310 return;
311
312 ND_TCHECK_2(bp->bp_secs);
313
314 /* The usual hardware address type is 1 (10Mb Ethernet) */
315 if (bp_htype != 1)
316 ND_PRINT(", htype %u", bp_htype);
317
318 /* The usual length for 10Mb Ethernet address is 6 bytes */
319 if (bp_htype != 1 || bp_hlen != MAC_ADDR_LEN)
320 ND_PRINT(", hlen %u", bp_hlen);
321
322 /* Only print interesting fields */
323 if (GET_U_1(bp->bp_hops))
324 ND_PRINT(", hops %u", GET_U_1(bp->bp_hops));
325 if (GET_BE_U_4(bp->bp_xid))
326 ND_PRINT(", xid 0x%x", GET_BE_U_4(bp->bp_xid));
327 if (GET_BE_U_2(bp->bp_secs))
328 ND_PRINT(", secs %u", GET_BE_U_2(bp->bp_secs));
329
330 ND_PRINT(", Flags [%s]",
331 bittok2str(bootp_flag_values, "none", GET_BE_U_2(bp->bp_flags)));
332 if (ndo->ndo_vflag > 1)
333 ND_PRINT(" (0x%04x)", GET_BE_U_2(bp->bp_flags));
334
335 /* Client's ip address */
336 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_ciaddr))
337 ND_PRINT("\n\t Client-IP %s", GET_IPADDR_STRING(bp->bp_ciaddr));
338
339 /* 'your' ip address (bootp client) */
340 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_yiaddr))
341 ND_PRINT("\n\t Your-IP %s", GET_IPADDR_STRING(bp->bp_yiaddr));
342
343 /* Server's ip address */
344 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_siaddr))
345 ND_PRINT("\n\t Server-IP %s", GET_IPADDR_STRING(bp->bp_siaddr));
346
347 /* Gateway's ip address */
348 if (GET_IPV4_TO_NETWORK_ORDER(bp->bp_giaddr))
349 ND_PRINT("\n\t Gateway-IP %s", GET_IPADDR_STRING(bp->bp_giaddr));
350
351 /* Client's Ethernet address */
352 if (bp_htype == 1 && bp_hlen == MAC_ADDR_LEN) {
353 ND_PRINT("\n\t Client-Ethernet-Address %s", GET_ETHERADDR_STRING(bp->bp_chaddr));
354 }
355
356 if (GET_U_1(bp->bp_sname)) { /* get first char only */
357 ND_PRINT("\n\t sname \"");
358 if (nd_printztn(ndo, bp->bp_sname, (u_int)sizeof(bp->bp_sname),
359 ndo->ndo_snapend) == 0) {
360 ND_PRINT("\"");
361 nd_print_trunc(ndo);
362 return;
363 }
364 ND_PRINT("\"");
365 }
366 if (GET_U_1(bp->bp_file)) { /* get first char only */
367 ND_PRINT("\n\t file \"");
368 if (nd_printztn(ndo, bp->bp_file, (u_int)sizeof(bp->bp_file),
369 ndo->ndo_snapend) == 0) {
370 ND_PRINT("\"");
371 nd_print_trunc(ndo);
372 return;
373 }
374 ND_PRINT("\"");
375 }
376
377 /* Decode the vendor buffer */
378 ND_TCHECK_4(bp->bp_vend);
379 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
380 sizeof(uint32_t)) == 0)
381 rfc1048_print(ndo, bp->bp_vend);
382 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
383 sizeof(uint32_t)) == 0)
384 cmu_print(ndo, bp->bp_vend);
385 else {
386 uint32_t ul;
387
388 ul = GET_BE_U_4(bp->bp_vend);
389 if (ul != 0)
390 ND_PRINT("\n\t Vendor-#0x%x", ul);
391 }
392
393 return;
394 trunc:
395 nd_print_trunc(ndo);
396 }
397
398 /*
399 * The first character specifies the format to print:
400 * i - ip address (32 bits)
401 * p - ip address pairs (32 bits + 32 bits)
402 * l - unsigned longs (32 bits)
403 * L - longs (32 bits)
404 * s - unsigned shorts (16 bits)
405 * b - period-separated decimal bytes (variable length)
406 * x - colon-separated hex bytes (variable length)
407 * a - ASCII string (variable length)
408 * B - on/off (8 bits)
409 * $ - special (explicit code to handle)
410 */
411 static const struct tok tag2str[] = {
412 /* RFC1048 tags */
413 { TAG_PAD, " PAD" },
414 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
415 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
416 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
417 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
418 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
419 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
420 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
421 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
422 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
423 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
424 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
425 { TAG_HOSTNAME, "aHostname" }, /* ASCII hostname */
426 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
427 { TAG_END, " END" },
428 /* RFC1497 tags */
429 { TAG_DUMPPATH, "aDP" },
430 { TAG_DOMAINNAME, "aDomain-Name" },
431 { TAG_SWAP_SERVER, "iSS" },
432 { TAG_ROOTPATH, "aRP" },
433 { TAG_EXTPATH, "aEP" },
434 /* RFC2132 tags */
435 { TAG_IP_FORWARD, "BIPF" },
436 { TAG_NL_SRCRT, "BSRT" },
437 { TAG_PFILTERS, "pPF" },
438 { TAG_REASS_SIZE, "sRSZ" },
439 { TAG_DEF_TTL, "bTTL" },
440 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
441 { TAG_MTU_TABLE, "sMTU-Table" },
442 { TAG_INT_MTU, "sMTU" },
443 { TAG_LOCAL_SUBNETS, "BLSN" },
444 { TAG_BROAD_ADDR, "iBR" },
445 { TAG_DO_MASK_DISC, "BMD" },
446 { TAG_SUPPLY_MASK, "BMS" },
447 { TAG_DO_RDISC, "BRouter-Discovery" },
448 { TAG_RTR_SOL_ADDR, "iRSA" },
449 { TAG_STATIC_ROUTE, "pStatic-Route" },
450 { TAG_USE_TRAILERS, "BUT" },
451 { TAG_ARP_TIMEOUT, "lAT" },
452 { TAG_ETH_ENCAP, "BIE" },
453 { TAG_TCP_TTL, "bTT" },
454 { TAG_TCP_KEEPALIVE, "lKI" },
455 { TAG_KEEPALIVE_GO, "BKG" },
456 { TAG_NIS_DOMAIN, "aYD" },
457 { TAG_NIS_SERVERS, "iYS" },
458 { TAG_NTP_SERVERS, "iNTP" },
459 { TAG_VENDOR_OPTS, "bVendor-Option" },
460 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
461 { TAG_NETBIOS_DDS, "iWDD" },
462 { TAG_NETBIOS_NODE, "$Netbios-Node" },
463 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
464 { TAG_XWIN_FS, "iXFS" },
465 { TAG_XWIN_DM, "iXDM" },
466 { TAG_NIS_P_DOMAIN, "sN+D" },
467 { TAG_NIS_P_SERVERS, "iN+S" },
468 { TAG_MOBILE_HOME, "iMH" },
469 { TAG_SMTP_SERVER, "iSMTP" },
470 { TAG_POP3_SERVER, "iPOP3" },
471 { TAG_NNTP_SERVER, "iNNTP" },
472 { TAG_WWW_SERVER, "iWWW" },
473 { TAG_FINGER_SERVER, "iFG" },
474 { TAG_IRC_SERVER, "iIRC" },
475 { TAG_STREETTALK_SRVR, "iSTS" },
476 { TAG_STREETTALK_STDA, "iSTDA" },
477 { TAG_REQUESTED_IP, "iRequested-IP" },
478 { TAG_IP_LEASE, "lLease-Time" },
479 { TAG_OPT_OVERLOAD, "$OO" },
480 { TAG_TFTP_SERVER, "aTFTP" },
481 { TAG_BOOTFILENAME, "aBF" },
482 { TAG_DHCP_MESSAGE, " DHCP-Message" },
483 { TAG_SERVER_ID, "iServer-ID" },
484 { TAG_PARM_REQUEST, "bParameter-Request" },
485 { TAG_MESSAGE, "aMSG" },
486 { TAG_MAX_MSG_SIZE, "sMSZ" },
487 { TAG_RENEWAL_TIME, "lRN" },
488 { TAG_REBIND_TIME, "lRB" },
489 { TAG_VENDOR_CLASS, "aVendor-Class" },
490 { TAG_CLIENT_ID, "$Client-ID" },
491 /* RFC 2485 */
492 { TAG_OPEN_GROUP_UAP, "aUAP" },
493 /* RFC 2563 */
494 { TAG_AUTO_CONFIGURE, "BAuto-Configure" },
495 /* RFC 2610 */
496 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
497 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
498 /* RFC 2937 */
499 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
500 /* RFC 3004 - The User Class Option for DHCP */
501 { TAG_USER_CLASS, "$User-Class" },
502 /* RFC 3011 */
503 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
504 /* RFC 3442 */
505 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
506 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
507 /* RFC 8572 */
508 { TAG_SZTP_REDIRECT, "$SZTP-Redirect" },
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 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
682 ND_PRINT("\"");
683 goto trunc;
684 }
685 ND_PRINT("\"");
686 bp += len;
687 len = 0;
688 break;
689
690 case 'i':
691 case 'l':
692 case 'L':
693 /* ip addresses/32-bit words */
694 while (len >= 4) {
695 if (!first)
696 ND_PRINT(",");
697 if (c == 'i')
698 ND_PRINT("%s", GET_IPADDR_STRING(bp));
699 else if (c == 'L')
700 ND_PRINT("%d", GET_BE_S_4(bp));
701 else
702 ND_PRINT("%u", GET_BE_U_4(bp));
703 bp += 4;
704 len -= 4;
705 first = 0;
706 }
707 break;
708
709 case 'p':
710 /* IP address pairs */
711 /* this option should be N x 8 bytes long */
712 if (len < 8 || len % 8 != 0) {
713 ND_PRINT("%s[length != N x 8 bytes]",
714 len == 0 ? " " : "");
715 bp += len;
716 len = 0;
717 break;
718 }
719 while (len >= 2*4) {
720 if (!first)
721 ND_PRINT(",");
722 ND_PRINT("(%s:", GET_IPADDR_STRING(bp));
723 bp += 4;
724 len -= 4;
725 ND_PRINT("%s)", GET_IPADDR_STRING(bp));
726 bp += 4;
727 len -= 4;
728 first = 0;
729 }
730 break;
731
732 case 's':
733 /* unsigned shorts */
734 while (len >= 2) {
735 if (!first)
736 ND_PRINT(",");
737 ND_PRINT("%u", GET_BE_U_2(bp));
738 bp += 2;
739 len -= 2;
740 first = 0;
741 }
742 break;
743
744 case 'B':
745 /* boolean */
746 {
747 /* this option should be 1 byte long */
748 if (len != 1) {
749 ND_PRINT("[length != 1 byte]");
750 nd_print_invalid(ndo);
751 bp += len;
752 len = 0;
753 break;
754 }
755
756 uint8_t bool_value;
757 bool_value = GET_U_1(bp);
758 switch (bool_value) {
759 case 0:
760 ND_PRINT("N");
761 break;
762 case 1:
763 ND_PRINT("Y");
764 break;
765 default:
766 ND_PRINT("%u?", bool_value);
767 break;
768 }
769 ++bp;
770 --len;
771 break;
772 }
773
774 case 'b':
775 case 'x':
776 default:
777 /* Bytes */
778 while (len > 0) {
779 uint8_t byte_value;
780 if (!first)
781 ND_PRINT(c == 'x' ? ":" : ".");
782 byte_value = GET_U_1(bp);
783 if (c == 'x')
784 ND_PRINT("%02x", byte_value);
785 else
786 ND_PRINT("%u", byte_value);
787 ++bp;
788 --len;
789 first = 0;
790 }
791 break;
792
793 case '$':
794 /* Guys we can't handle with one of the usual cases */
795 switch (tag) {
796
797 case TAG_NETBIOS_NODE:
798 /* this option should be at least 1 byte long */
799 if (len < 1) {
800 ND_PRINT("[length < 1 byte]");
801 nd_print_invalid(ndo);
802 break;
803 }
804 tag = GET_U_1(bp);
805 ++bp;
806 --len;
807 ND_PRINT("%s", tok2str(nbo2str, NULL, tag));
808 break;
809
810 case TAG_OPT_OVERLOAD:
811 /* this option should be at least 1 byte long */
812 if (len < 1) {
813 ND_PRINT("[length < 1 byte]");
814 nd_print_invalid(ndo);
815 break;
816 }
817 tag = GET_U_1(bp);
818 ++bp;
819 --len;
820 ND_PRINT("%s", tok2str(oo2str, NULL, tag));
821 break;
822
823 case TAG_CLIENT_FQDN:
824 /* this option should be at least 3 bytes long */
825 if (len < 3) {
826 ND_PRINT("[length < 3 bytes]");
827 nd_print_invalid(ndo);
828 bp += len;
829 len = 0;
830 break;
831 }
832 if (GET_U_1(bp) & 0xf0) {
833 ND_PRINT("[MBZ nibble 0x%x != 0] ",
834 (GET_U_1(bp) & 0xf0) >> 4);
835 nd_print_invalid(ndo);
836 }
837 if (GET_U_1(bp) & 0x0f)
838 ND_PRINT("[%s] ",
839 client_fqdn_flags(GET_U_1(bp)));
840 bp++;
841 if (GET_U_1(bp) || GET_U_1(bp + 1))
842 ND_PRINT("%u/%u ", GET_U_1(bp),
843 GET_U_1(bp + 1));
844 bp += 2;
845 ND_PRINT("\"");
846 if (nd_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
847 ND_PRINT("\"");
848 goto trunc;
849 }
850 ND_PRINT("\"");
851 bp += len - 3;
852 len = 0;
853 break;
854
855 case TAG_CLIENT_ID:
856 {
857 int type;
858
859 /* this option should be at least 1 byte long */
860 if (len < 1) {
861 ND_PRINT("[length < 1 byte]");
862 nd_print_invalid(ndo);
863 break;
864 }
865 type = GET_U_1(bp);
866 bp++;
867 len--;
868 if (type == 0) {
869 ND_PRINT("\"");
870 if (nd_printn(ndo, bp, len, ndo->ndo_snapend)) {
871 ND_PRINT("\"");
872 goto trunc;
873 }
874 ND_PRINT("\"");
875 bp += len;
876 len = 0;
877 break;
878 } else {
879 ND_PRINT("%s ", tok2str(arp2str, "hardware-type %u,", type));
880 while (len > 0) {
881 if (!first)
882 ND_PRINT(":");
883 ND_PRINT("%02x", GET_U_1(bp));
884 ++bp;
885 --len;
886 first = 0;
887 }
888 }
889 break;
890 }
891
892 case TAG_AGENT_CIRCUIT:
893 while (len >= 2) {
894 subopt = GET_U_1(bp);
895 suboptlen = GET_U_1(bp + 1);
896 bp += 2;
897 len -= 2;
898 if (suboptlen > len) {
899 ND_PRINT("\n\t %s SubOption %u, length %u: length goes past end of option",
900 tok2str(agent_suboption_values, "Unknown", subopt),
901 subopt,
902 suboptlen);
903 bp += len;
904 len = 0;
905 break;
906 }
907 ND_PRINT("\n\t %s SubOption %u, length %u: ",
908 tok2str(agent_suboption_values, "Unknown", subopt),
909 subopt,
910 suboptlen);
911 switch (subopt) {
912
913 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
914 case AGENT_SUBOPTION_REMOTE_ID:
915 case AGENT_SUBOPTION_SUBSCRIBER_ID:
916 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
917 goto trunc;
918 break;
919
920 default:
921 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
922 }
923
924 len -= suboptlen;
925 bp += suboptlen;
926 }
927 break;
928
929 case TAG_CLASSLESS_STATIC_RT:
930 case TAG_CLASSLESS_STA_RT_MS:
931 {
932 u_int mask_width, significant_octets, i;
933
934 /* this option should be at least 5 bytes long */
935 if (len < 5) {
936 ND_PRINT("[length < 5 bytes]");
937 nd_print_invalid(ndo);
938 bp += len;
939 len = 0;
940 break;
941 }
942 while (len > 0) {
943 if (!first)
944 ND_PRINT(",");
945 mask_width = GET_U_1(bp);
946 bp++;
947 len--;
948 /* mask_width <= 32 */
949 if (mask_width > 32) {
950 ND_PRINT("[Mask width (%u) > 32]", mask_width);
951 nd_print_invalid(ndo);
952 bp += len;
953 len = 0;
954 break;
955 }
956 significant_octets = (mask_width + 7) / 8;
957 /* significant octets + router(4) */
958 if (len < significant_octets + 4) {
959 ND_PRINT("[Remaining length (%u) < %u bytes]", len, significant_octets + 4);
960 nd_print_invalid(ndo);
961 bp += len;
962 len = 0;
963 break;
964 }
965 ND_PRINT("(");
966 if (mask_width == 0)
967 ND_PRINT("default");
968 else {
969 for (i = 0; i < significant_octets ; i++) {
970 if (i > 0)
971 ND_PRINT(".");
972 ND_PRINT("%u",
973 GET_U_1(bp));
974 bp++;
975 }
976 for (i = significant_octets ; i < 4 ; i++)
977 ND_PRINT(".0");
978 ND_PRINT("/%u", mask_width);
979 }
980 ND_PRINT(":%s)", GET_IPADDR_STRING(bp));
981 bp += 4;
982 len -= (significant_octets + 4);
983 first = 0;
984 }
985 break;
986 }
987
988 case TAG_USER_CLASS:
989 {
990 u_int suboptnumber = 1;
991
992 first = 1;
993 if (len < 2) {
994 ND_PRINT("[length < 2 bytes]");
995 nd_print_invalid(ndo);
996 bp += len;
997 len = 0;
998 break;
999 }
1000 while (len > 0) {
1001 suboptlen = GET_U_1(bp);
1002 bp++;
1003 len--;
1004 ND_PRINT("\n\t ");
1005 ND_PRINT("instance#%u: ", suboptnumber);
1006 if (suboptlen == 0) {
1007 ND_PRINT("[suboption length == 0]");
1008 nd_print_invalid(ndo);
1009 bp += len;
1010 len = 0;
1011 break;
1012 }
1013 if (len < suboptlen) {
1014 ND_PRINT("[length %u < suboption length %u",
1015 len, suboptlen);
1016 nd_print_invalid(ndo);
1017 bp += len;
1018 len = 0;
1019 break;
1020 }
1021 ND_PRINT("\"");
1022 if (nd_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
1023 ND_PRINT("\"");
1024 goto trunc;
1025 }
1026 ND_PRINT("\"");
1027 ND_PRINT(", length %u", suboptlen);
1028 suboptnumber++;
1029 len -= suboptlen;
1030 bp += suboptlen;
1031 }
1032 break;
1033 }
1034
1035
1036 case TAG_SZTP_REDIRECT:
1037 /* as per https://datatracker.ietf.org/doc/html/rfc8572#section-8.3
1038 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1039 | uri-length | URI |
1040 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...-+-+-+-+-+-+-+
1041
1042 * uri-length: 2 octets long; specifies the length of the URI data.
1043 * URI: URI of the SZTP bootstrap server.
1044 */
1045 while (len >= 2) {
1046 uint16_t suboptlen2;
1047
1048 suboptlen2 = GET_BE_U_2(bp);
1049 bp += 2;
1050 len -= 2;
1051 ND_PRINT("\n\t ");
1052 ND_PRINT("length %u: ", suboptlen2);
1053 if (len < suboptlen2) {
1054 ND_PRINT("length goes past end of option");
1055 bp += len;
1056 len = 0;
1057 break;
1058 }
1059 ND_PRINT("\"");
1060 nd_printjn(ndo, bp, suboptlen2);
1061 ND_PRINT("\"");
1062 len -= suboptlen2;
1063 bp += suboptlen2;
1064 }
1065 if (len != 0) {
1066 ND_PRINT("[length < 2 bytes]");
1067 nd_print_invalid(ndo);
1068 }
1069 break;
1070
1071 default:
1072 ND_PRINT("[unknown special tag %u, size %u]",
1073 tag, len);
1074 bp += len;
1075 len = 0;
1076 break;
1077 }
1078 break;
1079 }
1080 /* Data left over? */
1081 if (len) {
1082 ND_PRINT("\n\t trailing data length %u", len);
1083 bp += len;
1084 }
1085 }
1086 return;
1087 trunc:
1088 nd_print_trunc(ndo);
1089 }
1090
1091 #define PRINTCMUADDR(m, s) { ND_TCHECK_4(cmu->m); \
1092 if (GET_IPV4_TO_NETWORK_ORDER(cmu->m) != 0) \
1093 ND_PRINT(" %s:%s", s, GET_IPADDR_STRING(cmu->m)); }
1094
1095 static void
1096 cmu_print(netdissect_options *ndo,
1097 const u_char *bp)
1098 {
1099 const struct cmu_vend *cmu;
1100 uint8_t v_flags;
1101
1102 ND_PRINT(" vend-cmu");
1103 cmu = (const struct cmu_vend *)bp;
1104
1105 /* Only print if there are unknown bits */
1106 ND_TCHECK_4(cmu->v_flags);
1107 v_flags = GET_U_1(cmu->v_flags);
1108 if ((v_flags & ~(VF_SMASK)) != 0)
1109 ND_PRINT(" F:0x%x", v_flags);
1110 PRINTCMUADDR(v_dgate, "DG");
1111 PRINTCMUADDR(v_smask, v_flags & VF_SMASK ? "SM" : "SM*");
1112 PRINTCMUADDR(v_dns1, "NS1");
1113 PRINTCMUADDR(v_dns2, "NS2");
1114 PRINTCMUADDR(v_ins1, "IEN1");
1115 PRINTCMUADDR(v_ins2, "IEN2");
1116 PRINTCMUADDR(v_ts1, "TS1");
1117 PRINTCMUADDR(v_ts2, "TS2");
1118 return;
1119
1120 trunc:
1121 nd_print_trunc(ndo);
1122 }
1123
1124 #undef PRINTCMUADDR
1125
1126 static char *
1127 client_fqdn_flags(u_int flags)
1128 {
1129 static char buf[8+1];
1130 int i = 0;
1131
1132 if (flags & CLIENT_FQDN_FLAGS_S)
1133 buf[i++] = 'S';
1134 if (flags & CLIENT_FQDN_FLAGS_O)
1135 buf[i++] = 'O';
1136 if (flags & CLIENT_FQDN_FLAGS_E)
1137 buf[i++] = 'E';
1138 if (flags & CLIENT_FQDN_FLAGS_N)
1139 buf[i++] = 'N';
1140 buf[i] = '\0';
1141
1142 return buf;
1143 }
1144