public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning
@ 2025-07-24  9:32 Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 1/4] network-interface-pinning: use ifindex as order for pinning Stefan Hanreich
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:32 UTC (permalink / raw)
  To: pve-devel

Several improvements to the network interface pinning tool:
* interfaces are now iterated according to ifindex
* output of the mapping is now sorted and less verbose
* users can now set a specific target name
* if has been introduced as an additional legal prefix

Still looking into removing the PHYSICAL_NIC_RE altogether, but sending this
patch series as-is nevertheless for review / feedback. If I manage to remove the
PHYSICAL_NIC_RE in time, we could get rid of the constraints of prefix /
target-name altogether...

pve-manager:

Stefan Hanreich (4):
  network-interface-pinning: use ifindex as order for pinning
  network-interface-pinning: improve printing mapping
  network-interface-pinning: add target-name parameter
  network-interface-pinning: add if prefix to list of allowed prefixes

 PVE/CLI/proxmox_network_interface_pinning.pm | 76 +++++++++++++++++---
 1 file changed, 65 insertions(+), 11 deletions(-)


Summary over all repositories:
  1 files changed, 65 insertions(+), 11 deletions(-)

-- 
Generated by git-murpp 0.8.0

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH pve-manager 1/4] network-interface-pinning: use ifindex as order for pinning
  2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
@ 2025-07-24  9:32 ` Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 2/4] network-interface-pinning: improve printing mapping Stefan Hanreich
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:32 UTC (permalink / raw)
  To: pve-devel

While ifindex is not guaranteed to be stable across reboots, it seems
like a good enough heuristic for making sure interfaces with multiple
ports are clamped together when pinning.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/CLI/proxmox_network_interface_pinning.pm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/proxmox_network_interface_pinning.pm b/PVE/CLI/proxmox_network_interface_pinning.pm
index 3f1a83f10..05b1de38a 100644
--- a/PVE/CLI/proxmox_network_interface_pinning.pm
+++ b/PVE/CLI/proxmox_network_interface_pinning.pm
@@ -257,7 +257,11 @@ package PVE::CLI::proxmox_network_interface_pinning::InterfaceMapping {
 
         my %existing_names = map { $_ => 1 } values $pinned->%*;
 
-        for my $ifname (sort keys $ip_links->%*) {
+        my @sorted_links = sort {
+            $ip_links->{$a}->{ifindex} <=> $ip_links->{$b}->{ifindex};
+        } keys $ip_links->%*;
+
+        for my $ifname (@sorted_links) {
             my $ip_link = $ip_links->{$ifname};
             my $generated_name;
 
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH pve-manager 2/4] network-interface-pinning: improve printing mapping
  2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 1/4] network-interface-pinning: use ifindex as order for pinning Stefan Hanreich
@ 2025-07-24  9:32 ` Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 3/4] network-interface-pinning: add target-name parameter Stefan Hanreich
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:32 UTC (permalink / raw)
  To: pve-devel

Instead of printing a separate line for each altname, the tool now
only prints one line per physical interface. The primary name is used
as an identifier and the altnames are printed additionally in
parentheses (if they exist). Additionally, the output is now sorted by
ifindex (just as the pin order), so interfaces should now be printed
in ascending order.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/CLI/proxmox_network_interface_pinning.pm | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/PVE/CLI/proxmox_network_interface_pinning.pm b/PVE/CLI/proxmox_network_interface_pinning.pm
index 05b1de38a..2fb5338e9 100644
--- a/PVE/CLI/proxmox_network_interface_pinning.pm
+++ b/PVE/CLI/proxmox_network_interface_pinning.pm
@@ -414,8 +414,26 @@ __PACKAGE__->register_method({
                 exit 0;
             }
 
-            for my $old_name (sort keys $mapping->%*) {
-                print "Name for link '$old_name' will change to '$mapping->{$old_name}'\n";
+            my $altnames = PVE::Network::altname_mapping($ip_links);
+
+            my @sorted_links = sort {
+                my $a_name = $altnames->{$a} // $a;
+                my $b_name = $altnames->{$b} // $b;
+
+                $ip_links->{$a_name}->{ifindex} <=> $ip_links->{$b_name}->{ifindex};
+            } grep { $ip_links->{$_} } keys $mapping->%*;
+
+            for my $old_name (@sorted_links) {
+                my $altname_string = '';
+
+                if (my $interface_altnames = $ip_links->{$old_name}->{altnames}) {
+                    $altname_string = join(', ', $interface_altnames->@*);
+                }
+
+                print "Name for link '$old_name' ";
+                print "($altname_string) " if $altname_string;
+                print "will change to '$mapping->{$old_name}'\n";
+
             }
 
             generate_link_files($ip_links, $mapping);
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH pve-manager 3/4] network-interface-pinning: add target-name parameter
  2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 1/4] network-interface-pinning: use ifindex as order for pinning Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 2/4] network-interface-pinning: improve printing mapping Stefan Hanreich
@ 2025-07-24  9:32 ` Stefan Hanreich
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 4/4] network-interface-pinning: add if prefix to list of allowed prefixes Stefan Hanreich
  2025-07-24  9:35 ` [pve-devel] superseded: [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:32 UTC (permalink / raw)
  To: pve-devel

If a specific interface is specified via the interface parameter,
users can now additionally specify a target-name. This makes it easier
for users to assign specific names to specific interfaces, according
to their preferences.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/CLI/proxmox_network_interface_pinning.pm | 38 ++++++++++++++++----
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/PVE/CLI/proxmox_network_interface_pinning.pm b/PVE/CLI/proxmox_network_interface_pinning.pm
index 2fb5338e9..1c042f843 100644
--- a/PVE/CLI/proxmox_network_interface_pinning.pm
+++ b/PVE/CLI/proxmox_network_interface_pinning.pm
@@ -249,6 +249,11 @@ package PVE::CLI::proxmox_network_interface_pinning::InterfaceMapping {
     use PVE::CLI::proxmox_network_interface_pinning;
     use PVE::Tools;
 
+    sub new {
+        my ($class, $mapping) = @_;
+        bless $mapping, $class;
+    }
+
     sub generate {
         my ($class, $ip_links, $pinned, $prefix) = @_;
 
@@ -362,6 +367,12 @@ __PACKAGE__->register_method({
                 default => '<all>', # just for the docs.
                 optional => 1,
             },
+            'target-name' => {
+                description => 'Pin the interface to a specific name',
+                type => 'string',
+                pattern => 'nic\d+',
+                optional => 1,
+            },
         },
     },
     returns => {
@@ -371,6 +382,10 @@ __PACKAGE__->register_method({
         my ($params) = @_;
 
         my $iface = $params->{interface}; # undef means all.
+        my $target_name = $params->{'target-name'};
+
+        die "target-name can only be set, if interface is set as well!\n"
+            if $params->{'target-name'} && !$params->{interface};
 
         if (-t STDOUT) {
             my $target = defined($iface) ? "the interface '$iface'" : 'all interfaces';
@@ -402,12 +417,23 @@ __PACKAGE__->register_method({
                 }
             }
 
-            my $mapping =
-                PVE::CLI::proxmox_network_interface_pinning::InterfaceMapping->generate(
-                    $ip_links,
-                    $pinned,
-                    $prefix,
-                );
+            my $mapping;
+
+            if ($target_name) {
+                die "target-name already exists as link or pin!\n"
+                    if $ip_links->{$target_name} || grep { $target_name eq $_ } values $pinned->%*;
+
+                $mapping = PVE::CLI::proxmox_network_interface_pinning::InterfaceMapping->new({
+                        $iface => $target_name,
+                    });
+            } else {
+                $mapping =
+                    PVE::CLI::proxmox_network_interface_pinning::InterfaceMapping->generate(
+                        $ip_links,
+                        $pinned,
+                        $prefix,
+                    );
+            }
 
             if (!$mapping->%*) {
                 print "Nothing to do, aborting.\n";
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] [PATCH pve-manager 4/4] network-interface-pinning: add if prefix to list of allowed prefixes
  2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
                   ` (2 preceding siblings ...)
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 3/4] network-interface-pinning: add target-name parameter Stefan Hanreich
@ 2025-07-24  9:32 ` Stefan Hanreich
  2025-07-24  9:35 ` [pve-devel] superseded: [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:32 UTC (permalink / raw)
  To: pve-devel

'if' has been added as a possible prefix for physical nics in
pve-common. Add it as a possible prefix for pinning network interfaces
here as well.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/CLI/proxmox_network_interface_pinning.pm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/PVE/CLI/proxmox_network_interface_pinning.pm b/PVE/CLI/proxmox_network_interface_pinning.pm
index 1c042f843..71ac0291b 100644
--- a/PVE/CLI/proxmox_network_interface_pinning.pm
+++ b/PVE/CLI/proxmox_network_interface_pinning.pm
@@ -359,7 +359,6 @@ __PACKAGE__->register_method({
     parameters => {
         additionalProperties => 0,
         properties => {
-            # TODO: support a target name or prefix once pve-common supports generic physical ifaces
             interface => {
                 description => 'Only pin a specific interface.',
                 type => 'string',
@@ -367,10 +366,17 @@ __PACKAGE__->register_method({
                 default => '<all>', # just for the docs.
                 optional => 1,
             },
+            prefix => {
+                description => 'Only pin a specific interface.',
+                type => 'string',
+                enum => ['nic', 'if'],
+                default => 'nic', # just for the docs.
+                optional => 1,
+            },
             'target-name' => {
                 description => 'Pin the interface to a specific name',
                 type => 'string',
-                pattern => 'nic\d+',
+                pattern => '(?:nic|if)\d+',
                 optional => 1,
             },
         },
@@ -398,7 +404,7 @@ __PACKAGE__->register_method({
         }
 
         my $code = sub {
-            my $prefix = 'nic'; # TODO: make flexible once pve-common supports that.
+            my $prefix = $params->{prefix} // 'nic';
 
             my $ip_links = get_ip_links();
             my $pinned = get_pinned();
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] superseded: [PATCH manager 0/4] improvements to proxmox-network-interface-pinning
  2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
                   ` (3 preceding siblings ...)
  2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 4/4] network-interface-pinning: add if prefix to list of allowed prefixes Stefan Hanreich
@ 2025-07-24  9:35 ` Stefan Hanreich
  4 siblings, 0 replies; 6+ messages in thread
From: Stefan Hanreich @ 2025-07-24  9:35 UTC (permalink / raw)
  To: pve-devel

forgot to run make tidy...

https://lore.proxmox.com/pve-devel/20250724093459.76397-1-s.hanreich@proxmox.com/T/#t

On 7/24/25 11:32, Stefan Hanreich wrote:
> Several improvements to the network interface pinning tool:
> * interfaces are now iterated according to ifindex
> * output of the mapping is now sorted and less verbose
> * users can now set a specific target name
> * if has been introduced as an additional legal prefix
> 
> Still looking into removing the PHYSICAL_NIC_RE altogether, but sending this
> patch series as-is nevertheless for review / feedback. If I manage to remove the
> PHYSICAL_NIC_RE in time, we could get rid of the constraints of prefix /
> target-name altogether...
> 
> pve-manager:
> 
> Stefan Hanreich (4):
>   network-interface-pinning: use ifindex as order for pinning
>   network-interface-pinning: improve printing mapping
>   network-interface-pinning: add target-name parameter
>   network-interface-pinning: add if prefix to list of allowed prefixes
> 
>  PVE/CLI/proxmox_network_interface_pinning.pm | 76 +++++++++++++++++---
>  1 file changed, 65 insertions(+), 11 deletions(-)
> 
> 
> Summary over all repositories:
>   1 files changed, 65 insertions(+), 11 deletions(-)
> 



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

end of thread, other threads:[~2025-07-24  9:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-24  9:32 [pve-devel] [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich
2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 1/4] network-interface-pinning: use ifindex as order for pinning Stefan Hanreich
2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 2/4] network-interface-pinning: improve printing mapping Stefan Hanreich
2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 3/4] network-interface-pinning: add target-name parameter Stefan Hanreich
2025-07-24  9:32 ` [pve-devel] [PATCH pve-manager 4/4] network-interface-pinning: add if prefix to list of allowed prefixes Stefan Hanreich
2025-07-24  9:35 ` [pve-devel] superseded: [PATCH manager 0/4] improvements to proxmox-network-interface-pinning Stefan Hanreich

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