From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=pXY6U5+I; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id BE8A45A004E for ; Thu, 29 Aug 2024 06:28:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1724905673; bh=N2YdFsbihBdpG9394elYw2VdKspkGL8nTLwX+8umTHU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pXY6U5+IYGwM7853ZqQwkOMg5Nv9NRJmZtLU2m5JX2MW5W2wW1kXcI1uWb8HxZTn/ ObD6dfQ+ZQFvamS3A4XJ8QPa9mpTSbE+KrDnIAgIHd1/Mejqgp/AXiQhmVLsyi6XXr PoZQhid2Susl8yl0WN1umlzB03RdnZ34WiGpMHaEdt7BtyxqezErOdTZumFTngzQ+r YEp64ceL6wNRD20Et765SUwdURqtZR3aIczSxAgrJeeiEVUlQ0Ho9UyUIf3iXQ82gZ By4Slf0+9CQFh3jh9v5EFKu+o4C10kZahZehYWXE5L8ODzVXgcTEzzWnXsiIICaGRQ 1zBRfsPDC8S6g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WvStx4W0rz4x0t; Thu, 29 Aug 2024 14:27:53 +1000 (AEST) Date: Thu, 29 Aug 2024 14:14:30 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/3] fwd, conf: Probe host's ephemeral ports Message-ID: References: <20240828055610.3241117-1-david@gibson.dropbear.id.au> <20240828055610.3241117-4-david@gibson.dropbear.id.au> <9ba5487a-17b7-4c7b-a3d4-7a1e2c7d88a5@redhat.com> <20240829045955.7f83a9e5@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eTLJfo/Qsnls3HT5" Content-Disposition: inline In-Reply-To: <20240829045955.7f83a9e5@elisabeth> Message-ID-Hash: CFTIYWJEIPO4V3MUJ3HC5BKOHDLG3HP6 X-Message-ID-Hash: CFTIYWJEIPO4V3MUJ3HC5BKOHDLG3HP6 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: Laurent Vivier , 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: --eTLJfo/Qsnls3HT5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 29, 2024 at 04:59:55AM +0200, Stefano Brivio wrote: > On Thu, 29 Aug 2024 11:29:30 +1000 > David Gibson wrote: >=20 > > On Wed, Aug 28, 2024 at 12:22:18PM +0200, Laurent Vivier wrote: > > > On 28/08/2024 07:56, David Gibson wrote: =20 > > > > > > > > [...] > > > > > > > > + lineread_init(&lr, fd); > > > > + len =3D lineread_get(&lr, &line); > > > > + if (len < 0) > > > > + goto parse_err; > > > > + > > > > + tab =3D strchr(line, '\t'); > > > > + if (!tab) > > > > + goto parse_err; > > > > + *tab =3D '\0'; > > > > + > > > > + errno =3D 0; > > > > + min =3D strtol(line, &end, 10); > > > > + if (*end || errno) > > > > + goto parse_err; > > > > + > > > > + errno =3D 0; > > > > + max =3D strtol(tab + 1, &end, 10); > > > > + if (*end || errno) > > > > + goto parse_err; =20 > > >=20 > > > As /proc files are well formated, why don't you use fscanf()? > > > Something like: > > >=20 > > > FILE *f; > > >=20 > > > f =3D fopen(PORT_RANGE_SYSCTL, "r"); > > > if (f =3D=3D NULL) { > > > warn("Unable to parse %s", PORT_RANGE_SYSCTL); > > > return; > > > } > > > ret =3D fscanf(f, "%d %d", &min, &max); > > > fclose(f); > > > if (ret !=3D 2) > > > goto parse_error; =20 > >=20 > > Hm, maybe. I never feel like I know exactly what the parse rules for > > scanf() are, so I tend to avoid it. Stefano, any thoughts? >=20 > The issue with fopen() and ffscanf() is that they need dynamic > allocation, see also 32d07f5e59f2 ("passt, pasta: Completely avoid > dynamic memory allocation"). Ah, good point, I'd forgotten that. > Still, here, we could use lineread_get() and sscanf() as we do in fwd.c, > procfs_scan_listen(), but I don't really have a preference. If you find > that scanf() is confusing for you, perhaps it would be better to use > something simpler as you did. On the other hand it would be 2 lines of > code instead of (somewhat bug-prone) 14 lines. True. Ok, I've switched over to sscanf() for the next spin. > I'm not sure, I'd say whatever you feel most comfortable with... >=20 --=20 David Gibson (he or they) | 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 --eTLJfo/Qsnls3HT5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbP9ZUACgkQzQJF27ox 2GcxBg//RS3oGvqRqQDJCZryAvgMgDi54D+0A/+9nMjjwjVhBBJ6t+H2YRXWrJ24 8Bdk36jlvIINKN+5tCR8r4p5oxwDmLEv0ZH1MMGe60UNd7ITOm1Q5DQ/VSTbW0Zn bv0RHWGVghO4+EKHXS9ImHDHfQyshbKUP0A85lpb4lsDAVNm3c9t4qyC7EZEzthr mslU+03Rejzfs8flRYfuEkAdChogzeKIkoZBcDnkMlpExp378EY0ekF4f0sGRPv4 qK6AkLdtzmDZZqeZ+70msH9JGc44ApPRN2ijvRcLeLJz/6ry0u3mRnLtoPccVp1I zuw5SXG0/bii68BqJDNattC1BcX9UKt/93XMdyJrskMp2ljLBboKskL7wm32blJZ H6FVoZIYscR2sJ2Kh8JNV2eITawLSrz0YCZ6phwkTy1VGByrNR19EYMZ/Dtu6nW0 8mHla6VsMsJ/fNG3Xktt1O4mCPF5rCJZfm3/CvtvP57fegvPLKFt/wMdVXfbrLxt eo4iUYmIVyzv/1mzfCeJTdOGmpZJMa9Vscq+/huHa1FzXe9fDlgHkzvUd6RuoTjF QW8R3HZ0J/VJu2hZ+rz2YU3XWqnrVAWMw0VROuSbpW25xn4gRpuH8gDAXwJnedJ4 kIpucN4x9z5yXdAdhCoCuQuahhMZPHexiaIRPHhGkacn03MYEAE= =wHyg -----END PGP SIGNATURE----- --eTLJfo/Qsnls3HT5--