diff options
author | csjp <csjp@FreeBSD.org> | 2006-02-02 03:13:16 +0000 |
---|---|---|
committer | csjp <csjp@FreeBSD.org> | 2006-02-02 03:13:16 +0000 |
commit | 31292a14b63b17ba5db98a0848f9166080240c14 (patch) | |
tree | 70762151820deceeeabd2497892bd015c4607785 /sys/net/pfil.h | |
parent | ee6a12ceacf369efe24e49fa5ba813f41b43bd89 (diff) | |
download | FreeBSD-src-31292a14b63b17ba5db98a0848f9166080240c14.zip FreeBSD-src-31292a14b63b17ba5db98a0848f9166080240c14.tar.gz |
Somewhat re-factor the read/write locking mechanism associated with the packet
filtering mechanisms to use the new rwlock(9) locking API:
- Drop the variables stored in the phil_head structure which were specific to
conditions and the home rolled read/write locking mechanism.
- Drop some includes which were used for condition variables
- Drop the inline functions, and convert them to macros. Also, move these
macros into pfil.h
- Move pfil list locking macros intp phil.h as well
- Rename ph_busy_count to ph_nhooks. This variable will represent the number
of IN/OUT hooks registered with the pfil head structure
- Define PFIL_HOOKED macro which evaluates to true if there are any
hooks to be ran by pfil_run_hooks
- In the IP/IP6 stacks, change the ph_busy_count comparison to use the new
PFIL_HOOKED macro.
- Drop optimization in pfil_run_hooks which checks to see if there are any
hooks to be ran, and returns if not. This check is already performed by the
IP stacks when they call:
if (!PFIL_HOOKED(ph))
goto skip_hooks;
- Drop in assertion which makes sure that the number of hooks never drops
below 0 for good measure. This in theory should never happen, and if it
does than there are problems somewhere
- Drop special logic around PFIL_WAITOK because rw_wlock(9) does not sleep
- Drop variables which support home rolled read/write locking mechanism from
the IPFW firewall chain structure.
- Swap out the read/write firewall chain lock internal to use the rwlock(9)
API instead of our home rolled version
- Convert the inlined functions to macros
Reviewed by: mlaier, andre, glebius
Thanks to: jhb for the new locking API
Diffstat (limited to 'sys/net/pfil.h')
-rw-r--r-- | sys/net/pfil.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/sys/net/pfil.h b/sys/net/pfil.h index da14f5b..ccf7a65 100644 --- a/sys/net/pfil.h +++ b/sys/net/pfil.h @@ -36,7 +36,7 @@ #include <sys/queue.h> #include <sys/_lock.h> #include <sys/_mutex.h> -#include <sys/condvar.h> /* XXX */ +#include <sys/rwlock.h> struct mbuf; struct ifnet; @@ -67,14 +67,8 @@ struct pfil_head { pfil_list_t ph_in; pfil_list_t ph_out; int ph_type; - /* - * Locking: use a busycounter per pfil_head. - * Use ph_busy_count = -1 to indicate pfil_head is empty. - */ - int ph_busy_count; /* count of threads with read lock */ - int ph_want_write; /* want write lock flag */ - struct cv ph_cv; /* for waking up writers */ - struct mtx ph_mtx; /* mutex on locking state */ + int ph_nhooks; + struct rwlock ph_mtx; union { u_long phu_val; void *phu_ptr; @@ -97,11 +91,17 @@ int pfil_head_unregister(struct pfil_head *); struct pfil_head *pfil_head_get(int, u_long); +#define PFIL_HOOKED(p) (&(p)->ph_nhooks > 0) +#define PFIL_RLOCK(p) rw_rlock(&(p)->ph_mtx) +#define PFIL_WLOCK(p) rw_wlock(&(p)->ph_mtx) +#define PFIL_RUNLOCK(p) rw_runlock(&(p)->ph_mtx) +#define PFIL_WUNLOCK(p) rw_wunlock(&(p)->ph_mtx) +#define PFIL_LIST_LOCK() mtx_lock(&pfil_global_lock) +#define PFIL_LIST_UNLOCK() mtx_unlock(&pfil_global_lock) + static __inline struct packet_filter_hook * pfil_hook_get(int dir, struct pfil_head *ph) { - KASSERT(ph->ph_busy_count > 0, - ("pfil_hook_get: called on unbusy pfil_head")); if (dir == PFIL_IN) return (TAILQ_FIRST(&ph->ph_in)); else if (dir == PFIL_OUT) |