blob: 34c59abe04f220522390761b864a86a544c0d59f [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
William A. Kennington III8bd3a6f2024-09-10 16:44:23 -070020ROUTE_TABLE=900
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070021
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070022update_rtr() {
23 busctl set-property xyz.openbmc_project.Network /xyz/openbmc_project/network/"$RA_IF" \
24 xyz.openbmc_project.Network.EthernetInterface DefaultGateway6 s "" || true
25
26 default_update_rtr "$@"
William A. Kennington III8bd3a6f2024-09-10 16:44:23 -070027
28 # Add additional gateway information
29 for file in /run/systemd/network/{00,}-bmc-$RA_IF.network; do
30 mkdir -p "$file.d"
31 printf '[Route]\nGateway=%s\nGatewayOnLink=true\nTable=%d' \
32 "$rtr" "$ROUTE_TABLE" >"$file.d"/10-gateway-table.conf
33 done
34
35 ip -6 route replace default via "$rtr" onlink dev "$RA_IF" table "$ROUTE_TABLE" || \
36 networkctl reload && networkctl reconfigure "$RA_IF"
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070037}
38
39ncsi_is_active() {
40 systemctl is-active -q nic-hostless@"$RA_IF".target && return
41 systemctl is-active -q nic-hostful@"$RA_IF".target && return
42 return 1
43}
44
45update_fqdn() {
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070046 true
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070047}
48
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070049old_ncsi_pfx=
50
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070051update_pfx() {
52 local pfx="$1"
53
54 # We only do this for smartNICs (which don't use NCSI)
55 ncsi_is_active && return
56
57 # Don't change anything for an empty prefix
58 [ -z "$pfx" ] && return
59
60 # We no longer need NCSId if we are in this configuration
61 systemctl stop --no-block ncsid@"$RA_IF" || true
62
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070063 # DHCP Relay workaround until alternate source port is supported
64 # TODO: Remove this once internal relaying cleanups land
65 gbmc-ncsi-smartnic-wa.sh || true
William A. Kennington IIIdc3b3cf2024-09-05 02:04:48 -070066
67 # Override any existing address information within files
68 # Make sure we cover `00-*` and `-*` files
69 for file in /run/systemd/network/{00,}-bmc-gbmcbr.network; do
70 mkdir -p "$file.d"
71 printf '[Network]\nAddress=%s/128' \
72 "$pfx" >"$file.d"/10-ncsi-addr.conf
73 done
74
75 # Don't force networkd to reload as this can break phosphor-networkd
76 # Fall back to reload only if ip link commands fail
77 if [ -n "$old_ncsi_pfx" ]; then
78 ip -6 addr del "$old_ncsi_pfx/128" dev gbmcbr || true
79 fi
80 ip -6 addr replace "$pfx/128" dev gbmcbr || \
81 (networkctl reload && networkctl reconfigure gbmcbr) || true
82 old_ncsi_pfx=$pfx
83
84 echo "Set NCSI addr $pfx on gbmcbr" >&2
William A. Kennington III5f9f81f2024-09-04 15:06:51 -070085}
86
87# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-ra.sh
88source /usr/share/gbmc-ra.sh || exit