Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospf6d: Fix metric when sending AS-external LSAs #15627

Merged

Conversation

Max-Mustermann33
Copy link
Contributor

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.

@frrbot frrbot bot added the ospfv3 label Mar 27, 2024
@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch 3 times, most recently from a481212 to f5a1687 Compare April 2, 2024 10:56
@riw777 riw777 self-requested a review April 2, 2024 15:18
Copy link
Collaborator

@aceelindem aceelindem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong to change the behavior to unconditionally add the existing route metric to the redistributed metric. I'd hope we have a topotest that would catch this. If this behavior is desired is should be conditional (possibly via a route-map) and be available for all redistributions (not just applied to OSPFv3).

@Max-Mustermann33
Copy link
Contributor Author

This is wrong to change the behavior to unconditionally add the existing route metric to the redistributed metric. I'd hope we have a topotest that would catch this. If this behavior is desired is should be conditional (possibly via a route-map) and be available for all redistributions (not just applied to OSPFv3).

I could not find a lot about this in the FRRouting documentation, but after some tests it looks like the following config-option allows using the existing route metric as redistributed metric. At least for IPv4 it does.

redistribute kernel route-map ABC

route-map ABC permit 10
set metric +1

When using the same config with IPv6 I end up with metric 1 for all redistributed kernel-routes. (without my patch)

Is there possibly a bug in ospf6d that prevents this config from actually working or is there an intention behind the different behaviour?

@aceelindem
Copy link
Collaborator

This is wrong to change the behavior to unconditionally add the existing route metric to the redistributed metric. I'd hope we have a topotest that would catch this. If this behavior is desired is should be conditional (possibly via a route-map) and be available for all redistributions (not just applied to OSPFv3).

I could not find a lot about this in the FRRouting documentation, but after some tests it looks like the following config-option allows using the existing route metric as redistributed metric. At least for IPv4 it does.

redistribute kernel route-map ABC

route-map ABC permit 10 set metric +1

When using the same config with IPv6 I end up with metric 1 for all redistributed kernel-routes. (without my patch)

Is there possibly a bug in ospf6d that prevents this config from actually working or is there an intention behind the different behaviour?

Ok - I see that the route-map increment and decrement functions are not implemented. However, you have the wrong fix. The right fix is to add this capability to the route-map callback for ospf6d. static enum route_map_cmd_result_t
ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix,
void *object)
Unfortunatlely, I don't have time to work on this but hopefully I've pointed you in the right direction.

@aceelindem
Copy link
Collaborator

This is wrong to change the behavior to unconditionally add the existing route metric to the redistributed metric. I'd hope we have a topotest that would catch this. If this behavior is desired is should be conditional (possibly via a route-map) and be available for all redistributions (not just applied to OSPFv3).

I could not find a lot about this in the FRRouting documentation, but after some tests it looks like the following config-option allows using the existing route metric as redistributed metric. At least for IPv4 it does.
redistribute kernel route-map ABC
route-map ABC permit 10 set metric +1
When using the same config with IPv6 I end up with metric 1 for all redistributed kernel-routes. (without my patch)
Is there possibly a bug in ospf6d that prevents this config from actually working or is there an intention behind the different behaviour?

Ok - I see that the route-map increment and decrement functions are not implemented. However, you have the wrong fix. The right fix is to add this capability to the route-map callback for ospf6d. static enum route_map_cmd_result_t ospf6_routemap_rule_set_metric(void *rule, const struct prefix *prefix, void *object) Unfortunatlly, I don't have time to work on this but hopefully I've pointed you in the right direction.

Look at ospfd/ospf_routemap.c - route_set_metric(). You need to stash the redistributed metric in the route (but not as the the default metric) and do something like this.

@Max-Mustermann33
Copy link
Contributor Author

Thank you, I will look into that.

@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch from f5a1687 to 85e39be Compare April 9, 2024 14:01
@github-actions github-actions bot added size/M and removed size/S labels Apr 9, 2024
@Max-Mustermann33
Copy link
Contributor Author

I added support for metric increment and decrement in ospf6d routemaps.
The kernel metric will now only be redistributed if such a routemap is configured.
For my use case this still works.

Is this what you had in your mind?

Copy link
Collaborator

@aceelindem aceelindem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it should work but it could read a lot better and the range checking is needed to assure the metric is valid for AS External LSAs.

ospf6d/ospf6_asbr.c Outdated Show resolved Hide resolved
arg++;
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with a metric subtraction since this could be misinterpreted? Shouldn't you skip the +/- so we don't have to wonder about the precise strtoul() behavior where "u" stands for unsigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping the +/- is exactly what this code is doing. strtoul() will only see a number with no sign beforehand.
btw this is the same code as ospfd is using.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need range checking for the increment and decrement cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added range checking in those cases.
As this code is basically copy-paste from ospfd, I think there is also a problem - except if the range checking is done somewhere else.

@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch from 85e39be to a8fc0d3 Compare April 11, 2024 11:14
@github-actions github-actions bot added the rebase PR needs rebase label Apr 11, 2024
@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch from a8fc0d3 to 8c83b82 Compare April 11, 2024 11:23
Copy link
Collaborator

@aceelindem aceelindem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.


/* Check overflow */
if (route->path.cost == 0 || route->path.cost > route->path.redistribute_cost)
route->path.cost = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if OSPFv2 default to 1 or 0 in this case but it is a real cornercase anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was asking myself the same question. After reading the RFC It looks like metric 0 is only for some special cases.

@Max-Mustermann33
Copy link
Contributor Author

Is there something to do on my side? Like rebasing for example? Or will that be done upon merging?

@aceelindem
Copy link
Collaborator

Is there something to do on my side? Like rebasing for example? Or will that be done upon merging

Yes - you need to rebase as indicated by the @github-actions github-actions bot added the rebase label last week

Note that this could also help with the CI tests as the intermittent BFD failure (not related to your change) has been mitigated.

@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch from 8c83b82 to d0320e8 Compare April 19, 2024 07:38
Copy link
Member

@riw777 riw777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@ton31337
Copy link
Member

ton31337 commented May 3, 2024

Please fix styling/formatting (frrbot check) before merging.

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]>
@Max-Mustermann33 Max-Mustermann33 force-pushed the ospf6d_metric_for_type5_lsa branch from d0320e8 to 84d1285 Compare May 6, 2024 06:52
@github-actions github-actions bot added size/L and removed size/M labels May 6, 2024
@Max-Mustermann33
Copy link
Contributor Author

Please fix styling/formatting (frrbot check) before merging.

Thanks for the hint. I missed that one.

@riw777 riw777 merged commit e941145 into FRRouting:master May 7, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants