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 0CD591FF0E0 for ; Thu, 09 Jul 2026 15:29:17 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 69A97214F2; Thu, 09 Jul 2026 15:29:11 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-common 2/3] iproute2: add helper for getting bridge port mappings Date: Thu, 9 Jul 2026 15:28:54 +0200 Message-ID: <20260709132857.239615-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260709132857.239615-1-s.hanreich@proxmox.com> References: <20260709132857.239615-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783603736947 X-SPAM-LEVEL: Spam detection results: 0 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: DM6JNRZ4YGHRFPE5X74PVNZCJJMOIANJ X-Message-ID-Hash: DM6JNRZ4YGHRFPE5X74PVNZCJJMOIANJ X-MailFrom: s.hanreich@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: Add a new helper for getting all bridges and their enslaved ports. This is particularly useful for the SDN VLAN and QinQ zones, which require a list of all bridge ports for generating the configuration when they utilize a non-VLAN-aware bridge. With this function, SDN can pre-compute the list and then use it to lookup the bridge ports, instead of recalculating the list for every vnet. Signed-off-by: Stefan Hanreich --- src/PVE/IPRoute2.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/PVE/IPRoute2.pm b/src/PVE/IPRoute2.pm index ae837dc..cef0cbc 100644 --- a/src/PVE/IPRoute2.pm +++ b/src/PVE/IPRoute2.pm @@ -127,4 +127,28 @@ sub get_vlan_information() { return \%vlan_information; } +sub get_bridge_port_mapping($ip_links = undef) { + $ip_links = ip_link_details() if !defined($ip_links); + + my $mapping = {}; + + for my $iface_name (keys $ip_links->%*) { + my $ip_link = $ip_links->{$iface_name}; + next if !ip_link_is_bridge_member($ip_link); + + if (!defined($ip_link->{master})) { + # should never happen, but handle the case nonetheless + warn "found bridge_member without master"; + next; + } + + push($mapping->{$ip_link->{master}}->@*, $iface_name) + if ip_link_is_physical($ip_link) + || ip_link_is_vlan($ip_link) + || ip_link_is_bond($ip_link); + } + + return $mapping; +} + 1; -- 2.47.3