1

I'm experimenting with network drivers in a qemu VM running Ubuntu 16.04.1. uname -r gives 4.4.0-31-generic as the kernel version.

In linux/netdevice.h for that kernel version, I found the comment

"@netdev_ops: Includes several pointers to callbacks, if one wants to override the ndo_*() functions"

However, in my code, an assignment such as dev->netdev_ops->ndo_open = netmod_open (where netmod_open is the open method in my own driver) gives the compiler error:

assignment of member 'ndo_open' in read-only object

Further, netdev_ops is declared as const in the source:

const struct net_device_ops *netdev_ops;

How can I "override the ndo_*() functions" if the struct containing their pointers is const?

1
  • It looks like I need to create my own struct net_device_ops and then assign dev->netdev_ops the address of that struct. So in general I need to learn more about how data structures are passed around in the kernel. Any links to such info would be appreciated. It seems like most of the tutorials I find have outdated kernel APIs. Commented Dec 21, 2016 at 3:11

1 Answer 1

2

How can I "override the ndo_*() functions"

Define your own variable of type struct net_device_ops, setup its fields(hooks actually) which you want to override, and assign this variable to dev->netdev_ops.

Note, that according to description for struct net_device_ops, the only field .ndo_start_xmit is required to be set, other fields you may leave non-initialized (that is NULL).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.