From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox-perl-rs v4 18/45] pve-rs: sdn: microseg: bind the data plane
Date: Thu, 5 Nov 2026 12:12:57 +0100 [thread overview]
Message-ID: <20261105111324.706922-19-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261105111324.706922-1-h.laimer@proxmox.com>
Expose the policy lock to Perl, with the full apply of the running
config and the apply for one guest NIC at plug time as its methods.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
pve-rs/Cargo.toml | 2 +
pve-rs/Makefile | 2 +
pve-rs/debian/control | 1 +
pve-rs/src/bindings/sdn/microseg.rs | 108 ++++++++++++++++++++++++++++
4 files changed, 113 insertions(+)
diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index ecedb1ebe747..1b3e008323b1 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -38,6 +38,7 @@ proxmox-frr = { version = "0.6.0" }
proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] }
proxmox-http-error = "1"
proxmox-log = "1"
+proxmox-microseg = "0.1"
proxmox-network-types = "1.1.2"
proxmox-notify = { version = "2", features = ["pve-context", "legacy-matchers"] }
proxmox-oci = "0.2.2"
@@ -80,6 +81,7 @@ proxmox-wireguard = { version = "0.1.2" }
# proxmox-log = { path = "../../proxmox/proxmox-log" }
# proxmox-login = { path = "../../proxmox/proxmox-login" }
# proxmox-metrics = { path = "../../proxmox/proxmox-metrics" }
+# proxmox-microseg = { path = "../../proxmox-ve-rs/proxmox-microseg" }
# proxmox-network-api = { path = "../../proxmox/proxmox-network-api" }
# proxmox-network-types = { path = "../../proxmox/proxmox-network-types" }
# proxmox-notify = { path = "../../proxmox/proxmox-notify" }
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index df65dd994794..513cb29755db 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -35,6 +35,8 @@ PERLMOD_PACKAGES := \
PVE::RS::ResourceScheduling::Dynamic \
PVE::RS::SDN::Fabrics \
PVE::RS::SDN::Microseg \
+ PVE::RS::SDN::Microseg::ExclusiveLock \
+ PVE::RS::SDN::Microseg::SharedLock \
PVE::RS::SDN::PrefixLists \
PVE::RS::SDN::RouteMaps \
PVE::RS::SDN::WireGuard::PrivateKeys \
diff --git a/pve-rs/debian/control b/pve-rs/debian/control
index ad8611eb1b69..296fc7f05e42 100644
--- a/pve-rs/debian/control
+++ b/pve-rs/debian/control
@@ -26,6 +26,7 @@ Build-Depends: debhelper-compat (= 13),
librust-proxmox-http-1+default-dev (>= 1.0.2-~~),
librust-proxmox-http-error-1+default-dev,
librust-proxmox-log-1+default-dev,
+ librust-proxmox-microseg-0.1+default-dev,
librust-proxmox-network-types-1+default-dev (>= 1.1.2-~~),
librust-proxmox-notify-2+default-dev,
librust-proxmox-notify-2+legacy-matchers-dev,
diff --git a/pve-rs/src/bindings/sdn/microseg.rs b/pve-rs/src/bindings/sdn/microseg.rs
index a3a04b7dad1f..69173b3a662a 100644
--- a/pve-rs/src/bindings/sdn/microseg.rs
+++ b/pve-rs/src/bindings/sdn/microseg.rs
@@ -251,4 +251,112 @@ pub mod pve_rs_sdn_microseg {
pub fn delete(#[try_from_ref] this: &PerlMicrosegConfig, id: &str) -> Result<(), Error> {
change(this, |entries| microseg::api::delete(entries, id))
}
+
+ pub(super) fn running_config_from(
+ raw: Option<&[u8]>,
+ ) -> Result<Option<MicrosegRunningConfig>, Error> {
+ match raw {
+ // pmxcfs yields the empty string for a zero-length file and the Perl reader of the
+ // same file treats that as an empty config.
+ Some(raw) if !raw.is_empty() => std::str::from_utf8(raw)
+ .map_err(Error::from)
+ .and_then(proxmox_microseg::parse_running_config)
+ .context("parse /etc/pve/sdn/.running-config"),
+ _ => Ok(Some(MicrosegRunningConfig::default())),
+ }
+ }
+}
+
+#[perlmod::package(name = "PVE::RS::SDN::Microseg::SharedLock", lib = "pve_rs")]
+pub mod pve_rs_sdn_microseg_shared_lock {
+ //! The `PVE::RS::SDN::Microseg::SharedLock` package.
+ //!
+ //! The policy lock in shared mode. A plug takes it before reading the running config and the
+ //! guest, and holds it until the NIC is placed. Released when the object goes away.
+
+ use anyhow::Error;
+ use perlmod::Value;
+ use proxmox_microseg::SharedLock;
+ use proxmox_ve_config::sdn::microseg::GuestInfo;
+
+ use super::pve_rs_sdn_microseg::running_config_from;
+
+ pub struct PerlSharedLock {
+ lock: SharedLock,
+ }
+
+ perlmod::declare_magic!(Box<PerlSharedLock> : &PerlSharedLock as "PVE::RS::SDN::Microseg::SharedLock");
+
+ /// Class method: Take the lock. Fails when a full pass holds it past the lock timeout.
+ #[export]
+ pub fn new(#[raw] class: Value) -> Result<Value, Error> {
+ let lock = proxmox_microseg::lock_shared()?;
+ Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlSharedLock { lock })))
+ }
+
+ /// Method: Enforce the microseg policy on the guest NIC `iface`, `raw` as for the full pass.
+ /// Returns false for a running config without a microseg block. Fails where only a full pass
+ /// can place the NIC.
+ #[export]
+ pub fn apply_iface(
+ #[try_from_ref] this: &PerlSharedLock,
+ raw: Option<&[u8]>,
+ guest: GuestInfo,
+ iface: &str,
+ firewall_bridge: bool,
+ ) -> Result<bool, Error> {
+ let Some(cfg) = running_config_from(raw)? else {
+ return Ok(false);
+ };
+ proxmox_microseg::apply_iface(&this.lock, &cfg, &guest, iface, firewall_bridge)?;
+ Ok(true)
+ }
+}
+
+#[perlmod::package(name = "PVE::RS::SDN::Microseg::ExclusiveLock", lib = "pve_rs")]
+pub mod pve_rs_sdn_microseg_exclusive_lock {
+ //! The `PVE::RS::SDN::Microseg::ExclusiveLock` package.
+ //!
+ //! The policy lock in exclusive mode. A full pass takes it before reading the running config
+ //! and the inventory, and holds it until the node is synced. Released when the object goes
+ //! away.
+
+ use std::sync::Mutex;
+
+ use anyhow::Error;
+ use perlmod::Value;
+ use proxmox_microseg::ExclusiveLock;
+ use proxmox_ve_config::sdn::microseg::GuestInfo;
+
+ use super::pve_rs_sdn_microseg::running_config_from;
+
+ pub struct PerlExclusiveLock {
+ lock: Mutex<ExclusiveLock>,
+ }
+
+ perlmod::declare_magic!(Box<PerlExclusiveLock> : &PerlExclusiveLock as "PVE::RS::SDN::Microseg::ExclusiveLock");
+
+ /// Class method: Take the lock. Fails when plugs or a pass hold it past the lock timeout.
+ #[export]
+ pub fn new(#[raw] class: Value) -> Result<Value, Error> {
+ let lock = Mutex::new(proxmox_microseg::lock_exclusive()?);
+ Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(PerlExclusiveLock { lock })))
+ }
+
+ /// Method: Enforce the microseg policy on this whole node. `raw` is the content of
+ /// `/etc/pve/sdn/.running-config`, `undef` or empty before the first commit. Returns false
+ /// and leaves the node untouched for a running config without a microseg block.
+ #[export]
+ pub fn apply(
+ #[try_from_ref] this: &PerlExclusiveLock,
+ raw: Option<&[u8]>,
+ inventory: Vec<GuestInfo>,
+ ) -> Result<bool, Error> {
+ let Some(cfg) = running_config_from(raw)? else {
+ return Ok(false);
+ };
+ let mut lock = this.lock.lock().unwrap();
+ proxmox_microseg::apply(&mut lock, &cfg, &inventory)?;
+ Ok(true)
+ }
}
--
2.47.3
next prev parent reply other threads:[~2026-11-05 11:16 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 11:12 [PATCH access-control/cluster/container/docs/manager/network/proxmox{,-ve-rs,-perl-rs}/qemu-server v4 00/45] sdn: add microsegmentation support Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 01/45] ebpf: build: keep the build directory out of the BPF objects Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 02/45] ebpf: policy: add the enforcement subsystem for guest interfaces Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 03/45] ebpf: policy: add a check for non-first fragments Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 04/45] ve-config: firewall: add a constructor for sctp matches Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 05/45] ve-config: sdn: microseg: add identity allocation for group sets Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 06/45] ve-config: sdn: microseg: add config types Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 07/45] ve-config: sdn: microseg: add tag matcher Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 08/45] ve-config: sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 09/45] ve-config: sdn: microseg: narrow rules by protocol and ports Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 10/45] ve-config: sdn: microseg: add group hierarchy Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 11/45] ve-config: firewall: expose protocol, icmp type and code numbers Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 12/45] ve-config: sdn: microseg: add the desired state Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 13/45] microseg: add a crate that applies the policy to a node's guest NICs Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 14/45] microseg: add a rule option that matches non-first fragments Hannes Laimer
2026-11-05 11:12 ` [PATCH pve-cluster v4 15/45] cfs: add 'sdn/microseg.cfg' to observed files Hannes Laimer
2026-11-05 11:12 ` [PATCH pve-access-control v4 16/45] permissions: add ACL path for SDN microsegmentation Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 17/45] pve-rs: sdn: add microseg config binding Hannes Laimer
2026-11-05 11:12 ` Hannes Laimer [this message]
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 19/45] pve-rs: sdn: microseg: check the data plane limits on render Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 20/45] pve-rs: debian: fire the pve-microseg-update trigger on upgrade Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 21/45] sdn: zones: add vxlan-gbp option to vxlan and evpn zones Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 22/45] sdn: microseg: add config, API and guest inventory Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 23/45] sdn: dry-run: show pending microseg changes Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 24/45] sdn: microseg: enforce the policy on guest NICs Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 25/45] sdn: microseg: add tag matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 26/45] sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 27/45] sdn: microseg: add an update for a running NIC Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 28/45] sdn: microseg: expose protocol, port and macro rule options Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 29/45] sdn: microseg: allow nesting groups under a parent Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 30/45] sdn: microseg: expose the fragments rule option Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 31/45] network: apply the microseg policy on reload Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 32/45] pve-sdn-commit: apply the microseg policy at boot Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 33/45] ui: sdn: zones: add vxlan-gbp checkbox to vxlan and evpn Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 34/45] ui: sdn: add microsegmentation panel Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 35/45] ui: sdn: dry-run: show pending microseg diff Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 36/45] ui: sdn: microseg: add tag matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 37/45] ui: sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 38/45] ui: sdn: microseg: add narrowing to the rule form Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 39/45] ui: sdn: microseg: show and edit the group hierarchy Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 40/45] ui: sdn: microseg: add fragments option to the rule form Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 41/45] ui: sdn: microseg: add a guest tab with its groups and rules Hannes Laimer
2026-11-05 11:13 ` [PATCH qemu-server v4 42/45] network: update the microseg enforcement on a tag or name change Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-container v4 43/45] lxc: update the microseg enforcement on a tag or hostname change Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-docs v4 44/45] sdn: zones: document the VXLAN-GBP option Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-docs v4 45/45] sdn: add microsegmentation section 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=20261105111324.706922-19-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pve-devel@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.