Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netipsec KNF
details: https://anonhg.NetBSD.org/src/rev/1fc79b41317b
branches: trunk
changeset: 353770:1fc79b41317b
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Mon May 22 04:40:23 2017 +0000
description:
KNF
And avoid calling a function, assigning a result to a variable, and
comparing it all together in one condition expression.
diffstat:
sys/netipsec/key.c | 432 ++++++++++++++++++++++++++++------------------------
1 files changed, 232 insertions(+), 200 deletions(-)
diffs (truncated from 1176 to 300 lines):
diff -r cb459733f308 -r 1fc79b41317b sys/netipsec/key.c
--- a/sys/netipsec/key.c Mon May 22 04:23:55 2017 +0000
+++ b/sys/netipsec/key.c Mon May 22 04:40:23 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.136 2017/05/22 04:23:55 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.137 2017/05/22 04:40:23 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.136 2017/05/22 04:23:55 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.137 2017/05/22 04:40:23 ozaki-r Exp $");
/*
* This code is referd to RFC 2367
@@ -981,7 +981,7 @@
/* What the best method is to compare ? */
if (key_prefered_oldsa) {
if (candidate->lft_c->sadb_lifetime_addtime >
- sav->lft_c->sadb_lifetime_addtime) {
+ sav->lft_c->sadb_lifetime_addtime) {
candidate = sav;
}
continue;
@@ -990,7 +990,7 @@
/* prefered new sa rather than old sa */
if (candidate->lft_c->sadb_lifetime_addtime <
- sav->lft_c->sadb_lifetime_addtime) {
+ sav->lft_c->sadb_lifetime_addtime) {
d = candidate;
candidate = sav;
} else
@@ -1021,18 +1021,18 @@
/* set sadb_address for saidx's. */
m = key_setsadbaddr(SADB_EXT_ADDRESS_SRC,
- &d->sah->saidx.src.sa,
- d->sah->saidx.src.sa.sa_len << 3,
- IPSEC_ULPROTO_ANY);
+ &d->sah->saidx.src.sa,
+ d->sah->saidx.src.sa.sa_len << 3,
+ IPSEC_ULPROTO_ANY);
if (!m)
goto msgfail;
m_cat(result, m);
/* set sadb_address for saidx's. */
m = key_setsadbaddr(SADB_EXT_ADDRESS_DST,
- &d->sah->saidx.src.sa,
- d->sah->saidx.src.sa.sa_len << 3,
- IPSEC_ULPROTO_ANY);
+ &d->sah->saidx.src.sa,
+ d->sah->saidx.src.sa.sa_len << 3,
+ IPSEC_ULPROTO_ANY);
if (!m)
goto msgfail;
m_cat(result, m);
@@ -1045,7 +1045,7 @@
if (result->m_len < sizeof(struct sadb_msg)) {
result = m_pullup(result,
- sizeof(struct sadb_msg));
+ sizeof(struct sadb_msg));
if (result == NULL)
goto msgfail;
}
@@ -1054,10 +1054,9 @@
for (m = result; m; m = m->m_next)
result->m_pkthdr.len += m->m_len;
mtod(result, struct sadb_msg *)->sadb_msg_len =
- PFKEY_UNIT64(result->m_pkthdr.len);
-
- key_sendup_mbuf(NULL, result,
- KEY_SENDUP_REGISTERED);
+ PFKEY_UNIT64(result->m_pkthdr.len);
+
+ key_sendup_mbuf(NULL, result, KEY_SENDUP_REGISTERED);
result = 0;
msgfail:
if (result)
@@ -1467,7 +1466,8 @@
return NULL;
}
- if ((newsp = KEY_NEWSP()) == NULL) {
+ newsp = KEY_NEWSP();
+ if (newsp == NULL) {
*error = ENOBUFS;
return NULL;
}
@@ -1574,8 +1574,8 @@
/* allocate new reqid id if reqid is zero. */
if (xisr_reqid == 0) {
- u_int16_t reqid;
- if ((reqid = key_newreqid()) == 0) {
+ u_int16_t reqid = key_newreqid();
+ if (reqid == 0) {
*error = ENOBUFS;
goto free_exit;
}
@@ -1601,8 +1601,7 @@
paddr = (const struct sockaddr *)(xisr + 1);
/* validity check */
- if (paddr->sa_len
- > sizeof((*p_isr)->saidx.src)) {
+ if (paddr->sa_len > sizeof((*p_isr)->saidx.src)) {
IPSECLOG(LOG_DEBUG, "invalid request "
"address length.\n");
*error = EINVAL;
@@ -1611,11 +1610,10 @@
memcpy(&(*p_isr)->saidx.src, paddr, paddr->sa_len);
paddr = (const struct sockaddr *)((const char *)paddr
- + paddr->sa_len);
+ + paddr->sa_len);
/* validity check */
- if (paddr->sa_len
- > sizeof((*p_isr)->saidx.dst)) {
+ if (paddr->sa_len > sizeof((*p_isr)->saidx.dst)) {
IPSECLOG(LOG_DEBUG, "invalid request "
"address length.\n");
*error = EINVAL;
@@ -1638,8 +1636,8 @@
goto free_exit;
}
- xisr = (const struct sadb_x_ipsecrequest *)((const char *)xisr
- + xisr->sadb_x_ipsecrequest_len);
+ xisr = (const struct sadb_x_ipsecrequest *)((const char *)xisr +
+ xisr->sadb_x_ipsecrequest_len);
}
}
@@ -1656,8 +1654,8 @@
{
static u_int16_t auto_reqid = IPSEC_MANUAL_REQID_MAX + 1;
- auto_reqid = (auto_reqid == 0xffff
- ? IPSEC_MANUAL_REQID_MAX + 1 : auto_reqid + 1);
+ auto_reqid = (auto_reqid == 0xffff ?
+ IPSEC_MANUAL_REQID_MAX + 1 : auto_reqid + 1);
/* XXX should be unique check */
@@ -1719,9 +1717,9 @@
p += isr->saidx.src.sa.sa_len;
xisr->sadb_x_ipsecrequest_len =
- PFKEY_ALIGN8(sizeof(*xisr)
- + isr->saidx.src.sa.sa_len
- + isr->saidx.dst.sa.sa_len);
+ PFKEY_ALIGN8(sizeof(*xisr)
+ + isr->saidx.src.sa.sa_len
+ + isr->saidx.dst.sa.sa_len);
}
}
@@ -1750,7 +1748,7 @@
/* don't attempt to pull empty extension */
if (idx == SADB_EXT_RESERVED && mhp->msg == NULL)
continue;
- if (idx != SADB_EXT_RESERVED &&
+ if (idx != SADB_EXT_RESERVED &&
(mhp->ext[idx] == NULL || mhp->extlen[idx] == 0))
continue;
@@ -1849,8 +1847,8 @@
return key_senderror(so, m, EINVAL);
}
if (mhp->ext[SADB_EXT_LIFETIME_HARD] != NULL) {
- if (mhp->extlen[SADB_EXT_LIFETIME_HARD]
- < sizeof(struct sadb_lifetime)) {
+ if (mhp->extlen[SADB_EXT_LIFETIME_HARD] <
+ sizeof(struct sadb_lifetime)) {
IPSECLOG(LOG_DEBUG, "invalid message is passed.\n");
return key_senderror(so, m, EINVAL);
}
@@ -1884,8 +1882,8 @@
/* check policy */
/* key_spdadd() accepts DISCARD, NONE and IPSEC. */
- if (xpl0->sadb_x_policy_type == IPSEC_POLICY_ENTRUST
- || xpl0->sadb_x_policy_type == IPSEC_POLICY_BYPASS) {
+ if (xpl0->sadb_x_policy_type == IPSEC_POLICY_ENTRUST ||
+ xpl0->sadb_x_policy_type == IPSEC_POLICY_BYPASS) {
IPSECLOG(LOG_DEBUG, "Invalid policy type.\n");
return key_senderror(so, m, EINVAL);
}
@@ -1921,11 +1919,13 @@
}
/* allocation new SP entry */
- if ((newsp = key_msg2sp(xpl0, PFKEY_EXTLEN(xpl0), &error)) == NULL) {
+ newsp = key_msg2sp(xpl0, PFKEY_EXTLEN(xpl0), &error);
+ if (newsp == NULL) {
return key_senderror(so, m, error);
}
- if ((newsp->id = key_getnewspid()) == 0) {
+ newsp->id = key_getnewspid();
+ if (newsp->id == 0) {
kmem_free(newsp, sizeof(*newsp));
return key_senderror(so, m, ENOBUFS);
}
@@ -1941,12 +1941,12 @@
/* sanity check on addr pair */
if (((const struct sockaddr *)(src0 + 1))->sa_family !=
- ((const struct sockaddr *)(dst0+ 1))->sa_family) {
+ ((const struct sockaddr *)(dst0+ 1))->sa_family) {
kmem_free(newsp, sizeof(*newsp));
return key_senderror(so, m, EINVAL);
}
if (((const struct sockaddr *)(src0 + 1))->sa_len !=
- ((const struct sockaddr *)(dst0+ 1))->sa_len) {
+ ((const struct sockaddr *)(dst0+ 1))->sa_len) {
kmem_free(newsp, sizeof(*newsp));
return key_senderror(so, m, EINVAL);
}
@@ -1962,8 +1962,8 @@
/* delete the entry in spacqtree */
if (mhp->msg->sadb_msg_type == SADB_X_SPDUPDATE) {
- struct secspacq *spacq;
- if ((spacq = key_getspacq(&spidx)) != NULL) {
+ struct secspacq *spacq = key_getspacq(&spidx);
+ if (spacq != NULL) {
/* reset counter in order to deletion by timehandler. */
spacq->created = time_uptime;
spacq->count = 0;
@@ -2046,7 +2046,8 @@
while (count--) {
newid = (policy_id = (policy_id == ~0 ? 1 : policy_id + 1));
- if ((sp = key_getspbyid(newid)) == NULL)
+ sp = key_getspbyid(newid);
+ if (sp == NULL)
break;
KEY_FREESP(&sp);
@@ -2124,7 +2125,8 @@
}
/* Is there SP in SPD ? */
- if ((sp = key_getsp(&spidx)) == NULL) {
+ sp = key_getsp(&spidx);
+ if (sp == NULL) {
IPSECLOG(LOG_DEBUG, "no SP found.\n");
return key_senderror(so, m, EINVAL);
}
@@ -2195,7 +2197,8 @@
id = ((struct sadb_x_policy *)mhp->ext[SADB_X_EXT_POLICY])->sadb_x_policy_id;
/* Is there SP in SPD ? */
- if ((sp = key_getspbyid(id)) == NULL) {
+ sp = key_getspbyid(id);
+ if (sp == NULL) {
IPSECLOG(LOG_DEBUG, "no SP found id:%u.\n", id);
return key_senderror(so, m, EINVAL);
}
@@ -2294,7 +2297,8 @@
id = ((struct sadb_x_policy *)mhp->ext[SADB_X_EXT_POLICY])->sadb_x_policy_id;
/* Is there SP in SPD ? */
- if ((sp = key_getspbyid(id)) == NULL) {
+ sp = key_getspbyid(id);
+ if (sp == NULL) {
IPSECLOG(LOG_DEBUG, "no SP found id:%u.\n", id);
return key_senderror(so, m, ENOENT);
}
@@ -2337,7 +2341,8 @@
"policy mismathed. IPsec is expected");
/* Get an entry to check whether sent message or not. */
- if ((newspacq = key_getspacq(&sp->spidx)) != NULL) {
+ newspacq = key_getspacq(&sp->spidx);
+ if (newspacq != NULL) {
if (key_blockacq_count < newspacq->count) {
/* reset counter and do send message. */
newspacq->count = 0;
@@ -2348,7 +2353,8 @@
}
} else {
/* make new entry for blocking to send SADB_ACQUIRE. */
- if ((newspacq = key_newspacq(&sp->spidx)) == NULL)
+ newspacq = key_newspacq(&sp->spidx);
+ if (newspacq == NULL)
return ENOBUFS;
/* add to acqtree */
@@ -2478,7 +2484,8 @@
if (!n) {
Home |
Main Index |
Thread Index |
Old Index