[openwrt/openwrt] qosify: add qosify-status script

LEDE Commits lede-commits at lists.infradead.org
Fri Nov 19 14:53:02 PST 2021


nbd pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/b764cb9e5b1040b6dc13773f8cc153ce6cd7c44d

commit b764cb9e5b1040b6dc13773f8cc153ce6cd7c44d
Author: Felix Fietkau <nbd at nbd.name>
AuthorDate: Fri Nov 19 23:50:50 2021 +0100

    qosify: add qosify-status script
    
    This will show detailed status for all devices/interfaces
    
    Signed-off-by: Felix Fietkau <nbd at nbd.name>
---
 package/network/config/qosify/Makefile            |  5 +-
 package/network/config/qosify/files/qosify-status | 70 +++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/package/network/config/qosify/Makefile b/package/network/config/qosify/Makefile
index c5d1ce789b..01c6498e00 100644
--- a/package/network/config/qosify/Makefile
+++ b/package/network/config/qosify/Makefile
@@ -46,7 +46,10 @@ endef
 define Package/qosify/install
 	$(INSTALL_DIR) $(1)/lib/bpf $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config $(1)/etc/hotplug.d/net $(1)/etc/qosify
 	$(INSTALL_DATA) $(PKG_BUILD_DIR)/qosify-bpf.o $(1)/lib/bpf
-	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/qosify $(1)/usr/sbin/
+	$(INSTALL_BIN) \
+		$(PKG_INSTALL_DIR)/usr/bin/qosify \
+		./files/qosify-status \
+		$(1)/usr/sbin/
 	$(INSTALL_BIN) ./files/qosify.init $(1)/etc/init.d/qosify
 	$(INSTALL_DATA) ./files/qosify-defaults.conf $(1)/etc/qosify/00-defaults.conf
 	$(INSTALL_DATA) ./files/qosify.conf $(1)/etc/config/qosify
diff --git a/package/network/config/qosify/files/qosify-status b/package/network/config/qosify/files/qosify-status
new file mode 100644
index 0000000000..dc58232268
--- /dev/null
+++ b/package/network/config/qosify/files/qosify-status
@@ -0,0 +1,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



More information about the lede-commits mailing list