1 package PVE
::Network
::Network
::VlanPlugin
;
5 use PVE
::Network
::Network
::Plugin
;
7 use base
('PVE::Network::Network::Plugin');
13 PVE
::JSONSchema
::register_format
('pve-network-vlanrange', \
&pve_verify_network_vlanrange
);
14 sub pve_verify_network_vlanrange
{
17 PVE
::Network
::Network
::Plugin
::parse_tag_number_or_range
($vlanstr, '4096');
26 minimum
=> 1, maximum
=> 4096,
27 description
=> 'Uplink interface',
30 type
=> 'string', format
=> 'pve-network-vlanrange',
31 description
=> "Allowed vlan range",
35 description
=> "enable 802.1q stacked vlan",
39 enum
=> ['802.1q', '802.1ad'],
42 description
=> "vlan protocol",
50 'uplink-id' => { optional
=> 0 },
51 'vlan-allowed' => { optional
=> 1 },
52 'vlan-protocol' => { optional
=> 1 },
53 'vlan-aware' => { optional
=> 1 },
58 # Plugin implementation
59 sub generate_network_config
{
60 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks) = @_;
62 my $tag = $vnet->{tag
};
63 my $mtu = $vnet->{mtu
};
64 my $alias = $vnet->{alias
};
65 my $vlanaware = $plugin_config->{'vlan-aware'};
66 my $vlanprotocol = $plugin_config->{'vlan-protocol'};
67 my $uplink = $plugin_config->{'uplink-id'};
68 my $vlanallowed = $plugin_config->{'vlan-allowed'};
70 die "missing vlan tag" if !$tag;
72 my $iface = $uplinks->{$uplink}->{name
} ?
$uplinks->{$uplink}->{name
} : "uplink$uplink";
75 $config .= "auto $iface\n";
76 $config .= "iface $iface inet manual\n";
77 $config .= " vlan-protocol $vlanprotocol\n" if $vlanprotocol;
78 $config .= " mtu $mtu\n" if $mtu;
80 $config .= "auto $vnetid\n";
81 $config .= "iface $vnetid inet manual\n";
82 $config .= " bridge_ports $iface\n";
83 $config .= " bridge_stp off\n";
84 $config .= " bridge_fd 0\n";
85 $config .= " bridge-vlan-aware yes \n" if $vlanaware;
86 $config .= " mtu $mtu\n" if $mtu;
87 $config .= " alias $alias\n" if $alias;
93 my ($class, $transportid, $network_cfg) = @_;
95 # verify that no vnet are associated to this transport
96 foreach my $id (keys %{$network_cfg->{ids
}}) {
97 my $network = $network_cfg->{ids
}->{$id};
98 die "transport $transportid is used by vnet $id"
99 if ($network->{type
} eq 'vnet' && defined($network->{transportzone
}) && $network->{transportzone
} eq $transportid);
104 my ($class, $transportid, $network_cfg) = @_;
106 my $transport = $network_cfg->{ids
}->{$transportid};
108 # verify that vlan-allowed don't conflict with another vlan-allowed transport
110 # verify that vlan-allowed is matching currently vnet tag in this transport
111 my $vlanallowed = $transport->{'vlan-allowed'};
113 foreach my $id (keys %{$network_cfg->{ids
}}) {
114 my $network = $network_cfg->{ids
}->{$id};
115 if ($network->{type
} eq 'vnet' && defined($network->{tag
})) {
116 if(defined($network->{transportzone
}) && $network->{transportzone
} eq $transportid) {
117 my $tag = $network->{tag
};
119 PVE
::Network
::Network
::Plugin
::parse_tag_number_or_range
($vlanallowed, '4096', $tag);
122 die "vlan $tag is not allowed in transport $transportid";