From: Hannes Laimer <h.laimer@proxmox.com>
To: Stefan Hanreich <s.hanreich@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-perl-rs v3 03/17] pve-rs: sdn: add bindings for the eBPF DHCP responder
Date: Wed, 21 Oct 2026 09:32:55 +0200 [thread overview]
Message-ID: <8279a4bf-8c35-418f-b1e6-66a9522d17e0@proxmox.com> (raw)
In-Reply-To: <83ea64ef-6097-4f74-a824-bd0cfbdf8860@proxmox.com>
On 2026-10-20 15:10, Stefan Hanreich wrote:
> On 10/20/26 10:00 AM, Hannes Laimer wrote:
>> The responder answers with the records the caller hands in. The
>> caller has to build them under the responder's lock, or a full pass
>> could write older records over those a plug or record change built
>> later. So the lock is an object the caller takes before it builds the
>> records, and every call that hands in records is a method of that
>> lock.
>>
>> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
>> ---
>> pve-rs/Cargo.toml | 2 +
>> pve-rs/Makefile | 3 +
>> pve-rs/debian/control | 2 +
>> pve-rs/src/bindings/sdn/dhcp.rs | 229 ++++++++++++++++++++++++++++++++
>> pve-rs/src/bindings/sdn/mod.rs | 1 +
>> 5 files changed, 237 insertions(+)
>> create mode 100644 pve-rs/src/bindings/sdn/dhcp.rs
>>
>> diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
>> index 5ae9082..0adf00b 100644
>> --- a/pve-rs/Cargo.toml
>> +++ b/pve-rs/Cargo.toml
>> @@ -34,6 +34,7 @@ proxmox-apt = { version = "1.0.1", features = ["cache"] }
>> proxmox-apt-api-types = "3"
>> proxmox-base64 = "1"
>> proxmox-config-digest = "1"
>> +proxmox-ebpf = { version = "0.1", features = ["dhcp"] }
>> proxmox-frr = { version = "0.5.1" }
>> proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] }
>> proxmox-http-error = "1"
>> @@ -70,6 +71,7 @@ proxmox-wireguard = { version = "0.1.2" }
>> # proxmox-config-digest = { path = "../../proxmox/proxmox-config-digest" }
>> # proxmox-daemon = { path = "../../proxmox/proxmox-daemon" }
>> # proxmox-dns-api = { path = "../../proxmox/proxmox-dns-api" }
>> +# proxmox-ebpf = { path = "../../proxmox-ebpf" }
>> # proxmox-http-error = { path = "../../proxmox/proxmox-http-error" }
>> # proxmox-http = { path = "../../proxmox/proxmox-http" }
>> # proxmox-human-byte = { path = "../../proxmox/proxmox-human-byte" }
>> diff --git a/pve-rs/Makefile b/pve-rs/Makefile
>> index bb1cd2d..ebe8bd3 100644
>> --- a/pve-rs/Makefile
>> +++ b/pve-rs/Makefile
>> @@ -32,6 +32,9 @@ PERLMOD_PACKAGES := \
>> PVE::RS::OpenId \
>> PVE::RS::ResourceScheduling::Static \
>> PVE::RS::ResourceScheduling::Dynamic \
>> + PVE::RS::SDN::Dhcp \
>> + PVE::RS::SDN::Dhcp::ExclusiveLock \
>> + PVE::RS::SDN::Dhcp::SharedLock \
>> PVE::RS::SDN::Fabrics \
>> PVE::RS::SDN::PrefixLists \
>> PVE::RS::SDN::RouteMaps \
>> diff --git a/pve-rs/debian/control b/pve-rs/debian/control
>> index 70367dc..521d966 100644
>> --- a/pve-rs/debian/control
>> +++ b/pve-rs/debian/control
>> @@ -20,6 +20,8 @@ Build-Depends: debhelper-compat (= 13),
>> librust-proxmox-apt-api-types-3+default-dev (>= 3.0.0-~~),
>> librust-proxmox-base64-1+default-dev,
>> librust-proxmox-config-digest-1+default-dev,
>> + librust-proxmox-ebpf-0.1+default-dev,
>> + librust-proxmox-ebpf-0.1+dhcp-dev,
>> librust-proxmox-frr-0.5+default-dev (>= 0.5.1-~~),
>> librust-proxmox-http-1+client-sync-dev (>= 1.0.2-~~),
>> librust-proxmox-http-1+client-trait-dev (>= 1.0.2-~~),
>> diff --git a/pve-rs/src/bindings/sdn/dhcp.rs b/pve-rs/src/bindings/sdn/dhcp.rs
>> new file mode 100644
>> index 0000000..a6cdc95
>> --- /dev/null
>> +++ b/pve-rs/src/bindings/sdn/dhcp.rs
>> @@ -0,0 +1,229 @@
>> +#[perlmod::package(name = "PVE::RS::SDN::Dhcp", lib = "pve_rs")]
>> +pub mod pve_rs_sdn_dhcp {
>> + //! The `PVE::RS::SDN::Dhcp` package.
>> + //!
>> + //! Bindings for the per-tap eBPF DHCP responder. Interfaces and the records they answer with
>> + //! are handed in here and served directly from the kernel. The calls that change the responder
>> + //! are methods of a lock object, so nothing writes to it without holding the lock in the mode
>> + //! the change needs.
>> +
>> + use std::net::Ipv4Addr;
>> +
>> + use anyhow::Error;
>> + use serde::{Deserialize, Deserializer};
>> +
>> + use proxmox_ebpf::dhcp::{DhcpSubsystem, Iface, Record, Unplugged};
>> +
>> + /// One interface's DHCP answer, the address and every option the reply carries.
>> + #[derive(Deserialize)]
>> + pub struct DhcpRecord {
>> + ip: Ipv4Addr,
>> + prefixlen: u8,
>> + server_id: Ipv4Addr,
>> + lease: u32,
>> + #[serde(default)]
>> + router: Option<Ipv4Addr>,
>> + #[serde(default)]
>> + dns: Option<Ipv4Addr>,
>> + #[serde(default)]
>> + mtu: Option<u16>,
>> + #[serde(deserialize_with = "mac_from_str")]
>> + mac: [u8; 6],
>
> proxmox-network-types has a MAC address type that would fit here if we add an as_slice() method
grrr, patch ordering in thunderbird..
but yes, like in 02/17 i'd rather not include another repo in this
series, id do a small follow up with the mac type change included
>
>> + }
>> +
>> + // a MAC as six hex pairs
>> + fn mac_from_str<'de, D: Deserializer<'de>>(d: D) -> Result<[u8; 6], D::Error> {
>> + let text = String::deserialize(d)?;
>> + let mut mac = [0u8; 6];
>> + let mut parts = text.split(':');
>> + for byte in &mut mac {
>> + let part = parts
>> + .next()
>> + .ok_or_else(|| serde::de::Error::custom(format!("MAC {text} is too short")))?;
>> + if part.len() != 2 || !part.bytes().all(|b| b.is_ascii_hexdigit()) {
>> + return Err(serde::de::Error::custom(format!("MAC {text} is malformed")));
>> + }
>> + *byte = u8::from_str_radix(part, 16)
>> + .map_err(|_| serde::de::Error::custom(format!("MAC {text} is malformed")))?;
>> + }
>> + if parts.next().is_some() {
>> + return Err(serde::de::Error::custom(format!("MAC {text} is too long")));
>> + }
>> + Ok(mac)
>> + }
>
> would become obsolete if using the MacAddr type
>
>> + /// One guest interface, the vnet it sits on if any, whether the responder runs on it and what
>> + /// it answers there.
>> + #[derive(Deserialize)]
>> + pub struct DhcpIface {
>> + name: String,
>> + #[serde(default)]
>> + vnet: Option<String>,
>> + serve: bool,
>> + #[serde(default)]
>> + record: Option<DhcpRecord>,
>> + }
>> +
>> + /// Where an unplugged interface went, the vnet it sits on now, none for a plain bridge.
>> + #[derive(Deserialize)]
>> + pub struct DhcpTarget {
>> + #[serde(default)]
>> + vnet: Option<String>,
>> + }
>> +
>> + impl From<DhcpRecord> for Record {
>> + fn from(r: DhcpRecord) -> Self {
>> + Record {
>> + ip: r.ip,
>> + prefixlen: r.prefixlen,
>> + server_id: r.server_id,
>> + lease: r.lease,
>> + router: r.router,
>> + dns: r.dns,
>> + mtu: r.mtu,
>> + mac: r.mac,
>> + }
>> + }
>> + }
>> +
>> + impl From<DhcpIface> for Iface {
>> + fn from(i: DhcpIface) -> Self {
>> + Iface {
>> + name: i.name,
>> + vnet: i.vnet,
>> + serve: i.serve,
>> + record: i.record.map(Record::from),
>> + }
>> + }
>> + }
>> +
>> + pub(super) fn to_ifaces(ifaces: Vec<DhcpIface>) -> Vec<Iface> {
>> + ifaces.into_iter().map(Iface::from).collect()
>> + }
>> +
>> + /// A tap unplug. Without a target the interface is gone or going and takes its record with
>> + /// it. With one it was plugged onto a bridge the responder does not serve and keeps a marker
>> + /// naming that place.
>> + #[export]
>> + pub fn detach(iface: &str, target: Option<DhcpTarget>) -> Result<(), Error> {
>> + let unplugged = match target {
>> + None => Unplugged::Gone,
>> + Some(target) => Unplugged::MovedTo(target.vnet),
>> + };
>> + DhcpSubsystem::new().detach(iface, unplugged)
>> + }
>> +}
>> +
>> +#[perlmod::package(name = "PVE::RS::SDN::Dhcp::SharedLock", lib = "pve_rs")]
>> +pub mod pve_rs_sdn_dhcp_shared_lock {
>> + //! The `PVE::RS::SDN::Dhcp::SharedLock` package.
>> + //!
>> + //! The responder's lock taken shared, what a tap plug and a guest's own record change hold.
>> + //! Released when the object goes away.
>> +
>> + use anyhow::Error;
>> + use perlmod::Value;
>> +
>> + use proxmox_ebpf::dhcp::{DhcpSubsystem, Iface, Outcome, Record, SharedLock};
>> +
>> + use super::pve_rs_sdn_dhcp::{DhcpIface, DhcpRecord, to_ifaces};
>> +
>> + /// The lock as Perl holds it.
>> + pub struct PerlSharedLock {
>> + lock: SharedLock,
>> + }
>> +
>> + perlmod::declare_magic!(Box<PerlSharedLock> : &PerlSharedLock as "PVE::RS::SDN::Dhcp::SharedLock");
>> +
>> + /// Class method: take the lock. Plugs hold it next to each other and wait only behind a full
>> + /// pass or a record change.
>> + #[export]
>> + pub fn new(#[raw] class: Value) -> Result<Value, Error> {
>> + let lock = DhcpSubsystem::new().lock_shared()?;
>> + Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlSharedLock { lock })))
>> + }
>> +
>> + /// Method: a tap plug onto a vnet with the record it answers. Without a record the interface
>> + /// gets no answer. Returns false when nothing is loaded yet. An interface gone already counts
>> + /// as done.
>> + #[export]
>> + pub fn attach(
>> + #[try_from_ref] this: &PerlSharedLock,
>> + iface: String,
>> + vnet: String,
>> + record: Option<DhcpRecord>,
>> + ) -> Result<bool, Error> {
>> + let iface = Iface {
>> + name: iface,
>> + vnet: Some(vnet),
>> + serve: true,
>> + record: record.map(Record::from),
>> + };
>> + Ok(this.lock.attach(&iface)? == Outcome::Done)
>> + }
>> +
>> + /// Method: a record change for the listed interfaces by a caller holding the guest lock.
>> + /// Returns false when nothing is loaded to write into, so a full pass is due.
>> + #[export]
>> + pub fn update(
>> + #[try_from_ref] this: &PerlSharedLock,
>> + ifaces: Vec<DhcpIface>,
>> + ) -> Result<bool, Error> {
>> + Ok(this.lock.update(&to_ifaces(ifaces))? == Outcome::Done)
>> + }
>> +}
>> +
>> +#[perlmod::package(name = "PVE::RS::SDN::Dhcp::ExclusiveLock", lib = "pve_rs")]
>> +pub mod pve_rs_sdn_dhcp_exclusive_lock {
>> + //! The `PVE::RS::SDN::Dhcp::ExclusiveLock` package.
>> + //!
>> + //! The responder's lock taken exclusively, what a full pass and a record change hold. Released
>> + //! when the object goes away.
>> +
>> + use anyhow::Error;
>> + use perlmod::Value;
>> +
>> + use proxmox_ebpf::dhcp::{DhcpSubsystem, ExclusiveLock, Outcome};
>> +
>> + use super::pve_rs_sdn_dhcp::{DhcpIface, to_ifaces};
>> +
>> + /// The lock as Perl holds it.
>> + pub struct PerlExclusiveLock {
>> + lock: ExclusiveLock,
>> + }
>> +
>> + perlmod::declare_magic!(Box<PerlExclusiveLock> : &PerlExclusiveLock as "PVE::RS::SDN::Dhcp::ExclusiveLock");
>> +
>> + /// Class method: take the lock, waiting out every plug in flight.
>> + #[export]
>> + pub fn new(#[raw] class: Value) -> Result<Value, Error> {
>> + let lock = DhcpSubsystem::new().lock_exclusive()?;
>> + Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlExclusiveLock { lock })))
>> + }
>> +
>> + /// Method: the full pass over every guest interface of the cluster. Those found here get
>> + /// their entry and a link where served.
>> + #[export]
>> + pub fn apply(
>> + #[try_from_ref] this: &PerlExclusiveLock,
>> + ifaces: Vec<DhcpIface>,
>> + ) -> Result<(), Error> {
>> + this.lock.apply(&to_ifaces(ifaces))
>> + }
>> +
>> + /// Method: a record change for the listed interfaces. Those not found here are skipped.
>> + /// Returns false when nothing is loaded to write into, so a full pass is due.
>> + #[export]
>> + pub fn update(
>> + #[try_from_ref] this: &PerlExclusiveLock,
>> + ifaces: Vec<DhcpIface>,
>> + ) -> Result<bool, Error> {
>> + Ok(this.lock.update(&to_ifaces(ifaces))? == Outcome::Done)
>> + }
>> +
>> + /// Method: detach the responder everywhere and drop its pinned state.
>> + #[export]
>> + pub fn clear(#[try_from_ref] this: &PerlExclusiveLock) -> Result<(), Error> {
>> + this.lock.clear()
>> + }
>> +}
>> diff --git a/pve-rs/src/bindings/sdn/mod.rs b/pve-rs/src/bindings/sdn/mod.rs
>> index dcae046..4b99b8f 100644
>> --- a/pve-rs/src/bindings/sdn/mod.rs
>> +++ b/pve-rs/src/bindings/sdn/mod.rs
>> @@ -1,3 +1,4 @@
>> +pub(crate) mod dhcp;
>> pub(crate) mod fabrics;
>> pub(crate) mod prefix_lists;
>> pub(crate) mod route_maps;
>
>
>
>
>
next prev parent reply other threads:[~2026-10-21 7:33 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 7:59 [PATCH container/docs/manager/network/proxmox{-ebpf,-perl-rs}/qemu-server v3 00/17] sdn: implement DHCP for all zones using eBPF Hannes Laimer
2026-10-20 7:59 ` [PATCH proxmox-ebpf v3 01/17] dhcp: add the per-tap DHCPv4 responder program Hannes Laimer
2026-10-20 7:59 ` [PATCH proxmox-ebpf v3 02/17] dhcp: add the subsystem that loads the responder and keeps its records Hannes Laimer
2026-10-20 13:09 ` Stefan Hanreich
2026-10-21 7:09 ` Hannes Laimer
2026-10-20 7:59 ` [PATCH proxmox-perl-rs v3 03/17] pve-rs: sdn: add bindings for the eBPF DHCP responder Hannes Laimer
2026-10-20 13:10 ` Stefan Hanreich
2026-10-21 7:32 ` Hannes Laimer [this message]
2026-10-20 7:59 ` [PATCH pve-network v3 04/17] sdn: dhcp: replace a stale dnsmasq reservation instead of dropping it Hannes Laimer
2026-10-20 13:15 ` Stefan Hanreich
2026-10-20 7:59 ` [PATCH pve-network v3 05/17] sdn: dhcp: update reservations when ip mappings change Hannes Laimer
2026-10-20 13:42 ` Stefan Hanreich
2026-10-21 7:21 ` Hannes Laimer
2026-10-20 7:59 ` [PATCH pve-network v3 06/17] sdn: ipam: key the MAC cache by lower-case MAC, stop caching misses Hannes Laimer
2026-10-20 13:10 ` Stefan Hanreich
2026-10-21 6:17 ` Hannes Laimer
2026-10-20 7:59 ` [PATCH pve-network v3 07/17] sdn: dhcp: make the lease time configurable per subnet Hannes Laimer
2026-10-20 13:17 ` Stefan Hanreich
2026-10-20 7:59 ` [PATCH pve-network v3 08/17] sdn: dhcp: require a backend only if a zone on this node uses it Hannes Laimer
2026-10-20 13:17 ` Stefan Hanreich
2026-10-20 7:59 ` [PATCH pve-network v3 09/17] sdn: dhcp: add an eBPF backend answering on each guest interface Hannes Laimer
2026-10-20 13:10 ` Stefan Hanreich
2026-10-21 6:16 ` Hannes Laimer
2026-10-20 7:59 ` [PATCH pve-network v3 10/17] sdn: zones: report interface plugs and unplugs to the DHCP backends Hannes Laimer
2026-10-20 13:17 ` Stefan Hanreich
2026-10-20 7:59 ` [PATCH pve-network v3 11/17] sdn: dhcp: push IP mapping edits to the guest's node Hannes Laimer
2026-10-20 13:09 ` Stefan Hanreich
2026-10-21 6:44 ` Hannes Laimer
2026-10-20 8:00 ` [PATCH pve-network v3 12/17] sdn: zones: allow the ebpf DHCP backend on every zone type Hannes Laimer
2026-10-20 8:00 ` [PATCH qemu-server v3 13/17] network: sdn: keep the DHCP backends current on guest NICs Hannes Laimer
2026-10-20 13:38 ` Stefan Hanreich
2026-10-20 8:00 ` [PATCH pve-container v3 14/17] net: report NIC plugs and removals to the SDN DHCP backends Hannes Laimer
2026-10-20 13:36 ` Stefan Hanreich
2026-10-21 7:29 ` Hannes Laimer
2026-10-20 8:00 ` [PATCH pve-manager v3 15/17] ui: sdn: add zone DHCP backend selector and subnet DHCP options Hannes Laimer
2026-10-20 13:19 ` Stefan Hanreich
2026-10-20 8:00 ` [PATCH pve-manager v3 16/17] sdn: bring up the DHCP backends at boot before the guests start Hannes Laimer
2026-10-20 13:21 ` Stefan Hanreich
2026-10-21 7:17 ` Hannes Laimer
2026-10-20 8:00 ` [PATCH pve-docs v3 17/17] sdn: dhcp: add eBPF backend section Hannes Laimer
2026-10-20 13:11 ` [PATCH container/docs/manager/network/proxmox{-ebpf,-perl-rs}/qemu-server v3 00/17] sdn: implement DHCP for all zones using eBPF Stefan Hanreich
2026-10-21 7:35 ` Hannes Laimer
2026-10-21 8:46 ` superseded: " Hannes Laimer
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=8279a4bf-8c35-418f-b1e6-66a9522d17e0@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=s.hanreich@proxmox.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox