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