]> git.puffer.fish Git - mirror/frr.git/commitdiff
Fix redistribute metric change not taking effect
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 31 Jul 2015 12:53:12 +0000 (05:53 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 31 Jul 2015 13:28:37 +0000 (06:28 -0700)
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
bgpd/bgp_zebra.c
bgpd/bgp_zebra.h

index 9ed641fadad60519aea5212534f947b2501e98fa..a8e23bf1b4d192282ec6428b82b308319aefca89 100644 (file)
@@ -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);
 }
index 8a9beb8f0fc17facfd15cf0e360bf22645299355..ada6a0ea960189ae0e774979f2cae3386dcd7fac 100644 (file)
@@ -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;
 }
 
index a6d96e57401b30cb4e52484a8ddd78d351226149..93f8f229f8273c6059b7b8e8335290e74d625b94 100644 (file)
@@ -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 *);