From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-container v7 15/21] net: report NIC plugs and removals to the SDN DHCP backends
Date: Thu, 12 Nov 2026 13:41:55 +0100 [thread overview]
Message-ID: <20261112124201.2844423-16-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261112124201.2844423-1-h.laimer@proxmox.com>
An SDN DHCP backend answers a guest NIC with the address IPAM holds
for its MAC. A NIC joining its bridge now hands its MAC to the SDN
plug, so the backend of its vnet can answer it. Deleting a veth also
reports it as gone to the backends, since their state for an
interface can outlive it.
A hotplug moves the veth while its 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.
On a running container, a bridge change now pushes the DHCP mapping
for the new vnet, as adding a NIC or changing its MAC already does.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
src/PVE/LXC.pm | 33 +++++++++++++++++++++++++++------
src/PVE/LXC/Config.pm | 3 ++-
src/lxc-pve-poststop-hook | 6 +++---
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 59d803d2592c..aea41a545abe 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1074,8 +1074,8 @@ sub vm_stop_cleanup {
kill_dhclients($vmid);
}
-sub net_tap_plug : prototype($$) {
- my ($iface, $net) = @_;
+sub net_tap_plug : prototype($$;$) {
+ my ($iface, $net, $pending) = @_;
if ($net->{link_down}) {
PVE::Tools::run_command(['/sbin/ip', 'link', 'set', 'dev', $iface, 'down']);
@@ -1090,13 +1090,27 @@ sub net_tap_plug : prototype($$) {
my $create_firewall_bridges = $net->{firewall} && PVE::Firewall::Helpers::needs_fwbr($bridge);
PVE::Network::SDN::Zones::tap_plug(
- $iface, $bridge, $tag, $create_firewall_bridges, $trunks, $rate,
+ $iface,
+ $bridge,
+ $tag,
+ $create_firewall_bridges,
+ $trunks,
+ $rate,
+ { mac => $hwaddr, pending => $pending },
);
PVE::Network::SDN::Zones::add_bridge_fdb($iface, $hwaddr, $bridge);
PVE::Tools::run_command(['/sbin/ip', 'link', 'set', 'dev', $iface, 'up']);
}
+# the SDN DHCP backends serve a hotplugged NIC only once its change is applied to the config
+sub net_tap_commit {
+ my ($iface, $net) = @_;
+
+ return if $net->{link_down} || !$net->{bridge};
+ PVE::Network::SDN::Zones::tap_commit($iface, $net->{bridge}, $net->{hwaddr});
+}
+
sub update_net {
my ($vmid, $conf, $opt, $newnet, $netid, $rootdir) = @_;
@@ -1116,7 +1130,7 @@ sub update_net {
|| safe_string_ne($oldnet->{name}, $newnet->{name})
) {
- PVE::Network::veth_delete($veth);
+ PVE::Network::SDN::Zones::veth_delete($veth);
if (safe_string_ne($oldnet->{hwaddr}, $newnet->{hwaddr})) {
eval {
@@ -1171,8 +1185,11 @@ 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) };
+ eval { PVE::LXC::net_tap_plug($veth, $newnet, 1) };
if (my $err = $@) {
eval { PVE::LXC::net_tap_plug($veth, $oldnet) };
warn "restoring old network due to hot-plug failure for $veth failed - $@"
@@ -1192,6 +1209,8 @@ sub update_net {
}
$conf->{$opt} = PVE::LXC::Config->print_lxc_network($oldnet);
PVE::LXC::Config->write_config($vmid, $conf);
+ # $oldnet keeps a link_down that the change cleared
+ net_tap_commit($veth, $newnet);
}
} else {
PVE::Network::SDN::Vnets::add_next_free_cidr(
@@ -1218,7 +1237,7 @@ sub hotplug_net {
$veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr},
);
- PVE::LXC::net_tap_plug($veth, $newnet);
+ PVE::LXC::net_tap_plug($veth, $newnet, 1);
# attach peer in container
my $cmd = ['lxc-device', '-n', $vmid, 'add', $vethpeer, "$eth"];
@@ -1236,6 +1255,8 @@ sub hotplug_net {
$conf->{$opt} = PVE::LXC::Config->print_lxc_network($done);
PVE::LXC::Config->write_config($vmid, $conf);
+
+ net_tap_commit($veth, $newnet);
}
sub get_interfaces {
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index b2f623394b21..14bc60a22b8d 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -12,6 +12,7 @@ use PVE::GuestHelpers;
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Network::SDN::Vnets;
+use PVE::Network::SDN::Zones;
use PVE::RESTEnvironment;
use PVE::Tools;
@@ -1699,7 +1700,7 @@ sub vmconfig_hotplug_pending {
my $net = $class->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::Network::SDN::Zones::veth_delete("veth${vmid}i$netid");
print "delete ips from $opt\n";
eval {
PVE::Network::SDN::Vnets::del_ips_from_mac(
diff --git a/src/lxc-pve-poststop-hook b/src/lxc-pve-poststop-hook
index c8bbb7972156..c5d1059fae02 100755
--- a/src/lxc-pve-poststop-hook
+++ b/src/lxc-pve-poststop-hook
@@ -11,7 +11,7 @@ use PVE::GuestHelpers;
use PVE::LXC::Config;
use PVE::LXC::Tools;
use PVE::LXC;
-use PVE::Network;
+use PVE::Network::SDN::Zones;
use PVE::RESTEnvironment;
use PVE::Storage;
use PVE::Tools;
@@ -49,8 +49,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::Network::SDN::Zones::veth_delete("veth${vmid}i$ind");
}
my $config_updated = 0;
--
2.47.3
next prev parent reply other threads:[~2026-11-12 12:43 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 ` [PATCH qemu-server v7 14/21] network: sdn: keep the DHCP backends current on guest NICs Hannes Laimer
2026-11-12 12:41 ` Hannes Laimer [this message]
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-16-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.