Add support for FIB rule messages#310
Conversation
|
Hi @alexsikomas, thanks for the contribution. Can you provide more information on where these constants are defined? |
|
Hi, the definitions for these constants can be found here: include/uapi/linux/fib_rules.h |
|
@alexsikomas Thanks for providing the link to the constants. I wanted to check if it's covered in linux-sys-raw. It appears that it is not currently. If you could submit a PR to linux-sys-raw or libc to have the constants automatically generated from there, I would be willing to accept this PR. As it stands, hardcoding constants often causes breakage, so I'd prefer to have it generated from C headers by another crate. |
|
Sounds good, @jbaublitz I'll make a PR to libc. |
|
@alexsikomas Just be aware that if libc doesn't want to add it, linux-raw-sys may be willing to. There have been some constants that libc has avoided adding related to netlink. |
|
I've changed the hardcoded constants to rely on |
jbaublitz
left a comment
There was a problem hiding this comment.
Just one request and then I'll merge this. Also please rebase onto the current branch.
src/consts/rtnl.rs
Outdated
| @@ -1,3 +1,4 @@ | |||
| use linux_raw_sys::netlink::*; | |||
There was a problem hiding this comment.
For this file, I think it would be better to use the namespace in the path for the constants to avoid collisions as we're ultimately using two separate libraries now to supply constants.
Introduced linux-raw-sys to pull constants for supporting FIB rules. Added relavant constants and structures from the Linux UAPI. Added an example fwmark.
|
I've made the requested changes, removing the wildcard import, and rebased onto the current branch. |
jbaublitz
left a comment
There was a problem hiding this comment.
@alexsikomas I've fully reviewed the code and it all looks good and consistent with the style of neli. Thanks for that! The one concern is that I can't find the definition of fibmsg anywhere in the kernel or kernel headers based on a search. Can you link me to the place you're seeing this data structure defined?
|
Okay I found the definition. The naming was a little bit off so it was not easy to immediately find but I believe this is fine. I'm going to merge this now, but if you can follow up and explain your usage of libc::u_char instead of u8 as it is specified in the definition, that would be helpful. If I don't hear from you, I may change the type, but based on the C spec, they're equivalent anyway so it shouldn't be a problem. |
|
You're right, |
This PR adds support for managing the routing policy database through FIB rule messages, enabling the creation, deletion, and querying of ip rules.
Changes:
Fibmsgstruct: A message struct that corresponds to thefib_rule_hdrin the Linux kernel.Frattrenum: Netlink attributes for a FIB rule.FrActenum: Possible actions for a FIB rule.Frfflags: Possible flags associated with a FIB rulefwmark.rsexample: An example is included to demonstrate how to create and delete a firewall mark-based routing rule. It shows how to build aFibmsg, send it to the kernel, handle the acknowledgment, and then send a corresponding delete request.The new functionality can be tested by running the example:
# Requires network capabilities or root privileges sudo cargo run --example fwmarkor
When run, the example will:
[PRIORITY]: not from all fwmark 0xca6c lookup 246813579You can comment out the deletion part in examples/fwmark.rs and verify the rule's creation with
ip rule show.