]> git.proxmox.com Git - pve-container.git/commitdiff
don't try to add 'dhcp' or 'auto' as ip addresses
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 30 Jul 2015 08:53:59 +0000 (10:53 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 30 Jul 2015 09:41:00 +0000 (11:41 +0200)
The live ip address updating of running containers needs to
deal with dhcp and slaac settings by not trying to add these
keywords as ip addresses via the ip command.

(And fixing a typo...)

src/PVE/LXC.pm

index 2517ffdbe7bf0bfbb56baa66223e4b5f6d44f184..98b73befe6290f84b9ad1ac58d29c57ec5f54d56 100644 (file)
@@ -1369,14 +1369,18 @@ sub update_ipconfig {
        my $gw= "gw$suffix";
        my $ip= "ip$suffix";
 
-       my $change_ip = &$safe_string_ne($optdata->{$ip}, $newnet->{$ip});
-       my $change_gw = &$safe_string_ne($optdata->{$gw}, $newnet->{$gw});
+       my $newip = $newnet->{$ip};
+       my $newgw = $newnet->{$gw};
+       my $oldip = $optdata->{$ip};
+
+       my $change_ip = &$safe_string_ne($oldip, $newip);
+       my $change_gw = &$safe_string_ne($optdata->{$gw}, $newgw);
 
        return if !$change_ip && !$change_gw;
 
        # step 1: add new IP, if this fails we cancel
-       if ($change_ip && $newnet->{$ip}) {
-           eval { &$netcmd($family_opt, 'addr', 'add', $newnet->{$ip}, 'dev', $eth); };
+       if ($change_ip && $newip && $newip !~ /^(?:auto|dhcp)$/) {
+           eval { &$netcmd($family_opt, 'addr', 'add', $newip, 'dev', $eth); };
            if (my $err = $@) {
                warn $err;
                return;
@@ -1389,14 +1393,14 @@ sub update_ipconfig {
        #   errors. The config is then saved.
        # Note: 'ip route replace' can add
        if ($change_gw) {
-           if ($newnet->{$gw}) {
-               eval { &$netcmd($family_opt, 'route', 'replace', 'default', 'via', $newnet->{$gw}); };
+           if ($newgw) {
+               eval { &$netcmd($family_opt, 'route', 'replace', 'default', 'via', $newgw); };
                if (my $err = $@) {
                    warn $err;
                    # the route was not replaced, the old IP is still available
                    # rollback (delete new IP) and cancel
                    if ($change_ip) {
-                       eval { &$netcmd($family_opt, 'addr', 'del', $newnet->{$ip}, 'dev', $eth); };
+                       eval { &$netcmd($family_opt, 'addr', 'del', $newip, 'dev', $eth); };
                        warn $@ if $@; # no need to die here
                    }
                    return;
@@ -1409,10 +1413,10 @@ sub update_ipconfig {
            }
        }
 
-       # from this point on we safe the configuration
+       # from this point on we save the configuration
        # step 3: delete old IP ignoring errors
-       if ($change_ip && $optdata->{$ip}) {
-           eval { &$netcmd($family_opt, 'addr', 'del', $optdata->{$ip}, 'dev', $eth); };
+       if ($change_ip && $oldip && $oldip !~ /^(?:auto|dhcp)$/) {
+           eval { &$netcmd($family_opt, 'addr', 'del', $oldip, 'dev', $eth); };
            warn $@ if $@; # no need to die here
        }