public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
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	[thread overview]
Message-ID: <20261112124201.2844423-15-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261112124201.2844423-1-h.laimer@proxmox.com>

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 <h.laimer@proxmox.com>
---

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





  parent reply	other threads:[~2026-11-12 12:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 12:41 [PATCH container/docs/manager/network/proxmox{,-perl-rs,-ve-rs}/qemu-server v7 00/21] sdn: implement DHCP for all zones using eBPF Hannes Laimer
2026-11-12 12:41 ` [PATCH proxmox v7 01/21] network-types: mac address: add an accessor for the bytes Hannes Laimer
2026-11-12 12:41 ` [PATCH proxmox-perl-rs v7 02/21] pve-rs: sdn: add bindings for the eBPF DHCP responder Hannes Laimer
2026-11-12 12:41 ` [PATCH proxmox-perl-rs v7 03/21] pve-rs: fire the pve-ebpf-update trigger on upgrade Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 04/21] sdn: zones: take the VXLAN and EVPN MTU from the underlay interface Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 05/21] sdn: zones: account for IPv6 in the VXLAN and EVPN MTU Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 06/21] sdn: dhcp: make the lease time configurable per subnet Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 07/21] sdn: dhcp: require a backend only if a zone on this node uses it Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 08/21] bpf: add the build, the package and a native harness for BPF programs Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 09/21] sdn: dhcp: add the per-tap DHCPv4 responder program Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 10/21] sdn: dhcp: add an eBPF backend answering on each guest interface Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 11/21] sdn: zones: report interface plugs and unplugs to the DHCP backends Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 12/21] sdn: zones: factor out the underlay lookup of VXLAN and EVPN zones Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-network v7 13/21] sdn: zones: allow the ebpf DHCP backend on every zone type Hannes Laimer
2026-11-12 12:41 ` Hannes Laimer [this message]
2026-11-12 12:41 ` [PATCH pve-container v7 15/21] net: report NIC plugs and removals to the SDN DHCP backends Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-manager v7 16/21] ui: sdn: add zone DHCP backend selector and subnet DHCP options Hannes Laimer
2026-11-12 12:41 ` [PATCH pve-manager v7 17/21] sdn: bring up the DHCP backends at boot before the guests start Hannes Laimer
2026-11-12 12:41 ` [PATCH proxmox-ve-rs v7 18/21] ve-config: sdn: add the ebpf dhcp backend Hannes Laimer
2026-11-12 12:41 ` [PATCH proxmox-ve-rs v7 19/21] sdn-dhcp: add the crate that runs the eBPF DHCP responder Hannes Laimer
2026-11-12 12:42 ` [PATCH pve-docs v7 20/21] sdn: zones: document the MTU taken from the underlay interface Hannes Laimer
2026-11-12 12:42 ` [PATCH pve-docs v7 21/21] sdn: dhcp: add eBPF backend section Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112124201.2844423-15-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal