From: Jon Maloy <jmaloy@redhat.com>
To: sbrivio@redhat.com, dgibson@redhat.com,
david@gibson.dropbear.id.au, jmaloy@redhat.com,
passt-dev@passt.top
Subject: [PATCH v6 11/13] dhcp: Select address for DHCP distribution
Date: Sat, 21 Mar 2026 20:43:31 -0400 [thread overview]
Message-ID: <20260322004333.365713-12-jmaloy@redhat.com> (raw)
In-Reply-To: <20260322004333.365713-1-jmaloy@redhat.com>
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.
We also let the conf_print() function use this flag to determine
and print the selected address.
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
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(-)
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"
#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)));
- a = fwd_get_addr(c, AF_INET, 0, 0);
- if (a && !c->no_dhcp) {
- uint32_t mask;
-
- mask = IN4_MASK(inany_prefix_len(a));
+ a = fwd_get_addr(c, AF_INET, CONF_ADDR_DHCP, 0);
+ if (a) {
+ uint32_t mask = IN4_MASK(inany_prefix_len(a));
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"
/**
@@ -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)
{
- const struct guest_addr *a = 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;
+ 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;
eh = IOV_REMOVE_HEADER(data, eh_storage);
iph = IOV_PEEK_HEADER(data, iph_storage);
@@ -346,7 +347,11 @@ int dhcp(const struct ctx *c, struct iov_tail *data)
m->op != BOOTREQUEST)
return -1;
- ASSERT(a);
+ /* Select address to offer */
+ a = fwd_get_addr(c, AF_INET, CONF_ADDR_DHCP, 0);
+ if (!a)
+ return -1;
+
addr = *inany_v4(&a->addr);
reply.op = 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
-int dhcp(const struct ctx *c, struct iov_tail *data);
+int dhcp(struct ctx *c, struct iov_tail *data);
void dhcp_init(void);
#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_addr *addr,
return;
}
+ /* Determine advertisement eligibility */
+ if ((flags & (CONF_ADDR_HOST | CONF_ADDR_USER)) &&
+ !(flags & CONF_ADDR_LINKLOCAL)) {
+ if (inany_v4(addr)) {
+ if (!c->no_dhcp)
+ flags |= CONF_ADDR_DHCP;
+ }
+ }
+
/* Add to head or tail, depending on flag */
if (flags & CONF_ADDR_OBSERVED) {
a = &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)
/**
* 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 |= MIGRATE_ADDR_LINKLOCAL;
if (flags & CONF_ADDR_OBSERVED)
wire |= MIGRATE_ADDR_OBSERVED;
+ if (flags & CONF_ADDR_DHCP)
+ wire |= MIGRATE_ADDR_DHCP;
return wire;
}
@@ -105,6 +108,8 @@ static uint8_t flags_from_wire(uint8_t wire)
flags |= CONF_ADDR_LINKLOCAL;
if (wire & MIGRATE_ADDR_OBSERVED)
flags |= CONF_ADDR_OBSERVED;
+ if (wire & MIGRATE_ADDR_DHCP)
+ flags |= CONF_ADDR_DHCP;
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) */
/**
* struct guest_addr - Unified IPv4/IPv6 address entry
--
2.52.0
next prev parent reply other threads:[~2026-03-22 0:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-22 0:43 [PATCH v6 00/13] Introduce multiple addresses and late binding Jon Maloy
2026-03-22 0:43 ` [PATCH v6 01/13] conf: use a single buffer for print formatting in conf_print() Jon Maloy
2026-03-22 0:43 ` [PATCH v6 02/13] ip: Introduce unified multi-address data structures Jon Maloy
2026-03-22 0:43 ` [PATCH v6 03/13] fwd: Unify guest accessibility checks with unified address array Jon Maloy
2026-03-22 0:43 ` [PATCH v6 04/13] arp: Check all configured addresses in ARP filtering Jon Maloy
2026-03-22 0:43 ` [PATCH v6 05/13] conf: Allow multiple -a/--address options per address family Jon Maloy
2026-03-22 0:43 ` [PATCH v6 06/13] netlink, conf: Read all addresses from template interface at startup Jon Maloy
2026-03-22 0:43 ` [PATCH v6 07/13] ip: refactor function pasta_ns_conf() Jon Maloy
2026-03-22 0:43 ` [PATCH v6 08/13] ip: Track observed guest IPv4 addresses in unified address array Jon Maloy
2026-03-22 0:43 ` [PATCH v6 09/13] ip: Track observed guest IPv6 " Jon Maloy
2026-03-22 0:43 ` [PATCH v6 10/13] migrate: Update protocol to v3 for multi-address support Jon Maloy
2026-03-22 0:43 ` Jon Maloy [this message]
2026-03-22 0:43 ` [PATCH v6 12/13] dhcpv6: Select addresses for DHCPv6 distribution Jon Maloy
2026-03-22 0:43 ` [PATCH v6 13/13] ndp: Support advertising multiple prefixes in Router Advertisements Jon Maloy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260322004333.365713-12-jmaloy@redhat.com \
--to=jmaloy@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=dgibson@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).