tc default不指定导致流量限制无效

下面的全局端口限速实例必须指定default也就是让数据归到流量分类1:1里才有效,也就是tc做的限速仅是限速分类,它仍然需要用tc filter将数据进行匹配,然后进入到tc class进行流量限制,class间的规则根据rate ceil对1:1 分类的剩余带宽进行抢夺,所以1:1看起来并不存在全局限速效果。这也许是以前那个ifb为什么会出现流量超过ceil的情况吧,但也不对啊ceil本身就是个上限。

tc qdisc del dev eth0 root 2> /dev/null > /dev/null
tc qdisc add dev eth0 root handle 1: htb default 1
tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps

晕死,平时的习惯比较好都指定了 default ,上面这种针对 conoha 对 eth0 进行全局限速必须指定 default 1 ,也就归到分类 classid 1:1 ,不然无效,我倒,怎么今天才注意到有这问题。不指定的话,下面的命令根本没数据生成
tc -s -d class show dev eth0

以前有些实例并未使用 default ,可能是 filter 里本身就用匹配器精确匹配了。
$TC filter add dev $UDEV parent 1:0 protocol all prio 999 u32 match ip protocol 0 0x00 flowid 1:40

tc filter add dev eth0.1 parent 1:0 protocol all priority 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev $DDEV

tc 限速的过程是 tc filter 做数据匹配标记,然后按标记进入 tc class 流量进行分类,按照设定的速率进行限速。

第一个实例之所以失效看 4 楼,首先是 tc -s -d filter show dev eth0 根本就没有任何有效 tc filter 规则生成,无法按照设想对数据进行标记,然后默认的 classid 1:20 分类也不存在。平时习惯比较好,不可能犯这种错误,一直以为 tc class add dev eth0 parent 1:0 calssid 1:1 htb rate 1Mbit 有全局限制效果,显然这是个错误认识。

一直以为 htb 这种树形结构像,就像大水管套小水管,以为 parent 1:0 有全局限制效果,从不指定 default 分类,或者说没有任何有效标记的情况下导致失效,显然它仅仅只是个分类规则。 parent 1:0 什么时候生效,可以看下面的例子,更多的就是在子队列节点互相借父队列的带宽
2. Link sharing
http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm

http://wiki.mikrotik.com/wiki/Manual:HTB

在这种情况下,仍然只有源端口 8989 有限速效果,
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 300kbps #根本没有想像中的全局限速效果,无效
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 100kbps ceil 100kbps
tc filter add dev eth0 parent 1:0 protocol ip u32 match ip sport 8989 0xffff flowid 1:10

所以仍然需要一条规则对 tc filter 无匹配到的数据进行 default 匹配,或者使用 tc filter 根据 prio 999 低优先级对剩余数据进行归类。不然就不存在 标记过程,也就无法进行 流量分类了。
#tc filter add dev eth0 parent 1:0 protocol all prio 999 u32 match ip protocol 0 0x00 flowid 1:1
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 600Kbit ceil 1Mbit

tc qdisc add dev eth0 root handle 1: htb default 12
This command attaches queue discipline HTB to eth0 and gives it the “handle” 1:. This is just a name or identifier with which to refer to it below. The default 12 means that any traffic that is not otherwise classified will be assigned to class 1:12.

http://lartc.org/howto/lartc.qdisc.filters.html
tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match \
ip sport 80 0xffff flowid 10:1

About: dato


发表评论

邮箱地址不会被公开。 必填项已用*标注