Hi - I am looking to port an LKM over to Rust and it's been difficult getting started. What the LKM does is create a new address families at the application and transport layer.
What I'm looking for are examples to help me move along with the same in Rust. When I created this project as LKM's in C, I just used everything under the net directory as examples. Meanwhile, I'm still trying to work out the details in getting a basic skeleton working in Rust, but I'll eventually get past that.
Can anyone offer suggestions for examples that create new protocol families?
Have you looked at https://rust-for-linux.com/
Show us your C and maybe we can help make it rust..
To start with, I'm looking for the equivalent of these C structs and functions for which I would use to create a new address family protocol.
struct net_proto_family;
struct proto_ops;
// Add a socket protocol handler
err = sock_register(&proto_family);
When I search for something, I go to the kernel crate page at kernel - Rust and performe a search there. I hope that's the correct way to look something up. I've found none of these.
the goal of the r4l project is NOT to rewrite existing subsystems or drivers in rust. the rust apis are created mostly when there's real needs. for example, many device drivers would benefit from safer apis in rust for the usb subsystem, so the usb subsysem is relative higher in priority to bring rust support.
abstractions are not available for all the kernel internal APIs and concepts, but it is intended that coverage is expanded as time goes on.
the lack of proper apis for the net subsystem could mean there's not enough interest, or it could also mean there's simply not enough expertise for this field. I don't know.
nevertheless, you can use the same C apis if you still want to write your module in rust, but you'll have to update the generated bindings yourself. it's in the rust/bindings/bindings_helper.h file, just insert the header files you need and rebuild, bindgen will be run and the bindings crate will be updated automatically.
there's no rustdoc generated for the bindings crate, since these are just declarations for the same types and functions in the C headers.
note, using the raw C bindings directly in a "leaf" module is not the intended way to consume them. instead, you should build a (as safe as possible) rust abstraction layer on top of them.
there's also a section on submitting new rust abstractions in the contributing page, if you are interested to upstream your work: