From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 102055A026F for ; Fri, 3 Nov 2023 01:21:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1698970855; bh=hHAm6Iv+/476j4w8DcgMFlxi6toxNwwb/fxA4l3smdU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JDGJ1Q11fuYnKVnh0hLpIFRDVAICw2NcvIzNvnKbeNmmLzEYpTFb5aWXKvcHVs6nk 6GNDVD7c8b+NR8VJRqMHVJliLVNklLfd2CqTvDKGbEw0wQLYQHNRGlst1MImNRPbxz 1sKCYL1u4TYDXIsT5PM78XNxAeq8v9X3ai3so5R8= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SM1cR36rxz4x5k; Fri, 3 Nov 2023 11:20:55 +1100 (AEDT) Date: Fri, 3 Nov 2023 11:16:46 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/9] port_fwd: Better parameterise procfs_scan_listen() Message-ID: References: <20231005034445.2015303-1-david@gibson.dropbear.id.au> <20231005034445.2015303-4-david@gibson.dropbear.id.au> <20231102190719.1cfe4a78@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="iBwDrl7Sgw06Rgm+" Content-Disposition: inline In-Reply-To: <20231102190719.1cfe4a78@elisabeth> Message-ID-Hash: NWRQXUTHWODNCPAFPKERHLJRVG4WDQOA X-Message-ID-Hash: NWRQXUTHWODNCPAFPKERHLJRVG4WDQOA X-MailFrom: dgibson@gandalf.ozlabs.org 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: --iBwDrl7Sgw06Rgm+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 02, 2023 at 07:07:19PM +0100, Stefano Brivio wrote: > On Thu, 5 Oct 2023 14:44:39 +1100 > David Gibson wrote: >=20 > > 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. > >=20 > > However, the caller already has to make choices based on similar parame= ters > > so it can just pass in the things that procfs_scan_listen() needs direc= tly. > >=20 > > Signed-off-by: David Gibson > > --- > > port_fwd.c | 53 +++++++++++++++++++++++------------------------------ > > 1 file changed, 23 insertions(+), 30 deletions(-) > >=20 > > 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" > > =20 > > +#define UDP_LISTEN 0x07 > > +#define TCP_LISTEN 0x0a > > + > > /** > > * procfs_scan_listen() - Set bits for listening TCP or UDP sockets fr= om 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_ve= rsion, > > - 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 =3D=3D IPPROTO_TCP) { > > - fd =3D &c->proc_net_tcp[ip_version][ns]; > > - if (ip_version =3D=3D V4) > > - path =3D "/proc/net/tcp"; > > - else > > - path =3D "/proc/net/tcp6"; > > - } else { > > - fd =3D &c->proc_net_udp[ip_version][ns]; > > - if (ip_version =3D=3D V4) > > - path =3D "/proc/net/udp"; > > - else > > - path =3D "/proc/net/udp6"; > > - } > > + char *line; > > =20 > > if (*fd !=3D -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; > > =20 > > /* See enum in kernel's include/net/tcp_states.h */ >=20 > This comment should now be moved before #define UDP_LISTEN and > TCP_LISTEN, as it's not otherwise clear where they're coming from. Good point, fixed. > 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. >=20 > Same for the comments to the next patches/series. Eh, I don't think the rebasing should be too hard, so I'm happy to sort that out. --=20 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 --iBwDrl7Sgw06Rgm+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmVEO+YACgkQzQJF27ox 2GeUTA/+JloGOExuCd2dM4zI28QNeCNMwICaERuIVgYw8/fVUjh/hI/cCIHaFhXU 12AonSBQG2uNcAyYQcWR0oEGv0b1AvKpcWuADhyxCs3jfe3zzNAJ3l4DOwhZfMGp 23ypxZAUeqdeGSOhkmkYKXNJ2RpUolZLjSc1A9+as2vzwtJxJEqCtyAaA4DJ0hK5 RY58IJHkUM2CURLlMEG1m8/8sKrVd75ZCS8sjff72TDuhDJdPPKAc9Gq1z425z/+ 44YJx//aT+DJH6+Je/5Q11AeXd2dYTPy7t4GhqOT9u6vO8ysOUfxxh6O/rDONno8 mt3tw/AEB2PLRrSs3NzUcyxXQy3kWEMSL+aEgL3ddExIY6ceu7QMSJ7cDat21Kvf tnEm6UZuM1Kc1Leq7gIeMX/saEiZT/erf/bTXBuijS4H7e0sgbspEzrK6hXnn1S4 CKWSVwho6OK5zfxob5PoF+NWa1saFUZ38bxbB3vSPIsex8/Fi9bqGENUBNyHuq+T 8A6j1AhLCs5I2kJEYsJz9f/3ZeLnTXDAeCHirtMiS8VThtnf6zj8AguaH4ndaeTD o6pxZE+yEX3D0VnZLdLOLLyVInkrh991SLkcty8c72p2JjS7ZQuuoKIcxIAcBNcI GHli1HK5hQNtEHNueXDb49mxQotfjnguxNMAg8+iHicjGRjhLO0= =K+FG -----END PGP SIGNATURE----- --iBwDrl7Sgw06Rgm+--