public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier <aderumier@odiso.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-network 4/4] controllers: evpn: fix null routes order && ipv6
Date: Sun,  3 Dec 2023 16:46:10 +0100	[thread overview]
Message-ID: <20231203154610.217714-5-aderumier@odiso.com> (raw)
In-Reply-To: <20231203154610.217714-1-aderumier@odiso.com>

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

Signed-off-by: Alexandre Derumier <aderumier@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




  parent reply	other threads:[~2023-12-03 15:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-03 15:46 [pve-devel] [PATCH pve-network 0/4] evpn controller fix && cleanup Alexandre Derumier
2023-12-03 15:46 ` [pve-devel] [PATCH pve-network 1/4] controllers: evpn: add ipv6 prefix-list support Alexandre Derumier
2023-12-03 15:46 ` [pve-devel] [PATCH pve-network 2/4] controllers: evpn: bugfix: use prefix-list in route-map instead evpn match Alexandre Derumier
2023-12-03 15:46 ` [pve-devel] [PATCH pve-network 3/4] controllers: evpn: frr config cleanup Alexandre Derumier
2023-12-03 15:46 ` Alexandre Derumier [this message]
2024-01-06  6:41 ` [pve-devel] [PATCH pve-network 0/4] evpn controller fix && cleanup DERUMIER, Alexandre
2024-01-19 11:59   ` DERUMIER, Alexandre
2024-01-22 10:59 ` [pve-devel] applied: " 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=20231203154610.217714-5-aderumier@odiso.com \
    --to=aderumier@odiso.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal