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=202512 header.b=EXl/uCOI; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 652E55A0625 for ; Thu, 18 Dec 2025 06:02:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1766034152; bh=eSp24+4zHxzTkvA+BaJmvYZH53W+zJUpyurHxMp3HFw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EXl/uCOI7meZl7ZjfFg+fI27NegTt/R0QLpk0PCSCYrrt4gdJhTNyvKCJNm7trUdI b1U23tcYm/SSxYaAcMce1YZ4TKWg4i+Q/HM02ZNePwf3A0Cdc8yCliexdjHtpOvYJJ MoeEZ/SVvS6c8aBRSYzP63mc4/nxFw9crpO/WtWrF9Yn38hw412AmuCCvK/0JmTFya FmzheTR84WjA6OhBuPLH1MA9vVh+gNzmIzh1CaWhCBVG5NhsriujeftpAxI/iUFEoH DrP0lVFWS6LKIJIASBGhT06D1U48mf6Nr2RnXF9uun0qSpzgCNwHS7ZSRDOuo8TxOf 6E3NdpfMjwBDA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dWz7D6g6Yz4wGx; Thu, 18 Dec 2025 16:02:32 +1100 (AEDT) Date: Thu, 18 Dec 2025 15:59:06 +1100 From: David Gibson To: Jon Maloy Subject: Re: [RFC 11/12] netlink: Prevent host route events from overwriting guest-configured gateway Message-ID: References: <20251215015441.887736-1-jmaloy@redhat.com> <20251215015441.887736-12-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="drx2UOHNYQEtiIhu" Content-Disposition: inline In-Reply-To: <20251215015441.887736-12-jmaloy@redhat.com> Message-ID-Hash: 5J5RUNOAFJOWLEZOTARM3C6YE5EI3DTQ X-Message-ID-Hash: 5J5RUNOAFJOWLEZOTARM3C6YE5EI3DTQ 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: sbrivio@redhat.com, dgibson@redhat.com, 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: --drx2UOHNYQEtiIhu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 14, 2025 at 08:54:40PM -0500, Jon Maloy wrote: > We add a new context flag 'guest_gw_from_ns' to track if the gateway > was configured from the guest side, something that might have happened > either via the -g option or by a namespace-side netlink event. When set, > host side route events will not be permitted to overwrite the guest's > gateway configuration. If -g is set, I don't think we should even subscribe to the routing updates in the first place. If --config-net is *not* set, we shouldn't be touching the guest config anyway. If --config-net *is* set, that's essentially saying that we own the guest's network configuration. We don't need to go to these lengths to stop it from shooting itself by making conflicting config updates. >=20 > This gives any gateway setting from the guest side precedence over any > ditto coming from the host side. >=20 > Signed-off-by: Jon Maloy > --- > conf.c | 2 ++ > netlink.c | 15 +++++++++++++-- > passt.h | 4 ++++ > 3 files changed, 19 insertions(+), 2 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 0a4a28a..f26637c 100644 > --- a/conf.c > +++ b/conf.c > @@ -1891,6 +1891,7 @@ void conf(struct ctx *c, int argc, char **argv) > !IN6_IS_ADDR_LOOPBACK(&c->ip6.guest_gw)) { > if (c->mode =3D=3D MODE_PASTA) > c->ip6.no_copy_routes =3D true; > + c->ip6.guest_gw_from_ns =3D true; > break; > } > =20 > @@ -1900,6 +1901,7 @@ void conf(struct ctx *c, int argc, char **argv) > !IN4_IS_ADDR_LOOPBACK(&c->ip4.guest_gw)) { > if (c->mode =3D=3D MODE_PASTA) > c->ip4.no_copy_routes =3D true; > + c->ip4.guest_gw_from_ns =3D true; > break; > } > =20 > diff --git a/netlink.c b/netlink.c > index d049239..de04fb7 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -490,6 +490,9 @@ static void nl_linkaddr_host_msg_read(struct ctx *c, = const struct nlmsghdr *nh) > if (rtm->rtm_family =3D=3D AF_INET) { > char buf[INET_ADDRSTRLEN]; > =20 > + if (c->ip4.guest_gw_from_ns) > + return; > + > if (!is_new) { > c->ip4.guest_gw =3D (struct in_addr){ 0 }; > c->ip4.our_tap_addr =3D (struct in_addr){ 0 }; > @@ -503,6 +506,9 @@ static void nl_linkaddr_host_msg_read(struct ctx *c, = const struct nlmsghdr *nh) > } else if (rtm->rtm_family =3D=3D AF_INET6) { > char buf[INET6_ADDRSTRLEN]; > =20 > + if (c->ip6.guest_gw_from_ns) > + return; > + > if (!is_new) { > c->ip6.guest_gw =3D (struct in6_addr){ 0 }; > return; > @@ -658,15 +664,20 @@ static void nl_linkaddr_msg_read(struct ctx *c, con= st struct nlmsghdr *nh) > if (is_new) { > c->ip4.guest_gw =3D *(struct in_addr *)gw; > c->ip4.our_tap_addr =3D c->ip4.guest_gw; > + c->ip4.guest_gw_from_ns =3D true; > } else { > c->ip4.guest_gw =3D (struct in_addr){ 0 }; > c->ip4.our_tap_addr =3D (struct in_addr){ 0 }; > + c->ip4.guest_gw_from_ns =3D false; > } > } else if (rtm->rtm_family =3D=3D AF_INET6) { > - if (is_new) > + if (is_new) { > c->ip6.guest_gw =3D *(struct in6_addr *)gw; > - else > + c->ip6.guest_gw_from_ns =3D true; > + } else { > c->ip6.guest_gw =3D (struct in6_addr){ 0 }; > + c->ip6.guest_gw_from_ns =3D false; > + } > } > } > } > diff --git a/passt.h b/passt.h > index 70ccaf1..5e7bc99 100644 > --- a/passt.h > +++ b/passt.h > @@ -82,6 +82,7 @@ enum passt_modes { > * @ifname_out: Optional interface name to bind outbound sockets to > * @no_copy_routes: Don't copy all routes when configuring target namesp= ace > * @no_copy_addrs: Don't copy all addresses when configuring namespace > + * @guest_gw_from_ns: Gateway was set from namespace (config or ns event) > */ > struct ip4_ctx { > /* PIF_TAP addresses */ > @@ -104,6 +105,7 @@ struct ip4_ctx { > =20 > bool no_copy_routes; > bool no_copy_addrs; > + bool guest_gw_from_ns; > }; > =20 > /** > @@ -125,6 +127,7 @@ struct ip4_ctx { > * @ifname_out: Optional interface name to bind outbound sockets to > * @no_copy_routes: Don't copy all routes when configuring target namesp= ace > * @no_copy_addrs: Don't copy all addresses when configuring namespace > + * @guest_gw_from_ns: Gateway was set from namespace (config or ns event) > */ > struct ip6_ctx { > /* PIF_TAP addresses */ > @@ -148,6 +151,7 @@ struct ip6_ctx { > =20 > bool no_copy_routes; > bool no_copy_addrs; > + bool guest_gw_from_ns; > }; > =20 > #include > --=20 > 2.51.1 >=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 --drx2UOHNYQEtiIhu Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlDihkACgkQzQJF27ox 2GeJgxAAg+HN6Q554AOH0iwG7yCSTx4monBmW7vtm0kqhgFtxdMuB/2iAR9bj9jf OoegMJBHqc1JQFOHyo75oAmu0avc+A+f/AHG6ETZ9gssCss+nFyiazdRcfrafgn/ oM3icRcXrYs0Z/wL93zGBalo/3nc95ewuCFdmCJu+Mu79EuprTKnYxyKqrBL+fqU 2LGZ3v14DXJLN9MA01yNW6phSOd/Te4vIqOsJ/GUW8Im7MV946bF4cpBVGsKF6cO Vpnot+7n6bEIbqvtm0Grf7Euj9j7CdTqVWUi6wmx89vAZ8Ex1XuzjUAqzjAm9Z9x d1gL6BVLJ4WO4LfP35xJsw9xqnWjF8PsF4atbyTlCz0gwP6tDhE4iRBd+Is/MJ3J 4nq/jAP4EX3G7HlSD4mvVryPlaz68xTkltT6C7T+/9/9/tgX+4nX5/fq0JvrbtEs dfL400oW+Kj9kZmIDdFYdrBbc9MPupCDSGVqI64Rr/pQIztuJaw4ysrZiZn6Ho10 0vHjzb862kK0okw12turyrZMIulqiJa0rZUK5EdzMOIzNw1JqLnU4Ehcx1vejzJJ RMtIDebrcG5NeismpvFLf646nHLkJGrExq8LuLnv9FpwpYZ9sOKAjI08GynVzA2X SAyF+2e/8ccoQiqMsuDzvif6wqhoT/Roz8T2uKD1bqzLFqm0FMs= =LULy -----END PGP SIGNATURE----- --drx2UOHNYQEtiIhu--