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

network: use pyroute2 to manage default routes #1569

Merged
merged 2 commits into from
Feb 21, 2023

Conversation

dbungert
Copy link
Collaborator

The existing event based method of watching for has_network has a flaw.

The incoming route_change events from probert do not distinguish routes on the same interface but a different metric, so if 2 routes on one interface appear, we only get one event. Then if one of those routes is removed, we will inappropriately remove this route from the default_routes list.

Aside from the code watching the event stream, the set of default routes is an elaborate boolean value.

Simplify the code by passing around a boolean, and when we get a route_change event, use that to go looking again at the list of default routes.

LP: #2004659

Copy link
Collaborator

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

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

One more thing i think we should consider.


def _analyze_routes(self, routes):
return any(route['table'] == 254 and not route['dst']
for route in routes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should consider rejecting routes with metrics > 20000 here, to filter out connections that have not passed NM's connectivity check (unless there is a expectation that such routes might be created by some other mechanism? It seems very unlikely in the context of subiquity though?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should, yes. These high-metric routes can stick around. I think it sensible to filter them. Implemented.

Copy link
Member

@ogayot ogayot left a comment

Choose a reason for hiding this comment

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

LGTM.
Can we reword the update_default_routes function without breaking the world? It feels weird to me that it takes a boolean value.

apt-deps.txt Outdated Show resolved Hide resolved
@dbungert
Copy link
Collaborator Author

Can we reword the update_default_routes function without breaking the world? It feels weird to me that it takes a boolean value.

Sure, we are already changing the type so I think changing the name is appropriate. Implemented.

Copy link
Collaborator

@mwhudson mwhudson 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 pedantry to a possibly unhelpful level but this is a bit inconsistent about "has_default_route" vs "has_default_routes". Other than that it looks great!

The existing event based method of watching for has_network has a flaw.

The incoming route_change events from probert do not distinguish routes
on the same interface but a different metric, so if 2 routes on one
interface appear, we only get one event.  Then if one of those routes is
removed, we will inappropriately remove this route from the
default_routes list.

Aside from the code watching the event stream, the set of default routes
is an elaborate boolean value.

Simplify the code by passing around a boolean, and when we get a
route_change event, use that to go looking again at the list of default
routes.

LP: #2004659
Network manager can create routes at metric aka priority above 20000.
These can stick around if they are not the best choice, or they may
disappear quickly.

Do not consider one of these routes as a valid default route for
has_network purposes.
@dbungert dbungert merged commit 9d57798 into canonical:main Feb 21, 2023
@dbungert dbungert deleted the lp-2004659-has-network-try2 branch February 21, 2023 20:51
@@ -246,8 +246,7 @@ async def apply_autoinstall_config(self, context):
self.apply_config(context)
with context.child("wait_for_apply"):
await self.apply_config_task.wait()
self.model.has_network = bool(
self.network_event_receiver.default_routes)
self.model.has_network = self.network_event_receiver.has_default_route
Copy link
Collaborator

Choose a reason for hiding this comment

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

100% nothing to do with this branch but I think this line is pointless given that configured does the same and is called immediately after apply_autoinstall_config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants