From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 54A555A026C for ; Thu, 3 Nov 2022 04:42:39 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N2qMY4cSvz4xwl; Thu, 3 Nov 2022 14:42:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1667446953; bh=+iZo9E85RL9fYqNdg/XlE+I/S0eRC3CZlGlmAYCtvsU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fdwk1XSd/WOp1HfQzWzuuzPx1FZzLMkWXXYKObXUOdkWfE1UbfnSdICPRyWXZ/vFn ZUn5Qbr3dsS9SMQzz/vWmEsP0W+mMWabecsL87EsmIulHVE5SwINcQvd56KcH5pZ3P 7ZMYYKv7PHqPLnjxVtaCXTSsB86DFZ5Hw/wO3SvQ= Date: Thu, 3 Nov 2022 14:17:57 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 1/3] conf: Consistency check between configured IPv4 netmask and gateway Message-ID: References: <20221102230443.377446-1-sbrivio@redhat.com> <20221102230443.377446-2-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4Sq9b0veFhRiZxqL" Content-Disposition: inline In-Reply-To: <20221102230443.377446-2-sbrivio@redhat.com> Message-ID-Hash: 7XQZNRUHNRQWK2EHFBTDH755IEULNHFE X-Message-ID-Hash: 7XQZNRUHNRQWK2EHFBTDH755IEULNHFE 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, Paul Holzinger X-Mailman-Version: 3.3.3 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: --4Sq9b0veFhRiZxqL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 03, 2022 at 12:04:41AM +0100, Stefano Brivio wrote: > Seen in a Google Compute Engine environment with a machine configured > via cloud-init-dhcp, while testing Podman integration for pasta: the > assigned address has a /32 netmask, and there's a default route, > which can be added on the host because there's another route, also > /32, pointing to the default gateway. I'm afraid I'm having trouble getting a good picture of the situation =66rom this description. I think an actual example with addresses would make it much clearer. > This is not a valid configuration as far as I can tell: if the > address is configured as /32, it shouldn't be used to reach a gateway > outside its derived netmask. However, Linux allows that, and > everything works. >=20 > The problem comes when pasta --config-net sources address and default > route from the host, and it can't configure the route in the target > namespace because the gateway is invalid. >=20 > Sourcing more routes than just the default is doable, but probably > undesirable: pasta users want to provide connectivity to a container, > not reflect exactly whatever trickery is configured on the host. >=20 > Add a consistency check: if the configured default gateway is not > reachable, shrink the given netmask until we can reach it. Hmm... this isn't merely a check, it's changing an otherwise configured value. > Signed-off-by: Stefano Brivio > --- > conf.c | 4 ++++ > 1 file changed, 4 insertions(+) >=20 > diff --git a/conf.c b/conf.c > index 90214f5..5b88547 100644 > --- a/conf.c > +++ b/conf.c > @@ -562,6 +562,10 @@ static unsigned int conf_ip4(unsigned int ifi, > ip4->mask =3D 0xffffffff; > } > =20 > + /* Mask consistency check: ensure we can reach the default gateway */ Since this is to handle a very weird situation, we absolutely need a more detailed comment here. > + while ((ip4->addr & ip4->mask) !=3D (ip4->gw & ip4->mask)) > + ip4->mask =3D htonl(ntohl(ip4->mask) << 1); > + > memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen)); > =20 > if (MAC_IS_ZERO(mac)) --=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 --4Sq9b0veFhRiZxqL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNjMt4ACgkQgypY4gEw YSLdrg//aZa3jGLf4dvQ/avuQSb8DTWdHjdHc8zgZrKGCW3EWu743hRStvkcXUla NiP75YCk1RVaSsklqCauIjG3EzTRg8FRVQM9YwzJRcv7w3uu8vTfP5sGXgjM5pAm gOK5muug7OnSeb3jF9E92JXlWWGw8nryHbbJPLwMdhF3zp8s4nk3lV7D4U/j5rKK dM8E4PAdPkmv1NQJfJWCIl9qS4QjwoOEeeIQgRlqElsoEBw2QaG+uDu+fICUdV5y 1KW1no6hdHn1uzE0x6j/yiI5d8h0dOECvAhb7GgeRcngLKIl+/177I8Dik3KROda EHrAQKpdmnXkxW2eARscpBUmjg3/md3KtJkSa5V4s8dNWH34ffPyaFLEstN0XQn9 u16P7xlUaix9yMmDokHE8aSRItktKjxLzPrbjeLBK+/9kwrz1m2gqGn2o/1TBXPY nLTWhLAaaWTZdNEe6knqyseWTV7sPnOiRnmqRhe7iruxcW8ngiG8rGjc6O4If4ig re4SU/XBxewPeJ0DalGaA1mlgH5gaFiq32lyIST/N+6ahxCYsOp7zG1+pxgDnDm+ rUnRKl325vnjovWJBT4QTf7vnC1vym0W100ngk9ApX4qgwXrYQvxrGasAmw3PkTY VJZD34Is9IF1zCGN8GmUTdSCoFPtUC+epqr5+fzR/o/4wv5HKsE= =m05E -----END PGP SIGNATURE----- --4Sq9b0veFhRiZxqL--