]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/VxlanPlugin.pm
zones: vxlan : remove uplink-id and multicast
[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;
7e720d4d 9
f5eabba0 10use base('PVE::Network::SDN::Zones::Plugin');
7e720d4d 11
6bffe819
AD
12PVE::JSONSchema::register_format('pve-sdn-vxlanrange', \&pve_verify_sdn_vxlanrange);
13sub pve_verify_sdn_vxlanrange {
7e720d4d
AD
14 my ($vxlanstr) = @_;
15
f5eabba0 16 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
7e720d4d
AD
17
18 return $vxlanstr;
19}
20
21sub type {
3ee45e4c 22 return 'vxlan';
7e720d4d
AD
23}
24
25sub properties {
26 return {
ba7ac021
AD
27 'peers' => {
28 description => "peers address list.",
29 type => 'string', format => 'ip-list'
7e720d4d 30 },
7e720d4d
AD
31 };
32}
33
34sub options {
35
36 return {
c2b9c173 37 nodes => { optional => 1},
ba7ac021 38 peers => { optional => 0 },
7e720d4d
AD
39 };
40}
41
42# Plugin implementation
6bffe819 43sub generate_sdn_config {
ba7ac021 44 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
7e720d4d
AD
45
46 my $tag = $vnet->{tag};
dc7e431e 47 my $alias = $vnet->{alias};
5b31292c
AD
48 my $ipv4 = $vnet->{ipv4};
49 my $ipv6 = $vnet->{ipv6};
50 my $mac = $vnet->{mac};
7e720d4d 51 my $multicastaddress = $plugin_config->{'multicast-address'};
ba7ac021 52 my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
7e720d4d
AD
53
54 die "missing vxlan tag" if !$tag;
3ee45e4c 55
ba7ac021 56 my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
c1ae8486
AD
57
58 my $mtu = 1450;
ba7ac021 59 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
c1ae8486 60 $mtu = $vnet->{mtu} if $vnet->{mtu};
7e720d4d 61
93dea3aa
AD
62 #vxlan interface
63 my @iface_config = ();
64 push @iface_config, "vxlan-id $tag";
3ee45e4c 65
ba7ac021
AD
66 foreach my $address (@peers) {
67 next if $address eq $ifaceip;
68 push @iface_config, "vxlan_remoteip $address";
3ee45e4c
AD
69 }
70
93dea3aa 71 push @iface_config, "mtu $mtu" if $mtu;
87d8b623 72 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
93dea3aa
AD
73
74 #vnet bridge
75 @iface_config = ();
76 push @iface_config, "address $ipv4" if $ipv4;
77 push @iface_config, "address $ipv6" if $ipv6;
78 push @iface_config, "hwaddress $mac" if $mac;
79 push @iface_config, "bridge_ports vxlan$vnetid";
80 push @iface_config, "bridge_stp off";
81 push @iface_config, "bridge_fd 0";
82 push @iface_config, "mtu $mtu" if $mtu;
83 push @iface_config, "alias $alias" if $alias;
87d8b623 84 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
126fc68c 85
7e720d4d
AD
86 return $config;
87}
88
891;
90
91