X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/860edc72fde4104f1abc8779bd3397a17859b6c8..47fc89d711eec0a073d9b3b293a1af901b5bd791:/print-babel.c diff --git a/print-babel.c b/print-babel.c index 58faca15..4f128b32 100644 --- a/print-babel.c +++ b/print-babel.c @@ -39,6 +39,8 @@ #include "interface.h" #include "extract.h" +static const char tstr[] = "[|babel]"; + static void babel_print_v2(const u_char *cp, u_int length); void @@ -66,7 +68,7 @@ babel_print(const u_char *cp, u_int length) { return; trunc: - printf(" [|babel]"); + printf(" %s", tstr); return; } @@ -88,10 +90,10 @@ babel_print(const u_char *cp, u_int length) { /* sub-TLVs */ #define MESSAGE_SUB_PAD1 0 #define MESSAGE_SUB_PADN 1 -#define MESSAGE_SUB_CHANINFO 2 +#define MESSAGE_SUB_DIVERSITY 2 -/* ChanInfo sub-TLV channel codes */ -static const struct tok chaninfo_str[] = { +/* Diversity sub-TLV channel codes */ +static const struct tok diversity_str[] = { { 0, "reserved" }, { 255, "all" }, { 0, NULL } @@ -139,6 +141,23 @@ format_address(const u_char *prefix) #endif } +static const char * +format_interval(const u_int16_t i) +{ + static char buf[sizeof("0000.0s")]; + + if (i == 0) + return "0.0s (bogus)"; + snprintf(buf, sizeof(buf), "%u.%us", i / 10, i % 10); + return buf; +} + +static const char * +format_interval_update(const u_int16_t i) +{ + return i == 0xFFFF ? "infinity" : format_interval(i); +} + /* Return number of octets consumed from the input buffer (not the prefix length * in bytes), or -1 for encoding error. */ static int @@ -220,7 +239,7 @@ network_address(int ae, const unsigned char *a, unsigned int len, * * o Type 0 stands for Pad1 sub-TLV with the same encoding as the Pad1 TLV. * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV. - * o Type 2 stands for ChanInfo sub-TLV, which propagates diversity routing + * o Type 2 stands for Diversity sub-TLV, which propagates diversity routing * data. Its body is a variable-length sequence of 8-bit unsigned integers, * each representing per-hop number of interferring radio channel for the * prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel @@ -228,7 +247,7 @@ network_address(int ae, const unsigned char *a, unsigned int len, * * Sub-TLV types 0 and 1 are valid for any TLV type, whether sub-TLV type 2 is * only valid for TLV type 8 (Update). Note that within an Update TLV a missing - * ChanInfo sub-TLV is not the same as a ChanInfo sub-TLV with an empty body. + * Diversity sub-TLV is not the same as a Diversity sub-TLV with an empty body. * The former would mean a lack of any claims about the interference, and the * latter would state that interference is definitely absent. */ static void @@ -253,15 +272,15 @@ subtlvs_print(const u_char *cp, const u_char *ep, const uint8_t tlv_type) { printf(" sub-padn"); cp += sublen; break; - case MESSAGE_SUB_CHANINFO: - printf(" sub-chaninfo"); + case MESSAGE_SUB_DIVERSITY: + printf(" sub-diversity"); if (sublen == 0) { printf(" empty"); break; } sep = " "; while(sublen--) { - printf("%s%s", sep, tok2str(chaninfo_str, "%u", *cp++)); + printf("%s%s", sep, tok2str(diversity_str, "%u", *cp++)); sep = "-"; } if(tlv_type != MESSAGE_UPDATE) @@ -335,7 +354,7 @@ babel_print_v2(const u_char *cp, u_int length) { if(len < 6) goto corrupt; nonce = EXTRACT_16BITS(message + 4); interval = EXTRACT_16BITS(message + 6); - printf("%04x %d", nonce, interval); + printf("%04x %s", nonce, format_interval(interval)); } } break; @@ -362,7 +381,7 @@ babel_print_v2(const u_char *cp, u_int length) { if(len < 6) goto corrupt; seqno = EXTRACT_16BITS(message + 4); interval = EXTRACT_16BITS(message + 6); - printf("seqno %u interval %u", seqno, interval); + printf("seqno %u interval %s", seqno, format_interval(interval)); } } break; @@ -379,9 +398,9 @@ babel_print_v2(const u_char *cp, u_int length) { txcost = EXTRACT_16BITS(message + 4); interval = EXTRACT_16BITS(message + 6); rc = network_address(message[2], message + 8, len - 6, address); - if(rc < 0) { printf("[|babel]"); break; } - printf("%s txcost %u interval %d", - format_address(address), txcost, interval); + if(rc < 0) { printf("%s", tstr); break; } + printf("%s txcost %u interval %s", + format_address(address), txcost, format_interval(interval)); } } break; @@ -438,12 +457,12 @@ babel_print_v2(const u_char *cp, u_int length) { interval = EXTRACT_16BITS(message + 6); seqno = EXTRACT_16BITS(message + 8); metric = EXTRACT_16BITS(message + 10); - printf("%s%s%s %s metric %u seqno %u interval %u", + printf("%s%s%s %s metric %u seqno %u interval %s", (message[3] & 0x80) ? "/prefix": "", (message[3] & 0x40) ? "/id" : "", (message[3] & 0x3f) ? "/unknown" : "", format_prefix(prefix, plen), - metric, seqno, interval); + metric, seqno, format_interval_update(interval)); if(message[3] & 0x80) { if(message[2] == 1) memcpy(v4_prefix, prefix, 16); @@ -451,7 +470,7 @@ babel_print_v2(const u_char *cp, u_int length) { memcpy(v6_prefix, prefix, 16); } /* extra data? */ - if(rc < len - 10) + if((u_int)rc < len - 10) subtlvs_print(message + 12 + rc, message + 2 + len, type); } } @@ -530,7 +549,7 @@ babel_print_v2(const u_char *cp, u_int length) { return; trunc: - printf(" [|babel]"); + printf(" %s", tstr); return; corrupt: