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