]> git.proxmox.com Git - pve-network.git/commitdiff
move find_local_ip_interface sub helper to zone plugin
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 28 Nov 2019 08:40:27 +0000 (09:40 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Nov 2019 13:15:25 +0000 (14:15 +0100)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/SDN/Controllers/EvpnPlugin.pm
PVE/Network/SDN/Zones/EvpnPlugin.pm
PVE/Network/SDN/Zones/Plugin.pm
PVE/Network/SDN/Zones/VxlanPlugin.pm

index 66b4568ea680ed889787e73cbdb7e414c21f1d48..c8bf76a54a49ad2be4e3951f95a96f9c08103ff8 100644 (file)
@@ -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();
index 25c82c79b2330ba5c12bac31ad74d5b2190561a1..b9a941fb5043cfeb3f7639f3d76bf981f4a78a82 100644 (file)
@@ -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};
index 217ee65b9b98be6c290230c23dd125fa34cb3ecc..f84c1b2ac9aabd0f5ac21475561be8581bb538f1 100644 (file)
@@ -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;
index 66d8a954709b9952982575df0429f52437d7fd6b..e29e5404c78e7172e3bb4a2239631d96452ac808 100644 (file)
@@ -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};