Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/netipsec Tweak KEYDEBUG macros
details: https://anonhg.NetBSD.org/src/rev/10c0f9208386
branches: trunk
changeset: 353067:10c0f9208386
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Wed Apr 19 03:42:11 2017 +0000
description:
Tweak KEYDEBUG macros
Let's avoid passing statements to a macro.
diffstat:
sys/netipsec/ipsec.c | 112 ++++++++++++++++---------------
sys/netipsec/key.c | 164 ++++++++++++++++++++++------------------------
sys/netipsec/key_debug.h | 12 ++-
sys/netipsec/keysock.c | 12 ++-
4 files changed, 154 insertions(+), 146 deletions(-)
diffs (truncated from 691 to 300 lines):
diff -r 74e09e3c5bcc -r 10c0f9208386 sys/netipsec/ipsec.c
--- a/sys/netipsec/ipsec.c Wed Apr 19 03:40:58 2017 +0000
+++ b/sys/netipsec/ipsec.c Wed Apr 19 03:42:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.76 2017/04/19 03:40:58 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.77 2017/04/19 03:42:11 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.76 2017/04/19 03:40:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.77 2017/04/19 03:42:11 ozaki-r Exp $");
/*
* IPsec controller part.
@@ -264,10 +264,10 @@
pcbsp->sp_cache[dir].cachesp->lastused = time_second;
pcbsp->sp_cache[dir].cachesp->refcnt++;
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("DP %s cause refcnt++:%d SP:%p\n", __func__,
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP,
+ "DP cause refcnt++:%d SP:%p\n",
pcbsp->sp_cache[dir].cachesp->refcnt,
- pcbsp->sp_cache[dir].cachesp));
+ pcbsp->sp_cache[dir].cachesp);
return pcbsp->sp_cache[dir].cachesp;
}
@@ -298,10 +298,10 @@
pcbsp->sp_cache[dir].cachesp = sp;
if (pcbsp->sp_cache[dir].cachesp) {
pcbsp->sp_cache[dir].cachesp->refcnt++;
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("DP %s cause refcnt++:%d SP:%p\n", __func__,
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP,
+ "DP cause refcnt++:%d SP:%p\n",
pcbsp->sp_cache[dir].cachesp->refcnt,
- pcbsp->sp_cache[dir].cachesp));
+ pcbsp->sp_cache[dir].cachesp);
/*
* If the PCB is connected, we can remember a hint to
@@ -378,8 +378,7 @@
{
struct secpolicy *sp;
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("DP %s from %s:%u\n", __func__, where, tag));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, "DP from %s:%u\n", where, tag);
switch(af) {
case AF_INET:
@@ -391,9 +390,8 @@
break;
#endif
default:
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("%s: unexpected protocol family %u\n", __func__,
- af));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP,
+ "unexpected protocol family %u\n", af);
return NULL;
}
@@ -405,8 +403,8 @@
}
sp->refcnt++;
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP, printf("DP %s returns SP:%p (%u)\n",
- __func__, sp, sp->refcnt));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, "DP returns SP:%p (%u)\n",
+ sp, sp->refcnt);
return sp;
}
#define KEY_ALLOCSP_DEFAULT(af) \
@@ -571,9 +569,9 @@
}
KASSERTMSG(sp != NULL, "null SP (priv %u policy %u", pcbsp->priv,
currsp->policy);
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("DP %s (priv %u policy %u) allocates SP:%p (refcnt %u)\n",
- __func__, pcbsp->priv, currsp->policy, sp, sp->refcnt));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP,
+ "DP (priv %u policy %u) allocates SP:%p (refcnt %u)\n",
+ pcbsp->priv, currsp->policy, sp, sp->refcnt);
ipsec_fillpcbcache(pcbsp, m, sp, dir);
return sp;
}
@@ -1001,16 +999,16 @@
for (n = m; n; n = n->m_next)
len += n->m_len;
if (m->m_pkthdr.len != len) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: total of m_len(%d) "
- "!= pkthdr.len(%d), ignored.\n", __func__, len,
- m->m_pkthdr.len));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "total of m_len(%d) != pkthdr.len(%d), ignored.\n",
+ len, m->m_pkthdr.len);
return EINVAL;
}
if (m->m_pkthdr.len < sizeof(struct ip)) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: pkthdr.len(%d) < "
- "sizeof(struct ip), ignored.\n", __func__,
- m->m_pkthdr.len));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "pkthdr.len(%d) < sizeof(struct ip), ignored.\n",
+ m->m_pkthdr.len);
return EINVAL;
}
@@ -1031,9 +1029,9 @@
#ifdef INET6
case 6:
if (m->m_pkthdr.len < sizeof(struct ip6_hdr)) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: "
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
"pkthdr.len(%d) < sizeof(struct ip6_hdr), "
- "ignored.\n", __func__, m->m_pkthdr.len));
+ "ignored.\n", m->m_pkthdr.len);
return EINVAL;
}
error = ipsec6_setspidx_ipaddr(m, spidx);
@@ -1043,8 +1041,8 @@
return 0;
#endif
default:
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: unknown IP version "
- "%u, ignored.\n", __func__, v));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "unknown IP version %u, ignored.\n", v);
return EINVAL;
}
}
@@ -1180,8 +1178,10 @@
if (m == NULL)
panic("%s: NULL pointer was passed", __func__);
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s:\n", __func__);
- kdebug_mbuf(m));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
+ printf("%s:\n", __func__);
+ kdebug_mbuf(m);
+ }
/* set default */
spidx->ul_proto = IPSEC_ULPROTO_ANY;
@@ -1421,8 +1421,10 @@
return EINVAL;
xpl = (const struct sadb_x_policy *)request;
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: passed policy\n", __func__);
- kdebug_sadb_x_policy((const struct sadb_ext *)xpl));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
+ printf("%s: passed policy\n", __func__);
+ kdebug_sadb_x_policy((const struct sadb_ext *)xpl);
+ }
/* check policy type */
/* ipsec_set_policy() accepts IPSEC, ENTRUST and BYPASS. */
@@ -1447,8 +1449,10 @@
/* clear old SP and set new SP */
KEY_FREESP(policy);
*policy = newsp;
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s: new policy\n", __func__);
- kdebug_secpolicy(newsp));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
+ printf("%s: new policy\n", __func__);
+ kdebug_secpolicy(newsp);
+ }
return 0;
}
@@ -1468,8 +1472,10 @@
}
(*mp)->m_type = MT_DATA;
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP, printf("%s:\n", __func__);
- kdebug_mbuf(*mp));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
+ printf("%s:\n", __func__);
+ kdebug_mbuf(*mp);
+ }
return 0;
}
@@ -1763,8 +1769,10 @@
struct ipsecrequest *isr;
int need_auth;
- KEYDEBUG(KEYDEBUG_IPSEC_DATA, printf("%s: using SP\n", __func__);
- kdebug_secpolicy(sp));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DATA)) {
+ printf("%s: using SP\n", __func__);
+ kdebug_secpolicy(sp);
+ }
/* check policy */
switch (sp->policy) {
@@ -1787,9 +1795,8 @@
switch (isr->saidx.proto) {
case IPPROTO_ESP:
if ((m->m_flags & M_DECRYPTED) == 0) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
- printf("%s: ESP m_flags:%x\n", __func__,
- m->m_flags));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "ESP m_flags:%x\n", m->m_flags);
return 1;
}
@@ -1797,18 +1804,16 @@
isr->sav != NULL &&
isr->sav->tdb_authalgxform != NULL &&
(m->m_flags & M_AUTHIPDGM) == 0) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
- printf("%s: ESP/AH m_flags:%x\n", __func__,
- m->m_flags));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "ESP/AH m_flags:%x\n", m->m_flags);
return 1;
}
break;
case IPPROTO_AH:
need_auth = 1;
if ((m->m_flags & M_AUTHIPHDR) == 0) {
- KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
- printf("%s: AH m_flags:%x\n", __func__,
- m->m_flags));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DUMP,
+ "AH m_flags:%x\n", m->m_flags);
return 1;
}
break;
@@ -1913,8 +1918,10 @@
const struct ipsecrequest *isr;
size_t siz;
- KEYDEBUG(KEYDEBUG_IPSEC_DATA, printf("%s: using SP\n", __func__);
- kdebug_secpolicy(sp));
+ if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DATA)) {
+ printf("%s: using SP\n", __func__);
+ kdebug_secpolicy(sp);
+ }
switch (sp->policy) {
case IPSEC_POLICY_DISCARD:
@@ -1989,8 +1996,8 @@
if (sp != NULL) {
size = ipsec_hdrsiz(sp);
- KEYDEBUG(KEYDEBUG_IPSEC_DATA, printf("%s: size:%lu.\n",
- __func__, (unsigned long)size));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DATA, "size:%lu.\n",
+ (unsigned long)size);
KEY_FREESP(&sp);
} else {
@@ -2026,8 +2033,7 @@
if (sp == NULL)
return 0;
size = ipsec_hdrsiz(sp);
- KEYDEBUG(KEYDEBUG_IPSEC_DATA,
- printf("%s: size:%zu.\n", __func__, size));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_DATA, "size:%zu.\n", size);
KEY_FREESP(&sp);
return size;
diff -r 74e09e3c5bcc -r 10c0f9208386 sys/netipsec/key.c
--- a/sys/netipsec/key.c Wed Apr 19 03:40:58 2017 +0000
+++ b/sys/netipsec/key.c Wed Apr 19 03:42:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.110 2017/04/19 03:40:58 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.111 2017/04/19 03:42:11 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.110 2017/04/19 03:40:58 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.111 2017/04/19 03:42:11 ozaki-r Exp $");
/*
* This code is referd to RFC 2367
@@ -597,19 +597,20 @@
KASSERTMSG(dir == IPSEC_DIR_INBOUND || dir == IPSEC_DIR_OUTBOUND,
"invalid direction %u", dir);
- KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
- printf("DP %s from %s:%u\n", __func__, where, tag));
+ KEYDEBUG_PRINTF(KEYDEBUG_IPSEC_STAMP, "DP from %s:%u\n", where, tag);
/* get a SP entry */
s = splsoftnet(); /*called from softclock()*/
Home |
Main Index |
Thread Index |
Old Index