From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id CFFF91FF0B3 for ; Wed, 09 Sep 2026 12:43:42 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C529421749; Wed, 09 Sep 2026 12:42:14 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-container v2 13/16] net: report veth plug and unplug to SDN with the hwaddr Date: Wed, 9 Sep 2026 12:41:41 +0200 Message-ID: <20260909104144.1110031-14-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260909104144.1110031-1-h.laimer@proxmox.com> References: <20260909104144.1110031-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788950515178 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.544 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: E35TAD5DUYQTF5ANUIJ6QPY3WYBSUBLW X-Message-ID-Hash: E35TAD5DUYQTF5ANUIJ6QPY3WYBSUBLW X-MailFrom: h.laimer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The SDN layer answers DHCP on a plugged interface from the mapping of its guest NIC, and drops what it holds for the interface once it goes away. So the veth delete reports through it. A bridge change keeps pve-common's unplug, allocates on the new vnet and pushes through the mapping call, whose push writes the dnsmasq reservation. The plug that follows tells the SDN layer where the veth went and carries the responder's record. A disconnected NIC tells it at its next plug. This needs a libpve-network-perl with the SDN unplug when the package is installed at all. pve-container keeps working without it, so the floor is a Breaks on the older versions. Signed-off-by: Hannes Laimer --- src/PVE/LXC.pm | 24 ++++++++++++++++++++++-- src/PVE/LXC/Config.pm | 2 +- src/lxc-pve-poststop-hook | 5 ++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index dee073d..62b76b4 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1117,7 +1117,13 @@ sub net_tap_plug : prototype($$) { if ($have_sdn) { PVE::Network::SDN::Zones::tap_plug( - $iface, $bridge, $tag, $create_firewall_bridges, $trunks, $rate, + $iface, + $bridge, + $tag, + $create_firewall_bridges, + $trunks, + $rate, + { mac => $hwaddr }, ); PVE::Network::SDN::Zones::add_bridge_fdb($iface, $hwaddr, $bridge); } else { @@ -1135,6 +1141,17 @@ sub net_tap_plug : prototype($$) { PVE::Tools::run_command(['/sbin/ip', 'link', 'set', 'dev', $iface, 'up']); } +# the SDN layer drops what its DHCP backends hold for the veth, which may be gone already +sub net_veth_delete : prototype($) { + my ($veth) = @_; + + if ($have_sdn) { + PVE::Network::SDN::Zones::veth_delete($veth); + } else { + PVE::Network::veth_delete($veth); + } +} + sub update_net { my ($vmid, $conf, $opt, $newnet, $netid, $rootdir) = @_; @@ -1154,7 +1171,7 @@ sub update_net { || safe_string_ne($oldnet->{name}, $newnet->{name}) ) { - PVE::Network::veth_delete($veth); + PVE::LXC::net_veth_delete($veth); if ($have_sdn && safe_string_ne($oldnet->{hwaddr}, $newnet->{hwaddr})) { eval { @@ -1209,6 +1226,9 @@ sub update_net { 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}, $vmid, $conf->{hostname}, + ); } eval { PVE::LXC::net_tap_plug($veth, $newnet) }; if (my $err = $@) { diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 3eb1905..15ea6ea 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -1702,7 +1702,7 @@ sub vmconfig_hotplug_pending { my $net = parse_lxc_network($conf->{$opt}); PVE::LXC::kill_dhclients($vmid, $net->{name}) if $net->{'host-managed'}; - PVE::Network::veth_delete("veth${vmid}i$netid"); + PVE::LXC::net_veth_delete("veth${vmid}i$netid"); if ($have_sdn) { print "delete ips from $opt\n"; eval { diff --git a/src/lxc-pve-poststop-hook b/src/lxc-pve-poststop-hook index c8bbb79..aba6f4f 100755 --- a/src/lxc-pve-poststop-hook +++ b/src/lxc-pve-poststop-hook @@ -11,7 +11,6 @@ use PVE::GuestHelpers; use PVE::LXC::Config; use PVE::LXC::Tools; use PVE::LXC; -use PVE::Network; use PVE::RESTEnvironment; use PVE::Storage; use PVE::Tools; @@ -49,8 +48,8 @@ PVE::LXC::Tools::lxc_hook( my $ind = $1; my $net = PVE::LXC::Config->parse_lxc_network($conf->{$k}); next if $net->{type} ne 'veth'; - # veth_delete tests with '-d /sys/class/net/$name' before running the command - PVE::Network::veth_delete("veth${vmid}i$ind"); + # reports the unplug and deletes the veth only where it still exists + PVE::LXC::net_veth_delete("veth${vmid}i$ind"); } my $config_updated = 0; -- 2.47.3