From: David Limbeck Date: Tue, 4 Sep 2018 07:24:29 +0000 (+0200) Subject: fix #1885: delete old route when changing gateway X-Git-Url: https://git.proxmox.com/?p=pve-container.git;a=commitdiff_plain;h=ded5d25a1f19bce71532b476c374938a3183657f fix #1885: delete old route when changing gateway 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 --- diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 1504bd0..0b57ae9 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -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