2

Is there a way to have a callback argument passed to the netlink receive function when running in kernel space? I have the following code to create the socket:

struct netlink_kernel_cfg net_cfg = 
{
    .input = netlink_rcv,
};

private_data->netlink_sock = netlink_kernel_create(&init_net, private_data->netlink_type_id, &net_cfg);

Which works fine, but after endless digging through the man pages I can't see a way to have an argument passed through to the callback handler, to provide state information for example or access to the module's private data.

For info (since the netlink API seems to have changed significantly over recent years), I am using Linux kernel 3.14.

Could somebody please point me to a code snippet or somewhere in the man pages which I may have missed?

trigger
  • 108
  • 7
  • I might be wrong, since I don't have your code. But this code snippet is in the same module right? you can have the global data structure and access the private data. Am I missing something? – Pramod Jun 02 '16 at 09:48
  • @Pramod: Thanks for your response. It can be done that way but it won't work if there are multiple instances of the module. The module I am working on is a device driver of which there are two instances, because it services two separate peripherals. I need to be able to access the module private data which is associated with a specific instance of the module; if I keep a reference to the private data as a local variable, the local will reference the private data of the instance whose .probe() function was called last. I guess I could have two globals, but I was hoping there was a better way... – trigger Jun 02 '16 at 14:10
  • "but it won't work if there are multiple instances of the module. The module I am working on is a device driver of which there are two instances, because it services two separate peripherals" ? ======================================================== There will be only one instance of device driver. you should handle different device based on their types/model. That is how it is usually done. Have a { if , else if } check based on type or device model. – Pramod Jun 06 '16 at 04:58

0 Answers0