views:

98

answers:

3

i,

I have posted query previously and i am repeating same I want to modify igmpv3 (Linux) which is inbuilt in kernel2.6.-- such that it reads a value from a file and appropriately decides reserved(res 1) value inside the igmpv3 paket which is sent by a host.

I want to add more to above question by saying that this is more a generic question of changing variable of kernel space from user space.

Thanks in advance for your help.

Regards,

Bhavin

+1  A: 

You normally can't. Only structures exposed in /proc and /sys or via a module parameter can be modified from userspace.

Ignacio Vazquez-Abrams
what if we use filp_open, get_fs() and set_fs() in the igmpv3 file of kernel and compile the linux.
bhavin
+2  A: 

From the perspective of a user land program, you should think of the driver as a "black box" with well defined interfaces instead of code with variables you want to change. Using this mental model, there are four ways (i.e. interfaces) to communicate control information to the driver that you should consider:

  • Command line options. You can pass parameters to a kernel module which are available to it during initialization.
  • IOCTLs. This is the traditional way of passing control information to a driver, but this mechanism is a little more cumbersome to use than sysfs.
  • proc the process information pseudo-file system. proc creates files in the /proc directory which user land programs can read and sometimes write. In the past, this interface was appropriated to also communicate with drivers. Although proc looks similarly to sysfs, newer drivers (Linux 2.6) should use sysfs instead as the intent of the proc is to report on the status of processes.
  • sysfs is a pseudo-file system used to export information about drivers and devices. See the documentation in the kernel (Documentation/filesystems/sysfs.txt) for more details and code samples. For your particular case, pay attention to the "store" method.

Depending on when you need to communicate with the driver (i.e. initialization, run time), you should add either a new command line option or a new sysfs entry to change how the driver treats the value of reserved fields in the packet.

With regard to filp_open, the function's comment is

/**
 * This is the helper to open a file from kernelspace if you really
 * have to.  But in generally you should not do this, so please move
 * along, nothing to see here..
 */

meaning there are better ways than this to do what you want. Also see this SO question for more information on why drivers generally should not open files.

ctuffli
A: 

Thanks Ctuffli for your answer. I do not have any knowledge of sysfs. Can you provide more details abt it? I want to change one of the reserve value of igmpv3 pkt to be either 0 or 1 or 2. This the only thing which i need to change. Could you please give me more details for this specific problem?

bhavin