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=202602 header.b=RHlkmjde; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 9FB525A0262 for ; Tue, 10 Mar 2026 05:03:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1773115405; bh=luONssbbmNUJFNSBO1aCqnX8I3ToNjtmcRaIJwgXYY8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RHlkmjdew7sUaUPJmamgnyMnXKpqocb/BkDsm5QSGX1oklVN0763/uZkhlJLMqF4U asZRglJy4Kpco4u6cgszJXuokwpz3XGTrLPl1dWMxI2xp7E9ic51tRBttSHZD+dWJp 8c+rNFNMlJEJDpsf6565zrBhg3Ne3WjDbYucAIII4gvjnQ+tsiZig0v7xNBhEjCX0B Y4lMFbpTTYYHbMGP+BQ3aX4wtoaNW7jnkwyrdHuWGXIuD+CPlAolYGtR0Om66ZSf/l rrVfbjtXC1jRk9pl6i/fI0rx5HTebq3QSogTgdEMUQ/e5TNF/rzkx6c4GBEkU5wbSa qkdwj8feICLkA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fVKx90Zsbz4wHY; Tue, 10 Mar 2026 15:03:25 +1100 (AEDT) Date: Tue, 10 Mar 2026 15:03:20 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 12/13] ndp: Support advertising multiple prefixes in Router Advertisement Message-ID: References: <20260222174445.743845-1-jmaloy@redhat.com> <20260222174445.743845-13-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sDzUYiomOyBgUxEu" Content-Disposition: inline In-Reply-To: <20260222174445.743845-13-jmaloy@redhat.com> Message-ID-Hash: J3GQSMKGUZ5KCAE6MI5CEB5KFQJH3464 X-Message-ID-Hash: J3GQSMKGUZ5KCAE6MI5CEB5KFQJH3464 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: --sDzUYiomOyBgUxEu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 22, 2026 at 12:44:44PM -0500, Jon Maloy wrote: > We extend NDP to advertise all suitable IPv6 prefixes in Router > Advertisements, per RFC 4861. Observed and link-local addresses, > plus addresses with a prefix length !=3D 64, are excluded. >=20 > Signed-off-by: Jon Maloy > --- > ndp.c | 127 +++++++++++++++++++++++++++++++++++++++------------------- > 1 file changed, 85 insertions(+), 42 deletions(-) >=20 > diff --git a/ndp.c b/ndp.c > index ed8c6ae..cf64f3f 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -32,6 +32,8 @@ > #include "passt.h" > #include "tap.h" > #include "log.h" > +#include "fwd.h" > +#include "conf.h" > =20 > #define RT_LIFETIME 65535 > =20 > @@ -82,7 +84,7 @@ struct ndp_na { > } __attribute__((packed)); > =20 > /** > - * struct opt_prefix_info - Prefix Information option > + * struct opt_prefix_info - Prefix Information option header > * @header: Option header > * @prefix_len: The number of leading bits in the Prefix that are valid > * @prefix_flags: Flags associated with the prefix > @@ -99,6 +101,16 @@ struct opt_prefix_info { > uint32_t reserved; > } __attribute__((packed)); > =20 > +/** > + * struct ndp_prefix - Complete Prefix Information option with prefix > + * @info: Prefix Information option header > + * @prefix: IPv6 prefix > + */ > +struct ndp_prefix { > + struct opt_prefix_info info; > + struct in6_addr prefix; > +} __attribute__((__packed__)); > + > /** > * struct opt_mtu - Maximum transmission unit (MTU) option > * @header: Option header > @@ -140,27 +152,23 @@ struct opt_dnssl { > } __attribute__((packed)); > =20 > /** > - * struct ndp_ra - NDP Router Advertisement (RA) message > + * struct ndp_ra_hdr - NDP Router Advertisement fixed header > * @ih: ICMPv6 header > * @reachable: Reachability time, after confirmation (ms) > * @retrans: Time between retransmitted NS messages (ms) > - * @prefix_info: Prefix Information option > - * @prefix: IPv6 prefix > - * @mtu: MTU option > - * @source_ll: Target link-layer address > - * @var: Variable fields > */ > -struct ndp_ra { > +struct ndp_ra_hdr { > struct icmp6hdr ih; > uint32_t reachable; > uint32_t retrans; > - struct opt_prefix_info prefix_info; > - struct in6_addr prefix; > - struct opt_l2_addr source_ll; > +} __attribute__((__packed__)); > =20 > - unsigned char var[sizeof(struct opt_mtu) + sizeof(struct opt_rdnss) + > - sizeof(struct opt_dnssl)]; > -} __attribute__((packed, aligned(__alignof__(struct in6_addr)))); > +/* Maximum RA message size: header + prefixes + source_ll + mtu + rdnss = + dnssl */ > +#define NDP_RA_MAX_SIZE (sizeof(struct ndp_ra_hdr) + \ > + INANY_MAX_ADDRS * sizeof(struct ndp_prefix) + \ > + sizeof(struct opt_l2_addr) + \ > + sizeof(struct opt_mtu) + sizeof(struct opt_rdnss) + \ > + sizeof(struct opt_dnssl)) > =20 > /** > * struct ndp_ns - NDP Neighbor Solicitation (NS) message > @@ -231,6 +239,46 @@ void ndp_unsolicited_na(const struct ctx *c, const s= truct in6_addr *addr) > ndp_na(c, &in6addr_ll_all_nodes, addr); > } > =20 > +/** > + * ndp_prefix_fill() - Fill prefix options for all suitable addresses > + * @c: Execution context > + * @buf: Buffer to write prefix options into > + * > + * Fills buffer with Prefix Information options for all non-linklocal, > + * non-observed addresses with prefix_len =3D=3D 64 (required for SLAAC). > + * > + * Return: number of bytes written > + */ > +static size_t ndp_prefix_fill(const struct ctx *c, unsigned char *buf) > +{ > + int skip =3D CONF_ADDR_OBSERVED | CONF_ADDR_LINKLOCAL; > + const struct inany_addr_entry *e; > + struct ndp_prefix *p; > + size_t offset =3D 0; > + > + for_each_addr(e, c, AF_INET6) { > + if (e->flags & skip) Again, this will skip OBSERVED addresses that are also USER|HOST. > + continue; > + /* SLAAC requires /64 prefix */ > + if (e->prefix_len !=3D 64) > + continue; > + > + p =3D (struct ndp_prefix *)(buf + offset); > + p->info.header.type =3D OPT_PREFIX_INFO; > + p->info.header.len =3D 4; /* 4 * 8 =3D 32 bytes */ > + p->info.prefix_len =3D 64; > + p->info.prefix_flags =3D 0xc0; /* L, A flags */ > + p->info.valid_lifetime =3D ~0U; > + p->info.pref_lifetime =3D ~0U; > + p->info.reserved =3D 0; > + p->prefix =3D e->addr.a6; > + > + offset +=3D sizeof(struct ndp_prefix); > + } > + > + return offset; > +} > + > /** > * ndp_ra() - Send an NDP Router Advertisement (RA) message > * @c: Execution context > @@ -238,7 +286,15 @@ void ndp_unsolicited_na(const struct ctx *c, const s= truct in6_addr *addr) > */ > static void ndp_ra(const struct ctx *c, const struct in6_addr *dst) > { > - struct ndp_ra ra =3D { > + unsigned char buf[NDP_RA_MAX_SIZE] > + __attribute__((__aligned__(__alignof__(struct in6_addr)))); > + struct ndp_ra_hdr *hdr =3D (struct ndp_ra_hdr *)buf; > + struct opt_l2_addr *source_ll; > + unsigned char *ptr; > + size_t prefix_len; > + > + /* Build RA header */ > + *hdr =3D (struct ndp_ra_hdr){ > .ih =3D { > .icmp6_type =3D RA, > .icmp6_code =3D 0, > @@ -247,32 +303,22 @@ static void ndp_ra(const struct ctx *c, const struc= t in6_addr *dst) > .icmp6_rt_lifetime =3D htons_constant(RT_LIFETIME), > .icmp6_addrconf_managed =3D 1, > }, > - .prefix_info =3D { > - .header =3D { > - .type =3D OPT_PREFIX_INFO, > - .len =3D 4, > - }, > - .prefix_len =3D 64, > - .prefix_flags =3D 0xc0, /* prefix flags: L, A */ > - .valid_lifetime =3D ~0U, > - .pref_lifetime =3D ~0U, > - }, > - .prefix =3D IN6ADDR_ANY_INIT, > - .source_ll =3D { > - .header =3D { > - .type =3D OPT_SRC_L2_ADDR, > - .len =3D 1, > - }, > - }, > }; > - struct inany_addr_entry *e =3D first_v6(c); > - unsigned char *ptr =3D NULL; > - > - ASSERT(e); > =20 > - ra.prefix =3D e->addr.a6; > + /* Fill prefix options */ > + prefix_len =3D ndp_prefix_fill(c, buf + sizeof(struct ndp_ra_hdr)); > + if (prefix_len =3D=3D 0) { > + /* No suitable prefixes to advertise */ > + return; > + } > =20 > - ptr =3D &ra.var[0]; > + /* Add source link-layer address option */ > + ptr =3D buf + sizeof(struct ndp_ra_hdr) + prefix_len; Somewhat idiomatic trick you can use here is ptr =3D (char *)(hdr + 1) + prefix_len; > + source_ll =3D (struct opt_l2_addr *)ptr; > + source_ll->header.type =3D OPT_SRC_L2_ADDR; > + source_ll->header.len =3D 1; > + memcpy(source_ll->mac, c->our_tap_mac, ETH_ALEN); > + ptr +=3D sizeof(struct opt_l2_addr); > =20 > if (c->mtu) { > struct opt_mtu *mtu =3D (struct opt_mtu *)ptr; > @@ -346,10 +392,7 @@ static void ndp_ra(const struct ctx *c, const struct= in6_addr *dst) > } > } > =20 > - memcpy(&ra.source_ll.mac, c->our_tap_mac, ETH_ALEN); > - > - /* NOLINTNEXTLINE(clang-analyzer-security.PointerSub) */ > - ndp_send(c, dst, &ra, ptr - (unsigned char *)&ra); > + ndp_send(c, dst, buf, ptr - buf); > } > =20 > /** > --=20 > 2.52.0 >=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 --sDzUYiomOyBgUxEu Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmvmAcACgkQzQJF27ox 2GePLRAAoHeJrEDSpWNHmUq2FTCy8WvQzUtVIMk4wWidzFhpC31NOtKQXRRHl8/Z 66duUV/95iZSFSWswchYfdj6jHTzAWvlywQwSpI68EmL8rGoGF6RKEuQqeBiGw/B fA01iGxy7j3eFboJ/3VrGAJhVdcOETj/rQShybP11xyXY/g5euy/AWqtt7OzPfic mAYaLv8sl2DNCU7Q68EqH4B01YCNN9dfTmR+IA6QW1KUnJ0bl/AunVUARApLIvML tuZdM6kkg/U0MMq4+G285KnTPcnRkgFF62tknNQKziHnCG+Wolklrxk7Ni6IhGDM kJOYnklzsY7Q2kT9VWdyyXqSx0qmTTi9zBgBqvxNgAXCWlnQrxyW0Dx4dMMXa4+Z 1pRIBG4bjM94ihLcQ+q2oA04M24GjuiJlxUfDNk9kdkP99X7xXPdZN5LnfxC5zwi DSk7JQ37wgbHqcTRDugoukpyAZqtlclNlRfQ9tqT7K6yEPeiFHNhxtAfeQ0WCGVX T+Y6D2E7MMITUcyKRk1mfN8CAd4neAyUELN3txA5wVyGWvvdfvV8HXhJ28uedUdv z78fTVjGYORAqsM6rs6DsdoGsQ2QLXlWY44zc3RTDn/UO0XPJRHrLUP5TRGGAAmp m52uslMgoMQJLWLY7TjF9GVaM1vxdayVWmRZyYbzaDQANR11qf0= =vQyJ -----END PGP SIGNATURE----- --sDzUYiomOyBgUxEu--