event->kev_class == KEV_NETWORK_CLASS &&
event->kev_subclass == KEV_DL_SUBCLASS &&
event->event_code == KEV_DL_IF_DETACHING) {
- lck_mtx_assert(ndrvdomain.dom_mtx, LCK_MTX_ASSERT_NOTOWNED);
- lck_mtx_lock(ndrvdomain.dom_mtx);
ndrv_handle_ifp_detach(ifp->if_family, ifp->if_unit);
- lck_mtx_unlock(ndrvdomain.dom_mtx);
}
}
ndrv_proto.event = ndrv_event;
/* We aren't worried about double attaching, that should just return an error */
- socket_unlock(so, 0);
result = dlil_attach_protocol(&ndrv_proto);
- socket_lock(so, 0);
if (result && result != EEXIST) {
return result;
}
struct ndrv_cb* cur_np = NULL;
struct socket *so = np->nd_socket;
int error = 0;
- struct ifnet * ifp;
#if NDRV_DEBUG
kprintf("NDRV detach: %x, %x\n", so, np);
#endif
ndrv_remove_all_multicast(np);
- ifp = np->nd_if;
- /* Remove from the linked list of control blocks */
- TAILQ_REMOVE(&ndrvl, np, nd_next);
- if (ifp != NULL) {
- u_long proto_family = np->nd_proto_family;
-
- if (proto_family != PF_NDRV && proto_family != 0) {
- socket_unlock(so, 0);
- dlil_detach_protocol(ifp, proto_family);
- socket_lock(so, 0);
+
+ if (np->nd_if) {
+ if (np->nd_proto_family != PF_NDRV &&
+ np->nd_proto_family != 0) {
+ dlil_detach_protocol(np->nd_if, np->nd_proto_family);
}
+ /* Remove from the linked list of control blocks */
+ TAILQ_REMOVE(&ndrvl, np, nd_next);
+
/* Check if this is the last socket attached to this interface */
TAILQ_FOREACH(cur_np, &ndrvl, nd_next) {
if (cur_np->nd_family == np->nd_family &&
/* If there are no other interfaces, detach PF_NDRV from the interface */
if (cur_np == NULL) {
- socket_unlock(so, 0);
- dlil_detach_protocol(ifp, PF_NDRV);
- socket_lock(so, 0);
+ dlil_detach_protocol(np->nd_if, PF_NDRV);
}
+ } else {
+ /* Remove from the linked list of control blocks */
+ TAILQ_REMOVE(&ndrvl, np, nd_next);
}
- if (np->nd_laddr != NULL) {
- FREE((caddr_t)np->nd_laddr, M_IFADDR);
- np->nd_laddr = NULL;
- }
FREE((caddr_t)np, M_PCB);
so->so_pcb = 0;
so->so_flags |= SOF_PCBCLEARING;
static int
ndrv_do_disconnect(struct ndrv_cb *np)
{
- struct socket * so = np->nd_socket;
#if NDRV_DEBUG
kprintf("NDRV disconnect: %x\n", np);
#endif
FREE(np->nd_faddr, M_IFADDR);
np->nd_faddr = 0;
}
- if (so->so_state & SS_NOFDREF)
+ if (np->nd_socket->so_state & SS_NOFDREF)
ndrv_do_detach(np);
- soisdisconnected(so);
+ soisdisconnected(np->nd_socket);
return(0);
}
struct dlil_demux_desc* dlilDemux = NULL;
struct ndrv_demux_desc* ndrvDemux = NULL;
int error = 0;
- struct socket *so = np->nd_socket;
/* Sanity checking */
if (np->nd_proto_family != PF_NDRV)
if (error == 0)
{
/* We've got all our ducks lined up...lets attach! */
- socket_unlock(so, 0);
error = dlil_attach_protocol(&dlilSpec);
- socket_lock(so, 0);
if (error == 0)
np->nd_proto_family = dlilSpec.protocol_family;
}