meta-google: gbmc-bridge: Add optional fixed IP offset
Some of our machines do not support receiving DHCP packets to determine
their addresses, and need a workaround to piggyback off DHCPd nodes in
the system.
This change allows a machine to set a fixed numeric offset address,
where it can read the correct BMC prefix from RAs of other nodes and
then generate a fixed address for itself.
Tested: Ran on a 2 node BMC machine with one using this fixed scheme.
Verified that it correctly found an address and hostname.
Change-Id: Ibd79f800a582db44cf2ad469dbe0a75f13dcaeed
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 a9f2761..3c51c16 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge.bb
+++ b/meta-google/recipes-google/networking/gbmc-bridge.bb
@@ -20,6 +20,8 @@
file://gbmc-br-hostname.sh \
file://gbmc-br-hostname.service \
file://gbmc-ip-from-ra.sh \
+ file://gbmc-br-ip-from-ra.sh.in \
+ file://gbmc-br-ip-from-ra.service \
file://gbmc-br-gw-src.sh \
file://gbmc-br-nft.sh \
file://gbmc-br-dhcp.sh \
@@ -57,10 +59,18 @@
gbmc-br-dhcp.service \
gbmc-br-dhcp-term.service \
gbmc-br-load-ip.service \
+ ${@"gbmc-br-ip-from-ra.service" if d.getVar('GBMC_BR_FIXED_OFFSET') != "" else ""} \
"
GBMC_BR_MAC_ADDR ?= ""
+# Enables the assignment of IP address and hostname by discovering the
+# machine name and BMC prefix from another BMC on the bridge network.
+# This is intended only to be used when there is a single expansion tray
+# on the BMC network. If more than one machine uses this feature with the
+# same offset in the same machine network, it will collide with others.
+GBMC_BR_FIXED_OFFSET ?= ""
+
# Generated via https://cd34.com/rfc4193/ based on a MAC from a machine I own
# and we allocated it downstream. Intended to only be used within a complete
# system of multiple network endpoints.
@@ -145,6 +155,12 @@
install -d ${D}/${bindir}
install -m0755 ${WORKDIR}/gbmc-start-dhcp.sh ${D}${bindir}/
+
+ if [ -n "${GBMC_BR_FIXED_OFFSET}" ]; then
+ sed 's,@IP_OFFSET@,${GBMC_BR_FIXED_OFFSET},' ${WORKDIR}/gbmc-br-ip-from-ra.sh.in >${WORKDIR}/gbmc-br-ip-from-ra.sh
+ install -m0755 ${WORKDIR}/gbmc-br-ip-from-ra.sh ${D}${libexecdir}/
+ install -m0644 ${WORKDIR}/gbmc-br-ip-from-ra.service ${D}${systemd_system_unitdir}/
+ fi
}
do_rm_work:prepend() {
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.service b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.service
new file mode 100644
index 0000000..2aaf6a9
--- /dev/null
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=gBMC Bridge RA Discovery
+After=network.target
+StartLimitIntervalSec=10
+StartLimitBurst=3
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/libexec/gbmc-br-ip-from-ra.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.sh.in b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.sh.in
new file mode 100755
index 0000000..8fc4c8e
--- /dev/null
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ip-from-ra.sh.in
@@ -0,0 +1,32 @@
+#!/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.
+
+# shellcheck source=meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh
+source /usr/share/gbmc-br-lib.sh || exit
+
+update_fqdn() {
+ hostnamectl set-hostname "$1" || true
+}
+
+update_pfx() {
+ # Save the IP address for the interface
+ gbmc_br_set_ip "$1" || true
+}
+
+RA_IF=gbmcbr
+IP_OFFSET=@IP_OFFSET@
+
+# shellcheck source=meta-google/recipes-google/networking/gbmc-bridge/gbmc-ip-from-ra.sh
+source /usr/share/gbmc-ip-from-ra.sh || exit