]> The Tcpdump Group git mirrors - tcpdump/blob - print-bootp.c
don't pass on src & dst MAC adresses to the isoclns decoder as MAC adresses
[tcpdump] / print-bootp.c
1 /*
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * Format and print bootp packets.
22 */
23 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.73 2003-05-01 18:02:12 guy Exp $ (LBL)";
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <tcpdump-stdinc.h>
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 #include "ether.h"
41 #include "bootp.h"
42
43 static void rfc1048_print(const u_char *);
44 static void cmu_print(const u_char *);
45
46 static char tstr[] = " [|bootp]";
47
48 /*
49 * Print bootp requests
50 */
51 void
52 bootp_print(register const u_char *cp, u_int length)
53 {
54 register const struct bootp *bp;
55 static const u_char vm_cmu[4] = VM_CMU;
56 static const u_char vm_rfc1048[4] = VM_RFC1048;
57
58 bp = (const struct bootp *)cp;
59 TCHECK(bp->bp_op);
60
61 printf("BOOTP/DHCP, %s",
62 tok2str(bootp_op_values, "unknown (0x%02x)", bp->bp_op));
63
64 if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
65 TCHECK2(bp->bp_chaddr[0], 6);
66 printf(" from %s", etheraddr_string(bp->bp_chaddr));
67 }
68
69 printf(", length: %u", length);
70
71 if (!vflag)
72 return;
73
74 TCHECK(bp->bp_secs);
75
76 /* The usual hardware address type is 1 (10Mb Ethernet) */
77 if (bp->bp_htype != 1)
78 printf(", htype-#%d", bp->bp_htype);
79
80 /* The usual length for 10Mb Ethernet address is 6 bytes */
81 if (bp->bp_htype != 1 || bp->bp_hlen != 6)
82 printf(", hlen:%d", bp->bp_hlen);
83
84 /* Only print interesting fields */
85 if (bp->bp_hops)
86 printf(", hops:%d", bp->bp_hops);
87 if (bp->bp_xid)
88 printf(", xid:0x%x", EXTRACT_32BITS(&bp->bp_xid));
89 if (bp->bp_secs)
90 printf(", secs:%d", EXTRACT_16BITS(&bp->bp_secs));
91
92 printf(", flags: [%s]",
93 bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags)));
94 if (vflag>1)
95 printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags));
96
97 /* Client's ip address */
98 TCHECK(bp->bp_ciaddr);
99 if (bp->bp_ciaddr.s_addr)
100 printf("\n\t Client IP: %s", ipaddr_string(&bp->bp_ciaddr));
101
102 /* 'your' ip address (bootp client) */
103 TCHECK(bp->bp_yiaddr);
104 if (bp->bp_yiaddr.s_addr)
105 printf("\n\t Your IP: %s", ipaddr_string(&bp->bp_yiaddr));
106
107 /* Server's ip address */
108 TCHECK(bp->bp_siaddr);
109 if (bp->bp_siaddr.s_addr)
110 printf("\n\t Server IP: %s", ipaddr_string(&bp->bp_siaddr));
111
112 /* Gateway's ip address */
113 TCHECK(bp->bp_giaddr);
114 if (bp->bp_giaddr.s_addr)
115 printf("\n\t Gateway IP: %s", ipaddr_string(&bp->bp_giaddr));
116
117 /* Client's Ethernet address */
118 if (bp->bp_htype == 1 && bp->bp_hlen == 6) {
119 TCHECK2(bp->bp_chaddr[0], 6);
120 printf("\n\t Client Ethernet Address: %s", etheraddr_string(bp->bp_chaddr));
121 }
122
123 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
124 if (*bp->bp_sname) {
125 printf("\n\t sname \"");
126 if (fn_print(bp->bp_sname, snapend)) {
127 putchar('"');
128 fputs(tstr + 1, stdout);
129 return;
130 }
131 putchar('"');
132 }
133 TCHECK2(bp->bp_sname[0], 1); /* check first char only */
134 if (*bp->bp_file) {
135 printf("\n\t file \"");
136 if (fn_print(bp->bp_file, snapend)) {
137 putchar('"');
138 fputs(tstr + 1, stdout);
139 return;
140 }
141 putchar('"');
142 }
143
144 /* Decode the vendor buffer */
145 TCHECK(bp->bp_vend[0]);
146 if (memcmp((const char *)bp->bp_vend, vm_rfc1048,
147 sizeof(u_int32_t)) == 0)
148 rfc1048_print(bp->bp_vend);
149 else if (memcmp((const char *)bp->bp_vend, vm_cmu,
150 sizeof(u_int32_t)) == 0)
151 cmu_print(bp->bp_vend);
152 else {
153 u_int32_t ul;
154
155 ul = EXTRACT_32BITS(&bp->bp_vend);
156 if (ul != 0)
157 printf("\n\t Vendor-#0x%x", ul);
158 }
159
160 return;
161 trunc:
162 fputs(tstr, stdout);
163 }
164
165 /*
166 * The first character specifies the format to print:
167 * i - ip address (32 bits)
168 * p - ip address pairs (32 bits + 32 bits)
169 * l - long (32 bits)
170 * L - unsigned long (32 bits)
171 * s - short (16 bits)
172 * b - period-seperated decimal bytes (variable length)
173 * x - colon-seperated hex bytes (variable length)
174 * a - ascii string (variable length)
175 * B - on/off (8 bits)
176 * $ - special (explicit code to handle)
177 */
178 static struct tok tag2str[] = {
179 /* RFC1048 tags */
180 { TAG_PAD, " PAD" },
181 { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */
182 { TAG_TIME_OFFSET, "LTZ" }, /* seconds from UTC */
183 { TAG_GATEWAY, "iDG" }, /* default gateway */
184 { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */
185 { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */
186 { TAG_DOMAIN_SERVER, "iNS" }, /* domain name (RFC1035) */
187 { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */
188 { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */
189 { TAG_LPR_SERVER, "iLPR" }, /* lpr server (RFC1179) */
190 { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */
191 { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */
192 { TAG_HOSTNAME, "aHN" }, /* ascii hostname */
193 { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */
194 { TAG_END, " END" },
195 /* RFC1497 tags */
196 { TAG_DUMPPATH, "aDP" },
197 { TAG_DOMAINNAME, "aDN" },
198 { TAG_SWAP_SERVER, "iSS" },
199 { TAG_ROOTPATH, "aRP" },
200 { TAG_EXTPATH, "aEP" },
201 /* RFC2132 tags */
202 { TAG_IP_FORWARD, "BIPF" },
203 { TAG_NL_SRCRT, "BSRT" },
204 { TAG_PFILTERS, "pPF" },
205 { TAG_REASS_SIZE, "sRSZ" },
206 { TAG_DEF_TTL, "bTTL" },
207 { TAG_MTU_TIMEOUT, "lMA" },
208 { TAG_MTU_TABLE, "sMT" },
209 { TAG_INT_MTU, "sMTU" },
210 { TAG_LOCAL_SUBNETS, "BLSN" },
211 { TAG_BROAD_ADDR, "iBR" },
212 { TAG_DO_MASK_DISC, "BMD" },
213 { TAG_SUPPLY_MASK, "BMS" },
214 { TAG_DO_RDISC, "BRD" },
215 { TAG_RTR_SOL_ADDR, "iRSA" },
216 { TAG_STATIC_ROUTE, "pSR" },
217 { TAG_USE_TRAILERS, "BUT" },
218 { TAG_ARP_TIMEOUT, "lAT" },
219 { TAG_ETH_ENCAP, "BIE" },
220 { TAG_TCP_TTL, "bTT" },
221 { TAG_TCP_KEEPALIVE, "lKI" },
222 { TAG_KEEPALIVE_GO, "BKG" },
223 { TAG_NIS_DOMAIN, "aYD" },
224 { TAG_NIS_SERVERS, "iYS" },
225 { TAG_NTP_SERVERS, "iNTP" },
226 { TAG_VENDOR_OPTS, "bVO" },
227 { TAG_NETBIOS_NS, "iWNS" },
228 { TAG_NETBIOS_DDS, "iWDD" },
229 { TAG_NETBIOS_NODE, "$WNT" },
230 { TAG_NETBIOS_SCOPE, "aWSC" },
231 { TAG_XWIN_FS, "iXFS" },
232 { TAG_XWIN_DM, "iXDM" },
233 { TAG_NIS_P_DOMAIN, "sN+D" },
234 { TAG_NIS_P_SERVERS, "iN+S" },
235 { TAG_MOBILE_HOME, "iMH" },
236 { TAG_SMPT_SERVER, "iSMTP" },
237 { TAG_POP3_SERVER, "iPOP3" },
238 { TAG_NNTP_SERVER, "iNNTP" },
239 { TAG_WWW_SERVER, "iWWW" },
240 { TAG_FINGER_SERVER, "iFG" },
241 { TAG_IRC_SERVER, "iIRC" },
242 { TAG_STREETTALK_SRVR, "iSTS" },
243 { TAG_STREETTALK_STDA, "iSTDA" },
244 { TAG_REQUESTED_IP, "iRQ" },
245 { TAG_IP_LEASE, "lLT" },
246 { TAG_OPT_OVERLOAD, "$OO" },
247 { TAG_TFTP_SERVER, "aTFTP" },
248 { TAG_BOOTFILENAME, "aBF" },
249 { TAG_DHCP_MESSAGE, " DHCP" },
250 { TAG_SERVER_ID, "iSID" },
251 { TAG_PARM_REQUEST, "bPR" },
252 { TAG_MESSAGE, "aMSG" },
253 { TAG_MAX_MSG_SIZE, "sMSZ" },
254 { TAG_RENEWAL_TIME, "lRN" },
255 { TAG_REBIND_TIME, "lRB" },
256 { TAG_VENDOR_CLASS, "aVC" },
257 { TAG_CLIENT_ID, "$CID" },
258 /* RFC 2485 */
259 { TAG_OPEN_GROUP_UAP, "aUAP" },
260 /* RFC 2563 */
261 { TAG_DISABLE_AUTOCONF, "BNOAUTO" },
262 /* RFC 2610 */
263 { TAG_SLP_DA, "bSLP-DA" }, /*"b" is a little wrong */
264 { TAG_SLP_SCOPE, "bSLP-SCOPE" }, /*"b" is a little wrong */
265 /* RFC 2937 */
266 { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */
267 /* RFC 3011 */
268 { TAG_IP4_SUBNET_SELECT, "iSUBNET" },
269 /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */
270 { TAG_USER_CLASS, "aCLASS" },
271 { TAG_SLP_NAMING_AUTH, "aSLP-NA" },
272 { TAG_CLIENT_FQDN, "$FQDN" },
273 { TAG_AGENT_CIRCUIT, "bACKT" },
274 { TAG_AGENT_REMOTE, "bARMT" },
275 { TAG_AGENT_MASK, "bAMSK" },
276 { TAG_TZ_STRING, "aTZSTR" },
277 { TAG_FQDN_OPTION, "bFQDNS" }, /* XXX 'b' */
278 { TAG_AUTH, "bAUTH" }, /* XXX 'b' */
279 { TAG_VINES_SERVERS, "iVINES" },
280 { TAG_SERVER_RANK, "sRANK" },
281 { TAG_CLIENT_ARCH, "sARCH" },
282 { TAG_CLIENT_NDI, "bNDI" }, /* XXX 'b' */
283 { TAG_CLIENT_GUID, "bGUID" }, /* XXX 'b' */
284 { TAG_LDAP_URL, "aLDAP" },
285 { TAG_6OVER4, "i6o4" },
286 { TAG_PRINTER_NAME, "aPRTR" },
287 { TAG_MDHCP_SERVER, "bMDHCP" }, /* XXX 'b' */
288 { TAG_IPX_COMPAT, "bIPX" }, /* XXX 'b' */
289 { TAG_NETINFO_PARENT, "iNI" },
290 { TAG_NETINFO_PARENT_TAG, "aNITAG" },
291 { TAG_URL, "aURL" },
292 { TAG_FAILOVER, "bFAIL" }, /* XXX 'b' */
293 { 0, NULL }
294 };
295 /* 2-byte extended tags */
296 static struct tok xtag2str[] = {
297 { 0, NULL }
298 };
299
300 /* DHCP "options overload" types */
301 static struct tok oo2str[] = {
302 { 1, "file" },
303 { 2, "sname" },
304 { 3, "file+sname" },
305 { 0, NULL }
306 };
307
308 /* NETBIOS over TCP/IP node type options */
309 static struct tok nbo2str[] = {
310 { 0x1, "b-node" },
311 { 0x2, "p-node" },
312 { 0x4, "m-node" },
313 { 0x8, "h-node" },
314 { 0, NULL }
315 };
316
317 /* ARP Hardware types, for Client-ID option */
318 static struct tok arp2str[] = {
319 { 0x1, "ether" },
320 { 0x6, "ieee802" },
321 { 0x7, "arcnet" },
322 { 0xf, "frelay" },
323 { 0x17, "strip" },
324 { 0x18, "ieee1394" },
325 { 0, NULL }
326 };
327
328 static void
329 rfc1048_print(register const u_char *bp)
330 {
331 register u_int16_t tag;
332 register u_int len, size;
333 register const char *cp;
334 register char c;
335 int first;
336 u_int32_t ul;
337 u_int16_t us;
338 u_int8_t uc;
339
340 printf("\n\t Vendor-rfc1048:");
341
342 /* Step over magic cookie */
343 bp += sizeof(int32_t);
344
345 /* Loop while we there is a tag left in the buffer */
346 while (bp + 1 < snapend) {
347 tag = *bp++;
348 if (tag == TAG_PAD)
349 continue;
350 if (tag == TAG_END)
351 return;
352 if (tag == TAG_EXTENDED_OPTION) {
353 TCHECK2(*(bp + 1), 2);
354 tag = EXTRACT_16BITS(bp + 1);
355 /* XXX we don't know yet if the IANA will
356 * preclude overlap of 1-byte and 2-byte spaces.
357 * If not, we need to offset tag after this step.
358 */
359 cp = tok2str(xtag2str, "?xT%u", tag);
360 } else
361 cp = tok2str(tag2str, "?T%u", tag);
362 c = *cp++;
363 printf("\n\t %s:", cp);
364
365 /* Get the length; check for truncation */
366 if (bp + 1 >= snapend) {
367 fputs(tstr, stdout);
368 return;
369 }
370 len = *bp++;
371 if (bp + len >= snapend) {
372 printf("[|bootp %u]", len);
373 return;
374 }
375
376 if (tag == TAG_DHCP_MESSAGE && len == 1) {
377 uc = *bp++;
378 switch (uc) {
379 case DHCPDISCOVER: printf("DISCOVER"); break;
380 case DHCPOFFER: printf("OFFER"); break;
381 case DHCPREQUEST: printf("REQUEST"); break;
382 case DHCPDECLINE: printf("DECLINE"); break;
383 case DHCPACK: printf("ACK"); break;
384 case DHCPNAK: printf("NACK"); break;
385 case DHCPRELEASE: printf("RELEASE"); break;
386 case DHCPINFORM: printf("INFORM"); break;
387 default: printf("%u", uc); break;
388 }
389 continue;
390 }
391
392 if (tag == TAG_PARM_REQUEST) {
393 first = 1;
394 while (len-- > 0) {
395 uc = *bp++;
396 cp = tok2str(tag2str, "?T%u", uc);
397 if (!first)
398 putchar('+');
399 printf("%s", cp + 1);
400 first = 0;
401 }
402 continue;
403 }
404 if (tag == TAG_EXTENDED_REQUEST) {
405 first = 1;
406 while (len > 1) {
407 len -= 2;
408 us = EXTRACT_16BITS(bp);
409 bp += 2;
410 cp = tok2str(xtag2str, "?xT%u", us);
411 if (!first)
412 putchar('+');
413 printf("%s", cp + 1);
414 first = 0;
415 }
416 continue;
417 }
418
419 /* Print data */
420 size = len;
421 if (c == '?') {
422 /* Base default formats for unknown tags on data size */
423 if (size & 1)
424 c = 'b';
425 else if (size & 2)
426 c = 's';
427 else
428 c = 'l';
429 }
430 first = 1;
431 switch (c) {
432
433 case 'a':
434 /* ascii strings */
435 putchar('"');
436 (void)fn_printn(bp, size, NULL);
437 putchar('"');
438 bp += size;
439 size = 0;
440 break;
441
442 case 'i':
443 case 'l':
444 case 'L':
445 /* ip addresses/32-bit words */
446 while (size >= sizeof(ul)) {
447 if (!first)
448 putchar(',');
449 ul = EXTRACT_32BITS(bp);
450 if (c == 'i') {
451 ul = htonl(ul);
452 printf("%s", ipaddr_string(&ul));
453 } else if (c == 'L')
454 printf("%d", ul);
455 else
456 printf("%u", ul);
457 bp += sizeof(ul);
458 size -= sizeof(ul);
459 first = 0;
460 }
461 break;
462
463 case 'p':
464 /* IP address pairs */
465 while (size >= 2*sizeof(ul)) {
466 if (!first)
467 putchar(',');
468 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
469 printf("(%s:", ipaddr_string(&ul));
470 bp += sizeof(ul);
471 memcpy((char *)&ul, (const char *)bp, sizeof(ul));
472 printf("%s)", ipaddr_string(&ul));
473 bp += sizeof(ul);
474 size -= 2*sizeof(ul);
475 first = 0;
476 }
477 break;
478
479 case 's':
480 /* shorts */
481 while (size >= sizeof(us)) {
482 if (!first)
483 putchar(',');
484 us = EXTRACT_16BITS(bp);
485 printf("%u", us);
486 bp += sizeof(us);
487 size -= sizeof(us);
488 first = 0;
489 }
490 break;
491
492 case 'B':
493 /* boolean */
494 while (size > 0) {
495 if (!first)
496 putchar(',');
497 switch (*bp) {
498 case 0:
499 putchar('N');
500 break;
501 case 1:
502 putchar('Y');
503 break;
504 default:
505 printf("%u?", *bp);
506 break;
507 }
508 ++bp;
509 --size;
510 first = 0;
511 }
512 break;
513
514 case 'b':
515 case 'x':
516 default:
517 /* Bytes */
518 while (size > 0) {
519 if (!first)
520 putchar(c == 'x' ? ':' : '.');
521 if (c == 'x')
522 printf("%02x", *bp);
523 else
524 printf("%u", *bp);
525 ++bp;
526 --size;
527 first = 0;
528 }
529 break;
530
531 case '$':
532 /* Guys we can't handle with one of the usual cases */
533 switch (tag) {
534
535 case TAG_NETBIOS_NODE:
536 tag = *bp++;
537 --size;
538 fputs(tok2str(nbo2str, NULL, tag), stdout);
539 break;
540
541 case TAG_OPT_OVERLOAD:
542 tag = *bp++;
543 --size;
544 fputs(tok2str(oo2str, NULL, tag), stdout);
545 break;
546
547 case TAG_CLIENT_FQDN:
548 if (*bp++)
549 printf("[svrreg]");
550 if (*bp)
551 printf("%u/%u/", *bp, *(bp+1));
552 bp += 2;
553 putchar('"');
554 (void)fn_printn(bp, size - 3, NULL);
555 putchar('"');
556 bp += size - 3;
557 size = 0;
558 break;
559
560 case TAG_CLIENT_ID:
561 { int type = *bp++;
562 size--;
563 if (type == 0) {
564 putchar('"');
565 (void)fn_printn(bp, size, NULL);
566 putchar('"');
567 bp += size;
568 size = 0;
569 break;
570 } else {
571 printf("[%s]", tok2str(arp2str, "type-%d", type));
572 }
573 while (size > 0) {
574 if (!first)
575 putchar(':');
576 printf("%02x", *bp);
577 ++bp;
578 --size;
579 first = 0;
580 }
581 break;
582 }
583
584 default:
585 printf("[unknown special tag %u, size %u]",
586 tag, size);
587 bp += size;
588 size = 0;
589 break;
590 }
591 break;
592 }
593 /* Data left over? */
594 if (size) {
595 printf("[len %u]", len);
596 bp += size;
597 }
598 }
599 return;
600 trunc:
601 printf("|[rfc1048]");
602 }
603
604 static void
605 cmu_print(register const u_char *bp)
606 {
607 register const struct cmu_vend *cmu;
608
609 #define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \
610 if (cmu->m.s_addr != 0) \
611 printf(" %s:%s", s, ipaddr_string(&cmu->m.s_addr)); }
612
613 printf(" vend-cmu");
614 cmu = (const struct cmu_vend *)bp;
615
616 /* Only print if there are unknown bits */
617 TCHECK(cmu->v_flags);
618 if ((cmu->v_flags & ~(VF_SMASK)) != 0)
619 printf(" F:0x%x", cmu->v_flags);
620 PRINTCMUADDR(v_dgate, "DG");
621 PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*");
622 PRINTCMUADDR(v_dns1, "NS1");
623 PRINTCMUADDR(v_dns2, "NS2");
624 PRINTCMUADDR(v_ins1, "IEN1");
625 PRINTCMUADDR(v_ins2, "IEN2");
626 PRINTCMUADDR(v_ts1, "TS1");
627 PRINTCMUADDR(v_ts2, "TS2");
628 return;
629
630 trunc:
631 fputs(tstr, stdout);
632 #undef PRINTCMUADDR
633 }