]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/VxlanPlugin.pm
zones: simple|evpn: add gateway ip from subnets to vnet
[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;
1d44ce70 9use PVE::Exception qw(raise raise_param_exc);
7e720d4d 10
f5eabba0 11use base('PVE::Network::SDN::Zones::Plugin');
7e720d4d 12
6bffe819
AD
13PVE::JSONSchema::register_format('pve-sdn-vxlanrange', \&pve_verify_sdn_vxlanrange);
14sub pve_verify_sdn_vxlanrange {
7e720d4d
AD
15 my ($vxlanstr) = @_;
16
f5eabba0 17 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
7e720d4d
AD
18
19 return $vxlanstr;
20}
21
22sub type {
3ee45e4c 23 return 'vxlan';
7e720d4d
AD
24}
25
26sub properties {
27 return {
ba7ac021
AD
28 'peers' => {
29 description => "peers address list.",
30 type => 'string', format => 'ip-list'
7e720d4d 31 },
7e720d4d
AD
32 };
33}
34
35sub options {
36
37 return {
c2b9c173 38 nodes => { optional => 1},
ba7ac021 39 peers => { optional => 0 },
823f2e2a 40 mtu => { optional => 1 },
7e720d4d
AD
41 };
42}
43
44# Plugin implementation
6bffe819 45sub generate_sdn_config {
7024ec2b 46 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
7e720d4d
AD
47
48 my $tag = $vnet->{tag};
dc7e431e 49 my $alias = $vnet->{alias};
7e720d4d 50 my $multicastaddress = $plugin_config->{'multicast-address'};
3caa7687
FG
51 my @peers;
52 @peers = PVE::Tools::split_list($plugin_config->{'peers'}) if $plugin_config->{'peers'};
ff3088cb 53 my $vxlan_iface = "vxlan_$vnetid";
7e720d4d
AD
54
55 die "missing vxlan tag" if !$tag;
3ee45e4c 56
1f543c5f 57 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
c1ae8486
AD
58
59 my $mtu = 1450;
ba7ac021 60 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
0251ed2f 61 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
7e720d4d 62
93dea3aa
AD
63 #vxlan interface
64 my @iface_config = ();
65 push @iface_config, "vxlan-id $tag";
3ee45e4c 66
ba7ac021
AD
67 foreach my $address (@peers) {
68 next if $address eq $ifaceip;
69 push @iface_config, "vxlan_remoteip $address";
3ee45e4c
AD
70 }
71
ff3088cb 72
93dea3aa 73 push @iface_config, "mtu $mtu" if $mtu;
ff3088cb 74 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
93dea3aa
AD
75
76 #vnet bridge
77 @iface_config = ();
ff3088cb 78 push @iface_config, "bridge_ports $vxlan_iface";
93dea3aa
AD
79 push @iface_config, "bridge_stp off";
80 push @iface_config, "bridge_fd 0";
912fb443
AD
81 if($vnet->{vlanaware}) {
82 push @iface_config, "bridge-vlan-aware yes";
83 push @iface_config, "bridge-vids 2-4094";
84 }
93dea3aa
AD
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
1d44ce70
AD
92sub verify_tag {
93 my ($class, $tag) = @_;
94
95 raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
96 raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
97}
98
7e720d4d
AD
991;
100
101