From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id BF6F01FF0A7 for ; Wed, 02 Sep 2026 14:48:01 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9C84D21500; Wed, 02 Sep 2026 14:47:47 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs 03/12] pve-rs: sdn: add dhcp responder bindings Date: Wed, 2 Sep 2026 14:47:30 +0200 Message-ID: <20260902124739.750853-4-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260902124739.750853-1-h.laimer@proxmox.com> References: <20260902124739.750853-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788353259576 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.699 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 6WYJYGKTPE7Y4N26QYHFRSIPB4SFZBLX X-Message-ID-Hash: 6WYJYGKTPE7Y4N26QYHFRSIPB4SFZBLX X-MailFrom: h.laimer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The records are handed straight to the responder subsystem of proxmox-ebpf, single mapping pushes upsert or drop one record and a sync does a full mark-and-sweep resync. Signed-off-by: Hannes Laimer --- pve-rs/Cargo.toml | 2 + pve-rs/Makefile | 1 + pve-rs/debian/control | 2 + pve-rs/src/bindings/sdn/dhcp.rs | 91 +++++++++++++++++++++++++++++++++ pve-rs/src/bindings/sdn/mod.rs | 1 + 5 files changed, 97 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..7609a1e 100644 --- a/pve-rs/Makefile +++ b/pve-rs/Makefile @@ -32,6 +32,7 @@ PERLMOD_PACKAGES := \ PVE::RS::OpenId \ PVE::RS::ResourceScheduling::Static \ PVE::RS::ResourceScheduling::Dynamic \ + PVE::RS::SDN::Dhcp \ 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..4bea98f --- /dev/null +++ b/pve-rs/src/bindings/sdn/dhcp.rs @@ -0,0 +1,91 @@ +#[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. Records handed in here are + //! answered directly from the kernel. + + use std::net::Ipv4Addr; + + use anyhow::{Context, Error, bail}; + use serde::Deserialize; + + use proxmox_ebpf::dhcp::{DhcpSubsystem, Record}; + + /// One MAC's DHCP answer, the address and every option the reply carries. + #[derive(Deserialize)] + pub struct DhcpRecord { + mac: String, + ip: Ipv4Addr, + prefixlen: u8, + server_id: Ipv4Addr, + lease: u32, + router: Option, + dns: Option, + mtu: Option, + } + + fn parse_mac(s: &str) -> Result<[u8; 6], Error> { + let mut addr = [0u8; 6]; + let mut n = 0; + for part in s.split(':') { + if n >= 6 || part.len() != 2 { + bail!("invalid MAC {s:?}"); + } + addr[n] = u8::from_str_radix(part, 16).with_context(|| format!("invalid MAC {s:?}"))?; + n += 1; + } + if n != 6 { + bail!("invalid MAC {s:?}"); + } + Ok(addr) + } + + fn to_records(records: Vec) -> Result, Error> { + records + .into_iter() + .map(|r| { + Ok(Record { + mac: parse_mac(&r.mac)?, + ip: r.ip, + prefixlen: r.prefixlen, + server_id: r.server_id, + lease: r.lease, + router: r.router, + dns: r.dns, + mtu: r.mtu, + }) + }) + .collect() + } + + /// Make sure the responder programs are current and drop link pins of departed interfaces. + #[export] + pub fn apply() -> Result<(), Error> { + DhcpSubsystem::new().apply() + } + + /// Attach the responder to a guest interface. + #[export] + pub fn attach(iface: &str) -> Result<(), Error> { + DhcpSubsystem::new().attach(iface) + } + + /// Upsert the given records. + #[export] + pub fn update(records: Vec) -> Result<(), Error> { + DhcpSubsystem::new().update(&to_records(records)?) + } + + /// Drop one MAC's record. + #[export] + pub fn remove(mac: &str) -> Result<(), Error> { + DhcpSubsystem::new().remove(parse_mac(mac)?) + } + + /// Replace the record set with the given one. + #[export] + pub fn sync(records: Vec) -> Result<(), Error> { + DhcpSubsystem::new().sync(&to_records(records)?) + } +} 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; -- 2.47.3