Page MenuHomeFreeBSD

IfAPI: Add iterator to loop over all interfaces
ClosedPublic

Authored by jhibbits on Feb 1 2023, 9:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 29, 10:31 AM
Unknown Object (File)
Mon, Apr 29, 10:31 AM
Unknown Object (File)
Mon, Apr 29, 10:31 AM
Unknown Object (File)
Mon, Apr 29, 10:31 AM
Unknown Object (File)
Mon, Apr 29, 10:31 AM
Unknown Object (File)
Mon, Apr 29, 10:19 AM
Unknown Object (File)
Feb 18 2024, 7:52 AM
Unknown Object (File)
Feb 5 2024, 3:04 AM
Subscribers

Details

Summary

Sometimes it's useful to iterate over all interfaces in the current
VNET, as the linuxulator does in several places.

Unlike other iterators in the IfAPI this propagates any error received
up to the caller, instead of returning a count.

Sponsored by: Juniper Networks, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

melifaro added inline comments.
sys/net/if.c
4474

Nit: worth asserting net epoch and cb!=null

This revision is now accepted and ready to land.Feb 1 2023, 10:35 PM
sys/net/if.c
4474

Not sure about asserting the cb, as it would crash anyway. But the NET_EPOCH_ASSERT() needs to be here.

sys/net/if_var.h
510

I'd suggest to name the function if_foreach() and typedef as if_foreach_cb_t. The reason why I'd suggest to avoid "ifnet" is that a code that is fully converted to the new API should return empty on grep ifnet foo.c. That was suggested back in 2012 and it still works - just checked the drivers you recently converted.

I'd also suggest to place these declarations down at line 667, where the address iterating functions are declared.

sys/net/if_var.h
510

I was also thinking if_foreach(), and hesitated because it doesn't convey "foreach what?" and all other "if_" functions in the IfAPI act on a single interface. But just as happy to make the change, and move it.

if_foreach_ifp ?

The prefix already stands for interface, so why the tautology?

This revision now requires review to proceed.Feb 2 2023, 9:42 PM
This revision is now accepted and ready to land.Feb 2 2023, 11:47 PM