]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: use rib metric as the base for set metric +/-
authorJafar Al-Gharaibeh <jafar@atcorp.com>
Fri, 31 Mar 2023 03:36:13 +0000 (22:36 -0500)
committerJafar Al-Gharaibeh <jafar@atcorp.com>
Tue, 18 Apr 2023 05:21:05 +0000 (00:21 -0500)
When using route maps with external routes in OSPF as follows:
```
   set metric +10
 ```
The current behavior is to use the default ospf metric as the base and then add
to 10 to it. The behavior isn't useful as-is. A value 30 (20 dfeault + 10) can
be set directly instead. the behavior is also not consistent with bgp. bgp does
use the rib metric in this case as the base. The current behavior also doesn't
allow the metric to accumulate when crossing different routing domains such as
vrfs causing the metric to reset every time the route enters a new vrf with a new
ospf network.

This PR changes the behavior such that the rib metric is used as a base for
ospf exteral routes when used with `set metric -/+`

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
ospfd/ospf_asbr.c
ospfd/ospf_asbr.h
ospfd/ospf_ase.c
ospfd/ospf_routemap.c
ospfd/ospf_zebra.c

index 7befcc1086fbc51cd50f82e2b4be60e67176e8df..516ee80c5b300c8d4fc415c2c2f19caa74c3348c 100644 (file)
@@ -94,7 +94,7 @@ int ospf_route_map_set_compare(struct route_map_set_values *values1,
 struct external_info *
 ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance,
                       struct prefix_ipv4 p, ifindex_t ifindex,
-                      struct in_addr nexthop, route_tag_t tag)
+                      struct in_addr nexthop, route_tag_t tag, uint32_t metric)
 {
        struct external_info *new;
        struct route_node *rn;
@@ -131,6 +131,7 @@ ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance,
        new->tag = tag;
        new->orig_tag = tag;
        new->aggr_route = NULL;
+       new->metric = metric;
 
        /* we don't unlock rn from the get() because we're attaching the info */
        if (rn)
@@ -138,9 +139,9 @@ ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance,
 
        if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
                zlog_debug(
-                       "Redistribute[%s][%u]: %pFX external info created, with NH %pI4",
+                       "Redistribute[%s][%u]: %pFX external info created, with NH %pI4, metric:%u",
                        ospf_redist_string(type), ospf->vrf_id, &p,
-                       &nexthop.s_addr);
+                       &nexthop.s_addr, metric);
        }
        return new;
 }
index 6b427c5fd20e84afa50b0cc9c0c49bebc05e6b38..256a6c8b5bdd66efc11289ae2c9e5c701970a37b 100644 (file)
@@ -36,6 +36,8 @@ struct external_info {
        /* Actual tag received from zebra*/
        route_tag_t orig_tag;
 
+       uint32_t metric;
+
        struct route_map_set_values route_map_set;
 #define ROUTEMAP_METRIC(E) (E)->route_map_set.metric
 #define ROUTEMAP_METRIC_TYPE(E) (E)->route_map_set.metric_type
@@ -99,11 +101,10 @@ extern struct external_info *ospf_external_info_new(struct ospf *, uint8_t,
 extern void ospf_reset_route_map_set_values(struct route_map_set_values *);
 extern int ospf_route_map_set_compare(struct route_map_set_values *,
                                      struct route_map_set_values *);
-extern struct external_info *ospf_external_info_add(struct ospf *, uint8_t,
-                                                   unsigned short,
-                                                   struct prefix_ipv4,
-                                                   ifindex_t, struct in_addr,
-                                                   route_tag_t);
+extern struct external_info *
+ospf_external_info_add(struct ospf *, uint8_t, unsigned short,
+                      struct prefix_ipv4, ifindex_t, struct in_addr,
+                      route_tag_t, uint32_t metric);
 extern void ospf_external_info_delete(struct ospf *, uint8_t, unsigned short,
                                      struct prefix_ipv4);
 extern struct external_info *ospf_external_info_lookup(struct ospf *, uint8_t,
index 80390af505cdc4f9dc2df3eb5af587091bebca03..cc2110d43331d208a090a2d3a829af817b6fe47a 100644 (file)
@@ -159,7 +159,9 @@ ospf_ase_calculate_new_route(struct ospf_lsa *lsa,
 
        if (!IS_EXTERNAL_METRIC(al->e[0].tos)) {
                if (IS_DEBUG_OSPF(lsa, LSA))
-                       zlog_debug("Route[External]: type-1 created.");
+                       zlog_debug(
+                               "Route[External]: type-1 created, asbr cost:%d  metric:%d.",
+                               asbr_route->cost, metric);
                new->path_type = OSPF_PATH_TYPE1_EXTERNAL;
                new->cost = asbr_route->cost + metric; /* X + Y */
        } else {
index 3d5c5aa2d572c99d0e4f598701e45fa2cf18d242..965686774510c36d464107f4c48cb31d2089551d 100644 (file)
@@ -398,7 +398,7 @@ route_set_metric(void *rule, const struct prefix *prefix, void *object)
        if (!metric->used)
                return RMAP_OKAY;
 
-       ei->route_map_set.metric = DEFAULT_DEFAULT_METRIC;
+       ei->route_map_set.metric = ei->metric;
 
        if (metric->type == metric_increment)
                ei->route_map_set.metric += metric->metric;
index 3f967e41e4829ceed77d54e2553eecdaafcbd567..0b770a8364787c8679326798e9f2e3981cceb6ba 100644 (file)
@@ -956,8 +956,8 @@ int ospf_redistribute_default_set(struct ospf *ospf, int originate, int mtype,
                type_str = "always";
                ospf->redistribute++;
                ospf_external_add(ospf, DEFAULT_ROUTE, 0);
-               ospf_external_info_add(ospf, DEFAULT_ROUTE, 0, p, 0, nexthop,
-                                      0);
+               ospf_external_info_add(ospf, DEFAULT_ROUTE, 0, p, 0, nexthop, 0,
+                                      DEFAULT_DEFAULT_METRIC);
                break;
        }
 
@@ -1303,9 +1303,11 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
                rt_type = DEFAULT_ROUTE;
 
        if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
-               zlog_debug("%s: cmd %s from client %s: vrf_id %d, p %pFX",
-                          __func__, zserv_command_string(cmd),
-                          zebra_route_string(api.type), vrf_id, &api.prefix);
+               zlog_debug(
+                       "%s: cmd %s from client %s: vrf_id %d, p %pFX, metric %d",
+                       __func__, zserv_command_string(cmd),
+                       zebra_route_string(api.type), vrf_id, &api.prefix,
+                       api.metric);
 
        if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) {
                /* XXX|HACK|TODO|FIXME:
@@ -1332,7 +1334,8 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
                                                          p);
 
                ei = ospf_external_info_add(ospf, rt_type, api.instance, p,
-                                           ifindex, nexthop, api.tag);
+                                           ifindex, nexthop, api.tag,
+                                           api.metric);
                if (ei == NULL) {
                        /* Nothing has changed, so nothing to do; return */
                        return 0;