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