]> git.proxmox.com Git - pve-network.git/commitdiff
add vlan plugin
authorAlexandre Derumier <aderumier@odiso.com>
Wed, 27 Mar 2019 17:24:07 +0000 (18:24 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 28 Mar 2019 10:52:29 +0000 (11:52 +0100)
/etc/pve/network/transports.cfg

vlan: vlanzone1
      uplink-id 1
      vlan-aware 1
      vlan-allowed 2-4,6,10
      vlan-protocol 802.1ad

vlan: vlanzone2
      uplink-id 2
      vlan-aware 1

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/VlanPlugin.pm [new file with mode: 0644]

diff --git a/PVE/Network/VlanPlugin.pm b/PVE/Network/VlanPlugin.pm
new file mode 100644 (file)
index 0000000..0bd43fe
--- /dev/null
@@ -0,0 +1,94 @@
+package PVE::Network::VlanPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::Plugin;
+
+use base('PVE::Network::Plugin');
+
+sub type {
+    return 'vlan';
+}
+
+PVE::JSONSchema::register_format('pve-network-vlanrange', \&pve_verify_network_vlanrange);
+sub pve_verify_network_vlanrange {
+   my ($vlanstr) = @_;
+
+   PVE::Network::Plugin::parse_tag_number_or_range($vlanstr, '4096');
+
+   return $vlanstr;
+}
+
+sub properties {
+    return {
+       'vlan-allowed' => {
+           type => 'string', format => 'pve-network-vlanrange',
+           description => "Allowed vlan range",
+       },
+       'vlan-aware' => {
+            type => 'boolean',
+           description => "enable 802.1q stacked vlan",
+       },
+       'vlan-protocol' => {
+           type => 'string',
+            enum => ['802.1q', '802.1ad'],
+           default => '802.1q',
+           optional => 1,
+           description => "vlan protocol",
+       }
+    };
+}
+
+sub options {
+
+    return {
+       'uplink-id' => { fixed => 1 },
+        'vlan-allowed' => { optional => 1 },
+       'vlan-protocol' => { optional => 1 },
+       'vlan-aware' => { optional => 1 },
+
+    };
+}
+
+# Plugin implementation
+sub generate_network_config {
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $interfaces, $uplinks) = @_;
+
+    my $tag = $vnet->{tag};
+    my $mtu = $vnet->{mtu};
+    my $vlanaware = $plugin_config->{'vlan-aware'};
+    my $vlanprotocol = $plugin_config->{'vlan-protocol'};
+    my $uplink = $plugin_config->{'uplink-id'};
+    my $vlanallowed = $plugin_config->{'vlan-allowed'};
+
+    die "missing vlan tag" if !$tag;
+    die "uplink $uplink is not defined" if !$uplinks->{$uplink};
+
+    eval {
+       PVE::Network::Plugin::parse_tag_number_or_range($vlanallowed, '4096', $tag) if $vlanallowed;
+    };
+    if($@) {
+       die "vlan $tag is not allowed in transport $zoneid";
+    }
+
+    my $iface = $uplinks->{$uplink};
+    $iface .= ".$tag";
+
+    die "interface $iface already exist in main configuration" if ($interfaces->{iface}->{$iface});
+    
+    my $config = "\n";
+    $config .= "auto $vnetid\n";
+    $config .= "iface $vnetid inet manual\n";
+    $config .= "        bridge_ports $iface\n";
+    $config .= "        bridge_stp off\n";
+    $config .= "        bridge_fd 0\n";
+    $config .= "        vlan-aware 1 \n" if $vlanaware;
+    $config .= "        vlan-protocol $vlanprotocol \n" if $vlanprotocol;
+    $config .= "        mtu $mtu\n" if $mtu;
+
+    return $config;
+}
+
+1;
+
+