From 0eb3e34ea0228d63e45b49cd92cca5d155af2bb4 Mon Sep 17 00:00:00 2001 From: hk Date: Thu, 1 Feb 2018 01:26:42 +0100 Subject: [PATCH] Add prio class support to IFB interface using -C --- src/tc-gen | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/tc-gen b/src/tc-gen index 5284580..8a47755 100755 --- a/src/tc-gen +++ b/src/tc-gen @@ -43,12 +43,11 @@ OPTIONS ignored. -c ":::,:::,..." Define extra leaf classes if you want to slice up and guarantee - bandwith between different kinds of traffic using fw marks. The default - class has a priority of 4. If this is not set all the bandwith is - given to the default class which is sufficient for most use cases. - These classes are only used for egress shaping. - If ceil is not set it will default to UP_RATE. If prio is not - set, it will default to the same priority as the default class. + bandwith between different kinds of traffic using fw marks on egress. + The default class has a priority of 4. If this is not set all the + bandwith is given to the default class which is sufficient for most + use cases. If ceil is not set it will default to UP_RATE. If prio is + not set, it will default to the same priority as the default class. Example: -c "107:50::,109:1400k:7M:2" @@ -59,6 +58,8 @@ OPTIONS available in the root class and has the same priority as the default class. The next leaf class has a fw mark of 109, a rate of 1400 kbit/s, a ceil of 7 mbit/s and a priority of 2. + -C ":::,:::,..." + Same as `-c` but for ingress on IFB interface. -x Clear all traffic control config on interface. -V @@ -265,7 +266,7 @@ add_prio_classes () { [[ -n ${CONFIG[3]} ]] && PRIO=${CONFIG[3]} if [[ ${CEIL_RATE} -gt ${MAX_RATE} ]]; then - echo "ERROR: ceiling value should not be larger than total max rate" + >&2 echo "ERROR: ceiling value should not be larger than total max rate" exit 1 fi @@ -354,10 +355,21 @@ apply_ingress_shaping () { ${TC} class add dev ${IFB_IF_NAME} parent 1: classid 1:1 htb \ rate ${DOWN_RATE}kbit + local DEFAULT_RATE=${DOWN_RATE} + local DEFAULT_PRIO=4 + + if [[ -n ${IFB_CLASS_CONFIG} ]]; then + add_prio_classes \ + ${IFB_IF_NAME} \ + "${IFB_CLASS_CONFIG}" \ + ${DOWN_RATE} \ + ${DEFAULT_PRIO} + fi + # Create class for the default priority ${TC} class add dev ${IFB_IF_NAME} parent 1:1 classid 1:99 htb \ - rate ${DOWN_RATE}kbit \ - ceil ${DOWN_RATE}kbit prio 0 \ + rate ${DEFAULT_RATE}kbit \ + ceil ${DOWN_RATE}kbit prio ${DEFAULT_PRIO} \ quantum $(get_htb_quantum ${DOWN_RATE}) # Set qdisc to fq_codel. Enabling ECN is recommended for ingress @@ -424,7 +436,7 @@ convert_rate () { } -while getopts ":i:u:d:b:f:q:c:xV" OPT; do +while getopts ":i:u:d:b:f:q:c:C:xV" OPT; do case ${OPT} in i) IF_NAME="${OPTARG}" @@ -444,6 +456,9 @@ while getopts ":i:u:d:b:f:q:c:xV" OPT; do c) CLASS_CONFIG="${OPTARG}" ;; + C) + IFB_CLASS_CONFIG="${OPTARG}" + ;; x) CLEAR_CONFIG=1 ;; @@ -463,6 +478,11 @@ if [[ -z ${IF_NAME} ]]; then exit 1 fi +if [[ -n ${IFB_CLASS_CONFIG} && -z ${IFB_IF_NAME} ]]; then + >&2 echo "ERROR: you must define an IFB interface to use IFB priority classes" + exit 1 +fi + if [[ -n ${CLEAR_CONFIG} ]]; then clear_all echo "Config cleared"