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
|
|
|
|
|
2003-11-16 17:36:07 +08:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] _U_ =
|
2007-12-07 23:54:52 +08:00
|
|
|
"@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.118 2007-12-07 15:54:52 hannes Exp $";
|
2003-11-16 17:36:07 +08:00
|
|
|
#endif
|
2000-01-10 05:34:14 +08:00
|
|
|
|
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"
|
2004-05-28 05:20:49 +08:00
|
|
|
#include "decode_prefix.h"
|
1999-10-30 13:11:06 +08:00
|
|
|
#include "addrtoname.h"
|
2000-12-04 08:43:39 +08:00
|
|
|
#include "extract.h"
|
2004-06-12 16:17:50 +08:00
|
|
|
#include "bgp.h"
|
2006-02-21 18:27:40 +08:00
|
|
|
#include "af.h"
|
2004-06-15 17:42:40 +08:00
|
|
|
#include "l2vpn.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;
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
1999-10-30 13:11:06 +08:00
|
|
|
#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 */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
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 */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2001-10-16 16:00:36 +08:00
|
|
|
#define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
|
2012-03-03 09:30:32 +08:00
|
|
|
#define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
|
1999-12-22 14:27:19 +08:00
|
|
|
|
2004-06-22 23:04:51 +08:00
|
|
|
#define BGP_UPDATE_MINSIZE 23
|
|
|
|
|
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;
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
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 */
|
2002-12-11 15:13:49 +08:00
|
|
|
}; /* 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) ? \
|
2002-12-11 15:13:49 +08:00
|
|
|
EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
|
1999-10-30 13:11:06 +08:00
|
|
|
#define bgp_attr_off(p) \
|
|
|
|
(((p)->bgpa_flags & 0x10) ? 4 : 3)
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
#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 */
|
2007-12-07 23:54:52 +08:00
|
|
|
#define BGPTYPE_AS4_PATH 17 /* RFC4893 */
|
|
|
|
#define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
|
2007-05-24 06:24:49 +08:00
|
|
|
#define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
|
2003-12-24 06:07:56 +08:00
|
|
|
#define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
|
2002-07-04 17:24:43 +08:00
|
|
|
|
2004-06-22 23:04:51 +08:00
|
|
|
#define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
|
|
|
|
|
2002-07-04 17:24:43 +08:00
|
|
|
static struct tok bgp_attr_values[] = {
|
|
|
|
{ BGPTYPE_ORIGIN, "Origin"},
|
|
|
|
{ BGPTYPE_AS_PATH, "AS Path"},
|
2007-12-07 23:54:52 +08:00
|
|
|
{ BGPTYPE_AS4_PATH, "AS4 Path"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 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"},
|
2007-12-07 23:54:52 +08:00
|
|
|
{ BGPTYPE_AGGREGATOR4, "Aggregator4"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 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"},
|
2007-05-16 16:04:50 +08:00
|
|
|
{ BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
|
2003-12-24 06:07:56 +08:00
|
|
|
{ BGPTYPE_ATTR_SET, "Attribute Set"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 255, "Reserved for development"},
|
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2004-01-16 02:59:15 +08:00
|
|
|
#define BGP_AS_SET 1
|
|
|
|
#define BGP_AS_SEQUENCE 2
|
|
|
|
#define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
|
|
|
|
#define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
|
|
|
|
|
2007-12-07 23:54:52 +08:00
|
|
|
#define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
|
|
|
|
#define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
|
2007-10-05 10:00:11 +08:00
|
|
|
|
2004-01-16 02:59:15 +08:00
|
|
|
static struct tok bgp_as_path_segment_open_values[] = {
|
|
|
|
{ BGP_AS_SEQUENCE, ""},
|
|
|
|
{ BGP_AS_SET, "{ "},
|
|
|
|
{ BGP_CONFED_AS_SEQUENCE, "( "},
|
|
|
|
{ BGP_CONFED_AS_SET, "({ "},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tok bgp_as_path_segment_close_values[] = {
|
|
|
|
{ BGP_AS_SEQUENCE, ""},
|
|
|
|
{ BGP_AS_SET, "}"},
|
|
|
|
{ BGP_CONFED_AS_SEQUENCE, ")"},
|
|
|
|
{ BGP_CONFED_AS_SET, "})"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
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
|
2004-03-18 19:14:45 +08:00
|
|
|
#define BGP_CAPCODE_ORF 3 /* XXX */
|
2002-10-11 18:33:09 +08:00
|
|
|
#define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
|
2004-03-18 19:14:45 +08:00
|
|
|
#define BGP_CAPCODE_AS_NEW 65 /* XXX */
|
|
|
|
#define BGP_CAPCODE_DYN_CAP 67 /* XXX */
|
2002-07-14 22:14:50 +08:00
|
|
|
#define BGP_CAPCODE_RR_CISCO 128
|
|
|
|
|
|
|
|
static struct tok bgp_capcode_values[] = {
|
|
|
|
{ BGP_CAPCODE_MP, "Multiprotocol Extensions"},
|
|
|
|
{ BGP_CAPCODE_RR, "Route Refresh"},
|
2004-03-18 19:14:45 +08:00
|
|
|
{ BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
|
2002-10-11 18:33:09 +08:00
|
|
|
{ BGP_CAPCODE_RESTART, "Graceful Restart"},
|
2004-03-18 19:14:45 +08:00
|
|
|
{ BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
|
|
|
|
{ BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
|
2002-07-14 22:14:50 +08:00
|
|
|
{ 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
|
2003-05-27 22:34:04 +08:00
|
|
|
#define BGP_NOTIFY_MAJOR_CAP 7
|
2002-07-04 17:24:43 +08:00
|
|
|
|
|
|
|
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"},
|
2003-05-27 22:34:04 +08:00
|
|
|
{ BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ 0, NULL}
|
1999-10-30 13:11:06 +08:00
|
|
|
};
|
|
|
|
|
2003-05-27 20:43:37 +08:00
|
|
|
/* draft-ietf-idr-cease-subcode-02 */
|
2003-05-27 21:09:02 +08:00
|
|
|
#define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
|
2003-05-27 20:43:37 +08:00
|
|
|
static struct tok bgp_notify_minor_cease_values[] = {
|
2003-05-27 21:09:02 +08:00
|
|
|
{ BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
|
2003-05-27 20:43:37 +08:00
|
|
|
{ 2, "Administratively Shutdown"},
|
|
|
|
{ 3, "Peer Unconfigured"},
|
|
|
|
{ 4, "Administratively Reset"},
|
|
|
|
{ 5, "Connection Rejected"},
|
|
|
|
{ 6, "Other Configuration Change"},
|
|
|
|
{ 7, "Connection Collision Resolution"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
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"},
|
2006-06-14 01:15:28 +08:00
|
|
|
{ 7, "Capability Message Error"},
|
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
|
|
|
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
|
|
|
};
|
|
|
|
|
2003-05-27 22:34:04 +08:00
|
|
|
static struct tok bgp_notify_minor_cap_values[] = {
|
|
|
|
{ 1, "Invalid Action Value" },
|
|
|
|
{ 2, "Invalid Capability Length" },
|
|
|
|
{ 3, "Malformed Capability Value" },
|
|
|
|
{ 4, "Unsupported Capability Code" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2007-05-16 16:04:50 +08:00
|
|
|
#define BGP_PMSI_TUNNEL_RSVP_P2MP 1
|
|
|
|
#define BGP_PMSI_TUNNEL_LDP_P2MP 2
|
|
|
|
#define BGP_PMSI_TUNNEL_PIM_SSM 3
|
|
|
|
#define BGP_PMSI_TUNNEL_PIM_SM 4
|
|
|
|
#define BGP_PMSI_TUNNEL_PIM_BIDIR 5
|
|
|
|
#define BGP_PMSI_TUNNEL_INGRESS 6
|
|
|
|
#define BGP_PMSI_TUNNEL_LDP_MP2MP 7
|
|
|
|
|
|
|
|
static struct tok bgp_pmsi_tunnel_values[] = {
|
|
|
|
{ BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
|
|
|
|
{ BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
|
|
|
|
{ BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
|
|
|
|
{ BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
|
|
|
|
{ BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
|
|
|
|
{ BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
|
|
|
|
{ BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct tok bgp_pmsi_flag_values[] = {
|
|
|
|
{ 0x01, "Leaf Information required"},
|
|
|
|
{ 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
|
2007-06-20 21:29:50 +08:00
|
|
|
/* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
|
|
|
|
#define SAFNUM_MULTICAST_VPN 5
|
2004-03-18 19:14:45 +08:00
|
|
|
#define SAFNUM_TUNNEL 64 /* XXX */
|
|
|
|
#define SAFNUM_VPLS 65 /* XXX */
|
2009-01-21 04:12:42 +08:00
|
|
|
/* draft-nalawade-idr-mdt-safi-03 */
|
|
|
|
#define SAFNUM_MDT 66
|
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
|
2003-10-27 16:04:52 +08:00
|
|
|
/* draft-marques-ppvpn-rt-constrain-01.txt */
|
|
|
|
#define SAFNUM_RT_ROUTING_INFO 132
|
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"},
|
2004-03-18 19:14:45 +08:00
|
|
|
{ SAFNUM_TUNNEL, "Tunnel"},
|
|
|
|
{ SAFNUM_VPLS, "VPLS"},
|
|
|
|
{ SAFNUM_MDT, "MDT"},
|
2002-07-04 17:24:43 +08:00
|
|
|
{ SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
|
|
|
|
{ SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
|
|
|
|
{ SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
|
2007-05-16 16:04:50 +08:00
|
|
|
{ SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
|
|
|
|
{ SAFNUM_MULTICAST_VPN, "Multicast VPN"},
|
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
|
|
|
|
|
2003-06-17 21:12:59 +08:00
|
|
|
/* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
|
2002-08-24 21:55:31 +08:00
|
|
|
#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) */
|
2003-06-17 21:12:59 +08:00
|
|
|
#define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
|
2002-08-24 21:55:31 +08:00
|
|
|
#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) */
|
2003-06-17 21:12:59 +08:00
|
|
|
#define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
|
2002-08-24 21:55:31 +08:00
|
|
|
#define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
|
|
|
|
/* rfc2547 bgp-mpls-vpns */
|
2003-02-11 00:59:30 +08:00
|
|
|
#define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
|
|
|
|
#define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
|
|
|
|
#define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
|
|
|
|
#define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
|
|
|
|
|
|
|
|
#define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
|
|
|
|
#define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
|
|
|
|
|
|
|
|
#define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
|
|
|
|
#define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
|
|
|
|
|
2002-08-24 21:55:31 +08:00
|
|
|
#define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
|
|
|
|
|
2010-08-08 20:52:35 +08:00
|
|
|
#define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
|
|
|
|
#define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
|
|
|
|
#define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
|
|
|
|
#define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
|
|
|
|
|
2007-05-16 22:02:51 +08:00
|
|
|
|
2005-10-19 17:24:08 +08:00
|
|
|
/* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
|
|
|
|
#define BGP_EXT_COM_EIGRP_GEN 0x8800
|
|
|
|
#define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
|
|
|
|
#define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
|
|
|
|
#define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
|
|
|
|
#define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
|
|
|
|
#define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
|
|
|
|
|
2003-06-17 21:12:59 +08:00
|
|
|
static struct tok bgp_extd_comm_flag_values[] = {
|
|
|
|
{ 0x8000, "vendor-specific"},
|
|
|
|
{ 0x4000, "non-transitive"},
|
|
|
|
{ 0, NULL},
|
|
|
|
};
|
|
|
|
|
2002-07-22 10:55:20 +08:00
|
|
|
static struct tok bgp_extd_comm_subtype_values[] = {
|
2003-02-11 00:59:30 +08:00
|
|
|
{ BGP_EXT_COM_RT_0, "target"},
|
|
|
|
{ BGP_EXT_COM_RT_1, "target"},
|
2003-06-17 21:12:59 +08:00
|
|
|
{ BGP_EXT_COM_RT_2, "target"},
|
2003-02-11 00:59:30 +08:00
|
|
|
{ BGP_EXT_COM_RO_0, "origin"},
|
|
|
|
{ BGP_EXT_COM_RO_1, "origin"},
|
2003-06-17 21:12:59 +08:00
|
|
|
{ BGP_EXT_COM_RO_2, "origin"},
|
2003-02-11 00:59:30 +08:00
|
|
|
{ BGP_EXT_COM_LINKBAND, "link-BW"},
|
|
|
|
{ BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
|
|
|
|
{ BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
|
|
|
|
{ BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
|
|
|
|
{ BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
|
|
|
|
{ BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
|
|
|
|
{ BGP_EXT_COM_L2INFO, "layer2-info"},
|
2005-10-19 17:24:08 +08:00
|
|
|
{ BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
|
|
|
|
{ BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
|
|
|
|
{ BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
|
|
|
|
{ BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
|
|
|
|
{ BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
|
|
|
|
{ BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
|
2007-05-16 22:02:51 +08:00
|
|
|
{ BGP_EXT_COM_SOURCE_AS, "source-AS" },
|
|
|
|
{ BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
|
2010-08-08 20:52:35 +08:00
|
|
|
{ BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"},
|
|
|
|
{ BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"},
|
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 },
|
|
|
|
};
|
|
|
|
|
2009-01-21 04:40:22 +08:00
|
|
|
#define TOKBUFSIZE 128
|
|
|
|
static char astostr[20];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* as_printf
|
|
|
|
*
|
|
|
|
* Convert an AS number into a string and return string pointer.
|
|
|
|
*
|
|
|
|
* Bepending on bflag is set or not, AS number is converted into ASDOT notation
|
|
|
|
* or plain number notation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
as_printf (char *str, int size, u_int asnum)
|
|
|
|
{
|
|
|
|
if (!bflag || asnum <= 0xFFFF) {
|
|
|
|
snprintf(str, size, "%u", asnum);
|
|
|
|
} else {
|
|
|
|
snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-05-28 05:20:49 +08:00
|
|
|
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
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
2002-07-23 07:00:22 +08:00
|
|
|
plen = pptr[0];
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if (32 < plen)
|
1999-10-30 13:11:06 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[1], (plen + 7) / 8);
|
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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
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
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if (24 > plen)
|
|
|
|
return -1;
|
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
plen-=24; /* adjust prefixlen - labellength */
|
|
|
|
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if (32 < plen)
|
2002-05-25 01:49:29 +08:00
|
|
|
return -1;
|
|
|
|
|
2002-05-16 18:20:47 +08:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[4], (plen + 7) / 8);
|
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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2002-05-16 18:20:47 +08:00
|
|
|
}
|
|
|
|
|
2007-05-21 23:42:33 +08:00
|
|
|
/*
|
|
|
|
* bgp_vpn_ip_print
|
|
|
|
*
|
|
|
|
* print an ipv4 or ipv6 address into a buffer dependend on address length.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
bgp_vpn_ip_print (const u_char *pptr, u_int addr_length) {
|
|
|
|
|
|
|
|
/* worst case string is s fully formatted v6 address */
|
|
|
|
static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
|
|
|
|
char *pos = addr;
|
|
|
|
|
|
|
|
switch(addr_length) {
|
2007-06-18 21:24:25 +08:00
|
|
|
case (sizeof(struct in_addr) << 3): /* 32 */
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], sizeof(struct in_addr));
|
|
|
|
snprintf(pos, sizeof(addr), "%s", ipaddr_string(pptr));
|
|
|
|
break;
|
2007-07-22 10:42:53 +08:00
|
|
|
#ifdef INET6
|
2007-06-18 21:24:25 +08:00
|
|
|
case (sizeof(struct in6_addr) << 3): /* 128 */
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], sizeof(struct in6_addr));
|
|
|
|
snprintf(pos, sizeof(addr), "%s", ip6addr_string(pptr));
|
|
|
|
break;
|
2007-07-22 10:42:53 +08:00
|
|
|
#endif
|
2007-05-21 23:42:33 +08:00
|
|
|
default:
|
|
|
|
snprintf(pos, sizeof(addr), "bogus address length %u", addr_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos += strlen(pos);
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
*(pos) = '\0';
|
|
|
|
return (addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_vpn_sg_print
|
|
|
|
*
|
|
|
|
* print an multicast s,g entry into a buffer.
|
|
|
|
* the s,g entry is encoded like this.
|
|
|
|
*
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | Multicast Source Length (1 octet) |
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | Multicast Source (Variable) |
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | Multicast Group Length (1 octet) |
|
|
|
|
* +-----------------------------------+
|
|
|
|
* | Multicast Group (Variable) |
|
|
|
|
* +-----------------------------------+
|
|
|
|
*
|
|
|
|
* return the number of bytes read from the wire.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
bgp_vpn_sg_print (const u_char *pptr, char *buf, u_int buflen) {
|
|
|
|
|
|
|
|
u_int8_t addr_length;
|
|
|
|
u_int total_length, offset;
|
|
|
|
|
|
|
|
total_length = 0;
|
|
|
|
|
2007-06-18 21:24:25 +08:00
|
|
|
/* Source address length, encoded in bits */
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], 1);
|
|
|
|
addr_length = *pptr++;
|
|
|
|
|
|
|
|
/* Source address */
|
2007-06-18 21:24:25 +08:00
|
|
|
TCHECK2(pptr[0], (addr_length >> 3));
|
|
|
|
total_length += (addr_length >> 3) + 1;
|
2007-05-21 23:42:33 +08:00
|
|
|
offset = strlen(buf);
|
2007-05-25 07:21:28 +08:00
|
|
|
if (addr_length) {
|
|
|
|
snprintf(buf + offset, buflen - offset, ", Source %s",
|
|
|
|
bgp_vpn_ip_print(pptr, addr_length));
|
2007-06-18 21:24:25 +08:00
|
|
|
pptr += (addr_length >> 3);
|
2007-05-25 07:21:28 +08:00
|
|
|
}
|
2007-05-21 23:42:33 +08:00
|
|
|
|
2007-06-18 21:24:25 +08:00
|
|
|
/* Group address length, encoded in bits */
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], 1);
|
|
|
|
addr_length = *pptr++;
|
|
|
|
|
|
|
|
/* Group address */
|
2007-06-18 21:24:25 +08:00
|
|
|
TCHECK2(pptr[0], (addr_length >> 3));
|
|
|
|
total_length += (addr_length >> 3) + 1;
|
2007-05-21 23:42:33 +08:00
|
|
|
offset = strlen(buf);
|
2007-05-25 07:21:28 +08:00
|
|
|
if (addr_length) {
|
|
|
|
snprintf(buf + offset, buflen - offset, ", Group %s",
|
|
|
|
bgp_vpn_ip_print(pptr, addr_length));
|
2007-06-18 21:24:25 +08:00
|
|
|
pptr += (addr_length >> 3);
|
2007-05-25 07:21:28 +08:00
|
|
|
}
|
2007-05-21 23:42:33 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return (total_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-27 16:04:52 +08:00
|
|
|
/* RDs and RTs share the same semantics
|
|
|
|
* we use bgp_vpn_rd_print for
|
|
|
|
* printing route targets inside a NLRI */
|
2004-06-12 16:17:50 +08:00
|
|
|
char *
|
2002-07-23 07:00:22 +08:00
|
|
|
bgp_vpn_rd_print (const u_char *pptr) {
|
|
|
|
|
2004-03-16 19:39:59 +08:00
|
|
|
/* allocate space for the largest possible string */
|
|
|
|
static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
|
2002-07-23 07:00:22 +08:00
|
|
|
char *pos = rd;
|
|
|
|
|
|
|
|
/* ok lets load the RD format */
|
|
|
|
switch (EXTRACT_16BITS(pptr)) {
|
2003-10-27 16:04:52 +08:00
|
|
|
|
2007-07-24 21:16:48 +08:00
|
|
|
/* 2-byte-AS:number fmt*/
|
2002-07-23 07:00:22 +08:00
|
|
|
case 0:
|
2007-07-24 21:16:48 +08:00
|
|
|
snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
|
|
|
|
EXTRACT_16BITS(pptr+2),
|
|
|
|
EXTRACT_32BITS(pptr+4),
|
|
|
|
*(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
|
2002-07-23 07:00:22 +08:00
|
|
|
break;
|
|
|
|
/* IP-address:AS fmt*/
|
2003-10-27 16:04:52 +08:00
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
case 1:
|
2003-08-13 10:26:52 +08:00
|
|
|
snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
|
|
|
|
*(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
|
2002-07-23 07:00:22 +08:00
|
|
|
break;
|
2003-10-27 16:04:52 +08:00
|
|
|
|
|
|
|
/* 4-byte-AS:number fmt*/
|
|
|
|
case 2:
|
2009-01-21 04:40:22 +08:00
|
|
|
snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
|
|
|
|
as_printf(astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)),
|
|
|
|
EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4),
|
|
|
|
*(pptr+5), EXTRACT_16BITS(pptr+6));
|
2003-10-27 16:04:52 +08:00
|
|
|
break;
|
2002-07-23 07:00:22 +08:00
|
|
|
default:
|
2003-08-13 10:26:52 +08:00
|
|
|
snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
|
2002-07-23 07:00:22 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-08-13 10:26:52 +08:00
|
|
|
pos += strlen(pos);
|
2002-07-23 07:00:22 +08:00
|
|
|
*(pos) = '\0';
|
|
|
|
return (rd);
|
|
|
|
}
|
|
|
|
|
2003-10-27 16:04:52 +08:00
|
|
|
static int
|
|
|
|
decode_rt_routing_info(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
u_int8_t route_target[8];
|
|
|
|
u_int plen;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
2003-10-27 16:04:52 +08:00
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if (0 == plen)
|
|
|
|
return 1; /* default route target */
|
|
|
|
|
|
|
|
if (32 > plen)
|
|
|
|
return -1;
|
|
|
|
|
2003-10-27 16:04:52 +08:00
|
|
|
plen-=32; /* adjust prefix length */
|
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if (64 < plen)
|
2003-10-27 16:04:52 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&route_target, 0, sizeof(route_target));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[1], (plen + 7) / 8);
|
2003-10-27 16:04:52 +08:00
|
|
|
memcpy(&route_target, &pptr[1], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
2009-01-21 04:40:22 +08:00
|
|
|
snprintf(buf, buflen, "origin AS: %s, route target %s",
|
|
|
|
as_printf(astostr, sizeof(astostr), EXTRACT_32BITS(pptr+1)),
|
|
|
|
bgp_vpn_rd_print((u_char *)&route_target));
|
2003-10-27 16:04:52 +08:00
|
|
|
|
|
|
|
return 5 + (plen + 7) / 8;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2003-10-27 16:04:52 +08:00
|
|
|
}
|
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
static int
|
|
|
|
decode_labeled_vpn_prefix4(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
struct in_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
2002-07-23 07:00:22 +08:00
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if ((24+64) > plen)
|
|
|
|
return -1;
|
|
|
|
|
2002-07-23 07:00:22 +08:00
|
|
|
plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
|
|
|
|
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if (32 < plen)
|
2002-07-23 07:00:22 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[12], (plen + 7) / 8);
|
2002-07-23 07:00:22 +08:00
|
|
|
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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2002-07-23 07:00:22 +08:00
|
|
|
}
|
|
|
|
|
2009-01-21 04:12:42 +08:00
|
|
|
/*
|
|
|
|
* +-------------------------------+
|
|
|
|
* | |
|
|
|
|
* | RD:IPv4-address (12 octets) |
|
|
|
|
* | |
|
|
|
|
* +-------------------------------+
|
|
|
|
* | MDT Group-address (4 octets) |
|
|
|
|
* +-------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MDT_VPN_NLRI_LEN 16
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_mdt_vpn_nlri(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
|
|
|
|
const u_char *rd;
|
|
|
|
const u_char *vpn_ip;
|
|
|
|
|
|
|
|
TCHECK(pptr[0]);
|
|
|
|
|
|
|
|
/* if the NLRI is not predefined length, quit.*/
|
|
|
|
if (*pptr != MDT_VPN_NLRI_LEN * NBBY)
|
|
|
|
return -1;
|
|
|
|
pptr++;
|
|
|
|
|
|
|
|
/* RD */
|
|
|
|
TCHECK2(pptr[0], 8);
|
|
|
|
rd = pptr;
|
|
|
|
pptr+=8;
|
|
|
|
|
|
|
|
/* IPv4 address */
|
|
|
|
TCHECK2(pptr[0], sizeof(struct in_addr));
|
|
|
|
vpn_ip = pptr;
|
|
|
|
pptr+=sizeof(struct in_addr);
|
|
|
|
|
|
|
|
/* MDT Group Address */
|
|
|
|
TCHECK2(pptr[0], sizeof(struct in_addr));
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
|
|
|
|
bgp_vpn_rd_print(rd), ipaddr_string(vpn_ip), ipaddr_string(pptr));
|
|
|
|
|
|
|
|
return MDT_VPN_NLRI_LEN + 1;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2007-05-16 16:04:50 +08:00
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
|
|
|
|
#define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
|
|
|
|
|
|
|
|
static struct tok bgp_multicast_vpn_route_type_values[] = {
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
|
|
|
|
{ BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_multicast_vpn(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
2007-05-21 23:42:33 +08:00
|
|
|
u_int8_t route_type, route_length, addr_length, sg_length;
|
|
|
|
u_int offset;
|
2007-05-16 16:04:50 +08:00
|
|
|
|
|
|
|
TCHECK2(pptr[0], 2);
|
|
|
|
route_type = *pptr++;
|
|
|
|
route_length = *pptr++;
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
|
2007-05-21 23:42:33 +08:00
|
|
|
tok2str(bgp_multicast_vpn_route_type_values,
|
|
|
|
"Unknown", route_type),
|
2007-05-16 16:04:50 +08:00
|
|
|
route_type, route_length);
|
|
|
|
|
|
|
|
switch(route_type) {
|
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], BGP_VPN_RD_LEN);
|
|
|
|
offset = strlen(buf);
|
|
|
|
snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
|
|
|
|
bgp_vpn_rd_print(pptr),
|
|
|
|
bgp_vpn_ip_print(pptr + BGP_VPN_RD_LEN,
|
2007-06-18 21:24:25 +08:00
|
|
|
(route_length - BGP_VPN_RD_LEN) << 3));
|
2007-05-21 23:42:33 +08:00
|
|
|
break;
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
|
|
|
|
offset = strlen(buf);
|
2009-01-21 04:40:22 +08:00
|
|
|
snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
|
|
|
|
bgp_vpn_rd_print(pptr),
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
|
2007-05-21 23:42:33 +08:00
|
|
|
break;
|
|
|
|
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], BGP_VPN_RD_LEN);
|
|
|
|
offset = strlen(buf);
|
|
|
|
snprintf(buf + offset, buflen - offset, ", RD: %s",
|
|
|
|
bgp_vpn_rd_print(pptr));
|
|
|
|
pptr += BGP_VPN_RD_LEN;
|
|
|
|
|
|
|
|
sg_length = bgp_vpn_sg_print(pptr, buf, buflen);
|
|
|
|
addr_length = route_length - sg_length;
|
|
|
|
|
|
|
|
TCHECK2(pptr[0], addr_length);
|
|
|
|
offset = strlen(buf);
|
|
|
|
snprintf(buf + offset, buflen - offset, ", Originator %s",
|
2007-06-18 21:24:25 +08:00
|
|
|
bgp_vpn_ip_print(pptr, addr_length << 3));
|
2007-05-21 23:42:33 +08:00
|
|
|
break;
|
|
|
|
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], BGP_VPN_RD_LEN);
|
|
|
|
offset = strlen(buf);
|
|
|
|
snprintf(buf + offset, buflen - offset, ", RD: %s",
|
|
|
|
bgp_vpn_rd_print(pptr));
|
|
|
|
pptr += BGP_VPN_RD_LEN;
|
|
|
|
|
|
|
|
bgp_vpn_sg_print(pptr, buf, buflen);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
|
2007-05-21 23:42:33 +08:00
|
|
|
TCHECK2(pptr[0], BGP_VPN_RD_LEN);
|
|
|
|
offset = strlen(buf);
|
2009-01-21 04:40:22 +08:00
|
|
|
snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
|
|
|
|
bgp_vpn_rd_print(pptr),
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
|
2007-05-21 23:42:33 +08:00
|
|
|
pptr += BGP_VPN_RD_LEN;
|
|
|
|
|
|
|
|
bgp_vpn_sg_print(pptr, buf, buflen);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* no per route-type printing yet.
|
|
|
|
*/
|
|
|
|
case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
|
2007-05-16 16:04:50 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return route_length + 2;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2007-07-15 06:24:54 +08:00
|
|
|
/*
|
|
|
|
* As I remember, some versions of systems have an snprintf() that
|
|
|
|
* returns -1 if the buffer would have overflowed. If the return
|
|
|
|
* value is negative, set buflen to 0, to indicate that we've filled
|
|
|
|
* the buffer up.
|
|
|
|
*
|
|
|
|
* If the return value is greater than buflen, that means that
|
|
|
|
* the buffer would have overflowed; again, set buflen to 0 in
|
|
|
|
* that case.
|
|
|
|
*/
|
|
|
|
#define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
|
|
|
|
if (strlen<0) \
|
|
|
|
buflen=0; \
|
|
|
|
else if ((u_int)strlen>buflen) \
|
|
|
|
buflen=0; \
|
|
|
|
else { \
|
|
|
|
buflen-=strlen; \
|
|
|
|
buf+=strlen; \
|
|
|
|
}
|
|
|
|
|
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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
TCHECK2(pptr[0], 2);
|
2002-07-25 05:07:20 +08:00
|
|
|
plen=EXTRACT_16BITS(pptr);
|
|
|
|
tlen=plen;
|
|
|
|
pptr+=2;
|
2010-08-08 20:52:35 +08:00
|
|
|
/* Old and new L2VPN NLRI share AFI/SAFI
|
|
|
|
* -> Assume a 12 Byte-length NLRI is auto-discovery-only
|
|
|
|
* and > 17 as old format. Complain for the middle case
|
|
|
|
*/
|
|
|
|
if (plen==12) {
|
|
|
|
/* assume AD-only with RD, BGPNH */
|
|
|
|
TCHECK2(pptr[0],12);
|
|
|
|
buf[0]='\0';
|
|
|
|
strlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
|
|
|
|
bgp_vpn_rd_print(pptr),
|
|
|
|
/* need something like getname() here */
|
|
|
|
getname(pptr+8)
|
|
|
|
);
|
|
|
|
UPDATE_BUF_BUFLEN(buf, buflen, strlen);
|
|
|
|
pptr+=12;
|
|
|
|
tlen-=12;
|
|
|
|
return plen;
|
|
|
|
} else if (plen>17) {
|
|
|
|
/* assume old format */
|
|
|
|
/* RD, ID, LBLKOFF, LBLBASE */
|
|
|
|
|
|
|
|
TCHECK2(pptr[0],15);
|
|
|
|
buf[0]='\0';
|
|
|
|
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 */
|
|
|
|
UPDATE_BUF_BUFLEN(buf, buflen, strlen);
|
|
|
|
pptr+=15;
|
|
|
|
tlen-=15;
|
|
|
|
|
|
|
|
/* ok now the variable part - lets read out TLVs*/
|
|
|
|
while (tlen>0) {
|
|
|
|
if (tlen < 3)
|
|
|
|
return -1;
|
|
|
|
TCHECK2(pptr[0], 3);
|
|
|
|
tlv_type=*pptr++;
|
|
|
|
tlv_len=EXTRACT_16BITS(pptr);
|
|
|
|
ttlv_len=tlv_len;
|
|
|
|
pptr+=2;
|
|
|
|
|
|
|
|
switch(tlv_type) {
|
|
|
|
case 1:
|
|
|
|
if (buflen!=0) {
|
|
|
|
strlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
|
|
|
|
tlv_type,
|
|
|
|
tlv_len);
|
|
|
|
UPDATE_BUF_BUFLEN(buf, buflen, strlen);
|
|
|
|
}
|
|
|
|
ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
|
|
|
|
while (ttlv_len>0) {
|
|
|
|
TCHECK(pptr[0]);
|
|
|
|
if (buflen!=0) {
|
|
|
|
strlen=snprintf(buf,buflen, "%02x",*pptr++);
|
|
|
|
UPDATE_BUF_BUFLEN(buf, buflen, strlen);
|
|
|
|
}
|
|
|
|
ttlv_len--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (buflen!=0) {
|
|
|
|
strlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
|
|
|
|
tlv_type,
|
|
|
|
tlv_len);
|
|
|
|
UPDATE_BUF_BUFLEN(buf, buflen, strlen);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
|
|
|
|
}
|
|
|
|
return plen+2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* complain bitterly ? */
|
|
|
|
/* fall through */
|
|
|
|
goto trunc;
|
2002-07-25 05:07:20 +08:00
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2002-07-25 05:07:20 +08:00
|
|
|
}
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2004-05-28 05:20:49 +08:00
|
|
|
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
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pd[0]);
|
1999-10-30 13:11:06 +08:00
|
|
|
plen = pd[0];
|
2002-10-19 20:31:47 +08:00
|
|
|
if (128 < plen)
|
1999-10-30 13:11:06 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pd[1], (plen + 7) / 8);
|
1999-10-30 13:11:06 +08:00
|
|
|
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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2002-10-19 20:31:47 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
decode_labeled_prefix6(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
struct in6_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
2002-10-19 20:31:47 +08:00
|
|
|
plen = pptr[0]; /* get prefix length */
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
|
|
|
|
if (24 > plen)
|
|
|
|
return -1;
|
|
|
|
|
2002-10-19 20:31:47 +08:00
|
|
|
plen-=24; /* adjust prefixlen - labellength */
|
|
|
|
|
|
|
|
if (128 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[4], (plen + 7) / 8);
|
2002-10-19 20:31:47 +08:00
|
|
|
memcpy(&addr, &pptr[4], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
addr.s6_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, "%s/%d, label:%u %s",
|
|
|
|
getname6((u_char *)&addr),
|
|
|
|
plen,
|
|
|
|
EXTRACT_24BITS(pptr+1)>>4,
|
|
|
|
((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
|
|
|
|
|
|
|
|
return 4 + (plen + 7) / 8;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2002-10-19 20:31:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_labeled_vpn_prefix6(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
struct in6_addr addr;
|
|
|
|
u_int plen;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(pptr[0]);
|
2002-10-19 20:31:47 +08:00
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if ((24+64) > plen)
|
|
|
|
return -1;
|
|
|
|
|
2002-10-19 20:31:47 +08:00
|
|
|
plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
|
|
|
|
|
|
|
|
if (128 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(pptr[12], (plen + 7) / 8);
|
2002-10-19 20:31:47 +08:00
|
|
|
memcpy(&addr, &pptr[12], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
addr.s6_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),
|
|
|
|
getname6((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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
2002-10-19 20:31:47 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
|
|
|
|
2005-03-23 03:30:59 +08:00
|
|
|
static int
|
2005-05-19 03:58:36 +08:00
|
|
|
decode_clnp_prefix(const u_char *pptr, char *buf, u_int buflen)
|
2005-03-23 03:30:59 +08:00
|
|
|
{
|
|
|
|
u_int8_t addr[19];
|
|
|
|
u_int plen;
|
|
|
|
|
|
|
|
TCHECK(pptr[0]);
|
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
|
|
|
if (152 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
TCHECK2(pptr[4], (plen + 7) / 8);
|
|
|
|
memcpy(&addr, &pptr[4], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
addr[(plen + 7) / 8 - 1] &=
|
|
|
|
((0xff00 >> (plen % 8)) & 0xff);
|
|
|
|
}
|
2005-05-19 03:58:36 +08:00
|
|
|
snprintf(buf, buflen, "%s/%d",
|
2005-06-03 15:28:24 +08:00
|
|
|
isonsap_string(addr,(plen + 7) / 8),
|
2005-05-19 03:58:36 +08:00
|
|
|
plen);
|
2005-03-23 03:30:59 +08:00
|
|
|
|
2005-05-19 03:58:36 +08:00
|
|
|
return 1 + (plen + 7) / 8;
|
2005-03-23 03:30:59 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_labeled_vpn_clnp_prefix(const u_char *pptr, char *buf, u_int buflen)
|
|
|
|
{
|
|
|
|
u_int8_t addr[19];
|
|
|
|
u_int plen;
|
|
|
|
|
|
|
|
TCHECK(pptr[0]);
|
|
|
|
plen = pptr[0]; /* get prefix length */
|
|
|
|
|
Before subtracting a value from a prefix length, make sure the prefix
length is >= the value. (In theory, if that check isn't done, the
prefix length will overflow, and, as it's unsigned, that'd make it very
large, and rejected by the other sanity check - but it's cleaner to
check explicitly.)
In decode_rt_routing_info(), fix the checks for the prefix length -
according to draft-marques-ppvpn-rt-constrain-01, the default route
target has a 0-length prefix, and all others have a length between 32
and 96.
2005-10-17 02:14:55 +08:00
|
|
|
if ((24+64) > plen)
|
|
|
|
return -1;
|
|
|
|
|
2005-03-23 03:30:59 +08:00
|
|
|
plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
|
|
|
|
|
|
|
|
if (152 < plen)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
TCHECK2(pptr[12], (plen + 7) / 8);
|
|
|
|
memcpy(&addr, &pptr[12], (plen + 7) / 8);
|
|
|
|
if (plen % 8) {
|
|
|
|
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),
|
2005-06-03 15:28:24 +08:00
|
|
|
isonsap_string(addr,(plen + 7) / 8),
|
2005-03-23 03:30:59 +08:00
|
|
|
plen,
|
|
|
|
EXTRACT_24BITS(pptr+1)>>4,
|
|
|
|
((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
|
|
|
|
|
|
|
|
return 12 + (plen + 7) / 8;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2007-10-05 10:00:11 +08:00
|
|
|
/*
|
2007-12-07 23:54:52 +08:00
|
|
|
* bgp_attr_get_as_size
|
|
|
|
*
|
|
|
|
* Try to find the size of the ASs encoded in an as-path. It is not obvious, as
|
|
|
|
* both Old speakers that do not support 4 byte AS, and the new speakers that do
|
|
|
|
* support, exchange AS-Path with the same path-attribute type value 0x02.
|
2007-10-05 10:00:11 +08:00
|
|
|
*/
|
|
|
|
static int
|
2007-12-07 23:54:52 +08:00
|
|
|
bgp_attr_get_as_size (u_int8_t bgpa_type, const u_char *pptr, int len)
|
2007-10-05 10:00:11 +08:00
|
|
|
{
|
2007-12-07 23:54:52 +08:00
|
|
|
const u_char *tptr = pptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the path attribute is the optional AS4 path type, then we already
|
|
|
|
* know, that ASs must be encoded in 4 byte format.
|
|
|
|
*/
|
|
|
|
if (bgpa_type == BGPTYPE_AS4_PATH) {
|
|
|
|
return 4;
|
|
|
|
}
|
2007-10-05 10:00:11 +08:00
|
|
|
|
2007-12-07 23:54:52 +08:00
|
|
|
/*
|
|
|
|
* Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
|
|
|
|
* TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
|
|
|
|
* each.
|
|
|
|
*/
|
|
|
|
while (tptr < pptr + len) {
|
|
|
|
TCHECK(tptr[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we do not find a valid segment type, our guess might be wrong.
|
|
|
|
*/
|
|
|
|
if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
|
|
|
TCHECK(tptr[1]);
|
|
|
|
tptr += 2 + tptr[1] * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we correctly reached end of the AS path attribute data content,
|
|
|
|
* then most likely ASs were indeed encoded as 2 bytes.
|
|
|
|
*/
|
|
|
|
if (tptr == pptr + len) {
|
|
|
|
return 2;
|
|
|
|
}
|
2007-10-05 10:00:11 +08:00
|
|
|
|
|
|
|
trunc:
|
2007-12-07 23:54:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We can come here, either we did not have enough data, or if we
|
|
|
|
* try to decode 4 byte ASs in 2 byte format. Either way, return 4,
|
|
|
|
* so that calller can try to decode each AS as of 4 bytes. If indeed
|
|
|
|
* there was not enough data, it will crib and end the parse anyways.
|
|
|
|
*/
|
|
|
|
return 4;
|
2007-10-05 10:00:11 +08:00
|
|
|
}
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
static int
|
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;
|
2005-06-03 15:28:24 +08:00
|
|
|
u_int8_t safi, snpa, nhlen;
|
2003-06-17 21:12:59 +08:00
|
|
|
union { /* copy buffer for bandwidth values */
|
|
|
|
float f;
|
|
|
|
u_int32_t i;
|
|
|
|
} bw;
|
1999-10-30 13:11:06 +08:00
|
|
|
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];
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
2007-12-07 23:54:52 +08:00
|
|
|
int as_size;
|
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");
|
2004-03-24 08:01:00 +08:00
|
|
|
else {
|
|
|
|
TCHECK(*tptr);
|
2004-04-29 10:16:01 +08:00
|
|
|
printf("%s", tok2strbuf(bgp_origin_values,
|
|
|
|
"Unknown Origin Typecode",
|
|
|
|
tptr[0],
|
|
|
|
tokbuf, sizeof(tokbuf)));
|
2004-03-24 08:01:00 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
2004-04-29 10:16:01 +08:00
|
|
|
|
2007-12-07 23:54:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process AS4 byte path and AS2 byte path attributes here.
|
|
|
|
*/
|
|
|
|
case BGPTYPE_AS4_PATH:
|
1999-10-30 13:11:06 +08:00
|
|
|
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;
|
|
|
|
}
|
2004-01-16 02:59:15 +08:00
|
|
|
|
2007-12-07 23:54:52 +08:00
|
|
|
/*
|
|
|
|
* BGP updates exchanged between New speakers that support 4
|
|
|
|
* byte AS, ASs are always encoded in 4 bytes. There is no
|
|
|
|
* definitive way to find this, just by the packet's
|
|
|
|
* contents. So, check for packet's TLV's sanity assuming
|
|
|
|
* 2 bytes first, and it does not pass, assume that ASs are
|
|
|
|
* encoded in 4 bytes format and move on.
|
|
|
|
*/
|
|
|
|
as_size = bgp_attr_get_as_size(attr->bgpa_type, pptr, len);
|
|
|
|
|
2002-07-22 22:09:07 +08:00
|
|
|
while (tptr < pptr + len) {
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[0]);
|
2004-04-29 10:16:01 +08:00
|
|
|
printf("%s", tok2strbuf(bgp_as_path_segment_open_values,
|
|
|
|
"?", tptr[0],
|
|
|
|
tokbuf, sizeof(tokbuf)));
|
2007-12-07 23:54:52 +08:00
|
|
|
for (i = 0; i < tptr[1] * as_size; i += as_size) {
|
|
|
|
TCHECK2(tptr[2 + i], as_size);
|
2009-01-21 04:40:22 +08:00
|
|
|
printf("%s ",
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
as_size == 2 ?
|
|
|
|
EXTRACT_16BITS(&tptr[2 + i]) :
|
|
|
|
EXTRACT_32BITS(&tptr[2 + i])));
|
2004-01-16 02:59:15 +08:00
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[0]);
|
2004-04-29 10:16:01 +08:00
|
|
|
printf("%s", tok2strbuf(bgp_as_path_segment_close_values,
|
|
|
|
"?", tptr[0],
|
|
|
|
tokbuf, sizeof(tokbuf)));
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[1]);
|
2007-12-07 23:54:52 +08:00
|
|
|
tptr += 2 + tptr[1] * as_size;
|
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");
|
2004-03-24 08:01:00 +08:00
|
|
|
else {
|
|
|
|
TCHECK2(tptr[0], 4);
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%s", getname(tptr));
|
2004-03-24 08:01:00 +08:00
|
|
|
}
|
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");
|
2004-03-24 08:01:00 +08:00
|
|
|
else {
|
|
|
|
TCHECK2(tptr[0], 4);
|
2002-07-22 22:09:07 +08:00
|
|
|
printf("%u", EXTRACT_32BITS(tptr));
|
2004-03-24 08:01:00 +08:00
|
|
|
}
|
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;
|
2009-01-21 04:40:22 +08:00
|
|
|
case BGPTYPE_AGGREGATOR:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Depending on the AS encoded is of 2 bytes or of 4 bytes,
|
|
|
|
* the length of this PA can be either 6 bytes or 8 bytes.
|
|
|
|
*/
|
|
|
|
if (len != 6 && len != 8) {
|
|
|
|
printf("invalid len");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TCHECK2(tptr[0], len);
|
|
|
|
if (len == 6) {
|
|
|
|
printf(" AS #%s, origin %s",
|
|
|
|
as_printf(astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
|
2002-07-22 22:09:07 +08:00
|
|
|
getname(tptr + 2));
|
2009-01-21 04:40:22 +08:00
|
|
|
} else {
|
|
|
|
printf(" AS #%s, origin %s",
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
EXTRACT_32BITS(tptr)), getname(tptr + 4));
|
|
|
|
}
|
|
|
|
break;
|
2007-12-07 23:54:52 +08:00
|
|
|
case BGPTYPE_AGGREGATOR4:
|
|
|
|
if (len != 8) {
|
|
|
|
printf("invalid len");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TCHECK2(tptr[0], 8);
|
2009-01-21 04:40:22 +08:00
|
|
|
printf(" AS #%s, origin %s",
|
|
|
|
as_printf(astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
|
|
|
|
getname(tptr + 4));
|
2007-12-07 23:54:52 +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;
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], 4);
|
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;
|
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], 4);
|
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:
|
2004-03-24 08:01:00 +08:00
|
|
|
if (len % 4) {
|
|
|
|
printf("invalid len");
|
|
|
|
break;
|
|
|
|
}
|
2002-07-14 22:14:50 +08:00
|
|
|
while (tlen>0) {
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], 4);
|
2002-07-14 22:14:50 +08:00
|
|
|
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:
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], 3);
|
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)",
|
2006-02-21 18:27:40 +08:00
|
|
|
tok2strbuf(af_values, "Unknown AFI", af,
|
2004-04-29 10:16:01 +08:00
|
|
|
tokbuf, sizeof(tokbuf)),
|
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 */
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_safi_values, "Unknown SAFI", safi,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-14 22:14:50 +08:00
|
|
|
safi);
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2005-03-23 03:30:59 +08:00
|
|
|
switch(af<<8 | safi) {
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
|
2007-05-16 16:04:50 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
|
2009-01-21 04:12:42 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MDT):
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
|
2006-02-02 20:36:09 +08:00
|
|
|
case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
|
2005-03-23 03:30:59 +08:00
|
|
|
break;
|
|
|
|
default:
|
2005-05-06 06:49:17 +08:00
|
|
|
TCHECK2(tptr[0], tlen);
|
2005-03-23 03:30:59 +08:00
|
|
|
printf("\n\t no AFI %u / SAFI %u decoder",af,safi);
|
2002-10-05 18:45:27 +08:00
|
|
|
if (vflag <= 1)
|
2002-07-22 22:09:07 +08:00
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
2005-03-23 03:30:59 +08:00
|
|
|
goto done;
|
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;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[0]);
|
2005-06-03 15:28:24 +08:00
|
|
|
nhlen = tptr[0];
|
|
|
|
tlen = nhlen;
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr++;
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (tlen) {
|
2005-03-23 03:30:59 +08:00
|
|
|
printf("\n\t nexthop: ");
|
|
|
|
while (tlen > 0) {
|
|
|
|
switch(af<<8 | safi) {
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
|
2007-05-16 16:04:50 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
|
2009-01-21 04:12:42 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MDT):
|
|
|
|
if (tlen < (int)sizeof(struct in_addr)) {
|
2005-03-23 03:30:59 +08:00
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], sizeof(struct in_addr));
|
|
|
|
printf("%s",getname(tptr));
|
|
|
|
tlen -= sizeof(struct in_addr);
|
|
|
|
tptr += sizeof(struct in_addr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
|
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
|
|
|
|
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;
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
|
|
|
|
if (tlen < (int)sizeof(struct in6_addr)) {
|
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], sizeof(struct in6_addr));
|
|
|
|
printf("%s", getname6(tptr));
|
|
|
|
tlen -= sizeof(struct in6_addr);
|
|
|
|
tptr += sizeof(struct in6_addr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
|
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2006-02-02 20:36:09 +08:00
|
|
|
case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
if (tlen < (int)sizeof(struct in_addr)) {
|
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], sizeof(struct in_addr));
|
|
|
|
printf("%s", getname(tptr));
|
|
|
|
tlen -= (sizeof(struct in_addr));
|
|
|
|
tptr += (sizeof(struct in_addr));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
TCHECK2(tptr[0], tlen);
|
|
|
|
printf("%s",isonsap_string(tptr,tlen));
|
|
|
|
tptr += tlen;
|
|
|
|
tlen = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
if (tlen < BGP_VPN_RD_LEN+1) {
|
|
|
|
printf("invalid len");
|
|
|
|
tlen = 0;
|
|
|
|
} else {
|
|
|
|
TCHECK2(tptr[0], tlen);
|
|
|
|
printf("RD: %s, %s",
|
|
|
|
bgp_vpn_rd_print(tptr),
|
|
|
|
isonsap_string(tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN));
|
|
|
|
/* rfc986 mapped IPv4 address ? */
|
|
|
|
if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
|
|
|
|
printf(" = %s", getname(tptr+BGP_VPN_RD_LEN+4));
|
2005-03-27 09:31:25 +08:00
|
|
|
#ifdef INET6
|
2005-03-23 17:22:58 +08:00
|
|
|
/* rfc1888 mapped IPv6 address ? */
|
|
|
|
else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
|
|
|
|
printf(" = %s", getname6(tptr+BGP_VPN_RD_LEN+3));
|
2005-03-27 09:31:25 +08:00
|
|
|
#endif
|
2005-03-23 03:30:59 +08:00
|
|
|
tptr += tlen;
|
|
|
|
tlen = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TCHECK2(tptr[0], tlen);
|
|
|
|
printf("no AFI %u/SAFI %u decoder",af,safi);
|
|
|
|
if (vflag <= 1)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
|
|
|
tptr += tlen;
|
|
|
|
tlen = 0;
|
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2005-06-03 15:28:24 +08:00
|
|
|
printf(", nh-length: %u", nhlen);
|
2002-07-22 22:09:07 +08:00
|
|
|
tptr += tlen;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[0]);
|
2002-07-22 22:09:07 +08:00
|
|
|
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--) {
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK(tptr[0]);
|
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 {
|
2004-03-24 08:01:00 +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) {
|
2005-03-23 03:30:59 +08:00
|
|
|
switch (af<<8 | safi) {
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
advance = decode_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
|
|
|
|
advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
|
|
|
|
advance = decode_rt_routing_info(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2007-05-25 07:13:18 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
|
2007-05-16 16:04:50 +08:00
|
|
|
advance = decode_multicast_vpn(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2009-01-21 04:12:42 +08:00
|
|
|
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MDT):
|
|
|
|
advance = decode_mdt_vpn_nlri(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
advance = decode_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
|
|
|
|
advance = decode_labeled_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2006-02-02 20:36:09 +08:00
|
|
|
case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
|
2005-05-19 03:58:36 +08:00
|
|
|
advance = decode_clnp_prefix(tptr, buf, sizeof(buf));
|
2005-03-23 03:30:59 +08:00
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_clnp_prefix(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TCHECK2(*tptr,tlen);
|
|
|
|
printf("\n\t no AFI %u / SAFI %u decoder",af,safi);
|
|
|
|
if (vflag <= 1)
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
|
|
|
advance = 0;
|
|
|
|
tptr = pptr + len;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-21 04:45:34 +08:00
|
|
|
if (advance < 0)
|
|
|
|
break;
|
2005-03-23 03:30:59 +08:00
|
|
|
tptr += advance;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2005-03-23 03:30:59 +08:00
|
|
|
done:
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BGPTYPE_MP_UNREACH_NLRI:
|
2004-06-22 23:04:51 +08:00
|
|
|
TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
|
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)",
|
2006-02-21 18:27:40 +08:00
|
|
|
tok2strbuf(af_values, "Unknown AFI", af,
|
2004-04-29 10:16:01 +08:00
|
|
|
tokbuf, sizeof(tokbuf)),
|
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 */
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_safi_values, "Unknown SAFI", safi,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-14 22:14:50 +08:00
|
|
|
safi);
|
2002-07-14 17:36:00 +08:00
|
|
|
|
2004-06-22 23:04:51 +08:00
|
|
|
if (len == BGP_MP_NLRI_MINSIZE)
|
|
|
|
printf("\n\t End-of-Rib Marker (empty NLRI)");
|
|
|
|
|
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) {
|
2005-03-23 03:30:59 +08:00
|
|
|
switch (af<<8 | safi) {
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
advance = decode_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
|
|
|
|
advance = decode_labeled_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_prefix4(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef INET6
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
|
|
|
|
advance = decode_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
|
|
|
|
advance = decode_labeled_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_prefix6(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2006-02-02 20:36:09 +08:00
|
|
|
case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
|
2005-03-23 03:30:59 +08:00
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_l2(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
|
2005-05-19 03:58:36 +08:00
|
|
|
advance = decode_clnp_prefix(tptr, buf, sizeof(buf));
|
2005-03-23 03:30:59 +08:00
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
|
|
|
|
case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
|
|
|
|
advance = decode_labeled_vpn_clnp_prefix(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2009-01-21 04:40:22 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MDT):
|
|
|
|
advance = decode_mdt_vpn_nlri(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2007-05-25 07:13:18 +08:00
|
|
|
case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
|
|
|
|
case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
|
|
|
|
advance = decode_multicast_vpn(tptr, buf, sizeof(buf));
|
|
|
|
if (advance == -1)
|
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
else if (advance == -2)
|
|
|
|
goto trunc;
|
|
|
|
else
|
|
|
|
printf("\n\t %s", buf);
|
|
|
|
break;
|
2005-03-23 03:30:59 +08:00
|
|
|
default:
|
|
|
|
TCHECK2(*(tptr-3),tlen);
|
|
|
|
printf("no AFI %u / SAFI %u decoder",af,safi);
|
|
|
|
if (vflag <= 1)
|
|
|
|
print_unknown_data(tptr-3,"\n\t ",tlen);
|
|
|
|
advance = 0;
|
|
|
|
tptr = pptr + len;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-21 04:45:34 +08:00
|
|
|
if (advance < 0)
|
|
|
|
break;
|
2005-03-23 03:30:59 +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;
|
2004-03-24 08:01:00 +08:00
|
|
|
|
|
|
|
TCHECK2(tptr[0], 2);
|
2002-08-24 21:55:31 +08:00
|
|
|
extd_comm=EXTRACT_16BITS(tptr);
|
2003-06-17 21:12:59 +08:00
|
|
|
|
|
|
|
printf("\n\t %s (0x%04x), Flags [%s]",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_extd_comm_subtype_values,
|
|
|
|
"unknown extd community typecode",
|
|
|
|
extd_comm, tokbuf, sizeof(tokbuf)),
|
2003-06-17 21:12:59 +08:00
|
|
|
extd_comm,
|
|
|
|
bittok2str(bgp_extd_comm_flag_values, "none", extd_comm));
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(*(tptr+2), 6);
|
2002-08-24 21:55:31 +08:00
|
|
|
switch(extd_comm) {
|
|
|
|
case BGP_EXT_COM_RT_0:
|
|
|
|
case BGP_EXT_COM_RO_0:
|
2010-08-08 20:52:35 +08:00
|
|
|
case BGP_EXT_COM_L2VPN_RT_0:
|
2007-07-24 21:16:48 +08:00
|
|
|
printf(": %u:%u (= %s)",
|
2002-08-24 21:55:31 +08:00
|
|
|
EXTRACT_16BITS(tptr+2),
|
2007-07-24 21:16:48 +08:00
|
|
|
EXTRACT_32BITS(tptr+4),
|
2002-08-24 21:55:31 +08:00
|
|
|
getname(tptr+4));
|
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_RT_1:
|
|
|
|
case BGP_EXT_COM_RO_1:
|
2010-08-08 20:52:35 +08:00
|
|
|
case BGP_EXT_COM_L2VPN_RT_1:
|
2007-05-16 22:02:51 +08:00
|
|
|
case BGP_EXT_COM_VRF_RT_IMP:
|
2003-06-17 21:12:59 +08:00
|
|
|
printf(": %s:%u",
|
2002-08-24 21:55:31 +08:00
|
|
|
getname(tptr+2),
|
|
|
|
EXTRACT_16BITS(tptr+6));
|
|
|
|
break;
|
2003-06-17 21:12:59 +08:00
|
|
|
case BGP_EXT_COM_RT_2:
|
|
|
|
case BGP_EXT_COM_RO_2:
|
2009-01-21 04:40:22 +08:00
|
|
|
printf(": %s:%u",
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6));
|
|
|
|
break;
|
2002-08-26 02:25:57 +08:00
|
|
|
case BGP_EXT_COM_LINKBAND:
|
2003-06-17 21:12:59 +08:00
|
|
|
bw.i = EXTRACT_32BITS(tptr+2);
|
|
|
|
printf(": bandwidth: %.3f Mbps",
|
|
|
|
bw.f*8/1000000);
|
2002-08-26 02:25:57 +08:00
|
|
|
break;
|
2002-08-24 21:55:31 +08:00
|
|
|
case BGP_EXT_COM_VPN_ORIGIN:
|
2003-02-11 00:59:30 +08:00
|
|
|
case BGP_EXT_COM_VPN_ORIGIN2:
|
|
|
|
case BGP_EXT_COM_VPN_ORIGIN3:
|
|
|
|
case BGP_EXT_COM_VPN_ORIGIN4:
|
2002-08-24 21:55:31 +08:00
|
|
|
case BGP_EXT_COM_OSPF_RID:
|
2003-02-11 00:59:30 +08:00
|
|
|
case BGP_EXT_COM_OSPF_RID2:
|
2003-06-17 21:12:59 +08:00
|
|
|
printf("%s", getname(tptr+2));
|
2002-08-24 21:55:31 +08:00
|
|
|
break;
|
2003-02-11 00:59:30 +08:00
|
|
|
case BGP_EXT_COM_OSPF_RTYPE:
|
|
|
|
case BGP_EXT_COM_OSPF_RTYPE2:
|
2003-06-17 21:12:59 +08:00
|
|
|
printf(": area:%s, router-type:%s, metric-type:%s%s",
|
2002-08-24 21:55:31 +08:00
|
|
|
getname(tptr+2),
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_extd_comm_ospf_rtype_values,
|
|
|
|
"unknown (0x%02x)",
|
|
|
|
*(tptr+6),
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-08-24 21:55:31 +08:00
|
|
|
(*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
|
2006-10-06 14:25:06 +08:00
|
|
|
((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : "");
|
2002-08-24 21:55:31 +08:00
|
|
|
break;
|
|
|
|
case BGP_EXT_COM_L2INFO:
|
2003-06-17 21:12:59 +08:00
|
|
|
printf(": %s Control Flags [0x%02x]:MTU %u",
|
2004-06-15 17:42:40 +08:00
|
|
|
tok2strbuf(l2vpn_encaps_values,
|
2004-04-29 10:16:01 +08:00
|
|
|
"unknown encaps",
|
|
|
|
*(tptr+2),
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-25 05:07:20 +08:00
|
|
|
*(tptr+3),
|
2002-08-24 21:55:31 +08:00
|
|
|
EXTRACT_16BITS(tptr+4));
|
|
|
|
break;
|
2007-05-16 22:02:51 +08:00
|
|
|
case BGP_EXT_COM_SOURCE_AS:
|
|
|
|
printf(": AS %u", EXTRACT_16BITS(tptr+2));
|
|
|
|
break;
|
2002-08-24 21:55:31 +08:00
|
|
|
default:
|
2005-05-06 06:49:17 +08:00
|
|
|
TCHECK2(*tptr,8);
|
2002-08-24 21:55:31 +08:00
|
|
|
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;
|
|
|
|
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGPTYPE_PMSI_TUNNEL:
|
|
|
|
{
|
|
|
|
u_int8_t tunnel_type, flags;
|
|
|
|
|
|
|
|
tunnel_type = *(tptr+1);
|
|
|
|
flags = *tptr;
|
|
|
|
tlen = len;
|
|
|
|
|
|
|
|
TCHECK2(tptr[0], 5);
|
|
|
|
printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
|
|
|
|
tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
|
|
|
|
tunnel_type,
|
|
|
|
bittok2str(bgp_pmsi_flag_values, "none", flags),
|
|
|
|
EXTRACT_24BITS(tptr+2)>>4);
|
|
|
|
|
|
|
|
tptr +=5;
|
|
|
|
tlen -= 5;
|
|
|
|
|
|
|
|
switch (tunnel_type) {
|
2007-05-16 22:35:35 +08:00
|
|
|
case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */
|
|
|
|
case BGP_PMSI_TUNNEL_PIM_BIDIR:
|
2007-05-16 16:04:50 +08:00
|
|
|
TCHECK2(tptr[0], 8);
|
2007-05-16 22:35:35 +08:00
|
|
|
printf("\n\t Sender %s, P-Group %s",
|
2007-05-16 16:04:50 +08:00
|
|
|
ipaddr_string(tptr),
|
|
|
|
ipaddr_string(tptr+4));
|
|
|
|
break;
|
|
|
|
|
2007-05-16 22:35:35 +08:00
|
|
|
case BGP_PMSI_TUNNEL_PIM_SSM:
|
|
|
|
TCHECK2(tptr[0], 8);
|
|
|
|
printf("\n\t Root-Node %s, P-Group %s",
|
|
|
|
ipaddr_string(tptr),
|
|
|
|
ipaddr_string(tptr+4));
|
|
|
|
break;
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_PMSI_TUNNEL_INGRESS:
|
2007-05-16 22:35:35 +08:00
|
|
|
TCHECK2(tptr[0], 4);
|
|
|
|
printf("\n\t Tunnel-Endpoint %s",
|
|
|
|
ipaddr_string(tptr));
|
|
|
|
break;
|
|
|
|
case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
|
2007-05-16 16:04:50 +08:00
|
|
|
case BGP_PMSI_TUNNEL_LDP_MP2MP:
|
2007-05-16 22:35:35 +08:00
|
|
|
TCHECK2(tptr[0], 8);
|
|
|
|
printf("\n\t Root-Node %s, LSP-ID 0x%08x",
|
|
|
|
ipaddr_string(tptr),
|
|
|
|
EXTRACT_32BITS(tptr+4));
|
|
|
|
break;
|
|
|
|
case BGP_PMSI_TUNNEL_RSVP_P2MP:
|
|
|
|
TCHECK2(tptr[0], 8);
|
|
|
|
printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
|
|
|
|
ipaddr_string(tptr),
|
|
|
|
EXTRACT_32BITS(tptr+4));
|
|
|
|
break;
|
2007-05-16 16:04:50 +08:00
|
|
|
default:
|
|
|
|
if (vflag <= 1) {
|
|
|
|
print_unknown_data(tptr,"\n\t ",tlen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-12-24 06:07:56 +08:00
|
|
|
case BGPTYPE_ATTR_SET:
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], 4);
|
2009-01-21 04:40:22 +08:00
|
|
|
printf("\n\t Origin AS: %s",
|
|
|
|
as_printf(astostr, sizeof(astostr), EXTRACT_32BITS(tptr)));
|
|
|
|
tptr+=4;
|
2003-12-24 06:07:56 +08:00
|
|
|
len -=4;
|
|
|
|
|
|
|
|
while (len >= 2 ) {
|
|
|
|
int alen;
|
|
|
|
struct bgp_attr bgpa;
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(tptr[0], sizeof(bgpa));
|
2003-12-24 06:07:56 +08:00
|
|
|
memcpy(&bgpa, tptr, sizeof(bgpa));
|
|
|
|
alen = bgp_attr_len(&bgpa);
|
|
|
|
tptr += bgp_attr_off(&bgpa);
|
|
|
|
len -= bgp_attr_off(&bgpa);
|
|
|
|
|
|
|
|
printf("\n\t %s (%u), length: %u",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_attr_values,
|
|
|
|
"Unknown Attribute", bgpa.bgpa_type,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2003-12-24 06:07:56 +08:00
|
|
|
bgpa.bgpa_type,
|
|
|
|
alen);
|
|
|
|
|
|
|
|
if (bgpa.bgpa_flags) {
|
|
|
|
printf(", Flags [%s%s%s%s",
|
|
|
|
bgpa.bgpa_flags & 0x80 ? "O" : "",
|
|
|
|
bgpa.bgpa_flags & 0x40 ? "T" : "",
|
|
|
|
bgpa.bgpa_flags & 0x20 ? "P" : "",
|
|
|
|
bgpa.bgpa_flags & 0x10 ? "E" : "");
|
|
|
|
if (bgpa.bgpa_flags & 0xf)
|
|
|
|
printf("+%x", bgpa.bgpa_flags & 0xf);
|
|
|
|
printf("]: ");
|
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
/* FIXME check for recursion */
|
|
|
|
if (!bgp_attr_print(&bgpa, tptr, alen))
|
|
|
|
return 0;
|
2003-12-24 06:07:56 +08:00
|
|
|
tptr += alen;
|
|
|
|
len -= alen;
|
|
|
|
}
|
2003-12-24 06:18:35 +08:00
|
|
|
break;
|
2003-12-24 06:07:56 +08:00
|
|
|
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
default:
|
2004-03-24 08:01:00 +08:00
|
|
|
TCHECK2(*pptr,len);
|
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-10-05 18:45:27 +08:00
|
|
|
if (vflag <= 1)
|
2002-07-22 22:09:07 +08:00
|
|
|
print_unknown_data(pptr,"\n\t ",len);
|
2002-07-22 10:55:20 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2005-05-06 06:49:17 +08:00
|
|
|
if (vflag > 1 && len) { /* omit zero length attributes*/
|
|
|
|
TCHECK2(*pptr,len);
|
2002-07-22 22:09:07 +08:00
|
|
|
print_unknown_data(pptr,"\n\t ",len);
|
2005-05-06 06:49:17 +08:00
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 0;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
|
|
|
|
2012-03-03 09:30:32 +08:00
|
|
|
static void
|
|
|
|
bgp_capabilities_print(const u_char *opt, int caps_len)
|
|
|
|
{
|
|
|
|
char tokbuf[TOKBUFSIZE];
|
|
|
|
char tokbuf2[TOKBUFSIZE];
|
|
|
|
int cap_type, cap_len, tcap_len, cap_offset;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i < caps_len) {
|
|
|
|
TCHECK2(opt[i], BGP_CAP_HEADER_SIZE);
|
|
|
|
cap_type=opt[i];
|
|
|
|
cap_len=opt[i+1];
|
|
|
|
tcap_len=cap_len;
|
|
|
|
printf("\n\t %s (%u), length: %u",
|
|
|
|
tok2strbuf(bgp_capcode_values, "Unknown",
|
|
|
|
cap_type, tokbuf, sizeof(tokbuf)),
|
|
|
|
cap_type,
|
|
|
|
cap_len);
|
|
|
|
TCHECK2(opt[i+2], cap_len);
|
|
|
|
switch (cap_type) {
|
|
|
|
case BGP_CAPCODE_MP:
|
|
|
|
printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
|
|
|
|
tok2strbuf(af_values, "Unknown",
|
|
|
|
EXTRACT_16BITS(opt+i+2),
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
|
|
|
EXTRACT_16BITS(opt+i+2),
|
|
|
|
tok2strbuf(bgp_safi_values, "Unknown",
|
|
|
|
opt[i+5],
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
|
|
|
opt[i+5]);
|
|
|
|
break;
|
|
|
|
case BGP_CAPCODE_RESTART:
|
|
|
|
printf("\n\t\tRestart Flags: [%s], Restart Time %us",
|
|
|
|
((opt[i+2])&0x80) ? "R" : "none",
|
|
|
|
EXTRACT_16BITS(opt+i+2)&0xfff);
|
|
|
|
tcap_len-=2;
|
|
|
|
cap_offset=4;
|
|
|
|
while(tcap_len>=4) {
|
|
|
|
printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
|
|
|
|
tok2strbuf(af_values,"Unknown",
|
|
|
|
EXTRACT_16BITS(opt+i+cap_offset),
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
|
|
|
EXTRACT_16BITS(opt+i+cap_offset),
|
|
|
|
tok2strbuf(bgp_safi_values,"Unknown",
|
|
|
|
opt[i+cap_offset+2],
|
|
|
|
tokbuf2, sizeof(tokbuf2)),
|
|
|
|
opt[i+cap_offset+2],
|
|
|
|
((opt[i+cap_offset+3])&0x80) ? "yes" : "no" );
|
|
|
|
tcap_len-=4;
|
|
|
|
cap_offset+=4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BGP_CAPCODE_RR:
|
|
|
|
case BGP_CAPCODE_RR_CISCO:
|
|
|
|
break;
|
|
|
|
case BGP_CAPCODE_AS_NEW:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the 4 byte AS number encoded.
|
|
|
|
*/
|
|
|
|
if (cap_len == 4) {
|
|
|
|
printf("\n\t\t 4 Byte AS %s",
|
|
|
|
as_printf(astostr, sizeof(astostr),
|
|
|
|
EXTRACT_32BITS(opt + i + 2)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("\n\t\tno decoder for Capability %u",
|
|
|
|
cap_type);
|
|
|
|
if (vflag <= 1)
|
|
|
|
print_unknown_data(&opt[i+2],"\n\t\t",cap_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (vflag > 1 && cap_len > 0) {
|
|
|
|
print_unknown_data(&opt[i+2],"\n\t\t",cap_len);
|
|
|
|
}
|
|
|
|
i += BGP_CAP_HEADER_SIZE + cap_len;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
const u_char *opt;
|
2012-03-03 09:30:32 +08:00
|
|
|
int i;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
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
|
|
|
|
2002-07-14 22:14:50 +08:00
|
|
|
printf("\n\t Version %d, ", bgpo.bgpo_version);
|
2009-01-21 04:40:22 +08:00
|
|
|
printf("my AS %s, ",
|
|
|
|
as_printf(astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas)));
|
2002-07-14 22:14:50 +08:00
|
|
|
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
|
|
|
|
2002-10-05 18:45:27 +08:00
|
|
|
/* some little sanity checking */
|
|
|
|
if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
|
|
|
|
return;
|
|
|
|
|
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) {
|
2012-03-03 09:30:32 +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",
|
2012-03-03 09:30:32 +08:00
|
|
|
tok2strbuf(bgp_opt_values,"Unknown",
|
2004-04-29 10:16:01 +08:00
|
|
|
bgpopt.bgpopt_type,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2012-03-03 09:30:32 +08:00
|
|
|
bgpopt.bgpopt_type,
|
|
|
|
bgpopt.bgpopt_len);
|
|
|
|
|
|
|
|
/* now let's decode the options we know*/
|
|
|
|
switch(bgpopt.bgpopt_type) {
|
2002-07-14 22:14:50 +08:00
|
|
|
|
2012-03-03 09:30:32 +08:00
|
|
|
case BGP_OPT_CAP:
|
|
|
|
bgp_capabilities_print(&opt[i+BGP_OPT_SIZE],
|
|
|
|
bgpopt.bgpopt_len);
|
|
|
|
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;
|
|
|
|
const u_char *p;
|
|
|
|
int len;
|
1999-12-15 15:43:44 +08:00
|
|
|
int i;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
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
|
|
|
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];
|
2002-12-15 16:33:23 +08:00
|
|
|
int wpfx;
|
2000-12-04 08:43:39 +08:00
|
|
|
|
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) {
|
2002-12-15 16:33:23 +08:00
|
|
|
wpfx = decode_prefix4(&p[i], buf, sizeof(buf));
|
2004-03-24 08:01:00 +08:00
|
|
|
if (wpfx == -1) {
|
2002-12-15 16:33:23 +08:00
|
|
|
printf("\n\t (illegal prefix length)");
|
|
|
|
break;
|
2004-03-24 08:01:00 +08:00
|
|
|
} else if (wpfx == -2)
|
|
|
|
goto trunc;
|
|
|
|
else {
|
|
|
|
i += wpfx;
|
|
|
|
printf("\n\t %s", buf);
|
2002-12-15 16:33:23 +08:00
|
|
|
}
|
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);
|
2004-06-22 23:04:51 +08:00
|
|
|
|
|
|
|
if (len == 0 && length == BGP_UPDATE_MINSIZE) {
|
|
|
|
printf("\n\t End-of-Rib Marker (empty NLRI)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_attr_values, "Unknown Attribute",
|
|
|
|
bgpa.bgpa_type,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-18 08:39:12 +08:00
|
|
|
bgpa.bgpa_type,
|
|
|
|
alen);
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (bgpa.bgpa_flags) {
|
2003-06-17 21:12:59 +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
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
if (!bgp_attr_print(&bgpa, &p[i + aoff], alen))
|
|
|
|
goto trunc;
|
1999-10-30 13:11:06 +08:00
|
|
|
i += aoff + alen;
|
|
|
|
}
|
2004-06-22 23:04:51 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
p += 2 + len;
|
|
|
|
|
1999-12-22 14:27:19 +08:00
|
|
|
if (dat + length > p) {
|
2005-05-06 06:49:17 +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));
|
2005-05-06 06:49:17 +08:00
|
|
|
if (i == -1) {
|
2004-03-24 08:01:00 +08:00
|
|
|
printf("\n\t (illegal prefix length)");
|
2005-05-06 06:49:17 +08:00
|
|
|
break;
|
|
|
|
} else if (i == -2)
|
2004-03-24 08:01:00 +08:00
|
|
|
goto trunc;
|
|
|
|
else {
|
2002-12-15 16:33:23 +08:00
|
|
|
printf("\n\t %s", buf);
|
|
|
|
p += i;
|
|
|
|
}
|
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_notification_print(const u_char *dat, int length)
|
|
|
|
{
|
|
|
|
struct bgp_notification bgpn;
|
2003-06-17 21:12:59 +08:00
|
|
|
const u_char *tptr;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
|
|
|
char tokbuf2[TOKBUFSIZE];
|
1999-10-30 13:11:06 +08:00
|
|
|
|
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
|
|
|
|
2002-10-05 18:45:27 +08:00
|
|
|
/* some little sanity checking */
|
|
|
|
if (length<BGP_NOTIFICATION_SIZE)
|
|
|
|
return;
|
|
|
|
|
2003-05-30 19:09:39 +08:00
|
|
|
printf(", %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_major_values, "Unknown Error",
|
|
|
|
bgpn.bgpn_major, tokbuf, sizeof(tokbuf)),
|
2003-05-30 19:09:39 +08:00
|
|
|
bgpn.bgpn_major);
|
2002-07-04 17:24:43 +08:00
|
|
|
|
|
|
|
switch (bgpn.bgpn_major) {
|
|
|
|
|
|
|
|
case BGP_NOTIFY_MAJOR_MSG:
|
2003-05-30 19:09:39 +08:00
|
|
|
printf(", subcode %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_minor_msg_values, "Unknown",
|
|
|
|
bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
|
2003-05-27 21:09:02 +08:00
|
|
|
bgpn.bgpn_minor);
|
2002-07-04 17:24:43 +08:00
|
|
|
break;
|
|
|
|
case BGP_NOTIFY_MAJOR_OPEN:
|
2003-05-30 19:09:39 +08:00
|
|
|
printf(", subcode %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_minor_open_values, "Unknown",
|
|
|
|
bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
|
2003-05-27 21:09:02 +08:00
|
|
|
bgpn.bgpn_minor);
|
2002-07-04 17:24:43 +08:00
|
|
|
break;
|
|
|
|
case BGP_NOTIFY_MAJOR_UPDATE:
|
2003-05-30 19:09:39 +08:00
|
|
|
printf(", subcode %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_minor_update_values, "Unknown",
|
|
|
|
bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
|
2003-05-27 21:09:02 +08:00
|
|
|
bgpn.bgpn_minor);
|
2002-07-04 17:24:43 +08:00
|
|
|
break;
|
2003-05-27 22:34:04 +08:00
|
|
|
case BGP_NOTIFY_MAJOR_CAP:
|
|
|
|
printf(" subcode %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_minor_cap_values, "Unknown",
|
|
|
|
bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
|
2003-05-27 22:34:04 +08:00
|
|
|
bgpn.bgpn_minor);
|
2003-05-27 20:43:37 +08:00
|
|
|
case BGP_NOTIFY_MAJOR_CEASE:
|
2003-05-30 19:09:39 +08:00
|
|
|
printf(", subcode %s (%u)",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_notify_minor_cease_values, "Unknown",
|
|
|
|
bgpn.bgpn_minor, tokbuf, sizeof(tokbuf)),
|
2003-05-27 21:09:02 +08:00
|
|
|
bgpn.bgpn_minor);
|
|
|
|
|
|
|
|
/* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
|
|
|
|
* for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
|
|
|
|
*/
|
2003-06-04 06:15:58 +08:00
|
|
|
if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
|
2003-06-17 21:12:59 +08:00
|
|
|
tptr = dat + BGP_NOTIFICATION_SIZE;
|
|
|
|
TCHECK2(*tptr, 7);
|
2003-05-27 21:09:02 +08:00
|
|
|
printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
|
2006-02-21 18:27:40 +08:00
|
|
|
tok2strbuf(af_values, "Unknown",
|
2004-04-29 10:16:01 +08:00
|
|
|
EXTRACT_16BITS(tptr), tokbuf, sizeof(tokbuf)),
|
2003-06-17 21:12:59 +08:00
|
|
|
EXTRACT_16BITS(tptr),
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_safi_values, "Unknown", *(tptr+2),
|
|
|
|
tokbuf2, sizeof(tokbuf)),
|
2003-06-17 21:12:59 +08:00
|
|
|
*(tptr+2),
|
|
|
|
EXTRACT_32BITS(tptr+3));
|
2003-06-04 06:15:58 +08:00
|
|
|
}
|
2003-05-27 20:43:37 +08:00
|
|
|
break;
|
2002-07-04 17:24:43 +08:00
|
|
|
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;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
|
|
|
char tokbuf2[TOKBUFSIZE];
|
|
|
|
|
2005-05-06 06:49:17 +08:00
|
|
|
TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
|
|
|
|
|
|
|
|
/* some little sanity checking */
|
|
|
|
if (len<BGP_ROUTE_REFRESH_SIZE)
|
|
|
|
return;
|
|
|
|
|
2002-07-24 08:10:46 +08:00
|
|
|
bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
|
|
|
|
|
|
|
|
printf("\n\t AFI %s (%u), SAFI %s (%u)",
|
2006-02-21 18:27:40 +08:00
|
|
|
tok2strbuf(af_values,"Unknown",
|
2004-04-29 10:16:01 +08:00
|
|
|
/* this stinks but the compiler pads the structure
|
|
|
|
* weird */
|
|
|
|
EXTRACT_16BITS(&bgp_route_refresh_header->afi),
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-24 08:10:46 +08:00
|
|
|
EXTRACT_16BITS(&bgp_route_refresh_header->afi),
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_safi_values,"Unknown",
|
|
|
|
bgp_route_refresh_header->safi,
|
|
|
|
tokbuf2, sizeof(tokbuf2)),
|
2002-07-24 08:10:46 +08:00
|
|
|
bgp_route_refresh_header->safi);
|
|
|
|
|
2005-05-06 06:49:17 +08:00
|
|
|
if (vflag > 1) {
|
|
|
|
TCHECK2(*pptr, len);
|
2002-07-24 08:10:46 +08:00
|
|
|
print_unknown_data(pptr,"\n\t ", len);
|
2005-05-06 06:49:17 +08:00
|
|
|
}
|
2002-07-24 08:10:46 +08:00
|
|
|
|
|
|
|
return;
|
2005-05-06 06:49:17 +08:00
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
2002-07-24 08:10:46 +08:00
|
|
|
}
|
|
|
|
|
2004-03-24 08:01:00 +08:00
|
|
|
static int
|
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;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
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);
|
2002-08-20 08:23:59 +08:00
|
|
|
printf("\n\t%s Message (%u), length: %u",
|
2004-04-29 10:16:01 +08:00
|
|
|
tok2strbuf(bgp_msg_values, "Unknown", bgp.bgp_type,
|
|
|
|
tokbuf, sizeof(tokbuf)),
|
2002-07-18 08:39:12 +08:00
|
|
|
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:
|
2005-05-06 06:49:17 +08:00
|
|
|
/* we have no decoder for the BGP message */
|
|
|
|
TCHECK2(*dat, length);
|
|
|
|
printf("\n\t no Message %u decoder",bgp.bgp_type);
|
|
|
|
print_unknown_data(dat,"\n\t ",length);
|
2002-07-18 08:39:12 +08:00
|
|
|
break;
|
1999-10-30 13:11:06 +08:00
|
|
|
}
|
2004-03-24 08:01:00 +08:00
|
|
|
return 1;
|
2000-12-04 08:43:39 +08:00
|
|
|
trunc:
|
|
|
|
printf("[|BGP]");
|
2004-03-24 08:01:00 +08:00
|
|
|
return 0;
|
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;
|
2004-04-29 10:16:01 +08:00
|
|
|
char tokbuf[TOKBUFSIZE];
|
1999-10-30 13:11:06 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2002-10-05 18:45:27 +08:00
|
|
|
if (vflag < 1) /* lets be less chatty */
|
|
|
|
return;
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
p = dat;
|
1999-11-11 10:28:03 +08:00
|
|
|
start = p;
|
2005-04-21 04:45:34 +08:00
|
|
|
while (p < ep) {
|
1999-10-30 13:11:06 +08:00
|
|
|
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);
|
2003-06-04 07:23:50 +08:00
|
|
|
if (hlen < BGP_SIZE) {
|
|
|
|
printf("\n[|BGP Bogus header length %u < %u]", hlen,
|
|
|
|
BGP_SIZE);
|
|
|
|
break;
|
|
|
|
}
|
2002-07-14 22:14:50 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
if (TTEST2(p[0], hlen)) {
|
2004-03-24 08:01:00 +08:00
|
|
|
if (!bgp_header_print(p, hlen))
|
|
|
|
return;
|
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 {
|
2004-04-29 10:16:01 +08:00
|
|
|
printf("\n[|BGP %s]",
|
|
|
|
tok2strbuf(bgp_msg_values,
|
|
|
|
"Unknown Message Type",
|
|
|
|
bgp.bgp_type,
|
|
|
|
tokbuf, sizeof(tokbuf)));
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
printf(" [|BGP]");
|
|
|
|
}
|
2007-07-24 21:16:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|