blob: 711ae4b23fccccd1ad606f41ca7d9df3b119bbab [file] [log] [blame]
William A. Kennington III7d6fa422021-02-08 17:04:02 -08001#!/bin/bash
2source "$(dirname "${BASH_SOURCE[0]}")"/ncsid_lib.sh
3
4UpdateNeighbor() {
5 local netdev="$1"
6 local service="$2"
7 local object="$3"
8
9 eval "$(GetNeighbor "$service" "$object" | JSONToVars)" || return $?
10 local new_mac
11 if ! new_mac="$(DetermineNeighbor "$netdev" "$IPAddress")"; then
12 echo "Faild to find $IPAddress" >&2
13 return 10
14 fi
15 new_mac=$(normalize_mac "$new_mac") || return
16 if [ "$new_mac" != "$(normalize_mac "$MACAddress")" ]; then
17 echo "Updating $IPAddress: $MACAddress -> $new_mac" >&2
18 SuppressTerm
19 local rc=0
20 DeleteObject "$service" "$object" && \
21 AddNeighbor "$service" "$netdev" "$IPAddress" "$new_mac" || \
22 rc=$?
23 UnsuppressTerm
24 return $rc
25 fi
26}
27
28UpdateNeighbors() {
29 local netdev="$1"
30
31 local entry
32 while read entry; do
33 eval "$(echo "$entry" | JSONToVars)"
34 RunInterruptibleBg UpdateNeighbor "$netdev" "$service" "$object"
35 done < <(GetNeighborObjects "$netdev" 2>/dev/null)
36 WaitInterruptibleBg
37}
38
39Main() {
40 set -o nounset
41 set -o errexit
42 set -o pipefail
43
44 InitTerm
45 UpdateNeighbors "$@"
46}
47
48return 0 2>/dev/null
49Main "$@"