[pve-devel] [PATCH container v2] fix #1885: delete old route after changing gateway

David Limbeck d.limbeck at proxmox.com
Wed Aug 29 10:29:39 CEST 2018


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.limbeck at 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





More information about the pve-devel mailing list