Module Name: src Committed By: ozaki-r Date: Tue May 23 03:13:52 UTC 2017
Modified Files: src/sys/netipsec: key.c Log Message: Prepare to retire __LIST_CHAINED We shouldn't relpy on the band-aid and instead use a lock or refcnt to maintain chains properly. Before removing them, replace conditionals with KASSERTs and see what will happen. To generate a diff of this commit: cvs rdiff -u -r1.137 -r1.138 src/sys/netipsec/key.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netipsec/key.c diff -u src/sys/netipsec/key.c:1.137 src/sys/netipsec/key.c:1.138 --- src/sys/netipsec/key.c:1.137 Mon May 22 04:40:23 2017 +++ src/sys/netipsec/key.c Tue May 23 03:13:52 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.137 2017/05/22 04:40:23 ozaki-r Exp $ */ +/* $NetBSD: key.c,v 1.138 2017/05/23 03:13:52 ozaki-r Exp $ */ /* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ /* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.137 2017/05/22 04:40:23 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.138 2017/05/23 03:13:52 ozaki-r Exp $"); /* * This code is referd to RFC 2367 @@ -586,11 +586,10 @@ key_sp_unlink(struct secpolicy *sp) { /* remove from SP index */ - if (__LIST_CHAINED(sp)) { - LIST_REMOVE(sp, chain); - /* Release refcount held just for being on chain */ - KEY_FREESP(&sp); - } + KASSERT(__LIST_CHAINED(sp)); + LIST_REMOVE(sp, chain); + /* Release refcount held just for being on chain */ + KEY_FREESP(&sp); } @@ -2902,8 +2901,8 @@ key_delsah(struct secashead *sah) rtcache_free(&sah->sa_route); /* remove from tree of SA index */ - if (__LIST_CHAINED(sah)) - LIST_REMOVE(sah, chain); + KASSERT(__LIST_CHAINED(sah)); + LIST_REMOVE(sah, chain); if (sah->idents != NULL) kmem_free(sah->idents, sah->idents_len); @@ -3014,8 +3013,8 @@ key_delsav(struct secasvar *sav) KASSERTMSG(sav->refcnt == 0, "reference count %u > 0", sav->refcnt); /* remove from SA header */ - if (__LIST_CHAINED(sav)) - LIST_REMOVE(sav, chain); + KASSERT(__LIST_CHAINED(sav)); + LIST_REMOVE(sav, chain); /* * Cleanup xform state. Note that zeroize'ing causes the @@ -4661,8 +4660,8 @@ key_timehandler_work(struct work *wk, vo struct secacq *acq, *nextacq; LIST_FOREACH_SAFE(acq, &acqtree, chain, nextacq) { - if (now - acq->created > key_blockacq_lifetime && - __LIST_CHAINED(acq)) { + if (now - acq->created > key_blockacq_lifetime) { + KASSERT(__LIST_CHAINED(acq)); LIST_REMOVE(acq, chain); kmem_free(acq, sizeof(*acq)); } @@ -4675,8 +4674,8 @@ key_timehandler_work(struct work *wk, vo struct secspacq *acq, *nextacq; LIST_FOREACH_SAFE(acq, &spacqtree, chain, nextacq) { - if (now - acq->created > key_blockacq_lifetime && - __LIST_CHAINED(acq)) { + if (now - acq->created > key_blockacq_lifetime) { + KASSERT(__LIST_CHAINED(acq)); LIST_REMOVE(acq, chain); kmem_free(acq, sizeof(*acq)); } @@ -6751,7 +6750,8 @@ key_freereg(struct socket *so) */ for (i = 0; i <= SADB_SATYPE_MAX; i++) { LIST_FOREACH(reg, ®tree[i], chain) { - if (reg->so == so && __LIST_CHAINED(reg)) { + if (reg->so == so) { + KASSERT(__LIST_CHAINED(reg)); LIST_REMOVE(reg, chain); kmem_free(reg, sizeof(*reg)); break; @@ -7866,8 +7866,8 @@ key_sa_chgstate(struct secasvar *sav, u_ if (sav->state == state) return; - if (__LIST_CHAINED(sav)) - LIST_REMOVE(sav, chain); + KASSERT(__LIST_CHAINED(sav)); + LIST_REMOVE(sav, chain); sav->state = state; LIST_INSERT_HEAD(&sav->sah->savtree[state], sav, chain);