Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- run_command ()
- {
- if [ "$verbose" == "yes" ]; then
- echo $1
- fi
- $1 > /tmp/q0s-error1 2> /tmp/q0s-error2
- errorcode=$?
- if [ $errorcode -ne 0 ]; then
- if [ "$2" != "force" ]; then
- echo
- echo
- echo "*ERROR* Unable to execute the following command:"
- echo
- echo " $1"
- echo
- echo "The error message(s) was the following:"
- echo
- cat /tmp/q0s-error1
- cat /tmp/q0s-error2
- rm -f /tmp/q0s-error1 /tmp/q0s-error2
- echo
- echo
- echo
- echo "The script will now terminate."
- exit $errorcode
- fi
- fi
- rm -f /tmp/q0s-error1 /tmp/q0s-error2
- if [ -z "$quiet" ]; then
- echo -n "."
- fi
- }
- conffile="/etc/q0s.conf"
- if [ "$1" == "-v" ]; then
- verbose="yes"
- fi
- if [ "$1" == "-q" ]; then
- quiet="yes"
- fi
- if [ -z "$quiet" ]; then
- echo "QoS initializing..."
- echo
- fi
- # Parse the configuration file
- if [ -r $conffile ]; then
- if [ "$verbose" ]; then
- echo "Using $conffile"
- fi
- source $conffile
- else
- echo "Unable to read $conffile"
- exit 1
- fi
- # Convert from array format to comma separated list for use with multiport
- band1ports=`echo ${band1ports[@]} | sed -e 's/ /,/g'`
- band2ports=`echo ${band2ports[@]} | sed -e 's/ /,/g'`
- band3ports=`echo ${band3ports[@]} | sed -e 's/ /,/g'`
- band5ports=`echo ${band5ports[@]} | sed -e 's/ /,/g'`
- band8ports=`echo ${band8ports[@]} | sed -e 's/ /,/g'`
- l7_band=${l7_band[@]}
- l7_proto=${l7_proto[@]}
- specialserviceports=${specialserviceports[@]}
- specialhosts=${specialhosts[@]}
- specialhosts_shpd=${specialhosts_shpd[@]}
- # Was which user set, if not use hardcoded path
- which=${which:="/usr/bin/which"}
- # which sanity check (can it find itself?)
- if [ "`$which which`" == "$which" ]; then
- tc=${tc:=`which tc 2>/dev/null`}
- iptables=${iptables:=`which iptables 2>/dev/null`}
- fi
- # If these paths are not user set, and which couldn't find them. use hardcoded paths
- tc=${tc:="/sbin/tc"}
- iptables=${iptables:="/sbin/iptables"}
- shp_pct=${shp_pct:=10}
- class8_shp_pct=${class8_shp_pct:=10}
- wan_spd_down_shpd=${wad_spd_down_shpd:=$[$wan_spd_down-(($wan_spd_down*$shp_pct)/100)]}
- wan_spd_up_shpd=${wan_spd_up_shpd:=$[$wan_spd_up-(($wan_spd_up*$shp_pct)/100)]}
- lan_spd=${lan_spd:=102400}
- lan_spd_shpd=${lan_spd_shpd:=$[$lan_spd-($lan_spd*$shp_pct)/100]}
- wan_spd_class8_down_shpd=${wan_spd_class8_down_shpd:=$[$wan_spd_down-(($wan_spd_down*($shp_pct+$class8_shp_pct))/100)]}
- wan_spd_class8_up_shpd=${wan_spd_class8_up_shpd:=$[$wan_spd_up-(($wan_spd_up*($shp_pct+$class8_shp_pct))/100)]}
- band0down=${band0down:=$[$wan_spd_down_shpd*10/100]}
- band1down=${band1down:=$[$wan_spd_down_shpd*15/100]}
- band2down=${band2down:=$[$wan_spd_down_shpd*30/100]}
- band3down=${band3down:=$[$wan_spd_down_shpd*40/100]}
- band4down=${band4down:=$[$wan_spd_down_shpd/100]}
- band5down=${band5down:=$[$wan_spd_down_shpd/100]}
- band6down=${band6down:=$[$wan_spd_down_shpd/100]}
- band7down=${band7down:=$[$wan_spd_down_shpd/100]}
- band8down=${band8down:=$[$wan_spd_down_shpd/100]}
- band0up=${band0up:=$[$wan_spd_up_shpd*10/100]}
- band1up=${band1up:=$[$wan_spd_up_shpd*15/100]}
- band2up=${band2up:=$[$wan_spd_up_shpd*30/100]}
- band3up=${band3up:=$[$wan_spd_up_shpd*40/100]}
- band4up=${band4up:=$[$wan_spd_up_shpd/100]}
- band5up=${band5up:=$[$wan_spd_up_shpd/100]}
- band6up=${band6up:=$[$wan_spd_up_shpd/100]}
- band7up=${band7up:=$[$wan_spd_up_shpd/100]}
- band8up=${band8up:=$[$wan_spd_up_shpd/100]}
- band1move=${band1move:=20000}
- band2move=${band2move:=250000}
- band3move=${band3move:=1000000}
- band4move=${band4move:=2000000}
- band5move=${band5move:=5000000}
- band6move=${band6move:=7000000}
- force_interactive=${force_interactive:=500}
- mark_offset=${mark_offset:=0xFF}
- if [ -z "$quiet" ]; then
- echo -e "LAN interface: $lan_if \t Shaped at: ${lan_spd_shpd}/${lan_spd_shpd}kbps"
- echo -e "WAN interface: $wan_if \t Shaped at: ${wan_spd_down_shpd}/${wan_spd_up_shpd}kbps"
- echo
- echo "Bandwidth on LAN and WAN have been shaped by ${shp_pct}%"
- echo
- if [ "$has_ipp2p" == "yes" ]; then
- echo "Using ipp2p for marking packets."
- fi
- if [ "$has_l7" == "yes" ]; then
- echo "Using layer 7 packet classifier for marking packets."
- fi
- echo
- echo -n "Setting up htb tree for $lan_if."
- fi
- run_command "$tc qdisc del dev $lan_if root" "force"
- # Add classes and egrees (output) qdiscs to LAN interface
- run_command "$tc qdisc add dev $lan_if root handle 1: htb default 70"
- run_command "$tc class add dev $lan_if parent 1: classid 1:10 htb rate ${lan_spd_shpd}kbit ceil ${lan_spd_shpd}kbit burst 6k prio 1"
- run_command "$tc qdisc add dev $lan_if parent 1:10 handle 10: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1: classid 1:20 htb rate ${wan_spd_down_shpd}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 0"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:30 htb rate ${band0down}kbit ceil ${band0down}kbit burst 6k prio 0"
- run_command "$tc qdisc add dev $lan_if parent 1:30 handle 30: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:40 htb rate ${band1down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 1"
- run_command "$tc qdisc add dev $lan_if parent 1:40 handle 40: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:50 htb rate ${band2down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 2"
- run_command "$tc qdisc add dev $lan_if parent 1:50 handle 50: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:60 htb rate ${band3down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 3"
- run_command "$tc qdisc add dev $lan_if parent 1:60 handle 60: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:70 htb rate ${band4down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 4"
- run_command "$tc qdisc add dev $lan_if parent 1:70 handle 70: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:80 htb rate ${band5down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 5"
- run_command "$tc qdisc add dev $lan_if parent 1:80 handle 80: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:90 htb rate ${band6down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 6"
- run_command "$tc qdisc add dev $lan_if parent 1:90 handle 90: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:100 htb rate ${band7down}kbit ceil ${wan_spd_down_shpd}kbit burst 6k prio 7"
- run_command "$tc qdisc add dev $lan_if parent 1:100 handle 100: sfq perturb 10"
- run_command "$tc class add dev $lan_if parent 1:20 classid 1:110 htb rate ${band8down}kbit ceil ${wan_spd_class8_down_shpd}kbit burst 6k prio 8"
- run_command "$tc qdisc add dev $lan_if parent 1:110 handle 110: sfq perturb 10"
- if [ -z "$quiet" ]; then
- echo; echo -n "Setting up htb tree for $wan_if."
- fi
- # Add classes and egress (output) qdiscs to external interface
- run_command "$tc qdisc del dev $wan_if root" "force"
- run_command "$tc qdisc add dev $wan_if root handle 1: htb default 70"
- run_command "$tc class add dev $wan_if parent 1: classid 1:10 htb rate ${wan_spd_down}kbit ceil ${wan_spd_down}kbit burst 6k prio 1"
- run_command "$tc qdisc add dev $wan_if parent 1:10 handle 10: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1: classid 1:20 htb rate ${wan_spd_up_shpd}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 0"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:30 htb rate ${band0up}kbit ceil ${band0up}kbit burst 6k prio 0"
- run_command "$tc qdisc add dev $wan_if parent 1:30 handle 30: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:40 htb rate ${band1up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 1"
- run_command "$tc qdisc add dev $wan_if parent 1:40 handle 40: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:50 htb rate ${band2up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 2"
- run_command "$tc qdisc add dev $wan_if parent 1:50 handle 50: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:60 htb rate ${band3up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 3"
- run_command "$tc qdisc add dev $wan_if parent 1:60 handle 60: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:70 htb rate ${band4up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 4"
- run_command "$tc qdisc add dev $wan_if parent 1:70 handle 70: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:80 htb rate ${band5up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 5"
- run_command "$tc qdisc add dev $wan_if parent 1:80 handle 80: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:90 htb rate ${band6up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 6"
- run_command "$tc qdisc add dev $wan_if parent 1:90 handle 90: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:100 htb rate ${band7up}kbit ceil ${wan_spd_up_shpd}kbit burst 6k prio 7"
- run_command "$tc qdisc add dev $wan_if parent 1:100 handle 100: sfq perturb 10"
- run_command "$tc class add dev $wan_if parent 1:20 classid 1:110 htb rate ${band8up}kbit ceil ${wan_spd_class8_up_shpd}kbit burst 6k prio 8"
- run_command "$tc qdisc add dev $wan_if parent 1:110 handle 110: sfq perturb 10"
- # Set up rules for sorting the packages into the bands
- if [ -z "$quiet" ]; then
- echo; echo -n "Setting up filters."
- fi
- tc_filter_wan="$tc filter add dev $wan_if protocol ip parent 1:0 prio 1 handle"
- tc_filter_lan="$tc filter add dev $lan_if protocol ip parent 1:0 prio 1 handle"
- run_command "$tc_filter_lan $((1 + $mark_offset)) fw flowid 1:10"
- run_command "$tc_filter_lan $((3 + $mark_offset)) fw flowid 1:30"
- run_command "$tc_filter_wan $((3 + $mark_offset)) fw flowid 1:30"
- run_command "$tc_filter_lan $((4 + $mark_offset)) fw flowid 1:40"
- run_command "$tc_filter_wan $((4 + $mark_offset)) fw flowid 1:40"
- run_command "$tc_filter_lan $((5 + $mark_offset)) fw flowid 1:50"
- run_command "$tc_filter_wan $((5 + $mark_offset)) fw flowid 1:50"
- run_command "$tc_filter_lan $((6 + $mark_offset)) fw flowid 1:60"
- run_command "$tc_filter_wan $((6 + $mark_offset)) fw flowid 1:60"
- run_command "$tc_filter_lan $((7 + $mark_offset)) fw flowid 1:70"
- run_command "$tc_filter_wan $((7 + $mark_offset)) fw flowid 1:70"
- run_command "$tc_filter_lan $((8 + $mark_offset)) fw flowid 1:80"
- run_command "$tc_filter_wan $((8 + $mark_offset)) fw flowid 1:80"
- run_command "$tc_filter_lan $((9 + $mark_offset)) fw flowid 1:90"
- run_command "$tc_filter_wan $((9 + $mark_offset)) fw flowid 1:90"
- run_command "$tc_filter_lan $((10 + $mark_offset)) fw flowid 1:100"
- run_command "$tc_filter_wan $((10 + $mark_offset)) fw flowid 1:100"
- run_command "$tc_filter_lan $((11 + $mark_offset)) fw flowid 1:110"
- run_command "$tc_filter_wan $((11 + $mark_offset)) fw flowid 1:110"
- if [ -z "$quiet" ]; then
- echo; echo -n "Setting up packet marking."
- fi
- # Reset rules
- run_command "$iptables -F q0s_fwd -t mangle" "force"
- run_command "$iptables -F q0s_out_lan -t mangle" "force"
- run_command "$iptables -F q0s_out_wan -t mangle" "force"
- run_command "$iptables -X q0s_fwd -t mangle" "force"
- run_command "$iptables -X q0s_out_lan -t mangle" "force"
- run_command "$iptables -X q0s_out_wan -t mangle" "force"
- run_command "$iptables -N q0s_fwd -t mangle" "force"
- run_command "$iptables -N q0s_out_wan -t mangle" "force"
- run_command "$iptables -N q0s_out_lan -t mangle" "force"
- run_command "$iptables -D FORWARD -t mangle -i $lan_if -o $wan_if -j q0s_fwd" "force"
- run_command "$iptables -D FORWARD -t mangle -i $wan_if -o $lan_if -j q0s_fwd" "force"
- run_command "$iptables -D OUTPUT -t mangle -o $wan_if -j q0s_out_wan" "force"
- run_command "$iptables -D OUTPUT -t mangle -o $lan_if -j q0s_out_lan" "force"
- run_command "$iptables -A FORWARD -t mangle -i $lan_if -o $wan_if -j q0s_fwd"
- run_command "$iptables -A FORWARD -t mangle -i $wan_if -o $lan_if -j q0s_fwd"
- run_command "$iptables -A OUTPUT -t mangle -o $wan_if -j q0s_out_wan"
- run_command "$iptables -A OUTPUT -t mangle -o $lan_if -j q0s_out_lan"
- # If packets are connmarked, just return
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -j CONNMARK --restore-mark"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m mark --mark $((3 + $mark_offset)) -j RETURN"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m mark --mark $((4 + $mark_offset)) -j RETURN"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m mark --mark $((11 + $mark_offset)) -j RETURN"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m mark --mark $(($ipp2p_band + 3 + $mark_offset)) -j RETURN"
- # *** Band 1 ports ***
- if [ -n "$band1ports" ]; then
- # Default priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --dports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --sports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- # Connbytes priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band1move:$band2move -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band1move:$band2move -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- # Output default and connbytes
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp -m multiport --dports $band1ports -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band1move:$band2move -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band1ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- # Mark interactive, if packets are smaller than $force_interactive
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band1ports -m length --length 0:$force_interactive -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band1ports -m length --length 0:$force_interactive -j MARK --set-mark $((4 + $mark_offset))"
- fi
- # *** Band 2 ports ***
- if [ -n "$band2ports" ]; then
- # Default priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --dports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --sports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- # Connbytes priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- # Output default and connbytes
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp -m multiport --dports $band2ports -j MARK --set-mark $((5 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band2move:$band3move -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band2ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- fi
- # *** Band 3 ports ***
- if [ -n "$band3ports" ]; then
- # Default priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --dports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --sports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- # Connbytes priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band3ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band3ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- # Output default and connbytes
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp -m multiport --dports $band3ports -j MARK --set-mark $((6 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band3ports -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band3move:$band4move -j MARK --set-mark $((7 + $mark_offset))"
- fi
- # Transfers over band4move is moved down in priority:
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band4move:$band5move -j MARK --set-mark $((8 + $mark_offset))"
- # *** Band 5 ports ***
- if [ -n "$band5ports" ]; then
- # Default priority
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dport $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --dport $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sport $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --sport $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- # Output default
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp -m multiport --dports $band5ports -j MARK --set-mark $((9 + $mark_offset))"
- fi
- # Transfers over band4move is moved down in priority, connmark for the last match:
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band5move:$band6move -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band6move: -j MARK --set-mark $((10 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band5move:$band6move -j MARK --set-mark $((9 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m connbytes --connbytes-dir both --connbytes-mode bytes --connbytes $band6move: -j MARK --set-mark $((10 + $mark_offset))"
- # Special band 8, these ports are always in that band
- if [ -n "$band8ports" ]; then
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --dports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --dports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m multiport --sports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p udp -m multiport --sports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp -m multiport --dports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp -m multiport --dports $band8ports -j MARK --set-mark $((11 + $mark_offset))"
- fi
- if [ "$has_ipp2p" == "yes" ]; then
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m ipp2p $ipp2p_protos -j MARK --set-mark $(($ipp2p_band + 3 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m mark --mark $(($ipp2p_band + 3 + $mark_offset)) -j CONNMARK --save-mark"
- fi
- if [ "$has_l7" == "yes" ]; then
- for ((i=1; i<${#l7_proto[*]}; i++)); do
- run_command "$iptables -A q0s_fwd -t mangle -p tcp -m layer7 $l7_opts --l7proto ${l7_proto[$i]} -j MARK --set-mark $((${l7_band[$i]} + 3 + $mark_offset))"
- done
- fi
- # Packets from special hosts get in the interactive traffic band at all times
- for host in $specialhosts; do
- run_command "$iptables -A q0s_fwd -t mangle -s $host -j MARK --set-mark $((4 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -d $host -j MARK --set-mark $((4 + $mark_offset))"
- done
- for port in $specialserviceports; do
- run_command "$iptables -A q0s_out_wan -t mangle -p tcp --sport $port -j MARK --set-mark $((3 + $mark_offset))"
- run_command "$iptables -A q0s_out_wan -t mangle -p udp --sport $port -j MARK --set-mark $((3 + $mark_offset))"
- done
- # These get interactive, but have a much lower max rate
- for host in $specialhosts_shpd; do
- run_command "$iptables -A q0s_fwd -t mangle -s $host -j MARK --set-mark $((3 + $mark_offset))"
- run_command "$iptables -A q0s_fwd -t mangle -d $host -j MARK --set-mark $((3 + $mark_offset))"
- done
- # LOCALHOST to LAN needs full speed, not just the default
- run_command "$iptables -A q0s_out_lan -t mangle -j MARK --set-mark $((1 + $mark_offset))"
- #putting ACK packets in the interactive queue
- run_command "$tc filter add dev $wan_if parent 1: protocol ip prio 10 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u16 0x0000 0xffc0 at 2 match u8 0x10 0xff at 33 flowid 1:40"
- run_command "$tc filter add dev $lan_if parent 1: protocol ip prio 10 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u16 0x0000 0xffc0 at 2 match u8 0x10 0xff at 33 flowid 1:40"
- # Ensure that we never download more than the configured rate
- run_command "$tc qdisc del dev $wan_if handle ffff: ingress" "force"
- run_command "$tc qdisc add dev $wan_if handle ffff: ingress"
- run_command "$tc filter add dev $wan_if parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate ${wan_spd_down_shpd}kbit burst 10k drop flowid :1"
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement