是否可以通过netlink在两个Linux内核模块之间进行通信? [英] Is it possible to communicate between two linux kernel module via netlink?

查看:331
本文介绍了是否可以通过netlink在两个Linux内核模块之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,netlink是用户/内核空间通信机制.

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

我想从内核模块与另一个模块通信.另一个内核模块已经具有netlink接口.

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

是否有可能像我们在用户空间中那样建立从内核模块到netlink的连接?

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

推荐答案

简短答案:否.

如果要在两个内核模块之间进行通信,则应使用由另一个内核模块导出的符号(全局变量或函数).

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套接字用于内核和用户态之间的通信. AFAIR无法使用netlink(至少不是首选方法)在内核内进行通信.

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.

导出符号的示例:

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);
  }

这篇关于是否可以通过netlink在两个Linux内核模块之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆