X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/05bf9bfc237231a3d10e8f160a9037efdcec70f3..refs/heads/master:/print-babel.c diff --git a/print-babel.c b/print-babel.c index 58faca15..c7593ce1 100644 --- a/print-babel.c +++ b/print-babel.c @@ -26,48 +26,59 @@ * SUCH DAMAGE. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +/* \summary: Babel Routing Protocol printer */ +/* Specifications: + * + * RFC 6126 + * RFC 7298 + * RFC 7557 + * draft-ietf-babel-rfc6126bis-17 + * draft-ietf-babel-hmac-10 + * draft-ietf-babel-source-specific-0 + */ + +#include -#include +#include "netdissect-stdinc.h" #include #include +#include "netdissect.h" #include "addrtoname.h" -#include "interface.h" #include "extract.h" -static void babel_print_v2(const u_char *cp, u_int length); +static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length); void -babel_print(const u_char *cp, u_int length) { - printf("babel"); +babel_print(netdissect_options *ndo, + const u_char *cp, u_int length) +{ + ndo->ndo_protocol = "babel"; + nd_print_protocol(ndo); - TCHECK2(*cp, 4); + ND_TCHECK_4(cp); - if(cp[0] != 42) { - printf(" malformed header"); + if(GET_U_1(cp) != 42) { + ND_PRINT(" invalid header"); return; } else { - printf(" %d", cp[1]); + ND_PRINT(" %u", GET_U_1(cp + 1)); } - switch(cp[1]) { + switch(GET_U_1(cp + 1)) { case 2: - babel_print_v2(cp,length); + babel_print_v2(ndo, cp, length); break; default: - printf(" unknown version"); + ND_PRINT(" unknown version"); break; } return; trunc: - printf(" [|babel]"); - return; + nd_print_trunc(ndo); } /* TLVs */ @@ -80,29 +91,45 @@ babel_print(const u_char *cp, u_int length) { #define MESSAGE_ROUTER_ID 6 #define MESSAGE_NH 7 #define MESSAGE_UPDATE 8 -#define MESSAGE_REQUEST 9 -#define MESSAGE_MH_REQUEST 10 +#define MESSAGE_ROUTE_REQUEST 9 +#define MESSAGE_SEQNO_REQUEST 10 #define MESSAGE_TSPC 11 #define MESSAGE_HMAC 12 +#define MESSAGE_UPDATE_SRC_SPECIFIC 13 /* last appearance in draft-boutier-babel-source-specific-01 */ +#define MESSAGE_REQUEST_SRC_SPECIFIC 14 /* idem */ +#define MESSAGE_MH_REQUEST_SRC_SPECIFIC 15 /* idem */ +#define MESSAGE_MAC 16 +#define MESSAGE_PC 17 +#define MESSAGE_CHALLENGE_REQUEST 18 +#define MESSAGE_CHALLENGE_REPLY 19 /* sub-TLVs */ #define MESSAGE_SUB_PAD1 0 #define MESSAGE_SUB_PADN 1 -#define MESSAGE_SUB_CHANINFO 2 +#define MESSAGE_SUB_DIVERSITY 2 +#define MESSAGE_SUB_TIMESTAMP 3 + +/* "Mandatory" bit in sub-TLV types */ +#define MANDATORY_MASK 0x80 -/* ChanInfo sub-TLV channel codes */ -static const struct tok chaninfo_str[] = { +/* Flags for the Hello TLV */ +#define UNICAST_MASK 0x8000 + +/* Diversity sub-TLV channel codes */ +static const struct tok diversity_str[] = { { 0, "reserved" }, { 255, "all" }, { 0, NULL } }; static const char * -format_id(const u_char *id) +format_id(netdissect_options *ndo, const u_char *id) { static char buf[25]; snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", - id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); + 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; } @@ -111,32 +138,60 @@ static const unsigned char v4prefix[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }; static const char * -format_prefix(const u_char *prefix, unsigned char plen) +format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen) { static char buf[50]; + + /* + * prefix points to a buffer on the stack into which the prefix has + * been placed, so we can't use GET_IPADDR_STRING() or + * GET_IP6ADDR_STRING() on it. + */ if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0) - snprintf(buf, 50, "%s/%u", ipaddr_string(prefix + 12), plen - 96); + snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); else -#ifdef INET6 - snprintf(buf, 50, "%s/%u", ip6addr_string(prefix), plen); -#else - snprintf(buf, 50, "IPv6 addresses not supported"); -#endif + snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); buf[49] = '\0'; return buf; } static const char * -format_address(const u_char *prefix) +format_address(netdissect_options *ndo, const u_char *prefix) { + /* + * prefix points to a buffer on the stack into which the prefix has + * been placed, so we can't use GET_IPADDR_STRING() or + * GET_IP6ADDR_STRING() on it. + */ if(memcmp(prefix, v4prefix, 12) == 0) - return ipaddr_string(prefix + 12); + return ipaddr_string(ndo, prefix + 12); else -#ifdef INET6 - return ip6addr_string(prefix); -#else - return "IPv6 addresses not supported"; -#endif + return ip6addr_string(ndo, prefix); +} + +static const char * +format_interval(const uint16_t i) +{ + static char buf[sizeof("000.00s")]; + + if (i == 0) + return "0.0s (bogus)"; + snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); + return buf; +} + +static const char * +format_interval_update(const uint16_t i) +{ + return i == 0xFFFF ? "infinity" : format_interval(i); +} + +static const char * +format_timestamp(const uint32_t i) +{ + static char buf[sizeof("0000.000000s")]; + snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); + return buf; } /* Return number of octets consumed from the input buffer (not the prefix length @@ -220,320 +275,587 @@ 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 + * 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 + * neighbours. In the case of a Hello TLV, the body stores a 32-bits + * timestamp, while in the case of a IHU TLV, two 32-bits timestamps are + * stored. * * 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. */ + * latter would state that interference is definitely absent. + * A type 3 sub-TLV is valid both for Hello and IHU TLVs, though the exact + * semantic of the sub-TLV is different in each case. + */ static void -subtlvs_print(const u_char *cp, const u_char *ep, const uint8_t tlv_type) { +subtlvs_print(netdissect_options *ndo, + const u_char *cp, const u_char *ep, const uint8_t tlv_type) +{ uint8_t subtype, sublen; const char *sep; + uint32_t t1, t2; while (cp < ep) { - subtype = *cp++; + subtype = GET_U_1(cp); + cp++; if(subtype == MESSAGE_SUB_PAD1) { - printf(" sub-pad1"); + ND_PRINT(" sub-pad1"); continue; } + if ((MANDATORY_MASK & subtype) != 0) + ND_PRINT(" (M)"); if(cp == ep) - goto corrupt; - sublen = *cp++; + goto invalid; + sublen = GET_U_1(cp); + cp++; if(cp + sublen > ep) - goto corrupt; + goto invalid; switch(subtype) { case MESSAGE_SUB_PADN: - printf(" sub-padn"); + ND_PRINT(" sub-padn"); cp += sublen; break; - case MESSAGE_SUB_CHANINFO: - printf(" sub-chaninfo"); + case MESSAGE_SUB_DIVERSITY: + ND_PRINT(" sub-diversity"); if (sublen == 0) { - printf(" empty"); + ND_PRINT(" empty"); break; } sep = " "; - while(sublen--) { - printf("%s%s", sep, tok2str(chaninfo_str, "%u", *cp++)); + while (sublen) { + ND_PRINT("%s%s", sep, + tok2str(diversity_str, "%u", GET_U_1(cp))); + cp++; sep = "-"; + sublen--; } - if(tlv_type != MESSAGE_UPDATE) - printf(" (bogus)"); + if(tlv_type != MESSAGE_UPDATE && + tlv_type != MESSAGE_UPDATE_SRC_SPECIFIC) + ND_PRINT(" (bogus)"); + break; + case MESSAGE_SUB_TIMESTAMP: + ND_PRINT(" sub-timestamp"); + if(tlv_type == MESSAGE_HELLO) { + if(sublen < 4) + goto invalid; + t1 = GET_BE_U_4(cp); + ND_PRINT(" %s", format_timestamp(t1)); + } else if(tlv_type == MESSAGE_IHU) { + if(sublen < 8) + goto invalid; + t1 = GET_BE_U_4(cp); + ND_PRINT(" %s", format_timestamp(t1)); + t2 = GET_BE_U_4(cp + 4); + ND_PRINT("|%s", format_timestamp(t2)); + } else + ND_PRINT(" (bogus)"); + cp += sublen; break; default: - printf(" sub-unknown-0x%02x", subtype); + ND_PRINT(" sub-unknown-0x%02x", subtype); cp += sublen; } /* switch */ } /* while */ return; - corrupt: - printf(" (corrupt)"); + invalid: + nd_print_invalid(ndo); } #define ICHECK(i, l) \ - if ((i) + (l) > bodylen || (i) + (l) > length) goto corrupt; + if ((i) + (l) > tlvs_length || (i) + (l) > packet_length_remaining) \ + goto invalid; -static void -babel_print_v2(const u_char *cp, u_int length) { +static int +babel_print_v2_tlvs(netdissect_options *ndo, + const u_char *cp, u_int tlvs_length, + u_int packet_length_remaining) +{ u_int i; - u_short bodylen; u_char v4_prefix[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }; u_char v6_prefix[16] = {0}; - TCHECK2(*cp, 4); - if (length < 4) - goto corrupt; - bodylen = EXTRACT_16BITS(cp + 2); - printf(" (%u)", bodylen); - - /* Process the TLVs in the body */ i = 0; - while(i < bodylen) { + while(i < tlvs_length) { const u_char *message; - u_int type, len; + uint8_t type; + u_int len; - message = cp + 4 + i; + message = cp + i; - TCHECK2(*message, 1); - if((type = message[0]) == MESSAGE_PAD1) { - printf(vflag ? "\n\tPad 1" : " pad1"); + ICHECK(i, 1); + if((type = GET_U_1(message)) == MESSAGE_PAD1) { + ND_PRINT(ndo->ndo_vflag ? "\n\tPad 1" : " pad1"); i += 1; continue; } - TCHECK2(*message, 2); ICHECK(i, 2); - len = message[1]; + ND_TCHECK_2(message); + len = GET_U_1(message + 1); - TCHECK2(*message, 2 + len); ICHECK(i, 2 + len); + ND_TCHECK_LEN(message, 2 + len); switch(type) { case MESSAGE_PADN: { - if(!vflag) - printf(" padN"); + if (!ndo->ndo_vflag) + ND_PRINT(" padN"); else - printf("\n\tPad %d", len + 2); + ND_PRINT("\n\tPad %u", len + 2); } break; case MESSAGE_ACK_REQ: { u_short nonce, interval; - if(!vflag) - printf(" ack-req"); + if (!ndo->ndo_vflag) + ND_PRINT(" ack-req"); else { - printf("\n\tAcknowledgment Request "); - if(len < 6) goto corrupt; - nonce = EXTRACT_16BITS(message + 4); - interval = EXTRACT_16BITS(message + 6); - printf("%04x %d", nonce, interval); + ND_PRINT("\n\tAcknowledgment Request "); + if(len < 6) goto invalid; + nonce = GET_BE_U_2(message + 4); + interval = GET_BE_U_2(message + 6); + ND_PRINT("%04x %s", nonce, format_interval(interval)); } } break; case MESSAGE_ACK: { u_short nonce; - if(!vflag) - printf(" ack"); + if (!ndo->ndo_vflag) + ND_PRINT(" ack"); else { - printf("\n\tAcknowledgment "); - if(len < 2) goto corrupt; - nonce = EXTRACT_16BITS(message + 2); - printf("%04x", nonce); + ND_PRINT("\n\tAcknowledgment "); + if(len < 2) goto invalid; + nonce = GET_BE_U_2(message + 2); + ND_PRINT("%04x", nonce); } } break; case MESSAGE_HELLO: { - u_short seqno, interval; - if(!vflag) - printf(" hello"); + u_short seqno, interval, unicast; + if (!ndo->ndo_vflag) + ND_PRINT(" hello"); else { - printf("\n\tHello "); - if(len < 6) goto corrupt; - seqno = EXTRACT_16BITS(message + 4); - interval = EXTRACT_16BITS(message + 6); - printf("seqno %u interval %u", seqno, interval); + ND_PRINT("\n\tHello "); + if(len < 6) goto invalid; + unicast = (GET_BE_U_2(message + 2) & UNICAST_MASK); + seqno = GET_BE_U_2(message + 4); + interval = GET_BE_U_2(message + 6); + if(unicast) + ND_PRINT("(Unicast) "); + ND_PRINT("seqno %u ", seqno); + if(interval!=0) + ND_PRINT("interval %s", format_interval(interval)); + else + ND_PRINT("unscheduled"); + /* Extra data. */ + if(len > 6) + subtlvs_print(ndo, message + 8, message + 2 + len, type); } } break; case MESSAGE_IHU: { - unsigned short txcost, interval; - if(!vflag) - printf(" ihu"); + unsigned short rxcost, interval; + if (!ndo->ndo_vflag) + ND_PRINT(" ihu"); else { u_char address[16]; + u_char ae; int rc; - printf("\n\tIHU "); - if(len < 6) goto corrupt; - 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); + ND_PRINT("\n\tIHU "); + if(len < 6) goto invalid; + 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_trunc(ndo); break; } + ND_PRINT("%s rxcost %u interval %s", + ae == 0 ? "any" : format_address(ndo, address), + rxcost, format_interval(interval)); + /* Extra data. */ + if((u_int)rc < len - 6) + subtlvs_print(ndo, message + 8 + rc, message + 2 + len, + type); } } break; case MESSAGE_ROUTER_ID: { - if(!vflag) - printf(" router-id"); + if (!ndo->ndo_vflag) + ND_PRINT(" router-id"); else { - printf("\n\tRouter Id"); - if(len < 10) goto corrupt; - printf(" %s", format_id(message + 4)); + ND_PRINT("\n\tRouter Id"); + if(len < 10) goto invalid; + ND_PRINT(" %s", format_id(ndo, message + 4)); } } break; case MESSAGE_NH: { - if(!vflag) - printf(" nh"); + if (!ndo->ndo_vflag) + ND_PRINT(" nh"); else { int rc; + u_char ae; u_char nh[16]; - printf("\n\tNext Hop"); - if(len < 2) goto corrupt; - rc = network_address(message[2], message + 4, len - 2, nh); - if(rc < 0) goto corrupt; - printf(" %s", format_address(nh)); + ND_PRINT("\n\tNext Hop"); + if(len < 2) goto invalid; + ae = GET_U_1(message + 2); + rc = network_address(ae, message + 4, + len - 2, nh); + if(rc < 0) goto invalid; + ND_PRINT(" %s", ae == 0 ? "invalid AE 0" : format_address(ndo, nh)); } } break; case MESSAGE_UPDATE: { - if(!vflag) { - printf(" update"); - if(len < 1) - printf("/truncated"); + if (!ndo->ndo_vflag) { + ND_PRINT(" update"); + if(len < 10) + goto invalid; else - printf("%s%s%s", - (message[3] & 0x80) ? "/prefix": "", - (message[3] & 0x40) ? "/id" : "", - (message[3] & 0x3f) ? "/unknown" : ""); + ND_PRINT("%s%s%s", + (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 plen; + u_char ae, plen; int rc; u_char prefix[16]; - printf("\n\tUpdate"); - if(len < 10) goto corrupt; - plen = message[4] + (message[2] == 1 ? 96 : 0); - rc = network_prefix(message[2], message[4], message[5], + ND_PRINT("\n\tUpdate"); + if(len < 10) goto invalid; + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 4) + (GET_U_1(message + 2) == 1 ? 96 : 0); + rc = network_prefix(ae, + GET_U_1(message + 4), + GET_U_1(message + 5), message + 12, - message[2] == 1 ? v4_prefix : v6_prefix, + GET_U_1(message + 2) == 1 ? v4_prefix : v6_prefix, len - 10, prefix); - if(rc < 0) goto corrupt; - 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", - (message[3] & 0x80) ? "/prefix": "", - (message[3] & 0x40) ? "/id" : "", - (message[3] & 0x3f) ? "/unknown" : "", - format_prefix(prefix, plen), - metric, seqno, interval); - if(message[3] & 0x80) { - if(message[2] == 1) + if(rc < 0) goto invalid; + 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", + (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(GET_U_1(message + 3) & 0x80) { + if(GET_U_1(message + 2) == 1) memcpy(v4_prefix, prefix, 16); else memcpy(v6_prefix, prefix, 16); } /* extra data? */ - if(rc < len - 10) - subtlvs_print(message + 12 + rc, message + 2 + len, type); + if((u_int)rc < len - 10) + subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type); } } break; - case MESSAGE_REQUEST: { - if(!vflag) - printf(" request"); + case MESSAGE_ROUTE_REQUEST: { + if (!ndo->ndo_vflag) + ND_PRINT(" route-request"); else { int rc; - u_char prefix[16], plen; - printf("\n\tRequest "); - if(len < 2) goto corrupt; - plen = message[3] + (message[2] == 1 ? 96 : 0); - rc = network_prefix(message[2], message[3], 0, + u_char prefix[16], ae, plen; + ND_PRINT("\n\tRoute Request "); + if(len < 2) goto invalid; + ae = GET_U_1(message + 2); + plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); + rc = network_prefix(ae, + GET_U_1(message + 3), 0, message + 4, NULL, len - 2, prefix); - if(rc < 0) goto corrupt; - plen = message[3] + (message[2] == 1 ? 96 : 0); - printf("for %s", - message[2] == 0 ? "any" : format_prefix(prefix, plen)); + if(rc < 0) goto invalid; + ND_PRINT("for %s", + ae == 0 ? "any" : format_prefix(ndo, prefix, plen)); } } break; - case MESSAGE_MH_REQUEST : { - if(!vflag) - printf(" mh-request"); + case MESSAGE_SEQNO_REQUEST : { + if (!ndo->ndo_vflag) + ND_PRINT(" seqno-request"); else { int rc; u_short seqno; - u_char prefix[16], plen; - printf("\n\tMH-Request "); - if(len < 14) goto corrupt; - seqno = EXTRACT_16BITS(message + 4); - rc = network_prefix(message[2], message[3], 0, + u_char prefix[16], ae, plen; + ND_PRINT("\n\tSeqno Request "); + if(len < 14) goto invalid; + ae = GET_U_1(message + 2); + seqno = GET_BE_U_2(message + 4); + rc = network_prefix(ae, + GET_U_1(message + 3), 0, message + 16, NULL, len - 14, prefix); - if(rc < 0) goto corrupt; - plen = message[3] + (message[2] == 1 ? 96 : 0); - printf("(%u hops) for %s seqno %u id %s", - message[6], format_prefix(prefix, plen), - seqno, format_id(message + 8)); + if(rc < 0) goto invalid; + plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); + ND_PRINT("(%u hops) for %s seqno %u id %s", + GET_U_1(message + 6), + ae == 0 ? "invalid AE 0" : format_prefix(ndo, prefix, plen), + seqno, format_id(ndo, message + 8)); } } break; case MESSAGE_TSPC : - if(!vflag) - printf(" tspc"); + if (!ndo->ndo_vflag) + ND_PRINT(" tspc"); else { - printf("\n\tTS/PC "); - if(len < 6) goto corrupt; - printf("timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4), - EXTRACT_16BITS(message + 2)); + ND_PRINT("\n\tTS/PC "); + if(len < 6) goto invalid; + ND_PRINT("timestamp %u packetcounter %u", + GET_BE_U_4(message + 4), + GET_BE_U_2(message + 2)); } break; case MESSAGE_HMAC : { - if(!vflag) - printf(" hmac"); + if (!ndo->ndo_vflag) + ND_PRINT(" hmac"); else { unsigned j; - printf("\n\tHMAC "); - if(len < 18) goto corrupt; - printf("key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2); + ND_PRINT("\n\tHMAC "); + if(len < 18) goto invalid; + ND_PRINT("key-id %u digest-%u ", GET_BE_U_2(message + 2), + len - 2); for (j = 0; j < len - 2; j++) - printf ("%02X", message[4 + j]); + ND_PRINT("%02X", GET_U_1(message + j + 4)); + } + } + break; + + case MESSAGE_UPDATE_SRC_SPECIFIC : { + if(!ndo->ndo_vflag) { + ND_PRINT(" ss-update"); + } else { + u_char prefix[16], src_prefix[16]; + u_short interval, seqno, metric; + u_char ae, plen, src_plen, omitted; + int rc; + int parsed_len = 10; + ND_PRINT("\n\tSS-Update"); + if(len < 10) goto invalid; + 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); + if(rc < 0) goto invalid; + if(ae == 1) + plen += 96; + parsed_len += rc; + rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, + NULL, len - parsed_len, src_prefix); + if(rc < 0) goto invalid; + if(ae == 1) + src_plen += 96; + parsed_len += rc; + + ND_PRINT(" %s from", format_prefix(ndo, prefix, plen)); + ND_PRINT(" %s metric %u seqno %u interval %s", + format_prefix(ndo, src_prefix, src_plen), + metric, seqno, format_interval_update(interval)); + /* extra data? */ + if((u_int)parsed_len < len) + subtlvs_print(ndo, message + 2 + parsed_len, + message + 2 + len, type); + } + } + break; + + case MESSAGE_REQUEST_SRC_SPECIFIC : { + if(!ndo->ndo_vflag) + ND_PRINT(" ss-request"); + else { + int rc, parsed_len = 3; + u_char ae, plen, src_plen, prefix[16], src_prefix[16]; + ND_PRINT("\n\tSS-Request "); + if(len < 3) goto invalid; + 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; + if(ae == 1) + plen += 96; + parsed_len += rc; + rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, + NULL, len - parsed_len, src_prefix); + if(rc < 0) goto invalid; + if(ae == 1) + src_plen += 96; + parsed_len += rc; + if(ae == 0) { + ND_PRINT("for any"); + } else { + ND_PRINT("for (%s, ", format_prefix(ndo, prefix, plen)); + ND_PRINT("%s)", format_prefix(ndo, src_prefix, src_plen)); + } + } + } + break; + + case MESSAGE_MH_REQUEST_SRC_SPECIFIC : { + if(!ndo->ndo_vflag) + ND_PRINT(" ss-mh-request"); + else { + int rc, parsed_len = 14; + u_short seqno; + u_char ae, plen, src_plen, prefix[16], src_prefix[16], hopc; + const u_char *router_id = NULL; + ND_PRINT("\n\tSS-MH-Request "); + if(len < 14) goto invalid; + 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); + if(rc < 0) goto invalid; + if(ae == 1) + plen += 96; + parsed_len += rc; + rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, + NULL, len - parsed_len, src_prefix); + if(rc < 0) goto invalid; + if(ae == 1) + src_plen += 96; + ND_PRINT("(%u hops) for (%s, ", + hopc, format_prefix(ndo, prefix, plen)); + ND_PRINT("%s) seqno %u id %s", + format_prefix(ndo, src_prefix, src_plen), + seqno, format_id(ndo, router_id)); } } break; + + case MESSAGE_MAC: { + if (!ndo->ndo_vflag) + ND_PRINT(" mac"); + else { + ND_PRINT("\n\tMAC "); + ND_PRINT("len %u", len); + } + } + break; + + case MESSAGE_PC: { + if (!ndo->ndo_vflag) + ND_PRINT(" pc"); + else { + ND_PRINT("\n\tPC"); + if(len < 4) goto invalid; + ND_PRINT(" value %u", + GET_BE_U_4(message + 2)); + ND_PRINT(" index len %u", len-4); + } + } + break; + + case MESSAGE_CHALLENGE_REQUEST: { + if (!ndo->ndo_vflag) + ND_PRINT(" challenge_request"); + else { + ND_PRINT("\n\tChallenge Request"); + if(len > 192) goto invalid; + ND_PRINT(" len %u", len); + } + } + break; + + case MESSAGE_CHALLENGE_REPLY: { + if (!ndo->ndo_vflag) + ND_PRINT(" challenge_reply"); + else { + ND_PRINT("\n\tChallenge Reply"); + if (len > 192) goto invalid; + ND_PRINT(" len %u", len); + } + } + break; + default: - if(!vflag) - printf(" unknown"); + if (!ndo->ndo_vflag) + ND_PRINT(" unknown"); else - printf("\n\tUnknown message type %d", type); + ND_PRINT("\n\tUnknown message type %u", type); } i += len + 2; } + + return 0; /* OK */ + +trunc: + return -1; /* packet truncated by capture process */ + +invalid: + return -2; /* packet is invalid */ +} + +static void +babel_print_v2(netdissect_options *ndo, + const u_char *cp, u_int length) +{ + u_short bodylen; + int ret; + + ND_TCHECK_4(cp); + if (length < 4) + goto invalid; + bodylen = GET_BE_U_2(cp + 2); + ND_PRINT(" (%u)", bodylen); + length -= 4; + cp += 4; + + /* Process the TLVs in the body */ + if (length < bodylen) + goto invalid; + ret = babel_print_v2_tlvs(ndo, cp, bodylen, length); + if (ret == -1) + goto trunc; + if (ret == -2) + goto invalid; + length -= bodylen; + cp += bodylen; + + /* If there's a trailer, process the TLVs in the trailer */ + if (length != 0) { + if(ndo->ndo_vflag) ND_PRINT("\n\t----"); + else ND_PRINT(" |"); + ret = babel_print_v2_tlvs(ndo, cp, length, length); + if (ret == -1) + goto trunc; + if (ret == -2) + goto invalid; + } return; trunc: - printf(" [|babel]"); + nd_print_trunc(ndo); return; - corrupt: - printf(" (corrupt)"); - return; + invalid: + nd_print_invalid(ndo); }