From da18521b673de448170268c2fac80118d73923db Mon Sep 17 00:00:00 2001 From: Francois Dumontet Date: Wed, 13 Mar 2024 19:22:00 +0100 Subject: [PATCH] bgpd: make as-path-loop-detection conform to the framework currently: when as-path-loop-detection is set on a peer-group. members of the peer-group are not using that functionnality. analysis: the as-path-loop-detection, is not using the peer's flags related framework. fix: use the peer's flag framework for as-path-loop-detection. Signed-off-by: Francois Dumontet --- bgpd/bgp_route.c | 2 +- bgpd/bgp_updgrp.c | 8 +++++--- bgpd/bgp_vty.c | 22 +++------------------- bgpd/bgpd.c | 1 + bgpd/bgpd.h | 4 +--- 5 files changed, 11 insertions(+), 26 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 5d79a10591c8..8f5b2219c774 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2242,7 +2242,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, } /* AS path loop check. */ - if (peer->as_path_loop_detection && + if (CHECK_FLAG(peer->flags, PEER_FLAG_AS_LOOP_DETECTION) && aspath_loop_check(piattr->aspath, peer->as)) { if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) zlog_debug( diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index c522865ebabb..57a167f86463 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -151,7 +151,6 @@ static void conf_copy(struct peer *dst, struct peer *src, afi_t afi, dst->change_local_as = src->change_local_as; dst->shared_network = src->shared_network; dst->local_role = src->local_role; - dst->as_path_loop_detection = src->as_path_loop_detection; if (src->soo[afi][safi]) { ecommunity_free(&dst->soo[afi][safi]); @@ -360,9 +359,12 @@ static unsigned int updgrp_hash_key_make(const void *p) key = jhash_1word(peer->max_packet_size, key); key = jhash_1word(peer->pmax_out[afi][safi], key); - if (peer->as_path_loop_detection) - key = jhash_2words(peer->as, peer->as_path_loop_detection, key); + if (CHECK_FLAG(peer->flags, PEER_FLAG_AS_LOOP_DETECTION)) + key = jhash_2words(peer->as, + CHECK_FLAG(peer->flags, + PEER_FLAG_AS_LOOP_DETECTION), + key); if (peer->group) key = jhash_1word(jhash(peer->group->name, strlen(peer->group->name), SEED1), diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 292040578071..b1f6e2d82874 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -9198,15 +9198,7 @@ DEFPY( NEIGHBOR_ADDR_STR2 "Detect AS loops before sending to neighbor\n") { - struct peer *peer; - - peer = peer_and_group_lookup_vty(vty, neighbor); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; - - peer->as_path_loop_detection = true; - - return CMD_SUCCESS; + return peer_flag_set_vty(vty, neighbor, PEER_FLAG_AS_LOOP_DETECTION); } DEFPY (neighbor_addpath_paths_limit, @@ -9275,15 +9267,7 @@ DEFPY( NEIGHBOR_ADDR_STR2 "Detect AS loops before sending to neighbor\n") { - struct peer *peer; - - peer = peer_and_group_lookup_vty(vty, neighbor); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; - - peer->as_path_loop_detection = false; - - return CMD_SUCCESS; + return peer_flag_unset_vty(vty, neighbor, PEER_FLAG_AS_LOOP_DETECTION); } DEFPY(neighbor_path_attribute_discard, @@ -18460,7 +18444,7 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp, vty_out(vty, " neighbor %s strict-capability-match\n", addr); /* Sender side AS path loop detection. */ - if (peer->as_path_loop_detection) + if (peergroup_flag_check(peer, PEER_FLAG_AS_LOOP_DETECTION)) vty_out(vty, " neighbor %s sender-as-path-loop-detection\n", addr); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index be816c336139..fcff957d6517 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4587,6 +4587,7 @@ static const struct peer_flag_action peer_flag_action_list[] = { {PEER_FLAG_GRACEFUL_SHUTDOWN, 0, peer_change_none}, {PEER_FLAG_CAPABILITY_SOFT_VERSION, 0, peer_change_none}, {PEER_FLAG_CAPABILITY_FQDN, 0, peer_change_none}, + {PEER_FLAG_AS_LOOP_DETECTION, 0, peer_change_none}, {0, 0, 0}}; static const struct peer_flag_action peer_af_flag_action_list[] = { diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 94bb10725354..1c5f90c59bf8 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1470,6 +1470,7 @@ struct peer { #define PEER_FLAG_GRACEFUL_SHUTDOWN (1ULL << 35) #define PEER_FLAG_CAPABILITY_SOFT_VERSION (1ULL << 36) #define PEER_FLAG_CAPABILITY_FQDN (1ULL << 37) /* fqdn capability */ +#define PEER_FLAG_AS_LOOP_DETECTION (1ULL << 38) /* as path loop detection */ /* *GR-Disabled mode means unset PEER_FLAG_GRACEFUL_RESTART @@ -1823,9 +1824,6 @@ struct peer { char *hostname; char *domainname; - /* Sender side AS path loop detection. */ - bool as_path_loop_detection; - /* Extended Message Support */ uint16_t max_packet_size;