1999-10-15 17:00:47 +00:00
|
|
|
/* packet-bgp.c
|
1999-11-06 01:28:50 +00:00
|
|
|
* Routines for BGP packet dissection.
|
1999-10-15 17:00:47 +00:00
|
|
|
* Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
|
|
|
|
*
|
2001-01-09 06:32:10 +00:00
|
|
|
* $Id: packet-bgp.c,v 1.32 2001/01/09 06:31:34 guy Exp $
|
1999-11-06 01:28:50 +00:00
|
|
|
*
|
|
|
|
* Supports:
|
|
|
|
* RFC1771 A Border Gateway Protocol 4 (BGP-4)
|
2000-04-11 14:21:37 +00:00
|
|
|
* RFC1965 Autonomous System Confederations for BGP
|
1999-11-22 07:05:21 +00:00
|
|
|
* RFC1997 BGP Communities Attribute
|
2000-12-25 05:28:40 +00:00
|
|
|
* 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
|
1999-11-06 01:28:50 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* Destination Preference Attribute for BGP (work in progress)
|
2000-04-11 14:21:37 +00:00
|
|
|
* RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
|
1999-10-15 17:00:47 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2000-01-07 22:05:43 +00:00
|
|
|
* By Gerald Combs <gerald@zing.org>
|
1999-10-15 17:00:47 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
2000-08-11 13:37:21 +00:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
#include <arpa/inet.h>
|
1999-10-16 15:35:27 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2000-08-11 13:37:21 +00:00
|
|
|
|
|
|
|
#ifdef NEED_SNPRINTF_H
|
|
|
|
# include "snprintf.h"
|
|
|
|
#endif
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
#include "packet.h"
|
1999-11-01 06:57:01 +00:00
|
|
|
#include "packet-bgp.h"
|
1999-10-16 15:35:27 +00:00
|
|
|
#include "packet-ipv6.h"
|
2000-01-10 17:33:17 +00:00
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
static const value_string bgptypevals[] = {
|
1999-11-01 06:57:01 +00:00
|
|
|
{ BGP_OPEN, "OPEN Message" },
|
|
|
|
{ BGP_UPDATE, "UPDATE Message" },
|
|
|
|
{ BGP_NOTIFICATION, "NOTIFICATION Message" },
|
|
|
|
{ BGP_KEEPALIVE, "KEEPALIVE Message" },
|
2000-12-25 05:28:40 +00:00
|
|
|
{ BGP_ROUTE_REFRESH, "ROUTE-REFRESH Message" },
|
1999-10-15 17:00:47 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bgpnotify_major[] = {
|
|
|
|
{ 1, "Message Header Error" },
|
|
|
|
{ 2, "OPEN Message Error" },
|
|
|
|
{ 3, "UPDATE Message Error" },
|
|
|
|
{ 4, "Hold Timer Expired" },
|
|
|
|
{ 5, "Finite State Machine Error" },
|
|
|
|
{ 6, "Cease" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bgpnotify_minor_1[] = {
|
|
|
|
{ 1, "Connection Not Synchronized" },
|
|
|
|
{ 2, "Bad Message Length" },
|
|
|
|
{ 3, "Bad Message Type" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bgpnotify_minor_2[] = {
|
|
|
|
{ 1, "Unsupported Version Number" },
|
|
|
|
{ 2, "Bad Peer AS" },
|
|
|
|
{ 3, "Bad BGP Identifier" },
|
|
|
|
{ 4, "Unsupported Optional Parameter" },
|
|
|
|
{ 5, "Authentication Failure" },
|
|
|
|
{ 6, "Unacceptable Hold Time" },
|
2000-12-28 05:13:14 +00:00
|
|
|
{ 7, "Unsupported Capability" },
|
1999-10-15 17:00:47 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bgpnotify_minor_3[] = {
|
|
|
|
{ 1, "Malformed Attribute List" },
|
|
|
|
{ 2, "Unrecognized Well-known Attribute" },
|
|
|
|
{ 3, "Missing Well-known Attribute" },
|
|
|
|
{ 4, "Attribute Flags Error" },
|
|
|
|
{ 5, "Attribute Length Error" },
|
|
|
|
{ 6, "Invalid ORIGIN Attribute" },
|
|
|
|
{ 7, "AS Routing Loop" },
|
|
|
|
{ 8, "Invalid NEXT_HOP Attribute" },
|
|
|
|
{ 9, "Optional Attribute Error" },
|
|
|
|
{ 10, "Invalid Network Field" },
|
|
|
|
{ 11, "Malformed AS_PATH" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string *bgpnotify_minor[] = {
|
|
|
|
NULL, bgpnotify_minor_1, bgpnotify_minor_2, bgpnotify_minor_3,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string bgpattr_origin[] = {
|
|
|
|
{ 0, "IGP" },
|
|
|
|
{ 1, "EGP" },
|
|
|
|
{ 2, "INCOMPLETE" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
static const value_string as_segment_type[] = {
|
|
|
|
{ 1, "AS_SET" },
|
|
|
|
{ 2, "AS_SEQUENCE" },
|
2000-12-28 05:13:14 +00:00
|
|
|
/* RFC1965 has the wrong values, corrected in */
|
|
|
|
/* draft-ietf-idr-bgp-confed-rfc1965bis-01.txt */
|
2000-04-11 14:21:37 +00:00
|
|
|
{ 4, "AS_CONFED_SET" },
|
|
|
|
{ 3, "AS_CONFED_SEQUENCE" },
|
1999-11-22 07:05:21 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
static const value_string bgpattr_type[] = {
|
|
|
|
{ BGPTYPE_ORIGIN, "ORIGIN" },
|
|
|
|
{ BGPTYPE_AS_PATH, "AS_PATH" },
|
|
|
|
{ BGPTYPE_NEXT_HOP, "NEXT_HOP" },
|
|
|
|
{ BGPTYPE_MULTI_EXIT_DISC, "MULTI_EXIT_DISC" },
|
|
|
|
{ BGPTYPE_LOCAL_PREF, "LOCAL_PREF" },
|
|
|
|
{ BGPTYPE_ATOMIC_AGGREGATE, "ATOMIC_AGGREGATE" },
|
|
|
|
{ BGPTYPE_AGGREGATOR, "AGGREGATOR" },
|
1999-11-22 07:05:21 +00:00
|
|
|
{ BGPTYPE_COMMUNITIES, "COMMUNITIES" },
|
|
|
|
{ BGPTYPE_ORIGINATOR_ID, "ORIGINATOR_ID" },
|
|
|
|
{ BGPTYPE_CLUSTER_LIST, "CLUSTER_LIST" },
|
1999-10-16 00:21:07 +00:00
|
|
|
{ BGPTYPE_MP_REACH_NLRI, "MP_REACH_NLRI" },
|
|
|
|
{ BGPTYPE_MP_UNREACH_NLRI, "MP_UNREACH_NLRI" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Subsequent address family identifier, RFC2283 section 7 */
|
|
|
|
static const value_string bgpattr_nlri_safi[] = {
|
1999-10-16 15:35:27 +00:00
|
|
|
{ 0, "Reserved" },
|
1999-10-16 00:21:07 +00:00
|
|
|
{ 1, "Unicast" },
|
|
|
|
{ 2, "Multicast" },
|
|
|
|
{ 3, "Unicast+Multicast" },
|
1999-10-15 17:00:47 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
1999-10-16 15:35:27 +00:00
|
|
|
static const value_string afnumber[] = {
|
|
|
|
{ 0, "Reserved" },
|
|
|
|
{ AFNUM_INET, "IPv4" },
|
|
|
|
{ AFNUM_INET6, "IPv6" },
|
|
|
|
{ AFNUM_NSAP, "NSAP" },
|
|
|
|
{ AFNUM_HDLC, "HDLC" },
|
|
|
|
{ AFNUM_BBN1822, "BBN 1822" },
|
|
|
|
{ AFNUM_802, "802" },
|
|
|
|
{ AFNUM_E163, "E.163" },
|
|
|
|
{ AFNUM_E164, "E.164" },
|
|
|
|
{ AFNUM_F69, "F.69" },
|
|
|
|
{ AFNUM_X121, "X.121" },
|
|
|
|
{ AFNUM_IPX, "IPX" },
|
|
|
|
{ AFNUM_ATALK, "Appletalk" },
|
|
|
|
{ AFNUM_DECNET, "Decnet IV" },
|
|
|
|
{ AFNUM_BANYAN, "Banyan Vines" },
|
|
|
|
{ AFNUM_E164NSAP, "E.164 with NSAP subaddress" },
|
|
|
|
{ 65535, "Reserved" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
static int proto_bgp = -1;
|
2000-08-20 18:10:12 +00:00
|
|
|
static int hf_bgp_type = -1;
|
1999-10-15 17:00:47 +00:00
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_bgp = -1;
|
|
|
|
static gint ett_bgp_unfeas = -1;
|
|
|
|
static gint ett_bgp_attrs = -1;
|
|
|
|
static gint ett_bgp_attr = -1;
|
|
|
|
static gint ett_bgp_attr_flags = -1;
|
|
|
|
static gint ett_bgp_mp_reach_nlri = -1;
|
|
|
|
static gint ett_bgp_mp_unreach_nlri = -1;
|
|
|
|
static gint ett_bgp_nlri = -1;
|
|
|
|
static gint ett_bgp_open = -1;
|
|
|
|
static gint ett_bgp_update = -1;
|
|
|
|
static gint ett_bgp_notification = -1;
|
2000-12-25 05:28:40 +00:00
|
|
|
static gint ett_bgp_route_refresh = -1; /* ROUTE-REFRESH message tree */
|
1999-11-23 20:56:49 +00:00
|
|
|
static gint ett_bgp_as_paths = -1;
|
2000-01-25 09:24:42 +00:00
|
|
|
static gint ett_bgp_communities = -1;
|
2000-12-25 05:28:40 +00:00
|
|
|
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 */
|
1999-11-16 11:44:20 +00:00
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
/*
|
|
|
|
* Decode an IPv4 prefix.
|
|
|
|
*/
|
1999-10-16 15:35:27 +00:00
|
|
|
static int
|
|
|
|
decode_prefix4(const u_char *pd, char *buf, int buflen)
|
|
|
|
{
|
1999-11-22 07:05:21 +00:00
|
|
|
guint8 addr[4]; /* IP address */
|
|
|
|
int plen; /* prefix length */
|
|
|
|
int length; /* number of octets needed for prefix */
|
1999-10-16 15:35:27 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* snarf length */
|
1999-10-16 15:35:27 +00:00
|
|
|
plen = pd[0];
|
|
|
|
if (plen < 0 || 32 < plen)
|
|
|
|
return -1;
|
1999-11-22 07:05:21 +00:00
|
|
|
length = (plen + 7) / 8;
|
1999-10-16 15:35:27 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* snarf prefix */
|
1999-10-16 15:35:27 +00:00
|
|
|
memset(addr, 0, sizeof(addr));
|
1999-11-22 07:05:21 +00:00
|
|
|
memcpy(addr, &pd[1], length);
|
1999-10-16 15:35:27 +00:00
|
|
|
if (plen % 8)
|
1999-11-22 07:05:21 +00:00
|
|
|
addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
|
|
|
|
/* hand back a formatted string */
|
1999-10-16 15:35:27 +00:00
|
|
|
snprintf(buf, buflen, "%s/%d", ip_to_str(addr), plen);
|
1999-11-22 07:05:21 +00:00
|
|
|
return(1 + length);
|
1999-10-16 15:35:27 +00:00
|
|
|
}
|
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
/*
|
|
|
|
* Decode an IPv6 prefix.
|
|
|
|
*/
|
1999-10-16 15:35:27 +00:00
|
|
|
static int
|
|
|
|
decode_prefix6(const u_char *pd, char *buf, int buflen)
|
|
|
|
{
|
1999-11-22 07:05:21 +00:00
|
|
|
struct e_in6_addr addr; /* IPv6 address */
|
|
|
|
int plen; /* prefix length */
|
|
|
|
int length; /* number of octets needed for prefix */
|
1999-10-16 15:35:27 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* snarf length */
|
1999-10-16 15:35:27 +00:00
|
|
|
plen = pd[0];
|
|
|
|
if (plen < 0 || 128 < plen)
|
|
|
|
return -1;
|
1999-11-22 07:05:21 +00:00
|
|
|
length = (plen + 7) / 8;
|
1999-10-16 15:35:27 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* snarf prefix */
|
1999-10-16 15:35:27 +00:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
1999-11-22 07:05:21 +00:00
|
|
|
memcpy(&addr, &pd[1], length);
|
1999-10-16 15:35:27 +00:00
|
|
|
if (plen % 8)
|
1999-11-22 07:05:21 +00:00
|
|
|
addr.s6_addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
|
|
|
|
/* hand back a formatted string */
|
1999-10-16 15:35:27 +00:00
|
|
|
snprintf(buf, buflen, "%s/%d", ip6_to_str(&addr), plen);
|
1999-11-22 07:05:21 +00:00
|
|
|
return(1 + length);
|
1999-10-16 15:35:27 +00:00
|
|
|
}
|
|
|
|
|
1999-11-06 01:28:50 +00:00
|
|
|
/*
|
|
|
|
* Dissect a BGP OPEN message.
|
|
|
|
*/
|
1999-10-15 17:00:47 +00:00
|
|
|
static void
|
|
|
|
dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
|
|
|
|
{
|
2000-12-25 05:28:40 +00:00
|
|
|
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 */
|
1999-10-15 17:00:47 +00:00
|
|
|
|
1999-11-06 01:28:50 +00:00
|
|
|
/* snarf OPEN message */
|
1999-10-15 17:00:47 +00:00
|
|
|
memcpy(&bgpo, &pd[offset], sizeof(bgpo));
|
|
|
|
hlen = ntohs(bgpo.bgpo_len);
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_open, bgpo_version), 1,
|
|
|
|
"Version: %u", bgpo.bgpo_version);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_open, bgpo_myas), 2,
|
|
|
|
"My AS: %u", ntohs(bgpo.bgpo_myas));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_open, bgpo_holdtime), 2,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Hold time: %u", ntohs(bgpo.bgpo_holdtime));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_open, bgpo_id), 4,
|
1999-11-22 07:05:21 +00:00
|
|
|
"BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_open, bgpo_optlen), 1,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Optional parameters length: %u %s", bgpo.bgpo_optlen,
|
1999-11-06 01:28:50 +00:00
|
|
|
(bgpo.bgpo_optlen == 1) ? "byte" : "bytes");
|
|
|
|
|
2000-12-25 05:28:40 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
/*
|
|
|
|
* Dissect a BGP UPDATE message.
|
|
|
|
*/
|
1999-10-15 17:00:47 +00:00
|
|
|
static void
|
|
|
|
dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
|
|
|
|
proto_tree *tree)
|
2000-03-29 06:27:54 +00:00
|
|
|
{
|
|
|
|
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 */
|
|
|
|
int len; /* tmp */
|
|
|
|
proto_item *ti; /* tree item */
|
|
|
|
proto_tree *subtree; /* subtree for attibutes */
|
|
|
|
proto_tree *subtree2; /* subtree for attibutes */
|
|
|
|
proto_tree *subtree3; /* subtree for attibutes */
|
|
|
|
proto_tree *as_paths_tree; /* subtree for AS_PATHs */
|
|
|
|
proto_tree *as_path_tree; /* subtree for AS_PATH */
|
|
|
|
proto_tree *communities_tree; /* subtree for COMMUNITIES */
|
|
|
|
proto_tree *community_tree; /* subtree for a community */
|
|
|
|
proto_tree *cluster_list_tree; /* subtree for CLUSTER_LIST */
|
|
|
|
int i, j; /* tmp */
|
|
|
|
guint8 length; /* AS_PATH length */
|
|
|
|
guint8 type; /* AS_PATH type */
|
|
|
|
char *as_path_str = NULL; /* AS_PATH string */
|
|
|
|
char *communities_str = NULL; /* COMMUNITIES string */
|
|
|
|
char *cluster_list_str = NULL; /* CLUSTER_LIST string */
|
|
|
|
char junk_buf[256]; /* tmp */
|
1999-11-22 07:05:21 +00:00
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
|
|
|
|
/* snarf UPDATE message */
|
1999-10-15 17:00:47 +00:00
|
|
|
memcpy(&bgp, &pd[offset], sizeof(bgp));
|
|
|
|
hlen = ntohs(bgp.bgp_len);
|
1999-11-01 06:57:01 +00:00
|
|
|
p = &pd[offset + BGP_HEADER_SIZE]; /*XXX*/
|
1999-11-11 21:08:52 +00:00
|
|
|
|
|
|
|
/* check for withdrawals */
|
2000-01-15 04:17:37 +00:00
|
|
|
len = pntohs(p);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB, p - pd, 2,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
|
1999-11-22 07:05:21 +00:00
|
|
|
p += 2;
|
|
|
|
|
|
|
|
/* parse unfeasible prefixes */
|
1999-11-11 21:08:52 +00:00
|
|
|
if (len > 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(tree, NullTVB, p - pd, len, "Withdrawn routes:");
|
1999-11-16 11:44:20 +00:00
|
|
|
subtree = proto_item_add_subtree(ti, ett_bgp_unfeas);
|
1999-11-22 07:05:21 +00:00
|
|
|
|
|
|
|
/* parse each prefixes */
|
|
|
|
end = p + len;
|
|
|
|
while (p < end) {
|
|
|
|
i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
|
1999-11-22 07:05:21 +00:00
|
|
|
p += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p += len;
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
1999-11-11 21:08:52 +00:00
|
|
|
|
|
|
|
/* check for advertisements */
|
2000-01-15 04:17:37 +00:00
|
|
|
len = pntohs(p);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB, p - pd, 2, "Total path attribute length: %u %s",
|
1999-11-11 21:08:52 +00:00
|
|
|
len, (len == 1) ? "byte" : "bytes");
|
|
|
|
|
|
|
|
/* path attributes */
|
|
|
|
if (len > 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(tree, NullTVB, p - pd + 2, len, "Path attributes");
|
1999-11-16 11:44:20 +00:00
|
|
|
subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
|
1999-10-15 17:00:47 +00:00
|
|
|
i = 2;
|
|
|
|
while (i < len) {
|
|
|
|
int alen, aoff;
|
|
|
|
char *msg;
|
1999-10-16 15:35:27 +00:00
|
|
|
guint16 af;
|
|
|
|
int off, snpa;
|
1999-10-15 17:00:47 +00:00
|
|
|
|
|
|
|
memcpy(&bgpa, &p[i], sizeof(bgpa));
|
1999-11-22 07:05:21 +00:00
|
|
|
/* check for the Extended Length bit */
|
1999-11-11 21:08:52 +00:00
|
|
|
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
|
2000-01-15 04:17:37 +00:00
|
|
|
alen = pntohs(&p[i + sizeof(bgpa)]);
|
1999-10-15 17:00:47 +00:00
|
|
|
aoff = sizeof(bgpa) + 2;
|
|
|
|
} else {
|
|
|
|
alen = p[i + sizeof(bgpa)];
|
|
|
|
aoff = sizeof(bgpa) + 1;
|
|
|
|
}
|
1999-10-31 00:20:44 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* 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 */
|
1999-10-31 00:20:44 +00:00
|
|
|
switch (bgpa.bgpa_type) {
|
|
|
|
case BGPTYPE_ORIGIN:
|
|
|
|
if (alen != 1)
|
|
|
|
goto default_attribute_top;
|
|
|
|
msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
"%s: %s (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
1999-11-11 21:08:52 +00:00
|
|
|
msg, alen + aoff, (alen + aoff == 1) ? "byte" :
|
|
|
|
"bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_AS_PATH:
|
1999-11-11 21:08:52 +00:00
|
|
|
/* (p + i + 3) =
|
|
|
|
(p + current attribute + 3 bytes to first tuple) */
|
|
|
|
end = p + alen + i + 3;
|
|
|
|
q = p + i + 3;
|
1999-11-22 07:05:21 +00:00
|
|
|
/* must be freed by second switch! */
|
1999-11-11 21:08:52 +00:00
|
|
|
/* "alen * 6" (5 digits + space) should be a good estimate
|
|
|
|
of how long the AS path string could be */
|
1999-12-08 08:12:27 +00:00
|
|
|
as_path_str = malloc((alen + 1) * 6);
|
1999-11-11 21:08:52 +00:00
|
|
|
if (as_path_str == NULL) break;
|
1999-11-22 07:05:21 +00:00
|
|
|
as_path_str[0] = '\0';
|
1999-11-11 21:08:52 +00:00
|
|
|
|
|
|
|
/* snarf each AS path */
|
|
|
|
while (q < end) {
|
|
|
|
type = *q++;
|
|
|
|
if (type == AS_SET) {
|
1999-11-22 07:05:21 +00:00
|
|
|
snprintf(as_path_str, 2, "{");
|
1999-11-11 21:08:52 +00:00
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
else if (type == AS_CONFED_SET) {
|
|
|
|
snprintf(as_path_str, 2, "[");
|
1999-11-22 07:05:21 +00:00
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
else if (type == AS_CONFED_SEQUENCE) {
|
|
|
|
snprintf(as_path_str, 2, "(");
|
|
|
|
}
|
|
|
|
length = *q++;
|
1999-11-22 07:05:21 +00:00
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
/* snarf each value in path */
|
|
|
|
for (j = 0; j < length; j++) {
|
1999-11-22 07:05:21 +00:00
|
|
|
snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
|
2000-04-11 14:21:37 +00:00
|
|
|
(type == AS_SET || type == AS_CONFED_SET)
|
|
|
|
? ", " : " ");
|
1999-11-22 07:05:21 +00:00
|
|
|
strncat(as_path_str, junk_buf, sizeof(junk_buf));
|
1999-11-11 21:08:52 +00:00
|
|
|
q += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup end of string */
|
|
|
|
if (type == AS_SET) {
|
1999-11-22 07:05:21 +00:00
|
|
|
as_path_str[strlen(as_path_str) - 2] = '}';
|
1999-11-11 21:08:52 +00:00
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
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] = ')';
|
|
|
|
}
|
1999-11-11 21:08:52 +00:00
|
|
|
else {
|
|
|
|
as_path_str[strlen(as_path_str) - 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-08 08:12:27 +00:00
|
|
|
/* check for empty AS_PATH */
|
|
|
|
if (alen == 0)
|
|
|
|
strncpy(as_path_str, "empty", 6);
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-12-08 08:12:27 +00:00
|
|
|
"%s: %s (%u %s)",
|
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
|
|
|
as_path_str, alen + aoff,
|
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_NEXT_HOP:
|
|
|
|
if (alen != 4)
|
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
"%s: %s (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
1999-11-11 21:08:52 +00:00
|
|
|
ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
|
|
|
|
? "byte" : "bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_MULTI_EXIT_DISC:
|
|
|
|
if (alen != 4)
|
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
"%s: %u (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
2000-03-29 06:27:54 +00:00
|
|
|
pntohl(&p[i + aoff]), alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_LOCAL_PREF:
|
|
|
|
if (alen != 4)
|
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
"%s: %u (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
2000-01-15 04:17:37 +00:00
|
|
|
pntohl(&p[i + aoff]), alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
1999-11-11 21:08:52 +00:00
|
|
|
case BGPTYPE_ATOMIC_AGGREGATE:
|
|
|
|
if (alen != 0)
|
1999-10-31 00:20:44 +00:00
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-22 07:05:21 +00:00
|
|
|
"%s (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
1999-11-11 21:08:52 +00:00
|
|
|
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
1999-11-22 07:05:21 +00:00
|
|
|
case BGPTYPE_AGGREGATOR:
|
|
|
|
if (alen != 6)
|
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-22 07:05:21 +00:00
|
|
|
"%s: AS: %u origin: %s (%u %s)",
|
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
2000-01-15 04:17:37 +00:00
|
|
|
pntohs(&p[i + aoff]),
|
1999-11-22 07:05:21 +00:00
|
|
|
ip_to_str(&p[i + aoff + 2]), alen + aoff,
|
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
|
|
|
break;
|
|
|
|
case BGPTYPE_COMMUNITIES:
|
2000-01-25 09:24:42 +00:00
|
|
|
if (alen % 4 != 0)
|
1999-11-22 07:05:21 +00:00
|
|
|
goto default_attribute_top;
|
|
|
|
|
2000-03-29 06:27:54 +00:00
|
|
|
/* (p + i + 3) =
|
|
|
|
(p + current attribute + 3 bytes to first tuple) */
|
|
|
|
end = p + alen + i + 3;
|
|
|
|
q = p + 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
|
|
|
|
be */
|
|
|
|
communities_str = malloc((alen + 1) * 12);
|
|
|
|
if (communities_str == NULL) break;
|
|
|
|
communities_str[0] = '\0';
|
|
|
|
memset(junk_buf, 0, sizeof(junk_buf));
|
|
|
|
|
|
|
|
/* snarf each community */
|
|
|
|
while (q < end) {
|
|
|
|
/* check for well-known communities */
|
2000-01-25 09:24:42 +00:00
|
|
|
if (pntohl(q) == BGP_COMM_NO_EXPORT)
|
2000-03-29 06:27:54 +00:00
|
|
|
strncpy(junk_buf, "NO_EXPORT ", 10);
|
2000-01-25 09:24:42 +00:00
|
|
|
else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
|
2000-03-29 06:27:54 +00:00
|
|
|
strncpy(junk_buf, "NO_ADVERTISE ", 13);
|
2000-01-25 09:24:42 +00:00
|
|
|
else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
|
2000-03-29 06:27:54 +00:00
|
|
|
strncpy(junk_buf, "NO_EXPORT_SUBCONFED ", 20);
|
|
|
|
else {
|
|
|
|
snprintf(junk_buf, sizeof(junk_buf), "%u:%u ",
|
|
|
|
pntohs(q),
|
|
|
|
pntohs(q + 2));
|
|
|
|
}
|
|
|
|
q += 4;
|
|
|
|
|
|
|
|
strncat(communities_str, junk_buf, sizeof(junk_buf));
|
|
|
|
}
|
|
|
|
/* cleanup end of string */
|
|
|
|
communities_str[strlen(communities_str) - 1] = '\0';
|
1999-11-22 07:05:21 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-22 07:05:21 +00:00
|
|
|
"%s: %s (%u %s)",
|
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
2000-03-29 06:27:54 +00:00
|
|
|
communities_str, alen + aoff,
|
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
1999-11-22 07:05:21 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_ORIGINATOR_ID:
|
|
|
|
if (alen != 4)
|
|
|
|
goto default_attribute_top;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-22 07:05:21 +00:00
|
|
|
"%s: %s (%u %s)",
|
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
|
|
|
ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
|
2000-03-29 06:27:54 +00:00
|
|
|
? "byte" : "bytes");
|
1999-11-22 07:05:21 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_CLUSTER_LIST:
|
2000-03-29 06:27:54 +00:00
|
|
|
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;
|
|
|
|
/* 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
|
|
|
|
be */
|
|
|
|
cluster_list_str = malloc((alen + 1) * 16);
|
|
|
|
if (cluster_list_str == NULL) break;
|
|
|
|
cluster_list_str[0] = '\0';
|
|
|
|
memset(junk_buf, 0, sizeof(junk_buf));
|
|
|
|
|
|
|
|
/* snarf each cluster list */
|
|
|
|
while (q < end) {
|
|
|
|
snprintf(junk_buf, sizeof(junk_buf), "%s ", ip_to_str(q));
|
|
|
|
strncat(cluster_list_str, junk_buf, sizeof(junk_buf));
|
|
|
|
q += 4;
|
|
|
|
}
|
|
|
|
/* cleanup end of string */
|
|
|
|
cluster_list_str[strlen(cluster_list_str) - 1] = '\0';
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
2000-03-29 06:27:54 +00:00
|
|
|
"%s: %s (%u %s)",
|
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
|
|
|
cluster_list_str, alen + aoff,
|
|
|
|
(alen + aoff == 1) ? "byte" : "bytes");
|
|
|
|
break;
|
1999-10-31 00:20:44 +00:00
|
|
|
default:
|
|
|
|
default_attribute_top:
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
|
1999-11-11 21:08:52 +00:00
|
|
|
"%s (%u %s)",
|
1999-10-31 00:20:44 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
1999-11-11 21:08:52 +00:00
|
|
|
alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
|
2000-03-29 06:27:54 +00:00
|
|
|
} /* end of first switch */
|
1999-11-16 11:44:20 +00:00
|
|
|
subtree2 = proto_item_add_subtree(ti, ett_bgp_attr);
|
1999-10-15 17:00:47 +00:00
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
/* figure out flags */
|
1999-11-22 07:05:21 +00:00
|
|
|
junk_buf[0] = '\0';
|
|
|
|
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_OPTIONAL) {
|
|
|
|
strncat(junk_buf, "Optional, ", 10);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncat(junk_buf, "Well-known, ", 12);
|
|
|
|
}
|
|
|
|
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_TRANSITIVE) {
|
|
|
|
strncat(junk_buf, "Transitive, ", 12);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncat(junk_buf, "Non-transitive, ", 16);
|
|
|
|
}
|
|
|
|
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_PARTIAL) {
|
|
|
|
strncat(junk_buf, "Partial, ", 9);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncat(junk_buf, "Complete, ", 10);
|
|
|
|
}
|
|
|
|
if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
|
|
|
|
strncat(junk_buf, "Extended Length, ", 17);
|
|
|
|
}
|
|
|
|
/* stomp last ", " */
|
|
|
|
j = strlen(junk_buf);
|
|
|
|
junk_buf[j - 2] = '\0';
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Flags: 0x%02x (%s)", bgpa.bgpa_flags, junk_buf);
|
1999-11-16 11:44:20 +00:00
|
|
|
subtree3 = proto_item_add_subtree(ti, ett_bgp_attr_flags);
|
1999-11-22 07:05:21 +00:00
|
|
|
|
|
|
|
/* add flag bitfield subtrees */
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
|
|
|
|
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
|
1999-11-11 21:08:52 +00:00
|
|
|
BGP_ATTR_FLAG_OPTIONAL, 8, "Optional", "Well-known"));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
|
|
|
|
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
|
1999-11-11 21:08:52 +00:00
|
|
|
BGP_ATTR_FLAG_TRANSITIVE, 8, "Transitive",
|
|
|
|
"Non-transitive"));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
|
|
|
|
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
|
1999-11-11 21:08:52 +00:00
|
|
|
BGP_ATTR_FLAG_PARTIAL, 8, "Partial", "Complete"));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
|
|
|
|
"%s", decode_boolean_bitfield(bgpa.bgpa_flags,
|
1999-11-11 21:08:52 +00:00
|
|
|
BGP_ATTR_FLAG_EXTENDED_LENGTH, 8, "Extended length",
|
|
|
|
"Regular length"));
|
1999-10-15 17:00:47 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
p - pd + i + offsetof(struct bgp_attr, bgpa_type), 1,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Type code: %s (%u)",
|
1999-10-15 17:00:47 +00:00
|
|
|
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
|
|
|
|
bgpa.bgpa_type);
|
1999-11-11 21:08:52 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + sizeof(bgpa),
|
1999-11-22 07:05:21 +00:00
|
|
|
aoff - sizeof(bgpa), "Length: %d %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
1999-10-16 00:21:07 +00:00
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* the second switch prints things in the actual subtree of each
|
|
|
|
attribute */
|
1999-10-15 17:00:47 +00:00
|
|
|
switch (bgpa.bgpa_type) {
|
|
|
|
case BGPTYPE_ORIGIN:
|
|
|
|
if (alen != 1) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Origin (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
|
|
|
msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Origin: %s (%u)", msg, p[i + aoff]);
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGPTYPE_AS_PATH:
|
1999-12-08 08:12:27 +00:00
|
|
|
/* check for empty AS_PATH */
|
|
|
|
if (alen == 0) {
|
|
|
|
free(as_path_str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
"AS path: %s", as_path_str);
|
1999-11-23 20:56:49 +00:00
|
|
|
as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
|
1999-11-22 07:05:21 +00:00
|
|
|
|
|
|
|
/* (p + i + 3) =
|
|
|
|
(p + current attribute + 3 bytes to first tuple) */
|
|
|
|
end = p + alen + i + 3;
|
|
|
|
q = p + i + 3;
|
|
|
|
|
2000-04-11 14:21:37 +00:00
|
|
|
/* 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 */
|
1999-11-22 07:05:21 +00:00
|
|
|
while (q < end) {
|
|
|
|
as_path_str[0] = '\0';
|
|
|
|
type = *q++;
|
|
|
|
if (type == AS_SET) {
|
|
|
|
snprintf(as_path_str, 2, "{");
|
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
else if (type == AS_CONFED_SET) {
|
|
|
|
snprintf(as_path_str, 2, "[");
|
1999-11-22 07:05:21 +00:00
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
else if (type == AS_CONFED_SEQUENCE) {
|
|
|
|
snprintf(as_path_str, 2, "(");
|
|
|
|
}
|
|
|
|
length = *q++;
|
1999-11-22 07:05:21 +00:00
|
|
|
|
|
|
|
/* 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),
|
2000-04-11 14:21:37 +00:00
|
|
|
(type == AS_SET || type == AS_CONFED_SET)
|
|
|
|
? ", " : " ");
|
1999-11-22 07:05:21 +00:00
|
|
|
strncat(as_path_str, junk_buf, sizeof(junk_buf));
|
|
|
|
q += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup end of string */
|
|
|
|
if (type == AS_SET) {
|
|
|
|
as_path_str[strlen(as_path_str) - 2] = '}';
|
|
|
|
}
|
2000-04-11 14:21:37 +00:00
|
|
|
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] = ')';
|
|
|
|
}
|
1999-11-22 07:05:21 +00:00
|
|
|
else {
|
|
|
|
as_path_str[strlen(as_path_str) - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* length here means number of ASs, ie length * 2 bytes */
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(as_paths_tree, NullTVB,
|
1999-11-22 07:05:21 +00:00
|
|
|
q - pd - length * 2 - 2,
|
|
|
|
length * 2 + 2, "AS path segment: %s", as_path_str);
|
1999-11-23 20:56:49 +00:00
|
|
|
as_path_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 2,
|
1999-11-22 07:05:21 +00:00
|
|
|
1, "Path segment type: %s (%u)",
|
|
|
|
val_to_str(type, as_segment_type, "Unknown"), type);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 1,
|
1999-11-22 07:05:21 +00:00
|
|
|
1, "Path segment length: %u %s", length,
|
|
|
|
(length == 1) ? "AS" : "ASs");
|
2000-04-11 14:21:37 +00:00
|
|
|
|
|
|
|
/* 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';
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2,
|
1999-11-22 07:05:21 +00:00
|
|
|
length * 2, "Path segment value: %s", as_path_str);
|
|
|
|
}
|
|
|
|
|
1999-11-11 21:08:52 +00:00
|
|
|
free(as_path_str);
|
1999-10-31 00:20:44 +00:00
|
|
|
break;
|
1999-10-15 17:00:47 +00:00
|
|
|
case BGPTYPE_NEXT_HOP:
|
|
|
|
if (alen != 4) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Next hop (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-10-15 17:00:47 +00:00
|
|
|
"Next hop: %s", ip_to_str(&p[i + aoff]));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGPTYPE_MULTI_EXIT_DISC:
|
|
|
|
if (alen != 4) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Multiple exit discriminator (invalid): %u %s",
|
1999-11-11 21:08:52 +00:00
|
|
|
alen, (alen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Multiple exit discriminator: %u",
|
2000-01-15 04:17:37 +00:00
|
|
|
pntohl(&p[i + aoff]));
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGPTYPE_LOCAL_PREF:
|
|
|
|
if (alen != 4) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Local preference (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Local preference: %u", pntohl(&p[i + aoff]));
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGPTYPE_ATOMIC_AGGREGATE:
|
|
|
|
if (alen != 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Atomic aggregate (invalid): %u %s", alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
(alen == 1) ? "byte" : "bytes");
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_AGGREGATOR:
|
|
|
|
if (alen != 6) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Aggregator (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Aggregator AS: %u", pntohs(&p[i + aoff]));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 4,
|
1999-10-15 17:00:47 +00:00
|
|
|
"Aggregator origin: %s",
|
|
|
|
ip_to_str(&p[i + aoff + 2]));
|
|
|
|
}
|
1999-10-16 15:35:27 +00:00
|
|
|
break;
|
1999-11-22 07:05:21 +00:00
|
|
|
case BGPTYPE_COMMUNITIES:
|
2000-01-25 09:24:42 +00:00
|
|
|
if (alen % 4 != 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Communities (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
2000-03-29 06:27:54 +00:00
|
|
|
free(communities_str);
|
|
|
|
break;
|
1999-11-22 07:05:21 +00:00
|
|
|
}
|
2000-01-25 09:24:42 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"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;
|
|
|
|
|
|
|
|
/* snarf each community */
|
|
|
|
while (q < end) {
|
|
|
|
/* check for reserved values */
|
2000-01-25 09:24:42 +00:00
|
|
|
if (pntohs(q) == FOURHEX0 || pntohs(q) == FOURHEXF) {
|
2000-03-29 06:27:54 +00:00
|
|
|
/* check for well-known communities */
|
|
|
|
if (pntohl(q) == BGP_COMM_NO_EXPORT)
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(communities_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4,
|
|
|
|
"Community: NO_EXPORT (0x%x)", pntohl(q));
|
|
|
|
else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(communities_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4,
|
|
|
|
"Community: NO_ADVERTISE (0x%x)", pntohl(q));
|
|
|
|
else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(communities_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4,
|
|
|
|
"Community: NO_EXPORT_SUBCONFED (0x%x)",
|
|
|
|
pntohl(q));
|
|
|
|
else
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(communities_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4,
|
|
|
|
"Community (reserved): 0x%x", pntohl(q));
|
|
|
|
}
|
|
|
|
else {
|
2000-01-25 09:24:42 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(communities_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4, "Community: %u:%u",
|
|
|
|
pntohs(q), pntohs(q + 2));
|
|
|
|
community_tree = proto_item_add_subtree(ti,
|
|
|
|
ett_bgp_communities);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(community_tree, NullTVB, q - pd - 3 + aoff,
|
2000-03-29 06:27:54 +00:00
|
|
|
2, "Community AS: %u", pntohs(q));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(community_tree, NullTVB, q - pd - 1 + aoff,
|
2000-03-29 06:27:54 +00:00
|
|
|
2, "Community value: %u", pntohs(q + 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
q += 4;
|
|
|
|
}
|
2000-01-25 09:24:42 +00:00
|
|
|
|
2000-03-29 06:27:54 +00:00
|
|
|
free(communities_str);
|
1999-11-22 07:05:21 +00:00
|
|
|
break;
|
|
|
|
case BGPTYPE_ORIGINATOR_ID:
|
|
|
|
if (alen != 4) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Originator identifier (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Originator identifier: %s",
|
|
|
|
ip_to_str(&p[i + aoff]));
|
|
|
|
}
|
|
|
|
break;
|
1999-10-16 15:35:27 +00:00
|
|
|
case BGPTYPE_MP_REACH_NLRI:
|
2000-01-15 04:17:37 +00:00
|
|
|
af = pntohs(&p[i + aoff]);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
|
1999-10-16 15:35:27 +00:00
|
|
|
"Address family: %s (%u)",
|
|
|
|
val_to_str(af, afnumber, "Unknown"), af);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
|
1999-10-16 15:35:27 +00:00
|
|
|
"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]);
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3, 1,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Next hop network address (%d %s)",
|
|
|
|
p[i + aoff + 3], (p[i + aoff + 3] == 1) ? "byte" :
|
|
|
|
"bytes");
|
1999-10-16 15:35:27 +00:00
|
|
|
if (af == AFNUM_INET || af == AFNUM_INET6) {
|
|
|
|
int j, advance;
|
|
|
|
const char *s;
|
|
|
|
|
2000-04-11 14:21:37 +00:00
|
|
|
subtree3 = proto_item_add_subtree(ti,
|
|
|
|
ett_bgp_mp_reach_nlri);
|
1999-10-16 15:35:27 +00:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
while (j < p[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])
|
|
|
|
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]);
|
|
|
|
}
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB,
|
1999-10-16 15:35:27 +00:00
|
|
|
p - pd + i + aoff + 4 + j, advance,
|
|
|
|
"Next hop: %s", s);
|
|
|
|
j += advance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
alen -= (p[i + aoff + 3] + 4);
|
|
|
|
aoff += (p[i + aoff + 3] + 4);
|
|
|
|
off = 0;
|
|
|
|
snpa = p[i + aoff];
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
|
1999-10-16 15:35:27 +00:00
|
|
|
"Subnetwork points of attachment: %u", snpa);
|
|
|
|
off++;
|
|
|
|
if (snpa)
|
2000-04-11 14:21:37 +00:00
|
|
|
subtree3 = proto_item_add_subtree(ti,
|
|
|
|
ett_bgp_mp_reach_nlri);
|
1999-10-16 15:35:27 +00:00
|
|
|
for (/*nothing*/; snpa > 0; snpa--) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off, 1,
|
2000-03-06 20:04:53 +00:00
|
|
|
"SNPA length: %u", p[i + aoff + off]);
|
1999-10-16 15:35:27 +00:00
|
|
|
off++;
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off,
|
1999-10-16 15:35:27 +00:00
|
|
|
p[i + aoff + off - 1],
|
1999-11-11 21:08:52 +00:00
|
|
|
"SNPA (%u %s)", p[i + aoff + off - 1],
|
|
|
|
(p[i + aoff + off - 1] == 1) ? "byte" : "bytes");
|
1999-10-16 15:35:27 +00:00
|
|
|
off += p[i + aoff + off - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
alen -= off;
|
|
|
|
aoff += off;
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Network layer reachability information (%u %s)",
|
1999-11-11 21:08:52 +00:00
|
|
|
alen, (alen == 1) ? "byte" : "bytes");
|
1999-10-16 15:35:27 +00:00
|
|
|
if (alen)
|
2000-04-11 14:21:37 +00:00
|
|
|
subtree3 = proto_item_add_subtree(ti,
|
|
|
|
ett_bgp_mp_unreach_nlri);
|
1999-10-16 15:35:27 +00:00
|
|
|
while (alen > 0) {
|
|
|
|
int advance;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (af == AFNUM_INET) {
|
|
|
|
advance = decode_prefix4(&p[i + aoff], buf,
|
|
|
|
sizeof(buf));
|
|
|
|
} else if (af == AFNUM_INET6) {
|
|
|
|
advance = decode_prefix6(&p[i + aoff], buf,
|
|
|
|
sizeof(buf));
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
if (advance < 0)
|
|
|
|
break;
|
|
|
|
if (alen < advance)
|
|
|
|
break;
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
|
1999-11-22 07:05:21 +00:00
|
|
|
"Network layer reachability information: %s", buf);
|
1999-10-16 15:35:27 +00:00
|
|
|
|
|
|
|
alen -= advance;
|
|
|
|
aoff += advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case BGPTYPE_MP_UNREACH_NLRI:
|
2000-03-29 06:27:54 +00:00
|
|
|
af = pntohs(&p[i + aoff]);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
|
1999-10-16 15:35:27 +00:00
|
|
|
"Address family: %s (%u)",
|
|
|
|
val_to_str(af, afnumber, "Unknown"), af);
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
|
1999-10-16 15:35:27 +00:00
|
|
|
"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]);
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3,
|
1999-11-22 07:05:21 +00:00
|
|
|
alen - 3, "Withdrawn routes (%u %s)", alen - 3,
|
1999-11-11 21:08:52 +00:00
|
|
|
(alen - 3 == 1) ? "byte" : "bytes");
|
1999-10-16 15:35:27 +00:00
|
|
|
|
|
|
|
alen -= 3;
|
|
|
|
aoff += 3;
|
|
|
|
if (alen > 0)
|
2000-04-11 14:21:37 +00:00
|
|
|
subtree3 = proto_item_add_subtree(ti,
|
|
|
|
ett_bgp_mp_unreach_nlri);
|
1999-10-16 15:35:27 +00:00
|
|
|
while (alen > 0) {
|
|
|
|
int advance;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (af == AFNUM_INET) {
|
|
|
|
advance = decode_prefix4(&p[i + aoff], buf,
|
|
|
|
sizeof(buf));
|
|
|
|
} else if (af == AFNUM_INET6) {
|
|
|
|
advance = decode_prefix6(&p[i + aoff], buf,
|
|
|
|
sizeof(buf));
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
if (advance < 0)
|
|
|
|
break;
|
|
|
|
if (alen < advance)
|
|
|
|
break;
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
|
1999-10-16 15:35:27 +00:00
|
|
|
"Withdrawn route: %s", buf);
|
|
|
|
|
|
|
|
alen -= advance;
|
|
|
|
aoff += advance;
|
|
|
|
}
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
break;
|
1999-11-22 07:05:21 +00:00
|
|
|
case BGPTYPE_CLUSTER_LIST:
|
2000-03-29 06:27:54 +00:00
|
|
|
if (alen % 4 != 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Cluster list (invalid): %u %s", alen,
|
|
|
|
(alen == 1) ? "byte" : "bytes");
|
|
|
|
free(cluster_list_str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
2000-03-29 06:27:54 +00:00
|
|
|
"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;
|
|
|
|
|
|
|
|
/* snarf each cluster identifier */
|
|
|
|
while (q < end) {
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(cluster_list_tree, NullTVB,
|
2000-03-29 06:27:54 +00:00
|
|
|
q - pd - 3 + aoff, 4, "Cluster identifier: %s",
|
|
|
|
ip_to_str(q));
|
|
|
|
|
|
|
|
q += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cluster_list_str);
|
|
|
|
break;
|
1999-10-16 00:21:07 +00:00
|
|
|
default:
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
|
1999-11-11 21:08:52 +00:00
|
|
|
"Unknown (%d %s)", alen, (alen == 1) ? "byte" :
|
|
|
|
"bytes");
|
1999-10-16 00:21:07 +00:00
|
|
|
break;
|
2000-03-29 06:27:54 +00:00
|
|
|
} /* end of second switch */
|
1999-10-15 17:00:47 +00:00
|
|
|
|
|
|
|
i += alen + aoff;
|
|
|
|
}
|
1999-11-11 21:08:52 +00:00
|
|
|
p += 2 + len;
|
|
|
|
|
|
|
|
/* NLRI */
|
|
|
|
len = hlen - (p - &pd[offset]);
|
|
|
|
|
1999-11-22 07:05:21 +00:00
|
|
|
/* parse prefixes */
|
1999-11-11 21:08:52 +00:00
|
|
|
if (len > 0) {
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(tree, NullTVB, p - pd, len,
|
1999-12-08 08:12:27 +00:00
|
|
|
"Network layer reachability information: %u %s", len,
|
|
|
|
(len == 1) ? "byte" : "bytes");
|
1999-11-16 11:44:20 +00:00
|
|
|
subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
|
1999-11-11 21:08:52 +00:00
|
|
|
end = p + len;
|
|
|
|
while (p < end) {
|
1999-11-22 07:05:21 +00:00
|
|
|
i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
|
1999-11-11 21:08:52 +00:00
|
|
|
p += i;
|
|
|
|
}
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/*
|
|
|
|
* Dissect a BGP NOTIFICATION message.
|
|
|
|
*/
|
1999-10-15 17:00:47 +00:00
|
|
|
static void
|
|
|
|
dissect_bgp_notification(const u_char *pd, int offset, frame_data *fd,
|
|
|
|
proto_tree *tree)
|
|
|
|
{
|
1999-11-06 01:28:50 +00:00
|
|
|
struct bgp_notification bgpn; /* BGP NOTIFICATION message */
|
1999-11-22 07:05:21 +00:00
|
|
|
int hlen; /* message length */
|
|
|
|
char *p; /* string pointer */
|
1999-10-15 17:00:47 +00:00
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/* snarf message */
|
1999-10-15 17:00:47 +00:00
|
|
|
memcpy(&bgpn, &pd[offset], sizeof(bgpn));
|
|
|
|
hlen = ntohs(bgpn.bgpn_len);
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/* print error code */
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_notification, bgpn_major), 1,
|
|
|
|
"Error code: %s (%u)",
|
|
|
|
val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
|
|
|
|
bgpn.bgpn_major);
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/* print error subcode */
|
1999-10-15 17:00:47 +00:00
|
|
|
if (bgpn.bgpn_major < array_length(bgpnotify_minor)
|
|
|
|
&& bgpnotify_minor[bgpn.bgpn_major] != NULL) {
|
|
|
|
p = val_to_str(bgpn.bgpn_minor, bgpnotify_minor[bgpn.bgpn_major],
|
|
|
|
"Unknown");
|
1999-11-02 00:11:58 +00:00
|
|
|
} else if (bgpn.bgpn_minor == 0)
|
|
|
|
p = "Unspecified";
|
|
|
|
else
|
|
|
|
p = "Unknown";
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + offsetof(struct bgp_notification, bgpn_minor), 1,
|
|
|
|
"Error subcode: %s (%u)", p, bgpn.bgpn_minor);
|
1999-11-02 00:11:58 +00:00
|
|
|
|
|
|
|
/* only print if there is optional data */
|
|
|
|
if (hlen > BGP_MIN_NOTIFICATION_MSG_SIZE) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(tree, NullTVB, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
|
1999-11-02 00:11:58 +00:00
|
|
|
hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
|
2000-12-25 05:28:40 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/*
|
|
|
|
* Dissect a BGP packet.
|
|
|
|
*/
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
1999-10-15 17:00:47 +00:00
|
|
|
dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
|
|
|
|
{
|
1999-11-22 07:05:21 +00:00
|
|
|
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 */
|
1999-11-06 01:28:50 +00:00
|
|
|
static u_char marker[] = { /* BGP message marker */
|
1999-10-15 17:00:47 +00:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
};
|
1999-11-22 07:05:21 +00:00
|
|
|
struct bgp bgp; /* BGP header */
|
|
|
|
int hlen; /* BGP header length */
|
|
|
|
char *typ; /* BGP message type */
|
1999-10-15 17:00:47 +00:00
|
|
|
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
OLD_CHECK_DISPLAY_AS_DATA(proto_bgp, pd, offset, fd, tree);
|
|
|
|
|
1999-10-15 17:00:47 +00:00
|
|
|
if (check_col(fd, COL_PROTOCOL))
|
2000-11-19 08:54:37 +00:00
|
|
|
col_set_str(fd, COL_PROTOCOL, "BGP");
|
1999-10-15 17:00:47 +00:00
|
|
|
|
1999-11-01 06:57:01 +00:00
|
|
|
p = &pd[offset];
|
|
|
|
l = END_OF_FRAME;
|
|
|
|
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) {
|
1999-11-01 09:51:59 +00:00
|
|
|
/* look for bgp header */
|
|
|
|
if (p[i] != 0xff) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CHECK_SIZE(i, sizeof(marker), l);
|
|
|
|
if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&bgp, &p[i], sizeof(bgp));
|
|
|
|
found++;
|
1999-11-01 06:57:01 +00:00
|
|
|
hlen = ntohs(bgp.bgp_len);
|
1999-11-01 09:51:59 +00:00
|
|
|
typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
|
1999-11-01 06:57:01 +00:00
|
|
|
|
1999-11-01 09:51:59 +00:00
|
|
|
if (check_col(fd, COL_INFO)) {
|
|
|
|
if (found == 0)
|
|
|
|
col_add_fstr(fd, COL_INFO, "%s", typ);
|
|
|
|
else
|
|
|
|
col_append_fstr(fd, COL_INFO, ", %s", typ);
|
|
|
|
}
|
1999-11-01 06:57:01 +00:00
|
|
|
|
|
|
|
i += hlen;
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
|
|
|
|
if (tree) {
|
2000-08-20 18:10:12 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_bgp, NullTVB, offset,
|
|
|
|
END_OF_FRAME, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp_tree = proto_item_add_subtree(ti, ett_bgp);
|
1999-10-15 17:00:47 +00:00
|
|
|
|
|
|
|
p = &pd[offset];
|
|
|
|
l = END_OF_FRAME;
|
|
|
|
i = 0;
|
1999-11-02 00:11:58 +00:00
|
|
|
/* now, run through the TCP packet again, this time dissect */
|
|
|
|
/* each message that we find */
|
1999-10-15 17:00:47 +00:00
|
|
|
while (i < l) {
|
|
|
|
/* look for bgp header */
|
|
|
|
if (p[i] != 0xff) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CHECK_SIZE(i, sizeof(marker), l);
|
|
|
|
if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&bgp, &p[i], sizeof(bgp));
|
|
|
|
hlen = ntohs(bgp.bgp_len);
|
1999-11-01 06:57:01 +00:00
|
|
|
typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
|
1999-10-15 17:00:47 +00:00
|
|
|
if (END_OF_FRAME < hlen) {
|
2000-12-25 05:28:40 +00:00
|
|
|
ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i,
|
|
|
|
END_OF_FRAME, "%s (truncated)", typ);
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i, hlen,
|
1999-11-01 06:57:01 +00:00
|
|
|
"%s", typ);
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
1999-11-06 01:28:50 +00:00
|
|
|
/* add a different tree for each message type */
|
|
|
|
switch (bgp.bgp_type) {
|
|
|
|
case BGP_OPEN:
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp_open);
|
1999-11-06 01:28:50 +00:00
|
|
|
break;
|
|
|
|
case BGP_UPDATE:
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp_update);
|
1999-11-06 01:28:50 +00:00
|
|
|
break;
|
|
|
|
case BGP_NOTIFICATION:
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp_notification);
|
1999-11-06 01:28:50 +00:00
|
|
|
break;
|
|
|
|
case BGP_KEEPALIVE:
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
|
1999-11-06 01:28:50 +00:00
|
|
|
break;
|
2000-12-25 05:28:40 +00:00
|
|
|
case BGP_ROUTE_REFRESH:
|
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp_route_refresh);
|
|
|
|
break;
|
1999-11-06 01:28:50 +00:00
|
|
|
default:
|
1999-11-16 11:44:20 +00:00
|
|
|
bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
|
1999-11-06 01:28:50 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-10-15 17:00:47 +00:00
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(bgp1_tree, NullTVB, offset + i, BGP_MARKER_SIZE,
|
2000-03-29 06:27:54 +00:00
|
|
|
"Marker: 16 bytes");
|
1999-11-01 09:51:59 +00:00
|
|
|
|
1999-11-01 06:57:01 +00:00
|
|
|
if (hlen < BGP_HEADER_SIZE || hlen > BGP_MAX_PACKET_SIZE) {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(bgp1_tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + i + offsetof(struct bgp, bgp_len), 2,
|
1999-11-02 00:11:58 +00:00
|
|
|
"Length (invalid): %u %s", hlen,
|
1999-11-01 09:51:59 +00:00
|
|
|
(hlen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
} else {
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(bgp1_tree, NullTVB,
|
1999-10-15 17:00:47 +00:00
|
|
|
offset + i + offsetof(struct bgp, bgp_len), 2,
|
1999-11-01 06:57:01 +00:00
|
|
|
"Length: %u %s", hlen,
|
1999-11-01 09:51:59 +00:00
|
|
|
(hlen == 1) ? "byte" : "bytes");
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
1999-11-01 06:57:01 +00:00
|
|
|
|
2000-08-20 18:10:12 +00:00
|
|
|
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);
|
1999-10-15 17:00:47 +00:00
|
|
|
|
|
|
|
CHECK_SIZE(i, hlen, l);
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/* handle each message type */
|
1999-10-15 17:00:47 +00:00
|
|
|
switch (bgp.bgp_type) {
|
|
|
|
case BGP_OPEN:
|
|
|
|
dissect_bgp_open(pd, offset + i, fd, bgp1_tree);
|
|
|
|
break;
|
|
|
|
case BGP_UPDATE:
|
|
|
|
dissect_bgp_update(pd, offset + i, fd, bgp1_tree);
|
|
|
|
break;
|
|
|
|
case BGP_NOTIFICATION:
|
|
|
|
dissect_bgp_notification(pd, offset + i, fd, bgp1_tree);
|
|
|
|
break;
|
1999-11-01 09:51:59 +00:00
|
|
|
case BGP_KEEPALIVE:
|
|
|
|
/* no data in KEEPALIVE messages */
|
|
|
|
break;
|
2000-12-25 05:28:40 +00:00
|
|
|
case BGP_ROUTE_REFRESH:
|
|
|
|
dissect_bgp_route_refresh(pd, offset + i, fd, bgp1_tree);
|
|
|
|
break;
|
1999-11-01 09:51:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i += hlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 00:11:58 +00:00
|
|
|
/*
|
|
|
|
* Register ourselves.
|
|
|
|
*/
|
1999-10-15 17:00:47 +00:00
|
|
|
void
|
|
|
|
proto_register_bgp(void)
|
|
|
|
{
|
2000-08-20 18:10:12 +00:00
|
|
|
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_bgp_type,
|
|
|
|
{ "BGP message type", "bgp.type", FT_UINT8, BASE_HEX,
|
|
|
|
VALS(bgptypevals), 0x0, "BGP message type" }},
|
|
|
|
};
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_bgp,
|
|
|
|
&ett_bgp_unfeas,
|
|
|
|
&ett_bgp_attrs,
|
|
|
|
&ett_bgp_attr,
|
|
|
|
&ett_bgp_attr_flags,
|
|
|
|
&ett_bgp_mp_reach_nlri,
|
|
|
|
&ett_bgp_mp_unreach_nlri,
|
|
|
|
&ett_bgp_nlri,
|
|
|
|
&ett_bgp_open,
|
|
|
|
&ett_bgp_update,
|
|
|
|
&ett_bgp_notification,
|
2000-12-25 05:28:40 +00:00
|
|
|
&ett_bgp_route_refresh,
|
1999-11-23 20:56:49 +00:00
|
|
|
&ett_bgp_as_paths,
|
2000-01-25 09:24:42 +00:00
|
|
|
&ett_bgp_communities,
|
2000-03-29 06:27:54 +00:00
|
|
|
&ett_bgp_cluster_list,
|
2000-12-25 05:28:40 +00:00
|
|
|
&ett_bgp_options,
|
|
|
|
&ett_bgp_option,
|
1999-11-16 11:44:20 +00:00
|
|
|
};
|
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_bgp = proto_register_protocol("Border Gateway Protocol",
|
|
|
|
"BGP", "bgp");
|
2000-08-20 18:10:12 +00:00
|
|
|
proto_register_field_array(proto_bgp, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-10-15 17:00:47 +00:00
|
|
|
}
|
2000-04-08 07:07:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_bgp(void)
|
|
|
|
{
|
2001-01-09 06:32:10 +00:00
|
|
|
old_dissector_add("tcp.port", BGP_TCP_PORT, dissect_bgp, proto_bgp);
|
2000-04-08 07:07:42 +00:00
|
|
|
}
|