mirror of
https://git.proxmox.com/git/pve-network
synced 2025-08-11 20:26:26 +00:00
make Vxlanplugin generic for multicast/unicast/frr
if no multicast or unicast address is defined, default to frr Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
parent
0022a9189e
commit
3ee45e4ce1
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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,8 +76,24 @@ 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";
|
Loading…
Reference in New Issue
Block a user