]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/VxlanPlugin.pm
evpn: remove uplink-id
[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;
7e720d4d 8
f5eabba0 9use base('PVE::Network::SDN::Zones::Plugin');
7e720d4d 10
6bffe819
AD
11PVE::JSONSchema::register_format('pve-sdn-vxlanrange', \&pve_verify_sdn_vxlanrange);
12sub pve_verify_sdn_vxlanrange {
7e720d4d
AD
13 my ($vxlanstr) = @_;
14
f5eabba0 15 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
7e720d4d
AD
16
17 return $vxlanstr;
18}
19
c692cbfa
AD
20PVE::JSONSchema::register_format('ipv4-multicast', \&parse_ipv4_multicast);
21sub parse_ipv4_multicast {
22 my ($ipv4, $noerr) = @_;
23
24 if ($ipv4 !~ m/^(?:$IPV4RE)$/) {
25 return undef if $noerr;
26 die "value does not look like a valid multicast IPv4 address\n";
27 }
28
29 if ($ipv4 =~ m/^(\d+)\.\d+.\d+.\d+/) {
30 if($1 < 224 || $1 > 239) {
31 return undef if $noerr;
32 die "value does not look like a valid multicast IPv4 address\n";
33 }
34 }
35
36 return $ipv4;
37}
38
7e720d4d 39sub type {
3ee45e4c 40 return 'vxlan';
7e720d4d
AD
41}
42
43sub properties {
44 return {
7e720d4d
AD
45 'multicast-address' => {
46 description => "Multicast address.",
c692cbfa 47 type => 'string', format => 'ipv4-multicast'
7e720d4d 48 },
3ee45e4c
AD
49 'unicast-address' => {
50 description => "Unicast peers address ip list.",
fcfca9ef 51 type => 'string', format => 'ip-list'
3ee45e4c 52 },
7e720d4d
AD
53 };
54}
55
56sub options {
57
58 return {
c2b9c173 59 nodes => { optional => 1},
85533e98 60 'uplink-id' => { optional => 0 },
3ee45e4c
AD
61 'multicast-address' => { optional => 1 },
62 'unicast-address' => { optional => 1 },
7e720d4d
AD
63 };
64}
65
66# Plugin implementation
6bffe819 67sub generate_sdn_config {
4405f2de 68 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
7e720d4d
AD
69
70 my $tag = $vnet->{tag};
dc7e431e 71 my $alias = $vnet->{alias};
5b31292c
AD
72 my $ipv4 = $vnet->{ipv4};
73 my $ipv6 = $vnet->{ipv6};
74 my $mac = $vnet->{mac};
7e720d4d 75 my $multicastaddress = $plugin_config->{'multicast-address'};
3ee45e4c
AD
76 my @unicastaddress = split(',', $plugin_config->{'unicast-address'}) if $plugin_config->{'unicast-address'};
77
7e720d4d 78 my $uplink = $plugin_config->{'uplink-id'};
7e720d4d
AD
79
80 die "missing vxlan tag" if !$tag;
3ee45e4c
AD
81 my $iface = "uplink$uplink";
82 my $ifaceip = "";
83
84 if($uplinks->{$uplink}->{name}) {
85 $iface = $uplinks->{$uplink}->{name};
f5eabba0 86 $ifaceip = PVE::Network::SDN::Zones::Plugin::get_first_local_ipv4_from_interface($iface);
3ee45e4c 87 }
c1ae8486
AD
88
89 my $mtu = 1450;
90 $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu};
91 $mtu = $vnet->{mtu} if $vnet->{mtu};
7e720d4d 92
93dea3aa
AD
93 #vxlan interface
94 my @iface_config = ();
95 push @iface_config, "vxlan-id $tag";
3ee45e4c
AD
96
97 if($multicastaddress) {
93dea3aa
AD
98 push @iface_config, "vxlan-svcnodeip $multicastaddress";
99 push @iface_config, "vxlan-physdev $iface";
3ee45e4c
AD
100 } elsif (@unicastaddress) {
101
102 foreach my $address (@unicastaddress) {
103 next if $address eq $ifaceip;
93dea3aa 104 push @iface_config, "vxlan_remoteip $address";
3ee45e4c 105 }
3ee45e4c
AD
106 }
107
93dea3aa 108 push @iface_config, "mtu $mtu" if $mtu;
87d8b623 109 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
93dea3aa
AD
110
111 #vnet bridge
112 @iface_config = ();
113 push @iface_config, "address $ipv4" if $ipv4;
114 push @iface_config, "address $ipv6" if $ipv6;
115 push @iface_config, "hwaddress $mac" if $mac;
116 push @iface_config, "bridge_ports vxlan$vnetid";
117 push @iface_config, "bridge_stp off";
118 push @iface_config, "bridge_fd 0";
119 push @iface_config, "mtu $mtu" if $mtu;
120 push @iface_config, "alias $alias" if $alias;
87d8b623 121 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
126fc68c 122
7e720d4d
AD
123 return $config;
124}
125
1261;
127
128