tc filter del 将所有filter删除的原因及解决方法

发表于:2007-06-08来源:作者:点击数: 标签:
最近用tc来做一些流量控制,结果发现这样的问题,删除一条filter会把别的filter一起都给删掉了,很让我郁闷。。最后辛辛苦苦的跑到LARTC的邮件列表上一个一个的看主题,终于是找到了解决方法。 How can I delete an existing filter? Is it possible? You mus
最近用tc来做一些流量控制,结果发现这样的问题,删除一条filter会把别的filter一起都给删掉了,很让我郁闷。。最后辛辛苦苦的跑到LARTC的邮件列表上一个一个的看主题,终于是找到了解决方法。

> How can I delete an existing filter? Is it possible?

You must at least provide the following:
  dev
  parent (qdisc or class)
  prio
  kind (filter type)
  handle

The kernel will then lookup the device, find the qdisc or class
aclearcase/" target="_blank" >ccording to your parent, lookup the filter ops according to the kind
and prio and then calls get() in the filter to look it up. The get() is
dependant on the filter type and thus deleting may vary from filter to
filter.

handle == 0 will destroy the whole filter tree

example 1: (destroying the whole tree)
# tc filter add dev eth0 parent 10:0 prio 10 protocol all u32 match \
      ip tos 1 0 flowid 10:12
# tc filter list dev eth0 parent 10:0
filter protocol all pref 10 u32
filter protocol all pref 10 u32 fh 800: ht divisor 1
filter protocol all pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 10:12
  match 00000000/00000000 at 0
# tc filter del dev eth0 parent 10:0 prio 10 u32
# tc filter list dev eth0 parent 10:0
#

example 2: (destroying a single filter)
# tc filter add dev eth0 parent 10:0 prio 10 protocol all u32 match \
      ip tos 1 0 flowid 10:12
# tc filter add dev eth0 parent 10:0 prio 10 protocol all u32 match \
      ip tos 1 0 flowid 10:12
# tc filter list dev eth0 parent 10:0
filter protocol all pref 10 u32
filter protocol all pref 10 u32 fh 800: ht divisor 1
filter protocol all pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 10:12
  match 00000000/00000000 at 0
filter protocol all pref 10 u32 fh 800::801 order 2049 key ht 800 bkt 0 flowid 10:12
  match 00000000/00000000 at 0
# tc filter del dev eth0 parent 10:0 prio 10 handle 800::801 u32
# tc filter list dev eth0 parent 10:0
filter protocol all pref 10 u32
filter protocol all pref 10 u32 fh 800: ht divisor 1
filter protocol all pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0
flowid 10:12
  match 00000000/00000000 at 0
#

rule of thumb:
- deleting a filter with handle NOT specified deletes whole filter tree
- deleting a filter with handle specified deletes only the filter with
  the given handle
(说明,其实在这里也可以使用prio来区分,只是如果我有很多的规则的话,使用这个好像不太合适,因此还是使用handle来得好些。)

This does not apply to all filters though.

原文转自:http://www.ltesting.net