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 CA6061FF0B6 for ; Thu, 12 Nov 2026 13:44:26 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 42C73217B4; Thu, 12 Nov 2026 13:43:25 +0100 (CET) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v7 14/21] network: sdn: keep the DHCP backends current on guest NICs Date: Thu, 12 Nov 2026 13:41:54 +0100 Message-ID: <20261112124201.2844423-15-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112124201.2844423-1-h.laimer@proxmox.com> References: <20261112124201.2844423-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: 1794487345914 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.290 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: 2QYLGIBU4D3OL5T5UGUYXGKDTXLWVOIG X-Message-ID-Hash: 2QYLGIBU4D3OL5T5UGUYXGKDTXLWVOIG 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: A DHCP backend that serves the guest's tap itself has to hear of every plug and removal of that tap. The plug now carries the NIC's MAC, so the backend can look up the NIC's record. Removing a tap now goes through the SDN layer as well, so the backend drops its entry for that tap. A hotplug moves the tap while the NIC's new bridge is still a pending change in the config. So it marks its plug as pending, and the NIC is reported to the backends again once the change is applied. A bridge change allocated the NIC's address in the new vnet, but unlike a start or a hotplug it never pushed the mapping to the backend of that vnet's zone. It now does. Signed-off-by: Hannes Laimer --- Notes: v5: * the resume push moved to the IPAM series src/PVE/CLI/qm.pm | 4 ++-- src/PVE/QemuServer.pm | 16 ++++++++++++++++ src/PVE/QemuServer/Network.pm | 10 ++++++++-- .../aarch64/net-add-pci-bridge.conf.expected | 1 + src/test/hotplug/aarch64/net-add.conf.expected | 1 + .../aarch64/x86-guest-net-add.conf.expected | 1 + .../hotplug/net-add-pci-bridge.conf.expected | 1 + src/test/hotplug/net-add.conf.expected | 1 + src/test/hotplug/net-change-bridge.conf.expected | 4 +++- src/test/hotplug/net-change-model.conf.expected | 1 + src/test/hotplug/net-change-rate.conf.expected | 1 + src/test/run_hotplug_tests.pl | 5 ++++- src/usr/pve-bridge | 8 +++++++- src/usr/pve-bridgedown | 4 ++-- 14 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm index f62fe0366b97..4917760fca78 100755 --- a/src/PVE/CLI/qm.pm +++ b/src/PVE/CLI/qm.pm @@ -22,7 +22,7 @@ use PVE::GuestHelpers; use PVE::GuestImport::OVF; use PVE::INotify; use PVE::JSONSchema qw(get_standard_option); -use PVE::Network; +use PVE::Network::SDN::Zones; use PVE::RPCEnvironment; use PVE::SafeSyslog; use PVE::Tools qw(extract_param file_get_contents); @@ -1143,7 +1143,7 @@ __PACKAGE__->register_method({ foreach my $opt (keys %$conf) { next if $opt !~ m/^net(\d+)$/; my $interface = $1; - PVE::Network::tap_unplug("tap${vmid}i${interface}"); + PVE::Network::SDN::Zones::tap_unplug("tap${vmid}i${interface}"); } } diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 55abde5e219d..32367ea2826e 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -4627,6 +4627,7 @@ sub vmconfig_hotplug_pending { } my $cloudinit_opt; + my $hotplugged_nets = []; foreach my $opt (keys %{ $conf->{pending} }) { next if $selection && !$selection->{$opt}; my $value = $conf->{pending}->{$opt}; @@ -4735,6 +4736,7 @@ sub vmconfig_hotplug_pending { $cloudinit_record_changed->($conf, $opt, $conf->{$opt}, $value); $conf->{$opt} = $value; delete $conf->{pending}->{$opt}; + push $hotplugged_nets->@*, $opt if $opt =~ m/^net\d+$/; } } @@ -4778,6 +4780,16 @@ sub vmconfig_hotplug_pending { PVE::QemuConfig->write_config($vmid, $conf); + # the SDN DHCP backends serve a hotplugged NIC only once its change is applied to the config + for my $opt ($hotplugged_nets->@*) { + my $net = PVE::QemuServer::Network::parse_net($conf->{$opt}); + next if !$net || !$net->{bridge}; + my ($index) = $opt =~ m/^net(\d+)$/; + PVE::QemuServer::Network::tap_commit( + "tap${vmid}i$index", $net->{bridge}, $net->{macaddr}, + ); + } + if ($hotplug_features->{cloudinit} && PVE::QemuServer::Cloudinit::has_changes($conf)) { PVE::QemuServer::vmconfig_update_cloudinit_drive($storecfg, $conf, $vmid); } @@ -5000,6 +5012,9 @@ sub vmconfig_update_net { PVE::Network::SDN::Vnets::add_next_free_cidr( $newnet->{bridge}, $conf->{name}, $newnet->{macaddr}, $vmid, undef, 1, ); + PVE::Network::SDN::Vnets::add_dhcp_mapping( + $newnet->{bridge}, $newnet->{macaddr}, $vmid, $conf->{name}, + ); } PVE::QemuServer::Network::tap_plug( @@ -5009,6 +5024,7 @@ sub vmconfig_update_net { $newnet->{firewall}, $newnet->{trunks}, $newnet->{rate}, + { mac => $newnet->{macaddr}, pending => 1 }, ); # unplugging the interface dropped its forwarding database entries eval { PVE::QemuServer::Network::add_nets_bridge_fdb({ $opt => $value }, $vmid) }; diff --git a/src/PVE/QemuServer/Network.pm b/src/PVE/QemuServer/Network.pm index 1bad0196e179..cf0930c09a75 100644 --- a/src/PVE/QemuServer/Network.pm +++ b/src/PVE/QemuServer/Network.pm @@ -368,10 +368,16 @@ sub delete_ifaces_ipams_ips { } sub tap_plug { - my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_; + my ($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts) = @_; $firewall = $firewall && PVE::Firewall::Helpers::needs_fwbr($bridge); - PVE::Network::SDN::Zones::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate); + PVE::Network::SDN::Zones::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts); +} + +sub tap_commit { + my ($iface, $bridge, $mac) = @_; + + PVE::Network::SDN::Zones::tap_commit($iface, $bridge, $mac); } sub get_nets_host_mtu { diff --git a/src/test/hotplug/aarch64/net-add-pci-bridge.conf.expected b/src/test/hotplug/aarch64/net-add-pci-bridge.conf.expected index 40aa47c562c4..bc0a2d18fffe 100644 --- a/src/test/hotplug/aarch64/net-add-pci-bridge.conf.expected +++ b/src/test/hotplug/aarch64/net-add-pci-bridge.conf.expected @@ -3,3 +3,4 @@ sdn add_dhcp_mapping ["vmbr0","BA:DC:0F:FE:E0:06","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net6","ifname":"tap8006i6","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap","vhost":true} hmp device_add driver=virtio-net-pci,mac=BA:DC:0F:FE:E0:06,netdev=net6,bus=pci.1,addr=0x1,id=net6,rx_queue_size=1024,tx_queue_size=256,host_mtu=1500 qmp set_link {"name":"net6","up":true} +net tap_commit ["tap8006i6","vmbr0","BA:DC:0F:FE:E0:06"] diff --git a/src/test/hotplug/aarch64/net-add.conf.expected b/src/test/hotplug/aarch64/net-add.conf.expected index 8d5521215b7c..35599f8ed3fb 100644 --- a/src/test/hotplug/aarch64/net-add.conf.expected +++ b/src/test/hotplug/aarch64/net-add.conf.expected @@ -3,3 +3,4 @@ sdn add_dhcp_mapping ["vmbr0","BA:DC:0F:FE:E0:01","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net1","ifname":"tap8006i1","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap","vhost":true} hmp device_add driver=virtio-net-pci,mac=BA:DC:0F:FE:E0:01,netdev=net1,bus=pcie.0,addr=0x13,id=net1,rx_queue_size=1024,tx_queue_size=256,host_mtu=1500 qmp set_link {"name":"net1","up":true} +net tap_commit ["tap8006i1","vmbr0","BA:DC:0F:FE:E0:01"] diff --git a/src/test/hotplug/aarch64/x86-guest-net-add.conf.expected b/src/test/hotplug/aarch64/x86-guest-net-add.conf.expected index 7f2b08a81987..e27c5c80c01c 100644 --- a/src/test/hotplug/aarch64/x86-guest-net-add.conf.expected +++ b/src/test/hotplug/aarch64/x86-guest-net-add.conf.expected @@ -3,3 +3,4 @@ sdn add_dhcp_mapping ["vmbr0","BA:DC:0F:FE:E0:01","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net1","ifname":"tap8006i1","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap"} hmp device_add driver=virtio-net-pci,mac=BA:DC:0F:FE:E0:01,netdev=net1,bus=pci.0,addr=0x13,id=net1,rx_queue_size=1024,tx_queue_size=256,host_mtu=1500 qmp set_link {"name":"net1","up":true} +net tap_commit ["tap8006i1","vmbr0","BA:DC:0F:FE:E0:01"] diff --git a/src/test/hotplug/net-add-pci-bridge.conf.expected b/src/test/hotplug/net-add-pci-bridge.conf.expected index 40aa47c562c4..bc0a2d18fffe 100644 --- a/src/test/hotplug/net-add-pci-bridge.conf.expected +++ b/src/test/hotplug/net-add-pci-bridge.conf.expected @@ -3,3 +3,4 @@ sdn add_dhcp_mapping ["vmbr0","BA:DC:0F:FE:E0:06","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net6","ifname":"tap8006i6","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap","vhost":true} hmp device_add driver=virtio-net-pci,mac=BA:DC:0F:FE:E0:06,netdev=net6,bus=pci.1,addr=0x1,id=net6,rx_queue_size=1024,tx_queue_size=256,host_mtu=1500 qmp set_link {"name":"net6","up":true} +net tap_commit ["tap8006i6","vmbr0","BA:DC:0F:FE:E0:06"] diff --git a/src/test/hotplug/net-add.conf.expected b/src/test/hotplug/net-add.conf.expected index 562bfb1293be..edb2a48b4611 100644 --- a/src/test/hotplug/net-add.conf.expected +++ b/src/test/hotplug/net-add.conf.expected @@ -3,3 +3,4 @@ sdn add_dhcp_mapping ["vmbr0","BA:DC:0F:FE:E0:01","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net1","ifname":"tap8006i1","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap","vhost":true} hmp device_add driver=virtio-net-pci,mac=BA:DC:0F:FE:E0:01,netdev=net1,bus=pci.0,addr=0x13,id=net1,rx_queue_size=1024,tx_queue_size=256,host_mtu=1500 qmp set_link {"name":"net1","up":true} +net tap_commit ["tap8006i1","vmbr0","BA:DC:0F:FE:E0:01"] diff --git a/src/test/hotplug/net-change-bridge.conf.expected b/src/test/hotplug/net-change-bridge.conf.expected index a745b2e58e50..8f9d548cdddb 100644 --- a/src/test/hotplug/net-change-bridge.conf.expected +++ b/src/test/hotplug/net-change-bridge.conf.expected @@ -2,5 +2,7 @@ net tap_unplug ["tap8006i0"] qmp set_link {"name":"net0","up":false} sdn del_ips_from_mac ["vmbr0","A2:C0:43:77:08:A0","hotplug"] sdn add_next_free_cidr ["vmbr1","hotplug","A2:C0:43:77:08:A0","8006",null,1] -net tap_plug ["tap8006i0","vmbr1","100",null,null,null] +sdn add_dhcp_mapping ["vmbr1","A2:C0:43:77:08:A0","8006","hotplug"] +net tap_plug ["tap8006i0","vmbr1","100",null,null,null,{"mac":"A2:C0:43:77:08:A0","pending":1}] qmp set_link {"name":"net0","up":true} +net tap_commit ["tap8006i0","vmbr1","A2:C0:43:77:08:A0"] diff --git a/src/test/hotplug/net-change-model.conf.expected b/src/test/hotplug/net-change-model.conf.expected index b61756cd7c94..204470b28f2e 100644 --- a/src/test/hotplug/net-change-model.conf.expected +++ b/src/test/hotplug/net-change-model.conf.expected @@ -6,3 +6,4 @@ sdn add_dhcp_mapping ["vmbr0","A2:C0:43:77:08:A0","8006","hotplug"] qmp netdev_add {"downscript":"/usr/libexec/qemu-server/pve-bridgedown","id":"net0","ifname":"tap8006i0","script":"/usr/libexec/qemu-server/pve-bridge-hotplug","type":"tap"} hmp device_add driver=e1000,mac=A2:C0:43:77:08:A0,netdev=net0,bus=pci.0,addr=0x12,id=net0 qmp set_link {"name":"net0","up":true} +net tap_commit ["tap8006i0","vmbr0","A2:C0:43:77:08:A0"] diff --git a/src/test/hotplug/net-change-rate.conf.expected b/src/test/hotplug/net-change-rate.conf.expected index c4e24dae7bd0..c11e049e7fc9 100644 --- a/src/test/hotplug/net-change-rate.conf.expected +++ b/src/test/hotplug/net-change-rate.conf.expected @@ -1 +1,2 @@ net tap_rate_limit ["tap8006i0","10"] +net tap_commit ["tap8006i0","vmbr0","A2:C0:43:77:08:A0"] diff --git a/src/test/run_hotplug_tests.pl b/src/test/run_hotplug_tests.pl index fd3bc1fe4787..58f07eaf579f 100644 --- a/src/test/run_hotplug_tests.pl +++ b/src/test/run_hotplug_tests.pl @@ -663,7 +663,10 @@ $pve_common_network->mock( ); my $qemu_network_module = Test::MockModule->new('PVE::QemuServer::Network'); -$qemu_network_module->mock(tap_plug => recorder('net', 'tap_plug')); +$qemu_network_module->mock( + tap_plug => recorder('net', 'tap_plug'), + tap_commit => recorder('net', 'tap_commit'), +); my $sdn_vnets_module = Test::MockModule->new('PVE::Network::SDN::Vnets'); $sdn_vnets_module->mock( diff --git a/src/usr/pve-bridge b/src/usr/pve-bridge index c7260c6b5a82..c7ac7a3b3c5e 100755 --- a/src/usr/pve-bridge +++ b/src/usr/pve-bridge @@ -43,7 +43,13 @@ die "unable to parse network config '$netid'\n" if !$net; PVE::Network::SDN::Vnets::add_dhcp_mapping($net->{bridge}, $net->{macaddr}, $vmid, $conf->{name}); PVE::Network::SDN::Zones::tap_create($iface, $net->{bridge}); PVE::QemuServer::Network::tap_plug( - $iface, $net->{bridge}, $net->{tag}, $net->{firewall}, $net->{trunks}, $net->{rate}, + $iface, + $net->{bridge}, + $net->{tag}, + $net->{firewall}, + $net->{trunks}, + $net->{rate}, + { mac => $net->{macaddr}, pending => $hotplug }, ); exit 0; diff --git a/src/usr/pve-bridgedown b/src/usr/pve-bridgedown index e867b640207a..79a3722bd46a 100755 --- a/src/usr/pve-bridgedown +++ b/src/usr/pve-bridgedown @@ -2,7 +2,7 @@ use strict; use warnings; -use PVE::Network; +use PVE::Network::SDN::Zones; my $iface = shift; @@ -11,6 +11,6 @@ die "no interface specified\n" if !$iface; die "got strange interface name '$iface'\n" if $iface !~ m/^tap(\d+)i(\d+)$/; -PVE::Network::tap_unplug($iface); +PVE::Network::SDN::Zones::tap_unplug($iface); exit 0; -- 2.47.3