IfAPI: Add iterator to loop over all interfaces
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. Reviewed by: glebius, melifaro Differential Revision: https://reviews.freebsd.org/D38348
This commit is contained in:
parent
a1f8a0c793
commit
2eeb808361
19
sys/net/if.c
19
sys/net/if.c
@ -4466,6 +4466,25 @@ if_lladdr_count(if_t ifp)
|
||||
return (count);
|
||||
}
|
||||
|
||||
int
|
||||
if_foreach(if_foreach_cb_t cb, void *cb_arg)
|
||||
{
|
||||
if_t ifp;
|
||||
int error;
|
||||
|
||||
NET_EPOCH_ASSERT();
|
||||
MPASS(cb);
|
||||
|
||||
error = 0;
|
||||
CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
|
||||
error = cb(ifp, cb_arg);
|
||||
if (error != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
u_int
|
||||
if_foreach_lladdr(if_t ifp, iflladdr_cb_t cb, void *cb_arg)
|
||||
{
|
||||
|
@ -665,6 +665,9 @@ struct ifaddr * if_getifaddr(const if_t ifp);
|
||||
typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int);
|
||||
u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg);
|
||||
|
||||
typedef int (*if_foreach_cb_t)(if_t, void *);
|
||||
int if_foreach(if_foreach_cb_t, void *);
|
||||
|
||||
/* Functions */
|
||||
void if_setinitfn(if_t ifp, if_init_fn_t);
|
||||
void if_setinputfn(if_t ifp, if_input_fn_t);
|
||||
|
Loading…
Reference in New Issue
Block a user