Nftables 更新 1.1.5
nftables 1.1.5 – Commodore Bullmoose #6
nftables 1.1.5(“Commodore Bullmoose #6”)于 2025 年 8 月 27 日发布。这个版本继续延续了1.1 的版本名字,加了 #6
, 与之前预测一样,按照 #1
, #2
, #3
, #4
发布了多个小版本(marc.info)。
从git commit记录(Netfilter Git)来看,这个版本主要面向增强稳定性、修复边界架构(如 Big Endian)、完善测试框架、引入 tunnel 元数据支持 等方面。
下面根据官方的 Announce 梳理下具体更新的新功能.
nftables 1.1.5 改动详解
1. 支持 tunnel / 元数据 (metadata) / 语句 (statement)
这是 1.1.5 引入的较为明显的新支持之一 —— 在规则中可以声明 tunnel 元数据对象,并可匹配 / 操作这些 tunnel 元数据。
从 commit log 可见:
- tunnel: add tunnel object and statement json support (git.netfilter.org)
- tunnel: add geneve support (git.netfilter.org)
- tunnel: add vxlan support (git.netfilter.org)
- tunnel: add erspan support (git.netfilter.org)
具体示例(基于 commit 中给出的 usage):
table netdev x {
tunnel y {
id 10
ip saddr 192.168.2.10
ip daddr 192.168.2.11
sport 10
dport 20
ttl 10
geneve {
class 0x1010 opt-type 0x1 data "0x12345678"
class 0x1020 opt-type 0x2 data "0x87654321"
}
}
chain x {
type filter hook ingress device veth0 priority 0;
ip daddr 10.141.10.123
tunnel name y
fwd to erspan0
}
}
这个例子展示了在 netdev 表(即与网络设备关联的表)中定义一个名为 y
的 tunnel 对象,指定 geneve 隧道参数(包括选项数据),然后在 chain 中以 tunnel name y
作为条件使用,并将匹配流量 fwd to erspan0
。(git.netfilter.org)
换言之,你可以在规则里直接引用 tunnel 元数据,进行匹配或转发,这对处理隧道流量(Geneve, VXLAN, ERSPAN)非常便利。
2. 修正 Big Endian 平台上的 fib existence check 问题
在 1.1.4 中引入的 fib … check exists/missing
在大端(Big Endian)架构上存在字节顺序上的错误。1.1.5 中对此做了修复。(git.netfilter.org)
commit 说明:
- fib: Fix for existence check on Big Endian (git.netfilter.org)
“Adjust the expression size to 1B so cmp expression value is correct. Without this, the rule
fib saddr . iif oif present => reg 1
pluscmp eq reg 1 0x00000001
会在 BE 上错误处理,因为 nft_fib 模块只在第一个字节写入状态 (即使用 nft_reg_store8()),因此需要将比较表达式调整为 1 字节值 0x01 或 0x01000000,保证在 BE 平台比较正确。”(git.netfilter.org)
示例对比:
rule ip filter r1 {
fib saddr . iif check exists
counter accept
}
在 BE 架构,若未修正,该表达式在生成比较时可能把常量写为错误字节顺序,导致判断始终失败。1.1.5 修正后,就能在 BE 架构上正确执行 existence check。
nftables 1.1.5 编译安装指引
1. 依赖项
-
libnftnl ≥ 1.3.0:https://netfilter.org/projects/libnftnl/index.html
-
libmnl ≥ 1.0.4:https://netfilter.org/projects/libmnl/index.html
-
需要内核支持
nf_tables
(≥ Linux 3.14)。
2. 下载
-
官方下载页面:https://www.netfilter.org/projects/nftables/downloads.html
-
直接获取 1.1.5 源码包:
-
https://www.netfilter.org/pub/nftables/nftables-1.1.5.tar.xz
3. 编译与安装
# 解压源码包
tar xf nftables-1.1.5.tar.xz
cd nftables-1.1.5
# 配置,指定安装前缀(可选)
./configure --prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var
# 编译并测试
make
make check
# 安装
sudo make install
提示:如需卸载,可在源码目录内运行
sudo make uninstall
。
4. 更新 manpage 和重建库缓存
sudo mandb
ldconfig