How to edit proc file?
-
21-06-2021 - |
Pregunta
I want to edit the value of a proc file /proc/sys/net/ipv6/route/gc_interval in the middle of a running kernel. I want to edit the value of this proc file value relative to another value.
According to the lifetime value of function ndisc_router_discovery in file net/ipv6/ndisc.c, I want to toggle the value of gc_intervel between 1 and 30. I searched in google but I can find only creating a new proc entry. But this file is already existing. Kindly tell me how to alter the value of this file on fly.
Edit: I want to do this by editing the kernel code. I want some extra piece of code added to ndisc.c, that changes the gc_interval value according to the lifetime
Solución
The proc entry sys/net/ipv6/route/gc_interval
is defined in net/ipv6/route.c
:
{
.procname = "gc_interval",
.data = &init_net.ipv6.sysctl.ip6_rt_gc_interval,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
}
So the gc_interval
file is a user-land representation of the integer variable init_net.ipv6.sysctl.ip6_rt_gc_interval
with a jiffies-to-seconds conversion (the variable is stored in jiffies while the proc entry handle the value in seconds)
If you need to programmatically alter that value in the kernel, you only need to alter that variable:
...
init_net.ipv6.sysctl.ip6_rt_gc_interval = new_gc_interval_sec * HZ;
...
Notes:
- the kernel references are based on Linux 3.4.5 sources
<net/net_namespace.h>
should be included to accessinit_net
structure
Otros consejos
use sysctl command sudo sysctl -w net.ipv6.route.gc_interval=20
If you want to make this value permenant append net.ipv6.route.gc_interval=20
to /etc/sysctl.conf
file
Or just:
echo 20 > /proc/sys/net/ipv6/route/gc_interval
/etc/sysctl.conf allow do that's at the start up of the system.