ブリッジポートのTC

ブリッジポートのTC

4ポートブリッジがあります。

root@Linux-Switch:~# brctl show
bridge name bridge id       STP enabled interfaces
br0     8000.000024cd2cb0   no      eth0
                            eth1
                            eth2
                            eth3

私の目標は、eth2インターフェースのアップロード速度を制限することです。 (eth0はアップストリームスイッチのアップリンクインターフェイスです)。私はtcとiptablesでこれをやろうとしました。

# tried in both the filter table and mangle table
iptables -A FORWARD -t mangle -m physdev --physdev-in eth2 -j MARK --set-mark 5 

tc qdisc add dev eth0 root handle 1:0 htb default 2
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 1mbit ceil 1mbit
tc class add dev eth0 parent 1:0 classid 1:2 htb rate 5mbit ceil 5mbit
tc filter add dev eth0 parent 1:0 handle 5 fw flowid 1:1

iptablesルールが一致していることがわかります。

root@Linux-Switch:~# iptables -vL -t mangle
...

Chain FORWARD (policy ACCEPT 107K packets, 96M bytes)
 pkts bytes target     prot opt in     out     source   destination         
38269   11M MARK       all  --  any    any     anywhere anywhere     PHYSDEV match --physdev-in eth2 MARK set 0x5 

...
root@Linux-Switch:~# 

ただし、tc設定はファームウェアフラグを読みませんでした。ポートeth2のすべてのトラフィックは、私が設定しようとしていた1Mbではなく、デフォルトの5Mbに制限されました。

root@Linux-Switch:~# tc -s class show dev eth0
class htb 1:1 root prio 0 rate 1000Kbit ceil 1000Kbit burst 100Kb cburst 100Kb 
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 0 borrowed: 0 giants: 0
 tokens: 200000 ctokens: 200000

class htb 1:2 root prio 0 rate 5000Kbit ceil 5000Kbit burst 100Kb cburst 100Kb 
 Sent 11465766 bytes 39161 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 6744bit 3pps backlog 0b 0p requeues 0 
 lended: 39161 borrowed: 0 giants: 0
 tokens: 2454400 ctokens: 2454400

root@Linux-Switch:~# 

私は何が間違っていましたか?

ベストアンサー1

私はそれを見つけました。フィルタに「プロトコル」を指定する必要があります。これに関する多くの文書があります。見つけることができるすべての例では、プロトコルを「ip」と指定していますが、これがスイッチなので「all」を試してみるとうまくいきました!

tc qdisc add dev eth0 root handle 1:0 htb default 2
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 1mbit ceil 1mbit
tc class add dev eth0 parent 1:0 classid 1:2 htb rate 5mbit ceil 5mbit
tc filter add dev eth0 parent 1:0 handle protocol all 5 fw flowid 1:1

おすすめ記事