meta-google: gbmc-ncsi-config: Migrate to common RA handler
This gets rid of our bespoke RA handling code and uses the common RA
code for both RA processes on the NCSI port.
Tested: Ran on a NCSI CN and verified that RAs are still parsed and the
addresses / hostname can still be found with the smartnic WA executed.
Change-Id: Ia9667f9b6ada2668f2096abbced6d8571a686e49
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in
deleted file mode 100644
index 82972ff..0000000
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.service.in
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=gBMC NCSI RA Discovery
-After=network.target
-StartLimitIntervalSec=10
-StartLimitBurst=3
-Conflicts=nic-hostless@@NCSI_IF@.target
-Conflicts=nic-hostful@@NCSI_IF@.target
-
-[Service]
-Restart=always
-RestartSec=5
-ExecStart=/usr/libexec/gbmc-ncsi-ip-from-ra.sh
-
-[Install]
-WantedBy=multi-user.target
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
deleted file mode 100755
index ed1ca6a..0000000
--- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/bash
-# Copyright 2021 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.
-
-[ ! -e /usr/share/gbmc-br-lib.sh ] && exit
-
-# 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() {
- # We no longer need NCSId if we are in this configuration
- systemctl stop --no-block ncsid@"$NCSI_IF" || true
-
- # Save the IP address for the interface
- gbmc_br_set_ip "$1" || true
-
- # DHCP Relay workaround until alternate source port is supported
- # TODO: Remove this once internal relaying cleanups land
- gbmc-ncsi-smartnic-wa.sh || true
-}
-
-RA_IF=@NCSI_IF@
-IP_OFFSET=1
-
-# shellcheck source=meta-google/recipes-google/networking/gbmc-bridge/gbmc-ip-from-ra.sh
-source /usr/share/gbmc-ip-from-ra.sh || exit
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.service.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.service.in
new file mode 100644
index 0000000..d389740
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.service.in
@@ -0,0 +1,15 @@
+[Unit]
+Description=RA Gateway Updater
+Wants=mapper-wait@-xyz-openbmc_project-network-@NCSI_IF@.service
+After=mapper-wait@-xyz-openbmc_project-network-@NCSI_IF@.service
+After=ncsid@NCSI_IF@.service
+StartLimitIntervalSec=1min
+StartLimitBurst=5
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=/usr/libexec/gbmc-ncsi-ra.sh @NCSI_IF@
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.sh b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.sh
new file mode 100644
index 0000000..016ec4c
--- /dev/null
+++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ra.sh
@@ -0,0 +1,69 @@
+#!/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.
+
+RA_IF=$1
+IP_OFFSET=1
+# NCSI is known to be closer to the ToR than bridge routes. Prefer over bridge routes.
+ROUTE_METRIC=900
+
+has_bridge=1
+# shellcheck source=meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-lib.sh
+source /usr/share/gbmc-br-lib.sh || has_bridge=
+
+update_rtr() {
+ busctl set-property xyz.openbmc_project.Network /xyz/openbmc_project/network/"$RA_IF" \
+ xyz.openbmc_project.Network.EthernetInterface DefaultGateway6 s "" || true
+
+ default_update_rtr "$@"
+}
+
+ncsi_is_active() {
+ systemctl is-active -q nic-hostless@"$RA_IF".target && return
+ systemctl is-active -q nic-hostful@"$RA_IF".target && return
+ return 1
+}
+
+update_fqdn() {
+ # We only do this for smartNICs (which don't use NCSI)
+ ncsi_is_active && return
+
+ default_update_fqdn "$@"
+}
+
+update_pfx() {
+ local pfx="$1"
+
+ # We only do this for smartNICs (which don't use NCSI)
+ ncsi_is_active && return
+
+ # Don't change anything for an empty prefix
+ [ -z "$pfx" ] && return
+
+ # We no longer need NCSId if we are in this configuration
+ systemctl stop --no-block ncsid@"$RA_IF" || true
+
+ # Save the IP address for the interface
+ if [ -n "$has_bridge" ]; then
+ gbmc_br_set_ip "$1" || true
+ echo "IP $pfx set on $RA_IF" >&2
+ fi
+
+ # DHCP Relay workaround until alternate source port is supported
+ # TODO: Remove this once internal relaying cleanups land
+ gbmc-ncsi-smartnic-wa.sh || true
+}
+
+# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-ra.sh
+source /usr/share/gbmc-ra.sh || exit