2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-12-14 19:14:04 +01:00
|
|
|
/*
|
2011-07-21 05:43:22 +02:00
|
|
|
* BGP Multipath
|
|
|
|
* Copyright (C) 2010 Google Inc.
|
2024-09-30 21:09:42 +02:00
|
|
|
* 2024 Nvidia Corporation
|
|
|
|
* Donald Sharp
|
2011-07-21 05:43:22 +02:00
|
|
|
*
|
2024-09-30 21:09:42 +02:00
|
|
|
* This file is part of FRR
|
2011-07-21 05:43:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "command.h"
|
2011-07-21 05:45:12 +02:00
|
|
|
#include "prefix.h"
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "sockunion.h"
|
2011-07-21 05:46:01 +02:00
|
|
|
#include "memory.h"
|
2015-05-20 03:03:47 +02:00
|
|
|
#include "queue.h"
|
2016-01-07 16:03:01 +01:00
|
|
|
#include "filter.h"
|
2011-07-21 05:43:22 +02:00
|
|
|
|
|
|
|
#include "bgpd/bgpd.h"
|
2011-07-21 05:45:12 +02:00
|
|
|
#include "bgpd/bgp_table.h"
|
|
|
|
#include "bgpd/bgp_route.h"
|
|
|
|
#include "bgpd/bgp_attr.h"
|
2011-07-21 05:46:01 +02:00
|
|
|
#include "bgpd/bgp_debug.h"
|
2011-07-21 05:49:11 +02:00
|
|
|
#include "bgpd/bgp_aspath.h"
|
|
|
|
#include "bgpd/bgp_community.h"
|
|
|
|
#include "bgpd/bgp_ecommunity.h"
|
2016-11-15 11:00:39 +01:00
|
|
|
#include "bgpd/bgp_lcommunity.h"
|
2011-07-21 05:43:22 +02:00
|
|
|
#include "bgpd/bgp_mpath.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_maximum_paths_set
|
|
|
|
*
|
|
|
|
* Record maximum-paths configuration for BGP instance
|
|
|
|
*/
|
|
|
|
int bgp_maximum_paths_set(struct bgp *bgp, afi_t afi, safi_t safi, int peertype,
|
2022-05-12 14:06:14 +02:00
|
|
|
uint16_t maxpaths, bool same_clusterlen)
|
2011-07-21 05:43:22 +02:00
|
|
|
{
|
|
|
|
if (!bgp || (afi >= AFI_MAX) || (safi >= SAFI_MAX))
|
|
|
|
return -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:43:22 +02:00
|
|
|
switch (peertype) {
|
|
|
|
case BGP_PEER_IBGP:
|
|
|
|
bgp->maxpaths[afi][safi].maxpaths_ibgp = maxpaths;
|
2022-05-12 14:06:14 +02:00
|
|
|
bgp->maxpaths[afi][safi].same_clusterlen = same_clusterlen;
|
2011-07-21 05:43:22 +02:00
|
|
|
break;
|
|
|
|
case BGP_PEER_EBGP:
|
|
|
|
bgp->maxpaths[afi][safi].maxpaths_ebgp = maxpaths;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:43:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_maximum_paths_unset
|
|
|
|
*
|
|
|
|
* Remove maximum-paths configuration from BGP instance
|
|
|
|
*/
|
|
|
|
int bgp_maximum_paths_unset(struct bgp *bgp, afi_t afi, safi_t safi,
|
|
|
|
int peertype)
|
|
|
|
{
|
|
|
|
if (!bgp || (afi >= AFI_MAX) || (safi >= SAFI_MAX))
|
|
|
|
return -1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:43:22 +02:00
|
|
|
switch (peertype) {
|
|
|
|
case BGP_PEER_IBGP:
|
2016-11-04 00:59:19 +01:00
|
|
|
bgp->maxpaths[afi][safi].maxpaths_ibgp = multipath_num;
|
2022-05-12 14:06:14 +02:00
|
|
|
bgp->maxpaths[afi][safi].same_clusterlen = false;
|
2011-07-21 05:43:22 +02:00
|
|
|
break;
|
|
|
|
case BGP_PEER_EBGP:
|
2016-11-04 00:59:19 +01:00
|
|
|
bgp->maxpaths[afi][safi].maxpaths_ebgp = multipath_num;
|
2011-07-21 05:43:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:43:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2011-07-21 05:45:12 +02:00
|
|
|
|
2018-02-26 23:13:22 +01:00
|
|
|
/*
|
|
|
|
* bgp_interface_same
|
|
|
|
*
|
|
|
|
* Return true if ifindex for ifp1 and ifp2 are the same, else return false.
|
|
|
|
*/
|
|
|
|
static int bgp_interface_same(struct interface *ifp1, struct interface *ifp2)
|
|
|
|
{
|
|
|
|
if (!ifp1 && !ifp2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!ifp1 && ifp2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ifp1 && !ifp2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (ifp1->ifindex == ifp2->ifindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 05:45:12 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_nexthop_cmp
|
2011-07-21 05:45:12 +02:00
|
|
|
*
|
|
|
|
* Compare the nexthops of two paths. Return value is less than, equal to,
|
2018-10-03 02:43:07 +02:00
|
|
|
* or greater than zero if bpi1 is respectively less than, equal to,
|
|
|
|
* or greater than bpi2.
|
2011-07-21 05:45:12 +02:00
|
|
|
*/
|
2018-10-03 02:43:07 +02:00
|
|
|
int bgp_path_info_nexthop_cmp(struct bgp_path_info *bpi1,
|
|
|
|
struct bgp_path_info *bpi2)
|
2011-07-21 05:45:12 +02:00
|
|
|
{
|
|
|
|
int compare;
|
2017-07-26 15:41:36 +02:00
|
|
|
struct in6_addr addr1, addr2;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 02:43:07 +02:00
|
|
|
compare = IPV4_ADDR_CMP(&bpi1->attr->nexthop, &bpi2->attr->nexthop);
|
2017-06-06 19:20:38 +02:00
|
|
|
if (!compare) {
|
2018-10-03 02:43:07 +02:00
|
|
|
if (bpi1->attr->mp_nexthop_len == bpi2->attr->mp_nexthop_len) {
|
|
|
|
switch (bpi1->attr->mp_nexthop_len) {
|
2015-05-20 03:04:00 +02:00
|
|
|
case BGP_ATTR_NHLEN_IPV4:
|
|
|
|
case BGP_ATTR_NHLEN_VPNV4:
|
2017-06-06 19:20:38 +02:00
|
|
|
compare = IPV4_ADDR_CMP(
|
2018-10-03 02:43:07 +02:00
|
|
|
&bpi1->attr->mp_nexthop_global_in,
|
|
|
|
&bpi2->attr->mp_nexthop_global_in);
|
2015-05-20 03:03:59 +02:00
|
|
|
break;
|
2015-05-20 03:04:00 +02:00
|
|
|
case BGP_ATTR_NHLEN_IPV6_GLOBAL:
|
2017-01-06 13:35:40 +01:00
|
|
|
case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
|
2017-06-06 19:20:38 +02:00
|
|
|
compare = IPV6_ADDR_CMP(
|
2018-10-03 02:43:07 +02:00
|
|
|
&bpi1->attr->mp_nexthop_global,
|
|
|
|
&bpi2->attr->mp_nexthop_global);
|
2015-05-20 03:03:59 +02:00
|
|
|
break;
|
2015-05-20 03:04:00 +02:00
|
|
|
case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
|
2022-04-29 19:41:57 +02:00
|
|
|
addr1 = (CHECK_FLAG(bpi1->attr->nh_flags,
|
|
|
|
BGP_ATTR_NH_MP_PREFER_GLOBAL))
|
2018-10-03 02:43:07 +02:00
|
|
|
? bpi1->attr->mp_nexthop_global
|
|
|
|
: bpi1->attr->mp_nexthop_local;
|
2022-04-29 19:41:57 +02:00
|
|
|
addr2 = (CHECK_FLAG(bpi2->attr->nh_flags,
|
|
|
|
BGP_ATTR_NH_MP_PREFER_GLOBAL))
|
2018-10-03 02:43:07 +02:00
|
|
|
? bpi2->attr->mp_nexthop_global
|
|
|
|
: bpi2->attr->mp_nexthop_local;
|
|
|
|
|
2022-04-29 19:41:57 +02:00
|
|
|
if (!CHECK_FLAG(bpi1->attr->nh_flags,
|
|
|
|
BGP_ATTR_NH_MP_PREFER_GLOBAL) &&
|
|
|
|
!CHECK_FLAG(bpi2->attr->nh_flags,
|
|
|
|
BGP_ATTR_NH_MP_PREFER_GLOBAL))
|
2018-02-26 23:13:22 +01:00
|
|
|
compare = !bgp_interface_same(
|
2018-10-03 02:43:07 +02:00
|
|
|
bpi1->peer->ifp,
|
|
|
|
bpi2->peer->ifp);
|
2018-02-26 23:13:22 +01:00
|
|
|
|
2015-05-20 03:03:59 +02:00
|
|
|
if (!compare)
|
2017-07-26 15:41:36 +02:00
|
|
|
compare = IPV6_ADDR_CMP(&addr1, &addr2);
|
2015-05-20 03:03:59 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 03:03:59 +02:00
|
|
|
/* This can happen if one IPv6 peer sends you global and
|
|
|
|
* link-local
|
|
|
|
* nexthops but another IPv6 peer only sends you global
|
|
|
|
*/
|
2018-10-03 02:43:07 +02:00
|
|
|
else if (bpi1->attr->mp_nexthop_len
|
|
|
|
== BGP_ATTR_NHLEN_IPV6_GLOBAL
|
|
|
|
|| bpi1->attr->mp_nexthop_len
|
2017-06-06 19:20:38 +02:00
|
|
|
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
|
2018-10-03 02:43:07 +02:00
|
|
|
compare = IPV6_ADDR_CMP(&bpi1->attr->mp_nexthop_global,
|
|
|
|
&bpi2->attr->mp_nexthop_global);
|
2011-07-21 05:45:12 +02:00
|
|
|
if (!compare) {
|
2018-10-03 02:43:07 +02:00
|
|
|
if (bpi1->attr->mp_nexthop_len
|
|
|
|
< bpi2->attr->mp_nexthop_len)
|
2015-05-20 03:03:59 +02:00
|
|
|
compare = -1;
|
|
|
|
else
|
|
|
|
compare = 1;
|
|
|
|
}
|
2011-07-21 05:45:12 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
bgpd: VRF-Lite fix best path selection
Description:
Incorrect behavior during best path selection for the imported routes.
Imported routes are always treated as eBGP routes.
Change is intended for fixing the issues related to
bgp best path selection for leaked routes:
- FRR does ecmp for the imported routes,
even without any ecmp related config.
If the same prefix is imported from two different VRFs,
then we configure the route with ecmp even without
any ecmp related config.
- Locally imported routes are preferred over imported
eBGP routes.
If there is a local route and eBGP learned route
for the same prefix, if we import both the routes,
imported local route is selected as best path.
- Same route is imported from multiple tenant VRFs,
both imported routes point to the same VRF in nexthop.
- When the same route with same nexthop in two different VRFs
is imported from those two VRFs, route is not installed as ecmp,
even though we had ecmp config.
- During best path selection, while comparing the paths for imported routes,
we should correctly refer to the original route i.e. the ultimate path.
- When the same route is imported from multiple VRF,
use the correct VRF while installing in the FIB.
- When same route is imported from two different tenant VRFs,
while comparing bgp path info as part of bgp best path selection,
we should ideally also compare corresponding VRFs.
See-also: https://github.com/FRRouting/frr/files/7169555/FRR.and.Cisco.VRF-Lite.Behaviour.pdf
Co-authored-by: Santosh P K <sapk@vmware.com>
Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com>
Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2020-06-08 23:40:17 +02:00
|
|
|
/*
|
|
|
|
* If both nexthops are same then check
|
|
|
|
* if they belong to same VRF
|
|
|
|
*/
|
|
|
|
if (!compare && bpi1->attr->nh_type != NEXTHOP_TYPE_BLACKHOLE) {
|
2023-08-08 12:47:29 +02:00
|
|
|
if (bpi1->extra && bpi1->extra->vrfleak &&
|
|
|
|
bpi1->extra->vrfleak->bgp_orig && bpi2->extra &&
|
|
|
|
bpi2->extra->vrfleak && bpi2->extra->vrfleak->bgp_orig) {
|
|
|
|
if (bpi1->extra->vrfleak->bgp_orig->vrf_id !=
|
|
|
|
bpi2->extra->vrfleak->bgp_orig->vrf_id) {
|
bgpd: VRF-Lite fix best path selection
Description:
Incorrect behavior during best path selection for the imported routes.
Imported routes are always treated as eBGP routes.
Change is intended for fixing the issues related to
bgp best path selection for leaked routes:
- FRR does ecmp for the imported routes,
even without any ecmp related config.
If the same prefix is imported from two different VRFs,
then we configure the route with ecmp even without
any ecmp related config.
- Locally imported routes are preferred over imported
eBGP routes.
If there is a local route and eBGP learned route
for the same prefix, if we import both the routes,
imported local route is selected as best path.
- Same route is imported from multiple tenant VRFs,
both imported routes point to the same VRF in nexthop.
- When the same route with same nexthop in two different VRFs
is imported from those two VRFs, route is not installed as ecmp,
even though we had ecmp config.
- During best path selection, while comparing the paths for imported routes,
we should correctly refer to the original route i.e. the ultimate path.
- When the same route is imported from multiple VRF,
use the correct VRF while installing in the FIB.
- When same route is imported from two different tenant VRFs,
while comparing bgp path info as part of bgp best path selection,
we should ideally also compare corresponding VRFs.
See-also: https://github.com/FRRouting/frr/files/7169555/FRR.and.Cisco.VRF-Lite.Behaviour.pdf
Co-authored-by: Santosh P K <sapk@vmware.com>
Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com>
Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2020-06-08 23:40:17 +02:00
|
|
|
compare = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-21 05:45:12 +02:00
|
|
|
return compare;
|
|
|
|
}
|
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_new
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Allocate and zero memory for a new bgp_path_info_mpath element
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
static struct bgp_path_info_mpath *bgp_path_info_mpath_new(void)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info_mpath *new_mpath;
|
2022-11-28 14:52:48 +01:00
|
|
|
|
2018-10-02 22:41:30 +02:00
|
|
|
new_mpath = XCALLOC(MTYPE_BGP_MPATH_INFO,
|
|
|
|
sizeof(struct bgp_path_info_mpath));
|
2022-11-28 14:52:48 +01:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
new_mpath->mp_count = 1;
|
2011-07-21 05:46:01 +02:00
|
|
|
return new_mpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_free
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Release resources for a bgp_path_info_mpath element and zero out pointer
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
void bgp_path_info_mpath_free(struct bgp_path_info_mpath **mpath)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
|
|
|
if (mpath && *mpath) {
|
2011-07-21 05:49:11 +02:00
|
|
|
if ((*mpath)->mp_attr)
|
2012-04-28 22:37:20 +02:00
|
|
|
bgp_attr_unintern(&(*mpath)->mp_attr);
|
2024-09-30 21:09:42 +02:00
|
|
|
(*mpath)->mp_attr = NULL;
|
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
XFREE(MTYPE_BGP_MPATH_INFO, *mpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_get
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Fetch the mpath element for the given bgp_path_info. Used for
|
2011-07-21 05:46:01 +02:00
|
|
|
* doing lazy allocation.
|
|
|
|
*/
|
2018-10-02 22:41:30 +02:00
|
|
|
static struct bgp_path_info_mpath *
|
2018-10-03 00:34:03 +02:00
|
|
|
bgp_path_info_mpath_get(struct bgp_path_info *path)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info_mpath *mpath;
|
2019-06-04 21:06:26 +02:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return NULL;
|
|
|
|
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!path->mpath) {
|
2018-10-03 00:15:34 +02:00
|
|
|
mpath = bgp_path_info_mpath_new();
|
2018-10-03 00:34:03 +02:00
|
|
|
path->mpath = mpath;
|
|
|
|
mpath->mp_info = path;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
2018-10-03 00:34:03 +02:00
|
|
|
return path->mpath;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_next
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Given a bgp_path_info, return the next multipath entry
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
struct bgp_path_info *bgp_path_info_mpath_next(struct bgp_path_info *path)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2024-09-30 21:09:42 +02:00
|
|
|
path = path->next;
|
|
|
|
|
|
|
|
while (path) {
|
|
|
|
if (CHECK_FLAG(path->flags, BGP_PATH_MULTIPATH))
|
|
|
|
return path;
|
|
|
|
|
|
|
|
path = path->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_first
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Given bestpath bgp_path_info, return the first multipath entry.
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
struct bgp_path_info *bgp_path_info_mpath_first(struct bgp_path_info *path)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-03 00:34:03 +02:00
|
|
|
return bgp_path_info_mpath_next(path);
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_count
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Given the bestpath bgp_path_info, return the number of multipath entries
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
uint32_t bgp_path_info_mpath_count(struct bgp_path_info *path)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!path->mpath)
|
2024-09-30 21:09:42 +02:00
|
|
|
return 1;
|
|
|
|
|
2018-10-03 00:34:03 +02:00
|
|
|
return path->mpath->mp_count;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_count_set
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
|
|
|
* Sets the count of multipaths into bestpath's mpath element
|
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
static void bgp_path_info_mpath_count_set(struct bgp_path_info *path,
|
2020-03-24 20:19:37 +01:00
|
|
|
uint16_t count)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info_mpath *mpath;
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!count && !path->mpath)
|
2011-07-21 05:46:01 +02:00
|
|
|
return;
|
2018-10-03 00:34:03 +02:00
|
|
|
mpath = bgp_path_info_mpath_get(path);
|
2011-07-21 05:46:01 +02:00
|
|
|
if (!mpath)
|
|
|
|
return;
|
|
|
|
mpath->mp_count = count;
|
|
|
|
}
|
|
|
|
|
2020-03-24 20:22:17 +01:00
|
|
|
/*
|
|
|
|
* bgp_path_info_mpath_lb_update
|
|
|
|
*
|
|
|
|
* Update cumulative info related to link-bandwidth
|
2024-09-26 16:46:23 +02:00
|
|
|
*
|
|
|
|
* This is only set on the first mpath of the list
|
|
|
|
* as such we should UNSET the flags when removing
|
|
|
|
* to ensure nothing accidently happens
|
2020-03-24 20:22:17 +01:00
|
|
|
*/
|
|
|
|
static void bgp_path_info_mpath_lb_update(struct bgp_path_info *path, bool set,
|
|
|
|
bool all_paths_lb, uint64_t cum_bw)
|
|
|
|
{
|
|
|
|
struct bgp_path_info_mpath *mpath;
|
|
|
|
|
2021-06-29 13:53:39 +02:00
|
|
|
mpath = path->mpath;
|
|
|
|
if (mpath == NULL) {
|
2020-11-02 16:14:48 +01:00
|
|
|
if (!set || (cum_bw == 0 && !all_paths_lb))
|
2020-03-24 20:22:17 +01:00
|
|
|
return;
|
2020-11-02 16:14:48 +01:00
|
|
|
|
2020-03-24 20:22:17 +01:00
|
|
|
mpath = bgp_path_info_mpath_get(path);
|
|
|
|
if (!mpath)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set) {
|
2020-03-24 22:38:37 +01:00
|
|
|
if (cum_bw)
|
|
|
|
SET_FLAG(mpath->mp_flags, BGP_MP_LB_PRESENT);
|
|
|
|
else
|
|
|
|
UNSET_FLAG(mpath->mp_flags, BGP_MP_LB_PRESENT);
|
2020-03-24 20:22:17 +01:00
|
|
|
if (all_paths_lb)
|
|
|
|
SET_FLAG(mpath->mp_flags, BGP_MP_LB_ALL);
|
|
|
|
else
|
|
|
|
UNSET_FLAG(mpath->mp_flags, BGP_MP_LB_ALL);
|
|
|
|
mpath->cum_bw = cum_bw;
|
|
|
|
} else {
|
|
|
|
mpath->mp_flags = 0;
|
|
|
|
mpath->cum_bw = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_attr
|
2011-07-21 05:49:11 +02:00
|
|
|
*
|
2018-10-03 00:15:34 +02:00
|
|
|
* Given bestpath bgp_path_info, return aggregated attribute set used
|
2011-07-21 05:49:11 +02:00
|
|
|
* for advertising the multipath route
|
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
struct attr *bgp_path_info_mpath_attr(struct bgp_path_info *path)
|
2011-07-21 05:49:11 +02:00
|
|
|
{
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!path->mpath)
|
2011-07-21 05:49:11 +02:00
|
|
|
return NULL;
|
2018-10-03 00:34:03 +02:00
|
|
|
return path->mpath->mp_attr;
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 20:25:28 +01:00
|
|
|
/*
|
|
|
|
* bgp_path_info_chkwtd
|
|
|
|
*
|
2020-03-24 22:38:37 +01:00
|
|
|
* Return if we should attempt to do weighted ECMP or not
|
|
|
|
* The path passed in is the bestpath.
|
2020-03-24 20:25:28 +01:00
|
|
|
*/
|
2020-03-24 22:38:37 +01:00
|
|
|
bool bgp_path_info_mpath_chkwtd(struct bgp *bgp, struct bgp_path_info *path)
|
2020-03-24 20:25:28 +01:00
|
|
|
{
|
2020-03-24 22:38:37 +01:00
|
|
|
/* Check if told to ignore weights or not multipath */
|
|
|
|
if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW || !path->mpath)
|
2020-03-24 20:25:28 +01:00
|
|
|
return false;
|
2020-03-24 22:38:37 +01:00
|
|
|
|
|
|
|
/* All paths in multipath should have associated weight (bandwidth)
|
|
|
|
* unless told explicitly otherwise.
|
|
|
|
*/
|
|
|
|
if (bgp->lb_handling != BGP_LINK_BW_SKIP_MISSING &&
|
|
|
|
bgp->lb_handling != BGP_LINK_BW_DEFWT_4_MISSING)
|
2024-09-26 16:40:30 +02:00
|
|
|
return CHECK_FLAG(path->mpath->mp_flags, BGP_MP_LB_ALL);
|
2020-03-24 22:38:37 +01:00
|
|
|
|
|
|
|
/* At least one path should have bandwidth. */
|
2024-09-26 16:40:30 +02:00
|
|
|
return CHECK_FLAG(path->mpath->mp_flags, BGP_MP_LB_PRESENT);
|
2020-03-24 20:25:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_path_info_mpath_attr
|
|
|
|
*
|
|
|
|
* Given bestpath bgp_path_info, return cumulative bandwidth
|
|
|
|
* computed for all multipaths with bandwidth info
|
|
|
|
*/
|
|
|
|
uint64_t bgp_path_info_mpath_cumbw(struct bgp_path_info *path)
|
|
|
|
{
|
|
|
|
if (!path->mpath)
|
|
|
|
return 0;
|
|
|
|
return path->mpath->cum_bw;
|
|
|
|
}
|
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_attr_set
|
2011-07-21 05:49:11 +02:00
|
|
|
*
|
|
|
|
* Sets the aggregated attribute into bestpath's mpath element
|
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
static void bgp_path_info_mpath_attr_set(struct bgp_path_info *path,
|
2018-10-03 00:15:34 +02:00
|
|
|
struct attr *attr)
|
2011-07-21 05:49:11 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info_mpath *mpath;
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!attr && !path->mpath)
|
2011-07-21 05:49:11 +02:00
|
|
|
return;
|
2018-10-03 00:34:03 +02:00
|
|
|
mpath = bgp_path_info_mpath_get(path);
|
2011-07-21 05:49:11 +02:00
|
|
|
if (!mpath)
|
|
|
|
return;
|
|
|
|
mpath->mp_attr = attr;
|
|
|
|
}
|
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_update
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
2024-09-30 21:09:42 +02:00
|
|
|
* Compare and sync up the multipath flags with what was choosen
|
|
|
|
* in best selection
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2021-11-12 16:46:48 +01:00
|
|
|
void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest,
|
2024-09-30 21:09:42 +02:00
|
|
|
struct bgp_path_info *new_best, struct bgp_path_info *old_best,
|
|
|
|
uint32_t num_candidates, struct bgp_maxpaths_cfg *mpath_cfg)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t maxpaths, mpath_count, old_mpath_count;
|
2024-04-08 08:22:02 +02:00
|
|
|
uint64_t bwval;
|
2020-03-24 21:57:44 +01:00
|
|
|
uint64_t cum_bw, old_cum_bw;
|
2024-09-30 21:09:42 +02:00
|
|
|
struct bgp_path_info *cur_iterator = NULL;
|
|
|
|
bool mpath_changed, debug;
|
2020-03-24 20:22:17 +01:00
|
|
|
bool all_paths_lb;
|
2015-12-07 20:56:02 +01:00
|
|
|
char path_buf[PATH_ADDPATH_STR_BUFFER];
|
2024-09-30 21:09:42 +02:00
|
|
|
bool old_mpath, new_mpath;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
mpath_changed = false;
|
2016-11-04 00:59:19 +01:00
|
|
|
maxpaths = multipath_num;
|
2011-07-21 05:46:01 +02:00
|
|
|
mpath_count = 0;
|
|
|
|
old_mpath_count = 0;
|
2020-03-24 21:57:44 +01:00
|
|
|
old_cum_bw = cum_bw = 0;
|
2020-03-27 00:11:58 +01:00
|
|
|
debug = bgp_debug_bestpath(dest);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
if (old_best) {
|
2018-10-03 00:15:34 +02:00
|
|
|
old_mpath_count = bgp_path_info_mpath_count(old_best);
|
2024-09-30 21:09:42 +02:00
|
|
|
if (old_mpath_count == 1)
|
|
|
|
SET_FLAG(old_best->flags, BGP_PATH_MULTIPATH);
|
2020-03-24 21:57:44 +01:00
|
|
|
old_cum_bw = bgp_path_info_mpath_cumbw(old_best);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_count_set(old_best, 0);
|
2020-03-24 20:22:17 +01:00
|
|
|
bgp_path_info_mpath_lb_update(old_best, false, false, 0);
|
2024-09-30 21:09:42 +02:00
|
|
|
bgp_path_info_mpath_free(&old_best->mpath);
|
|
|
|
old_best->mpath = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_best) {
|
|
|
|
maxpaths = (new_best->peer->sort == BGP_PEER_IBGP) ? mpath_cfg->maxpaths_ibgp
|
|
|
|
: mpath_cfg->maxpaths_ebgp;
|
|
|
|
cur_iterator = new_best;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-05 19:53:06 +02:00
|
|
|
if (debug)
|
2024-09-30 21:09:42 +02:00
|
|
|
zlog_debug("%pBD(%s): starting mpath update, newbest %s num candidates %d old-mpath-count %d old-cum-bw %" PRIu64
|
|
|
|
" maxpaths set %u",
|
|
|
|
dest, bgp->name_pretty, new_best ? new_best->peer->host : "NONE",
|
|
|
|
num_candidates, old_mpath_count, old_cum_bw, maxpaths);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
|
|
|
* We perform an ordered walk through both lists in parallel.
|
|
|
|
* The reason for the ordered walk is that if there are paths
|
|
|
|
* that were previously multipaths and are still multipaths, the walk
|
|
|
|
* should encounter them in both lists at the same time. Otherwise
|
|
|
|
* there will be paths that are in one list or another, and we
|
|
|
|
* will deal with these separately.
|
|
|
|
*
|
|
|
|
* Note that new_best might be somewhere in the mp_list, so we need
|
|
|
|
* to skip over it
|
|
|
|
*/
|
2020-03-24 20:22:17 +01:00
|
|
|
all_paths_lb = true; /* We'll reset if any path doesn't have LB. */
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
while (cur_iterator) {
|
|
|
|
old_mpath = CHECK_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH);
|
|
|
|
new_mpath = CHECK_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH_NEW);
|
|
|
|
|
|
|
|
UNSET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH_NEW);
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
2024-09-30 21:09:42 +02:00
|
|
|
* If the current mpath count is equal to the number of
|
|
|
|
* maxpaths that can be used then we can bail, after
|
|
|
|
* we clean up the flags associated with the rest of the
|
|
|
|
* bestpaths
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2024-09-30 21:09:42 +02:00
|
|
|
if (mpath_count >= maxpaths) {
|
|
|
|
while (cur_iterator) {
|
|
|
|
UNSET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH);
|
|
|
|
UNSET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH_NEW);
|
|
|
|
|
|
|
|
cur_iterator = cur_iterator->next;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
if (debug)
|
|
|
|
zlog_debug("%pBD(%s): Mpath count %u is equal to maximum paths allowed, finished comparision for MPATHS",
|
|
|
|
dest, bgp->name_pretty, mpath_count);
|
2024-10-03 08:20:40 +02:00
|
|
|
|
|
|
|
break;
|
2024-09-30 21:09:42 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-05 19:53:06 +02:00
|
|
|
if (debug)
|
2024-09-30 21:09:42 +02:00
|
|
|
zlog_debug("%pBD(%s): Candidate %s old_mpath: %u new_mpath: %u, Nexthop %pI4 current mpath count: %u",
|
|
|
|
dest, bgp->name_pretty, cur_iterator->peer->host, old_mpath,
|
|
|
|
new_mpath, &cur_iterator->attr->nexthop, mpath_count);
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
2024-09-30 21:09:42 +02:00
|
|
|
* There is nothing to do if the cur_iterator is neither a old path
|
|
|
|
* or a new path
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2024-09-30 21:09:42 +02:00
|
|
|
if (!old_mpath && !new_mpath) {
|
|
|
|
UNSET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH);
|
|
|
|
cur_iterator = cur_iterator->next;
|
2011-07-21 05:46:01 +02:00
|
|
|
continue;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
if (new_mpath) {
|
|
|
|
mpath_count++;
|
|
|
|
|
|
|
|
if (cur_iterator != new_best)
|
|
|
|
SET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH);
|
|
|
|
|
|
|
|
if (!old_mpath)
|
|
|
|
mpath_changed = true;
|
|
|
|
|
|
|
|
if (ecommunity_linkbw_present(bgp_attr_get_ecommunity(cur_iterator->attr),
|
|
|
|
&bwval) ||
|
|
|
|
ecommunity_linkbw_present(bgp_attr_get_ipv6_ecommunity(
|
|
|
|
cur_iterator->attr),
|
|
|
|
&bwval))
|
|
|
|
cum_bw += bwval;
|
|
|
|
else
|
|
|
|
all_paths_lb = false;
|
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
if (debug) {
|
2024-09-30 21:09:42 +02:00
|
|
|
bgp_path_info_path_with_addpath_rx_str(cur_iterator, path_buf,
|
|
|
|
sizeof(path_buf));
|
|
|
|
zlog_debug("%pBD: add mpath %s nexthop %pI4, cur count %d cum_bw: %" PRIu64
|
|
|
|
" all_paths_lb: %u",
|
|
|
|
dest, path_buf, &cur_iterator->attr->nexthop,
|
|
|
|
mpath_count, cum_bw, all_paths_lb);
|
2015-12-07 20:56:02 +01:00
|
|
|
}
|
2011-07-21 05:46:01 +02:00
|
|
|
} else {
|
|
|
|
/*
|
2024-09-30 21:09:42 +02:00
|
|
|
* We know that old_mpath is true and new_mpath is false in this path
|
2011-07-21 05:46:01 +02:00
|
|
|
*/
|
2024-09-30 21:09:42 +02:00
|
|
|
mpath_changed = true;
|
|
|
|
UNSET_FLAG(cur_iterator->flags, BGP_PATH_MULTIPATH);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2024-09-30 21:09:42 +02:00
|
|
|
|
|
|
|
cur_iterator = cur_iterator->next;
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
if (new_best) {
|
2024-09-30 21:09:42 +02:00
|
|
|
if (mpath_count > 1 || new_best->mpath) {
|
|
|
|
bgp_path_info_mpath_count_set(new_best, mpath_count);
|
|
|
|
bgp_path_info_mpath_lb_update(new_best, true, all_paths_lb, cum_bw);
|
|
|
|
}
|
2016-09-05 19:53:06 +02:00
|
|
|
if (debug)
|
2023-11-13 16:26:48 +01:00
|
|
|
zlog_debug("%pBD(%s): New mpath count (incl newbest) %d mpath-change %s all_paths_lb %d cum_bw %" PRIu64,
|
|
|
|
dest, bgp->name_pretty, mpath_count,
|
|
|
|
mpath_changed ? "YES" : "NO", all_paths_lb,
|
|
|
|
cum_bw);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
if (mpath_count == 1)
|
|
|
|
UNSET_FLAG(new_best->flags, BGP_PATH_MULTIPATH);
|
2011-07-21 05:46:01 +02:00
|
|
|
if (mpath_changed
|
2018-10-03 00:15:34 +02:00
|
|
|
|| (bgp_path_info_mpath_count(new_best) != old_mpath_count))
|
2018-09-14 02:34:42 +02:00
|
|
|
SET_FLAG(new_best->flags, BGP_PATH_MULTIPATH_CHG);
|
2024-09-30 21:09:42 +02:00
|
|
|
if ((mpath_count) != old_mpath_count || old_cum_bw != cum_bw)
|
2020-03-24 21:57:44 +01:00
|
|
|
SET_FLAG(new_best->flags, BGP_PATH_LINK_BW_CHG);
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-21 05:48:20 +02:00
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_aggregate_update
|
2011-07-21 05:49:11 +02:00
|
|
|
*
|
|
|
|
* Set the multipath aggregate attribute. We need to see if the
|
|
|
|
* aggregate has changed and then set the ATTR_CHANGED flag on the
|
|
|
|
* bestpath info so that a peer update will be generated. The
|
|
|
|
* change is detected by generating the current attribute,
|
|
|
|
* interning it, and then comparing the interned pointer with the
|
|
|
|
* current value. We can skip this generate/compare step if there
|
|
|
|
* is no change in multipath selection and no attribute change in
|
|
|
|
* any multipath.
|
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
|
|
|
|
struct bgp_path_info *old_best)
|
2011-07-21 05:49:11 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info *mpinfo;
|
2011-07-21 05:49:11 +02:00
|
|
|
struct aspath *aspath;
|
|
|
|
struct aspath *asmerge;
|
|
|
|
struct attr *new_attr, *old_attr;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t origin;
|
2011-07-21 05:49:11 +02:00
|
|
|
struct community *community, *commerge;
|
|
|
|
struct ecommunity *ecomm, *ecommerge;
|
2016-11-15 11:00:39 +01:00
|
|
|
struct lcommunity *lcomm, *lcommerge;
|
2011-07-21 05:49:11 +02:00
|
|
|
struct attr attr = {0};
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
if (old_best && (old_best != new_best)
|
2018-10-03 00:15:34 +02:00
|
|
|
&& (old_attr = bgp_path_info_mpath_attr(old_best))) {
|
2012-04-28 22:37:20 +02:00
|
|
|
bgp_attr_unintern(&old_attr);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_attr_set(old_best, NULL);
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
if (!new_best)
|
|
|
|
return;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2024-09-30 21:09:42 +02:00
|
|
|
if (bgp_path_info_mpath_count(new_best) == 1) {
|
2018-10-03 00:15:34 +02:00
|
|
|
if ((new_attr = bgp_path_info_mpath_attr(new_best))) {
|
2012-04-28 22:37:20 +02:00
|
|
|
bgp_attr_unintern(&new_attr);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_attr_set(new_best, NULL);
|
2018-09-14 02:34:42 +02:00
|
|
|
SET_FLAG(new_best->flags, BGP_PATH_ATTR_CHANGED);
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-12-03 22:01:19 +01:00
|
|
|
attr = *new_best->attr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-02-06 15:37:20 +01:00
|
|
|
if (new_best->peer
|
|
|
|
&& CHECK_FLAG(new_best->peer->bgp->flags,
|
|
|
|
BGP_FLAG_MULTIPATH_RELAX_AS_SET)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 03:03:58 +02:00
|
|
|
/* aggregate attribute from multipath constituents */
|
|
|
|
aspath = aspath_dup(attr.aspath);
|
|
|
|
origin = attr.origin;
|
|
|
|
community =
|
2022-02-23 08:05:47 +01:00
|
|
|
bgp_attr_get_community(&attr)
|
|
|
|
? community_dup(bgp_attr_get_community(&attr))
|
|
|
|
: NULL;
|
2022-02-04 14:56:20 +01:00
|
|
|
ecomm = (bgp_attr_get_ecommunity(&attr))
|
|
|
|
? ecommunity_dup(bgp_attr_get_ecommunity(&attr))
|
|
|
|
: NULL;
|
2022-02-09 12:44:25 +01:00
|
|
|
lcomm = (bgp_attr_get_lcommunity(&attr))
|
|
|
|
? lcommunity_dup(bgp_attr_get_lcommunity(&attr))
|
|
|
|
: NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
for (mpinfo = bgp_path_info_mpath_first(new_best); mpinfo;
|
|
|
|
mpinfo = bgp_path_info_mpath_next(mpinfo)) {
|
2015-05-20 03:03:58 +02:00
|
|
|
asmerge =
|
|
|
|
aspath_aggregate(aspath, mpinfo->attr->aspath);
|
|
|
|
aspath_free(aspath);
|
|
|
|
aspath = asmerge;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 03:03:58 +02:00
|
|
|
if (origin < mpinfo->attr->origin)
|
|
|
|
origin = mpinfo->attr->origin;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-02-23 08:05:47 +01:00
|
|
|
if (bgp_attr_get_community(mpinfo->attr)) {
|
2015-05-20 03:03:58 +02:00
|
|
|
if (community) {
|
|
|
|
commerge = community_merge(
|
|
|
|
community,
|
2022-02-23 08:05:47 +01:00
|
|
|
bgp_attr_get_community(
|
|
|
|
mpinfo->attr));
|
2015-05-20 03:03:58 +02:00
|
|
|
community =
|
|
|
|
community_uniq_sort(commerge);
|
2018-10-22 21:58:39 +02:00
|
|
|
community_free(&commerge);
|
2015-05-20 03:03:58 +02:00
|
|
|
} else
|
|
|
|
community = community_dup(
|
2022-02-23 08:05:47 +01:00
|
|
|
bgp_attr_get_community(
|
|
|
|
mpinfo->attr));
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-02-04 14:56:20 +01:00
|
|
|
if (bgp_attr_get_ecommunity(mpinfo->attr)) {
|
2015-05-20 03:03:58 +02:00
|
|
|
if (ecomm) {
|
2017-06-06 19:20:38 +02:00
|
|
|
ecommerge = ecommunity_merge(
|
2022-02-04 14:56:20 +01:00
|
|
|
ecomm, bgp_attr_get_ecommunity(
|
|
|
|
mpinfo->attr));
|
2015-05-20 03:03:58 +02:00
|
|
|
ecomm = ecommunity_uniq_sort(ecommerge);
|
|
|
|
ecommunity_free(&ecommerge);
|
|
|
|
} else
|
2017-06-06 19:20:38 +02:00
|
|
|
ecomm = ecommunity_dup(
|
2022-02-04 14:56:20 +01:00
|
|
|
bgp_attr_get_ecommunity(
|
|
|
|
mpinfo->attr));
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
2022-02-09 12:44:25 +01:00
|
|
|
if (bgp_attr_get_lcommunity(mpinfo->attr)) {
|
2016-11-15 11:00:39 +01:00
|
|
|
if (lcomm) {
|
2017-06-06 19:20:38 +02:00
|
|
|
lcommerge = lcommunity_merge(
|
2022-02-09 12:44:25 +01:00
|
|
|
lcomm, bgp_attr_get_lcommunity(
|
|
|
|
mpinfo->attr));
|
2016-11-15 11:00:39 +01:00
|
|
|
lcomm = lcommunity_uniq_sort(lcommerge);
|
|
|
|
lcommunity_free(&lcommerge);
|
|
|
|
} else
|
2017-06-06 19:20:38 +02:00
|
|
|
lcomm = lcommunity_dup(
|
2022-02-09 12:44:25 +01:00
|
|
|
bgp_attr_get_lcommunity(
|
|
|
|
mpinfo->attr));
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2015-05-20 03:03:58 +02:00
|
|
|
attr.aspath = aspath;
|
|
|
|
attr.origin = origin;
|
2022-04-12 21:12:16 +02:00
|
|
|
if (community)
|
2022-02-23 08:05:47 +01:00
|
|
|
bgp_attr_set_community(&attr, community);
|
2022-04-12 10:06:52 +02:00
|
|
|
if (ecomm)
|
2022-02-04 14:56:20 +01:00
|
|
|
bgp_attr_set_ecommunity(&attr, ecomm);
|
2022-04-11 17:09:35 +02:00
|
|
|
if (lcomm)
|
2022-02-09 12:44:25 +01:00
|
|
|
bgp_attr_set_lcommunity(&attr, lcomm);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 03:03:58 +02:00
|
|
|
/* Zap multipath attr nexthop so we set nexthop to self */
|
2020-02-06 07:49:02 +01:00
|
|
|
attr.nexthop.s_addr = INADDR_ANY;
|
2017-06-06 19:20:38 +02:00
|
|
|
memset(&attr.mp_nexthop_global, 0, sizeof(struct in6_addr));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 03:03:58 +02:00
|
|
|
/* TODO: should we set ATOMIC_AGGREGATE and AGGREGATOR? */
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:49:11 +02:00
|
|
|
new_attr = bgp_attr_intern(&attr);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
if (new_attr != bgp_path_info_mpath_attr(new_best)) {
|
|
|
|
if ((old_attr = bgp_path_info_mpath_attr(new_best)))
|
2012-04-28 22:37:20 +02:00
|
|
|
bgp_attr_unintern(&old_attr);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_attr_set(new_best, new_attr);
|
2018-09-14 02:34:42 +02:00
|
|
|
SET_FLAG(new_best->flags, BGP_PATH_ATTR_CHANGED);
|
2011-07-21 05:49:11 +02:00
|
|
|
} else
|
2012-04-28 22:37:20 +02:00
|
|
|
bgp_attr_unintern(&new_attr);
|
2011-07-21 05:49:11 +02:00
|
|
|
}
|