From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 59F665A026B for ; Thu, 17 Nov 2022 01:15:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668644135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1/L8SHxv9l7jq120Z8xmlbKnQxqhPYqHo0bmKfMOUMo=; b=LSyRmeUg4QIzLMw4sh9ZI8dA4PqfYOcA+H3vHQ2fJAAPDezB+BUNeod5AxjGyV3k+lib+X BQgkAKUGNci72EpwuBjj+bha6kbn2fo02CzTw1C8hfxWKZbPdfeG5Y9b91L+eatytoHIvu go00EaAQLxAjEU5ZKq7MoipGJ8Eve28= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-434-It5AcIxAPoC4zfZkkQ6EWQ-1; Wed, 16 Nov 2022 19:15:33 -0500 X-MC-Unique: It5AcIxAPoC4zfZkkQ6EWQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA5972999B50; Thu, 17 Nov 2022 00:15:32 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-8.brq.redhat.com [10.40.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8069D40C2086; Thu, 17 Nov 2022 00:15:32 +0000 (UTC) Date: Thu, 17 Nov 2022 01:15:30 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 32/32] tcp: Use dual stack sockets for port forwarding when possible Message-ID: <20221117011530.2b8a7ca5@elisabeth> In-Reply-To: <20221116044212.3876516-33-david@gibson.dropbear.id.au> References: <20221116044212.3876516-1-david@gibson.dropbear.id.au> <20221116044212.3876516-33-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: XROH4CUZX5WPWEHDLKNARXI2H36B4H64 X-Message-ID-Hash: XROH4CUZX5WPWEHDLKNARXI2H36B4H64 X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top 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: On Wed, 16 Nov 2022 15:42:12 +1100 David Gibson wrote: > Platforms like Linux allow IPv6 sockets to listen for IPv4 connections as > well as native IPv6 connections. By doing this we halve the number of > listening sockets we need for TCP (assuming passt/pasta is listening on the > same ports for IPv4 and IPv6). When forwarding many ports (e.g. -t all) > this can significantly reduce the amount of kernel memory that passt > consumes. > > When forwarding all TCP and UDP ports for both IPv4 and IPv6 (-t all > -u all), this reduces kernel memory usage from ~677MiB to ~487MiB > (kernel version 6.0.8 on Fedora 37, x86_64). Oh, nice, that's quite significant. > Signed-off-by: David Gibson > --- > tcp.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 616b9d0..5860c9f 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2991,8 +2991,12 @@ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, > > s = sock_l4(c, af, IPPROTO_TCP, addr, ifname, port, tref.u32); > > - if (c->tcp.fwd_in.mode == FWD_AUTO) > - tcp_sock_init_ext[port][(af == AF_INET) ? V4 : V6] = s; > + if (c->tcp.fwd_in.mode == FWD_AUTO) { > + if (af == AF_INET || af == AF_UNSPEC) > + tcp_sock_init_ext[port][V4] = s; > + if (af == AF_INET6 || af == AF_UNSPEC) Nit: you could align the || af == AF_UNSPEC above with an extra whitespace (as it's done in the context below). > + tcp_sock_init_ext[port][V6] = s; > + } > > if (s < 0) > return -1; > @@ -3012,6 +3016,12 @@ static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port, > void tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, > const char *ifname, in_port_t port) > { > + if (af == AF_UNSPEC && c->ifi4 && c->ifi6) > + /* Attempt to get a dual stack socket */ > + if (tcp_sock_init_af(c, AF_UNSPEC, port, addr, ifname) >= 0) > + return; > + > + /* Otherwise create a socket per IP version */ ...this looks surprisingly clean by the way, at least much cleaner than I expected. > if ((af == AF_INET || af == AF_UNSPEC) && c->ifi4) > tcp_sock_init_af(c, AF_INET, port, addr, ifname); > if ((af == AF_INET6 || af == AF_UNSPEC) && c->ifi6) I just finished reviewing this series, in general it looks great to me, I would have another look (and test!) on Thursday -- either using this version or a re-spin. -- Stefano