另外一个新的网络协议的Linux内核 [英] addition of a new network protocol in the linux kernel

查看:148
本文介绍了另外一个新的网络协议的Linux内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Linux内核中,我们可以在传输层,类似于TCP,UDP等添加我们自己的协议。

I know that in the linux kernel we can add our own protocol at the transport layer, similar to TCP, UDP etc.

是否有任何挂钩注册一个新的协议,在网络层,类似于IP,ARP,这可以在数据包传输到应用程序以及如何在Linux内核中添加这个协议?

Are there any hooks to register a new protocol, at the network layer, similar to IP, ARP, which could transfer the packets to the application and how to add this protocol in the linux kernel?

推荐答案

要处理来自用户空间通信您的协议,与内核注册协议的套接字API 。这使您可以创建用户空间的一个正常的插座。

To handle communication from userspace to your protocol, register your protocol with the kernel sockets API. This allows you to create a normal socket from userspace.

看一看蓝牙/ RFCOM套接字实现相关的 code样品的。

Have a look at the bluetooth/RFCOM socket implementation for relevant code samples.

static const struct proto_ops rfcomm_sock_ops = {
     .family         = PF_BLUETOOTH,
     .owner          = THIS_MODULE,
     .bind           = rfcomm_sock_bind,
     .connect        = rfcomm_sock_connect,
     .listen         = rfcomm_sock_listen,
     .
     .
     .
     .accept         = rfcomm_sock_accept,

};

static const struct net_proto_family rfcomm_sock_family_ops = {
     .family         = PF_BLUETOOTH,
     .owner          = THIS_MODULE,
     .create         = rfcomm_sock_create
};


要注册一个协议,你将不得不填补 proto_ops 结构。这种结构如下在内核中其他地方观察到的面向对象模式。这个结构定义一个接口,遵循开发者实现自己的套接字接口。


To register a protocol you will have to fill the proto_ops structure. This structure follows the object oriented pattern observed elsewhere inside the kernel. This structure defines an interface to follow for developers implementing their own socket interface.

实现的接口定义,如绑定的功能,连接,侦听,并分配函数指针结构条目。定义的ioctl对未涉及的操作界面功能。

Implement the functions the interface defines such as bind, connect, listen, and assign the function pointer to the structure entry. Define ioctl's for functionality not covered by the operations interface.

您结束了以后就嵌入在的插座结构我们从创建函数返回。

You end up with a structure that later you embed at the socket struct we return from the create function.

net_proto_family 定义了一个新的协议家庭。这种结构包括创建函数,其中你的函数实现应填充一个插座结构充满proto_ops结构。

Struct net_proto_family defines a new protocol family. This structure includes the create function where your function implementation should populate a socket struct filled with the proto_ops struct.

在此之后注册的家庭与 sock_register ,如果一切正常,你应该能够从用户空间创建一个合适的插座。

After that register the family with sock_register, and if everything is ok you should be able to create a proper socket from userspace.

在内部协议应该使用skbuffs 1 ,的 [2] ,<一个href=\"http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=2184DD93AFBBEB3666FE35A4690662E8?doi=10.1.1.81.7216&rep=rep1&type=pdf\"相对=nofollow> [3] (PDF)。与网络设备进行通信。

Internally the protocol should probably use skbuffs1,[2],[3](pdf). to communicate with the networking devices.

skbuffs是在Linux内核处理网络数据包的普遍的方式。数据包由网卡接收的,投入一些skbuffs,然后传递到网络堆栈,它使用的skbuff所有的时间。

skbuffs are the universal way of handling network packets in the linux kernel. The packets are received by the network card, put into some skbuffs and then passed to the network stack, which uses the skbuff all the time.

这是基本的数据结构和IO路径来实现Linux内核内部的网络协议。

This is the basic data structure and io path to implement a networking protocol inside the linux kernel.

我不知道,描述了从开始到完成这个程序文件。
源是您在这一个。

I am not aware of a document that describes this procedure from start to finish. The source is with you on this one.

这篇关于另外一个新的网络协议的Linux内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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