jbaublitz / neli

Rust type safe netlink library
BSD 3-Clause "New" or "Revised" License
180 stars 35 forks source link

Linux SocketCAN structs and constants (attempt #2) #206

Open fpagliughi opened 1 year ago

fpagliughi commented 1 year ago

Big apologies for dropping the ball on #140 a while back. Work on the socketcan crate stalled while the project maintainership was being ironed out, but now a lot of progress is being made and one of the last major aspects to be added for the upcoming release is Netlink access to query and update the CANbus network interfaces.

It appears that most of what we need added is contained in the can/netlink.h header as can be seen here: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/can/netlink.h

It doesn't look too crazy; a few constants, bitflags, and structs. The things I'm still uncertain about is which parts of it might go here in the neli crate, which in libc, and what is best to just drop into the socketcan crate.

Any guidance would be appreciated.

fpagliughi commented 1 year ago

BTW... we've been discussing this work here: https://github.com/socketcan-rs/socketcan-rs/issues/32

jbaublitz commented 1 year ago

Hi @fpagliughi! So what I'd recommend is first creating a PR against libc with all of the constants that you want added. Once you've done that and it's been merged and released in a new version, let me know which constants you want added to neli and the version of libc that contains them. From there, I'll put up a PR and put out a new version with those included. Sound good?

fpagliughi commented 1 year ago

Thanks, @jbaublitz. What do you think about wrappers for the structs in that C header, like:

struct can_bittiming {
    __u32 bitrate;       /* Bit-rate in bits/second */
    __u32 sample_point;  /* Sample point in one-tenth of a percent */
    ...
};

Where should that stuff live? (i.e. the config info that goes across the NetLink connection)

jbaublitz commented 1 year ago

Those could go into libc too, but I would likely add those separately as Rust structs in neli. That's what I've done for other similar structs. You could also define them in your own library and use the derive implementations to autogenerate serialization and deserialization for them if you want to maintain control over them.

jbaublitz commented 1 year ago

Hi @fpagliughi, any way I can help with this? Or is this kind of a background task?

fpagliughi commented 11 months ago

Hey @jbaublitz. I was having trouble figuring out how to integrate a few things, and assumed I needed to get them in here to work. But I eventually found #[neli_enum(...)] and some related items, and was able to get everything working together from my crate. I put out a new release a few weeks back. (Really nice job on your end making it so easy).

But now I do have a submodule of structs and consts here that really should be pushed upstream to libc and neli. I have to circle through a couple of other open-source projects that need to get out, then I will get back to this. Hopefully in a few weeks.