diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-07-22 15:31:12 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-07-30 21:50:41 +0200 |
commit | 4b2e018d70f33d1e337b039d620823a020711ba5 (patch) | |
tree | f72ac2374fc672988aa7f9d0a086d26f41bc9ac3 /conf.c | |
parent | 0aae39d73a09eb32adc621acbbc98ac6f86b4ad1 (diff) | |
download | passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar.gz passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar.bz2 passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar.lz passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar.xz passt-4b2e018d70f33d1e337b039d620823a020711ba5.tar.zst passt-4b2e018d70f33d1e337b039d620823a020711ba5.zip |
Allow different external interfaces for IPv4 and IPv6 connectivity
It's quite plausible for a host to have both IPv4 and IPv6 connectivity,
but only via different interfaces. For example, this will happen in the
case that IPv6 connectivity is via a tunnel (e.g. 6in4 or 6rd). It would
also happen in the case that IPv4 access is via a tunnel on an otherwise
IPv6 only local network, which is a setup that might become more common in
the post IPv4 address exhaustion world.
In turns out there's no real need for passt/pasta to get its IPv4 and IPv6
connectivity via the same interface, so we can handle this situation fairly
easily. Change the core to allow eparate external interfaces for IPv4 and
IPv6. We don't actually set these separately for now.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'conf.c')
-rw-r--r-- | conf.c | 38 |
1 files changed, 21 insertions, 17 deletions
@@ -630,17 +630,17 @@ static void conf_ip(struct ctx *c) v4 = v6 = IP_VERSION_PROBE; } - if (!c->ifi) - c->ifi = nl_get_ext_if(&v4, &v6); + if (!c->ifi4 && !c->ifi6) + c->ifi4 = c->ifi6 = nl_get_ext_if(&v4, &v6); if (v4 != IP_VERSION_DISABLED) { if (!c->gw4) - nl_route(0, c->ifi, AF_INET, &c->gw4); + nl_route(0, c->ifi4, AF_INET, &c->gw4); if (!c->addr4) { int mask_len = 0; - nl_addr(0, c->ifi, AF_INET, &c->addr4, &mask_len, NULL); + nl_addr(0, c->ifi4, AF_INET, &c->addr4, &mask_len, NULL); c->mask4 = htonl(0xffffffff << (32 - mask_len)); } @@ -658,7 +658,7 @@ static void conf_ip(struct ctx *c) memcpy(&c->addr4_seen, &c->addr4, sizeof(c->addr4_seen)); if (!memcmp(c->mac, MAC_ZERO, ETH_ALEN)) - nl_link(0, c->ifi, c->mac, 0, 0); + nl_link(0, c->ifi4, c->mac, 0, 0); } if (c->mode == MODE_PASST) @@ -668,9 +668,9 @@ static void conf_ip(struct ctx *c) int prefix_len = 0; if (IN6_IS_ADDR_UNSPECIFIED(&c->gw6)) - nl_route(0, c->ifi, AF_INET6, &c->gw6); + nl_route(0, c->ifi6, AF_INET6, &c->gw6); - nl_addr(0, c->ifi, AF_INET6, + nl_addr(0, c->ifi6, AF_INET6, IN6_IS_ADDR_UNSPECIFIED(&c->addr6) ? &c->addr6 : NULL, &prefix_len, &c->addr6_ll); @@ -883,12 +883,12 @@ static void conf_print(const struct ctx *c) char buf4[INET_ADDRSTRLEN], ifn[IFNAMSIZ]; int i; - if (c->mode == MODE_PASTA) { - info("Outbound interface: %s, namespace interface: %s", - if_indextoname(c->ifi, ifn), c->pasta_ifn); - } else { - info("Outbound interface: %s", if_indextoname(c->ifi, ifn)); - } + if (c->ifi4) + info("Outbound interface (IPv4): %s", if_indextoname(c->ifi4, ifn)); + if (c->ifi6) + info("Outbound interface (IPv6): %s", if_indextoname(c->ifi6, ifn)); + if (c->mode == MODE_PASTA) + info("Namespace interface: %s", c->pasta_ifn); if (c->v4) { info("ARP:"); @@ -1395,12 +1395,12 @@ void conf(struct ctx *c, int argc, char **argv) usage(argv[0]); break; case 'i': - if (c->ifi) { + if (c->ifi4 || c->ifi6) { err("Redundant interface: %s", optarg); usage(argv[0]); } - if (!(c->ifi = if_nametoindex(optarg))) { + if (!(c->ifi4 = c->ifi6 = if_nametoindex(optarg))) { err("Invalid interface name %s: %s", optarg, strerror(errno)); usage(argv[0]); @@ -1559,8 +1559,12 @@ void conf(struct ctx *c, int argc, char **argv) get_dns(c); - if (!*c->pasta_ifn) - if_indextoname(c->ifi, c->pasta_ifn); + if (!*c->pasta_ifn) { + if (c->ifi4) + if_indextoname(c->ifi4, c->pasta_ifn); + else + if_indextoname(c->ifi6, c->pasta_ifn); + } c->tcp.ns_detect_ports = c->udp.ns_detect_ports = 0; c->tcp.init_detect_ports = c->udp.init_detect_ports = 0; |