]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: Add logic to set metric if route-map not present
authorYash Ranjan <ranjany@vmware.com>
Wed, 10 Feb 2021 07:28:52 +0000 (23:28 -0800)
committerYash Ranjan <ranjany@vmware.com>
Mon, 29 Mar 2021 13:37:10 +0000 (06:37 -0700)
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
ospf6d/ospf6_abr.c
ospf6d/ospf6_asbr.c
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h

index f6a246500b22cd8dfd7205cd319c0d69ebb4105f..140fc0d3d41eb6acc9c4d0a0ba8fad7d5560e73f 100644 (file)
@@ -646,6 +646,7 @@ void ospf6_abr_defaults_to_stub(struct ospf6 *o)
        struct listnode *node, *nnode;
        struct ospf6_area *oa;
        struct ospf6_route *def, *route;
+       int type = DEFAULT_ROUTE;
 
        if (!o->backbone)
                return;
@@ -659,6 +660,8 @@ void ospf6_abr_defaults_to_stub(struct ospf6 *o)
        def->path.type = OSPF6_PATH_TYPE_INTER;
        def->path.subtype = OSPF6_PATH_SUBTYPE_DEFAULT_RT;
        def->path.area_id = o->backbone->area_id;
+       def->path.metric_type = metric_type(o, type, 0);
+       def->path.cost = metric_value(o, type, 0);
 
        for (ALL_LIST_ELEMENTS(o->area_list, node, nnode, oa)) {
                if (!IS_AREA_STUB(oa)) {
index cb6359300ab460f42b2b2271307bd7e62a044c16..52219885dbc3a92e54e4a53a0dc1513b4fe23bd5 100644 (file)
@@ -1238,7 +1238,11 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
                                       sizeof(struct in6_addr));
                        info->tag = tinfo.tag;
                } else {
-                       /* If there is no route-map, simply update the tag */
+                       /* If there is no route-map, simply update the tag and
+                        * metric fields
+                        */
+                       match->path.metric_type = metric_type(ospf6, type, 0);
+                       match->path.cost = metric_value(ospf6, type, 0);
                        info->tag = tag;
                }
 
@@ -1291,7 +1295,11 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
                               sizeof(struct in6_addr));
                info->tag = tinfo.tag;
        } else {
-               /* If there is no route-map, simply set the tag */
+               /* If there is no route-map, simply update the tag and metric
+                * fields
+                */
+               route->path.metric_type = metric_type(ospf6, type, 0);
+               route->path.cost = metric_value(ospf6, type, 0);
                info->tag = tag;
        }
 
index b4f0c30f1221c201f74ff23d9abd3e1cb8289a4b..f5f429b041dc1bd372bc3c14686a0cdc552183b2 100644 (file)
@@ -34,6 +34,8 @@
 #include "ospf6_lsa.h"
 #include "ospf6_lsdb.h"
 #include "ospf6_message.h"
+#include "ospf6_asbr.h"
+#include "ospf6_zebra.h"
 
 #include "ospf6_top.h"
 #include "ospf6_area.h"
@@ -163,6 +165,34 @@ uint8_t ospf6_lstype_debug(uint16_t type)
        return handler->lh_debug;
 }
 
+int metric_type(struct ospf6 *ospf6, int type, uint8_t instance)
+{
+       struct ospf6_redist *red;
+
+       red = ospf6_redist_lookup(ospf6, type, instance);
+
+       return ((!red || red->dmetric.type < 0) ? DEFAULT_METRIC_TYPE
+                                               : red->dmetric.type);
+}
+
+int metric_value(struct ospf6 *ospf6, int type, uint8_t instance)
+{
+       struct ospf6_redist *red;
+
+       red = ospf6_redist_lookup(ospf6, type, instance);
+       if (!red || red->dmetric.value < 0) {
+               if (type == DEFAULT_ROUTE) {
+                       if (ospf6->default_originate == DEFAULT_ORIGINATE_ZEBRA)
+                               return DEFAULT_DEFAULT_ORIGINATE_METRIC;
+                       else
+                               return DEFAULT_DEFAULT_ALWAYS_METRIC;
+               } else
+                       return DEFAULT_DEFAULT_METRIC;
+       }
+
+       return red->dmetric.value;
+}
+
 /* RFC2328: Section 13.2 */
 int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2)
 {
index c4d0290c0c1639b2c11acf149e926d7cc5ad5f3c..84c3b856311aeb83011ae4a02b208167bc0ecc4a 100644 (file)
 #define OSPF6_LSA_DEBUG_EXAMIN    0x04
 #define OSPF6_LSA_DEBUG_FLOOD     0x08
 
+/* 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 2
+
 #define IS_OSPF6_DEBUG_LSA(name)                                               \
        (ospf6_lstype_debug(htons(OSPF6_LSTYPE_##name)) & OSPF6_LSA_DEBUG)
 #define IS_OSPF6_DEBUG_ORIGINATE(name)                                         \
@@ -197,6 +203,8 @@ extern vector ospf6_lsa_handler_vector;
 extern const char *ospf6_lstype_name(uint16_t type);
 extern const char *ospf6_lstype_short_name(uint16_t type);
 extern uint8_t ospf6_lstype_debug(uint16_t type);
+extern int metric_type(struct ospf6 *ospf6, int type, uint8_t instance);
+extern int metric_value(struct ospf6 *ospf6, int type, uint8_t instance);
 extern int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
 extern int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2);
 extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa *);