Created
August 19, 2016 03:47
-
-
Save mikehale/3699b64a007834200c4d7823d3ad069c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -x | |
# http://lartc.org/howto/lartc.qdisc.classful.html | |
# A single user has 5000kbit upload for himself. But they want prioritizing. | |
# Variables | |
TC=$(which tc) | |
IPT=$(which iptables) | |
IPTMO="$IPT -t mangle" | |
DEV=br-wan | |
RATE=5000 | |
insmod sch_prio | |
# The PRIO qdisc is a non-shaping container for a configurable number of classes | |
# which are dequeued in order. This allows for easy prioritization of traffic, | |
# where lower classes are only able to send if higher ones have no packets | |
# available. | |
$TC qdisc add dev $DEV root handle 1: prio | |
#$TC class add dev $DEV parent 1: classid 1:1 prio rate ${RATE}kbit | |
$TC qdisc add dev $DEV parent 1:1 handle 10: sfq | |
$TC qdisc add dev $DEV parent 1:1 handle 20: tbf rate ${RATE}kbit buffer 1600 limit 3000 | |
$TC qdisc add dev $DEV parent 1:1 handle 30: sfq | |
# Filter | |
# Since PRIO honors the TOS/QoS-Field by default, we should be concerned with our | |
# applications setting the right QoS for every packet they create. Additionally we | |
# can not blindly trust the set TOS and change it: | |
$IPTMO -F CHKTOS | |
$IPTMO -X CHKTOS | |
$IPTMO -N CHKTOS # create custom chain for this issue | |
$IPTMO -A POSTROUTING -o $DEV -j CHKTOS # every packet immediately jumps to custom-chain: CHKTOS | |
$IPTMO -A CHKTOS -m tos ! --tos Normal-Service -j RETURN # if TOS is set, leave it | |
$IPTMO -A CHKTOS -p udp -j TOS --set-tos Minimize-Delay # UDP gets high priority | |
$IPTMO -A CHKTOS -p udp -m length --length :160 -j TOS --set-tos Minimize-Delay # small udp packets | |
$IPTMO -A CHKTOS -p tcp -m length --length :128 -j TOS --set-tos Minimize-Delay # small tcp packets get high priority | |
$IPTMO -A CHKTOS -p tcp --sport ssh -j TOS --set-tos Minimize-Delay # prioritize ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment