]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: fix behavior of +/-metric
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 8 Apr 2019 17:05:45 +0000 (17:05 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 8 Apr 2019 17:05:45 +0000 (17:05 +0000)
OSPFD uses -1 as a sentinel value for uninitialized metrics. When
applying a route map with a +/-metric to redistributed routes, we were
using -1 as our base value to increment or decrement on, which meant
that if you set e.g. +10, you would end up with a redistributed route of
metric 9.

This patch also removes an off-by-one sanity check that would cause a
set metric +1 or set metric 0 to result in a metric value of 20 :-)

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
ospfd/ospf_lsa.c
ospfd/ospf_lsa.h
ospfd/ospf_routemap.c

index c9710e9165851e24655e192c29be61d1a15716ca..e38193cffc8e19d1b148847c572945dd0a96b273 100644 (file)
@@ -1499,12 +1499,6 @@ struct in_addr ospf_get_nssa_ip(struct ospf_area *area)
        return fwd;
 }
 
-#define DEFAULT_DEFAULT_METRIC              20
-#define DEFAULT_DEFAULT_ORIGINATE_METRIC     10
-#define DEFAULT_DEFAULT_ALWAYS_METRIC        1
-
-#define DEFAULT_METRIC_TYPE                 EXTERNAL_METRIC_TYPE_2
-
 int metric_type(struct ospf *ospf, uint8_t src, unsigned short instance)
 {
        struct ospf_redist *red;
index 4b4d760f4401dd7897b46766d18eb9087412a817..a381cf7145fd3a2fc123321567f2d3c8af4ac670 100644 (file)
 
 #include "stream.h"
 
+/* OSPF LSA Default metric values */
+#define DEFAULT_DEFAULT_METRIC 20
+#define DEFAULT_DEFAULT_ORIGINATE_METRIC 10
+#define DEFAULT_DEFAULT_ALWAYS_METRIC 1
+#define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2
+
 /* OSPF LSA Range definition. */
 #define OSPF_MIN_LSA           1  /* begin range here */
 #define OSPF_MAX_LSA           12
index a15e605aca1f49b93dae44b4759be818feaf7f7a..30b2a50bb38f4c57826f8577c4172130c2a387dc 100644 (file)
@@ -374,15 +374,16 @@ static route_map_result_t route_set_metric(void *rule,
                /* Set metric out value. */
                if (!metric->used)
                        return RMAP_OKAY;
+
+               ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC;
+
                if (metric->type == metric_increment)
                        ei->route_map_set.metric += metric->metric;
-               if (metric->type == metric_decrement)
+               else if (metric->type == metric_decrement)
                        ei->route_map_set.metric -= metric->metric;
-               if (metric->type == metric_absolute)
+               else if (metric->type == metric_absolute)
                        ei->route_map_set.metric = metric->metric;
 
-               if ((signed int)ei->route_map_set.metric < 1)
-                       ei->route_map_set.metric = -1;
                if (ei->route_map_set.metric > OSPF_LS_INFINITY)
                        ei->route_map_set.metric = OSPF_LS_INFINITY;
        }