1

I am developing a proof of concept for a networking application that uses a generic stack interface driver that connects the stack to a userspace application rather than a physical device. This driver works fine and is in production.

The problem I have encountered is this: after I register the device in the kernel module for that driver via register_netdev(), I must sleep between 3ms and 6ms before I can successfully call "ip addr add". It would obviously be better to query something to see if I can set the IP address than to wait for a fixed time (or repeatedly attempt to set it until it sticks).

I am running 4.19.19 with Centos 7.6.

Does anyone know how to check (in a C application, via a system call, via sysfs, etc) if a network device is ready to receive an IP address? Here are some things I have tried without success (they return before I can successfully set the IP without sleeping):

1) Waiting for net_device.flags & IFF_UP

2) Waiting for net_device.reg_state == NETREG_REGISTERED

3) Waiting for netif_running(net_device)

I have also waited to see that I have an index reported by ioctl(fd, SIOCGIFINDEX...), and I seem to right after registering the device.

It feels like something in the network registration notify chain is taking its sweet time to finish up, but I have no idea what it is or how to tell when it is done.

migrated from stackoverflow.com Mar 16 at 4:01

This question came from our site for professional and enthusiast programmers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy