1

有一些内核变量(例如tcp_frto)可以通过使用类似sysctl net.ipv4.tcp_frtoor的命令从用户空间访问cat /proc/sys/net/ipv4/tcp_frto

它可以从 bash 命令行读取和轻松更改。但是我想从我正在编写的内核模块中更改它们。

如何从模块中读取和写入这些变量?

(Linux源代码用于sysctl_tcp_frto访问tcp.h文件中声明的这个变量。也许可以导出变量名然后可以被模块找到,但我不想更改源并再次编译它)。我正在尝试制作可加载内核模块(LKM),而无需每次都编译源代码。

4

1 回答 1

1

Unless a Linux kernel variable is made global (using EXPORT_SYMBOL or one of its variants) it cannot be read outside its scope.

As there is an alternate means to access tcp_frto using the procfs, you can use VFS functions to do the same from within a Linux kernel module as shown in these sample code snippets.

How this works and why it is generally NOT a good idea (unless except for debugging) is described in detail in this article.

于 2013-08-11T05:46:33.153 回答