[pve-devel] [PATCH pve-network] ipam: improve update / delete behavior

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Nov 22 14:18:33 CET 2023


Am 22/11/2023 um 13:29 schrieb Stefan Hanreich:
> Currently when updating or deleting a mapping in the IPAM we would
> delete all existing entries in the IPAM with that mac address. Now we
> only delete the specific entry we are updating / deleting.
> 
> Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
> ---
>  src/PVE/API2/Network/SDN/Ips.pm | 20 +++++++++++++-------
>  src/PVE/Network/SDN/Subnets.pm  |  3 +++
>  2 files changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/src/PVE/API2/Network/SDN/Ips.pm b/src/PVE/API2/Network/SDN/Ips.pm
> index 6989b9b..0003b2a 100644
> --- a/src/PVE/API2/Network/SDN/Ips.pm
> +++ b/src/PVE/API2/Network/SDN/Ips.pm
> @@ -28,6 +28,11 @@ __PACKAGE__->register_method ({
>  	    zone => get_standard_option('pve-sdn-zone-id'),
>  	    vnet => get_standard_option('pve-sdn-vnet-id'),
>  	    mac => get_standard_option('mac-addr'),
> +	    ip => {
> +		type => 'string',
> +		format => 'ip',
> +		description => 'The IP address to delete',
> +	    },
>  	},
>      },
>      returns => { type => 'null' },
> @@ -36,13 +41,12 @@ __PACKAGE__->register_method ({
>  
>  	my $vnet = extract_param($param, 'vnet');
>  	my $mac = extract_param($param, 'mac');
> +	my $ip = extract_param($param, 'ip');
>  
>  	eval {
> -	    PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac);
> +	    PVE::Network::SDN::Vnets::del_ip($vnet, $ip, '', $mac);
>  	};
> -	my $error = $@;
> -
> -	die "$error\n" if $error;
> +	die "$@\n" if $@;

why bother with the eval then? or does something set $@ manually in the
called method?

>  
>  	return undef;
>      },
> @@ -117,7 +121,10 @@ __PACKAGE__->register_method ({
>  	my $vmid = extract_param($param, 'vmid');
>  	my $ip = extract_param($param, 'ip');
>  
> -	my ($old_ip4, $old_ip6) = PVE::Network::SDN::Vnets::del_ips_from_mac($vnet, $mac, '');
> +	my ($old_ip4, $old_ip6) = PVE::Network::SDN::Vnets::get_ips_from_mac($vnet, $mac);
> +	my $old_ip = (Net::IP::ip_get_version($ip) == 4) ? $old_ip4 : $old_ip6;
> +
> +	PVE::Network::SDN::Vnets::del_ip($vnet, $old_ip, '', $mac);
>  
>  	eval {
>  	    PVE::Network::SDN::Vnets::add_ip($vnet, $ip, '', $mac, $vmid);
> @@ -125,8 +132,7 @@ __PACKAGE__->register_method ({
>  	my $error = $@;
>  
>  	if ($error) {
> -	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip4, '', $mac, $vmid) if $old_ip4;
> -	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip6, '', $mac, $vmid) if $old_ip6;
> +	    PVE::Network::SDN::Vnets::add_ip($vnet, $old_ip, '', $mac, $vmid);
>  	}
>  
>  	die "$error\n" if $error;
> diff --git a/src/PVE/Network/SDN/Subnets.pm b/src/PVE/Network/SDN/Subnets.pm
> index 8e2a6aa..8f113b4 100644
> --- a/src/PVE/Network/SDN/Subnets.pm
> +++ b/src/PVE/Network/SDN/Subnets.pm
> @@ -305,6 +305,9 @@ sub add_ip {
>  	    $plugin->add_ip($plugin_config, $subnetid, $subnet, $ip, $hostname, $mac, $vmid, $is_gateway);
>  	};
>  	die $@ if $@;
> +
> +	eval { PVE::Network::SDN::Ipams::add_cache_mac_ip($mac, $ip) if $mac; };
> +	warn $@ if $@;

is this really related?

>      }
>  
>      eval {






More information about the pve-devel mailing list