From bb9fb95ffc2dcd537ff0a948441700e8812af60b Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Mon, 27 Sep 2021 18:10:27 -0700 Subject: 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 --- .../recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'meta-google/recipes-google/ncsi') 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 e4ee10d49..7ba159fcf 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 true; do 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 @@ EOF 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 -- cgit v1.2.3