[英]How kernel know which driver to be called when we are calling any socket from user-space?
I am using IWD as a wireless daemon in userspace.我将IWD用作用户空间中的无线守护程序。 Driver and firmware are loaded.
驱动程序和固件已加载。
When the socket is called by IWD using nl80211
, it passes to nl80211
and than cfg80211
in kernel space.当 IWD 使用
nl80211
调用套接字时,它会传递给nl80211
,然后传递给内核空间中的cfg80211
。 At kernel space how do they know which driver to call or pass requests to which driver?在内核空间,他们如何知道调用哪个驱动程序或将请求传递给哪个驱动程序?
Socket is created using this:使用以下方法创建套接字:
fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, NETLINK_GENERIC);
And this fd is used to pass requests to kernel space.而这个 fd 用于将请求传递给内核空间。
[edits] [编辑]
Similar concept of socket is used in this code: How to use netlink socket to communicate with a kernel module?这段代码中使用了类似的套接字概念: How to use netlink socket to communication with a kernel module?
It is using same socket creation and calling to communicate between userspace and kernel space.它使用相同的套接字创建和调用在用户空间和内核空间之间进行通信。
As explained by @stark in a comment:正如@stark 在评论中解释的那样:
You are using NETLINK_GENERIC protocol, so will call the Generic Netlink code.您正在使用 NETLINK_GENERIC 协议,因此将调用 Generic Netlink 代码。 The other question is using a user-written module that registers protocol 31. wiki.linuxfoundation.org/networking/generic_netlink_howto
另一个问题是使用注册协议 31 的用户编写的模块。wiki.linuxfoundation.org/networking/generic_netlink_howto
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.