From 208f7c9f083359bce9f5b51fb4a7fd67647997f7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 29 Jun 2026 19:35:04 +0200 Subject: [PATCH] confd: simplify gen-hostname, defer MAC expansion to confd gen-hostname baked the last three MAC octets straight into the generated hostname, so the actual MAC ended up stored in the configuration. Copy that config to another device and its hostname no longer matched the hardware. Emit the %h and %m format specifiers and let confd expand them when the config is applied, so the MAC is resolved per device and never written to a saved config. This also drops the /run/system.json lookup. Closes #1554 Signed-off-by: Joachim Wiberg --- src/confd/bin/gen-hostname | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/confd/bin/gen-hostname b/src/confd/bin/gen-hostname index 092ef24a..eb777220 100755 --- a/src/confd/bin/gen-hostname +++ b/src/confd/bin/gen-hostname @@ -2,26 +2,20 @@ # Generate ietf-system.yang hostname based on: # 1. Command line argument + MAC suffix # 2. Specific hostname from qemu_fw_cfg, from Qeneth -# 3. /etc/hostname from squashfs + MAC suffix +# 3. Default hostname + MAC suffix +# +# The MAC suffix is emitted as the %m format specifier, expanded by confd +# at apply time, so the actual MAC never ends up baked into a saved +# configuration (issue #1554). # set -e -gen() -{ - base_mac=$(jq -r '.["mac-address"]' /run/system.json) - if [ -z "$base_mac" ] || [ "$base_mac" = "null" ]; then - base_mac=00:00:00:00:00:00 - fi - - echo "$1-$(echo $base_mac | tail -c 9 | tr ':' '-')" -} - if [ "$1" ]; then - sysname=$(gen "$1") + sysname="$1-%m" elif [ -f "/sys/firmware/qemu_fw_cfg/by_name/opt/hostname/raw" ]; then sysname="$(cat /sys/firmware/qemu_fw_cfg/by_name/opt/hostname/raw)" else - sysname=$(gen "$(cat /etc/hostname)") + sysname="%h-%m" fi cat <