X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/70d569cd84432ac2cec00bbf5b17b325b697754f..cc2d4cbd8ca150504127f375d8b51b194958d95b:/print-bgp.c diff --git a/print-bgp.c b/print-bgp.c index c7aaba2e..6f523585 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -131,20 +131,20 @@ struct bgp_route_refresh { #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */ #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */ #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */ -#define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */ -#define BGPTYPE_AS4_PATH 17 /* RFC6793 */ -#define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */ -#define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */ -#define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */ -#define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */ -#define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */ -#define BGPTYPE_AIGP 26 /* RFC7311 */ -#define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */ -#define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */ -#define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */ -#define BGPTYPE_ATTR_SET 128 /* RFC6368 */ - -#define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */ +#define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */ +#define BGPTYPE_AS4_PATH 17 /* RFC6793 */ +#define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */ +#define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */ +#define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */ +#define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */ +#define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */ +#define BGPTYPE_AIGP 26 /* RFC7311 */ +#define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */ +#define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */ +#define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */ +#define BGPTYPE_ATTR_SET 128 /* RFC6368 */ + +#define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */ static const struct tok bgp_attr_values[] = { { BGPTYPE_ORIGIN, "Origin"}, @@ -410,7 +410,7 @@ static const struct tok bgp_safi_values[] = { #define BGP_COMMUNITY_NO_ADVERT 0xffffff02 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 -/* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */ +/* Extended community type - RFC 4360 */ #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */ #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */ #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */ @@ -468,12 +468,12 @@ static const struct tok bgp_extd_comm_subtype_values[] = { { BGP_EXT_COM_OSPF_RID, "ospf-router-id"}, { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"}, { BGP_EXT_COM_L2INFO, "layer2-info"}, - { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" }, - { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" }, - { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" }, - { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" }, - { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" }, - { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" }, + { BGP_EXT_COM_EIGRP_GEN, "eigrp-general-route (flag, tag)" }, + { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY, "eigrp-route-metric (AS, delay)" }, + { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW, "eigrp-route-metric (reliability, nexthop, bandwidth)" }, + { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU, "eigrp-route-metric (load, MTU)" }, + { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID, "eigrp-external-route (remote-AS, remote-ID)" }, + { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC, "eigrp-external-route (remote-proto, remote-metric)" }, { BGP_EXT_COM_SOURCE_AS, "source-AS" }, { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"}, { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"}, @@ -713,9 +713,7 @@ trunc: return (total_length); } -/* RDs and RTs share the same semantics - * we use bgp_vpn_rd_print for - * printing route targets inside a NLRI */ +/* Print an RFC 4364 Route Distinguisher */ const char * bgp_vpn_rd_print(netdissect_options *ndo, const u_char *pptr) @@ -727,30 +725,30 @@ bgp_vpn_rd_print(netdissect_options *ndo, /* ok lets load the RD format */ switch (EXTRACT_BE_U_2(pptr)) { - /* 2-byte-AS:number fmt*/ 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)); + 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)); break; - /* IP-address:AS fmt*/ 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)); + 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)); break; - /* 4-byte-AS:number fmt*/ 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)); + 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)); break; default: nd_snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format"); @@ -761,11 +759,101 @@ bgp_vpn_rd_print(netdissect_options *ndo, return (rd); } +/* + * Print an RFC 4360 Extended Community. + */ +static void +bgp_extended_community_print(netdissect_options *ndo, + const u_char *pptr) +{ + union { /* copy buffer for bandwidth values */ + float f; + uint32_t i; + } bw; + + switch (EXTRACT_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), + ipaddr_string(ndo, pptr+4)); + break; + + case BGP_EXT_COM_RT_1: + case BGP_EXT_COM_RO_1: + case BGP_EXT_COM_L2VPN_RT_1: + case BGP_EXT_COM_VRF_RT_IMP: + ND_PRINT("%s:%u", + ipaddr_string(ndo, pptr+2), + EXTRACT_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)); + break; + + case BGP_EXT_COM_LINKBAND: + bw.i = EXTRACT_BE_U_4(pptr + 2); + ND_PRINT("bandwidth: %.3f Mbps", + bw.f*8/1000000); + break; + + case BGP_EXT_COM_VPN_ORIGIN: + case BGP_EXT_COM_VPN_ORIGIN2: + case BGP_EXT_COM_VPN_ORIGIN3: + case BGP_EXT_COM_VPN_ORIGIN4: + case BGP_EXT_COM_OSPF_RID: + case BGP_EXT_COM_OSPF_RID2: + ND_PRINT("%s", ipaddr_string(ndo, pptr+2)); + break; + + case BGP_EXT_COM_OSPF_RTYPE: + case BGP_EXT_COM_OSPF_RTYPE2: + ND_PRINT("area:%s, router-type:%s, metric-type:%s%s", + 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" : ""); + 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)); + break; + + case BGP_EXT_COM_SOURCE_AS: + ND_PRINT("AS %u", EXTRACT_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)); + break; + } +} + +/* RFC 4684 */ static int decode_rt_routing_info(netdissect_options *ndo, - const u_char *pptr, char *buf, u_int buflen) + const u_char *pptr) { - uint8_t route_target[8]; u_int plen; char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */ @@ -779,12 +867,14 @@ decode_rt_routing_info(netdissect_options *ndo, */ if (0 == plen) { /* Without "origin AS", without "route target". */ - nd_snprintf(buf, buflen, "default route target"); + ND_PRINT("\n\t default route target"); return 1; } - if (32 > plen) + if (32 > plen) { + ND_PRINT("\n\t (illegal prefix length)"); return -1; + } /* With at least "origin AS", possibly with "route target". */ ND_TCHECK_4(pptr + 1); @@ -792,26 +882,18 @@ decode_rt_routing_info(netdissect_options *ndo, plen -= 32; /* adjust prefix length */ - if (64 < plen) - return -1; - - /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 } - * and gives the number of octets in the variable-length "route - * target" field inside this NLRI "prefix". Look for it. + /* An extended community is 8 octets, so the remaining prefix + * length must be 64. */ - memset(&route_target, 0, sizeof(route_target)); - ND_TCHECK_LEN(pptr + 5, (plen + 7) / 8); - memcpy(&route_target, pptr + 5, (plen + 7) / 8); - /* Which specification says to do this? */ - if (plen % 8) { - ((u_char *)&route_target)[(plen + 7) / 8 - 1] &= - ((0xff00 >> (plen % 8)) & 0xff); + if (64 != plen) { + ND_PRINT("\n\t (illegal prefix length)"); + return -1; } - nd_snprintf(buf, buflen, "origin AS: %s, route target %s", - asbuf, - bgp_vpn_rd_print(ndo, (u_char *)&route_target)); + ND_TCHECK_LEN(pptr + 5, 8); + ND_PRINT("\n\t origin AS: %s, route target ", asbuf); + bgp_extended_community_print(ndo, pptr + 5); - return 5 + (plen + 7) / 8; + return 5 + 8; trunc: return -2; @@ -844,11 +926,11 @@ decode_labeled_vpn_prefix4(netdissect_options *ndo, } /* the label may get offsetted by 4 bits so lets shift it right */ nd_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)" ); + 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)" ); return 12 + (plen + 7) / 8; @@ -896,7 +978,7 @@ decode_mdt_vpn_nlri(netdissect_options *ndo, ND_TCHECK_LEN(pptr, sizeof(nd_ipv4)); nd_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)); + bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr)); return MDT_VPN_NLRI_LEN + 1; @@ -947,9 +1029,9 @@ decode_multicast_vpn(netdissect_options *ndo, ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); offset = strlen(buf); nd_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)); + 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); @@ -964,7 +1046,7 @@ decode_multicast_vpn(netdissect_options *ndo, ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN); offset = strlen(buf); nd_snprintf(buf + offset, buflen - offset, ", RD: %s", - bgp_vpn_rd_print(ndo, pptr)); + bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen); @@ -973,14 +1055,14 @@ decode_multicast_vpn(netdissect_options *ndo, ND_TCHECK_LEN(pptr, addr_length); offset = strlen(buf); nd_snprintf(buf + offset, buflen - offset, ", Originator %s", - bgp_vpn_ip_print(ndo, pptr, addr_length << 3)); + 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", - bgp_vpn_rd_print(ndo, pptr)); + bgp_vpn_rd_print(ndo, pptr)); pptr += BGP_VPN_RD_LEN; bgp_vpn_sg_print(ndo, pptr, buf, buflen); @@ -991,9 +1073,9 @@ decode_multicast_vpn(netdissect_options *ndo, ND_TCHECK_LEN(pptr, BGP_VPN_RD_LEN + 4); offset = strlen(buf); nd_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))); + bgp_vpn_rd_print(ndo, pptr), + as_printf(ndo, astostr, sizeof(astostr), + EXTRACT_BE_U_4(pptr + BGP_VPN_RD_LEN))); pptr += BGP_VPN_RD_LEN + 4; bgp_vpn_sg_print(ndo, pptr, buf, buflen); @@ -1053,8 +1135,8 @@ decode_labeled_vpn_l2(netdissect_options *ndo, ND_TCHECK_LEN(pptr, 12); buf[0] = '\0'; stringlen = nd_snprintf(buf, buflen, "RD: %s, BGPNH: %s", - bgp_vpn_rd_print(ndo, pptr), - ipaddr_string(ndo, pptr+8)); + bgp_vpn_rd_print(ndo, pptr), + ipaddr_string(ndo, pptr+8)); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr += 12; tlen -= 12; @@ -1066,10 +1148,10 @@ 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", - 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 */ + 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 */ UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr += 15; tlen -= 15; @@ -1094,8 +1176,8 @@ decode_labeled_vpn_l2(netdissect_options *ndo, case 1: if (buflen != 0) { stringlen=nd_snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", - tlv_type, - tlv_len); + tlv_type, + tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } while (ttlv_len != 0) { @@ -1109,7 +1191,7 @@ decode_labeled_vpn_l2(netdissect_options *ndo, ND_TCHECK_1(pptr); if (buflen != 0) { stringlen=nd_snprintf(buf,buflen, "%02x", - EXTRACT_U_1(pptr)); + EXTRACT_U_1(pptr)); pptr++; UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } @@ -1120,8 +1202,8 @@ decode_labeled_vpn_l2(netdissect_options *ndo, default: if (buflen != 0) { stringlen=nd_snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", - tlv_type, - tlv_len); + tlv_type, + tlv_len); UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } if (tlen < ttlv_len) { @@ -1210,10 +1292,10 @@ decode_labeled_prefix6(netdissect_options *ndo, } /* the label may get offsetted by 4 bits so lets shift it right */ nd_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)" ); + 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)" ); return 4 + plenbytes; @@ -1251,11 +1333,11 @@ decode_labeled_vpn_prefix6(netdissect_options *ndo, } /* the label may get offsetted by 4 bits so lets shift it right */ nd_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)" ); + 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)" ); return 12 + (plen + 7) / 8; @@ -1284,8 +1366,8 @@ decode_clnp_prefix(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } nd_snprintf(buf, buflen, "%s/%u", - isonsap_string(ndo, addr,(plen + 7) / 8), - plen); + isonsap_string(ndo, addr,(plen + 7) / 8), + plen); return 1 + (plen + 7) / 8; @@ -1319,11 +1401,11 @@ decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, } /* the label may get offsetted by 4 bits so lets shift it right */ nd_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)" ); + 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)" ); return 12 + (plen + 7) / 8; @@ -1463,10 +1545,6 @@ bgp_attr_print(netdissect_options *ndo, u_int i; uint16_t af; uint8_t safi, snpa, nhlen; - union { /* copy buffer for bandwidth values */ - float f; - uint32_t i; - } bw; int advance; u_int tlen; const u_char *tptr; @@ -1894,13 +1972,9 @@ bgp_attr_print(netdissect_options *ndo, ND_PRINT("\n\t %s", buf); break; case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): - advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf)); - if (advance == -1) - ND_PRINT("\n\t (illegal prefix length)"); - else if (advance == -2) + advance = decode_rt_routing_info(ndo, tptr); + 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): @@ -2207,71 +2281,11 @@ bgp_attr_print(netdissect_options *ndo, extd_comm, bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)); - ND_TCHECK_6(tptr + 2); + ND_TCHECK_8(tptr); if (tlen < 8) goto trunc; - switch(extd_comm) { - 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(tptr + 2), - EXTRACT_BE_U_4(tptr + 4), - ipaddr_string(ndo, tptr+4)); - break; - case BGP_EXT_COM_RT_1: - case BGP_EXT_COM_RO_1: - case BGP_EXT_COM_L2VPN_RT_1: - case BGP_EXT_COM_VRF_RT_IMP: - ND_PRINT(": %s:%u", - ipaddr_string(ndo, tptr+2), - EXTRACT_BE_U_2(tptr + 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(tptr + 2)), EXTRACT_BE_U_2(tptr + 6)); - break; - case BGP_EXT_COM_LINKBAND: - bw.i = EXTRACT_BE_U_4(tptr + 2); - ND_PRINT(": bandwidth: %.3f Mbps", - bw.f*8/1000000); - break; - case BGP_EXT_COM_VPN_ORIGIN: - case BGP_EXT_COM_VPN_ORIGIN2: - case BGP_EXT_COM_VPN_ORIGIN3: - case BGP_EXT_COM_VPN_ORIGIN4: - case BGP_EXT_COM_OSPF_RID: - case BGP_EXT_COM_OSPF_RID2: - ND_PRINT("%s", ipaddr_string(ndo, tptr+2)); - break; - case BGP_EXT_COM_OSPF_RTYPE: - case BGP_EXT_COM_OSPF_RTYPE2: - ND_PRINT(": area:%s, router-type:%s, metric-type:%s%s", - ipaddr_string(ndo, tptr+2), - tok2str(bgp_extd_comm_ospf_rtype_values, - "unknown (0x%02x)", - EXTRACT_U_1((tptr + 6))), - (EXTRACT_U_1(tptr + 7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "", - ((EXTRACT_U_1(tptr + 6) == BGP_OSPF_RTYPE_EXT) || (EXTRACT_U_1(tptr + 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((tptr + 2))), - EXTRACT_U_1((tptr + 3)), - EXTRACT_BE_U_2(tptr + 4)); - break; - case BGP_EXT_COM_SOURCE_AS: - ND_PRINT(": AS %u", EXTRACT_BE_U_2(tptr + 2)); - break; - default: - ND_TCHECK_8(tptr); - print_unknown_data(ndo, tptr, "\n\t ", 8); - break; - } + ND_PRINT(": "); + bgp_extended_community_print(ndo, tptr); tlen -= 8; tptr += 8; } @@ -2567,7 +2581,7 @@ bgp_capabilities_print(netdissect_options *ndo, cap_offset=2; while (tcap_len != 0) { if (tcap_len < 4) { - ND_PRINT("\n\t\t(invalid)"); + nd_print_invalid(ndo); break; } ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s", @@ -2710,11 +2724,11 @@ bgp_update_print(netdissect_options *ndo, add_path = check_add_path(ndo, p, withdrawn_routes_len, 32); while (withdrawn_routes_len != 0) { if (add_path) { - if (withdrawn_routes_len < 4) { - p += withdrawn_routes_len; - length -= withdrawn_routes_len; - break; - } + if (withdrawn_routes_len < 4) { + p += withdrawn_routes_len; + length -= withdrawn_routes_len; + break; + } path_id = EXTRACT_BE_U_4(p); p += 4; length -= 4; @@ -3099,8 +3113,8 @@ bgp_print(netdissect_options *ndo, hlen = EXTRACT_BE_U_2(bgp_header->bgp_len); if (hlen < BGP_SIZE) { - ND_PRINT("\n[|BGP Bogus header length %u < %u]", hlen, - BGP_SIZE); + ND_PRINT("\nmessage length %u < %u", hlen, BGP_SIZE); + nd_print_invalid(ndo); break; }