diff options
author | rwatson <rwatson@FreeBSD.org> | 2005-01-09 05:00:41 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2005-01-09 05:00:41 +0000 |
commit | a6ab698ab0edb8e7baa3a6a732e387823f1c3dcd (patch) | |
tree | 4fd6402fc00deda5073cdd5d8a3074dacec8f007 | |
parent | dbe7c51df6abf448367f1b6dd6785e0cc8b5815b (diff) | |
download | FreeBSD-src-a6ab698ab0edb8e7baa3a6a732e387823f1c3dcd.zip FreeBSD-src-a6ab698ab0edb8e7baa3a6a732e387823f1c3dcd.tar.gz |
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
-rw-r--r-- | sys/netipx/ipx_input.c | 3 | ||||
-rw-r--r-- | sys/netipx/ipx_pcb.c | 2 | ||||
-rw-r--r-- | sys/netipx/ipx_pcb.h | 20 |
3 files changed, 24 insertions, 1 deletions
diff --git a/sys/netipx/ipx_input.c b/sys/netipx/ipx_input.c index 596b275..0e8f75e 100644 --- a/sys/netipx/ipx_input.c +++ b/sys/netipx/ipx_input.c @@ -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; diff --git a/sys/netipx/ipx_pcb.c b/sys/netipx/ipx_pcb.c index 1649b2e..322e569 100644 --- a/sys/netipx/ipx_pcb.c +++ b/sys/netipx/ipx_pcb.c @@ -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); } diff --git a/sys/netipx/ipx_pcb.h b/sys/netipx/ipx_pcb.h index 8164844..f65e133 100644 --- a/sys/netipx/ipx_pcb.h +++ b/sys/netipx/ipx_pcb.h @@ -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_ */ |