]> git.proxmox.com Git - pve-network.git/commitdiff
controllers: evpn: fix null routes order && ipv6
authorAlexandre Derumier <aderumier@odiso.com>
Sun, 3 Dec 2023 15:46:10 +0000 (16:46 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 22 Jan 2024 10:57:37 +0000 (11:57 +0100)
- 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
src/test/zones/evpn/exitnodenullroute/expected_controller_config
src/test/zones/evpn/exitnodenullroute/expected_sdn_interfaces
src/test/zones/evpn/exitnodenullroute/sdn_config

index 648f341c46a52cb4896d28b73203b5bfde0c9434..c2fdf884f934d11dc21b7dc60ba47a310cd88983 100644 (file)
@@ -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";
        }
     }
 
index e05fc7741d35441e25e93ed6f5ed88253bf654af..a6403c093b5d09542997e5dc8f789c21604cc44e 100644 (file)
@@ -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
index b6d9c1347a5c85a59368fc092c452e58bbcd2026..4bf5ccf96f91881e1e4fbbb9e2baa41e2e2974b1 100644 (file)
@@ -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
index 1060f83c485e72e2f52873fb32e4142d046ec0a6..5064ec4d8c9ee99bd16254650a821fe6d0cc8260 100644 (file)
 
   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',