[pve-devel] [PATCH pve-container] redhat: don't use aliases for dual stack networking
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Oct 20 16:50:33 CEST 2015
A static IPv6 as alias interface for ipv4 doesn't work (RH
has "secondaries" for that), DHCP on aliases doesn't work
either.
The only drawback of putting both in the same file is that
static addresses take longer to be configured if the DHCP
server is slow.
---
src/PVE/LXC/Setup/Redhat.pm | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/src/PVE/LXC/Setup/Redhat.pm b/src/PVE/LXC/Setup/Redhat.pm
index 813a87e..2ed9cda 100644
--- a/src/PVE/LXC/Setup/Redhat.pm
+++ b/src/PVE/LXC/Setup/Redhat.pm
@@ -197,15 +197,16 @@ sub setup_network {
my $filename = "/etc/sysconfig/network-scripts/ifcfg-$d->{name}";
my $routefile = "/etc/sysconfig/network-scripts/route-$d->{name}";
my $routes = '';
- my $had_v4 = 0;
+
+ my $header = "DEVICE=$d->{name}\nONBOOT=yes\n";
+ my $data = '';
+ my $bootproto = '';
if ($d->{ip} && $d->{ip} ne 'manual') {
- my $data = "DEVICE=$d->{name}\n";
- $data .= "ONBOOT=yes\n";
if ($d->{ip} eq 'dhcp') {
- $data .= "BOOTPROTO=dhcp\n";
+ $bootproto = 'dhcp';
} else {
- $data .= "BOOTPROTO=none\n";
+ $bootproto = 'none';
my $ipinfo = PVE::LXC::parse_ipv4_cidr($d->{ip});
$data .= "IPADDR=$ipinfo->{address}\n";
$data .= "NETMASK=$ipinfo->{netmask}\n";
@@ -213,25 +214,14 @@ sub setup_network {
$data .= "GATEWAY=$d->{gw}\n";
}
}
- $self->ct_file_set_contents($filename, $data);
if (!PVE::Network::is_ip_in_cidr($d->{gw}, $d->{ip}, 4)) {
$routes .= "$d->{gw} dev $d->{name}\n";
$routes .= "default via $d->{gw}\n";
}
- # If we also have an IPv6 configuration it'll end up in an alias
- # interface becuase otherwise RH doesn't support mixing dhcpv4 with
- # a static ipv6 address.
- $filename .= ':0';
- $had_v4 = 1;
}
if ($d->{ip6} && $d->{ip6} ne 'manual') {
- # If we're only on ipv6 delete the :0 alias
- $self->ct_unlink("$filename:0") if !$had_v4;
-
- my $data = "DEVICE=$d->{name}\n";
- $data .= "ONBOOT=yes\n";
- $data .= "BOOTPROTO=none\n";
+ $bootproto = 'none' if !$bootproto;
$data .= "IPV6INIT=yes\n";
if ($d->{ip6} eq 'auto') {
$data .= "IPV6_AUTOCONF=yes\n";
@@ -246,13 +236,16 @@ sub setup_network {
$data .= "IPV6_DEFAULTGW=$d->{gw6}\n";
}
}
- $self->ct_file_set_contents($filename, $data);
if (!PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6)) {
$routes .= "$d->{gw6} dev $d->{name}\n";
$routes .= "default via $d->{gw6}\n";
}
}
+ next unless $data;
+ $header .= "BOOTPROTO=$bootproto\n";
+ $self->ct_file_set_contents($filename, $header . $data);
+
# To keep user-defined routes in route-$iface we mark ours:
my $head = "# --- BEGIN PVE ROUTES ---\n";
my $tail = "# --- END PVE ROUTES ---\n";
--
2.1.4
More information about the pve-devel
mailing list