[pve-devel] [PATCH pve-network 4/4] controllers: evpn: fix null routes order && ipv6

Alexandre Derumier aderumier at odiso.com
Sun Dec 3 16:46:10 CET 2023


- don't duplicate ip
- ipv6 use "ipv6 route"
- order correctly

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/Network/SDN/Controllers/EvpnPlugin.pm | 16 ++++++++-
 .../expected_controller_config                |  7 ++++
 .../exitnodenullroute/expected_sdn_interfaces |  8 +++++
 .../zones/evpn/exitnodenullroute/sdn_config   | 35 +++++++++++++++++++
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm b/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
index 648f341..c2fdf88 100644
--- a/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
+++ b/src/PVE/Network/SDN/Controllers/EvpnPlugin.pm
@@ -162,11 +162,25 @@ sub generate_controller_zone_config {
     #null routes subnets of other zones
     if ($is_gateway) {
 	my $subnets = PVE::Network::SDN::Vnets::get_subnets();
+	my $cidrs = {};
 	foreach my $subnetid (sort keys %{$subnets}) {
 	    my $subnet = $subnets->{$subnetid};
 	    my $cidr = $subnet->{cidr};
 	    my $zone = $subnet->{zone};
-	    push @controller_config, "ip route $cidr null0" if $zone ne $id;
+	    my ($ip, $mask) = split(/\//, $cidr);
+	    $cidrs->{$ip} = $mask if $zone ne $id;
+
+	}
+
+	my @sorted_ip =
+		map  { $_->[0] }
+		sort { $a->[1] <=> $b->[1] }
+		map  { [ $_, eval { Net::IP->new( $_ )->intip } ] }
+		keys %{$cidrs} if $cidrs;
+
+	foreach my $ip (@sorted_ip) {
+	    my $ipversion = Net::IP::ip_is_ipv4($ip) ? 'ip' : 'ipv6';
+	    push @controller_config, "$ipversion route $ip/$cidrs->{$ip} null0";
 	}
     }
 
diff --git a/src/test/zones/evpn/exitnodenullroute/expected_controller_config b/src/test/zones/evpn/exitnodenullroute/expected_controller_config
index e05fc77..a6403c0 100644
--- a/src/test/zones/evpn/exitnodenullroute/expected_controller_config
+++ b/src/test/zones/evpn/exitnodenullroute/expected_controller_config
@@ -7,13 +7,20 @@ service integrated-vtysh-config
 !
 vrf vrf_myzone
  vni 1000
+ ip route 10.0.0.0/24 null0
  ip route 172.16.0.0/24 null0
  ip route 172.16.1.0/24 null0
+ ip route 172.16.3.0/24 null0
 exit-vrf
 !
 vrf vrf_myzone2
  vni 1001
  ip route 10.0.0.0/24 null0
+ ip route 192.168.0.1/24 null0
+ ip route 192.168.10.1/24 null0
+ ipv6 route 2b0f:1480::/64 null0
+ ipv6 route 2b0f:1480:4000:6000::/64 null0
+ ipv6 route 2b0f:1480:4000:8000::/64 null0
 exit-vrf
 !
 router bgp 65000
diff --git a/src/test/zones/evpn/exitnodenullroute/expected_sdn_interfaces b/src/test/zones/evpn/exitnodenullroute/expected_sdn_interfaces
index b6d9c13..4bf5ccf 100644
--- a/src/test/zones/evpn/exitnodenullroute/expected_sdn_interfaces
+++ b/src/test/zones/evpn/exitnodenullroute/expected_sdn_interfaces
@@ -3,17 +3,25 @@
 auto myvnet
 iface myvnet
 	address 10.0.0.1/24
+	address 192.168.0.1/24
+	address 192.168.10.1/24
+	address 2b0f:1480:4000:6000::1/64
+	address 2b0f:1480:4000:8000::1/64
+	address 2b0f:1480::1/64
 	bridge_ports vxlan_myvnet
 	bridge_stp off
 	bridge_fd 0
 	mtu 1450
 	ip-forward on
+	ip6-forward on
 	arp-accept on
 	vrf vrf_myzone
 
 auto myvnet2
 iface myvnet2
+	address 10.0.0.1/24
 	address 172.16.0.1/24
+	address 172.16.3.1/24
 	bridge_ports vxlan_myvnet2
 	bridge_stp off
 	bridge_fd 0
diff --git a/src/test/zones/evpn/exitnodenullroute/sdn_config b/src/test/zones/evpn/exitnodenullroute/sdn_config
index 1060f83..5064ec4 100644
--- a/src/test/zones/evpn/exitnodenullroute/sdn_config
+++ b/src/test/zones/evpn/exitnodenullroute/sdn_config
@@ -19,16 +19,51 @@
 
   subnets => {
 		ids => { 
+			'myzone-192.168.10.1-24' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet',
+			    'gateway' => '192.168.10.1',
+			},
+			'myzone-192.168.0.1-24' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet',
+			    'gateway' => '192.168.0.1',
+			},
 			'myzone-10.0.0.0-24' => {
 			    'type' => 'subnet',
 			    'vnet' => 'myvnet',
 			    'gateway' => '10.0.0.1',
 			},
+			'myzone2-10.0.0.0-24' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet2',
+			    'gateway' => '10.0.0.1',
+			},
+			'myzone-2b0f:1480:4000:8000::-64' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet',
+			    'gateway' => '2b0f:1480:4000:8000::1',
+			},
+			'myzone-2b0f:1480::-64' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet',
+			    'gateway' => '2b0f:1480::1',
+			},
 			'myzone2-172.16.0.0-24' => {
 			    'type' => 'subnet',
 			    'vnet' => 'myvnet2',
 			    'gateway' => '172.16.0.1',
 			},
+			'myzone2-172.16.3.0-24' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet2',
+			    'gateway' => '172.16.3.1',
+			},
+			'myzone-2b0f:1480:4000:6000::-64' => {
+			    'type' => 'subnet',
+			    'vnet' => 'myvnet',
+			    'gateway' => '2b0f:1480:4000:6000::1',
+			},
 			'myzone2-172.16.1.0-24' => {
 			    'type' => 'subnet',
 			    'vnet' => 'myvnet2',
-- 
2.39.2




More information about the pve-devel mailing list