From 82b11d88898e1f6c6b36e7f8c379ce7282168c10 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 28 Aug 2023 12:23:24 +0200 Subject: [PATCH] bgpd: fix redistribute table command after bgp restarts When the BGP 'redistribute table' command is used for a given route table, and BGP configuration is flushed and rebuilt, the redistribution does not work. Actually, when flushing the BGP configuration with the 'no router bgp' command, the BGP redistribute entries related to the 'redistribute table' entries are not flushed. Actually, at BGP deletion, the table number is not given as parameter in bgp_redistribute_unset() function, and the redistribution entry is not removed in zebra. Fix this by adding some code to flush all the redistribute table instances. Fixes: 7c8ff89e9346 ("Multi-Instance OSPF Summary") Signed-off-by: Philippe Guibert --- bgpd/bgp_vty.c | 9 ++++++--- bgpd/bgp_zebra.c | 23 +++++++++++++++++++---- bgpd/bgp_zebra.h | 4 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 445dea92d5..7167deeb44 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -16974,7 +16974,8 @@ DEFUN (no_bgp_redistribute_ipv4_ospf, protocol = ZEBRA_ROUTE_TABLE; instance = strtoul(argv[idx_number]->arg, NULL, 10); - return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance); + bgp_redistribute_unset(bgp, AFI_IP, protocol, instance); + return CMD_SUCCESS; } ALIAS_HIDDEN( @@ -17010,7 +17011,8 @@ DEFUN (no_bgp_redistribute_ipv4, vty_out(vty, "%% Invalid route type\n"); return CMD_WARNING_CONFIG_FAILED; } - return bgp_redistribute_unset(bgp, AFI_IP, type, 0); + bgp_redistribute_unset(bgp, AFI_IP, type, 0); + return CMD_SUCCESS; } ALIAS_HIDDEN( @@ -17194,7 +17196,8 @@ DEFUN (no_bgp_redistribute_ipv6, return CMD_WARNING_CONFIG_FAILED; } - return bgp_redistribute_unset(bgp, AFI_IP6, type, 0); + bgp_redistribute_unset(bgp, AFI_IP6, type, 0); + return CMD_SUCCESS; } /* Neighbor update tcp-mss. */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 21ccbebe67..489a9e9797 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -2078,8 +2078,8 @@ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, } /* Unset redistribution. */ -int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, - unsigned short instance) +static void _bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance) { struct bgp_redist *red; @@ -2096,7 +2096,7 @@ int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, red = bgp_redist_lookup(bgp, afi, type, instance); if (!red) - return CMD_SUCCESS; + return; bgp_redistribute_unreg(bgp, afi, type, instance); @@ -2110,8 +2110,23 @@ int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, red->redist_metric = 0; bgp_redist_del(bgp, afi, type, instance); +} - return CMD_SUCCESS; +void bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance) +{ + struct listnode *node, *nnode; + struct bgp_redist *red; + + if (type != ZEBRA_ROUTE_TABLE || instance != 0) + return _bgp_redistribute_unset(bgp, afi, type, instance); + + /* walk over instance */ + if (!bgp->redist[afi][type]) + return; + + for (ALL_LIST_ELEMENTS(bgp->redist[afi][type], node, nnode, red)) + _bgp_redistribute_unset(bgp, afi, type, red->instance); } void bgp_redistribute_redo(struct bgp *bgp) diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index ed2d5e669d..0edae041d2 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -64,8 +64,8 @@ extern bool bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, struct route_map *route_map); extern bool bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, afi_t afi, int type, uint32_t metric); -extern int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, - unsigned short instance); +extern void bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance); extern int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, unsigned short instance); -- 2.39.5