vikas
vikas

Reputation: 1021

Is it possible to modify interface index

If the kernel decides to change the interface index for some reason, our userspace code cached interface index does not gets updated and it starts dropping the packet because their is mismatch between interface index cached in userspace and what is actually present in kernel.

I've used if_indextoname(index, interfaceName) to solve this problem. Basically kernel knows which index maps to correct interface name.

Now comes my requirement: I need to test my code. Is there a way by which I can simulate index change so that I can verify my code? I have a gut feeling that since index is something which is very much particular to kernel thus it can only be accessed by calls(if_nametoindex()/etc.) but we can't change it. So how do I validate my changeset?

Upvotes: 2

Views: 3815

Answers (3)

Neil
Neil

Reputation: 395

You can reload the relevant network module to change ifindex.

Get module name with basename $(readlink /sys/class/<interface>/device/driver/module) then remove and re-insert it like so:

modprobe -r <modulename>
modprobe <modulename>

Upvotes: 0

tomereli
tomereli

Reputation: 332

If you can force the netdev to unregister, it will choose a new index when it re-registers. For example if the interface is RNDIS (over USB) you can simply disconnect and reconnect the USB. To make sure the index changed you can add a print in the netdev probe...

Upvotes: 0

Bogdan
Bogdan

Reputation: 652

sysctl can't do what you are suggesting.

udev takes care of naming interfaces and even though there are a few naming schemes there is nothing to change the index.

If you can read code have a look here:

http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20

Upvotes: 1

Related Questions