Source-Changes-HG archive

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

[src/trunk]: src/sys/netipsec Change the prefix of function names of SADB API...



details:   https://anonhg.NetBSD.org/src/rev/848c79ee74b5
branches:  trunk
changeset: 824335:848c79ee74b5
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Jun 02 01:22:50 2017 +0000

description:
Change the prefix of function names of SADB API handlers to key_api_

By doing so we can easily distinguish them from other utility functions.
And so we can easily know that they are all called from key_parse and
applied assumptions that the arguments are always non-NULL and they
are always called from userland, i.e., never called from interrupt
context (softint). As a result, we can omit some tedious assertions
in the functions.

diffstat:

 sys/netipsec/key.c |  231 ++++++++++++++++------------------------------------
 1 files changed, 72 insertions(+), 159 deletions(-)

diffs (truncated from 595 to 300 lines):

diff -r 438d68fc2f65 -r 848c79ee74b5 sys/netipsec/key.c
--- a/sys/netipsec/key.c        Fri Jun 02 01:18:51 2017 +0000
+++ b/sys/netipsec/key.c        Fri Jun 02 01:22:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: key.c,v 1.161 2017/06/01 09:50:35 ozaki-r Exp $        */
+/*     $NetBSD: key.c,v 1.162 2017/06/02 01:22:50 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.161 2017/06/01 09:50:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.162 2017/06/02 01:22:50 ozaki-r Exp $");
 
 /*
  * This code is referd to RFC 2367
@@ -400,22 +400,22 @@
 static u_int16_t key_newreqid (void);
 static struct mbuf *key_gather_mbuf (struct mbuf *,
        const struct sadb_msghdr *, int, int, ...);
-static int key_spdadd (struct socket *, struct mbuf *,
+static int key_api_spdadd(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static u_int32_t key_getnewspid (void);
-static int key_spddelete (struct socket *, struct mbuf *,
+static int key_api_spddelete(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_spddelete2 (struct socket *, struct mbuf *,
+static int key_api_spddelete2(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_spdget (struct socket *, struct mbuf *,
+static int key_api_spdget(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_spdflush (struct socket *, struct mbuf *,
+static int key_api_spdflush(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_spddump (struct socket *, struct mbuf *,
+static int key_api_spddump(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static struct mbuf * key_setspddump (int *errorp, pid_t);
 static struct mbuf * key_setspddump_chain (int *errorp, int *lenp, pid_t pid);
-static int key_nat_map (struct socket *, struct mbuf *,
+static int key_api_nat_map(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static struct mbuf *key_setdumpsp (struct secpolicy *,
        u_int8_t, u_int32_t, pid_t);
@@ -482,7 +482,7 @@
 static int key_spidx_match_withmask(const struct secpolicyindex *,
     const struct secpolicyindex *);
 
-static int key_getspi (struct socket *, struct mbuf *,
+static int key_api_getspi(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static u_int32_t key_do_getnewspi (const struct sadb_spirange *,
                                        const struct secasindex *);
@@ -491,20 +491,20 @@
 static int key_set_natt_ports (union sockaddr_union *,
                                union sockaddr_union *,
                                const struct sadb_msghdr *);
-static int key_update (struct socket *, struct mbuf *,
+static int key_api_update(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 #ifdef IPSEC_DOSEQCHECK
 static struct secasvar *key_getsavbyseq (struct secashead *, u_int32_t);
 #endif
-static int key_add (struct socket *, struct mbuf *,
+static int key_api_add(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static int key_setident (struct secashead *, struct mbuf *,
        const struct sadb_msghdr *);
 static struct mbuf *key_getmsgbuf_x1 (struct mbuf *,
        const struct sadb_msghdr *);
-static int key_delete (struct socket *, struct mbuf *,
+static int key_api_delete(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_get (struct socket *, struct mbuf *,
+static int key_api_get(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 
 static void key_getcomb_setlifetime (struct sadb_comb *);
@@ -523,18 +523,18 @@
 static struct secspacq *key_newspacq (const struct secpolicyindex *);
 static struct secspacq *key_getspacq (const struct secpolicyindex *);
 #endif
-static int key_acquire2 (struct socket *, struct mbuf *,
+static int key_api_acquire(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_register (struct socket *, struct mbuf *,
+static int key_api_register(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static int key_expire (struct secasvar *);
-static int key_flush (struct socket *, struct mbuf *,
+static int key_api_flush(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static struct mbuf *key_setdump_chain (u_int8_t req_satype, int *errorp,
        int *lenp, pid_t pid);
-static int key_dump (struct socket *, struct mbuf *,
+static int key_api_dump(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
-static int key_promisc (struct socket *, struct mbuf *,
+static int key_api_promisc(struct socket *, struct mbuf *,
        const struct sadb_msghdr *);
 static int key_senderror (struct socket *, struct mbuf *, int);
 static int key_validate_ext (const struct sadb_ext *, int);
@@ -1858,7 +1858,7 @@
  * m will always be freed.
  */
 static int
-key_spdadd(struct socket *so, struct mbuf *m,
+key_api_spdadd(struct socket *so, struct mbuf *m,
           const struct sadb_msghdr *mhp)
 {
        const struct sockaddr *src, *dst;
@@ -1869,12 +1869,6 @@
        struct secpolicy *newsp;
        int error;
 
-       KASSERT(!cpu_softintr_p());
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_EXT_ADDRESS_SRC] == NULL ||
            mhp->ext[SADB_EXT_ADDRESS_DST] == NULL ||
            mhp->ext[SADB_X_EXT_POLICY] == NULL) {
@@ -1909,7 +1903,7 @@
        }
 
        /* check policy */
-       /* key_spdadd() accepts DISCARD, NONE and IPSEC. */
+       /* key_api_spdadd() accepts DISCARD, NONE and IPSEC. */
        if (xpl0->sadb_x_policy_type == IPSEC_POLICY_ENTRUST ||
            xpl0->sadb_x_policy_type == IPSEC_POLICY_BYPASS) {
                IPSECLOG(LOG_DEBUG, "Invalid policy type.\n");
@@ -2094,18 +2088,13 @@
  * m will always be freed.
  */
 static int
-key_spddelete(struct socket *so, struct mbuf *m,
+key_api_spddelete(struct socket *so, struct mbuf *m,
               const struct sadb_msghdr *mhp)
 {
        struct sadb_x_policy *xpl0;
        struct secpolicyindex spidx;
        struct secpolicy *sp;
 
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_EXT_ADDRESS_SRC] == NULL ||
            mhp->ext[SADB_EXT_ADDRESS_DST] == NULL ||
            mhp->ext[SADB_X_EXT_POLICY] == NULL) {
@@ -2185,17 +2174,12 @@
  * m will always be freed.
  */
 static int
-key_spddelete2(struct socket *so, struct mbuf *m,
+key_api_spddelete2(struct socket *so, struct mbuf *m,
               const struct sadb_msghdr *mhp)
 {
        u_int32_t id;
        struct secpolicy *sp;
 
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_X_EXT_POLICY] == NULL ||
            mhp->extlen[SADB_X_EXT_POLICY] < sizeof(struct sadb_x_policy)) {
                IPSECLOG(LOG_DEBUG, "invalid message is passed.\n");
@@ -2283,18 +2267,13 @@
  * m will always be freed.
  */
 static int
-key_spdget(struct socket *so, struct mbuf *m,
+key_api_spdget(struct socket *so, struct mbuf *m,
           const struct sadb_msghdr *mhp)
 {
        u_int32_t id;
        struct secpolicy *sp;
        struct mbuf *n;
 
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_X_EXT_POLICY] == NULL ||
            mhp->extlen[SADB_X_EXT_POLICY] < sizeof(struct sadb_x_policy)) {
                IPSECLOG(LOG_DEBUG, "invalid message is passed.\n");
@@ -2406,18 +2385,13 @@
  * m will always be freed.
  */
 static int
-key_spdflush(struct socket *so, struct mbuf *m,
+key_api_spdflush(struct socket *so, struct mbuf *m,
             const struct sadb_msghdr *mhp)
 {
        struct sadb_msg *newmsg;
        struct secpolicy *sp;
        u_int dir;
 
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (m->m_len != PFKEY_ALIGN8(sizeof(struct sadb_msg)))
                return key_senderror(so, m, EINVAL);
 
@@ -2525,7 +2499,7 @@
  * m will always be freed.
  */
 static int
-key_spddump(struct socket *so, struct mbuf *m0,
+key_api_spddump(struct socket *so, struct mbuf *m0,
            const struct sadb_msghdr *mhp)
 {
        struct mbuf *n;
@@ -2533,11 +2507,6 @@
        int ok, s;
        pid_t pid;
 
-       KASSERT(so != NULL);
-       KASSERT(m0 != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        pid = mhp->msg->sadb_msg_pid;
        /*
         * If the requestor has insufficient socket-buffer space
@@ -2594,7 +2563,7 @@
  * SADB_X_NAT_T_NEW_MAPPING. Unused by racoon as of 2005/04/23
  */
 static int
-key_nat_map(struct socket *so, struct mbuf *m,
+key_api_nat_map(struct socket *so, struct mbuf *m,
            const struct sadb_msghdr *mhp)
 {
        struct sadb_x_nat_t_type *type;
@@ -2603,11 +2572,6 @@
        struct sadb_address *iaddr, *raddr;
        struct sadb_x_nat_t_frag *frag;
 
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_X_EXT_NAT_T_TYPE] == NULL ||
            mhp->ext[SADB_X_EXT_NAT_T_SPORT] == NULL ||
            mhp->ext[SADB_X_EXT_NAT_T_DPORT] == NULL) {
@@ -2926,7 +2890,8 @@
 }
 
 /*
- * allocating a new SA with LARVAL state.  key_add() and key_getspi() call,
+ * allocating a new SA with LARVAL state.
+ * key_api_add() and key_api_getspi() call,
  * and copy the values of mhp into new buffer.
  * When SAD message type is GETSPI:
  *     to set sequence number from acq_seq++,
@@ -4844,7 +4809,7 @@
  *     other if success, return pointer to the message to send.
  */
 static int
-key_getspi(struct socket *so, struct mbuf *m,
+key_api_getspi(struct socket *so, struct mbuf *m,
           const struct sadb_msghdr *mhp)
 {
        const struct sockaddr *src, *dst;
@@ -4857,12 +4822,6 @@
        u_int16_t reqid;
        int error;
 
-       KASSERT(!cpu_softintr_p());
-       KASSERT(so != NULL);
-       KASSERT(m != NULL);
-       KASSERT(mhp != NULL);
-       KASSERT(mhp->msg != NULL);
-
        if (mhp->ext[SADB_EXT_ADDRESS_SRC] == NULL ||
            mhp->ext[SADB_EXT_ADDRESS_DST] == NULL) {
                IPSECLOG(LOG_DEBUG, "invalid message is passed.\n");
@@ -5007,7 +4966,7 @@
 
 /*
  * allocating new SPI
- * called by key_getspi().
+ * called by key_api_getspi().
  * OUT:
  *     0:      failure.
  *     others: success.
@@ -5214,7 +5173,7 @@



Home | Main Index | Thread Index | Old Index