The two functions ifnet_byindex() and ifnet_byindex_locked() are exactly the
same after the network stack was epochified. Merge the two into one function and cleanup all uses of ifnet_byindex_locked(). While at it: - Add branch prediction macros. - Make sure the ifnet pointer is only deferred once, also when code optimisation is disabled. Sponsored by: Mellanox Technologies
This commit is contained in:
parent
93cfeb0ed9
commit
270b83b9d1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=353550
24
sys/net/if.c
24
sys/net/if.c
@ -328,24 +328,16 @@ static MALLOC_DEFINE(M_IFNET, "ifnet", "interface internals");
|
||||
MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
|
||||
MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
|
||||
|
||||
struct ifnet *
|
||||
ifnet_byindex_locked(u_short idx)
|
||||
{
|
||||
|
||||
if (idx > V_if_index)
|
||||
return (NULL);
|
||||
if (V_ifindex_table[idx] == IFNET_HOLD)
|
||||
return (NULL);
|
||||
return (V_ifindex_table[idx]);
|
||||
}
|
||||
|
||||
struct ifnet *
|
||||
ifnet_byindex(u_short idx)
|
||||
{
|
||||
struct ifnet *ifp;
|
||||
|
||||
ifp = ifnet_byindex_locked(idx);
|
||||
return (ifp);
|
||||
if (__predict_false(idx > V_if_index))
|
||||
return (NULL);
|
||||
|
||||
ifp = *(struct ifnet * const volatile *)(V_ifindex_table + idx);
|
||||
return (__predict_false(ifp == IFNET_HOLD) ? NULL : ifp);
|
||||
}
|
||||
|
||||
struct ifnet *
|
||||
@ -355,7 +347,7 @@ ifnet_byindex_ref(u_short idx)
|
||||
|
||||
NET_EPOCH_ASSERT();
|
||||
|
||||
ifp = ifnet_byindex_locked(idx);
|
||||
ifp = ifnet_byindex(idx);
|
||||
if (ifp == NULL || (ifp->if_flags & IFF_DYING))
|
||||
return (NULL);
|
||||
if_ref(ifp);
|
||||
@ -427,7 +419,7 @@ ifaddr_byindex(u_short idx)
|
||||
|
||||
NET_EPOCH_ASSERT();
|
||||
|
||||
ifp = ifnet_byindex_locked(idx);
|
||||
ifp = ifnet_byindex(idx);
|
||||
if (ifp != NULL && (ifa = ifp->if_addr) != NULL)
|
||||
ifa_ref(ifa);
|
||||
return (ifa);
|
||||
@ -653,7 +645,7 @@ if_free(struct ifnet *ifp)
|
||||
|
||||
CURVNET_SET_QUIET(ifp->if_vnet);
|
||||
IFNET_WLOCK();
|
||||
KASSERT(ifp == ifnet_byindex_locked(ifp->if_index),
|
||||
KASSERT(ifp == ifnet_byindex(ifp->if_index),
|
||||
("%s: freeing unallocated ifnet", ifp->if_xname));
|
||||
|
||||
ifindex_free_locked(ifp->if_index);
|
||||
|
@ -629,7 +629,6 @@ extern struct sx ifnet_sxlock;
|
||||
* to call ifnet_byindex() instead of ifnet_byindex_ref().
|
||||
*/
|
||||
struct ifnet *ifnet_byindex(u_short idx);
|
||||
struct ifnet *ifnet_byindex_locked(u_short idx);
|
||||
struct ifnet *ifnet_byindex_ref(u_short idx);
|
||||
|
||||
/*
|
||||
|
@ -1293,7 +1293,7 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
|
||||
ifpaddr->sa_family == AF_LINK) {
|
||||
const struct sockaddr_dl *sdl = (const struct sockaddr_dl *)ifpaddr;
|
||||
if (sdl->sdl_index != 0)
|
||||
info->rti_ifp = ifnet_byindex_locked(sdl->sdl_index);
|
||||
info->rti_ifp = ifnet_byindex(sdl->sdl_index);
|
||||
}
|
||||
/*
|
||||
* If we have source address specified, try to find it
|
||||
|
Loading…
Reference in New Issue
Block a user