summaryrefslogtreecommitdiff
path: root/meta-google
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2024-09-05 12:17:45 +0300
committerWilliam A. Kennington III <wak@google.com>2024-09-13 07:34:03 +0300
commitedc0c495036dd9eec8cd53e75c06b8b70e2bbcb3 (patch)
tree232cb87e6ace5ac90eaab1a6f2b6740989fd6e48 /meta-google
parentdd18b5e7e94c58d292cfb0b195b2dbe5b3e9a6da (diff)
downloadopenbmc-edc0c495036dd9eec8cd53e75c06b8b70e2bbcb3.tar.xz
meta-google: gbmc-bridge: ULA without networkd
This changes avoids using `systemd-networkd` at all for managing the ULA on the device and makes it sticky to the interface regardless of external operations. Change-Id: Ie615f17f8a0f9f4328185623743fe828a3d9f9e3 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'meta-google')
-rw-r--r--meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh98
1 files changed, 63 insertions, 35 deletions
diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh
index 42bb566c8a..b79e25fe4a 100644
--- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh
+++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-ula.sh
@@ -18,53 +18,81 @@
# shellcheck source=meta-google/recipes-google/networking/network-sh/lib.sh
source /usr/share/network/lib.sh || exit
-gbmc_br_ula_init=
-gbmc_br_ula_mac=
+declare -A gbmc_br_ulas=()
-gbmc_br_ula_update() {
- [[ -n $gbmc_br_ula_init ]] || return
+# BITs set for address suffixes
+GBMC_BR_ULA_SFX_HAS_LL=1
+GBMC_BR_ULA_SFX_HAS_ULA=2
- echo "gBMC Bridge ULA MAC: ${gbmc_br_ula_mac:-(deleted)}" >&2
-
- local addr=
- contents='[Network]'$'\n'
- if [[ -n $gbmc_br_ula_mac ]]; then
- local sfx
- if sfx="$(mac_to_eui64 "$gbmc_br_ula_mac")" &&
- addr="$(ip_pfx_concat "fdb5:0481:10ce::/64" "$sfx")"; then
- contents+="Address=$addr"$'\n'
+gbmc_br_ula_cleanup() {
+ local addr
+ for addr in "${!gbmc_br_ulas[@]}"; do
+ local val="${gbmc_br_ulas["$addr"]}"
+ if (( val & GBMC_BR_ULA_SFX_HAS_LL == 0 )); then
+ echo "Removing Stale ULA: $addr" >&2
+ ip addr del "$addr"/64 dev gbmcbr || true
fi
- fi
-
- local netfile
- for netfile in /run/systemd/network/{00,}-bmc-gbmcbr.network.d/60-ula.conf; do
- mkdir -p "$(dirname "$netfile")"
- printf '%s' "$contents" >"$netfile"
done
+}
- # Ensure that systemd-networkd performs a reconfiguration as it doesn't
- # currently check the mtime of drop-in files.
- touch -c /lib/systemd/network/*-bmc-gbmcbr.network
+gbmc_br_ula_is_ll() {
+ # shellcheck disable=SC2178
+ local -n bytes="$1"
+ (( bytes[0] == 0xfe && bytes[1] == 0x80 && bytes[2] == 0x00 &&
+ bytes[3] == 0x00 && bytes[4] == 0x00 && bytes[5] == 0x00 &&
+ bytes[6] == 0x00 && bytes[7] == 0x00 ))
+}
- if [[ $(systemctl is-active systemd-networkd) != inactive ]]; then
- networkctl reload
- networkctl reconfigure gbmcbr
- fi
+gbmc_br_ula_is_ula() {
+ # shellcheck disable=SC2178
+ local -n bytes="$1"
+ (( bytes[0] == 0xfd && bytes[1] == 0xb5 && bytes[2] == 0x04 &&
+ bytes[3] == 0x81 && bytes[4] == 0x10 && bytes[5] == 0xce &&
+ bytes[6] == 0x00 && bytes[7] == 0x00 ))
}
gbmc_br_ula_hook() {
# shellcheck disable=SC2154
if [[ $change == init ]]; then
- gbmc_br_ula_init=1
- gbmc_br_ula_update
- elif [[ $change == link && $intf == gbmcbr ]]; then
- if [[ $action == add && $mac != "$gbmc_br_ula_mac" ]]; then
- gbmc_br_ula_mac="$mac"
- gbmc_br_ula_update
+ gbmc_br_ula_cleanup
+ elif [[ $change == addr && $intf == gbmcbr && $fam == inet6 ]]; then
+ local pfx_bytes=()
+ ip_to_bytes pfx_bytes "$ip" || return
+ local val=0
+ if gbmc_br_ula_is_ll pfx_bytes; then
+ val="$GBMC_BR_ULA_SFX_HAS_LL"
+ elif gbmc_br_ula_is_ula pfx_bytes; then
+ val="$GBMC_BR_ULA_SFX_HAS_ULA"
+ else
+ return 0
+ fi
+ # Force all addresses into what they would be as a ULA so that we can
+ # store bits about the assigned addresses on the interface
+ pfx_bytes[0]=0xfd
+ pfx_bytes[1]=0xb5
+ pfx_bytes[2]=0x04
+ pfx_bytes[3]=0x81
+ pfx_bytes[4]=0x10
+ pfx_bytes[5]=0xce
+ addr="$(ip_bytes_to_str pfx_bytes)"
+ local old=${gbmc_br_ulas["$addr"]-0}
+ if [[ $action == add ]]; then
+ val=$((old | val))
+ elif [[ $action == del ]]; then
+ val=$((old & ~val))
fi
- if [[ $action == del && $mac == "$gbmc_br_ula_mac" ]]; then
- gbmc_br_ula_mac=
- gbmc_br_ula_update
+ gbmc_br_ulas["$addr"]=$val
+ if (( val == GBMC_BR_ULA_SFX_HAS_LL )); then
+ # We have a link local address but no ULA, so we need to add the ULA
+ echo "Adding ULA: $addr" >&2
+ ip addr replace "$addr"/64 dev gbmcbr
+ elif (( val == GBMC_BR_ULA_SFX_HAS_ULA )); then
+ # We have a ULA without a link local, so we should not longer have this ULA
+ echo "Removing ULA: $addr" >&2
+ ip addr del "$addr"/64 dev gbmcbr || true
+ elif (( val == 0 )); then
+ # Cleanup the map if we no longer have any addresses for the suffix
+ unset 'gbmc_br_ulas[$addr]'
fi
fi
}