blob: 1fb6b5886d37e43ec2366271ab2056767ebc17b6 [file] [log] [blame]
William A. Kennington IIIb163a2c2021-05-20 17:33:01 -07001#!/bin/bash
William A. Kennington III9a76b6f2021-09-30 16:04:18 -07002# Copyright 2021 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 IIIb163a2c2021-05-20 17:33:01 -070016source "$(dirname "${BASH_SOURCE[0]}")"/ncsid_lib.sh
17
18UpdateRA() {
19 local netdev="$1"
20
21 local service='xyz.openbmc_project.Network'
22 local gateways
23 if ! gateways="$(GetGateways "$service" "$netdev")"; then
24 echo "Failed to look up gateways" >&2
25 return 1
26 fi
27 local vars
28 vars="$(echo "$gateways" | JSONToVars)" || return
29 eval "$vars" || return
30
31 echo "GW($netdev): ${DefaultGateway6:-(none)}" >&2
32 if [ -z "$DefaultGateway6" ]; then
33 return 0
34 fi
35
William A. Kennington IIId7989582022-05-27 16:41:44 -070036 local st=0
William A. Kennington IIIb163a2c2021-05-20 17:33:01 -070037 local disc
William A. Kennington IIId7989582022-05-27 16:41:44 -070038 CaptureInterruptible disc DiscoverRouter6 "$netdev" -1 360000 "$DefaultGateway6" || st=$?
39 if (( st != 0 )); then
William A. Kennington IIIb163a2c2021-05-20 17:33:01 -070040 echo "Failed to discover router" >&2
41 return 1
42 fi
43 local vars
44 vars="$(echo "$disc" | JSONToVars)" || return
45 eval "$vars" || return
46 echo "GW($netdev) MAC: $router_mac" >&2
47
48 SuppressTerm
49 local rc=0
50 UpdateNeighbor "$service" "$netdev" "$router_ip" "$router_mac" || rc=$?
51 UnsuppressTerm
52 return $rc
53}
54
55Main() {
56 set -o nounset
57 set -o errexit
58 set -o pipefail
59
60 InitTerm
61 UpdateRA "$@"
62}
63
64return 0 2>/dev/null
65Main "$@"