]> git.proxmox.com Git - pve-network.git/commitdiff
vnet: make tag optional and verify value in zone plugins
authorAlexandre Derumier <aderumier@odiso.com>
Wed, 1 Jul 2020 07:10:37 +0000 (09:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 3 Jul 2020 11:46:52 +0000 (13:46 +0200)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN/Vnets.pm
PVE/Network/SDN/VnetPlugin.pm
PVE/Network/SDN/Zones/EvpnPlugin.pm
PVE/Network/SDN/Zones/Plugin.pm
PVE/Network/SDN/Zones/QinQPlugin.pm
PVE/Network/SDN/Zones/SimplePlugin.pm
PVE/Network/SDN/Zones/VlanPlugin.pm
PVE/Network/SDN/Zones/VxlanPlugin.pm

index 8f70bab6a39d85ca0972aa1f6649530ababfde26..5d669086689ee258a755b75a71115a00cdcac233 100644 (file)
@@ -7,6 +7,8 @@ use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::Cluster qw(cfs_read_file cfs_write_file);
 use PVE::Network::SDN;
+use PVE::Network::SDN::Zones;
+use PVE::Network::SDN::Zones::Plugin;
 use PVE::Network::SDN::Vnets;
 use PVE::Network::SDN::VnetPlugin;
 
@@ -129,6 +131,13 @@ __PACKAGE__->register_method ({
                }
 
                $cfg->{ids}->{$id} = $opts;
+
+               my $zone_cfg = PVE::Network::SDN::Zones::config();
+               my $zoneid = $cfg->{ids}->{$id}->{zone};
+               my $plugin_config = $zone_cfg->{ids}->{$zoneid};
+               my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+               $plugin->verify_tag($opts->{tag});
+
                PVE::Network::SDN::VnetPlugin->on_update_hook($id, $cfg);
 
                PVE::Network::SDN::Vnets::write_config($cfg);
@@ -168,6 +177,12 @@ __PACKAGE__->register_method ({
            my $opts = PVE::Network::SDN::VnetPlugin->check_config($id, $param, 0, 1);
            $cfg->{ids}->{$id} = $opts;
 
+           my $zone_cfg = PVE::Network::SDN::Zones::config();
+           my $zoneid = $cfg->{ids}->{$id}->{zone};
+            my $plugin_config = $zone_cfg->{ids}->{$zoneid};
+            my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+           $plugin->verify_tag($opts->{tag});
            PVE::Network::SDN::VnetPlugin->on_update_hook($id, $cfg);
 
            PVE::Network::SDN::Vnets::write_config($cfg);
index 243301370556a412dd73a124d43fc50c4d684bdb..384358c29f1f00086bf6d74f7b24c480eda7b16d 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
 use base qw(PVE::SectionConfig);
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::Exception qw(raise raise_param_exc);
 
 PVE::Cluster::cfs_register_file('sdn/vnets.cfg',
                                  sub { __PACKAGE__->parse_config(@_); },
@@ -88,7 +89,7 @@ sub properties {
 sub options {
     return {
         zone => { optional => 0},
-        tag => { optional => 0},
+        tag => { optional => 1},
         alias => { optional => 1 },
         ipv4 => { optional => 1 },
         ipv6 => { optional => 1 },
@@ -112,7 +113,7 @@ sub on_update_hook {
            next if $id eq $vnetid;
            my $vnet = $vnet_cfg->{ids}->{$id};
            if ($vnet->{type} eq 'vnet' && defined($vnet->{tag})) {
-               die "tag $tag already exist in vnet $id" if $tag eq $vnet->{tag};
+               raise_param_exc({ tag => "tag $tag already exist in vnet $id"}) if $tag eq $vnet->{tag};
            }
        }
     }
index b2f57ee6b8175de71dd8d1300df0bafc9cd28974..a9165799ee17d391709823651da100d17aa18372 100644 (file)
@@ -140,6 +140,13 @@ sub on_update_hook {
     }
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+
+    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
+    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
+}
+
 1;
 
 
index 5e3fdfd186a3ceb7e62ad93fbb2b9fc343d9e35e..d96e0695711be27712d636749c3837428d9eb692 100644 (file)
@@ -139,6 +139,11 @@ sub on_update_hook {
     # do nothing by default
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+    # do nothing by default
+}
+
 #helpers
 sub parse_tag_number_or_range {
     my ($str, $max, $tag) = @_;
index c8dd0ab145d397c7672a919cfcd57093e0d207be..b39732ac835bb93f5232ae0cb188f429a225e6af 100644 (file)
@@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::QinQPlugin;
 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');
 
@@ -210,6 +211,13 @@ sub status {
     return $err_msg;
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+
+    raise_param_exc({ tag => "missing vlan tag"}) if !defined($tag);
+    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $tag > 4096;
+}
+
 1;
 
 
index 60fb7db247f1396ba626efa1e67d4fd34621dfb8..9fd3b29e5679ad281c2dd127cf90cad88f1efb15 100644 (file)
@@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::SimplePlugin;
 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');
 
@@ -65,6 +66,12 @@ sub status {
     return $err_msg;
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+
+    raise_param_exc({ tag => "vlan tag is not allowed on simple bridge"}) if defined($tag);
+}
+
 1;
 
 
index dedb32c860b8babaef1d9d2c3d2e7f5585b0fe81..db719a067d470c8db6281656e60d9a79f1a8aaeb 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');
 
@@ -169,6 +170,13 @@ sub status {
     return $err_msg;
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+
+    raise_param_exc({ tag => "missing vlan tag"}) if !defined($tag);
+    raise_param_exc({ tag => "vlan tag max value is 4096"}) if $tag > 4096;
+}
+
 1;
 
 
index e8cf1bddd01089652319f12fc45b12018fe5af81..a2562681af7303b443a75cb7546daedb67cd639d 100644 (file)
@@ -6,6 +6,7 @@ use PVE::Network::SDN::Zones::Plugin;
 use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
 use PVE::Network::SDN::Controllers::EvpnPlugin;
+use PVE::Exception qw(raise raise_param_exc);
 
 use base('PVE::Network::SDN::Zones::Plugin');
 
@@ -94,6 +95,13 @@ sub generate_sdn_config {
     return $config;
 }
 
+sub verify_tag {
+    my ($class, $tag) = @_;
+
+    raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
+    raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
+}
+
 1;