Module Name: src Committed By: ozaki-r Date: Tue Aug 8 08:23:10 UTC 2017
Modified Files: src/sys/netipsec: key.c key.h key_debug.c Log Message: Introduce key_sa_refcnt and replace sav->refcnt with it (NFC) To generate a diff of this commit: cvs rdiff -u -r1.216 -r1.217 src/sys/netipsec/key.c cvs rdiff -u -r1.27 -r1.28 src/sys/netipsec/key.h cvs rdiff -u -r1.19 -r1.20 src/sys/netipsec/key_debug.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.216 src/sys/netipsec/key.c:1.217 --- src/sys/netipsec/key.c:1.216 Tue Aug 8 04:17:34 2017 +++ src/sys/netipsec/key.c Tue Aug 8 08:23:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: key.c,v 1.216 2017/08/08 04:17:34 ozaki-r Exp $ */ +/* $NetBSD: key.c,v 1.217 2017/08/08 08:23:10 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.216 2017/08/08 04:17:34 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.217 2017/08/08 08:23:10 ozaki-r Exp $"); /* * This code is referd to RFC 2367 @@ -1086,7 +1086,7 @@ key_lookup_sa_bysaidx(const struct secas SA_ADDREF(sav); KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, "DP cause refcnt++:%d SA:%p\n", - sav->refcnt, sav); + key_sa_refcnt(sav), sav); break; } } @@ -1107,7 +1107,7 @@ key_sendup_message_delete(struct secasva if (satype == 0) goto msgfail; - m = key_setsadbmsg(SADB_DELETE, 0, satype, 0, 0, sav->refcnt - 1); + m = key_setsadbmsg(SADB_DELETE, 0, satype, 0, 0, key_sa_refcnt(sav) - 1); if (m == NULL) goto msgfail; result = m; @@ -1292,7 +1292,7 @@ done: pserialize_read_exit(s); KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, - "DP return SA:%p; refcnt %u\n", sav, sav ? sav->refcnt : 0); + "DP return SA:%p; refcnt %u\n", sav, key_sa_refcnt(sav)); return sav; } @@ -1369,6 +1369,16 @@ key_sp_unref(struct secpolicy *sp, const localcount_release(&sp->localcount, &key_spd.cv, &key_spd.lock); } +u_int +key_sa_refcnt(const struct secasvar *sav) +{ + + if (sav == NULL) + return 0; + + return sav->refcnt; +} + void key_sa_ref(struct secasvar *sav, const char* where, int tag) { @@ -3322,7 +3332,7 @@ static void key_freesaval(struct secasvar *sav) { - KASSERT(sav->refcnt == 0); + KASSERT(key_sa_refcnt(sav) == 0); if (sav->replay != NULL) kmem_intr_free(sav->replay, sav->replay_len); @@ -3358,7 +3368,7 @@ key_setsaval(struct secasvar *sav, struc KASSERT(mhp->msg != NULL); /* We shouldn't initialize sav variables while someone uses it. */ - KASSERT(sav->refcnt == 0); + KASSERT(key_sa_refcnt(sav) == 0); /* SA */ if (mhp->ext[SADB_EXT_SA] != NULL) { @@ -3542,7 +3552,7 @@ key_init_xform(struct secasvar *sav) int error; /* We shouldn't initialize sav variables while someone uses it. */ - KASSERT(sav->refcnt == 0); + KASSERT(key_sa_refcnt(sav) == 0); /* check SPI value */ switch (sav->sah->saidx.proto) { @@ -3638,7 +3648,7 @@ key_setdumpsa(struct secasvar *sav, u_in }; - m = key_setsadbmsg(type, 0, satype, seq, pid, sav->refcnt); + m = key_setsadbmsg(type, 0, satype, seq, pid, key_sa_refcnt(sav)); if (m == NULL) goto fail; result = m; @@ -5620,7 +5630,7 @@ key_getsavbyseq(struct secashead *sah, u SA_ADDREF(sav); KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, "DP cause refcnt++:%d SA:%p\n", - sav->refcnt, sav); + key_sa_refcnt(sav), sav); break; } } @@ -7069,7 +7079,7 @@ key_expire(struct secasvar *sav) KASSERTMSG(satype != 0, "invalid proto is passed"); /* set msg header */ - m = key_setsadbmsg(SADB_EXPIRE, 0, satype, sav->seq, 0, sav->refcnt); + m = key_setsadbmsg(SADB_EXPIRE, 0, satype, sav->seq, 0, key_sa_refcnt(sav)); if (!m) { error = ENOBUFS; goto fail; Index: src/sys/netipsec/key.h diff -u src/sys/netipsec/key.h:1.27 src/sys/netipsec/key.h:1.28 --- src/sys/netipsec/key.h:1.27 Thu Aug 3 06:32:51 2017 +++ src/sys/netipsec/key.h Tue Aug 8 08:23:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: key.h,v 1.27 2017/08/03 06:32:51 ozaki-r Exp $ */ +/* $NetBSD: key.h,v 1.28 2017/08/08 08:23:10 ozaki-r Exp $ */ /* $FreeBSD: src/sys/netipsec/key.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */ /* $KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun Exp $ */ @@ -61,6 +61,7 @@ u_int key_sp_refcnt(const struct secpoli void key_sp_ref(struct secpolicy *, const char*, int); void key_sp_unref(struct secpolicy *, const char*, int); void key_sa_ref(struct secasvar *, const char*, int); +u_int key_sa_refcnt(const struct secasvar *); void key_socksplist_add(struct secpolicy *); Index: src/sys/netipsec/key_debug.c diff -u src/sys/netipsec/key_debug.c:1.19 src/sys/netipsec/key_debug.c:1.20 --- src/sys/netipsec/key_debug.c:1.19 Wed Jul 26 03:59:59 2017 +++ src/sys/netipsec/key_debug.c Tue Aug 8 08:23:10 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: key_debug.c,v 1.19 2017/07/26 03:59:59 ozaki-r Exp $ */ +/* $NetBSD: key_debug.c,v 1.20 2017/08/08 08:23:10 ozaki-r Exp $ */ /* $FreeBSD: src/sys/netipsec/key_debug.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */ /* $KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $ */ @@ -33,7 +33,7 @@ #ifdef _KERNEL #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.19 2017/07/26 03:59:59 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.20 2017/08/08 08:23:10 ozaki-r Exp $"); #endif #if defined(_KERNEL_OPT) @@ -550,7 +550,7 @@ kdebug_secasv(const struct secasvar *sav kdebug_secasindex(&sav->sah->saidx); printf(" refcnt=%u state=%u auth=%u enc=%u\n", - sav->refcnt, sav->state, sav->alg_auth, sav->alg_enc); + key_sa_refcnt(sav), sav->state, sav->alg_auth, sav->alg_enc); printf(" spi=%u flags=%u\n", (u_int32_t)ntohl(sav->spi), sav->flags);