public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Alex Goodkind via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Alex Goodkind <alex@goodkind.io>, tarick@bedeir.com
Subject: [pve-devel] [PATCH container 1/2] lxc: add DHCPv6 DUID retrieval to get_interfaces
Date: Sun, 23 Nov 2025 16:43:01 -0800	[thread overview]
Message-ID: <mailman.1.1763945026.399.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20251124004302.498297-1-alex@goodkind.io>

[-- Attachment #1: Type: message/rfc822, Size: 9674 bytes --]

From: Alex Goodkind <alex@goodkind.io>
To: pve-devel@lists.proxmox.com
Cc: tarick@bedeir.com, Alex Goodkind <alex@goodkind.io>
Subject: [PATCH container 1/2] lxc: add DHCPv6 DUID retrieval to get_interfaces
Date: Sun, 23 Nov 2025 16:43:01 -0800
Message-ID: <20251124004302.498297-2-alex@goodkind.io>

Extend get_interfaces function to retrieve DHCPv6 DUID from
networkctl. The DUID is parsed and formatted according to RFC
8415 with proper type prefix (DUID-LLT, DUID-EN/Vendor, DUID-LL,
UUID). The formatted DUID is added to the interface object.

Signed-off-by: Alex Goodkind <alex@goodkind.io>
---
 src/PVE/LXC.pm | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index de54a0d..d5f059b 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1310,6 +1310,78 @@ sub get_interfaces {
         # TODO: remove on next major release
         $obj->{hwaddr} = $interface->{address};
 
+        # Get DUID from networkctl (supports all DUID types)
+        eval {
+            my $duid_output;
+            run_command(
+                [
+                    'nsenter',
+                    '-t',
+                    $pid,
+                    '--all', # networkctl fails in partial namespace entry
+                    '--',
+                    'networkctl',
+                    'status',
+                    $interface->{ifname},
+                ],
+                outfunc => sub { $duid_output .= shift; },
+                errfunc => sub { },  # Ignore errors (networkctl might not be available)
+            );
+
+            # Parse DUID from networkctl output
+            # Format: "DHCP6 Client DUID: <TYPE>:<hex_data>"
+            # Possible types: DUID-LLT, DUID-EN/Vendor, DUID-LL, UUID, or hex for unknown types
+            # Examples:
+            #   "DHCP6 Client DUID: DUID-EN/Vendor:0000ab113f93f63a9e558dfb"
+            #   "DHCP6 Client DUID: DUID-LLT:0001000123456789abcdef..."
+            #   "DHCP6 Client DUID: DUID-LL:0003bc2411304fd2"
+            #   "DHCP6 Client DUID: UUID:1234567890abcdef..."
+            # Note: networkctl outputs the DUID data WITHOUT the type prefix bytes
+            # We need to prepend the 2-byte type code to form the complete DUID
+            if (
+                $duid_output
+                && $duid_output =~ /DHCP6\s+Client\s+DUID:\s+([^:]+):([0-9a-f:]+)/i
+            ) {
+                my $duid_type = $1;
+                my $duid_value = $2;
+
+                # Map type string to numeric type code (RFC 8415)
+                my $type_code;
+                if ($duid_type =~ /^DUID-LLT$/i) {
+                    $type_code = 1;    # 0x0001
+                } elsif ($duid_type =~ /^DUID-EN\/Vendor$/i) {
+                    $type_code = 2;    # 0x0002
+                } elsif ($duid_type =~ /^DUID-LL$/i) {
+                    $type_code = 3;    # 0x0003
+                } elsif ($duid_type =~ /^UUID$/i) {
+                    $type_code = 4;    # 0x0004
+                } else {
+                    # Unknown type - try to parse as hex
+                    if ($duid_type =~ /^([0-9a-f]{1,4})$/i) {
+                        $type_code = hex($duid_type);
+                    } else {
+                        # Fallback: skip adding prefix for unknown types
+                        $type_code = undef;
+                    }
+                }
+
+                # Normalize format: remove existing colons and rebuild with proper formatting
+                $duid_value =~ s/://g;
+                # Add colons every 2 hex digits
+                $duid_value =~ s/([0-9a-f]{2})(?=[0-9a-f]{2})/$1:/gi;
+
+                # Prepend type prefix (2 bytes, big-endian) if we have a valid type code
+                my $full_duid = $duid_value;
+                if (defined($type_code)) {
+                    my $type_prefix = sprintf("%04x", $type_code);
+                    $type_prefix =~ s/([0-9a-f]{2})(?=[0-9a-f]{2})/$1:/gi;
+                    $full_duid = lc("$type_prefix:$duid_value");
+                }
+
+                $obj->{'duid'} = lc($full_duid);
+            }
+        };
+
         push @$res, $obj;
     }
 
-- 
2.43.0



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

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

       reply	other threads:[~2025-11-24  0:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251124004302.498297-1-alex@goodkind.io>
2025-11-24  0:43 ` Alex Goodkind via pve-devel [this message]
2025-11-24  0:43 ` [pve-devel] [PATCH container 2/2] api: add duid field to container interface schema Alex Goodkind via pve-devel

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=mailman.1.1763945026.399.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=alex@goodkind.io \
    --cc=tarick@bedeir.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