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