aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-21 15:57:04 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-22 23:20:55 +0200
commita63199832a737dde45500e4037608727701c782f (patch)
tree951f21bedabaea40886003cfb3c68aa51ef9d156 /tcp.c
parent7a832a8a0edbdd5a705c1fe03fca0790a535ab11 (diff)
downloadpasst-a63199832a737dde45500e4037608727701c782f.tar
passt-a63199832a737dde45500e4037608727701c782f.tar.gz
passt-a63199832a737dde45500e4037608727701c782f.tar.bz2
passt-a63199832a737dde45500e4037608727701c782f.tar.lz
passt-a63199832a737dde45500e4037608727701c782f.tar.xz
passt-a63199832a737dde45500e4037608727701c782f.tar.zst
passt-a63199832a737dde45500e4037608727701c782f.zip
inany: Better helpers for using inany and specific family addrs together
This adds some extra inany helpers for comparing an inany address to addresses of a specific family (including special addresses), and building an inany from an IPv4 address (either statically or at runtime). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/tcp.c b/tcp.c
index 109d443..d0ce202 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2687,24 +2687,17 @@ static void tcp_connect_finish(struct ctx *c, struct tcp_tap_conn *conn)
*/
static void tcp_snat_inbound(const struct ctx *c, union inany_addr *addr)
{
- struct in_addr *addr4 = inany_v4(addr);
-
- if (addr4) {
- if (IN4_IS_ADDR_LOOPBACK(addr4) ||
- IN4_IS_ADDR_UNSPECIFIED(addr4) ||
- IN4_ARE_ADDR_EQUAL(addr4, &c->ip4.addr_seen))
- *addr4 = c->ip4.gw;
- } else {
- struct in6_addr *addr6 = &addr->a6;
-
- if (IN6_IS_ADDR_LOOPBACK(addr6) ||
- IN6_ARE_ADDR_EQUAL(addr6, &c->ip6.addr_seen) ||
- IN6_ARE_ADDR_EQUAL(addr6, &c->ip6.addr)) {
- if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw))
- *addr6 = c->ip6.gw;
- else
- *addr6 = c->ip6.addr_ll;
- }
+ if (inany_is_loopback4(addr) ||
+ inany_is_unspecified4(addr) ||
+ inany_equals4(addr, &c->ip4.addr_seen)) {
+ *addr = inany_from_v4(c->ip4.gw);
+ } else if (inany_is_loopback6(addr) ||
+ inany_equals6(addr, &c->ip6.addr_seen) ||
+ inany_equals6(addr, &c->ip6.addr)) {
+ if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw))
+ addr->a6 = c->ip6.gw;
+ else
+ addr->a6 = c->ip6.addr_ll;
}
}