]>
Commit | Line | Data |
---|---|---|
6bad73d0 | 1 | package PVE::Network::Network::VxlanMulticastPlugin; |
7e720d4d AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
6bad73d0 | 5 | use PVE::Network::Network::Plugin; |
7e720d4d | 6 | |
6bad73d0 | 7 | use base('PVE::Network::Network::Plugin'); |
7e720d4d AD |
8 | |
9 | PVE::JSONSchema::register_format('pve-network-vxlanrange', \&pve_verify_network_vxlanrange); | |
10 | sub pve_verify_network_vxlanrange { | |
11 | my ($vxlanstr) = @_; | |
12 | ||
6bad73d0 | 13 | PVE::Network::Network::Plugin::parse_tag_number_or_range($vxlanstr, '16777216'); |
7e720d4d AD |
14 | |
15 | return $vxlanstr; | |
16 | } | |
17 | ||
18 | sub type { | |
19 | return 'vxlanmulticast'; | |
20 | } | |
21 | ||
22 | sub properties { | |
23 | return { | |
24 | 'vxlan-allowed' => { | |
25 | type => 'string', format => 'pve-network-vxlanrange', | |
26 | description => "Allowed vlan range", | |
27 | }, | |
28 | 'multicast-address' => { | |
29 | description => "Multicast address.", | |
30 | type => 'string', #fixme: format | |
31 | }, | |
32 | ||
33 | }; | |
34 | } | |
35 | ||
36 | sub options { | |
37 | ||
38 | return { | |
85533e98 AD |
39 | 'uplink-id' => { optional => 0 }, |
40 | 'multicast-address' => { optional => 0 }, | |
7e720d4d AD |
41 | 'vxlan-allowed' => { optional => 1 }, |
42 | }; | |
43 | } | |
44 | ||
45 | # Plugin implementation | |
46 | sub generate_network_config { | |
bad3d113 | 47 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks) = @_; |
7e720d4d AD |
48 | |
49 | my $tag = $vnet->{tag}; | |
50 | my $mtu = $vnet->{mtu}; | |
dc7e431e | 51 | my $alias = $vnet->{alias}; |
7e720d4d AD |
52 | my $multicastaddress = $plugin_config->{'multicast-address'}; |
53 | my $uplink = $plugin_config->{'uplink-id'}; | |
54 | my $vxlanallowed = $plugin_config->{'vxlan-allowed'}; | |
55 | ||
56 | die "missing vxlan tag" if !$tag; | |
57 | die "uplink $uplink is not defined" if !$uplinks->{$uplink}; | |
58 | my $iface = $uplinks->{$uplink}; | |
59 | ||
60 | eval { | |
6bad73d0 | 61 | PVE::Network::Network::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed; |
7e720d4d AD |
62 | }; |
63 | if($@) { | |
64 | die "vlan $tag is not allowed in transport $zoneid"; | |
65 | } | |
66 | ||
67 | my $config = "\n"; | |
68 | $config .= "auto vxlan$vnetid\n"; | |
69 | $config .= "iface vxlan$vnetid inet manual\n"; | |
70 | $config .= " vxlan-id $tag\n" if $tag; | |
71 | $config .= " vxlan-svcnodeip $multicastaddress\n" if $multicastaddress; | |
72 | $config .= " vxlan-physdev $iface\n" if $iface; | |
9c2f5e3f | 73 | $config .= " mtu $mtu\n" if $mtu; |
7e720d4d AD |
74 | $config .= "\n"; |
75 | $config .= "auto $vnetid\n"; | |
76 | $config .= "iface $vnetid inet manual\n"; | |
77 | $config .= " bridge_ports vxlan$vnetid\n"; | |
78 | $config .= " bridge_stp off\n"; | |
79 | $config .= " bridge_fd 0\n"; | |
80 | $config .= " mtu $mtu\n" if $mtu; | |
dc7e431e | 81 | $config .= " alias $alias\n" if $alias; |
7e720d4d AD |
82 | |
83 | return $config; | |
84 | } | |
85 | ||
fe0c6b9e AD |
86 | sub on_delete_hook { |
87 | my ($class, $networkid, $scfg) = @_; | |
88 | ||
89 | # verify that no vnet are associated to this transport | |
90 | } | |
91 | ||
e8d5906e AD |
92 | sub on_update_hook { |
93 | my ($class, $networkid, $scfg) = @_; | |
94 | ||
95 | # verify that vxlan-allowed don't conflict with another vxlan-allowed transport | |
96 | ||
97 | # verify that vxlan-allowed is matching currently vnet tag in this transport | |
98 | ||
99 | } | |
100 | ||
7e720d4d AD |
101 | 1; |
102 | ||
103 |