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 | DiscoverRouter6() { |
| 5 | local netdev="$1" |
| 6 | |
| 7 | local output |
| 8 | local st=0 |
| 9 | output="$(RunInterruptible rdisc6 -1 -r 5 -w 1000 -n "$netdev")" || st=$? |
| 10 | if (( st != 0 )); then |
| 11 | echo "rdisc6 failed with: " >&2 |
| 12 | echo "$output" >&2 |
| 13 | return $st |
| 14 | fi |
| 15 | |
| 16 | local ip="$(echo "$output" | grep 'from' | awk '{print $2}')" |
| 17 | local mac="$(echo "$output" | grep 'Source link-layer' | ParseMACFromLine)" |
| 18 | printf '{"router_ip":"%s","router_mac":"%s"}\n' "$ip" "$mac" |
| 19 | } |
| 20 | |
| 21 | HandleDHCP6() { |
| 22 | local op="$1" |
| 23 | |
| 24 | if [ "$op" = "bound" ]; then |
| 25 | echo "INTF: $interface" >&2 |
| 26 | echo "IP: $ipv6/128" >&2 |
| 27 | |
| 28 | local disc |
| 29 | if ! disc="$(DiscoverRouter6 "$interface")"; then |
| 30 | echo "Failed to discover router" >&2 |
| 31 | return 1 |
| 32 | fi |
| 33 | local vars |
| 34 | vars="$(echo "$disc" | JSONToVars)" || return |
| 35 | eval "$vars" || return |
| 36 | echo "GW: $router_ip" >&2 |
| 37 | echo "GW_MAC: $router_mac" >&2 |
| 38 | |
| 39 | SuppressTerm |
| 40 | local service='xyz.openbmc_project.Network' |
| 41 | local rc=0 |
| 42 | UpdateIP "$service" "$interface" "$ipv6" '128' && \ |
| 43 | UpdateGateway "$service" "$router_ip" && \ |
| 44 | UpdateNeighbor "$service" "$interface" "$router_ip" "$router_mac" || \ |
| 45 | rc=$? |
| 46 | UnsuppressTerm |
| 47 | touch /run/dhcp6.done |
| 48 | return $rc |
| 49 | fi |
| 50 | } |
| 51 | |
| 52 | Main() { |
| 53 | set -o nounset |
| 54 | set -o errexit |
| 55 | set -o pipefail |
| 56 | |
| 57 | InitTerm |
| 58 | HandleDHCP6 "$@" |
| 59 | } |
| 60 | |
| 61 | return 0 2>/dev/null |
| 62 | Main "$@" |