]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/VxlanPlugin.pm
move dns options from subnets to zone
[pve-network.git] / PVE / Network / SDN / Zones / VxlanPlugin.pm
CommitLineData
f5eabba0 1package PVE::Network::SDN::Zones::VxlanPlugin;
7e720d4d
AD
2
3use strict;
4use warnings;
f5eabba0 5use PVE::Network::SDN::Zones::Plugin;
c692cbfa 6use PVE::Tools qw($IPV4RE);
e3dca233 7use PVE::INotify;
ba7ac021 8use PVE::Network::SDN::Controllers::EvpnPlugin;
1d44ce70 9use PVE::Exception qw(raise raise_param_exc);
7e720d4d 10
f5eabba0 11use base('PVE::Network::SDN::Zones::Plugin');
7e720d4d 12
6bffe819
AD
13PVE::JSONSchema::register_format('pve-sdn-vxlanrange', \&pve_verify_sdn_vxlanrange);
14sub pve_verify_sdn_vxlanrange {
7e720d4d
AD
15 my ($vxlanstr) = @_;
16
f5eabba0 17 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
7e720d4d
AD
18
19 return $vxlanstr;
20}
21
22sub type {
3ee45e4c 23 return 'vxlan';
7e720d4d
AD
24}
25
26sub properties {
27 return {
ba7ac021
AD
28 'peers' => {
29 description => "peers address list.",
30 type => 'string', format => 'ip-list'
7e720d4d 31 },
7e720d4d
AD
32 };
33}
34
35sub options {
36
37 return {
c2b9c173 38 nodes => { optional => 1},
ba7ac021 39 peers => { optional => 0 },
823f2e2a 40 mtu => { optional => 1 },
4ad78442
AD
41 dns => { optional => 1 },
42 reversedns => { optional => 1 },
43 dnszone => { optional => 1 },
7e720d4d
AD
44 };
45}
46
47# Plugin implementation
6bffe819 48sub generate_sdn_config {
7024ec2b 49 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
7e720d4d
AD
50
51 my $tag = $vnet->{tag};
dc7e431e 52 my $alias = $vnet->{alias};
7e720d4d 53 my $multicastaddress = $plugin_config->{'multicast-address'};
3caa7687
FG
54 my @peers;
55 @peers = PVE::Tools::split_list($plugin_config->{'peers'}) if $plugin_config->{'peers'};
ff3088cb 56 my $vxlan_iface = "vxlan_$vnetid";
7e720d4d
AD
57
58 die "missing vxlan tag" if !$tag;
3ee45e4c 59
1f543c5f 60 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
c1ae8486
AD
61
62 my $mtu = 1450;
ba7ac021 63 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
0251ed2f 64 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
7e720d4d 65
93dea3aa
AD
66 #vxlan interface
67 my @iface_config = ();
68 push @iface_config, "vxlan-id $tag";
3ee45e4c 69
ba7ac021
AD
70 foreach my $address (@peers) {
71 next if $address eq $ifaceip;
72 push @iface_config, "vxlan_remoteip $address";
3ee45e4c
AD
73 }
74
ff3088cb 75
93dea3aa 76 push @iface_config, "mtu $mtu" if $mtu;
ff3088cb 77 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
93dea3aa
AD
78
79 #vnet bridge
80 @iface_config = ();
ff3088cb 81 push @iface_config, "bridge_ports $vxlan_iface";
93dea3aa
AD
82 push @iface_config, "bridge_stp off";
83 push @iface_config, "bridge_fd 0";
912fb443
AD
84 if($vnet->{vlanaware}) {
85 push @iface_config, "bridge-vlan-aware yes";
86 push @iface_config, "bridge-vids 2-4094";
87 }
93dea3aa
AD
88 push @iface_config, "mtu $mtu" if $mtu;
89 push @iface_config, "alias $alias" if $alias;
87d8b623 90 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
126fc68c 91
7e720d4d
AD
92 return $config;
93}
94
5ca07ed9
AD
95sub vnet_update_hook {
96 my ($class, $vnet) = @_;
1d44ce70 97
5ca07ed9
AD
98 raise_param_exc({ tag => "missing vxlan tag"}) if !defined($vnet->{tag});
99 raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $vnet->{tag} > 16777216;
1d44ce70
AD
100}
101
7e720d4d
AD
1021;
103
104