简体   繁体   English

用户空间到内核空间和sysfs,以及如何使用sysfs更改igmpv3 pkt中的一个保留值

[英]userspace to kernel space and sysfs and how to use sysfs to change one reserved value in igmpv3 pkt

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 packet which is sent by a host. 我以前发布过查询,我重复同样的操作,我想修改kernel2.6中内置的igmpv3(Linux)。-这样它就可以从文件中读取一个值并适当地确定igmpv3数据包内的reserved(res 1)值由主机发送。

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. 我想在上面的问题中添加更多内容,这是一个更常见的问题,即从用户空间更改内核空间的变量。

To that one ctuffli has replied: 对此ctuffli回答:

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 (ie 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. IOCTL。 This is the traditional way of passing control information to a driver, but this mechanism is a little more cumbersome to use than sysfs. 这是将控制信息传递给驱动程序的传统方式,但是使用这种机制比sysfs更为麻烦。
  • proc the process information pseudo-file system. proc处理信息伪文件系统。 proc creates files in the /proc directory which user land programs can read and sometimes write. proc在/ proc目录中创建文件,用户登陆程序可以读取和写入文件。 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. 尽管proc看上去与sysfs类似,但是较新的驱动程序(Linux 2.6)应该使用sysfs代替,因为proc的目的是报告进程状态。
  • sysfs is a pseudo-file system used to export information about drivers and devices sysfs是一个伪文件系统,用于导出有关驱动程序和设备的信息

Depending on when you need to communicate with the driver (ie 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. 根据需要与驱动程序进行通信的时间(即初始化,运行时间),应添加新的命令行选项或新的sysfs条目,以更改驱动程序对待数据包中保留字段的值的方式。

Thanks Ctuffli for your answer. 感谢Ctuffli的回答。 I do not have any knowledge of sysfs. 我对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. 我想将igmpv3 pkt的保留值之一更改为0或1或2。这是我唯一需要更改的内容。 Could you please give me more details for this specific problem? 您能给我更多有关此特定问题的详细信息吗?

There is a description of the sysfs (that is, /sys/...) interface in this SO answer : 在此SO答案中有sysfs (即/ sys / ...)接口的说明:

It specifically describes what to add to the driver, namely: 它专门描述了要添加到驱动程序的内容,即:

static ssize_t mydrvr_version_show(struct device *dev,
        struct device_attribute *attr, char *buf)
{
    return sprintf(buf, "%s\n", DRIVER_RELEASE);
}

static DEVICE_ATTR(version, S_IRUGO, mydrvr_version_show, NULL);

And during driver setup: 在驱动程序安装过程中:

device_create_file(dev, &dev_attr_version);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM