Question

Up until now, I've used Genetlink to enable users to send my module some basic commands, with no parameters needed. Times have changed and I need to enable the users to add some more data to the message. Specifically, I need them to be able to send arrays of char, int and enum values.

Where can I add the needed data to the message?

The examples I've seen so far (like this one) were more simple and didn't help.

I see that GENL operations define the callback as follows:

int (*doit)(struct sk_buff *skb, struct genl_info *info);

but I couldn't find any example that uses the sk_buff, only the the genl_info. Could this be what I'm looking for?

Was it helpful?

Solution

This might not be the best answer you are looking for, but here goes. I've done a bit with netlink sockets, but I'm not sure if what I know holds true for "Genetlink." Anyway, I think you should find that skb->data should be where you put your data. (That's what sockets are for. To be honest, I'm not sure how you can communicate anything without it.)

As for sending arbitrary amounts of data as well as different types of data, I find it best to use structs that the module and user space application agree on.

For example, I use something like this:

struct IntArrayMessage  {
  u_int32_t message_type;
  u_int32_t length;
  // Buffer data goes at the end
};

The "message_type" is basically an enum that tells the receiving program that it is a "IntArrayMessage" and to cast the data to an "IntArrayMessage". Once it is cast, you can read the length to know how much more to read from the socket. Those values that you read are the int array.

Obviously, you have to make sure to send the extra info from the other end.

Anyway, hope this helps, better than no answer at all.

Again, I'm not familiar with "Genetlink", but if this helps, then good.

Also, here's a complete example of sending "hello" using netlink. example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top