public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container 1/2] lxc: add DHCPv6 DUID retrieval to get_interfaces
       [not found] <20251124004302.498297-1-alex@goodkind.io>
@ 2025-11-24  0:43 ` Alex Goodkind via pve-devel
  2025-11-24  0:43 ` [pve-devel] [PATCH container 2/2] api: add duid field to container interface schema Alex Goodkind via pve-devel
  1 sibling, 0 replies; 2+ messages in thread
From: Alex Goodkind via pve-devel @ 2025-11-24  0:43 UTC (permalink / raw)
  To: pve-devel; +Cc: Alex Goodkind, tarick

[-- 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

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

* [pve-devel] [PATCH container 2/2] api: add duid field to container interface schema
       [not found] <20251124004302.498297-1-alex@goodkind.io>
  2025-11-24  0:43 ` [pve-devel] [PATCH container 1/2] lxc: add DHCPv6 DUID retrieval to get_interfaces Alex Goodkind via pve-devel
@ 2025-11-24  0:43 ` Alex Goodkind via pve-devel
  1 sibling, 0 replies; 2+ messages in thread
From: Alex Goodkind via pve-devel @ 2025-11-24  0:43 UTC (permalink / raw)
  To: pve-devel; +Cc: Alex Goodkind, tarick

[-- Attachment #1: Type: message/rfc822, Size: 6558 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 2/2] api: add duid field to container interface schema
Date: Sun, 23 Nov 2025 16:43:02 -0800
Message-ID: <20251124004302.498297-3-alex@goodkind.io>

Add optional 'duid' field to the interface object schema in the
container interface query API. This field contains the DHCPv6
DUID value in hexadecimal format with colons.

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

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 3d74f71..280f9c9 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -2970,6 +2970,11 @@ __PACKAGE__->register_method({
                     description => 'The MAC address of the interface',
                     optional => 0,
                 },
+                duid => {
+                    type => 'string',
+                    description => 'DHCPv6 DUID (DHCP Unique Identifier) value in hex format with colons',
+                    optional => 1,
+                },
                 # TODO: deprecate on next major release
                 inet => {
                     type => 'string',
-- 
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

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

end of thread, other threads:[~2025-11-24  0:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20251124004302.498297-1-alex@goodkind.io>
2025-11-24  0:43 ` [pve-devel] [PATCH container 1/2] lxc: add DHCPv6 DUID retrieval to get_interfaces Alex Goodkind via pve-devel
2025-11-24  0:43 ` [pve-devel] [PATCH container 2/2] api: add duid field to container interface schema Alex Goodkind via pve-devel

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