jbaublitz / neli

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

How to Specify an Empty Nlattr Payload? #242

Closed a-gavin closed 4 months ago

a-gavin commented 4 months ago

I am currently looking for a way to pass empty data in a Nlattr payload, but I'm stumped and likely running into my limits of Rust knowledge.

Below is a packet capture on a Netlink monitor interface comparing the NL80211_CMD_GET_WIPHY command of iw phy0 info with that of example neli code in this gist (using neli v0.7.0-rc2). On the left is iw command netlink command with the empty NL80211_ATTR_SPLIT_WIPHY_DUMP attribute. On the right is the non-empty attribute as generated by the neli example code I linked.

For others looking to do the same, the command I run the following commands to create and up a Netlink monitor interface nlmon0 on Linux:

# This interface will be removed on shutdown
$ sudo modprobe nlmon
$ sudo ip link add dev nlmon0 type nlmon
$ sudo ip link set up dev nlmon0

I'd be happy to contribute this to the nl80211.rs example, including more interesting NL80211_CMD_GET_WIPHY output, once I figure out how to do so as it's a task I'm already working on.

Empty Attr Value Non-empty Attr Value
image image
jbaublitz commented 4 months ago

Hi @a-gavin, I think the best way to handle the fact that the payload field is required in NlAttr is to pass in the empty type (()) as the payload. This will result in an empty payload.

a-gavin commented 4 months ago

Why didn't I think of that? haha. I'll give that a try. Thanks!

jbaublitz commented 4 months ago

Sure thing! Closing, but feel free to comment if that doesn't resolve your issue.

a-gavin commented 4 months ago

This fixed my issue. Thanks for the quick help!