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