]>
Commit | Line | Data |
---|---|---|
f5eabba0 | 1 | package PVE::Network::SDN::Zones::VlanPlugin; |
f8140d53 AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
f5eabba0 | 5 | use PVE::Network::SDN::Zones::Plugin; |
f8140d53 | 6 | |
f5eabba0 | 7 | use base('PVE::Network::SDN::Zones::Plugin'); |
f8140d53 AD |
8 | |
9 | sub type { | |
10 | return 'vlan'; | |
11 | } | |
12 | ||
6bffe819 AD |
13 | PVE::JSONSchema::register_format('pve-sdn-vlanrange', \&pve_verify_sdn_vlanrange); |
14 | sub pve_verify_sdn_vlanrange { | |
f8140d53 AD |
15 | my ($vlanstr) = @_; |
16 | ||
f5eabba0 | 17 | PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vlanstr, '4096'); |
f8140d53 AD |
18 | |
19 | return $vlanstr; | |
20 | } | |
21 | ||
22 | sub properties { | |
23 | return { | |
eec580bf AD |
24 | 'uplink-id' => { |
25 | type => 'integer', | |
26 | minimum => 1, maximum => 4096, | |
27 | description => 'Uplink interface', | |
28 | }, | |
f8140d53 AD |
29 | }; |
30 | } | |
31 | ||
32 | sub options { | |
33 | ||
34 | return { | |
c2b9c173 | 35 | nodes => { optional => 1}, |
41eec961 | 36 | 'uplink-id' => { optional => 0 }, |
f8140d53 AD |
37 | }; |
38 | } | |
39 | ||
40 | # Plugin implementation | |
6bffe819 | 41 | sub generate_sdn_config { |
4405f2de | 42 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_; |
f8140d53 AD |
43 | |
44 | my $tag = $vnet->{tag}; | |
45 | my $mtu = $vnet->{mtu}; | |
dc7e431e | 46 | my $alias = $vnet->{alias}; |
f8140d53 | 47 | my $uplink = $plugin_config->{'uplink-id'}; |
f8140d53 AD |
48 | |
49 | die "missing vlan tag" if !$tag; | |
f8140d53 | 50 | |
83d209f5 TL |
51 | my $iface = $uplinks->{$uplink}->{name}; |
52 | $iface = "uplink${uplink}" if !$iface; | |
f8140d53 | 53 | $iface .= ".$tag"; |
93dea3aa AD |
54 | |
55 | #tagged interface | |
56 | my @iface_config = (); | |
93dea3aa | 57 | push @iface_config, "mtu $mtu" if $mtu; |
87d8b623 | 58 | push(@{$config->{$iface}}, @iface_config) if !$config->{$iface}; |
93dea3aa AD |
59 | |
60 | #vnet bridge | |
61 | @iface_config = (); | |
62 | push @iface_config, "bridge_ports $iface"; | |
63 | push @iface_config, "bridge_stp off"; | |
64 | push @iface_config, "bridge_fd 0"; | |
93dea3aa AD |
65 | push @iface_config, "mtu $mtu" if $mtu; |
66 | push @iface_config, "alias $alias" if $alias; | |
87d8b623 | 67 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; |
f8140d53 AD |
68 | |
69 | return $config; | |
70 | } | |
71 | ||
72 | 1; | |
73 | ||
74 |