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=l/VZiwOI; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id D0E6C5A0262 for ; Wed, 27 May 2026 06:40:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779856823; bh=YxuuIKA9ZeyZceC0W62EowTgyqcmvwh0tBC+s3cnrPw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l/VZiwOIxCgG1zOOhLQf5sQ9V+KLjyCZtm3WszsnBfnHmQ9nw0SFVOh59q/0amOlC r0bDA9mW7kslaOazQiWKF+lT0BSZZKt1siCofnSy6+WrUg5vIT/6LFosl9qCkHPfV2 GsQ0LDRTwGLB/ykEIKTmkYKvlIgB+KKYe+8urnh2yLZ9QtgB56yvyblDChp1VIsq+G r/i4T/6dJrQHYMcAksgtVAgC10I0Kp2Q+i5rsQzB6zLNG9YcaEmfWOj27JSB3jAhSx pAvp6VIQlf8hmhZTlIDTAJDbOFx8FSIuOeeoNfXhpCl7ATS5ZGBQgbRJJLrpF0J4tm 923tho3vRdR2w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQH3q5FLbz4wCH; Wed, 27 May 2026 14:40:23 +1000 (AEST) Date: Wed, 27 May 2026 14:30:31 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v7 11/13] dhcp: Select address for DHCP distribution Message-ID: References: <20260413005319.3295910-1-jmaloy@redhat.com> <20260413005319.3295910-12-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="X317RqUioIDQvF07" Content-Disposition: inline In-Reply-To: <20260413005319.3295910-12-jmaloy@redhat.com> Message-ID-Hash: 2UVXRF77A4TZF4GHBZLAXZS2KUU2CMX7 X-Message-ID-Hash: 2UVXRF77A4TZF4GHBZLAXZS2KUU2CMX7 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, 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: --X317RqUioIDQvF07 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Apr 12, 2026 at 08:53:17PM -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 >=20 > v7: -Modified DHCP advertisement eligibility criteria IPv4 addresses: > We now permit link local addresses to be eligible if they were > configured by the user. > -Adapted to previous changes in this series > --- > conf.c | 5 +++-- > dhcp.c | 14 +++++++++----- > fwd.c | 8 ++++++++ > migrate.c | 5 +++++ > passt.h | 1 + > 5 files changed, 26 insertions(+), 7 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 3cb3553..612df07 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" > @@ -1181,8 +1182,8 @@ 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) { > + a =3D fwd_get_addr(c, AF_INET, CONF_ADDR_DHCP, 0); > + if (a) { > uint32_t mask; > =20 > mask =3D IN4_MASK(inany_prefix_len(&a->addr, > diff --git a/dhcp.c b/dhcp.c > index f0fa212..0f98cfc 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 > /** > @@ -302,19 +304,18 @@ static void opt_set_dns_search(const struct ctx *c,= size_t max_len) > */ > int dhcp(const struct ctx *c, struct iov_tail *data) > { > + 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 ethhdr eh_storage; > struct iphdr iph_storage; > struct udphdr uh_storage; > + 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; > =20 > @@ -346,8 +347,11 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > m->op !=3D BOOTREQUEST) > return -1; > =20 > - a =3D fwd_get_addr(c, AF_INET, 0, 0); > - 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/fwd.c b/fwd.c > index b177be9..39e52c4 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -293,6 +293,14 @@ void fwd_set_addr(struct ctx *c, const union inany_a= ddr *addr, > return; > } > =20 > + /* Determine advertisement eligibility */ > + if (inany_v4(addr)) { > + if ((flags & CONF_ADDR_USER) || > + (flags & CONF_ADDR_HOST && !(flags & CONF_ADDR_LINKLOCAL))) > + if (!c->no_dhcp) Nit: the !no_dhcp test can become part of the outermost if. > + 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 93f67ae..afdc8b4 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 - Migration format for a single address entry > @@ -83,6 +84,8 @@ static uint8_t flags_to_migration(uint8_t flags) > migration |=3D MIGRATE_ADDR_LINKLOCAL; > if (flags & CONF_ADDR_OBSERVED) > migration |=3D MIGRATE_ADDR_OBSERVED; > + if (flags & CONF_ADDR_DHCP) > + migration |=3D MIGRATE_ADDR_DHCP; > =20 > return migration; > } > @@ -105,6 +108,8 @@ static uint8_t flags_from_migration(uint8_t migration) > flags |=3D CONF_ADDR_LINKLOCAL; > if (migration & MIGRATE_ADDR_OBSERVED) > flags |=3D CONF_ADDR_OBSERVED; > + if (migration & MIGRATE_ADDR_DHCP) > + flags |=3D CONF_ADDR_DHCP; This is a change to the migration protocol, although not exactly a breaking change to it. You can avoid the question my moving this patch before the one that introduces v3 migration. > =20 > return flags; > } > diff --git a/passt.h b/passt.h > index 3ef84eb..9508c2a 100644 > --- a/passt.h > +++ b/passt.h > @@ -83,6 +83,7 @@ struct guest_addr { > #define CONF_ADDR_GENERATED BIT(2) /* Generated by PASST/PASTA */ > #define CONF_ADDR_LINKLOCAL BIT(3) /* Link-local address */ > #define CONF_ADDR_OBSERVED BIT(4) /* Seen in guest traffic */ > +#define CONF_ADDR_DHCP BIT(5) /* Advertise via DHCP (IPv4) */ > }; > =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 --X317RqUioIDQvF07 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoWc2YACgkQzQJF27ox 2GceVg//ZBAmtVLd3njEJZ+0Pl/crXr5mcdTVmYsswHOEvCAQvixrQnLjWzlUJXE Oz5sRmju0MCR0P/5wo9enreN2vsmGBQkCmANd8vubkTNu0FhrjneVpYx4eFbgOuG cLSxoYKAKZIQcU70K2s72NOMz9qrPNASJeC5K6W1a/bwl5lBJjmIkcLebZkPfnl7 ea/dgsp9FPkFIxSC+o85862GsjYJxY8sDG1gHr8QIiCgBNHMrhxQVtQQkFU7iIuS X/ng+3uBT7hhkeR0MQmJPXboQBzaCYLmjnxgpcQwfswDONbrFwA7Sb5hotCW22Qx Ylkmm0fDRpgxgnLq2jipq4bQJah4/g25M5ojUi2bGBDdgAzS8jzfKvU21PqLS8Nk /J5wyXElMDJGfSBUyZyldaw67x5RKemlRwneJXIeOnzneFd0gEgIdh+S4fFCZX17 hoQ9Kz7YDipmwpeT6G344/hUYE6rFkJn3JlJuuIHdxT1LR43MFDHj8pf51gJSKuQ MYEv6ArWVfVbgnt4UeTRz7pON5A6VUkrByLvQZpuppQWlni9xwqAwW6bbskcbRRy ony1Cv9lkvZFFXaZBqK3rXvcN3zc06dWIEQIY9SYkigtx6eroegOvktr6inRlgTh GnNaqFYRJyYQyHfvA+WWLJkMytLJGyrfceUku8OrO6CpY2HeRX8= =CUu4 -----END PGP SIGNATURE----- --X317RqUioIDQvF07--