[lkml]   [2005]   [Dec]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectPreferred method to export info to userspace
Hello everybody:

I am writing a module for analyzing packets in kernel space. In SMP
systems, the module creates as many kernel threads as CPUs, each bound
to a processor. When a new packet arrives, if it comes from the
capture interface, it is enqueued in a global skb queue (this is done
from netif_receive_skb()). The kernel threads will thereafter get the
packets from that queue and analyze them.

To test the module, as well as to gain some flexibility in its working
mode, the module has to communicate with user space. Configuration
options are:

* Turn ON/OFF the packet capturing, as well as change the way it captures them
[I do this with a "flags" variable, which is changed from userspace
via ioctl]
* Change some configuration parameters: maximum length of the skb queue,
capture interface i.e. eth0
[I do this via read-write /proc files]
* Export statistics to userspace
[I do this via a read-only /proc file]

This all works, but I would like to code it more ellegantly. I've been
reading some kernel code, and people use to do this kind of things in
different ways. For example, in the packet generator module (pktgen),
it uses some /proc files for all the configuration, for example, to
set/clear a flag:

set a flag: echo "flag IPDST_RND" > /proc/net/pktgen/eth1
clear a flag: echo "flag !IPDST_RND" > /proc/net/pktgen/eth1

In contrast, in dev_ioctl() (net/core/dev.c), flags are set or cleared
via two ioctl commands (set: SIOCSIFFLAGS, get: SIOCGIFFLAGS).

If this weren't enough, it seems that there is a new filesystem for
exporting information to userspace: sysfs. This is similar to /proc
but with more constraints.
I mean, each file (attribute) should contain just one value. In my
module I export quite a lot information just calling

$ cat /proc/ksensor/stats:
iface: eth1
captured: 18233
processed: 3334
dropped: 15003
errors: 34
cur_queue_len: 56
max_queue_len: 1024

So, I would have to create as many files as values I want to export in
sysfs? that would be quite a lot files, no?

And the last question, how should I configure the "flags" variable I
told before? Currently, I have three flags:

KSF_UP: whether the capture device is running or not
KSF_CONCTRL: whether it is used congestion control for incoming packets
KSF_TRANSP: whether it is made a copy of the packet so that the kernel
can continue processing the packet later (if not, the packet is
captured, analyzed and dropped).

Possible options are:

* I do this with a ioctl command for setting the flags and another one
for getting them.
* Another possibility would be to create as many files as flags in
/proc/ksensor and echo 1 to turn it on or echo 0 to turn it off.
* Another more possibility would be to use a command as I told before
what is done with pktgen module.
* And the last one, would be to do this in sysfs.

Which option do you think is better? I would thank any replies, or
ideas to these questions.

Aritz Bastida
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-12-08 15:30    [W:0.032 / U:22.744 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site