Zia
Zia

Reputation: 23

Changing kernel variables/parameters from a kernel module

There are some kernel variables(for example tcp_frto) which can be accessible from the user space by using the commands like sysctl net.ipv4.tcp_frto or cat /proc/sys/net/ipv4/tcp_frto.

It can be read and easily changed from bash command line. But I want to change them from the kernel module that I am writing.

How can I read and write into these variables from the module?

(Linux source code uses sysctl_tcp_frto to access this variable which was declared in the tcp.h file. Maybe possible to EXPORT the varible name and then can be found by modules, but I don't want to change the source and compile it again). I am trying to make a Loadable Kernel Module (LKM) without compiling the source every time.

Upvotes: 1

Views: 1237

Answers (1)

TheCodeArtist
TheCodeArtist

Reputation: 22507

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.

Upvotes: 1

Related Questions