]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/Zones/VlanPlugin.pm
zones: evpn : add support for loopback
[pve-network.git] / PVE / Network / SDN / Zones / VlanPlugin.pm
index 8e99fc4da7a9f76cad44231d03578b58ff38d3f9..ca6bd8f2472d6714281e052bd6a506f20ee570fe 100644 (file)
@@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::VlanPlugin;
 use strict;
 use warnings;
 use PVE::Network::SDN::Zones::Plugin;
+use PVE::Exception qw(raise raise_param_exc);
 
 use base('PVE::Network::SDN::Zones::Plugin');
 
@@ -32,23 +33,27 @@ sub options {
     return {
         nodes => { optional => 1},
        'bridge' => { optional => 0 },
-       mtu => { optional => 1 }
+       mtu => { optional => 1 },
+       dns => { optional => 1 },
+       reversedns => { optional => 1 },
+       dnszone => { optional => 1 },
+        ipam => { optional => 0 },
     };
 }
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
 
     my $bridge = $plugin_config->{bridge};
     die "can't find bridge $bridge" if !-d "/sys/class/net/$bridge";
 
     my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
-    my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
+    my $is_ovs = !-d "/sys/class/net/$bridge/brif";
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
-    my $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
+    my $mtu = $plugin_config->{mtu};
 
     my $vnet_uplink = "ln_".$vnetid;
     my $vnet_uplinkpeer = "pr_".$vnetid;
@@ -142,7 +147,7 @@ sub status {
     }
 
     my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering");
-    my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif";
+    my $is_ovs = !-d "/sys/class/net/$bridge/brif";
 
     my $tag = $vnet->{tag};
     my $vnet_uplink = "ln_".$vnetid;
@@ -169,6 +174,25 @@ sub status {
     return $err_msg;
 }
 
+sub vnet_update_hook {
+    my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
+
+    my $vnet = $vnet_cfg->{ids}->{$vnetid};
+    my $tag = $vnet->{tag};
+
+    raise_param_exc({ tag => "missing vlan tag"}) if !defined($vnet->{tag});
+    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $vnet->{tag} > 4096;
+
+    # verify that tag is not already defined in another vnet on same zone
+    foreach my $id (keys %{$vnet_cfg->{ids}}) {
+       next if $id eq $vnetid;
+       my $othervnet = $vnet_cfg->{ids}->{$id};
+       my $other_tag = $othervnet->{tag};
+       next if $vnet->{zone} ne $othervnet->{zone};
+       raise_param_exc({ tag => "tag $tag already exist in vnet $id"}) if $other_tag && $tag eq $other_tag;
+    }
+}
+
 1;