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=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=CjiB+RT4; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 156895A026E for ; Thu, 15 Aug 2024 12:42:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1723718573; bh=KGzvXShnYiqIJGY2haAM4HdMw00JEuQmKq7xtgZ5g0M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CjiB+RT4zdt63NMd/wID31L9BcbJNgHla/DFC/Mqvp7hO41DxexXxZu9WrhLQ0udW iwvWRVU2A8xvTwkLNTkn3VdY8hE9xm8joUYL6ZBuUS8whvyHNcDqehEs5xq+RsUAZn 2b1cXPsxOU2no0cW+80LDPPRUnlR7e73a+InJsV48sT6xOkxn36KQ6d4/hmkAyLCQ9 zR9sDbweBiK74LFg8kxn98IMLPFIHUodZsuC8NcNEBnl6TQKi1Trw5QxAQcCUxAmgV JRJem18WxVAq0CwCT4ThVsbxr/CNJp9Z2GB3t7moX6xPWUUWV0drl5zfY97KjSFOxa SjSWat69k3/Kg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Wl1t50pVtz4x2J; Thu, 15 Aug 2024 20:42:53 +1000 (AEST) Date: Thu, 15 Aug 2024 20:41:41 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 5/7] netlink, pasta: Fetch link-local address from namespace interface once it's up Message-ID: References: <20240815083649.4188007-1-sbrivio@redhat.com> <20240815083649.4188007-6-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="w47lykdfugtn7lmc" Content-Disposition: inline In-Reply-To: <20240815083649.4188007-6-sbrivio@redhat.com> Message-ID-Hash: CGGP27YLBK3WHIXROZJM4VAUGZZLKJJC X-Message-ID-Hash: CGGP27YLBK3WHIXROZJM4VAUGZZLKJJC 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.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: --w47lykdfugtn7lmc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 15, 2024 at 10:36:47AM +0200, Stefano Brivio wrote: > As soon as we bring up the interface, the Linux kernel will set up a > link-local address for it, so we can fetch it and start using right > away, if we need a link-local address to communicate to the container > before we see any traffic coming from it. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > netlink.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > netlink.h | 1 + > pasta.c | 7 +++++++ > 3 files changed, 55 insertions(+) >=20 > diff --git a/netlink.c b/netlink.c > index 59f2fd9..06a3816 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -794,6 +794,53 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t= af, > return status; > } > =20 > +/** > + * nl_addr_get_ll() - Get first IPv6 link-local address for a given inte= rface > + * @s: Netlink socket > + * @ifi: Interface index in outer network namespace > + * @addr: Link-local address to fill > + * > + * Return: 0 on success, negative error code on failure > + */ > +int nl_addr_get_ll(int s, unsigned int ifi, struct in6_addr *addr) > +{ > + struct req_t { > + struct nlmsghdr nlh; > + struct ifaddrmsg ifa; > + } req =3D { > + .ifa.ifa_family =3D AF_INET6, > + .ifa.ifa_index =3D ifi, > + }; > + struct nlmsghdr *nh; > + bool found =3D false; > + char buf[NLBUFSIZ]; > + ssize_t status; > + uint32_t seq; > + > + seq =3D nl_send(s, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req)); > + nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWADDR) { > + struct ifaddrmsg *ifa =3D (struct ifaddrmsg *)NLMSG_DATA(nh); > + struct rtattr *rta; > + size_t na; > + > + if (ifa->ifa_index !=3D ifi || ifa->ifa_scope !=3D RT_SCOPE_LINK || > + found) > + continue; > + > + for (rta =3D IFA_RTA(ifa), na =3D IFA_PAYLOAD(nh); RTA_OK(rta, na); > + rta =3D RTA_NEXT(rta, na)) { > + if (rta->rta_type !=3D IFA_ADDRESS) > + continue; > + > + if (!found) { > + memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > + found =3D true; > + } > + } > + } > + return status; > +} > + > /** > * nl_add_set() - Set IP addresses for given interface and address family > * @s: Netlink socket > diff --git a/netlink.h b/netlink.h > index 66a44ad..b51e99c 100644 > --- a/netlink.h > +++ b/netlink.h > @@ -19,6 +19,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af, > void *addr, int *prefix_len, void *addr_l); > int nl_addr_set(int s, unsigned int ifi, sa_family_t af, > const void *addr, int prefix_len); > +int nl_addr_get_ll(int s, unsigned int ifi, struct in6_addr *addr); > int nl_addr_set_ll_nodad(int s, unsigned int ifi); > int nl_addr_dup(int s_src, unsigned int ifi_src, > int s_dst, unsigned int ifi_dst, sa_family_t af); > diff --git a/pasta.c b/pasta.c > index 17eed15..e8883bd 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -340,6 +340,13 @@ void pasta_ns_conf(struct ctx *c) > } > =20 > if (c->ifi6) { > + rc =3D nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, > + &c->ip6.addr_ll_seen); > + if (rc < 0) { > + warn("Can't get LL address from namespace: %s", > + strerror(-rc)); > + } > + > rc =3D nl_addr_set_ll_nodad(nl_sock_ns, c->pasta_ifi); > if (rc < 0) { > warn("Can't set nodad for LL in namespace: %s", --=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 --w47lykdfugtn7lmc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAma921gACgkQzQJF27ox 2GcG/xAAnOyBkZ+euoCKNTCNnEajtFaAUWJjCTiyS1SjRANBvoa8L1kVzItLjOBs d56o80cCF0FSMY9CLxsqzxR+wpoV3W0EEERofJ5KYGWP3371EGBaDMn8m38GyUE/ worXcrCVa4Is4SV7By0B652ll6JbcK11g2sHKRdvaX6K0I/iNyWoy2VcXkmJX4m+ rivsMxlyEQvlOcl/WcMW7LZtwenx1U4B/9741slHKA4+DMs43H8G9BeHo+u2pzGi u6ZTeLvxsGoYSJtK1P4k6Lk6fKItcvp7ri3RU4GKIMlP+H/IlJQR3KlCBoZdqPD6 2l0Z4QXbHQ/KrPqnXFl2FI+23FuCpTNdXhFSdA0cs6b12Gz+9IDh84CE0ckfmhV6 BEK5Qbc2zlQTeXv1xqNyGdfhUC3YKzokgk9d3aqKx9YzdsvJfURH2zQjFt6fgm1S 6sEqtOVqs26qVyI5z/3eG3XLA//sxKb9M9CBddsPuY/IdqMIA0NENLwJsNh4QzvL 1RBt31w+B+9Fc+0FyrNtBUloEggHZPp98t/UB7qqr5/11dK582rHb+AAjJMI2w2q znZPoT1yEwnuquGexNm+TlaRJghkDZA7EHBK/ZpYKjBjh2Xsp5zXubJR9emczTOZ VMdbppgBVQ4QyBcg6nfa2ZF2GT81qkviwisj4pCGSdKgGbVPgFA= =zUB4 -----END PGP SIGNATURE----- --w47lykdfugtn7lmc--