From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VNPyxhH2; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id E59635A0619 for ; Thu, 02 Apr 2026 23:55:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775166937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CKCXC5A7mdOxqT5Lvgmf9Elktukf8vKs2OFcJCuzokQ=; b=VNPyxhH2423QTUIV3wJ2pEYudz/MpKX6Vi7JBhE1kgLT5BAdVC89U+HemHBEwZJTo8cVck HLLCr4B39PxCC/iDJH+eBz/zMtaX7mC8Vf5OFR+gfU4IIGQdvANx2WOWzvIQQvT6bHlf14 EfgnyTHxpZ2G5JaTDL4NXztTLMwdUI0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-V5ekBCkwO76NpgGdV9y8UQ-1; Thu, 02 Apr 2026 17:55:36 -0400 X-MC-Unique: V5ekBCkwO76NpgGdV9y8UQ-1 X-Mimecast-MFC-AGG-ID: V5ekBCkwO76NpgGdV9y8UQ_1775166935 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d177fb157so1261454f8f.0 for ; Thu, 02 Apr 2026 14:55:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775166935; x=1775771735; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CKCXC5A7mdOxqT5Lvgmf9Elktukf8vKs2OFcJCuzokQ=; b=SGluZEpGxFfWJeil46LxgVgTgbkkuENjzmRv45LzxPc8ap6iqK3HwG0HAqI//r6UeQ PNMmlMWiyV2UBoCv5JHZud03QeJn/NRLmXhYy8F74hLpYhPKQ6PgsIlt8NSHaJpsA//P UkSx8LRjCjEbJs2KLFb1VW+4rgbqc0Ixf2van/CWEKYajddzQBRGZmAXmKL4XiWkhSv4 I8bE3DJK4nI1WhmeEioTLo69D1kx12K2yXFXWJVIFwOhTDDn8b08/Q7+HqL1wHC9hSl+ WG/kmqslV5Youzrr/KRuye1QbPf7BvjU6cHlpHQ+gMUplt6PkZT/ELj6HlGF7omBQha/ kZPA== X-Forwarded-Encrypted: i=1; AJvYcCXRMjAAci6SlM7GpFZAbvXKjk8IKuI2NkE5pMem8p7p9yJUFd8iqzzbwiJ9/2mjafyk6H27bA3AgAI=@passt.top X-Gm-Message-State: AOJu0Yxgb+CbFq0c9+u2qd+1gmDY2PHE4H/xspoaOOWAhe5zHHqLTq72 V2NkqSYVIMyHsIVCAQHkxLI/brvekFhCuSrSeMzjuoFAjOFl/jKYArq5VyWceoyqSJCOfPZtl1l CH8s/8NeukCOqFHB82IyPw0tUg+waU/DOcSAft5MHstmpLyWX6eIaUg== X-Gm-Gg: ATEYQzzBu0eOaYNbNosl0DnHmB6m4Gcp6HO7tckWnVXC1Er4grUPOhOw7YriaOgYNKj 0k0WQQPa9gKGgVJVoZoEahxdZxo2Z1BRxvNtBdZLRdet5ziz6F+rHaXEww+4RYdRP0vK/GlGzkx /oyg5vjsnX0fFhQ7/0iOoEd1iTD8lH6KijyKr9NJ9m0W4FhFOem61VwmiTAx+29TU4lN0/E+coQ ziXeO6XRgX6MxJ0cMJUoQx8H30Uk/MOFq952TbbaguiHrkUYyvNdX35sPZ597R3EwIUTZRbRuII HHms8IqHzREF0YzWterfsbyUFAZNwyA9Oc9drkT3vtxINQLIoDkXerkGGWRnNyJ6nLnojNDX5+S aTyfSdkHs1a+FykX7K+vWElbPBNOsB9Yf X-Received: by 2002:a05:600c:818c:b0:488:7784:d06 with SMTP id 5b1f17b1804b1-488997dcc53mr8524135e9.31.1775166935440; Thu, 02 Apr 2026 14:55:35 -0700 (PDT) X-Received: by 2002:a05:600c:818c:b0:488:7784:d06 with SMTP id 5b1f17b1804b1-488997dcc53mr8523775e9.31.1775166934834; Thu, 02 Apr 2026 14:55:34 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4887e9630ddsm207124335e9.13.2026.04.02.14.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 14:55:34 -0700 (PDT) From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v6 11/13] dhcp: Select address for DHCP distribution Message-ID: <20260402235533.639a70d2@elisabeth> In-Reply-To: <20260322004333.365713-12-jmaloy@redhat.com> References: <20260322004333.365713-1-jmaloy@redhat.com> <20260322004333.365713-12-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Thu, 02 Apr 2026 23:55:34 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hX-x-Kx1vVIBJZ7BhKsAH9FfYu8mtTWTbmeTBPZuEUs_1775166935 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: RDK3DVB2ZPUKSGS2KL5YAFXFUJMPGB7X X-Message-ID-Hash: RDK3DVB2ZPUKSGS2KL5YAFXFUJMPGB7X X-MailFrom: sbrivio@redhat.com 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: david@gibson.dropbear.id.au, 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: On Sat, 21 Mar 2026 20:43:31 -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. > > We also let the conf_print() function use this flag to determine > and print the selected address. > > Signed-off-by: Jon Maloy > > --- > 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)) { I think that this kind of check / assignment shows that it might be convenient to have those as clearly separated input / output flags. Excluding IPv4 link-local addresses from DHCP assignment might make sense, even though RFC 3927 doesn't seem to imply anything with that regard (I haven't checked other references though). Still, I think it would be safer to keep them eligible for DHCP assignment because we might otherwise break setups relying on local mode (with a disconnected host) where the guest will only gain connectivity if a DHCP server is available. It looks otherwise harmless (even though maybe we should have a deeper look at normative references on the subject). > + 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 -- Stefano