1#!/bin/bash 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 16source "$(dirname "${BASH_SOURCE[0]}")"/ncsid_lib.sh 17 18UpdateRAGW() { 19 local netdev="$1" 20 21 local reqs=5 22 while true; do 23 local disc 24 if ! disc="$(RunInterruptible DiscoverRouter6 "$1" "$reqs" 360000)"; then 25 echo "Failed to discover router" >&2 26 continue 27 fi 28 # We don't want to send any requests after the initial finding 29 # Just passively listen now 30 reqs=-1 31 32 local vars 33 vars="$(echo "$disc" | JSONToVars)" || return 34 eval "$vars" || return 35 [ -n "$stateful_address" ] || continue 36 echo "GW($netdev) $router_ip MAC: $router_mac" >&2 37 38 SuppressTerm 39 local service='xyz.openbmc_project.Network' 40 local rc=0 41 UpdateGateway "$service" "$router_ip" && \ 42 UpdateNeighbor "$service" "$netdev" "$router_ip" "$router_mac" || rc=$? 43 UnsuppressTerm 44 done 45} 46 47Main() { 48 set -o nounset 49 set -o errexit 50 set -o pipefail 51 52 InitTerm 53 UpdateRAGW "$@" 54} 55 56return 0 2>/dev/null 57Main "$@" 58