From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network] sdn: zones: support IPv6 peers in local underlay selection
Date: Wed, 13 May 2026 19:51:22 +0200 [thread overview]
Message-ID: <20260513175122.447818-1-h.laimer@proxmox.com> (raw)
The local underlay selection only checked the IPv4 `address` key, so a
peer list of IPv6 addresses always returned undef and callers using an
IPv6 underlay could not locate the local node.
Check both address families so the selection works for IPv6 as well.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/PVE/Network/SDN/Zones/Plugin.pm | 70 +++++++++++++++++--
.../zones/vxlan/ipv6/expected_sdn_interfaces | 15 ++++
src/test/zones/vxlan/ipv6/interfaces | 7 ++
src/test/zones/vxlan/ipv6/sdn_config | 17 +++++
4 files changed, 102 insertions(+), 7 deletions(-)
create mode 100644 src/test/zones/vxlan/ipv6/expected_sdn_interfaces
create mode 100644 src/test/zones/vxlan/ipv6/interfaces
create mode 100644 src/test/zones/vxlan/ipv6/sdn_config
diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 5d858af..74a3384 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use PVE::Tools qw(run_command);
+use Net::IP qw(ip_get_version);
use PVE::IPRoute2;
use PVE::JSONSchema;
use PVE::Cluster;
@@ -267,6 +268,43 @@ sub del_bridge_fdb {
#helper
+sub normalize_ip {
+ my ($ip) = @_;
+
+ return undef if !defined($ip);
+ $ip =~ s!/.*$!!;
+ return $ip;
+}
+
+# Return 4 or 6 for the IP family of $address (with optional /prefix), or undef
+# if $address is not parseable. Net::IP::ip_get_version rejects strings with a
+# /prefix, so strip that first via normalize_ip.
+sub ip_family {
+ my ($address) = @_;
+
+ my $ip = normalize_ip($address);
+ return defined($ip) ? ip_get_version($ip) : undef;
+}
+
+sub get_iface_addresses {
+ my ($iface_cfg) = @_;
+
+ return () if !$iface_cfg;
+
+ my @addrs;
+ for my $key (qw(address address6)) {
+ my $val = $iface_cfg->{$key};
+ next if !defined($val);
+ if (ref($val) eq 'ARRAY') {
+ push @addrs, @$val;
+ } else {
+ push @addrs, $val;
+ }
+ }
+
+ return @addrs;
+}
+
sub get_local_route_ip {
my ($targetip) = @_;
@@ -291,21 +329,39 @@ sub get_local_route_ip {
sub find_local_ip_interface_peers {
my ($peers, $iface) = @_;
+ $peers //= [];
+
my $network_config = PVE::INotify::read_file('interfaces');
my $ifaces = $network_config->{ifaces};
#if iface is defined, return ip if exist (if not,try to find it on other ifaces)
if ($iface) {
- my $ip = $ifaces->{$iface}->{address};
- return ($ip, $iface) if $ip;
+ my @iface_addrs = get_iface_addresses($ifaces->{$iface});
+ if (!@$peers && @iface_addrs) {
+ my $ip = normalize_ip($iface_addrs[0]);
+ return ($ip, $iface) if $ip;
+ }
+ foreach my $address (@$peers) {
+ my $family = ip_family($address) // next;
+ foreach my $iface_addr (@iface_addrs) {
+ next if ip_family($iface_addr) != $family;
+ my $ip = normalize_ip($iface_addr);
+ return ($ip, $iface) if $ip;
+ }
+ }
}
#is a local ip member of peers list ?
- foreach my $address (@{$peers}) {
- while (my $interface = each %$ifaces) {
- my $ip = $ifaces->{$interface}->{address};
- if ($ip && $ip eq $address) {
- return ($ip, $interface);
+ foreach my $address (@$peers) {
+ my $peer_ip = normalize_ip($address);
+ my $family = ip_family($peer_ip) // next;
+ foreach my $interface (keys %$ifaces) {
+ foreach my $iface_addr (get_iface_addresses($ifaces->{$interface})) {
+ next if ip_family($iface_addr) != $family;
+ my $ip = normalize_ip($iface_addr);
+ if ($ip && $ip eq $peer_ip) {
+ return ($ip, $interface);
+ }
}
}
}
diff --git a/src/test/zones/vxlan/ipv6/expected_sdn_interfaces b/src/test/zones/vxlan/ipv6/expected_sdn_interfaces
new file mode 100644
index 0000000..032ab99
--- /dev/null
+++ b/src/test/zones/vxlan/ipv6/expected_sdn_interfaces
@@ -0,0 +1,15 @@
+#version:1
+
+auto myvnet
+iface myvnet
+ bridge_ports vxlan_myvnet
+ bridge_stp off
+ bridge_fd 0
+ mtu 1450
+
+auto vxlan_myvnet
+iface vxlan_myvnet
+ vxlan-id 100
+ vxlan_remoteip 2a08:2200:100:1::11
+ vxlan_remoteip 2a08:2200:100:1::12
+ mtu 1450
diff --git a/src/test/zones/vxlan/ipv6/interfaces b/src/test/zones/vxlan/ipv6/interfaces
new file mode 100644
index 0000000..7f9b1ad
--- /dev/null
+++ b/src/test/zones/vxlan/ipv6/interfaces
@@ -0,0 +1,7 @@
+auto vmbr0
+iface vmbr0 inet6 static
+ address 2a08:2200:100:1::10/64
+ gateway 2a08:2200:100:1::1
+ bridge-ports eth0
+ bridge-stp off
+ bridge-fd 0
diff --git a/src/test/zones/vxlan/ipv6/sdn_config b/src/test/zones/vxlan/ipv6/sdn_config
new file mode 100644
index 0000000..484be23
--- /dev/null
+++ b/src/test/zones/vxlan/ipv6/sdn_config
@@ -0,0 +1,17 @@
+{
+ version => 1,
+ vnets => {
+ ids => {
+ myvnet => { tag => 100, type => "vnet", zone => "myzone" },
+ },
+ },
+ zones => {
+ ids => {
+ myzone => {
+ ipam => "pve",
+ type => "vxlan",
+ peers => "2a08:2200:100:1::10,2a08:2200:100:1::11,2a08:2200:100:1::12",
+ },
+ },
+ },
+}
--
2.47.3
next reply other threads:[~2026-05-13 17:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 17:51 Hannes Laimer [this message]
2026-05-15 5:02 ` applied: [PATCH pve-network] sdn: zones: support IPv6 peers in local underlay selection Thomas Lamprecht
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=20260513175122.447818-1-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.