tc 中 at 使用方法

发布时间 2023-04-14 19:42:16作者: salami_china

at 后面值是偏移量,偏移是从以太网头末尾开始计算的,在这之后用正数表示偏移量,在这之前用负数表示偏移量

以太网数据包格式:【https://blog.csdn.net/hhpingyear/article/details/80216680

 at等于0就是上面红色区域的其实位置,负数向前偏移,正数向后偏移

举例:

tc filter add dev eth0 parent ffff: prio 1 protocol arp u32 match u16 0x0806 0xffff at -2 match u32 0xe4f5db58 0xffffffff at -12 match u16 0xae7f 0xffff at -14 action mirred egress redirect dev eth1

 

dst MAC:ae 7f e4 f5 db 58 ---> 6字节
src MAC:ff ff ff ff ff ff ---> 6字节
协议:    08 06             ---> 2字节
at = 0

at -2 就是协议 0806
at -12 就是e4开始
at -14 就是ae开始

u32 只能匹配4字节,所以mac需要两个u32来匹配