--- Begin Message ---
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 <[email protected]>
---
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
--- End Message ---
_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel