I'm looking at the implementation of sysctl in the kernel, and I've found that doing a sysctl is just the same as writing a value to a file in the /proc filesystem.
In your case you just want to do the equivalent of:
echo 0 >/proc/sys/net/ipv4/conf/all/rp_filter
Here is a rough code sample, based on what I see in the kernel code I am reading just now:
struct vfsmount *mnt;
struct file *file;
ssize_t result;
char *pathname = "sys/net/ipv4/conf/all/rp_filter";
int flags = O_WRONLY;
mnt = task_active_pid_ns(current)->proc_mnt;
file = file_open_root(mnt->mnt_root, mnt, pathname, flags);
result = PTR_ERR(file);
if (IS_ERR(file)) {
// oops, something bad happened
} else {
char *buffer = "\0";
result = kernel_write(file, buffer, 1, 0); // last 2 args are 'count' and 'pos'
if (result < 0) {
// oops, something else bad happened
}
}
fput(file);
This is just a rough sample, so you will have to do your own research and testing to get it working. Good luck!
net/ipv4/devinet.c? - stdcall