-
Notifications
You must be signed in to change notification settings - Fork 21
feat(net): add netlink route support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Co-authored-by: 朝倉水希 <asakuramizu111@gmail.com>
Signed-off-by: Weikang Guo <guoweikang@kylinos.cn> Co-authored-by: Weikang Guo <guoweikang@kylinos.cn> Co-authored-by: zhangguoyu <zhangguoyu@kylinos.cn>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Netlink Route support to enable Linux applications to retrieve network interface and address information through the Netlink protocol. The implementation references Asterinas and DragonOS designs and is essential for adapting FastDDS and ROS 2 to Starry.
Key changes:
- Implements Netlink Route protocol with support for
ip link showandip addr showcommands - Adds comprehensive message parsing and attribute handling infrastructure
- Fixes filesystem open flag validation to conform to POSIX semantics
Reviewed changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/axnet/src/socket.rs | Adds Netlink socket variant and address type to socket infrastructure |
| modules/axnet/src/service.rs | Exposes device iterator for Netlink route queries |
| modules/axnet/src/netlink/table.rs | Implements bind table for managing Netlink socket bindings and multicast groups |
| modules/axnet/src/netlink/route/mod.rs | Implements route transport layer with send/recv operations |
| modules/axnet/src/netlink/route/message/segment/*.rs | Defines route message segment structures for links and addresses |
| modules/axnet/src/netlink/route/message/attr/*.rs | Implements attribute parsing for link and address information |
| modules/axnet/src/netlink/route/handle.rs | Handles GetLink and GetAddr requests with device filtering |
| modules/axnet/src/netlink/receiver.rs | Implements message queue and receiver for async message handling |
| modules/axnet/src/netlink/mod.rs | Main Netlink socket implementation with bind/connect/send/recv operations |
| modules/axnet/src/netlink/message/*.rs | Core message parsing infrastructure with segments and attributes |
| modules/axnet/src/netlink/addr.rs | Netlink socket addressing with port and multicast group support |
| modules/axnet/src/lib.rs | Adds device index counter and Netlink module integration |
| modules/axnet/src/device/*.rs | Extends device trait with type, flags, index, and IP information |
| modules/axnet/Cargo.toml | Adds dependencies for Netlink feature |
| modules/axfs/src/highlevel/file.rs | Refactors file open options validation to fix POSIX compliance |
| api/axfeat/Cargo.toml | Adds netlink feature flag |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| align_up(payload_len, NLMSG_ALIGN) - payload_len | ||
| } | ||
|
|
||
| fn lecacy_padding_len() -> usize { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'lecacy' to 'legacy'.
| fn lecacy_padding_len() -> usize { | |
| fn legacy_padding_len() -> usize { |
| const DEPRECATED = 0x20; | ||
| const TENTATIVE = 0x40; | ||
| const PERMANENT = 0x80; | ||
| const MANAGETEMPADDR = 0x100; | ||
| const NOPREFIXROUTE = 0x200; | ||
| const MCAUTOJOIN = 0x400; | ||
| const STABLE_PRIVACY = 0x800; |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent whitespace in flag definitions; use consistent spacing between flag name and value.
| const DEPRECATED = 0x20; | |
| const TENTATIVE = 0x40; | |
| const PERMANENT = 0x80; | |
| const MANAGETEMPADDR = 0x100; | |
| const NOPREFIXROUTE = 0x200; | |
| const MCAUTOJOIN = 0x400; | |
| const STABLE_PRIVACY = 0x800; | |
| const DEPRECATED = 0x20; | |
| const TENTATIVE = 0x40; | |
| const PERMANENT = 0x80; | |
| const MANAGETEMPADDR = 0x100; | |
| const NOPREFIXROUTE = 0x200; | |
| const MCAUTOJOIN = 0x400; | |
| const STABLE_PRIVACY = 0x800; |
| }, | ||
| }; | ||
|
|
||
| /// An helper function to access the route protocol bind table. |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected grammar: 'An helper' should be 'A helper'.
| /// An helper function to access the route protocol bind table. | |
| /// A helper function to access the route protocol bind table. |
| self.index | ||
| } | ||
|
|
||
| fn ipv4_addr(&self) -> Option<Ipv4Addr> { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type uses Ipv4Addr from std::net, but Device trait definition shows Option<Ipv4Address> from smoltcp. The trait definition should use the stdlib type for consistency, or this implementation should match the trait's smoltcp type.
| self.index | ||
| } | ||
|
|
||
| fn ipv4_addr(&self) -> Option<Ipv4Address> { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type uses Ipv4Address from smoltcp, which is inconsistent with loopback device's use of Ipv4Addr from std::net. Both implementations should use the same type for consistency.
| /// Reference: <https://elixir.bootlin.com/linux/v6.13/source/include/uapi/linux/netlink.h#L86>. | ||
| pub struct AckFlags: u16 { | ||
| const CAPPED = 0x100; | ||
| const ACK_TLVS = 0x100; |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two different flags have the same value 0x100. This appears to be a copy-paste error - these flags should have distinct values.
| const ACK_TLVS = 0x100; | |
| const ACK_TLVS = 0x200; |
This PR introduces support for Netlink Route, referencing the implementations of Asterinas and DragonOS.
Some Linux apps rely on simple Netlink mechanisms to retrieve link or address information. This support is crucial for adapting FastDDS and ROS 2 to Starry.
Now, Starry can run ip link show and ip addr show normally:
Dependencies:
This PR is based on the API from the axio PR: https://github.com/Starry-OS/axio/pull/1. Considering that axio is currently being refactored, I am opening this as a Draft. I will mark it as ready for review once the refactoring is completed.
Additional Fix (FS):
The original function is_valid checked file open flags based on std::fs::OpenOptions, which does not conform to POSIX semantics (e.g., it was unable to create read-only files), leading to failures in some programs.
I have renamed is_valid to check_options to perform simple flag checks. More comprehensive checks may need to be added later, referencing https://man7.org/linux/man-pages/man2/open.2.html.