Skip to content

Commit

Permalink
bgpd: Sort the bgp_path_info's
Browse files Browse the repository at this point in the history
Currently bgp_path_info's are stored in reverse order
received.  Sort them by the best path ordering.

This will allow for optimizations in the future on
how multipath is done.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Apr 1, 2024
1 parent 6ebb7ad commit f099883
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 69 deletions.
20 changes: 17 additions & 3 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,13 +1440,26 @@ static void evpn_delete_old_local_route(struct bgp *bgp, struct bgpevpn *vpn,
int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
struct bgp_dest *dest, struct bgp_path_info *pi)
{
struct bgp_path_info *old_select, *new_select;
struct bgp_path_info *old_select, *new_select, *first;
struct bgp_path_info_pair old_and_new;
afi_t afi = AFI_L2VPN;
safi_t safi = SAFI_EVPN;
int ret = 0;

first = bgp_dest_get_bgp_path_info(dest);
SET_FLAG(pi->flags, BGP_PATH_UNSORTED);
if (pi != first) {
if (pi->next)
pi->next->prev = pi->prev;
if (pi->prev)
pi->prev->next = pi->next;

if (first)
first->prev = pi;
pi->next = first;
pi->prev = NULL;
bgp_dest_set_bgp_path_info(dest, pi);
}

/* Compute the best path. */
bgp_best_selection(bgp, dest, &bgp->maxpaths[afi][safi], &old_and_new,
Expand Down Expand Up @@ -6429,9 +6442,10 @@ void bgp_filter_evpn_routes_upon_martian_change(

for (dest = bgp_table_top(table); dest;
dest = bgp_route_next(dest)) {
struct bgp_path_info *next;

for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
for (pi = bgp_dest_get_bgp_path_info(dest);
(pi != NULL) && (next = pi->next, 1); pi = next) {
bool affected = false;
const struct prefix *p;

Expand Down
19 changes: 11 additions & 8 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp, struct bgp *from_bgp,

struct bgp_table *table;
struct bgp_dest *bn;
struct bgp_path_info *bpi;
struct bgp_path_info *bpi, *next;

/* This is the per-RD table of prefixes */
table = bgp_dest_get_bgp_table_info(pdest);
Expand All @@ -1991,7 +1991,8 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp, struct bgp *from_bgp,
__func__, bn);
}

for (; bpi; bpi = bpi->next) {
for (; (bpi != NULL) && (next = bpi->next, 1);
bpi = next) {
if (debug)
zlog_debug("%s: type %d, sub_type %d",
__func__, bpi->type,
Expand Down Expand Up @@ -2515,7 +2516,7 @@ void vpn_leak_to_vrf_withdraw(struct bgp_path_info *path_vpn)
void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi)
{
struct bgp_dest *bn;
struct bgp_path_info *bpi;
struct bgp_path_info *bpi, *next;
safi_t safi = SAFI_UNICAST;
int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF);

Expand All @@ -2526,9 +2527,8 @@ void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi)
*/
for (bn = bgp_table_top(to_bgp->rib[afi][safi]); bn;
bn = bgp_route_next(bn)) {

for (bpi = bgp_dest_get_bgp_path_info(bn); bpi;
bpi = bpi->next) {
for (bpi = bgp_dest_get_bgp_path_info(bn);
(bpi != NULL) && (next = bpi->next, 1); bpi = next) {
if (bpi->extra && bpi->extra->vrfleak &&
bpi->extra->vrfleak->bgp_orig != to_bgp &&
bpi->extra->vrfleak->parent &&
Expand Down Expand Up @@ -2567,8 +2567,11 @@ void vpn_leak_no_retain(struct bgp *to_bgp, struct bgp *vpn_from, afi_t afi)
continue;

for (bn = bgp_table_top(table); bn; bn = bgp_route_next(bn)) {
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi;
bpi = bpi->next) {
struct bgp_path_info *next;

for (bpi = bgp_dest_get_bgp_path_info(bn);
(bpi != NULL) && (next = bpi->next, 1);
bpi = next) {
if (bpi->extra && bpi->extra->vrfleak &&
bpi->extra->vrfleak->bgp_orig == to_bgp)
continue;
Expand Down
Loading

0 comments on commit f099883

Please sign in to comment.