From 7e14d0fab23955f345ecef9893238845b4be30fe Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Fri, 18 Nov 2022 16:56:09 +0100 Subject: [PATCH] bgpd: store the confederation as identifier as a string The confederation peers as and the confederation identifier as are stored as a string to preserve the output in the running configuration. Signed-off-by: Philippe Guibert --- bgpd/bgp_vty.c | 11 ++++++----- bgpd/bgpd.c | 40 +++++++++++++++++++++++++++------------- bgpd/bgpd.h | 14 +++++++++++--- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 6a01791444..87d5d27385 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -2003,7 +2003,7 @@ DEFUN (bgp_confederation_identifier, return CMD_WARNING_CONFIG_FAILED; } - bgp_confederation_id_set(bgp, as); + bgp_confederation_id_set(bgp, as, argv[idx_number]->arg); return CMD_SUCCESS; } @@ -2043,7 +2043,7 @@ DEFUN (bgp_confederation_peers, continue; } - bgp_confederation_peers_add(bgp, as); + bgp_confederation_peers_add(bgp, as, argv[i]->arg); } return CMD_SUCCESS; } @@ -18163,8 +18163,8 @@ int bgp_config_write(struct vty *vty) /* Confederation identifier*/ if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) - vty_out(vty, " bgp confederation identifier %u\n", - bgp->confed_id); + vty_out(vty, " bgp confederation identifier %s\n", + bgp->confed_id_pretty); /* Confederation peer */ if (bgp->confed_peers_cnt > 0) { @@ -18173,7 +18173,8 @@ int bgp_config_write(struct vty *vty) vty_out(vty, " bgp confederation peers"); for (i = 0; i < bgp->confed_peers_cnt; i++) - vty_out(vty, " %u", bgp->confed_peers[i]); + vty_out(vty, " %s", + bgp->confed_peers[i].as_pretty); vty_out(vty, "\n"); } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 97e55a9fb1..69557507d0 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -568,7 +568,7 @@ void bgp_tcp_keepalive_unset(struct bgp *bgp) } /* BGP confederation configuration. */ -void bgp_confederation_id_set(struct bgp *bgp, as_t as) +void bgp_confederation_id_set(struct bgp *bgp, as_t as, const char *as_str) { struct peer *peer; struct listnode *node, *nnode; @@ -580,6 +580,9 @@ void bgp_confederation_id_set(struct bgp *bgp, as_t as) /* Remember - were we doing confederation before? */ already_confed = bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION); bgp->confed_id = as; + if (bgp->confed_id_pretty) + XFREE(MTYPE_BGP, bgp->confed_id_pretty); + bgp->confed_id_pretty = XSTRDUP(MTYPE_BGP, as_str); bgp_config_set(bgp, BGP_CONFIG_CONFEDERATION); /* If we were doing confederation already, this is just an external @@ -632,6 +635,7 @@ void bgp_confederation_id_unset(struct bgp *bgp) struct listnode *node, *nnode; bgp->confed_id = 0; + XFREE(MTYPE_BGP, bgp->confed_id_pretty); bgp_config_unset(bgp, BGP_CONFIG_CONFEDERATION); for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { @@ -659,14 +663,14 @@ bool bgp_confederation_peers_check(struct bgp *bgp, as_t as) return false; for (i = 0; i < bgp->confed_peers_cnt; i++) - if (bgp->confed_peers[i] == as) + if (bgp->confed_peers[i].as == as) return true; return false; } /* Add an AS to the confederation set. */ -void bgp_confederation_peers_add(struct bgp *bgp, as_t as) +void bgp_confederation_peers_add(struct bgp *bgp, as_t as, const char *as_str) { struct peer *peer; struct listnode *node, *nnode; @@ -677,11 +681,13 @@ void bgp_confederation_peers_add(struct bgp *bgp, as_t as) if (bgp_confederation_peers_check(bgp, as)) return; - bgp->confed_peers = - XREALLOC(MTYPE_BGP_CONFED_LIST, bgp->confed_peers, - (bgp->confed_peers_cnt + 1) * sizeof(as_t)); + bgp->confed_peers = XREALLOC(MTYPE_BGP_CONFED_LIST, bgp->confed_peers, + (bgp->confed_peers_cnt + 1) * + sizeof(struct as_confed)); - bgp->confed_peers[bgp->confed_peers_cnt] = as; + bgp->confed_peers[bgp->confed_peers_cnt].as = as; + bgp->confed_peers[bgp->confed_peers_cnt].as_pretty = + XSTRDUP(MTYPE_BGP, as_str); bgp->confed_peers_cnt++; if (bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION)) { @@ -718,9 +724,15 @@ void bgp_confederation_peers_remove(struct bgp *bgp, as_t as) return; for (i = 0; i < bgp->confed_peers_cnt; i++) - if (bgp->confed_peers[i] == as) - for (j = i + 1; j < bgp->confed_peers_cnt; j++) - bgp->confed_peers[j - 1] = bgp->confed_peers[j]; + if (bgp->confed_peers[i].as == as) { + XFREE(MTYPE_BGP, bgp->confed_peers[i].as_pretty); + for (j = i + 1; j < bgp->confed_peers_cnt; j++) { + bgp->confed_peers[j - 1].as = + bgp->confed_peers[j].as; + bgp->confed_peers[j - 1].as_pretty = + bgp->confed_peers[j].as_pretty; + } + } bgp->confed_peers_cnt--; @@ -729,9 +741,9 @@ void bgp_confederation_peers_remove(struct bgp *bgp, as_t as) XFREE(MTYPE_BGP_CONFED_LIST, bgp->confed_peers); bgp->confed_peers = NULL; } else - bgp->confed_peers = - XREALLOC(MTYPE_BGP_CONFED_LIST, bgp->confed_peers, - bgp->confed_peers_cnt * sizeof(as_t)); + bgp->confed_peers = XREALLOC( + MTYPE_BGP_CONFED_LIST, bgp->confed_peers, + bgp->confed_peers_cnt * sizeof(struct as_confed)); /* Now reset any peer who's remote AS has just been removed from the CONFED */ @@ -3961,6 +3973,8 @@ void bgp_free(struct bgp *bgp) ecommunity_free(&bgp->vpn_policy[afi].rtlist[dir]); } + bgp_confederation_id_unset(bgp); + XFREE(MTYPE_BGP, bgp->as_pretty); XFREE(MTYPE_BGP, bgp->name); XFREE(MTYPE_BGP, bgp->name_pretty); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 995c92d225..57685390c8 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -339,6 +339,11 @@ struct bgp_srv6_function { char locator_name[SRV6_LOCNAME_SIZE]; }; +struct as_confed { + as_t as; + char *as_pretty; +}; + /* BGP instance structure. */ struct bgp { /* AS number of this BGP instance. */ @@ -411,7 +416,8 @@ struct bgp { /* BGP confederation information. */ as_t confed_id; - as_t *confed_peers; + char *confed_id_pretty; + struct as_confed *confed_peers; int confed_peers_cnt; struct thread @@ -2187,11 +2193,13 @@ extern void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set); extern void bgp_cluster_id_set(struct bgp *bgp, struct in_addr *cluster_id); extern void bgp_cluster_id_unset(struct bgp *bgp); -extern void bgp_confederation_id_set(struct bgp *bgp, as_t as); +extern void bgp_confederation_id_set(struct bgp *bgp, as_t as, + const char *as_str); extern void bgp_confederation_id_unset(struct bgp *bgp); extern bool bgp_confederation_peers_check(struct bgp *, as_t); -extern void bgp_confederation_peers_add(struct bgp *bgp, as_t as); +extern void bgp_confederation_peers_add(struct bgp *bgp, as_t as, + const char *as_str); extern void bgp_confederation_peers_remove(struct bgp *bgp, as_t as); extern void bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime,