aboutsummaryrefslogtreecommitdiffstats
path: root/packet-bgp.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-04-17 21:25:13 +0000
committerGuy Harris <guy@alum.mit.edu>2001-04-17 21:25:13 +0000
commitaa1b532612bbb529d59b592970fb7078ab406f1c (patch)
treeab41c984b9e5dd1c56baf97648f367a42daedfce /packet-bgp.c
parent4694e6b0d8f5d52bfca5d6b7367cf19fc9e2e869 (diff)
Tvbuffified by Heikki Vatiainen.
svn path=/trunk/; revision=3317
Diffstat (limited to 'packet-bgp.c')
-rw-r--r--packet-bgp.c642
1 files changed, 315 insertions, 327 deletions
diff --git a/packet-bgp.c b/packet-bgp.c
index 337c8b5065..10e611e75f 100644
--- a/packet-bgp.c
+++ b/packet-bgp.c
@@ -2,7 +2,7 @@
* Routines for BGP packet dissection.
* Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
*
- * $Id: packet-bgp.c,v 1.33 2001/01/22 03:33:45 guy Exp $
+ * $Id: packet-bgp.c,v 1.34 2001/04/17 21:25:13 guy Exp $
*
* Supports:
* RFC1771 A Border Gateway Protocol 4 (BGP-4)
@@ -210,21 +210,21 @@ static gint ett_bgp_option = -1; /* an optional parameter tree */
* Decode an IPv4 prefix.
*/
static int
-decode_prefix4(const u_char *pd, char *buf, int buflen)
+decode_prefix4(tvbuff_t *tvb, gint offset, char *buf, int buflen)
{
guint8 addr[4]; /* IP address */
int plen; /* prefix length */
int length; /* number of octets needed for prefix */
/* snarf length */
- plen = pd[0];
+ plen = tvb_get_guint8(tvb, offset);
if (plen < 0 || 32 < plen)
return -1;
length = (plen + 7) / 8;
/* snarf prefix */
memset(addr, 0, sizeof(addr));
- memcpy(addr, &pd[1], length);
+ tvb_memcpy(tvb, addr, offset + 1, length);
if (plen % 8)
addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
@@ -237,21 +237,21 @@ decode_prefix4(const u_char *pd, char *buf, int buflen)
* Decode an IPv6 prefix.
*/
static int
-decode_prefix6(const u_char *pd, char *buf, int buflen)
+decode_prefix6(tvbuff_t *tvb, gint offset, char *buf, int buflen)
{
struct e_in6_addr addr; /* IPv6 address */
int plen; /* prefix length */
int length; /* number of octets needed for prefix */
/* snarf length */
- plen = pd[0];
+ plen = tvb_get_guint8(tvb, offset);
if (plen < 0 || 128 < plen)
return -1;
length = (plen + 7) / 8;
/* snarf prefix */
memset(&addr, 0, sizeof(addr));
- memcpy(&addr, &pd[1], length);
+ tvb_memcpy(tvb, (guint8 *)&addr, offset + 1, length);
if (plen % 8)
addr.s6_addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
@@ -264,7 +264,7 @@ decode_prefix6(const u_char *pd, char *buf, int buflen)
* Dissect a BGP OPEN message.
*/
static void
-dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_bgp_open(tvbuff_t *tvb, int offset, proto_tree *tree)
{
struct bgp_open bgpo; /* BGP OPEN message */
int hlen; /* message length */
@@ -274,30 +274,30 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
int ctype; /* capability type */
int clen; /* capability length */
int ostart; /* options start */
- const u_char *oend; /* options end */
- const u_char *p; /* packet offset pointer */
+ int oend; /* options end */
+ int p; /* tvb offset counter */
proto_item *ti; /* tree item */
proto_tree *subtree; /* subtree for options */
proto_tree *subtree2; /* subtree for an option */
proto_tree *subtree3; /* subtree for an option */
/* snarf OPEN message */
- memcpy(&bgpo, &pd[offset], sizeof(bgpo));
+ tvb_memcpy(tvb, bgpo.bgpo_marker, offset, BGP_MIN_OPEN_MSG_SIZE);
hlen = ntohs(bgpo.bgpo_len);
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_open, bgpo_version), 1,
"Version: %u", bgpo.bgpo_version);
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_open, bgpo_myas), 2,
"My AS: %u", ntohs(bgpo.bgpo_myas));
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_open, bgpo_holdtime), 2,
"Hold time: %u", ntohs(bgpo.bgpo_holdtime));
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_open, bgpo_id), 4,
"BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_open, bgpo_optlen), 1,
"Optional parameters length: %u %s", bgpo.bgpo_optlen,
(bgpo.bgpo_optlen == 1) ? "byte" : "bytes");
@@ -305,96 +305,96 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
/* optional parameters */
if (bgpo.bgpo_optlen > 0) {
/* add a subtree and setup some offsets */
- ostart = offset + sizeof(bgpo) - 3;
- ti = proto_tree_add_text(tree, NullTVB, ostart, bgpo.bgpo_optlen,
+ ostart = offset + BGP_MIN_OPEN_MSG_SIZE;
+ ti = proto_tree_add_text(tree, tvb, ostart, bgpo.bgpo_optlen,
"Optional parameters");
subtree = proto_item_add_subtree(ti, ett_bgp_options);
- p = &pd[ostart];
+ p = offset + ostart;
oend = p + bgpo.bgpo_optlen;
/* step through all of the optional parameters */
while (p < oend) {
/* grab the type and length */
- ptype = *p++;
- plen = *p++;
+ ptype = tvb_get_guint8(tvb, p++);
+ plen = tvb_get_guint8(tvb, p++);
/* check the type */
switch (ptype) {
case BGP_OPTION_AUTHENTICATION:
- proto_tree_add_text(subtree, NullTVB, p - pd - 2, 2 + plen,
+ proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
"Authentication information (%u %s)", plen,
(plen == 1) ? "byte" : "bytes");
break;
case BGP_OPTION_CAPABILITY:
/* grab the capability code */
- ctype = *p++;
- clen = *p++;
+ ctype = tvb_get_guint8(tvb, p++);
+ clen = tvb_get_guint8(tvb, p++);
/* check the capability type */
switch (ctype) {
case BGP_CAPABILITY_RESERVED:
- ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
+ ti = proto_tree_add_text(subtree, tvb, p - 4,
2 + plen, "Reserved capability (%u %s)", 2 + plen,
(plen == 1) ? "byte" : "bytes");
subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
- proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
+ proto_tree_add_text(subtree2, tvb, p - 4,
1, "Parameter type: Capabilities (2)");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ proto_tree_add_text(subtree2, tvb, p - 3,
1, "Parameter length: %u %s", plen,
(plen == 1) ? "byte" : "bytes");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ proto_tree_add_text(subtree2, tvb, p - 2,
1, "Capability code: Reserved (0)");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ proto_tree_add_text(subtree2, tvb, p - 1,
1, "Capability length: %u %s", clen,
(clen == 1) ? "byte" : "bytes");
if (clen != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd,
+ proto_tree_add_text(subtree2, tvb, p,
clen, "Capability value: Unknown");
}
p += clen;
break;
case BGP_CAPABILITY_MULTIPROTOCOL:
- ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
+ ti = proto_tree_add_text(subtree, tvb, p - 4,
2 + plen,
"Multiprotocol extensions capability (%u %s)",
2 + plen, (plen == 1) ? "byte" : "bytes");
subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
- proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
+ proto_tree_add_text(subtree2, tvb, p - 4,
1, "Parameter type: Capabilities (2)");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ proto_tree_add_text(subtree2, tvb, p - 3,
1, "Parameter length: %u %s", plen,
(plen == 1) ? "byte" : "bytes");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ proto_tree_add_text(subtree2, tvb, p - 2,
1, "Capability code: Multiprotocol extensions (%d)",
ctype);
if (clen != 4) {
- proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ proto_tree_add_text(subtree2, tvb, p - 1,
1, "Capability length: Invalid");
- proto_tree_add_text(subtree2, NullTVB, p - pd,
+ proto_tree_add_text(subtree2, tvb, p,
clen, "Capability value: Unknown");
}
else {
- proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ proto_tree_add_text(subtree2, tvb, p - 1,
1, "Capability length: %u %s", clen,
(clen == 1) ? "byte" : "bytes");
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd,
+ ti = proto_tree_add_text(subtree2, tvb, p,
clen, "Capability value");
subtree3 = proto_item_add_subtree(ti,
ett_bgp_option);
/* AFI */
- i = pntohs(p);
- proto_tree_add_text(subtree3, NullTVB, p - pd,
+ i = tvb_get_ntohs(tvb, p);
+ proto_tree_add_text(subtree3, tvb, p,
2, "Address family identifier: %s (%u)",
val_to_str(i, afnumber, "Unknown"), i);
p += 2;
/* Reserved */
- proto_tree_add_text(subtree3, NullTVB, p - pd,
+ proto_tree_add_text(subtree3, tvb, p,
1, "Reserved: 1 byte");
p++;
/* SAFI */
- i = *p;
- proto_tree_add_text(subtree3, NullTVB, p - pd,
+ i = tvb_get_guint8(tvb, p);
+ proto_tree_add_text(subtree3, tvb, p,
1, "Subsequent address family identifier: %s (%u)",
val_to_str(i, bgpattr_nlri_safi,
i >= 128 ? "Vendor specific" : "Unknown"), i);
@@ -402,23 +402,23 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
}
break;
case BGP_CAPABILITY_ROUTE_REFRESH:
- ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
+ ti = proto_tree_add_text(subtree, tvb, p - 4,
2 + plen, "Route refresh capability (%u %s)", 2 + plen,
(plen == 1) ? "byte" : "bytes");
subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
- proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
+ proto_tree_add_text(subtree2, tvb, p - 4,
1, "Parameter type: Capabilities (2)");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ proto_tree_add_text(subtree2, tvb, p - 3,
1, "Parameter length: %u %s", plen,
(plen == 1) ? "byte" : "bytes");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ proto_tree_add_text(subtree2, tvb, p - 2,
1, "Capability code: Route refresh (%d)", ctype);
if (clen != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd,
+ proto_tree_add_text(subtree2, tvb, p,
clen, "Capability value: Invalid");
}
else {
- proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ proto_tree_add_text(subtree2, tvb, p - 1,
1, "Capability length: %u %s", clen,
(clen == 1) ? "byte" : "bytes");
}
@@ -426,23 +426,23 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
break;
/* unknown capability */
default:
- ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
+ ti = proto_tree_add_text(subtree, tvb, p - 4,
2 + plen, "Unknown capability (%u %s)", 2 + plen,
(plen == 1) ? "byte" : "bytes");
subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
- proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
+ proto_tree_add_text(subtree2, tvb, p - 4,
1, "Parameter type: Capabilities (2)");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ proto_tree_add_text(subtree2, tvb, p - 3,
1, "Parameter length: %u %s", plen,
(plen == 1) ? "byte" : "bytes");
- proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ proto_tree_add_text(subtree2, tvb, p - 2,
1, "Capability code: %s (%d)",
ctype >= 128 ? "Private use" : "Unknown", ctype);
- proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ proto_tree_add_text(subtree2, tvb, p - 1,
1, "Capability length: %u %s", clen,
(clen == 1) ? "byte" : "bytes");
if (clen != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd,
+ proto_tree_add_text(subtree2, tvb, p,
clen, "Capability value: Unknown");
}
p += clen;
@@ -450,7 +450,7 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
}
break;
default:
- proto_tree_add_text(subtree, NullTVB, p - pd - 2, 2 + plen,
+ proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
"Unknown optional parameter");
break;
}
@@ -462,15 +462,13 @@ dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
* Dissect a BGP UPDATE message.
*/
static void
-dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
- proto_tree *tree)
+dissect_bgp_update(tvbuff_t *tvb, int offset, proto_tree *tree)
{
- struct bgp bgp; /* BGP header */
struct bgp_attr bgpa; /* path attributes */
int hlen; /* message length */
- const u_char *p; /* packet offset pointer */
- const u_char *q; /* tmp */
- const u_char *end; /* message end */
+ gint o; /* packet offset */
+ gint q; /* tmp */
+ gint end; /* message end */
int len; /* tmp */
proto_item *ti; /* tree item */
proto_tree *subtree; /* subtree for attibutes */
@@ -488,44 +486,43 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
char *communities_str = NULL; /* COMMUNITIES string */
char *cluster_list_str = NULL; /* CLUSTER_LIST string */
char junk_buf[256]; /* tmp */
+ guint8 ipaddr[4]; /* IPv4 address */
+ struct e_in6_addr ip6addr; /* IPv6 address */
-
- /* snarf UPDATE message */
- memcpy(&bgp, &pd[offset], sizeof(bgp));
- hlen = ntohs(bgp.bgp_len);
- p = &pd[offset + BGP_HEADER_SIZE]; /*XXX*/
+ hlen = tvb_get_ntohs(tvb, offset + BGP_MARKER_SIZE);
+ o = offset + BGP_HEADER_SIZE;
/* check for withdrawals */
- len = pntohs(p);
- proto_tree_add_text(tree, NullTVB, p - pd, 2,
+ len = tvb_get_ntohs(tvb, o);
+ proto_tree_add_text(tree, tvb, o, 2,
"Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
- p += 2;
+ o += 2;
/* parse unfeasible prefixes */
if (len > 0) {
- ti = proto_tree_add_text(tree, NullTVB, p - pd, len, "Withdrawn routes:");
+ ti = proto_tree_add_text(tree, tvb, o, len, "Withdrawn routes:");
subtree = proto_item_add_subtree(ti, ett_bgp_unfeas);
/* parse each prefixes */
- end = p + len;
- while (p < end) {
- i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
- proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
- p += i;
+ end = o + len;
+ while (o < end) {
+ i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
+ proto_tree_add_text(subtree, tvb, o, i, "%s", junk_buf);
+ o += i;
}
}
else {
- p += len;
+ o += len;
}
/* check for advertisements */
- len = pntohs(p);
- proto_tree_add_text(tree, NullTVB, p - pd, 2, "Total path attribute length: %u %s",
+ len = tvb_get_ntohs(tvb, o);
+ proto_tree_add_text(tree, tvb, o, 2, "Total path attribute length: %u %s",
len, (len == 1) ? "byte" : "bytes");
/* path attributes */
if (len > 0) {
- ti = proto_tree_add_text(tree, NullTVB, p - pd + 2, len, "Path attributes");
+ ti = proto_tree_add_text(tree, tvb, o + 2, len, "Path attributes");
subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
i = 2;
while (i < len) {
@@ -534,16 +531,16 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
guint16 af;
int off, snpa;
- memcpy(&bgpa, &p[i], sizeof(bgpa));
+ tvb_memcpy(tvb, (guint8 *)&bgpa, o + i, sizeof(bgpa));
/* check for the Extended Length bit */
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
- alen = pntohs(&p[i + sizeof(bgpa)]);
+ alen = tvb_get_ntohs(tvb, o + i + sizeof(bgpa));
aoff = sizeof(bgpa) + 2;
} else {
- alen = p[i + sizeof(bgpa)];
+ alen = tvb_get_guint8(tvb, o + i + sizeof(bgpa));
aoff = sizeof(bgpa) + 1;
}
-
+
/* This is kind of ugly - similar code appears twice, but it
helps browsing attrs. */
/* the first switch prints things in the title of the subtree */
@@ -551,18 +548,18 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
case BGPTYPE_ORIGIN:
if (alen != 1)
goto default_attribute_top;
- msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ msg = val_to_str(tvb_get_guint8(tvb, o + i + aoff), bgpattr_origin, "Unknown");
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
msg, alen + aoff, (alen + aoff == 1) ? "byte" :
"bytes");
break;
case BGPTYPE_AS_PATH:
- /* (p + i + 3) =
- (p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ /* (o + i + 3) =
+ (o + current attribute + 3 bytes to first tuple) */
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* must be freed by second switch! */
/* "alen * 6" (5 digits + space) should be a good estimate
of how long the AS path string could be */
@@ -572,7 +569,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
/* snarf each AS path */
while (q < end) {
- type = *q++;
+ type = tvb_get_guint8(tvb, q++);
if (type == AS_SET) {
snprintf(as_path_str, 2, "{");
}
@@ -582,11 +579,11 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
else if (type == AS_CONFED_SEQUENCE) {
snprintf(as_path_str, 2, "(");
}
- length = *q++;
+ length = tvb_get_guint8(tvb, q++);
/* snarf each value in path */
for (j = 0; j < length; j++) {
- snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
+ snprintf(junk_buf, sizeof(junk_buf), "%u%s", tvb_get_ntohs(tvb, q),
(type == AS_SET || type == AS_CONFED_SET)
? ", " : " ");
strncat(as_path_str, junk_buf, sizeof(junk_buf));
@@ -612,7 +609,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
if (alen == 0)
strncpy(as_path_str, "empty", 6);
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
as_path_str, alen + aoff,
@@ -621,34 +618,35 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
case BGPTYPE_NEXT_HOP:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
+ ip_to_str(ipaddr), alen + aoff, (alen + aoff == 1)
? "byte" : "bytes");
break;
case BGPTYPE_MULTI_EXIT_DISC:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- pntohl(&p[i + aoff]), alen + aoff,
+ tvb_get_ntohl(tvb, o + i + aoff), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_LOCAL_PREF:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- pntohl(&p[i + aoff]), alen + aoff,
+ tvb_get_ntohl(tvb, o + i + aoff), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_ATOMIC_AGGREGATE:
if (alen != 0)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
@@ -656,21 +654,22 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
case BGPTYPE_AGGREGATOR:
if (alen != 6)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ tvb_memcpy(tvb, ipaddr, o + i + aoff + 2, 4);
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: AS: %u origin: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- pntohs(&p[i + aoff]),
- ip_to_str(&p[i + aoff + 2]), alen + aoff,
+ tvb_get_ntohs(tvb, o + i + aoff),
+ ip_to_str(ipaddr), alen + aoff,
(alen + aoff == 1) ? "byte" : "bytes");
break;
case BGPTYPE_COMMUNITIES:
if (alen % 4 != 0)
goto default_attribute_top;
- /* (p + i + 3) =
- (p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ /* (o + i + 3) =
+ (o + current attribute + 3 bytes to first tuple) */
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* must be freed by second switch! */
/* "alen * 12" (5 digits, a :, 5 digits + space ) should be
a good estimate of how long the communities string could
@@ -683,16 +682,16 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
/* snarf each community */
while (q < end) {
/* check for well-known communities */
- if (pntohl(q) == BGP_COMM_NO_EXPORT)
+ if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT)
strncpy(junk_buf, "NO_EXPORT ", 10);
- else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
+ else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_ADVERTISE)
strncpy(junk_buf, "NO_ADVERTISE ", 13);
- else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
+ else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT_SUBCONFED)
strncpy(junk_buf, "NO_EXPORT_SUBCONFED ", 20);
else {
snprintf(junk_buf, sizeof(junk_buf), "%u:%u ",
- pntohs(q),
- pntohs(q + 2));
+ tvb_get_ntohs(tvb, q),
+ tvb_get_ntohs(tvb, q + 2));
}
q += 4;
@@ -701,7 +700,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
/* cleanup end of string */
communities_str[strlen(communities_str) - 1] = '\0';
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
communities_str, alen + aoff,
@@ -710,20 +709,21 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
case BGPTYPE_ORIGINATOR_ID:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
- ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
+ ip_to_str(ipaddr), alen + aoff, (alen + aoff == 1)
? "byte" : "bytes");
break;
case BGPTYPE_CLUSTER_LIST:
if (alen % 4 != 0)
goto default_attribute_top;
- /* (p + i + 3) =
- (p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ /* (o + i + 3) =
+ (o + current attribute + 3 bytes to first tuple) */
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* must be freed by second switch! */
/* "alen * 16" (12 digits, 3 dots + space ) should be
a good estimate of how long the cluster_list string could
@@ -734,15 +734,16 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
memset(junk_buf, 0, sizeof(junk_buf));
/* snarf each cluster list */
+ tvb_memcpy(tvb, ipaddr, q, 4);
while (q < end) {
- snprintf(junk_buf, sizeof(junk_buf), "%s ", ip_to_str(q));
+ snprintf(junk_buf, sizeof(junk_buf), "%s ", ip_to_str(ipaddr));
strncat(cluster_list_str, junk_buf, sizeof(junk_buf));
q += 4;
}
/* cleanup end of string */
cluster_list_str[strlen(cluster_list_str) - 1] = '\0';
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
cluster_list_str, alen + aoff,
@@ -750,7 +751,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
default:
default_attribute_top:
- ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, tvb, o + i, alen + aoff,
"%s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
@@ -783,38 +784,38 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
/* stomp last ", " */
j = strlen(junk_buf);
junk_buf[j - 2] = '\0';
- ti = proto_tree_add_text(subtree2, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
+ ti = proto_tree_add_text(subtree2, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
"Flags: 0x%02x (%s)", bgpa.bgpa_flags, junk_buf);
subtree3 = proto_item_add_subtree(ti, ett_bgp_attr_flags);
/* add flag bitfield subtrees */
- proto_tree_add_text(subtree3, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
+ proto_tree_add_text(subtree3, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
BGP_ATTR_FLAG_OPTIONAL, 8, "Optional", "Well-known"));
- proto_tree_add_text(subtree3, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
+ proto_tree_add_text(subtree3, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
BGP_ATTR_FLAG_TRANSITIVE, 8, "Transitive",
"Non-transitive"));
- proto_tree_add_text(subtree3, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
+ proto_tree_add_text(subtree3, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
BGP_ATTR_FLAG_PARTIAL, 8, "Partial", "Complete"));
- proto_tree_add_text(subtree3, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
+ proto_tree_add_text(subtree3, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
BGP_ATTR_FLAG_EXTENDED_LENGTH, 8, "Extended length",
"Regular length"));
- proto_tree_add_text(subtree2, NullTVB,
- p - pd + i + offsetof(struct bgp_attr, bgpa_type), 1,
+ proto_tree_add_text(subtree2, tvb,
+ o + i + offsetof(struct bgp_attr, bgpa_type), 1,
"Type code: %s (%u)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
bgpa.bgpa_type);
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + sizeof(bgpa),
+ proto_tree_add_text(subtree2, tvb, o + i + sizeof(bgpa),
aoff - sizeof(bgpa), "Length: %d %s", alen,
(alen == 1) ? "byte" : "bytes");
@@ -823,13 +824,13 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
switch (bgpa.bgpa_type) {
case BGPTYPE_ORIGIN:
if (alen != 1) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Origin (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
- "Origin: %s (%u)", msg, p[i + aoff]);
+ msg = val_to_str(tvb_get_guint8(tvb, o + i + aoff), bgpattr_origin, "Unknown");
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, 1,
+ "Origin: %s (%u)", msg, tvb_get_guint8(tvb, o + i + aoff));
}
break;
case BGPTYPE_AS_PATH:
@@ -839,21 +840,21 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
}
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"AS path: %s", as_path_str);
as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
- /* (p + i + 3) =
- (p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ /* (o + i + 3) =
+ (o + current attribute + 3 bytes to first tuple) */
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* snarf each AS path tuple, we have to step through each one
again to make a separate subtree so we can't just reuse
as_path_str from above */
while (q < end) {
as_path_str[0] = '\0';
- type = *q++;
+ type = tvb_get_guint8(tvb, q++);
if (type == AS_SET) {
snprintf(as_path_str, 2, "{");
}
@@ -863,12 +864,12 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
else if (type == AS_CONFED_SEQUENCE) {
snprintf(as_path_str, 2, "(");
}
- length = *q++;
+ length = tvb_get_guint8(tvb, q++);
/* snarf each value in path, we're just going to reuse
as_path_str since we already have it malloced */
for (j = 0; j < length; j++) {
- snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
+ snprintf(junk_buf, sizeof(junk_buf), "%u%s", tvb_get_ntohs(tvb, q),
(type == AS_SET || type == AS_CONFED_SET)
? ", " : " ");
strncat(as_path_str, junk_buf, sizeof(junk_buf));
@@ -890,14 +891,14 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
}
/* length here means number of ASs, ie length * 2 bytes */
- ti = proto_tree_add_text(as_paths_tree, NullTVB,
- q - pd - length * 2 - 2,
+ ti = proto_tree_add_text(as_paths_tree, tvb,
+ q - length * 2 - 2,
length * 2 + 2, "AS path segment: %s", as_path_str);
as_path_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
- proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 2,
+ proto_tree_add_text(as_path_tree, tvb, q - length * 2 - 2,
1, "Path segment type: %s (%u)",
val_to_str(type, as_segment_type, "Unknown"), type);
- proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 1,
+ proto_tree_add_text(as_path_tree, tvb, q - length * 2 - 1,
1, "Path segment length: %u %s", length,
(length == 1) ? "AS" : "ASs");
@@ -905,13 +906,13 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
q -= 2 * length;
as_path_str[0] = '\0';
for (j = 0; j < length; j++) {
- snprintf(junk_buf, sizeof(junk_buf), "%u ", pntohs(q));
+ snprintf(junk_buf, sizeof(junk_buf), "%u ", tvb_get_ntohs(tvb, q));
strncat(as_path_str, junk_buf, sizeof(junk_buf));
q += 2;
}
as_path_str[strlen(as_path_str) - 1] = '\0';
- proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2,
+ proto_tree_add_text(as_path_tree, tvb, q - length * 2,
length * 2, "Path segment value: %s", as_path_str);
}
@@ -919,108 +920,110 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
case BGPTYPE_NEXT_HOP:
if (alen != 4) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Next hop (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
- "Next hop: %s", ip_to_str(&p[i + aoff]));
+ tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
+ "Next hop: %s", ip_to_str(ipaddr));
}
break;
case BGPTYPE_MULTI_EXIT_DISC:
if (alen != 4) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Multiple exit discriminator (invalid): %u %s",
alen, (alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Multiple exit discriminator: %u",
- pntohl(&p[i + aoff]));
+ tvb_get_ntohl(tvb, o + i + aoff));
}
break;
case BGPTYPE_LOCAL_PREF:
if (alen != 4) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Local preference (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
- "Local preference: %u", pntohl(&p[i + aoff]));
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
+ "Local preference: %u", tvb_get_ntohl(tvb, o + i + aoff));
}
break;
case BGPTYPE_ATOMIC_AGGREGATE:
if (alen != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Atomic aggregate (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
}
break;
case BGPTYPE_AGGREGATOR:
if (alen != 6) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Aggregator (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
- "Aggregator AS: %u", pntohs(&p[i + aoff]));
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 4,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
+ "Aggregator AS: %u", tvb_get_ntohs(tvb, o + i + aoff));
+ tvb_memcpy(tvb, ipaddr, o + i + aoff + 2, 4);
+ proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 4,
"Aggregator origin: %s",
- ip_to_str(&p[i + aoff + 2]));
+ ip_to_str(ipaddr));
}
break;
case BGPTYPE_COMMUNITIES:
if (alen % 4 != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Communities (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
free(communities_str);
break;
}
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Communities: %s", communities_str);
communities_tree = proto_item_add_subtree(ti,
ett_bgp_communities);
- /* (p + i + 3) =
- (p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ /* (o + i + 3) =
+ (o + current attribute + 3 bytes to first tuple) */
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* snarf each community */
while (q < end) {
/* check for reserved values */
- if (pntohs(q) == FOURHEX0 || pntohs(q) == FOURHEXF) {
+ if (tvb_get_ntohs(tvb, q) == FOURHEX0 || tvb_get_ntohs(tvb, q) == FOURHEXF) {
/* check for well-known communities */
- if (pntohl(q) == BGP_COMM_NO_EXPORT)
- proto_tree_add_text(communities_tree, NullTVB,
- q - pd - 3 + aoff, 4,
- "Community: NO_EXPORT (0x%x)", pntohl(q));
- else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
- proto_tree_add_text(communities_tree, NullTVB,
- q - pd - 3 + aoff, 4,
+ if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT)
+ proto_tree_add_text(communities_tree, tvb,
+ q - 3 + aoff, 4,
+ "Community: NO_EXPORT (0x%x)", tvb_get_ntohl(tvb, q));
+ else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_ADVERTISE)
+ proto_tree_add_text(communities_tree, tvb,
+ q - 3 + aoff, 4,
"Community: NO_ADVERTISE (0x%x)", pntohl(q));
- else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
- proto_tree_add_text(communities_tree, NullTVB,
- q - pd - 3 + aoff, 4,
+ else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT_SUBCONFED)
+ proto_tree_add_text(communities_tree, tvb,
+ q - 3 + aoff, 4,
"Community: NO_EXPORT_SUBCONFED (0x%x)",
- pntohl(q));
+ tvb_get_ntohl(tvb, q));
else
- proto_tree_add_text(communities_tree, NullTVB,
- q - pd - 3 + aoff, 4,
- "Community (reserved): 0x%x", pntohl(q));
+ proto_tree_add_text(communities_tree, tvb,
+ q - 3 + aoff, 4,
+ "Community (reserved): 0x%x", tvb_get_ntohl(tvb, q));
}
else {
- ti = proto_tree_add_text(communities_tree, NullTVB,
- q - pd - 3 + aoff, 4, "Community: %u:%u",
- pntohs(q), pntohs(q + 2));
+ ti = proto_tree_add_text(communities_tree, tvb,
+ q - 3 + aoff, 4, "Community: %u:%u",
+ tvb_get_ntohs(tvb, q), tvb_get_ntohs(tvb, q + 2));
community_tree = proto_item_add_subtree(ti,
ett_bgp_communities);
- proto_tree_add_text(community_tree, NullTVB, q - pd - 3 + aoff,
- 2, "Community AS: %u", pntohs(q));
- proto_tree_add_text(community_tree, NullTVB, q - pd - 1 + aoff,
- 2, "Community value: %u", pntohs(q + 2));
+ proto_tree_add_text(community_tree, tvb, q - 3 + aoff,
+ 2, "Community AS: %u", tvb_get_ntohs(tvb, q));
+ proto_tree_add_text(community_tree, tvb, q - 1 + aoff,
+ 2, "Community value: %u", tvb_get_ntohs(tvb, q + 2));
}
q += 4;
@@ -1030,29 +1033,30 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
case BGPTYPE_ORIGINATOR_ID:
if (alen != 4) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Originator identifier (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ tvb_memcpy(tvb, ipaddr, o + i + aoff, 4);
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Originator identifier: %s",
- ip_to_str(&p[i + aoff]));
+ ip_to_str(ipaddr));
}
break;
case BGPTYPE_MP_REACH_NLRI:
- af = pntohs(&p[i + aoff]);
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
+ af = tvb_get_ntohs(tvb, o + i + aoff);
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
"Subsequent address family identifier: %s (%u)",
- val_to_str(p[i + aoff + 2], bgpattr_nlri_safi,
- p[i + aoff + 2] >= 128 ? "Vendor specific" : "Unknown"),
- p[i + aoff + 2]);
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3, 1,
+ val_to_str(tvb_get_guint8(tvb, o + i + aoff + 2), bgpattr_nlri_safi,
+ tvb_get_guint8(tvb, o + i + aoff + 2) >= 128 ? "Vendor specific" : "Unknown"),
+ tvb_get_guint8(tvb, o + i + aoff + 2));
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3, 1,
"Next hop network address (%d %s)",
- p[i + aoff + 3], (p[i + aoff + 3] == 1) ? "byte" :
- "bytes");
+ tvb_get_guint8(tvb, o + i + aoff + 3),
+ (tvb_get_guint8(tvb, o + i + aoff + 3) == 1) ? "byte" : "bytes");
if (af == AFNUM_INET || af == AFNUM_INET6) {
int j, advance;
const char *s;
@@ -1061,53 +1065,55 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
ett_bgp_mp_reach_nlri);
j = 0;
- while (j < p[i + aoff + 3]) {
+ while (j < tvb_get_guint8(tvb, o + i + aoff + 3)) {
if (af == AFNUM_INET)
advance = 4;
else if (af == AFNUM_INET6)
advance = 16;
else
break;
- if (j + advance > p[i + aoff + 3])
+ if (j + advance > tvb_get_guint8(tvb, o + i + aoff + 3))
break;
- if (af == AFNUM_INET)
- s = ip_to_str(&p[i + aoff + 4 + j]);
- else {
- s = ip6_to_str((struct e_in6_addr *)
- &p[i + aoff + 4 + j]);
+ if (af == AFNUM_INET) {
+ tvb_memcpy(tvb, ipaddr, o + i + aoff + 4 + j, 4);
+ s = ip_to_str(ipaddr);
+ } else {
+ tvb_memcpy(tvb, ip6addr.u6_addr.u6_addr8,
+ o + i + aoff + 4 + j, sizeof ip6addr);
+ s = ip6_to_str(&ip6addr);
}
- proto_tree_add_text(subtree3, NullTVB,
- p - pd + i + aoff + 4 + j, advance,
+ proto_tree_add_text(subtree3, tvb,
+ o + i + aoff + 4 + j, advance,
"Next hop: %s", s);
j += advance;
}
}
- alen -= (p[i + aoff + 3] + 4);
- aoff += (p[i + aoff + 3] + 4);
+ alen -= tvb_get_guint8(tvb, o + i + aoff + 3) + 4;
+ aoff += tvb_get_guint8(tvb, o + i + aoff + 3) + 4;
off = 0;
- snpa = p[i + aoff];
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
+ snpa = tvb_get_guint8(tvb, o + i + aoff);
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, 1,
"Subnetwork points of attachment: %u", snpa);
off++;
if (snpa)
subtree3 = proto_item_add_subtree(ti,
ett_bgp_mp_reach_nlri);
for (/*nothing*/; snpa > 0; snpa--) {
- proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off, 1,
- "SNPA length: %u", p[i + aoff + off]);
+ proto_tree_add_text(subtree3, tvb, o + i + aoff + off, 1,
+ "SNPA length: %u", tvb_get_guint8(tvb, o + i + aoff + off));
off++;
- proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off,
- p[i + aoff + off - 1],
- "SNPA (%u %s)", p[i + aoff + off - 1],
- (p[i + aoff + off - 1] == 1) ? "byte" : "bytes");
- off += p[i + aoff + off - 1];
+ proto_tree_add_text(subtree3, tvb, o + i + aoff + off,
+ tvb_get_guint8(tvb, o + i + aoff + off - 1),
+ "SNPA (%u %s)", tvb_get_guint8(tvb, o + i + aoff + off - 1),
+ (tvb_get_guint8(tvb, o + i + aoff + off - 1) == 1) ? "byte" : "bytes");
+ off += tvb_get_guint8(tvb, o + i + aoff + off - 1);
}
alen -= off;
aoff += off;
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Network layer reachability information (%u %s)",
alen, (alen == 1) ? "byte" : "bytes");
if (alen)
@@ -1118,10 +1124,10 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
char buf[256];
if (af == AFNUM_INET) {
- advance = decode_prefix4(&p[i + aoff], buf,
+ advance = decode_prefix4(tvb, o + i + aoff, buf,
sizeof(buf));
} else if (af == AFNUM_INET6) {
- advance = decode_prefix6(&p[i + aoff], buf,
+ advance = decode_prefix6(tvb, o + i + aoff, buf,
sizeof(buf));
} else
break;
@@ -1129,7 +1135,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
if (alen < advance)
break;
- proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
+ proto_tree_add_text(subtree3, tvb, o + i + aoff, advance,
"Network layer reachability information: %s", buf);
alen -= advance;
@@ -1138,16 +1144,16 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
case BGPTYPE_MP_UNREACH_NLRI:
- af = pntohs(&p[i + aoff]);
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
+ af = tvb_get_ntohs(tvb, o + i + aoff);
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
"Subsequent address family identifier: %s (%u)",
- val_to_str(p[i + aoff + 2], bgpattr_nlri_safi,
- p[i + aoff + 2] >= 128 ? "Vendor specific" : "Unknown"),
- p[i + aoff + 2]);
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3,
+ val_to_str(tvb_get_guint8(tvb, o + i + aoff + 2), bgpattr_nlri_safi,
+ tvb_get_guint8(tvb, o + i + aoff + 2) >= 128 ? "Vendor specific" : "Unknown"),
+ tvb_get_guint8(tvb, o + i + aoff + 2));
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3,
alen - 3, "Withdrawn routes (%u %s)", alen - 3,
(alen - 3 == 1) ? "byte" : "bytes");
@@ -1161,10 +1167,10 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
char buf[256];
if (af == AFNUM_INET) {
- advance = decode_prefix4(&p[i + aoff], buf,
+ advance = decode_prefix4(tvb, o + i + aoff, buf,
sizeof(buf));
} else if (af == AFNUM_INET6) {
- advance = decode_prefix6(&p[i + aoff], buf,
+ advance = decode_prefix6(tvb, o + i + aoff, buf,
sizeof(buf));
} else
break;
@@ -1172,7 +1178,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
if (alen < advance)
break;
- proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
+ proto_tree_add_text(subtree3, tvb, o + i + aoff, advance,
"Withdrawn route: %s", buf);
alen -= advance;
@@ -1182,28 +1188,29 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
break;
case BGPTYPE_CLUSTER_LIST:
if (alen % 4 != 0) {
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Cluster list (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
free(cluster_list_str);
break;
}
- ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Cluster list: %s", cluster_list_str);
cluster_list_tree = proto_item_add_subtree(ti,
ett_bgp_cluster_list);
/* (p + i + 3) =
(p + current attribute + 3 bytes to first tuple) */
- end = p + alen + i + 3;
- q = p + i + 3;
+ end = o + alen + i + 3;
+ q = o + i + 3;
/* snarf each cluster identifier */
while (q < end) {
- ti = proto_tree_add_text(cluster_list_tree, NullTVB,
- q - pd - 3 + aoff, 4, "Cluster identifier: %s",
- ip_to_str(q));
+ tvb_memcpy(tvb, ipaddr, q, 4);
+ ti = proto_tree_add_text(cluster_list_tree, tvb,
+ q - 3 + aoff, 4, "Cluster identifier: %s",
+ ip_to_str(ipaddr));
q += 4;
}
@@ -1211,7 +1218,7 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
free(cluster_list_str);
break;
default:
- proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, tvb, o + i + aoff, alen,
"Unknown (%d %s)", alen, (alen == 1) ? "byte" :
"bytes");
break;
@@ -1219,22 +1226,22 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
i += alen + aoff;
}
- p += 2 + len;
+ o += 2 + len;
/* NLRI */
- len = hlen - (p - &pd[offset]);
+ len = offset + hlen - o;
/* parse prefixes */
if (len > 0) {
- ti = proto_tree_add_text(tree, NullTVB, p - pd, len,
+ ti = proto_tree_add_text(tree, tvb, o, len,
"Network layer reachability information: %u %s", len,
(len == 1) ? "byte" : "bytes");
subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
- end = p + len;
- while (p < end) {
- i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
- proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
- p += i;
+ end = o + len;
+ while (o < end) {
+ i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
+ proto_tree_add_text(subtree, tvb, o, i, "%s", junk_buf);
+ o += i;
}
}
}
@@ -1244,19 +1251,18 @@ dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
* Dissect a BGP NOTIFICATION message.
*/
static void
-dissect_bgp_notification(const u_char *pd, int offset, frame_data *fd,
- proto_tree *tree)
+dissect_bgp_notification(tvbuff_t *tvb, int offset, proto_tree *tree)
{
struct bgp_notification bgpn; /* BGP NOTIFICATION message */
int hlen; /* message length */
char *p; /* string pointer */
/* snarf message */
- memcpy(&bgpn, &pd[offset], sizeof(bgpn));
+ tvb_memcpy(tvb, bgpn.bgpn_marker, offset, BGP_MIN_NOTIFICATION_MSG_SIZE);
hlen = ntohs(bgpn.bgpn_len);
/* print error code */
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_notification, bgpn_major), 1,
"Error code: %s (%u)",
val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
@@ -1271,13 +1277,13 @@ dissect_bgp_notification(const u_char *pd, int offset, frame_data *fd,
p = "Unspecified";
else
p = "Unknown";
- proto_tree_add_text(tree, NullTVB,
+ proto_tree_add_text(tree, tvb,
offset + offsetof(struct bgp_notification, bgpn_minor), 1,
"Error subcode: %s (%u)", p, bgpn.bgpn_minor);
/* only print if there is optional data */
if (hlen > BGP_MIN_NOTIFICATION_MSG_SIZE) {
- proto_tree_add_text(tree, NullTVB, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
+ proto_tree_add_text(tree, tvb, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
}
}
@@ -1286,26 +1292,23 @@ dissect_bgp_notification(const u_char *pd, int offset, frame_data *fd,
* Dissect a BGP ROUTE-REFRESH message.
*/
static void
-dissect_bgp_route_refresh(const u_char *pd, int offset, frame_data *fd,
- proto_tree *tree)
+dissect_bgp_route_refresh(tvbuff_t *tvb, int offset, proto_tree *tree)
{
- const u_char *p; /* string pointer */
u_int i; /* tmp */
/* AFI */
- p = &pd[offset + BGP_HEADER_SIZE];
- i = pntohs(p);
- proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE, 2,
+ i = tvb_get_ntohs(tvb, offset + BGP_HEADER_SIZE);
+ proto_tree_add_text(tree, tvb, offset + BGP_HEADER_SIZE, 2,
"Address family identifier: %s (%u)",
val_to_str(i, afnumber, "Unknown"), i);
- p += 2;
+ offset += 2;
/* Reserved */
- proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 2, 1,
+ proto_tree_add_text(tree, tvb, offset + BGP_HEADER_SIZE + 2, 1,
"Reserved: 1 byte");
- p++;
+ offset++;
/* SAFI */
- i = *p;
- proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 3, 1,
+ i = tvb_get_guint8(tvb, offset);
+ proto_tree_add_text(tree, tvb, offset + BGP_HEADER_SIZE + 3, 1,
"Subsequent address family identifier: %s (%u)",
val_to_str(i, bgpattr_nlri_safi,
i >= 128 ? "Vendor specific" : "Unknown"),
@@ -1316,12 +1319,11 @@ dissect_bgp_route_refresh(const u_char *pd, int offset, frame_data *fd,
* Dissect a BGP packet.
*/
static void
-dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_bgp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_item *ti; /* tree item */
proto_tree *bgp_tree; /* BGP packet tree */
proto_tree *bgp1_tree; /* BGP message tree */
- const u_char *p; /* packet offset pointer */
int l, i; /* tmp */
int found; /* number of BGP messages in packet */
static u_char marker[] = { /* BGP message marker */
@@ -1332,75 +1334,65 @@ dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
int hlen; /* BGP header length */
char *typ; /* BGP message type */
- if (check_col(fd, COL_PROTOCOL))
- col_set_str(fd, COL_PROTOCOL, "BGP");
- if (check_col(fd, COL_INFO))
- col_clear(fd, COL_INFO);
+ pinfo->current_proto = "BGP";
+ if (check_col(pinfo->fd, COL_PROTOCOL))
+ col_set_str(pinfo->fd, COL_PROTOCOL, "BGP");
+ if (check_col(pinfo->fd, COL_INFO))
+ col_clear(pinfo->fd, COL_INFO);
- p = &pd[offset];
- l = END_OF_FRAME;
+ l = tvb_length(tvb);
i = 0;
found = -1;
/* run through the TCP packet looking for BGP headers */
/* this is done twice, but this way each message type can be
printed in the COL_INFO field */
- while (i < l) {
+ while (i + BGP_HEADER_SIZE <= l) {
+ tvb_memcpy(tvb, bgp.bgp_marker, i, BGP_HEADER_SIZE);
+
/* look for bgp header */
- if (p[i] != 0xff) {
- i++;
- continue;
- }
- CHECK_SIZE(i, sizeof(marker), l);
- if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
+ if (memcmp(bgp.bgp_marker, marker, sizeof(marker)) != 0) {
i++;
continue;
}
- memcpy(&bgp, &p[i], sizeof(bgp));
found++;
hlen = ntohs(bgp.bgp_len);
typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
- if (check_col(fd, COL_INFO)) {
+ if (check_col(pinfo->fd, COL_INFO)) {
if (found == 0)
- col_add_fstr(fd, COL_INFO, "%s", typ);
+ col_add_fstr(pinfo->fd, COL_INFO, "%s", typ);
else
- col_append_fstr(fd, COL_INFO, ", %s", typ);
+ col_append_fstr(pinfo->fd, COL_INFO, ", %s", typ);
}
i += hlen;
}
if (tree) {
- ti = proto_tree_add_item(tree, proto_bgp, NullTVB, offset,
- END_OF_FRAME, FALSE);
+ ti = proto_tree_add_item(tree, proto_bgp, tvb, 0,
+ l, FALSE);
bgp_tree = proto_item_add_subtree(ti, ett_bgp);
- p = &pd[offset];
- l = END_OF_FRAME;
i = 0;
/* now, run through the TCP packet again, this time dissect */
/* each message that we find */
- while (i < l) {
+ while (i + BGP_HEADER_SIZE <= l) {
+ tvb_memcpy(tvb, bgp.bgp_marker, i, BGP_HEADER_SIZE);
+
/* look for bgp header */
- if (p[i] != 0xff) {
- i++;
- continue;
- }
- CHECK_SIZE(i, sizeof(marker), l);
- if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
+ if (memcmp(bgp.bgp_marker, marker, sizeof(marker)) != 0) {
i++;
continue;
}
- memcpy(&bgp, &p[i], sizeof(bgp));
hlen = ntohs(bgp.bgp_len);
typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
- if (END_OF_FRAME < hlen) {
- ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i,
- END_OF_FRAME, "%s (truncated)", typ);
+ if (l < hlen) {
+ ti = proto_tree_add_text(bgp_tree, tvb, i,
+ l, "%s (truncated)", typ);
} else {
- ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i, hlen,
+ ti = proto_tree_add_text(bgp_tree, tvb, i, hlen,
"%s", typ);
}
/* add a different tree for each message type */
@@ -1425,45 +1417,41 @@ dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
break;
}
- proto_tree_add_text(bgp1_tree, NullTVB, offset + i, BGP_MARKER_SIZE,
+ proto_tree_add_text(bgp1_tree, tvb, i, BGP_MARKER_SIZE,
"Marker: 16 bytes");
if (hlen < BGP_HEADER_SIZE || hlen > BGP_MAX_PACKET_SIZE) {
- proto_tree_add_text(bgp1_tree, NullTVB,
- offset + i + offsetof(struct bgp, bgp_len), 2,
+ proto_tree_add_text(bgp1_tree, tvb,
+ i + offsetof(struct bgp, bgp_len), 2,
"Length (invalid): %u %s", hlen,
(hlen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(bgp1_tree, NullTVB,
- offset + i + offsetof(struct bgp, bgp_len), 2,
+ proto_tree_add_text(bgp1_tree, tvb,
+ i + offsetof(struct bgp, bgp_len), 2,
"Length: %u %s", hlen,
(hlen == 1) ? "byte" : "bytes");
}
- proto_tree_add_uint_format(bgp1_tree, hf_bgp_type, NullTVB,
- offset + i +
- offsetof(struct bgp, bgp_type), 1,
+ proto_tree_add_uint_format(bgp1_tree, hf_bgp_type, tvb,
+ i + offsetof(struct bgp, bgp_type), 1,
bgp.bgp_type,
"Type: %s (%u)", typ, bgp.bgp_type);
- CHECK_SIZE(i, hlen, l);
-
- /* handle each message type */
switch (bgp.bgp_type) {
case BGP_OPEN:
- dissect_bgp_open(pd, offset + i, fd, bgp1_tree);
+ dissect_bgp_open(tvb, i, bgp1_tree);
break;
case BGP_UPDATE:
- dissect_bgp_update(pd, offset + i, fd, bgp1_tree);
+ dissect_bgp_update(tvb, i, bgp1_tree);
break;
case BGP_NOTIFICATION:
- dissect_bgp_notification(pd, offset + i, fd, bgp1_tree);
+ dissect_bgp_notification(tvb, i, bgp1_tree);
break;
case BGP_KEEPALIVE:
/* no data in KEEPALIVE messages */
break;
case BGP_ROUTE_REFRESH:
- dissect_bgp_route_refresh(pd, offset + i, fd, bgp1_tree);
+ dissect_bgp_route_refresh(tvb, i, bgp1_tree);
break;
default:
break;
@@ -1516,5 +1504,5 @@ proto_register_bgp(void)
void
proto_reg_handoff_bgp(void)
{
- old_dissector_add("tcp.port", BGP_TCP_PORT, dissect_bgp, proto_bgp);
+ dissector_add("tcp.port", BGP_TCP_PORT, dissect_bgp, proto_bgp);
}