-
Notifications
You must be signed in to change notification settings - Fork 164
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
Use NetworkMonitor in zedrouter #3033
Use NetworkMonitor in zedrouter #3033
Conversation
That's cool. Sorry to stick my nose into not my area, I was just curious how you implemented the NetworkMonitor and found this comment:
This seems to be correct. I followed the following path:
Creates a netlink request, which gets routes and dumps them. The following is the callback for RTM_GETROUTE messages and PF_UNSPEC family registered in the kernel:
Which registers router netlink The
and here is the ipv6:
So '// XXX is AF_UNSPEC ok?' comment is not needed :) (if you did not mean something different of course) LGTM (at least to my shallow understanding of what you are doing in this patchset). |
1a4c18b
to
d76b715
Compare
@rouming Nice, thanks for sticking your nose into the networking area, that was educational :) |
@@ -557,6 +557,7 @@ func (m *LinuxNetworkMonitor) linkSubscribe(doneChan chan struct{}) chan netlink | |||
} | |||
linkOpts := netlink.LinkSubscribeOptions{ | |||
ErrorCallback: linkErrFunc, | |||
ListExisting: true, // XXX: currently required by zedrouter (later will be removed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you plan to remove the listExisting?
Can't use a get+subscription since the order would not be defined between what you retrieve with a get and when you see any additions or deletings from the subscription.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have very small routing tables (only getting routes from DHCP or static config, no dynamic routing protocols), I would prefer to fully reconcile a routing table on change (reread the current state, update the intended state, run reconcile). In other words, use these notifications only to detect that config is out-of-sync. It should be more robust at the cost of more netlink calls made overall.
But I may rethink this once I get to it, so for now keeping there the XXX
comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, such an approach can avoid race conditions as long as you notification generated after you start the read of the current causes the code to redo the full read. I don't know if you also need to make sure you discard the results of that first read - whether the set of routes you read could be inconsistent. By that I mean that a read could have e.g., a default route with a nexthop of 192.168.17.1 but you have no route for 192.168.17.1 in the set of routes you read (because that interface/route was deleted just after netlink read the default route.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; let it test.
|
d76b715
to
24ac6a8
Compare
Eden tests should be fixed, @eriknordmark please rerun when you can. |
NetworkMonitor provides all features needed by zedrouter to watch for changes in the network stack (used mostly for policy based routing purposes). This way we can remove some code from the zedrouter and avoid duplication. Moreover, NetworkMonitor is an interface and there will be multiple implementations for different network stacks (currently there is only one for Linux). This is just a small step in the process of zedrouter refactoring. Signed-off-by: Milan Lenco <milan@zededa.com>
24ac6a8
to
e2d39fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-run eden
NetworkMonitor provides all features needed by zedrouter to watch for changes in the network stack (used mostly for policy based routing purposes). This way we can remove some code from the zedrouter and avoid duplication. Moreover, NetworkMonitor is an interface and there will be multiple implementations for different network stacks (currently there is only one for Linux).
This is just a small step in the process of zedrouter refactoring. My goal is to avoid creating large PRs and overwhelming myself and reviewers. Instead, I would like to refactor in small steps (while keeping zedrouter functional in-between). But the value of some of these smaller steps will only be apparent once everything is completed.
Signed-off-by: Milan Lenco milan@zededa.com