William A. Kennington III | b163a2c | 2021-05-20 17:33:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
William A. Kennington III | 9a76b6f | 2021-09-30 16:04:18 -0700 | [diff] [blame] | 2 | # 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 III | b163a2c | 2021-05-20 17:33:01 -0700 | [diff] [blame] | 16 | source "$(dirname "${BASH_SOURCE[0]}")"/ncsid_lib.sh |
| 17 | |
| 18 | UpdateRA() { |
| 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 III | d798958 | 2022-05-27 16:41:44 -0700 | [diff] [blame^] | 36 | local st=0 |
William A. Kennington III | b163a2c | 2021-05-20 17:33:01 -0700 | [diff] [blame] | 37 | local disc |
William A. Kennington III | d798958 | 2022-05-27 16:41:44 -0700 | [diff] [blame^] | 38 | CaptureInterruptible disc DiscoverRouter6 "$netdev" -1 360000 "$DefaultGateway6" || st=$? |
| 39 | if (( st != 0 )); then |
William A. Kennington III | b163a2c | 2021-05-20 17:33:01 -0700 | [diff] [blame] | 40 | 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 | |
| 55 | Main() { |
| 56 | set -o nounset |
| 57 | set -o errexit |
| 58 | set -o pipefail |
| 59 | |
| 60 | InitTerm |
| 61 | UpdateRA "$@" |
| 62 | } |
| 63 | |
| 64 | return 0 2>/dev/null |
| 65 | Main "$@" |