#!/bin/bash #################################################################################### ## # Wait before starting sleep 1 # Set variables DEV=$1 AIP=$5 LOG=/usr/local/billing/shaper.log # Load config . /etc/billing.conf # Set mysql command line MYSQL="/usr/bin/mysql -h${rdbhost} -u${rdbuser} -p${rdbpass} ${rdbname}" q=`echo "select vgroups.tar_id,vgroups.shape from vgroups,sessionsradius where \ inet_ntoa(sessionsradius.assigned_ip=)\"$AIP\" and sessionsradius.vg_id=vgroups.vg_id" \ | $MYSQL | tail -n1` if test -z "$q"; then echo "`date` $DEV cannot find ${AIP} in active sessions" >> $LOG exit 0 fi tarid=`echo "$q" | awk '{print $1}'` shape=`echo "$q" | awk '{print $2}'` if test $shape -eq 0 2>/dev/null; then shape=`echo "select shape from tarifs where tar_id=${tarid}" | $MYSQL | tail -n1` fi if ! test $shape -ge 0 2>/dev/null then echo "`date` $DEV cannot get proper shape rate for $AIP" >> $LOG exit 0; fi if test $shape -gt 0 2>/dev/null then burst=`echo $shape/100+2 | bc 2>/dev/null` /sbin/tc qdisc add dev $DEV root tbf rate ${shape}kbit burst ${burst}kb latency 70ms minburst 1540 >/dev/null 2>&1 #/sbin/tc qdisc add dev $DEV handle ffff: ingress #/sbin/tc filter add dev $DEV parent ffff: protocol ip u32 match ip src 0.0.0.0/0 police rate ${shape}kbps burst ${burst}k mtu 12k drop flowid :1 echo "`date` Setting shape rate $shape for $DEV [$AIP]" >> $LOG fi; exit 0