tc 中 at 使用方法

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

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

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

举例:【匹配arp报文,目的mac是ae:7f:e4:f5:db:58

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来匹配

 

举例:【匹配arp协议,目的IP是1.2.3.4】

 共偏移24字节才能匹配到Target IP address

# 1.2.3.4
01 02 03 04
tc filter add dev bond1 parent ffff: protocol arp prio 10 u32 match u16 0x0806 0xffff at -2 match u32 0xc01020304 0xffffffff at 24 action mirred egress redirect dev eth15

 

 
posted @ 2023-04-14 19:35  salami_china  阅读(69)  评论(0编辑  收藏  举报