qossky - QOS shaping script
State: active
This project has been founded because of several troubles with many users which use the same internet connection. In the majority of cases small businesses and home users haven't a commercial high expensive firewall.. The problem is very simple. Just think about the fact there are 10 standard users and 2 powerusers. The powerusers will blockade the complete line for the standard users. IPCop and other firewall/router distributions allow to make traffic shaping but only port and/or priority based. This script will give you the alternative to set a maximum of up & downstream capacity for each member IP-Address of an Class C network.
In later versions I will add a feature for a configuration file and group based shaping. Furthermore I will apply the script for IPCop web interface...
Download the current version now
#!/bin/bash
VERSION="2008-03-13"
###############################################################################
#
# Title: qossky
#
# Description: QS/TC script to shape the up&download speed for one netmask.
# In this version it is'nt possible to enter exceptions.
# Read more on www.skycube.net
#
# Author: Per Lasse Baasch (c)
# Website: http://www.skycube.net
#
# Licinse: GnuGPL v2
# Go to www.skycube.net to read the complete license
#
# Notes: This script has been tested on IPCop 1.4.13.
# In order to other qos sollutions like the small qos tool in
# IPCOP, you may should disable that scripts/progs./plugins...
#
# IMPORTANT: THIS SCRIPT HAD BEEN WRITTEN FOR "IPv4 Class C" NETWORKS !!!
# IF YOU WOULD LIKE TO USE IT IN A "IPv6" or Class A/B NETWORK,
# YOU HAVE TO COSTUMIZE SOMETHING IN THE RULES !!!!
#
# Requirements: - iptables (IPCop = default installed)
# - iproute (IPCop = default installed)
###############################################################################
# INSTALL
#
# - Copy this file to any directory on your server/router an execute it
# with > ./qossky.sh start
#
# IPCop: - > mv /tmp/qossky.sh /etc/rc.d/
# - > chmod 755 /etc/rc.d/qossky.sh
# - > vi /etc/rc.d/rc.local
# - > type the following: /etc/rc.d/qossky.sh
# - > reboot
#
###############################################################################
# USSAGE
#
# start -> start this script
# stop -> stop this script
# restart -> stop this script and start this script
# version -> print the version
#
###############################################################################
# START BASIC CONFIGURATION
# Path of tc... IPcop,ubuntu,debian -> /sbin/tc
TC=/sbin/tc
# device (INTRANET DEVICE, LOCAL with your local IP NOT ppp0!) // e.g. eth0
DEV1=eth0
# Netmask for the IPv4 Class C net // e.g. 192.168.11.
NETMASK=192.168.2.
# Download configuration
DOWNLOAD_1=4000kbit #(user=admin)
DOWNLOAD_2=1500kbit #(user=friends)
DOWNLOAD_3=800kbit #(user=normal)
# Upload configuration
UPLOAD_1=400kbit #(user=admin)
UPLOAD_2=150kbit #(user=friends)
UPLOAD_3=80kbit #(user=normal)
# END BASIC CONFIGURATION
###############################################################################
# START USERS CONFIGURATION
USERS_1=( 252 )
USERS_2=( 102 114 205 )
USERS_3=( 001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
031 032 033 034 035 036 037 038 039 040
041 042 043 044 045 046 047 048 049 050
051 052 053 054 055 056 057 058 059 060
061 062 063 064 065 066 067 068 069 070
071 072 073 074 075 076 077 078 079 080
081 082 083 084 085 086 087 088 089 090
091 092 093 094 095 096 097 098 099 100
101 103 104 105 106 107 108 109 110
111 112 113 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130
131 132 133 134 135 136 137 138 139 140
141 142 143 144 145 146 147 148 149 150
151 152 153 154 155 156 157 158 159 160
161 162 163 164 165 166 167 168 169 170
171 172 173 174 175 176 177 178 179 180
181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200
201 202 203 204 206 207 208 209 210
211 212 213 214 215 216 217 218 219 220
221 222 223 224 225 226 227 228 229 230
231 232 233 234 235 236 237 238 239
241 242 243 244 245 246 247 248 249 250
251 253 254 )
# END USERS CONFIGURATION
###############################################################################
# function for start
qossky_start() {
# INIT DEVICES
# download device
$TC qdisc add dev $DEV1 handle 1:0 root htb
# upload device
$TC qdisc add dev $DEV1 handle ffff: ingress
# DOWNLOAD & UPLOAD FILTERS FOR USERS_1
USERS_1SIZE=${#USERS_1[*]}
USERS_1COUNTER="0"
while [ "$USERS_1SIZE" -gt "$USERS_1COUNTER" ]
do
$TC filter add dev $DEV1 protocol ip parent 1:0 prio 1 u32 match ip dst ${NETMASK}${USERS_1[$USERS_1COUNTER]} police rate $DOWNLOAD_1 burst 10k drop flowid 1:1
$TC filter add dev $DEV1 protocol ip parent ffff:0 prio 1 u32 match ip src ${NETMASK}${USERS_1[$USERS_1COUNTER]} police rate $UPLOAD_1 burst 10k drop flowid ffff:1
let USERS_1COUNTER=USERS_1COUNTER+1
done
# DOWNLOAD & UPLOAD FILTERS FOR USERS_2
USERS_2SIZE=${#USERS_2[*]}
USERS_2COUNTER="0"
while [ "$USERS_2SIZE" -gt "$USERS_2COUNTER" ]
do
$TC filter add dev $DEV1 protocol ip parent 1:0 prio 1 u32 match ip dst ${NETMASK}${USERS_2[$USERS_2COUNTER]} police rate $DOWNLOAD_2 burst 10k drop flowid 1:1
$TC filter add dev $DEV1 protocol ip parent ffff:0 prio 1 u32 match ip src ${NETMASK}${USERS_2[$USERS_2COUNTER]} police rate $UPLOAD_2 burst 10k drop flowid ffff:1
let USERS_2COUNTER=USERS_2COUNTER+1
done
# DOWNLOAD & UPLOAD FILTERS FOR USERS_3
USERS_3SIZE=${#USERS_3[*]}
USERS_3COUNTER="0"
while [ "$USERS_3SIZE" -gt "$USERS_3COUNTER" ]
do
$TC filter add dev $DEV1 protocol ip parent 1:0 prio 1 u32 match ip dst ${NETMASK}${USERS_3[$USERS_3COUNTER]} police rate $DOWNLOAD_3 burst 10k drop flowid 1:1
$TC filter add dev $DEV1 protocol ip parent ffff:0 prio 1 u32 match ip src ${NETMASK}${USERS_3[$USERS_3COUNTER]} police rate $UPLOAD_3 burst 10k drop flowid ffff:1
let USERS_3COUNTER=USERS_3COUNTER+1
done
}
# function for stop
qossky_stop() {
# download traffic delete
$TC qdisc del dev $DEV1 root
# upload traffic delete
$TC qdisc del dev $DEV1 ingress
# iptables refresh
iptables -t mangle -F
}
# function for restart
qossky_restart() {
# exec stop function
qossky_stop
# wait a second :)
sleep 3
# exec start function
qossky_start
}
qossky_version() {
# Print the version of this script
echo " "
echo "qossky version:" $VERSION
echo " "
}
# handle functions
case "$1" in
start)
echo -n "Starting bandwidth shaping with qossky: "
qossky_start
echo "done"
;;
stop)
echo -n "Stopping bandwidth shaping with qossky: "
qossky_stop
echo "done"
;;
restart)
echo -n "Restarting bandwidth shaping with qossky: "
qossky_restart
echo "done"
;;
version)
qossky_version
;;
*)
echo "Usage: qossky {start|stop|restart|version}"
;;
esac
exit 0