meta-google: gbmc-bridge: Send hostname in RAs

This adds support for a process that monitors hostname changes and adds
the current hostnmae as a "DNS Search List" field entry in the RA
messages from a node. This makes it possible to discover the hostnames
of nodes within the machine simply by looking at RA messages.

Tested: Ran on a machine and verified with `rdisc6 gbmcbr` that the
hostname was being included in RA messages and updated after
`hostnamectl set-hostname <new name>`

Change-Id: Iac8ee6300384191f4fb8ec3bf252afe84ef814c0
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.service b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.service
new file mode 100644
index 0000000..9841419
--- /dev/null
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.service
@@ -0,0 +1,8 @@
+[Unit]
+Before=systemd-networkd.service
+
+[Service]
+ExecStart=/usr/libexec/gbmc-br-hostname.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.sh
new file mode 100755
index 0000000..408ffb6
--- /dev/null
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-hostname.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+oldname=
+while read -r _; do
+  # Don't bother parsing the output, just read the final hostname
+  name="$(</etc/hostname)" || continue
+  [[ "$oldname" == "$name" ]] && continue
+  oldname="$name"
+  echo "Updating BMC RA Hostname $name" >&2
+
+  contents='[IPv6SendRA]'$'\n'"Domains=$name"
+  for netfile in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/60-domains.conf; do
+    mkdir -p "$(dirname "$netfile")"
+    printf '%s' "$contents" >"$netfile"
+   done
+
+  networkctl reload && networkctl reconfigure gbmcbr
+done < <(dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.hostname1'")