From fb78a9b66be380df139a99667b6f5ba2e0f2503c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 30 Oct 2024 12:48:35 -0400 Subject: [PATCH] bgpd: In bgp_update try to optimize is_loop_check variable The variable is_loop_check is being set and then later we test against it multiple times. Move the setting of whether or not to check for as loops to where it is tested against and stop testing it multiple times. Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index f58be40b72..814910f9c2 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4639,7 +4639,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, const char *reason; char pfx_buf[BGP_PRD_PATH_STRLEN]; int connected = 0; - int do_loop_check = 1; afi_t nh_afi; bool force_evpn_import = false; safi_t orig_safi = safi; @@ -4720,14 +4719,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, } } - /* If the peer is configured for "allowas-in origin" and the last ASN in - * the - * as-path is our ASN then we do not need to call aspath_loop_check - */ - if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN)) - if (aspath_get_last_as(attr->aspath) == bgp->as) - do_loop_check = 0; - /* When using bgp ipv4 labeled session, the local prefix is * received by a peer, and finds out that the proposed prefix * and its next-hop are the same. To avoid a route loop locally, @@ -4748,24 +4739,30 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, else bgp_nht_param_prefix = p; - /* AS path loop check. */ - if (do_loop_check) { + /* + * If the peer is configured for "allowas-in origin" and the last ASN in + * the as-path is our ASN then we do not need to call aspath_loop_check + */ + if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN) || + (aspath_get_last_as(attr->aspath) != bgp->as)) { + /* AS path loop check. */ if (aspath_loop_check(attr->aspath, bgp->as) > peer->allowas_in[afi][safi]) { peer->stat_pfx_aspath_loop++; reason = "as-path contains our own AS;"; goto filtered; } - } - /* If we're a CONFED we need to loop check the CONFED ID too */ - if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION) && do_loop_check) - if (aspath_loop_check_confed(attr->aspath, bgp->confed_id) > - peer->allowas_in[afi][safi]) { - peer->stat_pfx_aspath_loop++; - reason = "as-path contains our own confed AS;"; - goto filtered; + /* If we're a CONFED we need to loop check the CONFED ID too */ + if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) { + if (aspath_loop_check_confed(attr->aspath, bgp->confed_id) > + peer->allowas_in[afi][safi]) { + peer->stat_pfx_aspath_loop++; + reason = "as-path contains our own confed AS;"; + goto filtered; + } } + } /* Route reflector originator ID check. If ACCEPT_OWN mechanism is * enabled, then take care of that too. -- 2.39.5