From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 5F9481FF0E0 for ; Thu, 09 Jul 2026 11:22:18 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 18D9821477; Thu, 09 Jul 2026 11:20:07 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v2 14/27] sdn: zones: trigger microseg apply on tap_plug Date: Thu, 9 Jul 2026 11:18:39 +0200 Message-ID: <20260709091852.538885-15-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260709091852.538885-1-h.laimer@proxmox.com> References: <20260709091852.538885-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: 1783588742317 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.250 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) 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: NI3FTIAHVDZMAIMJD36DQR7UYYOHNQMR X-Message-ID-Hash: NI3FTIAHVDZMAIMJD36DQR7UYYOHNQMR 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: Attach enforcement when a guest NIC is plugged, before it is added to the bridge, so an assigned NIC never passes traffic unenforced. A failure to enforce fails the plug, and with it the guest start, instead of bringing the NIC up open. This adds the two agent invocation helpers to the microseg module: the per-interface one used here, and a full resync for the network reload path. Signed-off-by: Hannes Laimer --- src/PVE/Network/SDN/Microseg.pm | 33 +++++++++++++++++++++++++++++++++ src/PVE/Network/SDN/Zones.pm | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/src/PVE/Network/SDN/Microseg.pm b/src/PVE/Network/SDN/Microseg.pm index 82ee52d..4f135c6 100644 --- a/src/PVE/Network/SDN/Microseg.pm +++ b/src/PVE/Network/SDN/Microseg.pm @@ -422,4 +422,37 @@ sub list_objects { return $res; } +my $MICROSEG_AGENT = '/usr/libexec/proxmox/proxmox-ebpf'; + +sub apply_interface { + my ($iface) = @_; + + return if !-x $MICROSEG_AGENT; + + # An assigned NIC that cannot be enforced must not come up, so a non-zero exit fails the plug + # and the task that triggered it. Capture the agent's output and put it in the error so that + # task shows why, instead of a bare exit code. + my $output = ''; + my $collect = sub { $output .= "$_[0]\n" }; + eval { + PVE::Tools::run_command( + [$MICROSEG_AGENT, 'apply', $iface], + outfunc => $collect, + errfunc => $collect, + ); + }; + if (my $err = $@) { + chomp $output; + die "microseg: refusing to bring up '$iface' unenforced\n" + . ($output ne '' ? "$output\n" : "$err"); + } +} + +sub apply_all { + return if !-x $MICROSEG_AGENT; + + eval { PVE::Tools::run_command([$MICROSEG_AGENT, 'apply']); }; + warn "microseg: failed to apply running config: $@" if $@; +} + 1; diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm index 4c1468c..1af5e5c 100644 --- a/src/PVE/Network/SDN/Zones.pm +++ b/src/PVE/Network/SDN/Zones.pm @@ -10,6 +10,7 @@ use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); use PVE::Network; use PVE::Network::SDN::Vnets; +use PVE::Network::SDN::Microseg; use PVE::Network::SDN::Zones::VlanPlugin; use PVE::Network::SDN::Zones::QinQPlugin; use PVE::Network::SDN::Zones::VxlanPlugin; @@ -332,6 +333,8 @@ sub tap_plug { $opts->{learning} = 0 if $interfaces_config->{ifaces}->{$bridge} && $interfaces_config->{ifaces}->{$bridge}->{'bridge-disable-mac-learning'}; + # attach enforcement before bridging, so the NIC never passes traffic unenforced + PVE::Network::SDN::Microseg::apply_interface($iface); PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts); return; } @@ -343,6 +346,9 @@ sub tap_plug { if $plugin_config->{nodes} && !defined($plugin_config->{nodes}->{$nodename}); my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type}); + + # attach enforcement before bridging, so the NIC never passes traffic unenforced + PVE::Network::SDN::Microseg::apply_interface($iface); $plugin->tap_plug($plugin_config, $vnet, $tag, $iface, $bridge, $firewall, $trunks, $rate); } -- 2.47.3