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

parser: check for route duplicates (LP: #2003061) #320

Merged
merged 3 commits into from Feb 6, 2023

Conversation

daniloegea
Copy link
Collaborator

@daniloegea daniloegea commented Jan 31, 2023

We currently check if the number of routes we have in the list is the same as the number of entries in the yaml structure. This cause problems when routes come from different files, see LP#2003061. In this case, the second route is not added to the netdef.

This patch changes the logic to actually check if the route being processed is already in the list. For the uniqueness check, it compares the route IP family, table ID, metric, from, to and via fields.

Description

Checklist

  • Runs make check successfully.
  • Retains 100% code coverage (make check-coverage).
  • New/changed keys in YAML format are documented.
  • (Optional) Adds example YAML for new feature.
  • (Optional) Closes an open bug in Launchpad. LP#2003061

We currently check if the number of routes we have in the list is the
same as the number of entries in the yaml structure. This cause problems
when routes come from different files, see LP#2003061. In this case, the
second route is not added to the netdef.

This patch changes the logic to actually check if the route being
processed is already in the list. For the uniqueness check, it compares
the route table ID, metric, from, to and via fields.
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thanks, I like this approach. But I think we need to work a bit more on the route matching logic. Everything else are just small suggestions inline.

While on it, we might consider refactoring some of this code, by introducing a reset_route helper (similar to reset_ip_rule). Also, what about handle_ip_roules in general? Wouldn't the routing-policy handling have the same problem of duplicates?

src/parse.c Outdated Show resolved Hide resolved
src/util.c Outdated Show resolved Hide resolved
Comment on lines +881 to +882
* XXX: in the future we could add a route "key" to a hash set so this verification could
* be done faster.
Copy link
Collaborator

Choose a reason for hiding this comment

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

praise: I like this idea!

src/util.c Outdated Show resolved Hide resolved
tests/generator/test_routing.py Show resolved Hide resolved
Take into account that the destination could be 'default' or
'0.0.0.0/0' (or '::/0' for IPv6). In this case we should
consider them the same.
Add the family to the matching criteria as well.
@slyon slyon changed the title parser: check for route duplicates parser: check for route duplicates (LP: #2003061) Feb 6, 2023
Copy link
Collaborator

@slyon slyon left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm. The refactoring and potential improvement of ip_rules can be done at later point in time. Let's keep this fix isolated.

@slyon slyon merged commit eb0ff44 into canonical:main Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants