Skip to content

Commit

Permalink
ospf6d: Redistribute metric for AS-external route
Browse files Browse the repository at this point in the history
When ospf6d originates an AS-external route that has been read from a kernel
routing table, then the metric of that route was ignored until now.
If a routemap is configured, then this metric will be redistributed from
now on.

Using metric increment and decrement in routemaps is supported by ospf6d now.

Signed-off-by: Alexander Rose <[email protected]>
  • Loading branch information
Max-Mustermann33 committed Apr 9, 2024
1 parent d7f6d0d commit 85e39be
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
65 changes: 54 additions & 11 deletions ospf6d/ospf6_asbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "table.h"
#include "plist.h"
#include "frrevent.h"
#include "frrstr.h"
#include "linklist.h"
#include "lib/northbound_cli.h"

Expand Down Expand Up @@ -1429,7 +1430,8 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
struct prefix *prefix,
unsigned int nexthop_num,
const struct in6_addr *nexthop,
route_tag_t tag, struct ospf6 *ospf6)
route_tag_t tag, struct ospf6 *ospf6,
uint32_t metric)
{
route_map_result_t ret;
struct ospf6_route troute;
Expand Down Expand Up @@ -1472,6 +1474,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
if (ROUTEMAP(red)) {
troute.route_option = &tinfo;
troute.ospf6 = ospf6;
troute.path.redistribute_cost = metric;
tinfo.ifindex = ifindex;
tinfo.tag = tag;

Expand Down Expand Up @@ -1924,7 +1927,7 @@ static void ospf6_redistribute_default_set(struct ospf6 *ospf6, int originate)
case DEFAULT_ORIGINATE_ALWAYS:
ospf6_asbr_redistribute_add(DEFAULT_ROUTE, 0,
(struct prefix *)&p, 0, &nexthop, 0,
ospf6);
ospf6, 0);
break;
}
}
Expand Down Expand Up @@ -2153,25 +2156,65 @@ static const struct route_map_rule_cmd
ospf6_routemap_rule_set_metric_type_free,
};

struct ospf6_metric {
enum { metric_increment, metric_decrement, metric_absolute } type;
bool used;
uint32_t metric;
};

static enum route_map_cmd_result_t
ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix,
void *object)
{
char *metric = rule;
struct ospf6_route *route = object;
struct ospf6_metric *metric;
struct ospf6_route *route;

/* Fetch routemap's rule information. */
metric = rule;
route = object;

/* Set metric out value. */
if (!metric->used)
return RMAP_OKAY;

route->path.cost = route->path.redistribute_cost;

if (metric->type == metric_increment)
route->path.cost += metric->metric;
else if (metric->type == metric_decrement)
route->path.cost -= metric->metric;
else if (metric->type == metric_absolute)
route->path.cost = metric->metric;

route->path.cost = atoi(metric);
return RMAP_OKAY;
}

static void *ospf6_routemap_rule_set_metric_compile(const char *arg)
{
uint32_t metric;
char *endp;
metric = strtoul(arg, &endp, 0);
if (metric > OSPF_LS_INFINITY || *endp != '\0')
return NULL;
return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
struct ospf6_metric *metric;

metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(*metric));
metric->used = false;

if (all_digit(arg))
metric->type = metric_absolute;

if ((arg[0] == '+') && all_digit(arg + 1)) {
metric->type = metric_increment;
arg++;
}

if ((arg[0] == '-') && all_digit(arg + 1)) {
metric->type = metric_decrement;
arg++;
}

metric->metric = strtoul(arg, NULL, 10);

if (metric->metric)
metric->used = true;

return metric;
}

static void ospf6_routemap_rule_set_metric_free(void *rule)
Expand Down
3 changes: 2 additions & 1 deletion ospf6d/ospf6_asbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ extern void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
struct prefix *prefix,
unsigned int nexthop_num,
const struct in6_addr *nexthop,
route_tag_t tag, struct ospf6 *ospf6);
route_tag_t tag, struct ospf6 *ospf6,
uint32_t metric);
extern void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
struct prefix *prefix,
struct ospf6 *ospf6);
Expand Down
1 change: 1 addition & 0 deletions ospf6d/ospf6_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct ospf6_path {
/* Cost */
uint8_t metric_type;
uint32_t cost;
uint32_t redistribute_cost;

struct prefix ls_prefix;

Expand Down
2 changes: 1 addition & 1 deletion ospf6d/ospf6_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS)
if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix,
api.nexthop_num, nexthop, api.tag,
ospf6);
ospf6, api.metric);
else
ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix,
ospf6);
Expand Down

0 comments on commit 85e39be

Please sign in to comment.