diff options
author | Kristof Provost <kp@FreeBSD.org> | 2017-03-22 21:18:18 +0000 |
---|---|---|
committer | Kristof Provost <kp@FreeBSD.org> | 2017-03-22 21:18:18 +0000 |
commit | 2f8fb3a8689169dd0b272c7718670cf58698d1a9 (patch) | |
tree | 0cdc182512664b6b92e6fee7aedd9b3e7835cb23 /sys/netpfil | |
parent | 62fd382c4360a574b8d4eabb8555afd4ebc84a45 (diff) | |
download | src-2f8fb3a8689169dd0b272c7718670cf58698d1a9.tar.gz src-2f8fb3a8689169dd0b272c7718670cf58698d1a9.zip |
Notes
Diffstat (limited to 'sys/netpfil')
-rw-r--r-- | sys/netpfil/pf/pf.c | 17 | ||||
-rw-r--r-- | sys/netpfil/pf/pf_ioctl.c | 10 |
2 files changed, 16 insertions, 11 deletions
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 8a82d0807589..cf5d15984674 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -302,6 +302,7 @@ static void pf_route6(struct mbuf **, struct pf_rule *, int, int in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len); extern int pf_end_threads; +extern struct proc *pf_purge_proc; VNET_DEFINE(struct pf_limit, pf_limits[PF_LIMIT_MAX]); @@ -1428,19 +1429,14 @@ pf_purge_thread(void *unused __unused) VNET_ITERATOR_DECL(vnet_iter); u_int idx = 0; - for (;;) { - tsleep(pf_purge_thread, 0, "pftm", hz / 10); + sx_xlock(&pf_end_lock); + while (pf_end_threads == 0) { + sx_sleep(pf_purge_thread, &pf_end_lock, 0, "pftm", hz / 10); VNET_LIST_RLOCK(); VNET_FOREACH(vnet_iter) { CURVNET_SET(vnet_iter); - if (pf_end_threads) { - pf_end_threads++; - wakeup(pf_purge_thread); - VNET_LIST_RUNLOCK(); - kproc_exit(0); - } /* Wait until V_pf_default_rule is initialized. */ if (V_pf_vnet_active == 0) { @@ -1474,7 +1470,10 @@ pf_purge_thread(void *unused __unused) } VNET_LIST_RUNLOCK(); } - /* not reached */ + + pf_end_threads++; + sx_xunlock(&pf_end_lock); + kproc_exit(0); } void diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 455fb9b1bb49..584d942e6969 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -198,9 +198,11 @@ VNET_DEFINE(int, pf_vnet_active); #define V_pf_vnet_active VNET(pf_vnet_active) int pf_end_threads; +struct proc *pf_purge_proc; struct rwlock pf_rules_lock; struct sx pf_ioctl_lock; +struct sx pf_end_lock; /* pfsync */ pfsync_state_import_t *pfsync_state_import_ptr = NULL; @@ -3730,6 +3732,7 @@ pf_load(void) rw_init(&pf_rules_lock, "pf rulesets"); sx_init(&pf_ioctl_lock, "pf ioctl"); + sx_init(&pf_end_lock, "pf end thread"); pf_mtag_initialize(); @@ -3738,7 +3741,7 @@ pf_load(void) return (ENOMEM); pf_end_threads = 0; - error = kproc_create(pf_purge_thread, NULL, NULL, 0, 0, "pf purge"); + error = kproc_create(pf_purge_thread, NULL, &pf_purge_proc, 0, 0, "pf purge"); if (error != 0) return (error); @@ -3788,11 +3791,13 @@ pf_unload(void) { int error = 0; + sx_xlock(&pf_end_lock); pf_end_threads = 1; while (pf_end_threads < 2) { wakeup_one(pf_purge_thread); - tsleep(pf_purge_thread, 0, "pftmo", 0); + sx_sleep(pf_purge_proc, &pf_end_lock, 0, "pftmo", 0); } + sx_xunlock(&pf_end_lock); if (pf_dev != NULL) destroy_dev(pf_dev); @@ -3801,6 +3806,7 @@ pf_unload(void) rw_destroy(&pf_rules_lock); sx_destroy(&pf_ioctl_lock); + sx_destroy(&pf_end_lock); return (error); } |