[pve-devel] [PATCH container 1/3] setup: deal with link-local gateways

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Apr 25 16:20:41 CEST 2016


We used to write out special routes for gateways outside the
IP address' subnet, but link-local addresses don't need the
extra route.
---
 src/PVE/LXC/Setup/Base.pm                          |  3 ++-
 src/PVE/LXC/Setup/CentOS.pm                        |  3 ++-
 src/PVE/LXC/Setup/Debian.pm                        |  3 ++-
 src/PVE/LXC/Setup/SUSE.pm                          |  3 ++-
 src/test/test-centos6-002/config                   |  3 +++
 src/test/test-centos6-002/etc/rc.d/rc.sysinit      |  6 ++++++
 src/test/test-centos6-002/etc/redhat-release       |  1 +
 src/test/test-centos6-002/etc/securetty            | 23 ++++++++++++++++++++++
 src/test/test-centos6-002/etc/sysconfig/network    |  0
 .../etc/sysconfig/network-scripts/ifcfg-eth0.exp   | 10 ++++++++++
 .../etc/sysconfig/network-scripts/ifcfg-eth1.exp   |  7 +++++++
 .../etc/sysconfig/network-scripts/route-eth0.exp   |  6 ++++++
 .../test-centos6-002/etc/sysconfig/network.exp     |  3 +++
 .../test-centos6-002/root/.ssh/authorized_keys.exp |  3 +++
 src/test/test-debian-012/config                    |  1 +
 .../test-debian-012/etc/network/interfaces.exp     |  6 ++++++
 src/test/test-opensuse-002/config                  |  3 ++-
 .../etc/sysconfig/network/ifcfg-eth3.exp           |  3 +++
 .../etc/sysconfig/network/ifroute-eth0.exp         |  3 ++-
 .../etc/sysconfig/network/ifroute-eth3.exp         |  3 +++
 20 files changed, 87 insertions(+), 6 deletions(-)
 create mode 100644 src/test/test-centos6-002/config
 create mode 100644 src/test/test-centos6-002/etc/rc.d/rc.sysinit
 create mode 100644 src/test/test-centos6-002/etc/redhat-release
 create mode 100644 src/test/test-centos6-002/etc/securetty
 create mode 100644 src/test/test-centos6-002/etc/sysconfig/network
 create mode 100644 src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth0.exp
 create mode 100644 src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth1.exp
 create mode 100644 src/test/test-centos6-002/etc/sysconfig/network-scripts/route-eth0.exp
 create mode 100644 src/test/test-centos6-002/etc/sysconfig/network.exp
 create mode 100644 src/test/test-centos6-002/root/.ssh/authorized_keys.exp
 create mode 100644 src/test/test-opensuse-002/etc/sysconfig/network/ifcfg-eth3.exp
 create mode 100644 src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth3.exp

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index 12c60ff..d781153 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -261,7 +261,8 @@ DATA
 	}
 	if (defined(my $gw = $d->{gw6})) {
 	    $data .= "Gateway = $gw\n";
-	    if ($has_ipv6 && !PVE::Network::is_ip_in_cidr($gw, $d->{ip6}, 6)) {
+	    if ($has_ipv6 && !PVE::Network::is_ip_in_cidr($gw, $d->{ip6}, 6) &&
+		!PVE::Network::is_ip_in_cidr($gw, 'fe80::/10', 6)) {
 		$routes .= "\n[Route]\nDestination = $gw/128\nScope = link\n";
 	    }
 	}
diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index be30ca6..c0330c2 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -215,7 +215,8 @@ sub setup_network {
 		$data .= "IPV6ADDR=$d->{ip6}\n";
 		if (defined($d->{gw6})) {
 		    $data .= "IPV6_DEFAULTGW=$d->{gw6}\n";
-		    if (!PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6)) {
+		    if (!PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6) &&
+			!PVE::Network::is_ip_in_cidr($d->{gw6}, 'fe80::/10', 6)) {
 			$routes .= "$d->{gw6} dev $d->{name}\n";
 			$routes .= "default via $d->{gw6}\n";
 		    }
diff --git a/src/PVE/LXC/Setup/Debian.pm b/src/PVE/LXC/Setup/Debian.pm
index 4dae668..299e2d5 100644
--- a/src/PVE/LXC/Setup/Debian.pm
+++ b/src/PVE/LXC/Setup/Debian.pm
@@ -161,7 +161,8 @@ sub setup_network {
 	    }
 	    if (defined($d->{'gw6'})) {
 		$net->{gateway6} = $d->{'gw6'};
-		if (defined($cidr) && !PVE::Network::is_ip_in_cidr($d->{gw6}, $cidr, 6)) {
+		if (defined($cidr) && !PVE::Network::is_ip_in_cidr($d->{gw6}, $cidr, 6) &&
+		    !PVE::Network::is_ip_in_cidr($d->{gw6}, 'fe80::/10', 6)) {
 		    # gateway is not reachable, need an extra route
 		    $net->{needsroute6} = 1;
 		}
diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm
index 2529f2c..c511ab6 100644
--- a/src/PVE/LXC/Setup/SUSE.pm
+++ b/src/PVE/LXC/Setup/SUSE.pm
@@ -98,7 +98,8 @@ sub setup_network {
 	    } else {
 		push @addrs, $d->{ip6};
 		if (defined($d->{gw6})) {
-		    if (!PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6)) {
+		    if (!PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6) &&
+		        !PVE::Network::is_ip_in_cidr($d->{gw6}, 'fe80::/10', 6)) {
 			$routes .= "$d->{gw6}/128 - - $d->{name}\n";
 		    }
 		    $routes .= "default $d->{gw6} - $d->{name}\n";
diff --git a/src/test/test-centos6-002/config b/src/test/test-centos6-002/config
new file mode 100644
index 0000000..e159341
--- /dev/null
+++ b/src/test/test-centos6-002/config
@@ -0,0 +1,3 @@
+hostname: test2
+net0: bridge=vmbr0,name=eth0,ip=1.2.3.4/24,gw=4.3.2.1,ip6=2000::1/64,gw6=20ff::1
+net1: bridge=vmbr0,name=eth1,ip6=2222::1/64,gw6=fe80::1
diff --git a/src/test/test-centos6-002/etc/rc.d/rc.sysinit b/src/test/test-centos6-002/etc/rc.d/rc.sysinit
new file mode 100644
index 0000000..a98b7dd
--- /dev/null
+++ b/src/test/test-centos6-002/etc/rc.d/rc.sysinit
@@ -0,0 +1,6 @@
+# just a test
+# dummy
+
+/sbin/start_udev xxxxxxxxxxyyyyyyzzzz
+
+
diff --git a/src/test/test-centos6-002/etc/redhat-release b/src/test/test-centos6-002/etc/redhat-release
new file mode 100644
index 0000000..cdb73e8
--- /dev/null
+++ b/src/test/test-centos6-002/etc/redhat-release
@@ -0,0 +1 @@
+CentOS release 6.3 (Final)
diff --git a/src/test/test-centos6-002/etc/securetty b/src/test/test-centos6-002/etc/securetty
new file mode 100644
index 0000000..fae1648
--- /dev/null
+++ b/src/test/test-centos6-002/etc/securetty
@@ -0,0 +1,23 @@
+console
+vc/1
+vc/2
+vc/3
+vc/4
+vc/5
+vc/6
+vc/7
+vc/8
+vc/9
+vc/10
+vc/11
+tty1
+tty2
+tty3
+tty4
+tty5
+tty6
+tty7
+tty8
+tty9
+tty10
+tty11
\ No newline at end of file
diff --git a/src/test/test-centos6-002/etc/sysconfig/network b/src/test/test-centos6-002/etc/sysconfig/network
new file mode 100644
index 0000000..e69de29
diff --git a/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth0.exp b/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth0.exp
new file mode 100644
index 0000000..1935e20
--- /dev/null
+++ b/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth0.exp
@@ -0,0 +1,10 @@
+DEVICE=eth0
+ONBOOT=yes
+BOOTPROTO=none
+IPADDR=1.2.3.4
+NETMASK=255.255.255.0
+GATEWAY=4.3.2.1
+IPV6INIT=yes
+IPV6_AUTOCONF=no
+IPV6ADDR=2000::1/64
+IPV6_DEFAULTGW=20ff::1
diff --git a/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth1.exp b/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth1.exp
new file mode 100644
index 0000000..6b92947
--- /dev/null
+++ b/src/test/test-centos6-002/etc/sysconfig/network-scripts/ifcfg-eth1.exp
@@ -0,0 +1,7 @@
+DEVICE=eth1
+ONBOOT=yes
+BOOTPROTO=none
+IPV6INIT=yes
+IPV6_AUTOCONF=no
+IPV6ADDR=2222::1/64
+IPV6_DEFAULTGW=fe80::1
diff --git a/src/test/test-centos6-002/etc/sysconfig/network-scripts/route-eth0.exp b/src/test/test-centos6-002/etc/sysconfig/network-scripts/route-eth0.exp
new file mode 100644
index 0000000..6bf6cbb
--- /dev/null
+++ b/src/test/test-centos6-002/etc/sysconfig/network-scripts/route-eth0.exp
@@ -0,0 +1,6 @@
+# --- BEGIN PVE ---
+4.3.2.1 dev eth0
+default via 4.3.2.1
+20ff::1 dev eth0
+default via 20ff::1
+# --- END PVE ---
diff --git a/src/test/test-centos6-002/etc/sysconfig/network.exp b/src/test/test-centos6-002/etc/sysconfig/network.exp
new file mode 100644
index 0000000..442f399
--- /dev/null
+++ b/src/test/test-centos6-002/etc/sysconfig/network.exp
@@ -0,0 +1,3 @@
+NETWORKING=yes
+NETWORKING_IPV6=yes
+HOSTNAME=test2
diff --git a/src/test/test-centos6-002/root/.ssh/authorized_keys.exp b/src/test/test-centos6-002/root/.ssh/authorized_keys.exp
new file mode 100644
index 0000000..1cb3ec3
--- /dev/null
+++ b/src/test/test-centos6-002/root/.ssh/authorized_keys.exp
@@ -0,0 +1,3 @@
+# --- BEGIN PVE ---
+ssh-rsa ABCDEFG ABC at DEF
+# --- END PVE ---
diff --git a/src/test/test-debian-012/config b/src/test/test-debian-012/config
index 1aeb8c8..40be5a0 100644
--- a/src/test/test-debian-012/config
+++ b/src/test/test-debian-012/config
@@ -1,2 +1,3 @@
 net0: name=eth0,hwaddr=11:22:33:44:55:66,bridge=vmbr0,ip=10.0.0.100/32,gw=11.0.0.1
 net1: name=eth1,hwaddr=22:33:44:55:66:77,bridge=vmbr0,ip6=fc00::1/64,gw6=fc00:1::ff
+net2: name=eth2,hwaddr=33:44:55:66:77:88,bridge=vmbr2,ip6=fc02::1/64,gw6=fe80::1
diff --git a/src/test/test-debian-012/etc/network/interfaces.exp b/src/test/test-debian-012/etc/network/interfaces.exp
index 4606578..c9725aa 100644
--- a/src/test/test-debian-012/etc/network/interfaces.exp
+++ b/src/test/test-debian-012/etc/network/interfaces.exp
@@ -19,3 +19,9 @@ iface eth1 inet6 static
 	pre-down ip route del default via fc00:1::ff
 	pre-down ip route del fc00:1::ff dev eth1
 
+auto eth2
+iface eth2 inet6 static
+	address fc02::1
+	netmask 64
+	gateway fe80::1
+
diff --git a/src/test/test-opensuse-002/config b/src/test/test-opensuse-002/config
index 3337969..75b139d 100644
--- a/src/test/test-opensuse-002/config
+++ b/src/test/test-opensuse-002/config
@@ -1,4 +1,5 @@
 hostname: pvesuse1
-net0: bridge=vmbr0,name=eth0,ip6=2001:1::/64,gw6=2001:1::ffff
+net0: bridge=vmbr0,name=eth0,ip6=2001:1::/64,gw6=20ff::1
 net1: bridge=vmbr0,name=eth1,ip6=2001:2::/64
 net2: bridge=vmbr0,name=eth2,ip6=manual
+net3: bridge=vmbr0,name=eth3,ip6=2000::1/64,gw6=fe80::1
diff --git a/src/test/test-opensuse-002/etc/sysconfig/network/ifcfg-eth3.exp b/src/test/test-opensuse-002/etc/sysconfig/network/ifcfg-eth3.exp
new file mode 100644
index 0000000..e7b23dc
--- /dev/null
+++ b/src/test/test-opensuse-002/etc/sysconfig/network/ifcfg-eth3.exp
@@ -0,0 +1,3 @@
+STARTMODE=onboot
+BOOTPROTO=static
+IPADDR=2000::1/64
diff --git a/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth0.exp b/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth0.exp
index 8556275..e491a16 100644
--- a/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth0.exp
+++ b/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth0.exp
@@ -1,3 +1,4 @@
 # --- BEGIN PVE ---
-default 2001:1::ffff - eth0
+20ff::1/128 - - eth0
+default 20ff::1 - eth0
 # --- END PVE ---
diff --git a/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth3.exp b/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth3.exp
new file mode 100644
index 0000000..2faf7c5
--- /dev/null
+++ b/src/test/test-opensuse-002/etc/sysconfig/network/ifroute-eth3.exp
@@ -0,0 +1,3 @@
+# --- BEGIN PVE ---
+default fe80::1 - eth3
+# --- END PVE ---
-- 
2.1.4





More information about the pve-devel mailing list