summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Derumier <aderumier@odiso.com>2019-11-28 09:40:27 +0100
committerThomas Lamprecht <t.lamprecht@proxmox.com>2019-11-28 14:15:25 +0100
commit1f543c5f3c7b64cd2278e71a1480c8a3ce0b430f (patch)
treeb1bea2ec622d836707691210afdfce2cfbe81158
parent3794e4297275bc74d63ccb281601461ccb919ad6 (diff)
move find_local_ip_interface sub helper to zone plugin
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
-rw-r--r--PVE/Network/SDN/Controllers/EvpnPlugin.pm46
-rw-r--r--PVE/Network/SDN/Zones/EvpnPlugin.pm2
-rw-r--r--PVE/Network/SDN/Zones/Plugin.pm44
-rw-r--r--PVE/Network/SDN/Zones/VxlanPlugin.pm2
4 files changed, 48 insertions, 46 deletions
diff --git a/PVE/Network/SDN/Controllers/EvpnPlugin.pm b/PVE/Network/SDN/Controllers/EvpnPlugin.pm
index 66b4568..c8bf76a 100644
--- a/PVE/Network/SDN/Controllers/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Controllers/EvpnPlugin.pm
@@ -3,10 +3,10 @@ package PVE::Network::SDN::Controllers::EvpnPlugin;
use strict;
use warnings;
use PVE::Network::SDN::Controllers::Plugin;
-use PVE::Tools qw(run_command);
+use PVE::Tools;
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
-
+use PVE::Network::SDN::Zones::Plugin;
use base('PVE::Network::SDN::Controllers::Plugin');
sub type {
@@ -41,46 +41,6 @@ sub options {
};
}
-sub get_local_route_ip {
- my ($targetip) = @_;
-
- my $ip = undef;
- my $interface = undef;
-
- run_command(['/sbin/ip', 'route', 'get', $targetip], outfunc => sub {
- if ($_[0] =~ m/src ($PVE::Tools::IPRE)/) {
- $ip = $1;
- }
- if ($_[0] =~ m/dev (\S+)/) {
- $interface = $1;
- }
-
- });
- return ($ip, $interface);
-}
-
-sub find_local_ip_interface {
- my ($peers) = @_;
-
- my $network_config = PVE::INotify::read_file('interfaces');
- my $ifaces = $network_config->{ifaces};
- #is a local ip member of peers list ?
- foreach my $address (@{$peers}) {
- while (my $interface = each %$ifaces) {
- my $ip = $ifaces->{$interface}->{address};
- if ($ip && $ip eq $address) {
- return ($ip, $interface);
- }
- }
- }
-
- #if peer is remote, find source with ip route
- foreach my $address (@{$peers}) {
- my ($ip, $interface) = get_local_route_ip($address);
- return ($ip, $interface);
- }
-}
-
# Plugin implementation
sub generate_controller_config {
my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
@@ -93,7 +53,7 @@ sub generate_controller_config {
return if !$asn;
- my ($ifaceip, $interface) = find_local_ip_interface(\@peers);
+ my ($ifaceip, $interface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
my $is_gateway = undef;
my $local_node = PVE::INotify::nodename();
diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/EvpnPlugin.pm
index 25c82c7..b9a941f 100644
--- a/PVE/Network/SDN/Zones/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm
@@ -51,7 +51,7 @@ sub generate_sdn_config {
die "missing vxlan tag" if !$tag;
my @peers = split(',', $controller->{'peers'});
- my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
+ my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
my $mtu = 1450;
$mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 217ee65..f84c1b2 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -3,7 +3,7 @@ package PVE::Network::SDN::Zones::Plugin;
use strict;
use warnings;
-use PVE::Tools;
+use PVE::Tools qw(run_command);
use PVE::JSONSchema;
use PVE::Cluster;
@@ -205,4 +205,46 @@ sub get_uplink_iface {
return $iface;
}
+
+sub get_local_route_ip {
+ my ($targetip) = @_;
+
+ my $ip = undef;
+ my $interface = undef;
+
+ run_command(['/sbin/ip', 'route', 'get', $targetip], outfunc => sub {
+ if ($_[0] =~ m/src ($PVE::Tools::IPRE)/) {
+ $ip = $1;
+ }
+ if ($_[0] =~ m/dev (\S+)/) {
+ $interface = $1;
+ }
+
+ });
+ return ($ip, $interface);
+}
+
+
+sub find_local_ip_interface_peers {
+ my ($peers) = @_;
+
+ my $network_config = PVE::INotify::read_file('interfaces');
+ my $ifaces = $network_config->{ifaces};
+ #is a local ip member of peers list ?
+ foreach my $address (@{$peers}) {
+ while (my $interface = each %$ifaces) {
+ my $ip = $ifaces->{$interface}->{address};
+ if ($ip && $ip eq $address) {
+ return ($ip, $interface);
+ }
+ }
+ }
+
+ #if peer is remote, find source with ip route
+ foreach my $address (@{$peers}) {
+ my ($ip, $interface) = get_local_route_ip($address);
+ return ($ip, $interface);
+ }
+}
+
1;
diff --git a/PVE/Network/SDN/Zones/VxlanPlugin.pm b/PVE/Network/SDN/Zones/VxlanPlugin.pm
index 66d8a95..e29e540 100644
--- a/PVE/Network/SDN/Zones/VxlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VxlanPlugin.pm
@@ -53,7 +53,7 @@ sub generate_sdn_config {
die "missing vxlan tag" if !$tag;
- my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
+ my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
my $mtu = 1450;
$mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};