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
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:
<net/net_namespace.h>
should be included to access init_net
structure