]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/VlanPlugin.pm
remove $interfaces arg from generate_network_config
[pve-network.git] / PVE / Network / VlanPlugin.pm
1 package PVE::Network::VlanPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::Plugin;
6
7 use base('PVE::Network::Plugin');
8
9 sub type {
10 return 'vlan';
11 }
12
13 PVE::JSONSchema::register_format('pve-network-vlanrange', \&pve_verify_network_vlanrange);
14 sub pve_verify_network_vlanrange {
15 my ($vlanstr) = @_;
16
17 PVE::Network::Plugin::parse_tag_number_or_range($vlanstr, '4096');
18
19 return $vlanstr;
20 }
21
22 sub properties {
23 return {
24 'vlan-allowed' => {
25 type => 'string', format => 'pve-network-vlanrange',
26 description => "Allowed vlan range",
27 },
28 'vlan-aware' => {
29 type => 'boolean',
30 description => "enable 802.1q stacked vlan",
31 },
32 'vlan-protocol' => {
33 type => 'string',
34 enum => ['802.1q', '802.1ad'],
35 default => '802.1q',
36 optional => 1,
37 description => "vlan protocol",
38 }
39 };
40 }
41
42 sub options {
43
44 return {
45 'uplink-id' => { fixed => 1 },
46 'vlan-allowed' => { optional => 1 },
47 'vlan-protocol' => { optional => 1 },
48 'vlan-aware' => { optional => 1 },
49
50 };
51 }
52
53 # Plugin implementation
54 sub generate_network_config {
55 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks) = @_;
56
57 my $tag = $vnet->{tag};
58 my $mtu = $vnet->{mtu};
59 my $vlanaware = $plugin_config->{'vlan-aware'};
60 my $vlanprotocol = $plugin_config->{'vlan-protocol'};
61 my $uplink = $plugin_config->{'uplink-id'};
62 my $vlanallowed = $plugin_config->{'vlan-allowed'};
63
64 die "missing vlan tag" if !$tag;
65 die "uplink $uplink is not defined" if !$uplinks->{$uplink};
66
67 eval {
68 PVE::Network::Plugin::parse_tag_number_or_range($vlanallowed, '4096', $tag) if $vlanallowed;
69 };
70 if($@) {
71 die "vlan $tag is not allowed in transport $zoneid";
72 }
73
74 my $iface = $uplinks->{$uplink};
75 $iface .= ".$tag";
76
77 my $config = "\n";
78 $config .= "auto $iface\n";
79 $config .= "iface $iface inet manual\n";
80 $config .= " vlan-protocol $vlanprotocol\n" if $vlanprotocol;
81 $config .= " mtu $mtu\n" if $mtu;
82 $config .= "\n";
83 $config .= "auto $vnetid\n";
84 $config .= "iface $vnetid inet manual\n";
85 $config .= " bridge_ports $iface\n";
86 $config .= " bridge_stp off\n";
87 $config .= " bridge_fd 0\n";
88 $config .= " vlan-aware 1 \n" if $vlanaware;
89 $config .= " mtu $mtu\n" if $mtu;
90
91 return $config;
92 }
93
94 1;
95
96