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 4500D5A026F for ; Thu, 2 Nov 2023 19:07:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698948444; 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=3b0uyCBq6Mrs1Rdl8tWULnh75KkzihcenZ+mja+UxcY=; b=dKkla2xH7qC2HDbzEozvjEvahL7vq69llKtNgINqQPLkELkDJMnxkABnl6BsepO0+jbGwc h+RTGvKdUBBcMVpuaZnjbsWJbAqgLSKJ+3CStOzap/Oh5pLjZWRhC/fqSG+hBQrX0ivI/t QH7CUrRcx3R1dmsU0zXRphQ54SCV+p0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-1qhC3COoPjq5442U6Yg7sQ-1; Thu, 02 Nov 2023 14:07:22 -0400 X-MC-Unique: 1qhC3COoPjq5442U6Yg7sQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C68C3C0BE31; Thu, 2 Nov 2023 18:07:22 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AE1540C6EBC; Thu, 2 Nov 2023 18:07:21 +0000 (UTC) Date: Thu, 2 Nov 2023 19:07:19 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 3/9] port_fwd: Better parameterise procfs_scan_listen() Message-ID: <20231102190719.1cfe4a78@elisabeth> In-Reply-To: <20231005034445.2015303-4-david@gibson.dropbear.id.au> References: <20231005034445.2015303-1-david@gibson.dropbear.id.au> <20231005034445.2015303-4-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 3YLK3SWWPFGRBZTOJ5N3EH3D2JXR3XBM X-Message-ID-Hash: 3YLK3SWWPFGRBZTOJ5N3EH3D2JXR3XBM 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 Thu, 5 Oct 2023 14:44:39 +1100 David Gibson wrote: > procfs_scan_listen() does some slightly clunky logic to deduce the fd it > wants to use, the path it wants to open and the state it's looking for > based on parameters for protocol, IP version and whether we're in the > namespace. > > However, the caller already has to make choices based on similar parameters > so it can just pass in the things that procfs_scan_listen() needs directly. > > Signed-off-by: David Gibson > --- > port_fwd.c | 53 +++++++++++++++++++++++------------------------------ > 1 file changed, 23 insertions(+), 30 deletions(-) > > diff --git a/port_fwd.c b/port_fwd.c > index 136a450..4b54877 100644 > --- a/port_fwd.c > +++ b/port_fwd.c > @@ -23,39 +23,27 @@ > #include "passt.h" > #include "lineread.h" > > +#define UDP_LISTEN 0x07 > +#define TCP_LISTEN 0x0a > + > /** > * procfs_scan_listen() - Set bits for listening TCP or UDP sockets from procfs > - * @proto: IPPROTO_TCP or IPPROTO_UDP > - * @ip_version: IP version, V4 or V6 > - * @ns: Use saved file descriptors for namespace if set > + * @fd: Pointer to fd for relevant /proc/net file > + * @path: Path to /proc/net file to open (if fd is -1) > + * @lstate: Code for listening state to scan for > * @map: Bitmap where numbers of ports in listening state will be set > * @exclude: Bitmap of ports to exclude from setting (and clear) > * > * #syscalls:pasta lseek > * #syscalls:pasta ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek > */ > -static void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, > - int ns, uint8_t *map, const uint8_t *exclude) > +static void procfs_scan_listen(int *fd, const char *path, unsigned int lstate, > + uint8_t *map, const uint8_t *exclude) > { > - char *path, *line; > struct lineread lr; > unsigned long port; > unsigned int state; > - int *fd; > - > - if (proto == IPPROTO_TCP) { > - fd = &c->proc_net_tcp[ip_version][ns]; > - if (ip_version == V4) > - path = "/proc/net/tcp"; > - else > - path = "/proc/net/tcp6"; > - } else { > - fd = &c->proc_net_udp[ip_version][ns]; > - if (ip_version == V4) > - path = "/proc/net/udp"; > - else > - path = "/proc/net/udp6"; > - } > + char *line; > > if (*fd != -1) { > if (lseek(*fd, 0, SEEK_SET)) { > @@ -74,8 +62,7 @@ static void procfs_scan_listen(struct ctx *c, uint8_t proto, int ip_version, > continue; > > /* See enum in kernel's include/net/tcp_states.h */ This comment should now be moved before #define UDP_LISTEN and TCP_LISTEN, as it's not otherwise clear where they're coming from. Given how late I'm reviewing all this, and that presumably you have a bunch of series/patches based on it, I'm also fine to apply this and patch it in a separate commit, or also fix this up on merge myself -- let me know. Same for the comments to the next patches/series. -- Stefano