"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "print-bgp.c" between
tcpdump-4.99.0.tar.gz and tcpdump-4.99.1.tar.gz

About: tcpdump is a tool for network monitoring and data acquisition.

print-bgp.c  (tcpdump-4.99.0):print-bgp.c  (tcpdump-4.99.1)
skipping to change at line 560 skipping to change at line 560
}; };
/* ADD-PATH Send/Receive field values */ /* ADD-PATH Send/Receive field values */
static const struct tok bgp_add_path_recvsend[] = { static const struct tok bgp_add_path_recvsend[] = {
{ 1, "Receive" }, { 1, "Receive" },
{ 2, "Send" }, { 2, "Send" },
{ 3, "Both" }, { 3, "Both" },
{ 0, NULL }, { 0, NULL },
}; };
/* allocate space for the largest possible string */ #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
static char astostr[sizeof("xxxxx.xxxxx")];
/* /*
* as_printf * as_printf
* *
* Convert an AS number into a string and return string pointer. * Convert an AS number into a string and return string pointer.
* *
* Depending on bflag is set or not, AS number is converted into ASDOT notation * Depending on bflag is set or not, AS number is converted into ASDOT notation
* or plain number notation. * or plain number notation.
* *
*/ */
skipping to change at line 601 skipping to change at line 600
u_int plen, plenbytes; u_int plen, plenbytes;
ITEMCHECK(1); ITEMCHECK(1);
plen = GET_U_1(pptr); plen = GET_U_1(pptr);
if (32 < plen) if (32 < plen)
return -1; return -1;
itemlen -= 1; itemlen -= 1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
plenbytes = (plen + 7) / 8; plenbytes = (plen + 7) / 8;
ND_TCHECK_LEN(pptr + 1, plenbytes);
ITEMCHECK(plenbytes); ITEMCHECK(plenbytes);
memcpy(&addr, pptr + 1, plenbytes); GET_CPY_BYTES(&addr, pptr + 1, plenbytes);
if (plen % 8) { if (plen % 8) {
((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
} }
snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), pl en); snprintf(buf, buflen, "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), pl en);
return 1 + plenbytes; return 1 + plenbytes;
trunc:
return -2;
badtlv: badtlv:
return -3; return -2;
} }
static int static int
decode_labeled_prefix4(netdissect_options *ndo, decode_labeled_prefix4(netdissect_options *ndo,
const u_char *pptr, u_int itemlen, char *buf, const u_char *pptr, u_int itemlen, char *buf,
size_t buflen) size_t buflen)
{ {
nd_ipv4 addr; nd_ipv4 addr;
u_int plen, plenbytes; u_int plen, plenbytes;
skipping to change at line 649 skipping to change at line 644
return -1; return -1;
plen-=24; /* adjust prefixlen - labellength */ plen-=24; /* adjust prefixlen - labellength */
if (32 < plen) if (32 < plen)
return -1; return -1;
itemlen -= 4; itemlen -= 4;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
plenbytes = (plen + 7) / 8; plenbytes = (plen + 7) / 8;
ND_TCHECK_LEN(pptr + 4, plenbytes);
ITEMCHECK(plenbytes); ITEMCHECK(plenbytes);
memcpy(&addr, pptr + 4, plenbytes); GET_CPY_BYTES(&addr, pptr + 4, plenbytes);
if (plen % 8) { if (plen % 8) {
((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff); ((u_char *)&addr)[plenbytes - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
} }
/* the label may get offsetted by 4 bits so lets shift it right */ /* the label may get offsetted by 4 bits so lets shift it right */
snprintf(buf, buflen, "%s/%u, label:%u %s", snprintf(buf, buflen, "%s/%u, label:%u %s",
ipaddr_string(ndo, (const u_char *)&addr), ipaddr_string(ndo, (const u_char *)&addr),
plen, plen,
GET_BE_U_3(pptr + 1)>>4, GET_BE_U_3(pptr + 1)>>4,
((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!) " : "(bottom)" ); ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!) " : "(bottom)" );
skipping to change at line 769 skipping to change at line 763
} }
/* Print an RFC 4364 Route Distinguisher */ /* Print an RFC 4364 Route Distinguisher */
const char * const char *
bgp_vpn_rd_print(netdissect_options *ndo, bgp_vpn_rd_print(netdissect_options *ndo,
const u_char *pptr) const u_char *pptr)
{ {
/* allocate space for the largest possible string */ /* allocate space for the largest possible string */
static char rd[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")]; static char rd[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
char *pos = rd; char *pos = rd;
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
/* ok lets load the RD format */ /* ok lets load the RD format */
switch (GET_BE_U_2(pptr)) { switch (GET_BE_U_2(pptr)) {
case 0: case 0:
/* 2-byte-AS:number fmt */ /* 2-byte-AS:number fmt */
snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)", snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
GET_BE_U_2(pptr + 2), GET_BE_U_2(pptr + 2),
GET_BE_U_4(pptr + 4), GET_BE_U_4(pptr + 4),
GET_U_1(pptr + 4), GET_U_1(pptr + 5), GET_U_1(pptr + 4), GET_U_1(pptr + 5),
skipping to change at line 818 skipping to change at line 814
* Print an RFC 4360 Extended Community. * Print an RFC 4360 Extended Community.
*/ */
static void static void
bgp_extended_community_print(netdissect_options *ndo, bgp_extended_community_print(netdissect_options *ndo,
const u_char *pptr) const u_char *pptr)
{ {
union { /* copy buffer for bandwidth values */ union { /* copy buffer for bandwidth values */
float f; float f;
uint32_t i; uint32_t i;
} bw; } bw;
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
switch (GET_BE_U_2(pptr)) { switch (GET_BE_U_2(pptr)) {
case BGP_EXT_COM_RT_0: case BGP_EXT_COM_RT_0:
case BGP_EXT_COM_RO_0: case BGP_EXT_COM_RO_0:
case BGP_EXT_COM_L2VPN_RT_0: case BGP_EXT_COM_L2VPN_RT_0:
ND_PRINT("%u:%u (= %s)", ND_PRINT("%u:%u (= %s)",
GET_BE_U_2(pptr + 2), GET_BE_U_2(pptr + 2),
GET_BE_U_4(pptr + 4), GET_BE_U_4(pptr + 4),
GET_IPADDR_STRING(pptr+4)); GET_IPADDR_STRING(pptr+4));
skipping to change at line 923 skipping to change at line 921
*/ */
static char * static char *
bgp_rt_prefix_print(netdissect_options *ndo, bgp_rt_prefix_print(netdissect_options *ndo,
const u_char *pptr, const u_char *pptr,
u_int plen) u_int plen)
{ {
/* allocate space for the largest possible string */ /* allocate space for the largest possible string */
char rtc_prefix_in_hex[20] = ""; char rtc_prefix_in_hex[20] = "";
u_int rtc_prefix_in_hex_len = 0; u_int rtc_prefix_in_hex_len = 0;
static char output[61]; /* max response string */ static char output[61]; /* max response string */
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
uint16_t ec_type = 0; uint16_t ec_type = 0;
u_int octet_count; u_int octet_count;
u_int i; u_int i;
if (plen == 0) { if (plen == 0) {
snprintf(output, sizeof(output), "route-target: 0:0/0"); snprintf(output, sizeof(output), "route-target: 0:0/0");
return (output); return (output);
} }
/* hex representation of the prefix */ /* hex representation of the prefix */
skipping to change at line 996 skipping to change at line 996
return (output); return (output);
} }
/* RFC 4684 */ /* RFC 4684 */
static int static int
decode_rt_routing_info(netdissect_options *ndo, decode_rt_routing_info(netdissect_options *ndo,
const u_char *pptr) const u_char *pptr)
{ {
uint8_t route_target[8]; uint8_t route_target[8];
u_int plen; u_int plen;
char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */ /* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
u_int num_octets; u_int num_octets;
/* NLRI "prefix length" from RFC 2858 Section 4. */ /* NLRI "prefix length" from RFC 2858 Section 4. */
plen = GET_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. /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
* RFC 4684 Section 4 defines the layout of "origin AS" and "route * RFC 4684 Section 4 defines the layout of "origin AS" and "route
* target" fields inside the "prefix" depending on its length. * target" fields inside the "prefix" depending on its length.
*/ */
if (0 == plen) { if (0 == plen) {
skipping to change at line 1018 skipping to change at line 1019
ND_PRINT("\n\t default route target"); ND_PRINT("\n\t default route target");
return 1; return 1;
} }
if (32 > plen) { if (32 > plen) {
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
return -1; return -1;
} }
/* With at least "origin AS", possibly with "route target". */ /* With at least "origin AS", possibly with "route target". */
as_printf(ndo, asbuf, sizeof(asbuf), GET_BE_U_4(pptr + 1)); as_printf(ndo, astostr, sizeof(astostr), GET_BE_U_4(pptr + 1));
plen -= 32; /* adjust prefix length */ plen -= 32; /* adjust prefix length */
if (64 < plen) { if (64 < plen) {
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
return -1; return -1;
} }
/* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 } /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
* and gives the number of octets in the variable-length "route * and gives the number of octets in the variable-length "route
* target" field inside this NLRI "prefix". Look for it. * target" field inside this NLRI "prefix". Look for it.
*/ */
memset(&route_target, 0, sizeof(route_target)); memset(&route_target, 0, sizeof(route_target));
num_octets = (plen + 7) / 8; num_octets = (plen + 7) / 8;
ND_TCHECK_LEN(pptr + 5, num_octets); GET_CPY_BYTES(&route_target, pptr + 5, num_octets);
memcpy(&route_target, pptr + 5, num_octets);
/* If mask-len is not on octet boundary, ensure all extra bits are 0 */ /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
if (plen % 8) { if (plen % 8) {
((u_char *)&route_target)[num_octets - 1] &= ((u_char *)&route_target)[num_octets - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
ND_PRINT("\n\t origin AS: %s, %s", ND_PRINT("\n\t origin AS: %s, %s",
asbuf, astostr,
bgp_rt_prefix_print(ndo, (u_char *)&route_target, plen)); bgp_rt_prefix_print(ndo, (u_char *)&route_target, plen));
return 5 + num_octets; return 5 + num_octets;
trunc:
return -2;
} }
static int static int
decode_labeled_vpn_prefix4(netdissect_options *ndo, decode_labeled_vpn_prefix4(netdissect_options *ndo,
const u_char *pptr, char *buf, size_t buflen) const u_char *pptr, char *buf, size_t buflen)
{ {
nd_ipv4 addr; nd_ipv4 addr;
u_int plen; u_int plen;
plen = GET_U_1(pptr); /* get prefix length */ plen = GET_U_1(pptr); /* get prefix length */
if ((24+64) > plen) if ((24+64) > plen)
return -1; return -1;
plen -= (24+64); /* adjust prefixlen - labellength - RD len*/ plen -= (24+64); /* adjust prefixlen - labellength - RD len*/
if (32 < plen) if (32 < plen)
return -1; return -1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
ND_TCHECK_LEN(pptr + 12, (plen + 7) / 8); GET_CPY_BYTES(&addr, pptr + 12, (plen + 7) / 8);
memcpy(&addr, pptr + 12, (plen + 7) / 8);
if (plen % 8) { if (plen % 8) {
((u_char *)&addr)[(plen + 7) / 8 - 1] &= ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
/* the label may get offsetted by 4 bits so lets shift it right */ /* the label may get offsetted by 4 bits so lets shift it right */
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), bgp_vpn_rd_print(ndo, pptr+4),
ipaddr_string(ndo, (const u_char *)&addr), ipaddr_string(ndo, (const u_char *)&addr),
plen, plen,
GET_BE_U_3(pptr + 1)>>4, GET_BE_U_3(pptr + 1)>>4,
((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" ); ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" );
return 12 + (plen + 7) / 8; return 12 + (plen + 7) / 8;
trunc:
return -2;
} }
/* /*
* +-------------------------------+ * +-------------------------------+
* | | * | |
* | RD:IPv4-address (12 octets) | * | RD:IPv4-address (12 octets) |
* | | * | |
* +-------------------------------+ * +-------------------------------+
* | MDT Group-address (4 octets) | * | MDT Group-address (4 octets) |
* +-------------------------------+ * +-------------------------------+
skipping to change at line 1153 skipping to change at line 1147
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"}, { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
{ 0, NULL} { 0, NULL}
}; };
static int static int
decode_multicast_vpn(netdissect_options *ndo, decode_multicast_vpn(netdissect_options *ndo,
const u_char *pptr, char *buf, size_t buflen) const u_char *pptr, char *buf, size_t buflen)
{ {
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
uint8_t route_type, route_length; uint8_t route_type, route_length;
u_int addr_length, sg_length; u_int addr_length, sg_length;
u_int offset; u_int offset;
route_type = GET_U_1(pptr); route_type = GET_U_1(pptr);
pptr++; pptr++;
route_length = GET_U_1(pptr); route_length = GET_U_1(pptr);
pptr++; pptr++;
snprintf(buf, buflen, "Route-Type: %s (%u), length: %u", snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
skipping to change at line 1384 skipping to change at line 1380
u_int plen, plenbytes; u_int plen, plenbytes;
ITEMCHECK(1); ITEMCHECK(1);
plen = GET_U_1(pd); plen = GET_U_1(pd);
if (128 < plen) if (128 < plen)
return -1; return -1;
itemlen -= 1; itemlen -= 1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
plenbytes = (plen + 7) / 8; plenbytes = (plen + 7) / 8;
ND_TCHECK_LEN(pd + 1, plenbytes);
ITEMCHECK(plenbytes); ITEMCHECK(plenbytes);
memcpy(&addr, pd + 1, plenbytes); GET_CPY_BYTES(&addr, pd + 1, plenbytes);
if (plen % 8) { if (plen % 8) {
addr[plenbytes - 1] &= addr[plenbytes - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, (const u_char *)&addr), p len); snprintf(buf, buflen, "%s/%u", ip6addr_string(ndo, (const u_char *)&addr), p len);
return 1 + plenbytes; return 1 + plenbytes;
trunc:
return -2;
badtlv: badtlv:
return -3; return -2;
} }
static int static int
decode_labeled_prefix6(netdissect_options *ndo, decode_labeled_prefix6(netdissect_options *ndo,
const u_char *pptr, u_int itemlen, char *buf, size_t buflen) const u_char *pptr, u_int itemlen, char *buf, size_t buflen)
{ {
nd_ipv6 addr; nd_ipv6 addr;
u_int plen, plenbytes; u_int plen, plenbytes;
/* prefix length and label = 4 bytes */ /* prefix length and label = 4 bytes */
skipping to change at line 1424 skipping to change at line 1416
return -1; return -1;
plen -= 24; /* adjust prefixlen - labellength */ plen -= 24; /* adjust prefixlen - labellength */
if (128 < plen) if (128 < plen)
return -1; return -1;
itemlen -= 4; itemlen -= 4;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
plenbytes = (plen + 7) / 8; plenbytes = (plen + 7) / 8;
ND_TCHECK_LEN(pptr + 4, plenbytes); GET_CPY_BYTES(&addr, pptr + 4, plenbytes);
memcpy(&addr, pptr + 4, plenbytes);
if (plen % 8) { if (plen % 8) {
addr[plenbytes - 1] &= addr[plenbytes - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
/* the label may get offsetted by 4 bits so lets shift it right */ /* the label may get offsetted by 4 bits so lets shift it right */
snprintf(buf, buflen, "%s/%u, label:%u %s", snprintf(buf, buflen, "%s/%u, label:%u %s",
ip6addr_string(ndo, (const u_char *)&addr), ip6addr_string(ndo, (const u_char *)&addr),
plen, plen,
GET_BE_U_3(pptr + 1)>>4, GET_BE_U_3(pptr + 1)>>4,
((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" ); ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" );
skipping to change at line 1464 skipping to change at line 1455
if ((24+64) > plen) if ((24+64) > plen)
return -1; return -1;
plen -= (24+64); /* adjust prefixlen - labellength - RD len*/ plen -= (24+64); /* adjust prefixlen - labellength - RD len*/
if (128 < plen) if (128 < plen)
return -1; return -1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
ND_TCHECK_LEN(pptr + 12, (plen + 7) / 8); GET_CPY_BYTES(&addr, pptr + 12, (plen + 7) / 8);
memcpy(&addr, pptr + 12, (plen + 7) / 8);
if (plen % 8) { if (plen % 8) {
addr[(plen + 7) / 8 - 1] &= addr[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
/* the label may get offsetted by 4 bits so lets shift it right */ /* the label may get offsetted by 4 bits so lets shift it right */
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), bgp_vpn_rd_print(ndo, pptr+4),
ip6addr_string(ndo, (const u_char *)&addr), ip6addr_string(ndo, (const u_char *)&addr),
plen, plen,
GET_BE_U_3(pptr + 1)>>4, GET_BE_U_3(pptr + 1)>>4,
((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" ); ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" );
return 12 + (plen + 7) / 8; return 12 + (plen + 7) / 8;
trunc:
return -2;
} }
static int static int
decode_clnp_prefix(netdissect_options *ndo, decode_clnp_prefix(netdissect_options *ndo,
const u_char *pptr, char *buf, size_t buflen) const u_char *pptr, char *buf, size_t buflen)
{ {
uint8_t addr[19]; uint8_t addr[19];
u_int plen; u_int plen;
plen = GET_U_1(pptr); /* get prefix length */ plen = GET_U_1(pptr); /* get prefix length */
if (152 < plen) if (152 < plen)
return -1; return -1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
ND_TCHECK_LEN(pptr + 4, (plen + 7) / 8); GET_CPY_BYTES(&addr, pptr + 4, (plen + 7) / 8);
memcpy(&addr, pptr + 4, (plen + 7) / 8);
if (plen % 8) { if (plen % 8) {
addr[(plen + 7) / 8 - 1] &= addr[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff); ((0xff00 >> (plen % 8)) & 0xff);
} }
/* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */ /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
snprintf(buf, buflen, "%s/%u", snprintf(buf, buflen, "%s/%u",
isonsap_string(ndo, addr,(plen + 7) / 8), isonsap_string(ndo, addr,(plen + 7) / 8),
plen); plen);
return 1 + (plen + 7) / 8; return 1 + (plen + 7) / 8;
trunc:
return -2;
} }
static int static int
decode_labeled_vpn_clnp_prefix(netdissect_options *ndo, decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
const u_char *pptr, char *buf, size_t buflen) const u_char *pptr, char *buf, size_t buflen)
{ {
uint8_t addr[19]; uint8_t addr[19];
u_int plen; u_int plen;
plen = GET_U_1(pptr); /* get prefix length */ plen = GET_U_1(pptr); /* get prefix length */
if ((24+64) > plen) if ((24+64) > plen)
return -1; return -1;
plen -= (24+64); /* adjust prefixlen - labellength - RD len*/ plen -= (24+64); /* adjust prefixlen - labellength - RD len*/
if (152 < plen) if (152 < plen)
return -1; return -1;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
ND_TCHECK_LEN(pptr + 12, (plen + 7) / 8); GET_CPY_BYTES(&addr, pptr + 12, (plen + 7) / 8);
memcpy(&addr, pptr + 12, (plen + 7) / 8);
if (plen % 8) { if (plen % 8) {
addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff); addr[(plen + 7) / 8 - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
} }
/* the label may get offsetted by 4 bits so lets shift it right */ /* the label may get offsetted by 4 bits so lets shift it right */
/* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */ /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
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), bgp_vpn_rd_print(ndo, pptr+4),
isonsap_string(ndo, addr,(plen + 7) / 8), isonsap_string(ndo, addr,(plen + 7) / 8),
plen, plen,
GET_BE_U_3(pptr + 1)>>4, GET_BE_U_3(pptr + 1)>>4,
((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" ); ((GET_U_1(pptr + 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT se t!)" : "(bottom)" );
return 12 + (plen + 7) / 8; return 12 + (plen + 7) / 8;
trunc:
return -2;
} }
/* /*
* bgp_attr_get_as_size * bgp_attr_get_as_size
* *
* Try to find the size of the ASs encoded in an as-path. It is not obvious, as * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
* both Old speakers that do not support 4 byte AS, and the new speakers that do * both Old speakers that do not support 4 byte AS, and the new speakers that do
* support, exchange AS-Path with the same path-attribute type value 0x02. * support, exchange AS-Path with the same path-attribute type value 0x02.
*/ */
static u_int static u_int
skipping to change at line 1756 skipping to change at line 1735
case (AFNUM_INET<<8 | SAFNUM_MULTICAST): case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
if (add_path4) { if (add_path4) {
path_id = GET_BE_U_4(tptr); path_id = GET_BE_U_4(tptr);
tptr += 4; tptr += 4;
} }
advance = decode_prefix4(ndo, tptr, len, buf, buflen); advance = decode_prefix4(ndo, tptr, len, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2) else if (advance == -2)
goto trunc;
else if (advance == -3)
break; /* bytes left, but not enough */ break; /* bytes left, but not enough */
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
if (add_path4) { if (add_path4) {
ND_PRINT(" Path Id: %u", path_id); ND_PRINT(" Path Id: %u", path_id);
advance += 4; advance += 4;
} }
break; break;
case (AFNUM_INET<<8 | SAFNUM_LABUNICAST): case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
advance = decode_labeled_prefix4(ndo, tptr, len, buf, buflen); advance = decode_labeled_prefix4(ndo, tptr, len, buf, buflen);
skipping to change at line 1783 skipping to change at line 1760
break; /* bytes left, but not enough */ break; /* bytes left, but not enough */
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, buflen); advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2)
goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO): case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
advance = decode_rt_routing_info(ndo, tptr); advance = decode_rt_routing_info(ndo, tptr);
if (advance == -2)
goto trunc;
break; break;
case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */ case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
advance = decode_multicast_vpn(ndo, tptr, buf, buflen); advance = decode_multicast_vpn(ndo, tptr, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2) else if (advance == -2)
goto trunc; goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
skipping to change at line 1824 skipping to change at line 1797
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST): case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
if (add_path6) { if (add_path6) {
path_id = GET_BE_U_4(tptr); path_id = GET_BE_U_4(tptr);
tptr += 4; tptr += 4;
} }
advance = decode_prefix6(ndo, tptr, len, buf, buflen); advance = decode_prefix6(ndo, tptr, len, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2) else if (advance == -2)
goto trunc;
else if (advance == -3)
break; /* bytes left, but not enough */ break; /* bytes left, but not enough */
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
if (add_path6) { if (add_path6) {
ND_PRINT(" Path Id: %u", path_id); ND_PRINT(" Path Id: %u", path_id);
advance += 4; advance += 4;
} }
break; break;
case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST): case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
advance = decode_labeled_prefix6(ndo, tptr, len, buf, buflen); advance = decode_labeled_prefix6(ndo, tptr, len, buf, buflen);
skipping to change at line 1851 skipping to change at line 1822
break; /* bytes left, but not enough */ break; /* bytes left, but not enough */
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, buflen); advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2)
goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_VPLS<<8 | SAFNUM_VPLS): case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
advance = decode_labeled_vpn_l2(ndo, tptr, buf, buflen); advance = decode_labeled_vpn_l2(ndo, tptr, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal length)"); ND_PRINT("\n\t (illegal length)");
skipping to change at line 1874 skipping to change at line 1843
goto trunc; goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_NSAP<<8 | SAFNUM_UNICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
advance = decode_clnp_prefix(ndo, tptr, buf, buflen); advance = decode_clnp_prefix(ndo, tptr, buf, buflen);
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2)
goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST): case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, buflen) ; advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, buflen) ;
if (advance == -1) if (advance == -1)
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
else if (advance == -2)
goto trunc;
else else
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
break; break;
default: default:
/* /*
* This should not happen, we should have been protected * This should not happen, we should have been protected
* by bgp_mp_af_print()'s return value. * by bgp_mp_af_print()'s return value.
*/ */
ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af, safi) ; ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af, safi) ;
advance = -4; advance = -4;
skipping to change at line 1909 skipping to change at line 1874
return advance; return advance;
trunc: /* we rely on the caller to recognize -2 return value */ trunc: /* we rely on the caller to recognize -2 return value */
return -2; return -2;
} }
static int static int
bgp_attr_print(netdissect_options *ndo, bgp_attr_print(netdissect_options *ndo,
uint8_t atype, const u_char *pptr, u_int len, uint8_t atype, const u_char *pptr, u_int len,
const unsigned attr_set_level) const unsigned attr_set_level)
{ {
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
u_int i; u_int i;
uint16_t af; uint16_t af;
uint8_t safi, snpa, nhlen; uint8_t safi, snpa, nhlen;
int advance; int advance;
u_int tlen; u_int tlen;
const u_char *tptr; const u_char *tptr;
char buf[MAXHOSTNAMELEN + 100]; char buf[MAXHOSTNAMELEN + 100];
u_int as_size; u_int as_size;
int add_path4, add_path6; int add_path4, add_path6;
int ret; int ret;
skipping to change at line 2554 skipping to change at line 2521
return 1; return 1;
trunc: trunc:
return 0; return 0;
} }
static void static void
bgp_capabilities_print(netdissect_options *ndo, bgp_capabilities_print(netdissect_options *ndo,
const u_char *opt, u_int caps_len) const u_char *opt, u_int caps_len)
{ {
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
u_int cap_type, cap_len, tcap_len, cap_offset; u_int cap_type, cap_len, tcap_len, cap_offset;
u_int i = 0; u_int i = 0;
while (i < caps_len) { while (i < caps_len) {
ND_TCHECK_LEN(opt + i, BGP_CAP_HEADER_SIZE); ND_TCHECK_LEN(opt + i, BGP_CAP_HEADER_SIZE);
cap_type=GET_U_1(opt + i); cap_type=GET_U_1(opt + i);
cap_len=GET_U_1(opt + i + 1); cap_len=GET_U_1(opt + i + 1);
ND_PRINT("\n\t %s (%u), length: %u", ND_PRINT("\n\t %s (%u), length: %u",
tok2str(bgp_capcode_values, "Unknown", cap_type), tok2str(bgp_capcode_values, "Unknown", cap_type),
cap_type, cap_type,
skipping to change at line 2682 skipping to change at line 2651
return; return;
trunc: trunc:
nd_print_trunc(ndo); nd_print_trunc(ndo);
} }
static void static void
bgp_open_print(netdissect_options *ndo, bgp_open_print(netdissect_options *ndo,
const u_char *dat, u_int length) const u_char *dat, u_int length)
{ {
/* allocate space for the largest possible string */
char astostr[AS_STR_SIZE];
const struct bgp_open *bgp_open_header; const struct bgp_open *bgp_open_header;
u_int optslen; u_int optslen;
const struct bgp_opt *bgpopt; const struct bgp_opt *bgpopt;
const u_char *opt; const u_char *opt;
u_int i; u_int i;
ND_TCHECK_LEN(dat, BGP_OPEN_SIZE); ND_TCHECK_LEN(dat, BGP_OPEN_SIZE);
if (length < BGP_OPEN_SIZE) if (length < BGP_OPEN_SIZE)
goto trunc; goto trunc;
skipping to change at line 2803 skipping to change at line 2774
path_id = GET_BE_U_4(p); path_id = GET_BE_U_4(p);
p += 4; p += 4;
length -= 4; length -= 4;
withdrawn_routes_len -= 4; withdrawn_routes_len -= 4;
} }
wpfx = decode_prefix4(ndo, p, withdrawn_routes_len, buf, sizeof(buf) ); wpfx = decode_prefix4(ndo, p, withdrawn_routes_len, buf, sizeof(buf) );
if (wpfx == -1) { if (wpfx == -1) {
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
break; break;
} else if (wpfx == -2) } else if (wpfx == -2)
goto trunc;
else if (wpfx == -3)
goto trunc; /* bytes left, but not enough */ goto trunc; /* bytes left, but not enough */
else { else {
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
if (add_path) { if (add_path) {
ND_PRINT(" Path Id: %u", path_id); ND_PRINT(" Path Id: %u", path_id);
} }
p += wpfx; p += wpfx;
length -= wpfx; length -= wpfx;
withdrawn_routes_len -= wpfx; withdrawn_routes_len -= wpfx;
} }
skipping to change at line 2920 skipping to change at line 2889
goto trunc; goto trunc;
path_id = GET_BE_U_4(p); path_id = GET_BE_U_4(p);
p += 4; p += 4;
length -= 4; length -= 4;
} }
i = decode_prefix4(ndo, p, length, buf, sizeof(buf)); i = decode_prefix4(ndo, p, length, buf, sizeof(buf));
if (i == -1) { if (i == -1) {
ND_PRINT("\n\t (illegal prefix length)"); ND_PRINT("\n\t (illegal prefix length)");
break; break;
} else if (i == -2) } else if (i == -2)
goto trunc;
else if (i == -3)
goto trunc; /* bytes left, but not enough */ goto trunc; /* bytes left, but not enough */
else { else {
ND_PRINT("\n\t %s", buf); ND_PRINT("\n\t %s", buf);
if (add_path) { if (add_path) {
ND_PRINT(" Path Id: %u", path_id); ND_PRINT(" Path Id: %u", path_id);
} }
p += i; p += i;
length -= i; length -= i;
} }
} }
 End of changes. 41 change blocks. 
63 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)