From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 949755A004E for ; Thu, 25 Jul 2024 06:40:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1721882418; bh=gR9kj0doNGhZ3KYbDuXkjts1u/GmSuT6Ybbm5iEQinw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=h0R7JWZXQPOlMMbb7cp+5awYe7WHYWGw0alIzOP9qf+HgYtEftt8zzBhZDrIu+A8M sjjM/331QE7xyceNMWAxnsatWtZ82vspz6avk0F96J8PP7PqAEM0NVPMiFE3R9G4XI +3bXRpmSMyf06h582gwtvYVEgO08EsjGWfVPT8Qtp2evERF/i1/UUPCuIsTfeN4Coa NVPWaeW7XVZFKJNI0o2AnQO0odKQP87ETpU8WHJyRV6DBeNA6IsBlcX9AXWTtk/CXZ Mu2OTbpKt6uLMb7YuSMCepYJQT3k5w7VaJ+/2mmQK+o2uHXI1GC1oAoeAvIs4NOCbO vJSDTWkuL1iXg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WTyqQ4nQRz4x0C; Thu, 25 Jul 2024 14:40:18 +1000 (AEST) Date: Thu, 25 Jul 2024 14:39:49 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 11/11] conf: Accept addresses enclosed by square brackets in port forwarding specifiers Message-ID: References: <20240724215021.3366863-1-sbrivio@redhat.com> <20240724215021.3366863-12-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="oG5kyWugp9ATiolU" Content-Disposition: inline In-Reply-To: <20240724215021.3366863-12-sbrivio@redhat.com> Message-ID-Hash: NL23GTGA6AUHW6PCWW3Y7VTD77WVW4GD X-Message-ID-Hash: NL23GTGA6AUHW6PCWW3Y7VTD77WVW4GD 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: --oG5kyWugp9ATiolU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 24, 2024 at 11:50:17PM +0200, Stefano Brivio wrote: > Even though we don't use : as delimiter for the port, making square > brackets unneeded, RFC 3986, section 3.2.2, mandates them for IPv6 > literals. We want IPv6 addresses there, but some users might still > specify them out of habit. >=20 > Same for IPv4 addresses: RFC 3986 doesn't specify square brackets for > IPv4 literals, but I had reports of users actually trying to use them > (they're accepted by many tools). >=20 > Allow square brackets for both IPv4 and IPv6 addresses, correct or > not, they're harmless anyway. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > conf.c | 24 +++++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 3cf9ed8..338742e 100644 > --- a/conf.c > +++ b/conf.c > @@ -209,14 +209,24 @@ static void conf_ports(const struct ctx *c, char op= tname, const char *optarg, > =20 > } > =20 > - if (ifname =3D=3D buf + 1) /* Interface without address */ > + if (ifname =3D=3D buf + 1) { /* Interface without address */ > addr =3D NULL; > - else if (inet_pton(AF_INET, buf, addr)) > - af =3D AF_INET; > - else if (inet_pton(AF_INET6, buf, addr)) > - af =3D AF_INET6; > - else > - goto bad; > + } else { > + p =3D buf; > + > + /* Allow square brackets for IPv4 too for convenience */ > + if (*p =3D=3D '[' && p[strlen(p) - 1] =3D=3D ']') { > + p[strlen(p) - 1] =3D 0; Nit: I think =3D '\0' would make the intention here clearer. > + p++; > + } > + > + if (inet_pton(AF_INET, p, addr)) > + af =3D AF_INET; > + else if (inet_pton(AF_INET6, p, addr)) > + af =3D AF_INET6; > + else > + goto bad; > + } > } else { > spec =3D buf; > =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 --oG5kyWugp9ATiolU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmah1xQACgkQzQJF27ox 2Gcs4Q//W7rz1gQn4pOOw+N4fFgGOG/JK8HCABIreUrw23RgV7Q6BXQ2Lv0c0LB0 jzYvnWf4PDtQWHZtOMnK0GQSR2ep1fltpv78v3LongkIgWj3iWmryZtxP/QYu7bg 6mteTA5Rf1ObPQnxZdf9OGWGr5v0DBFYaNm2DCgmx8LRQxukvpv7mhwu/I03dzU4 hg1Tu2UeHmbBF5ElodQav8DWJnpRPhOFwFYuAK3Myd7lDi87DWEjOg3NzWmOq8dW 1mxmIbdlrLrVzHRFm3enqRFsjKrdtxbD2x0O1EjNwXLUK9vV7tKdHRL+ZqZzvvvz dZ/2663mDVUabgaHcjQmc41xsixhycsLTfYwqdYyZmcMGUA/9Zit6HvtZetKJsA8 YIZsq9/pQ/GNP0jGupZ5Va5MXi4mG4MreBcyxr5N5iBsbYH4o9zQvJU0bKsIKebD +Oriob8ZJ9A5aqRxFlZoa6hezoO0lTB9+6rPgwWhzqqpMP9QY2ktBSaPazKJZoyW BSkgvi0GtBm101WTWVpGSawqseciki6kaM7NTdpAAwxNdIJvkAJlognN0prEPhlN ixp4/OpNN81P3lG3Pc6v9GFXDLsQ849cE52i5LmSgjR/JsVP8tCXjnzWH/delUYr tnl6HqZpFGFdJY8oy1frr6kNJqAMqzioHzYOxuvDhKv31Edq/wM= =4a7t -----END PGP SIGNATURE----- --oG5kyWugp9ATiolU--