2.13. 使用 flowtables 加快 nftables 数据包转发
nftables 工具使用 Netfilter 框架,它提供基于快速路径特性的 流表 机制来加快已建立连接的数据包。
flowtable 机制有以下功能:
- 使用连接跟踪来绕过典型的数据包转发路径。
- 避免通过绕过经典数据包处理来重新访问路由表。
- 只适用于 TCP 和 UDP 协议。
- 硬件独立软件快速路径。
流程
添加
inet系列的一个example-table:# nft add table inet <example-table>添加一个带有
ingress钩子和filter作为优先级类型的example-flowtableflowtable :# nft add flowtable inet <example-table> <example-flowtable> { hook ingress priority filter \; devices = { example_device_one, example_device_two } \; }将
example-forwardchain流添加到数据包处理表中的 flowtable :# nft add chain inet <example-table> <example-forwardchain> { type filter hook forward priority filter \; }此命令添加了一个带有
forward钩子和filter优先级的filter类型的 flowtable 。添加一个
established连接跟踪状态的规则,来卸载example-flowtable流:# nft add rule inet <example-table> <example-forwardchain> ct state { established, related } flow add @<example-flowtable>
验证
验证
example-table的属性:# nft list table inet <example-table> table inet example-table { flowtable example-flowtable { hook ingress priority filter devices = { example_device_one, example_device_two } } chain example-forwardchain { type filter hook forward priority filter; policy accept; ct state established flow add @example-flowtable } }