]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/VxlanPlugin.pm
66d8a954709b9952982575df0429f52437d7fd6b
[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 };
40 }
41
42 # Plugin implementation
43 sub generate_sdn_config {
44 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
45
46 my $tag = $vnet->{tag};
47 my $alias = $vnet->{alias};
48 my $ipv4 = $vnet->{ipv4};
49 my $ipv6 = $vnet->{ipv6};
50 my $mac = $vnet->{mac};
51 my $multicastaddress = $plugin_config->{'multicast-address'};
52 my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
53
54 die "missing vxlan tag" if !$tag;
55
56 my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
57
58 my $mtu = 1450;
59 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
60 $mtu = $vnet->{mtu} if $vnet->{mtu};
61
62 #vxlan interface
63 my @iface_config = ();
64 push @iface_config, "vxlan-id $tag";
65
66 foreach my $address (@peers) {
67 next if $address eq $ifaceip;
68 push @iface_config, "vxlan_remoteip $address";
69 }
70
71 push @iface_config, "mtu $mtu" if $mtu;
72 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
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;
84 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
85
86 return $config;
87 }
88
89 1;
90
91