print-bootp.c revision 1.4 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that: (1) source code distributions
7 1.1 christos * retain the above copyright notice and this paragraph in its entirety, (2)
8 1.1 christos * distributions including binary code include the above copyright notice and
9 1.1 christos * this paragraph in its entirety in the documentation or other materials
10 1.1 christos * provided with the distribution, and (3) all advertising materials mentioning
11 1.1 christos * features or use of this software display the following acknowledgement:
12 1.1 christos * ``This product includes software developed by the University of California,
13 1.1 christos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 1.1 christos * the University nor the names of its contributors may be used to endorse
15 1.1 christos * or promote products derived from this software without specific prior
16 1.1 christos * written permission.
17 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 1.1 christos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 christos *
21 1.1 christos * Format and print bootp packets.
22 1.1 christos */
23 1.2 christos #include <sys/cdefs.h>
24 1.1 christos #ifndef lint
25 1.2 christos #if 0
26 1.1 christos static const char rcsid[] _U_ =
27 1.3 christos "@(#) Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.89 2008-04-22 09:45:08 hannes Exp (LBL)";
28 1.2 christos #else
29 1.4 christos __RCSID("$NetBSD: print-bootp.c,v 1.4 2013/12/31 17:33:31 christos Exp $");
30 1.2 christos #endif
31 1.1 christos #endif
32 1.1 christos
33 1.1 christos #ifdef HAVE_CONFIG_H
34 1.1 christos #include "config.h"
35 1.1 christos #endif
36 1.1 christos
37 1.1 christos #include <tcpdump-stdinc.h>
38 1.1 christos
39 1.1 christos #include <stdio.h>
40 1.1 christos #include <string.h>
41 1.1 christos
42 1.1 christos #include "interface.h"
43 1.1 christos #include "addrtoname.h"
44 1.1 christos #include "extract.h"
45 1.1 christos #include "ether.h"
46 1.1 christos #include "bootp.h"
47 1.1 christos
48 1.1 christos static void rfc1048_print(const u_char *);
49 1.1 christos static void cmu_print(const u_char *);
50 1.1 christos static char *client_fqdn_flags(u_int flags);
51 1.1 christos
52 1.1 christos static char tstr[] = " [|bootp]";
53 1.1 christos
54 1.1 christos static const struct tok bootp_flag_values[] = {
55 1.1 christos { 0x8000, "Broadcast" },
56 1.1 christos { 0, NULL}
57 1.1 christos };
58 1.1 christos
59 1.1 christos static const struct tok bootp_op_values[] = {
60 1.1 christos { BOOTPREQUEST, "Request" },
61 1.1 christos { BOOTPREPLY, "Reply" },
62 1.1 christos { 0, NULL}
63 1.1 christos };
64 1.1 christos
65 1.1 christos /*
66 1.1 christos * Print bootp requests
67 1.1 christos */
68 1.1 christos void
69 1.1 christos bootp_print(register const u_char *cp, u_int length)
70 1.1 christos {
71 1.1 christos register const struct bootp *bp;
72 1.1 christos static const u_char vm_cmu[4] = VM_CMU;
73 1.1 christos static const u_char vm_rfc1048[4] = VM_RFC1048;
74 1.1 christos
75 1.1 christos bp = (const struct bootp *)cp;
76 1.1 christos TCHECK(bp->bp_op);
77 1.1 christos
78 1.1 christos printf("BOOTP/DHCP, %s",
79 1.1 christos tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
80 1.1 christos
81 1.1 christos if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
82 1.1 christos TCHECK2(bp->bp_chaddr[0], 6);
83 1.1 christos printf(" from %s", etheraddr_string(bp->bp_chaddr));
84 1.1 christos }
85 1.1 christos
86 1.1 christos printf(", length %u", length);
87 1.1 christos
88 1.1 christos if (!vflag)
89 1.1 christos return;
90 1.1 christos
91 1.1 christos TCHECK(bp->bp_secs);
92 1.1 christos
93 1.1 christos /* The usual hardware address type is 1 (10Mb Ethernet) */
94 1.1 christos if (bp->bp_htype != 1)
95 1.1 christos printf(", htype %d", bp->bp_htype);
96 1.1 christos
97 1.1 christos /* The usual length for 10Mb Ethernet address is 6 bytes */
98 1.1 christos if (bp->bp_htype != 1 || bp->bp_hlen != 6)
99 1.1 christos printf(", hlen %d", bp->bp_hlen);
100 1.1 christos
101 1.1 christos /* Only print interesting fields */
102 1.1 christos if (bp->bp_hops)
103 1.1 christos printf(", hops %d", bp->bp_hops);
104 1.1 christos if (bp->bp_xid)
105 1.1 christos printf(", xid 0x%x", EXTRACT_32BITS(&bp->bp_xid));
106 1.1 christos if (bp->bp_secs)
107 1.1 christos printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs));
108 1.1 christos
109 1.1 christos printf(", Flags [%s]",
110 1.1 christos bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
111 1.1 christos if (vflag > 1)
112 1.1 christos printf(" (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
113 1.1 christos
114 1.1 christos /* Client's ip address */
115 1.1 christos TCHECK(bp->bp_ciaddr);
116 1.1 christos if (bp->bp_ciaddr.s_addr)
117 1.1 christos printf("\n\t Client-IP %s", ipaddr_string(&bp->bp_ciaddr));
118 1.1 christos
119 1.1 christos /* 'your' ip address (bootp client) */
120 1.1 christos TCHECK(bp->bp_yiaddr);
121 1.1 christos if (bp->bp_yiaddr.s_addr)
122 1.1 christos printf("\n\t Your-IP %s", ipaddr_string(&bp->bp_yiaddr));
123 1.1 christos
124 1.1 christos /* Server's ip address */
125 1.1 christos TCHECK(bp->bp_siaddr);
126 1.1 christos if (bp->bp_siaddr.s_addr)
127 1.1 christos printf("\n\t Server-IP %s", ipaddr_string(&bp->bp_siaddr));
128 1.1 christos
129 1.1 christos /* Gateway's ip address */
130 1.1 christos TCHECK(bp->bp_giaddr);
131 1.1 christos if (bp->bp_giaddr.s_addr)
132 1.1 christos printf("\n\t Gateway-IP %s", ipaddr_string(&bp->bp_giaddr));
133 1.1 christos
134 1.1 christos /* Client's Ethernet address */
135 1.1 christos if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
136 1.1 christos TCHECK2(bp->bp_chaddr[0], 6);
137 1.1 christos printf("\n\t Client-Ethernet-Address %s", etheraddr_string(bp->bp_chaddr));
138 1.1 christos }
139 1.1 christos
140 1.1 christos TCHECK2(bp->bp_sname[0], 1); /* check first char only */
141 1.1 christos if (*bp->bp_sname) {
142 1.1 christos printf("\n\t sname \"");
143 1.1 christos if (fn_print(bp->bp_sname, snapend)) {
144 1.1 christos putchar('"');
145 1.1 christos fputs(tstr + 1, stdout);
146 1.1 christos return;
147 1.1 christos }
148 1.1 christos putchar('"');
149 1.1 christos }
150 1.1 christos TCHECK2(bp->bp_file[0], 1); /* check first char only */
151 1.1 christos if (*bp->bp_file) {
152 1.1 christos printf("\n\t file \"");
153 1.1 christos if (fn_print(bp->bp_file, snapend)) {
154 1.1 christos putchar('"');
155 1.1 christos fputs(tstr + 1, stdout);
156 1.1 christos return;
157 1.1 christos }
158 1.1 christos putchar('"');
159 1.1 christos }
160 1.1 christos
161 1.1 christos /* Decode the vendor buffer */
162 1.1 christos TCHECK(bp->bp_vend[0]);
163 1.1 christos if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
164 1.1 christos sizeof(u_int32_t)) == 0)
165 1.1 christos rfc1048_print(bp->bp_vend);
166 1.1 christos else if (memcmp((const char *)bp->bp_vend, vm_cmu,
167 1.1 christos sizeof(u_int32_t)) == 0)
168 1.1 christos cmu_print(bp->bp_vend);
169 1.1 christos else {
170 1.1 christos u_int32_t ul;
171 1.1 christos
172 1.1 christos ul = EXTRACT_32BITS(&bp->bp_vend);
173 1.1 christos if (ul != 0)
174 1.1 christos printf("\n\t Vendor-#0x%x", ul);
175 1.1 christos }
176 1.1 christos
177 1.1 christos return;
178 1.1 christos trunc:
179 1.1 christos fputs(tstr, stdout);
180 1.1 christos }
181 1.1 christos
182 1.1 christos /*
183 1.1 christos * The first character specifies the format to print:
184 1.1 christos * i - ip address (32 bits)
185 1.1 christos * p - ip address pairs (32 bits + 32 bits)
186 1.1 christos * l - long (32 bits)
187 1.1 christos * L - unsigned long (32 bits)
188 1.1 christos * s - short (16 bits)
189 1.1 christos * b - period-seperated decimal bytes (variable length)
190 1.1 christos * x - colon-seperated hex bytes (variable length)
191 1.1 christos * a - ascii string (variable length)
192 1.1 christos * B - on/off (8 bits)
193 1.1 christos * $ - special (explicit code to handle)
194 1.1 christos */
195 1.4 christos static const struct tok tag2str[] = {
196 1.1 christos /* RFC1048 tags */
197 1.1 christos { TAG_PAD, " PAD" },
198 1.1 christos { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */
199 1.1 christos { TAG_TIME_OFFSET, "LTime-Zone" }, /* seconds from UTC */
200 1.1 christos { TAG_GATEWAY, "iDefault-Gateway" }, /* default gateway */
201 1.1 christos { TAG_TIME_SERVER, "iTime-Server" }, /* time servers (RFC868) */
202 1.1 christos { TAG_NAME_SERVER, "iIEN-Name-Server" }, /* IEN name servers (IEN116) */
203 1.1 christos { TAG_DOMAIN_SERVER, "iDomain-Name-Server" }, /* domain name (RFC1035) */
204 1.1 christos { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
205 1.1 christos { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
206 1.1 christos { TAG_LPR_SERVER, "iLPR-Server" }, /* lpr server (RFC1179) */
207 1.1 christos { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
208 1.1 christos { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
209 1.1 christos { TAG_HOSTNAME, "aHostname" }, /* ascii hostname */
210 1.1 christos { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
211 1.1 christos { TAG_END, " END" },
212 1.1 christos /* RFC1497 tags */
213 1.1 christos { TAG_DUMPPATH, "aDP" },
214 1.1 christos { TAG_DOMAINNAME, "aDomain-Name" },
215 1.1 christos { TAG_SWAP_SERVER, "iSS" },
216 1.1 christos { TAG_ROOTPATH, "aRP" },
217 1.1 christos { TAG_EXTPATH, "aEP" },
218 1.1 christos /* RFC2132 tags */
219 1.1 christos { TAG_IP_FORWARD, "BIPF" },
220 1.1 christos { TAG_NL_SRCRT, "BSRT" },
221 1.1 christos { TAG_PFILTERS, "pPF" },
222 1.1 christos { TAG_REASS_SIZE, "sRSZ" },
223 1.1 christos { TAG_DEF_TTL, "bTTL" },
224 1.1 christos { TAG_MTU_TIMEOUT, "lMTU-Timeout" },
225 1.1 christos { TAG_MTU_TABLE, "sMTU-Table" },
226 1.1 christos { TAG_INT_MTU, "sMTU" },
227 1.1 christos { TAG_LOCAL_SUBNETS, "BLSN" },
228 1.1 christos { TAG_BROAD_ADDR, "iBR" },
229 1.1 christos { TAG_DO_MASK_DISC, "BMD" },
230 1.1 christos { TAG_SUPPLY_MASK, "BMS" },
231 1.1 christos { TAG_DO_RDISC, "BRouter-Discovery" },
232 1.1 christos { TAG_RTR_SOL_ADDR, "iRSA" },
233 1.1 christos { TAG_STATIC_ROUTE, "pStatic-Route" },
234 1.1 christos { TAG_USE_TRAILERS, "BUT" },
235 1.1 christos { TAG_ARP_TIMEOUT, "lAT" },
236 1.1 christos { TAG_ETH_ENCAP, "BIE" },
237 1.1 christos { TAG_TCP_TTL, "bTT" },
238 1.1 christos { TAG_TCP_KEEPALIVE, "lKI" },
239 1.1 christos { TAG_KEEPALIVE_GO, "BKG" },
240 1.1 christos { TAG_NIS_DOMAIN, "aYD" },
241 1.1 christos { TAG_NIS_SERVERS, "iYS" },
242 1.1 christos { TAG_NTP_SERVERS, "iNTP" },
243 1.1 christos { TAG_VENDOR_OPTS, "bVendor-Option" },
244 1.1 christos { TAG_NETBIOS_NS, "iNetbios-Name-Server" },
245 1.1 christos { TAG_NETBIOS_DDS, "iWDD" },
246 1.1 christos { TAG_NETBIOS_NODE, "$Netbios-Node" },
247 1.1 christos { TAG_NETBIOS_SCOPE, "aNetbios-Scope" },
248 1.1 christos { TAG_XWIN_FS, "iXFS" },
249 1.1 christos { TAG_XWIN_DM, "iXDM" },
250 1.1 christos { TAG_NIS_P_DOMAIN, "sN+D" },
251 1.1 christos { TAG_NIS_P_SERVERS, "iN+S" },
252 1.1 christos { TAG_MOBILE_HOME, "iMH" },
253 1.1 christos { TAG_SMPT_SERVER, "iSMTP" },
254 1.1 christos { TAG_POP3_SERVER, "iPOP3" },
255 1.1 christos { TAG_NNTP_SERVER, "iNNTP" },
256 1.1 christos { TAG_WWW_SERVER, "iWWW" },
257 1.1 christos { TAG_FINGER_SERVER, "iFG" },
258 1.1 christos { TAG_IRC_SERVER, "iIRC" },
259 1.1 christos { TAG_STREETTALK_SRVR, "iSTS" },
260 1.1 christos { TAG_STREETTALK_STDA, "iSTDA" },
261 1.1 christos { TAG_REQUESTED_IP, "iRequested-IP" },
262 1.1 christos { TAG_IP_LEASE, "lLease-Time" },
263 1.1 christos { TAG_OPT_OVERLOAD, "$OO" },
264 1.1 christos { TAG_TFTP_SERVER, "aTFTP" },
265 1.1 christos { TAG_BOOTFILENAME, "aBF" },
266 1.1 christos { TAG_DHCP_MESSAGE, " DHCP-Message" },
267 1.1 christos { TAG_SERVER_ID, "iServer-ID" },
268 1.1 christos { TAG_PARM_REQUEST, "bParameter-Request" },
269 1.1 christos { TAG_MESSAGE, "aMSG" },
270 1.1 christos { TAG_MAX_MSG_SIZE, "sMSZ" },
271 1.1 christos { TAG_RENEWAL_TIME, "lRN" },
272 1.1 christos { TAG_REBIND_TIME, "lRB" },
273 1.1 christos { TAG_VENDOR_CLASS, "aVendor-Class" },
274 1.1 christos { TAG_CLIENT_ID, "$Client-ID" },
275 1.1 christos /* RFC 2485 */
276 1.1 christos { TAG_OPEN_GROUP_UAP, "aUAP" },
277 1.1 christos /* RFC 2563 */
278 1.1 christos { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
279 1.1 christos /* RFC 2610 */
280 1.1 christos { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
281 1.1 christos { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
282 1.1 christos /* RFC 2937 */
283 1.1 christos { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
284 1.1 christos /* RFC 3011 */
285 1.1 christos { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
286 1.1 christos /* RFC 3442 */
287 1.1 christos { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" },
288 1.1 christos { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" },
289 1.1 christos /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
290 1.1 christos { TAG_USER_CLASS, "aCLASS" },
291 1.1 christos { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
292 1.1 christos { TAG_CLIENT_FQDN, "$FQDN" },
293 1.1 christos { TAG_AGENT_CIRCUIT, "$Agent-Information" },
294 1.1 christos { TAG_AGENT_REMOTE, "bARMT" },
295 1.1 christos { TAG_AGENT_MASK, "bAMSK" },
296 1.1 christos { TAG_TZ_STRING, "aTZSTR" },
297 1.1 christos { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
298 1.1 christos { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
299 1.1 christos { TAG_VINES_SERVERS, "iVINES" },
300 1.1 christos { TAG_SERVER_RANK, "sRANK" },
301 1.1 christos { TAG_CLIENT_ARCH, "sARCH" },
302 1.1 christos { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
303 1.1 christos { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
304 1.1 christos { TAG_LDAP_URL, "aLDAP" },
305 1.1 christos { TAG_6OVER4, "i6o4" },
306 1.1 christos { TAG_PRINTER_NAME, "aPRTR" },
307 1.1 christos { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
308 1.1 christos { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
309 1.1 christos { TAG_NETINFO_PARENT, "iNI" },
310 1.1 christos { TAG_NETINFO_PARENT_TAG, "aNITAG" },
311 1.1 christos { TAG_URL, "aURL" },
312 1.1 christos { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
313 1.1 christos { 0, NULL }
314 1.1 christos };
315 1.1 christos /* 2-byte extended tags */
316 1.4 christos static const struct tok xtag2str[] = {
317 1.1 christos { 0, NULL }
318 1.1 christos };
319 1.1 christos
320 1.1 christos /* DHCP "options overload" types */
321 1.4 christos static const struct tok oo2str[] = {
322 1.1 christos { 1, "file" },
323 1.1 christos { 2, "sname" },
324 1.1 christos { 3, "file+sname" },
325 1.1 christos { 0, NULL }
326 1.1 christos };
327 1.1 christos
328 1.1 christos /* NETBIOS over TCP/IP node type options */
329 1.4 christos static const struct tok nbo2str[] = {
330 1.1 christos { 0x1, "b-node" },
331 1.1 christos { 0x2, "p-node" },
332 1.1 christos { 0x4, "m-node" },
333 1.1 christos { 0x8, "h-node" },
334 1.1 christos { 0, NULL }
335 1.1 christos };
336 1.1 christos
337 1.1 christos /* ARP Hardware types, for Client-ID option */
338 1.4 christos static const struct tok arp2str[] = {
339 1.1 christos { 0x1, "ether" },
340 1.1 christos { 0x6, "ieee802" },
341 1.1 christos { 0x7, "arcnet" },
342 1.1 christos { 0xf, "frelay" },
343 1.1 christos { 0x17, "strip" },
344 1.1 christos { 0x18, "ieee1394" },
345 1.1 christos { 0, NULL }
346 1.1 christos };
347 1.1 christos
348 1.4 christos static const struct tok dhcp_msg_values[] = {
349 1.1 christos { DHCPDISCOVER, "Discover" },
350 1.1 christos { DHCPOFFER, "Offer" },
351 1.1 christos { DHCPREQUEST, "Request" },
352 1.1 christos { DHCPDECLINE, "Decline" },
353 1.1 christos { DHCPACK, "ACK" },
354 1.1 christos { DHCPNAK, "NACK" },
355 1.1 christos { DHCPRELEASE, "Release" },
356 1.1 christos { DHCPINFORM, "Inform" },
357 1.1 christos { 0, NULL }
358 1.1 christos };
359 1.1 christos
360 1.1 christos #define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */
361 1.1 christos #define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */
362 1.1 christos #define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */
363 1.4 christos static const struct tok agent_suboption_values[] = {
364 1.1 christos { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" },
365 1.1 christos { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" },
366 1.1 christos { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" },
367 1.1 christos { 0, NULL }
368 1.1 christos };
369 1.1 christos
370 1.1 christos
371 1.1 christos static void
372 1.1 christos rfc1048_print(register const u_char *bp)
373 1.1 christos {
374 1.1 christos register u_int16_t tag;
375 1.1 christos register u_int len;
376 1.1 christos register const char *cp;
377 1.1 christos register char c;
378 1.1 christos int first, idx;
379 1.1 christos u_int32_t ul;
380 1.1 christos u_int16_t us;
381 1.1 christos u_int8_t uc, subopt, suboptlen;
382 1.1 christos
383 1.1 christos printf("\n\t Vendor-rfc1048 Extensions");
384 1.1 christos
385 1.1 christos /* Step over magic cookie */
386 1.1 christos printf("\n\t Magic Cookie 0x%08x", EXTRACT_32BITS(bp));
387 1.1 christos bp += sizeof(int32_t);
388 1.1 christos
389 1.1 christos /* Loop while we there is a tag left in the buffer */
390 1.1 christos while (TTEST2(*bp, 1)) {
391 1.1 christos tag = *bp++;
392 1.1 christos if (tag == TAG_PAD && vflag < 3)
393 1.1 christos continue;
394 1.1 christos if (tag == TAG_END && vflag < 3)
395 1.1 christos return;
396 1.1 christos if (tag == TAG_EXTENDED_OPTION) {
397 1.1 christos TCHECK2(*(bp + 1), 2);
398 1.1 christos tag = EXTRACT_16BITS(bp + 1);
399 1.1 christos /* XXX we don't know yet if the IANA will
400 1.1 christos * preclude overlap of 1-byte and 2-byte spaces.
401 1.1 christos * If not, we need to offset tag after this step.
402 1.1 christos */
403 1.1 christos cp = tok2str(xtag2str, "?xT%u", tag);
404 1.1 christos } else
405 1.1 christos cp = tok2str(tag2str, "?T%u", tag);
406 1.1 christos c = *cp++;
407 1.1 christos
408 1.1 christos if (tag == TAG_PAD || tag == TAG_END)
409 1.1 christos len = 0;
410 1.1 christos else {
411 1.1 christos /* Get the length; check for truncation */
412 1.1 christos TCHECK2(*bp, 1);
413 1.1 christos len = *bp++;
414 1.1 christos }
415 1.1 christos
416 1.1 christos printf("\n\t %s Option %u, length %u%s", cp, tag, len,
417 1.1 christos len > 0 ? ": " : "");
418 1.1 christos
419 1.1 christos if (tag == TAG_PAD && vflag > 2) {
420 1.1 christos u_int ntag = 1;
421 1.1 christos while (TTEST2(*bp, 1) && *bp == TAG_PAD) {
422 1.1 christos bp++;
423 1.1 christos ntag++;
424 1.1 christos }
425 1.1 christos if (ntag > 1)
426 1.1 christos printf(", occurs %u", ntag);
427 1.1 christos }
428 1.1 christos
429 1.1 christos if (!TTEST2(*bp, len)) {
430 1.1 christos printf("[|rfc1048 %u]", len);
431 1.1 christos return;
432 1.1 christos }
433 1.1 christos
434 1.1 christos if (tag == TAG_DHCP_MESSAGE && len == 1) {
435 1.1 christos uc = *bp++;
436 1.1 christos printf("%s", tok2str(dhcp_msg_values, "Unknown (%u)", uc));
437 1.1 christos continue;
438 1.1 christos }
439 1.1 christos
440 1.1 christos if (tag == TAG_PARM_REQUEST) {
441 1.1 christos idx = 0;
442 1.1 christos while (len-- > 0) {
443 1.1 christos uc = *bp++;
444 1.1 christos cp = tok2str(tag2str, "?Option %u", uc);
445 1.1 christos if (idx % 4 == 0)
446 1.1 christos printf("\n\t ");
447 1.1 christos else
448 1.1 christos printf(", ");
449 1.1 christos printf("%s", cp + 1);
450 1.1 christos idx++;
451 1.1 christos }
452 1.1 christos continue;
453 1.1 christos }
454 1.1 christos
455 1.1 christos if (tag == TAG_EXTENDED_REQUEST) {
456 1.1 christos first = 1;
457 1.1 christos while (len > 1) {
458 1.1 christos len -= 2;
459 1.1 christos us = EXTRACT_16BITS(bp);
460 1.1 christos bp += 2;
461 1.1 christos cp = tok2str(xtag2str, "?xT%u", us);
462 1.1 christos if (!first)
463 1.1 christos putchar('+');
464 1.1 christos printf("%s", cp + 1);
465 1.1 christos first = 0;
466 1.1 christos }
467 1.1 christos continue;
468 1.1 christos }
469 1.1 christos
470 1.1 christos /* Print data */
471 1.1 christos if (c == '?') {
472 1.1 christos /* Base default formats for unknown tags on data size */
473 1.1 christos if (len & 1)
474 1.1 christos c = 'b';
475 1.1 christos else if (len & 2)
476 1.1 christos c = 's';
477 1.1 christos else
478 1.1 christos c = 'l';
479 1.1 christos }
480 1.1 christos first = 1;
481 1.1 christos switch (c) {
482 1.1 christos
483 1.1 christos case 'a':
484 1.1 christos /* ascii strings */
485 1.1 christos putchar('"');
486 1.1 christos if (fn_printn(bp, len, snapend)) {
487 1.1 christos putchar('"');
488 1.1 christos goto trunc;
489 1.1 christos }
490 1.1 christos putchar('"');
491 1.1 christos bp += len;
492 1.1 christos len = 0;
493 1.1 christos break;
494 1.1 christos
495 1.1 christos case 'i':
496 1.1 christos case 'l':
497 1.1 christos case 'L':
498 1.1 christos /* ip addresses/32-bit words */
499 1.1 christos while (len >= sizeof(ul)) {
500 1.1 christos if (!first)
501 1.1 christos putchar(',');
502 1.1 christos ul = EXTRACT_32BITS(bp);
503 1.1 christos if (c == 'i') {
504 1.1 christos ul = htonl(ul);
505 1.1 christos printf("%s", ipaddr_string(&ul));
506 1.1 christos } else if (c == 'L')
507 1.1 christos printf("%d", ul);
508 1.1 christos else
509 1.1 christos printf("%u", ul);
510 1.1 christos bp += sizeof(ul);
511 1.1 christos len -= sizeof(ul);
512 1.1 christos first = 0;
513 1.1 christos }
514 1.1 christos break;
515 1.1 christos
516 1.1 christos case 'p':
517 1.1 christos /* IP address pairs */
518 1.1 christos while (len >= 2*sizeof(ul)) {
519 1.1 christos if (!first)
520 1.1 christos putchar(',');
521 1.1 christos memcpy((char *)&ul, (const char *)bp, sizeof(ul));
522 1.1 christos printf("(%s:", ipaddr_string(&ul));
523 1.1 christos bp += sizeof(ul);
524 1.1 christos memcpy((char *)&ul, (const char *)bp, sizeof(ul));
525 1.1 christos printf("%s)", ipaddr_string(&ul));
526 1.1 christos bp += sizeof(ul);
527 1.1 christos len -= 2*sizeof(ul);
528 1.1 christos first = 0;
529 1.1 christos }
530 1.1 christos break;
531 1.1 christos
532 1.1 christos case 's':
533 1.1 christos /* shorts */
534 1.1 christos while (len >= sizeof(us)) {
535 1.1 christos if (!first)
536 1.1 christos putchar(',');
537 1.1 christos us = EXTRACT_16BITS(bp);
538 1.1 christos printf("%u", us);
539 1.1 christos bp += sizeof(us);
540 1.1 christos len -= sizeof(us);
541 1.1 christos first = 0;
542 1.1 christos }
543 1.1 christos break;
544 1.1 christos
545 1.1 christos case 'B':
546 1.1 christos /* boolean */
547 1.1 christos while (len > 0) {
548 1.1 christos if (!first)
549 1.1 christos putchar(',');
550 1.1 christos switch (*bp) {
551 1.1 christos case 0:
552 1.1 christos putchar('N');
553 1.1 christos break;
554 1.1 christos case 1:
555 1.1 christos putchar('Y');
556 1.1 christos break;
557 1.1 christos default:
558 1.1 christos printf("%u?", *bp);
559 1.1 christos break;
560 1.1 christos }
561 1.1 christos ++bp;
562 1.1 christos --len;
563 1.1 christos first = 0;
564 1.1 christos }
565 1.1 christos break;
566 1.1 christos
567 1.1 christos case 'b':
568 1.1 christos case 'x':
569 1.1 christos default:
570 1.1 christos /* Bytes */
571 1.1 christos while (len > 0) {
572 1.1 christos if (!first)
573 1.1 christos putchar(c == 'x' ? ':' : '.');
574 1.1 christos if (c == 'x')
575 1.1 christos printf("%02x", *bp);
576 1.1 christos else
577 1.1 christos printf("%u", *bp);
578 1.1 christos ++bp;
579 1.1 christos --len;
580 1.1 christos first = 0;
581 1.1 christos }
582 1.1 christos break;
583 1.1 christos
584 1.1 christos case '$':
585 1.1 christos /* Guys we can't handle with one of the usual cases */
586 1.1 christos switch (tag) {
587 1.1 christos
588 1.1 christos case TAG_NETBIOS_NODE:
589 1.1 christos /* this option should be at least 1 byte long */
590 1.1 christos if (len < 1) {
591 1.1 christos printf("ERROR: option %u len %u < 1 bytes",
592 1.1 christos TAG_NETBIOS_NODE, len);
593 1.1 christos break;
594 1.1 christos }
595 1.1 christos tag = *bp++;
596 1.1 christos --len;
597 1.1 christos fputs(tok2str(nbo2str, NULL, tag), stdout);
598 1.1 christos break;
599 1.1 christos
600 1.1 christos case TAG_OPT_OVERLOAD:
601 1.1 christos /* this option should be at least 1 byte long */
602 1.1 christos if (len < 1) {
603 1.1 christos printf("ERROR: option %u len %u < 1 bytes",
604 1.1 christos TAG_OPT_OVERLOAD, len);
605 1.1 christos break;
606 1.1 christos }
607 1.1 christos tag = *bp++;
608 1.1 christos --len;
609 1.1 christos fputs(tok2str(oo2str, NULL, tag), stdout);
610 1.1 christos break;
611 1.1 christos
612 1.1 christos case TAG_CLIENT_FQDN:
613 1.1 christos /* this option should be at least 3 bytes long */
614 1.1 christos if (len < 3) {
615 1.1 christos printf("ERROR: option %u len %u < 3 bytes",
616 1.1 christos TAG_CLIENT_FQDN, len);
617 1.1 christos bp += len;
618 1.1 christos len = 0;
619 1.1 christos break;
620 1.1 christos }
621 1.1 christos if (*bp)
622 1.1 christos printf("[%s] ", client_fqdn_flags(*bp));
623 1.1 christos bp++;
624 1.1 christos if (*bp || *(bp+1))
625 1.1 christos printf("%u/%u ", *bp, *(bp+1));
626 1.1 christos bp += 2;
627 1.1 christos putchar('"');
628 1.1 christos if (fn_printn(bp, len - 3, snapend)) {
629 1.1 christos putchar('"');
630 1.1 christos goto trunc;
631 1.1 christos }
632 1.1 christos putchar('"');
633 1.1 christos bp += len - 3;
634 1.1 christos len = 0;
635 1.1 christos break;
636 1.1 christos
637 1.1 christos case TAG_CLIENT_ID:
638 1.1 christos { int type;
639 1.1 christos
640 1.1 christos /* this option should be at least 1 byte long */
641 1.1 christos if (len < 1) {
642 1.1 christos printf("ERROR: option %u len %u < 1 bytes",
643 1.1 christos TAG_CLIENT_ID, len);
644 1.1 christos break;
645 1.1 christos }
646 1.1 christos type = *bp++;
647 1.1 christos len--;
648 1.1 christos if (type == 0) {
649 1.1 christos putchar('"');
650 1.1 christos if (fn_printn(bp, len, snapend)) {
651 1.1 christos putchar('"');
652 1.1 christos goto trunc;
653 1.1 christos }
654 1.1 christos putchar('"');
655 1.1 christos bp += len;
656 1.1 christos len = 0;
657 1.1 christos break;
658 1.1 christos } else {
659 1.1 christos printf("%s ", tok2str(arp2str, "hardware-type %u,", type));
660 1.1 christos while (len > 0) {
661 1.1 christos if (!first)
662 1.1 christos putchar(':');
663 1.1 christos printf("%02x", *bp);
664 1.1 christos ++bp;
665 1.1 christos --len;
666 1.1 christos first = 0;
667 1.1 christos }
668 1.1 christos }
669 1.1 christos break;
670 1.1 christos }
671 1.1 christos
672 1.1 christos case TAG_AGENT_CIRCUIT:
673 1.1 christos while (len >= 2) {
674 1.1 christos subopt = *bp++;
675 1.1 christos suboptlen = *bp++;
676 1.1 christos len -= 2;
677 1.1 christos if (suboptlen > len) {
678 1.1 christos printf("\n\t %s SubOption %u, length %u: length goes past end of option",
679 1.1 christos tok2str(agent_suboption_values, "Unknown", subopt),
680 1.1 christos subopt,
681 1.1 christos suboptlen);
682 1.1 christos bp += len;
683 1.1 christos len = 0;
684 1.1 christos break;
685 1.1 christos }
686 1.1 christos printf("\n\t %s SubOption %u, length %u: ",
687 1.1 christos tok2str(agent_suboption_values, "Unknown", subopt),
688 1.1 christos subopt,
689 1.1 christos suboptlen);
690 1.1 christos switch (subopt) {
691 1.1 christos
692 1.1 christos case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */
693 1.1 christos case AGENT_SUBOPTION_REMOTE_ID:
694 1.1 christos case AGENT_SUBOPTION_SUBSCRIBER_ID:
695 1.1 christos fn_printn(bp, suboptlen, NULL);
696 1.1 christos break;
697 1.1 christos
698 1.1 christos default:
699 1.1 christos print_unknown_data(bp, "\n\t\t", suboptlen);
700 1.1 christos }
701 1.1 christos
702 1.1 christos len -= suboptlen;
703 1.1 christos bp += suboptlen;
704 1.1 christos }
705 1.1 christos break;
706 1.1 christos
707 1.1 christos case TAG_CLASSLESS_STATIC_RT:
708 1.1 christos case TAG_CLASSLESS_STA_RT_MS:
709 1.1 christos {
710 1.1 christos u_int mask_width, significant_octets, i;
711 1.1 christos
712 1.1 christos /* this option should be at least 5 bytes long */
713 1.1 christos if (len < 5) {
714 1.1 christos printf("ERROR: option %u len %u < 5 bytes",
715 1.1 christos TAG_CLASSLESS_STATIC_RT, len);
716 1.1 christos bp += len;
717 1.1 christos len = 0;
718 1.1 christos break;
719 1.1 christos }
720 1.1 christos while (len > 0) {
721 1.1 christos if (!first)
722 1.1 christos putchar(',');
723 1.1 christos mask_width = *bp++;
724 1.1 christos len--;
725 1.1 christos /* mask_width <= 32 */
726 1.1 christos if (mask_width > 32) {
727 1.1 christos printf("[ERROR: Mask width (%d) > 32]", mask_width);
728 1.1 christos bp += len;
729 1.1 christos len = 0;
730 1.1 christos break;
731 1.1 christos }
732 1.1 christos significant_octets = (mask_width + 7) / 8;
733 1.1 christos /* significant octets + router(4) */
734 1.1 christos if (len < significant_octets + 4) {
735 1.1 christos printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4);
736 1.1 christos bp += len;
737 1.1 christos len = 0;
738 1.1 christos break;
739 1.1 christos }
740 1.1 christos putchar('(');
741 1.1 christos if (mask_width == 0)
742 1.1 christos printf("default");
743 1.1 christos else {
744 1.1 christos for (i = 0; i < significant_octets ; i++) {
745 1.1 christos if (i > 0)
746 1.1 christos putchar('.');
747 1.1 christos printf("%d", *bp++);
748 1.1 christos }
749 1.1 christos for (i = significant_octets ; i < 4 ; i++)
750 1.1 christos printf(".0");
751 1.1 christos printf("/%d", mask_width);
752 1.1 christos }
753 1.1 christos memcpy((char *)&ul, (const char *)bp, sizeof(ul));
754 1.1 christos printf(":%s)", ipaddr_string(&ul));
755 1.1 christos bp += sizeof(ul);
756 1.1 christos len -= (significant_octets + 4);
757 1.1 christos first = 0;
758 1.1 christos }
759 1.1 christos }
760 1.1 christos break;
761 1.1 christos
762 1.1 christos default:
763 1.1 christos printf("[unknown special tag %u, size %u]",
764 1.1 christos tag, len);
765 1.1 christos bp += len;
766 1.1 christos len = 0;
767 1.1 christos break;
768 1.1 christos }
769 1.1 christos break;
770 1.1 christos }
771 1.1 christos /* Data left over? */
772 1.1 christos if (len) {
773 1.1 christos printf("\n\t trailing data length %u", len);
774 1.1 christos bp += len;
775 1.1 christos }
776 1.1 christos }
777 1.1 christos return;
778 1.1 christos trunc:
779 1.1 christos printf("|[rfc1048]");
780 1.1 christos }
781 1.1 christos
782 1.1 christos static void
783 1.1 christos cmu_print(register const u_char *bp)
784 1.1 christos {
785 1.1 christos register const struct cmu_vend *cmu;
786 1.1 christos
787 1.1 christos #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
788 1.1 christos if (cmu->m.s_addr != 0) \
789 1.1 christos printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
790 1.1 christos
791 1.1 christos printf(" vend-cmu");
792 1.1 christos cmu = (const struct cmu_vend *)bp;
793 1.1 christos
794 1.1 christos /* Only print if there are unknown bits */
795 1.1 christos TCHECK(cmu->v_flags);
796 1.1 christos if ((cmu->v_flags & ~(VF_SMASK)) != 0)
797 1.1 christos printf(" F:0x%x", cmu->v_flags);
798 1.1 christos PRINTCMUADDR(v_dgate, "DG");
799 1.1 christos PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
800 1.1 christos PRINTCMUADDR(v_dns1, "NS1");
801 1.1 christos PRINTCMUADDR(v_dns2, "NS2");
802 1.1 christos PRINTCMUADDR(v_ins1, "IEN1");
803 1.1 christos PRINTCMUADDR(v_ins2, "IEN2");
804 1.1 christos PRINTCMUADDR(v_ts1, "TS1");
805 1.1 christos PRINTCMUADDR(v_ts2, "TS2");
806 1.1 christos return;
807 1.1 christos
808 1.1 christos trunc:
809 1.1 christos fputs(tstr, stdout);
810 1.1 christos #undef PRINTCMUADDR
811 1.1 christos }
812 1.1 christos
813 1.1 christos static char *
814 1.1 christos client_fqdn_flags(u_int flags)
815 1.1 christos {
816 1.1 christos static char buf[8+1];
817 1.1 christos int i = 0;
818 1.1 christos
819 1.1 christos if (flags & CLIENT_FQDN_FLAGS_S)
820 1.1 christos buf[i++] = 'S';
821 1.1 christos if (flags & CLIENT_FQDN_FLAGS_O)
822 1.1 christos buf[i++] = 'O';
823 1.1 christos if (flags & CLIENT_FQDN_FLAGS_E)
824 1.1 christos buf[i++] = 'E';
825 1.1 christos if (flags & CLIENT_FQDN_FLAGS_N)
826 1.1 christos buf[i++] = 'N';
827 1.1 christos buf[i] = '\0';
828 1.1 christos
829 1.1 christos return buf;
830 1.1 christos }
831