[pve-devel] [PATCH v4 pve-common 3/6] INotify: add vrf support

Alexandre Derumier aderumier at odiso.com
Wed Apr 3 00:18:31 CEST 2019


---
 src/PVE/INotify.pm | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index fe6cad8..0dae177 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -955,6 +955,8 @@ sub __read_etc_network_interfaces {
 			'bond_miimon' => 1,
 			'bond_xmit_hash_policy' => 1,
 			'uplink-id' => 1,
+			'vrf' => 1,
+			'vrf-table' => 1,
 			'vlan-protocol' => 1,
 			'vxlan-id' => 1,
 			'vxlan-svcnodeip' => 1,
@@ -1095,6 +1097,8 @@ sub __read_etc_network_interfaces {
 	} else {
 	    if ($d->{'vxlan-id'}) {
 		$d->{type} = 'vxlan';
+	    } elsif ($d->{'vrf-table'}) {
+		$d->{type} = 'vrfint';
 	    } elsif (!$d->{ovs_type}) {
 		$d->{type} = 'unknown';
 	    } elsif ($d->{ovs_type} eq 'OVSIntPort') {
@@ -1206,6 +1210,17 @@ sub __interface_to_string {
     } elsif ($d->{type} eq 'vlan') {
 	die "$iface: wrong vlan-protocol $d->{'vlan-protocol'}\n" 
 	    if $d->{'vlan-protocol'} && $d->{'vlan-protocol'} ne '802.1ad' && $d->{'vlan-protocol'} ne '802.1q';
+
+    } elsif ($d->{type} eq 'vrfint') {
+
+	my $vrftable = $d->{'vrf-table'};
+	if ($vrftable) {
+	    if ($vrftable =~ m/(\d+)$/) {
+		die "$iface: vrf-table $vrftable must be between 1001 and 1255" if ($vrftable < 1001 || $vrftable > 1255);
+	    } else {
+		die "$iface: vrf-table $vrftable need to be auto if no tableid is defined" if $vrftable ne 'auto';
+	    }
+	}
 	
     } elsif ($d->{type} eq 'vxlan') {
 
@@ -1457,6 +1472,16 @@ sub __write_etc_network_interfaces {
 	}
     }
 
+    # check vrf
+    my $vrfs = {};
+    foreach my $iface (keys %$ifaces) {
+	my $d = $ifaces->{$iface};
+	if ($d->{'type'} eq 'vrfint') {
+	    die "vrf $iface already exist" if $vrfs->{$iface};
+	    $vrfs->{$iface} = 1;
+	}
+    }
+
     # check uplink
     my $uplinks = {};
     foreach my $iface (keys %$ifaces) {
@@ -1501,6 +1526,8 @@ sub __write_etc_network_interfaces {
 	if ($d->{'bridge-access'} && !$bridges->{$bridgeports->{$iface}}->{bridge_vlan_aware}) {
 	    die "iface $iface - bridge-access option can be only used if interface is in a vlan aware bridge\n";
 	}
+
+	die "vrf $d->{vrf} don't exist" if $d->{vrf} && !$vrfs->{$d->{vrf}};
     }
 
     my $raw = <<'NETWORKDOC';
@@ -1528,6 +1555,7 @@ NETWORKDOC
 	bridge => 400000,
 	OVSBridge => 400000,
 	vxlan => 500000,
+	vrfint => 600000
    };
 
     my $lookup_type_prio = sub {
@@ -1536,7 +1564,6 @@ NETWORKDOC
 	my ($rootiface, @rest) = split(/[.:]/, $iface);
 	my $childlevel = scalar(@rest);
 	my $n = $ifaces->{$rootiface};
-
 	my $pri = $if_type_hash->{$n->{type}} + $childlevel
 	    if $n->{type} && $n->{type} ne 'unknown';
 
-- 
2.11.0




More information about the pve-devel mailing list