From c4122b55a6068aa685091eed991b7b71390d9d03 Mon Sep 17 00:00:00 2001 From: Yash Ranjan Date: Tue, 9 Feb 2021 23:28:52 -0800 Subject: [PATCH] ospf6d: Add logic to set metric if route-map not present Signed-off-by: Yash Ranjan --- ospf6d/ospf6_abr.c | 3 +++ ospf6d/ospf6_asbr.c | 12 ++++++++++-- ospf6d/ospf6_lsa.c | 30 ++++++++++++++++++++++++++++++ ospf6d/ospf6_lsa.h | 8 ++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index f6a246500b..140fc0d3d4 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -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)) { diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index cb6359300a..52219885db 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -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; } diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index b4f0c30f12..f5f429b041 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -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) { diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index c4d0290c0c..84c3b85631 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -29,6 +29,12 @@ #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 *); -- 2.39.5