出于学习目的,我正在开发一个名为 HTP 的新协议(protocol)(在传输层作为 UDP/TCP),并倾向于将其作为一个模块注册到 Linux 内核。
学习本教程 https://linuxwarrior.wordpress.com/2008/12/02/add-a-new-protocol-to-linux-kernel/
我在linux/sock.h头文件中插入了一条新记录:
#define AF_HTP 41 /* new HTP protocol family*/
#define AF_MAX 42 /* For now.. */
(原来只有41个协议(protocol),AF_MAX = 41)
在我的代码中,我做了:
static struct net_proto_family htp_proto_family = {
.family = AF_HTP,
.create = htp_create_socket,
.owner = THIS_MODULE,
};
...
//in init_module
proto_register_status = proto_register(&htp_proto, 1);
这是我在安装模块失败后通过 dmesg 得到的结果:
[ 594.098672] protocol 41 >= NPROTO(41)
我的问题: 遇到这种情况怎么办?我必须重新编译 Linux 内核还是有其他一些解决方法?
非常感谢。
最佳答案
此打印来自内核代码,而不是任何驱动程序。如您所见,41
是硬编码的……内核广泛使用此 const。
所以是的,为了使用"new"AF,您必须重新编译 Linux。
另一种选择是为您的协议(protocol)重用一些其他 AF_*
- 您的内核可能没有加载所有协议(protocol)。所以你可以选择一个未使用的“家庭”并使用它。它会起作用。
关于c - 错误协议(protocol) 41 >= NPROTO(41) 向 linux 内核添加新协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848716/