jbaublitz / neli

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

NlRouter and responses as a multicast message #216

Closed DerZade closed 1 year ago

DerZade commented 1 year ago

We're currently experimenting with nl80211, which has some weird behavior, which makes it kind of hard to work with the NlRouter.

So nl80211 is (in my opinion) badly designed, as it uses multicast messages, where it should not imho. For example when sending a NL80211_CMD_CONNECT request to the kernel, you get an response (also with command NL80211_CMD_CONNECT), but as a multicast message (PID = 0). The same is true for some other commands as well.

This makes usage with the new NlRouter kinda shitty, because the router thinks it is a multicast message (because it sees PID=0) and therefore routes the message to the multicast receiver, instead of the receiver returned by the send call. Admittedly, this is not because of how neli is implemented (which is reasonable), but how suboptimally nl80211 was designed.

I looked at the neli code and found (at least as far as I can tell) that the router currently uses the PID to route to the correct receiver. Is there any way we could make this work maybe via CMD instead of PID? 🤔

jbaublitz commented 1 year ago

Hi @DerZade, I apologize for the delay. How would you suggest using CMD? One additional clarification that I wanted to understand is whether this is actually a multicast message or not. For example, my understanding is that multicast messages only are sent if you're subscribed to a multicast group, so is the socket in your example subscribed to any multicast groups? If not, we can absolutely try to have better heuristics for determining whether a message is a multicast message or not. I still haven't found a good way to infallibly determine that from the netlink header.

I appreciate you providing feedback. I've left the 0.7.0 release as a release candidate for now largely because I wanted people to test it and open issues before the final release. This is very helpful, so I'm happy to work with you to have it meet as many use cases as possible.

DerZade commented 1 year ago

One additional clarification that I wanted to understand is whether this is actually a multicast message or not. [...]

It is a message with PID and SEQ set to 0. I'm quite sure that I did not need to subscribe to a multicast group to receive the message if I sent the request myself, but I would have to try again to verify this.

Hi @DerZade, I apologize for the delay. How would you suggest using CMD?

Currently neli sets the PID of the request and then routes responses with the same PID to the receiver returned by send. For our use case with nl80211 it would be nice if that routing is not done because of the PID, but because of the command. So I would like to receive messages with the same command as I sent. Arguably this would only be a "good behavior" for usage with nl80211 and not any other netlink api, because it makes a lot of assumptions, i.e. that it is GenNL and not just plain NL.

For our use case we have now spawned an additional thread that receives all multicast messages and then forwards them to different listeners depending on the GenNL command of the message.

jbaublitz commented 1 year ago

@DerZade Sorry for the delay. Can you test #209 and see if it resolves your issue?

DerZade commented 1 year ago

Sorry for not replying sooner. I will try to get to it next week, but I can not promise anything 😅.