Source-Changes-HG archive

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

[src/trunk]: src/sys Dedup: merge ipsec4_set_policy and ipsec6_set_policy. Th...



details:   https://anonhg.NetBSD.org/src/rev/bd76dccfa97a
branches:  trunk
changeset: 830172:bd76dccfa97a
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Feb 27 15:01:30 2018 +0000

description:
Dedup: merge ipsec4_set_policy and ipsec6_set_policy. The content of the
original ipsec_set_policy function is inlined into the new one.

diffstat:

 sys/netinet/ip_output.c             |    6 +-
 sys/netinet6/ip6_output.c           |    6 +-
 sys/netipsec/ipsec.c                |  111 +++++++++--------------------------
 sys/netipsec/ipsec.h                |    4 +-
 sys/netipsec/ipsec6.h               |    3 +-
 sys/rump/librump/rumpnet/net_stub.c |    7 +-
 6 files changed, 42 insertions(+), 95 deletions(-)

diffs (284 lines):

diff -r 403337ee3db6 -r bd76dccfa97a sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/netinet/ip_output.c   Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_output.c,v 1.296 2018/02/27 14:44:10 maxv Exp $     */
+/*     $NetBSD: ip_output.c,v 1.297 2018/02/27 15:01:30 maxv Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.296 2018/02/27 14:44:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.297 2018/02/27 15:01:30 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1263,7 +1263,7 @@
 #if defined(IPSEC)
                case IP_IPSEC_POLICY:
                        if (ipsec_enabled) {
-                               error = ipsec4_set_policy(inp, sopt->sopt_name,
+                               error = ipsec_set_policy(inp, sopt->sopt_name,
                                    sopt->sopt_data, sopt->sopt_size,
                                    curlwp->l_cred);
                                break;
diff -r 403337ee3db6 -r bd76dccfa97a sys/netinet6/ip6_output.c
--- a/sys/netinet6/ip6_output.c Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/netinet6/ip6_output.c Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_output.c,v 1.202 2018/02/27 14:44:10 maxv Exp $    */
+/*     $NetBSD: ip6_output.c,v 1.203 2018/02/27 15:01:30 maxv Exp $    */
 /*     $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $    */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.202 2018/02/27 14:44:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.203 2018/02/27 15:01:30 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1773,7 +1773,7 @@
 #if defined(IPSEC)
                case IPV6_IPSEC_POLICY:
                        if (ipsec_enabled) {
-                               error = ipsec6_set_policy(in6p, optname,
+                               error = ipsec_set_policy(in6p, optname,
                                    sopt->sopt_data, sopt->sopt_size,
                                    kauth_cred_get());
                                break;
diff -r 403337ee3db6 -r bd76dccfa97a sys/netipsec/ipsec.c
--- a/sys/netipsec/ipsec.c      Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/netipsec/ipsec.c      Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.145 2018/02/27 14:52:51 maxv Exp $ */
+/* $NetBSD: ipsec.c,v 1.146 2018/02/27 15:01:30 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.145 2018/02/27 14:52:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.146 2018/02/27 15:01:30 maxv Exp $");
 
 /*
  * IPsec controller part.
@@ -185,8 +185,6 @@
 #if 0 /* unused */
 static struct secpolicy *ipsec_deepcopy_policy(const struct secpolicy *);
 #endif
-static int ipsec_set_policy(struct secpolicy **, int, const void *, size_t,
-    kauth_cred_t);
 static void ipsec_destroy_policy(struct secpolicy *);
 static int ipsec_sp_reject(const struct secpolicy *, const struct mbuf *);
 static void vshiftl(unsigned char *, int, int);
@@ -1272,21 +1270,44 @@
        }
 }
 
-/* set policy and ipsec request if present. */
-static int
-ipsec_set_policy(struct secpolicy **policy, int optname, const void *request,
-    size_t len, kauth_cred_t cred)
+int
+ipsec_set_policy(void *inp, int optname, const void *request, size_t len,
+    kauth_cred_t cred)
 {
+       struct inpcb_hdr *inph = (struct inpcb_hdr *)inp;
        const struct sadb_x_policy *xpl;
        struct secpolicy *newsp, *oldsp;
+       struct secpolicy **policy;
        int error;
 
        KASSERT(!cpu_softintr_p());
+       KASSERT(inph != NULL);
+       KASSERT(inph_locked(inph));
+       KASSERT(request != NULL);
+
+       if (len < sizeof(*xpl))
+               return EINVAL;
+       xpl = (const struct sadb_x_policy *)request;
+
+       KASSERT(inph->inph_sp != NULL);
+
+       /* select direction */
+       switch (xpl->sadb_x_policy_dir) {
+       case IPSEC_DIR_INBOUND:
+               policy = &inph->inph_sp->sp_in;
+               break;
+       case IPSEC_DIR_OUTBOUND:
+               policy = &inph->inph_sp->sp_out;
+               break;
+       default:
+               IPSECLOG(LOG_ERR, "invalid direction=%u\n",
+                   xpl->sadb_x_policy_dir);
+               return EINVAL;
+       }
 
        /* sanity check. */
        if (policy == NULL || *policy == NULL)
                return EINVAL;
-       xpl = (const struct sadb_x_policy *)request;
 
        if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
                kdebug_sadb_xpolicy("set passed policy", request);
@@ -1329,42 +1350,6 @@
 }
 
 int
-ipsec4_set_policy(struct inpcb *inp, int optname, const void *request,
-    size_t len, kauth_cred_t cred)
-{
-       struct inpcb_hdr *inph = (struct inpcb_hdr *)inp;
-       const struct sadb_x_policy *xpl;
-       struct secpolicy **policy;
-
-       KASSERT(!cpu_softintr_p());
-       KASSERT(inph != NULL);
-       KASSERT(inph_locked(inph));
-       KASSERT(request != NULL);
-
-       if (len < sizeof(*xpl))
-               return EINVAL;
-       xpl = (const struct sadb_x_policy *)request;
-
-       KASSERT(inph->inph_sp != NULL);
-
-       /* select direction */
-       switch (xpl->sadb_x_policy_dir) {
-       case IPSEC_DIR_INBOUND:
-               policy = &inph->inph_sp->sp_in;
-               break;
-       case IPSEC_DIR_OUTBOUND:
-               policy = &inph->inph_sp->sp_out;
-               break;
-       default:
-               IPSECLOG(LOG_ERR, "invalid direction=%u\n",
-                   xpl->sadb_x_policy_dir);
-               return EINVAL;
-       }
-
-       return ipsec_set_policy(policy, optname, request, len, cred);
-}
-
-int
 ipsec_get_policy(void *inp, const void *request, size_t len,
     struct mbuf **mp)
 {
@@ -1435,42 +1420,6 @@
        return 0;
 }
 
-#ifdef INET6
-int
-ipsec6_set_policy(struct in6pcb *in6p, int optname, const void *request,
-    size_t len, kauth_cred_t cred)
-{
-       struct inpcb_hdr *inph = (struct inpcb_hdr *)in6p;
-       const struct sadb_x_policy *xpl;
-       struct secpolicy **policy;
-
-       KASSERT(!cpu_softintr_p());
-       KASSERT(inph != NULL);
-       KASSERT(inph_locked(inph));
-       KASSERT(request != NULL);
-
-       if (len < sizeof(*xpl))
-               return EINVAL;
-       xpl = (const struct sadb_x_policy *)request;
-
-       /* select direction */
-       switch (xpl->sadb_x_policy_dir) {
-       case IPSEC_DIR_INBOUND:
-               policy = &inph->inph_sp->sp_in;
-               break;
-       case IPSEC_DIR_OUTBOUND:
-               policy = &inph->inph_sp->sp_out;
-               break;
-       default:
-               IPSECLOG(LOG_ERR, "invalid direction=%u\n",
-                   xpl->sadb_x_policy_dir);
-               return EINVAL;
-       }
-
-       return ipsec_set_policy(policy, optname, request, len, cred);
-}
-#endif
-
 /*
  * Return the current level (either IPSEC_LEVEL_USE or IPSEC_LEVEL_REQUIRE).
  */
diff -r 403337ee3db6 -r bd76dccfa97a sys/netipsec/ipsec.h
--- a/sys/netipsec/ipsec.h      Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/netipsec/ipsec.h      Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipsec.h,v 1.70 2018/02/27 14:44:10 maxv Exp $  */
+/*     $NetBSD: ipsec.h,v 1.71 2018/02/27 15:01:30 maxv Exp $  */
 /*     $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $       */
 /*     $KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $  */
 
@@ -291,7 +291,7 @@
 int ipsec_copy_policy(const struct inpcbpolicy *, struct inpcbpolicy *);
 u_int ipsec_get_reqlevel(const struct ipsecrequest *);
 
-int ipsec4_set_policy(struct inpcb *, int, const void *, size_t, kauth_cred_t);
+int ipsec_set_policy(void *, int, const void *, size_t, kauth_cred_t);
 int ipsec_get_policy(void *, const void *, size_t, struct mbuf **);
 int ipsec_delete_pcbpolicy(void *);
 int ipsec_in_reject(struct mbuf *, void *);
diff -r 403337ee3db6 -r bd76dccfa97a sys/netipsec/ipsec6.h
--- a/sys/netipsec/ipsec6.h     Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/netipsec/ipsec6.h     Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipsec6.h,v 1.25 2018/02/27 14:44:10 maxv Exp $ */
+/*     $NetBSD: ipsec6.h,v 1.26 2018/02/27 15:01:30 maxv Exp $ */
 /*     $FreeBSD: src/sys/netipsec/ipsec6.h,v 1.1.4.1 2003/01/24 05:11:35 sam Exp $     */
 /*     $KAME: ipsec.h,v 1.44 2001/03/23 08:08:47 itojun Exp $  */
 
@@ -53,7 +53,6 @@
 struct inpcb;
 struct in6pcb;
 
-int ipsec6_set_policy(struct in6pcb *, int, const void *, size_t, kauth_cred_t);
 struct secpolicy *ipsec6_check_policy(struct mbuf *, 
     struct in6pcb *, int, int*,int*);
 
diff -r 403337ee3db6 -r bd76dccfa97a sys/rump/librump/rumpnet/net_stub.c
--- a/sys/rump/librump/rumpnet/net_stub.c       Tue Feb 27 14:52:51 2018 +0000
+++ b/sys/rump/librump/rumpnet/net_stub.c       Tue Feb 27 15:01:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net_stub.c,v 1.30 2018/02/27 14:45:43 maxv Exp $       */
+/*     $NetBSD: net_stub.c,v 1.31 2018/02/27 15:01:30 maxv Exp $       */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.30 2018/02/27 14:45:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.31 2018/02/27 15:01:30 maxv Exp $");
 
 #include <sys/mutex.h>
 #include <sys/param.h>
@@ -91,12 +91,11 @@
 __weak_alias(ipsec4_common_input,rumpnet_stub);
 __weak_alias(ipsec4_forward,rumpnet_stub);
 __weak_alias(ipsec4_input,rumpnet_stub);
-__weak_alias(ipsec4_set_policy,rumpnet_stub);
 __weak_alias(ipsec6_common_input,rumpnet_stub);
 __weak_alias(ipsec6_input,rumpnet_stub);
 __weak_alias(ipsec6_check_policy,rumpnet_stub);
 __weak_alias(ipsec6_process_packet,rumpnet_stub);
-__weak_alias(ipsec6_set_policy,rumpnet_stub);
+__weak_alias(ipsec_set_policy,rumpnet_stub);
 __weak_alias(ipsec_get_policy,rumpnet_stub);
 __weak_alias(ipsec_delete_pcbpolicy,rumpnet_stub);
 __weak_alias(ipsec_hdrsiz,rumpnet_stub);



Home | Main Index | Thread Index | Old Index