]>
Commit | Line | Data |
---|---|---|
7e720d4d AD |
1 | package PVE::Network::VxlanMulticastPlugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Network::Plugin; | |
6 | ||
7 | use base('PVE::Network::Plugin'); | |
8 | ||
9 | PVE::JSONSchema::register_format('pve-network-vxlanrange', \&pve_verify_network_vxlanrange); | |
10 | sub pve_verify_network_vxlanrange { | |
11 | my ($vxlanstr) = @_; | |
12 | ||
13 | PVE::Network::Plugin::parse_tag_number_or_range($vxlanstr, '16777216'); | |
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 { | |
39 | 'uplink-id' => { fixed => 1 }, | |
40 | 'multicast-address' => { fixed => 1 }, | |
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}; | |
51 | my $multicastaddress = $plugin_config->{'multicast-address'}; | |
52 | my $uplink = $plugin_config->{'uplink-id'}; | |
53 | my $vxlanallowed = $plugin_config->{'vxlan-allowed'}; | |
54 | ||
55 | die "missing vxlan tag" if !$tag; | |
56 | die "uplink $uplink is not defined" if !$uplinks->{$uplink}; | |
57 | my $iface = $uplinks->{$uplink}; | |
58 | ||
59 | eval { | |
60 | PVE::Network::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed; | |
61 | }; | |
62 | if($@) { | |
63 | die "vlan $tag is not allowed in transport $zoneid"; | |
64 | } | |
65 | ||
66 | my $config = "\n"; | |
67 | $config .= "auto vxlan$vnetid\n"; | |
68 | $config .= "iface vxlan$vnetid inet manual\n"; | |
69 | $config .= " vxlan-id $tag\n" if $tag; | |
70 | $config .= " vxlan-svcnodeip $multicastaddress\n" if $multicastaddress; | |
71 | $config .= " vxlan-physdev $iface\n" if $iface; | |
72 | $config .= "\n"; | |
73 | $config .= "auto $vnetid\n"; | |
74 | $config .= "iface $vnetid inet manual\n"; | |
75 | $config .= " bridge_ports vxlan$vnetid\n"; | |
76 | $config .= " bridge_stp off\n"; | |
77 | $config .= " bridge_fd 0\n"; | |
78 | $config .= " mtu $mtu\n" if $mtu; | |
79 | ||
80 | return $config; | |
81 | } | |
82 | ||
83 | 1; | |
84 | ||
85 |