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=UGqxRJSt; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 034FC5A026D for ; Wed, 25 Mar 2026 02:46:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774403174; bh=9i8MbsbqLFvS1uiany/mNZGNtNwAZZx8O1RhkHSbgtg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UGqxRJStRzugKvYuuszN7jb/V6TkQzjKdnUBnuwG2aj+X0BF+wIqDCqCXsgYkbr3S Ie5E00Cs5o+vSIhgAsuc1ekiTHPJRWdZE8rYoAYcAkP/2tYzFJX7oPduJ3gGqvSfY9 yI+AYWgCHiEhv7sGp9sNpT6EVFbxvvS1vsDusa01RnUMDAIG7G+2r7S5gk7nyPHMDp WJZOvHarKLmtPlCyfUwq73dBkz5nburhO3iDG8E5FMswhHctidMiv43KcUvWBrh12R fwTuMgsbQl0eskfxrbgbhd2JG5kGWmMs2bexuNrJ9eeSaSwi7FR4yXlILqwyo+FJC3 kscNCFtrLsk6g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fgV9y418bz4wQx; Wed, 25 Mar 2026 12:46:14 +1100 (AEDT) Date: Wed, 25 Mar 2026 12:26:48 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v6 11/13] dhcp: Select address for DHCP distribution Message-ID: References: <20260322004333.365713-1-jmaloy@redhat.com> <20260322004333.365713-12-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="KsgMsvwK2trdLH9M" Content-Disposition: inline In-Reply-To: <20260322004333.365713-12-jmaloy@redhat.com> Message-ID-Hash: F4MSCJAZ43ZITTE6UCQB3JNDC2NL5BPG X-Message-ID-Hash: F4MSCJAZ43ZITTE6UCQB3JNDC2NL5BPG 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: --KsgMsvwK2trdLH9M Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 21, 2026 at 08:43:31PM -0400, Jon Maloy wrote: > We introduce a CONF_ADDR_DHCP flag to mark if an added address is > eligible for DHCP advertisement. By doing this once and for all > in the fwd_set_addr() function, the DHCP code only needs to check > for this flag to know that all criteria for advertisement are > fulfilled. Hence, we update the code in dhcp.c correspondingly. >=20 > We also let the conf_print() function use this flag to determine > and print the selected address. >=20 > Signed-off-by: Jon Maloy >=20 > --- > v6: Split off from a commit handling both DHCP and DHCPv6 > --- > conf.c | 9 ++++----- > dhcp.c | 21 +++++++++++++-------- > dhcp.h | 2 +- > fwd.c | 9 +++++++++ > migrate.c | 5 +++++ > passt.h | 1 + > 6 files changed, 33 insertions(+), 14 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 320a9e4..512fa38 100644 > --- a/conf.c > +++ b/conf.c > @@ -46,6 +46,7 @@ > #include "lineread.h" > #include "isolation.h" > #include "log.h" > +#include "fwd.h" > #include "vhost_user.h" > =20 > #define NETNS_RUN_DIR "/run/netns" > @@ -1182,11 +1183,9 @@ static void conf_print(const struct ctx *c) > inet_ntop(AF_INET, &c->ip4.map_host_loopback, > buf, sizeof(buf))); > =20 > - a =3D fwd_get_addr(c, AF_INET, 0, 0); > - if (a && !c->no_dhcp) { > - uint32_t mask; > - > - mask =3D IN4_MASK(inany_prefix_len(a)); > + a =3D fwd_get_addr(c, AF_INET, CONF_ADDR_DHCP, 0); > + if (a) { > + uint32_t mask =3D IN4_MASK(inany_prefix_len(a)); > =20 > info("DHCP:"); > inany_ntop(&a->addr, buf, sizeof(buf)); > diff --git a/dhcp.c b/dhcp.c > index 6d9def5..cdb3afb 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -31,6 +31,8 @@ > #include "passt.h" > #include "tap.h" > #include "log.h" > +#include "fwd.h" > +#include "conf.h" > #include "dhcp.h" > =20 > /** > @@ -300,23 +302,22 @@ static void opt_set_dns_search(const struct ctx *c,= size_t max_len) > * > * Return: 0 if it's not a DHCP message, 1 if handled, -1 on failure > */ > -int dhcp(const struct ctx *c, struct iov_tail *data) > +int dhcp(struct ctx *c, struct iov_tail *data) I don't see why the const needs to be dropped. > { > - const struct guest_addr *a =3D fwd_get_addr(c, AF_INET, 0, 0); > + struct in_addr addr, mask, dst; > char macstr[ETH_ADDRSTRLEN]; > + const struct guest_addr *a; > size_t mlen, dlen, opt_len; > - struct in_addr mask, dst; > + struct udphdr uh_storage; > struct ethhdr eh_storage; > struct iphdr iph_storage; > - struct udphdr uh_storage; Re-ordering uh_storage seems an unrelated change. > + const struct udphdr *uh; > const struct ethhdr *eh; > const struct iphdr *iph; > - const struct udphdr *uh; > struct msg m_storage; > struct msg const *m; > - struct in_addr addr; > struct msg reply; > - unsigned int i; > + int i; As does this. > =20 > eh =3D IOV_REMOVE_HEADER(data, eh_storage); > iph =3D IOV_PEEK_HEADER(data, iph_storage); > @@ -346,7 +347,11 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > m->op !=3D BOOTREQUEST) > return -1; > =20 > - ASSERT(a); > + /* Select address to offer */ > + a =3D fwd_get_addr(c, AF_INET, CONF_ADDR_DHCP, 0); > + if (!a) > + return -1; > + > addr =3D *inany_v4(&a->addr); > =20 > reply.op =3D BOOTREPLY; > diff --git a/dhcp.h b/dhcp.h > index cd50c99..7326c7d 100644 > --- a/dhcp.h > +++ b/dhcp.h > @@ -6,7 +6,7 @@ > #ifndef DHCP_H > #define DHCP_H > =20 > -int dhcp(const struct ctx *c, struct iov_tail *data); > +int dhcp(struct ctx *c, struct iov_tail *data); > void dhcp_init(void); > =20 > #endif /* DHCP_H */ > diff --git a/fwd.c b/fwd.c > index b3f5dc0..e1c85dd 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -295,6 +295,15 @@ void fwd_set_addr(struct ctx *c, const union inany_a= ddr *addr, > return; > } > =20 > + /* Determine advertisement eligibility */ > + if ((flags & (CONF_ADDR_HOST | CONF_ADDR_USER)) && > + !(flags & CONF_ADDR_LINKLOCAL)) { > + if (inany_v4(addr)) { > + if (!c->no_dhcp) > + flags |=3D CONF_ADDR_DHCP; > + } > + } > + > /* Add to head or tail, depending on flag */ > if (flags & CONF_ADDR_OBSERVED) { > a =3D &arr[0]; > diff --git a/migrate.c b/migrate.c > index 7b9a2f6..1d1e0e6 100644 > --- a/migrate.c > +++ b/migrate.c > @@ -52,6 +52,7 @@ struct migrate_seen_addrs_v2 { > #define MIGRATE_ADDR_HOST BIT(1) > #define MIGRATE_ADDR_LINKLOCAL BIT(2) > #define MIGRATE_ADDR_OBSERVED BIT(3) > +#define MIGRATE_ADDR_DHCP BIT(4) > =20 > /** > * struct migrate_addr_v3 - Wire format for a single address entry > @@ -83,6 +84,8 @@ static uint8_t flags_to_wire(uint8_t flags) > wire |=3D MIGRATE_ADDR_LINKLOCAL; > if (flags & CONF_ADDR_OBSERVED) > wire |=3D MIGRATE_ADDR_OBSERVED; > + if (flags & CONF_ADDR_DHCP) > + wire |=3D MIGRATE_ADDR_DHCP; > =20 > return wire; > } > @@ -105,6 +108,8 @@ static uint8_t flags_from_wire(uint8_t wire) > flags |=3D CONF_ADDR_LINKLOCAL; > if (wire & MIGRATE_ADDR_OBSERVED) > flags |=3D CONF_ADDR_OBSERVED; > + if (wire & MIGRATE_ADDR_DHCP) > + flags |=3D CONF_ADDR_DHCP; > =20 > return flags; > } > diff --git a/passt.h b/passt.h > index db2f10d..5ea1715 100644 > --- a/passt.h > +++ b/passt.h > @@ -75,6 +75,7 @@ enum passt_modes { > #define CONF_ADDR_HOST BIT(1) /* From host interface */ > #define CONF_ADDR_LINKLOCAL BIT(2) /* Link-local address */ > #define CONF_ADDR_OBSERVED BIT(3) /* Seen in guest traffic */ > +#define CONF_ADDR_DHCP BIT(4) /* Advertise via DHCP (IPv4) */ > =20 > /** > * struct guest_addr - Unified IPv4/IPv6 address entry > --=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 --KsgMsvwK2trdLH9M Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnDOdcACgkQzQJF27ox 2GeKiQ//aXKAtv0VDrfa8LfeY5hqa2zybpVx1pp6+g+eiBPoYppujgCES2M+FgVC BEaREZtwsN4frlePUjE7Ov68rUYGFXoLZ0u6+ae4530k9bW9ggBbAeSMBUzkhkUJ RrHfO12CewG0rGpTRkrRzxs++UC9ZfRwthbsx46y+o7XBn8nhzNGdaZRDWpCpF8t 6jBboe2rANdLINV5JbkYgRjnciNiLfkZRqJXRGJdeXCYZUVKzBr/hLeNpRs4JCXA VdF64wjeUEIoIyteQGUDetuv6cWoxIMUw6wB7E5eJGtAnqxsEf3rrzHeuZGsaGXi R/nOJZhWJoOYq5qAs0xmaxI4VfEXtSL6XcHL0fxr8hYgKsEdY3NNAJzKlUtdiEBJ t2s2z+GuQ1JX6LeOUqLjbqVJpbpBheZyIJftvTLzqgtI2DYsf2AcnO4tCXzqgPh3 q3pBZ1SAHE/H11bfDvRLsdtV1Rl5JSg7w8R98NBrSc8A6OorNT0r+i28b5sU/X/c 9J0YVQxY1lagPWk5efpADjLxtolsn6InqHN4Pvjo9O21AJXsrjUAtW73kdgo3Olc lcy4cmAFRuHajsgrSYxjV/R2nQF8QVQOOEdqakX4XRAJD2oALcMgs0A1NffWk2lm F4M8d8prmmeWkuBZyqJY+7zdVOx68rNCKpkVGifYCzRunmZmz2Y= =wKvW -----END PGP SIGNATURE----- --KsgMsvwK2trdLH9M--