X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/32e24ead3b2a171e5f5eff50d7231c2514eda9b4..1ed63b5:/print-bgp.c diff --git a/print-bgp.c b/print-bgp.c index 6f523585..301d24f8 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -114,7 +114,7 @@ struct bgp_route_refresh { #define bgp_attr_lenlen(flags, p) \ (((flags) & 0x10) ? 2U : 1U) #define bgp_attr_len(flags, p) \ - (((flags) & 0x10) ? EXTRACT_BE_U_2(p) : EXTRACT_U_1(p)) + (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p)) #define BGPTYPE_ORIGIN 1 #define BGPTYPE_AS_PATH 2 @@ -216,6 +216,7 @@ static const struct tok bgp_opt_values[] = { #define BGP_CAPCODE_ORF 3 /* RFC5291 */ #define BGP_CAPCODE_MR 4 /* RFC3107 */ #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */ +#define BGP_CAPCODE_ML 8 /* RFC8277 */ #define BGP_CAPCODE_RESTART 64 /* RFC4724 */ #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */ #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */ @@ -230,6 +231,7 @@ static const struct tok bgp_capcode_values[] = { { BGP_CAPCODE_ORF, "Cooperative Route Filtering"}, { BGP_CAPCODE_MR, "Multiple Routes to a Destination"}, { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"}, + { BGP_CAPCODE_ML, "Multiple Labels"}, { BGP_CAPCODE_RESTART, "Graceful Restart"}, { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"}, { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"}, @@ -524,9 +526,9 @@ as_printf(netdissect_options *ndo, char *str, size_t size, u_int asnum) { if (!ndo->ndo_bflag || asnum <= 0xFFFF) { - nd_snprintf(str, size, "%u", asnum); + snprintf(str, size, "%u", asnum); } else { - nd_snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF); + snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF); } return str; } @@ -535,14 +537,14 @@ as_printf(netdissect_options *ndo, int decode_prefix4(netdissect_options *ndo, - const u_char *pptr, u_int itemlen, char *buf, u_int buflen) + const u_char *pptr, u_int itemlen, char *buf, size_t buflen) { - struct in_addr addr; + nd_ipv4 addr; u_int plen, plenbytes; ND_TCHECK_1(pptr); ITEMCHECK(1); - plen = EXTRACT_U_1(pptr); + plen = GET_U_1(pptr); if (32 < plen) return -1; itemlen -= 1; @@ -555,7 +557,7 @@ decode_prefix4(netdissect_options *ndo, if (plen % 8) { ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - nd_snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), plen); + snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), plen); return 1 + plenbytes; trunc: @@ -567,15 +569,16 @@ badtlv: static int decode_labeled_prefix4(netdissect_options *ndo, - const u_char *pptr, u_int itemlen, char *buf, u_int buflen) + const u_char *pptr, u_int itemlen, char *buf, + size_t buflen) { - struct in_addr addr; + nd_ipv4 addr; u_int plen, plenbytes; /* prefix length and label = 4 bytes */ ND_TCHECK_4(pptr); ITEMCHECK(4); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ /* this is one of the weirdnesses of rfc3107 the label length (actually the label + COS bits) @@ -603,11 +606,11 @@ decode_labeled_prefix4(netdissect_options *ndo, ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - nd_snprintf(buf, buflen, "%s/%u, label:%u %s", + snprintf(buf, buflen, "%s/%u, label:%u %s", ipaddr_string(ndo, (const u_char *)&addr), plen, - EXTRACT_BE_U_3(pptr + 1)>>4, - ((EXTRACT_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + GET_BE_U_3(pptr + 1)>>4, + ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 4 + plenbytes; @@ -635,14 +638,14 @@ bgp_vpn_ip_print(netdissect_options *ndo, switch(addr_length) { case (sizeof(nd_ipv4) << 3): /* 32 */ ND_TCHECK_LEN(pptr, sizeof(nd_ipv4)); - nd_snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); + snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); break; case (sizeof(nd_ipv6) << 3): /* 128 */ ND_TCHECK_LEN(pptr, sizeof(nd_ipv6)); - nd_snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); + snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); break; default: - nd_snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); + snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); break; } pos += strlen(pos); @@ -672,7 +675,7 @@ trunc: */ static u_int bgp_vpn_sg_print(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { uint8_t addr_length; u_int total_length, offset; @@ -681,30 +684,30 @@ bgp_vpn_sg_print(netdissect_options *ndo, /* Source address length, encoded in bits */ ND_TCHECK_1(pptr); - addr_length = EXTRACT_U_1(pptr); + addr_length = GET_U_1(pptr); pptr++; /* Source address */ ND_TCHECK_LEN(pptr, (addr_length >> 3)); total_length += (addr_length >> 3) + 1; - offset = strlen(buf); + offset = (u_int)strlen(buf); if (addr_length) { - nd_snprintf(buf + offset, buflen - offset, ", Source %s", + snprintf(buf + offset, buflen - offset, ", Source %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } /* Group address length, encoded in bits */ ND_TCHECK_1(pptr); - addr_length = EXTRACT_U_1(pptr); + addr_length = GET_U_1(pptr); pptr++; /* Group address */ ND_TCHECK_LEN(pptr, (addr_length >> 3)); total_length += (addr_length >> 3) + 1; - offset = strlen(buf); + offset = (u_int)strlen(buf); if (addr_length) { - nd_snprintf(buf + offset, buflen - offset, ", Group %s", + snprintf(buf + offset, buflen - offset, ", Group %s", bgp_vpn_ip_print(ndo, pptr, addr_length)); pptr += (addr_length >> 3); } @@ -723,35 +726,35 @@ bgp_vpn_rd_print(netdissect_options *ndo, char *pos = rd; /* ok lets load the RD format */ - switch (EXTRACT_BE_U_2(pptr)) { + switch (GET_BE_U_2(pptr)) { case 0: /* 2-byte-AS:number fmt */ - nd_snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", - EXTRACT_BE_U_2(pptr + 2), - EXTRACT_BE_U_4(pptr + 4), - EXTRACT_U_1(pptr + 4), EXTRACT_U_1(pptr + 5), - EXTRACT_U_1(pptr + 6), EXTRACT_U_1(pptr + 7)); + snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", + GET_BE_U_2(pptr + 2), + GET_BE_U_4(pptr + 4), + GET_U_1(pptr + 4), GET_U_1(pptr + 5), + GET_U_1(pptr + 6), GET_U_1(pptr + 7)); break; case 1: /* IP-address:AS fmt */ - nd_snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", - EXTRACT_U_1(pptr + 2), EXTRACT_U_1(pptr + 3), - EXTRACT_U_1(pptr + 4), EXTRACT_U_1(pptr + 5), - EXTRACT_BE_U_2(pptr + 6)); + snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u", + GET_U_1(pptr + 2), GET_U_1(pptr + 3), + GET_U_1(pptr + 4), GET_U_1(pptr + 5), + GET_BE_U_2(pptr + 6)); break; case 2: /* 4-byte-AS:number fmt */ - nd_snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", - as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(pptr + 2)), - EXTRACT_BE_U_2(pptr + 6), EXTRACT_U_1(pptr + 2), - EXTRACT_U_1(pptr + 3), EXTRACT_U_1(pptr + 4), - EXTRACT_U_1(pptr + 5), EXTRACT_BE_U_2(pptr + 6)); + snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)", + as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(pptr + 2)), + GET_BE_U_2(pptr + 6), GET_U_1(pptr + 2), + GET_U_1(pptr + 3), GET_U_1(pptr + 4), + GET_U_1(pptr + 5), GET_BE_U_2(pptr + 6)); break; default: - nd_snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); + snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); break; } pos += strlen(pos); @@ -771,14 +774,14 @@ bgp_extended_community_print(netdissect_options *ndo, uint32_t i; } bw; - switch (EXTRACT_BE_U_2(pptr)) { + switch (GET_BE_U_2(pptr)) { case BGP_EXT_COM_RT_0: case BGP_EXT_COM_RO_0: case BGP_EXT_COM_L2VPN_RT_0: ND_PRINT("%u:%u (= %s)", - EXTRACT_BE_U_2(pptr + 2), - EXTRACT_BE_U_4(pptr + 4), + GET_BE_U_2(pptr + 2), + GET_BE_U_4(pptr + 4), ipaddr_string(ndo, pptr+4)); break; @@ -788,18 +791,18 @@ bgp_extended_community_print(netdissect_options *ndo, case BGP_EXT_COM_VRF_RT_IMP: ND_PRINT("%s:%u", ipaddr_string(ndo, pptr+2), - EXTRACT_BE_U_2(pptr + 6)); + GET_BE_U_2(pptr + 6)); break; case BGP_EXT_COM_RT_2: case BGP_EXT_COM_RO_2: ND_PRINT("%s:%u", as_printf(ndo, astostr, sizeof(astostr), - EXTRACT_BE_U_4(pptr + 2)), EXTRACT_BE_U_2(pptr + 6)); + GET_BE_U_4(pptr + 2)), GET_BE_U_2(pptr + 6)); break; case BGP_EXT_COM_LINKBAND: - bw.i = EXTRACT_BE_U_4(pptr + 2); + bw.i = GET_BE_U_4(pptr + 2); ND_PRINT("bandwidth: %.3f Mbps", bw.f*8/1000000); break; @@ -819,32 +822,32 @@ bgp_extended_community_print(netdissect_options *ndo, ipaddr_string(ndo, pptr+2), tok2str(bgp_extd_comm_ospf_rtype_values, "unknown (0x%02x)", - EXTRACT_U_1((pptr + 6))), - (EXTRACT_U_1(pptr + 7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "", - ((EXTRACT_U_1(pptr + 6) == BGP_OSPF_RTYPE_EXT) || (EXTRACT_U_1(pptr + 6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""); + GET_U_1((pptr + 6))), + (GET_U_1(pptr + 7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "", + ((GET_U_1(pptr + 6) == BGP_OSPF_RTYPE_EXT) || (GET_U_1(pptr + 6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""); break; case BGP_EXT_COM_L2INFO: ND_PRINT("%s Control Flags [0x%02x]:MTU %u", tok2str(l2vpn_encaps_values, "unknown encaps", - EXTRACT_U_1((pptr + 2))), - EXTRACT_U_1((pptr + 3)), - EXTRACT_BE_U_2(pptr + 4)); + GET_U_1((pptr + 2))), + GET_U_1((pptr + 3)), + GET_BE_U_2(pptr + 4)); break; case BGP_EXT_COM_SOURCE_AS: - ND_PRINT("AS %u", EXTRACT_BE_U_2(pptr + 2)); + ND_PRINT("AS %u", GET_BE_U_2(pptr + 2)); break; default: ND_PRINT("%02x%02x%02x%02x%02x%02x", - EXTRACT_U_1(pptr + 2), - EXTRACT_U_1(pptr + 3), - EXTRACT_U_1(pptr + 4), - EXTRACT_U_1(pptr + 5), - EXTRACT_U_1(pptr + 6), - EXTRACT_U_1(pptr + 7)); + GET_U_1(pptr + 2), + GET_U_1(pptr + 3), + GET_U_1(pptr + 4), + GET_U_1(pptr + 5), + GET_U_1(pptr + 6), + GET_U_1(pptr + 7)); break; } } @@ -859,7 +862,7 @@ decode_rt_routing_info(netdissect_options *ndo, /* NLRI "prefix length" from RFC 2858 Section 4. */ ND_TCHECK_1(pptr); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits. * RFC 4684 Section 4 defines the layout of "origin AS" and "route @@ -878,7 +881,7 @@ decode_rt_routing_info(netdissect_options *ndo, /* With at least "origin AS", possibly with "route target". */ ND_TCHECK_4(pptr + 1); - as_printf(ndo, asbuf, sizeof(asbuf), EXTRACT_BE_U_4(pptr + 1)); + as_printf(ndo, asbuf, sizeof(asbuf), GET_BE_U_4(pptr + 1)); plen -= 32; /* adjust prefix length */ @@ -901,13 +904,13 @@ trunc: static int decode_labeled_vpn_prefix4(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { - struct in_addr addr; + nd_ipv4 addr; u_int plen; ND_TCHECK_1(pptr); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ if ((24+64) > plen) return -1; @@ -925,12 +928,12 @@ decode_labeled_vpn_prefix4(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ipaddr_string(ndo, (const u_char *)&addr), plen, - EXTRACT_BE_U_3(pptr + 1)>>4, - ((EXTRACT_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + GET_BE_U_3(pptr + 1)>>4, + ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; @@ -952,7 +955,7 @@ trunc: static int decode_mdt_vpn_nlri(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { const u_char *rd; const u_char *vpn_ip; @@ -960,7 +963,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo, ND_TCHECK_1(pptr); /* if the NLRI is not predefined length, quit.*/ - if (EXTRACT_U_1(pptr) != MDT_VPN_NLRI_LEN * 8) + if (GET_U_1(pptr) != MDT_VPN_NLRI_LEN * 8) return -1; pptr++; @@ -977,7 +980,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo, /* MDT Group Address */ ND_TCHECK_LEN(pptr, sizeof(nd_ipv4)); - nd_snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s", + snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s", bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr)); return MDT_VPN_NLRI_LEN + 1; @@ -1009,17 +1012,17 @@ static int decode_multicast_vpn(netdissect_options *ndo, const u_char *pptr, char *buf, size_t buflen) { - uint8_t route_type, route_length, addr_length; - u_int sg_length; + uint8_t route_type, route_length; + u_int addr_length, sg_length; u_int offset; ND_TCHECK_2(pptr); - route_type = EXTRACT_U_1(pptr); + route_type = GET_U_1(pptr); pptr++; - route_length = EXTRACT_U_1(pptr); + route_length = GET_U_1(pptr); pptr++; - nd_snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", + snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", tok2str(bgp_multicast_vpn_route_type_values, "Unknown", route_type), route_type, route_length); @@ -1027,25 +1030,25 @@ decode_multicast_vpn(netdissect_options *ndo, switch(route_type) { case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s", bgp_vpn_rd_print(ndo, pptr), bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN, (route_length - BGP_VPN_RD_LEN) << 3)); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), - EXTRACT_BE_U_4(pptr + BGP_VPN_RD_LEN))); + GET_BE_U_4(pptr + BGP_VPN_RD_LEN))); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", RD: %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; @@ -1053,15 +1056,15 @@ decode_multicast_vpn(netdissect_options *ndo, addr_length = route_length - sg_length; ND_TCHECK_LEN(pptr, addr_length); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", Originator %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", Originator %s", bgp_vpn_ip_print(ndo, pptr, addr_length << 3)); break; case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", RD: %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", RD: %s", bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; @@ -1071,11 +1074,11 @@ decode_multicast_vpn(netdissect_options *ndo, case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */ case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN: ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4); - offset = strlen(buf); - nd_snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", + offset = (u_int)strlen(buf); + snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s", bgp_vpn_rd_print(ndo, pptr), as_printf(ndo, astostr, sizeof(astostr), - EXTRACT_BE_U_4(pptr + BGP_VPN_RD_LEN))); + GET_BE_U_4(pptr + BGP_VPN_RD_LEN))); pptr += BGP_VPN_RD_LEN + 4; bgp_vpn_sg_print(ndo, pptr, buf, buflen); @@ -1117,13 +1120,13 @@ trunc: static int decode_labeled_vpn_l2(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { u_int plen, tlen, tlv_type, tlv_len, ttlv_len; int stringlen; ND_TCHECK_2(pptr); - plen = EXTRACT_BE_U_2(pptr); + plen = GET_BE_U_2(pptr); tlen = plen; pptr += 2; /* Old and new L2VPN NLRI share AFI/SAFI @@ -1134,7 +1137,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, /* assume AD-only with RD, BGPNH */ ND_TCHECK_LEN(pptr, 12); buf[0] = '\0'; - stringlen = nd_snprintf(buf, buflen, "RD: %s, BGPNH: %s", + stringlen = snprintf(buf, buflen, "RD: %s, BGPNH: %s", bgp_vpn_rd_print(ndo, pptr), ipaddr_string(ndo, pptr+8)); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); @@ -1147,11 +1150,11 @@ decode_labeled_vpn_l2(netdissect_options *ndo, ND_TCHECK_LEN(pptr, 15); buf[0] = '\0'; - stringlen = nd_snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", + stringlen = snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", bgp_vpn_rd_print(ndo, pptr), - EXTRACT_BE_U_2(pptr + 8), - EXTRACT_BE_U_2(pptr + 10), - EXTRACT_BE_U_3(pptr + 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ + GET_BE_U_2(pptr + 8), + GET_BE_U_2(pptr + 10), + GET_BE_U_3(pptr + 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr += 15; tlen -= 15; @@ -1160,22 +1163,22 @@ decode_labeled_vpn_l2(netdissect_options *ndo, while (tlen != 0) { if (tlen < 3) { if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, "\n\t\tran past the end"); + stringlen=snprintf(buf,buflen, "\n\t\tran past the end"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; } ND_TCHECK_3(pptr); - tlv_type = EXTRACT_U_1(pptr); + tlv_type = GET_U_1(pptr); pptr++; - tlv_len = EXTRACT_BE_U_2(pptr); /* length, in *bits* */ + tlv_len = GET_BE_U_2(pptr); /* length, in *bits* */ ttlv_len = (tlv_len + 7)/8; /* length, in *bytes* */ pptr += 2; switch(tlv_type) { case 1: if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", + stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); @@ -1183,15 +1186,15 @@ decode_labeled_vpn_l2(netdissect_options *ndo, while (ttlv_len != 0) { if (tlen < 1) { if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, " (ran past the end)"); + stringlen=snprintf(buf,buflen, " (ran past the end)"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; } ND_TCHECK_1(pptr); if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, "%02x", - EXTRACT_U_1(pptr)); + stringlen=snprintf(buf,buflen, "%02x", + GET_U_1(pptr)); pptr++; UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } @@ -1201,14 +1204,14 @@ decode_labeled_vpn_l2(netdissect_options *ndo, break; default: if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", + stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", tlv_type, tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } if (tlen < ttlv_len) { if (buflen != 0) { - stringlen=nd_snprintf(buf,buflen, " (ran past the end)"); + stringlen=snprintf(buf,buflen, " (ran past the end)"); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } return plen + 2; @@ -1230,14 +1233,14 @@ trunc: int decode_prefix6(netdissect_options *ndo, - const u_char *pd, u_int itemlen, char *buf, u_int buflen) + const u_char *pd, u_int itemlen, char *buf, size_t buflen) { - struct in6_addr addr; + nd_ipv6 addr; u_int plen, plenbytes; ND_TCHECK_1(pd); ITEMCHECK(1); - plen = EXTRACT_U_1(pd); + plen = GET_U_1(pd); if (128 < plen) return -1; itemlen -= 1; @@ -1248,10 +1251,10 @@ decode_prefix6(netdissect_options *ndo, ITEMCHECK(plenbytes); memcpy(&addr, pd + 1, plenbytes); if (plen % 8) { - addr.s6_addr[plenbytes - 1] &= + addr[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - nd_snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, (const u_char *)&addr), plen); + snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, (const u_char *)&addr), plen); return 1 + plenbytes; trunc: @@ -1263,15 +1266,15 @@ badtlv: static int decode_labeled_prefix6(netdissect_options *ndo, - const u_char *pptr, u_int itemlen, char *buf, u_int buflen) + const u_char *pptr, u_int itemlen, char *buf, size_t buflen) { - struct in6_addr addr; + nd_ipv6 addr; u_int plen, plenbytes; /* prefix length and label = 4 bytes */ ND_TCHECK_4(pptr); ITEMCHECK(4); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ if (24 > plen) return -1; @@ -1287,15 +1290,15 @@ decode_labeled_prefix6(netdissect_options *ndo, ND_TCHECK_LEN(pptr + 4, plenbytes); memcpy(&addr, pptr + 4, plenbytes); if (plen % 8) { - addr.s6_addr[plenbytes - 1] &= + addr[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - nd_snprintf(buf, buflen, "%s/%u, label:%u %s", + snprintf(buf, buflen, "%s/%u, label:%u %s", ip6addr_string(ndo, (const u_char *)&addr), plen, - EXTRACT_BE_U_3(pptr + 1)>>4, - ((EXTRACT_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + GET_BE_U_3(pptr + 1)>>4, + ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 4 + plenbytes; @@ -1308,13 +1311,13 @@ badtlv: static int decode_labeled_vpn_prefix6(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { - struct in6_addr addr; + nd_ipv6 addr; u_int plen; ND_TCHECK_1(pptr); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ if ((24+64) > plen) return -1; @@ -1328,16 +1331,16 @@ decode_labeled_vpn_prefix6(netdissect_options *ndo, ND_TCHECK_LEN(pptr + 12, (plen + 7) / 8); memcpy(&addr, pptr + 12, (plen + 7) / 8); if (plen % 8) { - addr.s6_addr[(plen + 7) / 8 - 1] &= + addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), ip6addr_string(ndo, (const u_char *)&addr), plen, - EXTRACT_BE_U_3(pptr + 1)>>4, - ((EXTRACT_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + GET_BE_U_3(pptr + 1)>>4, + ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; @@ -1347,13 +1350,13 @@ trunc: static int decode_clnp_prefix(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { uint8_t addr[19]; u_int plen; ND_TCHECK_1(pptr); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ if (152 < plen) return -1; @@ -1365,7 +1368,7 @@ decode_clnp_prefix(netdissect_options *ndo, addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } - nd_snprintf(buf, buflen, "%s/%u", + snprintf(buf, buflen, "%s/%u", isonsap_string(ndo, addr,(plen + 7) / 8), plen); @@ -1377,13 +1380,13 @@ trunc: static int decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr, char *buf, size_t buflen) { uint8_t addr[19]; u_int plen; ND_TCHECK_1(pptr); - plen = EXTRACT_U_1(pptr); /* get prefix length */ + plen = GET_U_1(pptr); /* get prefix length */ if ((24+64) > plen) return -1; @@ -1400,12 +1403,12 @@ decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); } /* the label may get offsetted by 4 bits so lets shift it right */ - nd_snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", + snprintf(buf, buflen, "RD: %s, %s/%u, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), isonsap_string(ndo, addr,(plen + 7) / 8), plen, - EXTRACT_BE_U_3(pptr + 1)>>4, - ((EXTRACT_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); + GET_BE_U_3(pptr + 1)>>4, + ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); return 12 + (plen + 7) / 8; @@ -1445,11 +1448,11 @@ bgp_attr_get_as_size(netdissect_options *ndo, /* * If we do not find a valid segment type, our guess might be wrong. */ - if (EXTRACT_U_1(tptr) < BGP_AS_SEG_TYPE_MIN || EXTRACT_U_1(tptr) > BGP_AS_SEG_TYPE_MAX) { + if (GET_U_1(tptr) < BGP_AS_SEG_TYPE_MIN || GET_U_1(tptr) > BGP_AS_SEG_TYPE_MAX) { goto trunc; } ND_TCHECK_1(tptr + 1); - tptr += 2 + EXTRACT_U_1(tptr + 1) * 2; + tptr += 2 + GET_U_1(tptr + 1) * 2; } /* @@ -1497,7 +1500,7 @@ check_add_path(netdissect_options *ndo, const u_char *pptr, u_int length, /* We ran out of captured data; quit scanning. */ break; } - prefix_length = EXTRACT_U_1(pptr + offset); + prefix_length = GET_U_1(pptr + offset); /* * Add 4 to cover the path id * and check the prefix length isn't greater than 32/128. @@ -1519,7 +1522,7 @@ check_add_path(netdissect_options *ndo, const u_char *pptr, u_int length, /* We ran out of captured data; quit scanning. */ break; } - prefix_length = EXTRACT_U_1(pptr + offset); + prefix_length = GET_U_1(pptr + offset); /* * If the prefix_length is zero (0.0.0.0/0) * and since it's not the only address (length >= 5) @@ -1538,9 +1541,239 @@ check_add_path(netdissect_options *ndo, const u_char *pptr, u_int length, return 0; } +static int +bgp_mp_af_print(netdissect_options *ndo, + const u_char *tptr, u_int tlen, + uint16_t *afp, uint8_t *safip) +{ + uint16_t af; + uint8_t safi; + + af = GET_BE_U_2(tptr); + *afp = af; + safi = GET_U_1(tptr + 2); + *safip = safi; + + ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)", + tok2str(af_values, "Unknown AFI", af), + af, + (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ + tok2str(bgp_safi_values, "Unknown SAFI", safi), + safi); + + switch(af<<8 | safi) { + case (AFNUM_INET<<8 | SAFNUM_UNICAST): + case (AFNUM_INET<<8 | SAFNUM_MULTICAST): + case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): + case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): + case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): + case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): + case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): + case (AFNUM_INET<<8 | SAFNUM_MDT): + case (AFNUM_INET6<<8 | SAFNUM_UNICAST): + case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): + case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): + case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): + case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): + case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): + case (AFNUM_VPLS<<8 | SAFNUM_VPLS): + break; + default: + ND_TCHECK_LEN(tptr, tlen); + ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af, safi); + if (ndo->ndo_vflag <= 1) + print_unknown_data(ndo, tptr, "\n\t ", tlen); + return -1; + } + return 0; +trunc: + return -2; +} + +static int +bgp_nlri_print(netdissect_options *ndo, uint16_t af, uint8_t safi, + const u_char *tptr, u_int len, + char *buf, size_t buflen, + int add_path4, int add_path6) +{ + int advance; + u_int path_id = 0; + + switch (af<<8 | safi) { + case (AFNUM_INET<<8 | SAFNUM_UNICAST): + case (AFNUM_INET<<8 | SAFNUM_MULTICAST): + case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): + if (add_path4) { + path_id = GET_BE_U_4(tptr); + tptr += 4; + } + advance = decode_prefix4(ndo, tptr, len, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else if (advance == -3) + break; /* bytes left, but not enough */ + else + ND_PRINT("\n\t %s", buf); + if (add_path4) { + ND_PRINT(" Path Id: %u", path_id); + advance += 4; + } + break; + case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): + advance = decode_labeled_prefix4(ndo, tptr, len, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else if (advance == -3) + break; /* bytes left, but not enough */ + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): + advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): + advance = decode_rt_routing_info(ndo, tptr); + if (advance == -2) + goto trunc; + break; + case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ + case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): + advance = decode_multicast_vpn(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + + case (AFNUM_INET<<8 | SAFNUM_MDT): + advance = decode_mdt_vpn_nlri(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_INET6<<8 | SAFNUM_UNICAST): + case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): + case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): + if (add_path6) { + path_id = GET_BE_U_4(tptr); + tptr += 4; + } + advance = decode_prefix6(ndo, tptr, len, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else if (advance == -3) + break; /* bytes left, but not enough */ + else + ND_PRINT("\n\t %s", buf); + if (add_path6) { + ND_PRINT(" Path Id: %u", path_id); + advance += 4; + } + break; + case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): + advance = decode_labeled_prefix6(ndo, tptr, len, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else if (advance == -3) + break; /* bytes left, but not enough */ + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): + advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_VPLS<<8 | SAFNUM_VPLS): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): + advance = decode_labeled_vpn_l2(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): + case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): + advance = decode_clnp_prefix(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): + case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): + case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): + advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, buflen); + if (advance == -1) + ND_PRINT("\n\t (illegal prefix length)"); + else if (advance == -2) + goto trunc; + else + ND_PRINT("\n\t %s", buf); + break; + default: + /* + * This should not happen, we should have been protected + * by bgp_mp_af_print()'s return value. + */ + ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af, safi); + advance = -4; + break; + } + return advance; +trunc: /* we rely on the caller to recognize -2 return value */ + return -2; +} + static int bgp_attr_print(netdissect_options *ndo, - u_int atype, const u_char *pptr, u_int len) + uint8_t atype, const u_char *pptr, u_int len) { u_int i; uint16_t af; @@ -1551,7 +1784,7 @@ bgp_attr_print(netdissect_options *ndo, char buf[MAXHOSTNAMELEN + 100]; u_int as_size; int add_path4, add_path6; - u_int path_id = 0; + int ret; tptr = pptr; tlen = len; @@ -1564,7 +1797,7 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_1(tptr); ND_PRINT("%s", tok2str(bgp_origin_values, "Unknown Origin Typecode", - EXTRACT_U_1(tptr))); + GET_U_1(tptr))); } break; @@ -1595,21 +1828,21 @@ bgp_attr_print(netdissect_options *ndo, while (tptr < pptr + len) { ND_TCHECK_1(tptr); ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values, - "?", EXTRACT_U_1(tptr))); + "?", GET_U_1(tptr))); ND_TCHECK_1(tptr + 1); - for (i = 0; i < EXTRACT_U_1(tptr + 1) * as_size; i += as_size) { + for (i = 0; i < GET_U_1(tptr + 1) * as_size; i += as_size) { ND_TCHECK_LEN(tptr + 2 + i, as_size); ND_PRINT("%s ", as_printf(ndo, astostr, sizeof(astostr), as_size == 2 ? - EXTRACT_BE_U_2(tptr + i + 2) : - EXTRACT_BE_U_4(tptr + i + 2))); + GET_BE_U_2(tptr + i + 2) : + GET_BE_U_4(tptr + i + 2))); } ND_TCHECK_1(tptr); ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values, - "?", EXTRACT_U_1(tptr))); + "?", GET_U_1(tptr))); ND_TCHECK_1(tptr + 1); - tptr += 2 + EXTRACT_U_1(tptr + 1) * as_size; + tptr += 2 + GET_U_1(tptr + 1) * as_size; } break; case BGPTYPE_NEXT_HOP: @@ -1626,7 +1859,7 @@ bgp_attr_print(netdissect_options *ndo, ND_PRINT("invalid len"); else { ND_TCHECK_4(tptr); - ND_PRINT("%u", EXTRACT_BE_U_4(tptr)); + ND_PRINT("%u", GET_BE_U_4(tptr)); } break; case BGPTYPE_ATOMIC_AGGREGATE: @@ -1646,12 +1879,12 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_LEN(tptr, len); if (len == 6) { ND_PRINT(" AS #%s, origin %s", - as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_2(tptr)), + as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_2(tptr)), ipaddr_string(ndo, tptr + 2)); } else { ND_PRINT(" AS #%s, origin %s", as_printf(ndo, astostr, sizeof(astostr), - EXTRACT_BE_U_4(tptr)), ipaddr_string(ndo, tptr + 4)); + GET_BE_U_4(tptr)), ipaddr_string(ndo, tptr + 4)); } break; case BGPTYPE_AGGREGATOR4: @@ -1661,7 +1894,7 @@ bgp_attr_print(netdissect_options *ndo, } ND_TCHECK_8(tptr); ND_PRINT(" AS #%s, origin %s", - as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(tptr)), + as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(tptr)), ipaddr_string(ndo, tptr + 4)); break; case BGPTYPE_COMMUNITIES: @@ -1674,7 +1907,7 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_4(tptr); if (tlen < 4) goto trunc; - comm = EXTRACT_BE_U_4(tptr); + comm = GET_BE_U_4(tptr); switch (comm) { case BGP_COMMUNITY_NO_EXPORT: ND_PRINT(" NO_EXPORT"); @@ -1724,58 +1957,16 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_3(tptr); if (tlen < 3) goto trunc; - af = EXTRACT_BE_U_2(tptr); - safi = EXTRACT_U_1(tptr + 2); - - ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)", - tok2str(af_values, "Unknown AFI", af), - af, - (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ - tok2str(bgp_safi_values, "Unknown SAFI", safi), - safi); - - switch(af<<8 | safi) { - case (AFNUM_INET<<8 | SAFNUM_UNICAST): - case (AFNUM_INET<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): - case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): - case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): - case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): - case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): - case (AFNUM_INET<<8 | SAFNUM_MDT): - case (AFNUM_INET6<<8 | SAFNUM_UNICAST): - case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): - case (AFNUM_VPLS<<8 | SAFNUM_VPLS): - break; - default: - ND_TCHECK_LEN(tptr, tlen); - ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af, safi); - if (ndo->ndo_vflag <= 1) - print_unknown_data(ndo, tptr, "\n\t ", tlen); - goto done; - break; - } + ret = bgp_mp_af_print(ndo, tptr, tlen, &af, &safi); + if (ret == -2) + goto trunc; + if (ret < 0) + break; tptr +=3; ND_TCHECK_1(tptr); - nhlen = EXTRACT_U_1(tptr); + nhlen = GET_U_1(tptr); tlen = nhlen; tptr++; @@ -1885,20 +2076,21 @@ bgp_attr_print(netdissect_options *ndo, bgp_vpn_rd_print(ndo, tptr), isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)); /* rfc986 mapped IPv4 address ? */ - if (EXTRACT_BE_U_4(tptr + BGP_VPN_RD_LEN) == 0x47000601) + if (GET_BE_U_4(tptr + BGP_VPN_RD_LEN) == 0x47000601) ND_PRINT(" = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4)); /* rfc1888 mapped IPv6 address ? */ - else if (EXTRACT_BE_U_3(tptr + BGP_VPN_RD_LEN) == 0x350000) + else if (GET_BE_U_3(tptr + BGP_VPN_RD_LEN) == 0x350000) ND_PRINT(" = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3)); tptr += tlen; tlen = 0; } break; default: - ND_TCHECK_LEN(tptr, tlen); - ND_PRINT("no AFI %u/SAFI %u decoder", af, safi); - if (ndo->ndo_vflag <= 1) - print_unknown_data(ndo, tptr, "\n\t ", tlen); + /* + * bgp_mp_af_print() should have saved us from + * an unsupported AFI/SAFI. + */ + ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af, safi); tptr += tlen; tlen = 0; goto done; @@ -1910,352 +2102,55 @@ bgp_attr_print(netdissect_options *ndo, tptr += tlen; ND_TCHECK_1(tptr); - snpa = EXTRACT_U_1(tptr); + snpa = GET_U_1(tptr); tptr++; if (snpa) { ND_PRINT("\n\t %u SNPA", snpa); for (/*nothing*/; snpa != 0; snpa--) { ND_TCHECK_1(tptr); - ND_PRINT("\n\t %u bytes", EXTRACT_U_1(tptr)); - tptr += EXTRACT_U_1(tptr) + 1; + ND_PRINT("\n\t %u bytes", GET_U_1(tptr)); + tptr += GET_U_1(tptr) + 1; } } else { ND_PRINT(", no SNPA"); } - add_path4 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 32); - add_path6 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 128); + add_path4 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 32); + add_path6 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 128); while (tptr < pptr + len) { - switch (af<<8 | safi) { - case (AFNUM_INET<<8 | SAFNUM_UNICAST): - case (AFNUM_INET<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): - if (add_path4) { - path_id = EXTRACT_BE_U_4(tptr); - tptr += 4; - } - advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - if (add_path4) { - ND_PRINT(" Path Id: %u", path_id); - } - break; - case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): - advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): - advance = decode_rt_routing_info(ndo, tptr); - if (advance == -2) - goto trunc; - break; - case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ - case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): - advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - - case (AFNUM_INET<<8 | SAFNUM_MDT): - advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET6<<8 | SAFNUM_UNICAST): - case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): - if (add_path6) { - path_id = EXTRACT_BE_U_4(tptr); - tptr += 4; - } - advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - if (add_path6) { - ND_PRINT(" Path Id: %u", path_id); - } - break; - case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): - advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_VPLS<<8 | SAFNUM_VPLS): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): - advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - default: - ND_TCHECK_LEN(tptr, tlen); - ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af, safi); - if (ndo->ndo_vflag <= 1) - print_unknown_data(ndo, tptr, "\n\t ", tlen); - advance = 0; - tptr = pptr + len; - break; - } + advance = bgp_nlri_print(ndo, af, safi, tptr, len, buf, sizeof(buf), + add_path4, add_path6); + if (advance == -2) + goto trunc; if (advance < 0) break; tptr += advance; } - done: break; case BGPTYPE_MP_UNREACH_NLRI: ND_TCHECK_LEN(tptr, BGP_MP_NLRI_MINSIZE); - af = EXTRACT_BE_U_2(tptr); - safi = EXTRACT_U_1(tptr + 2); - - ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)", - tok2str(af_values, "Unknown AFI", af), - af, - (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */ - tok2str(bgp_safi_values, "Unknown SAFI", safi), - safi); + ret = bgp_mp_af_print(ndo, tptr, tlen, &af, &safi); + if (ret == -2) + goto trunc; + if (ret < 0) + break; if (len == BGP_MP_NLRI_MINSIZE) ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)"); tptr += 3; - add_path4 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 32); - add_path6 = check_add_path(ndo, tptr, (len-(tptr - pptr)), 128); + add_path4 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 32); + add_path6 = check_add_path(ndo, tptr, (len-ND_BYTES_BETWEEN(tptr, pptr)), 128); while (tptr < pptr + len) { - switch (af<<8 | safi) { - case (AFNUM_INET<<8 | SAFNUM_UNICAST): - case (AFNUM_INET<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): - if (add_path4) { - path_id = EXTRACT_BE_U_4(tptr); - tptr += 4; - } - advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - if (add_path4) { - ND_PRINT(" Path Id: %u", path_id); - } - break; - case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): - advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET6<<8 | SAFNUM_UNICAST): - case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): - if (add_path6) { - path_id = EXTRACT_BE_U_4(tptr); - tptr += 4; - } - advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - if (add_path6) { - ND_PRINT(" Path Id: %u", path_id); - } - break; - case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): - advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else if (advance == -3) - break; /* bytes left, but not enough */ - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_VPLS<<8 | SAFNUM_VPLS): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): - advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): - case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): - advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET<<8 | SAFNUM_MDT): - advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ - case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): - advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) - goto trunc; - else - ND_PRINT("\n\t %s", buf); - break; - default: - ND_TCHECK_LEN(tptr - 3, tlen); - ND_PRINT("no AFI %u / SAFI %u decoder", af, safi); - if (ndo->ndo_vflag <= 1) - print_unknown_data(ndo, tptr-3, "\n\t ", tlen); - advance = 0; - tptr = pptr + len; - break; - } + advance = bgp_nlri_print(ndo, af, safi, tptr, len, buf, sizeof(buf), + add_path4, add_path6); + if (advance == -2) + goto trunc; if (advance < 0) break; tptr += advance; @@ -2272,7 +2167,7 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_2(tptr); if (tlen < 2) goto trunc; - extd_comm=EXTRACT_BE_U_2(tptr); + extd_comm=GET_BE_U_2(tptr); ND_PRINT("\n\t %s (0x%04x), Flags [%s]", tok2str(bgp_extd_comm_subtype_values, @@ -2298,15 +2193,15 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_5(tptr); if (tlen < 5) goto trunc; - flags = EXTRACT_U_1(tptr); - tunnel_type = EXTRACT_U_1(tptr + 1); + flags = GET_U_1(tptr); + tunnel_type = GET_U_1(tptr + 1); tlen = len; ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u", tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type), tunnel_type, bittok2str(bgp_pmsi_flag_values, "none", flags), - EXTRACT_BE_U_3(tptr + 2)>>4); + GET_BE_U_3(tptr + 2)>>4); tptr +=5; tlen -= 5; @@ -2336,13 +2231,13 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_8(tptr); ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x", ipaddr_string(ndo, tptr), - EXTRACT_BE_U_4(tptr + 4)); + GET_BE_U_4(tptr + 4)); break; case BGP_PMSI_TUNNEL_RSVP_P2MP: ND_TCHECK_8(tptr); ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x", ipaddr_string(ndo, tptr), - EXTRACT_BE_U_4(tptr + 4)); + GET_BE_U_4(tptr + 4)); break; default: if (ndo->ndo_vflag <= 1) { @@ -2362,8 +2257,8 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK_3(tptr); - type = EXTRACT_U_1(tptr); - length = EXTRACT_BE_U_2(tptr + 1); + type = GET_U_1(tptr); + length = GET_BE_U_2(tptr + 1); tptr += 3; tlen -= 3; @@ -2388,7 +2283,7 @@ bgp_attr_print(netdissect_options *ndo, if (length < 8) goto trunc; ND_PRINT(", metric %" PRIu64, - EXTRACT_BE_U_8(tptr)); + GET_BE_U_8(tptr)); break; default: @@ -2407,7 +2302,7 @@ bgp_attr_print(netdissect_options *ndo, if (len < 4) goto trunc; ND_PRINT("\n\t Origin AS: %s", - as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_4(tptr))); + as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(tptr))); tptr += 4; len -= 4; @@ -2420,8 +2315,8 @@ bgp_attr_print(netdissect_options *ndo, tptr += len; break; } - aflags = EXTRACT_U_1(tptr); - atype = EXTRACT_U_1(tptr + 1); + aflags = GET_U_1(tptr); + atype = GET_U_1(tptr + 1); tptr += 2; len -= 2; alenlen = bgp_attr_lenlen(aflags, tptr); @@ -2474,9 +2369,9 @@ bgp_attr_print(netdissect_options *ndo, while (len != 0) { ND_TCHECK_LEN(tptr, 12); ND_PRINT("%u:%u:%u%s", - EXTRACT_BE_U_4(tptr), - EXTRACT_BE_U_4(tptr + 4), - EXTRACT_BE_U_4(tptr + 8), + GET_BE_U_4(tptr), + GET_BE_U_4(tptr + 4), + GET_BE_U_4(tptr + 8), (len > 12) ? ", " : ""); tptr += 12; /* @@ -2493,6 +2388,7 @@ bgp_attr_print(netdissect_options *ndo, print_unknown_data(ndo, pptr, "\n\t ", len); break; } +done: if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/ ND_TCHECK_LEN(pptr, len); print_unknown_data(ndo, pptr, "\n\t ", len); @@ -2512,8 +2408,8 @@ bgp_capabilities_print(netdissect_options *ndo, while (i < caps_len) { ND_TCHECK_LEN(opt + i, BGP_CAP_HEADER_SIZE); - cap_type=EXTRACT_U_1(opt + i); - cap_len=EXTRACT_U_1(opt + i + 1); + cap_type=GET_U_1(opt + i); + cap_len=GET_U_1(opt + i + 1); ND_PRINT("\n\t %s (%u), length: %u", tok2str(bgp_capcode_values, "Unknown", cap_type), cap_type, @@ -2527,10 +2423,26 @@ bgp_capabilities_print(netdissect_options *ndo, return; } ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)", - tok2str(af_values, "Unknown", EXTRACT_BE_U_2(opt + i + 2)), - EXTRACT_BE_U_2(opt + i + 2), - tok2str(bgp_safi_values, "Unknown", EXTRACT_U_1(opt + i + 5)), - EXTRACT_U_1(opt + i + 5)); + tok2str(af_values, "Unknown", GET_BE_U_2(opt + i + 2)), + GET_BE_U_2(opt + i + 2), + tok2str(bgp_safi_values, "Unknown", GET_U_1(opt + i + 5)), + GET_U_1(opt + i + 5)); + break; + case BGP_CAPCODE_ML: + cap_offset = 2; + tcap_len = cap_len; + while (tcap_len >= 4) { + ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u", + tok2str(af_values, "Unknown", + GET_BE_U_2(opt + i + cap_offset)), + GET_BE_U_2(opt + i + cap_offset), + tok2str(bgp_safi_values, "Unknown", + GET_U_1(opt + i + cap_offset + 2)), + GET_U_1(opt + i + cap_offset + 2), + GET_U_1(opt + i + cap_offset + 3)); + tcap_len -= 4; + cap_offset += 4; + } break; case BGP_CAPCODE_RESTART: /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */ @@ -2540,19 +2452,19 @@ bgp_capabilities_print(netdissect_options *ndo, } tcap_len=cap_len; ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us", - ((EXTRACT_U_1(opt + i + 2))&0x80) ? "R" : "none", - EXTRACT_BE_U_2(opt + i + 2)&0xfff); + ((GET_U_1(opt + i + 2))&0x80) ? "R" : "none", + GET_BE_U_2(opt + i + 2)&0xfff); tcap_len-=2; cap_offset=4; while(tcap_len>=4) { ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s", tok2str(af_values,"Unknown", - EXTRACT_BE_U_2(opt + i + cap_offset)), - EXTRACT_BE_U_2(opt + i + cap_offset), + GET_BE_U_2(opt + i + cap_offset)), + GET_BE_U_2(opt + i + cap_offset), tok2str(bgp_safi_values,"Unknown", - EXTRACT_U_1(opt + i + cap_offset + 2)), - EXTRACT_U_1(opt + (i + cap_offset + 2)), - ((EXTRACT_U_1(opt + (i + cap_offset + 3)))&0x80) ? "yes" : "no" ); + GET_U_1(opt + i + cap_offset + 2)), + GET_U_1(opt + (i + cap_offset + 2)), + ((GET_U_1(opt + (i + cap_offset + 3)))&0x80) ? "yes" : "no" ); tcap_len -= 4; cap_offset += 4; } @@ -2570,7 +2482,7 @@ bgp_capabilities_print(netdissect_options *ndo, } ND_PRINT("\n\t\t 4 Byte AS %s", as_printf(ndo, astostr, sizeof(astostr), - EXTRACT_BE_U_4(opt + i + 2))); + GET_BE_U_4(opt + i + 2))); break; case BGP_CAPCODE_ADD_PATH: if (cap_len == 0) { @@ -2585,11 +2497,11 @@ bgp_capabilities_print(netdissect_options *ndo, break; } ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s", - tok2str(af_values,"Unknown",EXTRACT_BE_U_2(opt + i + cap_offset)), - EXTRACT_BE_U_2(opt + i + cap_offset), - tok2str(bgp_safi_values,"Unknown",EXTRACT_U_1(opt + i + cap_offset + 2)), - EXTRACT_U_1(opt + (i + cap_offset + 2)), - tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",EXTRACT_U_1(opt + i + cap_offset + 3)) + tok2str(af_values,"Unknown",GET_BE_U_2(opt + i + cap_offset)), + GET_BE_U_2(opt + i + cap_offset), + tok2str(bgp_safi_values,"Unknown",GET_U_1(opt + i + cap_offset + 2)), + GET_U_1(opt + (i + cap_offset + 2)), + tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",GET_U_1(opt + i + cap_offset + 3)) ); tcap_len -= 4; cap_offset += 4; @@ -2631,13 +2543,13 @@ bgp_open_print(netdissect_options *ndo, bgp_open_header = (const struct bgp_open *)dat; ND_PRINT("\n\t Version %u, ", - EXTRACT_U_1(bgp_open_header->bgpo_version)); + GET_U_1(bgp_open_header->bgpo_version)); ND_PRINT("my AS %s, ", - as_printf(ndo, astostr, sizeof(astostr), EXTRACT_BE_U_2(bgp_open_header->bgpo_myas))); + as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_2(bgp_open_header->bgpo_myas))); ND_PRINT("Holdtime %us, ", - EXTRACT_BE_U_2(bgp_open_header->bgpo_holdtime)); + GET_BE_U_2(bgp_open_header->bgpo_holdtime)); ND_PRINT("ID %s", ipaddr_string(ndo, bgp_open_header->bgpo_id)); - optslen = EXTRACT_U_1(bgp_open_header->bgpo_optlen); + optslen = GET_U_1(bgp_open_header->bgpo_optlen); ND_PRINT("\n\t Optional parameters, length: %u", optslen); opt = dat + BGP_OPEN_SIZE; @@ -2651,8 +2563,8 @@ bgp_open_print(netdissect_options *ndo, if (length < BGP_OPT_SIZE + i) goto trunc; bgpopt = (const struct bgp_opt *)(opt + i); - opt_type = EXTRACT_U_1(bgpopt->bgpopt_type); - opt_len = EXTRACT_U_1(bgpopt->bgpopt_len); + opt_type = GET_U_1(bgpopt->bgpopt_type); + opt_len = GET_U_1(bgpopt->bgpopt_len); if (BGP_OPT_SIZE + i + opt_len > optslen) { ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options", opt_type, opt_len); @@ -2708,7 +2620,7 @@ bgp_update_print(netdissect_options *ndo, ND_TCHECK_2(p); if (length < 2) goto trunc; - withdrawn_routes_len = EXTRACT_BE_U_2(p); + withdrawn_routes_len = GET_BE_U_2(p); p += 2; length -= 2; if (withdrawn_routes_len > 1) { @@ -2729,7 +2641,7 @@ bgp_update_print(netdissect_options *ndo, length -= withdrawn_routes_len; break; } - path_id = EXTRACT_BE_U_4(p); + path_id = GET_BE_U_4(p); p += 4; length -= 4; withdrawn_routes_len -= 4; @@ -2763,7 +2675,7 @@ bgp_update_print(netdissect_options *ndo, ND_TCHECK_2(p); if (length < 2) goto trunc; - len = EXTRACT_BE_U_2(p); + len = GET_BE_U_2(p); p += 2; length -= 2; @@ -2776,7 +2688,8 @@ bgp_update_print(netdissect_options *ndo, if (len) { /* do something more useful!*/ while (len) { - u_int aflags, atype, alenlen, alen; + uint8_t aflags, atype, alenlen; + uint16_t alen; ND_TCHECK_2(p); if (length < 2) @@ -2787,8 +2700,8 @@ bgp_update_print(netdissect_options *ndo, length -= len; break; } - aflags = EXTRACT_U_1(p); - atype = EXTRACT_U_1(p + 1); + aflags = GET_U_1(p); + atype = GET_U_1(p + 1); p += 2; len -= 2; length -= 2; @@ -2846,7 +2759,7 @@ bgp_update_print(netdissect_options *ndo, ND_TCHECK_4(p); if (length < 4) goto trunc; - path_id = EXTRACT_BE_U_4(p); + path_id = GET_BE_U_4(p); p += 4; length -= 4; } @@ -2888,8 +2801,8 @@ bgp_notification_print(netdissect_options *ndo, return; bgp_notification_header = (const struct bgp_notification *)dat; - bgpn_major = EXTRACT_U_1(bgp_notification_header->bgpn_major); - bgpn_minor = EXTRACT_U_1(bgp_notification_header->bgpn_minor); + bgpn_major = GET_U_1(bgp_notification_header->bgpn_major); + bgpn_minor = GET_U_1(bgp_notification_header->bgpn_minor); ND_PRINT(", %s (%u)", tok2str(bgp_notify_major_values, "Unknown Error", @@ -2941,11 +2854,11 @@ bgp_notification_print(netdissect_options *ndo, tptr = dat + BGP_NOTIFICATION_SIZE; ND_TCHECK_7(tptr); ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u", - tok2str(af_values, "Unknown", EXTRACT_BE_U_2(tptr)), - EXTRACT_BE_U_2(tptr), - tok2str(bgp_safi_values, "Unknown", EXTRACT_U_1((tptr + 2))), - EXTRACT_U_1((tptr + 2)), - EXTRACT_BE_U_4(tptr + 3)); + tok2str(af_values, "Unknown", GET_BE_U_2(tptr)), + GET_BE_U_2(tptr), + tok2str(bgp_safi_values, "Unknown", GET_U_1((tptr + 2))), + GET_U_1((tptr + 2)), + GET_BE_U_4(tptr + 3)); } /* * draft-ietf-idr-shutdown describes a method to send a communication @@ -2956,7 +2869,7 @@ bgp_notification_print(netdissect_options *ndo, length >= BGP_NOTIFICATION_SIZE + 1) { tptr = dat + BGP_NOTIFICATION_SIZE; ND_TCHECK_1(tptr); - shutdown_comm_length = EXTRACT_U_1(tptr); + shutdown_comm_length = GET_U_1(tptr); remainder_offset = 0; /* garbage, hexdump it all */ if (shutdown_comm_length > BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN || @@ -3007,11 +2920,11 @@ bgp_route_refresh_print(netdissect_options *ndo, ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u)", tok2str(af_values,"Unknown", - EXTRACT_BE_U_2(bgp_route_refresh_header->afi)), - EXTRACT_BE_U_2(bgp_route_refresh_header->afi), + GET_BE_U_2(bgp_route_refresh_header->afi)), + GET_BE_U_2(bgp_route_refresh_header->afi), tok2str(bgp_safi_values,"Unknown", - EXTRACT_U_1(bgp_route_refresh_header->safi)), - EXTRACT_U_1(bgp_route_refresh_header->safi)); + GET_U_1(bgp_route_refresh_header->safi)), + GET_U_1(bgp_route_refresh_header->safi)); if (ndo->ndo_vflag > 1) { ND_TCHECK_LEN(pptr, len); @@ -3032,7 +2945,7 @@ bgp_pdu_print(netdissect_options *ndo, ND_TCHECK_LEN(dat, BGP_SIZE); bgp_header = (const struct bgp *)dat; - bgp_type = EXTRACT_U_1(bgp_header->bgp_type); + bgp_type = GET_U_1(bgp_header->bgp_type); ND_PRINT("\n\t%s Message (%u), length: %u", tok2str(bgp_msg_values, "Unknown", bgp_type), @@ -3092,7 +3005,7 @@ bgp_print(netdissect_options *ndo, while (p < ep) { if (!ND_TTEST_1(p)) break; - if (EXTRACT_U_1(p) != 0xff) { + if (GET_U_1(p) != 0xff) { p++; continue; } @@ -3111,7 +3024,7 @@ bgp_print(netdissect_options *ndo, if (start != p) nd_print_trunc(ndo); - hlen = EXTRACT_BE_U_2(bgp_header->bgp_len); + hlen = GET_BE_U_2(bgp_header->bgp_len); if (hlen < BGP_SIZE) { ND_PRINT("\nmessage length %u < %u", hlen, BGP_SIZE); nd_print_invalid(ndo); @@ -3127,7 +3040,7 @@ bgp_print(netdissect_options *ndo, ND_PRINT("\n[|BGP %s]", tok2str(bgp_msg_values, "Unknown Message Type", - EXTRACT_U_1(bgp_header->bgp_type))); + GET_U_1(bgp_header->bgp_type))); break; } }