aboutgitcodebugslistschat
path: root/fwd.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-08-21 14:20:19 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-08-21 12:00:40 +0200
commit57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53 (patch)
treea15f5320b134c31902a597f7f0348ee2b5b468b4 /fwd.c
parent8436c0d61b3a0443df12fa7b2c928932ba202ba6 (diff)
downloadpasst-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar.gz
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar.bz2
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar.lz
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar.xz
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.tar.zst
passt-57b7bd2a48a1dc5c87f4db51f7bf439cc84fcd53.zip
fwd, conf: Allow NAT of the guest's assigned address
The guest is usually assigned one of the host's IP addresses. That means it can't access the host itself via its usual address. The --map-host-loopback option (enabled by default with the gateway address) allows the guest to contact the host. However, connections forwarded this way appear on the host to have originated from the loopback interface, which isn't always desirable. Add a new --map-guest-addr option, which acts similarly but forwarded connections will go to the host's external address, instead of loopback. If '-a' is used, so the guest's address is not the same as the host's, this will instead forward to whatever host-visible site is shadowed by the guest's assigned address. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'fwd.c')
-rw-r--r--fwd.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/fwd.c b/fwd.c
index c55aea0..2a0452f 100644
--- a/fwd.c
+++ b/fwd.c
@@ -272,6 +272,10 @@ uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto,
tgt->eaddr = inany_loopback4;
else if (inany_equals6(&ini->oaddr, &c->ip6.map_host_loopback))
tgt->eaddr = inany_loopback6;
+ else if (inany_equals4(&ini->oaddr, &c->ip4.map_guest_addr))
+ tgt->eaddr = inany_from_v4(c->ip4.addr);
+ else if (inany_equals6(&ini->oaddr, &c->ip6.map_guest_addr))
+ tgt->eaddr.a6 = c->ip6.addr;
else
tgt->eaddr = ini->oaddr;
@@ -393,6 +397,12 @@ uint8_t fwd_nat_from_host(const struct ctx *c, uint8_t proto,
} else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.map_host_loopback) &&
inany_equals6(&ini->eaddr, &in6addr_loopback)) {
tgt->oaddr.a6 = c->ip6.map_host_loopback;
+ } else if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.map_guest_addr) &&
+ inany_equals4(&ini->eaddr, &c->ip4.addr)) {
+ tgt->oaddr = inany_from_v4(c->ip4.map_guest_addr);
+ } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.map_guest_addr) &&
+ inany_equals6(&ini->eaddr, &c->ip6.addr)) {
+ tgt->oaddr.a6 = c->ip6.map_guest_addr;
} else if (!fwd_guest_accessible(c, &ini->eaddr)) {
if (inany_v4(&ini->eaddr)) {
if (IN4_IS_ADDR_UNSPECIFIED(&c->ip4.our_tap_addr))