all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v2 09/16] sdn: zones: attach the dhcp responder on tap plug, detach on unplug
Date: Wed,  9 Sep 2026 12:41:37 +0200	[thread overview]
Message-ID: <20260909104144.1110031-10-h.laimer@proxmox.com> (raw)
In-Reply-To: <20260909104144.1110031-1-h.laimer@proxmox.com>

Program attach is per guest interface and the plug is the one moment
every such interface passes through on this node, covering guest
start, hotplug and incoming migration. The responder attaches before
the interface joins the bridge, so a guest already running cannot slip
its first request past it. The plug hands over the MAC of the guest
NIC, which the responder answers the interface for. Attach failures
only warn, a guest start must not depend on the responder. An unplug
reaches the backends the same way, with the interface alone, since its
zone is gone with it. A tap plugged onto a plain bridge is reported to
the backends as well, so a responder still attached to it lets go.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/PVE/Network/SDN/Zones.pm        |  31 ++++++-
 src/test/run_test_vnets_blackbox.pl | 129 ++++++++++++++++++++++++++++
 2 files changed, 156 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Network/SDN/Zones.pm b/src/PVE/Network/SDN/Zones.pm
index f668303..cda8176 100644
--- a/src/PVE/Network/SDN/Zones.pm
+++ b/src/PVE/Network/SDN/Zones.pm
@@ -323,16 +323,18 @@ sub veth_create {
 }
 
 sub tap_plug {
-    my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_;
+    my ($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts) = @_;
 
     my $vnet = PVE::Network::SDN::Vnets::get_vnet($bridge, 1);
     if (!$vnet) { # fallback for classic bridge
         my $interfaces_config = PVE::INotify::read_file('interfaces');
-        my $opts = {};
-        $opts->{learning} = 0
+        my $bridge_opts = {};
+        $bridge_opts->{learning} = 0
             if $interfaces_config->{ifaces}->{$bridge}
             && $interfaces_config->{ifaces}->{$bridge}->{'bridge-disable-mac-learning'};
-        PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, $opts);
+        # the dhcp backends hear of an interface moving onto a plain bridge as well
+        PVE::Network::SDN::Dhcp::tap_plug($bridge, $iface, $opts->{mac});
+        PVE::Network::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate, $bridge_opts);
         return;
     }
 
@@ -343,9 +345,30 @@ sub tap_plug {
         if $plugin_config->{nodes} && !defined($plugin_config->{nodes}->{$nodename});
 
     my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
+
+    # the responder attaches before the interface joins the bridge, so a running guest cannot
+    # slip its first request past it. Loaded through Vnets, a use here would close a
+    # load-order cycle
+    PVE::Network::SDN::Dhcp::tap_plug($bridge, $iface, $opts->{mac});
     $plugin->tap_plug($plugin_config, $vnet, $tag, $iface, $bridge, $firewall, $trunks, $rate);
 }
 
+# the interface is gone or leaving, the dhcp backends drop what they hold
+# for it before the bridge side is cleaned up
+sub tap_unplug {
+    my ($iface) = @_;
+
+    PVE::Network::SDN::Dhcp::tap_unplug($iface);
+    PVE::Network::tap_unplug($iface);
+}
+
+sub veth_delete {
+    my ($veth) = @_;
+
+    PVE::Network::SDN::Dhcp::tap_unplug($veth);
+    PVE::Network::veth_delete($veth);
+}
+
 sub add_bridge_fdb {
     my ($iface, $macaddr, $bridge) = @_;
 
diff --git a/src/test/run_test_vnets_blackbox.pl b/src/test/run_test_vnets_blackbox.pl
index 2af4880..064a96c 100755
--- a/src/test/run_test_vnets_blackbox.pl
+++ b/src/test/run_test_vnets_blackbox.pl
@@ -1770,6 +1770,135 @@ sub test_ebpf_backend_edge_cases {
 }
 
 run_test(\&test_ebpf_backend);
+
+sub test_zone_tap_plug {
+    my $test_name = (split(/::/, (caller(0))[3]))[-1];
+    my $zoneid = "TESTZONE";
+    my $vnetid = "testvnet";
+    my $mac = "da:65:8f:18:9b:6f";
+
+    # the zone plug hands the MAC on to the dhcp backends, a plug onto a
+    # plain bridge tells them where the interface went
+    create_zone({
+        type => "simple",
+        dhcp => "ebpf",
+        ipam => "pve",
+        zone => $zoneid,
+    });
+    create_vnet({
+        type => "vnet",
+        zone => $zoneid,
+        vnet => $vnetid,
+    });
+    create_subnet({
+        type => "subnet",
+        vnet => $vnetid,
+        subnet => "10.0.0.0/24",
+        gateway => "10.0.0.1",
+        'dhcp-range' => ["start-address=10.0.0.100,end-address=10.0.0.200"],
+    });
+    create_ip({
+        zone => $zoneid,
+        vnet => $vnetid,
+        mac => $mac,
+        ip => "10.0.0.100",
+    });
+    my $bridged = [];
+    my $unplugged = [];
+    $mocked_sdn_zones_super_plugin->mock(
+        tap_plug => sub {
+            push @$bridged, $_[5];
+            push $test_state->{order}->@*, 'bridge';
+        },
+    );
+    my $mocked_pve_network = Test::MockModule->new('PVE::Network');
+    $mocked_pve_network->mock(
+        tap_plug => sub {
+            push @$bridged, $_[1];
+            push $test_state->{order}->@*, 'bridge';
+        },
+        tap_unplug => sub { push @$unplugged, $_[0]; },
+        veth_delete => sub { push @$unplugged, $_[0]; },
+    );
+    $mocked_pve_inotify->mock(read_file => sub { return { ifaces => {} }; });
+    take_ebpf_calls();
+    take_order();
+
+    PVE::Network::SDN::Zones::tap_plug('tap999i0', $vnetid, undef, 0, undef, undef,
+        { mac => $mac });
+    eq_or_diff($bridged, [$vnetid], "$test_name: the zone plugin plugs the interface");
+    eq_or_diff(
+        take_ebpf_calls(),
+        [{ method => 'attach', args => ['tap999i0', $vnetid, $ebpf_record->("10.0.0.100")] }],
+        "$test_name: and the dhcp backend attaches it with the MAC's record",
+    );
+    is_deeply(
+        take_order(),
+        ['draw', 'refresh', 'write', 'bridge'],
+        "$test_name: the responder attaches before the interface joins the bridge",
+    );
+
+    @$bridged = ();
+    PVE::Network::SDN::Zones::tap_plug('tap999i0', 'vmbr0', undef, 0, undef, undef,
+        { mac => $mac });
+    eq_or_diff($bridged, ['vmbr0'], "$test_name: a plain bridge is plugged the classic way");
+    eq_or_diff(
+        take_ebpf_calls(),
+        [{ method => 'detach', args => ['tap999i0', { vnet => undef }] }],
+        "$test_name: and the dhcp backends hear where the interface went",
+    );
+
+    # a vnet of another backend is a place the ebpf backend hears of as well
+    create_zone({
+        type => "simple",
+        dhcp => "dnsmasq",
+        ipam => "pve",
+        zone => "DNSZONE",
+    });
+    create_vnet({
+        type => "vnet",
+        zone => "DNSZONE",
+        vnet => "dnsvnet",
+    });
+    @$bridged = ();
+    PVE::Network::SDN::Zones::tap_plug(
+        'tap999i0',
+        'dnsvnet',
+        undef,
+        0,
+        undef,
+        undef,
+        { mac => $mac },
+    );
+    eq_or_diff(
+        $bridged,
+        ['dnsvnet'],
+        "$test_name: a vnet of another backend is plugged by its zone",
+    );
+    eq_or_diff(
+        take_ebpf_calls(),
+        [{ method => 'detach', args => ['tap999i0', { vnet => 'dnsvnet' }] }],
+        "$test_name: and the ebpf backend hears which vnet the interface went to",
+    );
+
+    # the zone unplug and the veth delete report the interface gone before
+    # the classic ones run
+    PVE::Network::SDN::Zones::tap_unplug('tap999i0');
+    PVE::Network::SDN::Zones::veth_delete('veth999i0');
+    eq_or_diff($unplugged, ['tap999i0', 'veth999i0'], "$test_name: the classic unplugs run");
+    eq_or_diff(
+        take_ebpf_calls(),
+        [
+            { method => 'detach', args => ['tap999i0', undef] },
+            { method => 'detach', args => ['veth999i0', undef] },
+        ],
+        "$test_name: and the dhcp backends hear the interfaces are gone",
+    );
+    $mocked_sdn_zones_super_plugin->unmock('tap_plug');
+    $mocked_pve_inotify->unmock('read_file');
+}
+
+run_test(\&test_zone_tap_plug);
 run_test(\&test_ebpf_backend_edge_cases);
 
 sub test_ebpf_mac_case {
-- 
2.47.3





  parent reply	other threads:[~2026-09-09 10:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 10:41 [PATCH container/docs/manager/network/proxmox{-ebpf,-perl-rs}/qemu-server v2 00/16] sdn: implement DHCP for all zones using eBPF Hannes Laimer
2026-09-09 10:41 ` [PATCH proxmox-ebpf v2 01/16] dhcp: add per-tap responder BPF program Hannes Laimer
2026-09-09 10:41 ` [PATCH proxmox-ebpf v2 02/16] dhcp: add responder subsystem Hannes Laimer
2026-09-09 10:41 ` [PATCH proxmox-perl-rs v2 03/16] pve-rs: sdn: add dhcp responder bindings Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 04/16] sdn: push mapping changes from the ipam API to the dhcp backend Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 05/16] sdn: ipam: do not cache negative per-MAC answers, lock the write Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 06/16] sdn: subnets: add dhcp-lease-time property Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 07/16] sdn: dhcp: only assert a backend's availability for zones using it Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 08/16] sdn: dhcp: add ebpf plugin Hannes Laimer
2026-09-09 10:41 ` Hannes Laimer [this message]
2026-09-09 10:41 ` [PATCH pve-network v2 10/16] sdn: dhcp: apply mapping edits on the node serving the guest Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-network v2 11/16] sdn: zones: offer dhcp on all zone types, keep dnsmasq simple-only Hannes Laimer
2026-09-09 10:41 ` [PATCH qemu-server v2 12/16] network: report NIC plug and unplug to SDN with the MAC Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-container v2 13/16] net: report veth plug and unplug to SDN with the hwaddr Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-manager v2 14/16] ui: sdn: dhcp backend selector on all zones, expose dhcp options Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-manager v2 15/16] sdn: bring the dhcp backends up at boot before the guests start Hannes Laimer
2026-09-09 10:41 ` [PATCH pve-docs v2 16/16] sdn: dhcp: document the ebpf backend 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=20260909104144.1110031-10-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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal