[pve-devel] [PATCH pve-container 4/6] debian setup: dhcp, manual and unmanaged network

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jul 24 09:14:56 CEST 2015


---
 src/PVE/LXCSetup/Debian.pm      | 48 ++++++++++++++++++++++++++++++-----------
 src/test/test-debian-002/config |  1 +
 src/test/test-debian-003/config |  1 +
 3 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/src/PVE/LXCSetup/Debian.pm b/src/PVE/LXCSetup/Debian.pm
index 21da86f..7635e08 100644
--- a/src/PVE/LXCSetup/Debian.pm
+++ b/src/PVE/LXCSetup/Debian.pm
@@ -113,24 +113,31 @@ sub setup_network {
 	if ($d->{name}) {
 	    my $net = {};
 	    if (defined($d->{ip})) {
-		my $ipinfo = PVE::LXC::parse_ipv4_cidr($d->{ip});
-		$net->{address} = $ipinfo->{address};
-		$net->{netmask} = $ipinfo->{netmask};
+		if ($d->{ip} =~ /^(?:dhcp|manual)$/) {
+		    $net->{address} = $d->{ip};
+		} else {
+		    my $ipinfo = PVE::LXC::parse_ipv4_cidr($d->{ip});
+		    $net->{address} = $ipinfo->{address};
+		    $net->{netmask} = $ipinfo->{netmask};
+		}
 	    }
 	    if (defined($d->{'gw'})) {
 		$net->{gateway} = $d->{'gw'};
 	    }
 	    if (defined($d->{ip6})) {
-		if ($d->{ip6} !~ /^($IPV6RE)\/(\d+)$/) {
+		if ($d->{ip6} =~ /^(?:dhcp|manual)$/) {
+		    $net->{address6} = $d->{ip6};
+		} elsif ($d->{ip6} !~ /^($IPV6RE)\/(\d+)$/) {
 		    die "unable to parse ipv6 address/prefix\n";
+		} else {
+		    $net->{address6} = $1;
+		    $net->{netmask6} = $2;
 		}
-		$net->{address6} = $1;
-		$net->{netmask6} = $2;
 	    }
 	    if (defined($d->{'gw6'})) {
 		$net->{gateway6} = $d->{'gw6'};
 	    }
-	    $networks->{$d->{name}} = $net;
+	    $networks->{$d->{name}} = $net if keys %$net;
 	}
     }
 
@@ -156,7 +163,9 @@ sub setup_network {
 
 	    $interfaces .= "auto $section->{ifname}\n" if $new;
 
-	    if ($net->{address}) {
+	    if ($net->{address} =~ /^(dhcp|manual)$/) {
+		$interfaces .= "iface $section->{ifname} inet $1\n";
+	    } elsif ($net->{address}) {
 		$interfaces .= "iface $section->{ifname} inet static\n";
 		$interfaces .= "\taddress $net->{address}\n" if defined($net->{address});
 		$interfaces .= "\tnetmask $net->{netmask}\n" if defined($net->{netmask});
@@ -164,8 +173,6 @@ sub setup_network {
 		foreach my $attr (@{$section->{attr}}) {
 		    $interfaces .= "\t$attr\n";
 		}
-	    } else {
-		$interfaces .= "iface $section->{ifname} inet manual\n";		
 	    }
 	    
 	    $interfaces .= "\n";
@@ -173,7 +180,9 @@ sub setup_network {
 	} elsif ($section->{type} eq 'ipv6') {
 	    $done_v6_hash->{$section->{ifname}} = 1;
 	    
-	    if ($net->{address6}) {
+	    if ($net->{address6} =~ /^(dhcp|manual)$/) {
+		$interfaces .= "iface $section->{ifname} inet6 $1\n";
+	    } elsif ($net->{address6}) {
 		$interfaces .= "iface $section->{ifname} inet6 static\n";
 		$interfaces .= "\taddress $net->{address6}\n" if defined($net->{address6});
 		$interfaces .= "\tnetmask $net->{netmask6}\n" if defined($net->{netmask6});
@@ -206,8 +215,9 @@ sub setup_network {
 		}
 		next;
 	    }
-	    if ($line =~ m/^iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
+	    if ($line =~ m/^\s*iface\s+(\S+)\s+inet\s+(\S+)\s*$/) {
 		my $ifname = $1;
+		&$print_section(); # print previous section
 		if (!$networks->{$ifname}) {
 		    $interfaces .= "$line\n";
 		    next;
@@ -215,8 +225,9 @@ sub setup_network {
 		$section = { type => 'ipv4', ifname => $ifname, attr => []};
 		next;
 	    }
-	    if ($line =~ m/^iface\s+(\S+)\s+inet6\s+(\S+)\s*$/) {
+	    if ($line =~ m/^\s*iface\s+(\S+)\s+inet6\s+(\S+)\s*$/) {
 		my $ifname = $1;
+		&$print_section(); # print previous section
 		if (!$networks->{$ifname}) {
 		    $interfaces .= "$line\n";
 		    next;
@@ -224,6 +235,17 @@ sub setup_network {
 		$section = { type => 'ipv6', ifname => $ifname, attr => []};
 		next;
 	    }
+	    # Handle other section delimiters:
+	    if ($line =~ m/^\s*(?:mapping\s
+	                         |auto\s
+	                         |allow-
+	                         |source\s
+	                         |source-directory\s
+	                       )/x) {
+	        &$print_section();
+	        $interfaces .= "$line\n";
+	        next;
+	    }
 	    if ($section && $line =~ m/^\s*((\S+)\s(.*))$/) {
 		my ($adata, $aname) = ($1, $2);
 		if ($aname eq 'address' || $aname eq 'netmask' ||
diff --git a/src/test/test-debian-002/config b/src/test/test-debian-002/config
index 73b98ff..cf54bcc 100644
--- a/src/test/test-debian-002/config
+++ b/src/test/test-debian-002/config
@@ -14,3 +14,4 @@ lxc.network.type = veth
 pve.network.bridge = vmbr0
 lxc.network.name = eth2
 lxc.network.veth.pair = veth100i2
+pve.network.ip = manual
diff --git a/src/test/test-debian-003/config b/src/test/test-debian-003/config
index c57b6cb..cf83d34 100644
--- a/src/test/test-debian-003/config
+++ b/src/test/test-debian-003/config
@@ -8,3 +8,4 @@ lxc.network.hwaddr = 26:2B:CC:E5:7F:F9
 pve.network.bridge = vmbr0
 lxc.network.name = eth0
 lxc.network.veth.pair = veth100.0
+pve.network.ip = manual
-- 
2.1.4





More information about the pve-devel mailing list