From f5a16879b22d584941561122e7b36c3ecb6c953e Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Wed, 27 Mar 2024 14:33:21 +0100 Subject: [PATCH] ospf6d: Fix metric when sending AS-external LSAs 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. In my case all of these routes were announced with metric 1 in LS-updates. Now the metric of the kernel route is added to whatever metric ospf6d already computed originally. Signed-off-by: Alexander Rose --- ospf6d/ospf6_asbr.c | 20 ++++++++++++-------- ospf6d/ospf6_asbr.h | 3 ++- ospf6d/ospf6_zebra.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index d1c2b8bfc9a4..050f0498a913 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1426,10 +1426,9 @@ static void ospf6_external_lsa_fwd_addr_set(struct ospf6 *ospf6, } 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) + struct prefix *prefix, unsigned int nexthop_num, + const struct in6_addr *nexthop, route_tag_t tag, + struct ospf6 *ospf6, uint32_t metric) { route_map_result_t ret; struct ospf6_route troute; @@ -1498,9 +1497,10 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, match->path.metric_type = metric_type(ospf6, type, 0); if (troute.path.cost) - match->path.cost = troute.path.cost; + match->path.cost = troute.path.cost + metric; else - match->path.cost = metric_value(ospf6, type, 0); + match->path.cost = + metric_value(ospf6, type, 0) + metric; if (!IN6_IS_ADDR_UNSPECIFIED(&tinfo.forwarding)) memcpy(&info->forwarding, &tinfo.forwarding, @@ -1511,10 +1511,14 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, * metric fields */ match->path.metric_type = metric_type(ospf6, type, 0); - match->path.cost = metric_value(ospf6, type, 0); + match->path.cost = metric_value(ospf6, type, 0) + metric; info->tag = tag; } + /* sum of metrics caused an overflow */ + if (match->path.cost < metric) + match->path.cost = UINT32_MAX; + info->type = type; if (nexthop_num && nexthop) { @@ -1924,7 +1928,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; } } diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h index d63e46727890..d69b85ea6830 100644 --- a/ospf6d/ospf6_asbr.h +++ b/ospf6d/ospf6_asbr.h @@ -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); diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 3245578b07f2..911f3567d453 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -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);