* Routines for BGP packet dissection.
* Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
*
- * $Id
+ * $Id: packet-bgp.c,v 1.31 2001/01/03 06:55:27 guy Exp $
*
* Supports:
* RFC1771 A Border Gateway Protocol 4 (BGP-4)
- * RFC1966 BGP Route Reflection An alternative to full mesh IBGP
+ * RFC1965 Autonomous System Confederations for BGP
* RFC1997 BGP Communities Attribute
- * RFC2283 Multiprotocol Extensions for BGP-4
+ * RFC2796 BGP Route Reflection An alternative to full mesh IBGP
+ * RFC2842 Capabilities Advertisement with BGP-4
+ * RFC2858 Multiprotocol Extensions for BGP-4
+ * RFC2918 Route Refresh Capability for BGP-4
*
* TODO:
- * RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
- * RFC1965 Autonomous System Confederations for BGP
* Destination Preference Attribute for BGP (work in progress)
+ * RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
# include <netinet/in.h>
#endif
-#ifdef NEED_SNPRINTF_H
-# ifdef HAVE_STDARG_H
-# include <stdarg.h>
-# else
-# include <varargs.h>
-# endif
-# include "snprintf.h"
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
#endif
#include <string.h>
#include <glib.h>
+
+#ifdef NEED_SNPRINTF_H
+# include "snprintf.h"
+#endif
+
#include "packet.h"
#include "packet-bgp.h"
#include "packet-ipv6.h"
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
static const value_string bgptypevals[] = {
{ BGP_OPEN, "OPEN Message" },
{ BGP_UPDATE, "UPDATE Message" },
{ BGP_NOTIFICATION, "NOTIFICATION Message" },
{ BGP_KEEPALIVE, "KEEPALIVE Message" },
+ { BGP_ROUTE_REFRESH, "ROUTE-REFRESH Message" },
{ 0, NULL },
};
{ 4, "Unsupported Optional Parameter" },
{ 5, "Authentication Failure" },
{ 6, "Unacceptable Hold Time" },
+ { 7, "Unsupported Capability" },
{ 0, NULL },
};
static const value_string as_segment_type[] = {
{ 1, "AS_SET" },
{ 2, "AS_SEQUENCE" },
- { 3, "AS_CONFED_SET" },
- { 4, "AS_CONFED_SEQUENCE" },
+/* RFC1965 has the wrong values, corrected in */
+/* draft-ietf-idr-bgp-confed-rfc1965bis-01.txt */
+ { 4, "AS_CONFED_SET" },
+ { 3, "AS_CONFED_SEQUENCE" },
{ 0, NULL },
};
};
static int proto_bgp = -1;
+static int hf_bgp_type = -1;
static gint ett_bgp = -1;
static gint ett_bgp_unfeas = -1;
static gint ett_bgp_open = -1;
static gint ett_bgp_update = -1;
static gint ett_bgp_notification = -1;
+static gint ett_bgp_route_refresh = -1; /* ROUTE-REFRESH message tree */
static gint ett_bgp_as_paths = -1;
static gint ett_bgp_communities = -1;
-static gint ett_bgp_cluster_list = -1;
+static gint ett_bgp_cluster_list = -1; /* cluster list tree */
+static gint ett_bgp_options = -1; /* optional parameters tree */
+static gint ett_bgp_option = -1; /* an optional parameter tree */
/*
* Decode an IPv4 prefix.
static void
dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{
- struct bgp_open bgpo; /* BGP OPEN message */
- int hlen; /* message length */
+ struct bgp_open bgpo; /* BGP OPEN message */
+ int hlen; /* message length */
+ u_int i; /* tmp */
+ int ptype; /* parameter type */
+ int plen; /* parameter length */
+ 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 */
+ 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));
hlen = ntohs(bgpo.bgpo_len);
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_open, bgpo_version), 1,
"Version: %u", bgpo.bgpo_version);
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_open, bgpo_myas), 2,
"My AS: %u", ntohs(bgpo.bgpo_myas));
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_open, bgpo_holdtime), 2,
"Hold time: %u", ntohs(bgpo.bgpo_holdtime));
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_open, bgpo_id), 4,
"BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_open, bgpo_optlen), 1,
"Optional parameters length: %u %s", bgpo.bgpo_optlen,
(bgpo.bgpo_optlen == 1) ? "byte" : "bytes");
- if (hlen > sizeof(struct bgp_open)) {
- int openoff;
- openoff = ((char *)&bgpo.bgpo_optlen - (char *)&bgpo) + 1;
- proto_tree_add_text(tree,
- offset + openoff, hlen - openoff,
- "Optional parameters");
+ /* 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,
+ "Optional parameters");
+ subtree = proto_item_add_subtree(ti, ett_bgp_options);
+ p = &pd[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++;
+
+ /* check the type */
+ switch (ptype) {
+ case BGP_OPTION_AUTHENTICATION:
+ proto_tree_add_text(subtree, NullTVB, p - pd - 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++;
+
+ /* check the capability type */
+ switch (ctype) {
+ case BGP_CAPABILITY_RESERVED:
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd - 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,
+ 1, "Parameter type: Capabilities (2)");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ 1, "Parameter length: %u %s", plen,
+ (plen == 1) ? "byte" : "bytes");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ 1, "Capability code: Reserved (0)");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ 1, "Capability length: %u %s", clen,
+ (clen == 1) ? "byte" : "bytes");
+ if (clen != 0) {
+ proto_tree_add_text(subtree2, NullTVB, p - pd,
+ clen, "Capability value: Unknown");
+ }
+ p += clen;
+ break;
+ case BGP_CAPABILITY_MULTIPROTOCOL:
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd - 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,
+ 1, "Parameter type: Capabilities (2)");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ 1, "Parameter length: %u %s", plen,
+ (plen == 1) ? "byte" : "bytes");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ 1, "Capability code: Multiprotocol extensions (%d)",
+ ctype);
+ if (clen != 4) {
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ 1, "Capability length: Invalid");
+ proto_tree_add_text(subtree2, NullTVB, p - pd,
+ clen, "Capability value: Unknown");
+ }
+ else {
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ 1, "Capability length: %u %s", clen,
+ (clen == 1) ? "byte" : "bytes");
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd,
+ clen, "Capability value");
+ subtree3 = proto_item_add_subtree(ti,
+ ett_bgp_option);
+ /* AFI */
+ i = pntohs(p);
+ proto_tree_add_text(subtree3, NullTVB, p - pd,
+ 2, "Address family identifier: %s (%u)",
+ val_to_str(i, afnumber, "Unknown"), i);
+ p += 2;
+ /* Reserved */
+ proto_tree_add_text(subtree3, NullTVB, p - pd,
+ 1, "Reserved: 1 byte");
+ p++;
+ /* SAFI */
+ i = *p;
+ proto_tree_add_text(subtree3, NullTVB, p - pd,
+ 1, "Subsequent address family identifier: %s (%u)",
+ val_to_str(i, bgpattr_nlri_safi,
+ i >= 128 ? "Vendor specific" : "Unknown"), i);
+ p++;
+ }
+ break;
+ case BGP_CAPABILITY_ROUTE_REFRESH:
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd - 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,
+ 1, "Parameter type: Capabilities (2)");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ 1, "Parameter length: %u %s", plen,
+ (plen == 1) ? "byte" : "bytes");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ 1, "Capability code: Route refresh (%d)", ctype);
+ if (clen != 0) {
+ proto_tree_add_text(subtree2, NullTVB, p - pd,
+ clen, "Capability value: Invalid");
+ }
+ else {
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ 1, "Capability length: %u %s", clen,
+ (clen == 1) ? "byte" : "bytes");
+ }
+ p += clen;
+ break;
+ /* unknown capability */
+ default:
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd - 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,
+ 1, "Parameter type: Capabilities (2)");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
+ 1, "Parameter length: %u %s", plen,
+ (plen == 1) ? "byte" : "bytes");
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
+ 1, "Capability code: %s (%d)",
+ ctype >= 128 ? "Private use" : "Unknown", ctype);
+ proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
+ 1, "Capability length: %u %s", clen,
+ (clen == 1) ? "byte" : "bytes");
+ if (clen != 0) {
+ proto_tree_add_text(subtree2, NullTVB, p - pd,
+ clen, "Capability value: Unknown");
+ }
+ p += clen;
+ break;
+ }
+ break;
+ default:
+ proto_tree_add_text(subtree, NullTVB, p - pd - 2, 2 + plen,
+ "Unknown optional parameter");
+ break;
+ }
+ }
}
}
/* check for withdrawals */
len = pntohs(p);
- proto_tree_add_text(tree, p - pd, 2,
+ proto_tree_add_text(tree, NullTVB, p - pd, 2,
"Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
p += 2;
/* parse unfeasible prefixes */
if (len > 0) {
- ti = proto_tree_add_text(tree, p - pd, len, "Withdrawn routes:");
+ ti = proto_tree_add_text(tree, NullTVB, p - pd, 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, p - pd, i, "%s", junk_buf);
+ proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
p += i;
}
}
/* check for advertisements */
len = pntohs(p);
- proto_tree_add_text(tree, p - pd, 2, "Total path attribute length: %u %s",
+ proto_tree_add_text(tree, NullTVB, p - pd, 2, "Total path attribute length: %u %s",
len, (len == 1) ? "byte" : "bytes");
/* path attributes */
-/* --- move --- */
if (len > 0) {
- ti = proto_tree_add_text(tree, p - pd + 2, len, "Path attributes");
+ ti = proto_tree_add_text(tree, NullTVB, p - pd + 2, len, "Path attributes");
subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
i = 2;
while (i < len) {
if (alen != 1)
goto default_attribute_top;
msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
msg, alen + aoff, (alen + aoff == 1) ? "byte" :
if (type == AS_SET) {
snprintf(as_path_str, 2, "{");
}
- length = *q++;
-
- /* ignore confederation types until we support them */
- if (type == AS_CONFED_SET || type == AS_CONFED_SEQUENCE) {
- q += length;
- break;
+ else if (type == AS_CONFED_SET) {
+ snprintf(as_path_str, 2, "[");
}
+ else if (type == AS_CONFED_SEQUENCE) {
+ snprintf(as_path_str, 2, "(");
+ }
+ length = *q++;
/* snarf each value in path */
for (j = 0; j < length; j++) {
snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
- (type == AS_SET) ? ", " : " ");
+ (type == AS_SET || type == AS_CONFED_SET)
+ ? ", " : " ");
strncat(as_path_str, junk_buf, sizeof(junk_buf));
q += 2;
}
if (type == AS_SET) {
as_path_str[strlen(as_path_str) - 2] = '}';
}
+ else if (type == AS_CONFED_SET) {
+ as_path_str[strlen(as_path_str) - 2] = ']';
+ }
+ else if (type == AS_CONFED_SEQUENCE) {
+ as_path_str[strlen(as_path_str) - 1] = ')';
+ }
else {
as_path_str[strlen(as_path_str) - 1] = '\0';
}
if (alen == 0)
strncpy(as_path_str, "empty", 6);
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
as_path_str, alen + aoff,
case BGPTYPE_NEXT_HOP:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + 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)
case BGPTYPE_MULTI_EXIT_DISC:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
pntohl(&p[i + aoff]), alen + aoff,
case BGPTYPE_LOCAL_PREF:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %u (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
pntohl(&p[i + aoff]), alen + aoff,
case BGPTYPE_ATOMIC_AGGREGATE:
if (alen != 0)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
case BGPTYPE_AGGREGATOR:
if (alen != 6)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: AS: %u origin: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
pntohs(&p[i + aoff]),
/* cleanup end of string */
communities_str[strlen(communities_str) - 1] = '\0';
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
communities_str, alen + aoff,
case BGPTYPE_ORIGINATOR_ID:
if (alen != 4)
goto default_attribute_top;
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + 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)
/* cleanup end of string */
cluster_list_str[strlen(cluster_list_str) - 1] = '\0';
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s: %s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
cluster_list_str, alen + aoff,
break;
default:
default_attribute_top:
- ti = proto_tree_add_text(subtree, p - pd + i, alen + aoff,
+ ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
"%s (%u %s)",
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
/* stomp last ", " */
j = strlen(junk_buf);
junk_buf[j - 2] = '\0';
- ti = proto_tree_add_text(subtree2,
+ ti = proto_tree_add_text(subtree2, NullTVB,
p - pd + 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,
+ proto_tree_add_text(subtree3, NullTVB,
p - pd + 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,
+ proto_tree_add_text(subtree3, NullTVB,
p - pd + 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,
+ proto_tree_add_text(subtree3, NullTVB,
p - pd + 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,
+ proto_tree_add_text(subtree3, NullTVB,
p - pd + 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,
+ proto_tree_add_text(subtree2, NullTVB,
p - pd + 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, p - pd + i + sizeof(bgpa),
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + sizeof(bgpa),
aoff - sizeof(bgpa), "Length: %d %s", alen,
(alen == 1) ? "byte" : "bytes");
switch (bgpa.bgpa_type) {
case BGPTYPE_ORIGIN:
if (alen != 1) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + 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, p - pd + i + aoff, 1,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
"Origin: %s (%u)", msg, p[i + aoff]);
}
break;
break;
}
- ti = proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"AS path: %s", as_path_str);
as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
end = p + alen + i + 3;
q = p + i + 3;
- /* snarf each AS path tuple */
+ /* 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++;
if (type == AS_SET) {
snprintf(as_path_str, 2, "{");
}
- length = *q++;
-
- /* ignore confederation types until we support them */
- if (type == AS_CONFED_SET || type == AS_CONFED_SEQUENCE) {
- q += length;
- break;
+ else if (type == AS_CONFED_SET) {
+ snprintf(as_path_str, 2, "[");
+ }
+ else if (type == AS_CONFED_SEQUENCE) {
+ snprintf(as_path_str, 2, "(");
}
+ length = *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),
- (type == AS_SET) ? ", " : " ");
+ (type == AS_SET || type == AS_CONFED_SET)
+ ? ", " : " ");
strncat(as_path_str, junk_buf, sizeof(junk_buf));
q += 2;
}
if (type == AS_SET) {
as_path_str[strlen(as_path_str) - 2] = '}';
}
+ else if (type == AS_CONFED_SET) {
+ as_path_str[strlen(as_path_str) - 2] = ']';
+ }
+ else if (type == AS_CONFED_SEQUENCE) {
+ as_path_str[strlen(as_path_str) - 1] = ')';
+ }
else {
as_path_str[strlen(as_path_str) - 1] = '\0';
}
/* length here means number of ASs, ie length * 2 bytes */
- ti = proto_tree_add_text(as_paths_tree,
+ ti = proto_tree_add_text(as_paths_tree, NullTVB,
q - pd - 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, q - pd - length * 2 - 2,
+ proto_tree_add_text(as_path_tree, NullTVB, q - pd - 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, q - pd - length * 2 - 1,
+ proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 1,
1, "Path segment length: %u %s", length,
(length == 1) ? "AS" : "ASs");
- proto_tree_add_text(as_path_tree, q - pd - length * 2,
+
+ /* backup and reprint path segment value(s) only */
+ q -= 2 * length;
+ as_path_str[0] = '\0';
+ for (j = 0; j < length; j++) {
+ snprintf(junk_buf, sizeof(junk_buf), "%u ", pntohs(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,
length * 2, "Path segment value: %s", as_path_str);
}
break;
case BGPTYPE_NEXT_HOP:
if (alen != 4) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Next hop (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Next hop: %s", ip_to_str(&p[i + aoff]));
}
break;
case BGPTYPE_MULTI_EXIT_DISC:
if (alen != 4) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Multiple exit discriminator (invalid): %u %s",
alen, (alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Multiple exit discriminator: %u",
pntohl(&p[i + aoff]));
}
break;
case BGPTYPE_LOCAL_PREF:
if (alen != 4) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Local preference (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Local preference: %u", pntohl(&p[i + aoff]));
}
break;
case BGPTYPE_ATOMIC_AGGREGATE:
if (alen != 0) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + 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, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Aggregator (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
"Aggregator AS: %u", pntohs(&p[i + aoff]));
- proto_tree_add_text(subtree2, p - pd + i + aoff + 2, 4,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 4,
"Aggregator origin: %s",
ip_to_str(&p[i + aoff + 2]));
}
break;
case BGPTYPE_COMMUNITIES:
if (alen % 4 != 0) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Communities (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
free(communities_str);
break;
}
- ti = proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Communities: %s", communities_str);
communities_tree = proto_item_add_subtree(ti,
ett_bgp_communities);
if (pntohs(q) == FOURHEX0 || pntohs(q) == FOURHEXF) {
/* check for well-known communities */
if (pntohl(q) == BGP_COMM_NO_EXPORT)
- proto_tree_add_text(communities_tree,
+ 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,
+ proto_tree_add_text(communities_tree, NullTVB,
q - pd - 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,
+ proto_tree_add_text(communities_tree, NullTVB,
q - pd - 3 + aoff, 4,
"Community: NO_EXPORT_SUBCONFED (0x%x)",
pntohl(q));
else
- proto_tree_add_text(communities_tree,
+ proto_tree_add_text(communities_tree, NullTVB,
q - pd - 3 + aoff, 4,
"Community (reserved): 0x%x", pntohl(q));
}
else {
- ti = proto_tree_add_text(communities_tree,
+ ti = proto_tree_add_text(communities_tree, NullTVB,
q - pd - 3 + aoff, 4, "Community: %u:%u",
pntohs(q), pntohs(q + 2));
community_tree = proto_item_add_subtree(ti,
ett_bgp_communities);
- proto_tree_add_text(community_tree, q - pd - 3 + aoff,
+ proto_tree_add_text(community_tree, NullTVB, q - pd - 3 + aoff,
2, "Community AS: %u", pntohs(q));
- proto_tree_add_text(community_tree, q - pd - 1 + aoff,
+ proto_tree_add_text(community_tree, NullTVB, q - pd - 1 + aoff,
2, "Community value: %u", pntohs(q + 2));
}
break;
case BGPTYPE_ORIGINATOR_ID:
if (alen != 4) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Originator identifier (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Originator identifier: %s",
ip_to_str(&p[i + aoff]));
}
break;
case BGPTYPE_MP_REACH_NLRI:
af = pntohs(&p[i + aoff]);
- proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
- proto_tree_add_text(subtree2, p - pd + i + aoff + 2, 1,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + 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, p - pd + i + aoff + 3, 1,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3, 1,
"Next hop network address (%d %s)",
p[i + aoff + 3], (p[i + aoff + 3] == 1) ? "byte" :
"bytes");
int j, advance;
const char *s;
- subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_reach_nlri);
+ subtree3 = proto_item_add_subtree(ti,
+ ett_bgp_mp_reach_nlri);
j = 0;
while (j < p[i + aoff + 3]) {
s = ip6_to_str((struct e_in6_addr *)
&p[i + aoff + 4 + j]);
}
- proto_tree_add_text(subtree3,
+ proto_tree_add_text(subtree3, NullTVB,
p - pd + i + aoff + 4 + j, advance,
"Next hop: %s", s);
j += advance;
aoff += (p[i + aoff + 3] + 4);
off = 0;
snpa = p[i + aoff];
- ti = proto_tree_add_text(subtree2, p - pd + i + aoff, 1,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
"Subnetwork points of attachment: %u", snpa);
off++;
if (snpa)
- subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_reach_nlri);
+ subtree3 = proto_item_add_subtree(ti,
+ ett_bgp_mp_reach_nlri);
for (/*nothing*/; snpa > 0; snpa--) {
- proto_tree_add_text(subtree3, p - pd + i + aoff + off, 1,
+ proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off, 1,
"SNPA length: %u", p[i + aoff + off]);
off++;
- proto_tree_add_text(subtree3, p - pd + i + aoff + 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");
alen -= off;
aoff += off;
- ti = proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Network layer reachability information (%u %s)",
alen, (alen == 1) ? "byte" : "bytes");
if (alen)
- subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_unreach_nlri);
+ subtree3 = proto_item_add_subtree(ti,
+ ett_bgp_mp_unreach_nlri);
while (alen > 0) {
int advance;
char buf[256];
break;
if (alen < advance)
break;
- proto_tree_add_text(subtree3, p - pd + i + aoff, advance,
+ proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
"Network layer reachability information: %s", buf);
alen -= advance;
break;
case BGPTYPE_MP_UNREACH_NLRI:
af = pntohs(&p[i + aoff]);
- proto_tree_add_text(subtree2, p - pd + i + aoff, 2,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
"Address family: %s (%u)",
val_to_str(af, afnumber, "Unknown"), af);
- proto_tree_add_text(subtree2, p - pd + i + aoff + 2, 1,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + 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, p - pd + i + aoff + 3,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3,
alen - 3, "Withdrawn routes (%u %s)", alen - 3,
(alen - 3 == 1) ? "byte" : "bytes");
alen -= 3;
aoff += 3;
if (alen > 0)
- subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_unreach_nlri);
+ subtree3 = proto_item_add_subtree(ti,
+ ett_bgp_mp_unreach_nlri);
while (alen > 0) {
int advance;
char buf[256];
break;
if (alen < advance)
break;
- proto_tree_add_text(subtree3, p - pd + i + aoff, advance,
+ proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
"Withdrawn route: %s", buf);
alen -= advance;
break;
case BGPTYPE_CLUSTER_LIST:
if (alen % 4 != 0) {
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Cluster list (invalid): %u %s", alen,
(alen == 1) ? "byte" : "bytes");
free(cluster_list_str);
break;
}
- ti = proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Cluster list: %s", cluster_list_str);
cluster_list_tree = proto_item_add_subtree(ti,
ett_bgp_cluster_list);
/* snarf each cluster identifier */
while (q < end) {
- ti = proto_tree_add_text(cluster_list_tree,
+ ti = proto_tree_add_text(cluster_list_tree, NullTVB,
q - pd - 3 + aoff, 4, "Cluster identifier: %s",
ip_to_str(q));
free(cluster_list_str);
break;
default:
- proto_tree_add_text(subtree2, p - pd + i + aoff, alen,
+ proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
"Unknown (%d %s)", alen, (alen == 1) ? "byte" :
"bytes");
break;
i += alen + aoff;
}
-/* --- move --- */
p += 2 + len;
/* NLRI */
/* parse prefixes */
if (len > 0) {
- ti = proto_tree_add_text(tree, p - pd, len,
+ ti = proto_tree_add_text(tree, NullTVB, p - pd, 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, p - pd, i, "%s", junk_buf);
+ proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
p += i;
}
}
hlen = ntohs(bgpn.bgpn_len);
/* print error code */
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
offset + offsetof(struct bgp_notification, bgpn_major), 1,
"Error code: %s (%u)",
val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
p = "Unspecified";
else
p = "Unknown";
- proto_tree_add_text(tree,
+ proto_tree_add_text(tree, NullTVB,
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, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
+ proto_tree_add_text(tree, NullTVB, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
}
}
+/*
+ * Dissect a BGP ROUTE-REFRESH message.
+ */
+static void
+dissect_bgp_route_refresh(const u_char *pd, int offset, frame_data *fd,
+ 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,
+ "Address family identifier: %s (%u)",
+ val_to_str(i, afnumber, "Unknown"), i);
+ p += 2;
+ /* Reserved */
+ proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 2, 1,
+ "Reserved: 1 byte");
+ p++;
+ /* SAFI */
+ i = *p;
+ proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 3, 1,
+ "Subsequent address family identifier: %s (%u)",
+ val_to_str(i, bgpattr_nlri_safi,
+ i >= 128 ? "Vendor specific" : "Unknown"),
+ i);
+}
+
/*
* Dissect a BGP packet.
*/
-void
+static void
dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{
proto_item *ti; /* tree item */
int hlen; /* BGP header length */
char *typ; /* BGP message type */
+ OLD_CHECK_DISPLAY_AS_DATA(proto_bgp, pd, offset, fd, tree);
+
if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "BGP");
+ col_set_str(fd, COL_PROTOCOL, "BGP");
p = &pd[offset];
l = END_OF_FRAME;
}
if (tree) {
- ti = proto_tree_add_text(tree, offset, END_OF_FRAME,
- "Border Gateway Protocol");
+ ti = proto_tree_add_item(tree, proto_bgp, NullTVB, offset,
+ END_OF_FRAME, FALSE);
bgp_tree = proto_item_add_subtree(ti, ett_bgp);
p = &pd[offset];
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, offset + i, END_OF_FRAME,
- "%s (truncated)", typ);
+ ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i,
+ END_OF_FRAME, "%s (truncated)", typ);
} else {
- ti = proto_tree_add_text(bgp_tree, offset + i, hlen,
+ ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i, hlen,
"%s", typ);
}
/* add a different tree for each message type */
case BGP_KEEPALIVE:
bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
break;
+ case BGP_ROUTE_REFRESH:
+ bgp1_tree = proto_item_add_subtree(ti, ett_bgp_route_refresh);
+ break;
default:
bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
break;
}
- proto_tree_add_text(bgp1_tree, offset + i, BGP_MARKER_SIZE,
+ proto_tree_add_text(bgp1_tree, NullTVB, offset + i, BGP_MARKER_SIZE,
"Marker: 16 bytes");
if (hlen < BGP_HEADER_SIZE || hlen > BGP_MAX_PACKET_SIZE) {
- proto_tree_add_text(bgp1_tree,
+ proto_tree_add_text(bgp1_tree, NullTVB,
offset + i + offsetof(struct bgp, bgp_len), 2,
"Length (invalid): %u %s", hlen,
(hlen == 1) ? "byte" : "bytes");
} else {
- proto_tree_add_text(bgp1_tree,
+ proto_tree_add_text(bgp1_tree, NullTVB,
offset + i + offsetof(struct bgp, bgp_len), 2,
"Length: %u %s", hlen,
(hlen == 1) ? "byte" : "bytes");
}
- proto_tree_add_text(bgp1_tree,
- offset + i + offsetof(struct bgp, bgp_type), 1,
- "Type: %s (%u)", typ, bgp.bgp_type);
+ proto_tree_add_uint_format(bgp1_tree, hf_bgp_type, NullTVB,
+ offset + i +
+ offsetof(struct bgp, bgp_type), 1,
+ bgp.bgp_type,
+ "Type: %s (%u)", typ, bgp.bgp_type);
CHECK_SIZE(i, hlen, l);
case BGP_KEEPALIVE:
/* no data in KEEPALIVE messages */
break;
+ case BGP_ROUTE_REFRESH:
+ dissect_bgp_route_refresh(pd, offset + i, fd, bgp1_tree);
+ break;
default:
break;
}
void
proto_register_bgp(void)
{
+
+ static hf_register_info hf[] = {
+ { &hf_bgp_type,
+ { "BGP message type", "bgp.type", FT_UINT8, BASE_HEX,
+ VALS(bgptypevals), 0x0, "BGP message type" }},
+ };
+
static gint *ett[] = {
&ett_bgp,
&ett_bgp_unfeas,
&ett_bgp_open,
&ett_bgp_update,
&ett_bgp_notification,
+ &ett_bgp_route_refresh,
&ett_bgp_as_paths,
&ett_bgp_communities,
&ett_bgp_cluster_list,
+ &ett_bgp_options,
+ &ett_bgp_option,
};
- proto_bgp = proto_register_protocol("Border Gateway Protocol", "bgp");
+ proto_bgp = proto_register_protocol("Border Gateway Protocol",
+ "BGP", "bgp");
+ proto_register_field_array(proto_bgp, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
+
+void
+proto_reg_handoff_bgp(void)
+{
+ old_dissector_add("tcp.port", BGP_TCP_PORT, dissect_bgp);
+}