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.bb b/meta-google/recipes-google/networking/gbmc-bridge.bb
index 3f20530..ba4b691 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge.bb
+++ b/meta-google/recipes-google/networking/gbmc-bridge.bb
@@ -17,6 +17,8 @@
file://gbmc-br-from-ra.sh \
file://gbmc-br-ensure-ra.sh \
file://gbmc-br-ensure-ra.service \
+ file://gbmc-br-hostname.sh \
+ file://gbmc-br-hostname.service \
file://gbmc-br-gw-src.sh \
file://gbmc-br-nft.sh \
file://gbmc-br-dhcp.sh \
@@ -49,6 +51,7 @@
SYSTEMD_SERVICE:${PN} += " \
gbmc-br-ensure-ra.service \
+ gbmc-br-hostname.service \
gbmc-br-dhcp.service \
gbmc-br-dhcp-term.service \
gbmc-br-load-ip.service \
@@ -123,10 +126,12 @@
install -d -m0755 ${D}${libexecdir}
install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.sh ${D}${libexecdir}/
+ install -m0755 ${WORKDIR}/gbmc-br-hostname.sh ${D}${libexecdir}/
install -m0755 ${WORKDIR}/gbmc-br-dhcp.sh ${D}${libexecdir}/
install -m0755 ${WORKDIR}/gbmc-br-dhcp-term.sh ${D}${libexecdir}/
install -d -m0755 ${D}${systemd_system_unitdir}
install -m0644 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/
+ install -m0644 ${WORKDIR}/gbmc-br-hostname.service ${D}${systemd_system_unitdir}/
install -m0644 ${WORKDIR}/gbmc-br-dhcp.service ${D}${systemd_system_unitdir}/
install -m0644 ${WORKDIR}/gbmc-br-dhcp-term.service ${D}${systemd_system_unitdir}/
install -m0644 ${WORKDIR}/gbmc-br-load-ip.service ${D}${systemd_system_unitdir}/
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'")