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 021671FF09C for ; Mon, 19 Oct 2026 13:27:02 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C9FB021676; Mon, 19 Oct 2026 13:26:53 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-common v2 2/3] iproute2: add helper for getting bridge port mappings Date: Mon, 19 Oct 2026 13:26:35 +0200 Message-ID: <20261019112640.181849-3-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261019112640.181849-1-s.hanreich@proxmox.com> References: <20261019112640.181849-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: 1792409207966 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.444 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: Y244CUP5ZYYNAQVFAI5WQKIQOO7PYGSO X-Message-ID-Hash: Y244CUP5ZYYNAQVFAI5WQKIQOO7PYGSO 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 CC: Lukas Sichert , Gabriel Goller 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 Reviewed-by: Lukas Sichert Tested-by: Lukas Sichert Reviewed-by: Gabriel Goller Tested-by: Gabriel Goller --- src/PVE/IPRoute2.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/PVE/IPRoute2.pm b/src/PVE/IPRoute2.pm index ae837dc..1e440b8 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