summaryrefslogtreecommitdiffstats
path: root/sys/netinet/ip_fw2.c
diff options
context:
space:
mode:
authorcsjp <csjp@FreeBSD.org>2006-02-02 03:13:16 +0000
committercsjp <csjp@FreeBSD.org>2006-02-02 03:13:16 +0000
commit31292a14b63b17ba5db98a0848f9166080240c14 (patch)
tree70762151820deceeeabd2497892bd015c4607785 /sys/netinet/ip_fw2.c
parentee6a12ceacf369efe24e49fa5ba813f41b43bd89 (diff)
downloadFreeBSD-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/netinet/ip_fw2.c')
-rw-r--r--sys/netinet/ip_fw2.c55
1 files changed, 10 insertions, 45 deletions
diff --git a/sys/netinet/ip_fw2.c b/sys/netinet/ip_fw2.c
index e286951..ea43ece 100644
--- a/sys/netinet/ip_fw2.c
+++ b/sys/netinet/ip_fw2.c
@@ -50,9 +50,11 @@
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
+#include <sys/lock.h>
#include <sys/jail.h>
#include <sys/module.h>
#include <sys/proc.h>
+#include <sys/rwlock.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sysctl.h>
@@ -131,54 +133,20 @@ struct ip_fw_chain {
struct ip_fw *rules; /* list of rules */
struct ip_fw *reap; /* list of rules to reap */
struct radix_node_head *tables[IPFW_TABLES_MAX];
- struct mtx mtx; /* lock guarding rule list */
- int busy_count; /* busy count for rw locks */
- int want_write;
- struct cv cv;
+ struct rwlock rwmtx;
};
#define IPFW_LOCK_INIT(_chain) \
- mtx_init(&(_chain)->mtx, "IPFW static rules", NULL, \
- MTX_DEF | MTX_RECURSE)
-#define IPFW_LOCK_DESTROY(_chain) mtx_destroy(&(_chain)->mtx)
+ rw_init(&(_chain)->rwmtx, "IPFW static rules")
+#define IPFW_LOCK_DESTROY(_chain) rw_destroy(&(_chain)->rwmtx)
#define IPFW_WLOCK_ASSERT(_chain) do { \
- mtx_assert(&(_chain)->mtx, MA_OWNED); \
+ rw_assert(rw, RA_WLOCKED); \
NET_ASSERT_GIANT(); \
} while (0)
-static __inline void
-IPFW_RLOCK(struct ip_fw_chain *chain)
-{
- mtx_lock(&chain->mtx);
- chain->busy_count++;
- mtx_unlock(&chain->mtx);
-}
-
-static __inline void
-IPFW_RUNLOCK(struct ip_fw_chain *chain)
-{
- mtx_lock(&chain->mtx);
- chain->busy_count--;
- if (chain->busy_count == 0 && chain->want_write)
- cv_signal(&chain->cv);
- mtx_unlock(&chain->mtx);
-}
-
-static __inline void
-IPFW_WLOCK(struct ip_fw_chain *chain)
-{
- mtx_lock(&chain->mtx);
- chain->want_write++;
- while (chain->busy_count > 0)
- cv_wait(&chain->cv, &chain->mtx);
-}
-
-static __inline void
-IPFW_WUNLOCK(struct ip_fw_chain *chain)
-{
- chain->want_write--;
- cv_signal(&chain->cv);
- mtx_unlock(&chain->mtx);
-}
+#define IPFW_RLOCK(p) rw_rlock(&(p)->rwmtx)
+#define IPFW_RUNLOCK(p) rw_runlock(&(p)->rwmtx)
+#define IPFW_WLOCK(p) rw_wlock(&(p)->rwmtx)
+#define IPFW_WUNLOCK(p) rw_wunlock(&(p)->rwmtx)
/*
* list of rules for layer 3
@@ -4155,9 +4123,6 @@ ipfw_init(void)
#endif
layer3_chain.rules = NULL;
- layer3_chain.want_write = 0;
- layer3_chain.busy_count = 0;
- cv_init(&layer3_chain.cv, "Condition variable for IPFW rw locks");
IPFW_LOCK_INIT(&layer3_chain);
ipfw_dyn_rule_zone = uma_zcreate("IPFW dynamic rule zone",
sizeof(ipfw_dyn_rule), NULL, NULL, NULL, NULL,
OpenPOWER on IntegriCloud