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.
|
|
|
|
*
|
|
|
|
* This file is part of Quagga
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_cmp
|
2011-07-21 05:45:12 +02:00
|
|
|
*
|
|
|
|
* This function determines our multipath list ordering. By ordering
|
|
|
|
* the list we can deterministically select which paths are included
|
|
|
|
* in the multipath set. The ordering also helps in detecting changes
|
|
|
|
* in the multipath selection so we can detect whether to send an
|
|
|
|
* update to zebra.
|
|
|
|
*
|
|
|
|
* The order of paths is determined first by received nexthop, and then
|
|
|
|
* by peer address if the nexthops are the same.
|
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
static int bgp_path_info_mpath_cmp(void *val1, void *val2)
|
2011-07-21 05:45:12 +02:00
|
|
|
{
|
2018-10-03 02:43:07 +02:00
|
|
|
struct bgp_path_info *bpi1, *bpi2;
|
2011-07-21 05:45:12 +02:00
|
|
|
int compare;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 02:43:07 +02:00
|
|
|
bpi1 = val1;
|
|
|
|
bpi2 = val2;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 02:43:07 +02:00
|
|
|
compare = bgp_path_info_nexthop_cmp(bpi1, bpi2);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:45:12 +02:00
|
|
|
if (!compare) {
|
2018-10-03 02:43:07 +02:00
|
|
|
if (!bpi1->peer->su_remote && !bpi2->peer->su_remote)
|
2016-03-13 07:03:10 +01:00
|
|
|
compare = 0;
|
2018-10-03 02:43:07 +02:00
|
|
|
else if (!bpi1->peer->su_remote)
|
2016-03-13 07:03:10 +01:00
|
|
|
compare = 1;
|
2018-10-03 02:43:07 +02:00
|
|
|
else if (!bpi2->peer->su_remote)
|
2016-03-13 07:03:10 +01:00
|
|
|
compare = -1;
|
|
|
|
else
|
2018-10-03 02:43:07 +02:00
|
|
|
compare = sockunion_cmp(bpi1->peer->su_remote,
|
|
|
|
bpi2->peer->su_remote);
|
2016-03-13 07:03:10 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:45:12 +02:00
|
|
|
return compare;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_mp_list_init
|
|
|
|
*
|
|
|
|
* Initialize the mp_list, which holds the list of multipaths
|
|
|
|
* selected by bgp_best_selection
|
|
|
|
*/
|
|
|
|
void bgp_mp_list_init(struct list *mp_list)
|
|
|
|
{
|
|
|
|
assert(mp_list);
|
|
|
|
memset(mp_list, 0, sizeof(struct list));
|
2018-10-03 00:15:34 +02:00
|
|
|
mp_list->cmp = bgp_path_info_mpath_cmp;
|
2011-07-21 05:45:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_mp_list_clear
|
|
|
|
*
|
|
|
|
* Clears all entries out of the mp_list
|
|
|
|
*/
|
|
|
|
void bgp_mp_list_clear(struct list *mp_list)
|
|
|
|
{
|
|
|
|
assert(mp_list);
|
|
|
|
list_delete_all_node(mp_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_mp_list_add
|
|
|
|
*
|
|
|
|
* Adds a multipath entry to the mp_list
|
|
|
|
*/
|
2018-10-02 22:41:30 +02:00
|
|
|
void bgp_mp_list_add(struct list *mp_list, struct bgp_path_info *mpinfo)
|
2011-07-21 05:45:12 +02:00
|
|
|
{
|
|
|
|
assert(mp_list && mpinfo);
|
|
|
|
listnode_add_sort(mp_list, mpinfo);
|
|
|
|
}
|
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
|
|
|
|
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);
|
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_enqueue
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
|
|
|
* Enqueue a path onto the multipath list given the previous multipath
|
|
|
|
* list entry
|
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
static void bgp_path_info_mpath_enqueue(struct bgp_path_info *prev_info,
|
2018-10-03 00:34:03 +02:00
|
|
|
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 *prev, *mpath;
|
2011-07-21 05:46:01 +02:00
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
prev = bgp_path_info_mpath_get(prev_info);
|
2018-10-03 00:34:03 +02:00
|
|
|
mpath = bgp_path_info_mpath_get(path);
|
2011-07-21 05:46:01 +02:00
|
|
|
if (!prev || !mpath)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mpath->mp_next = prev->mp_next;
|
|
|
|
mpath->mp_prev = prev;
|
|
|
|
if (prev->mp_next)
|
|
|
|
prev->mp_next->mp_prev = mpath;
|
|
|
|
prev->mp_next = mpath;
|
|
|
|
|
2018-10-03 00:34:03 +02:00
|
|
|
SET_FLAG(path->flags, BGP_PATH_MULTIPATH);
|
2011-07-21 05:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-10-03 00:15:34 +02:00
|
|
|
* bgp_path_info_mpath_dequeue
|
2011-07-21 05:46:01 +02:00
|
|
|
*
|
|
|
|
* Remove a path from the multipath list
|
|
|
|
*/
|
2018-10-03 00:34:03 +02:00
|
|
|
void bgp_path_info_mpath_dequeue(struct bgp_path_info *path)
|
2011-07-21 05:46:01 +02:00
|
|
|
{
|
2018-10-03 00:34:03 +02:00
|
|
|
struct bgp_path_info_mpath *mpath = path->mpath;
|
2011-07-21 05:46:01 +02:00
|
|
|
if (!mpath)
|
|
|
|
return;
|
|
|
|
if (mpath->mp_prev)
|
|
|
|
mpath->mp_prev->mp_next = mpath->mp_next;
|
|
|
|
if (mpath->mp_next)
|
|
|
|
mpath->mp_next->mp_prev = mpath->mp_prev;
|
|
|
|
mpath->mp_next = mpath->mp_prev = NULL;
|
2018-10-03 00:34:03 +02:00
|
|
|
UNSET_FLAG(path->flags, BGP_PATH_MULTIPATH);
|
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
|
|
|
{
|
2018-10-03 00:34:03 +02:00
|
|
|
if (!path->mpath || !path->mpath->mp_next)
|
2011-07-21 05:46:01 +02:00
|
|
|
return NULL;
|
2018-10-03 00:34:03 +02:00
|
|
|
return path->mpath->mp_next->mp_info;
|
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)
|
2011-07-21 05:46:01 +02:00
|
|
|
return 0;
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
|
|
|
* Compare and sync up the multipath list with the mp_list generated by
|
|
|
|
* bgp_best_selection
|
|
|
|
*/
|
2021-11-12 16:46:48 +01:00
|
|
|
void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest,
|
2018-10-03 00:15:34 +02:00
|
|
|
struct bgp_path_info *new_best,
|
|
|
|
struct bgp_path_info *old_best,
|
|
|
|
struct list *mp_list,
|
|
|
|
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;
|
2011-07-21 05:46:01 +02:00
|
|
|
struct listnode *mp_node, *mp_next_node;
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info *cur_mpath, *new_mpath, *next_mpath, *prev_mpath;
|
2011-07-21 05:46:01 +02:00
|
|
|
int 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];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
mpath_changed = 0;
|
2016-11-04 00:59:19 +01:00
|
|
|
maxpaths = multipath_num;
|
2011-07-21 05:46:01 +02:00
|
|
|
mpath_count = 0;
|
|
|
|
cur_mpath = NULL;
|
|
|
|
old_mpath_count = 0;
|
2020-03-24 21:57:44 +01:00
|
|
|
old_cum_bw = cum_bw = 0;
|
2011-07-21 05:46:01 +02:00
|
|
|
prev_mpath = new_best;
|
|
|
|
mp_node = listhead(mp_list);
|
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 (new_best) {
|
|
|
|
mpath_count++;
|
|
|
|
if (new_best != old_best)
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_dequeue(new_best);
|
2012-05-07 18:52:54 +02:00
|
|
|
maxpaths = (new_best->peer->sort == BGP_PEER_IBGP)
|
2011-07-21 05:46:01 +02:00
|
|
|
? mpath_cfg->maxpaths_ibgp
|
|
|
|
: mpath_cfg->maxpaths_ebgp;
|
|
|
|
}
|
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
|
|
|
cur_mpath = bgp_path_info_mpath_first(old_best);
|
|
|
|
old_mpath_count = bgp_path_info_mpath_count(old_best);
|
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);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_dequeue(old_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)
|
2023-11-13 16:26:48 +01:00
|
|
|
zlog_debug("%pBD(%s): starting mpath update, newbest %s num candidates %d old-mpath-count %d old-cum-bw %" PRIu64,
|
|
|
|
dest, bgp->name_pretty,
|
|
|
|
new_best ? new_best->peer->host : "NONE",
|
|
|
|
mp_list ? listcount(mp_list) : 0, old_mpath_count,
|
|
|
|
old_cum_bw);
|
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. */
|
2011-07-21 05:46:01 +02:00
|
|
|
while (mp_node || cur_mpath) {
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info *tmp_info;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
|
|
|
* We can bail out of this loop if all existing paths on the
|
|
|
|
* multipath list have been visited (for cleanup purposes) and
|
|
|
|
* the maxpath requirement is fulfulled
|
|
|
|
*/
|
|
|
|
if (!cur_mpath && (mpath_count >= maxpaths))
|
|
|
|
break;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
mp_next_node = mp_node ? listnextnode(mp_node) : NULL;
|
2018-10-03 00:15:34 +02:00
|
|
|
next_mpath =
|
|
|
|
cur_mpath ? bgp_path_info_mpath_next(cur_mpath) : NULL;
|
2016-09-05 19:53:06 +02:00
|
|
|
tmp_info = mp_node ? listgetdata(mp_node) : NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-05 19:53:06 +02:00
|
|
|
if (debug)
|
2023-11-13 16:26:48 +01:00
|
|
|
zlog_debug("%pBD(%s): comparing candidate %s with existing mpath %s",
|
|
|
|
dest, bgp->name_pretty,
|
|
|
|
tmp_info ? tmp_info->peer->host : "NONE",
|
|
|
|
cur_mpath ? cur_mpath->peer->host : "NONE");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
/*
|
|
|
|
* If equal, the path was a multipath and is still a multipath.
|
|
|
|
* Insert onto new multipath list if maxpaths allows.
|
|
|
|
*/
|
|
|
|
if (mp_node && (listgetdata(mp_node) == cur_mpath)) {
|
|
|
|
list_delete_node(mp_list, mp_node);
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_dequeue(cur_mpath);
|
bgpd: fix do not skip paths with same nexthop
Under a setup where two BGP prefixes are available from multiple sources,
if one of the two prefixes is recursive over the other BGP prefix, then
it will not be considered as multipath. The below output shows the two
prefixes 192.0.2.24/32 and 192.0.2.21/32. The 192.0.2.[5,6,8] are the
known IP addresses visible from the IGP.
> # show bgp ipv4 192.0.2.24/32
> *>i 192.0.2.24/32 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> # show bgp ipv4 192.0.2.21/32
> *>i 192.0.2.21/32 192.0.2.5 0 100 0 i
> *=i 192.0.2.6 0 100 0 i
> *=i 192.0.2.8 0 100 0 i
The bgp best selection algorithm refuses to consider the paths to
'192.0.2.24/32' as multipath, whereas the BGP paths which use the
BGP peer as nexthop are considered multipath.
> ... has the same nexthop as the bestpath, skip it ...
Previously, this condition has been added to prevent ZEBRA from
installing routes with same nexthop:
> Here you can see the two paths with nexthop 210.2.2.2
> superm-redxp-05# show ip route 2.23.24.192/28
> Routing entry for 2.23.24.192/28
> Known via "bgp", distance 20, metric 0, best
> Last update 00:32:12 ago
> * 210.2.2.2, via swp3
> * 210.2.0.2, via swp1
> * 210.2.1.2, via swp2
> * 210.2.2.2, via swp3
> [..]
But today, ZEBRA knows how to handle it. When receiving incoming routes,
nexthop groups are used. At creation, duplicated nexthops are
identified, and will not be installed. The below output illustrate the
duplicate paths to 172.16.0.200 received by an other peer.
> r1# show ip route 172.18.1.100 nexthop-group
> Routing entry for 172.18.1.100/32
> Known via "bgp", distance 200, metric 0, best
> Last update 00:03:03 ago
> Nexthop Group ID: 75757580
> 172.16.0.200 (recursive), weight 1
> * 172.31.0.3, via r1-eth1, label 16055, weight 1
> * 172.31.2.4, via r1-eth2, label 16055, weight 1
> * 172.31.0.3, via r1-eth1, label 16006, weight 1
> * 172.31.2.4, via r1-eth2, label 16006, weight 1
> * 172.31.8.7, via r1-eth4, label 16008, weight 1
> 172.16.0.200 (duplicate nexthop removed) (recursive), weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16055, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16055, weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16006, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16006, weight 1
> 172.31.8.7, via r1-eth4 (duplicate nexthop removed), label 16008, weight 1
Fix this by proposing to let ZEBRA handle this duplicate decision.
Fixes: 7dc9d4e4e360 ("bgp may add multiple path entries with the same nexthop")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-05-30 15:47:11 +02:00
|
|
|
if ((mpath_count < maxpaths) && prev_mpath) {
|
|
|
|
mpath_count++;
|
|
|
|
if (bgp_path_info_nexthop_cmp(prev_mpath,
|
|
|
|
cur_mpath)) {
|
|
|
|
if (ecommunity_linkbw_present(
|
|
|
|
bgp_attr_get_ecommunity(
|
|
|
|
cur_mpath->attr),
|
|
|
|
&bwval) ||
|
|
|
|
ecommunity_linkbw_present(
|
|
|
|
bgp_attr_get_ipv6_ecommunity(
|
|
|
|
cur_mpath->attr),
|
|
|
|
&bwval))
|
|
|
|
cum_bw += bwval;
|
|
|
|
else
|
|
|
|
all_paths_lb = false;
|
|
|
|
if (debug) {
|
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
|
|
|
cur_mpath, path_buf,
|
|
|
|
sizeof(path_buf));
|
|
|
|
zlog_debug("%pBD: %s is still multipath, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
mpath_count);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (debug) {
|
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
|
|
|
cur_mpath, path_buf,
|
|
|
|
sizeof(path_buf));
|
|
|
|
zlog_debug("%pBD: nexthop equal, however add mpath %s nexthop %pI4, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
&cur_mpath->attr->nexthop,
|
|
|
|
mpath_count);
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_enqueue(prev_mpath,
|
|
|
|
cur_mpath);
|
2011-07-21 05:46:01 +02:00
|
|
|
prev_mpath = cur_mpath;
|
|
|
|
} else {
|
|
|
|
mpath_changed = 1;
|
|
|
|
if (debug) {
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
2021-02-08 04:39:42 +01:00
|
|
|
cur_mpath, path_buf,
|
|
|
|
sizeof(path_buf));
|
2023-11-13 16:26:48 +01:00
|
|
|
zlog_debug("%pBD: remove mpath %s nexthop %pI4, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
&cur_mpath->attr->nexthop,
|
|
|
|
mpath_count);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2015-12-07 20:56:02 +01:00
|
|
|
}
|
2011-07-21 05:46:01 +02:00
|
|
|
mp_node = mp_next_node;
|
|
|
|
cur_mpath = next_mpath;
|
|
|
|
continue;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2011-07-21 05:46:01 +02:00
|
|
|
if (cur_mpath
|
|
|
|
&& (!mp_node
|
2018-10-03 00:15:34 +02:00
|
|
|
|| (bgp_path_info_mpath_cmp(cur_mpath,
|
|
|
|
listgetdata(mp_node))
|
2011-07-21 05:46:01 +02:00
|
|
|
< 0))) {
|
|
|
|
/*
|
|
|
|
* If here, we have an old multipath and either the
|
|
|
|
* mp_list
|
|
|
|
* is finished or the next mp_node points to a later
|
|
|
|
* multipath, so we need to purge this path from the
|
|
|
|
* multipath list
|
|
|
|
*/
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_dequeue(cur_mpath);
|
2011-07-21 05:46:01 +02:00
|
|
|
mpath_changed = 1;
|
|
|
|
if (debug) {
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
2021-02-08 04:39:42 +01:00
|
|
|
cur_mpath, path_buf, sizeof(path_buf));
|
2023-11-13 16:26:48 +01:00
|
|
|
zlog_debug("%pBD: remove mpath %s nexthop %pI4, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
&cur_mpath->attr->nexthop,
|
|
|
|
mpath_count);
|
2015-12-07 20:56:02 +01:00
|
|
|
}
|
2011-07-21 05:46:01 +02:00
|
|
|
cur_mpath = next_mpath;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If here, we have a path on the mp_list that was not
|
|
|
|
* previously
|
|
|
|
* a multipath (due to non-equivalance or maxpaths
|
|
|
|
* exceeded),
|
|
|
|
* or the matching multipath is sorted later in the
|
|
|
|
* multipath
|
|
|
|
* list. Before we enqueue the path on the new multipath
|
|
|
|
* list,
|
|
|
|
* make sure its not on the old_best multipath list or
|
|
|
|
* referenced
|
|
|
|
* via next_mpath:
|
|
|
|
* - If next_mpath points to this new path, update
|
|
|
|
* next_mpath to
|
|
|
|
* point to the multipath after this one
|
|
|
|
* - Dequeue the path from the multipath list just to
|
|
|
|
* make sure
|
|
|
|
*/
|
|
|
|
new_mpath = listgetdata(mp_node);
|
|
|
|
list_delete_node(mp_list, mp_node);
|
2018-04-11 21:26:28 +02:00
|
|
|
assert(new_mpath);
|
|
|
|
assert(prev_mpath);
|
bgpd: fix do not skip paths with same nexthop
Under a setup where two BGP prefixes are available from multiple sources,
if one of the two prefixes is recursive over the other BGP prefix, then
it will not be considered as multipath. The below output shows the two
prefixes 192.0.2.24/32 and 192.0.2.21/32. The 192.0.2.[5,6,8] are the
known IP addresses visible from the IGP.
> # show bgp ipv4 192.0.2.24/32
> *>i 192.0.2.24/32 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> # show bgp ipv4 192.0.2.21/32
> *>i 192.0.2.21/32 192.0.2.5 0 100 0 i
> *=i 192.0.2.6 0 100 0 i
> *=i 192.0.2.8 0 100 0 i
The bgp best selection algorithm refuses to consider the paths to
'192.0.2.24/32' as multipath, whereas the BGP paths which use the
BGP peer as nexthop are considered multipath.
> ... has the same nexthop as the bestpath, skip it ...
Previously, this condition has been added to prevent ZEBRA from
installing routes with same nexthop:
> Here you can see the two paths with nexthop 210.2.2.2
> superm-redxp-05# show ip route 2.23.24.192/28
> Routing entry for 2.23.24.192/28
> Known via "bgp", distance 20, metric 0, best
> Last update 00:32:12 ago
> * 210.2.2.2, via swp3
> * 210.2.0.2, via swp1
> * 210.2.1.2, via swp2
> * 210.2.2.2, via swp3
> [..]
But today, ZEBRA knows how to handle it. When receiving incoming routes,
nexthop groups are used. At creation, duplicated nexthops are
identified, and will not be installed. The below output illustrate the
duplicate paths to 172.16.0.200 received by an other peer.
> r1# show ip route 172.18.1.100 nexthop-group
> Routing entry for 172.18.1.100/32
> Known via "bgp", distance 200, metric 0, best
> Last update 00:03:03 ago
> Nexthop Group ID: 75757580
> 172.16.0.200 (recursive), weight 1
> * 172.31.0.3, via r1-eth1, label 16055, weight 1
> * 172.31.2.4, via r1-eth2, label 16055, weight 1
> * 172.31.0.3, via r1-eth1, label 16006, weight 1
> * 172.31.2.4, via r1-eth2, label 16006, weight 1
> * 172.31.8.7, via r1-eth4, label 16008, weight 1
> 172.16.0.200 (duplicate nexthop removed) (recursive), weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16055, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16055, weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16006, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16006, weight 1
> 172.31.8.7, via r1-eth4 (duplicate nexthop removed), label 16008, weight 1
Fix this by proposing to let ZEBRA handle this duplicate decision.
Fixes: 7dc9d4e4e360 ("bgp may add multiple path entries with the same nexthop")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-05-30 15:47:11 +02:00
|
|
|
if ((mpath_count < maxpaths) && (new_mpath != new_best)) {
|
|
|
|
/* keep duplicate nexthop */
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_dequeue(new_mpath);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_enqueue(prev_mpath,
|
|
|
|
new_mpath);
|
2011-07-21 05:46:01 +02:00
|
|
|
mpath_changed = 1;
|
|
|
|
mpath_count++;
|
bgpd: fix do not skip paths with same nexthop
Under a setup where two BGP prefixes are available from multiple sources,
if one of the two prefixes is recursive over the other BGP prefix, then
it will not be considered as multipath. The below output shows the two
prefixes 192.0.2.24/32 and 192.0.2.21/32. The 192.0.2.[5,6,8] are the
known IP addresses visible from the IGP.
> # show bgp ipv4 192.0.2.24/32
> *>i 192.0.2.24/32 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> # show bgp ipv4 192.0.2.21/32
> *>i 192.0.2.21/32 192.0.2.5 0 100 0 i
> *=i 192.0.2.6 0 100 0 i
> *=i 192.0.2.8 0 100 0 i
The bgp best selection algorithm refuses to consider the paths to
'192.0.2.24/32' as multipath, whereas the BGP paths which use the
BGP peer as nexthop are considered multipath.
> ... has the same nexthop as the bestpath, skip it ...
Previously, this condition has been added to prevent ZEBRA from
installing routes with same nexthop:
> Here you can see the two paths with nexthop 210.2.2.2
> superm-redxp-05# show ip route 2.23.24.192/28
> Routing entry for 2.23.24.192/28
> Known via "bgp", distance 20, metric 0, best
> Last update 00:32:12 ago
> * 210.2.2.2, via swp3
> * 210.2.0.2, via swp1
> * 210.2.1.2, via swp2
> * 210.2.2.2, via swp3
> [..]
But today, ZEBRA knows how to handle it. When receiving incoming routes,
nexthop groups are used. At creation, duplicated nexthops are
identified, and will not be installed. The below output illustrate the
duplicate paths to 172.16.0.200 received by an other peer.
> r1# show ip route 172.18.1.100 nexthop-group
> Routing entry for 172.18.1.100/32
> Known via "bgp", distance 200, metric 0, best
> Last update 00:03:03 ago
> Nexthop Group ID: 75757580
> 172.16.0.200 (recursive), weight 1
> * 172.31.0.3, via r1-eth1, label 16055, weight 1
> * 172.31.2.4, via r1-eth2, label 16055, weight 1
> * 172.31.0.3, via r1-eth1, label 16006, weight 1
> * 172.31.2.4, via r1-eth2, label 16006, weight 1
> * 172.31.8.7, via r1-eth4, label 16008, weight 1
> 172.16.0.200 (duplicate nexthop removed) (recursive), weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16055, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16055, weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16006, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16006, weight 1
> 172.31.8.7, via r1-eth4 (duplicate nexthop removed), label 16008, weight 1
Fix this by proposing to let ZEBRA handle this duplicate decision.
Fixes: 7dc9d4e4e360 ("bgp may add multiple path entries with the same nexthop")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-05-30 15:47:11 +02:00
|
|
|
if (bgp_path_info_nexthop_cmp(prev_mpath,
|
|
|
|
new_mpath)) {
|
|
|
|
if (ecommunity_linkbw_present(
|
|
|
|
bgp_attr_get_ecommunity(
|
|
|
|
new_mpath->attr),
|
|
|
|
&bwval) ||
|
|
|
|
ecommunity_linkbw_present(
|
|
|
|
bgp_attr_get_ipv6_ecommunity(
|
|
|
|
new_mpath->attr),
|
|
|
|
&bwval))
|
|
|
|
cum_bw += bwval;
|
|
|
|
else
|
|
|
|
all_paths_lb = false;
|
|
|
|
if (debug) {
|
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
|
|
|
new_mpath, path_buf,
|
|
|
|
sizeof(path_buf));
|
|
|
|
zlog_debug("%pBD: add mpath %s nexthop %pI4, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
&new_mpath->attr
|
|
|
|
->nexthop,
|
|
|
|
mpath_count);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (debug) {
|
|
|
|
bgp_path_info_path_with_addpath_rx_str(
|
|
|
|
new_mpath, path_buf,
|
|
|
|
sizeof(path_buf));
|
|
|
|
zlog_debug("%pBD: nexthop equal, however add mpath %s nexthop %pI4, cur count %d",
|
|
|
|
dest, path_buf,
|
|
|
|
&new_mpath->attr
|
|
|
|
->nexthop,
|
|
|
|
mpath_count);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
bgpd: fix do not skip paths with same nexthop
Under a setup where two BGP prefixes are available from multiple sources,
if one of the two prefixes is recursive over the other BGP prefix, then
it will not be considered as multipath. The below output shows the two
prefixes 192.0.2.24/32 and 192.0.2.21/32. The 192.0.2.[5,6,8] are the
known IP addresses visible from the IGP.
> # show bgp ipv4 192.0.2.24/32
> *>i 192.0.2.24/32 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> * i 192.0.2.21 0 100 0 i
> # show bgp ipv4 192.0.2.21/32
> *>i 192.0.2.21/32 192.0.2.5 0 100 0 i
> *=i 192.0.2.6 0 100 0 i
> *=i 192.0.2.8 0 100 0 i
The bgp best selection algorithm refuses to consider the paths to
'192.0.2.24/32' as multipath, whereas the BGP paths which use the
BGP peer as nexthop are considered multipath.
> ... has the same nexthop as the bestpath, skip it ...
Previously, this condition has been added to prevent ZEBRA from
installing routes with same nexthop:
> Here you can see the two paths with nexthop 210.2.2.2
> superm-redxp-05# show ip route 2.23.24.192/28
> Routing entry for 2.23.24.192/28
> Known via "bgp", distance 20, metric 0, best
> Last update 00:32:12 ago
> * 210.2.2.2, via swp3
> * 210.2.0.2, via swp1
> * 210.2.1.2, via swp2
> * 210.2.2.2, via swp3
> [..]
But today, ZEBRA knows how to handle it. When receiving incoming routes,
nexthop groups are used. At creation, duplicated nexthops are
identified, and will not be installed. The below output illustrate the
duplicate paths to 172.16.0.200 received by an other peer.
> r1# show ip route 172.18.1.100 nexthop-group
> Routing entry for 172.18.1.100/32
> Known via "bgp", distance 200, metric 0, best
> Last update 00:03:03 ago
> Nexthop Group ID: 75757580
> 172.16.0.200 (recursive), weight 1
> * 172.31.0.3, via r1-eth1, label 16055, weight 1
> * 172.31.2.4, via r1-eth2, label 16055, weight 1
> * 172.31.0.3, via r1-eth1, label 16006, weight 1
> * 172.31.2.4, via r1-eth2, label 16006, weight 1
> * 172.31.8.7, via r1-eth4, label 16008, weight 1
> 172.16.0.200 (duplicate nexthop removed) (recursive), weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16055, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16055, weight 1
> 172.31.0.3, via r1-eth1 (duplicate nexthop removed), label 16006, weight 1
> 172.31.2.4, via r1-eth2 (duplicate nexthop removed), label 16006, weight 1
> 172.31.8.7, via r1-eth4 (duplicate nexthop removed), label 16008, weight 1
Fix this by proposing to let ZEBRA handle this duplicate decision.
Fixes: 7dc9d4e4e360 ("bgp may add multiple path entries with the same nexthop")
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-05-30 15:47:11 +02:00
|
|
|
prev_mpath = new_mpath;
|
2015-12-07 20:56:02 +01:00
|
|
|
}
|
2011-07-21 05:46:01 +02:00
|
|
|
mp_node = mp_next_node;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
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) {
|
2020-03-24 20:22:17 +01:00
|
|
|
bgp_path_info_mpath_count_set(new_best, mpath_count - 1);
|
2022-02-04 14:56:20 +01:00
|
|
|
if (mpath_count <= 1 ||
|
2024-04-11 10:52:02 +02:00
|
|
|
(!ecommunity_linkbw_present(bgp_attr_get_ecommunity(
|
|
|
|
new_best->attr),
|
|
|
|
&bwval) &&
|
|
|
|
!ecommunity_linkbw_present(bgp_attr_get_ipv6_ecommunity(
|
|
|
|
new_best->attr),
|
|
|
|
&bwval)))
|
2020-03-24 20:22:17 +01:00
|
|
|
all_paths_lb = false;
|
|
|
|
else
|
|
|
|
cum_bw += bwval;
|
|
|
|
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
|
|
|
|
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);
|
2020-03-24 21:57:44 +01:00
|
|
|
if ((mpath_count - 1) != old_mpath_count ||
|
|
|
|
old_cum_bw != cum_bw)
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* bgp_mp_dmed_deselect
|
|
|
|
*
|
2018-09-14 02:34:42 +02:00
|
|
|
* Clean up multipath information for BGP_PATH_DMED_SELECTED path that
|
2011-07-21 05:48:20 +02:00
|
|
|
* is not selected as best path
|
|
|
|
*/
|
2018-10-02 22:41:30 +02:00
|
|
|
void bgp_mp_dmed_deselect(struct bgp_path_info *dmed_best)
|
2011-07-21 05:48:20 +02:00
|
|
|
{
|
2018-10-02 22:41:30 +02:00
|
|
|
struct bgp_path_info *mpinfo, *mpnext;
|
2011-07-21 05:48:20 +02:00
|
|
|
|
|
|
|
if (!dmed_best)
|
|
|
|
return;
|
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
for (mpinfo = bgp_path_info_mpath_first(dmed_best); mpinfo;
|
2011-07-21 05:48:20 +02:00
|
|
|
mpinfo = mpnext) {
|
2018-10-03 00:15:34 +02:00
|
|
|
mpnext = bgp_path_info_mpath_next(mpinfo);
|
|
|
|
bgp_path_info_mpath_dequeue(mpinfo);
|
2011-07-21 05:48:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
bgp_path_info_mpath_count_set(dmed_best, 0);
|
2018-09-14 02:34:42 +02:00
|
|
|
UNSET_FLAG(dmed_best->flags, BGP_PATH_MULTIPATH_CHG);
|
2020-03-24 21:57:44 +01:00
|
|
|
UNSET_FLAG(dmed_best->flags, BGP_PATH_LINK_BW_CHG);
|
2019-02-25 20:49:00 +01:00
|
|
|
assert(bgp_path_info_mpath_first(dmed_best) == NULL);
|
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
|
|
|
|
2018-10-03 00:15:34 +02:00
|
|
|
if (!bgp_path_info_mpath_count(new_best)) {
|
|
|
|
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
|
|
|
}
|