Welcome! Log In Create A New Profile

Advanced

struct net_device and net_device_ops

Posted by pedr0 
struct net_device and net_device_ops
May 25, 2012 04:16AM
Hi all,

I would like add a new operation at the struct net_device_ops but I am a really newbye in this type of things and I am a bit worried to follow a wrong way from the begin.

I added a ops like this:

static const struct net_device_ops wl_netdev_ops =
{
/* The other operations..
.ndo_clear_stats = clear_stats
};

What is not clear from my point of view is how I can call from user space that, I usually take statisincs from

/sys/class/net/.../statistics
But now I really don't understand where my new operation is placed, can someone help me telling a good tutorial or link where I can find a simple example or tutorial ?

Thanks in advance, pedr0
Re: struct net_device and net_device_ops
May 25, 2012 04:46AM
He Pedr0,
I think you are getting a bit confused here. There are three separate concepts that you seem to be mixing in to one.
1) The net_device_ops structure is a kernel structure used to interface network device drivers to the kernel. It's an interface. The kernel knows about what's in the structure and knows how and when to call each function on a given device.
2) The device driver for a particular hardware vendor also knows about this structure and populates it with functions to be called by the kernel.
3) Userspace operates on network devices via the socket interface and setting socket options.


To do what you want, you're going to have to do the following:
1) Create a new socket option in the kernel. Have a look at net/core/sock.c in sock_setsockopt() (line 480 in 2.6.35.13) I'm no expert, but this is a good place to start
2) Modify the net_device_ops structure as you propose and tie you new sock opt into that structure
3) Modify the specific device driver that you are using on your hardware to support the new option.
4) Compile, rebuild, reinstall, hope and pray.


There is probably a faster an more hacky way to do what you want.
1) Create a character device interface to your specific driver that runs on your specific hardware.
2) Add a "write" function to the character device.
3) When write is called, reset the stats.

Job done. This is not standard/best practice, but it will get the job done a lot faster.

Have a look at: [lwn.net] for an example of adding a character interface. Also take a look at [www.cs.fsu.edu] for some example source code.
Re: struct net_device and net_device_ops
May 25, 2012 06:38AM
Hi mgrosvenor ,

I solved my probleam discovering an other, completeley different, way to do what I want, it is strictly related at how device driver is implemented and what I did for my purpose is really simple.
Anyway I read carefully your post and I am going to read and do the sample/explanation you sent me, especially lwn.net.

Thank you very much.

pedr0
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 13 plus 18?
Message: