28 个版本 (重大更改)
0.20.1 | 2024年6月29日 |
---|---|
0.19.0 | 2024年1月31日 |
0.18.1 | 2023年12月5日 |
0.17.1 | 2023年8月30日 |
0.1.0 | 2019年12月20日 |
#14 in 网络编程
407,613 每月下载量
用于 360 个Crate (直接使用29个)
1MB
24K SLoC
Rust Netlink 路由协议 crate
netlink-packet-route
crate 被设计用来将 Netlink 路由协议(rtnetlink
) 数据包抽象成 Rust 数据类型。这个 crate 的目标是让 netlink 用户免于阅读内核 Netlink 代码。
此 crate 将 Netlink 路由协议分成了以下模块
link
:网络接口卡(NIC)接口,类似于ip link
命令。address
:IP 地址,类似于ip address
命令。route
:路由,类似于ip route
命令。rule
:路由规则,类似于ip rule
命令。tc
:流量控制,类似于tc
命令。neighbour
:邻居,类似于ip neighbour
命令。neighbour_table
:邻居表,类似于ip ntable
命令。nsid
:命名空间,类似于ip netns
命令。
通常,您应该使用 rtnetlink
而不是直接使用此 crate。
开发
-
请使用
git commit --signoff
将 Signed-off-by 后缀添加到提交信息中。 -
对于新源文件,请在开头添加
// SPDX-License-Identifier: MIT
,内容为新代码的 MIT 许可证。 -
不允许恐慌,请使用
Result<>
代替unwrap()
或expect()
。 -
在创建 pull request 之前,请运行
cargo fmt
和cargo clippy
。 -
除非维护者明确批准,所有结构体/枚举都应该用
#[non_exhaustive]
装饰以保留 API 向后兼容性。 -
未知的 netlink 属性应该存储到
Other(DefaultNla)
而不是中断解码。 -
请使用单元测试用例来覆盖已更改的 netlink 属性的序列化和反序列化。为了捕获 netlink 原始字节,您可以再次使用 tcpdump/wireshark 对
nlmon
接口。例如
modprobe nlmon
ip link add nl0 type nlmon
ip link set nl0 up
tcpdump -i nl0 -w netlink_capture_file.cap
# Then use wireshark to open this `netlink_capture_file.cap`
# Find out the packet you are interested,
# right click -> "Copy" -> "...as Hex Dump".
# You may use https://github.com/cathay4t/hex_to_rust to convert this
# hexdump to rust u8 array
-
集成测试(与 Linux 内核 netlink 接口交互)应放在
rtnetlink
crate 中。当前的(netlink-packet-route)crate 应仅包含单元测试用例。 -
对于无法由 nlmon 捕获的某些 netlink 消息,请在注释中用 Rust 调试并解释每个位。
-
可选地,请运行
tools/test_cross_build.sh
以确保您的代码可以在其他平台上编译。
依赖项
~0.7–1.3MB
~28K SLoC