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