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