On Fri, 16 Aug 2024 15:40:00 +1000
David Gibson <david(a)gibson.dropbear.id.au> wrote:
The @gw fields in the ip4_ctx and ip6_ctx give
the (host's) default
gateway. We use this for two quite distinct things: advertising the
gateway that the guest should use (via DHCP, NDP and/or --config-net)
and for a limited form of NAT. So that the guest can access services
on the host, we map the gateway address within the guest to the
loopback address on the host.
Using the gateway address for this isn't necessarily the best choice
for this purpose, certainly not for all circumstances. So, start off
by splitting the notion of these into two different values: @guest_gw
which is the gateway address the guest should use and @nat_host_loopback,
which is the guest visible address to remap to the host's loopback.
Usually nat_host_loopback will have the same value as guest_gw. However
when --no-map-gw is specified we leave them unspecified instead. This
means when we use nat_host_loopback, we don't need to separately check
c->no_map_gw to see if it's relevant.
Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
conf.c | 60 +++++++++++++++++++++++++++++----------------------------
dhcp.c | 10 ++++++----
fwd.c | 4 ++--
passt.h | 16 +++++++++------
pasta.c | 6 ++++--
5 files changed, 53 insertions(+), 43 deletions(-)
diff --git a/conf.c b/conf.c
index b1c58d5b..26373584 100644
--- a/conf.c
+++ b/conf.c
@@ -410,12 +410,12 @@ static void add_dns_resolv(struct ctx *c, const char *nameserver,
* redirect
*/
if (IN4_IS_ADDR_LOOPBACK(&ns4)) {
- if (c->no_map_gw)
+ if (IN4_IS_ADDR_UNSPECIFIED(&c->ip4.nat_host_loopback))
If you change the command-line option name to use "map", it would be
good to also change these names.
Will do.
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.