2002-12-13 21:15:29 +01:00
|
|
|
/* BGP attributes management routines.
|
2017-05-13 10:25:29 +02:00
|
|
|
* Copyright (C) 1996, 97, 98, 1999 Kunihiro Ishiguro
|
|
|
|
*
|
|
|
|
* This file is part of GNU Zebra.
|
|
|
|
*
|
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "vector.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "hash.h"
|
2010-08-27 23:12:54 +02:00
|
|
|
#include "jhash.h"
|
2015-05-20 03:03:47 +02:00
|
|
|
#include "queue.h"
|
2016-01-12 19:42:01 +01:00
|
|
|
#include "table.h"
|
2016-01-07 16:03:01 +01:00
|
|
|
#include "filter.h"
|
2016-09-22 17:15:50 +02:00
|
|
|
#include "command.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#include "bgpd/bgpd.h"
|
|
|
|
#include "bgpd/bgp_attr.h"
|
|
|
|
#include "bgpd/bgp_route.h"
|
|
|
|
#include "bgpd/bgp_aspath.h"
|
|
|
|
#include "bgpd/bgp_community.h"
|
|
|
|
#include "bgpd/bgp_debug.h"
|
2018-06-15 23:08:53 +02:00
|
|
|
#include "bgpd/bgp_errors.h"
|
2017-06-16 21:12:57 +02:00
|
|
|
#include "bgpd/bgp_label.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "bgpd/bgp_packet.h"
|
|
|
|
#include "bgpd/bgp_ecommunity.h"
|
2016-11-15 11:00:39 +01:00
|
|
|
#include "bgpd/bgp_lcommunity.h"
|
2015-05-20 03:03:47 +02:00
|
|
|
#include "bgpd/bgp_updgrp.h"
|
2016-06-11 20:36:42 +02:00
|
|
|
#include "bgpd/bgp_encap_types.h"
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
#include "bgpd/rfapi/bgp_rfapi_cfg.h"
|
|
|
|
#include "bgp_encap_types.h"
|
|
|
|
#include "bgp_vnc_types.h"
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2016-09-05 14:19:40 +02:00
|
|
|
#include "bgp_evpn.h"
|
2017-01-23 03:45:30 +01:00
|
|
|
#include "bgp_flowspec_private.h"
|
2019-02-20 01:02:00 +01:00
|
|
|
#include "bgp_mac.h"
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Attribute strings for logging. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static const struct message attr_str[] = {
|
|
|
|
{BGP_ATTR_ORIGIN, "ORIGIN"},
|
|
|
|
{BGP_ATTR_AS_PATH, "AS_PATH"},
|
|
|
|
{BGP_ATTR_NEXT_HOP, "NEXT_HOP"},
|
|
|
|
{BGP_ATTR_MULTI_EXIT_DISC, "MULTI_EXIT_DISC"},
|
|
|
|
{BGP_ATTR_LOCAL_PREF, "LOCAL_PREF"},
|
|
|
|
{BGP_ATTR_ATOMIC_AGGREGATE, "ATOMIC_AGGREGATE"},
|
|
|
|
{BGP_ATTR_AGGREGATOR, "AGGREGATOR"},
|
|
|
|
{BGP_ATTR_COMMUNITIES, "COMMUNITY"},
|
|
|
|
{BGP_ATTR_ORIGINATOR_ID, "ORIGINATOR_ID"},
|
|
|
|
{BGP_ATTR_CLUSTER_LIST, "CLUSTER_LIST"},
|
|
|
|
{BGP_ATTR_DPA, "DPA"},
|
|
|
|
{BGP_ATTR_ADVERTISER, "ADVERTISER"},
|
|
|
|
{BGP_ATTR_RCID_PATH, "RCID_PATH"},
|
|
|
|
{BGP_ATTR_MP_REACH_NLRI, "MP_REACH_NLRI"},
|
|
|
|
{BGP_ATTR_MP_UNREACH_NLRI, "MP_UNREACH_NLRI"},
|
|
|
|
{BGP_ATTR_EXT_COMMUNITIES, "EXT_COMMUNITIES"},
|
|
|
|
{BGP_ATTR_AS4_PATH, "AS4_PATH"},
|
|
|
|
{BGP_ATTR_AS4_AGGREGATOR, "AS4_AGGREGATOR"},
|
|
|
|
{BGP_ATTR_AS_PATHLIMIT, "AS_PATHLIMIT"},
|
2018-01-04 12:34:24 +01:00
|
|
|
{BGP_ATTR_PMSI_TUNNEL, "PMSI_TUNNEL_ATTRIBUTE"},
|
2017-07-17 14:03:14 +02:00
|
|
|
{BGP_ATTR_ENCAP, "ENCAP"},
|
2019-01-07 17:32:54 +01:00
|
|
|
#if ENABLE_BGP_VNC_ATTR
|
2017-07-17 14:03:14 +02:00
|
|
|
{BGP_ATTR_VNC, "VNC"},
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
{BGP_ATTR_LARGE_COMMUNITIES, "LARGE_COMMUNITY"},
|
|
|
|
{BGP_ATTR_PREFIX_SID, "PREFIX_SID"},
|
|
|
|
{0}};
|
2011-10-23 20:32:44 +02:00
|
|
|
|
2018-03-06 20:02:52 +01:00
|
|
|
static const struct message attr_flag_str[] = {
|
|
|
|
{BGP_ATTR_FLAG_OPTIONAL, "Optional"},
|
|
|
|
{BGP_ATTR_FLAG_TRANS, "Transitive"},
|
|
|
|
{BGP_ATTR_FLAG_PARTIAL, "Partial"},
|
|
|
|
/* bgp_attr_flags_diagnose() relies on this bit being last in
|
|
|
|
this list */
|
|
|
|
{BGP_ATTR_FLAG_EXTLEN, "Extended Length"},
|
|
|
|
{0}};
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2009-05-15 18:59:51 +02:00
|
|
|
static struct hash *cluster_hash;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void *cluster_hash_alloc(void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct cluster_list *val = (const struct cluster_list *)p;
|
|
|
|
struct cluster_list *cluster;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
cluster = XMALLOC(MTYPE_CLUSTER, sizeof(struct cluster_list));
|
|
|
|
cluster->length = val->length;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (cluster->length) {
|
|
|
|
cluster->list = XMALLOC(MTYPE_CLUSTER_VAL, val->length);
|
|
|
|
memcpy(cluster->list, val->list, val->length);
|
|
|
|
} else
|
|
|
|
cluster->list = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
cluster->refcnt = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return cluster;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cluster list related functions. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static struct cluster_list *cluster_parse(struct in_addr *pnt, int length)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct cluster_list tmp;
|
|
|
|
struct cluster_list *cluster;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
tmp.length = length;
|
|
|
|
tmp.list = pnt;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
cluster = hash_get(cluster_hash, &tmp, cluster_hash_alloc);
|
|
|
|
cluster->refcnt++;
|
|
|
|
return cluster;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int cluster_loop_check(struct cluster_list *cluster, struct in_addr originator)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cluster->length / 4; i++)
|
|
|
|
if (cluster->list[i].s_addr == originator.s_addr)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 22:19:07 +02:00
|
|
|
static unsigned int cluster_hash_key_make(const void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct cluster_list *cluster = p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return jhash(cluster->list, cluster->length, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
static bool cluster_hash_cmp(const void *p1, const void *p2)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct cluster_list *cluster1 = p1;
|
|
|
|
const struct cluster_list *cluster2 = p2;
|
[bgpd] Fix warnings: hash callbacks should match hash API declarations
2007-04-22 Sebastien Tandel <sebastien@tandel.be>
* bgp_advertise.c : (baa_hash_alloc, baa_hash_key, baa_hash_cmp)
conforms to quagga hash API. Defines _hash_[alloc|key|cmp] with
void * arguments as defined by the API.
* bgp_aspath.c,h : (aspath_key_make) conforms to quagga hash API.
Defines _hash_[alloc|key|cmp] with void * arguments as defined by
the API.
* bgp_attr.c,h : (cluster_hash_alloc, cluster_hash_key_make,
cluster_hash_cmp, transit_hash_alloc, transit_hash_key_make,
transit_hash_cmp, attrhash_key_make, attrhash_cmp,
bgp_attr_hash_alloc) conforms to quagga hash API. Defines
_hash_[alloc|key|cmp] with void * arguments as defined by the API.
2007-04-29 20:25:17 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return (cluster1->length == cluster2->length
|
|
|
|
&& memcmp(cluster1->list, cluster2->list, cluster1->length)
|
|
|
|
== 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void cluster_free(struct cluster_list *cluster)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_CLUSTER_VAL, cluster->list);
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_CLUSTER, cluster);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static struct cluster_list *cluster_intern(struct cluster_list *cluster)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct cluster_list *find;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
find = hash_get(cluster_hash, cluster, cluster_hash_alloc);
|
|
|
|
find->refcnt++;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return find;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void cluster_unintern(struct cluster_list *cluster)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (cluster->refcnt)
|
|
|
|
cluster->refcnt--;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (cluster->refcnt == 0) {
|
|
|
|
hash_release(cluster_hash, cluster);
|
|
|
|
cluster_free(cluster);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void cluster_init(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-03-06 20:02:52 +01:00
|
|
|
cluster_hash = hash_create(cluster_hash_key_make, cluster_hash_cmp,
|
2017-09-04 00:57:30 +02:00
|
|
|
"BGP Cluster");
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void cluster_finish(void)
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_clean(cluster_hash, (void (*)(void *))cluster_free);
|
|
|
|
hash_free(cluster_hash);
|
|
|
|
cluster_hash = NULL;
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2016-12-17 23:58:33 +01:00
|
|
|
static struct hash *encap_hash = NULL;
|
|
|
|
#if ENABLE_BGP_VNC
|
|
|
|
static struct hash *vnc_hash = NULL;
|
|
|
|
#endif
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct bgp_attr_encap_subtlv *encap_tlv_dup(struct bgp_attr_encap_subtlv *orig)
|
2016-01-12 19:42:01 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct bgp_attr_encap_subtlv *new;
|
|
|
|
struct bgp_attr_encap_subtlv *tail;
|
|
|
|
struct bgp_attr_encap_subtlv *p;
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (p = orig, tail = new = NULL; p; p = p->next) {
|
2017-10-19 00:37:38 +02:00
|
|
|
int size = sizeof(struct bgp_attr_encap_subtlv) + p->length;
|
2017-07-17 14:03:14 +02:00
|
|
|
if (tail) {
|
|
|
|
tail->next = XCALLOC(MTYPE_ENCAP_TLV, size);
|
|
|
|
tail = tail->next;
|
|
|
|
} else {
|
|
|
|
tail = new = XCALLOC(MTYPE_ENCAP_TLV, size);
|
|
|
|
}
|
|
|
|
assert(tail);
|
|
|
|
memcpy(tail, p, size);
|
|
|
|
tail->next = NULL;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return new;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void encap_free(struct bgp_attr_encap_subtlv *p)
|
2016-01-12 19:42:01 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct bgp_attr_encap_subtlv *next;
|
|
|
|
while (p) {
|
|
|
|
next = p->next;
|
|
|
|
p->next = NULL;
|
|
|
|
XFREE(MTYPE_ENCAP_TLV, p);
|
|
|
|
p = next;
|
|
|
|
}
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_flush_encap(struct attr *attr)
|
2016-01-12 19:42:01 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!attr)
|
|
|
|
return;
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->encap_subtlvs) {
|
|
|
|
encap_free(attr->encap_subtlvs);
|
|
|
|
attr->encap_subtlvs = NULL;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs) {
|
|
|
|
encap_free(attr->vnc_subtlvs);
|
|
|
|
attr->vnc_subtlvs = NULL;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare encap sub-tlv chains
|
|
|
|
*
|
|
|
|
* 1 = equivalent
|
|
|
|
* 0 = not equivalent
|
|
|
|
*
|
|
|
|
* This algorithm could be made faster if needed
|
|
|
|
*/
|
2018-09-17 18:22:59 +02:00
|
|
|
static int encap_same(const struct bgp_attr_encap_subtlv *h1,
|
|
|
|
const struct bgp_attr_encap_subtlv *h2)
|
2016-01-12 19:42:01 +01:00
|
|
|
{
|
2018-09-17 18:22:59 +02:00
|
|
|
const struct bgp_attr_encap_subtlv *p;
|
|
|
|
const struct bgp_attr_encap_subtlv *q;
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (h1 == h2)
|
|
|
|
return 1;
|
|
|
|
if (h1 == NULL || h2 == NULL)
|
|
|
|
return 0;
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (p = h1; p; p = p->next) {
|
|
|
|
for (q = h2; q; q = q->next) {
|
|
|
|
if ((p->type == q->type) && (p->length == q->length)
|
|
|
|
&& !memcmp(p->value, q->value, p->length)) {
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!q)
|
|
|
|
return 0;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (p = h2; p; p = p->next) {
|
|
|
|
for (q = h1; q; q = q->next) {
|
|
|
|
if ((p->type == q->type) && (p->length == q->length)
|
|
|
|
&& !memcmp(p->value, q->value, p->length)) {
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!q)
|
|
|
|
return 0;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return 1;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void *encap_hash_alloc(void *p)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Encap structure is already allocated. */
|
|
|
|
return p;
|
2016-12-17 23:58:33 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
typedef enum {
|
|
|
|
ENCAP_SUBTLV_TYPE,
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
VNC_SUBTLV_TYPE
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
|
|
|
} encap_subtlv_type;
|
|
|
|
|
|
|
|
static struct bgp_attr_encap_subtlv *
|
2017-07-17 14:03:14 +02:00
|
|
|
encap_intern(struct bgp_attr_encap_subtlv *encap, encap_subtlv_type type)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct bgp_attr_encap_subtlv *find;
|
|
|
|
struct hash *hash = encap_hash;
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (type == VNC_SUBTLV_TYPE)
|
|
|
|
hash = vnc_hash;
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
find = hash_get(hash, encap, encap_hash_alloc);
|
|
|
|
if (find != encap)
|
|
|
|
encap_free(encap);
|
|
|
|
find->refcnt++;
|
2016-12-17 23:58:33 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return find;
|
2016-12-17 23:58:33 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void encap_unintern(struct bgp_attr_encap_subtlv **encapp,
|
|
|
|
encap_subtlv_type type)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct bgp_attr_encap_subtlv *encap = *encapp;
|
|
|
|
if (encap->refcnt)
|
|
|
|
encap->refcnt--;
|
2016-12-17 23:58:33 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (encap->refcnt == 0) {
|
|
|
|
struct hash *hash = encap_hash;
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (type == VNC_SUBTLV_TYPE)
|
|
|
|
hash = vnc_hash;
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_release(hash, encap);
|
|
|
|
encap_free(encap);
|
|
|
|
*encapp = NULL;
|
|
|
|
}
|
2016-12-17 23:58:33 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 22:19:07 +02:00
|
|
|
static unsigned int encap_hash_key_make(const void *p)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct bgp_attr_encap_subtlv *encap = p;
|
2016-12-17 23:58:33 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return jhash(encap->value, encap->length, 0);
|
2016-12-17 23:58:33 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
static bool encap_hash_cmp(const void *p1, const void *p2)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2018-09-17 18:22:59 +02:00
|
|
|
return encap_same((const struct bgp_attr_encap_subtlv *)p1,
|
|
|
|
(const struct bgp_attr_encap_subtlv *)p2);
|
2016-12-17 23:58:33 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void encap_init(void)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2018-03-06 20:02:52 +01:00
|
|
|
encap_hash = hash_create(encap_hash_key_make, encap_hash_cmp,
|
2017-09-04 00:57:30 +02:00
|
|
|
"BGP Encap Hash");
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2018-03-06 20:02:52 +01:00
|
|
|
vnc_hash = hash_create(encap_hash_key_make, encap_hash_cmp,
|
2017-09-04 00:57:30 +02:00
|
|
|
"BGP VNC Hash");
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void encap_finish(void)
|
2016-12-17 23:58:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_clean(encap_hash, (void (*)(void *))encap_free);
|
|
|
|
hash_free(encap_hash);
|
|
|
|
encap_hash = NULL;
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_clean(vnc_hash, (void (*)(void *))encap_free);
|
|
|
|
hash_free(vnc_hash);
|
|
|
|
vnc_hash = NULL;
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static bool overlay_index_same(const struct attr *a1, const struct attr *a2)
|
2016-09-05 14:07:01 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!a1 && a2)
|
|
|
|
return false;
|
|
|
|
if (!a2 && a1)
|
|
|
|
return false;
|
|
|
|
if (!a1 && !a2)
|
|
|
|
return true;
|
|
|
|
return !memcmp(&(a1->evpn_overlay), &(a2->evpn_overlay),
|
2018-10-30 14:05:27 +01:00
|
|
|
sizeof(struct bgp_route_evpn));
|
2016-09-05 14:07:01 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Unknown transit attribute. */
|
2009-05-15 18:59:51 +02:00
|
|
|
static struct hash *transit_hash;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void transit_free(struct transit *transit)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_TRANSIT_VAL, transit->val);
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_TRANSIT, transit);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void *transit_hash_alloc(void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Transit structure is already allocated. */
|
|
|
|
return p;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static struct transit *transit_intern(struct transit *transit)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct transit *find;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
find = hash_get(transit_hash, transit, transit_hash_alloc);
|
|
|
|
if (find != transit)
|
|
|
|
transit_free(transit);
|
|
|
|
find->refcnt++;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return find;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void transit_unintern(struct transit *transit)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (transit->refcnt)
|
|
|
|
transit->refcnt--;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (transit->refcnt == 0) {
|
|
|
|
hash_release(transit_hash, transit);
|
|
|
|
transit_free(transit);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 22:19:07 +02:00
|
|
|
static unsigned int transit_hash_key_make(const void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct transit *transit = p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return jhash(transit->val, transit->length, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
static bool transit_hash_cmp(const void *p1, const void *p2)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct transit *transit1 = p1;
|
|
|
|
const struct transit *transit2 = p2;
|
[bgpd] Fix warnings: hash callbacks should match hash API declarations
2007-04-22 Sebastien Tandel <sebastien@tandel.be>
* bgp_advertise.c : (baa_hash_alloc, baa_hash_key, baa_hash_cmp)
conforms to quagga hash API. Defines _hash_[alloc|key|cmp] with
void * arguments as defined by the API.
* bgp_aspath.c,h : (aspath_key_make) conforms to quagga hash API.
Defines _hash_[alloc|key|cmp] with void * arguments as defined by
the API.
* bgp_attr.c,h : (cluster_hash_alloc, cluster_hash_key_make,
cluster_hash_cmp, transit_hash_alloc, transit_hash_key_make,
transit_hash_cmp, attrhash_key_make, attrhash_cmp,
bgp_attr_hash_alloc) conforms to quagga hash API. Defines
_hash_[alloc|key|cmp] with void * arguments as defined by the API.
2007-04-29 20:25:17 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return (transit1->length == transit2->length
|
|
|
|
&& memcmp(transit1->val, transit2->val, transit1->length) == 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void transit_init(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-03-06 20:02:52 +01:00
|
|
|
transit_hash = hash_create(transit_hash_key_make, transit_hash_cmp,
|
2017-09-04 00:57:30 +02:00
|
|
|
"BGP Transit Hash");
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void transit_finish(void)
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_clean(transit_hash, (void (*)(void *))transit_free);
|
|
|
|
hash_free(transit_hash);
|
|
|
|
transit_hash = NULL;
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Attribute hash routines. */
|
2009-05-15 18:59:51 +02:00
|
|
|
static struct hash *attrhash;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2007-05-04 22:15:47 +02:00
|
|
|
/* Shallow copy of an attribute
|
|
|
|
* Though, not so shallow that it doesn't copy the contents
|
|
|
|
* of the attr_extra pointed to by 'extra'
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_dup(struct attr *new, struct attr *orig)
|
2007-05-04 22:15:47 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
*new = *orig;
|
2007-05-04 22:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
unsigned long int attr_count(void)
|
2006-03-30 15:20:48 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return attrhash->count;
|
2006-03-30 15:20:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
unsigned long int attr_unknown_count(void)
|
2006-03-30 15:20:48 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return transit_hash->count;
|
2006-03-30 15:20:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 22:19:07 +02:00
|
|
|
unsigned int attrhash_key_make(const void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const struct attr *attr = (struct attr *)p;
|
|
|
|
uint32_t key = 0;
|
2010-08-27 23:12:54 +02:00
|
|
|
#define MIX(val) key = jhash_1word(val, key)
|
2017-12-12 14:26:20 +01:00
|
|
|
#define MIX3(a, b, c) key = jhash_3words((a), (b), (c), key)
|
2010-08-27 23:12:54 +02:00
|
|
|
|
2017-12-12 14:26:20 +01:00
|
|
|
MIX3(attr->origin, attr->nexthop.s_addr, attr->med);
|
2018-03-06 20:02:52 +01:00
|
|
|
MIX3(attr->local_pref, attr->aggregator_as,
|
|
|
|
attr->aggregator_addr.s_addr);
|
2017-12-12 14:26:20 +01:00
|
|
|
MIX3(attr->weight, attr->mp_nexthop_global_in.s_addr,
|
|
|
|
attr->originator_id.s_addr);
|
|
|
|
MIX3(attr->tag, attr->label, attr->label_index);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (attr->aspath)
|
|
|
|
MIX(aspath_key_make(attr->aspath));
|
|
|
|
if (attr->community)
|
|
|
|
MIX(community_hash_make(attr->community));
|
|
|
|
|
|
|
|
if (attr->lcommunity)
|
|
|
|
MIX(lcommunity_hash_make(attr->lcommunity));
|
|
|
|
if (attr->ecommunity)
|
|
|
|
MIX(ecommunity_hash_make(attr->ecommunity));
|
|
|
|
if (attr->cluster)
|
|
|
|
MIX(cluster_hash_key_make(attr->cluster));
|
|
|
|
if (attr->transit)
|
|
|
|
MIX(transit_hash_key_make(attr->transit));
|
|
|
|
if (attr->encap_subtlvs)
|
|
|
|
MIX(encap_hash_key_make(attr->encap_subtlvs));
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs)
|
|
|
|
MIX(encap_hash_key_make(attr->vnc_subtlvs));
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
MIX(attr->mp_nexthop_len);
|
|
|
|
key = jhash(attr->mp_nexthop_global.s6_addr, IPV6_MAX_BYTELEN, key);
|
|
|
|
key = jhash(attr->mp_nexthop_local.s6_addr, IPV6_MAX_BYTELEN, key);
|
2018-04-05 19:42:27 +02:00
|
|
|
MIX(attr->nh_ifindex);
|
|
|
|
MIX(attr->nh_lla_ifindex);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
bool attrhash_cmp(const void *p1, const void *p2)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
const struct attr *attr1 = p1;
|
|
|
|
const struct attr *attr2 = p2;
|
|
|
|
|
|
|
|
if (attr1->flag == attr2->flag && attr1->origin == attr2->origin
|
|
|
|
&& attr1->nexthop.s_addr == attr2->nexthop.s_addr
|
|
|
|
&& attr1->aspath == attr2->aspath
|
|
|
|
&& attr1->community == attr2->community && attr1->med == attr2->med
|
|
|
|
&& attr1->local_pref == attr2->local_pref
|
|
|
|
&& attr1->rmap_change_flags == attr2->rmap_change_flags) {
|
|
|
|
if (attr1->aggregator_as == attr2->aggregator_as
|
|
|
|
&& attr1->aggregator_addr.s_addr
|
|
|
|
== attr2->aggregator_addr.s_addr
|
|
|
|
&& attr1->weight == attr2->weight
|
|
|
|
&& attr1->tag == attr2->tag
|
|
|
|
&& attr1->label_index == attr2->label_index
|
|
|
|
&& attr1->mp_nexthop_len == attr2->mp_nexthop_len
|
|
|
|
&& attr1->ecommunity == attr2->ecommunity
|
|
|
|
&& attr1->lcommunity == attr2->lcommunity
|
|
|
|
&& attr1->cluster == attr2->cluster
|
|
|
|
&& attr1->transit == attr2->transit
|
|
|
|
&& (attr1->encap_tunneltype == attr2->encap_tunneltype)
|
|
|
|
&& encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs)
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
&& encap_same(attr1->vnc_subtlvs, attr2->vnc_subtlvs)
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-12-12 14:26:20 +01:00
|
|
|
&& IPV6_ADDR_SAME(&attr1->mp_nexthop_global,
|
|
|
|
&attr2->mp_nexthop_global)
|
|
|
|
&& IPV6_ADDR_SAME(&attr1->mp_nexthop_local,
|
|
|
|
&attr2->mp_nexthop_local)
|
|
|
|
&& IPV4_ADDR_SAME(&attr1->mp_nexthop_global_in,
|
|
|
|
&attr2->mp_nexthop_global_in)
|
2017-07-17 14:03:14 +02:00
|
|
|
&& IPV4_ADDR_SAME(&attr1->originator_id,
|
|
|
|
&attr2->originator_id)
|
2018-04-05 19:42:27 +02:00
|
|
|
&& overlay_index_same(attr1, attr2)
|
|
|
|
&& attr1->nh_ifindex == attr2->nh_ifindex
|
|
|
|
&& attr1->nh_lla_ifindex == attr2->nh_lla_ifindex)
|
2018-10-17 21:27:12 +02:00
|
|
|
return true;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2017-06-06 19:20:38 +02:00
|
|
|
|
2018-10-17 21:27:12 +02:00
|
|
|
return false;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void attrhash_init(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-03-06 20:02:52 +01:00
|
|
|
attrhash =
|
|
|
|
hash_create(attrhash_key_make, attrhash_cmp, "BGP Attributes");
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2013-04-10 21:30:04 +02:00
|
|
|
/*
|
|
|
|
* special for hash_clean below
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
static void attr_vfree(void *attr)
|
2013-04-10 21:30:04 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_ATTR, attr);
|
2013-04-10 21:30:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void attrhash_finish(void)
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
hash_clean(attrhash, attr_vfree);
|
|
|
|
hash_free(attrhash);
|
|
|
|
attrhash = NULL;
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:46:52 +01:00
|
|
|
static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-02-19 16:46:52 +01:00
|
|
|
struct attr *attr = bucket->data;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
vty_out(vty, "attr[%ld] nexthop %s\n", attr->refcnt,
|
|
|
|
inet_ntoa(attr->nexthop));
|
2018-04-25 16:23:22 +02:00
|
|
|
vty_out(vty, "\tflags: %" PRIu64 " med: %u local_pref: %u origin: %u weight: %u label: %u\n",
|
2018-04-23 21:24:26 +02:00
|
|
|
attr->flag, attr->med, attr->local_pref, attr->origin,
|
2018-04-25 16:23:22 +02:00
|
|
|
attr->weight, attr->label);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void attr_show_all(struct vty *vty)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-02-19 16:46:52 +01:00
|
|
|
hash_iterate(attrhash, (void (*)(struct hash_bucket *,
|
2017-07-22 14:52:33 +02:00
|
|
|
void *))attr_show_all_iterator,
|
|
|
|
vty);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static void *bgp_attr_hash_alloc(void *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct attr *val = (struct attr *)p;
|
|
|
|
struct attr *attr;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr = XMALLOC(MTYPE_ATTR, sizeof(struct attr));
|
|
|
|
*attr = *val;
|
|
|
|
if (val->encap_subtlvs) {
|
|
|
|
val->encap_subtlvs = NULL;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (val->vnc_subtlvs) {
|
|
|
|
val->vnc_subtlvs = NULL;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->refcnt = 0;
|
|
|
|
return attr;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Internet argument attribute. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct attr *bgp_attr_intern(struct attr *attr)
|
|
|
|
{
|
|
|
|
struct attr *find;
|
|
|
|
|
|
|
|
/* Intern referenced strucutre. */
|
|
|
|
if (attr->aspath) {
|
|
|
|
if (!attr->aspath->refcnt)
|
|
|
|
attr->aspath = aspath_intern(attr->aspath);
|
|
|
|
else
|
|
|
|
attr->aspath->refcnt++;
|
|
|
|
}
|
|
|
|
if (attr->community) {
|
|
|
|
if (!attr->community->refcnt)
|
|
|
|
attr->community = community_intern(attr->community);
|
|
|
|
else
|
|
|
|
attr->community->refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr->ecommunity) {
|
|
|
|
if (!attr->ecommunity->refcnt)
|
|
|
|
attr->ecommunity = ecommunity_intern(attr->ecommunity);
|
|
|
|
else
|
|
|
|
attr->ecommunity->refcnt++;
|
|
|
|
}
|
|
|
|
if (attr->lcommunity) {
|
|
|
|
if (!attr->lcommunity->refcnt)
|
|
|
|
attr->lcommunity = lcommunity_intern(attr->lcommunity);
|
|
|
|
else
|
|
|
|
attr->lcommunity->refcnt++;
|
|
|
|
}
|
|
|
|
if (attr->cluster) {
|
|
|
|
if (!attr->cluster->refcnt)
|
|
|
|
attr->cluster = cluster_intern(attr->cluster);
|
|
|
|
else
|
|
|
|
attr->cluster->refcnt++;
|
|
|
|
}
|
|
|
|
if (attr->transit) {
|
|
|
|
if (!attr->transit->refcnt)
|
|
|
|
attr->transit = transit_intern(attr->transit);
|
|
|
|
else
|
|
|
|
attr->transit->refcnt++;
|
|
|
|
}
|
|
|
|
if (attr->encap_subtlvs) {
|
|
|
|
if (!attr->encap_subtlvs->refcnt)
|
|
|
|
attr->encap_subtlvs = encap_intern(attr->encap_subtlvs,
|
|
|
|
ENCAP_SUBTLV_TYPE);
|
|
|
|
else
|
|
|
|
attr->encap_subtlvs->refcnt++;
|
|
|
|
}
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs) {
|
|
|
|
if (!attr->vnc_subtlvs->refcnt)
|
|
|
|
attr->vnc_subtlvs = encap_intern(attr->vnc_subtlvs,
|
|
|
|
VNC_SUBTLV_TYPE);
|
|
|
|
else
|
|
|
|
attr->vnc_subtlvs->refcnt++;
|
|
|
|
}
|
2017-06-06 19:20:38 +02:00
|
|
|
#endif
|
2016-12-17 23:58:33 +01:00
|
|
|
|
2017-09-07 15:27:12 +02:00
|
|
|
/* At this point, attr only contains intern'd pointers. that means
|
|
|
|
* if we find it in attrhash, it has all the same pointers and we
|
|
|
|
* correctly updated the refcounts on these.
|
|
|
|
* If we don't find it, we need to allocate a one because in all
|
|
|
|
* cases this returns a new reference to a hashed attr, but the input
|
|
|
|
* wasn't on hash. */
|
2017-07-17 14:03:14 +02:00
|
|
|
find = (struct attr *)hash_get(attrhash, attr, bgp_attr_hash_alloc);
|
|
|
|
find->refcnt++;
|
|
|
|
|
|
|
|
return find;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make network statement's attribute. */
|
2018-03-27 21:13:34 +02:00
|
|
|
struct attr *bgp_attr_default_set(struct attr *attr, uint8_t origin)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
memset(attr, 0, sizeof(struct attr));
|
2007-04-29 20:31:07 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->origin = origin;
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGIN);
|
|
|
|
attr->aspath = aspath_empty();
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS_PATH);
|
|
|
|
attr->weight = BGP_ATTR_DEFAULT_WEIGHT;
|
|
|
|
attr->tag = 0;
|
|
|
|
attr->label_index = BGP_INVALID_LABEL_INDEX;
|
|
|
|
attr->label = MPLS_INVALID_LABEL;
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
|
|
|
|
attr->mp_nexthop_len = IPV6_MAX_BYTELEN;
|
|
|
|
|
|
|
|
return attr;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:47:24 +02:00
|
|
|
/* Create the attributes for an aggregate */
|
2018-03-27 21:13:34 +02:00
|
|
|
struct attr *bgp_attr_aggregate_intern(struct bgp *bgp, uint8_t origin,
|
2017-07-17 14:03:14 +02:00
|
|
|
struct aspath *aspath,
|
2018-10-16 14:13:03 +02:00
|
|
|
struct community *community,
|
|
|
|
struct ecommunity *ecommunity,
|
2018-10-16 14:24:01 +02:00
|
|
|
struct lcommunity *lcommunity,
|
2018-10-16 14:13:03 +02:00
|
|
|
int as_set, uint8_t atomic_aggregate)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
struct attr attr;
|
|
|
|
struct attr *new;
|
|
|
|
|
|
|
|
memset(&attr, 0, sizeof(struct attr));
|
|
|
|
|
|
|
|
/* Origin attribute. */
|
|
|
|
attr.origin = origin;
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGIN);
|
|
|
|
|
|
|
|
/* AS path attribute. */
|
|
|
|
if (aspath)
|
|
|
|
attr.aspath = aspath_intern(aspath);
|
|
|
|
else
|
|
|
|
attr.aspath = aspath_empty();
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_AS_PATH);
|
|
|
|
|
|
|
|
/* Next hop attribute. */
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
|
|
|
|
|
|
|
|
if (community) {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t gshut = COMMUNITY_GSHUT;
|
2017-08-25 20:27:49 +02:00
|
|
|
|
|
|
|
/* If we are not shutting down ourselves and we are
|
|
|
|
* aggregating a route that contains the GSHUT community we
|
|
|
|
* need to remove that community when creating the aggregate */
|
2018-03-06 20:02:52 +01:00
|
|
|
if (!bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)
|
|
|
|
&& community_include(community, gshut)) {
|
2017-08-25 20:27:49 +02:00
|
|
|
community_del_val(community, &gshut);
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr.community = community;
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:13:03 +02:00
|
|
|
if (ecommunity) {
|
|
|
|
attr.ecommunity = ecommunity;
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
}
|
|
|
|
|
2018-10-16 14:24:01 +02:00
|
|
|
if (lcommunity) {
|
|
|
|
attr.lcommunity = lcommunity;
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
|
|
|
|
}
|
|
|
|
|
2017-08-25 20:27:49 +02:00
|
|
|
if (bgp_flag_check(bgp, BGP_FLAG_GRACEFUL_SHUTDOWN)) {
|
|
|
|
bgp_attr_add_gshut_community(&attr);
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr.label_index = BGP_INVALID_LABEL_INDEX;
|
|
|
|
attr.label = MPLS_INVALID_LABEL;
|
|
|
|
attr.weight = BGP_ATTR_DEFAULT_WEIGHT;
|
|
|
|
attr.mp_nexthop_len = IPV6_MAX_BYTELEN;
|
|
|
|
if (!as_set || atomic_aggregate)
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE);
|
|
|
|
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR);
|
|
|
|
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
|
|
|
|
attr.aggregator_as = bgp->confed_id;
|
|
|
|
else
|
|
|
|
attr.aggregator_as = bgp->as;
|
|
|
|
attr.aggregator_addr = bgp->router_id;
|
|
|
|
attr.label_index = BGP_INVALID_LABEL_INDEX;
|
|
|
|
attr.label = MPLS_INVALID_LABEL;
|
|
|
|
|
|
|
|
new = bgp_attr_intern(&attr);
|
|
|
|
|
|
|
|
aspath_unintern(&new->aspath);
|
|
|
|
return new;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
/* Unintern just the sub-components of the attr, but not the attr */
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_unintern_sub(struct attr *attr)
|
|
|
|
{
|
|
|
|
/* aspath refcount shoud be decrement. */
|
|
|
|
if (attr->aspath)
|
|
|
|
aspath_unintern(&attr->aspath);
|
|
|
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH));
|
|
|
|
|
|
|
|
if (attr->community)
|
|
|
|
community_unintern(&attr->community);
|
|
|
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
|
|
|
|
|
|
|
|
if (attr->ecommunity)
|
|
|
|
ecommunity_unintern(&attr->ecommunity);
|
|
|
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
|
|
|
|
|
|
|
|
if (attr->lcommunity)
|
|
|
|
lcommunity_unintern(&attr->lcommunity);
|
|
|
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
|
|
|
|
|
|
|
|
if (attr->cluster)
|
|
|
|
cluster_unintern(attr->cluster);
|
|
|
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
|
|
|
|
|
|
|
|
if (attr->transit)
|
|
|
|
transit_unintern(attr->transit);
|
|
|
|
|
|
|
|
if (attr->encap_subtlvs)
|
|
|
|
encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE);
|
2016-12-17 23:58:33 +01:00
|
|
|
|
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs)
|
|
|
|
encap_unintern(&attr->vnc_subtlvs, VNC_SUBTLV_TYPE);
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
}
|
|
|
|
|
2017-10-25 02:57:00 +02:00
|
|
|
/*
|
|
|
|
* We have some show commands that let you experimentally
|
|
|
|
* apply a route-map. When we apply the route-map
|
|
|
|
* we are reseting values but not saving them for
|
|
|
|
* posterity via intern'ing( because route-maps don't
|
|
|
|
* do that) but at this point in time we need
|
|
|
|
* to compare the new attr to the old and if the
|
|
|
|
* routemap has changed it we need to, as Snoop Dog says,
|
|
|
|
* Drop it like it's hot
|
|
|
|
*/
|
|
|
|
void bgp_attr_undup(struct attr *new, struct attr *old)
|
|
|
|
{
|
|
|
|
if (new->aspath != old->aspath)
|
|
|
|
aspath_free(new->aspath);
|
|
|
|
|
|
|
|
if (new->community != old->community)
|
2018-10-22 21:58:39 +02:00
|
|
|
community_free(&new->community);
|
2017-10-25 02:57:00 +02:00
|
|
|
|
|
|
|
if (new->ecommunity != old->ecommunity)
|
|
|
|
ecommunity_free(&new->ecommunity);
|
|
|
|
|
|
|
|
if (new->lcommunity != old->lcommunity)
|
|
|
|
lcommunity_free(&new->lcommunity);
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Free bgp attribute and aspath. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_unintern(struct attr **pattr)
|
|
|
|
{
|
|
|
|
struct attr *attr = *pattr;
|
|
|
|
struct attr *ret;
|
|
|
|
struct attr tmp;
|
|
|
|
|
|
|
|
/* Decrement attribute reference. */
|
|
|
|
attr->refcnt--;
|
|
|
|
|
|
|
|
tmp = *attr;
|
|
|
|
|
|
|
|
/* If reference becomes zero then free attribute object. */
|
|
|
|
if (attr->refcnt == 0) {
|
|
|
|
ret = hash_release(attrhash, attr);
|
|
|
|
assert(ret != NULL);
|
|
|
|
XFREE(MTYPE_ATTR, attr);
|
|
|
|
*pattr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgp_attr_unintern_sub(&tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bgp_attr_flush(struct attr *attr)
|
|
|
|
{
|
|
|
|
if (attr->aspath && !attr->aspath->refcnt) {
|
|
|
|
aspath_free(attr->aspath);
|
|
|
|
attr->aspath = NULL;
|
|
|
|
}
|
2018-10-22 21:58:39 +02:00
|
|
|
if (attr->community && !attr->community->refcnt)
|
|
|
|
community_free(&attr->community);
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->ecommunity && !attr->ecommunity->refcnt)
|
|
|
|
ecommunity_free(&attr->ecommunity);
|
|
|
|
if (attr->lcommunity && !attr->lcommunity->refcnt)
|
|
|
|
lcommunity_free(&attr->lcommunity);
|
|
|
|
if (attr->cluster && !attr->cluster->refcnt) {
|
|
|
|
cluster_free(attr->cluster);
|
|
|
|
attr->cluster = NULL;
|
|
|
|
}
|
|
|
|
if (attr->transit && !attr->transit->refcnt) {
|
|
|
|
transit_free(attr->transit);
|
|
|
|
attr->transit = NULL;
|
|
|
|
}
|
|
|
|
if (attr->encap_subtlvs && !attr->encap_subtlvs->refcnt) {
|
|
|
|
encap_free(attr->encap_subtlvs);
|
|
|
|
attr->encap_subtlvs = NULL;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs && !attr->vnc_subtlvs->refcnt) {
|
|
|
|
encap_free(attr->vnc_subtlvs);
|
|
|
|
attr->vnc_subtlvs = NULL;
|
|
|
|
}
|
2017-06-06 19:20:38 +02:00
|
|
|
#endif
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
/* Implement draft-scudder-idr-optional-transitive behaviour and
|
|
|
|
* avoid resetting sessions for malformed attributes which are
|
|
|
|
* are partial/optional and hence where the error likely was not
|
|
|
|
* introduced by the sending neighbour.
|
|
|
|
*/
|
|
|
|
static bgp_attr_parse_ret_t
|
2018-03-27 21:13:34 +02:00
|
|
|
bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode,
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_size_t length)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
2018-03-27 21:13:34 +02:00
|
|
|
const uint8_t flags = args->flags;
|
2017-07-17 14:03:14 +02:00
|
|
|
/* startp and length must be special-cased, as whether or not to
|
|
|
|
* send the attribute data with the NOTIFY depends on the error,
|
|
|
|
* the caller therefore signals this with the seperate length argument
|
|
|
|
*/
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t *notify_datap = (length > 0 ? args->startp : NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Only relax error handling for eBGP peers */
|
|
|
|
if (peer->sort != BGP_PEER_EBGP) {
|
|
|
|
bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, subcode,
|
|
|
|
notify_datap, length);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the stream getp to the end of the attribute, in case we can
|
|
|
|
* still proceed but the caller hasn't read all the attribute.
|
|
|
|
*/
|
|
|
|
stream_set_getp(BGP_INPUT(peer),
|
|
|
|
(args->startp - STREAM_DATA(BGP_INPUT(peer)))
|
|
|
|
+ args->total);
|
|
|
|
|
|
|
|
switch (args->type) {
|
|
|
|
/* where an attribute is relatively inconsequential, e.g. it does not
|
|
|
|
* affect route selection, and can be safely ignored, then any such
|
|
|
|
* attributes which are malformed should just be ignored and the route
|
|
|
|
* processed as normal.
|
|
|
|
*/
|
|
|
|
case BGP_ATTR_AS4_AGGREGATOR:
|
|
|
|
case BGP_ATTR_AGGREGATOR:
|
|
|
|
case BGP_ATTR_ATOMIC_AGGREGATE:
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
|
|
|
|
/* Core attributes, particularly ones which may influence route
|
|
|
|
* selection, should always cause session resets
|
|
|
|
*/
|
|
|
|
case BGP_ATTR_ORIGIN:
|
|
|
|
case BGP_ATTR_AS_PATH:
|
|
|
|
case BGP_ATTR_NEXT_HOP:
|
|
|
|
case BGP_ATTR_MULTI_EXIT_DISC:
|
|
|
|
case BGP_ATTR_LOCAL_PREF:
|
|
|
|
case BGP_ATTR_COMMUNITIES:
|
|
|
|
case BGP_ATTR_ORIGINATOR_ID:
|
|
|
|
case BGP_ATTR_CLUSTER_LIST:
|
|
|
|
case BGP_ATTR_MP_REACH_NLRI:
|
|
|
|
case BGP_ATTR_MP_UNREACH_NLRI:
|
|
|
|
case BGP_ATTR_EXT_COMMUNITIES:
|
|
|
|
bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, subcode,
|
|
|
|
notify_datap, length);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Partial optional attributes that are malformed should not cause
|
|
|
|
* the whole session to be reset. Instead treat it as a withdrawal
|
|
|
|
* of the routes, if possible.
|
|
|
|
*/
|
|
|
|
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_TRANS)
|
|
|
|
&& CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)
|
|
|
|
&& CHECK_FLAG(flags, BGP_ATTR_FLAG_PARTIAL))
|
|
|
|
return BGP_ATTR_PARSE_WITHDRAW;
|
|
|
|
|
|
|
|
/* default to reset */
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
}
|
|
|
|
|
2011-10-23 20:32:44 +02:00
|
|
|
/* Find out what is wrong with the path attribute flag bits and log the error.
|
|
|
|
"Flag bits" here stand for Optional, Transitive and Partial, but not for
|
|
|
|
Extended Length. Checking O/T/P bits at once implies, that the attribute
|
|
|
|
being diagnosed is defined by RFC as either a "well-known" or an "optional,
|
|
|
|
non-transitive" attribute. */
|
|
|
|
static void
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_flags_diagnose(struct bgp_attr_parser_args *args,
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t desired_flags /* how RFC says it must be */
|
|
|
|
)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t seen = 0, i;
|
|
|
|
uint8_t real_flags = args->flags;
|
|
|
|
const uint8_t attr_code = args->type;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
desired_flags &= ~BGP_ATTR_FLAG_EXTLEN;
|
|
|
|
real_flags &= ~BGP_ATTR_FLAG_EXTLEN;
|
|
|
|
for (i = 0; i <= 2; i++) /* O,T,P, but not E */
|
|
|
|
if (CHECK_FLAG(desired_flags, attr_flag_str[i].key)
|
|
|
|
!= CHECK_FLAG(real_flags, attr_flag_str[i].key)) {
|
2018-09-13 21:38:57 +02:00
|
|
|
flog_err(EC_BGP_ATTR_FLAG,
|
|
|
|
"%s attribute must%s be flagged as \"%s\"",
|
|
|
|
lookup_msg(attr_str, attr_code, NULL),
|
|
|
|
CHECK_FLAG(desired_flags, attr_flag_str[i].key)
|
|
|
|
? ""
|
|
|
|
: " not",
|
|
|
|
attr_flag_str[i].str);
|
2017-07-17 14:03:14 +02:00
|
|
|
seen = 1;
|
|
|
|
}
|
|
|
|
if (!seen) {
|
|
|
|
zlog_debug(
|
|
|
|
"Strange, %s called for attr %s, but no problem found with flags"
|
|
|
|
" (real flags 0x%x, desired 0x%x)",
|
|
|
|
__func__, lookup_msg(attr_str, attr_code, NULL),
|
|
|
|
real_flags, desired_flags);
|
|
|
|
}
|
2011-10-23 20:32:44 +02:00
|
|
|
}
|
|
|
|
|
2012-01-17 14:31:33 +01:00
|
|
|
/* Required flags for attributes. EXTLEN will be masked off when testing,
|
|
|
|
* as will PARTIAL for optional+transitive attributes.
|
|
|
|
*/
|
2018-03-27 21:13:34 +02:00
|
|
|
const uint8_t attr_flags_values[] = {
|
|
|
|
[BGP_ATTR_ORIGIN] = BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_AS_PATH] = BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_NEXT_HOP] = BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_MULTI_EXIT_DISC] = BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_LOCAL_PREF] = BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_ATOMIC_AGGREGATE] = BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_AGGREGATOR] = BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_COMMUNITIES] = BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_ORIGINATOR_ID] = BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_CLUSTER_LIST] = BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_MP_REACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_MP_UNREACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL,
|
|
|
|
[BGP_ATTR_EXT_COMMUNITIES] =
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_AS4_PATH] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_AS4_AGGREGATOR] =
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_PMSI_TUNNEL] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_LARGE_COMMUNITIES] =
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
|
|
|
[BGP_ATTR_PREFIX_SID] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS,
|
2012-01-17 14:31:33 +01:00
|
|
|
};
|
2016-06-14 20:07:00 +02:00
|
|
|
static const size_t attr_flags_values_max = array_size(attr_flags_values) - 1;
|
2012-01-17 14:31:33 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t mask = BGP_ATTR_FLAG_EXTLEN;
|
|
|
|
const uint8_t flags = args->flags;
|
|
|
|
const uint8_t attr_code = args->type;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* there may be attributes we don't know about */
|
|
|
|
if (attr_code > attr_flags_values_max)
|
|
|
|
return 0;
|
|
|
|
if (attr_flags_values[attr_code] == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* RFC4271, "For well-known attributes, the Transitive bit MUST be set
|
|
|
|
* to
|
|
|
|
* 1."
|
|
|
|
*/
|
|
|
|
if (!CHECK_FLAG(BGP_ATTR_FLAG_OPTIONAL, flags)
|
|
|
|
&& !CHECK_FLAG(BGP_ATTR_FLAG_TRANS, flags)) {
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTR_FLAG,
|
2017-07-17 14:03:14 +02:00
|
|
|
"%s well-known attributes must have transitive flag set (%x)",
|
|
|
|
lookup_msg(attr_str, attr_code, NULL), flags);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "For well-known attributes and for optional non-transitive
|
|
|
|
* attributes,
|
|
|
|
* the Partial bit MUST be set to 0."
|
|
|
|
*/
|
|
|
|
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_PARTIAL)) {
|
|
|
|
if (!CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_FLAG,
|
2018-09-13 21:38:57 +02:00
|
|
|
"%s well-known attribute "
|
|
|
|
"must NOT have the partial flag set (%x)",
|
|
|
|
lookup_msg(attr_str, attr_code, NULL), flags);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)
|
|
|
|
&& !CHECK_FLAG(flags, BGP_ATTR_FLAG_TRANS)) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_FLAG,
|
2018-09-13 21:38:57 +02:00
|
|
|
"%s optional + transitive attribute "
|
|
|
|
"must NOT have the partial flag set (%x)",
|
|
|
|
lookup_msg(attr_str, attr_code, NULL), flags);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Optional transitive attributes may go through speakers that don't
|
|
|
|
* reocgnise them and set the Partial bit.
|
|
|
|
*/
|
|
|
|
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)
|
|
|
|
&& CHECK_FLAG(flags, BGP_ATTR_FLAG_TRANS))
|
|
|
|
SET_FLAG(mask, BGP_ATTR_FLAG_PARTIAL);
|
|
|
|
|
|
|
|
if ((flags & ~mask) == attr_flags_values[attr_code])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bgp_attr_flags_diagnose(args, attr_flags_values[attr_code]);
|
|
|
|
return 1;
|
2012-01-17 14:31:33 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Get origin attribute of the update message. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static bgp_attr_parse_ret_t bgp_attr_origin(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* If any recognized attribute has Attribute Length that conflicts
|
|
|
|
with the expected length (based on the attribute type code), then
|
|
|
|
the Error Subcode is set to Attribute Length Error. The Data
|
|
|
|
field contains the erroneous attribute (type, length and
|
|
|
|
value). */
|
|
|
|
if (length != 1) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Origin attribute length is not one %d", length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fetch origin attribute. */
|
|
|
|
attr->origin = stream_getc(BGP_INPUT(peer));
|
|
|
|
|
|
|
|
/* If the ORIGIN attribute has an undefined value, then the Error
|
|
|
|
Subcode is set to Invalid Origin Attribute. The Data field
|
|
|
|
contains the unrecognized attribute (type, length and value). */
|
|
|
|
if ((attr->origin != BGP_ORIGIN_IGP) && (attr->origin != BGP_ORIGIN_EGP)
|
|
|
|
&& (attr->origin != BGP_ORIGIN_INCOMPLETE)) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_ORIGIN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Origin attribute value is invalid %d", attr->origin);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_INVAL_ORIGIN,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set oring attribute flag. */
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGIN);
|
|
|
|
|
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2010-11-27 23:48:34 +01:00
|
|
|
|
|
|
|
/* Parse AS path information. This function is wrapper of
|
|
|
|
aspath_parse. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_aspath(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* peer with AS4 => will get 4Byte ASnums
|
|
|
|
* otherwise, will get 16 Bit
|
|
|
|
*/
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->aspath = aspath_parse(peer->curr, length,
|
2017-07-17 14:03:14 +02:00
|
|
|
CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV));
|
|
|
|
|
|
|
|
/* In case of IBGP, length will be zero. */
|
|
|
|
if (!attr->aspath) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_MAL_AS_PATH,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Malformed AS path from %s, length is %d", peer->host,
|
|
|
|
length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH,
|
|
|
|
0);
|
|
|
|
}
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set aspath attribute flag. */
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS_PATH);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bgp_attr_parse_ret_t bgp_attr_aspath_check(struct peer *const peer,
|
|
|
|
struct attr *const attr)
|
|
|
|
{
|
|
|
|
/* These checks were part of bgp_attr_aspath, but with
|
|
|
|
* as4 we should to check aspath things when
|
|
|
|
* aspath synthesizing with as4_path has already taken place.
|
|
|
|
* Otherwise we check ASPATH and use the synthesized thing, and that is
|
|
|
|
* not right.
|
|
|
|
* So do the checks later, i.e. here
|
|
|
|
*/
|
|
|
|
struct aspath *aspath;
|
|
|
|
|
|
|
|
/* Confederation sanity check. */
|
|
|
|
if ((peer->sort == BGP_PEER_CONFED
|
|
|
|
&& !aspath_left_confed_check(attr->aspath))
|
|
|
|
|| (peer->sort == BGP_PEER_EBGP
|
|
|
|
&& aspath_confed_check(attr->aspath))) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_MAL_AS_PATH, "Malformed AS path from %s",
|
2018-09-13 21:38:57 +02:00
|
|
|
peer->host);
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
2010-08-09 20:31:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* First AS check for EBGP. */
|
2018-05-17 22:51:35 +02:00
|
|
|
if (CHECK_FLAG(peer->flags, PEER_FLAG_ENFORCE_FIRST_AS)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
if (peer->sort == BGP_PEER_EBGP
|
|
|
|
&& !aspath_firstas_check(attr->aspath, peer->as)) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_FIRST_AS,
|
2018-09-13 21:38:57 +02:00
|
|
|
"%s incorrect first AS (must be %u)",
|
|
|
|
peer->host, peer->as);
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* local-as prepend */
|
|
|
|
if (peer->change_local_as
|
|
|
|
&& !CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)) {
|
|
|
|
aspath = aspath_dup(attr->aspath);
|
|
|
|
aspath = aspath_add_seq(aspath, peer->change_local_as);
|
|
|
|
aspath_unintern(&attr->aspath);
|
|
|
|
attr->aspath = aspath_intern(aspath);
|
|
|
|
}
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
}
|
|
|
|
|
2010-11-27 23:48:34 +01:00
|
|
|
/* Parse AS4 path information. This function is another wrapper of
|
|
|
|
aspath_parse. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_as4_path(struct bgp_attr_parser_args *args,
|
|
|
|
struct aspath **as4_path)
|
2010-11-27 23:48:34 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
2010-11-27 23:48:34 +01:00
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
*as4_path = aspath_parse(peer->curr, length, 1);
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* In case of IBGP, length will be zero. */
|
|
|
|
if (!*as4_path) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_MAL_AS_PATH,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Malformed AS4 path from %s, length is %d", peer->host,
|
|
|
|
length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH,
|
|
|
|
0);
|
|
|
|
}
|
2010-11-27 23:48:34 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set aspath attribute flag. */
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 09:02:16 +02:00
|
|
|
/*
|
|
|
|
* Check that the nexthop attribute is valid.
|
|
|
|
*/
|
|
|
|
bgp_attr_parse_ret_t
|
|
|
|
bgp_attr_nexthop_valid(struct peer *peer, struct attr *attr)
|
|
|
|
{
|
|
|
|
in_addr_t nexthop_h;
|
|
|
|
|
|
|
|
nexthop_h = ntohl(attr->nexthop.s_addr);
|
|
|
|
if ((IPV4_NET0(nexthop_h) || IPV4_NET127(nexthop_h)
|
|
|
|
|| IPV4_CLASS_DE(nexthop_h))
|
|
|
|
&& !BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
|
|
|
|
char buf[INET_ADDRSTRLEN];
|
|
|
|
|
|
|
|
inet_ntop(AF_INET, &attr->nexthop.s_addr, buf,
|
|
|
|
INET_ADDRSTRLEN);
|
|
|
|
flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %s",
|
|
|
|
buf);
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Nexthop attribute. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static bgp_attr_parse_ret_t bgp_attr_nexthop(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* Check nexthop attribute length. */
|
|
|
|
if (length != 4) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Nexthop attribute length isn't four [%d]", length);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
2019-05-04 08:22:30 +02:00
|
|
|
attr->nexthop.s_addr = stream_get_ipv4(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* MED atrribute. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static bgp_attr_parse_ret_t bgp_attr_med(struct bgp_attr_parser_args *args)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Length check. */
|
|
|
|
if (length != 4) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"MED attribute length isn't four [%d]", length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->med = stream_getl(peer->curr);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Local preference attribute. */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_local_pref(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* Length check. */
|
|
|
|
if (length != 4) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"LOCAL_PREF attribute length isn't 4 [%u]", length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is contained in an UPDATE message that is received from an
|
|
|
|
external peer, then this attribute MUST be ignored by the
|
|
|
|
receiving speaker. */
|
|
|
|
if (peer->sort == BGP_PEER_EBGP) {
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->local_pref = stream_getl(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-08-25 20:27:49 +02:00
|
|
|
/* Set the local-pref flag. */
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic aggregate. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_atomic(struct bgp_attr_parser_args *args)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* Length check. */
|
|
|
|
if (length != 0) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"ATOMIC_AGGREGATE attribute length isn't 0 [%u]",
|
|
|
|
length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set atomic aggregate flag. */
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Aggregator attribute */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_aggregator(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
int wantedlen = 6;
|
|
|
|
|
|
|
|
/* peer with AS4 will send 4 Byte AS, peer without will send 2 Byte */
|
|
|
|
if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV))
|
|
|
|
wantedlen = 8;
|
|
|
|
|
|
|
|
if (length != wantedlen) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"AGGREGATOR attribute length isn't %u [%u]", wantedlen,
|
|
|
|
length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV))
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->aggregator_as = stream_getl(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->aggregator_as = stream_getw(peer->curr);
|
|
|
|
attr->aggregator_addr.s_addr = stream_get_ipv4(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Set atomic aggregate flag. */
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
/* New Aggregator attribute */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_as4_aggregator(struct bgp_attr_parser_args *args,
|
|
|
|
as_t *as4_aggregator_as,
|
|
|
|
struct in_addr *as4_aggregator_addr)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
if (length != 8) {
|
2018-09-13 21:38:57 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN, "New Aggregator length is not 8 [%d]",
|
|
|
|
length);
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
*as4_aggregator_as = stream_getl(peer->curr);
|
|
|
|
as4_aggregator_addr->s_addr = stream_get_ipv4(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Munge Aggregator and New-Aggregator, AS_PATH and NEW_AS_PATH.
|
|
|
|
*/
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_munge_as4_attrs(struct peer *const peer, struct attr *const attr,
|
|
|
|
struct aspath *as4_path, as_t as4_aggregator,
|
|
|
|
struct in_addr *as4_aggregator_addr)
|
|
|
|
{
|
|
|
|
int ignore_as4_path = 0;
|
|
|
|
struct aspath *newpath;
|
|
|
|
|
|
|
|
if (!attr->aspath) {
|
|
|
|
/* NULL aspath shouldn't be possible as bgp_attr_parse should
|
|
|
|
* have
|
|
|
|
* checked that all well-known, mandatory attributes were
|
|
|
|
* present.
|
|
|
|
*
|
|
|
|
* Can only be a problem with peer itself - hard error
|
|
|
|
*/
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) {
|
|
|
|
/* peer can do AS4, so we ignore AS4_PATH and AS4_AGGREGATOR
|
|
|
|
* if given.
|
|
|
|
* It is worth a warning though, because the peer really
|
|
|
|
* should not send them
|
|
|
|
*/
|
|
|
|
if (BGP_DEBUG(as4, AS4)) {
|
|
|
|
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH)))
|
|
|
|
zlog_debug("[AS4] %s %s AS4_PATH", peer->host,
|
|
|
|
"AS4 capable peer, yet it sent");
|
|
|
|
|
|
|
|
if (attr->flag
|
|
|
|
& (ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR)))
|
|
|
|
zlog_debug("[AS4] %s %s AS4_AGGREGATOR",
|
|
|
|
peer->host,
|
|
|
|
"AS4 capable peer, yet it sent");
|
|
|
|
}
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have a asn16 peer. First, look for AS4_AGGREGATOR
|
|
|
|
* because that may override AS4_PATH
|
|
|
|
*/
|
|
|
|
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR))) {
|
|
|
|
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))) {
|
|
|
|
/* received both.
|
|
|
|
* if the as_number in aggregator is not AS_TRANS,
|
|
|
|
* then AS4_AGGREGATOR and AS4_PATH shall be ignored
|
|
|
|
* and the Aggregator shall be taken as
|
|
|
|
* info on the aggregating node, and the AS_PATH
|
|
|
|
* shall be taken as the AS_PATH
|
|
|
|
* otherwise
|
|
|
|
* the Aggregator shall be ignored and the
|
|
|
|
* AS4_AGGREGATOR shall be taken as the
|
|
|
|
* Aggregating node and the AS_PATH is to be
|
|
|
|
* constructed "as in all other cases"
|
|
|
|
*/
|
|
|
|
if (attr->aggregator_as != BGP_AS_TRANS) {
|
|
|
|
/* ignore */
|
|
|
|
if (BGP_DEBUG(as4, AS4))
|
|
|
|
zlog_debug(
|
|
|
|
"[AS4] %s BGP not AS4 capable peer"
|
|
|
|
" send AGGREGATOR != AS_TRANS and"
|
|
|
|
" AS4_AGGREGATOR, so ignore"
|
|
|
|
" AS4_AGGREGATOR and AS4_PATH",
|
|
|
|
peer->host);
|
|
|
|
ignore_as4_path = 1;
|
|
|
|
} else {
|
|
|
|
/* "New_aggregator shall be taken as aggregator"
|
|
|
|
*/
|
|
|
|
attr->aggregator_as = as4_aggregator;
|
|
|
|
attr->aggregator_addr.s_addr =
|
|
|
|
as4_aggregator_addr->s_addr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* We received a AS4_AGGREGATOR but no AGGREGATOR.
|
|
|
|
* That is bogus - but reading the conditions
|
|
|
|
* we have to handle AS4_AGGREGATOR as if it were
|
|
|
|
* AGGREGATOR in that case
|
|
|
|
*/
|
|
|
|
if (BGP_DEBUG(as4, AS4))
|
|
|
|
zlog_debug(
|
|
|
|
"[AS4] %s BGP not AS4 capable peer send"
|
|
|
|
" AS4_AGGREGATOR but no AGGREGATOR, will take"
|
|
|
|
" it as if AGGREGATOR with AS_TRANS had been there",
|
|
|
|
peer->host);
|
|
|
|
attr->aggregator_as = as4_aggregator;
|
|
|
|
/* sweep it under the carpet and simulate a "good"
|
|
|
|
* AGGREGATOR */
|
|
|
|
attr->flag |= (ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* need to reconcile NEW_AS_PATH and AS_PATH */
|
|
|
|
if (!ignore_as4_path
|
|
|
|
&& (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH)))) {
|
|
|
|
newpath = aspath_reconcile_as4(attr->aspath, as4_path);
|
2018-06-21 15:58:51 +02:00
|
|
|
if (!newpath)
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
aspath_unintern(&attr->aspath);
|
|
|
|
attr->aspath = aspath_intern(newpath);
|
|
|
|
}
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
[bgpd] Merge AS4 support
2007-10-14 Paul Jakma <paul.jakma@sun.com>
* NEWS: Note that MRT dumps are now version 2
* (general) Merge in Juergen Kammer's AS4 patch.
2007-09-27 Paul Jakma <paul.jakma@sun.com>
* bgp_aspath.c: (assegment_normalise) remove duplicates from
from sets.
(aspath_reconcile_as4) disregard a broken part of the RFC around
error handling in path reconciliation.
* aspath_test.c: Test dupe-weeding from sets.
Test that reconciliation merges AS_PATH and AS4_PATH where
former is shorter than latter.
2007-09-26 Paul Jakma <paul.jakma@sun.com>
* aspath_test.c: Test AS4_PATH reconcilation where length
of AS_PATH and AS4_PATH is same.
2007-09-25 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (peek_for_as4_capability) Fix to work.
* bgp_packet.c: (bgp_open_receive) Fix sanity check of as4.
* tests/bgp_capability_test.c: (general) Extend tests to validate
peek_for_as4_capability.
Add test of full OPEN Option block, with multiple capabilities,
both as a series of Option, and a single option.
Add some crap to beginning of stream, to prevent code depending
on getp == 0.
2007-09-18 Paul Jakma <paul.jakma@sun.com>
* bgp_open.c: (bgp_capability_as4) debug printf inline with others.
(peek_for_as4_capability) There's no need to signal failure, as
failure is better dealt with through full capability parser -
just return the AS4, simpler.
* bgp_packet.c: (bgp_open_receive) Update to match
peek_for_as4_capability change.
Allow use of BGP_AS_TRANS by 2b speakers.
Use NOTIFY_OPEN_ERR rather than CEASE for OPEN parsing errors.
(bgp_capability_msg_parse) missing argument to debug print
(bgp_capability_receive) missing return values.
* tests/bgp_capability_test.c: (parse_test) update for changes to
peek_for_as4_capability
2007-07-25 Paul Jakma <paul.jakma@sun.com>
* Remove 2-byte size macros, just make existing macros take
argument to indicate which size to use.
Adjust all users - typically they want '1'.
* bgp_aspath.c: (aspath_has_as4) New, return 1 if there are any
as4's in a path.
(aspath_put) Return the number of bytes actually written, to
fix the bug Juergen noted: Splitting of segments will change
the number of bytes written from that already written to the
AS_PATH header.
(aspath_snmp_pathseg) Pass 2-byte flag to aspath_put. SNMP
is still defined as 2b.
(aspath_aggregate) fix latent bug.
(aspath_reconcile_as4) AS_PATH+NEW_AS_PATH reconciliation
function.
(aspath_key_make) Hash the AS_PATH string, rather than
just taking the addition of assegment ASes as the hash value,
hopefully sligthly more collision resistant.
(bgp_attr_munge_as4_attrs) Collide the NEW_ attributes
together with the OLD 2-byte forms, code Juergen
had in bgp_attr_parse but re-organised a bit.
(bgp_attr_parse) Bunch of code from Juergen moves
to previous function.
(bgp_packet_attribute) Compact significantly by
just /always/ using extended-length attr header.
Fix bug Juergen noted, by using aspath_put's
(new) returned size value for the attr header rather
than the (guesstimate) of aspath_size() - the two could
differ when aspath_put had to split large segments, unlikely
this bug was ever hit in the 'wild'.
(bgp_dump_routes_attr) Always use extended-len and
use aspath_put return for header length. Output 4b ASN
for AS_PATH and AGGREGATOR.
* bgp_ecommunity.c: (ecommunity_{hash_make,cmp}) fix
hash callback declarations to match prototypes.
(ecommunity_gettoken) Updated for ECOMMUNITY_ENCODE_AS4,
complete rewrite of Juergen's changes (no asdot support)
* bgp_open.c: (bgp_capability_as4) New, does what it says
on the tin.
(peek_for_as4_capability) Rewritten to use streams and
bgp_capability_as4.
* bgp_packet.c: (bgp_open_send) minor edit
checked (in the abstract at least) with Juergen.
Changes are to be more accepting, e.g, allow AS_TRANS on
a 2-byte session.
* (general) Update all commands to use CMD_AS_RANGE.
* bgp_vty.c: (bgp_clear) Fix return vals to use CMD_..
Remove stuff replicated by VTY_GET_LONG
(bgp_clear_vty) Return bgp_clear directly to vty.
* tests/aspath_test.c: Exercise 32bit parsing. Test reconcile
function.
* tests/ecommunity_test.c: New, test AS4 ecommunity changes,
positive test only at this time, error cases not tested yet.
2007-07-25 Juergen Kammer <j.kammer@eurodata.de>
* (general) AS4 support.
* bgpd.h: as_t changes to 4-bytes.
* bgp_aspath.h: Add BGP_AS4_MAX and BGP_AS_TRANS defines.
* bgp_aspath.c: AS_VALUE_SIZE becomes 4-byte, AS16_VALUE_SIZE
added for 2-byte.
Add AS16 versions of length calc macros.
(aspath_count_numas) New, count number of ASes.
(aspath_has_as4) New, return 1 if there are any as4's in a
path.
(assegments_parse) Interpret assegment as 4 or 2 byte,
according to how the caller instructs us, with a new
argument.
(aspath_parse) Add use32bit argument to pass to
assegments_parse. Adjust all its callers to pass 1, unless
otherwise noted.
(assegment_data_put) Adjust to be able to write 2 or 4 byte
AS, according to new use32bit argument.
(aspath_put) Adjust to write 2 or 4.
(aspath_gettoken) Use a long for passed in asno.
* bgp_attr.c: (attr_str) Add BGP_ATTR_AS4_PATH and
BGP_ATTR_AS4_AGGREGATOR.
(bgp_attr_aspath) Call aspath_parse with right 2/4 arg, as
determined by received-capability flag.
(bgp_attr_aspath_check) New, code previously in attr_aspath
but moved to new func so it can be run after NEW_AS_PATH
reconciliation.
(bgp_attr_as4_path) New, handle NEW_AS_PATH.
(bgp_attr_aggregator) Adjust to cope with 2/4 byte ASes.
(bgp_attr_as4_aggregator) New, read NEW_AGGREGATOR.
(bgp_attr_parse) Add handoffs to previous parsers for the two
new AS4 NEW_ attributes.
Various checks added for NEW/OLD reconciliation.
(bgp_packet_attribute) Support 2/4 for AS_PATH and
AGGREGATOR, detect when NEW_ attrs need to be sent.
* bgp_debug.{c,h}: Add 'debug bgp as4'.
* bgp_dump.c: MRTv2 support, unconditionally enabled, which
supports AS4. Based on patches from Erik (RIPE?).
* bgp_ecommunity.c: (ecommunity_ecom2str) ECOMMUNITY_ENCODE_AS4
support.
* bgp_open.c: (peek_for_as4_capability) New, peek for AS4
capability prior to full capability parsing, so we know which
ASN to use for struct peer lookup.
(bgp_open_capability) Always send AS4 capability.
* bgp_packet.c: (bgp_open_send) AS4 handling for AS field
(bgp_open_receive) Peek for AS4 capability first, and figure
out which AS to believe.
* bgp_vty.c: (bgp_show_peer) Print AS4 cap
* tests/aspath_test.c: Support asn32 changes, call aspath_parse
with 16 bit.
* vtysh/extract.pl: AS4 compatibility for router bgp ASNUMBER
* vtysh/extract.pl.in: AS4 compatibility for router bgp ASNUMBER
* vtysh/vtysh.c: AS4 compatibility for router bgp ASNUMBER
2007-10-15 00:32:21 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Community attribute. */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_community(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
attr->community = NULL;
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->community =
|
2018-03-27 21:13:34 +02:00
|
|
|
community_parse((uint32_t *)stream_pnt(peer->curr), length);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* XXX: fix community_parse to use stream API and remove this */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (!attr->community)
|
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
args->total);
|
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Originator ID attribute. */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_originator_id(struct bgp_attr_parser_args *args)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Length check. */
|
|
|
|
if (length != 4) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN, "Bad originator ID length %d",
|
2018-09-13 21:38:57 +02:00
|
|
|
length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
attr->originator_id.s_addr = stream_get_ipv4(peer->curr);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cluster list attribute. */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_cluster_list(struct bgp_attr_parser_args *args)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* Check length. */
|
|
|
|
if (length % 4) {
|
2018-09-13 21:38:57 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN, "Bad cluster list length %d", length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->cluster =
|
2017-05-02 02:37:45 +02:00
|
|
|
cluster_parse((struct in_addr *)stream_pnt(peer->curr), length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* XXX: Fix cluster_parse to use stream API and then remove this */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiprotocol reachability information parse. */
|
2017-07-17 14:03:14 +02:00
|
|
|
int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
|
|
|
|
struct bgp_nlri *mp_update)
|
|
|
|
{
|
|
|
|
iana_afi_t pkt_afi;
|
|
|
|
afi_t afi;
|
2017-08-01 02:06:40 +02:00
|
|
|
iana_safi_t pkt_safi;
|
|
|
|
safi_t safi;
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_size_t nlri_len;
|
|
|
|
size_t start;
|
|
|
|
struct stream *s;
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/* Set end of packet. */
|
|
|
|
s = BGP_INPUT(peer);
|
|
|
|
start = stream_get_getp(s);
|
|
|
|
|
|
|
|
/* safe to read statically sized header? */
|
2007-04-10 21:36:48 +02:00
|
|
|
#define BGP_MP_REACH_MIN_SIZE 5
|
2008-06-07 22:37:10 +02:00
|
|
|
#define LEN_LEFT (length - (stream_get_getp(s) - start))
|
2017-07-17 14:03:14 +02:00
|
|
|
if ((length > STREAM_READABLE(s)) || (length < BGP_MP_REACH_MIN_SIZE)) {
|
|
|
|
zlog_info("%s: %s sent invalid length, %lu", __func__,
|
|
|
|
peer->host, (unsigned long)length);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load AFI, SAFI. */
|
|
|
|
pkt_afi = stream_getw(s);
|
|
|
|
pkt_safi = stream_getc(s);
|
|
|
|
|
|
|
|
/* Convert AFI, SAFI to internal values, check. */
|
|
|
|
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) {
|
|
|
|
/* Log if AFI or SAFI is unrecognized. This is not an error
|
|
|
|
* unless
|
|
|
|
* the attribute is otherwise malformed.
|
|
|
|
*/
|
|
|
|
if (bgp_debug_update(peer, NULL, NULL, 0))
|
|
|
|
zlog_debug(
|
|
|
|
"%s: MP_REACH received AFI %u or SAFI %u is unrecognized",
|
|
|
|
peer->host, pkt_afi, pkt_safi);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get nexthop length. */
|
|
|
|
attr->mp_nexthop_len = stream_getc(s);
|
|
|
|
|
|
|
|
if (LEN_LEFT < attr->mp_nexthop_len) {
|
|
|
|
zlog_info(
|
|
|
|
"%s: %s, MP nexthop length, %u, goes past end of attribute",
|
|
|
|
__func__, peer->host, attr->mp_nexthop_len);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nexthop length check. */
|
|
|
|
switch (attr->mp_nexthop_len) {
|
2017-01-23 03:45:30 +01:00
|
|
|
case 0:
|
|
|
|
if (safi != SAFI_FLOWSPEC) {
|
|
|
|
zlog_info("%s: (%s) Wrong multiprotocol next hop length: %d",
|
|
|
|
__func__, peer->host, attr->mp_nexthop_len);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
break;
|
2017-10-28 21:04:20 +02:00
|
|
|
case BGP_ATTR_NHLEN_VPNV4:
|
|
|
|
stream_getl(s); /* RD high */
|
|
|
|
stream_getl(s); /* RD low */
|
2018-03-06 20:02:52 +01:00
|
|
|
/*
|
|
|
|
* NOTE: intentional fall through
|
|
|
|
* - for consistency in rx processing
|
|
|
|
*
|
|
|
|
* The following comment is to signal GCC this intention
|
2018-10-25 20:06:59 +02:00
|
|
|
* and suppress the warning
|
2018-03-06 20:02:52 +01:00
|
|
|
*/
|
|
|
|
/* FALLTHRU */
|
2017-07-17 14:03:14 +02:00
|
|
|
case BGP_ATTR_NHLEN_IPV4:
|
|
|
|
stream_get(&attr->mp_nexthop_global_in, s, IPV4_MAX_BYTELEN);
|
|
|
|
/* Probably needed for RFC 2283 */
|
|
|
|
if (attr->nexthop.s_addr == 0)
|
|
|
|
memcpy(&attr->nexthop.s_addr,
|
|
|
|
&attr->mp_nexthop_global_in, IPV4_MAX_BYTELEN);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_NHLEN_IPV6_GLOBAL:
|
|
|
|
case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
|
|
|
|
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) {
|
|
|
|
stream_getl(s); /* RD high */
|
|
|
|
stream_getl(s); /* RD low */
|
|
|
|
}
|
|
|
|
stream_get(&attr->mp_nexthop_global, s, IPV6_MAX_BYTELEN);
|
2018-09-06 16:51:08 +02:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&attr->mp_nexthop_global)) {
|
|
|
|
if (!peer->nexthop.ifp) {
|
2019-03-26 14:11:28 +01:00
|
|
|
zlog_warn("%s: Received a V6/VPNV6 Global attribute but address is a V6 LL and we have no peer interface information, withdrawing",
|
2018-09-06 16:51:08 +02:00
|
|
|
peer->host);
|
|
|
|
return BGP_ATTR_PARSE_WITHDRAW;
|
|
|
|
}
|
2018-04-05 19:42:27 +02:00
|
|
|
attr->nh_ifindex = peer->nexthop.ifp->ifindex;
|
2018-09-06 16:51:08 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
|
|
|
|
case BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL:
|
|
|
|
if (attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) {
|
|
|
|
stream_getl(s); /* RD high */
|
|
|
|
stream_getl(s); /* RD low */
|
|
|
|
}
|
|
|
|
stream_get(&attr->mp_nexthop_global, s, IPV6_MAX_BYTELEN);
|
2018-09-06 16:51:08 +02:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&attr->mp_nexthop_global)) {
|
|
|
|
if (!peer->nexthop.ifp) {
|
2019-03-26 14:11:28 +01:00
|
|
|
zlog_warn("%s: Received V6/VPNV6 Global and LL attribute but global address is a V6 LL and we have no peer interface information, withdrawing",
|
2018-09-06 16:51:08 +02:00
|
|
|
peer->host);
|
|
|
|
return BGP_ATTR_PARSE_WITHDRAW;
|
|
|
|
}
|
2018-04-05 19:42:27 +02:00
|
|
|
attr->nh_ifindex = peer->nexthop.ifp->ifindex;
|
2018-09-06 16:51:08 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) {
|
|
|
|
stream_getl(s); /* RD high */
|
|
|
|
stream_getl(s); /* RD low */
|
|
|
|
}
|
|
|
|
stream_get(&attr->mp_nexthop_local, s, IPV6_MAX_BYTELEN);
|
|
|
|
if (!IN6_IS_ADDR_LINKLOCAL(&attr->mp_nexthop_local)) {
|
|
|
|
char buf1[INET6_ADDRSTRLEN];
|
|
|
|
char buf2[INET6_ADDRSTRLEN];
|
|
|
|
|
|
|
|
if (bgp_debug_update(peer, NULL, NULL, 1))
|
|
|
|
zlog_debug(
|
|
|
|
"%s rcvd nexthops %s, %s -- ignoring non-LL value",
|
|
|
|
peer->host,
|
|
|
|
inet_ntop(AF_INET6,
|
|
|
|
&attr->mp_nexthop_global,
|
|
|
|
buf1, INET6_ADDRSTRLEN),
|
|
|
|
inet_ntop(AF_INET6,
|
|
|
|
&attr->mp_nexthop_local, buf2,
|
|
|
|
INET6_ADDRSTRLEN));
|
|
|
|
|
|
|
|
attr->mp_nexthop_len = IPV6_MAX_BYTELEN;
|
|
|
|
}
|
2018-09-06 16:51:08 +02:00
|
|
|
if (!peer->nexthop.ifp) {
|
2019-03-26 14:11:28 +01:00
|
|
|
zlog_warn("%s: Received a V6 LL nexthop and we have no peer interface information, withdrawing",
|
2018-09-06 16:51:08 +02:00
|
|
|
peer->host);
|
|
|
|
return BGP_ATTR_PARSE_WITHDRAW;
|
|
|
|
}
|
2018-04-05 19:42:27 +02:00
|
|
|
attr->nh_lla_ifindex = peer->nexthop.ifp->ifindex;
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
zlog_info("%s: (%s) Wrong multiprotocol next hop length: %d",
|
|
|
|
__func__, peer->host, attr->mp_nexthop_len);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LEN_LEFT) {
|
|
|
|
zlog_info("%s: (%s) Failed to read SNPA and NLRI(s)", __func__,
|
|
|
|
peer->host);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t val;
|
2017-07-17 14:03:14 +02:00
|
|
|
if ((val = stream_getc(s)))
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_DEFUNCT_SNPA_LEN,
|
2018-08-24 18:26:43 +02:00
|
|
|
"%s sent non-zero value, %u, for defunct SNPA-length field",
|
|
|
|
peer->host, val);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* must have nrli_len, what is left of the attribute */
|
|
|
|
nlri_len = LEN_LEFT;
|
2017-10-26 05:07:21 +02:00
|
|
|
if (nlri_len > STREAM_READABLE(s)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_info("%s: (%s) Failed to read NLRI", __func__, peer->host);
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
}
|
|
|
|
|
2017-10-26 05:07:21 +02:00
|
|
|
if (!nlri_len) {
|
|
|
|
zlog_info("%s: (%s) No Reachability, Treating as a EOR marker",
|
|
|
|
__func__, peer->host);
|
|
|
|
|
|
|
|
mp_update->afi = afi;
|
|
|
|
mp_update->safi = safi;
|
|
|
|
return BGP_ATTR_PARSE_EOR;
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
mp_update->afi = afi;
|
|
|
|
mp_update->safi = safi;
|
|
|
|
mp_update->nlri = stream_pnt(s);
|
|
|
|
mp_update->length = nlri_len;
|
|
|
|
|
|
|
|
stream_forward_getp(s, nlri_len);
|
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2008-06-07 22:37:10 +02:00
|
|
|
#undef LEN_LEFT
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiprotocol unreachable parse */
|
2017-07-17 14:03:14 +02:00
|
|
|
int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args,
|
|
|
|
struct bgp_nlri *mp_withdraw)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
iana_afi_t pkt_afi;
|
|
|
|
afi_t afi;
|
2017-08-01 02:06:40 +02:00
|
|
|
iana_safi_t pkt_safi;
|
|
|
|
safi_t safi;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t withdraw_len;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
2016-06-15 19:25:35 +02:00
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
s = peer->curr;
|
2016-06-15 19:25:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
#define BGP_MP_UNREACH_MIN_SIZE 3
|
|
|
|
if ((length > STREAM_READABLE(s)) || (length < BGP_MP_UNREACH_MIN_SIZE))
|
|
|
|
return BGP_ATTR_PARSE_ERROR_NOTIFYPLS;
|
|
|
|
|
|
|
|
pkt_afi = stream_getw(s);
|
|
|
|
pkt_safi = stream_getc(s);
|
|
|
|
|
|
|
|
/* Convert AFI, SAFI to internal values, check. */
|
|
|
|
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) {
|
|
|
|
/* Log if AFI or SAFI is unrecognized. This is not an error
|
|
|
|
* unless
|
|
|
|
* the attribute is otherwise malformed.
|
|
|
|
*/
|
|
|
|
if (bgp_debug_update(peer, NULL, NULL, 0))
|
|
|
|
zlog_debug(
|
|
|
|
"%s: MP_UNREACH received AFI %u or SAFI %u is unrecognized",
|
|
|
|
peer->host, pkt_afi, pkt_safi);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
withdraw_len = length - BGP_MP_UNREACH_MIN_SIZE;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
mp_withdraw->afi = afi;
|
|
|
|
mp_withdraw->safi = safi;
|
|
|
|
mp_withdraw->nlri = stream_pnt(s);
|
|
|
|
mp_withdraw->length = withdraw_len;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_forward_getp(s, withdraw_len);
|
2014-12-08 17:42:12 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI);
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 11:00:39 +01:00
|
|
|
/* Large Community attribute. */
|
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_large_community(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Large community follows new attribute format.
|
|
|
|
*/
|
|
|
|
if (length == 0) {
|
|
|
|
attr->lcommunity = NULL;
|
|
|
|
/* Empty extcomm doesn't seem to be invalid per se */
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
2016-11-15 11:00:39 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->lcommunity =
|
2018-03-27 21:13:34 +02:00
|
|
|
lcommunity_parse((uint8_t *)stream_pnt(peer->curr), length);
|
2017-07-17 14:03:14 +02:00
|
|
|
/* XXX: fix ecommunity_parse to use stream API */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2016-11-15 11:00:39 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!attr->lcommunity)
|
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
args->total);
|
2016-11-15 11:00:39 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
|
2016-11-15 11:00:39 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2016-11-15 11:00:39 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Extended Community attribute. */
|
bgpd: Implement revised error handling for partial optional/trans. attributes
* BGP error handling generally boils down to "reset session". This was fine
when all BGP speakers pretty much understood all BGP messages. However
the increasing deployment of new attribute types has shown this approach
to cause problems, in particular where a new attribute type is "tunneled"
over some speakers which do not understand it, and then arrives at a speaker
which does but considers it malformed (e.g. corruption along the way, or
because of early implementation bugs/interop issues).
To mitigate this drafts before the IDR (likely to be adopted) propose to
treat errors in partial (i.e. not understood by neighbour), optional
transitive attributes, when received from eBGP peers, as withdrawing only
the NLRIs in the affected UPDATE, rather than causing the entire session
to be reset. See:
http://tools.ietf.org/html/draft-scudder-idr-optional-transitive
* bgp_aspath.c: (assegments_parse) Replace the "NULL means valid, 0-length
OR an error" return value with an error code - instead taking
pointer to result structure as arg.
(aspath_parse) adjust to suit previous change, but here NULL really
does mean error in the external interface.
* bgp_attr.h (bgp_attr_parse) use an explictly typed and enumerated
value to indicate return result.
(bgp_attr_unintern_sub) cleans up just the members of an attr, but not the
attr itself, for benefit of those who use a stack-local attr.
* bgp_attr.c: (bgp_attr_unintern_sub) split out from bgp_attr_unintern
(bgp_attr_unintern) as previous.
(bgp_attr_malformed) helper function to centralise decisions on how to
handle errors in attributes.
(bgp_attr_{aspathlimit,origin,etc..}) Use bgp_attr_malformed.
(bgp_attr_aspathlimit) Subcode for error specifc to this attr should be
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR.
(bgp_attr_as4_path) be more rigorous about checks, ala bgp_attr_as_path.
(bgp_attr_parse) Adjust to deal with the additional error level that
bgp_attr_ parsers can raise, and also similarly return appropriate
error back up to (bgp_update_receive). Try to avoid leaking as4_path.
* bgp_packet.c: (bgp_update_receive) Adjust to deal with BGP_ATTR_PARSE_WITHDRAW
error level from bgp_attr_parse, which should lead to a withdraw, by
making the attribute parameter in call to (bgp_nlri_parse) conditional
on the error, so the update case morphs also into a withdraw.
Use bgp_attr_unintern_sub from above, instead of doing this itself.
Fix error case returns which were not calling bgp_attr_unintern_sub
and probably leaking memory.
* tests/aspath_test.c: Fix to work for null return with bad segments
2010-11-23 17:35:42 +01:00
|
|
|
static bgp_attr_parse_ret_t
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t sticky = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
attr->ecommunity = NULL;
|
|
|
|
/* Empty extcomm doesn't seem to be invalid per se */
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->ecommunity =
|
2018-03-27 21:13:34 +02:00
|
|
|
ecommunity_parse((uint8_t *)stream_pnt(peer->curr), length);
|
2017-07-17 14:03:14 +02:00
|
|
|
/* XXX: fix ecommunity_parse to use stream API */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (!attr->ecommunity)
|
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
args->total);
|
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
|
|
|
|
/* Extract MAC mobility sequence number, if any. */
|
|
|
|
attr->mm_seqnum = bgp_attr_mac_mobility_seqnum(attr, &sticky);
|
|
|
|
attr->sticky = sticky;
|
|
|
|
|
2017-11-13 12:19:52 +01:00
|
|
|
/* Check if this is a Gateway MAC-IP advertisement */
|
|
|
|
attr->default_gw = bgp_attr_default_gw(attr);
|
|
|
|
|
2018-07-07 06:46:46 +02:00
|
|
|
/* Handle scenario where router flag ecommunity is not
|
|
|
|
* set but default gw ext community is present.
|
|
|
|
* Use default gateway, set and propogate R-bit.
|
|
|
|
*/
|
|
|
|
if (attr->default_gw)
|
|
|
|
attr->router_flag = 1;
|
|
|
|
|
|
|
|
/* Check EVPN Neighbor advertisement flags, R-bit */
|
|
|
|
bgp_attr_evpn_na_flag(attr, &attr->router_flag);
|
|
|
|
|
2017-10-09 13:55:57 +02:00
|
|
|
/* Extract the Rmac, if any */
|
2019-02-20 01:02:00 +01:00
|
|
|
if (bgp_attr_rmac(attr, &attr->rmac)) {
|
|
|
|
if (bgp_debug_update(peer, NULL, NULL, 1) &&
|
|
|
|
bgp_mac_exist(&attr->rmac)) {
|
|
|
|
char buf1[ETHER_ADDR_STRLEN];
|
|
|
|
|
|
|
|
zlog_debug("%s: router mac %s is self mac",
|
|
|
|
__func__,
|
|
|
|
prefix_mac2str(&attr->rmac, buf1,
|
|
|
|
sizeof(buf1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-10-09 13:55:57 +02:00
|
|
|
|
2019-05-11 19:17:23 +02:00
|
|
|
/* Get the tunnel type from encap extended community */
|
|
|
|
bgp_attr_extcom_tunnel_type(attr,
|
|
|
|
(bgp_encap_types *)&attr->encap_tunneltype);
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:42:01 +01:00
|
|
|
/* Parse Tunnel Encap attribute in an UPDATE */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */
|
|
|
|
bgp_size_t length, /* IN: attr's length field */
|
|
|
|
struct attr *attr, /* IN: caller already allocated */
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t flag, /* IN: attr's flags field */
|
|
|
|
uint8_t *startp)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
bgp_size_t total;
|
|
|
|
uint16_t tunneltype = 0;
|
|
|
|
|
|
|
|
total = length + (CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 4 : 3);
|
|
|
|
|
|
|
|
if (!CHECK_FLAG(flag, BGP_ATTR_FLAG_TRANS)
|
|
|
|
|| !CHECK_FLAG(flag, BGP_ATTR_FLAG_OPTIONAL)) {
|
|
|
|
zlog_info(
|
|
|
|
"Tunnel Encap attribute flag isn't optional and transitive %d",
|
|
|
|
flag);
|
|
|
|
bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
|
|
|
|
startp, total);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BGP_ATTR_ENCAP == type) {
|
|
|
|
/* read outer TLV type and length */
|
|
|
|
uint16_t tlv_length;
|
|
|
|
|
|
|
|
if (length < 4) {
|
|
|
|
zlog_info(
|
|
|
|
"Tunnel Encap attribute not long enough to contain outer T,L");
|
|
|
|
bgp_notify_send_with_data(
|
|
|
|
peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, startp, total);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tunneltype = stream_getw(BGP_INPUT(peer));
|
|
|
|
tlv_length = stream_getw(BGP_INPUT(peer));
|
|
|
|
length -= 4;
|
|
|
|
|
|
|
|
if (tlv_length != length) {
|
|
|
|
zlog_info("%s: tlv_length(%d) != length(%d)", __func__,
|
|
|
|
tlv_length, length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (length >= 4) {
|
|
|
|
uint16_t subtype = 0;
|
|
|
|
uint16_t sublength = 0;
|
|
|
|
struct bgp_attr_encap_subtlv *tlv;
|
|
|
|
|
|
|
|
if (BGP_ATTR_ENCAP == type) {
|
|
|
|
subtype = stream_getc(BGP_INPUT(peer));
|
|
|
|
sublength = stream_getc(BGP_INPUT(peer));
|
|
|
|
length -= 2;
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
|
|
|
subtype = stream_getw(BGP_INPUT(peer));
|
|
|
|
sublength = stream_getw(BGP_INPUT(peer));
|
|
|
|
length -= 4;
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sublength > length) {
|
|
|
|
zlog_info(
|
|
|
|
"Tunnel Encap attribute sub-tlv length %d exceeds remaining length %d",
|
|
|
|
sublength, length);
|
|
|
|
bgp_notify_send_with_data(
|
|
|
|
peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, startp, total);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* alloc and copy sub-tlv */
|
|
|
|
/* TBD make sure these are freed when attributes are released */
|
|
|
|
tlv = XCALLOC(MTYPE_ENCAP_TLV,
|
2018-03-06 20:02:52 +01:00
|
|
|
sizeof(struct bgp_attr_encap_subtlv) + sublength);
|
2017-07-17 14:03:14 +02:00
|
|
|
tlv->type = subtype;
|
|
|
|
tlv->length = sublength;
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_get(tlv->value, peer->curr, sublength);
|
2017-07-17 14:03:14 +02:00
|
|
|
length -= sublength;
|
|
|
|
|
|
|
|
/* attach tlv to encap chain */
|
|
|
|
if (BGP_ATTR_ENCAP == type) {
|
2017-10-09 01:18:09 +02:00
|
|
|
struct bgp_attr_encap_subtlv *stlv_last;
|
2017-07-17 14:03:14 +02:00
|
|
|
for (stlv_last = attr->encap_subtlvs;
|
|
|
|
stlv_last && stlv_last->next;
|
|
|
|
stlv_last = stlv_last->next)
|
|
|
|
;
|
|
|
|
if (stlv_last) {
|
|
|
|
stlv_last->next = tlv;
|
|
|
|
} else {
|
|
|
|
attr->encap_subtlvs = tlv;
|
|
|
|
}
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
2017-10-09 01:18:09 +02:00
|
|
|
struct bgp_attr_encap_subtlv *stlv_last;
|
2017-07-17 14:03:14 +02:00
|
|
|
for (stlv_last = attr->vnc_subtlvs;
|
|
|
|
stlv_last && stlv_last->next;
|
|
|
|
stlv_last = stlv_last->next)
|
|
|
|
;
|
|
|
|
if (stlv_last) {
|
|
|
|
stlv_last->next = tlv;
|
|
|
|
} else {
|
|
|
|
attr->vnc_subtlvs = tlv;
|
|
|
|
}
|
2017-06-06 19:20:38 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (BGP_ATTR_ENCAP == type) {
|
|
|
|
attr->encap_tunneltype = tunneltype;
|
|
|
|
}
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (length) {
|
|
|
|
/* spurious leftover data */
|
|
|
|
zlog_info(
|
|
|
|
"Tunnel Encap attribute length is bad: %d leftover octets",
|
|
|
|
length);
|
|
|
|
bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
startp, total);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2018-05-02 20:03:39 +02:00
|
|
|
/*
|
|
|
|
* Read an individual SID value returning how much data we have read
|
|
|
|
* Returns 0 if there was an error that needs to be passed up the stack
|
2017-04-26 23:45:32 +02:00
|
|
|
*/
|
2018-05-02 20:03:39 +02:00
|
|
|
static bgp_attr_parse_ret_t bgp_attr_psid_sub(int32_t type,
|
|
|
|
int32_t length,
|
|
|
|
struct bgp_attr_parser_args *args,
|
|
|
|
struct bgp_nlri *mp_update)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t label_index;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct in6_addr ipv6_sid;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t srgb_base;
|
|
|
|
uint32_t srgb_range;
|
2017-07-17 14:03:14 +02:00
|
|
|
int srgb_count;
|
|
|
|
|
|
|
|
if (type == BGP_PREFIX_SID_LABEL_INDEX) {
|
|
|
|
if (length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) {
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTR_LEN,
|
2018-06-15 23:08:53 +02:00
|
|
|
"Prefix SID label index length is %d instead of %d",
|
|
|
|
length, BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
|
2018-05-02 20:03:39 +02:00
|
|
|
return bgp_attr_malformed(args,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore flags and reserved */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_getc(peer->curr);
|
|
|
|
stream_getw(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Fetch the label index and see if it is valid. */
|
2017-05-02 02:37:45 +02:00
|
|
|
label_index = stream_getl(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
if (label_index == BGP_INVALID_LABEL_INDEX)
|
2018-05-02 20:03:39 +02:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
args->total);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Store label index; subsequently, we'll check on
|
|
|
|
* address-family */
|
|
|
|
attr->label_index = label_index;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore the Label index attribute unless received for
|
|
|
|
* labeled-unicast
|
|
|
|
* SAFI.
|
|
|
|
*/
|
|
|
|
if (!mp_update->length
|
|
|
|
|| mp_update->safi != SAFI_LABELED_UNICAST)
|
|
|
|
attr->label_index = BGP_INVALID_LABEL_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Placeholder code for the IPv6 SID type */
|
|
|
|
else if (type == BGP_PREFIX_SID_IPV6) {
|
|
|
|
if (length != BGP_PREFIX_SID_IPV6_LENGTH) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Prefix SID IPv6 length is %d instead of %d",
|
|
|
|
length, BGP_PREFIX_SID_IPV6_LENGTH);
|
2018-05-02 20:03:39 +02:00
|
|
|
return bgp_attr_malformed(args,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore reserved */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_getc(peer->curr);
|
|
|
|
stream_getw(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_get(&ipv6_sid, peer->curr, 16);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Placeholder code for the Originator SRGB type */
|
|
|
|
else if (type == BGP_PREFIX_SID_ORIGINATOR_SRGB) {
|
|
|
|
/* Ignore flags */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_getw(peer->curr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
length -= 2;
|
|
|
|
|
|
|
|
if (length % BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH) {
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTR_LEN,
|
2017-07-17 14:03:14 +02:00
|
|
|
"Prefix SID Originator SRGB length is %d, it must be a multiple of %d ",
|
|
|
|
length, BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH);
|
|
|
|
return bgp_attr_malformed(
|
|
|
|
args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
srgb_count = length / BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH;
|
|
|
|
|
|
|
|
for (int i = 0; i < srgb_count; i++) {
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_get(&srgb_base, peer->curr, 3);
|
|
|
|
stream_get(&srgb_range, peer->curr, 3);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2017-03-09 18:22:04 +01:00
|
|
|
}
|
|
|
|
|
2018-05-02 20:03:39 +02:00
|
|
|
/* Prefix SID attribute
|
|
|
|
* draft-ietf-idr-bgp-prefix-sid-05
|
|
|
|
*/
|
|
|
|
bgp_attr_parse_ret_t
|
|
|
|
bgp_attr_prefix_sid(int32_t tlength, struct bgp_attr_parser_args *args,
|
|
|
|
struct bgp_nlri *mp_update)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
bgp_attr_parse_ret_t ret;
|
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID);
|
|
|
|
|
|
|
|
while (tlength) {
|
|
|
|
int32_t type, length;
|
|
|
|
|
|
|
|
type = stream_getc(peer->curr);
|
|
|
|
length = stream_getw(peer->curr);
|
|
|
|
|
|
|
|
ret = bgp_attr_psid_sub(type, length, args, mp_update);
|
|
|
|
|
|
|
|
if (ret != BGP_ATTR_PARSE_PROCEED)
|
|
|
|
return ret;
|
|
|
|
/*
|
|
|
|
* Subtract length + the T and the L
|
|
|
|
* since length is the Vector portion
|
|
|
|
*/
|
|
|
|
tlength -= length + 3;
|
|
|
|
|
|
|
|
if (tlength < 0) {
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTR_LEN,
|
2018-06-15 23:08:53 +02:00
|
|
|
"Prefix SID internal length %d causes us to read beyond the total Prefix SID length",
|
|
|
|
length);
|
2018-05-02 20:03:39 +02:00
|
|
|
return bgp_attr_malformed(args,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
2018-03-04 04:28:50 +01:00
|
|
|
/* PMSI tunnel attribute (RFC 6514)
|
|
|
|
* Basic validation checks done here.
|
|
|
|
*/
|
|
|
|
static bgp_attr_parse_ret_t
|
|
|
|
bgp_attr_pmsi_tunnel(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
|
|
|
const bgp_size_t length = args->length;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t tnl_type;
|
bgpd: parse label in pmsi tunnel attribute
Consider the following topo VTEP1->SPINE1->VTEP2. ebgp is being used
for evpn route exchange with SPINE just acting as a pass through.
1. VTEP1 was building the type-3 IMET route with the correct PMSI
tunnel type (ingress-replication) and label (VNI)
2. Spine1 was however only parsing the tunnel-type in the attr (was
skipping parsing of the label field altogether) -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 227
Last update: Thu Feb 7 15:44:22 2019
PMSI Tunnel Type: Ingress Replication, label: 16777213 >>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3. So VTEP2 didn't rx the correct label.
In an all FRR setup this doesn't have any functional consequence but some
vendors are validating the content of the label field as well and ignoring
the IMET route from FRR (say VTEP1 is FRR and VTEP2 is 3rd-party). The
functional consequence of this VTEP2 ignores VTEP1's IMET route and doesn't
add VTEP1 to the corresponding l2-vni flood list.
This commit fixes up the PMSI attr parsing on spine-1 -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 278
Last update: Thu Feb 7 00:17:40 2019
PMSI Tunnel Type: Ingress Replication, label: 1003 >>>>>>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ticket: CM-23790
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-02-12 21:56:26 +01:00
|
|
|
int attr_parse_len = 2 + BGP_LABEL_BYTES;
|
2018-03-04 04:28:50 +01:00
|
|
|
|
|
|
|
/* Verify that the receiver is expecting "ingress replication" as we
|
|
|
|
* can only support that.
|
|
|
|
*/
|
bgpd: parse label in pmsi tunnel attribute
Consider the following topo VTEP1->SPINE1->VTEP2. ebgp is being used
for evpn route exchange with SPINE just acting as a pass through.
1. VTEP1 was building the type-3 IMET route with the correct PMSI
tunnel type (ingress-replication) and label (VNI)
2. Spine1 was however only parsing the tunnel-type in the attr (was
skipping parsing of the label field altogether) -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 227
Last update: Thu Feb 7 15:44:22 2019
PMSI Tunnel Type: Ingress Replication, label: 16777213 >>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3. So VTEP2 didn't rx the correct label.
In an all FRR setup this doesn't have any functional consequence but some
vendors are validating the content of the label field as well and ignoring
the IMET route from FRR (say VTEP1 is FRR and VTEP2 is 3rd-party). The
functional consequence of this VTEP2 ignores VTEP1's IMET route and doesn't
add VTEP1 to the corresponding l2-vni flood list.
This commit fixes up the PMSI attr parsing on spine-1 -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 278
Last update: Thu Feb 7 00:17:40 2019
PMSI Tunnel Type: Ingress Replication, label: 1003 >>>>>>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ticket: CM-23790
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-02-12 21:56:26 +01:00
|
|
|
if (length < attr_parse_len) {
|
2018-09-13 21:38:57 +02:00
|
|
|
flog_err(EC_BGP_ATTR_LEN, "Bad PMSI tunnel attribute length %d",
|
|
|
|
length);
|
2018-03-04 04:28:50 +01:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
stream_getc(peer->curr); /* Flags */
|
|
|
|
tnl_type = stream_getc(peer->curr);
|
|
|
|
if (tnl_type > PMSI_TNLTYPE_MAX) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_PMSI_TYPE,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Invalid PMSI tunnel attribute type %d", tnl_type);
|
2018-03-04 04:28:50 +01:00
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
if (tnl_type == PMSI_TNLTYPE_INGR_REPL) {
|
|
|
|
if (length != 9) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_err(EC_BGP_ATTR_PMSI_LEN,
|
2018-09-13 21:38:57 +02:00
|
|
|
"Bad PMSI tunnel attribute length %d for IR",
|
|
|
|
length);
|
2018-03-04 07:56:19 +01:00
|
|
|
return bgp_attr_malformed(
|
|
|
|
args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
|
|
|
|
args->total);
|
2018-03-04 04:28:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL);
|
|
|
|
attr->pmsi_tnl_type = tnl_type;
|
bgpd: parse label in pmsi tunnel attribute
Consider the following topo VTEP1->SPINE1->VTEP2. ebgp is being used
for evpn route exchange with SPINE just acting as a pass through.
1. VTEP1 was building the type-3 IMET route with the correct PMSI
tunnel type (ingress-replication) and label (VNI)
2. Spine1 was however only parsing the tunnel-type in the attr (was
skipping parsing of the label field altogether) -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 227
Last update: Thu Feb 7 15:44:22 2019
PMSI Tunnel Type: Ingress Replication, label: 16777213 >>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3. So VTEP2 didn't rx the correct label.
In an all FRR setup this doesn't have any functional consequence but some
vendors are validating the content of the label field as well and ignoring
the IMET route from FRR (say VTEP1 is FRR and VTEP2 is 3rd-party). The
functional consequence of this VTEP2 ignores VTEP1's IMET route and doesn't
add VTEP1 to the corresponding l2-vni flood list.
This commit fixes up the PMSI attr parsing on spine-1 -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 278
Last update: Thu Feb 7 00:17:40 2019
PMSI Tunnel Type: Ingress Replication, label: 1003 >>>>>>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ticket: CM-23790
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-02-12 21:56:26 +01:00
|
|
|
stream_get(&attr->label, peer->curr, BGP_LABEL_BYTES);
|
2018-03-04 04:28:50 +01:00
|
|
|
|
|
|
|
/* Forward read pointer of input stream. */
|
bgpd: parse label in pmsi tunnel attribute
Consider the following topo VTEP1->SPINE1->VTEP2. ebgp is being used
for evpn route exchange with SPINE just acting as a pass through.
1. VTEP1 was building the type-3 IMET route with the correct PMSI
tunnel type (ingress-replication) and label (VNI)
2. Spine1 was however only parsing the tunnel-type in the attr (was
skipping parsing of the label field altogether) -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 227
Last update: Thu Feb 7 15:44:22 2019
PMSI Tunnel Type: Ingress Replication, label: 16777213 >>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
3. So VTEP2 didn't rx the correct label.
In an all FRR setup this doesn't have any functional consequence but some
vendors are validating the content of the label field as well and ignoring
the IMET route from FRR (say VTEP1 is FRR and VTEP2 is 3rd-party). The
functional consequence of this VTEP2 ignores VTEP1's IMET route and doesn't
add VTEP1 to the corresponding l2-vni flood list.
This commit fixes up the PMSI attr parsing on spine-1 -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@MSP1:~# net show bgp l2vpn evpn route rd 27.0.0.15:4 type multicast
EVPN type-2 prefix: [2]:[ESI]:[EthTag]:[MAClen]:[MAC]
EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]
EVPN type-5 prefix: [5]:[ESI]:[EthTag]:[IPlen]:[IP]
BGP routing table entry for 27.0.0.15:4:[3]:[0]:[32]:[27.0.0.15]
Paths: (1 available, best #1)
Advertised to non peer-group peers:
TORC11(downlink-1) TORC12(downlink-2) TORC21(downlink-3) TORC22(downlink-4) TORS1(downlink-5) TORS2(downlink-6)
Route [3]:[0]:[32]:[27.0.0.15]
5550
27.0.0.15 from TORS1(downlink-5) (27.0.0.15)
Origin IGP, valid, external, bestpath-from-AS 5550, best
Extended Community: RT:5550:1003 ET:8
AddPath ID: RX 0, TX 278
Last update: Thu Feb 7 00:17:40 2019
PMSI Tunnel Type: Ingress Replication, label: 1003 >>>>>>>>>>>
Displayed 1 prefixes (1 paths) with this RD (of requested type)
root@MSP1:~#
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Ticket: CM-23790
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-02-12 21:56:26 +01:00
|
|
|
stream_forward_getp(peer->curr, length - attr_parse_len);
|
2018-03-04 04:28:50 +01:00
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* BGP unknown attribute treatment. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args)
|
|
|
|
{
|
|
|
|
bgp_size_t total = args->total;
|
|
|
|
struct transit *transit;
|
|
|
|
struct peer *const peer = args->peer;
|
|
|
|
struct attr *const attr = args->attr;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t *const startp = args->startp;
|
|
|
|
const uint8_t type = args->type;
|
|
|
|
const uint8_t flag = args->flags;
|
2017-07-17 14:03:14 +02:00
|
|
|
const bgp_size_t length = args->length;
|
|
|
|
|
|
|
|
if (bgp_debug_update(peer, NULL, NULL, 1))
|
|
|
|
zlog_debug(
|
|
|
|
"%s Unknown attribute is received (type %d, length %d)",
|
|
|
|
peer->host, type, length);
|
|
|
|
|
|
|
|
/* Forward read pointer of input stream. */
|
2017-05-02 02:37:45 +02:00
|
|
|
stream_forward_getp(peer->curr, length);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* If any of the mandatory well-known attributes are not recognized,
|
|
|
|
then the Error Subcode is set to Unrecognized Well-known
|
|
|
|
Attribute. The Data field contains the unrecognized attribute
|
|
|
|
(type, length and value). */
|
|
|
|
if (!CHECK_FLAG(flag, BGP_ATTR_FLAG_OPTIONAL)) {
|
|
|
|
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_UNREC_ATTR,
|
|
|
|
args->total);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unrecognized non-transitive optional attributes must be quietly
|
|
|
|
ignored and not passed along to other BGP peers. */
|
|
|
|
if (!CHECK_FLAG(flag, BGP_ATTR_FLAG_TRANS))
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
|
|
|
|
/* If a path with recognized transitive optional attribute is
|
|
|
|
accepted and passed along to other BGP peers and the Partial bit
|
|
|
|
in the Attribute Flags octet is set to 1 by some previous AS, it
|
|
|
|
is not set back to 0 by the current AS. */
|
|
|
|
SET_FLAG(*startp, BGP_ATTR_FLAG_PARTIAL);
|
|
|
|
|
|
|
|
/* Store transitive attribute to the end of attr->transit. */
|
|
|
|
if (!attr->transit)
|
|
|
|
attr->transit = XCALLOC(MTYPE_TRANSIT, sizeof(struct transit));
|
|
|
|
|
|
|
|
transit = attr->transit;
|
|
|
|
|
|
|
|
if (transit->val)
|
|
|
|
transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val,
|
|
|
|
transit->length + total);
|
|
|
|
else
|
|
|
|
transit->val = XMALLOC(MTYPE_TRANSIT_VAL, total);
|
|
|
|
|
|
|
|
memcpy(transit->val + transit->length, startp, total);
|
|
|
|
transit->length += total;
|
|
|
|
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2014-09-23 16:23:01 +02:00
|
|
|
/* Well-known attribute check. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int bgp_attr_check(struct peer *peer, struct attr *attr)
|
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t type = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* BGP Graceful-Restart End-of-RIB for IPv4 unicast is signaled as an
|
|
|
|
* empty UPDATE. */
|
|
|
|
if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV) && !attr->flag)
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
|
|
|
|
/* "An UPDATE message that contains the MP_UNREACH_NLRI is not required
|
|
|
|
to carry any other path attributes.", though if MP_REACH_NLRI or NLRI
|
|
|
|
are present, it should. Check for any other attribute being present
|
|
|
|
instead.
|
|
|
|
*/
|
2018-05-25 12:22:14 +02:00
|
|
|
if ((!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) &&
|
|
|
|
CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI))))
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
|
|
|
|
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
|
|
|
|
type = BGP_ATTR_ORIGIN;
|
|
|
|
|
|
|
|
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
|
|
|
|
type = BGP_ATTR_AS_PATH;
|
|
|
|
|
|
|
|
/* RFC 2858 makes Next-Hop optional/ignored, if MP_REACH_NLRI is present
|
|
|
|
* and
|
|
|
|
* NLRI is empty. We can't easily check NLRI empty here though.
|
|
|
|
*/
|
|
|
|
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))
|
|
|
|
&& !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)))
|
|
|
|
type = BGP_ATTR_NEXT_HOP;
|
|
|
|
|
|
|
|
if (peer->sort == BGP_PEER_IBGP
|
|
|
|
&& !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
|
|
|
|
type = BGP_ATTR_LOCAL_PREF;
|
|
|
|
|
|
|
|
if (type) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_warn(EC_BGP_MISSING_ATTRIBUTE,
|
2018-08-15 20:46:27 +02:00
|
|
|
"%s Missing well-known attribute %s.", peer->host,
|
2017-07-17 14:03:14 +02:00
|
|
|
lookup_msg(attr_str, type, NULL));
|
|
|
|
bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MISS_ATTR, &type,
|
|
|
|
1);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
2014-09-23 16:23:01 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Read attribute of update packet. This function is called from
|
2012-11-08 00:50:08 +01:00
|
|
|
bgp_update_receive() in bgp_packet.c. */
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr,
|
|
|
|
bgp_size_t size, struct bgp_nlri *mp_update,
|
|
|
|
struct bgp_nlri *mp_withdraw)
|
|
|
|
{
|
2018-09-12 12:18:44 +02:00
|
|
|
bgp_attr_parse_ret_t ret;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t flag = 0;
|
|
|
|
uint8_t type = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_size_t length;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t *startp, *endp;
|
|
|
|
uint8_t *attr_endp;
|
|
|
|
uint8_t seen[BGP_ATTR_BITMAP_SIZE];
|
2017-07-17 14:03:14 +02:00
|
|
|
/* we need the as4_path only until we have synthesized the as_path with
|
|
|
|
* it */
|
|
|
|
/* same goes for as4_aggregator */
|
|
|
|
struct aspath *as4_path = NULL;
|
|
|
|
as_t as4_aggregator = 0;
|
|
|
|
struct in_addr as4_aggregator_addr = {.s_addr = 0};
|
|
|
|
|
|
|
|
/* Initialize bitmap. */
|
|
|
|
memset(seen, 0, BGP_ATTR_BITMAP_SIZE);
|
|
|
|
|
|
|
|
/* End pointer of BGP attribute. */
|
|
|
|
endp = BGP_INPUT_PNT(peer) + size;
|
|
|
|
|
|
|
|
/* Get attributes to the end of attribute length. */
|
|
|
|
while (BGP_INPUT_PNT(peer) < endp) {
|
|
|
|
/* Check remaining length check.*/
|
|
|
|
if (endp - BGP_INPUT_PNT(peer) < BGP_ATTR_MIN_LEN) {
|
|
|
|
/* XXX warning: long int format, int arg (arg 5) */
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTRIBUTE_TOO_SMALL,
|
2018-08-24 18:26:43 +02:00
|
|
|
"%s: error BGP attribute length %lu is smaller than min len",
|
|
|
|
peer->host,
|
|
|
|
(unsigned long)(endp
|
|
|
|
- stream_pnt(BGP_INPUT(peer))));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Fetch attribute flag and type. */
|
|
|
|
startp = BGP_INPUT_PNT(peer);
|
|
|
|
/* "The lower-order four bits of the Attribute Flags octet are
|
|
|
|
unused. They MUST be zero when sent and MUST be ignored when
|
|
|
|
received." */
|
|
|
|
flag = 0xF0 & stream_getc(BGP_INPUT(peer));
|
|
|
|
type = stream_getc(BGP_INPUT(peer));
|
|
|
|
|
|
|
|
/* Check whether Extended-Length applies and is in bounds */
|
|
|
|
if (CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN)
|
|
|
|
&& ((endp - startp) < (BGP_ATTR_MIN_LEN + 1))) {
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_EXT_ATTRIBUTE_TOO_SMALL,
|
2018-08-24 18:26:43 +02:00
|
|
|
"%s: Extended length set, but just %lu bytes of attr header",
|
|
|
|
peer->host,
|
|
|
|
(unsigned long)(endp
|
|
|
|
- stream_pnt(BGP_INPUT(peer))));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Check extended attribue length bit. */
|
|
|
|
if (CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN))
|
|
|
|
length = stream_getw(BGP_INPUT(peer));
|
|
|
|
else
|
|
|
|
length = stream_getc(BGP_INPUT(peer));
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* If any attribute appears more than once in the UPDATE
|
|
|
|
message, then the Error Subcode is set to Malformed Attribute
|
|
|
|
List. */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (CHECK_BITMAP(seen, type)) {
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTRIBUTE_REPEATED,
|
2018-08-24 18:26:43 +02:00
|
|
|
"%s: error BGP attribute type %d appears twice in a message",
|
|
|
|
peer->host, type);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MAL_ATTR);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set type to bitmap to check duplicate attribute. `type' is
|
|
|
|
unsigned char so it never overflow bitmap range. */
|
|
|
|
|
|
|
|
SET_BITMAP(seen, type);
|
|
|
|
|
|
|
|
/* Overflow check. */
|
|
|
|
attr_endp = BGP_INPUT_PNT(peer) + length;
|
|
|
|
|
|
|
|
if (attr_endp > endp) {
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTRIBUTE_TOO_LARGE,
|
2018-08-24 18:26:43 +02:00
|
|
|
"%s: BGP type %d length %d is too large, attribute total length is %d. attr_endp is %p. endp is %p",
|
|
|
|
peer->host, type, length, size, attr_endp,
|
|
|
|
endp);
|
2017-10-23 22:43:32 +02:00
|
|
|
/*
|
|
|
|
* RFC 4271 6.3
|
|
|
|
* If any recognized attribute has an Attribute
|
|
|
|
* Length that conflicts with the expected length
|
|
|
|
* (based on the attribute type code), then the
|
|
|
|
* Error Subcode MUST be set to Attribute Length
|
|
|
|
* Error. The Data field MUST contain the erroneous
|
|
|
|
* attribute (type, length, and value).
|
|
|
|
* ----------
|
|
|
|
* We do not currently have a good way to determine the
|
|
|
|
* length of the attribute independent of the length
|
|
|
|
* received in the message. Instead we send the
|
|
|
|
* minimum between the amount of data we have and the
|
|
|
|
* amount specified by the attribute length field.
|
|
|
|
*
|
|
|
|
* Instead of directly passing in the packet buffer and
|
|
|
|
* offset we use the stream_get* functions to read into
|
|
|
|
* a stack buffer, since they perform bounds checking
|
|
|
|
* and we are working with untrusted data.
|
|
|
|
*/
|
|
|
|
unsigned char ndata[BGP_MAX_PACKET_SIZE];
|
|
|
|
memset(ndata, 0x00, sizeof(ndata));
|
|
|
|
size_t lfl =
|
|
|
|
CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 2 : 1;
|
|
|
|
/* Rewind to end of flag field */
|
|
|
|
stream_forward_getp(BGP_INPUT(peer), -(1 + lfl));
|
|
|
|
/* Type */
|
|
|
|
stream_get(&ndata[0], BGP_INPUT(peer), 1);
|
|
|
|
/* Length */
|
|
|
|
stream_get(&ndata[1], BGP_INPUT(peer), lfl);
|
|
|
|
/* Value */
|
|
|
|
size_t atl = attr_endp - startp;
|
|
|
|
size_t ndl = MIN(atl, STREAM_READABLE(BGP_INPUT(peer)));
|
|
|
|
stream_get(&ndata[lfl + 1], BGP_INPUT(peer), ndl);
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_notify_send_with_data(
|
|
|
|
peer, BGP_NOTIFY_UPDATE_ERR,
|
2017-10-23 22:43:32 +02:00
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, ndata,
|
|
|
|
ndl + lfl + 1);
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bgp_attr_parser_args attr_args = {
|
|
|
|
.peer = peer,
|
|
|
|
.length = length,
|
|
|
|
.attr = attr,
|
|
|
|
.type = type,
|
|
|
|
.flags = flag,
|
|
|
|
.startp = startp,
|
|
|
|
.total = attr_endp - startp,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* If any recognized attribute has Attribute Flags that conflict
|
|
|
|
with the Attribute Type Code, then the Error Subcode is set
|
|
|
|
to
|
|
|
|
Attribute Flags Error. The Data field contains the erroneous
|
|
|
|
attribute (type, length and value). */
|
|
|
|
if (bgp_attr_flag_invalid(&attr_args)) {
|
|
|
|
ret = bgp_attr_malformed(
|
|
|
|
&attr_args, BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR,
|
|
|
|
attr_args.total);
|
|
|
|
if (ret == BGP_ATTR_PARSE_PROCEED)
|
|
|
|
continue;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK check attribute and store it's value. */
|
|
|
|
switch (type) {
|
|
|
|
case BGP_ATTR_ORIGIN:
|
|
|
|
ret = bgp_attr_origin(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_AS_PATH:
|
|
|
|
ret = bgp_attr_aspath(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_AS4_PATH:
|
|
|
|
ret = bgp_attr_as4_path(&attr_args, &as4_path);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_NEXT_HOP:
|
|
|
|
ret = bgp_attr_nexthop(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_MULTI_EXIT_DISC:
|
|
|
|
ret = bgp_attr_med(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_LOCAL_PREF:
|
|
|
|
ret = bgp_attr_local_pref(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_ATOMIC_AGGREGATE:
|
|
|
|
ret = bgp_attr_atomic(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_AGGREGATOR:
|
|
|
|
ret = bgp_attr_aggregator(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_AS4_AGGREGATOR:
|
|
|
|
ret = bgp_attr_as4_aggregator(&attr_args,
|
|
|
|
&as4_aggregator,
|
|
|
|
&as4_aggregator_addr);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_COMMUNITIES:
|
|
|
|
ret = bgp_attr_community(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_LARGE_COMMUNITIES:
|
|
|
|
ret = bgp_attr_large_community(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_ORIGINATOR_ID:
|
|
|
|
ret = bgp_attr_originator_id(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_CLUSTER_LIST:
|
|
|
|
ret = bgp_attr_cluster_list(&attr_args);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_MP_REACH_NLRI:
|
|
|
|
ret = bgp_mp_reach_parse(&attr_args, mp_update);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_MP_UNREACH_NLRI:
|
|
|
|
ret = bgp_mp_unreach_parse(&attr_args, mp_withdraw);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_EXT_COMMUNITIES:
|
|
|
|
ret = bgp_attr_ext_communities(&attr_args);
|
|
|
|
break;
|
2019-01-07 17:32:54 +01:00
|
|
|
#if ENABLE_BGP_VNC_ATTR
|
2017-07-17 14:03:14 +02:00
|
|
|
case BGP_ATTR_VNC:
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
case BGP_ATTR_ENCAP:
|
|
|
|
ret = bgp_attr_encap(type, peer, length, attr, flag,
|
|
|
|
startp);
|
|
|
|
break;
|
|
|
|
case BGP_ATTR_PREFIX_SID:
|
2018-05-02 20:03:39 +02:00
|
|
|
ret = bgp_attr_prefix_sid(length,
|
|
|
|
&attr_args, mp_update);
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
2018-03-04 04:28:50 +01:00
|
|
|
case BGP_ATTR_PMSI_TUNNEL:
|
|
|
|
ret = bgp_attr_pmsi_tunnel(&attr_args);
|
|
|
|
break;
|
2017-07-17 14:03:14 +02:00
|
|
|
default:
|
|
|
|
ret = bgp_attr_unknown(&attr_args);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == BGP_ATTR_PARSE_ERROR_NOTIFYPLS) {
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MAL_ATTR);
|
|
|
|
ret = BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-10-26 05:07:21 +02:00
|
|
|
if (ret == BGP_ATTR_PARSE_EOR) {
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-25 20:06:59 +02:00
|
|
|
/* If hard error occurred immediately return to the caller. */
|
2017-07-17 14:03:14 +02:00
|
|
|
if (ret == BGP_ATTR_PARSE_ERROR) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_warn(EC_BGP_ATTRIBUTE_PARSE_ERROR,
|
2018-08-15 20:46:27 +02:00
|
|
|
"%s: Attribute %s, parse error", peer->host,
|
2017-07-17 14:03:14 +02:00
|
|
|
lookup_msg(attr_str, type, NULL));
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (ret == BGP_ATTR_PARSE_WITHDRAW) {
|
|
|
|
|
2018-08-24 18:26:43 +02:00
|
|
|
flog_warn(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTRIBUTE_PARSE_WITHDRAW,
|
2017-07-17 14:03:14 +02:00
|
|
|
"%s: Attribute %s, parse error - treating as withdrawal",
|
|
|
|
peer->host, lookup_msg(attr_str, type, NULL));
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the fetched length. */
|
|
|
|
if (BGP_INPUT_PNT(peer) != attr_endp) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_warn(EC_BGP_ATTRIBUTE_FETCH_ERROR,
|
2018-08-15 20:46:27 +02:00
|
|
|
"%s: BGP attribute %s, fetch error",
|
2017-07-17 14:03:14 +02:00
|
|
|
peer->host, lookup_msg(attr_str, type, NULL));
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Check final read pointer is same as end pointer. */
|
|
|
|
if (BGP_INPUT_PNT(peer) != endp) {
|
2018-09-13 20:23:42 +02:00
|
|
|
flog_warn(EC_BGP_ATTRIBUTES_MISMATCH,
|
2018-08-15 20:46:27 +02:00
|
|
|
"%s: BGP attribute %s, length mismatch", peer->host,
|
2017-07-17 14:03:14 +02:00
|
|
|
lookup_msg(attr_str, type, NULL));
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR);
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-05-04 08:22:30 +02:00
|
|
|
/*
|
|
|
|
* RFC4271: If the NEXT_HOP attribute field is syntactically incorrect,
|
|
|
|
* then the Error Subcode MUST be set to Invalid NEXT_HOP Attribute.
|
|
|
|
* This is implemented below and will result in a NOTIFICATION. If the
|
|
|
|
* NEXT_HOP attribute is semantically incorrect, the error SHOULD be
|
|
|
|
* logged, and the route SHOULD be ignored. In this case, a NOTIFICATION
|
|
|
|
* message SHOULD NOT be sent. This is implemented elsewhere.
|
|
|
|
*
|
|
|
|
* RFC4760: An UPDATE message that carries no NLRI, other than the one
|
|
|
|
* encoded in the MP_REACH_NLRI attribute, SHOULD NOT carry the NEXT_HOP
|
|
|
|
* attribute. If such a message contains the NEXT_HOP attribute, the BGP
|
|
|
|
* speaker that receives the message SHOULD ignore this attribute.
|
|
|
|
*/
|
|
|
|
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))
|
|
|
|
&& !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI))) {
|
2019-05-09 09:02:16 +02:00
|
|
|
if (bgp_attr_nexthop_valid(peer, attr) < 0) {
|
2019-05-04 08:22:30 +02:00
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Check all mandatory well-known attributes are present */
|
2018-09-12 12:18:44 +02:00
|
|
|
if ((ret = bgp_attr_check(peer, attr)) < 0) {
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return ret;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this place we can see whether we got AS4_PATH and/or
|
|
|
|
* AS4_AGGREGATOR from a 16Bit peer and act accordingly.
|
|
|
|
* We can not do this before we've read all attributes because
|
|
|
|
* the as4 handling does not say whether AS4_PATH has to be sent
|
|
|
|
* after AS_PATH or not - and when AS4_AGGREGATOR will be send
|
|
|
|
* in relationship to AGGREGATOR.
|
|
|
|
* So, to be defensive, we are not relying on any order and read
|
|
|
|
* all attributes first, including these 32bit ones, and now,
|
|
|
|
* afterwards, we look what and if something is to be done for as4.
|
|
|
|
*
|
|
|
|
* It is possible to not have AS_PATH, e.g. GR EoR and sole
|
|
|
|
* MP_UNREACH_NLRI.
|
|
|
|
*/
|
|
|
|
/* actually... this doesn't ever return failure currently, but
|
|
|
|
* better safe than sorry */
|
|
|
|
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH))
|
|
|
|
&& bgp_attr_munge_as4_attrs(peer, attr, as4_path, as4_aggregator,
|
|
|
|
&as4_aggregator_addr)) {
|
|
|
|
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
|
|
|
|
BGP_NOTIFY_UPDATE_MAL_ATTR);
|
|
|
|
if (as4_path)
|
|
|
|
aspath_unintern(&as4_path);
|
|
|
|
return BGP_ATTR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* At this stage, we have done all fiddling with as4, and the
|
|
|
|
* resulting info is in attr->aggregator resp. attr->aspath
|
|
|
|
* so we can chuck as4_aggregator and as4_path alltogether in
|
|
|
|
* order to save memory
|
|
|
|
*/
|
|
|
|
if (as4_path) {
|
|
|
|
aspath_unintern(&as4_path); /* unintern - it is in the hash */
|
|
|
|
/* The flag that we got this is still there, but that does not
|
|
|
|
* do any trouble
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The "rest" of the code does nothing with as4_aggregator.
|
|
|
|
* there is no memory attached specifically which is not part
|
|
|
|
* of the attr.
|
|
|
|
* so ignoring just means do nothing.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Finally do the checks on the aspath we did not do yet
|
|
|
|
* because we waited for a potentially synthesized aspath.
|
|
|
|
*/
|
|
|
|
if (attr->flag & (ATTR_FLAG_BIT(BGP_ATTR_AS_PATH))) {
|
|
|
|
ret = bgp_attr_aspath_check(peer, attr);
|
|
|
|
if (ret != BGP_ATTR_PARSE_PROCEED)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* Finally intern unknown attribute. */
|
|
|
|
if (attr->transit)
|
|
|
|
attr->transit = transit_intern(attr->transit);
|
|
|
|
if (attr->encap_subtlvs)
|
|
|
|
attr->encap_subtlvs =
|
|
|
|
encap_intern(attr->encap_subtlvs, ENCAP_SUBTLV_TYPE);
|
2016-12-17 23:58:33 +01:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
if (attr->vnc_subtlvs)
|
|
|
|
attr->vnc_subtlvs =
|
|
|
|
encap_intern(attr->vnc_subtlvs, VNC_SUBTLV_TYPE);
|
2016-12-17 23:58:33 +01:00
|
|
|
#endif
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return BGP_ATTR_PARSE_PROCEED;
|
|
|
|
}
|
|
|
|
|
2019-05-11 19:17:23 +02:00
|
|
|
/*
|
|
|
|
* Extract the tunnel type from extended community
|
|
|
|
*/
|
|
|
|
void bgp_attr_extcom_tunnel_type(struct attr *attr,
|
2019-05-15 04:42:05 +02:00
|
|
|
bgp_encap_types *tunnel_type)
|
2019-05-11 19:17:23 +02:00
|
|
|
{
|
|
|
|
struct ecommunity *ecom;
|
|
|
|
int i;
|
|
|
|
if (!attr)
|
2019-05-15 04:42:05 +02:00
|
|
|
return;
|
2019-05-11 19:17:23 +02:00
|
|
|
|
|
|
|
ecom = attr->ecommunity;
|
|
|
|
if (!ecom || !ecom->size)
|
2019-05-15 04:42:05 +02:00
|
|
|
return;
|
2019-05-11 19:17:23 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ecom->size; i++) {
|
|
|
|
uint8_t *pnt;
|
|
|
|
uint8_t type, sub_type;
|
|
|
|
|
|
|
|
pnt = (ecom->val + (i * ECOMMUNITY_SIZE));
|
|
|
|
type = pnt[0];
|
|
|
|
sub_type = pnt[1];
|
|
|
|
if (!(type == ECOMMUNITY_ENCODE_OPAQUE &&
|
|
|
|
sub_type == ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP))
|
|
|
|
continue;
|
|
|
|
*tunnel_type = ((pnt[6] << 8) | pnt[7]);
|
2019-05-15 04:42:05 +02:00
|
|
|
return;
|
2019-05-11 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 04:42:05 +02:00
|
|
|
return;
|
2019-05-11 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
|
|
|
|
safi_t safi, struct bpacket_attr_vec_arr *vecarr,
|
|
|
|
struct attr *attr)
|
|
|
|
{
|
|
|
|
size_t sizep;
|
|
|
|
iana_afi_t pkt_afi;
|
2017-08-01 02:06:40 +02:00
|
|
|
iana_safi_t pkt_safi;
|
2017-07-17 14:03:14 +02:00
|
|
|
afi_t nh_afi;
|
|
|
|
|
|
|
|
/* Set extended bit always to encode the attribute length as 2 bytes */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_EXTLEN);
|
|
|
|
stream_putc(s, BGP_ATTR_MP_REACH_NLRI);
|
|
|
|
sizep = stream_get_endp(s);
|
|
|
|
stream_putw(s, 0); /* Marker: Attribute length. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Convert AFI, SAFI to values for packet. */
|
|
|
|
bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi);
|
|
|
|
|
|
|
|
stream_putw(s, pkt_afi); /* AFI */
|
|
|
|
stream_putc(s, pkt_safi); /* SAFI */
|
|
|
|
|
|
|
|
/* Nexthop AFI */
|
2017-06-07 07:12:39 +02:00
|
|
|
if (afi == AFI_IP
|
|
|
|
&& (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST))
|
2017-07-17 14:03:14 +02:00
|
|
|
nh_afi = peer_cap_enhe(peer, afi, safi) ? AFI_IP6 : AFI_IP;
|
|
|
|
else
|
|
|
|
nh_afi = BGP_NEXTHOP_AFI_FROM_NHLEN(attr->mp_nexthop_len);
|
|
|
|
|
|
|
|
/* Nexthop */
|
|
|
|
bpacket_attr_vec_arr_set_vec(vecarr, BGP_ATTR_VEC_NH, s, attr);
|
|
|
|
switch (nh_afi) {
|
|
|
|
case AFI_IP:
|
|
|
|
switch (safi) {
|
|
|
|
case SAFI_UNICAST:
|
|
|
|
case SAFI_MULTICAST:
|
|
|
|
case SAFI_LABELED_UNICAST:
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_put_ipv4(s, attr->nexthop.s_addr);
|
|
|
|
break;
|
|
|
|
case SAFI_MPLS_VPN:
|
|
|
|
stream_putc(s, 12);
|
|
|
|
stream_putl(s, 0); /* RD = 0, per RFC */
|
|
|
|
stream_putl(s, 0);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global_in, 4);
|
|
|
|
break;
|
|
|
|
case SAFI_ENCAP:
|
|
|
|
case SAFI_EVPN:
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global_in, 4);
|
|
|
|
break;
|
2017-01-23 03:45:30 +01:00
|
|
|
case SAFI_FLOWSPEC:
|
|
|
|
stream_putc(s, 0); /* no nexthop for flowspec */
|
2017-07-17 14:03:14 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AFI_IP6:
|
|
|
|
switch (safi) {
|
|
|
|
case SAFI_UNICAST:
|
|
|
|
case SAFI_MULTICAST:
|
|
|
|
case SAFI_LABELED_UNICAST:
|
|
|
|
case SAFI_EVPN: {
|
|
|
|
if (attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
|
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
stream_put(s, &attr->mp_nexthop_local,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
} else {
|
|
|
|
stream_putc(s, IPV6_MAX_BYTELEN);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case SAFI_MPLS_VPN: {
|
|
|
|
if (attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_IPV6_GLOBAL) {
|
|
|
|
stream_putc(s, 24);
|
|
|
|
stream_putl(s, 0); /* RD = 0, per RFC */
|
|
|
|
stream_putl(s, 0);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
} else if (attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
|
|
|
|
stream_putc(s, 48);
|
|
|
|
stream_putl(s, 0); /* RD = 0, per RFC */
|
|
|
|
stream_putl(s, 0);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
stream_putl(s, 0); /* RD = 0, per RFC */
|
|
|
|
stream_putl(s, 0);
|
|
|
|
stream_put(s, &attr->mp_nexthop_local,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case SAFI_ENCAP:
|
|
|
|
stream_putc(s, IPV6_MAX_BYTELEN);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
break;
|
2017-01-23 03:45:30 +01:00
|
|
|
case SAFI_FLOWSPEC:
|
|
|
|
stream_putc(s, 0); /* no nexthop for flowspec */
|
2017-07-17 14:03:14 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2014-01-15 07:57:57 +01:00
|
|
|
default:
|
2018-03-14 10:33:40 +01:00
|
|
|
if (safi != SAFI_FLOWSPEC)
|
2018-08-03 20:03:29 +02:00
|
|
|
flog_err(
|
2018-09-13 20:23:42 +02:00
|
|
|
EC_BGP_ATTR_NH_SEND_LEN,
|
2018-06-15 23:08:53 +02:00
|
|
|
"Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d",
|
|
|
|
peer->host, afi, safi, attr->mp_nexthop_len);
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SNPA */
|
|
|
|
stream_putc(s, 0);
|
|
|
|
return sizep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
|
|
|
|
struct prefix *p, struct prefix_rd *prd,
|
2018-03-27 21:13:34 +02:00
|
|
|
mpls_label_t *label, uint32_t num_labels,
|
|
|
|
int addpath_encode, uint32_t addpath_tx_id,
|
2017-11-21 11:42:05 +01:00
|
|
|
struct attr *attr)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
if (safi == SAFI_MPLS_VPN) {
|
|
|
|
if (addpath_encode)
|
|
|
|
stream_putl(s, addpath_tx_id);
|
|
|
|
/* Label, RD, Prefix write. */
|
|
|
|
stream_putc(s, p->prefixlen + 88);
|
|
|
|
stream_put(s, label, BGP_LABEL_BYTES);
|
|
|
|
stream_put(s, prd->val, 8);
|
|
|
|
stream_put(s, &p->u.prefix, PSIZE(p->prefixlen));
|
|
|
|
} else if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
|
|
|
|
/* EVPN prefix - contents depend on type */
|
2018-03-06 20:02:52 +01:00
|
|
|
bgp_evpn_encode_prefix(s, p, prd, label, num_labels, attr,
|
|
|
|
addpath_encode, addpath_tx_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
} else if (safi == SAFI_LABELED_UNICAST) {
|
|
|
|
/* Prefix write with label. */
|
|
|
|
stream_put_labeled_prefix(s, p, label);
|
2017-01-23 03:45:30 +01:00
|
|
|
} else if (safi == SAFI_FLOWSPEC) {
|
|
|
|
if (PSIZE (p->prefixlen)+2 < FLOWSPEC_NLRI_SIZELIMIT)
|
|
|
|
stream_putc(s, PSIZE (p->prefixlen)+2);
|
|
|
|
else
|
|
|
|
stream_putw(s, (PSIZE (p->prefixlen)+2)|(0xf<<12));
|
|
|
|
stream_putc(s, 2);/* Filter type */
|
|
|
|
stream_putc(s, p->prefixlen);/* Prefix length */
|
|
|
|
stream_put(s, &p->u.prefix, PSIZE (p->prefixlen));
|
2017-07-17 14:03:14 +02:00
|
|
|
} else
|
|
|
|
stream_put_prefix_addpath(s, p, addpath_encode, addpath_tx_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi, struct prefix *p)
|
|
|
|
{
|
|
|
|
int size = PSIZE(p->prefixlen);
|
|
|
|
if (safi == SAFI_MPLS_VPN)
|
|
|
|
size += 88;
|
|
|
|
else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
|
|
|
|
size += 232; // TODO: Maximum possible for type-2, type-3 and
|
|
|
|
// type-5
|
|
|
|
return size;
|
2014-01-15 07:57:57 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 19:42:01 +01:00
|
|
|
/*
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
* Encodes the tunnel encapsulation attribute,
|
2017-07-17 14:03:14 +02:00
|
|
|
* and with ENABLE_BGP_VNC the VNC attribute which uses
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
* almost the same TLV format
|
2016-01-12 19:42:01 +01:00
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
static void bgp_packet_mpattr_tea(struct bgp *bgp, struct peer *peer,
|
|
|
|
struct stream *s, struct attr *attr,
|
|
|
|
uint8_t attrtype)
|
|
|
|
{
|
|
|
|
unsigned int attrlenfield = 0;
|
|
|
|
unsigned int attrhdrlen = 0;
|
|
|
|
struct bgp_attr_encap_subtlv *subtlvs;
|
|
|
|
struct bgp_attr_encap_subtlv *st;
|
|
|
|
const char *attrname;
|
|
|
|
|
2017-07-22 14:52:33 +02:00
|
|
|
if (!attr || (attrtype == BGP_ATTR_ENCAP
|
|
|
|
&& (!attr->encap_tunneltype
|
|
|
|
|| attr->encap_tunneltype == BGP_ENCAP_TYPE_MPLS)))
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (attrtype) {
|
2016-01-12 19:42:01 +01:00
|
|
|
case BGP_ATTR_ENCAP:
|
2017-07-17 14:03:14 +02:00
|
|
|
attrname = "Tunnel Encap";
|
|
|
|
subtlvs = attr->encap_subtlvs;
|
|
|
|
if (subtlvs == NULL) /* nothing to do */
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* The tunnel encap attr has an "outer" tlv.
|
|
|
|
* T = tunneltype,
|
|
|
|
* L = total length of subtlvs,
|
|
|
|
* V = concatenated subtlvs.
|
|
|
|
*/
|
|
|
|
attrlenfield = 2 + 2; /* T + L */
|
|
|
|
attrhdrlen = 1 + 1; /* subTLV T + L */
|
|
|
|
break;
|
2016-01-12 19:42:01 +01:00
|
|
|
|
2019-01-07 17:32:54 +01:00
|
|
|
#if ENABLE_BGP_VNC_ATTR
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
case BGP_ATTR_VNC:
|
2017-07-17 14:03:14 +02:00
|
|
|
attrname = "VNC";
|
|
|
|
subtlvs = attr->vnc_subtlvs;
|
|
|
|
if (subtlvs == NULL) /* nothing to do */
|
|
|
|
return;
|
|
|
|
attrlenfield = 0; /* no outer T + L */
|
|
|
|
attrhdrlen = 2 + 2; /* subTLV T + L */
|
|
|
|
break;
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
|
|
|
|
2016-01-12 19:42:01 +01:00
|
|
|
default:
|
2017-07-17 14:03:14 +02:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute attr length */
|
|
|
|
for (st = subtlvs; st; st = st->next) {
|
|
|
|
attrlenfield += (attrhdrlen + st->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrlenfield > 0xffff) {
|
|
|
|
zlog_info("%s attribute is too long (length=%d), can't send it",
|
|
|
|
attrname, attrlenfield);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrlenfield > 0xff) {
|
|
|
|
/* 2-octet length field */
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, attrtype);
|
|
|
|
stream_putw(s, attrlenfield & 0xffff);
|
|
|
|
} else {
|
|
|
|
/* 1-octet length field */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, attrtype);
|
|
|
|
stream_putc(s, attrlenfield & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attrtype == BGP_ATTR_ENCAP) {
|
|
|
|
/* write outer T+L */
|
|
|
|
stream_putw(s, attr->encap_tunneltype);
|
|
|
|
stream_putw(s, attrlenfield - 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write each sub-tlv */
|
|
|
|
for (st = subtlvs; st; st = st->next) {
|
|
|
|
if (attrtype == BGP_ATTR_ENCAP) {
|
|
|
|
stream_putc(s, st->type);
|
|
|
|
stream_putc(s, st->length);
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#if ENABLE_BGP_VNC
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
|
|
|
stream_putw(s, st->type);
|
|
|
|
stream_putw(s, st->length);
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
stream_put(s, st->value, st->length);
|
|
|
|
}
|
2016-01-12 19:42:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_packet_mpattr_end(struct stream *s, size_t sizep)
|
2014-01-15 07:57:57 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set MP attribute length. Don't count the (2) bytes used to encode
|
|
|
|
the attr length */
|
|
|
|
stream_putw_at(s, sizep, (stream_get_endp(s) - sizep) - 2);
|
2014-01-15 07:57:57 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:36:31 +01:00
|
|
|
static int bgp_append_local_as(struct peer *peer, afi_t afi, safi_t safi)
|
|
|
|
{
|
|
|
|
if (!BGP_AS_IS_PRIVATE(peer->local_as)
|
|
|
|
|| (BGP_AS_IS_PRIVATE(peer->local_as)
|
|
|
|
&& !CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_REMOVE_PRIVATE_AS)
|
|
|
|
&& !CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_REMOVE_PRIVATE_AS_ALL)
|
|
|
|
&& !CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)
|
|
|
|
&& !CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make attribute packet. */
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
|
|
|
|
struct stream *s, struct attr *attr,
|
|
|
|
struct bpacket_attr_vec_arr *vecarr,
|
|
|
|
struct prefix *p, afi_t afi, safi_t safi,
|
|
|
|
struct peer *from, struct prefix_rd *prd,
|
2018-03-27 21:13:34 +02:00
|
|
|
mpls_label_t *label, uint32_t num_labels,
|
|
|
|
int addpath_encode, uint32_t addpath_tx_id)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
|
|
|
size_t cp;
|
|
|
|
size_t aspath_sizep;
|
|
|
|
struct aspath *aspath;
|
|
|
|
int send_as4_path = 0;
|
|
|
|
int send_as4_aggregator = 0;
|
|
|
|
int use32bit = (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!bgp)
|
|
|
|
bgp = peer->bgp;
|
|
|
|
|
|
|
|
/* Remember current pointer. */
|
|
|
|
cp = stream_get_endp(s);
|
|
|
|
|
|
|
|
if (p
|
|
|
|
&& !((afi == AFI_IP && safi == SAFI_UNICAST)
|
|
|
|
&& !peer_cap_enhe(peer, afi, safi))) {
|
|
|
|
size_t mpattrlen_pos = 0;
|
|
|
|
|
|
|
|
mpattrlen_pos = bgp_packet_mpattr_start(s, peer, afi, safi,
|
|
|
|
vecarr, attr);
|
2018-03-06 20:02:52 +01:00
|
|
|
bgp_packet_mpattr_prefix(s, afi, safi, p, prd, label,
|
|
|
|
num_labels, addpath_encode,
|
|
|
|
addpath_tx_id, attr);
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_packet_mpattr_end(s, mpattrlen_pos);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Origin attribute. */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_ORIGIN);
|
|
|
|
stream_putc(s, 1);
|
|
|
|
stream_putc(s, attr->origin);
|
|
|
|
|
|
|
|
/* AS path attribute. */
|
|
|
|
|
|
|
|
/* If remote-peer is EBGP */
|
|
|
|
if (peer->sort == BGP_PEER_EBGP
|
|
|
|
&& (!CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_AS_PATH_UNCHANGED)
|
|
|
|
|| attr->aspath->segments == NULL)
|
|
|
|
&& (!CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_RSERVER_CLIENT))) {
|
|
|
|
aspath = aspath_dup(attr->aspath);
|
|
|
|
|
|
|
|
/* Even though we may not be configured for confederations we
|
|
|
|
* may have
|
|
|
|
* RXed an AS_PATH with AS_CONFED_SEQUENCE or AS_CONFED_SET */
|
|
|
|
aspath = aspath_delete_confed_seq(aspath);
|
|
|
|
|
|
|
|
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
|
|
|
|
/* Stuff our path CONFED_ID on the front */
|
|
|
|
aspath = aspath_add_seq(aspath, bgp->confed_id);
|
|
|
|
} else {
|
|
|
|
if (peer->change_local_as) {
|
|
|
|
/* If replace-as is specified, we only use the
|
|
|
|
change_local_as when
|
|
|
|
advertising routes. */
|
2019-03-02 21:36:31 +01:00
|
|
|
if (!CHECK_FLAG(peer->flags,
|
|
|
|
PEER_FLAG_LOCAL_AS_REPLACE_AS))
|
|
|
|
if (bgp_append_local_as(peer, afi,
|
|
|
|
safi))
|
|
|
|
aspath = aspath_add_seq(
|
|
|
|
aspath, peer->local_as);
|
2017-07-17 14:03:14 +02:00
|
|
|
aspath = aspath_add_seq(aspath,
|
|
|
|
peer->change_local_as);
|
|
|
|
} else {
|
|
|
|
aspath = aspath_add_seq(aspath, peer->local_as);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (peer->sort == BGP_PEER_CONFED) {
|
|
|
|
/* A confed member, so we need to do the AS_CONFED_SEQUENCE
|
|
|
|
* thing */
|
|
|
|
aspath = aspath_dup(attr->aspath);
|
|
|
|
aspath = aspath_add_confed_seq(aspath, peer->local_as);
|
|
|
|
} else
|
|
|
|
aspath = attr->aspath;
|
|
|
|
|
|
|
|
/* If peer is not AS4 capable, then:
|
|
|
|
* - send the created AS_PATH out as AS4_PATH (optional, transitive),
|
|
|
|
* but ensure that no AS_CONFED_SEQUENCE and AS_CONFED_SET path
|
|
|
|
* segment
|
|
|
|
* types are in it (i.e. exclude them if they are there)
|
|
|
|
* AND do this only if there is at least one asnum > 65535 in the
|
|
|
|
* path!
|
|
|
|
* - send an AS_PATH out, but put 16Bit ASnums in it, not 32bit, and
|
|
|
|
* change
|
|
|
|
* all ASnums > 65535 to BGP_AS_TRANS
|
|
|
|
*/
|
|
|
|
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN);
|
|
|
|
stream_putc(s, BGP_ATTR_AS_PATH);
|
|
|
|
aspath_sizep = stream_get_endp(s);
|
|
|
|
stream_putw(s, 0);
|
|
|
|
stream_putw_at(s, aspath_sizep, aspath_put(s, aspath, use32bit));
|
|
|
|
|
|
|
|
/* OLD session may need NEW_AS_PATH sent, if there are 4-byte ASNs
|
|
|
|
* in the path
|
|
|
|
*/
|
|
|
|
if (!use32bit && aspath_has_as4(aspath))
|
|
|
|
send_as4_path =
|
|
|
|
1; /* we'll do this later, at the correct place */
|
|
|
|
|
|
|
|
/* Nexthop attribute. */
|
|
|
|
if (afi == AFI_IP && safi == SAFI_UNICAST
|
|
|
|
&& !peer_cap_enhe(peer, afi, safi)) {
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_NEXT_HOP);
|
|
|
|
bpacket_attr_vec_arr_set_vec(vecarr, BGP_ATTR_VEC_NH, s,
|
|
|
|
attr);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_put_ipv4(s, attr->nexthop.s_addr);
|
|
|
|
} else if (peer_cap_enhe(from, afi, safi)) {
|
|
|
|
/*
|
|
|
|
* Likely this is the case when an IPv4 prefix was
|
|
|
|
* received with
|
|
|
|
* Extended Next-hop capability and now being advertised
|
|
|
|
* to
|
|
|
|
* non-ENHE peers.
|
|
|
|
* Setting the mandatory (ipv4) next-hop attribute here
|
|
|
|
* to enable
|
|
|
|
* implicit next-hop self with correct (ipv4 address
|
|
|
|
* family).
|
|
|
|
*/
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_NEXT_HOP);
|
|
|
|
bpacket_attr_vec_arr_set_vec(vecarr, BGP_ATTR_VEC_NH, s,
|
|
|
|
NULL);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_put_ipv4(s, 0);
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* MED attribute. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)
|
|
|
|
|| bgp->maxmed_active) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, BGP_ATTR_MULTI_EXIT_DISC);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_putl(s, (bgp->maxmed_active ? bgp->maxmed_value
|
|
|
|
: attr->med));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Local preference. */
|
|
|
|
if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_LOCAL_PREF);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_putl(s, attr->local_pref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic aggregate. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_ATOMIC_AGGREGATE);
|
|
|
|
stream_putc(s, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Aggregator. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)) {
|
|
|
|
/* Common to BGP_ATTR_AGGREGATOR, regardless of ASN size */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_AGGREGATOR);
|
|
|
|
|
|
|
|
if (use32bit) {
|
|
|
|
/* AS4 capable peer */
|
|
|
|
stream_putc(s, 8);
|
|
|
|
stream_putl(s, attr->aggregator_as);
|
|
|
|
} else {
|
|
|
|
/* 2-byte AS peer */
|
|
|
|
stream_putc(s, 6);
|
|
|
|
|
|
|
|
/* Is ASN representable in 2-bytes? Or must AS_TRANS be
|
|
|
|
* used? */
|
|
|
|
if (attr->aggregator_as > 65535) {
|
|
|
|
stream_putw(s, BGP_AS_TRANS);
|
|
|
|
|
|
|
|
/* we have to send AS4_AGGREGATOR, too.
|
|
|
|
* we'll do that later in order to send
|
|
|
|
* attributes in ascending
|
|
|
|
* order.
|
|
|
|
*/
|
|
|
|
send_as4_aggregator = 1;
|
|
|
|
} else
|
2018-03-27 21:13:34 +02:00
|
|
|
stream_putw(s, (uint16_t)attr->aggregator_as);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
stream_put_ipv4(s, attr->aggregator_addr.s_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Community attribute. */
|
|
|
|
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY)
|
|
|
|
&& (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) {
|
|
|
|
if (attr->community->size * 4 > 255) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_COMMUNITIES);
|
|
|
|
stream_putw(s, attr->community->size * 4);
|
|
|
|
} else {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_COMMUNITIES);
|
|
|
|
stream_putc(s, attr->community->size * 4);
|
2004-05-20 12:20:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_put(s, attr->community->val, attr->community->size * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Large Community attribute.
|
|
|
|
*/
|
|
|
|
if (CHECK_FLAG(peer->af_flags[afi][safi],
|
|
|
|
PEER_FLAG_SEND_LARGE_COMMUNITY)
|
|
|
|
&& (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) {
|
2017-08-30 07:53:37 +02:00
|
|
|
if (lcom_length(attr->lcommunity) > 255) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
|
2017-08-30 07:53:37 +02:00
|
|
|
stream_putw(s, lcom_length(attr->lcommunity));
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
|
2017-08-30 07:53:37 +02:00
|
|
|
stream_putc(s, lcom_length(attr->lcommunity));
|
2004-05-20 12:20:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_put(s, attr->lcommunity->val,
|
2017-08-30 07:53:37 +02:00
|
|
|
lcom_length(attr->lcommunity));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2004-05-20 12:20:02 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Route Reflector. */
|
|
|
|
if (peer->sort == BGP_PEER_IBGP && from
|
|
|
|
&& from->sort == BGP_PEER_IBGP) {
|
|
|
|
/* Originator ID. */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, BGP_ATTR_ORIGINATOR_ID);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
|
|
|
|
stream_put_in_addr(s, &attr->originator_id);
|
|
|
|
else
|
|
|
|
stream_put_in_addr(s, &from->remote_id);
|
|
|
|
|
|
|
|
/* Cluster list. */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, BGP_ATTR_CLUSTER_LIST);
|
|
|
|
|
|
|
|
if (attr->cluster) {
|
|
|
|
stream_putc(s, attr->cluster->length + 4);
|
|
|
|
/* If this peer configuration's parent BGP has
|
|
|
|
* cluster_id. */
|
|
|
|
if (bgp->config & BGP_CONFIG_CLUSTER_ID)
|
|
|
|
stream_put_in_addr(s, &bgp->cluster_id);
|
|
|
|
else
|
|
|
|
stream_put_in_addr(s, &bgp->router_id);
|
|
|
|
stream_put(s, attr->cluster->list,
|
|
|
|
attr->cluster->length);
|
|
|
|
} else {
|
|
|
|
stream_putc(s, 4);
|
|
|
|
/* If this peer configuration's parent BGP has
|
|
|
|
* cluster_id. */
|
|
|
|
if (bgp->config & BGP_CONFIG_CLUSTER_ID)
|
|
|
|
stream_put_in_addr(s, &bgp->cluster_id);
|
|
|
|
else
|
|
|
|
stream_put_in_addr(s, &bgp->router_id);
|
|
|
|
}
|
|
|
|
}
|
2004-05-20 12:20:02 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Extended Communities attribute. */
|
|
|
|
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
|
|
|
|
&& (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
|
|
|
|
if (peer->sort == BGP_PEER_IBGP
|
|
|
|
|| peer->sort == BGP_PEER_CONFED) {
|
|
|
|
if (attr->ecommunity->size * 8 > 255) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
stream_putw(s, attr->ecommunity->size * 8);
|
|
|
|
} else {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
stream_putc(s, attr->ecommunity->size * 8);
|
|
|
|
}
|
|
|
|
stream_put(s, attr->ecommunity->val,
|
|
|
|
attr->ecommunity->size * 8);
|
|
|
|
} else {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t *pnt;
|
2017-07-17 14:03:14 +02:00
|
|
|
int tbit;
|
|
|
|
int ecom_tr_size = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < attr->ecommunity->size; i++) {
|
|
|
|
pnt = attr->ecommunity->val + (i * 8);
|
|
|
|
tbit = *pnt;
|
|
|
|
|
|
|
|
if (CHECK_FLAG(tbit,
|
|
|
|
ECOMMUNITY_FLAG_NON_TRANSITIVE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ecom_tr_size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ecom_tr_size) {
|
|
|
|
if (ecom_tr_size * 8 > 255) {
|
|
|
|
stream_putc(
|
|
|
|
s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
stream_putw(s, ecom_tr_size * 8);
|
|
|
|
} else {
|
|
|
|
stream_putc(
|
|
|
|
s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_EXT_COMMUNITIES);
|
|
|
|
stream_putc(s, ecom_tr_size * 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < attr->ecommunity->size; i++) {
|
|
|
|
pnt = attr->ecommunity->val + (i * 8);
|
|
|
|
tbit = *pnt;
|
|
|
|
|
|
|
|
if (CHECK_FLAG(
|
|
|
|
tbit,
|
|
|
|
ECOMMUNITY_FLAG_NON_TRANSITIVE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stream_put(s, pnt, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-20 12:20:02 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Label index attribute. */
|
|
|
|
if (safi == SAFI_LABELED_UNICAST) {
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t label_index;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
label_index = attr->label_index;
|
|
|
|
|
|
|
|
if (label_index != BGP_INVALID_LABEL_INDEX) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_PREFIX_SID);
|
|
|
|
stream_putc(s, 10);
|
|
|
|
stream_putc(s, BGP_PREFIX_SID_LABEL_INDEX);
|
|
|
|
stream_putw(s,
|
|
|
|
BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
|
|
|
|
stream_putc(s, 0); // reserved
|
|
|
|
stream_putw(s, 0); // flags
|
|
|
|
stream_putl(s, label_index);
|
|
|
|
}
|
2004-05-20 12:20:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (send_as4_path) {
|
|
|
|
/* If the peer is NOT As4 capable, AND */
|
|
|
|
/* there are ASnums > 65535 in path THEN
|
|
|
|
* give out AS4_PATH */
|
|
|
|
|
|
|
|
/* Get rid of all AS_CONFED_SEQUENCE and AS_CONFED_SET
|
|
|
|
* path segments!
|
|
|
|
* Hm, I wonder... confederation things *should* only be at
|
|
|
|
* the beginning of an aspath, right? Then we should use
|
|
|
|
* aspath_delete_confed_seq for this, because it is already
|
|
|
|
* there! (JK)
|
|
|
|
* Folks, talk to me: what is reasonable here!?
|
|
|
|
*/
|
|
|
|
aspath = aspath_delete_confed_seq(aspath);
|
|
|
|
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_AS4_PATH);
|
|
|
|
aspath_sizep = stream_get_endp(s);
|
|
|
|
stream_putw(s, 0);
|
|
|
|
stream_putw_at(s, aspath_sizep, aspath_put(s, aspath, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aspath != attr->aspath)
|
|
|
|
aspath_free(aspath);
|
|
|
|
|
|
|
|
if (send_as4_aggregator) {
|
|
|
|
/* send AS4_AGGREGATOR, at this place */
|
|
|
|
/* this section of code moved here in order to ensure the
|
|
|
|
* correct
|
|
|
|
* *ascending* order of attributes
|
|
|
|
*/
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_AS4_AGGREGATOR);
|
|
|
|
stream_putc(s, 8);
|
|
|
|
stream_putl(s, attr->aggregator_as);
|
|
|
|
stream_put_ipv4(s, attr->aggregator_addr.s_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((afi == AFI_IP || afi == AFI_IP6)
|
|
|
|
&& (safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN))
|
|
|
|
|| (afi == AFI_L2VPN && safi == SAFI_EVPN)) {
|
|
|
|
/* Tunnel Encap attribute */
|
|
|
|
bgp_packet_mpattr_tea(bgp, peer, s, attr, BGP_ATTR_ENCAP);
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
|
2019-01-07 17:32:54 +01:00
|
|
|
#if ENABLE_BGP_VNC_ATTR
|
2017-07-17 14:03:14 +02:00
|
|
|
/* VNC attribute */
|
|
|
|
bgp_packet_mpattr_tea(bgp, peer, s, attr, BGP_ATTR_VNC);
|
bgpd: add L3/L2VPN Virtual Network Control feature
This feature adds an L3 & L2 VPN application that makes use of the VPN
and Encap SAFIs. This code is currently used to support IETF NVO3 style
operation. In NVO3 terminology it provides the Network Virtualization
Authority (NVA) and the ability to import/export IP prefixes and MAC
addresses from Network Virtualization Edges (NVEs). The code supports
per-NVE tables.
The NVE-NVA protocol used to communicate routing and Ethernet / Layer 2
(L2) forwarding information between NVAs and NVEs is referred to as the
Remote Forwarder Protocol (RFP). OpenFlow is an example RFP. For
general background on NVO3 and RFP concepts see [1]. For information on
Openflow see [2].
RFPs are integrated with BGP via the RF API contained in the new "rfapi"
BGP sub-directory. Currently, only a simple example RFP is included in
Quagga. Developers may use this example as a starting point to integrate
Quagga with an RFP of their choosing, e.g., OpenFlow. The RFAPI code
also supports the ability import/export of routing information between
VNC and customer edge routers (CEs) operating within a virtual
network. Import/export may take place between BGP views or to the
default zebera VRF.
BGP, with IP VPNs and Tunnel Encapsulation, is used to distribute VPN
information between NVAs. BGP based IP VPN support is defined in
RFC4364, BGP/MPLS IP Virtual Private Networks (VPNs), and RFC4659,
BGP-MPLS IP Virtual Private Network (VPN) Extension for IPv6 VPN . Use
of both the Encapsulation Subsequent Address Family Identifier (SAFI)
and the Tunnel Encapsulation Attribute, RFC5512, The BGP Encapsulation
Subsequent Address Family Identifier (SAFI) and the BGP Tunnel
Encapsulation Attribute, are supported. MAC address distribution does
not follow any standard BGB encoding, although it was inspired by the
early IETF EVPN concepts.
The feature is conditionally compiled and disabled by default.
Use the --enable-bgp-vnc configure option to enable.
The majority of this code was authored by G. Paul Ziemba
<paulz@labn.net>.
[1] http://tools.ietf.org/html/draft-ietf-nvo3-nve-nva-cp-req
[2] https://www.opennetworking.org/sdn-resources/technical-library
Now includes changes needed to merge with cmaster-next.
2016-05-07 20:18:56 +02:00
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2016-01-12 19:42:02 +01:00
|
|
|
|
2018-01-04 12:34:24 +01:00
|
|
|
/* PMSI Tunnel */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_PMSI_TUNNEL);
|
|
|
|
stream_putc(s, 9); // Length
|
|
|
|
stream_putc(s, 0); // Flags
|
2019-02-12 21:51:49 +01:00
|
|
|
stream_putc(s, attr->pmsi_tnl_type);
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_put(s, &(attr->label),
|
|
|
|
BGP_LABEL_BYTES); // MPLS Label / VXLAN VNI
|
2018-03-06 20:10:38 +01:00
|
|
|
stream_put_ipv4(s, attr->nexthop.s_addr);
|
|
|
|
// Unicast tunnel endpoint IP address
|
2018-01-04 12:34:24 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Unknown transit attribute. */
|
|
|
|
if (attr->transit)
|
|
|
|
stream_put(s, attr->transit->val, attr->transit->length);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Return total size of attribute. */
|
|
|
|
return stream_get_endp(s) - cp;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, safi_t safi)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
unsigned long attrlen_pnt;
|
|
|
|
iana_afi_t pkt_afi;
|
2017-08-01 02:06:40 +02:00
|
|
|
iana_safi_t pkt_safi;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set extended bit always to encode the attribute length as 2 bytes */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_EXTLEN);
|
|
|
|
stream_putc(s, BGP_ATTR_MP_UNREACH_NLRI);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
attrlen_pnt = stream_get_endp(s);
|
|
|
|
stream_putw(s, 0); /* Length of this attribute. */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Convert AFI, SAFI to values for packet. */
|
|
|
|
bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi);
|
2016-06-15 19:25:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putw(s, pkt_afi);
|
|
|
|
stream_putc(s, pkt_safi);
|
2016-06-15 19:25:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return attrlen_pnt;
|
2014-01-15 07:57:57 +01:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p, afi_t afi,
|
|
|
|
safi_t safi, struct prefix_rd *prd,
|
2018-03-27 21:13:34 +02:00
|
|
|
mpls_label_t *label, uint32_t num_labels,
|
|
|
|
int addpath_encode, uint32_t addpath_tx_id,
|
2017-11-21 11:42:05 +01:00
|
|
|
struct attr *attr)
|
2014-01-15 07:57:57 +01:00
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t wlabel[3] = {0x80, 0x00, 0x00};
|
2017-03-09 15:54:20 +01:00
|
|
|
|
2017-11-21 11:42:05 +01:00
|
|
|
if (safi == SAFI_LABELED_UNICAST) {
|
2017-07-17 14:03:14 +02:00
|
|
|
label = (mpls_label_t *)wlabel;
|
2017-11-21 11:42:05 +01:00
|
|
|
num_labels = 1;
|
|
|
|
}
|
2017-03-09 15:54:20 +01:00
|
|
|
|
2018-11-20 16:30:20 +01:00
|
|
|
bgp_packet_mpattr_prefix(s, afi, safi, p, prd, label, num_labels,
|
|
|
|
addpath_encode, addpath_tx_id, attr);
|
2014-01-15 07:57:57 +01:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt)
|
2014-01-15 07:57:57 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
bgp_packet_mpattr_end(s, attrlen_pnt);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization of attribute. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_init(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
aspath_init();
|
|
|
|
attrhash_init();
|
|
|
|
community_init();
|
|
|
|
ecommunity_init();
|
|
|
|
lcommunity_init();
|
|
|
|
cluster_init();
|
|
|
|
transit_init();
|
|
|
|
encap_init();
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_attr_finish(void)
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
aspath_finish();
|
|
|
|
attrhash_finish();
|
|
|
|
community_finish();
|
|
|
|
ecommunity_finish();
|
|
|
|
lcommunity_finish();
|
|
|
|
cluster_finish();
|
|
|
|
transit_finish();
|
|
|
|
encap_finish();
|
[bgpd] Stability fixes including bugs 397, 492
I've spent the last several weeks working on stability fixes to bgpd.
These patches fix all of the numerous crashes, assertion failures, memory
leaks and memory stomping I could find. Valgrind was used extensively.
Added new function bgp_exit() to help catch problems. If "debug bgp" is
configured and bgpd exits with status of 0, statistics on remaining
lib/memory.c allocations are printed to stderr. It is my hope that other
developers will use this to stay on top of memory issues.
Example questionable exit:
bgpd: memstats: Current memory utilization in module LIB:
bgpd: memstats: Link List : 6
bgpd: memstats: Link Node : 5
bgpd: memstats: Hash : 8
bgpd: memstats: Hash Bucket : 2
bgpd: memstats: Hash Index : 8
bgpd: memstats: Work queue : 3
bgpd: memstats: Work queue item : 2
bgpd: memstats: Work queue name string : 3
bgpd: memstats: Current memory utilization in module BGP:
bgpd: memstats: BGP instance : 1
bgpd: memstats: BGP peer : 1
bgpd: memstats: BGP peer hostname : 1
bgpd: memstats: BGP attribute : 1
bgpd: memstats: BGP extra attributes : 1
bgpd: memstats: BGP aspath : 1
bgpd: memstats: BGP aspath str : 1
bgpd: memstats: BGP table : 24
bgpd: memstats: BGP node : 1
bgpd: memstats: BGP route : 1
bgpd: memstats: BGP synchronise : 8
bgpd: memstats: BGP Process queue : 1
bgpd: memstats: BGP node clear queue : 1
bgpd: memstats: NOTE: If configuration exists, utilization may be expected.
Example clean exit:
bgpd: memstats: No remaining tracked memory utilization.
This patch fixes bug #397: "Invalid free in bgp_announce_check()".
This patch fixes bug #492: "SIGBUS in bgpd/bgp_route.c:
bgp_clear_route_node()".
My apologies for not separating out these changes into individual patches.
The complexity of doing so boggled what is left of my brain. I hope this
is all still useful to the community.
This code has been production tested, in non-route-server-client mode, on
a linux 32-bit box and a 64-bit box.
Release/reset functions, used by bgp_exit(), added to:
bgpd/bgp_attr.c,h
bgpd/bgp_community.c,h
bgpd/bgp_dump.c,h
bgpd/bgp_ecommunity.c,h
bgpd/bgp_filter.c,h
bgpd/bgp_nexthop.c,h
bgpd/bgp_route.c,h
lib/routemap.c,h
File by file analysis:
* bgpd/bgp_aspath.c: Prevent re-use of ashash after it is released.
* bgpd/bgp_attr.c: #if removed uncalled cluster_dup().
* bgpd/bgp_clist.c,h: Allow community_list_terminate() to be called from
bgp_exit().
* bgpd/bgp_filter.c: Fix aslist->name use without allocation check, and
also fix memory leak.
* bgpd/bgp_main.c: Created bgp_exit() exit routine. This function frees
allocations made as part of bgpd initialization and, to some extent,
configuration. If "debug bgp" is configured, memory stats are printed
as described above.
* bgpd/bgp_nexthop.c: zclient_new() already allocates stream for
ibuf/obuf, so bgp_scan_init() shouldn't do it too. Also, made it so
zlookup is global so bgp_exit() can use it.
* bgpd/bgp_packet.c: bgp_capability_msg_parse() call to bgp_clear_route()
adjusted to use new BGP_CLEAR_ROUTE_NORMAL flag.
* bgpd/bgp_route.h: Correct reference counter "lock" to be signed.
bgp_clear_route() now accepts a bgp_clear_route_type of either
BGP_CLEAR_ROUTE_NORMAL or BGP_CLEAR_ROUTE_MY_RSCLIENT.
* bgpd/bgp_route.c:
- bgp_process_rsclient(): attr was being zero'ed and then
bgp_attr_extra_free() was being called with it, even though it was
never filled with valid data.
- bgp_process_rsclient(): Make sure rsclient->group is not NULL before
use.
- bgp_processq_del(): Add call to bgp_table_unlock().
- bgp_process(): Add call to bgp_table_lock().
- bgp_update_rsclient(): memset clearing of new_attr not needed since
declarationw with "= { 0 }" does it. memset was already commented
out.
- bgp_update_rsclient(): Fix screwed up misleading indentation.
- bgp_withdraw_rsclient(): Fix screwed up misleading indentation.
- bgp_clear_route_node(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_node_queue_del(): Add call to bgp_table_unlock() and also
free struct bgp_clear_node_queue used for work item.
- bgp_clear_node_complete(): Do peer_unlock() after BGP_EVENT_ADD() in
case peer is released by peer_unlock() call.
- bgp_clear_route_table(): Support BGP_CLEAR_ROUTE_MY_RSCLIENT. Use
struct bgp_clear_node_queue to supply data to worker. Add call to
bgp_table_lock().
- bgp_clear_route(): Add support for BGP_CLEAR_ROUTE_NORMAL or
BGP_CLEAR_ROUTE_MY_RSCLIENT.
- bgp_clear_route_all(): Use BGP_CLEAR_ROUTE_NORMAL.
Bug 397 fixes:
- bgp_default_originate()
- bgp_announce_table()
* bgpd/bgp_table.h:
- struct bgp_table: Added reference count. Changed type of owner to be
"struct peer *" rather than "void *".
- struct bgp_node: Correct reference counter "lock" to be signed.
* bgpd/bgp_table.c:
- Added bgp_table reference counting.
- bgp_table_free(): Fixed cleanup code. Call peer_unlock() on owner if
set.
- bgp_unlock_node(): Added assertion.
- bgp_node_get(): Added call to bgp_lock_node() to code path that it was
missing from.
* bgpd/bgp_vty.c:
- peer_rsclient_set_vty(): Call peer_lock() as part of peer assignment
to owner. Handle failure gracefully.
- peer_rsclient_unset_vty(): Add call to bgp_clear_route() with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
* bgpd/bgp_zebra.c: Made it so zclient is global so bgp_exit() can use it.
* bgpd/bgpd.c:
- peer_lock(): Allow to be called when status is "Deleted".
- peer_deactivate(): Supply BGP_CLEAR_ROUTE_NORMAL purpose to
bgp_clear_route() call.
- peer_delete(): Common variable listnode pn. Fix bug in which rsclient
was only dealt with if not part of a peer group. Call
bgp_clear_route() for rsclient, if appropriate, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- peer_group_get(): Use XSTRDUP() instead of strdup() for conf->host.
- peer_group_bind(): Call bgp_clear_route() for rsclient, and do so with
BGP_CLEAR_ROUTE_MY_RSCLIENT purpose.
- bgp_create(): Use XSTRDUP() instead of strdup() for peer_self->host.
- bgp_delete(): Delete peers before groups, rather than after. And then
rather than deleting rsclients, verify that there are none at this
point.
- bgp_unlock(): Add assertion.
- bgp_free(): Call bgp_table_finish() rather than doing XFREE() itself.
* lib/command.c,h: Compiler warning fixes. Add cmd_terminate(). Fixed
massive leak in install_element() in which cmd_make_descvec() was being
called more than once for the same cmd->strvec/string/doc.
* lib/log.c: Make closezlog() check fp before calling fclose().
* lib/memory.c: Catch when alloc count goes negative by using signed
counts. Correct #endif comment. Add log_memstats_stderr().
* lib/memory.h: Add log_memstats_stderr().
* lib/thread.c: thread->funcname was being accessed in thread_call() after
it had been freed. Rearranged things so that thread_call() frees
funcname. Also made it so thread_master_free() cleans up cpu_record.
* lib/vty.c,h: Use global command_cr. Add vty_terminate().
* lib/zclient.c,h: Re-enable zclient_free().
2009-07-18 07:44:03 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Make attribute packet. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void bgp_dump_routes_attr(struct stream *s, struct attr *attr,
|
|
|
|
struct prefix *prefix)
|
|
|
|
{
|
|
|
|
unsigned long cp;
|
|
|
|
unsigned long len;
|
|
|
|
size_t aspath_lenp;
|
|
|
|
struct aspath *aspath;
|
|
|
|
int addpath_encode = 0;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t addpath_tx_id = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* Remember current pointer. */
|
|
|
|
cp = stream_get_endp(s);
|
|
|
|
|
|
|
|
/* Place holder of length. */
|
|
|
|
stream_putw(s, 0);
|
|
|
|
|
|
|
|
/* Origin attribute. */
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_ORIGIN);
|
|
|
|
stream_putc(s, 1);
|
|
|
|
stream_putc(s, attr->origin);
|
|
|
|
|
|
|
|
aspath = attr->aspath;
|
|
|
|
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN);
|
|
|
|
stream_putc(s, BGP_ATTR_AS_PATH);
|
|
|
|
aspath_lenp = stream_get_endp(s);
|
|
|
|
stream_putw(s, 0);
|
|
|
|
|
|
|
|
stream_putw_at(s, aspath_lenp, aspath_put(s, aspath, 1));
|
|
|
|
|
|
|
|
/* Nexthop attribute. */
|
|
|
|
/* If it's an IPv6 prefix, don't dump the IPv4 nexthop to save space */
|
|
|
|
if (prefix != NULL && prefix->family != AF_INET6) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_NEXT_HOP);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_put_ipv4(s, attr->nexthop.s_addr);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* MED attribute. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, BGP_ATTR_MULTI_EXIT_DISC);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_putl(s, attr->med);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Local preference. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_LOCAL_PREF);
|
|
|
|
stream_putc(s, 4);
|
|
|
|
stream_putl(s, attr->local_pref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomic aggregate. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_ATOMIC_AGGREGATE);
|
|
|
|
stream_putc(s, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Aggregator. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)) {
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
|
|
|
|
stream_putc(s, BGP_ATTR_AGGREGATOR);
|
|
|
|
stream_putc(s, 8);
|
|
|
|
stream_putl(s, attr->aggregator_as);
|
|
|
|
stream_put_ipv4(s, attr->aggregator_addr.s_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Community attribute. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) {
|
|
|
|
if (attr->community->size * 4 > 255) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_COMMUNITIES);
|
|
|
|
stream_putw(s, attr->community->size * 4);
|
|
|
|
} else {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_COMMUNITIES);
|
|
|
|
stream_putc(s, attr->community->size * 4);
|
|
|
|
}
|
|
|
|
stream_put(s, attr->community->val, attr->community->size * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Large Community attribute. */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
|
2017-08-30 07:53:37 +02:00
|
|
|
if (lcom_length(attr->lcommunity) > 255) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
|
|
|
|
| BGP_ATTR_FLAG_EXTLEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
|
2017-08-30 07:53:37 +02:00
|
|
|
stream_putw(s, lcom_length(attr->lcommunity));
|
2017-07-17 14:03:14 +02:00
|
|
|
} else {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
|
2017-08-30 07:53:37 +02:00
|
|
|
stream_putc(s, lcom_length(attr->lcommunity));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_put(s, attr->lcommunity->val,
|
|
|
|
lcom_length(attr->lcommunity));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a MP_NLRI attribute to dump the IPv6 next hop */
|
|
|
|
if (prefix != NULL && prefix->family == AF_INET6
|
|
|
|
&& (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
|
|
|
|
|| attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)) {
|
|
|
|
int sizep;
|
|
|
|
|
|
|
|
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL);
|
|
|
|
stream_putc(s, BGP_ATTR_MP_REACH_NLRI);
|
|
|
|
sizep = stream_get_endp(s);
|
|
|
|
|
|
|
|
/* MP header */
|
|
|
|
stream_putc(s, 0); /* Marker: Attribute length. */
|
|
|
|
stream_putw(s, AFI_IP6); /* AFI */
|
|
|
|
stream_putc(s, SAFI_UNICAST); /* SAFI */
|
|
|
|
|
|
|
|
/* Next hop */
|
|
|
|
stream_putc(s, attr->mp_nexthop_len);
|
|
|
|
stream_put(s, &attr->mp_nexthop_global, IPV6_MAX_BYTELEN);
|
|
|
|
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
|
|
|
|
stream_put(s, &attr->mp_nexthop_local,
|
|
|
|
IPV6_MAX_BYTELEN);
|
|
|
|
|
|
|
|
/* SNPA */
|
|
|
|
stream_putc(s, 0);
|
|
|
|
|
|
|
|
/* Prefix */
|
|
|
|
stream_put_prefix_addpath(s, prefix, addpath_encode,
|
|
|
|
addpath_tx_id);
|
|
|
|
|
|
|
|
/* Set MP attribute length. */
|
|
|
|
stream_putc_at(s, sizep, (stream_get_endp(s) - sizep) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prefix SID */
|
|
|
|
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) {
|
|
|
|
if (attr->label_index != BGP_INVALID_LABEL_INDEX) {
|
2018-03-06 20:02:52 +01:00
|
|
|
stream_putc(s,
|
|
|
|
BGP_ATTR_FLAG_OPTIONAL
|
|
|
|
| BGP_ATTR_FLAG_TRANS);
|
2017-07-17 14:03:14 +02:00
|
|
|
stream_putc(s, BGP_ATTR_PREFIX_SID);
|
|
|
|
stream_putc(s, 10);
|
|
|
|
stream_putc(s, BGP_PREFIX_SID_LABEL_INDEX);
|
|
|
|
stream_putc(s, BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
|
|
|
|
stream_putc(s, 0); // reserved
|
|
|
|
stream_putw(s, 0); // flags
|
|
|
|
stream_putl(s, attr->label_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return total size of attribute. */
|
|
|
|
len = stream_get_endp(s) - cp - 2;
|
|
|
|
stream_putw_at(s, cp, len);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|