]>
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; | |
ef8d35c8 | 57 | my $iface = $uplinks->{$uplink} ? $uplinks->{$uplink} : "uplink$uplink"; |
7e720d4d | 58 | |
7e720d4d | 59 | my $config = "\n"; |
4394cbf2 AD |
60 | $config .= "auto vxlan$tag\n"; |
61 | $config .= "iface vxlan$tag inet manual\n"; | |
62 | $config .= " vxlan-id $tag\n"; | |
7e720d4d AD |
63 | $config .= " vxlan-svcnodeip $multicastaddress\n" if $multicastaddress; |
64 | $config .= " vxlan-physdev $iface\n" if $iface; | |
9c2f5e3f | 65 | $config .= " mtu $mtu\n" if $mtu; |
7e720d4d AD |
66 | $config .= "\n"; |
67 | $config .= "auto $vnetid\n"; | |
68 | $config .= "iface $vnetid inet manual\n"; | |
4394cbf2 | 69 | $config .= " bridge_ports vxlan$tag\n"; |
7e720d4d AD |
70 | $config .= " bridge_stp off\n"; |
71 | $config .= " bridge_fd 0\n"; | |
72 | $config .= " mtu $mtu\n" if $mtu; | |
dc7e431e | 73 | $config .= " alias $alias\n" if $alias; |
7e720d4d AD |
74 | |
75 | return $config; | |
76 | } | |
77 | ||
fe0c6b9e | 78 | sub on_delete_hook { |
a8ad2789 | 79 | my ($class, $transportid, $network_cfg) = @_; |
fe0c6b9e AD |
80 | |
81 | # verify that no vnet are associated to this transport | |
a8ad2789 AD |
82 | foreach my $id (keys %{$network_cfg->{ids}}) { |
83 | my $network = $network_cfg->{ids}->{$id}; | |
84 | die "transport $transportid is used by vnet $id" | |
85 | if ($network->{type} eq 'vnet' && defined($network->{transportzone}) && $network->{transportzone} eq $transportid); | |
86 | } | |
fe0c6b9e AD |
87 | } |
88 | ||
e8d5906e | 89 | sub on_update_hook { |
c723980e AD |
90 | my ($class, $transportid, $network_cfg) = @_; |
91 | ||
92 | my $transport = $network_cfg->{ids}->{$transportid}; | |
e8d5906e AD |
93 | |
94 | # verify that vxlan-allowed don't conflict with another vxlan-allowed transport | |
95 | ||
96 | # verify that vxlan-allowed is matching currently vnet tag in this transport | |
c723980e AD |
97 | my $vxlanallowed = $transport->{'vxlan-allowed'}; |
98 | if ($vxlanallowed) { | |
99 | foreach my $id (keys %{$network_cfg->{ids}}) { | |
100 | my $network = $network_cfg->{ids}->{$id}; | |
101 | if ($network->{type} eq 'vnet' && defined($network->{tag})) { | |
102 | if(defined($network->{transportzone}) && $network->{transportzone} eq $transportid) { | |
103 | my $tag = $network->{tag}; | |
104 | eval { | |
105 | PVE::Network::Network::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag); | |
106 | }; | |
107 | if($@) { | |
108 | die "vnet $id - vlan $tag is not allowed in transport $transportid"; | |
109 | } | |
110 | } | |
111 | } | |
112 | } | |
113 | } | |
e8d5906e AD |
114 | } |
115 | ||
7e720d4d AD |
116 | 1; |
117 | ||
118 |