summaryrefslogtreecommitdiff
path: root/src/PVE/Network/SDN/Controllers/Plugin.pm
diff options
context:
space:
mode:
authorAlexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>2024-04-12 14:57:42 +0200
committerThomas Lamprecht <t.lamprecht@proxmox.com>2024-04-22 13:56:48 +0200
commit7638f25336ab2c05edc8b0c306176b356da1a98e (patch)
tree5499068ad6e2a0ae359269371a1f3a7b6e10047a /src/PVE/Network/SDN/Controllers/Plugin.pm
parentc508ffa2de63d1b35a2447a2b89315061f0ff7e3 (diff)
fix #5364: bgp|evpn: derivated router-id from mac address for ipv6 underlay
for ipv4, we use the iface ipv4 router-id as router-id need to 32bit. That's doesn't work for pure ipv6 underlay network. since https://www.rfc-editor.org/rfc/rfc6286, we can use any 32bit id, it's just need to be unique in the ASN. Simply use the last 4 bytes of iface mac address as unique id changelog V2: add missing test Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Diffstat (limited to 'src/PVE/Network/SDN/Controllers/Plugin.pm')
-rw-r--r--src/PVE/Network/SDN/Controllers/Plugin.pm21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/PVE/Network/SDN/Controllers/Plugin.pm b/src/PVE/Network/SDN/Controllers/Plugin.pm
index c1c2cfd..5579513 100644
--- a/src/PVE/Network/SDN/Controllers/Plugin.pm
+++ b/src/PVE/Network/SDN/Controllers/Plugin.pm
@@ -118,4 +118,25 @@ sub on_update_hook {
# do nothing by default
}
+#helpers
+
+sub read_iface_mac {
+ my ($iface) = @_;
+ return PVE::Tools::file_read_firstline("/sys/class/net/$iface/master/address");
+}
+
+sub get_router_id {
+ my ($ip, $iface) = @_;
+
+ return $ip if Net::IP::ip_is_ipv4($ip);
+
+ #for ipv6, use 4 last bytes of iface mac address as unique id
+ my $mac = read_iface_mac($iface);
+
+ die "can't autofind a router-id value from ip or mac" if !$mac;
+
+ my @mac_bytes = split(':', $mac);
+ return hex($mac_bytes[2]).".".hex($mac_bytes[3]).".".hex($mac_bytes[4]).".".hex($mac_bytes[5]);
+}
+
1;