X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/546558eabd81cfc36a81a4df728fdfea0d83b41a..41ef9cfe38f86553ffd8f61b6f87e9c00baf5f07:/print-babel.c diff --git a/print-babel.c b/print-babel.c index 9f2ecf10..5f1d90f0 100644 --- a/print-babel.c +++ b/print-babel.c @@ -41,7 +41,6 @@ #include "addrtoname.h" #include "extract.h" -static const char tstr[] = "[|babel]"; static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length); @@ -54,14 +53,14 @@ babel_print(netdissect_options *ndo, ND_TCHECK_4(cp); - if(EXTRACT_U_1(cp) != 42) { + if(GET_U_1(cp) != 42) { ND_PRINT(" invalid header"); return; } else { - ND_PRINT(" %u", EXTRACT_U_1(cp + 1)); + ND_PRINT(" %u", GET_U_1(cp + 1)); } - switch(EXTRACT_U_1(cp + 1)) { + switch(GET_U_1(cp + 1)) { case 2: babel_print_v2(ndo, cp, length); break; @@ -73,7 +72,7 @@ babel_print(netdissect_options *ndo, return; trunc: - ND_PRINT(" %s", tstr); + nd_print_trunc(ndo); return; } @@ -109,13 +108,13 @@ static const struct tok diversity_str[] = { }; static const char * -format_id(const u_char *id) +format_id(netdissect_options *ndo, const u_char *id) { static char buf[25]; - nd_snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", - EXTRACT_U_1(id), EXTRACT_U_1(id + 1), EXTRACT_U_1(id + 2), - EXTRACT_U_1(id + 3), EXTRACT_U_1(id + 4), EXTRACT_U_1(id + 5), - EXTRACT_U_1(id + 6), EXTRACT_U_1(id + 7)); + snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + GET_U_1(id), GET_U_1(id + 1), GET_U_1(id + 2), + GET_U_1(id + 3), GET_U_1(id + 4), GET_U_1(id + 5), + GET_U_1(id + 6), GET_U_1(id + 7)); buf[24] = '\0'; return buf; } @@ -128,9 +127,9 @@ format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen) { static char buf[50]; if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0) - nd_snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); + snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); else - nd_snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); + snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); buf[49] = '\0'; return buf; } @@ -151,7 +150,7 @@ format_interval(const uint16_t i) if (i == 0) return "0.0s (bogus)"; - nd_snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); + snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); return buf; } @@ -165,7 +164,7 @@ static const char * format_timestamp(const uint32_t i) { static char buf[sizeof("0000.000000s")]; - nd_snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); + snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); return buf; } @@ -252,7 +251,7 @@ network_address(int ae, const unsigned char *a, unsigned int len, * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV. * 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 + * each representing per-hop number of interfering radio channel for the * prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel * 255 interferes with any other channel. * o Type 3 stands for Timestamp sub-TLV, used to compute RTT between @@ -277,7 +276,7 @@ subtlvs_print(netdissect_options *ndo, uint32_t t1, t2; while (cp < ep) { - subtype = EXTRACT_U_1(cp); + subtype = GET_U_1(cp); cp++; if(subtype == MESSAGE_SUB_PAD1) { ND_PRINT(" sub-pad1"); @@ -285,7 +284,7 @@ subtlvs_print(netdissect_options *ndo, } if(cp == ep) goto invalid; - sublen = EXTRACT_U_1(cp); + sublen = GET_U_1(cp); cp++; if(cp + sublen > ep) goto invalid; @@ -302,10 +301,12 @@ subtlvs_print(netdissect_options *ndo, break; } sep = " "; - while(sublen--) { - ND_PRINT("%s%s", sep, tok2str(diversity_str, "%u", EXTRACT_U_1(cp))); + while (sublen) { + ND_PRINT("%s%s", sep, + tok2str(diversity_str, "%u", GET_U_1(cp))); cp++; sep = "-"; + sublen--; } if(tlv_type != MESSAGE_UPDATE && tlv_type != MESSAGE_UPDATE_SRC_SPECIFIC) @@ -316,14 +317,14 @@ subtlvs_print(netdissect_options *ndo, if(tlv_type == MESSAGE_HELLO) { if(sublen < 4) goto invalid; - t1 = EXTRACT_BE_U_4(cp); + t1 = GET_BE_U_4(cp); ND_PRINT(" %s", format_timestamp(t1)); } else if(tlv_type == MESSAGE_IHU) { if(sublen < 8) goto invalid; - t1 = EXTRACT_BE_U_4(cp); + t1 = GET_BE_U_4(cp); ND_PRINT(" %s", format_timestamp(t1)); - t2 = EXTRACT_BE_U_4(cp + 4); + t2 = GET_BE_U_4(cp + 4); ND_PRINT("|%s", format_timestamp(t2)); } else ND_PRINT(" (bogus)"); @@ -337,7 +338,7 @@ subtlvs_print(netdissect_options *ndo, return; invalid: - ND_PRINT("%s", istr); + nd_print_invalid(ndo); } #define ICHECK(i, l) \ @@ -356,19 +357,20 @@ babel_print_v2(netdissect_options *ndo, ND_TCHECK_4(cp); if (length < 4) goto invalid; - bodylen = EXTRACT_BE_U_2(cp + 2); + bodylen = GET_BE_U_2(cp + 2); ND_PRINT(" (%u)", bodylen); /* Process the TLVs in the body */ i = 0; while(i < bodylen) { const u_char *message; - u_int type, len; + uint8_t type; + u_int len; message = cp + 4 + i; ND_TCHECK_1(message); - if((type = EXTRACT_U_1(message)) == MESSAGE_PAD1) { + if((type = GET_U_1(message)) == MESSAGE_PAD1) { ND_PRINT(ndo->ndo_vflag ? "\n\tPad 1" : " pad1"); i += 1; continue; @@ -376,7 +378,7 @@ babel_print_v2(netdissect_options *ndo, ND_TCHECK_2(message); ICHECK(i, 2); - len = EXTRACT_U_1(message + 1); + len = GET_U_1(message + 1); ND_TCHECK_LEN(message, 2 + len); ICHECK(i, 2 + len); @@ -397,8 +399,8 @@ babel_print_v2(netdissect_options *ndo, else { ND_PRINT("\n\tAcknowledgment Request "); if(len < 6) goto invalid; - nonce = EXTRACT_BE_U_2(message + 4); - interval = EXTRACT_BE_U_2(message + 6); + nonce = GET_BE_U_2(message + 4); + interval = GET_BE_U_2(message + 6); ND_PRINT("%04x %s", nonce, format_interval(interval)); } } @@ -411,7 +413,7 @@ babel_print_v2(netdissect_options *ndo, else { ND_PRINT("\n\tAcknowledgment "); if(len < 2) goto invalid; - nonce = EXTRACT_BE_U_2(message + 2); + nonce = GET_BE_U_2(message + 2); ND_PRINT("%04x", nonce); } } @@ -424,8 +426,8 @@ babel_print_v2(netdissect_options *ndo, else { ND_PRINT("\n\tHello "); if(len < 6) goto invalid; - seqno = EXTRACT_BE_U_2(message + 4); - interval = EXTRACT_BE_U_2(message + 6); + seqno = GET_BE_U_2(message + 4); + interval = GET_BE_U_2(message + 6); ND_PRINT("seqno %u interval %s", seqno, format_interval(interval)); /* Extra data. */ if(len > 6) @@ -444,12 +446,12 @@ babel_print_v2(netdissect_options *ndo, int rc; ND_PRINT("\n\tIHU "); if(len < 6) goto invalid; - rxcost = EXTRACT_BE_U_2(message + 4); - interval = EXTRACT_BE_U_2(message + 6); - ae = EXTRACT_U_1(message + 2); + rxcost = GET_BE_U_2(message + 4); + interval = GET_BE_U_2(message + 6); + ae = GET_U_1(message + 2); rc = network_address(ae, message + 8, len - 6, address); - if(rc < 0) { ND_PRINT("%s", tstr); break; } + if(rc < 0) { nd_print_trunc(ndo); break; } ND_PRINT("%s rxcost %u interval %s", ae == 0 ? "any" : format_address(ndo, address), rxcost, format_interval(interval)); @@ -467,7 +469,7 @@ babel_print_v2(netdissect_options *ndo, else { ND_PRINT("\n\tRouter Id"); if(len < 10) goto invalid; - ND_PRINT(" %s", format_id(message + 4)); + ND_PRINT(" %s", format_id(ndo, message + 4)); } } break; @@ -481,7 +483,7 @@ babel_print_v2(netdissect_options *ndo, u_char nh[16]; ND_PRINT("\n\tNext Hop"); if(len < 2) goto invalid; - ae = EXTRACT_U_1(message + 2); + ae = GET_U_1(message + 2); rc = network_address(ae, message + 4, len - 2, nh); if(rc < 0) goto invalid; @@ -497,9 +499,9 @@ babel_print_v2(netdissect_options *ndo, ND_PRINT("/truncated"); else ND_PRINT("%s%s%s", - (EXTRACT_U_1(message + 3) & 0x80) ? "/prefix": "", - (EXTRACT_U_1(message + 3) & 0x40) ? "/id" : "", - (EXTRACT_U_1(message + 3) & 0x3f) ? "/unknown" : ""); + (GET_U_1(message + 3) & 0x80) ? "/prefix": "", + (GET_U_1(message + 3) & 0x40) ? "/id" : "", + (GET_U_1(message + 3) & 0x3f) ? "/unknown" : ""); } else { u_short interval, seqno, metric; u_char ae, plen; @@ -507,26 +509,26 @@ babel_print_v2(netdissect_options *ndo, u_char prefix[16]; ND_PRINT("\n\tUpdate"); if(len < 10) goto invalid; - ae = EXTRACT_U_1(message + 2); - plen = EXTRACT_U_1(message + 4) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0); + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 4) + (GET_U_1(message + 2) == 1 ? 96 : 0); rc = network_prefix(ae, - EXTRACT_U_1(message + 4), - EXTRACT_U_1(message + 5), + GET_U_1(message + 4), + GET_U_1(message + 5), message + 12, - EXTRACT_U_1(message + 2) == 1 ? v4_prefix : v6_prefix, + GET_U_1(message + 2) == 1 ? v4_prefix : v6_prefix, len - 10, prefix); if(rc < 0) goto invalid; - interval = EXTRACT_BE_U_2(message + 6); - seqno = EXTRACT_BE_U_2(message + 8); - metric = EXTRACT_BE_U_2(message + 10); + interval = GET_BE_U_2(message + 6); + seqno = GET_BE_U_2(message + 8); + metric = GET_BE_U_2(message + 10); ND_PRINT("%s%s%s %s metric %u seqno %u interval %s", - (EXTRACT_U_1(message + 3) & 0x80) ? "/prefix": "", - (EXTRACT_U_1(message + 3) & 0x40) ? "/id" : "", - (EXTRACT_U_1(message + 3) & 0x3f) ? "/unknown" : "", + (GET_U_1(message + 3) & 0x80) ? "/prefix": "", + (GET_U_1(message + 3) & 0x40) ? "/id" : "", + (GET_U_1(message + 3) & 0x3f) ? "/unknown" : "", ae == 0 ? "any" : format_prefix(ndo, prefix, plen), metric, seqno, format_interval_update(interval)); - if(EXTRACT_U_1(message + 3) & 0x80) { - if(EXTRACT_U_1(message + 2) == 1) + if(GET_U_1(message + 3) & 0x80) { + if(GET_U_1(message + 2) == 1) memcpy(v4_prefix, prefix, 16); else memcpy(v6_prefix, prefix, 16); @@ -546,10 +548,10 @@ babel_print_v2(netdissect_options *ndo, u_char prefix[16], ae, plen; ND_PRINT("\n\tRoute Request "); if(len < 2) goto invalid; - ae = EXTRACT_U_1(message + 2); - plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0); + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); rc = network_prefix(ae, - EXTRACT_U_1(message + 3), 0, + GET_U_1(message + 3), 0, message + 4, NULL, len - 2, prefix); if(rc < 0) goto invalid; ND_PRINT("for %s", @@ -567,17 +569,17 @@ babel_print_v2(netdissect_options *ndo, u_char prefix[16], ae, plen; ND_PRINT("\n\tSeqno Request "); if(len < 14) goto invalid; - ae = EXTRACT_U_1(message + 2); - seqno = EXTRACT_BE_U_2(message + 4); + ae = GET_U_1(message + 2); + seqno = GET_BE_U_2(message + 4); rc = network_prefix(ae, - EXTRACT_U_1(message + 3), 0, + GET_U_1(message + 3), 0, message + 16, NULL, len - 14, prefix); if(rc < 0) goto invalid; - plen = EXTRACT_U_1(message + 3) + (EXTRACT_U_1(message + 2) == 1 ? 96 : 0); + plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); ND_PRINT("(%u hops) for %s seqno %u id %s", - EXTRACT_U_1(message + 6), + GET_U_1(message + 6), ae == 0 ? "invalid AE 0" : format_prefix(ndo, prefix, plen), - seqno, format_id(message + 8)); + seqno, format_id(ndo, message + 8)); } } break; @@ -587,8 +589,9 @@ babel_print_v2(netdissect_options *ndo, else { ND_PRINT("\n\tTS/PC "); if(len < 6) goto invalid; - ND_PRINT("timestamp %u packetcounter %u", EXTRACT_BE_U_4(message + 4), - EXTRACT_BE_U_2(message + 2)); + ND_PRINT("timestamp %u packetcounter %u", + GET_BE_U_4(message + 4), + GET_BE_U_2(message + 2)); } break; case MESSAGE_HMAC : { @@ -598,9 +601,10 @@ babel_print_v2(netdissect_options *ndo, unsigned j; ND_PRINT("\n\tHMAC "); if(len < 18) goto invalid; - ND_PRINT("key-id %u digest-%u ", EXTRACT_BE_U_2(message + 2), len - 2); + ND_PRINT("key-id %u digest-%u ", GET_BE_U_2(message + 2), + len - 2); for (j = 0; j < len - 2; j++) - ND_PRINT("%02X", EXTRACT_U_1(message + j + 4)); + ND_PRINT("%02X", GET_U_1(message + j + 4)); } } break; @@ -616,13 +620,13 @@ babel_print_v2(netdissect_options *ndo, int parsed_len = 10; ND_PRINT("\n\tSS-Update"); if(len < 10) goto invalid; - ae = EXTRACT_U_1(message + 2); - src_plen = EXTRACT_U_1(message + 3); - plen = EXTRACT_U_1(message + 4); - omitted = EXTRACT_U_1(message + 5); - interval = EXTRACT_BE_U_2(message + 6); - seqno = EXTRACT_BE_U_2(message + 8); - metric = EXTRACT_BE_U_2(message + 10); + ae = GET_U_1(message + 2); + src_plen = GET_U_1(message + 3); + plen = GET_U_1(message + 4); + omitted = GET_U_1(message + 5); + interval = GET_BE_U_2(message + 6); + seqno = GET_BE_U_2(message + 8); + metric = GET_BE_U_2(message + 10); rc = network_prefix(ae, plen, omitted, message + 2 + parsed_len, ae == 1 ? v4_prefix : v6_prefix, len - parsed_len, prefix); @@ -657,9 +661,9 @@ babel_print_v2(netdissect_options *ndo, u_char ae, plen, src_plen, prefix[16], src_prefix[16]; ND_PRINT("\n\tSS-Request "); if(len < 3) goto invalid; - ae = EXTRACT_U_1(message + 2); - plen = EXTRACT_U_1(message + 3); - src_plen = EXTRACT_U_1(message + 4); + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 3); + src_plen = GET_U_1(message + 4); rc = network_prefix(ae, plen, 0, message + 2 + parsed_len, NULL, len - parsed_len, prefix); if(rc < 0) goto invalid; @@ -692,11 +696,11 @@ babel_print_v2(netdissect_options *ndo, const u_char *router_id = NULL; ND_PRINT("\n\tSS-MH-Request "); if(len < 14) goto invalid; - ae = EXTRACT_U_1(message + 2); - plen = EXTRACT_U_1(message + 3); - seqno = EXTRACT_BE_U_2(message + 4); - hopc = EXTRACT_U_1(message + 6); - src_plen = EXTRACT_U_1(message + 7); + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 3); + seqno = GET_BE_U_2(message + 4); + hopc = GET_U_1(message + 6); + src_plen = GET_U_1(message + 7); router_id = message + 8; rc = network_prefix(ae, plen, 0, message + 2 + parsed_len, NULL, len - parsed_len, prefix); @@ -713,7 +717,7 @@ babel_print_v2(netdissect_options *ndo, hopc, format_prefix(ndo, prefix, plen)); ND_PRINT("%s) seqno %u id %s", format_prefix(ndo, src_prefix, src_plen), - seqno, format_id(router_id)); + seqno, format_id(ndo, router_id)); } } break; @@ -729,10 +733,10 @@ babel_print_v2(netdissect_options *ndo, return; trunc: - ND_PRINT(" %s", tstr); + nd_print_trunc(ndo); return; invalid: - ND_PRINT("%s", istr); + nd_print_invalid(ndo); return; }