diff options
author | Aaron Goodman <aaronjg@stanford.edu> | 2020-11-12 19:21:04 -0500 |
---|---|---|
committer | Aaron Goodman <aaronjg@stanford.edu> | 2020-11-16 11:19:55 -0500 |
commit | a5f3e6bb6be8e7c0e9dd5be0b7e2387d7354c96c (patch) | |
tree | fe46b3090ea409f4aeb8fa5f24066f75a650279a /net/mwan3 | |
parent | f644dadfea79fd0ac86995108e43c1ac0ca403ac (diff) |
mwan3: don't call rpcd on 'mwan3 interfaces'
Allow `mwan3 interfaces` to get uptime via an internal function and
thus remove the dependency on rpcd for `mwan3 interface` calls.
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
Diffstat (limited to 'net/mwan3')
-rw-r--r-- | net/mwan3/files/lib/mwan3/common.sh | 20 | ||||
-rw-r--r-- | net/mwan3/files/lib/mwan3/mwan3.sh | 11 | ||||
-rwxr-xr-x | net/mwan3/files/usr/libexec/rpcd/mwan3 | 40 |
3 files changed, 40 insertions, 31 deletions
diff --git a/net/mwan3/files/lib/mwan3/common.sh b/net/mwan3/files/lib/mwan3/common.sh index 5c9b2a805..3cb6f1a45 100644 --- a/net/mwan3/files/lib/mwan3/common.sh +++ b/net/mwan3/files/lib/mwan3/common.sh @@ -1,10 +1,5 @@ #!/bin/sh -get_uptime() { - local uptime=$(cat /proc/uptime) - echo "${uptime%%.*}" -} - IP4="ip -4" IP6="ip -6" SCRIPTNAME="$(basename "$0")" @@ -180,3 +175,18 @@ mwan3_count_one_bits() done echo $count } + +get_uptime() { + local uptime=$(cat /proc/uptime) + echo "${uptime%%.*}" +} + +get_online_time() { + local time_n time_u iface + iface="$1" + time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE" 2>/dev/null)" + [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_u)) + } +} diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index fcfda5b89..26bdcbcd2 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -1053,15 +1053,8 @@ mwan3_report_iface_status() if [ "$result" = "offline" ]; then : elif [ $error -eq 0 ]; then - json_init - json_add_string section interfaces - json_add_string interface "$1" - json_load "$(ubus call mwan3 status "$(json_dump)")" - json_select "interfaces" - json_select "$1" - json_get_vars online uptime - json_select .. - json_select .. + online=$(get_online_time "$1") + network_get_uptime uptime "$1" online="$(printf '%02dh:%02dm:%02ds\n' $((online/3600)) $((online%3600/60)) $((online%60)))" uptime="$(printf '%02dh:%02dm:%02ds\n' $((uptime/3600)) $((uptime%3600/60)) $((uptime%60)))" result="$(mwan3_get_iface_hotplug_state $1) $online, uptime $uptime" diff --git a/net/mwan3/files/usr/libexec/rpcd/mwan3 b/net/mwan3/files/usr/libexec/rpcd/mwan3 index 0d8693e64..d4e7adb6f 100755 --- a/net/mwan3/files/usr/libexec/rpcd/mwan3 +++ b/net/mwan3/files/usr/libexec/rpcd/mwan3 @@ -69,6 +69,26 @@ report_policies_v6() { done } +get_age() { + local time_p time_u + iface="$1" + time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" + [ -z "${time_p}" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_p)) + } +} + +get_offline_time() { + local time_n time_d iface + iface="$1" + time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" + [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { + time_n="$(get_uptime)" + echo $((time_n-time_d)) + } +} + get_mwan3_status() { local iface="${1}" local iface_select="${2}" @@ -85,23 +105,9 @@ get_mwan3_status() { track_status="$(mwan3_get_mwan3track_status "$1")" [ "$track_status" = "active" ] && running="1" - time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")" - [ -z "${time_p}" ] || { - time_n="$(get_uptime)" - let age=time_n-time_p - } - - time_u="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE")" - [ -z "${time_u}" ] || [ "${time_u}" = "0" ] || { - time_n="$(get_uptime)" - let online=time_n-time_u - } - - time_d="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE")" - [ -z "${time_d}" ] || [ "${time_d}" = "0" ] || { - time_n="$(get_uptime)" - let offline=time_n-time_d - } + age=$(get_age "$iface") + online=$(get_online_time "$iface") + offline=$(get_offline_time "$iface") local uptime="0" |