jkunz 24157ffb64
Build / Build (x86_64-linux-android) (push) Failing after 4s
Build / Build (x86_64-apple-darwin) (push) Canceled after 6s
Build / Build (x86_64-unknown-freebsd) (push) Canceled after 5s
Build / Build (x86_64-unknown-fuchsia) (push) Canceled after 5s
Build / Build (x86_64-unknown-linux-gnu) (push) Canceled after 6s
Rustfmt and clippy check / Rustfmt and clippy check (push) Failing after 6s
CI / CI (stable) (push) Failing after 7s
license / Check License (push) Successful in 48s
fix(decode): build error contexts only when decoding fails
Every decode error context that formatted its message eagerly now goes
through netlink-packet-core 0.9.0's lazy `ErrorContext::with_context`
(src/error.rs:17, Result impl :51-60): the `.context(format!(..))`,
`.context({ format!(..) })`, `.context(err(payload))` and
`.context(nla_err!(..))` sites, 344 in 66 files. `nla_err!` in
tc/filters/flower/mpls.rs returns an owned String so the closure can
return it. Literal contexts are unchanged.

A link dump Debug-formatted the IFLA_MAP, IFLA_STATS, IFLA_STATS64 and
IFLA_INET6_* payloads of every link on the success path (10 formats per
link). On the same captured RTM_NEWLINK dumps a link now decodes in about
6 us instead of about 60 us on musl, and about 4 us instead of 22 us on
glibc. Decoded values and error texts are unchanged; tests pin the
truncated IFLA_MAP error text and the zero-extended short IFLA_STATS64.
2026-10-28 18:49:46 +00:00
2026-04-20 19:47:09 +08:00
2025-05-21 19:52:24 +08:00
2022-10-08 21:33:38 +08:00
2025-08-27 21:06:17 +08:00
2026-08-18 14:01:06 +08:00
2025-10-12 23:32:43 +08:00
2026-04-20 19:47:09 +08:00

Rust crate for Netlink Route Protocol

The netlink-packet-route crate is designed to abstract Netlink route protocol(rtnetlink) packet into Rust data types. The goal of this crate is saving netlink user from reading Kernel Netlink codes.

This crate grouped Netlink route protocol into these modules:

  • link: NIC interface, similar to ip link command.
  • address: IP address, similar to ip address command.
  • route: Route, similar to ip route command.
  • rule: Route rule, similar to ip rule command.
  • tc: Traffic control, similar to tc command.
  • neighbour: Neighbour, similar to ip neighbour command.
  • neighbour_table: Neighbour table, similar to ip ntable command.
  • nsid: Namespace, similar to ip netns command.

Normally, you should use rtnetlink instead of using this crate directly.

Development

  • Please use git commit --signoff to append Signed-off-by trailer to commit message.

  • For new source file, please append // SPDX-License-Identifier: MIT at the beginning with content of license new code to MIT license.

  • No panic is allowed, please use Result<> instead of unwrap() or expect().

  • Please run cargo fmt and cargo clippy before creating pull request.

  • All struct/enum should be decorated by #[non_exhaustive] to preserve API backwards compatibility unless explicit approval from maintainer.

  • Unknown netlink attribute should be stored into Other(DefaultNla) instead of breaking decoding.

  • Please use unit test case to cover the serialize and deserialize of the changed netlink attribute. To capture the netlink raw bytes, you may use tcpdump/wireshark again the nlmon interface. For example:

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
  • The integration test(play with linux kernel netlink interface) should be placed into rtnetlink crate. Current(netlink-packet-route) crate should only unit test case only.

  • For certain netlink message which cannot captured by nlmon, please use Rust Debug and explain every bits in comment.

  • Optionally, please run tools/test_cross_build.sh to make sure your code is compilable on other platforms.

S
Description
foss.global maintained netlink-packet-route with typed Linux NETCONF messages
Readme
1.9 MiB
0 Stars 3 Watchers 0 Forks
Languages
Rust 99.1%
Python 0.7%
Shell 0.2%