blob: fe798a0483da50311042ed48a93856a7a7f2272d [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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.
The Android Open Source Project2949f582009-03-03 19:30:46 -080020 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080021
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: BOOTP and IPv4 DHCP printer */
23
The Android Open Source Project2949f582009-03-03 19:30:46 -080024#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
Elliott Hughese2e3bd12017-05-15 10:59:29 -070028#include <netdissect-stdinc.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080029
The Android Open Source Project2949f582009-03-03 19:30:46 -080030#include <string.h>
31
Elliott Hughese2e3bd12017-05-15 10:59:29 -070032#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080033#include "addrtoname.h"
34#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080035
Elliott Hughes892a68b2015-10-19 14:43:53 -070036static const char tstr[] = " [|bootp]";
37
38/*
39 * Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
40 *
41 * This file specifies the "implementation-independent" BOOTP protocol
42 * information which is common to both client and server.
43 *
44 * Copyright 1988 by Carnegie Mellon.
45 *
46 * Permission to use, copy, modify, and distribute this program for any
47 * purpose and without fee is hereby granted, provided that this copyright
48 * and permission notice appear on all copies and supporting documentation,
49 * the name of Carnegie Mellon not be used in advertising or publicity
50 * pertaining to distribution of the program without specific prior
51 * permission, and notice be given in supporting documentation that copying
52 * and distribution is by permission of Carnegie Mellon and Stanford
53 * University. Carnegie Mellon makes no representations about the
54 * suitability of this software for any purpose. It is provided "as is"
55 * without express or implied warranty.
56 */
57
58struct bootp {
59 uint8_t bp_op; /* packet opcode type */
60 uint8_t bp_htype; /* hardware addr type */
61 uint8_t bp_hlen; /* hardware addr length */
62 uint8_t bp_hops; /* gateway hops */
63 uint32_t bp_xid; /* transaction ID */
64 uint16_t bp_secs; /* seconds since boot began */
65 uint16_t bp_flags; /* flags - see bootp_flag_values[]
66 in print-bootp.c */
67 struct in_addr bp_ciaddr; /* client IP address */
68 struct in_addr bp_yiaddr; /* 'your' IP address */
69 struct in_addr bp_siaddr; /* server IP address */
70 struct in_addr bp_giaddr; /* gateway IP address */
71 uint8_t bp_chaddr[16]; /* client hardware address */
72 uint8_t bp_sname[64]; /* server host name */
73 uint8_t bp_file[128]; /* boot file name */
74 uint8_t bp_vend[64]; /* vendor-specific area */
75} UNALIGNED;
76
77#define BOOTPREPLY 2
78#define BOOTPREQUEST 1
79
80/*
81 * Vendor magic cookie (v_magic) for CMU
82 */
83#define VM_CMU "CMU"
84
85/*
86 * Vendor magic cookie (v_magic) for RFC1048
87 */
88#define VM_RFC1048 { 99, 130, 83, 99 }
89
90/*
91 * RFC1048 tag values used to specify what information is being supplied in
92 * the vendor field of the packet.
93 */
94
95#define TAG_PAD ((uint8_t) 0)
96#define TAG_SUBNET_MASK ((uint8_t) 1)
97#define TAG_TIME_OFFSET ((uint8_t) 2)
98#define TAG_GATEWAY ((uint8_t) 3)
99#define TAG_TIME_SERVER ((uint8_t) 4)
100#define TAG_NAME_SERVER ((uint8_t) 5)
101#define TAG_DOMAIN_SERVER ((uint8_t) 6)
102#define TAG_LOG_SERVER ((uint8_t) 7)
103#define TAG_COOKIE_SERVER ((uint8_t) 8)
104#define TAG_LPR_SERVER ((uint8_t) 9)
105#define TAG_IMPRESS_SERVER ((uint8_t) 10)
106#define TAG_RLP_SERVER ((uint8_t) 11)
107#define TAG_HOSTNAME ((uint8_t) 12)
108#define TAG_BOOTSIZE ((uint8_t) 13)
109#define TAG_END ((uint8_t) 255)
110/* RFC1497 tags */
111#define TAG_DUMPPATH ((uint8_t) 14)
112#define TAG_DOMAINNAME ((uint8_t) 15)
113#define TAG_SWAP_SERVER ((uint8_t) 16)
114#define TAG_ROOTPATH ((uint8_t) 17)
115#define TAG_EXTPATH ((uint8_t) 18)
116/* RFC2132 */
117#define TAG_IP_FORWARD ((uint8_t) 19)
118#define TAG_NL_SRCRT ((uint8_t) 20)
119#define TAG_PFILTERS ((uint8_t) 21)
120#define TAG_REASS_SIZE ((uint8_t) 22)
121#define TAG_DEF_TTL ((uint8_t) 23)
122#define TAG_MTU_TIMEOUT ((uint8_t) 24)
123#define TAG_MTU_TABLE ((uint8_t) 25)
124#define TAG_INT_MTU ((uint8_t) 26)
125#define TAG_LOCAL_SUBNETS ((uint8_t) 27)
126#define TAG_BROAD_ADDR ((uint8_t) 28)
127#define TAG_DO_MASK_DISC ((uint8_t) 29)
128#define TAG_SUPPLY_MASK ((uint8_t) 30)
129#define TAG_DO_RDISC ((uint8_t) 31)
130#define TAG_RTR_SOL_ADDR ((uint8_t) 32)
131#define TAG_STATIC_ROUTE ((uint8_t) 33)
132#define TAG_USE_TRAILERS ((uint8_t) 34)
133#define TAG_ARP_TIMEOUT ((uint8_t) 35)
134#define TAG_ETH_ENCAP ((uint8_t) 36)
135#define TAG_TCP_TTL ((uint8_t) 37)
136#define TAG_TCP_KEEPALIVE ((uint8_t) 38)
137#define TAG_KEEPALIVE_GO ((uint8_t) 39)
138#define TAG_NIS_DOMAIN ((uint8_t) 40)
139#define TAG_NIS_SERVERS ((uint8_t) 41)
140#define TAG_NTP_SERVERS ((uint8_t) 42)
141#define TAG_VENDOR_OPTS ((uint8_t) 43)
142#define TAG_NETBIOS_NS ((uint8_t) 44)
143#define TAG_NETBIOS_DDS ((uint8_t) 45)
144#define TAG_NETBIOS_NODE ((uint8_t) 46)
145#define TAG_NETBIOS_SCOPE ((uint8_t) 47)
146#define TAG_XWIN_FS ((uint8_t) 48)
147#define TAG_XWIN_DM ((uint8_t) 49)
148#define TAG_NIS_P_DOMAIN ((uint8_t) 64)
149#define TAG_NIS_P_SERVERS ((uint8_t) 65)
150#define TAG_MOBILE_HOME ((uint8_t) 68)
151#define TAG_SMPT_SERVER ((uint8_t) 69)
152#define TAG_POP3_SERVER ((uint8_t) 70)
153#define TAG_NNTP_SERVER ((uint8_t) 71)
154#define TAG_WWW_SERVER ((uint8_t) 72)
155#define TAG_FINGER_SERVER ((uint8_t) 73)
156#define TAG_IRC_SERVER ((uint8_t) 74)
157#define TAG_STREETTALK_SRVR ((uint8_t) 75)
158#define TAG_STREETTALK_STDA ((uint8_t) 76)
159/* DHCP options */
160#define TAG_REQUESTED_IP ((uint8_t) 50)
161#define TAG_IP_LEASE ((uint8_t) 51)
162#define TAG_OPT_OVERLOAD ((uint8_t) 52)
163#define TAG_TFTP_SERVER ((uint8_t) 66)
164#define TAG_BOOTFILENAME ((uint8_t) 67)
165#define TAG_DHCP_MESSAGE ((uint8_t) 53)
166#define TAG_SERVER_ID ((uint8_t) 54)
167#define TAG_PARM_REQUEST ((uint8_t) 55)
168#define TAG_MESSAGE ((uint8_t) 56)
169#define TAG_MAX_MSG_SIZE ((uint8_t) 57)
170#define TAG_RENEWAL_TIME ((uint8_t) 58)
171#define TAG_REBIND_TIME ((uint8_t) 59)
172#define TAG_VENDOR_CLASS ((uint8_t) 60)
173#define TAG_CLIENT_ID ((uint8_t) 61)
174/* RFC 2241 */
175#define TAG_NDS_SERVERS ((uint8_t) 85)
176#define TAG_NDS_TREE_NAME ((uint8_t) 86)
177#define TAG_NDS_CONTEXT ((uint8_t) 87)
178/* RFC 2242 */
179#define TAG_NDS_IPDOMAIN ((uint8_t) 62)
180#define TAG_NDS_IPINFO ((uint8_t) 63)
181/* RFC 2485 */
182#define TAG_OPEN_GROUP_UAP ((uint8_t) 98)
183/* RFC 2563 */
184#define TAG_DISABLE_AUTOCONF ((uint8_t) 116)
185/* RFC 2610 */
186#define TAG_SLP_DA ((uint8_t) 78)
187#define TAG_SLP_SCOPE ((uint8_t) 79)
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/* RFC 5859 - TFTP Server Address Option for DHCPv4 */
198#define TAG_TFTP_SERVER_ADDRESS ((uint8_t) 150)
199/* ftp://ftp.isi.edu/.../assignments/bootp-dhcp-extensions */
200#define TAG_SLP_NAMING_AUTH ((uint8_t) 80)
201#define TAG_CLIENT_FQDN ((uint8_t) 81)
202#define TAG_AGENT_CIRCUIT ((uint8_t) 82)
203#define TAG_AGENT_REMOTE ((uint8_t) 83)
204#define TAG_AGENT_MASK ((uint8_t) 84)
205#define TAG_TZ_STRING ((uint8_t) 88)
206#define TAG_FQDN_OPTION ((uint8_t) 89)
207#define TAG_AUTH ((uint8_t) 90)
208#define TAG_VINES_SERVERS ((uint8_t) 91)
209#define TAG_SERVER_RANK ((uint8_t) 92)
210#define TAG_CLIENT_ARCH ((uint8_t) 93)
211#define TAG_CLIENT_NDI ((uint8_t) 94)
212#define TAG_CLIENT_GUID ((uint8_t) 97)
213#define TAG_LDAP_URL ((uint8_t) 95)
214#define TAG_6OVER4 ((uint8_t) 96)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700215/* RFC 4833, TZ codes */
216#define TAG_TZ_PCODE ((uint8_t) 100)
217#define TAG_TZ_TCODE ((uint8_t) 101)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700218#define TAG_IPX_COMPAT ((uint8_t) 110)
219#define TAG_NETINFO_PARENT ((uint8_t) 112)
220#define TAG_NETINFO_PARENT_TAG ((uint8_t) 113)
221#define TAG_URL ((uint8_t) 114)
222#define TAG_FAILOVER ((uint8_t) 115)
223#define TAG_EXTENDED_REQUEST ((uint8_t) 126)
224#define TAG_EXTENDED_OPTION ((uint8_t) 127)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700225#define TAG_MUDURL ((uint8_t) 161)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700226
227/* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
228#define DHCPDISCOVER 1
229#define DHCPOFFER 2
230#define DHCPREQUEST 3
231#define DHCPDECLINE 4
232#define DHCPACK 5
233#define DHCPNAK 6
234#define DHCPRELEASE 7
235#define DHCPINFORM 8
236
237/*
238 * "vendor" data permitted for CMU bootp clients.
239 */
240
241struct cmu_vend {
242 uint8_t v_magic[4]; /* magic number */
243 uint32_t v_flags; /* flags/opcodes, etc. */
244 struct in_addr v_smask; /* Subnet mask */
245 struct in_addr v_dgate; /* Default gateway */
246 struct in_addr v_dns1, v_dns2; /* Domain name servers */
247 struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
248 struct in_addr v_ts1, v_ts2; /* Time servers */
249 uint8_t v_unused[24]; /* currently unused */
250} UNALIGNED;
251
252
253/* v_flags values */
254#define VF_SMASK 1 /* Subnet mask field contains valid data */
255
256/* RFC 4702 DHCP Client FQDN Option */
257
258#define CLIENT_FQDN_FLAGS_S 0x01
259#define CLIENT_FQDN_FLAGS_O 0x02
260#define CLIENT_FQDN_FLAGS_E 0x04
261#define CLIENT_FQDN_FLAGS_N 0x08
262/* end of original bootp.h */
263
264static void rfc1048_print(netdissect_options *, const u_char *);
265static void cmu_print(netdissect_options *, const u_char *);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800266static char *client_fqdn_flags(u_int flags);
267
The Android Open Source Project2949f582009-03-03 19:30:46 -0800268static const struct tok bootp_flag_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700269 { 0x8000, "Broadcast" },
270 { 0, NULL}
The Android Open Source Project2949f582009-03-03 19:30:46 -0800271};
272
273static const struct tok bootp_op_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700274 { BOOTPREQUEST, "Request" },
275 { BOOTPREPLY, "Reply" },
276 { 0, NULL}
The Android Open Source Project2949f582009-03-03 19:30:46 -0800277};
278
279/*
280 * Print bootp requests
281 */
282void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700283bootp_print(netdissect_options *ndo,
284 register const u_char *cp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800285{
286 register const struct bootp *bp;
287 static const u_char vm_cmu[4] = VM_CMU;
288 static const u_char vm_rfc1048[4] = VM_RFC1048;
289
290 bp = (const struct bootp *)cp;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700291 ND_TCHECK(bp->bp_op);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800292
Elliott Hughes892a68b2015-10-19 14:43:53 -0700293 ND_PRINT((ndo, "BOOTP/DHCP, %s",
294 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800295
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700296 ND_TCHECK(bp->bp_hlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800297 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700298 ND_TCHECK2(bp->bp_chaddr[0], 6);
299 ND_PRINT((ndo, " from %s", etheraddr_string(ndo, bp->bp_chaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800300 }
301
Elliott Hughes892a68b2015-10-19 14:43:53 -0700302 ND_PRINT((ndo, ", length %u", length));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303
Elliott Hughes892a68b2015-10-19 14:43:53 -0700304 if (!ndo->ndo_vflag)
305 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800306
Elliott Hughes892a68b2015-10-19 14:43:53 -0700307 ND_TCHECK(bp->bp_secs);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800308
309 /* The usual hardware address type is 1 (10Mb Ethernet) */
310 if (bp->bp_htype != 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700311 ND_PRINT((ndo, ", htype %d", bp->bp_htype));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800312
313 /* The usual length for 10Mb Ethernet address is 6 bytes */
314 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315 ND_PRINT((ndo, ", hlen %d", bp->bp_hlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800316
317 /* Only print interesting fields */
318 if (bp->bp_hops)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700319 ND_PRINT((ndo, ", hops %d", bp->bp_hops));
JP Abgrall53f17a92014-02-12 14:02:41 -0800320 if (EXTRACT_32BITS(&bp->bp_xid))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700321 ND_PRINT((ndo, ", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800322 if (EXTRACT_16BITS(&bp->bp_secs))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700323 ND_PRINT((ndo, ", secs %d", EXTRACT_16BITS(&bp->bp_secs)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800324
Elliott Hughes892a68b2015-10-19 14:43:53 -0700325 ND_PRINT((ndo, ", Flags [%s]",
326 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))));
327 if (ndo->ndo_vflag > 1)
328 ND_PRINT((ndo, " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800329
330 /* Client's ip address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700331 ND_TCHECK(bp->bp_ciaddr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800332 if (EXTRACT_32BITS(&bp->bp_ciaddr.s_addr))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700333 ND_PRINT((ndo, "\n\t Client-IP %s", ipaddr_string(ndo, &bp->bp_ciaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800334
335 /* 'your' ip address (bootp client) */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700336 ND_TCHECK(bp->bp_yiaddr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800337 if (EXTRACT_32BITS(&bp->bp_yiaddr.s_addr))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700338 ND_PRINT((ndo, "\n\t Your-IP %s", ipaddr_string(ndo, &bp->bp_yiaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800339
340 /* Server's ip address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700341 ND_TCHECK(bp->bp_siaddr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800342 if (EXTRACT_32BITS(&bp->bp_siaddr.s_addr))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700343 ND_PRINT((ndo, "\n\t Server-IP %s", ipaddr_string(ndo, &bp->bp_siaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800344
345 /* Gateway's ip address */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700346 ND_TCHECK(bp->bp_giaddr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800347 if (EXTRACT_32BITS(&bp->bp_giaddr.s_addr))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700348 ND_PRINT((ndo, "\n\t Gateway-IP %s", ipaddr_string(ndo, &bp->bp_giaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800349
350 /* Client's Ethernet address */
351 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700352 ND_TCHECK2(bp->bp_chaddr[0], 6);
353 ND_PRINT((ndo, "\n\t Client-Ethernet-Address %s", etheraddr_string(ndo, bp->bp_chaddr)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800354 }
355
Elliott Hughes892a68b2015-10-19 14:43:53 -0700356 ND_TCHECK2(bp->bp_sname[0], 1); /* check first char only */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800357 if (*bp->bp_sname) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700358 ND_PRINT((ndo, "\n\t sname \""));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700359 if (fn_printztn(ndo, bp->bp_sname, (u_int)sizeof bp->bp_sname,
360 ndo->ndo_snapend)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700361 ND_PRINT((ndo, "\""));
362 ND_PRINT((ndo, "%s", tstr + 1));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800363 return;
364 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700365 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800366 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700367 ND_TCHECK2(bp->bp_file[0], 1); /* check first char only */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800368 if (*bp->bp_file) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700369 ND_PRINT((ndo, "\n\t file \""));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700370 if (fn_printztn(ndo, bp->bp_file, (u_int)sizeof bp->bp_file,
371 ndo->ndo_snapend)) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700372 ND_PRINT((ndo, "\""));
373 ND_PRINT((ndo, "%s", tstr + 1));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374 return;
375 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700376 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800377 }
378
379 /* Decode the vendor buffer */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700380 ND_TCHECK(bp->bp_vend[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800381 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700382 sizeof(uint32_t)) == 0)
383 rfc1048_print(ndo, bp->bp_vend);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800384 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700385 sizeof(uint32_t)) == 0)
386 cmu_print(ndo, bp->bp_vend);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800387 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700388 uint32_t ul;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800389
390 ul = EXTRACT_32BITS(&bp->bp_vend);
391 if (ul != 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700392 ND_PRINT((ndo, "\n\t Vendor-#0x%x", ul));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800393 }
394
395 return;
396trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700397 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800398}
399
400/*
401 * The first character specifies the format to print:
402 * i - ip address (32 bits)
403 * p - ip address pairs (32 bits + 32 bits)
404 * l - long (32 bits)
405 * L - unsigned long (32 bits)
406 * s - short (16 bits)
407 * b - period-seperated decimal bytes (variable length)
408 * x - colon-seperated hex bytes (variable length)
409 * a - ascii string (variable length)
410 * B - on/off (8 bits)
411 * $ - special (explicit code to handle)
412 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800413static const struct tok tag2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800414/* RFC1048 tags */
415 { TAG_PAD, " PAD" },
416 { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
417 { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
418 { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
419 { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
420 { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
421 { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
422 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
423 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
424 { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
425 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
426 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
427 { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
428 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
429 { TAG_END, " END" },
430/* RFC1497 tags */
431 { TAG_DUMPPATH, "aDP" },
432 { TAG_DOMAINNAME, "aDomain-Name" },
433 { TAG_SWAP_SERVER, "iSS" },
434 { TAG_ROOTPATH, "aRP" },
435 { TAG_EXTPATH, "aEP" },
436/* RFC2132 tags */
437 { TAG_IP_FORWARD, "BIPF" },
438 { TAG_NL_SRCRT, "BSRT" },
439 { TAG_PFILTERS, "pPF" },
440 { TAG_REASS_SIZE, "sRSZ" },
441 { TAG_DEF_TTL, "bTTL" },
442 { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
443 { TAG_MTU_TABLE, "sMTU-Table" },
444 { TAG_INT_MTU, "sMTU" },
445 { TAG_LOCAL_SUBNETS, "BLSN" },
446 { TAG_BROAD_ADDR, "iBR" },
447 { TAG_DO_MASK_DISC, "BMD" },
448 { TAG_SUPPLY_MASK, "BMS" },
449 { TAG_DO_RDISC, "BRouter-Discovery" },
450 { TAG_RTR_SOL_ADDR, "iRSA" },
451 { TAG_STATIC_ROUTE, "pStatic-Route" },
452 { TAG_USE_TRAILERS, "BUT" },
453 { TAG_ARP_TIMEOUT, "lAT" },
454 { TAG_ETH_ENCAP, "BIE" },
455 { TAG_TCP_TTL, "bTT" },
456 { TAG_TCP_KEEPALIVE, "lKI" },
457 { TAG_KEEPALIVE_GO, "BKG" },
458 { TAG_NIS_DOMAIN, "aYD" },
459 { TAG_NIS_SERVERS, "iYS" },
460 { TAG_NTP_SERVERS, "iNTP" },
461 { TAG_VENDOR_OPTS, "bVendor-Option" },
462 { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
463 { TAG_NETBIOS_DDS, "iWDD" },
464 { TAG_NETBIOS_NODE, "$Netbios-Node" },
465 { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
466 { TAG_XWIN_FS, "iXFS" },
467 { TAG_XWIN_DM, "iXDM" },
468 { TAG_NIS_P_DOMAIN, "sN+D" },
469 { TAG_NIS_P_SERVERS, "iN+S" },
470 { TAG_MOBILE_HOME, "iMH" },
471 { TAG_SMPT_SERVER, "iSMTP" },
472 { TAG_POP3_SERVER, "iPOP3" },
473 { TAG_NNTP_SERVER, "iNNTP" },
474 { TAG_WWW_SERVER, "iWWW" },
475 { TAG_FINGER_SERVER, "iFG" },
476 { TAG_IRC_SERVER, "iIRC" },
477 { TAG_STREETTALK_SRVR, "iSTS" },
478 { TAG_STREETTALK_STDA, "iSTDA" },
479 { TAG_REQUESTED_IP, "iRequested-IP" },
480 { TAG_IP_LEASE, "lLease-Time" },
481 { TAG_OPT_OVERLOAD, "$OO" },
482 { TAG_TFTP_SERVER, "aTFTP" },
483 { TAG_BOOTFILENAME, "aBF" },
484 { TAG_DHCP_MESSAGE, " DHCP-Message" },
485 { TAG_SERVER_ID, "iServer-ID" },
486 { TAG_PARM_REQUEST, "bParameter-Request" },
487 { TAG_MESSAGE, "aMSG" },
488 { TAG_MAX_MSG_SIZE, "sMSZ" },
489 { TAG_RENEWAL_TIME, "lRN" },
490 { TAG_REBIND_TIME, "lRB" },
491 { TAG_VENDOR_CLASS, "aVendor-Class" },
492 { TAG_CLIENT_ID, "$Client-ID" },
493/* RFC 2485 */
494 { TAG_OPEN_GROUP_UAP, "aUAP" },
495/* RFC 2563 */
496 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
497/* RFC 2610 */
498 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
499 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
500/* RFC 2937 */
501 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700502/* RFC 3004 - The User Class Option for DHCP */
503 { TAG_USER_CLASS, "$User-Class" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800504/* RFC 3011 */
505 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
506/* RFC 3442 */
507 { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
508 { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700509/* RFC 5859 - TFTP Server Address Option for DHCPv4 */
510 { TAG_TFTP_SERVER_ADDRESS, "iTFTP-Server-Address" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800511/* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800512 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
513 { TAG_CLIENT_FQDN, "$FQDN" },
514 { TAG_AGENT_CIRCUIT, "$Agent-Information" },
515 { TAG_AGENT_REMOTE, "bARMT" },
516 { TAG_AGENT_MASK, "bAMSK" },
517 { TAG_TZ_STRING, "aTZSTR" },
518 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
519 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
520 { TAG_VINES_SERVERS, "iVINES" },
521 { TAG_SERVER_RANK, "sRANK" },
522 { TAG_CLIENT_ARCH, "sARCH" },
523 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
524 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
525 { TAG_LDAP_URL, "aLDAP" },
526 { TAG_6OVER4, "i6o4" },
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700527 { TAG_TZ_PCODE, "aPOSIX-TZ" },
528 { TAG_TZ_TCODE, "aTZ-Name" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800529 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
530 { TAG_NETINFO_PARENT, "iNI" },
531 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
532 { TAG_URL, "aURL" },
533 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700534 { TAG_MUDURL, "aMUD-URL" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700535 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800536};
537/* 2-byte extended tags */
JP Abgrall53f17a92014-02-12 14:02:41 -0800538static const struct tok xtag2str[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700539 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800540};
541
542/* DHCP "options overload" types */
JP Abgrall53f17a92014-02-12 14:02:41 -0800543static const struct tok oo2str[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700544 { 1, "file" },
545 { 2, "sname" },
546 { 3, "file+sname" },
547 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548};
549
550/* NETBIOS over TCP/IP node type options */
JP Abgrall53f17a92014-02-12 14:02:41 -0800551static const struct tok nbo2str[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700552 { 0x1, "b-node" },
553 { 0x2, "p-node" },
554 { 0x4, "m-node" },
555 { 0x8, "h-node" },
556 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800557};
558
559/* ARP Hardware types, for Client-ID option */
JP Abgrall53f17a92014-02-12 14:02:41 -0800560static const struct tok arp2str[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700561 { 0x1, "ether" },
562 { 0x6, "ieee802" },
563 { 0x7, "arcnet" },
564 { 0xf, "frelay" },
565 { 0x17, "strip" },
566 { 0x18, "ieee1394" },
567 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800568};
569
JP Abgrall53f17a92014-02-12 14:02:41 -0800570static const struct tok dhcp_msg_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700571 { DHCPDISCOVER, "Discover" },
572 { DHCPOFFER, "Offer" },
573 { DHCPREQUEST, "Request" },
574 { DHCPDECLINE, "Decline" },
575 { DHCPACK, "ACK" },
576 { DHCPNAK, "NACK" },
577 { DHCPRELEASE, "Release" },
578 { DHCPINFORM, "Inform" },
579 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800580};
581
Elliott Hughes892a68b2015-10-19 14:43:53 -0700582#define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
583#define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
584#define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
JP Abgrall53f17a92014-02-12 14:02:41 -0800585static const struct tok agent_suboption_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700586 { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
587 { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" },
588 { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
589 { 0, NULL }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800590};
591
592
593static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700594rfc1048_print(netdissect_options *ndo,
595 register const u_char *bp)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800596{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700597 register uint16_t tag;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800598 register u_int len;
599 register const char *cp;
600 register char c;
601 int first, idx;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700602 uint32_t ul;
603 uint16_t us;
604 uint8_t uc, subopt, suboptlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800605
Elliott Hughes892a68b2015-10-19 14:43:53 -0700606 ND_PRINT((ndo, "\n\t Vendor-rfc1048 Extensions"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800607
608 /* Step over magic cookie */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700609 ND_PRINT((ndo, "\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800610 bp += sizeof(int32_t);
611
612 /* Loop while we there is a tag left in the buffer */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700613 while (ND_TTEST2(*bp, 1)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800614 tag = *bp++;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700615 if (tag == TAG_PAD && ndo->ndo_vflag < 3)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800616 continue;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700617 if (tag == TAG_END && ndo->ndo_vflag < 3)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800618 return;
619 if (tag == TAG_EXTENDED_OPTION) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700620 ND_TCHECK2(*(bp + 1), 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800621 tag = EXTRACT_16BITS(bp + 1);
622 /* XXX we don't know yet if the IANA will
623 * preclude overlap of 1-byte and 2-byte spaces.
624 * If not, we need to offset tag after this step.
625 */
626 cp = tok2str(xtag2str, "?xT%u", tag);
627 } else
628 cp = tok2str(tag2str, "?T%u", tag);
629 c = *cp++;
630
631 if (tag == TAG_PAD || tag == TAG_END)
632 len = 0;
633 else {
634 /* Get the length; check for truncation */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700635 ND_TCHECK2(*bp, 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800636 len = *bp++;
637 }
638
Elliott Hughes892a68b2015-10-19 14:43:53 -0700639 ND_PRINT((ndo, "\n\t %s Option %u, length %u%s", cp, tag, len,
640 len > 0 ? ": " : ""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800641
Elliott Hughes892a68b2015-10-19 14:43:53 -0700642 if (tag == TAG_PAD && ndo->ndo_vflag > 2) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800643 u_int ntag = 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700644 while (ND_TTEST2(*bp, 1) && *bp == TAG_PAD) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800645 bp++;
646 ntag++;
647 }
648 if (ntag > 1)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700649 ND_PRINT((ndo, ", occurs %u", ntag));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800650 }
651
Elliott Hughes892a68b2015-10-19 14:43:53 -0700652 if (!ND_TTEST2(*bp, len)) {
653 ND_PRINT((ndo, "[|rfc1048 %u]", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800654 return;
655 }
656
657 if (tag == TAG_DHCP_MESSAGE && len == 1) {
658 uc = *bp++;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700659 ND_PRINT((ndo, "%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc)));
660 continue;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800661 }
662
663 if (tag == TAG_PARM_REQUEST) {
664 idx = 0;
665 while (len-- > 0) {
666 uc = *bp++;
667 cp = tok2str(tag2str, "?Option %u", uc);
668 if (idx % 4 == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700669 ND_PRINT((ndo, "\n\t "));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800670 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700671 ND_PRINT((ndo, ", "));
672 ND_PRINT((ndo, "%s", cp + 1));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800673 idx++;
674 }
675 continue;
676 }
677
678 if (tag == TAG_EXTENDED_REQUEST) {
679 first = 1;
680 while (len > 1) {
681 len -= 2;
682 us = EXTRACT_16BITS(bp);
683 bp += 2;
684 cp = tok2str(xtag2str, "?xT%u", us);
685 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700686 ND_PRINT((ndo, "+"));
687 ND_PRINT((ndo, "%s", cp + 1));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800688 first = 0;
689 }
690 continue;
691 }
692
693 /* Print data */
694 if (c == '?') {
695 /* Base default formats for unknown tags on data size */
696 if (len & 1)
697 c = 'b';
698 else if (len & 2)
699 c = 's';
700 else
701 c = 'l';
702 }
703 first = 1;
704 switch (c) {
705
706 case 'a':
707 /* ascii strings */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700708 ND_PRINT((ndo, "\""));
709 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
710 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800711 goto trunc;
712 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700713 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800714 bp += len;
715 len = 0;
716 break;
717
718 case 'i':
719 case 'l':
720 case 'L':
721 /* ip addresses/32-bit words */
722 while (len >= sizeof(ul)) {
723 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700724 ND_PRINT((ndo, ","));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800725 ul = EXTRACT_32BITS(bp);
726 if (c == 'i') {
727 ul = htonl(ul);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700728 ND_PRINT((ndo, "%s", ipaddr_string(ndo, &ul)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800729 } else if (c == 'L')
Elliott Hughes892a68b2015-10-19 14:43:53 -0700730 ND_PRINT((ndo, "%d", ul));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800731 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700732 ND_PRINT((ndo, "%u", ul));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800733 bp += sizeof(ul);
734 len -= sizeof(ul);
735 first = 0;
736 }
737 break;
738
739 case 'p':
740 /* IP address pairs */
741 while (len >= 2*sizeof(ul)) {
742 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700743 ND_PRINT((ndo, ","));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800744 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700745 ND_PRINT((ndo, "(%s:", ipaddr_string(ndo, &ul)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800746 bp += sizeof(ul);
747 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700748 ND_PRINT((ndo, "%s)", ipaddr_string(ndo, &ul)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800749 bp += sizeof(ul);
750 len -= 2*sizeof(ul);
751 first = 0;
752 }
753 break;
754
755 case 's':
756 /* shorts */
757 while (len >= sizeof(us)) {
758 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700759 ND_PRINT((ndo, ","));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800760 us = EXTRACT_16BITS(bp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700761 ND_PRINT((ndo, "%u", us));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800762 bp += sizeof(us);
763 len -= sizeof(us);
764 first = 0;
765 }
766 break;
767
768 case 'B':
769 /* boolean */
770 while (len > 0) {
771 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700772 ND_PRINT((ndo, ","));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800773 switch (*bp) {
774 case 0:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700775 ND_PRINT((ndo, "N"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800776 break;
777 case 1:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700778 ND_PRINT((ndo, "Y"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800779 break;
780 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700781 ND_PRINT((ndo, "%u?", *bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800782 break;
783 }
784 ++bp;
785 --len;
786 first = 0;
787 }
788 break;
789
790 case 'b':
791 case 'x':
792 default:
793 /* Bytes */
794 while (len > 0) {
795 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700796 ND_PRINT((ndo, c == 'x' ? ":" : "."));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800797 if (c == 'x')
Elliott Hughes892a68b2015-10-19 14:43:53 -0700798 ND_PRINT((ndo, "%02x", *bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800799 else
Elliott Hughes892a68b2015-10-19 14:43:53 -0700800 ND_PRINT((ndo, "%u", *bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800801 ++bp;
802 --len;
803 first = 0;
804 }
805 break;
806
807 case '$':
808 /* Guys we can't handle with one of the usual cases */
809 switch (tag) {
810
811 case TAG_NETBIOS_NODE:
812 /* this option should be at least 1 byte long */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700813 if (len < 1) {
814 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800815 break;
816 }
817 tag = *bp++;
818 --len;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700819 ND_PRINT((ndo, "%s", tok2str(nbo2str, NULL, tag)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800820 break;
821
822 case TAG_OPT_OVERLOAD:
823 /* this option should be at least 1 byte long */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700824 if (len < 1) {
825 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800826 break;
827 }
828 tag = *bp++;
829 --len;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700830 ND_PRINT((ndo, "%s", tok2str(oo2str, NULL, tag)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800831 break;
832
833 case TAG_CLIENT_FQDN:
834 /* this option should be at least 3 bytes long */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700835 if (len < 3) {
836 ND_PRINT((ndo, "ERROR: length < 3 bytes"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800837 bp += len;
838 len = 0;
839 break;
840 }
841 if (*bp)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700842 ND_PRINT((ndo, "[%s] ", client_fqdn_flags(*bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 bp++;
844 if (*bp || *(bp+1))
Elliott Hughes892a68b2015-10-19 14:43:53 -0700845 ND_PRINT((ndo, "%u/%u ", *bp, *(bp+1)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800846 bp += 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700847 ND_PRINT((ndo, "\""));
848 if (fn_printn(ndo, bp, len - 3, ndo->ndo_snapend)) {
849 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800850 goto trunc;
851 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700852 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800853 bp += len - 3;
854 len = 0;
855 break;
856
857 case TAG_CLIENT_ID:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700858 {
859 int type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800860
861 /* this option should be at least 1 byte long */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700862 if (len < 1) {
863 ND_PRINT((ndo, "ERROR: length < 1 bytes"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800864 break;
865 }
866 type = *bp++;
867 len--;
868 if (type == 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700869 ND_PRINT((ndo, "\""));
870 if (fn_printn(ndo, bp, len, ndo->ndo_snapend)) {
871 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800872 goto trunc;
873 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700874 ND_PRINT((ndo, "\""));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800875 bp += len;
876 len = 0;
877 break;
878 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700879 ND_PRINT((ndo, "%s ", tok2str(arp2str, "hardware-type %u,", type)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800880 while (len > 0) {
881 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700882 ND_PRINT((ndo, ":"));
883 ND_PRINT((ndo, "%02x", *bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800884 ++bp;
885 --len;
886 first = 0;
887 }
888 }
889 break;
890 }
891
892 case TAG_AGENT_CIRCUIT:
893 while (len >= 2) {
894 subopt = *bp++;
895 suboptlen = *bp++;
896 len -= 2;
897 if (suboptlen > len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700898 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: length goes past end of option",
899 tok2str(agent_suboption_values, "Unknown", subopt),
900 subopt,
901 suboptlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800902 bp += len;
903 len = 0;
904 break;
905 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700906 ND_PRINT((ndo, "\n\t %s SubOption %u, length %u: ",
907 tok2str(agent_suboption_values, "Unknown", subopt),
908 subopt,
909 suboptlen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800910 switch (subopt) {
911
Elliott Hughes892a68b2015-10-19 14:43:53 -0700912 case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
913 case AGENT_SUBOPTION_REMOTE_ID:
914 case AGENT_SUBOPTION_SUBSCRIBER_ID:
915 if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend))
916 goto trunc;
917 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800918
919 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700920 print_unknown_data(ndo, bp, "\n\t\t", suboptlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800921 }
922
923 len -= suboptlen;
924 bp += suboptlen;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700925 }
926 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800927
928 case TAG_CLASSLESS_STATIC_RT:
929 case TAG_CLASSLESS_STA_RT_MS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700930 {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 u_int mask_width, significant_octets, i;
932
933 /* this option should be at least 5 bytes long */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700934 if (len < 5) {
935 ND_PRINT((ndo, "ERROR: length < 5 bytes"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800936 bp += len;
937 len = 0;
938 break;
939 }
940 while (len > 0) {
941 if (!first)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700942 ND_PRINT((ndo, ","));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800943 mask_width = *bp++;
944 len--;
945 /* mask_width <= 32 */
946 if (mask_width > 32) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700947 ND_PRINT((ndo, "[ERROR: Mask width (%d) > 32]", mask_width));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800948 bp += len;
949 len = 0;
950 break;
951 }
952 significant_octets = (mask_width + 7) / 8;
953 /* significant octets + router(4) */
954 if (len < significant_octets + 4) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700955 ND_PRINT((ndo, "[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800956 bp += len;
957 len = 0;
958 break;
959 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700960 ND_PRINT((ndo, "("));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800961 if (mask_width == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700962 ND_PRINT((ndo, "default"));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800963 else {
964 for (i = 0; i < significant_octets ; i++) {
965 if (i > 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700966 ND_PRINT((ndo, "."));
967 ND_PRINT((ndo, "%d", *bp++));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800968 }
969 for (i = significant_octets ; i < 4 ; i++)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700970 ND_PRINT((ndo, ".0"));
971 ND_PRINT((ndo, "/%d", mask_width));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800972 }
973 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700974 ND_PRINT((ndo, ":%s)", ipaddr_string(ndo, &ul)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800975 bp += sizeof(ul);
976 len -= (significant_octets + 4);
977 first = 0;
978 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700979 break;
980 }
981
982 case TAG_USER_CLASS:
983 {
984 u_int suboptnumber = 1;
985
986 first = 1;
987 if (len < 2) {
988 ND_PRINT((ndo, "ERROR: length < 2 bytes"));
989 bp += len;
990 len = 0;
991 break;
992 }
993 while (len > 0) {
994 suboptlen = *bp++;
995 len--;
996 ND_PRINT((ndo, "\n\t "));
997 ND_PRINT((ndo, "instance#%u: ", suboptnumber));
998 if (suboptlen == 0) {
999 ND_PRINT((ndo, "ERROR: suboption length must be non-zero"));
1000 bp += len;
1001 len = 0;
1002 break;
1003 }
1004 if (len < suboptlen) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001005 ND_PRINT((ndo, "ERROR: invalid option"));
Elliott Hughes892a68b2015-10-19 14:43:53 -07001006 bp += len;
1007 len = 0;
1008 break;
1009 }
1010 ND_PRINT((ndo, "\""));
1011 if (fn_printn(ndo, bp, suboptlen, ndo->ndo_snapend)) {
1012 ND_PRINT((ndo, "\""));
1013 goto trunc;
1014 }
1015 ND_PRINT((ndo, "\""));
1016 ND_PRINT((ndo, ", length %d", suboptlen));
1017 suboptnumber++;
1018 len -= suboptlen;
1019 bp += suboptlen;
1020 }
1021 break;
1022 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001023
1024 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001025 ND_PRINT((ndo, "[unknown special tag %u, size %u]",
1026 tag, len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001027 bp += len;
1028 len = 0;
1029 break;
1030 }
1031 break;
1032 }
1033 /* Data left over? */
1034 if (len) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001035 ND_PRINT((ndo, "\n\t trailing data length %u", len));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001036 bp += len;
1037 }
1038 }
1039 return;
1040trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001041 ND_PRINT((ndo, "|[rfc1048]"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001042}
1043
1044static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001045cmu_print(netdissect_options *ndo,
1046 register const u_char *bp)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001047{
1048 register const struct cmu_vend *cmu;
1049
Elliott Hughes892a68b2015-10-19 14:43:53 -07001050#define PRINTCMUADDR(m, s) { ND_TCHECK(cmu->m); \
The Android Open Source Project2949f582009-03-03 19:30:46 -08001051 if (cmu->m.s_addr != 0) \
Elliott Hughes892a68b2015-10-19 14:43:53 -07001052 ND_PRINT((ndo, " %s:%s", s, ipaddr_string(ndo, &cmu->m.s_addr))); }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053
Elliott Hughes892a68b2015-10-19 14:43:53 -07001054 ND_PRINT((ndo, " vend-cmu"));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001055 cmu = (const struct cmu_vend *)bp;
1056
1057 /* Only print if there are unknown bits */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001058 ND_TCHECK(cmu->v_flags);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001059 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001060 ND_PRINT((ndo, " F:0x%x", cmu->v_flags));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001061 PRINTCMUADDR(v_dgate, "DG");
1062 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
1063 PRINTCMUADDR(v_dns1, "NS1");
1064 PRINTCMUADDR(v_dns2, "NS2");
1065 PRINTCMUADDR(v_ins1, "IEN1");
1066 PRINTCMUADDR(v_ins2, "IEN2");
1067 PRINTCMUADDR(v_ts1, "TS1");
1068 PRINTCMUADDR(v_ts2, "TS2");
1069 return;
1070
1071trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001072 ND_PRINT((ndo, "%s", tstr));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001073#undef PRINTCMUADDR
1074}
1075
1076static char *
1077client_fqdn_flags(u_int flags)
1078{
1079 static char buf[8+1];
1080 int i = 0;
1081
1082 if (flags & CLIENT_FQDN_FLAGS_S)
1083 buf[i++] = 'S';
1084 if (flags & CLIENT_FQDN_FLAGS_O)
1085 buf[i++] = 'O';
1086 if (flags & CLIENT_FQDN_FLAGS_E)
1087 buf[i++] = 'E';
1088 if (flags & CLIENT_FQDN_FLAGS_N)
1089 buf[i++] = 'N';
1090 buf[i] = '\0';
1091
1092 return buf;
1093}