限制rp-pppoe伺服器每一個連接配接的帶寬
關鍵就是使用一個腳本,在ppp建立和取消連接配接的時候調用tc使用htb對每一個ppp連接配接的帶寬進行限制。
調用的腳本讀取/var/run/radattr.pppx中的radius屬性,限制帶寬。
use the roaringpenguin rp pppoe-server and limit the bandwidth per
interface with this script:
(im using freeradius plugins too, thats the reason of the
/var/run/radattr.pppx file)
(/etc/ppp/ip-up.d/0pppx_up)
#!/bin/sh
DOWN=`cat /var/run/radattr.$1 | grep 'RP-Downstream-Speed-Limit' | cut -d '
' -f 2`
UP=`cat /var/run/radattr.$1 | grep 'RP-Upstream-Speed-Limit' | cut -d ' ' -f
2`
# limit Download Bandwidth with a simple htb qdisc and class (add QoS
here?...)
/sbin/tc qdisc add dev $1 root handle 1: htb default 1
/sbin/tc class add dev $1 parent 1: classid 1:1 htb rate ${DOWN}kbit ceil
${DOWN}kbit burst 1540
/sbin/tc qdisc add dev $1 handle ffff: ingress
/sbin/tc filter add dev $1 parent ffff: protocol ip prio 50 u32 \
match ip src 0.0.0.0/0 \
police rate ${UP}kbit burst 10k drop flowid :1
and have another script for deleting the rules
(/etc/ppp/ip-down.d/0pppx_down):
#!/bin/sh
/sbin/tc qdisc del dev $1 root
/sbin/tc qdisc del dev $1 ingress
ppp executes this scripts each time an interface gets up or down.