forked from Mirror/frr
ospfd: use rib metric as the base for set metric +/-
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>
This commit is contained in:
parent
be574cf987
commit
6af89f8f03
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
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);
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue