Changeset View
Changeset View
Standalone View
Standalone View
sys/net/if.c
Show All 33 Lines | |||||
#include "opt_inet6.h" | #include "opt_inet6.h" | ||||
#include "opt_inet.h" | #include "opt_inet.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/conf.h> | #include <sys/conf.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/_domainset.h> | |||||
kib: Thus header is excessive if domainset.h is included ? | |||||
Done Inline ActionsIndeed, you are correct. I confess to just copying from the domainset(9) man page. gallatin: Indeed, you are correct. I confess to just copying from the domainset(9) man page. | |||||
#include <sys/domainset.h> | |||||
#include <sys/sbuf.h> | #include <sys/sbuf.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/epoch.h> | #include <sys/epoch.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/priv.h> | #include <sys/priv.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
▲ Show 20 Lines • Show All 471 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/* | /* | ||||
* Allocate a struct ifnet and an index for an interface. A layer 2 | * Allocate a struct ifnet and an index for an interface. A layer 2 | ||||
* common structure will also be allocated if an allocation routine is | * common structure will also be allocated if an allocation routine is | ||||
* registered for the passed type. | * registered for the passed type. | ||||
*/ | */ | ||||
struct ifnet * | struct ifnet * | ||||
if_alloc(u_char type) | if_alloc_domain(u_char type, int numa_domain) | ||||
{ | { | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
u_short idx; | u_short idx; | ||||
void *old; | void *old; | ||||
KASSERT(numa_domain <= IF_NODOM, ("numa_domain too large")); | |||||
if (numa_domain == IF_NODOM) | |||||
ifp = malloc(sizeof(struct ifnet), M_IFNET, M_WAITOK|M_ZERO); | ifp = malloc(sizeof(struct ifnet), M_IFNET, M_WAITOK|M_ZERO); | ||||
kibUnsubmitted Done Inline ActionsThere should be spaces around binary op. kib: There should be spaces around binary op. | |||||
else | |||||
ifp = malloc_domainset(sizeof(struct ifnet), M_IFNET, | |||||
DOMAINSET_PREF(numa_domain), M_WAITOK|M_ZERO); | |||||
restart: | restart: | ||||
IFNET_WLOCK(); | IFNET_WLOCK(); | ||||
idx = ifindex_alloc(&old); | idx = ifindex_alloc(&old); | ||||
if (__predict_false(idx == USHRT_MAX)) { | if (__predict_false(idx == USHRT_MAX)) { | ||||
IFNET_WUNLOCK(); | IFNET_WUNLOCK(); | ||||
epoch_wait_preempt(net_epoch_preempt); | epoch_wait_preempt(net_epoch_preempt); | ||||
free(old, M_IFNET); | free(old, M_IFNET); | ||||
goto restart; | goto restart; | ||||
} | } | ||||
ifnet_setbyindex(idx, IFNET_HOLD); | ifnet_setbyindex(idx, IFNET_HOLD); | ||||
IFNET_WUNLOCK(); | IFNET_WUNLOCK(); | ||||
ifp->if_index = idx; | ifp->if_index = idx; | ||||
ifp->if_type = type; | ifp->if_type = type; | ||||
ifp->if_alloctype = type; | ifp->if_alloctype = type; | ||||
ifp->if_numa_domain = numa_domain; | |||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
ifp->if_vnet = curvnet; | ifp->if_vnet = curvnet; | ||||
#endif | #endif | ||||
if (if_com_alloc[type] != NULL) { | if (if_com_alloc[type] != NULL) { | ||||
ifp->if_l2com = if_com_alloc[type](type, ifp); | ifp->if_l2com = if_com_alloc[type](type, ifp); | ||||
if (ifp->if_l2com == NULL) { | if (ifp->if_l2com == NULL) { | ||||
free(ifp, M_IFNET); | free(ifp, M_IFNET); | ||||
ifindex_free(idx); | ifindex_free(idx); | ||||
Show All 17 Lines | #endif | ||||
for (int i = 0; i < IFCOUNTERS; i++) | for (int i = 0; i < IFCOUNTERS; i++) | ||||
ifp->if_counters[i] = counter_u64_alloc(M_WAITOK); | ifp->if_counters[i] = counter_u64_alloc(M_WAITOK); | ||||
ifp->if_get_counter = if_get_counter_default; | ifp->if_get_counter = if_get_counter_default; | ||||
ifp->if_pcp = IFNET_PCP_NONE; | ifp->if_pcp = IFNET_PCP_NONE; | ||||
ifnet_setbyindex(ifp->if_index, ifp); | ifnet_setbyindex(ifp->if_index, ifp); | ||||
return (ifp); | return (ifp); | ||||
} | } | ||||
struct ifnet * | |||||
if_alloc(u_char type) | |||||
{ | |||||
kibUnsubmitted Done Inline ActionsThere should be a blank line after '{' if there is no locals. kib: There should be a blank line after '{' if there is no locals. | |||||
return (if_alloc_domain(type, IF_NODOM)); | |||||
} | |||||
Done Inline ActionsThere are redundant parens around the call. markj: There are redundant parens around the call. | |||||
/* | /* | ||||
* Do the actual work of freeing a struct ifnet, and layer 2 common | * Do the actual work of freeing a struct ifnet, and layer 2 common | ||||
* structure. This call is made when the last reference to an | * structure. This call is made when the last reference to an | ||||
Done Inline ActionsI would write it as if (dev == NULL || bus_get_domain(dev, &numa_domain) != 0) return (if_alloc_domain(type, IF_NODOM); return (if_alloc_domain(type, numa_domain); kib: I would write it as
```
if (dev == NULL || bus_get_domain(dev, &numa_domain) != 0)… | |||||
* interface is released. | * interface is released. | ||||
*/ | */ | ||||
static void | static void | ||||
if_free_internal(struct ifnet *ifp) | if_free_internal(struct ifnet *ifp) | ||||
{ | { | ||||
KASSERT((ifp->if_flags & IFF_DYING), | KASSERT((ifp->if_flags & IFF_DYING), | ||||
("if_free_internal: interface not dying")); | ("if_free_internal: interface not dying")); | ||||
Show All 9 Lines | #endif /* MAC */ | ||||
IF_ADDR_LOCK_DESTROY(ifp); | IF_ADDR_LOCK_DESTROY(ifp); | ||||
ifq_delete(&ifp->if_snd); | ifq_delete(&ifp->if_snd); | ||||
for (int i = 0; i < IFCOUNTERS; i++) | for (int i = 0; i < IFCOUNTERS; i++) | ||||
counter_u64_free(ifp->if_counters[i]); | counter_u64_free(ifp->if_counters[i]); | ||||
free(ifp->if_description, M_IFDESCR); | free(ifp->if_description, M_IFDESCR); | ||||
free(ifp->if_hw_addr, M_IFADDR); | free(ifp->if_hw_addr, M_IFADDR); | ||||
if (ifp->if_numa_domain == IF_NODOM) | |||||
free(ifp, M_IFNET); | free(ifp, M_IFNET); | ||||
else | |||||
free_domain(ifp, M_IFNET); | |||||
} | } | ||||
static void | static void | ||||
if_destroy(epoch_context_t ctx) | if_destroy(epoch_context_t ctx) | ||||
{ | { | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
ifp = __containerof(ctx, struct ifnet, if_epoch_ctx); | ifp = __containerof(ctx, struct ifnet, if_epoch_ctx); | ||||
▲ Show 20 Lines • Show All 3,976 Lines • Show Last 20 Lines |
Thus header is excessive if domainset.h is included ?