Source-Changes-HG archive

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

[src/trunk]: src/sys/netipsec ipsec6_setspidx_in6pcb: call ipsec_setspidx() o...



details:   https://anonhg.NetBSD.org/src/rev/9a851091a80b
branches:  trunk
changeset: 830187:9a851091a80b
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Feb 28 10:09:17 2018 +0000

description:
ipsec6_setspidx_in6pcb: call ipsec_setspidx() only once, just like the
IPv4 code. While here put the correct variable in sizeof.

ok ozaki-r@

diffstat:

 sys/netipsec/ipsec.c |  38 ++++++++++++++------------------------
 1 files changed, 14 insertions(+), 24 deletions(-)

diffs (73 lines):

diff -r 10453b50c871 -r 9a851091a80b sys/netipsec/ipsec.c
--- a/sys/netipsec/ipsec.c      Wed Feb 28 09:44:25 2018 +0000
+++ b/sys/netipsec/ipsec.c      Wed Feb 28 10:09:17 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.146 2018/02/27 15:01:30 maxv Exp $ */
+/* $NetBSD: ipsec.c,v 1.147 2018/02/28 10:09:17 maxv Exp $ */
 /* $FreeBSD: src/sys/netipsec/ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $ */
 /* $KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $ */
 
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.146 2018/02/27 15:01:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.147 2018/02/28 10:09:17 maxv Exp $");
 
 /*
  * IPsec controller part.
@@ -812,7 +812,7 @@
                memset(&pcb->inp_sp->sp_in->spidx, 0,
                    sizeof(pcb->inp_sp->sp_in->spidx));
                memset(&pcb->inp_sp->sp_out->spidx, 0,
-                   sizeof(pcb->inp_sp->sp_in->spidx));
+                   sizeof(pcb->inp_sp->sp_out->spidx));
        }
        return error;
 }
@@ -821,7 +821,6 @@
 static int
 ipsec6_setspidx_in6pcb(struct mbuf *m, struct in6pcb *pcb)
 {
-       struct secpolicyindex *spidx;
        int error;
 
        KASSERT(pcb != NULL);
@@ -829,26 +828,17 @@
        KASSERT(pcb->in6p_sp->sp_out != NULL);
        KASSERT(pcb->in6p_sp->sp_in != NULL);
 
-       memset(&pcb->in6p_sp->sp_in->spidx, 0, sizeof(*spidx));
-       memset(&pcb->in6p_sp->sp_out->spidx, 0, sizeof(*spidx));
-
-       spidx = &pcb->in6p_sp->sp_in->spidx;
-       error = ipsec_setspidx(m, spidx, 1);
-       if (error)
-               goto bad;
-       spidx->dir = IPSEC_DIR_INBOUND;
-
-       spidx = &pcb->in6p_sp->sp_out->spidx;
-       error = ipsec_setspidx(m, spidx, 1);
-       if (error)
-               goto bad;
-       spidx->dir = IPSEC_DIR_OUTBOUND;
-
-       return 0;
-
-bad:
-       memset(&pcb->in6p_sp->sp_in->spidx, 0, sizeof(*spidx));
-       memset(&pcb->in6p_sp->sp_out->spidx, 0, sizeof(*spidx));
+       error = ipsec_setspidx(m, &pcb->in6p_sp->sp_in->spidx, 1);
+       if (error == 0) {
+               pcb->in6p_sp->sp_in->spidx.dir = IPSEC_DIR_INBOUND;
+               pcb->in6p_sp->sp_out->spidx = pcb->in6p_sp->sp_in->spidx;
+               pcb->in6p_sp->sp_out->spidx.dir = IPSEC_DIR_OUTBOUND;
+       } else {
+               memset(&pcb->in6p_sp->sp_in->spidx, 0,
+                   sizeof(pcb->in6p_sp->sp_in->spidx));
+               memset(&pcb->in6p_sp->sp_out->spidx, 0,
+                   sizeof(pcb->in6p_sp->sp_out->spidx));
+       }
        return error;
 }
 #endif



Home | Main Index | Thread Index | Old Index