* [pve-devel] [PATCH v2 pve-container 1/4] hotplug network: Only change IPAM when MAC or bridge changes
2023-11-20 19:19 [pve-devel] [PATCH v2 container 0/4] Bugfixes for DHCP Stefan Hanreich
@ 2023-11-20 19:19 ` Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 2/4] network: Do not always reserve new IP in IPAM Stefan Hanreich
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2023-11-20 19:19 UTC (permalink / raw)
To: pve-devel
Currently a new IPAM entry is created everytime a NIC config changes.
When editing properties other than MAC or Bridge this could lead to
duplicated entries in the IPAM. Only reserve a new IP when the bridge
or MAC changes or the NIC is completely new.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC.pm | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 2dad83d..c239715 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -965,9 +965,12 @@ sub update_net {
PVE::Network::veth_delete($veth);
- if ($have_sdn) {
+ if ($have_sdn && safe_string_ne($oldnet->{hwaddr}, $newnet->{hwaddr})) {
eval { PVE::Network::SDN::Vnets::del_ips_from_mac($oldnet->{bridge}, $oldnet->{hwaddr}, $conf->{hostname}) };
warn $@ if $@;
+
+ PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{hostname}, $newnet->{hwaddr}, $vmid, undef, 1);
+ PVE::Network::SDN::Vnets::add_dhcp_mapping($newnet->{bridge}, $newnet->{hwaddr});
}
delete $conf->{$opt};
@@ -976,13 +979,15 @@ sub update_net {
hotplug_net($vmid, $conf, $opt, $newnet, $netid);
} else {
- if (safe_string_ne($oldnet->{bridge}, $newnet->{bridge}) ||
+ my $bridge_changed = safe_string_ne($oldnet->{bridge}, $newnet->{bridge});
+
+ if ($bridge_changed ||
safe_num_ne($oldnet->{tag}, $newnet->{tag}) ||
safe_num_ne($oldnet->{firewall}, $newnet->{firewall}) ||
safe_boolean_ne($oldnet->{link_down}, $newnet->{link_down})
) {
-
if ($oldnet->{bridge}) {
+ my $oldbridge = $oldnet->{bridge};
PVE::Network::tap_unplug($veth);
foreach (qw(bridge tag firewall)) {
@@ -991,13 +996,13 @@ sub update_net {
$conf->{$opt} = PVE::LXC::Config->print_lxc_network($oldnet);
PVE::LXC::Config->write_config($vmid, $conf);
- if ($have_sdn) {
- eval { PVE::Network::SDN::Vnets::del_ips_from_mac($oldnet->{bridge}, $oldnet->{hwaddr}, $conf->{hostname}) };
+ if ($have_sdn && $bridge_changed) {
+ eval { PVE::Network::SDN::Vnets::del_ips_from_mac($oldbridge, $oldnet->{hwaddr}, $conf->{hostname}) };
warn $@ if $@;
}
}
- if ($have_sdn) {
+ if ($have_sdn && $bridge_changed) {
PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{hostname}, $newnet->{hwaddr}, $vmid, undef, 1);
}
PVE::LXC::net_tap_plug($veth, $newnet);
@@ -1016,6 +1021,9 @@ sub update_net {
PVE::LXC::Config->write_config($vmid, $conf);
}
} else {
+ PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{hostname}, $newnet->{hwaddr}, $vmid, undef, 1);
+ PVE::Network::SDN::Vnets::add_dhcp_mapping($newnet->{bridge}, $newnet->{hwaddr});
+
hotplug_net($vmid, $conf, $opt, $newnet, $netid);
}
@@ -1030,8 +1038,6 @@ sub hotplug_net {
my $eth = $newnet->{name};
if ($have_sdn) {
- PVE::Network::SDN::Vnets::add_next_free_cidr($newnet->{bridge}, $conf->{hostname}, $newnet->{hwaddr}, $vmid, undef, 1);
- PVE::Network::SDN::Vnets::add_dhcp_mapping($newnet->{bridge}, $newnet->{hwaddr});
PVE::Network::SDN::Zones::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
} else {
PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pve-devel] [PATCH v2 pve-container 2/4] network: Do not always reserve new IP in IPAM
2023-11-20 19:19 [pve-devel] [PATCH v2 container 0/4] Bugfixes for DHCP Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 1/4] hotplug network: Only change IPAM when MAC or bridge changes Stefan Hanreich
@ 2023-11-20 19:19 ` Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 3/4] config: Use LXC Config instead of QemuServer for parsing net Stefan Hanreich
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2023-11-20 19:19 UTC (permalink / raw)
To: pve-devel
Currently when updating the network configuration of a container, SDN
would always create a new entry in the IPAM. Only create a new entry
when the bridge or MAC changes or the NIC is completely new.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC/Config.pm | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 823a2b9..53662b7 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1500,13 +1500,15 @@ sub vmconfig_apply_pending {
my $net = $class->parse_lxc_network($conf->{pending}->{$opt});
$conf->{pending}->{$opt} = $class->print_lxc_network($net);
if ($have_sdn) {
- if($conf->{$opt}) {
+ if ($conf->{$opt}) {
my $old_net = $class->parse_lxc_network($conf->{$opt});
if ($old_net->{bridge} ne $net->{bridge} || $old_net->{hwaddr} ne $net->{hwaddr}) {
PVE::Network::SDN::Vnets::del_ips_from_mac($old_net->{bridge}, $old_net->{hwaddr}, $conf->{name});
+ PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1);
}
+ } else {
+ PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1);
}
- PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1);
}
}
};
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [pve-devel] [PATCH v2 pve-container 3/4] config: Use LXC Config instead of QemuServer for parsing net
2023-11-20 19:19 [pve-devel] [PATCH v2 container 0/4] Bugfixes for DHCP Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 1/4] hotplug network: Only change IPAM when MAC or bridge changes Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 2/4] network: Do not always reserve new IP in IPAM Stefan Hanreich
@ 2023-11-20 19:19 ` Stefan Hanreich
2023-11-20 19:19 ` [pve-devel] [PATCH v2 pve-container 4/4] create: Do not call create_ifaces_ipams_ips Stefan Hanreich
2023-11-22 13:42 ` [pve-devel] applied: [PATCH v2 container 0/4] Bugfixes for DHCP Thomas Lamprecht
4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2023-11-20 19:19 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
src/PVE/LXC.pm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index c239715..847b8c8 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2771,9 +2771,9 @@ sub create_ifaces_ipams_ips {
for my $opt (keys %$conf) {
next if $opt !~ m/^net(\d+)$/;
- my $net = PVE::QemuServer::parse_net($conf->{$opt});
+ my $net = PVE::LXC::Config->parse_lxc_network($conf->{$opt});
next if $net->{type} ne 'veth';
- PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1);
+ PVE::Network::SDN::Vnets::add_next_free_cidr($net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1);
}
}
@@ -2784,7 +2784,7 @@ sub delete_ifaces_ipams_ips {
for my $opt (keys %$conf) {
next if $opt !~ m/^net(\d+)$/;
- my $net = PVE::QemuServer::parse_net($conf->{$opt});
+ my $net = PVE::LXC::Config->parse_lxc_network($conf->{$opt});
eval { PVE::Network::SDN::Vnets::del_ips_from_mac($net->{bridge}, $net->{hwaddr}, $conf->{hostname}) };
warn $@ if $@;
}
--
2.39.2
^ permalink raw reply [flat|nested] 6+ messages in thread