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