]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/Zones/EvpnPlugin.pm
vnets: allow duplicate tags in differents zones
[pve-network.git] / PVE / Network / SDN / Zones / EvpnPlugin.pm
index 219100888a83f45f2af9f418c91a1f16fb5945c9..5338a1bd247e7382841465f17e4dcb1a01932217 100644 (file)
@@ -37,6 +37,10 @@ sub options {
         'vrf-vxlan' => { optional => 0 },
         'controller' => { optional => 0 },
        mtu => { optional => 1 },
+       dns => { optional => 1 },
+       reversedns => { optional => 1 },
+       dnszone => { optional => 1 },
+       ipam => { optional => 0 },
     };
 }
 
@@ -82,7 +86,8 @@ sub generate_sdn_config {
     my $subnets = PVE::Network::SDN::Vnets::get_subnets($vnetid, 1);
     foreach my $subnetid (sort keys %{$subnets}) {
        my $subnet = $subnets->{$subnetid};
-       my $cidr = $subnetid =~ s/-/\//r;
+       my $cidr = $subnet->{cidr};
+
        my $gateway = $subnet->{gateway};
        if ($gateway) {
            push @iface_config, "address $gateway" if !defined($address->{$gateway});
@@ -176,10 +181,24 @@ sub on_update_hook {
 
 
 sub vnet_update_hook {
-    my ($class, $vnet) = @_;
+    my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
+
+    my $vnet = $vnet_cfg->{ids}->{$vnetid};
+    my $tag = $vnet->{tag};
 
-    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($vnet->{tag});
-    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $vnet->{tag} > 16777216;
+    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
+    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
+
+    # verify that tag is not already defined globally (vxlan-id are unique)
+    foreach my $id (keys %{$vnet_cfg->{ids}}) {
+       next if $id eq $vnetid;
+       my $othervnet = $vnet_cfg->{ids}->{$id};
+       my $other_tag = $othervnet->{tag};
+       my $other_zoneid = $othervnet->{zone};
+       my $other_zone = $zone_cfg->{ids}->{$other_zoneid};
+       next if $other_zone->{type} ne 'vxlan' && $other_zone->{type} ne 'evpn';
+       raise_param_exc({ tag => "vxlan tag $tag already exist in vnet $id in zone $other_zoneid "}) if $other_tag && $tag eq $other_tag;
+    }
 
     if (!defined($vnet->{mac})) {
        my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');