William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | source "$(dirname "${BASH_SOURCE[0]}")"/ncsid_lib.sh |
| 3 | |
| 4 | UpdateNeighbor() { |
| 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 | |
| 28 | UpdateNeighbors() { |
| 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 | |
| 39 | Main() { |
| 40 | set -o nounset |
| 41 | set -o errexit |
| 42 | set -o pipefail |
| 43 | |
| 44 | InitTerm |
| 45 | UpdateNeighbors "$@" |
| 46 | } |
| 47 | |
| 48 | return 0 2>/dev/null |
| 49 | Main "$@" |