1999-10-30 13:11:06 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 WIDE Project.
|
|
|
|
* All rights reserved.
|
2002-06-12 01:08:37 +08:00
|
|
|
*
|
1999-10-30 13:11:06 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2002-06-12 01:08:37 +08:00
|
|
|
*
|
1999-10-30 13:11:06 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2002-08-24 21:55:31 +08:00
|
|
|
*
|
|
|
|
* Extensively modified by Hannes Gredler (hannes@juniper.net) for more
|
|
|
|
* complete BGP support.
|
1999-10-30 13:11:06 +08:00
|
|
|
*/
|
|
|
|
|
1999-11-21 17:36:43 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-01-10 05:34:14 +08:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
2002-08-24 21:55:31 +08:00
|
|
|
"@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.48 2002-08-24 13:55:31 hannes Exp $";
|
2000-01-10 05:34:14 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-01 16:52:55 +08:00
|
|
|
#include <tcpdump-stdinc.h>
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-12-15 15:43:44 +08:00
|
|
|
#include <string.h>
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
#include "interface.h"
|
|
|
|
#include "addrtoname.h"
|
2000-12-04 08:43:39 +08:00
|
|
|
#include "extract.h"
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
struct bgp {
|
|
|
|
u_int8_t bgp_marker[16];
|
|
|
|
u_int16_t bgp_len;
|
|
|
|
u_int8_t bgp_type;
|
|
|
|
};
|
|
|
|
#define BGP_SIZE 19 /* unaligned */
|
|
|
|
|
|
|
|
#define BGP_OPEN 1
|
|
|
|
#define BGP_UPDATE 2
|
|
|
|
#define BGP_NOTIFICATION 3
|
|
|
|
#define BGP_KEEPALIVE 4
|
2002-07-22 10:55:20 +08:00
|
|
|
#define BGP_ROUTE_REFRESH 5
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_msg_values[] = {
|
|
|
|
{ BGP_OPEN, "Open"},
|
|
|
|
{ BGP_UPDATE, "Update"},
|
|
|
|
{ BGP_NOTIFICATION, "Notification"},
|
|
|
|
{ BGP_KEEPALIVE, "Keepalive"},
|
2002-07-22 10:55:20 +08:00
|
|
|
{ BGP_ROUTE_REFRESH, "Route Refresh"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
struct bgp_open {
|
|
|
|
u_int8_t bgpo_marker[16];
|
|
|
|
u_int16_t bgpo_len;
|
|
|
|
u_int8_t bgpo_type;
|
|
|
|
u_int8_t bgpo_version;
|
|
|
|
u_int16_t bgpo_myas;
|
|
|
|
u_int16_t bgpo_holdtime;
|
|
|
|
u_int32_t bgpo_id;
|
|
|
|
u_int8_t bgpo_optlen;
|
|
|
|
/* options should follow */
|
|
|
|
};
|
2001-10-16 16:00:36 +08:00
|
|
|
#define BGP_OPEN_SIZE 29 /* unaligned */
|
1999-10-30 13:11:06 +08:00
|
|
|
|
1999-12-22 14:27:19 +08:00
|
|
|
struct bgp_opt {
|
|
|
|
u_int8_t bgpopt_type;
|
|
|
|
u_int8_t bgpopt_len;
|
|
|
|
/* variable length */
|
|
|
|
};
|
2001-10-16 16:00:36 +08:00
|
|
|
#define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
|
1999-12-22 14:27:19 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
struct bgp_notification {
|
|
|
|
u_int8_t bgpn_marker[16];
|
|
|
|
u_int16_t bgpn_len;
|
|
|
|
u_int8_t bgpn_type;
|
|
|
|
u_int8_t bgpn_major;
|
|
|
|
u_int8_t bgpn_minor;
|
|
|
|
/* data should follow */
|
|
|
|
};
|
2001-10-16 16:00:36 +08:00
|
|
|
#define BGP_NOTIFICATION_SIZE 21 /* unaligned */
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-24 08:10:46 +08:00
|
|
|
struct bgp_route_refresh {
|
|
|
|
u_int8_t bgp_marker[16];
|
|
|
|
u_int16_t len;
|
|
|
|
u_int8_t type;
|
2002-07-25 05:07:20 +08:00
|
|
|
u_int8_t afi[2]; /* the compiler messes this structure up */
|
|
|
|
u_int8_t res; /* when doing misaligned sequences of int8 and int16 */
|
|
|
|
u_int8_t safi; /* afi should be int16 - so we have to access it using */
|
|
|
|
}; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
|
2002-07-24 08:10:46 +08:00
|
|
|
#define BGP_ROUTE_REFRESH_SIZE 23
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
struct bgp_attr {
|
|
|
|
u_int8_t bgpa_flags;
|
|
|
|
u_int8_t bgpa_type;
|
|
|
|
union {
|
|
|
|
u_int8_t len;
|
|
|
|
u_int16_t elen;
|
|
|
|
} bgpa_len;
|
|
|
|
#define bgp_attr_len(p) \
|
|
|
|
(((p)->bgpa_flags & 0x10) ? \
|
|
|
|
ntohs((p)->bgpa_len.elen) : (p)->bgpa_len.len)
|
|
|
|
#define bgp_attr_off(p) \
|
|
|
|
(((p)->bgpa_flags & 0x10) ? 4 : 3)
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BGPTYPE_ORIGIN 1
|
|
|
|
#define BGPTYPE_AS_PATH 2
|
|
|
|
#define BGPTYPE_NEXT_HOP 3
|
|
|
|
#define BGPTYPE_MULTI_EXIT_DISC 4
|
|
|
|
#define BGPTYPE_LOCAL_PREF 5
|
|
|
|
#define BGPTYPE_ATOMIC_AGGREGATE 6
|
|
|
|
#define BGPTYPE_AGGREGATOR 7
|
1999-12-22 14:27:19 +08:00
|
|
|
#define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
|
|
|
|
#define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
|
|
|
|
#define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
|
2002-07-04 17:24:43 +08:00
|
|
|
#define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
|
1999-12-22 14:27:19 +08:00
|
|
|
#define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
|
|
|
|
#define BGPTYPE_RCID_PATH 13 /* RFC1863 */
|
1999-10-30 13:11:06 +08:00
|
|
|
#define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
|
|
|
|
#define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
|
2002-07-04 17:24:43 +08:00
|
|
|
#define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
|
|
|
|
|
|
|
|
static struct tok bgp_attr_values[] = {
|
|
|
|
{ BGPTYPE_ORIGIN, "Origin"},
|
|
|
|
{ BGPTYPE_AS_PATH, "AS Path"},
|
|
|
|
{ BGPTYPE_NEXT_HOP, "Next Hop"},
|
|
|
|
{ BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
|
|
|
|
{ BGPTYPE_LOCAL_PREF, "Local Preference"},
|
|
|
|
{ BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
|
|
|
|
{ BGPTYPE_AGGREGATOR, "Aggregator"},
|
|
|
|
{ BGPTYPE_COMMUNITIES, "Community"},
|
|
|
|
{ BGPTYPE_ORIGINATOR_ID, "Originator ID"},
|
|
|
|
{ BGPTYPE_CLUSTER_LIST, "Cluster List"},
|
|
|
|
{ BGPTYPE_DPA, "DPA"},
|
|
|
|
{ BGPTYPE_ADVERTISERS, "Advertisers"},
|
|
|
|
{ BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
|
|
|
|
{ BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
|
|
|
|
{ BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
|
|
|
|
{ BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
|
|
|
|
{ 255, "Reserved for development"},
|
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-14 22:14:50 +08:00
|
|
|
#define BGP_OPT_AUTH 1
|
|
|
|
#define BGP_OPT_CAP 2
|
|
|
|
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_opt_values[] = {
|
2002-07-14 22:14:50 +08:00
|
|
|
{ BGP_OPT_AUTH, "Authentication Information"},
|
|
|
|
{ BGP_OPT_CAP, "Capabilities Advertisement"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BGP_CAPCODE_MP 1
|
|
|
|
#define BGP_CAPCODE_RR 2
|
|
|
|
#define BGP_CAPCODE_RR_CISCO 128
|
|
|
|
|
|
|
|
static struct tok bgp_capcode_values[] = {
|
|
|
|
{ BGP_CAPCODE_MP, "Multiprotocol Extensions"},
|
|
|
|
{ BGP_CAPCODE_RR, "Route Refresh"},
|
|
|
|
{ BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
#define BGP_NOTIFY_MAJOR_MSG 1
|
|
|
|
#define BGP_NOTIFY_MAJOR_OPEN 2
|
|
|
|
#define BGP_NOTIFY_MAJOR_UPDATE 3
|
|
|
|
#define BGP_NOTIFY_MAJOR_HOLDTIME 4
|
|
|
|
#define BGP_NOTIFY_MAJOR_FSM 5
|
|
|
|
#define BGP_NOTIFY_MAJOR_CEASE 6
|
|
|
|
|
|
|
|
static struct tok bgp_notify_major_values[] = {
|
|
|
|
{ BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
|
|
|
|
{ BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
|
|
|
|
{ BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
|
|
|
|
{ BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
|
|
|
|
{ BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
|
|
|
|
{ BGP_NOTIFY_MAJOR_CEASE, "Cease"},
|
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_notify_minor_msg_values[] = {
|
|
|
|
{ 1, "Connection Not Synchronized"},
|
|
|
|
{ 2, "Bad Message Length"},
|
|
|
|
{ 3, "Bad Message Type"},
|
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_notify_minor_open_values[] = {
|
|
|
|
{ 1, "Unsupported Version Number"},
|
|
|
|
{ 2, "Bad Peer AS"},
|
|
|
|
{ 3, "Bad BGP Identifier"},
|
|
|
|
{ 4, "Unsupported Optional Parameter"},
|
|
|
|
{ 5, "Authentication Failure"},
|
|
|
|
{ 6, "Unacceptable Hold Time"},
|
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_notify_minor_update_values[] = {
|
|
|
|
{ 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}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_origin_values[] = {
|
2002-07-14 22:14:50 +08:00
|
|
|
{ 0, "IGP"},
|
|
|
|
{ 1, "EGP"},
|
|
|
|
{ 2, "Incomplete"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Subsequent address family identifier, RFC2283 section 7 */
|
2002-07-04 17:24:43 +08:00
|
|
|
#define SAFNUM_RES 0
|
|
|
|
#define SAFNUM_UNICAST 1
|
|
|
|
#define SAFNUM_MULTICAST 2
|
|
|
|
#define SAFNUM_UNIMULTICAST 3
|
2002-05-16 18:20:47 +08:00
|
|
|
/* labeled BGP RFC3107 */
|
2002-07-04 17:24:43 +08:00
|
|
|
#define SAFNUM_LABUNICAST 4
|
2002-07-02 18:05:09 +08:00
|
|
|
/* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
|
2002-07-04 17:24:43 +08:00
|
|
|
#define SAFNUM_VPNUNICAST 128
|
|
|
|
#define SAFNUM_VPNMULTICAST 129
|
|
|
|
#define SAFNUM_VPNUNIMULTICAST 130
|
2002-07-04 03:47:53 +08:00
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
#define BGP_VPN_RD_LEN 8
|
|
|
|
|
2002-07-04 03:47:53 +08:00
|
|
|
static struct tok bgp_safi_values[] = {
|
2002-07-04 17:24:43 +08:00
|
|
|
{ SAFNUM_RES, "Reserved"},
|
|
|
|
{ SAFNUM_UNICAST, "Unicast"},
|
|
|
|
{ SAFNUM_MULTICAST, "Multicast"},
|
|
|
|
{ SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
|
|
|
|
{ SAFNUM_LABUNICAST, "labeled Unicast"},
|
|
|
|
{ SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
|
|
|
|
{ SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
|
|
|
|
{ SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
|
2002-07-04 03:47:53 +08:00
|
|
|
{ 0, NULL }
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
1999-12-22 14:27:19 +08:00
|
|
|
/* well-known community */
|
|
|
|
#define BGP_COMMUNITY_NO_EXPORT 0xffffff01
|
|
|
|
#define BGP_COMMUNITY_NO_ADVERT 0xffffff02
|
|
|
|
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
/* RFC1700 address family numbers */
|
|
|
|
#define AFNUM_INET 1
|
|
|
|
#define AFNUM_INET6 2
|
|
|
|
#define AFNUM_NSAP 3
|
|
|
|
#define AFNUM_HDLC 4
|
|
|
|
#define AFNUM_BBN1822 5
|
|
|
|
#define AFNUM_802 6
|
|
|
|
#define AFNUM_E163 7
|
|
|
|
#define AFNUM_E164 8
|
|
|
|
#define AFNUM_F69 9
|
|
|
|
#define AFNUM_X121 10
|
|
|
|
#define AFNUM_IPX 11
|
|
|
|
#define AFNUM_ATALK 12
|
|
|
|
#define AFNUM_DECNET 13
|
|
|
|
#define AFNUM_BANYAN 14
|
|
|
|
#define AFNUM_E164NSAP 15
|
2002-07-04 03:47:53 +08:00
|
|
|
/* draft-kompella-ppvpn-l2vpn */
|
|
|
|
#define AFNUM_L2VPN 196 /* still to be approved by IANA */
|
|
|
|
|
|
|
|
static struct tok bgp_afi_values[] = {
|
|
|
|
{ 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, "Novell IPX"},
|
|
|
|
{ AFNUM_ATALK, "Appletalk"},
|
|
|
|
{ AFNUM_DECNET, "Decnet IV"},
|
|
|
|
{ AFNUM_BANYAN, "Banyan Vines"},
|
|
|
|
{ AFNUM_E164NSAP, "E.164 with NSAP subaddress"},
|
|
|
|
{ AFNUM_L2VPN, "Layer-2 VPN"},
|
|
|
|
{ 0, NULL},
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2002-08-24 21:55:31 +08:00
|
|
|
/* Extended community type - draft-ramachandra-bgp-ext-communities */
|
|
|
|
#define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
|
|
|
|
#define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
|
|
|
|
#define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
|
|
|
|
#define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
|
|
|
|
#define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
|
|
|
|
/* rfc2547 bgp-mpls-vpns */
|
|
|
|
#define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin */
|
|
|
|
/* draft-rosen-vpns-ospf-bgp-mpls */
|
|
|
|
#define BGP_EXT_COM_OSPF_RTYPE 0x8000 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
|
|
|
|
#define BGP_EXT_COM_OSPF_RID 0x8001 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
|
|
|
|
#define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
|
|
|
|
|
2002-07-22 10:55:20 +08:00
|
|
|
static struct tok bgp_extd_comm_subtype_values[] = {
|
2002-08-24 21:55:31 +08:00
|
|
|
{ BGP_EXT_COM_RT_0, "target"},
|
|
|
|
{ BGP_EXT_COM_RT_1, "target"},
|
|
|
|
{ BGP_EXT_COM_RO_0, "origin"},
|
|
|
|
{ BGP_EXT_COM_RO_1, "origin"},
|
|
|
|
{ BGP_EXT_COM_LINKBAND, "link-BW"},
|
|
|
|
{ BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
|
|
|
|
{ BGP_EXT_COM_L2INFO, "layer2-info"},
|
2002-07-25 05:07:20 +08:00
|
|
|
{ 0, NULL},
|
|
|
|
};
|
|
|
|
|
2002-08-24 21:55:31 +08:00
|
|
|
/* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
|
|
|
|
#define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
|
|
|
|
#define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
|
|
|
|
#define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
|
|
|
|
#define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
|
|
|
|
#define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
|
|
|
|
#define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
|
|
|
|
#define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
|
|
|
|
|
|
|
|
static struct tok bgp_extd_comm_ospf_rtype_values[] = {
|
|
|
|
{ BGP_OSPF_RTYPE_RTR, "Router" },
|
|
|
|
{ BGP_OSPF_RTYPE_NET, "Network" },
|
|
|
|
{ BGP_OSPF_RTYPE_SUM, "Summary" },
|
|
|
|
{ BGP_OSPF_RTYPE_EXT, "External" },
|
|
|
|
{ BGP_OSPF_RTYPE_NSSA,"NSSA External" },
|
|
|
|
{ BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
2002-07-25 05:07:20 +08:00
|
|
|
static struct tok bgp_l2vpn_encaps_values[] = {
|
|
|
|
{ 0, "Reserved"},
|
|
|
|
{ 1, "Frame Relay"},
|
|
|
|
{ 2, "ATM AAL5 VCC transport"},
|
|
|
|
{ 3, "ATM transparent cell transport"},
|
|
|
|
{ 4, "Ethernet VLAN"},
|
|
|
|
{ 5, "Ethernet"},
|
|
|
|
{ 6, "Cisco-HDLC"},
|
|
|
|
{ 7, "PPP"},
|
|
|
|
{ 8, "CEM"},
|
|
|
|
{ 9, "ATM VCC cell transport"},
|
|
|
|
{ 10, "ATM VPC cell transport"},
|
|
|
|
{ 11, "MPLS"},
|
|
|
|
{ 12, "VPLS"},
|
|
|
|
{ 64, "IP-interworking"},
|
2002-07-22 10:55:20 +08:00
|
|
|
{ 0, NULL},
|
|
|
|
};
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
static int
|
2002-07-23 07:00:22 +08:00
|
|
|
decode_prefix4(const u_char *pptr, char *buf, u_int buflen)
|
1999-10-30 13:11:06 +08:00
|
|
|
{
|
|
|
|
struct in_addr addr;
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int plen;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
plen = pptr[0];
|
1999-10-30 13:11:06 +08:00
|
|
|
if (plen < 0 || 32 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2002-07-23 07:00:22 +08:00
|
|
|
memcpy(&addr, &pptr[1], (plen + 7) / 8);
|
1999-10-30 13:11:06 +08:00
|
|
|
if (plen % 8) {
|
|
|
|
((u_char *)&addr)[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
2000-09-24 15:48:19 +08:00
|
|
|
snprintf(buf, buflen, "%s/%d", getname((u_char *)&addr), plen);
|
1999-10-30 13:11:06 +08:00
|
|
|
return 1 + (plen + 7) / 8;
|
|
|
|
}
|
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
static int
|
2002-07-23 07:00:22 +08:00
|
|
|
decode_labeled_prefix4(const u_char *pptr, char *buf, u_int buflen)
|
2002-05-16 18:20:47 +08:00
|
|
|
{
|
|
|
|
struct in_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
plen = pptr[0]; /* get prefix length */
|
2002-05-16 18:20:47 +08:00
|
|
|
|
|
|
|
/* this is one of the weirdnesses of rfc3107
|
|
|
|
the label length (actually the label + COS bits)
|
2002-07-23 07:00:22 +08:00
|
|
|
is added to the prefix length;
|
2002-05-25 01:49:29 +08:00
|
|
|
we also do only read out just one label -
|
2002-07-23 07:00:22 +08:00
|
|
|
there is no real application for advertisement of
|
2002-07-02 18:05:09 +08:00
|
|
|
stacked labels in a a single BGP message
|
2002-05-16 18:20:47 +08:00
|
|
|
*/
|
2002-05-25 01:49:29 +08:00
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
plen-=24; /* adjust prefixlen - labellength */
|
|
|
|
|
2002-05-25 01:49:29 +08:00
|
|
|
if (plen < 0 || 32 < plen)
|
|
|
|
return -1;
|
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
2002-07-23 07:00:22 +08:00
|
|
|
memcpy(&addr, &pptr[4], (plen + 7) / 8);
|
2002-05-16 18:20:47 +08:00
|
|
|
if (plen % 8) {
|
|
|
|
((u_char *)&addr)[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
|
|
|
/* the label may get offsetted by 4 bits so lets shift it right */
|
2002-07-23 07:00:22 +08:00
|
|
|
snprintf(buf, buflen, "%s/%d, label:%u %s",
|
2002-05-16 18:20:47 +08:00
|
|
|
getname((u_char *)&addr),
|
|
|
|
plen,
|
2002-07-23 07:00:22 +08:00
|
|
|
EXTRACT_24BITS(pptr+1)>>4,
|
|
|
|
((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
|
2002-05-25 01:49:29 +08:00
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
return 4 + (plen + 7) / 8;
|
|
|
|
}
|
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
|
2002-08-02 12:04:37 +08:00
|
|
|
static char *
|
2002-07-23 07:00:22 +08:00
|
|
|
bgp_vpn_rd_print (const u_char *pptr) {
|
|
|
|
|
|
|
|
/* allocate space for the following string
|
|
|
|
* xxx.xxx.xxx.xxx:xxxxx
|
|
|
|
* 21 bytes plus one termination byte */
|
|
|
|
static char rd[22];
|
|
|
|
char *pos = rd;
|
|
|
|
|
|
|
|
/* ok lets load the RD format */
|
|
|
|
switch (EXTRACT_16BITS(pptr)) {
|
|
|
|
/* AS:IP-address fmt*/
|
|
|
|
case 0:
|
2002-07-23 07:16:12 +08:00
|
|
|
pos+=sprintf(pos, "%u:%u.%u.%u.%u",
|
2002-07-23 07:00:22 +08:00
|
|
|
EXTRACT_16BITS(pptr+2),
|
2002-07-23 07:16:12 +08:00
|
|
|
*(pptr+4),
|
|
|
|
*(pptr+5),
|
|
|
|
*(pptr+6),
|
|
|
|
*(pptr+7));
|
2002-07-23 07:00:22 +08:00
|
|
|
break;
|
|
|
|
/* IP-address:AS fmt*/
|
|
|
|
case 1:
|
2002-07-23 07:16:12 +08:00
|
|
|
pos+=sprintf(pos, "%u.%u.%u.%u:%u",
|
|
|
|
*(pptr+2),
|
|
|
|
*(pptr+3),
|
|
|
|
*(pptr+4),
|
|
|
|
*(pptr+5),
|
2002-07-23 07:00:22 +08:00
|
|
|
EXTRACT_16BITS(pptr+6));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pos+=sprintf(pos, "unknown RD format");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*(pos) = '\0';
|
|
|
|
return (rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
struct in_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
|
|
|
plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
|
|
|
|
|
|
|
|
if (plen < 0 || 32 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
memcpy(&addr, &pptr[12], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
((u_char *)&addr)[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
|
|
|
/* the label may get offsetted by 4 bits so lets shift it right */
|
|
|
|
snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
|
|
|
|
bgp_vpn_rd_print(pptr+4),
|
|
|
|
getname((u_char *)&addr),
|
|
|
|
plen,
|
|
|
|
EXTRACT_24BITS(pptr+1)>>4,
|
|
|
|
((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
|
|
|
|
|
|
|
|
return 12 + (plen + 7) / 8;
|
|
|
|
}
|
|
|
|
|
2002-07-25 05:07:20 +08:00
|
|
|
static int
|
|
|
|
decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
int plen,tlen,strlen,tlv_type,tlv_len,ttlv_len;
|
|
|
|
plen=EXTRACT_16BITS(pptr);
|
|
|
|
tlen=plen;
|
|
|
|
pptr+=2;
|
|
|
|
strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
|
|
|
|
bgp_vpn_rd_print(pptr),
|
|
|
|
EXTRACT_16BITS(pptr+8),
|
|
|
|
EXTRACT_16BITS(pptr+10),
|
|
|
|
EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
|
|
|
|
pptr+=15;
|
|
|
|
tlen-=15;
|
|
|
|
|
|
|
|
/* ok now the variable part - lets read out TLVs*/
|
|
|
|
while (tlen>0) {
|
|
|
|
tlv_type=*pptr++;
|
|
|
|
tlv_len=EXTRACT_16BITS(pptr);
|
|
|
|
ttlv_len=tlv_len;
|
|
|
|
pptr+=2;
|
|
|
|
|
|
|
|
switch(tlv_type) {
|
|
|
|
case 1:
|
|
|
|
strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
|
|
|
|
tlv_type,
|
|
|
|
tlv_len);
|
|
|
|
ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
|
|
|
|
while (ttlv_len>0) {
|
|
|
|
strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++);
|
|
|
|
ttlv_len--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u",
|
|
|
|
tlv_type,
|
|
|
|
tlv_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */
|
|
|
|
}
|
|
|
|
return plen+2;
|
|
|
|
}
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
|
|
|
static int
|
2001-09-18 05:57:50 +08:00
|
|
|
decode_prefix6(const u_char *pd, char *buf, u_int buflen)
|
1999-10-30 13:11:06 +08:00
|
|
|
{
|
|
|
|
struct in6_addr addr;
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int plen;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
plen = pd[0];
|
|
|
|
if (plen < 0 || 128 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
memcpy(&addr, &pd[1], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
addr.s6_addr[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
2001-09-18 05:57:50 +08:00
|
|
|
snprintf(buf, buflen, "%s/%d", getname6((u_char *)&addr), plen);
|
1999-10-30 13:11:06 +08:00
|
|
|
return 1 + (plen + 7) / 8;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
2002-07-22 22:09:07 +08:00
|
|
|
bgp_attr_print(const struct bgp_attr *attr, const u_char *pptr, int len)
|
1999-10-30 13:11:06 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_int16_t af;
|
|
|
|
u_int8_t safi, snpa;
|
|
|
|
int advance;
|
|
|
|
int tlen;
|
2002-07-22 22:09:07 +08:00
|
|
|
const u_char *tptr;
|
2000-11-11 01:52:02 +08:00
|
|
|
char buf[MAXHOSTNAMELEN + 100];
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr;
|
2002-07-14 22:14:50 +08:00
|
|
|
tlen=len;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
switch (attr->bgpa_type) {
|
|
|
|
case BGPTYPE_ORIGIN:
|
|
|
|
if (len != 1)
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
else
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", tok2str(bgp_origin_values, "Unknown Origin Typecode", tptr[0]));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_AS_PATH:
|
|
|
|
if (len % 2) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-14 22:14:50 +08:00
|
|
|
if (!len) {
|
|
|
|
printf("empty");
|
|
|
|
break;
|
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
while (tptr < pptr + len) {
|
1999-12-22 14:27:19 +08:00
|
|
|
/*
|
|
|
|
* under RFC1965, p[0] means:
|
|
|
|
* 1: AS_SET 2: AS_SEQUENCE
|
|
|
|
* 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
|
|
|
|
*/
|
2002-07-22 22:09:07 +08:00
|
|
|
if (tptr[0] == 3 || tptr[0] == 4)
|
1999-12-22 14:27:19 +08:00
|
|
|
printf("confed");
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", (tptr[0] & 1) ? "{" : "");
|
|
|
|
for (i = 0; i < tptr[1] * 2; i += 2) {
|
1999-12-22 14:27:19 +08:00
|
|
|
printf("%s%u", i == 0 ? "" : " ",
|
2002-07-22 22:09:07 +08:00
|
|
|
EXTRACT_16BITS(&tptr[2 + i]));
|
1999-12-22 14:27:19 +08:00
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", (tptr[0] & 1) ? "}" : "");
|
|
|
|
tptr += 2 + tptr[1] * 2;
|
1999-12-22 14:27:19 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_NEXT_HOP:
|
|
|
|
if (len != 4)
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
else
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", getname(tptr));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_MULTI_EXIT_DISC:
|
|
|
|
case BGPTYPE_LOCAL_PREF:
|
|
|
|
if (len != 4)
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
else
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%u", EXTRACT_32BITS(tptr));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_ATOMIC_AGGREGATE:
|
|
|
|
if (len != 0)
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_AGGREGATOR:
|
|
|
|
if (len != 6) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr),
|
|
|
|
getname(tptr + 2));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
1999-12-22 14:27:19 +08:00
|
|
|
case BGPTYPE_COMMUNITIES:
|
|
|
|
if (len % 4) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("invalid len");
|
1999-12-22 14:27:19 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-14 22:14:50 +08:00
|
|
|
while (tlen>0) {
|
1999-12-22 14:27:19 +08:00
|
|
|
u_int32_t comm;
|
2002-07-22 22:09:07 +08:00
|
|
|
comm = EXTRACT_32BITS(tptr);
|
1999-12-22 14:27:19 +08:00
|
|
|
switch (comm) {
|
|
|
|
case BGP_COMMUNITY_NO_EXPORT:
|
|
|
|
printf(" NO_EXPORT");
|
|
|
|
break;
|
|
|
|
case BGP_COMMUNITY_NO_ADVERT:
|
|
|
|
printf(" NO_ADVERTISE");
|
|
|
|
break;
|
|
|
|
case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
|
|
|
|
printf(" NO_EXPORT_SUBCONFED");
|
|
|
|
break;
|
|
|
|
default:
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("%u:%u%s",
|
|
|
|
(comm >> 16) & 0xffff,
|
|
|
|
comm & 0xffff,
|
|
|
|
(tlen>4) ? ", " : "");
|
1999-12-22 14:27:19 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-14 22:14:50 +08:00
|
|
|
tlen -=4;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr +=4;
|
1999-12-22 14:27:19 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-07-14 22:14:50 +08:00
|
|
|
case BGPTYPE_ORIGINATOR_ID:
|
|
|
|
if (len != 4) {
|
|
|
|
printf("invalid len");
|
|
|
|
break;
|
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s",getname(tptr));
|
2002-07-14 22:14:50 +08:00
|
|
|
break;
|
|
|
|
case BGPTYPE_CLUSTER_LIST:
|
|
|
|
while (tlen>0) {
|
|
|
|
printf("%s%s",
|
2002-07-22 22:09:07 +08:00
|
|
|
getname(tptr),
|
2002-07-14 22:14:50 +08:00
|
|
|
(tlen>4) ? ", " : "");
|
|
|
|
tlen -=4;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr +=4;
|
2002-07-14 22:14:50 +08:00
|
|
|
}
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
case BGPTYPE_MP_REACH_NLRI:
|
2002-07-22 22:09:07 +08:00
|
|
|
af = EXTRACT_16BITS(tptr);
|
|
|
|
safi = tptr[2];
|
2002-07-14 17:36:00 +08:00
|
|
|
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
|
2002-07-14 17:36:00 +08:00
|
|
|
tok2str(bgp_afi_values, "Unknown AFI", af),
|
2002-07-14 22:14:50 +08:00
|
|
|
af,
|
2002-07-14 17:36:00 +08:00
|
|
|
(safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
|
2002-07-14 22:14:50 +08:00
|
|
|
tok2str(bgp_safi_values, "Unknown SAFI", safi),
|
|
|
|
safi);
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-25 05:07:20 +08:00
|
|
|
if (af == AFNUM_INET || af==AFNUM_L2VPN)
|
1999-10-30 13:11:06 +08:00
|
|
|
;
|
|
|
|
#ifdef INET6
|
|
|
|
else if (af == AFNUM_INET6)
|
|
|
|
;
|
|
|
|
#endif
|
2002-07-18 08:39:12 +08:00
|
|
|
else {
|
|
|
|
printf("\n\t no AFI %u decoder",af);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
2002-07-18 08:39:12 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr +=3;
|
|
|
|
|
|
|
|
tlen = tptr[0];
|
|
|
|
tptr++;
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (tlen) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t nexthop: ");
|
2002-07-22 22:09:07 +08:00
|
|
|
while (tlen > 0) {
|
2000-04-28 19:34:12 +08:00
|
|
|
switch (af) {
|
|
|
|
case AFNUM_INET:
|
2002-07-14 22:14:50 +08:00
|
|
|
switch(safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
|
|
|
case SAFNUM_LABUNICAST:
|
2002-07-23 07:00:22 +08:00
|
|
|
printf("%s",getname(tptr));
|
2002-07-22 22:09:07 +08:00
|
|
|
tlen -= sizeof(struct in_addr);
|
|
|
|
tptr += sizeof(struct in_addr);
|
2000-04-28 19:34:12 +08:00
|
|
|
break;
|
2002-07-23 07:00:22 +08:00
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
printf("RD: %s, %s",
|
|
|
|
bgp_vpn_rd_print(tptr),
|
|
|
|
getname(tptr+BGP_VPN_RD_LEN));
|
|
|
|
tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
|
|
|
|
tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
|
|
|
|
break;
|
2002-07-14 22:14:50 +08:00
|
|
|
default:
|
|
|
|
printf("no SAFI %u decoder",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
2002-07-14 22:14:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2000-04-28 19:34:12 +08:00
|
|
|
case AFNUM_INET6:
|
2002-07-14 22:14:50 +08:00
|
|
|
switch(safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
|
|
|
case SAFNUM_LABUNICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", getname6(tptr));
|
|
|
|
tlen -= sizeof(struct in6_addr);
|
|
|
|
tptr += sizeof(struct in6_addr);
|
2002-07-25 05:07:20 +08:00
|
|
|
break;
|
2002-07-23 07:00:22 +08:00
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
printf("RD: %s, %s",
|
|
|
|
bgp_vpn_rd_print(tptr),
|
|
|
|
getname6(tptr+BGP_VPN_RD_LEN));
|
|
|
|
tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
|
|
|
|
tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
|
2002-07-25 05:07:20 +08:00
|
|
|
break;
|
2002-07-14 22:14:50 +08:00
|
|
|
default:
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("no SAFI %u decoder",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
2002-07-14 22:14:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-07-25 05:07:20 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2002-07-25 05:07:20 +08:00
|
|
|
case AFNUM_L2VPN:
|
|
|
|
switch(safi) {
|
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
printf("%s", getname(tptr));
|
|
|
|
tlen -= (sizeof(struct in_addr));
|
|
|
|
tptr += (sizeof(struct in_addr));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("no SAFI %u decoder",safi);
|
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-04-28 19:34:12 +08:00
|
|
|
default:
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("no AFI %u decoder",af);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
2002-07-14 22:14:50 +08:00
|
|
|
break;
|
2000-04-28 19:34:12 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr += tlen;
|
|
|
|
|
|
|
|
snpa = tptr[0];
|
|
|
|
tptr++;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
if (snpa) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %u SNPA", snpa);
|
1999-10-30 13:11:06 +08:00
|
|
|
for (/*nothing*/; snpa > 0; snpa--) {
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("\n\t %d bytes", tptr[0]);
|
|
|
|
tptr += tptr[0] + 1;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2002-05-16 18:20:47 +08:00
|
|
|
} else {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf(", no SNPA");
|
2002-05-16 18:20:47 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
while (len - (tptr - pptr) > 0) {
|
2000-04-28 19:34:12 +08:00
|
|
|
switch (af) {
|
|
|
|
case AFNUM_INET:
|
2002-07-14 17:36:00 +08:00
|
|
|
switch (safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_prefix4(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
case SAFNUM_LABUNICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
2002-07-23 07:00:22 +08:00
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2002-07-14 17:36:00 +08:00
|
|
|
default:
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t no SAFI %u decoder",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2002-07-14 17:36:00 +08:00
|
|
|
advance = 0;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr + len;
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2000-04-28 19:34:12 +08:00
|
|
|
case AFNUM_INET6:
|
2002-07-14 17:36:00 +08:00
|
|
|
switch (safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_prefix6(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
default:
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t no SAFI %u decoder ",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2002-07-14 17:36:00 +08:00
|
|
|
advance = 0;
|
2002-07-25 05:07:20 +08:00
|
|
|
tptr = pptr + len;
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2002-07-25 05:07:20 +08:00
|
|
|
case AFNUM_L2VPN:
|
|
|
|
switch(safi) {
|
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("no SAFI %u decoder",safi);
|
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
|
|
|
advance = 0;
|
|
|
|
tptr = pptr + len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2000-04-28 19:34:12 +08:00
|
|
|
default:
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("\n\t no AFI %u decoder ",af);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2002-05-16 18:20:47 +08:00
|
|
|
advance = 0;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr + len;
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
2000-04-28 19:34:12 +08:00
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr += advance;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BGPTYPE_MP_UNREACH_NLRI:
|
2002-07-22 22:09:07 +08:00
|
|
|
af = EXTRACT_16BITS(tptr);
|
|
|
|
safi = tptr[2];
|
2002-07-14 17:36:00 +08:00
|
|
|
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
|
2002-07-14 17:36:00 +08:00
|
|
|
tok2str(bgp_afi_values, "Unknown AFI", af),
|
2002-07-14 22:14:50 +08:00
|
|
|
af,
|
2002-07-14 17:36:00 +08:00
|
|
|
(safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
|
2002-07-14 22:14:50 +08:00
|
|
|
tok2str(bgp_safi_values, "Unknown SAFI", safi),
|
|
|
|
safi);
|
2002-07-14 17:36:00 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr += 3;
|
2002-07-14 17:36:00 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
while (len - (tptr - pptr) > 0) {
|
2000-04-28 19:34:12 +08:00
|
|
|
switch (af) {
|
|
|
|
case AFNUM_INET:
|
2002-07-14 17:36:00 +08:00
|
|
|
switch (safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_prefix4(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
case SAFNUM_LABUNICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
2002-07-23 07:00:22 +08:00
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2002-07-14 17:36:00 +08:00
|
|
|
default:
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t no SAFI %u decoder",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2002-07-14 17:36:00 +08:00
|
|
|
advance = 0;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr + len;
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-05-16 18:20:47 +08:00
|
|
|
break;
|
2002-07-14 17:36:00 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2000-04-28 19:34:12 +08:00
|
|
|
case AFNUM_INET6:
|
2002-07-14 17:36:00 +08:00
|
|
|
switch (safi) {
|
|
|
|
case SAFNUM_UNICAST:
|
|
|
|
case SAFNUM_MULTICAST:
|
|
|
|
case SAFNUM_UNIMULTICAST:
|
2002-07-22 22:09:07 +08:00
|
|
|
advance = decode_prefix6(tptr, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2000-04-28 19:34:12 +08:00
|
|
|
break;
|
2002-07-14 17:36:00 +08:00
|
|
|
default:
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t no SAFI %u decoder",safi);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2002-07-14 17:36:00 +08:00
|
|
|
advance = 0;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr + len;
|
2002-07-14 17:36:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2002-07-25 05:07:20 +08:00
|
|
|
|
|
|
|
case AFNUM_L2VPN:
|
|
|
|
switch(safi) {
|
|
|
|
case SAFNUM_VPNUNICAST:
|
|
|
|
case SAFNUM_VPNMULTICAST:
|
|
|
|
case SAFNUM_VPNUNIMULTICAST:
|
|
|
|
advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("no SAFI %u decoder",safi);
|
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
|
|
|
advance = 0;
|
|
|
|
tptr = pptr + len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-04-28 19:34:12 +08:00
|
|
|
default:
|
2002-07-22 10:55:20 +08:00
|
|
|
printf("\n\t no AFI %u decoder",af);
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
2000-04-28 19:34:12 +08:00
|
|
|
advance = 0;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr = pptr + len;
|
2000-04-28 19:34:12 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr += advance;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-07-22 10:55:20 +08:00
|
|
|
case BGPTYPE_EXTD_COMMUNITIES:
|
|
|
|
if (len % 8) {
|
|
|
|
printf("invalid len");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (tlen>0) {
|
2002-08-24 21:55:31 +08:00
|
|
|
u_int16_t extd_comm;
|
|
|
|
extd_comm=EXTRACT_16BITS(tptr);
|
|
|
|
switch(extd_comm) {
|
|
|
|
case BGP_EXT_COM_RT_0:
|
|
|
|
case BGP_EXT_COM_RO_0:
|
|
|
|
printf("\n\t %s%s%s:%u:%s",
|
|
|
|
(extd_comm&0x8000) ? "vendor-specific: " : "",
|
|
|
|
(extd_comm&0x4000) ? "non-transitive: " : "",
|
|
|
|
tok2str(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
EXTRACT_16BITS(tptr+2),
|
|
|
|
getname(tptr+4));
|
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_RT_1:
|
|
|
|
case BGP_EXT_COM_RO_1:
|
|
|
|
printf("\n\t %s%s%s:%s:%u",
|
|
|
|
(extd_comm&0x8000) ? "vendor-specific: " : "",
|
|
|
|
(extd_comm&0x4000) ? "non-transitive: " : "",
|
|
|
|
tok2str(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
getname(tptr+2),
|
|
|
|
EXTRACT_16BITS(tptr+6));
|
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_VPN_ORIGIN:
|
|
|
|
case BGP_EXT_COM_OSPF_RID:
|
|
|
|
printf("\n\t %s%s%s:%s",
|
|
|
|
(extd_comm&0x8000) ? "vendor-specific: " : "",
|
|
|
|
(extd_comm&0x4000) ? "non-transitive: " : "",
|
|
|
|
tok2str(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
getname(tptr+2));
|
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_OSPF_RTYPE:
|
|
|
|
printf("\n\t %s%s%s, area:%s, router-type:%s, metric-type:%s%s",
|
|
|
|
(extd_comm&0x8000) ? "vendor-specific: " : "",
|
|
|
|
(extd_comm&0x4000) ? "non-transitive: " : "",
|
|
|
|
tok2str(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
getname(tptr+2),
|
|
|
|
tok2str(bgp_extd_comm_ospf_rtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
(*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
|
|
|
|
(*(tptr+6) == (BGP_OSPF_RTYPE_EXT ||BGP_OSPF_RTYPE_NSSA )) ? "E1" : "");
|
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_L2INFO:
|
|
|
|
printf("\n\t %s%s:%s:Control Flags [0x%02x]:MTU %u",
|
|
|
|
(extd_comm&0x4000) ? "non-transitive: " : "",
|
|
|
|
tok2str(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown",
|
|
|
|
extd_comm),
|
|
|
|
tok2str(bgp_l2vpn_encaps_values,
|
|
|
|
"unknown encaps",
|
|
|
|
*(tptr+2)),
|
2002-07-25 05:07:20 +08:00
|
|
|
*(tptr+3),
|
2002-08-24 21:55:31 +08:00
|
|
|
EXTRACT_16BITS(tptr+4));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("\n\t no typecode %u decoder",
|
|
|
|
extd_comm);
|
|
|
|
print_unknown_data(tptr,"\n\t ",8);
|
|
|
|
break;
|
2002-07-22 10:55:20 +08:00
|
|
|
}
|
|
|
|
tlen -=8;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr +=8;
|
2002-07-22 10:55:20 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
default:
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("\n\t no Attribute %u decoder",attr->bgpa_type); /* we have no decoder for the attribute */
|
2002-07-22 22:09:07 +08:00
|
|
|
if (!vflag)
|
|
|
|
print_unknown_data(pptr,"\n\t ",len);
|
2002-07-22 10:55:20 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2002-07-22 22:09:07 +08:00
|
|
|
if (vflag&&len) /* omit zero length attributes*/
|
|
|
|
print_unknown_data(pptr,"\n\t ",len);
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_open_print(const u_char *dat, int length)
|
|
|
|
{
|
|
|
|
struct bgp_open bgpo;
|
1999-12-22 14:27:19 +08:00
|
|
|
struct bgp_opt bgpopt;
|
1999-10-30 13:11:06 +08:00
|
|
|
int hlen;
|
1999-12-22 14:27:19 +08:00
|
|
|
const u_char *opt;
|
2002-07-14 22:14:50 +08:00
|
|
|
int i,cap_type,cap_len;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(dat[0], BGP_OPEN_SIZE);
|
|
|
|
memcpy(&bgpo, dat, BGP_OPEN_SIZE);
|
1999-10-30 13:11:06 +08:00
|
|
|
hlen = ntohs(bgpo.bgpo_len);
|
|
|
|
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t Version %d, ", bgpo.bgpo_version);
|
|
|
|
printf("my AS %u, ", ntohs(bgpo.bgpo_myas));
|
|
|
|
printf("Holdtime %us, ", ntohs(bgpo.bgpo_holdtime));
|
|
|
|
printf("ID %s", getname((u_char *)&bgpo.bgpo_id));
|
2002-07-23 07:00:22 +08:00
|
|
|
printf("\n\t Optional parameters, length: %u", bgpo.bgpo_optlen);
|
1999-12-22 14:27:19 +08:00
|
|
|
|
|
|
|
/* ugly! */
|
2001-09-18 05:57:50 +08:00
|
|
|
opt = &((const struct bgp_open *)dat)->bgpo_optlen;
|
1999-12-22 14:27:19 +08:00
|
|
|
opt++;
|
|
|
|
|
2001-10-18 17:51:31 +08:00
|
|
|
i = 0;
|
|
|
|
while (i < bgpo.bgpo_optlen) {
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(opt[i], BGP_OPT_SIZE);
|
|
|
|
memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
|
1999-12-22 14:27:19 +08:00
|
|
|
if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
|
2002-07-23 07:00:22 +08:00
|
|
|
printf("\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len);
|
1999-12-22 14:27:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
printf("\n\t Option %s (%u), length: %u",
|
2002-07-04 17:24:43 +08:00
|
|
|
tok2str(bgp_opt_values,"Unknown", bgpopt.bgpopt_type),
|
2002-07-14 22:14:50 +08:00
|
|
|
bgpopt.bgpopt_type,
|
2002-07-04 17:24:43 +08:00
|
|
|
bgpopt.bgpopt_len);
|
2002-07-14 22:14:50 +08:00
|
|
|
|
|
|
|
/* now lets decode the options we know*/
|
|
|
|
switch(bgpopt.bgpopt_type) {
|
|
|
|
case BGP_OPT_CAP:
|
|
|
|
cap_type=opt[i+BGP_OPT_SIZE];
|
|
|
|
cap_len=opt[i+BGP_OPT_SIZE+1];
|
2002-07-23 07:00:22 +08:00
|
|
|
printf("\n\t %s, length: %u",
|
2002-07-14 22:14:50 +08:00
|
|
|
tok2str(bgp_capcode_values,"Unknown", cap_type),
|
|
|
|
cap_len);
|
|
|
|
switch(cap_type) {
|
|
|
|
case BGP_CAPCODE_MP:
|
|
|
|
printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
|
|
|
|
tok2str(bgp_afi_values,"Unknown", EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2)),
|
|
|
|
EXTRACT_16BITS(opt+i+BGP_OPT_SIZE+2),
|
|
|
|
tok2str(bgp_safi_values,"Unknown", opt[i+BGP_OPT_SIZE+5]),
|
|
|
|
opt[i+BGP_OPT_SIZE+5]);
|
|
|
|
break;
|
|
|
|
case BGP_CAPCODE_RR:
|
|
|
|
case BGP_CAPCODE_RR_CISCO:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("\n\t\tno decoder for Capability %u",
|
|
|
|
cap_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGP_OPT_AUTH:
|
|
|
|
default:
|
|
|
|
printf("\n\t no decoder for option %u",
|
|
|
|
bgpopt.bgpopt_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-10-16 16:00:36 +08:00
|
|
|
i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
|
1999-12-22 14:27:19 +08:00
|
|
|
}
|
2000-12-04 08:43:39 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_update_print(const u_char *dat, int length)
|
|
|
|
{
|
|
|
|
struct bgp bgp;
|
|
|
|
struct bgp_attr bgpa;
|
|
|
|
int hlen;
|
|
|
|
const u_char *p;
|
|
|
|
int len;
|
1999-12-15 15:43:44 +08:00
|
|
|
int i;
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(dat[0], BGP_SIZE);
|
|
|
|
memcpy(&bgp, dat, BGP_SIZE);
|
1999-10-30 13:11:06 +08:00
|
|
|
hlen = ntohs(bgp.bgp_len);
|
|
|
|
p = dat + BGP_SIZE; /*XXX*/
|
|
|
|
|
|
|
|
/* Unfeasible routes */
|
2000-12-04 08:43:39 +08:00
|
|
|
len = EXTRACT_16BITS(p);
|
1999-10-30 13:11:06 +08:00
|
|
|
if (len) {
|
2001-01-28 17:52:47 +08:00
|
|
|
/*
|
|
|
|
* Without keeping state from the original NLRI message,
|
|
|
|
* it's not possible to tell if this a v4 or v6 route,
|
|
|
|
* so only try to decode it if we're not v6 enabled.
|
2000-12-04 08:43:39 +08:00
|
|
|
*/
|
|
|
|
#ifdef INET6
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t Withdrawn routes: %d bytes", len);
|
2002-06-12 01:08:37 +08:00
|
|
|
#else
|
2000-12-04 08:43:39 +08:00
|
|
|
char buf[MAXHOSTNAMELEN + 100];
|
|
|
|
|
2000-12-04 13:27:49 +08:00
|
|
|
TCHECK2(p[2], len);
|
2002-06-12 01:08:37 +08:00
|
|
|
i = 2;
|
2000-12-04 13:27:49 +08:00
|
|
|
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t Withdrawn routes:");
|
2002-06-12 01:08:37 +08:00
|
|
|
|
2000-12-04 13:27:49 +08:00
|
|
|
while(i < 2 + len) {
|
|
|
|
i += decode_prefix4(&p[i], buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
2000-12-04 08:43:39 +08:00
|
|
|
}
|
|
|
|
#endif
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
p += 2 + len;
|
|
|
|
|
2000-12-04 13:27:49 +08:00
|
|
|
TCHECK2(p[0], 2);
|
2000-12-04 08:43:39 +08:00
|
|
|
len = EXTRACT_16BITS(p);
|
1999-10-30 13:11:06 +08:00
|
|
|
if (len) {
|
|
|
|
/* do something more useful!*/
|
|
|
|
i = 2;
|
|
|
|
while (i < 2 + len) {
|
|
|
|
int alen, aoff;
|
|
|
|
|
2000-12-04 08:43:39 +08:00
|
|
|
TCHECK2(p[i], sizeof(bgpa));
|
1999-10-30 13:11:06 +08:00
|
|
|
memcpy(&bgpa, &p[i], sizeof(bgpa));
|
|
|
|
alen = bgp_attr_len(&bgpa);
|
|
|
|
aoff = bgp_attr_off(&bgpa);
|
|
|
|
|
2002-07-18 08:39:12 +08:00
|
|
|
printf("\n\t %s (%u), length: %u",
|
|
|
|
tok2str(bgp_attr_values, "Unknown Attribute", bgpa.bgpa_type),
|
|
|
|
bgpa.bgpa_type,
|
|
|
|
alen);
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (bgpa.bgpa_flags) {
|
2002-07-18 08:39:12 +08:00
|
|
|
printf(", flags [%s%s%s%s",
|
1999-10-30 13:11:06 +08:00
|
|
|
bgpa.bgpa_flags & 0x80 ? "O" : "",
|
|
|
|
bgpa.bgpa_flags & 0x40 ? "T" : "",
|
|
|
|
bgpa.bgpa_flags & 0x20 ? "P" : "",
|
2000-12-04 08:43:39 +08:00
|
|
|
bgpa.bgpa_flags & 0x10 ? "E" : "");
|
|
|
|
if (bgpa.bgpa_flags & 0xf)
|
|
|
|
printf("+%x", bgpa.bgpa_flags & 0xf);
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("]: ");
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
bgp_attr_print(&bgpa, &p[i + aoff], alen);
|
|
|
|
i += aoff + alen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p += 2 + len;
|
|
|
|
|
1999-12-22 14:27:19 +08:00
|
|
|
if (dat + length > p) {
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t Updated routes:");
|
1999-12-22 14:27:19 +08:00
|
|
|
while (dat + length > p) {
|
2000-11-11 01:52:02 +08:00
|
|
|
char buf[MAXHOSTNAMELEN + 100];
|
1999-12-22 14:27:19 +08:00
|
|
|
i = decode_prefix4(p, buf, sizeof(buf));
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t %s", buf);
|
1999-12-22 14:27:19 +08:00
|
|
|
if (i < 0)
|
|
|
|
break;
|
|
|
|
p += i;
|
|
|
|
}
|
|
|
|
}
|
2000-12-04 08:43:39 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bgp_notification_print(const u_char *dat, int length)
|
|
|
|
{
|
|
|
|
struct bgp_notification bgpn;
|
|
|
|
int hlen;
|
|
|
|
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
|
|
|
|
memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
|
1999-10-30 13:11:06 +08:00
|
|
|
hlen = ntohs(bgpn.bgpn_len);
|
|
|
|
|
2002-07-14 22:14:50 +08:00
|
|
|
printf(", Error - %s", tok2str(bgp_notify_major_values, "Unknown", bgpn.bgpn_major));
|
2002-07-04 17:24:43 +08:00
|
|
|
|
|
|
|
switch (bgpn.bgpn_major) {
|
|
|
|
|
|
|
|
case BGP_NOTIFY_MAJOR_MSG:
|
|
|
|
printf(" subcode %s", tok2str(bgp_notify_minor_msg_values, "Unknown", bgpn.bgpn_minor));
|
|
|
|
break;
|
|
|
|
case BGP_NOTIFY_MAJOR_OPEN:
|
|
|
|
printf(" subcode %s", tok2str(bgp_notify_minor_open_values, "Unknown", bgpn.bgpn_minor));
|
|
|
|
break;
|
|
|
|
case BGP_NOTIFY_MAJOR_UPDATE:
|
|
|
|
printf(" subcode %s", tok2str(bgp_notify_minor_update_values, "Unknown", bgpn.bgpn_minor));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-04 08:43:39 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
2002-07-24 08:10:46 +08:00
|
|
|
static void
|
|
|
|
bgp_route_refresh_print(const u_char *pptr, int len) {
|
|
|
|
|
|
|
|
const struct bgp_route_refresh *bgp_route_refresh_header;
|
|
|
|
bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
|
|
|
|
|
|
|
|
printf("\n\t AFI %s (%u), SAFI %s (%u)",
|
|
|
|
tok2str(bgp_afi_values,"Unknown",
|
|
|
|
EXTRACT_16BITS(&bgp_route_refresh_header->afi)), /* this stinks but the compiler pads the structure weird */
|
|
|
|
EXTRACT_16BITS(&bgp_route_refresh_header->afi),
|
|
|
|
tok2str(bgp_safi_values,"Unknown",
|
|
|
|
bgp_route_refresh_header->safi),
|
|
|
|
bgp_route_refresh_header->safi);
|
|
|
|
|
|
|
|
if (vflag)
|
|
|
|
print_unknown_data(pptr,"\n\t ", len);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
static void
|
1999-11-11 10:28:03 +08:00
|
|
|
bgp_header_print(const u_char *dat, int length)
|
1999-10-30 13:11:06 +08:00
|
|
|
{
|
|
|
|
struct bgp bgp;
|
|
|
|
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(dat[0], BGP_SIZE);
|
|
|
|
memcpy(&bgp, dat, BGP_SIZE);
|
2002-08-20 08:23:59 +08:00
|
|
|
printf("\n\t%s Message (%u), length: %u",
|
2002-07-18 08:39:12 +08:00
|
|
|
tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
|
|
|
|
bgp.bgp_type,
|
|
|
|
length);
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
switch (bgp.bgp_type) {
|
|
|
|
case BGP_OPEN:
|
|
|
|
bgp_open_print(dat, length);
|
|
|
|
break;
|
|
|
|
case BGP_UPDATE:
|
|
|
|
bgp_update_print(dat, length);
|
|
|
|
break;
|
|
|
|
case BGP_NOTIFICATION:
|
|
|
|
bgp_notification_print(dat, length);
|
|
|
|
break;
|
2002-07-18 08:39:12 +08:00
|
|
|
case BGP_KEEPALIVE:
|
|
|
|
break;
|
2002-07-24 08:10:46 +08:00
|
|
|
case BGP_ROUTE_REFRESH:
|
|
|
|
bgp_route_refresh_print(dat, length);
|
|
|
|
break;
|
2002-07-18 08:39:12 +08:00
|
|
|
default:
|
|
|
|
/* we have no decoder for the BGP message */
|
|
|
|
printf("\n\t no Message %u decoder",bgp.bgp_type);
|
|
|
|
print_unknown_data(dat,"\n\t ",length);
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2000-12-04 08:43:39 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bgp_print(const u_char *dat, int length)
|
|
|
|
{
|
|
|
|
const u_char *p;
|
|
|
|
const u_char *ep;
|
1999-12-15 15:43:44 +08:00
|
|
|
const u_char *start;
|
1999-10-30 13:11:06 +08:00
|
|
|
const u_char marker[] = {
|
2002-06-12 01:08:37 +08:00
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
struct bgp bgp;
|
|
|
|
u_int16_t hlen;
|
|
|
|
|
|
|
|
ep = dat + length;
|
|
|
|
if (snapend < dat + length)
|
|
|
|
ep = snapend;
|
|
|
|
|
2002-08-20 08:23:59 +08:00
|
|
|
printf(": BGP, length: %u",length);
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
p = dat;
|
1999-11-11 10:28:03 +08:00
|
|
|
start = p;
|
1999-10-30 13:11:06 +08:00
|
|
|
while (p < snapend) {
|
|
|
|
if (!TTEST2(p[0], 1))
|
|
|
|
break;
|
|
|
|
if (p[0] != 0xff) {
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TTEST2(p[0], sizeof(marker)))
|
|
|
|
break;
|
|
|
|
if (memcmp(p, marker, sizeof(marker)) != 0) {
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* found BGP header */
|
2001-10-16 16:00:36 +08:00
|
|
|
TCHECK2(p[0], BGP_SIZE); /*XXX*/
|
|
|
|
memcpy(&bgp, p, BGP_SIZE);
|
1999-10-30 13:11:06 +08:00
|
|
|
|
1999-11-11 10:28:03 +08:00
|
|
|
if (start != p)
|
|
|
|
printf(" [|BGP]");
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
hlen = ntohs(bgp.bgp_len);
|
2002-07-14 22:14:50 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (TTEST2(p[0], hlen)) {
|
1999-11-11 10:28:03 +08:00
|
|
|
bgp_header_print(p, hlen);
|
1999-10-30 13:11:06 +08:00
|
|
|
p += hlen;
|
1999-11-11 10:28:03 +08:00
|
|
|
start = p;
|
1999-10-30 13:11:06 +08:00
|
|
|
} else {
|
2002-07-04 17:24:43 +08:00
|
|
|
printf("[|BGP %s]", tok2str(bgp_msg_values, "Unknown Message Type",bgp.bgp_type));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
printf(" [|BGP]");
|
|
|
|
}
|
2002-07-02 18:05:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-18 08:39:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|