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