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

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Aug 28 10:49:37 CEST 2018


On Fri, Aug 24, 2018 at 01:45:33PM +0200, David Limbeck wrote:
> 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>
> ---
>  src/PVE/LXC.pm | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index 1504bd0..4d9f5b0 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -791,6 +791,7 @@ 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);
                                          ^^^^^^^^^^^^^^
When introducing $oldgw, please also change the above reference to the
same value ;-)

> @@ -836,6 +837,12 @@ sub update_ipconfig {
>  		# warn and continue
>  		warn $@ if $@;
>  	    }
> +	    if ($oldgw) {
> +		eval { &$ipcmd($family_opt, 'route', 'del', $oldgw, 'dev', $eth); };
> +		# if the route was not deleted, the guest might have deleted it manually
> +		# warn and continue

Maybe don't use the exact same comment from above, but also mention the
fact that the route may not even have existed ;-)
Alternatively we can use the same condition we use for adding the
route in the first place, though since we ignore errors here that's not
really required. The upside of adding the check would be that we don't
produce warnings in the "normal" case.

> +		warn $@ if $@;
> +	    }
>  	}
>  
>  	# from this point on we save the configuration
> -- 
> 2.11.0




More information about the pve-devel mailing list