Changeset View
Changeset View
Standalone View
Standalone View
sys/net/if.c
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
NET_EPOCH_ASSERT(); | NET_EPOCH_ASSERT(); | ||||
ifp = ifnet_byindex(idx); | ifp = ifnet_byindex(idx); | ||||
if (ifp == NULL || (ifp->if_flags & IFF_DYING)) | if (ifp == NULL || (ifp->if_flags & IFF_DYING)) | ||||
return (NULL); | return (NULL); | ||||
if_ref(ifp); | if (!if_try_ref(ifp)) | ||||
return (NULL); | |||||
return (ifp); | return (ifp); | ||||
} | } | ||||
/* | /* | ||||
* Allocate an ifindex array entry; return 0 on success or an error on | * Allocate an ifindex array entry; return 0 on success or an error on | ||||
* failure. | * failure. | ||||
*/ | */ | ||||
static u_short | static u_short | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Interfaces to keep an ifnet type-stable despite the possibility of the | * Interfaces to keep an ifnet type-stable despite the possibility of the | ||||
* driver calling if_free(). If there are additional references, we defer | * driver calling if_free(). If there are additional references, we defer | ||||
* freeing the underlying data structure. | * freeing the underlying data structure. | ||||
*/ | */ | ||||
void | void | ||||
if_ref(struct ifnet *ifp) | if_ref(struct ifnet *ifp) | ||||
{ | { | ||||
u_int old; | |||||
/* We don't assert the ifnet list lock here, but arguably should. */ | /* We don't assert the ifnet list lock here, but arguably should. */ | ||||
refcount_acquire(&ifp->if_refcount); | old = refcount_acquire(&ifp->if_refcount); | ||||
KASSERT(old > 0, ("%s: ifp %p has 0 refs", __func__, ifp)); | |||||
} | |||||
bool | |||||
if_try_ref(struct ifnet *ifp) | |||||
{ | |||||
NET_EPOCH_ASSERT(); | |||||
return (refcount_acquire_if_not_zero(&ifp->if_refcount)); | |||||
} | } | ||||
void | void | ||||
if_rele(struct ifnet *ifp) | if_rele(struct ifnet *ifp) | ||||
{ | { | ||||
if (!refcount_release(&ifp->if_refcount)) | if (!refcount_release(&ifp->if_refcount)) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 3,819 Lines • Show Last 20 Lines |