X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e4c03ecd3b5e27294f38363caf064453740453a9..refs/pull/482/head:/print-bgp.c diff --git a/print-bgp.c b/print-bgp.c index 7c722999..fd25ba84 100644 --- a/print-bgp.c +++ b/print-bgp.c @@ -34,12 +34,12 @@ #include "config.h" #endif -#include +#include #include #include -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" #include "af.h" @@ -603,12 +603,10 @@ bgp_vpn_ip_print(netdissect_options *ndo, ND_TCHECK2(pptr[0], sizeof(struct in_addr)); snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr)); break; -#ifdef INET6 case (sizeof(struct in6_addr) << 3): /* 128 */ ND_TCHECK2(pptr[0], sizeof(struct in6_addr)); snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr)); break; -#endif default: snprintf(pos, sizeof(addr), "bogus address length %u", addr_length); break; @@ -968,21 +966,21 @@ trunc: * the buffer would have overflowed; again, set buflen to 0 in * that case. */ -#define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \ - if (strlen<0) \ +#define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \ + if (stringlen<0) \ buflen=0; \ - else if ((u_int)strlen>buflen) \ + else if ((u_int)stringlen>buflen) \ buflen=0; \ else { \ - buflen-=strlen; \ - buf+=strlen; \ + buflen-=stringlen; \ + buf+=stringlen; \ } static int decode_labeled_vpn_l2(netdissect_options *ndo, const u_char *pptr, char *buf, u_int buflen) { - int plen,tlen,strlen,tlv_type,tlv_len,ttlv_len; + int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len; ND_TCHECK2(pptr[0], 2); plen=EXTRACT_16BITS(pptr); @@ -996,12 +994,12 @@ decode_labeled_vpn_l2(netdissect_options *ndo, /* assume AD-only with RD, BGPNH */ ND_TCHECK2(pptr[0],12); buf[0]='\0'; - strlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s", - bgp_vpn_rd_print(ndo, pptr), - /* need something like getname(ndo, ) here */ - getname(ndo, pptr+8) - ); - UPDATE_BUF_BUFLEN(buf, buflen, strlen); + stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s", + bgp_vpn_rd_print(ndo, pptr), + /* need something like getname(ndo, ) here */ + getname(ndo, pptr+8) + ); + UPDATE_BUF_BUFLEN(buf, buflen, stringlen); pptr+=12; tlen-=12; return plen; @@ -1011,12 +1009,12 @@ decode_labeled_vpn_l2(netdissect_options *ndo, ND_TCHECK2(pptr[0],15); buf[0]='\0'; - strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", - bgp_vpn_rd_print(ndo, pptr), - EXTRACT_16BITS(pptr+8), - EXTRACT_16BITS(pptr+10), - EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ - UPDATE_BUF_BUFLEN(buf, buflen, strlen); + stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", + bgp_vpn_rd_print(ndo, pptr), + EXTRACT_16BITS(pptr+8), + EXTRACT_16BITS(pptr+10), + EXTRACT_24BITS(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; @@ -1033,27 +1031,27 @@ decode_labeled_vpn_l2(netdissect_options *ndo, switch(tlv_type) { case 1: if (buflen!=0) { - strlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", - tlv_type, - tlv_len); - UPDATE_BUF_BUFLEN(buf, buflen, strlen); + stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", + tlv_type, + tlv_len); + UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */ while (ttlv_len>0) { ND_TCHECK(pptr[0]); if (buflen!=0) { - strlen=snprintf(buf,buflen, "%02x",*pptr++); - UPDATE_BUF_BUFLEN(buf, buflen, strlen); + stringlen=snprintf(buf,buflen, "%02x",*pptr++); + UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } ttlv_len--; } break; default: if (buflen!=0) { - strlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", - tlv_type, - tlv_len); - UPDATE_BUF_BUFLEN(buf, buflen, strlen); + stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", + tlv_type, + tlv_len); + UPDATE_BUF_BUFLEN(buf, buflen, stringlen); } break; } @@ -1071,7 +1069,6 @@ trunc: return -2; } -#ifdef INET6 int decode_prefix6(netdissect_options *ndo, const u_char *pd, u_int itemlen, char *buf, u_int buflen) @@ -1188,7 +1185,6 @@ decode_labeled_vpn_prefix6(netdissect_options *ndo, trunc: return -2; } -#endif static int decode_clnp_prefix(netdissect_options *ndo, @@ -1211,7 +1207,7 @@ decode_clnp_prefix(netdissect_options *ndo, ((0xff00 >> (plen % 8)) & 0xff); } snprintf(buf, buflen, "%s/%d", - isonsap_string(addr,(plen + 7) / 8), + isonsap_string(ndo, addr,(plen + 7) / 8), plen); return 1 + (plen + 7) / 8; @@ -1248,7 +1244,7 @@ decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, /* the label may get offsetted by 4 bits so lets shift it right */ snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s", bgp_vpn_rd_print(ndo, pptr+4), - isonsap_string(addr,(plen + 7) / 8), + isonsap_string(ndo, addr,(plen + 7) / 8), plen, EXTRACT_24BITS(pptr+1)>>4, ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" ); @@ -1520,7 +1516,6 @@ bgp_attr_print(netdissect_options *ndo, case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): case (AFNUM_INET<<8 | SAFNUM_MDT): -#ifdef INET6 case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): @@ -1528,7 +1523,6 @@ bgp_attr_print(netdissect_options *ndo, case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): -#endif case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): @@ -1596,7 +1590,6 @@ bgp_attr_print(netdissect_options *ndo, tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN); } break; -#ifdef INET6 case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): @@ -1626,7 +1619,6 @@ bgp_attr_print(netdissect_options *ndo, tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN); } break; -#endif case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): @@ -1645,7 +1637,7 @@ bgp_attr_print(netdissect_options *ndo, case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): ND_TCHECK2(tptr[0], tlen); - ND_PRINT((ndo, "%s", isonsap_string(tptr, tlen))); + ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen))); tptr += tlen; tlen = 0; break; @@ -1660,15 +1652,13 @@ bgp_attr_print(netdissect_options *ndo, ND_TCHECK2(tptr[0], tlen); ND_PRINT((ndo, "RD: %s, %s", bgp_vpn_rd_print(ndo, tptr), - isonsap_string(tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN))); + isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN))); /* rfc986 mapped IPv4 address ? */ if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601) ND_PRINT((ndo, " = %s", getname(ndo, tptr+BGP_VPN_RD_LEN+4))); -#ifdef INET6 /* rfc1888 mapped IPv6 address ? */ else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000) ND_PRINT((ndo, " = %s", getname6(ndo, tptr+BGP_VPN_RD_LEN+3))); -#endif tptr += tlen; tlen = 0; } @@ -1769,7 +1759,6 @@ bgp_attr_print(netdissect_options *ndo, else ND_PRINT((ndo, "\n\t %s", buf)); break; -#ifdef INET6 case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): @@ -1805,7 +1794,6 @@ bgp_attr_print(netdissect_options *ndo, else ND_PRINT((ndo, "\n\t %s", buf)); break; -#endif case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): @@ -1910,7 +1898,6 @@ bgp_attr_print(netdissect_options *ndo, else ND_PRINT((ndo, "\n\t %s", buf)); break; -#ifdef INET6 case (AFNUM_INET6<<8 | SAFNUM_UNICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): @@ -1946,7 +1933,6 @@ bgp_attr_print(netdissect_options *ndo, else ND_PRINT((ndo, "\n\t %s", buf)); break; -#endif case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): @@ -2160,8 +2146,8 @@ bgp_attr_print(netdissect_options *ndo, } case BGPTYPE_AIGP: { - u_int8_t type; - u_int16_t length; + uint8_t type; + uint16_t length; ND_TCHECK2(tptr[0], 3); @@ -2211,7 +2197,7 @@ bgp_attr_print(netdissect_options *ndo, len -=4; while (len) { - u_int aflags, atype, alenlen, alen; + u_int aflags, alenlen, alen; ND_TCHECK2(tptr[0], 2); if (len < 2) @@ -2339,7 +2325,7 @@ bgp_capabilities_print(netdissect_options *ndo, } while (tcap_len > 0) { if (tcap_len < 4) { - ND_PRINT((ndo, "\n\t\t(malformed)")); + ND_PRINT((ndo, "\n\t\t(invalid)")); break; } ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s", @@ -2443,10 +2429,6 @@ bgp_update_print(netdissect_options *ndo, int withdrawn_routes_len; int len; int i; -#ifndef INET6 - char buf[MAXHOSTNAMELEN + 100]; - int wpfx; -#endif ND_TCHECK2(dat[0], BGP_SIZE); if (length < BGP_SIZE) @@ -2471,36 +2453,9 @@ bgp_update_print(netdissect_options *ndo, ND_TCHECK2(p[0], withdrawn_routes_len); if (length < withdrawn_routes_len) goto trunc; -#ifdef INET6 ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len)); p += withdrawn_routes_len; length -= withdrawn_routes_len; -#else - if (withdrawn_routes_len < 2) - goto trunc; - length -= 2; - withdrawn_routes_len -= 2; - - - ND_PRINT((ndo, "\n\t Withdrawn routes:")); - - while(withdrawn_routes_len > 0) { - wpfx = decode_prefix4(ndo, p, withdrawn_routes_len, buf, sizeof(buf)); - if (wpfx == -1) { - ND_PRINT((ndo, "\n\t (illegal prefix length)")); - break; - } else if (wpfx == -2) - goto trunc; - else if (wpfx == -3) - goto trunc; /* bytes left, but not enough */ - else { - ND_PRINT((ndo, "\n\t %s", buf)); - p += wpfx; - length -= wpfx; - withdrawn_routes_len -= wpfx; - } - } -#endif } ND_TCHECK2(p[0], 2);