Page MenuHomeFreeBSD

libc: Shortcut if_indextoname() if index == 0

Authored by kp on Apr 21 2020, 7:57 PM.



If the index we're trying to convert is 0 we can avoid a potentially
expensive call to getifaddrs(). No interface has an ifindex of zero, so
we can handle this as an error: set the errno to ENXIO and return NULL.

Submitted by: Nick Rogers
Sponsed by: RG Nets
MFC after: 2 weeks

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Is there really a typical use case for this call?

Yeah, pfctl calls this, and there are flows where it gets called with an index of 0. There's no point in asking the kernel, that only takes time and doesn't change the answer.
We could take this shortcut in pfctl, but it makes more sense to do add the shortcut for everyone.

This revision is now accepted and ready to land.Apr 23 2020, 10:56 AM
This revision was automatically updated to reflect the committed changes.