aboutsummaryrefslogtreecommitdiff
path: root/package/network/config/qosify/files/qosify-status
blob: dc582322681e0bfcc0ed679f7d417b6bb7d35b9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
. /usr/share/libubox/jshn.sh

dev_status() {
	tc -s qdisc sh dev "$1" root
	echo
}

common_status() {
	json_get_vars ifname ingress egress

	[ -n "$ifname" ] || return

	[ "$egress" -gt 0 ] && {
		echo "egress status:"
		dev_status "$ifname"
	}
	[ "$ingress" -gt 0 ] && {
		echo "ingress status:"
		dev_status "$(printf %.16s "ifb-$ifname")"
	}
}

is_active() {
	json_get_vars active

	[ "${active:-0}" -gt 0 ]
}

device_status() {
	local name="$2"

	json_select "$name"

	if is_active; then
		status="active"
	else
		status="not found"
	fi

	echo "===== device $name: $status ====="

	is_active && common_status

	json_select ..
}

interface_status() {
	local name="$2"

	json_select "$name"

	if is_active; then
		status="active"
	elif ubus -S -t 0 wait_for "network.interface.$name"; then
		status="down"
	else
		status="not found"
	fi

	echo "===== interface $name: $status ====="

	is_active && common_status

	json_select ..
}

json_load "$(ubus call qosify status)"
json_for_each_item device_status devices
json_for_each_item interface_status interfaces