Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netipsec Use M_WAITOK to allocate mbufs wherever sleepable
details: https://anonhg.NetBSD.org/src/rev/3d51d7800bf1
branches: trunk
changeset: 357678:3d51d7800bf1
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Tue Nov 21 07:03:08 2017 +0000
description:
Use M_WAITOK to allocate mbufs wherever sleepable
Further changes will get rid of unnecessary NULL checks then.
diffstat:
sys/netipsec/ipsec.c | 6 +-
sys/netipsec/key.c | 165 +++++++++++++++++++++++++++-----------------------
sys/netipsec/key.h | 4 +-
3 files changed, 93 insertions(+), 82 deletions(-)
diffs (truncated from 681 to 300 lines):
diff -r e7cad60e11c4 -r 3d51d7800bf1 sys/netipsec/ipsec.c
--- a/sys/netipsec/ipsec.c Tue Nov 21 06:52:51 2017 +0000
+++ b/sys/netipsec/ipsec.c Tue Nov 21 07:03:08 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.122 2017/10/17 07:23:08 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.123 2017/11/21 07:03:08 ozaki-r Exp $ */
/* $FreeBSD: /usr/local/www/cvsroot/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.122 2017/10/17 07:23:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.123 2017/11/21 07:03:08 ozaki-r Exp $");
/*
* IPsec controller part.
@@ -1422,7 +1422,7 @@
if (policy == NULL || mp == NULL)
return EINVAL;
- *mp = key_sp2msg(policy);
+ *mp = key_sp2msg(policy, M_NOWAIT);
if (!*mp) {
IPSECLOG(LOG_DEBUG, "No more memory.\n");
return ENOBUFS;
diff -r e7cad60e11c4 -r 3d51d7800bf1 sys/netipsec/key.c
--- a/sys/netipsec/key.c Tue Nov 21 06:52:51 2017 +0000
+++ b/sys/netipsec/key.c Tue Nov 21 07:03:08 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.238 2017/11/21 06:52:51 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.239 2017/11/21 07:03:08 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.238 2017/11/21 06:52:51 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.239 2017/11/21 07:03:08 ozaki-r Exp $");
/*
* This code is referred to RFC 2367
@@ -684,17 +684,17 @@
static void key_porttosaddr (union sockaddr_union *, u_int16_t);
static int key_checksalen (const union sockaddr_union *);
static struct mbuf *key_setsadbmsg (u_int8_t, u_int16_t, u_int8_t,
- u_int32_t, pid_t, u_int16_t);
+ u_int32_t, pid_t, u_int16_t, int);
static struct mbuf *key_setsadbsa (struct secasvar *);
-static struct mbuf *key_setsadbaddr (u_int16_t,
- const struct sockaddr *, u_int8_t, u_int16_t);
+static struct mbuf *key_setsadbaddr(u_int16_t,
+ const struct sockaddr *, u_int8_t, u_int16_t, int);
#if 0
static struct mbuf *key_setsadbident (u_int16_t, u_int16_t, void *,
int, u_int64_t);
#endif
static struct mbuf *key_setsadbxsa2 (u_int8_t, u_int32_t, u_int16_t);
static struct mbuf *key_setsadbxpolicy (u_int16_t, u_int8_t,
- u_int32_t);
+ u_int32_t, int);
static void *key_newbuf (const void *, u_int);
#ifdef INET6
static int key_ismyaddr6 (const struct sockaddr_in6 *);
@@ -748,12 +748,13 @@
const struct sadb_msghdr *);
static void key_getcomb_setlifetime (struct sadb_comb *);
-static struct mbuf *key_getcomb_esp (void);
-static struct mbuf *key_getcomb_ah (void);
-static struct mbuf *key_getcomb_ipcomp (void);
-static struct mbuf *key_getprop (const struct secasindex *);
-
-static int key_acquire(const struct secasindex *, const struct secpolicy *);
+static struct mbuf *key_getcomb_esp(int);
+static struct mbuf *key_getcomb_ah(int);
+static struct mbuf *key_getcomb_ipcomp(int);
+static struct mbuf *key_getprop(const struct secasindex *, int);
+
+static int key_acquire(const struct secasindex *, const struct secpolicy *,
+ int);
static int key_acquire_sendup_mbuf_later(struct mbuf *);
static void key_acquire_sendup_pending_mbuf(void);
#ifndef IPSEC_NONBLOCK_ACQUIRE
@@ -787,7 +788,7 @@
#endif
static void key_sa_chgstate (struct secasvar *, u_int8_t);
-static struct mbuf *key_alloc_mbuf (int);
+static struct mbuf *key_alloc_mbuf(int, int);
static struct mbuf *key_alloc_mbuf_simple(int, int);
static void key_timehandler(void *);
@@ -1026,7 +1027,7 @@
}
/* there is no SA */
- error = key_acquire(saidx, isr->sp);
+ error = key_acquire(saidx, isr->sp, M_NOWAIT);
if (error != 0) {
/* XXX What should I do ? */
IPSECLOG(LOG_DEBUG, "error %d returned from key_acquire.\n",
@@ -1970,7 +1971,7 @@
* copy secpolicy struct to sadb_x_policy structure indicated.
*/
struct mbuf *
-key_sp2msg(const struct secpolicy *sp)
+key_sp2msg(const struct secpolicy *sp, int mflag)
{
struct sadb_x_policy *xpl;
int tlen;
@@ -1981,7 +1982,7 @@
tlen = key_getspreqmsglen(sp);
- m = key_alloc_mbuf(tlen);
+ m = key_alloc_mbuf(tlen, mflag);
if (!m || m->m_next) { /*XXX*/
if (m)
m_freem(m);
@@ -2043,6 +2044,7 @@
KASSERT(m != NULL);
KASSERT(mhp != NULL);
+ KASSERT(!cpu_softintr_p());
va_start(ap, nitem);
for (i = 0; i < nitem; i++) {
@@ -2059,7 +2061,7 @@
if (idx == SADB_EXT_RESERVED) {
CTASSERT(PFKEY_ALIGN8(sizeof(struct sadb_msg)) <= MHLEN);
len = PFKEY_ALIGN8(sizeof(struct sadb_msg));
- MGETHDR(n, M_DONTWAIT, MT_DATA);
+ MGETHDR(n, M_WAITOK, MT_DATA);
if (!n)
goto fail;
n->m_len = len;
@@ -2068,7 +2070,7 @@
mtod(n, void *));
} else if (i < ndeep) {
len = mhp->extlen[idx];
- n = key_alloc_mbuf(len);
+ n = key_alloc_mbuf(len, M_WAITOK);
if (!n || n->m_next) { /*XXX*/
if (n)
m_freem(n);
@@ -2078,7 +2080,7 @@
mtod(n, void *));
} else {
n = m_copym(m, mhp->extoff[idx], mhp->extlen[idx],
- M_DONTWAIT);
+ M_WAITOK);
}
if (n == NULL)
goto fail;
@@ -2422,6 +2424,8 @@
{
struct mbuf *n;
+ KASSERT(mflag == M_NOWAIT || (mflag == M_WAITOK && !cpu_softintr_p()));
+
MGETHDR(n, mflag, MT_DATA);
if (n && len > MHLEN) {
MCLGET(n, mflag);
@@ -2482,7 +2486,7 @@
/* create new sadb_msg to reply. */
len = PFKEY_ALIGN8(sizeof(struct sadb_msg));
- n = key_alloc_mbuf_simple(len, M_DONTWAIT);
+ n = key_alloc_mbuf_simple(len, M_WAITOK);
if (!n)
return key_senderror(so, m, ENOBUFS);
@@ -2496,7 +2500,7 @@
KASSERTMSG(off == len, "length inconsistency");
n->m_next = m_copym(m, mhp->extoff[SADB_X_EXT_POLICY],
- mhp->extlen[SADB_X_EXT_POLICY], M_DONTWAIT);
+ mhp->extlen[SADB_X_EXT_POLICY], M_WAITOK);
if (!n->m_next) {
m_freem(n);
return key_senderror(so, m, ENOBUFS);
@@ -2886,25 +2890,27 @@
{
struct mbuf *result = NULL, *m;
+ KASSERT(!cpu_softintr_p());
+
m = key_setsadbmsg(type, 0, SADB_SATYPE_UNSPEC, seq, pid,
- key_sp_refcnt(sp));
+ key_sp_refcnt(sp), M_WAITOK);
if (!m)
goto fail;
result = m;
m = key_setsadbaddr(SADB_EXT_ADDRESS_SRC,
- &sp->spidx.src.sa, sp->spidx.prefs, sp->spidx.ul_proto);
+ &sp->spidx.src.sa, sp->spidx.prefs, sp->spidx.ul_proto, M_WAITOK);
if (!m)
goto fail;
m_cat(result, m);
m = key_setsadbaddr(SADB_EXT_ADDRESS_DST,
- &sp->spidx.dst.sa, sp->spidx.prefd, sp->spidx.ul_proto);
+ &sp->spidx.dst.sa, sp->spidx.prefd, sp->spidx.ul_proto, M_WAITOK);
if (!m)
goto fail;
m_cat(result, m);
- m = key_sp2msg(sp);
+ m = key_sp2msg(sp, M_WAITOK);
if (!m)
goto fail;
m_cat(result, m);
@@ -2986,7 +2992,7 @@
KASSERT(sp != NULL);
/* set msg header */
- m = key_setsadbmsg(SADB_X_SPDEXPIRE, 0, 0, 0, 0, 0);
+ m = key_setsadbmsg(SADB_X_SPDEXPIRE, 0, 0, 0, 0, 0, M_WAITOK);
if (!m) {
error = ENOBUFS;
goto fail;
@@ -2995,7 +3001,7 @@
/* create lifetime extension (current and hard) */
len = PFKEY_ALIGN8(sizeof(*lt)) * 2;
- m = key_alloc_mbuf(len);
+ m = key_alloc_mbuf(len, M_WAITOK);
if (!m || m->m_next) { /*XXX*/
if (m)
m_freem(m);
@@ -3021,7 +3027,7 @@
/* set sadb_address for source */
m = key_setsadbaddr(SADB_EXT_ADDRESS_SRC, &sp->spidx.src.sa,
- sp->spidx.prefs, sp->spidx.ul_proto);
+ sp->spidx.prefs, sp->spidx.ul_proto, M_WAITOK);
if (!m) {
error = ENOBUFS;
goto fail;
@@ -3030,7 +3036,7 @@
/* set sadb_address for destination */
m = key_setsadbaddr(SADB_EXT_ADDRESS_DST, &sp->spidx.dst.sa,
- sp->spidx.prefd, sp->spidx.ul_proto);
+ sp->spidx.prefd, sp->spidx.ul_proto, M_WAITOK);
if (!m) {
error = ENOBUFS;
goto fail;
@@ -3038,7 +3044,7 @@
m_cat(result, m);
/* set secpolicy */
- m = key_sp2msg(sp);
+ m = key_sp2msg(sp, M_WAITOK);
if (!m) {
error = ENOBUFS;
goto fail;
@@ -3743,7 +3749,7 @@
};
- m = key_setsadbmsg(type, 0, satype, seq, pid, key_sa_refcnt(sav));
+ m = key_setsadbmsg(type, 0, satype, seq, pid, key_sa_refcnt(sav), M_WAITOK);
if (m == NULL)
goto fail;
result = m;
@@ -3765,13 +3771,13 @@
case SADB_EXT_ADDRESS_SRC:
m = key_setsadbaddr(SADB_EXT_ADDRESS_SRC,
&sav->sah->saidx.src.sa,
- FULLMASK, IPSEC_ULPROTO_ANY);
+ FULLMASK, IPSEC_ULPROTO_ANY, M_WAITOK);
break;
case SADB_EXT_ADDRESS_DST:
m = key_setsadbaddr(SADB_EXT_ADDRESS_DST,
&sav->sah->saidx.dst.sa,
- FULLMASK, IPSEC_ULPROTO_ANY);
+ FULLMASK, IPSEC_ULPROTO_ANY, M_WAITOK);
break;
case SADB_EXT_KEY_AUTH:
@@ -3857,14 +3863,14 @@
if (!m && !p)
goto fail;
if (p && tres) {
- M_PREPEND(tres, l, M_DONTWAIT);
+ M_PREPEND(tres, l, M_WAITOK);
if (!tres)
goto fail;
memcpy(mtod(tres, void *), p, l);
continue;
}
if (p) {
- m = key_alloc_mbuf(l);
Home |
Main Index |
Thread Index |
Old Index