From 06abfcf6d95762976d37aa5721c16802c649efd4 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 22 Jul 2022 15:31:13 +1000 Subject: Separately locate external interfaces for IPv4 and IPv6 Now that the back end allows passt/pasta to use different external interfaces for IPv4 and IPv6, use that to do the right thing in the case that the host has IPv4 and IPv6 connectivity via different interfaces. If the user hasn't explicitly chosen an interface, separately search for a suitable external interface for each protocol. As a bonus, this substantially simplifies the external interface probe. It also eliminates a subtle confusing case where in some circumstances we would pick the first interface in interface index order, and sometimes in order of routes returned from netlink. On some network configurations that could cause tests to fail, because the logic in the tests was subtly different (it always used route order). Signed-off-by: David Gibson --- conf.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index 943526d..cc08de3 100644 --- a/conf.c +++ b/conf.c @@ -630,8 +630,23 @@ static void conf_ip(struct ctx *c) v4 = v6 = IP_VERSION_PROBE; } - if (!c->ifi4 && !c->ifi6) - c->ifi4 = c->ifi6 = nl_get_ext_if(&v4, &v6); + if (v4 != IP_VERSION_DISABLED) { + if (!c->ifi4) + c->ifi4 = nl_get_ext_if(AF_INET); + if (!c->ifi4) { + warn("No external routable interface for IPv4"); + v4 = IP_VERSION_DISABLED; + } + } + + if (v6 != IP_VERSION_DISABLED) { + if (!c->ifi6) + c->ifi6 = nl_get_ext_if(AF_INET6); + if (!c->ifi6) { + warn("No external routable interface for IPv6"); + v6 = IP_VERSION_DISABLED; + } + } if (v4 != IP_VERSION_DISABLED) { if (!c->gw4) -- cgit v1.2.3