From caf958b43a5c0d1496a6bcbbc14717a8227d95d4 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 31 Jul 2015 05:53:12 -0700 Subject: [PATCH] Fix redistribute metric change not taking effect Ticket: CM-6048 Reviewed-By: CCR-3251 Tested: See bug When a redistribute metric is changed, the new metric was not being used. Modify the code to look for existing redistributed routes and fix their metric. --- bgpd/bgp_vty.c | 18 +++++++++--------- bgpd/bgp_zebra.c | 16 +++++++++++++++- bgpd/bgp_zebra.h | 3 ++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 9ed641fada..a8e23bf1b4 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -10972,7 +10972,7 @@ DEFUN (bgp_redistribute_ipv4_metric, VTY_GET_INTEGER ("metric", metric, argv[1]); red = bgp_redist_add(vty->index, AFI_IP, type, 0); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric); return bgp_redistribute_set (AFI_IP, type, 0); } @@ -11000,7 +11000,7 @@ DEFUN (bgp_redistribute_ipv4_rmap_metric, red = bgp_redist_add(vty->index, AFI_IP, type, 0); bgp_redistribute_rmap_set (red, argv[1]); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric); return bgp_redistribute_set (AFI_IP, type, 0); } @@ -11027,7 +11027,7 @@ DEFUN (bgp_redistribute_ipv4_metric_rmap, VTY_GET_INTEGER ("metric", metric, argv[1]); red = bgp_redist_add(vty->index, AFI_IP, type, 0); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric); bgp_redistribute_rmap_set (red, argv[2]); return bgp_redistribute_set (AFI_IP, type, 0); } @@ -11103,7 +11103,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric, VTY_GET_INTEGER ("metric", metric, argv[2]); red = bgp_redist_add(vty->index, AFI_IP, protocol, instance); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric); return bgp_redistribute_set (AFI_IP, protocol, instance); } @@ -11134,7 +11134,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, red = bgp_redist_add(vty->index, AFI_IP, protocol, instance); bgp_redistribute_rmap_set (red, argv[2]); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric); return bgp_redistribute_set (AFI_IP, protocol, instance); } @@ -11164,7 +11164,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, VTY_GET_INTEGER ("metric", metric, argv[2]); red = bgp_redist_add(vty->index, AFI_IP, protocol, instance); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric); bgp_redistribute_rmap_set (red, argv[3]); return bgp_redistribute_set (AFI_IP, protocol, instance); } @@ -11360,7 +11360,7 @@ DEFUN (bgp_redistribute_ipv6_metric, VTY_GET_INTEGER ("metric", metric, argv[1]); red = bgp_redist_add(vty->index, AFI_IP6, type, 0); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric); return bgp_redistribute_set (AFI_IP6, type, 0); } @@ -11388,7 +11388,7 @@ DEFUN (bgp_redistribute_ipv6_rmap_metric, red = bgp_redist_add(vty->index, AFI_IP6, type, 0); bgp_redistribute_rmap_set (red, argv[1]); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric); return bgp_redistribute_set (AFI_IP6, type, 0); } @@ -11415,7 +11415,7 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap, VTY_GET_INTEGER ("metric", metric, argv[1]); red = bgp_redist_add(vty->index, AFI_IP6, type, 0); - bgp_redistribute_metric_set (red, metric); + bgp_redistribute_metric_set(vty->index, red, AFI_IP6, SAFI_UNICAST, metric); bgp_redistribute_rmap_set (red, argv[2]); return bgp_redistribute_set (AFI_IP6, type, 0); } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 8a9beb8f0f..ada6a0ea96 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1602,8 +1602,12 @@ bgp_redistribute_rmap_set (struct bgp_redist *red, const char *name) /* Redistribute with metric specification. */ int -bgp_redistribute_metric_set (struct bgp_redist *red, u_int32_t metric) +bgp_redistribute_metric_set (struct bgp *bgp, struct bgp_redist *red, afi_t afi, + int type, u_int32_t metric) { + struct bgp_node *rn; + struct bgp_info *ri; + if (red->redist_metric_flag && red->redist_metric == metric) return 0; @@ -1611,6 +1615,16 @@ bgp_redistribute_metric_set (struct bgp_redist *red, u_int32_t metric) red->redist_metric_flag = 1; red->redist_metric = metric; + for (rn = bgp_table_top(bgp->rib[afi][SAFI_UNICAST]); rn; rn = bgp_route_next(rn)) { + for (ri = rn->info; ri; ri = ri->next) { + if (ri->sub_type == BGP_ROUTE_REDISTRIBUTE && ri->type == type) { + ri->attr->med = red->redist_metric; + bgp_info_set_flag(rn, ri, BGP_INFO_ATTR_CHANGED); + bgp_process(bgp, rn, afi, SAFI_UNICAST); + } + } + } + return 1; } diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index a6d96e5740..93f8f229f8 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -43,7 +43,8 @@ extern struct bgp_redist *bgp_redist_add (struct bgp *, afi_t, u_char, u_short); extern int bgp_redistribute_set (afi_t, int, u_short); extern int bgp_redistribute_resend (struct bgp *, afi_t, int, u_short); extern int bgp_redistribute_rmap_set (struct bgp_redist *, const char *); -extern int bgp_redistribute_metric_set (struct bgp_redist *, u_int32_t); +extern int bgp_redistribute_metric_set(struct bgp *, struct bgp_redist *, + afi_t, int, u_int32_t); extern int bgp_redistribute_unset (struct bgp *, afi_t, int, u_short); extern struct interface *if_lookup_by_ipv4 (struct in_addr *); -- 2.39.5