freeradius 限制rp-pppoe服务器每一个连接的带宽

限制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.

你可能感兴趣的:(freeradius)