[pve-devel] [PATCH pve-network 4/4] move find_local_ip_interface sub helper to zone plugin
Alexandre Derumier
aderumier at odiso.com
Thu Nov 28 09:40:27 CET 2019
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Network/SDN/Controllers/EvpnPlugin.pm | 46 ++---------------------
PVE/Network/SDN/Zones/EvpnPlugin.pm | 2 +-
PVE/Network/SDN/Zones/Plugin.pm | 44 +++++++++++++++++++++-
PVE/Network/SDN/Zones/VxlanPlugin.pm | 2 +-
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};
--
2.20.1
More information about the pve-devel
mailing list