From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH] tcp, udp: Don't initialise IPv6/IPv4 sockets if IPv4/IPv6 are not enabled
Date: Thu, 10 Nov 2022 11:15:47 +1100 [thread overview]
Message-ID: <Y2xCs2Em6j6uckx5@yekko> (raw)
In-Reply-To: <20221109173808.3356358-1-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3081 bytes --]
On Wed, Nov 09, 2022 at 06:38:08PM +0100, Stefano Brivio wrote:
> 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 <pholzing@redhat.com>
> Fixes: 3c6ae625101a ("conf, tcp, udp: Allow address specification for forwarded ports")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Heh, I also noticed this while working on the dual stack socket stuff,
but didn't get around to fixing it yet.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> 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
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2022-11-10 0:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 17:38 [PATCH] tcp, udp: Don't initialise IPv6/IPv4 sockets if IPv4/IPv6 are not enabled Stefano Brivio
2022-11-10 0:15 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2xCs2Em6j6uckx5@yekko \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=pholzing@redhat.com \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).