aboutgitcodebugslistschat
path: root/netlink.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-06-18 18:55:43 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-06-19 15:00:55 +0200
commit450a6131beabd6537f2460bcc110a9a961697649 (patch)
tree4eafdfc249cfa33fe84190df3830678355f07886 /netlink.c
parent54a9d3801b9549e68bd169e2c938c265ef46e973 (diff)
downloadpasst-450a6131beabd6537f2460bcc110a9a961697649.tar
passt-450a6131beabd6537f2460bcc110a9a961697649.tar.gz
passt-450a6131beabd6537f2460bcc110a9a961697649.tar.bz2
passt-450a6131beabd6537f2460bcc110a9a961697649.tar.lz
passt-450a6131beabd6537f2460bcc110a9a961697649.tar.xz
passt-450a6131beabd6537f2460bcc110a9a961697649.tar.zst
passt-450a6131beabd6537f2460bcc110a9a961697649.zip
netlink: With no default route, pick the first interface with a route
While commit f919dc7a4b1c ("conf, netlink: Don't require a default route to start") sounded reasonable in the assumption that, if we don't find default routes for a given address family, we can still proceed by selecting an interface with any route *iff it's the only one for that protocol family*, Jelle reported a further issue in a similar setup. There, multiple interfaces are present, and while remote container connectivity doesn't matter for the container, local connectivity is desired. There are no default routes, but those multiple interfaces all have non-default routes, so we should just pick one and start. Pick the first interface reported by the kernel with any route, if there are no default routes. There should be no harm in doing so. Reported-by: Jelle van der Waa <jvanderwaa@redhat.com> Reported-by: Martin Pitt <mpitt@redhat.com> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2277954 Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'netlink.c')
-rw-r--r--netlink.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/netlink.c b/netlink.c
index d3bea68..0221a53 100644
--- a/netlink.c
+++ b/netlink.c
@@ -269,8 +269,7 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
size_t na;
/* Look for an interface with a default route first, failing that, look
- * for any interface with a route, and pick it only if it's the only
- * interface with a route.
+ * for any interface with a route, and pick the first one, if any.
*/
seq = nl_send(s, &req, RTM_GETROUTE, NLM_F_DUMP, sizeof(req));
nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWROUTE) {
@@ -324,18 +323,19 @@ unsigned int nl_get_ext_if(int s, sa_family_t af)
warn("netlink: RTM_GETROUTE failed: %s", strerror(-status));
if (defifi) {
- if (ndef > 1)
+ if (ndef > 1) {
info("Multiple default %s routes, picked first",
af_name(af));
+ }
return defifi;
}
if (anyifi) {
- if (nany == 1)
- return anyifi;
-
- info("Multiple interfaces with %s routes, use -i to select one",
- af_name(af));
+ if (nany > 1) {
+ info("Multiple interfaces with %s routes, picked first",
+ af_name(af));
+ }
+ return anyifi;
}
if (!nany)