blob: 014b3b7cfcea7eb2c7e0b81fa68b01a1b4e3804c [file] [log] [blame]
William A. Kennington III5f9f81f2024-09-04 15:06:51 -07001#!/bin/bash
2# Copyright 2024 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16RA_IF=$1
17IP_OFFSET=1
18# NCSI is known to be closer to the ToR than bridge routes. Prefer over bridge routes.
19ROUTE_METRIC=900
20
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070021update_rtr() {
22 busctl set-property xyz.openbmc_project.Network /xyz/openbmc_project/network/"$RA_IF" \
23 xyz.openbmc_project.Network.EthernetInterface DefaultGateway6 s "" || true
24
25 default_update_rtr "$@"
26}
27
28ncsi_is_active() {
29 systemctl is-active -q nic-hostless@"$RA_IF".target && return
30 systemctl is-active -q nic-hostful@"$RA_IF".target && return
31 return 1
32}
33
34update_fqdn() {
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070035 true
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070036}
37
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070038old_ncsi_pfx=
39
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070040update_pfx() {
41 local pfx="$1"
42
43 # We only do this for smartNICs (which don't use NCSI)
44 ncsi_is_active && return
45
46 # Don't change anything for an empty prefix
47 [ -z "$pfx" ] && return
48
49 # We no longer need NCSId if we are in this configuration
50 systemctl stop --no-block ncsid@"$RA_IF" || true
51
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070052 # DHCP Relay workaround until alternate source port is supported
53 # TODO: Remove this once internal relaying cleanups land
54 gbmc-ncsi-smartnic-wa.sh || true
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070055
56 # Override any existing address information within files
57 # Make sure we cover `00-*` and `-*` files
58 for file in /run/systemd/network/{00,}-bmc-gbmcbr.network; do
59 mkdir -p "$file.d"
60 printf '[Network]\nAddress=%s/128' \
61 "$pfx" >"$file.d"/10-ncsi-addr.conf
62 done
63
64 # Don't force networkd to reload as this can break phosphor-networkd
65 # Fall back to reload only if ip link commands fail
66 if [ -n "$old_ncsi_pfx" ]; then
67 ip -6 addr del "$old_ncsi_pfx/128" dev gbmcbr || true
68 fi
69 ip -6 addr replace "$pfx/128" dev gbmcbr || \
70 (networkctl reload && networkctl reconfigure gbmcbr) || true
71 old_ncsi_pfx=$pfx
72
73 echo "Set NCSI addr $pfx on gbmcbr" >&2
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070074}
75
76# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-ra.sh
77source /usr/share/gbmc-ra.sh || exit