Introduce a global mutex, ipxpcb_list_mtx, to protect the global

IPX PCB lists.  Add macros to initialize, destroy, lock, unlock,
and assert the mutex.  Initialize the mutex when IPX is started.

Add per-IPX PCB mutexes, ipxp_mtx in struct ipxpcb, to protect
per-PCB IPX/SPX state.  Add macros to initialize, destroy, lock,
unlock, and assert the mutex.  Initialize the mutex when a new
PCB is allocated; destroy it when the PCB is free'd.

MFC after:	2 weeks
This commit is contained in:
Robert Watson 2005-01-09 05:00:41 +00:00
parent 9d98ffa087
commit c2b563b532
3 changed files with 24 additions and 1 deletions

View File

@ -88,6 +88,7 @@ struct sockaddr_ipx ipx_netmask, ipx_hostmask;
/*
* IPX protocol control block (pcb) lists.
*/
struct mtx ipxpcb_list_mtx;
struct ipxpcbhead ipxpcb_list;
struct ipxpcbhead ipxrawpcb_list;
@ -114,6 +115,8 @@ ipx_init()
LIST_INIT(&ipxpcb_list);
LIST_INIT(&ipxrawpcb_list);
IPX_LIST_LOCK_INIT();
ipx_netmask.sipx_len = 6;
ipx_netmask.sipx_addr.x_net = ipx_broadnet;

View File

@ -66,6 +66,7 @@ ipx_pcballoc(so, head, td)
MALLOC(ipxp, struct ipxpcb *, sizeof *ipxp, M_PCB, M_NOWAIT | M_ZERO);
if (ipxp == NULL)
return (ENOBUFS);
IPX_LOCK_INIT(ipxp);
ipxp->ipxp_socket = so;
if (ipxcksum)
ipxp->ipxp_flags |= IPXP_CHECKSUM;
@ -277,6 +278,7 @@ ipx_pcbdetach(ipxp)
if (ipxp->ipxp_route.ro_rt != NULL)
RTFREE(ipxp->ipxp_route.ro_rt);
LIST_REMOVE(ipxp, ipxp_list);
IPX_LOCK_DESTROY(ipxp);
FREE(ipxp, M_PCB);
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2004, Robert N. M. Watson
* Copyright (c) 2004-2005 Robert N. M. Watson
* Copyright (c) 1995, Mike Mitchell
* Copyright (c) 1984, 1985, 1986, 1987, 1993
* The Regents of the University of California. All rights reserved.
@ -54,6 +54,7 @@ struct ipxpcb {
short ipxp_flags;
u_char ipxp_dpt; /* default packet type for ipx_output */
u_char ipxp_rpt; /* last received packet type by ipx_input() */
struct mtx ipxp_mtx;
};
/*
@ -63,6 +64,10 @@ LIST_HEAD(ipxpcbhead, ipxpcb);
extern struct ipxpcbhead ipxpcb_list;
extern struct ipxpcbhead ipxrawpcb_list;
#ifdef _KERNEL
extern struct mtx ipxpcb_list_mtx;
#endif
/* possible flags */
#define IPXP_IN_ABORT 0x1 /* calling abort through socket */
@ -97,6 +102,19 @@ struct ipxpcb *
ipx_pcblookup(struct ipx_addr *faddr, int lport, int wildp);
void ipx_setpeeraddr(struct ipxpcb *ipxp, struct sockaddr **nam);
void ipx_setsockaddr(struct ipxpcb *ipxp, struct sockaddr **nam);
#define IPX_LIST_LOCK_INIT() mtx_init(&ipxpcb_list_mtx, "ipx_list_mtx", \
NULL, MTX_DEF | MTX_RECURSE)
#define IPX_LIST_LOCK() mtx_lock(&ipxpcb_list_mtx)
#define IPX_LIST_UNLOCK() mtx_unlock(&ipxpcb_list_mtx)
#define IPX_LIST_LOCK_ASSERT() mtx_assert(&ipxpcb_list_mtx, MA_OWNED)
#define IPX_LOCK_INIT(ipx) mtx_init(&(ipx)->ipxp_mtx, "ipx_mtx", NULL, \
MTX_DEF)
#define IPX_LOCK_DESTROY(ipx) mtx_destroy(&(ipx)->ipxp_mtx)
#define IPX_LOCK(ipx) mtx_lock(&(ipx)->ipxp_mtx)
#define IPX_UNLOCK(ipx) mtx_unlock(&(ipx)->ipxp_mtx)
#define IPX_LOCK_ASSERT(ipx) mtx_assert(&(ipx)->ipxp_mtx, MA_OWNED)
#endif /* _KERNEL */
#endif /* !_NETIPX_IPX_PCB_H_ */