Patrick Laimbock
2016-Jul-27 12:55 UTC
[CentOS] How to convert /etc/machine-id into a default-duid for IPv6 static DHCP?
Hi, The use-case is deploying C7 VMs with a pre-set machine-id and default-duid based on the machine-id to facilitate static DHCP with IPv6. The default-duid is found in dhclient6-<value>-eth0.lease and IPv6 DHCP uses default-duid like IPv4 DHCP uses MAC addresses for static DHCP. How does one convert /etc/machine-id to a default-duid (in bash)? 1) /etc/machine-id -> DUID: <read RFC6355 and try to grasp the NetworkManager code at [0] & [1]> Use sha256 hash of machine-id, use first 128 bits, add colons and prepend 00:04: $ MACHINE_ID_SHA256=`cat /etc/machine_id | sha256sum | cut -c1-32` $ TMPID=$(sed -e 's/.\{2\}/&:/g;s/.$//' <<<$MACHINE_ID_SHA256) $ DUID=00:04:`echo $TMPID` Correct? 2) convert $DUID to a default-duid. Example value of default-duid can be found in /var/lib/NetworkManager/dhclient6-<string>-eth0.lease. Will stick the pre-set default-duid in /etc/dhclient6.leases so it gets picked up by NM once the VM is deployed and started. So going from e.g. /etc/machine-id 52d8c0f2a04a462a9c9ac1a906446d85 to duid 00:04:a6:89:54:e8:bf:e2:13:71:82:3d:ea:33:4d:a5:2f:75 to default-duid ??? example: default-duid "\000\004%\011\324\251\274\334\001c\304\366\275\314\220\357\255("; So how does one create the default-duid from the duid? The default-duid seems escaped octal with some chars here and there. The NetworkManager code at [2] that does the duid->default-duid conversion is above my pay grade. Anyone know how do this conversion preferably in bash? TIA, Patrick [0] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/nm-core-utils.c#n2658 [1] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/dhcp-manager/nm-dhcp-client.c#n439 [2] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/dhcp-manager/nm-dhcp-dhclient-utils.c#n356