A
A
Alex Serov2016-11-24 14:15:17
linux
Alex Serov, 2016-11-24 14:15:17

How to safely replace the network interface operations table?

The network interface in Linux is represented by the structure:

struct net_device {
        ...
        const struct net_device_ops *netdev_ops;
        ...
};

I'm writing a kernel module that serves as a network packet filter.
How to safely swap this table (I'm afraid of the effects of concurrency).
Use rtnl_lock()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
theg4sh, 2016-12-01
@gibsonman01

Solve problems as they come. By the way, setting a semaphore does not guarantee access security in case of concurrency, but only reduces the probability of collisions to almost 0.
As far as I understand, the link to net_device_ops does not change often at all, so IMHO it will be enough:

struct net_device dev;
static struct net_device_ops overwrited_netdev_ops;
...
dev->netdev_ops = &overwrited_netdev_ops;

But now the operation functions themselves have their own semaphores, read:
https://www.kernel.org/doc/Documentation/networkin...
In pursuit, it is also worth reading the rtnetlink.c source
for a better understanding of the process:
lxr.free -electrons.com/source/net/core/rtnetlink.c

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question