Linux中tcp/ip协议栈如何获取net_device接口
我正在阅读网络设备驱动程序代码。我的驱动程序遵循驱动程序模型。参考:kernel/Documentation/driver-model。 读取interface.txt: { 设备接口是关联设备类的逻辑接口 直接连接到用户空间接口,例如设备节点。 每个接口在设备的目录中都有一个目录 它所属的类。 )
还没有能够确定确切的接口。所以在查看了 struct net_device 和 interface.txt 文件中的编程接口之后(kernel./Documentation/driver-model 我再次得出结论,就是这些人所说的net_device。 现在我想知道的是 TCP/IP 堆栈的物理层,链路层是网络驱动程序。我想将网络驱动程序提供的接口提供给我的 tcp/ip 堆栈。问题是如何?如何将 net_device 结构提供给 TCP/ip 堆栈。有谁知道这件事吗。 问候 斯拉达
。
I was reading through the network device driver code.My driver follows the driver-model.REF:kernel/Documentation/driver-model.
Reading through the interface.txt:
{
Device interfaces are the logical interfaces of device classes that correlate
directly to userspace interfaces, like device nodes.
Each interface is given a directory in the directory of the device
class it belongs to.
}
Havent been able to pinpoint the exact interface yet.So after going through the struct net_device and the Programming interface in the interface.txt file (kernel./Documentation/driver-model)
I again come to the conclusion that its the net_device these people are talking about.
Now what I want to know is the TCP/IP stack the physical and the link layer is the network driver.I want to give the interface my network driver provides to my tcp/ip stack.Question is How ? How can I give the net_device struct to the TCP/ip stack. Does anyone know about this.
Regards
Sraddha
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
层次结构如下
struct inet_protosw(互联网协议)有一个指向 struct 成员 proto(协议)的指针
struct sock 有一个指向 struct 成员 proto(协议)的指针
struct sock 有一个指向 struct 成员 sk_buff_head 的指针
struct sk_buff_head 有两个指向sk_buff 的结构成员(一个称为 next,一个称为 prev)
struct sk_buff 有一个指向结构成员 net_device 的指针。
我不相信你直接向 inet_protosw 注册 net_device 。
首先
inet_init
通过调用proto_register
注册内置网络协议,然后调用inet_register_protosw
初始化协议,然后初始化各个inet模块( IP、TCP、ICMP 等)。负责链接协议和设备的接口有
register_netdevice
和unregister_netdevice
,它们的作用就像听起来一样,向内核注册和取消注册网络设备。要通过设备从协议发送数据包,请使用dev_queue_xmit
和netif_rx
接收从设备层传递到网络层的数据包,然后调用netif_rx_schedule
code> 安排数据包进行进一步处理。有关组织/工作流程的资源和文档包括:
The hierarchy is as follows
struct inet_protosw (internet protocols) has a pointer to a struct member proto (protocol)
struct sock has a pointer to a struct member proto (protocol)
struct sock has member to a struct member sk_buff_head
struct sk_buff_head has two pointer to struct members to sk_buff (one called next, one called prev)
struct sk_buff has a pointer to struct member net_device.
I don't believe you register the net_device with inet_protosw directly.
First
inet_init
registers the built in network protocols by callingproto_register
, then it callsinet_register_protosw
to initialise the protocols, then it initialises the various inet modules (ip,tcp,icmp,etc).The interface responsible with linking the protocols and the device later has the
register_netdevice
andunregister_netdevice
, which do what the sound like and register and unregister network devices with kernel. To send a packet from a protocol through a device usedev_queue_xmit
andnetif_rx
receives a packet passes from the device layer to the network layer, it then callsnetif_rx_schedule
to schedule the packet for further processing.Resources and documentation on the organisation / workflow include: