X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ac3e9eddebf49c7ce1ab7323a9cced1ad6ac6a4b..ad7a38341c19e71e3595c17368ac18f08b71482d:/print-bootp.c diff --git a/print-bootp.c b/print-bootp.c index b92a6550..c4601567 100644 --- a/print-bootp.c +++ b/print-bootp.c @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.83 2007-01-14 21:29:22 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-bootp.c,v 1.89 2008-04-22 09:45:08 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -40,10 +40,11 @@ static const char rcsid[] _U_ = #include "ether.h" #include "bootp.h" +static const char tstr[] = " [|bootp]"; + static void rfc1048_print(const u_char *); static void cmu_print(const u_char *); - -static char tstr[] = " [|bootp]"; +static char *client_fqdn_flags(u_int flags); static const struct tok bootp_flag_values[] = { { 0x8000, "Broadcast" }, @@ -100,10 +101,10 @@ bootp_print(register const u_char *cp, u_int length) if (bp->bp_secs) printf(", secs %d", EXTRACT_16BITS(&bp->bp_secs)); - printf(", Flags [ %s ]", - bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))); - if (vflag>1) - printf( " (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)); + printf(", Flags [%s]", + bittok2str(bootp_flag_values, "none", EXTRACT_16BITS(&bp->bp_flags))); + if (vflag > 1) + printf(" (0x%04x)", EXTRACT_16BITS(&bp->bp_flags)); /* Client's ip address */ TCHECK(bp->bp_ciaddr); @@ -186,7 +187,7 @@ trunc: * B - on/off (8 bits) * $ - special (explicit code to handle) */ -static struct tok tag2str[] = { +static const struct tok tag2str[] = { /* RFC1048 tags */ { TAG_PAD, " PAD" }, { TAG_SUBNET_MASK, "iSubnet-Mask" }, /* subnet mask (RFC950) */ @@ -277,6 +278,9 @@ static struct tok tag2str[] = { { TAG_NS_SEARCH, "sNSSEARCH" }, /* XXX 's' */ /* RFC 3011 */ { TAG_IP4_SUBNET_SELECT, "iSUBNET" }, +/* RFC 3442 */ + { TAG_CLASSLESS_STATIC_RT, "$Classless-Static-Route" }, + { TAG_CLASSLESS_STA_RT_MS, "$Classless-Static-Route-Microsoft" }, /* http://www.iana.org/assignments/bootp-dhcp-extensions/index.htm */ { TAG_USER_CLASS, "aCLASS" }, { TAG_SLP_NAMING_AUTH, "aSLP-NA" }, @@ -304,12 +308,12 @@ static struct tok tag2str[] = { { 0, NULL } }; /* 2-byte extended tags */ -static struct tok xtag2str[] = { +static const struct tok xtag2str[] = { { 0, NULL } }; /* DHCP "options overload" types */ -static struct tok oo2str[] = { +static const struct tok oo2str[] = { { 1, "file" }, { 2, "sname" }, { 3, "file+sname" }, @@ -317,7 +321,7 @@ static struct tok oo2str[] = { }; /* NETBIOS over TCP/IP node type options */ -static struct tok nbo2str[] = { +static const struct tok nbo2str[] = { { 0x1, "b-node" }, { 0x2, "p-node" }, { 0x4, "m-node" }, @@ -326,7 +330,7 @@ static struct tok nbo2str[] = { }; /* ARP Hardware types, for Client-ID option */ -static struct tok arp2str[] = { +static const struct tok arp2str[] = { { 0x1, "ether" }, { 0x6, "ieee802" }, { 0x7, "arcnet" }, @@ -336,7 +340,7 @@ static struct tok arp2str[] = { { 0, NULL } }; -static struct tok dhcp_msg_values[] = { +static const struct tok dhcp_msg_values[] = { { DHCPDISCOVER, "Discover" }, { DHCPOFFER, "Offer" }, { DHCPREQUEST, "Request" }, @@ -348,9 +352,13 @@ static struct tok dhcp_msg_values[] = { { 0, NULL } }; -#define AGENT_SUBOPTION_CIRCUIT_ID 1 -static struct tok agent_suboption_values[] = { +#define AGENT_SUBOPTION_CIRCUIT_ID 1 /* RFC 3046 */ +#define AGENT_SUBOPTION_REMOTE_ID 2 /* RFC 3046 */ +#define AGENT_SUBOPTION_SUBSCRIBER_ID 6 /* RFC 3993 */ +static const struct tok agent_suboption_values[] = { { AGENT_SUBOPTION_CIRCUIT_ID, "Circuit-ID" }, + { AGENT_SUBOPTION_REMOTE_ID, "Remote-ID" }, + { AGENT_SUBOPTION_SUBSCRIBER_ID, "Subscriber-ID" }, { 0, NULL } }; @@ -359,7 +367,7 @@ static void rfc1048_print(register const u_char *bp) { register u_int16_t tag; - register u_int len, size; + register u_int len; register const char *cp; register char c; int first, idx; @@ -455,12 +463,11 @@ rfc1048_print(register const u_char *bp) } /* Print data */ - size = len; if (c == '?') { /* Base default formats for unknown tags on data size */ - if (size & 1) + if (len & 1) c = 'b'; - else if (size & 2) + else if (len & 2) c = 's'; else c = 'l'; @@ -471,20 +478,20 @@ rfc1048_print(register const u_char *bp) case 'a': /* ascii strings */ putchar('"'); - if (fn_printn(bp, size, snapend)) { + if (fn_printn(bp, len, snapend)) { putchar('"'); goto trunc; } putchar('"'); - bp += size; - size = 0; + bp += len; + len = 0; break; case 'i': case 'l': case 'L': /* ip addresses/32-bit words */ - while (size >= sizeof(ul)) { + while (len >= sizeof(ul)) { if (!first) putchar(','); ul = EXTRACT_32BITS(bp); @@ -496,14 +503,14 @@ rfc1048_print(register const u_char *bp) else printf("%u", ul); bp += sizeof(ul); - size -= sizeof(ul); + len -= sizeof(ul); first = 0; } break; case 'p': /* IP address pairs */ - while (size >= 2*sizeof(ul)) { + while (len >= 2*sizeof(ul)) { if (!first) putchar(','); memcpy((char *)&ul, (const char *)bp, sizeof(ul)); @@ -512,27 +519,27 @@ rfc1048_print(register const u_char *bp) memcpy((char *)&ul, (const char *)bp, sizeof(ul)); printf("%s)", ipaddr_string(&ul)); bp += sizeof(ul); - size -= 2*sizeof(ul); + len -= 2*sizeof(ul); first = 0; } break; case 's': /* shorts */ - while (size >= sizeof(us)) { + while (len >= sizeof(us)) { if (!first) putchar(','); us = EXTRACT_16BITS(bp); printf("%u", us); bp += sizeof(us); - size -= sizeof(us); + len -= sizeof(us); first = 0; } break; case 'B': /* boolean */ - while (size > 0) { + while (len > 0) { if (!first) putchar(','); switch (*bp) { @@ -547,7 +554,7 @@ rfc1048_print(register const u_char *bp) break; } ++bp; - --size; + --len; first = 0; } break; @@ -556,7 +563,7 @@ rfc1048_print(register const u_char *bp) case 'x': default: /* Bytes */ - while (size > 0) { + while (len > 0) { if (!first) putchar(c == 'x' ? ':' : '.'); if (c == 'x') @@ -564,7 +571,7 @@ rfc1048_print(register const u_char *bp) else printf("%u", *bp); ++bp; - --size; + --len; first = 0; } break; @@ -574,109 +581,192 @@ rfc1048_print(register const u_char *bp) switch (tag) { case TAG_NETBIOS_NODE: + /* this option should be at least 1 byte long */ + if (len < 1) { + printf("ERROR: option %u len %u < 1 bytes", + TAG_NETBIOS_NODE, len); + break; + } tag = *bp++; - --size; + --len; fputs(tok2str(nbo2str, NULL, tag), stdout); break; case TAG_OPT_OVERLOAD: + /* this option should be at least 1 byte long */ + if (len < 1) { + printf("ERROR: option %u len %u < 1 bytes", + TAG_OPT_OVERLOAD, len); + break; + } tag = *bp++; - --size; + --len; fputs(tok2str(oo2str, NULL, tag), stdout); break; case TAG_CLIENT_FQDN: - /* option 81 should be at least 4 bytes long */ - if (len < 4) { - printf("ERROR: options 81 len %u < 4 bytes", len); + /* this option should be at least 3 bytes long */ + if (len < 3) { + printf("ERROR: option %u len %u < 3 bytes", + TAG_CLIENT_FQDN, len); + bp += len; + len = 0; break; } - if (*bp++) - printf("[svrreg]"); if (*bp) - printf("%u/%u/", *bp, *(bp+1)); + printf("[%s] ", client_fqdn_flags(*bp)); + bp++; + if (*bp || *(bp+1)) + printf("%u/%u ", *bp, *(bp+1)); bp += 2; putchar('"'); - if (fn_printn(bp, size - 3, snapend)) { + if (fn_printn(bp, len - 3, snapend)) { putchar('"'); goto trunc; } putchar('"'); - bp += size - 3; - size = 0; + bp += len - 3; + len = 0; break; case TAG_CLIENT_ID: - { int type = *bp++; - size--; + { int type; + + /* this option should be at least 1 byte long */ + if (len < 1) { + printf("ERROR: option %u len %u < 1 bytes", + TAG_CLIENT_ID, len); + break; + } + type = *bp++; + len--; if (type == 0) { putchar('"'); - if (fn_printn(bp, size, snapend)) { + if (fn_printn(bp, len, snapend)) { putchar('"'); goto trunc; } putchar('"'); - bp += size; - size = 0; + bp += len; + len = 0; break; } else { printf("%s ", tok2str(arp2str, "hardware-type %u,", type)); - } - while (size > 0) { - if (!first) - putchar(':'); - printf("%02x", *bp); - ++bp; - --size; - first = 0; + while (len > 0) { + if (!first) + putchar(':'); + printf("%02x", *bp); + ++bp; + --len; + first = 0; + } } break; } - case TAG_AGENT_CIRCUIT: - { - while (size > 0 ) { - subopt = *bp++; - suboptlen = *bp++; - size -= 2; - printf("\n\t %s SubOption %u, length %u: ", - tok2str(agent_suboption_values, "Unknown", subopt), - subopt, - suboptlen); - - if (subopt == 0 || suboptlen == 0) { - break; - } - - switch(subopt) { - case AGENT_SUBOPTION_CIRCUIT_ID: - for (idx = 0; idx < suboptlen; idx++) { - safeputchar(*(bp+idx)); - } - break; - default: - print_unknown_data(bp, "\n\t\t", suboptlen); - } - - size -= suboptlen; - bp += suboptlen; - } - } - break; + case TAG_AGENT_CIRCUIT: + while (len >= 2) { + subopt = *bp++; + suboptlen = *bp++; + len -= 2; + if (suboptlen > len) { + printf("\n\t %s SubOption %u, length %u: length goes past end of option", + tok2str(agent_suboption_values, "Unknown", subopt), + subopt, + suboptlen); + bp += len; + len = 0; + break; + } + printf("\n\t %s SubOption %u, length %u: ", + tok2str(agent_suboption_values, "Unknown", subopt), + subopt, + suboptlen); + switch (subopt) { + + case AGENT_SUBOPTION_CIRCUIT_ID: /* fall through */ + case AGENT_SUBOPTION_REMOTE_ID: + case AGENT_SUBOPTION_SUBSCRIBER_ID: + fn_printn(bp, suboptlen, NULL); + break; + + default: + print_unknown_data(gndo,bp, "\n\t\t", suboptlen); + } + + len -= suboptlen; + bp += suboptlen; + } + break; + + case TAG_CLASSLESS_STATIC_RT: + case TAG_CLASSLESS_STA_RT_MS: + { + u_int mask_width, significant_octets, i; + + /* this option should be at least 5 bytes long */ + if (len < 5) { + printf("ERROR: option %u len %u < 5 bytes", + TAG_CLASSLESS_STATIC_RT, len); + bp += len; + len = 0; + break; + } + while (len > 0) { + if (!first) + putchar(','); + mask_width = *bp++; + len--; + /* mask_width <= 32 */ + if (mask_width > 32) { + printf("[ERROR: Mask width (%d) > 32]", mask_width); + bp += len; + len = 0; + break; + } + significant_octets = (mask_width + 7) / 8; + /* significant octets + router(4) */ + if (len < significant_octets + 4) { + printf("[ERROR: Remaining length (%u) < %u bytes]", len, significant_octets + 4); + bp += len; + len = 0; + break; + } + putchar('('); + if (mask_width == 0) + printf("default"); + else { + for (i = 0; i < significant_octets ; i++) { + if (i > 0) + putchar('.'); + printf("%d", *bp++); + } + for (i = significant_octets ; i < 4 ; i++) + printf(".0"); + printf("/%d", mask_width); + } + memcpy((char *)&ul, (const char *)bp, sizeof(ul)); + printf(":%s)", ipaddr_string(&ul)); + bp += sizeof(ul); + len -= (significant_octets + 4); + first = 0; + } + } + break; default: printf("[unknown special tag %u, size %u]", - tag, size); - bp += size; - size = 0; + tag, len); + bp += len; + len = 0; break; } break; } /* Data left over? */ - if (size) { + if (len) { printf("\n\t trailing data length %u", len); - bp += size; + bp += len; } } return; @@ -714,3 +804,22 @@ trunc: fputs(tstr, stdout); #undef PRINTCMUADDR } + +static char * +client_fqdn_flags(u_int flags) +{ + static char buf[8+1]; + int i = 0; + + if (flags & CLIENT_FQDN_FLAGS_S) + buf[i++] = 'S'; + if (flags & CLIENT_FQDN_FLAGS_O) + buf[i++] = 'O'; + if (flags & CLIENT_FQDN_FLAGS_E) + buf[i++] = 'E'; + if (flags & CLIENT_FQDN_FLAGS_N) + buf[i++] = 'N'; + buf[i] = '\0'; + + return buf; +}