Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netipsec Introduce key_sa_refcnt and replace sav->refcnt...



details:   https://anonhg.NetBSD.org/src/rev/01b92bf769e7
branches:  trunk
changeset: 355655:01b92bf769e7
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Tue Aug 08 08:23:10 2017 +0000

description:
Introduce key_sa_refcnt and replace sav->refcnt with it (NFC)

diffstat:

 sys/netipsec/key.c       |  32 +++++++++++++++++++++-----------
 sys/netipsec/key.h       |   3 ++-
 sys/netipsec/key_debug.c |   6 +++---
 3 files changed, 26 insertions(+), 15 deletions(-)

diffs (160 lines):

diff -r 4b431ac5bfe4 -r 01b92bf769e7 sys/netipsec/key.c
--- a/sys/netipsec/key.c        Tue Aug 08 08:12:14 2017 +0000
+++ b/sys/netipsec/key.c        Tue Aug 08 08:23:10 2017 +0000
@@ -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 @@
                        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 @@
        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 @@
        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 @@
        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 @@
 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 @@
        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 @@
        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 @@
 
        };
 
-       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 @@
                        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 @@
        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;
diff -r 4b431ac5bfe4 -r 01b92bf769e7 sys/netipsec/key.h
--- a/sys/netipsec/key.h        Tue Aug 08 08:12:14 2017 +0000
+++ b/sys/netipsec/key.h        Tue Aug 08 08:23:10 2017 +0000
@@ -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 @@
 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 *);
 
diff -r 4b431ac5bfe4 -r 01b92bf769e7 sys/netipsec/key_debug.c
--- a/sys/netipsec/key_debug.c  Tue Aug 08 08:12:14 2017 +0000
+++ b/sys/netipsec/key_debug.c  Tue Aug 08 08:23:10 2017 +0000
@@ -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_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);
 



Home | Main Index | Thread Index | Old Index