blob: ca8fa05caaa166fada8367e76df94c8d491d6aee [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
William A. Kennington IIIa108fcd2024-09-12 14:39:38 -070016# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-net-lib.sh
17source /usr/share/gbmc-net-lib.sh || exit
18
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070019RA_IF=$1
20IP_OFFSET=1
21# NCSI is known to be closer to the ToR than bridge routes. Prefer over bridge routes.
22ROUTE_METRIC=900
William A. Kennington III8bd3a6f2024-09-10 16:44:23 -070023ROUTE_TABLE=900
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070024
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070025update_rtr() {
26 busctl set-property xyz.openbmc_project.Network /xyz/openbmc_project/network/"$RA_IF" \
27 xyz.openbmc_project.Network.EthernetInterface DefaultGateway6 s "" || true
28
29 default_update_rtr "$@"
William A. Kennington III8bd3a6f2024-09-10 16:44:23 -070030
31 # Add additional gateway information
32 for file in /run/systemd/network/{00,}-bmc-$RA_IF.network; do
33 mkdir -p "$file.d"
34 printf '[Route]\nGateway=%s\nGatewayOnLink=true\nTable=%d' \
35 "$rtr" "$ROUTE_TABLE" >"$file.d"/10-gateway-table.conf
36 done
37
38 ip -6 route replace default via "$rtr" onlink dev "$RA_IF" table "$ROUTE_TABLE" || \
William A. Kennington IIIa108fcd2024-09-12 14:39:38 -070039 gbmc_net_networkd_reload "$RA_IF"
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070040}
41
42ncsi_is_active() {
43 systemctl is-active -q nic-hostless@"$RA_IF".target && return
44 systemctl is-active -q nic-hostful@"$RA_IF".target && return
45 return 1
46}
47
48update_fqdn() {
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070049 true
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070050}
51
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070052old_ncsi_pfx=
53
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070054update_pfx() {
55 local pfx="$1"
56
57 # We only do this for smartNICs (which don't use NCSI)
58 ncsi_is_active && return
59
60 # Don't change anything for an empty prefix
61 [ -z "$pfx" ] && return
62
63 # We no longer need NCSId if we are in this configuration
64 systemctl stop --no-block ncsid@"$RA_IF" || true
65
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070066 # DHCP Relay workaround until alternate source port is supported
67 # TODO: Remove this once internal relaying cleanups land
68 gbmc-ncsi-smartnic-wa.sh || true
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070069
70 # Override any existing address information within files
71 # Make sure we cover `00-*` and `-*` files
72 for file in /run/systemd/network/{00,}-bmc-gbmcbr.network; do
73 mkdir -p "$file.d"
74 printf '[Network]\nAddress=%s/128' \
75 "$pfx" >"$file.d"/10-ncsi-addr.conf
76 done
77
78 # Don't force networkd to reload as this can break phosphor-networkd
79 # Fall back to reload only if ip link commands fail
80 if [ -n "$old_ncsi_pfx" ]; then
81 ip -6 addr del "$old_ncsi_pfx/128" dev gbmcbr || true
82 fi
83 ip -6 addr replace "$pfx/128" dev gbmcbr || \
William A. Kennington IIIa108fcd2024-09-12 14:39:38 -070084 gbmc_net_networkd_reload gbmcbr || true
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070085 old_ncsi_pfx=$pfx
86
87 echo "Set NCSI addr $pfx on gbmcbr" >&2
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070088}
89
90# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-ra.sh
91source /usr/share/gbmc-ra.sh || exit