Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to communicate between two linux kernel module via netlink?

As all know, netlink it's user/kernel space communication mechanism.

I want to communicate from my kernel module to an another. Another kernel module already has the netlink interface.

Is it possible to make connection from kernel module to netlink, as we do it in user space?

like image 623
AlexeyPerevalov Avatar asked Jun 13 '12 12:06

AlexeyPerevalov


People also ask

What is Netlink used for?

Netlink is used to transfer information between the kernel and user-space processes. It consists of a standard sockets-based interface for user space processes and an internal kernel API for kernel modules.

How do you make a netlink socket?

In user space, we call socket() to create a netlink socket, but in kernel space, we call the following API: struct sock * netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len)); The parameter unit is, in fact, the netlink protocol type, such as NETLINK_TEST.

What is generic Netlink?

Generic netlink was designed to allow kernel modules to easily communicate with userspace applications using netlink. Instead of creating a new top level netlink family for each module, generic netlink provides a simplified interface to enable modules to plug into the generic netlink bus.


1 Answers

Short answer: No.

If you want to communicate between two kernel modules you should use symbols (global variables or functions) which are exported by the other kernel module.

netlink Sockets are used to communicate between kernel and userland. AFAIR there is no way to use netlink (at least it is not the preferred way) to communicate within the kernel.

example for exporting a symbol:

module1.c:

  int foo(int a)
  {
      /* do some stuff here */
  }
  EXPORT_SYMBOL(foo);

module2.c

  extern int foo(int);
  int bla(int b)
  {
      /* call foo(a) */
      int ret = foo(b);
  }
like image 141
dwalter Avatar answered Sep 22 '22 20:09

dwalter