]>
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 { |
ba7ac021 | 42 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $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 | |
ba7ac021 AD |
51 | #check uplinks |
52 | my $uplinks = {}; | |
53 | foreach my $id (keys %{$interfaces_config->{ifaces}}) { | |
54 | my $interface = $interfaces_config->{ifaces}->{$id}; | |
55 | if (my $uplink = $interface->{'uplink-id'}) { | |
56 | die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink}; | |
57 | $interface->{name} = $id; | |
58 | $uplinks->{$interface->{'uplink-id'}} = $interface; | |
59 | } | |
60 | } | |
61 | ||
83d209f5 TL |
62 | my $iface = $uplinks->{$uplink}->{name}; |
63 | $iface = "uplink${uplink}" if !$iface; | |
f8140d53 | 64 | $iface .= ".$tag"; |
93dea3aa AD |
65 | |
66 | #tagged interface | |
67 | my @iface_config = (); | |
93dea3aa | 68 | push @iface_config, "mtu $mtu" if $mtu; |
87d8b623 | 69 | push(@{$config->{$iface}}, @iface_config) if !$config->{$iface}; |
93dea3aa AD |
70 | |
71 | #vnet bridge | |
72 | @iface_config = (); | |
73 | push @iface_config, "bridge_ports $iface"; | |
74 | push @iface_config, "bridge_stp off"; | |
75 | push @iface_config, "bridge_fd 0"; | |
93dea3aa AD |
76 | push @iface_config, "mtu $mtu" if $mtu; |
77 | push @iface_config, "alias $alias" if $alias; | |
87d8b623 | 78 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; |
f8140d53 AD |
79 | |
80 | return $config; | |
81 | } | |
82 | ||
83 | 1; | |
84 | ||
85 |