if no multicast or unicast address is defined, default to frr Signed-off-by: Alexandre Derumier <aderum...@odiso.com> --- PVE/API2/Network/SDN.pm | 2 +- PVE/Network/SDN.pm | 4 +- PVE/Network/SDN/Makefile | 2 +- PVE/Network/SDN/Plugin.pm | 22 ++++++++ ...VxlanMulticastPlugin.pm => VxlanPlugin.pm} | 53 ++++++++++++++----- 5 files changed, 67 insertions(+), 16 deletions(-) rename PVE/Network/SDN/{VxlanMulticastPlugin.pm => VxlanPlugin.pm} (66%)
diff --git a/PVE/API2/Network/SDN.pm b/PVE/API2/Network/SDN.pm index 7baf7ee..22b26f8 100644 --- a/PVE/API2/Network/SDN.pm +++ b/PVE/API2/Network/SDN.pm @@ -9,7 +9,7 @@ use PVE::Cluster qw(cfs_read_file cfs_write_file); use PVE::Network::SDN; use PVE::Network::SDN::Plugin; use PVE::Network::SDN::VlanPlugin; -use PVE::Network::SDN::VxlanMulticastPlugin; +use PVE::Network::SDN::VxlanPlugin; use PVE::Network::SDN::VnetPlugin; use Storable qw(dclone); use PVE::JSONSchema qw(get_standard_option); diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm index 1b1529b..1b060e7 100644 --- a/PVE/Network/SDN.pm +++ b/PVE/Network/SDN.pm @@ -11,11 +11,11 @@ use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); use PVE::Network::SDN::Plugin; use PVE::Network::SDN::VnetPlugin; use PVE::Network::SDN::VlanPlugin; -use PVE::Network::SDN::VxlanMulticastPlugin; +use PVE::Network::SDN::VxlanPlugin; PVE::Network::SDN::VnetPlugin->register(); PVE::Network::SDN::VlanPlugin->register(); -PVE::Network::SDN::VxlanMulticastPlugin->register(); +PVE::Network::SDN::VxlanPlugin->register(); PVE::Network::SDN::Plugin->init(); diff --git a/PVE/Network/SDN/Makefile b/PVE/Network/SDN/Makefile index 194a708..19a8e35 100644 --- a/PVE/Network/SDN/Makefile +++ b/PVE/Network/SDN/Makefile @@ -1,4 +1,4 @@ -SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanMulticastPlugin.pm +SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm PERL5DIR=${DESTDIR}/usr/share/perl5 diff --git a/PVE/Network/SDN/Plugin.pm b/PVE/Network/SDN/Plugin.pm index a76442b..36efbe1 100644 --- a/PVE/Network/SDN/Plugin.pm +++ b/PVE/Network/SDN/Plugin.pm @@ -121,4 +121,26 @@ sub parse_tag_number_or_range { return (scalar(@elements) > 1); } +#to be move to Network.pm helper +sub get_first_local_ipv4_from_interface { + my ($interface) = @_; + + my $cmd = ['/sbin/ip', 'address', 'show', 'dev', $interface]; + + my $IP = ""; + + my $code = sub { + my $line = shift; + + if ($line =~ m!^\s*inet\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) { + $IP = $1; + return; + } + }; + + PVE::Tools::run_command($cmd, outfunc => $code); + + return $IP; +} + 1; diff --git a/PVE/Network/SDN/VxlanMulticastPlugin.pm b/PVE/Network/SDN/VxlanPlugin.pm similarity index 66% rename from PVE/Network/SDN/VxlanMulticastPlugin.pm rename to PVE/Network/SDN/VxlanPlugin.pm index ac60734..ae1f86a 100644 --- a/PVE/Network/SDN/VxlanMulticastPlugin.pm +++ b/PVE/Network/SDN/VxlanPlugin.pm @@ -1,8 +1,9 @@ -package PVE::Network::SDN::VxlanMulticastPlugin; +package PVE::Network::SDN::VxlanPlugin; use strict; use warnings; use PVE::Network::SDN::Plugin; +use PVE::Tools; use base('PVE::Network::SDN::Plugin'); @@ -16,7 +17,7 @@ sub pve_verify_sdn_vxlanrange { } sub type { - return 'vxlanmulticast'; + return 'vxlan'; } sub properties { @@ -29,7 +30,10 @@ sub properties { description => "Multicast address.", type => 'string', #fixme: format }, - + 'unicast-address' => { + description => "Unicast peers address ip list.", + type => 'string', #fixme: format + }, }; } @@ -37,7 +41,8 @@ sub options { return { 'uplink-id' => { optional => 0 }, - 'multicast-address' => { optional => 0 }, + 'multicast-address' => { optional => 1 }, + 'unicast-address' => { optional => 1 }, 'vxlan-allowed' => { optional => 1 }, }; } @@ -49,11 +54,19 @@ sub generate_sdn_config { my $tag = $vnet->{tag}; my $alias = $vnet->{alias}; my $multicastaddress = $plugin_config->{'multicast-address'}; + my @unicastaddress = split(',', $plugin_config->{'unicast-address'}) if $plugin_config->{'unicast-address'}; + my $uplink = $plugin_config->{'uplink-id'}; my $vxlanallowed = $plugin_config->{'vxlan-allowed'}; die "missing vxlan tag" if !$tag; - my $iface = $uplinks->{$uplink}->{name} ? $uplinks->{$uplink}->{name} : "uplink$uplink"; + my $iface = "uplink$uplink"; + my $ifaceip = ""; + + if($uplinks->{$uplink}->{name}) { + $iface = $uplinks->{$uplink}->{name}; + $ifaceip = PVE::Network::SDN::Plugin::get_first_local_ipv4_from_interface($iface); + } my $mtu = 1450; $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu}; @@ -63,17 +76,33 @@ sub generate_sdn_config { $config .= "auto vxlan$vnetid\n"; $config .= "iface vxlan$vnetid inet manual\n"; $config .= " vxlan-id $tag\n"; - $config .= " vxlan-svcnodeip $multicastaddress\n" if $multicastaddress; - $config .= " vxlan-physdev $iface\n" if $iface; + + if($multicastaddress) { + $config .= " vxlan-svcnodeip $multicastaddress\n"; + $config .= " vxlan-physdev $iface\n"; + } elsif (@unicastaddress) { + + foreach my $address (@unicastaddress) { + next if $address eq $ifaceip; + $config .= " vxlan_remoteip $address\n"; + } + } else { + $config .= " vxlan-local-tunnelip $ifaceip\n" if $ifaceip; + $config .= " bridge-learning off\n"; + $config .= " bridge-arp-nd-suppress on\n"; + $config .= " bridge-unicast-flood off\n"; + $config .= " bridge-multicast-flood off\n"; + } + $config .= " mtu $mtu\n" if $mtu; $config .= "\n"; $config .= "auto $vnetid\n"; $config .= "iface $vnetid inet manual\n"; - $config .= " bridge_ports vxlan$vnetid\n"; - $config .= " bridge_stp off\n"; - $config .= " bridge_fd 0\n"; - $config .= " mtu $mtu\n" if $mtu; - $config .= " alias $alias\n" if $alias; + $config .= " bridge_ports vxlan$vnetid\n"; + $config .= " bridge_stp off\n"; + $config .= " bridge_fd 0\n"; + $config .= " mtu $mtu\n" if $mtu; + $config .= " alias $alias\n" if $alias; return $config; } -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel