6-match(u32分类器fw分类器)

Linux流量控制—过滤规则/U32–实例解析:
http://blog.sina.com.cn/s/blog_a481de5701015npe.html
https://www.cnblogs.com/CasonChan/p/5033949.html

linux2.6.35内核qos源码分析之fw分类器 - 豆丁网:
https://max.book118.com/html/2017/0418/100980173.shtm

  • 源地址段:match ip src 1.2.3.0/24
  • 目的地址段:match ip dst 4.3.2.0/24
  • 单个IP地址:match ip 1.2.3.4/32
  • 源端口80:match ip sport 80 0xffff,其中0xffff表示所有数据包
  • 目的端口80:match ip dport 80 0xffff
  • 根据IP协议 (tcp, udp, icmp, gre, ipsec)

image

icmp是1:match ip protocol 1 0xff,其中 1是根据/etc/protocols协议号来设定

root@zihome:/# cat /etc/protocols
# Internet (IP) protocols
#
# Updated from http://www.iana.org/assignments/protocol-numbers and other
# sources.
# New protocols will be added on request if they have been officially
# assigned by IANA and are not historical.
# If you need a huge list of used numbers please install the nmap package.

ip      0       IP              # internet protocol, pseudo protocol number
#hopopt 0       HOPOPT          # IPv6 Hop-by-Hop Option [RFC1883]
icmp    1       ICMP            # internet control message protocol
igmp    2       IGMP            # Internet Group Management
ggp     3       GGP             # gateway-gateway protocol
ipencap 4       IP-ENCAP        # IP encapsulated in IP (officially ``IP'')
st      5       ST              # ST datagram mode
tcp     6       TCP             # transmission control protocol
egp     8       EGP             # exterior gateway protocol
igp     9       IGP             # any private interior gateway (Cisco)
pup     12      PUP             # PARC universal packet protocol
udp     17      UDP             # user datagram protocol
hmp     20      HMP             # host monitoring protocol
xns-idp 22      XNS-IDP         # Xerox NS IDP
rdp     27      RDP             # "reliable datagram" protocol
iso-tp4 29      ISO-TP4         # ISO Transport Protocol class 4 [RFC905]
xtp     36      XTP             # Xpress Transfer Protocol
ddp     37      DDP             # Datagram Delivery Protocol
idpr-cmtp 38    IDPR-CMTP       # IDPR Control Message Transport
ipv6    41      IPv6            # Internet Protocol, version 6
ipv6-route 43   IPv6-Route      # Routing Header for IPv6
ipv6-frag 44    IPv6-Frag       # Fragment Header for IPv6
idrp    45      IDRP            # Inter-Domain Routing Protocol
rsvp    46      RSVP            # Reservation Protocol
gre     47      GRE             # General Routing Encapsulation
esp     50      IPSEC-ESP       # Encap Security Payload [RFC2046]
ah      51      IPSEC-AH        # Authentication Header [RFC2402]
skip    57      SKIP            # SKIP
ipv6-icmp 58    IPv6-ICMP       # ICMP for IPv6
ipv6-nonxt 59   IPv6-NoNxt      # No Next Header for IPv6
ipv6-opts 60    IPv6-Opts       # Destination Options for IPv6
rspf    73      RSPF CPHB       # Radio Shortest Path First (officially CPHB)
vmtp    81      VMTP            # Versatile Message Transport
eigrp   88      EIGRP           # Enhanced Interior Routing Protocol (Cisco)
ospf    89      OSPFIGP         # Open Shortest Path First IGP
ax.25   93      AX.25           # AX.25 frames
ipip    94      IPIP            # IP-within-IP Encapsulation Protocol
etherip 97      ETHERIP         # Ethernet-within-IP Encapsulation [RFC3378]
encap   98      ENCAP           # Yet Another IP encapsulation [RFC1241]
#       99                      # any private encryption scheme
pim     103     PIM             # Protocol Independent Multicast
ipcomp  108     IPCOMP          # IP Payload Compression Protocol
vrrp    112     VRRP            # Virtual Router Redundancy Protocol
l2tp    115     L2TP            # Layer Two Tunneling Protocol [RFC2661]
isis    124     ISIS            # IS-IS over IPv4
sctp    132     SCTP            # Stream Control Transmission Protocol
fc      133     FC              # Fibre Channel

根据fwmark

iptables -A PREROUTING -t mangle -i eth0 -j MARK --set-mark 6
tc filter add dev eth1 protocol ip parent 1:0 prio 1 handle 6 fw flowid 1:1

注:handle根据过滤器的不同,含义也不同

https://www.cnblogs.com/CasonChan/p/5033947.html

Example that matches ARP (a big “thank you” to Martin Brown for this!):
dst MAC is 6 bytes at -14
src MAC is 6 bytes at -8
the ARP protocol is 2 bytes at -2
the “0806” comes from linux/include/linux/if_ether.h

tc filter add dev $DEV parent 1: protocol ip prio 5 u32 match u16 0x0806 0xffff at -2 flowid 1:50

为实现基于tc命令和ifb虚拟网卡的下行限速,通过ebtables表为特定设备标记,而后设计如下命令,ifconfig ifb1 up tc qdisc add dev ifb1 root handle 2: htb default 3 ebtables -N CSL_MARK_OUTPUT ebtables -A OUTPUT -j CSL_MARK_OUTPUT ebtables -A CSL_MARK_OUTPUT -d 10:B6:76:57:7B:A1 -j mark --set-mark 0x8002 ebtables -A CSL_MARK_OUTPUT -d 10:B6:76:57:7B:A1 -j RETURN ebtables -A CSL_MARK_OUTPUT -d A6:2A:D4:FE:88:21 -j mark --set-mark 0x8002 ebtables -A CSL_MARK_OUTPUT -d A6:2A:D4:FE:88:21 -j RETURN ebtables -A CSL_MARK_OUTPUT -d 20:7B:D2:42:D9:03 -j mark --set-mark 0x8002 ebtables -A CSL_MARK_OUTPUT -d 20:7B:D2:42:D9:03 -j RETURN --- tc qdisc add dev ae_wan root handle 10: prio tc filter add dev ae_wan parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev eth0.8.3 root handle 10: prio tc filter add dev eth0.8.3 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev eth0.8.4 root handle 10: prio tc filter add dev eth0.8.4 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev eth0.8.5 root handle 10: prio tc filter add dev eth0.8.5 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev eth0.8.6 root handle 10: prio tc filter add dev eth0.8.6 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev eth0 root handle 10: prio tc filter add dev eth0 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 tc qdisc add dev ae_wan@0 root handle 10: prio tc filter add dev ae_wan@0 parent 10: protocol all prio 1 u32 match u32 0 0 flowid 10:1 action mirred egress redirect dev ifb1 --- tc class add dev ifb1 parent 2:0 classid 2:1 htb rate 2000kbit ceil 2000kbit ---- tc class add dev ifb1 parent 2:1 classid 2:2 htb rate 1000kbit ceil 1000kbit tc filter add dev ifb1 parent 2:0 protocol all handle 0x8002 fw classid 2:2 tc qdisc add dev ifb1 parent 2:2 handle 22: sfq perturb 10。此外,ebtables表如下:~ # ebtables -L Bridge table: filter Bridge chain: INPUT, entries: 1, policy: ACCEPT -i ae_wan+ -j DROP Bridge chain: FORWARD, entries: 4, policy: ACCEPT -j EB_TS_WIREINTF_FORWARD -j EB_FORWARD_BEFORE_LAN -j EB_FORWARD_LAN -j EB_FORWARD_AFTER_LAN Bridge chain: OUTPUT, entries: 3, policy: ACCEPT -j EB_ETH_1905_OUTPUT -j EB_TS_WIREINTF_OUTPUT -j CSL_MARK_OUTPUT Bridge chain: EB_TS_WIREINTF_FORWARD, entries: 4, policy: RETURN -o eth0.8.4.40+ -j DROP -o eth0.8.5.40+ -j DROP -o eth0.8.3.40+ -j DROP -o eth0.8.6.40+ -j DROP Bridge chain: EB_TS_WIREINTF_OUTPUT, entries: 4, policy: RETURN -o eth0.8.4.40+ -j DROP -o eth0.8.5.40+ -j DROP -o eth0.8.3.40+ -j DROP -o eth0.8.6.40+ -j DROP Bridge chain: EB_FORWARD_BEFORE_LAN, entries: 1, policy: RETURN -i ae_wan+ -o ae_wan+ -j DROP Bridge chain: EB_FORWARD_LAN, entries: 8, policy: RETURN -i ra+ -o eth+ -j ACCEPT -i eth+ -o ra+ -j ACCEPT -i ra+ -o ra+ -j ACCEPT -i rai+ -o eth+ -j ACCEPT -i eth+ -o rai+ -j ACCEPT -i rai+ -o rai+ -j ACCEPT -i ra+ -o rai+ -j ACCEPT -i rai+ -o ra+ -j ACCEPT Bridge chain: EB_FORWARD_AFTER_LAN, entries: 0, policy: RETURN Bridge chain: ACCESSCTL, entries: 0, policy: ACCEPT Bridge chain: EB_ETH_1905_OUTPUT, entries: 0, policy: RETURN Bridge chain: CSL_MARK_OUTPUT, entries: 6, policy: ACCEPT -d 10:B6:76:57:7B:A1 -j mark --mark-set 0x8002 --mark-target ACCEPT -d 10:B6:76:57:7B:A1 -j RETURN -d A6:2A:D4:FE:88:21 -j mark --mark-set 0x8002 --mark-target ACCEPT -d A6:2A:D4:FE:88:21 -j RETURN -d 20:7B:D2:42:D9:03 -j mark --mark-set 0x8002 --mark-target ACCEPT -d 20:7B:D2:42:D9:03 -j RETURN ~ # 请分析为什么限速失败
10-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Creator_Ly

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值