diff options
author | William A. Kennington III <wak@google.com> | 2021-09-28 04:10:27 +0300 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2021-09-29 01:50:10 +0300 |
commit | bb9fb95ffc2dcd537ff0a948441700e8812af60b (patch) | |
tree | 0aea8ba9b2a2918cb5c0d1a29ba2b59bc9d69a67 | |
parent | c7454fb1c54ec6281a42b7cdb29e746b808eb271 (diff) | |
download | openbmc-bb9fb95ffc2dcd537ff0a948441700e8812af60b.tar.xz |
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>
-rwxr-xr-x | meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in | 10 |
1 files changed, 10 insertions, 0 deletions
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 |