欢迎光临
我们一直在努力

Traffic Control 添加 filter u32 错误 We have an error talking to the kernel

有问题请告诉我。我正在研究基于centos x86_64、linux版本2.6.32-431.3.1.el6.x86_64的构建流量整形器。所以,它有10个u32哈希表,都有256个除数。在默认表800中,我散列第三个八位字节并将数据包指向其中一个表,然后在散列第四个八位字节并将数据包指向描述每个用户带宽限制的类。所以,对于每个IP地址都有一个对应的TC类。我们很容易形成3000个IP地址。当我的脚本将这些IP添加到哈希表中时,我得到一个错误:RTNETLink回答:文件存在。更多代码:

tc qdisc add dev $inet root handle 2: htb default 8000
tc class add dev $inet parent 2: classid 2:6000 htb rate 100mbit

#this hash-tables are for subnets
for i in {901..912}; do
tc filter add dev $inet parent 2: handle $i: protocol ip u32 divisor 256
done
#adding filters for packet classifying
tc filter add dev $inet protocol ip parent 2: u32 ht 800:: match ip src 172.16.16.0/20 hashkey mask 0x0000ff00 at 12 link 901:
tc filter add dev $inet protocol ip parent 2: u32 ht 901:11: match ip src 172.16.17.0/24 hashkey mask 0x000000ff at 12 link 902:
tc filter add dev $inet protocol ip parent 2: u32 ht 901:12: match ip src 172.16.18.0/24 hashkey mask 0x000000ff at 12 link 903:
#...
#and so on under "link 912:"

#creating classes for every host, place it under root class 2: (100mb for all)
for i in {1..2815}; do tc class add dev $inet parent 2:6000 classid 2:$i htb rate 1mbit ceil 6mbit; done

#place each host in corresponding u32 table
for i in {1..255}; do printf -v hi "%x" "$i";
tc filter add dev $inet protocol ip parent 2: u32 ht 902:$hi: match ip src 172.16.17.$i flowid 2:$i
done
for i in {256..511}; do let j="i-256"; printf -v hi "%x" "$j";
tc filter add dev $inet protocol ip parent 2: u32 ht 903:$hi: match ip src 172.16.18.$j flowid 2:$i
done
#....
#and so on under 2815 hosts

在命令结束后的某个地方

tc filter add dev eth0 protocol ip parent 2: u32 ht 909:dc: match ip src 172.16.24.220 flowid 2:2012
RTNETLINK answers: File exists
We have an error talking to the kernel

我无法解决这个问题,我以为Linux内核中有一个过滤器数量限制,但有人说我这不是真的,根本没有限制。未重用流ID,也未发生哈希表句柄超限。还有什么可以导致代码中出现此错误?

最佳答案

我已经用另外两个内核重新创建了这个问题:现代的ubuntu 12.04 3.5.0-39-generic x86_64内核和旧的fedora 2.6.33.3-85 i686内核。它们都有。
这里的一些U32筛选器文档:http://ace-host.stuart.id.au/russell/files/tc/doc/cls_u32.txt建议筛选器句柄的最后一部分,即筛选器项,应该是十六进制0xfff,即4096(例如901:0:0到901:0:fff)。当您手动添加筛选器时,这是正确的。但是,使用哈希添加筛选器时,可以指定哈希表和bucket,但会自动创建筛选器id。
问题在于,当自动创建过滤器项时,它从800开始,这意味着您实际上只能使用0x800到0xffe过滤器(总共2048个)。
您可能认为可以像在示例中所做的那样,为添加的每个2048个筛选器切换哈希表,但事实并非如此-它仍然只允许您在哈希时总共添加2048个筛选器。我不确定这种行为是一个错误,一个限制,还是故意的。
要解决此问题,可以通过将筛选器项ID放在U32筛选器声明之前手动指定它,它必须具有零哈希表和bucket ID。这将允许您添加完整的4096筛选器,包括子网声明。它似乎还允许为每个哈希表添加4096个过滤器,因此您可以通过链接到另一个哈希表来添加更多的过滤器。脚本的最后一部分需要如下所示:

#place each host in corresponding u32 table
for i in {1..255}; do
  printf -v hi "%x" "$i";
  tc filter add dev $inet protocol ip parent 2: handle ::$hi u32 ht 902:$hi: match ip src 172.16.17.$i flowid 2:$i
done

for i in {256..511}; do 
  let j="i-256"; 
  printf -v hi "%x" "$i";
  printf -v hj "%x" "$j";
  tc filter add dev $inet protocol ip parent 2: handle ::$hi u32 ht 903:$hj: match ip src 172.16.18.$j flowid 2:$i
done
#....
#and so on under 2815 hosts

这是我测试过的代码,和你的代码一样,但是我重新构造了它,只使用了一个哈希表。它应该有同样的效率。它只在最后一个八位字节上散列到所需的bucket,然后按顺序匹配bucket中的过滤器,而不是按顺序匹配并链接到子网,然后散列到bucket。

#!/bin/bash

inet='eth0'

# Delete any existing traffic shaping
tc qdisc del dev $inet root
tc qdisc add dev $inet root handle 2: htb default 8000
tc class add dev $inet parent 2: classid 2:6000 htb rate 100mbit

# Create a single hash table (901) with 256 buckets
tc filter add dev $inet parent 2: handle 901: protocol ip u32 divisor 256

# Direct traffic from 172.16.16.0 - 172.16.31.255 to link 901, hash on last octet of src ip 
tc filter add dev $inet protocol ip parent 2: u32 ht 800:: match ip src 172.16.16.0/20 hashkey mask 0x000000ff at 12 link 901:

# Create classes for each host, place it under root class 2: (100mb for all)
for i in {1..2815}; do
    hex_handle=$(echo "obase=16; $i" | bc)
    tc class add dev $inet parent 2:6000 classid 2:$hex_handle htb rate 1mbit ceil 6mbit || exit 1;
done

# Add filters for each possible host
for y in {16..27}; do
    for x in {1..255}; do
        j=$(( (($y - 16) * 255) + $x ));
        hex_bucket=$(echo "obase=16; $x" | bc)
        hex_handle=$(echo "obase=16; $j" | bc)
        tc filter add dev $inet protocol ip parent 2: handle ::$hex_handle u32 ht 901:$hex_bucket match ip src 172.16.$y.$x flowid 2:$hex_handle || exit 1;
    done
done

https://tonydeng.github.io/sdn-handbook/linux/tc.html

赞(2) 打赏
转载请注明来源:IT技术资讯 » Traffic Control 添加 filter u32 错误 We have an error talking to the kernel

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏