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 | |
| 36 | local disc |
| 37 | if ! disc="$(DiscoverRouter6 "$netdev" -1 360000 "$DefaultGateway6")"; then |
| 38 | echo "Failed to discover router" >&2 |
| 39 | return 1 |
| 40 | fi |
| 41 | local vars |
| 42 | vars="$(echo "$disc" | JSONToVars)" || return |
| 43 | eval "$vars" || return |
| 44 | echo "GW($netdev) MAC: $router_mac" >&2 |
| 45 | |
| 46 | SuppressTerm |
| 47 | local rc=0 |
| 48 | UpdateNeighbor "$service" "$netdev" "$router_ip" "$router_mac" || rc=$? |
| 49 | UnsuppressTerm |
| 50 | return $rc |
| 51 | } |
| 52 | |
| 53 | Main() { |
| 54 | set -o nounset |
| 55 | set -o errexit |
| 56 | set -o pipefail |
| 57 | |
| 58 | InitTerm |
| 59 | UpdateRA "$@" |
| 60 | } |
| 61 | |
| 62 | return 0 2>/dev/null |
| 63 | Main "$@" |