From 4d15174b5d42be9cfc87b47c6ee042163e4550ce Mon Sep 17 00:00:00 2001 From: "Ycarus (Yannick Chabanois)" Date: Mon, 19 Oct 2020 16:20:53 +0200 Subject: [PATCH] Add interface additional latency settings --- .../root/etc/init.d/openmptcprouter | 16 ++++++++++++++++ .../resources/view/network/interfaces.js | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/luci-app-openmptcprouter/root/etc/init.d/openmptcprouter b/luci-app-openmptcprouter/root/etc/init.d/openmptcprouter index 46fc817b7..8309d6c2d 100755 --- a/luci-app-openmptcprouter/root/etc/init.d/openmptcprouter +++ b/luci-app-openmptcprouter/root/etc/init.d/openmptcprouter @@ -23,8 +23,24 @@ omr_intf_set() { config_get ifname "$1" ifname config_get device "$1" device config_get proto "$1" proto + config_get addlatency "$1" addlatency "0" devicename=$(echo "$device" | cut -d'/' -f3) + [ -z "$ifname" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]') + + if [ -n "$ifname" ]; then + if [ "$addlatency" = "0" ] && [ "$(tc qdisc show $ifname | grep delay)" != "" ]; then + tc qdisc del dev ${ifname} root netem + fi + if [ "$addlatency" != "0" ]; then + if [ "$(tc qdisc show $ifname | grep delay)" != "" ]; then + tc qdisc add dev ${ifname} root netem delay ${addlatency}ms + elif [ "$(tc qdisc show $ifname | awk '/delay/ { print $10 }' | sed 's/ms//')" != "$addlatency" ]; then + tc qdisc replace dev ${ifname} root netem delay ${addlatency}ms + fi + fi + fi + if [ -n "$ifname" ] && [ -f /sys/class/net/${ifname}/device/uevent ]; then devicepath=$(readlink -f /sys/class/net/${ifname}) if [ -n "$devicepath" ] && [ "$(echo ${devicepath} | grep virtual)" = "" ]; then diff --git a/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js b/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js index 995515f01..5cd091920 100644 --- a/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js +++ b/luci-mod-network/htdocs/luci-static/resources/view/network/interfaces.js @@ -575,6 +575,10 @@ return view.extend({ o.value('backup',_('Backup')); o.default = 'off'; + o = s.taboption('advanced', form.Value, 'addlatency', _('Additional latency')); + o.datatype = 'uinteger'; + o.default = '0'; + if (L.hasSystemFeature('dnsmasq') || L.hasSystemFeature('odhcpd')) { o = s.taboption('dhcp', form.SectionValue, '_dhcp', form.TypedSection, 'dhcp'); o.depends('proto', 'static');