changing a gateway can fail if there is an old conflicting route. this
can happen when changing gateways back and forth.
with this change all old routes that are no longer relevant are deleted
after a change.

Signed-off-by: David Limbeck <d.limb...@proxmox.com>
---
changes since v1:
  using $oldgw everywhere
  check for an out-of-subnet route

 src/PVE/LXC.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 1504bd0..f685279 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 && !PVE::Network::is_ip_in_cidr($oldgw, $oldip)) {
+               eval { &$ipcmd($family_opt, 'route', 'del', $oldgw, 'dev', 
$eth); };
+               # keep warning in case route was deleted manually
+               warn $@ if $@;
+           }
        }
 
        # from this point on we save the configuration
-- 
2.11.0


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to