[pve-devel] [PATCH container] fix #1134: debian: don't start empty interface sections

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Oct 3 09:41:19 CEST 2016


While a completely unconfigured network interface is
considered manually managed, one that contains an ipv4 _or_
an ipv6 address needs to remove sections with no configured
address rather than printing the 'iface' section header with
no content.
---
 src/PVE/LXC/Setup/Debian.pm                        | 19 +++++++++---------
 src/test/test-debian-006/config                    |  4 +++-
 src/test/test-debian-006/etc/hosts.exp             |  2 +-
 src/test/test-debian-006/etc/network/interfaces    | 23 ++++++++++++++++++++++
 .../test-debian-006/etc/network/interfaces.exp     | 15 ++++++++++++++
 5 files changed, 52 insertions(+), 11 deletions(-)
 create mode 100644 src/test/test-debian-006/etc/network/interfaces
 create mode 100644 src/test/test-debian-006/etc/network/interfaces.exp

diff --git a/src/PVE/LXC/Setup/Debian.pm b/src/PVE/LXC/Setup/Debian.pm
index e927c37..e1749de 100644
--- a/src/PVE/LXC/Setup/Debian.pm
+++ b/src/PVE/LXC/Setup/Debian.pm
@@ -209,8 +209,10 @@ sub setup_network {
 	if ($section->{type} eq 'ipv4') {
 	    $done_v4_hash->{$ifname} = 1;
 
-	    if (defined($net->{address}) && $net->{address} =~ /^(dhcp|manual)$/) {
-		$interfaces .= "iface $ifname inet $1\n";
+	    if (!defined($net->{address})) {
+		# no address => no iface line
+	    } elsif ($net->{address} =~ /^(dhcp|manual)$/) {
+		$interfaces .= "iface $ifname inet $1\n\n";
 	    } else {
 		$interfaces .= "iface $ifname inet static\n";
 		$interfaces .= "\taddress $net->{address}\n" if defined($net->{address});
@@ -227,15 +229,15 @@ sub setup_network {
 		foreach my $attr (@{$section->{attr}}) {
 		    $interfaces .= "\t$attr\n";
 		}
+		$interfaces .= "\n";
 	    }
-
-	    $interfaces .= "\n";
-
 	} elsif ($section->{type} eq 'ipv6') {
 	    $done_v6_hash->{$ifname} = 1;
 
-	    if (defined($net->{address6}) && $net->{address6} =~ /^(auto|dhcp|manual)$/) {
-		$interfaces .= "iface $ifname inet6 $1\n";
+	    if (!defined($net->{address6})) {
+		# no address => no iface line
+	    } elsif ($net->{address6} =~ /^(auto|dhcp|manual)$/) {
+		$interfaces .= "iface $ifname inet6 $1\n\n";
 	    } else {
 		$interfaces .= "iface $ifname inet6 static\n";
 		$interfaces .= "\taddress $net->{address6}\n" if defined($net->{address6});
@@ -251,9 +253,8 @@ sub setup_network {
 		foreach my $attr (@{$section->{attr}}) {
 		    $interfaces .= "\t$attr\n";
 		}
+		$interfaces .= "\n";
 	    }
-
-	    $interfaces .= "\n";
 	} else {
 	    die "unknown section type '$section->{type}'";
 	}
diff --git a/src/test/test-debian-006/config b/src/test/test-debian-006/config
index 3ad4192..7041053 100644
--- a/src/test/test-debian-006/config
+++ b/src/test/test-debian-006/config
@@ -1,2 +1,4 @@
 hostname: test1
-tty: 0
\ No newline at end of file
+tty: 0
+net0: bridge=vmbr0,name=eth0,ip=1.2.3.4/24
+net1: bridge=vmbr1,name=eth1,ip6=1234::1/64
diff --git a/src/test/test-debian-006/etc/hosts.exp b/src/test/test-debian-006/etc/hosts.exp
index c0dd46e..01ac197 100644
--- a/src/test/test-debian-006/etc/hosts.exp
+++ b/src/test/test-debian-006/etc/hosts.exp
@@ -1,5 +1,5 @@
 # --- BEGIN PVE ---
 127.0.0.1 localhost.localnet localhost
 ::1 localhost.localnet localhost
-127.0.1.1 test1
+1.2.3.4 test1.proxmox.com test1
 # --- END PVE ---
diff --git a/src/test/test-debian-006/etc/network/interfaces b/src/test/test-debian-006/etc/network/interfaces
new file mode 100644
index 0000000..d84f213
--- /dev/null
+++ b/src/test/test-debian-006/etc/network/interfaces
@@ -0,0 +1,23 @@
+# Scenario:
+#  An address was previously configured but then removed.
+
+# ipv6 removed
+auto eth0
+iface eth0 inet static
+	address 1.2.3.4
+	netmask 255.255.255.0
+
+iface eth0 inet6 static
+	address fc00::1
+	netmask 64
+
+# ipv4 removed
+auto eth1
+iface eth1 inet static
+	address 2.3.4.5
+	netmask 255.255.255.0
+
+iface eth1 inet6 static
+	address 1234::1
+	netmask 64
+
diff --git a/src/test/test-debian-006/etc/network/interfaces.exp b/src/test/test-debian-006/etc/network/interfaces.exp
new file mode 100644
index 0000000..c16c07b
--- /dev/null
+++ b/src/test/test-debian-006/etc/network/interfaces.exp
@@ -0,0 +1,15 @@
+# Scenario:
+#  An address was previously configured but then removed.
+
+# ipv6 removed
+auto eth0
+iface eth0 inet static
+	address 1.2.3.4
+	netmask 255.255.255.0
+
+# ipv4 removed
+auto eth1
+iface eth1 inet6 static
+	address 1234::1
+	netmask 64
+
-- 
2.1.4





More information about the pve-devel mailing list