]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/VxlanPlugin.pm
vxlan: prefix interfaces
[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 },
823f2e2a 39 mtu => { optional => 1 },
7e720d4d
AD
40 };
41}
42
43# Plugin implementation
6bffe819 44sub generate_sdn_config {
ba7ac021 45 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
7e720d4d
AD
46
47 my $tag = $vnet->{tag};
dc7e431e 48 my $alias = $vnet->{alias};
5b31292c
AD
49 my $ipv4 = $vnet->{ipv4};
50 my $ipv6 = $vnet->{ipv6};
51 my $mac = $vnet->{mac};
7e720d4d 52 my $multicastaddress = $plugin_config->{'multicast-address'};
ba7ac021 53 my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
ff3088cb 54 my $vxlan_iface = "vxlan_$vnetid";
7e720d4d
AD
55
56 die "missing vxlan tag" if !$tag;
3ee45e4c 57
1f543c5f 58 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
c1ae8486
AD
59
60 my $mtu = 1450;
ba7ac021 61 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
0251ed2f 62 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
7e720d4d 63
93dea3aa
AD
64 #vxlan interface
65 my @iface_config = ();
66 push @iface_config, "vxlan-id $tag";
3ee45e4c 67
ba7ac021
AD
68 foreach my $address (@peers) {
69 next if $address eq $ifaceip;
70 push @iface_config, "vxlan_remoteip $address";
3ee45e4c
AD
71 }
72
ff3088cb 73
93dea3aa 74 push @iface_config, "mtu $mtu" if $mtu;
ff3088cb 75 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
93dea3aa
AD
76
77 #vnet bridge
78 @iface_config = ();
79 push @iface_config, "address $ipv4" if $ipv4;
80 push @iface_config, "address $ipv6" if $ipv6;
81 push @iface_config, "hwaddress $mac" if $mac;
ff3088cb 82 push @iface_config, "bridge_ports $vxlan_iface";
93dea3aa
AD
83 push @iface_config, "bridge_stp off";
84 push @iface_config, "bridge_fd 0";
85 push @iface_config, "mtu $mtu" if $mtu;
86 push @iface_config, "alias $alias" if $alias;
87d8b623 87 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
126fc68c 88
7e720d4d
AD
89 return $config;
90}
91
921;
93
94