From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id E32C75A0269; Wed, 9 Nov 2022 18:38:08 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tcp, udp: Don't initialise IPv6/IPv4 sockets if IPv4/IPv6 are not enabled Date: Wed, 9 Nov 2022 18:38:08 +0100 Message-Id: <20221109173808.3356358-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NLF5IBZJWWQRDWXS2FSSVMJSULUMYQNX X-Message-ID-Hash: NLF5IBZJWWQRDWXS2FSSVMJSULUMYQNX X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Paul Holzinger X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: <> Archived-At: List-Archive: <> List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If we disable a given IP version automatically (no corresponding default route on host) or administratively (--ipv4-only or --ipv6-only options), we don't initialise related buffers and services (DHCP for IPv4, NDP and DHCPv6 for IPv6). The "tap" handlers will also ignore packets with a disabled IP version. However, in commit 3c6ae625101a ("conf, tcp, udp: Allow address specification for forwarded ports") I happily changed socket initialisation functions to take AF_UNSPEC meaning "any enabled IP version", but I forgot to add checks back for the "enabled" part. Reported by Paul: on a host without default IPv6 route, but IPv6 enabled, connect, using IPv6, to a port handled by pasta, which tries to send data to a tap device without initialised buffers for that IP version and exits because the resulting write() fails. Simpler way to reproduce: pasta -6 and inbound IPv4 connection, or pasta -4 and inbound IPv6 connection. Reported-by: Paul Holzinger Fixes: 3c6ae625101a ("conf, tcp, udp: Allow address specification for forwarded ports") Signed-off-by: Stefano Brivio --- tcp.c | 4 ++-- udp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tcp.c b/tcp.c index 713248f..d043123 100644 --- a/tcp.c +++ b/tcp.c @@ -3213,9 +3213,9 @@ static void tcp_sock_init6(const struct ctx *c, int ns, void tcp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port) { - if (af == AF_INET || af == AF_UNSPEC) + if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) tcp_sock_init4(c, ns, addr, ifname, port); - if (af == AF_INET6 || af == AF_UNSPEC) + if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) tcp_sock_init6(c, ns, addr, ifname, port); } diff --git a/udp.c b/udp.c index 42a17a7..ff7f993 100644 --- a/udp.c +++ b/udp.c @@ -1129,7 +1129,7 @@ void udp_sock_init(const struct ctx *c, int ns, sa_family_t af, c->udp.fwd_in.f.delta[port]); } - if (af == AF_INET || af == AF_UNSPEC) { + if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) { if (!addr && c->mode == MODE_PASTA) bind_addr = &c->ip4.addr; else @@ -1162,7 +1162,7 @@ void udp_sock_init(const struct ctx *c, int ns, sa_family_t af, } } - if (af == AF_INET6 || af == AF_UNSPEC) { + if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) { if (!addr && c->mode == MODE_PASTA) bind_addr = &c->ip6.addr; else -- 2.35.1