]> git.proxmox.com Git - pve-network.git/commitdiff
zones: vlan|qinq: add get_uplink_iface sub
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 28 Nov 2019 08:40:26 +0000 (09:40 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Nov 2019 13:15:25 +0000 (14:15 +0100)
also check that interface is eth or bond

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/SDN/Zones/Plugin.pm
PVE/Network/SDN/Zones/QinQPlugin.pm
PVE/Network/SDN/Zones/VlanPlugin.pm

index 4d0732e31a7589547fd7af485f34d2eff7a8887b..217ee65b9b98be6c290230c23dd125fa34cb3ecc 100644 (file)
@@ -179,4 +179,30 @@ sub parse_tag_number_or_range {
     return (scalar(@elements) > 1);
 }
 
+#helper
+
+sub get_uplink_iface {
+    my ($interfaces_config, $uplink) = @_;
+
+    my $iface = undef;
+    foreach my $id (keys %{$interfaces_config->{ifaces}}) {
+        my $interface = $interfaces_config->{ifaces}->{$id};
+        if (my $iface_uplink = $interface->{'uplink-id'}) {
+           next if $iface_uplink ne $uplink;
+            if($interface->{type} ne 'eth' && $interface->{type} ne 'bond') {
+                warn "uplink $uplink is not a physical or bond interface";
+                next;
+            }
+           $iface = $id;
+        }
+    }
+
+    #create a dummy uplink interface if no uplink found
+    if(!$iface) {
+        warn "can't find uplink $uplink in physical interface";
+        $iface = "uplink${uplink}";
+    }
+
+    return $iface;
+}
 1;
index 63f4528f5bb47f39fa28034020d085d9a9b20678..d36f0d8ffd98fffb855cc2dec5f49b68579f63e6 100644 (file)
@@ -50,19 +50,8 @@ sub generate_sdn_config {
     die "missing vlan tag" if !$tag;
     die "missing zone vlan tag" if !$zone_tag;
 
-    #check uplinks
-    my $uplinks = {};
-    foreach my $id (keys %{$interfaces_config->{ifaces}}) {
-       my $interface = $interfaces_config->{ifaces}->{$id};
-       if (my $uplink = $interface->{'uplink-id'}) {
-           die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
-           $interface->{name} = $id;
-           $uplinks->{$interface->{'uplink-id'}} = $interface;
-       }
-    }
+    my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink);
 
-    my $iface = $uplinks->{$uplink}->{name};
-    $iface = "uplink${uplink}" if !$iface;
     $iface .= ".$zone_tag";
 
     #tagged interface
index adb698f7e3c05ad53c36a0cc788a6f2c531dc924..63db8abb19067258f844c0306b982ddb1881570c 100644 (file)
@@ -48,19 +48,8 @@ sub generate_sdn_config {
 
     die "missing vlan tag" if !$tag;
 
-    #check uplinks
-    my $uplinks = {};
-    foreach my $id (keys %{$interfaces_config->{ifaces}}) {
-       my $interface = $interfaces_config->{ifaces}->{$id};
-       if (my $uplink = $interface->{'uplink-id'}) {
-           die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
-           $interface->{name} = $id;
-           $uplinks->{$interface->{'uplink-id'}} = $interface;
-        }
-    }
-
-    my $iface = $uplinks->{$uplink}->{name};
-    $iface = "uplink${uplink}" if !$iface;
+    my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink);
+
     $iface .= ".$tag";
 
     #tagged interface