From: Felix Fietkau Date: Mon, 1 Nov 2021 15:35:16 +0000 (+0100) Subject: qosify: add package for simple qos based on ebpf+cake X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f3a28b6bcf984dc55ec2d675ba75f0d3bc794eb9;p=openwrt%2Fstaging%2Fjow.git qosify: add package for simple qos based on ebpf+cake qosify is simple daemon for setting up and managing CAKE along with a custom eBPF based classifier that sets DSCP fields of packets. It is configured via UCI and it supports the following features: - simple TCP/UDP port based mapping - IP address based mapping - priority boosting based on average packet size - bulk flow detection based on number of packets per second - dynamically add IP entries with timeout Signed-off-by: Felix Fietkau --- diff --git a/package/network/config/qosify/Makefile b/package/network/config/qosify/Makefile new file mode 100644 index 0000000000..28dedf874d --- /dev/null +++ b/package/network/config/qosify/Makefile @@ -0,0 +1,55 @@ +# +# Copyright (C) 2021 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=qosify +PKG_SOURCE_URL=$(PROJECT_GIT)/project/qosify.git +PKG_SOURCE_PROTO:=git +PKG_SOURCE_DATE:=2021-11-01 +PKG_SOURCE_VERSION:=52a57bf0e4eb2c6419be304981c5c94adb32d037 +PKG_MIRROR_HASH:=11a5f2650cf9c4979455ca230eb9ceddb035e6914bda78cf75b8dd7ebaff65d3 + +PKG_LICENSE:=GPL-2.0 +PKG_MAINTAINER:=Felix Fietkau + +PKG_BUILD_DEPENDS:=bpf-headers + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk +include $(INCLUDE_DIR)/bpf.mk + +define Package/qosify + SECTION:=kernel + CATEGORY:=Kernel modules + SUBMENU:=Network Support + TITLE:=A simple QoS solution based eBPF + CAKE + DEPENDS:=+libbpf +libubox +libubus +kmod-sched-cake +tc-full @!BPF_TOOLCHAIN_NONE +endef + +define Build/Compile + $(call CompileBPF,$(PKG_BUILD_DIR)/qosify-bpf.c) + $(Build/Compile/Default) +endef + +define Package/qosify/conffiles +/etc/config/qosify +/etc/qosify-defaults.conf +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 + $(INSTALL_DATA) $(PKG_BUILD_DIR)/qosify-bpf.o $(1)/lib/bpf + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/qosify $(1)/usr/sbin/ + $(INSTALL_BIN) ./files/qosify.init $(1)/etc/init.d/qosify + $(INSTALL_DATA) ./files/qosify-defaults.conf $(1)/etc/qosify-defaults.conf + $(INSTALL_DATA) ./files/qosify.conf $(1)/etc/config/qosify + $(INSTALL_DATA) ./files/qosify.hotplug $(1)/etc/hotplug.d/net/10-qosify +endef + +$(eval $(call BuildPackage,qosify)) diff --git a/package/network/config/qosify/files/qosify-defaults.conf b/package/network/config/qosify/files/qosify-defaults.conf new file mode 100644 index 0000000000..23408d54cc --- /dev/null +++ b/package/network/config/qosify/files/qosify-defaults.conf @@ -0,0 +1,17 @@ +# DNS +tcp:53 CS5 +tcp:5353 CS5 +udp:53 CS5 +udp:5353 CS5 + +# NTP +udp:123 CS6 + +# SSH +tcp:22 +CS4 + +# HTTP/QUIC +tcp:80 +CS3 +tcp:443 +CS3 +udp:80 +CS3 +udp:443 +CS3 diff --git a/package/network/config/qosify/files/qosify.conf b/package/network/config/qosify/files/qosify.conf new file mode 100644 index 0000000000..cf703a3bfb --- /dev/null +++ b/package/network/config/qosify/files/qosify.conf @@ -0,0 +1,30 @@ +config defaults + list defaults /etc/qosify-defaults.conf + option dscp_prio CS5 + option dscp_icmp CS6 + option dscp_bulk CS0 + option dscp_default_udp CS4 + option bulk_trigger_timeout 5 + option bulk_trigger_pps 100 + option prio_max_avg_pkt_len 500 + +config interface wan + option name wan + option disabled 1 + option bandwidth_up 100mbit + option bandwidth_down 100mbit + # defaults: + option ingress 1 + option egress 1 + option mode diffserv4 + option host_isolate 1 + option autorate_ingress 1 + option ingress_options "" + option egress_options "" + option options "" + +config device wandev + option disabled 1 + option name wan + option bandwidth 100mbit + diff --git a/package/network/config/qosify/files/qosify.hotplug b/package/network/config/qosify/files/qosify.hotplug new file mode 100644 index 0000000000..950812c03c --- /dev/null +++ b/package/network/config/qosify/files/qosify.hotplug @@ -0,0 +1,2 @@ +#!/bin/sh +ubus call qosify check_devices diff --git a/package/network/config/qosify/files/qosify.init b/package/network/config/qosify/files/qosify.init new file mode 100644 index 0000000000..c4139d7381 --- /dev/null +++ b/package/network/config/qosify/files/qosify.init @@ -0,0 +1,105 @@ +#!/bin/sh /etc/rc.common +# Copyright (c) 2021 OpenWrt.org + +START=19 + +USE_PROCD=1 +PROG=/usr/sbin/qosify + +add_option() { + local type="$1" + local name="$2" + + config_get val "$cfg" "$name" + + [ -n "$val" ] && json_add_$type "$name" "$val" +} + +add_defaults() { + cfg="$1" + + json_add_boolean reset 1 + + config_get files "$cfg" defaults + json_add_array files + for i in $files; do + json_add_string "" "$i" + done + json_close_array + + add_option int timeout + add_option string dscp_prio + add_option string dscp_bulk + add_option string dscp_icmp + add_option string dscp_default_udp + add_option string dscp_default_tcp + add_option int bulk_trigger_timeout + add_option int bulk_trigger_pps + add_option int prio_max_avg_pkt_len +} + +add_interface() { + local cfg="$1" + + config_get_bool disabled "$cfg" disabled 0 + [ "$disabled" -gt 0 ] && return + + config_get name "$cfg" name + json_add_object "$name" + + config_get bw "$cfg" bandwidth + + config_get bw_up "$cfg" bandwidth_up + bw_up="${bw_up:-$bw}" + [ -n "$bw_up" ] && json_add_string bandwidth_up "$bw_up" + + config_get bw_down "$cfg" bandwidth_down + bw_down="${bw_down:-$bw}" + [ -n "$bw_down" ] && json_add_string bandwidth_down "$bw_down" + + add_option string bandwidth + add_option boolean ingress + add_option boolean egress + add_option string mode + add_option boolean host_isolate + add_option boolean autorate_ingress + add_option string ingress_options + add_option string egress_options + add_option string options + + json_close_object +} + +reload_service() { + json_init + + config_load qosify + + config_foreach add_defaults defaults + + json_add_object interfaces + config_foreach add_interface interface + json_close_object + + json_add_object devices + config_foreach add_interface device + json_close_object + + ubus call qosify config "$(json_dump)" +} + +service_triggers() { + procd_add_reload_trigger qosify +} + +start_service() { + procd_open_instance + procd_set_param command "$PROG" + procd_set_param respawn + procd_close_instance +} + +service_started() { + ubus -t 10 wait_for qosify + [ $? = 0 ] && reload_service +}