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

发布于 2024-08-28 10:27:12 字数 852 浏览 14 评论 0原文

我之前已经发布过查询,我正在重复同样的事情,我想修改kernel2.6中内置的igmpv3(Linux),以便它从文件中读取一个值并适当地决定igmpv3数据包内的保留(res 1)值由主机发送。

我想对上述问题添加更多内容,说这更多的是从用户空间更改内核空间变量的一般问题。

对此,一位 ctuffli 的回应是:

从用户态程序的角度来看,您应该将驱动程序视为具有明确定义的接口的“黑匣子”,而不是具有要更改的变量的代码。使用这种心理模型,您应该考虑通过四种方式(即接口)向驱动程序传达控制信息:

  • 命令行选项。您可以将参数传递给内核模块,这些模块在初始化期间可用。
  • IOCTL。这是向驱动程序传递控制信息的传统方式,但这种机制使用起来比 sysfs 稍微麻烦一些。
  • proc 进程信息伪文件系统。 proc 在 /proc 目录中创建文件,用户态程序可以读取这些文件,有时也可以写入这些文件。过去,该接口也被用来与驱动程序通信。尽管 proc 看起来与 sysfs 类似,但较新的驱动程序 (Linux 2.6) 应使用 sysfs,因为 proc 的目的是报告进程的状态。
  • sysfs 是一个伪文件系统,用于导出有关驱动程序和设备的信息

根据您需要与驱动程序通信的时间(即初始化、运行时),您应该添加新的命令行选项或新的 sysfs 条目来更改驱动程序处理数据包中保留字段的值的方式。

感谢 Ctuffli 的回答。我对 sysfs 没有任何了解。您能提供更多详细信息吗?我想将 igmpv3 pkt 的保留值之一更改为 0 或 1 或 2。这是我唯一需要更改的内容。您能否为我提供有关此具体问题的更多详细信息?

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.

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:

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混浊又暗下来 2024-09-04 10:27:12

SO 答案中有对 sysfs (即 /sys/...)接口的描述

它具体描述了要添加到驱动程序中的内容,即:

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);

在驱动程序设置过程中:

device_create_file(dev, &dev_attr_version);

There is a description of the sysfs (that is, /sys/...) interface in this SO answer:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文