public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v2 17/27] sdn: microseg: add tag matcher
Date: Thu,  9 Jul 2026 11:18:42 +0200	[thread overview]
Message-ID: <20260709091852.538885-18-h.laimer@proxmox.com> (raw)
In-Reply-To: <20260709091852.538885-1-h.laimer@proxmox.com>

A second NIC-to-group assignment matcher next to the guest matcher: a
'tagassignment' type binding every guest matching the given tags, with
tags and tag_match properties gated to it, and the guest inventory
extended to report each guest's tags.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/PVE/API2/Network/SDN/Microseg.pm |  2 +-
 src/PVE/Network/SDN/Microseg.pm      | 42 ++++++++++++++++++++++------
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/src/PVE/API2/Network/SDN/Microseg.pm b/src/PVE/API2/Network/SDN/Microseg.pm
index c88b5f1..fc1e4ac 100644
--- a/src/PVE/API2/Network/SDN/Microseg.pm
+++ b/src/PVE/API2/Network/SDN/Microseg.pm
@@ -97,7 +97,7 @@ __PACKAGE__->register_method({
                         id => { type => 'string', description => 'Object identifier.' },
                         type => {
                             type => 'string',
-                            enum => ['group', 'rule', 'guestassignment'],
+                            enum => ['group', 'rule', 'guestassignment', 'tagassignment'],
                         },
                         state => get_standard_option('pve-sdn-config-state'),
                         pending => {
diff --git a/src/PVE/Network/SDN/Microseg.pm b/src/PVE/Network/SDN/Microseg.pm
index 4f135c6..f000ce6 100644
--- a/src/PVE/Network/SDN/Microseg.pm
+++ b/src/PVE/Network/SDN/Microseg.pm
@@ -39,7 +39,7 @@ cfs_register_file('sdn/microseg.cfg', \&parse_microseg_config, \&write_microseg_
 # The stored section types of the assignment family, one per matcher kind. The API presents them
 # under a single 'assignment' endpoint that discriminates on the 'type' property (storage splits
 # them so each section carries only its matcher's fields). Add a new matcher's stored type here.
-our $ASSIGNMENT_TYPES = ['guestassignment'];
+our $ASSIGNMENT_TYPES = ['guestassignment', 'tagassignment'];
 
 sub parse_microseg_config {
     my ($filename, $raw) = @_;
@@ -184,7 +184,8 @@ sub assignment_properties {
         $properties->{type} = {
             type => 'string',
             enum => $ASSIGNMENT_TYPES,
-            description => "The matcher kind: 'guestassignment' binds a specific guest.",
+            description => "The matcher kind: 'guestassignment' binds a specific guest,"
+                . " 'tagassignment' binds every guest carrying the matched tags.",
         };
         $properties->{vmid} = get_standard_option(
             'pve-vmid',
@@ -195,6 +196,27 @@ sub assignment_properties {
                 description => "Guest matcher: the guest whose NIC(s) to bind.",
             },
         );
+        $properties->{tags} = {
+            type => 'array',
+            items => {
+                type => 'string',
+                format => 'pve-tag',
+            },
+            optional => 1,
+            'type-property' => 'type',
+            'instance-types' => ['tagassignment'],
+            description => "Tag matcher: the guest tags to match.",
+        };
+        $properties->{tag_match} = {
+            type => 'string',
+            enum => ['any', 'all', 'exact'],
+            optional => 1,
+            default => 'any',
+            'type-property' => 'type',
+            'instance-types' => ['tagassignment'],
+            description => "How tags match: any (the guest shares a listed tag), all"
+                . " (the guest carries every listed tag), or exact (its tags equal the listed set).",
+        };
         $properties->{iface} = {
             type => 'integer',
             minimum => 0,
@@ -207,24 +229,28 @@ sub assignment_properties {
     return $properties;
 }
 
-# The guest inventory assignments are expanded against at render time: every guest and the netN
-# indices it currently has. Pulled cluster-wide from the pmxcfs in-memory index in a single call
-# (>100x faster than parsing each config). All guests are included, since a guest matcher with no
-# iface needs the guest's NIC list too. Returns an arrayref of { vmid, nics => [...] } for the Rust
-# render / realized expansion.
+# The guest inventory assignments are expanded against at render time: every guest, with its tags
+# and the netN indices it currently has. Pulled cluster-wide from the pmxcfs in-memory index in a
+# single call (faster than parsing each config). All guests are included (not just tagged
+# ones), since a guest matcher with no iface needs the guest's NIC list too. Returns an arrayref of
+# { vmid, tags => [...], nics => [...] } for the Rust render / realized expansion.
 sub guest_inventory {
-    my $props = [map { "net$_" } 0 .. 31];
+    my $props = ['tags', map { "net$_" } 0 .. 31];
     my $by_vmid = PVE::Cluster::get_guest_config_properties($props);
 
     my $inventory = [];
     for my $vmid (sort { $a <=> $b } keys %$by_vmid) {
         my $guest = $by_vmid->{$vmid};
 
+        my $tags_raw = $guest->{tags} // '';
+        my @tags = grep { length } split(/[;,\s]+/, $tags_raw);
+
         my @nics = grep { defined $guest->{"net$_"} } 0 .. 31;
 
         push @$inventory,
             {
                 vmid => $vmid + 0,
+                tags => \@tags,
                 nics => [map { $_ + 0 } @nics],
             };
     }
-- 
2.47.3





  parent reply	other threads:[~2026-07-09  9:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  9:18 SPAM: [RFC cluster/docs/ifupdown2/manager/network/proxmox{-ve-rs,-ebpf,-perl-rs} v2 00/27] sdn: add microsegmentation support Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ve-rs v2 01/27] ve-config: sdn: add microseg signature-identity engine Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ve-rs v2 02/27] ve-config: sdn: add microseg config types Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ve-rs v2 03/27] ve-config: sdn: microseg: add tag matcher Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ve-rs v2 04/27] ve-config: sdn: microseg: add name regex matcher Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ve-rs v2 05/27] ve-config: sdn: microseg: add carrier bridge section Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ebpf v2 06/27] agent: add userspace coordinator and stateless policy subsystem Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ebpf v2 07/27] bpf: add bridge subsystem Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-ebpf v2 08/27] debian: add packaging and boot-time oneshot unit Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-cluster v2 09/27] cfs: add 'sdn/microseg.cfg' to observed files Hannes Laimer
2026-07-09  9:18 ` [PATCH proxmox-perl-rs v2 10/27] pve-rs: sdn: add microseg config binding Hannes Laimer
2026-07-09  9:18 ` [PATCH ifupdown2 v2 11/27] d/patches: add support for VXLAN-GBP flag Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 12/27] sdn: microseg: add config, API and guest inventory Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 13/27] sdn: dry-run: surface pending microseg changes Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 14/27] sdn: zones: trigger microseg apply on tap_plug Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 15/27] sdn: zones: add vxlan-gbp option to vxlan and evpn zones Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 16/27] evpn: disable vxlan-learning on create if GBP is enabled Hannes Laimer
2026-07-09  9:18 ` Hannes Laimer [this message]
2026-07-09  9:18 ` [PATCH pve-network v2 18/27] sdn: microseg: add name regex matcher Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-network v2 19/27] sdn: microseg: add carrier bridge API Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 20/27] ui: sdn: add microsegmentation panel Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 21/27] ui: sdn: dry-run: show pending microseg diff Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 22/27] network: apply microseg state on reload Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 23/27] ui: sdn: zones: add vxlan-gbp checkbox to vxlan and evpn Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 24/27] ui: sdn: microseg: add tag matcher Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-manager v2 25/27] ui: sdn: microseg: add name regex matcher Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-docs v2 26/27] sdn: add microsegmentation section Hannes Laimer
2026-07-09  9:18 ` [PATCH pve-docs v2 27/27] sdn: add VXLAN-GBP flag to evpn/vxlan zone sections 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=20260709091852.538885-18-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal