meta-google: gbmc-ncsi-config: Parse hostnames from RA
We need the hostname to be properly configured in order to login with
GLOME. This derives the hostname from the FQDN that is passed via the
DNS list in the RA messages from the smart NIC.
Change-Id: I4e7a414b6b75bfb227df5763917e9e5d09579d7d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
index e4ee10d..7ba159f 100755
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
@@ -25,15 +25,20 @@
while read line; do
if [ -z "$line" ]; then
pfx=
+ host=
elif [[ "$line" =~ ^Prefix' '*:' '*(.*)/([0-9]+)$ ]]; then
t_pfx="${BASH_REMATCH[1]}"
t_pfx_len="${BASH_REMATCH[2]}"
ip_to_bytes t_pfx_b "$t_pfx" || continue
(( t_pfx_len == 76 && t_pfx_b[8] & 0xfd == 0xfd )) || continue
(( t_pfx_b[9] |= 1 ))
+ hextet="fd$(printf '%02x' ${t_pfx_b[9]})"
pfx="$(ip_bytes_to_str t_pfx_b)"
(( t_pfx_b[9] &= 0xf0 ))
stateless_pfx="$(ip_bytes_to_str t_pfx_b)"
+ elif [[ "$line" =~ ^'DNS search list'' '*:' '*([^.-]*)[^.]*[.](.*.google.com)$ ]]; then
+ host="${BASH_REMATCH[1]}"
+ domain="${BASH_REMATCH[2]}"
elif [[ "$line" =~ ^from' '(.*)$ ]]; then
rtr="${BASH_REMATCH[1]}"
(( "${#pfx}" != 0 )) || continue
@@ -102,6 +107,11 @@
systemctl reset-failed nftables
systemctl --no-block restart nftables
+ # Set the machine hostname if discovered
+ if [ -n "$host" ]; then
+ hostnamectl set-hostname "$host-n$hextet.$domain"
+ fi
+
old_pfx="$pfx"
old_rtr="$rtr"
fi