]> git.proxmox.com Git - pve-container.git/commitdiff
fix #1885: delete old route when changing gateway
authorDavid Limbeck <d.limbeck@proxmox.com>
Tue, 4 Sep 2018 07:24:29 +0000 (09:24 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 4 Sep 2018 08:27:05 +0000 (10:27 +0200)
if the gateway is not in the subnet of the ip a route is
added. this change enables the deletion of the old route when it
is no longer needed.

Signed-off-by: David Limbeck <d.limbeck@proxmox.com>
src/PVE/LXC.pm

index 1504bd015f9b641bd7f7a2dd73ffee38f90b0d9f..0b57ae9f32ccf275e64cd85621dc02f62bce5f3c 100644 (file)
@@ -791,9 +791,10 @@ sub update_ipconfig {
        my $newip = $newnet->{$ip};
        my $newgw = $newnet->{$gw};
        my $oldip = $optdata->{$ip};
+       my $oldgw = $optdata->{$gw};
 
        my $change_ip = &$safe_string_ne($oldip, $newip);
-       my $change_gw = &$safe_string_ne($optdata->{$gw}, $newgw);
+       my $change_gw = &$safe_string_ne($oldgw, $newgw);
 
        return if !$change_ip && !$change_gw;
 
@@ -836,6 +837,11 @@ sub update_ipconfig {
                # warn and continue
                warn $@ if $@;
            }
+           if ($oldgw && $oldip && !PVE::Network::is_ip_in_cidr($oldgw, $oldip)) {
+               eval { &$ipcmd($family_opt, 'route', 'del', $oldgw, 'dev', $eth); };
+               # warn if the route was deleted manually
+               warn $@ if $@;
+           }
        }
 
        # from this point on we save the configuration