Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtnl_link_get returns NULL for USB wireless indexes if it has ever been unplugged #49

Closed
ghost opened this issue Oct 29, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Oct 29, 2013

I have a small application where I iterate through the interfaces of my system like so:

485 int index = 1;
486
487 forever {
488 struct rtnl_link *link = rtnl_link_get(link_cache, index);
489
490 if(link != NULL) {
491 char *name = rtnl_link_get_name(link);
492
493 qDebug() << "found interface: " << name;
494
495 linkList << name;
496
497 rtnl_link_put(link);
498 }else{
499 break;
500 }
501
502 ++index;
503 }

This works fine to detect all my ethernet interfaces as well as USB wireless, until the wireless adapter is unplugged. Once it is re-plugged, rtnl_link_get returns NULL for the index associated with the wireless adapter. All other system utilities such as ip, iw etc. continue to work fine after the adapter is re-plugged, just not libnl. As a workaround I instead read from /sys/class/net to find the system's interfaces until this issue is resolved. Any idea what could be wrong?

@tgraf
Copy link
Contributor

tgraf commented Oct 30, 2013

Did you resync the cache after replugging the interface?

@ghost
Copy link
Author

ghost commented Oct 31, 2013

That seemed to do it, thanks!

I had no idea about the resync function until I dove into the source looking for it. Is there a note in the docs somewhere about needing to use it if you have hotplug devices?

@tgraf
Copy link
Contributor

tgraf commented Oct 31, 2013

Unfortunately the caching system is not very well documented at this point.

@tgraf tgraf closed this as completed Oct 31, 2013
@ghost
Copy link
Author

ghost commented Oct 31, 2013

Actually I was wrong... it's still not working. I'm doing rtnl_cache_resync(sock, link_cache, NULL, NULL) right after I allocate the link cache, is that the correct way to use it? Any ideas?

@tgraf
Copy link
Contributor

tgraf commented Oct 31, 2013

You have two options:
a) Manually resync the cache periodically to update your local cache to the latest state in the kernel. Caches do not automatically receive updates.
b) Use the cache manager to allocate and manage the cache [0] which will listen for notifications such as new links appearing, links disappearing and updating the cache as needed.

[0] http://www.infradead.org/~tgr/libnl/doc/core.html#_cache_manager

@ghost
Copy link
Author

ghost commented Nov 13, 2013

So what is the preferred way to manually resync the cache?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant