public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH pve-container] lxc: depend on pve-network instead of loading it optionally
@ 2026-10-15  8:10 Hannes Laimer
  2026-10-16 13:36 ` applied: " Wolfgang Bumiller
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Laimer @ 2026-10-15  8:10 UTC (permalink / raw)
  To: pve-devel

The SDN modules were loaded with a fallback to the plain bridge code
for a node without pve-network, from the time it was an optional
package. pve-manager depends on it since commit c3a5d35dbd67
("d/control: change recommendation of pve-network packages to hard
dependency"), so every node has it and the fallback never runs.
Declare the dependency and drop the fallback paths.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 debian/control            |  2 +-
 src/PVE/LXC.pm            | 63 +++++++++--------------------
 src/PVE/LXC/Config.pm     | 84 ++++++++++++++++-----------------------
 src/lxc-pve-prestart-hook | 23 ++++-------
 4 files changed, 61 insertions(+), 111 deletions(-)

diff --git a/debian/control b/debian/control
index 238bffc..ef57b13 100644
--- a/debian/control
+++ b/debian/control
@@ -28,6 +28,7 @@ Depends: binutils,
          libpve-cluster-perl,
          libpve-common-perl (>= 9.1.18~),
          libpve-guest-common-perl (>= 5.1.3),
+         libpve-network-perl (>= 0.8.3),
          libpve-rs-perl (>= 0.11~),
          libpve-storage-perl (>= 8.3.5),
          lxc-pve (>= 6.0.5-3~~),
@@ -40,6 +41,5 @@ Depends: binutils,
          xz-utils,
          ${misc:Depends},
          ${perl:Depends},
-Recommends: libpve-network-perl (>= 0.8.3),
 Description: Proxmox VE Container management tool
  Tool to manage Linux Containers on Proxmox VE.
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index dee073d..1f11490 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -25,6 +25,8 @@ use PVE::GuestHelpers qw(check_vnet_access safe_string_ne safe_num_ne safe_boole
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::Network;
+use PVE::Network::SDN::Vnets;
+use PVE::Network::SDN::Zones;
 use PVE::ProcFSTools;
 use PVE::RESTEnvironment;
 use PVE::SafeSyslog;
@@ -47,13 +49,6 @@ use PVE::LXC::Monitor;
 use PVE::LXC::Namespaces;
 use PVE::LXC::Tools;
 
-my $have_sdn;
-eval {
-    require PVE::Network::SDN::Zones;
-    require PVE::Network::SDN::Vnets;
-    $have_sdn = 1;
-};
-
 my $LXC_CONFIG_PATH = '/usr/share/lxc/config';
 
 my $nodename = PVE::INotify::nodename();
@@ -1115,22 +1110,10 @@ sub net_tap_plug : prototype($$) {
 
     my $create_firewall_bridges = $net->{firewall} && PVE::Firewall::Helpers::needs_fwbr($bridge);
 
-    if ($have_sdn) {
-        PVE::Network::SDN::Zones::tap_plug(
-            $iface, $bridge, $tag, $create_firewall_bridges, $trunks, $rate,
-        );
-        PVE::Network::SDN::Zones::add_bridge_fdb($iface, $hwaddr, $bridge);
-    } else {
-        PVE::Network::tap_plug(
-            $iface,
-            $bridge,
-            $tag,
-            $create_firewall_bridges,
-            $trunks,
-            $rate,
-            { mac => $hwaddr },
-        );
-    }
+    PVE::Network::SDN::Zones::tap_plug(
+        $iface, $bridge, $tag, $create_firewall_bridges, $trunks, $rate,
+    );
+    PVE::Network::SDN::Zones::add_bridge_fdb($iface, $hwaddr, $bridge);
 
     PVE::Tools::run_command(['/sbin/ip', 'link', 'set', 'dev', $iface, 'up']);
 }
@@ -1156,7 +1139,7 @@ sub update_net {
 
             PVE::Network::veth_delete($veth);
 
-            if ($have_sdn && safe_string_ne($oldnet->{hwaddr}, $newnet->{hwaddr})) {
+            if (safe_string_ne($oldnet->{hwaddr}, $newnet->{hwaddr})) {
                 eval {
                     PVE::Network::SDN::Vnets::del_ips_from_mac(
                         $oldnet->{bridge},
@@ -1193,7 +1176,7 @@ sub update_net {
 
                     PVE::Network::tap_unplug($veth);
 
-                    if ($have_sdn && $bridge_changed) {
+                    if ($bridge_changed) {
                         eval {
                             PVE::Network::SDN::Vnets::del_ips_from_mac(
                                 $oldbridge,
@@ -1205,7 +1188,7 @@ sub update_net {
                     }
                 }
 
-                if ($have_sdn && $bridge_changed) {
+                if ($bridge_changed) {
                     PVE::Network::SDN::Vnets::add_next_free_cidr(
                         $newnet->{bridge}, $conf->{hostname}, $newnet->{hwaddr}, $vmid, undef, 1,
                     );
@@ -1232,14 +1215,12 @@ sub update_net {
             PVE::LXC::Config->write_config($vmid, $conf);
         }
     } else {
-        if ($have_sdn) {
-            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},
-            );
-        }
+        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},
+        );
 
         hotplug_net($vmid, $conf, $opt, $newnet, $netid);
     }
@@ -1254,13 +1235,9 @@ sub hotplug_net {
     my $vethpeer = $veth . "p";
     my $eth = $newnet->{name};
 
-    if ($have_sdn) {
-        PVE::Network::SDN::Zones::veth_create(
-            $veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr},
-        );
-    } else {
-        PVE::Network::veth_create($veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr});
-    }
+    PVE::Network::SDN::Zones::veth_create(
+        $veth, $vethpeer, $newnet->{bridge}, $newnet->{hwaddr},
+    );
 
     PVE::LXC::net_tap_plug($veth, $newnet);
 
@@ -3479,8 +3456,6 @@ sub thaw($) {
 sub create_ifaces_ipams_ips {
     my ($conf, $vmid) = @_;
 
-    return if !$have_sdn;
-
     for my $opt (keys %$conf) {
         next if $opt !~ m/^net(\d+)$/;
         my $net = PVE::LXC::Config->parse_lxc_network($conf->{$opt});
@@ -3494,8 +3469,6 @@ sub create_ifaces_ipams_ips {
 sub delete_ifaces_ipams_ips {
     my ($conf, $vmid) = @_;
 
-    return if !$have_sdn;
-
     for my $opt (keys %$conf) {
         next if $opt !~ m/^net(\d+)$/;
         my $net = PVE::LXC::Config->parse_lxc_network($conf->{$opt});
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 5c6804b..9823d00 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -11,6 +11,7 @@ use PVE::DataCenterConfig;
 use PVE::GuestHelpers;
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::Network::SDN::Vnets;
 use PVE::RESTEnvironment;
 use PVE::Tools;
 
@@ -24,12 +25,6 @@ use constant {
     FITHAW => 0xc0045878,
 };
 
-my $have_sdn;
-eval {
-    require PVE::Network::SDN::Vnets;
-    $have_sdn = 1;
-};
-
 my $nodename = PVE::INotify::nodename();
 my $lock_handles = {};
 my $lockdir = "/run/lock/lxc";
@@ -1702,17 +1697,15 @@ sub vmconfig_hotplug_pending {
                 PVE::LXC::kill_dhclients($vmid, $net->{name}) if $net->{'host-managed'};
 
                 PVE::Network::veth_delete("veth${vmid}i$netid");
-                if ($have_sdn) {
-                    print "delete ips from $opt\n";
-                    eval {
-                        PVE::Network::SDN::Vnets::del_ips_from_mac(
-                            $net->{bridge},
-                            $net->{hwaddr},
-                            $conf->{hostname},
-                        );
-                    };
-                    warn $@ if $@;
-                }
+                print "delete ips from $opt\n";
+                eval {
+                    PVE::Network::SDN::Vnets::del_ips_from_mac(
+                        $net->{bridge},
+                        $net->{hwaddr},
+                        $conf->{hostname},
+                    );
+                };
+                warn $@ if $@;
             } else {
                 die "skip\n"; # skip non-hotpluggable opts
             }
@@ -1811,17 +1804,15 @@ sub vmconfig_apply_pending {
                     },
                 );
             } elsif ($opt =~ m/^net(\d+)$/) {
-                if ($have_sdn) {
-                    my $net = $class->parse_lxc_network($conf->{$opt});
-                    eval {
-                        PVE::Network::SDN::Vnets::del_ips_from_mac(
-                            $net->{bridge},
-                            $net->{hwaddr},
-                            $conf->{hostname},
-                        );
-                    };
-                    warn $@ if $@;
-                }
+                my $net = $class->parse_lxc_network($conf->{$opt});
+                eval {
+                    PVE::Network::SDN::Vnets::del_ips_from_mac(
+                        $net->{bridge},
+                        $net->{hwaddr},
+                        $conf->{hostname},
+                    );
+                };
+                warn $@ if $@;
             }
         };
         if (my $err = $@) {
@@ -1844,28 +1835,17 @@ sub vmconfig_apply_pending {
                 my $netid = $1;
                 my $net = $class->parse_lxc_network($conf->{pending}->{$opt});
                 $conf->{pending}->{$opt} = $class->print_lxc_network($net);
-                if ($have_sdn) {
-                    if ($conf->{$opt}) {
-                        my $old_net = $class->parse_lxc_network($conf->{$opt});
-                        if (
-                            $old_net->{bridge} ne $net->{bridge}
-                            || $old_net->{hwaddr} ne $net->{hwaddr}
-                        ) {
-                            PVE::Network::SDN::Vnets::del_ips_from_mac(
-                                $old_net->{bridge},
-                                $old_net->{hwaddr},
-                                $conf->{name},
-                            );
-                            PVE::Network::SDN::Vnets::add_next_free_cidr(
-                                $net->{bridge},
-                                $conf->{hostname},
-                                $net->{hwaddr},
-                                $vmid,
-                                undef,
-                                1,
-                            );
-                        }
-                    } else {
+                if ($conf->{$opt}) {
+                    my $old_net = $class->parse_lxc_network($conf->{$opt});
+                    if (
+                        $old_net->{bridge} ne $net->{bridge}
+                        || $old_net->{hwaddr} ne $net->{hwaddr}
+                    ) {
+                        PVE::Network::SDN::Vnets::del_ips_from_mac(
+                            $old_net->{bridge},
+                            $old_net->{hwaddr},
+                            $conf->{name},
+                        );
                         PVE::Network::SDN::Vnets::add_next_free_cidr(
                             $net->{bridge},
                             $conf->{hostname},
@@ -1875,6 +1855,10 @@ sub vmconfig_apply_pending {
                             1,
                         );
                     }
+                } else {
+                    PVE::Network::SDN::Vnets::add_next_free_cidr(
+                        $net->{bridge}, $conf->{hostname}, $net->{hwaddr}, $vmid, undef, 1,
+                    );
                 }
             }
         };
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index 2bfce31..e88347d 100755
--- a/src/lxc-pve-prestart-hook
+++ b/src/lxc-pve-prestart-hook
@@ -16,18 +16,13 @@ use PVE::LXC::Config;
 use PVE::LXC::Setup;
 use PVE::LXC::Tools;
 use PVE::LXC;
+use PVE::Network::SDN::Vnets;
 use PVE::RESTEnvironment;
 use PVE::SafeSyslog;
 use PVE::Storage;
 use PVE::Syscall qw(:fsmount);
 use PVE::Tools qw(AT_FDCWD O_PATH);
 
-my $have_sdn;
-eval {
-    require PVE::Network::SDN::Vnets;
-    $have_sdn = 1;
-};
-
 PVE::LXC::Tools::lxc_hook(
     'pre-start',
     'lxc',
@@ -220,15 +215,13 @@ PVE::LXC::Tools::lxc_hook(
             PVE::Tools::file_set_contents("/var/lib/lxc/$vmid/passthrough/devices", $devlist);
         }
 
-        if ($have_sdn) {
-            for my $k (keys %$conf) {
-                next if $k !~ /^net(\d+)/;
-                my $net = PVE::LXC::Config->parse_lxc_network($conf->{$k});
-                next if $net->{type} ne 'veth';
-                PVE::Network::SDN::Vnets::add_dhcp_mapping(
-                    $net->{bridge}, $net->{hwaddr}, $vmid, $conf->{hostname},
-                );
-            }
+        for my $k (keys %$conf) {
+            next if $k !~ /^net(\d+)/;
+            my $net = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+            next if $net->{type} ne 'veth';
+            PVE::Network::SDN::Vnets::add_dhcp_mapping(
+                $net->{bridge}, $net->{hwaddr}, $vmid, $conf->{hostname},
+            );
         }
     },
 );
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-16 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15  8:10 [PATCH pve-container] lxc: depend on pve-network instead of loading it optionally Hannes Laimer
2026-10-16 13:36 ` applied: " Wolfgang Bumiller

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