svn commit: r237376 - projects/pf/head/sys/contrib/pf/net

Gleb Smirnoff glebius at FreeBSD.org
Thu Jun 21 10:21:15 UTC 2012


Author: glebius
Date: Thu Jun 21 10:21:14 2012
New Revision: 237376
URL: http://svn.freebsd.org/changeset/base/237376

Log:
  - To free all rules when shutting down we need to perform
    a couple of scans. Do this and provide some comments
    to explain what is going on here.
  - We can't call into pf_purge_unlinked_rules() with rules
    lock held, since it would obtain it exclusively.

Modified:
  projects/pf/head/sys/contrib/pf/net/pf.c

Modified: projects/pf/head/sys/contrib/pf/net/pf.c
==============================================================================
--- projects/pf/head/sys/contrib/pf/net/pf.c	Thu Jun 21 10:06:00 2012	(r237375)
+++ projects/pf/head/sys/contrib/pf/net/pf.c	Thu Jun 21 10:21:14 2012	(r237376)
@@ -1317,19 +1317,45 @@ pf_purge_thread(void *v)
 
 	CURVNET_SET((struct vnet *)v);
 
-	PF_RULES_RLOCK();
 	for (;;) {
+		PF_RULES_RLOCK();
 		rw_sleep(pf_purge_thread, &pf_rules_lock, 0, "pftm", hz / 10);
 
 		if (V_pf_end_threads) {
+			/*
+			 * To cleanse up all kifs and rules we need
+			 * two runs: first one clears reference flags,
+			 * then pf_purge_expired_states() doesn't
+			 * raise them, and then second run frees.
+			 */
+			PF_RULES_RUNLOCK();
+			pf_purge_unlinked_rules();
+			pfi_kif_purge();
+
+			/*
+			 * Now purge everything.
+			 */
 			pf_purge_expired_states(V_pf_hashmask + 1);
 			pf_purge_expired_fragments();
 			pf_purge_expired_src_nodes();
+
+			/*
+			 * Now all kifs & rules should be unreferenced,
+			 * thus should be successfully freed.
+			 */
+			pf_purge_unlinked_rules();
+			pfi_kif_purge();
+
+			/*
+			 * Announce success and exit.
+			 */
+			PF_RULES_RLOCK();
 			V_pf_end_threads++;
 			PF_RULES_RUNLOCK();
 			wakeup(pf_purge_thread);
 			kproc_exit(0);
 		}
+		PF_RULES_RUNLOCK();
 
 		/* Process 1/interval fraction of the state table every run. */
 		fullrun = pf_purge_expired_states(V_pf_hashmask /


More information about the svn-src-projects mailing list