From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iPCuCE+L; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id C9E955A0619 for ; Mon, 20 Oct 2025 08:08:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760940524; 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=rD08t3nTKdUk/48L1QsVZDLlthRVayRl5HF+xVmwPXo=; b=iPCuCE+LswxQcBOolssFPBpuzpMJQobctLauA+F5YY4kjXPuvZ7NRXMJ+DR99ChY+lRytO jbDussJwPg01PCAlLxbuZe8QZ8nl5ZLnf3jjBJAakOqRN32cz9TCcJvZGERzXLh9m6a7rp pYU4dYQiqz5780XRXGmgMiWJXFQMBho= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-dw2pXbbaOFWp6U1j1qgxYQ-1; Mon, 20 Oct 2025 02:08:43 -0400 X-MC-Unique: dw2pXbbaOFWp6U1j1qgxYQ-1 X-Mimecast-MFC-AGG-ID: dw2pXbbaOFWp6U1j1qgxYQ_1760940522 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-4270a273b6eso1970895f8f.0 for ; Sun, 19 Oct 2025 23:08:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760940521; x=1761545321; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rD08t3nTKdUk/48L1QsVZDLlthRVayRl5HF+xVmwPXo=; b=XBl4Suu8pL7AyYxfszJPRqhI8S0u8rYMbQv2jag8FiRpGGz0JIlo0q+eFFaEqOH6ZV CCh8TuMcTawcut0jL2ZNAOkVqupfIYUTWim8W3MPAs8N4bhTYTwL4PN7xAKpGXr+4oCm BEsKDfXcQ9x80mXRoeiCgUePYzD8hMODz6AvNSsA6DO60V17xq7SBAhkfOZxv2n4iM4X 7lIl5velY8QoUdP5iCAJIwgMmmog4NdA71fkDRTl9yDGuDFu5foojhz6oILo1gdJeeUu q0PrLmUtk+7z98e0+dd4hNnzvapQ3/0bNoUxg1anT+SxtNbArmFibpkLmDd3hhlIKp9q Buuw== X-Gm-Message-State: AOJu0YxKGn7QJuWYJYUcFlVK/XMS+qhSg2V29ScpFXAMk/X/CRe0DvCT K/v+roStmp0W9lHydVfsKrNVAFo8kpl/BOZEvqXXEeEqzeqPMWkiAkriJe1Nn4O1ta51iQiE0sZ BCd6zdRIF9noUXEwmOCciiQyQNcRfOh3i75f6O48iZ845n/QcGqRPnXWDfKmPHA== X-Gm-Gg: ASbGnctzpbItAwXnrmmrcQOmGu7IqL5jY/mZLaqLmigZUQNQhhqlDWTSUI8Ktjg7RjM mpSsb3zu1VDbUjIaP582kY8313VBHGMNBljBlBGoJ2eDRhVkWyhqONSEmQRte/HiPArl6S+YCx1 qN6KyLlNfwS+ck6tXCsRh921BEAdwS9pZzE8DbuVGB97gkuQcvUvVv8HbHdW/nfz9Yy4hMNOB66 UA9smgo6AE/KMFiNyY/ji9wb8vVp/HSzCFxQ3fDx66aYBf3laHPRaMUAamVrXjxsSL6Vu3F0Yma kbybnF39TMPd2MFRAbM2/fUsUksAaUIHE1shd7S6p4g4uBnxNxeHhiR+9EoEelONlR+ZYjSFg02 F7J7gJLrTy15Wjsd+/0DZsBOh3Bo= X-Received: by 2002:a05:6000:4606:b0:427:608:c64d with SMTP id ffacd0b85a97d-4270608c806mr6874307f8f.37.1760940521327; Sun, 19 Oct 2025 23:08:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm33JaGwb8fTYFu8rPL70qakGu+i19nGGubShs7vrM2A8EtvkdeeoZWM2VNnaDOLCK3dR+PA== X-Received: by 2002:a05:6000:4606:b0:427:608:c64d with SMTP id ffacd0b85a97d-4270608c806mr6874281f8f.37.1760940520909; Sun, 19 Oct 2025 23:08:40 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-427ea5b3d4csm13186071f8f.19.2025.10.19.23.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Oct 2025 23:08:40 -0700 (PDT) Date: Mon, 20 Oct 2025 08:08:39 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/3] tcp: Merge tcp_ns_sock_init[46]() into tcp_sock_init_one() Message-ID: <20251020080839.0b4d4f82@elisabeth> In-Reply-To: <20251017003447.414103-2-david@gibson.dropbear.id.au> References: <20251017003447.414103-1-david@gibson.dropbear.id.au> <20251017003447.414103-2-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: tpO6lYIprHMo7t7dB0BGx2hr7eac9ID2Aer8UWd0H70_1760940522 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: Q74HCKSIKAZMD37VJ7X4BZYGBHM4WYAW X-Message-ID-Hash: Q74HCKSIKAZMD37VJ7X4BZYGBHM4WYAW 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.8 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 Fri, 17 Oct 2025 11:34:45 +1100 David Gibson wrote: > Surprisingly little logic is shared between the path for creating a > listen()ing socket in the guest namespace versus in the host namespace. > Improve this, by extending tcp_sock_init_one() to take a pif parameter > indicating where it should open the socket. This allows > tcp_ns_sock_init[46]() to be removed entirely. > > We generalise tcp_sock_init() in the same way, although we don't use it > yet, due to some subtle differences in how we bind for -t versus -T. > > Signed-off-by: David Gibson > --- > conf.c | 2 +- > tcp.c | 96 ++++++++++++++++++---------------------------------------- > tcp.h | 5 +-- > 3 files changed, 33 insertions(+), 70 deletions(-) > > diff --git a/conf.c b/conf.c > index 66b9e634..26f1bcc0 100644 > --- a/conf.c > +++ b/conf.c > @@ -169,7 +169,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname, > fwd->delta[i] = to - first; > > if (optname == 't') > - ret = tcp_sock_init(c, addr, ifname, i); > + ret = tcp_sock_init(c, PIF_HOST, addr, ifname, i); > else if (optname == 'u') > ret = udp_sock_init(c, 0, addr, ifname, i); > else > diff --git a/tcp.c b/tcp.c > index 0f9e9b3f..15c012d7 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2515,29 +2515,38 @@ void tcp_sock_handler(const struct ctx *c, union epoll_ref ref, > /** > * tcp_sock_init_one() - Initialise listening socket for address and port > * @c: Execution context > + * @pif: Interface to open the socket for (PIF_HOST or PIF_SPLICE) > * @addr: Pointer to address for binding, NULL for dual stack any > * @ifname: Name of interface to bind to, NULL if not configured > * @port: Port, host order > * > * Return: fd for the new listening socket, negative error code on failure > + * > + * If pif == PIF_SPLICE, must have already entered the namespace. > */ > -static int tcp_sock_init_one(const struct ctx *c, const union inany_addr *addr, > - const char *ifname, in_port_t port) > +static int tcp_sock_init_one(const struct ctx *c, uint8_t pif, > + const union inany_addr *addr, const char *ifname, > + in_port_t port) > { > + const struct fwd_ports *fwd = pif == PIF_HOST ? > + &c->tcp.fwd_in : &c->tcp.fwd_out; While I appreciate the resulting brevity, I wonder if it would make more sense to have this as an explicit if / else clause, for readability. Same for similar occurrences in the next patches (which I didn't fully review, yet). Another alternative is: const struct fwd_ports *fwd; fwd = (pif == PIF_HOST) ? &c->tcp.fwd_in : &c->tcp.fwd_out; ...still two lines of code, perhaps just slightly less readable than the five obvious ones: const struct fwd_ports *fwd; if (pif == PIF_HOST) fwd = &c->tcp.fwd_in; else fwd = &c->tcp.fwd_out; -- Stefano