Module Name: src
Committed By: christos
Date: Thu Sep 28 17:21:42 UTC 2017
Modified Files:
src/sys/netipsec: ipsec.c key.c key_debug.c key_debug.h keysock.c
Log Message:
- sanitize key debugging so that we don't print extra newlines or unassociated
debugging messages.
- remove unused functions and make internal ones static
- print information in one line per message
To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/netipsec/ipsec.c
cvs rdiff -u -r1.227 -r1.228 src/sys/netipsec/key.c
cvs rdiff -u -r1.20 -r1.21 src/sys/netipsec/key_debug.c
cvs rdiff -u -r1.8 -r1.9 src/sys/netipsec/key_debug.h
cvs rdiff -u -r1.61 -r1.62 src/sys/netipsec/keysock.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/netipsec/ipsec.c
diff -u src/sys/netipsec/ipsec.c:1.119 src/sys/netipsec/ipsec.c:1.120
--- src/sys/netipsec/ipsec.c:1.119 Mon Sep 18 22:44:14 2017
+++ src/sys/netipsec/ipsec.c Thu Sep 28 13:21:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: ipsec.c,v 1.119 2017/09/19 02:44:14 ozaki-r Exp $ */
+/* $NetBSD: ipsec.c,v 1.120 2017/09/28 17:21:42 christos 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.119 2017/09/19 02:44:14 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.120 2017/09/28 17:21:42 christos Exp $");
/*
* IPsec controller part.
@@ -1132,8 +1132,7 @@ ipsec6_get_ulp(struct mbuf *m, struct se
KASSERT(m != NULL);
if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
- printf("%s:\n", __func__);
- kdebug_mbuf(m);
+ kdebug_mbuf(__func__, m);
}
/* set default */
@@ -1375,8 +1374,7 @@ ipsec_set_policy(
xpl = (const struct sadb_x_policy *)request;
if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
- printf("%s: passed policy\n", __func__);
- kdebug_sadb_x_policy((const struct sadb_ext *)xpl);
+ kdebug_sadb_xpolicy("set passed policy", request);
}
/* check policy type */
@@ -1431,8 +1429,7 @@ ipsec_get_policy(struct secpolicy *polic
(*mp)->m_type = MT_DATA;
if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DUMP)) {
- printf("%s:\n", __func__);
- kdebug_mbuf(*mp);
+ kdebug_mbuf(__func__, *mp);
}
return 0;
Index: src/sys/netipsec/key.c
diff -u src/sys/netipsec/key.c:1.227 src/sys/netipsec/key.c:1.228
--- src/sys/netipsec/key.c:1.227 Wed Sep 27 05:55:52 2017
+++ src/sys/netipsec/key.c Thu Sep 28 13:21:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.227 2017/09/27 09:55:52 ozaki-r Exp $ */
+/* $NetBSD: key.c,v 1.228 2017/09/28 17:21:42 christos 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.227 2017/09/27 09:55:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key.c,v 1.228 2017/09/28 17:21:42 christos Exp $");
/*
* This code is referd to RFC 2367
@@ -881,15 +881,13 @@ key_lookup_sp_byspidx(const struct secpo
/* get a SP entry */
if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DATA)) {
- printf("*** objects\n");
- kdebug_secpolicyindex(spidx);
+ kdebug_secpolicyindex("objects", spidx);
}
s = pserialize_read_enter();
SPLIST_READER_FOREACH(sp, dir) {
if (KEYDEBUG_ON(KEYDEBUG_IPSEC_DATA)) {
- printf("*** in SPD\n");
- kdebug_secpolicyindex(&sp->spidx);
+ kdebug_secpolicyindex("in SPD", &sp->spidx);
}
if (sp->state == IPSEC_SPSTATE_DEAD)
@@ -7680,8 +7678,7 @@ key_parse(struct mbuf *m, struct socket
#if 0 /*kdebug_sadb assumes msg in linear buffer*/
if (KEYDEBUG_ON(KEYDEBUG_KEY_DUMP)) {
- IPSECLOG(LOG_DEBUG, "passed sadb_msg\n");
- kdebug_sadb(msg);
+ kdebug_sadb("passed sadb_msg", msg);
}
#endif
Index: src/sys/netipsec/key_debug.c
diff -u src/sys/netipsec/key_debug.c:1.20 src/sys/netipsec/key_debug.c:1.21
--- src/sys/netipsec/key_debug.c:1.20 Tue Aug 8 04:23:10 2017
+++ src/sys/netipsec/key_debug.c Thu Sep 28 13:21:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: key_debug.c,v 1.20 2017/08/08 08:23:10 ozaki-r Exp $ */
+/* $NetBSD: key_debug.c,v 1.21 2017/09/28 17:21:42 christos Exp $ */
/* $FreeBSD: src/sys/netipsec/key_debug.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */
/* $KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $ */
@@ -33,7 +33,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.20 2017/08/08 08:23:10 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: key_debug.c,v 1.21 2017/09/28 17:21:42 christos Exp $");
#endif
#if defined(_KERNEL_OPT)
@@ -62,27 +62,38 @@ __KERNEL_RCSID(0, "$NetBSD: key_debug.c,
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+#include <err.h>
#endif /* !_KERNEL */
-static void kdebug_sadb_prop (const struct sadb_ext *);
-static void kdebug_sadb_identity (const struct sadb_ext *);
-static void kdebug_sadb_supported (const struct sadb_ext *);
-static void kdebug_sadb_lifetime (const struct sadb_ext *);
-static void kdebug_sadb_sa (const struct sadb_ext *);
-static void kdebug_sadb_address (const struct sadb_ext *);
-static void kdebug_sadb_key (const struct sadb_ext *);
-static void kdebug_sadb_x_sa2 (const struct sadb_ext *);
+static void kdebug_sadb_prop(const struct sadb_ext *);
+static void kdebug_sadb_identity(const struct sadb_ext *);
+static void kdebug_sadb_supported(const struct sadb_ext *);
+static void kdebug_sadb_lifetime(const struct sadb_ext *);
+static void kdebug_sadb_sa(const struct sadb_ext *);
+static void kdebug_sadb_address(const struct sadb_ext *);
+static void kdebug_sadb_key(const struct sadb_ext *);
+static void kdebug_sadb_x_sa2(const struct sadb_ext *);
+static void kdebug_sadb_x_policy(const struct sadb_ext *);
+
+static void kdebug__secpolicyindex(const struct secpolicyindex *);
+
+static void kdebug_hexdump(const char *, const void *, size_t);
+static void kdebug_sockaddr(const struct sockaddr *);
+static void kdebug_secasindex(const struct secasindex *);
+static void kdebug_mbufhdr(const struct mbuf *);
#ifdef _KERNEL
-static void kdebug_secreplay (const struct secreplay *);
+#if 0
+static void kdebug_secasv(const struct secasvar *);
+static void kdebug_secreplay(const struct secreplay *);
+#endif
#endif
#ifndef _KERNEL
-#define panic(param) { printf(param); exit(-1); }
+#define panic(...) err(EXIT_FAILURE, __VA_ARGS__)
#endif
/* NOTE: host byte order */
-
/* %%%: about struct sadb_msg */
void
kdebug_sadb(const struct sadb_msg *base)
@@ -92,30 +103,27 @@ kdebug_sadb(const struct sadb_msg *base)
/* sanity check */
if (base == NULL)
- panic("kdebug_sadb: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_msg{ version=%u type=%u errno=%u satype=%u\n",
+ printf("sadb { version=%u type=%u errno=%u satype=%u",
base->sadb_msg_version, base->sadb_msg_type,
base->sadb_msg_errno, base->sadb_msg_satype);
- printf(" len=%u reserved=%u seq=%u pid=%u\n",
+ printf(" len=%u reserved=%u seq=%u pid=%u",
base->sadb_msg_len, base->sadb_msg_reserved,
base->sadb_msg_seq, base->sadb_msg_pid);
tlen = PFKEY_UNUNIT64(base->sadb_msg_len) - sizeof(struct sadb_msg);
- ext = (const struct sadb_ext *)((const char *)base + sizeof(struct sadb_msg));
+ ext = (const void *)(base + 1);
while (tlen > 0) {
- printf("sadb_ext{ len=%u type=%u }\n",
+ if (ext->sadb_ext_len == 0 || ext->sadb_ext_len > tlen) {
+ panic("%s: invalid ext_len=%d tlen=%d was passed",
+ __func__, ext->sadb_ext_len, tlen);
+ }
+
+ printf(" sadb_ext { len=%u type=%u }",
PFKEY_UNUNIT64(ext->sadb_ext_len), ext->sadb_ext_type);
- if (ext->sadb_ext_len == 0) {
- printf("kdebug_sadb: invalid ext_len=0 was passed.\n");
- return;
- }
- if (ext->sadb_ext_len > tlen) {
- printf("kdebug_sadb: ext_len exceeds end of buffer.\n");
- return;
- }
switch (ext->sadb_ext_type) {
case SADB_EXT_SA:
@@ -158,17 +166,15 @@ kdebug_sadb(const struct sadb_msg *base)
kdebug_sadb_x_sa2(ext);
break;
default:
- printf("kdebug_sadb: invalid ext_type %u was passed.\n",
- ext->sadb_ext_type);
- return;
+ panic("%s: invalid ext_type %u was passed",
+ __func__, ext->sadb_ext_type);
}
extlen = PFKEY_UNUNIT64(ext->sadb_ext_len);
tlen -= extlen;
- ext = (const struct sadb_ext *)((const char *)ext + extlen);
+ ext = (const void *)((const char *)ext + extlen);
}
-
- return;
+ printf("\n");
}
static void
@@ -180,42 +186,42 @@ kdebug_sadb_prop(const struct sadb_ext *
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_prop: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
len = (PFKEY_UNUNIT64(prop->sadb_prop_len) - sizeof(*prop))
/ sizeof(*comb);
- comb = (const struct sadb_comb *)(prop + 1);
- printf("sadb_prop{ replay=%u\n", prop->sadb_prop_replay);
+ comb = (const void *)(prop + 1);
+ printf(" sadb_prop { replay=%u", prop->sadb_prop_replay);
while (len--) {
- printf("sadb_comb{ auth=%u encrypt=%u "
- "flags=0x%04x reserved=0x%08x\n",
- comb->sadb_comb_auth, comb->sadb_comb_encrypt,
- comb->sadb_comb_flags, comb->sadb_comb_reserved);
-
- printf(" auth_minbits=%u auth_maxbits=%u "
- "encrypt_minbits=%u encrypt_maxbits=%u\n",
- comb->sadb_comb_auth_minbits,
- comb->sadb_comb_auth_maxbits,
- comb->sadb_comb_encrypt_minbits,
- comb->sadb_comb_encrypt_maxbits);
-
- printf(" soft_alloc=%u hard_alloc=%u "
- "soft_bytes=%lu hard_bytes=%lu\n",
- comb->sadb_comb_soft_allocations,
- comb->sadb_comb_hard_allocations,
- (unsigned long)comb->sadb_comb_soft_bytes,
- (unsigned long)comb->sadb_comb_hard_bytes);
-
- printf(" soft_alloc=%lu hard_alloc=%lu "
- "soft_bytes=%lu hard_bytes=%lu }\n",
- (unsigned long)comb->sadb_comb_soft_addtime,
- (unsigned long)comb->sadb_comb_hard_addtime,
- (unsigned long)comb->sadb_comb_soft_usetime,
- (unsigned long)comb->sadb_comb_hard_usetime);
+ printf(" sadb_comb { auth=%u encrypt=%u"
+ "flags=%#04x reserved=%#08x ",
+ comb->sadb_comb_auth, comb->sadb_comb_encrypt,
+ comb->sadb_comb_flags, comb->sadb_comb_reserved);
+
+ printf(" auth_minbits=%u auth_maxbits=%u"
+ "encrypt_minbits=%u encrypt_maxbits=%u",
+ comb->sadb_comb_auth_minbits,
+ comb->sadb_comb_auth_maxbits,
+ comb->sadb_comb_encrypt_minbits,
+ comb->sadb_comb_encrypt_maxbits);
+
+ printf(" soft_alloc=%u hard_alloc=%u"
+ "soft_bytes=%lu hard_bytes=%lu",
+ comb->sadb_comb_soft_allocations,
+ comb->sadb_comb_hard_allocations,
+ (unsigned long)comb->sadb_comb_soft_bytes,
+ (unsigned long)comb->sadb_comb_hard_bytes);
+
+ printf(" soft_alloc=%lu hard_alloc=%lu"
+ "soft_bytes=%lu hard_bytes=%lu }",
+ (unsigned long)comb->sadb_comb_soft_addtime,
+ (unsigned long)comb->sadb_comb_hard_addtime,
+ (unsigned long)comb->sadb_comb_soft_usetime,
+ (unsigned long)comb->sadb_comb_hard_usetime);
comb++;
}
- printf("}\n");
+ printf(" }");
return;
}
@@ -228,38 +234,22 @@ kdebug_sadb_identity(const struct sadb_e
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_identity: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
len = PFKEY_UNUNIT64(id->sadb_ident_len) - sizeof(*id);
- printf("sadb_ident_%s{",
+ printf(" sadb_ident_%s {",
id->sadb_ident_exttype == SADB_EXT_IDENTITY_SRC ? "src" : "dst");
switch (id->sadb_ident_type) {
default:
printf(" type=%d id=%lu",
- id->sadb_ident_type, (u_long)id->sadb_ident_id);
+ id->sadb_ident_type, (u_long)id->sadb_ident_id);
if (len) {
-#ifdef _KERNEL
- ipsec_hexdump((const char *)(id + 1), len); /*XXX cast ?*/
-#else
- const char *p, *ep;
- printf("\n str=\"");
- p = (const char *)(id + 1);
- ep = p + len;
- for (/*nothing*/; *p && p < ep; p++) {
- if (isprint(*p))
- printf("%c", *p & 0xff);
- else
- printf("\\%03o", *p & 0xff);
- }
-#endif
- printf("\"");
+ kdebug_hexdump("data", id + 1, len);
}
break;
}
- printf(" }\n");
-
- return;
+ printf(" }");
}
static void
@@ -271,21 +261,19 @@ kdebug_sadb_supported(const struct sadb_
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_supported: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
len = (PFKEY_UNUNIT64(sup->sadb_supported_len) - sizeof(*sup))
/ sizeof(*alg);
- alg = (const struct sadb_alg *)(sup + 1);
- printf("sadb_sup{\n");
+ alg = (const void *)(sup + 1);
+ printf(" sadb_sup {");
while (len--) {
- printf(" { id=%d ivlen=%d min=%d max=%d }\n",
- alg->sadb_alg_id, alg->sadb_alg_ivlen,
- alg->sadb_alg_minbits, alg->sadb_alg_maxbits);
+ printf(" { id=%d ivlen=%d min=%d max=%d }",
+ alg->sadb_alg_id, alg->sadb_alg_ivlen,
+ alg->sadb_alg_minbits, alg->sadb_alg_maxbits);
alg++;
}
- printf("}\n");
-
- return;
+ printf(" }");
}
static void
@@ -295,16 +283,14 @@ kdebug_sadb_lifetime(const struct sadb_e
/* sanity check */
if (ext == NULL)
- printf("kdebug_sadb_lifetime: NULL pointer was passed.\n");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_lifetime{ alloc=%u, bytes=%u\n",
- lft->sadb_lifetime_allocations,
- (u_int32_t)lft->sadb_lifetime_bytes);
- printf(" addtime=%u, usetime=%u }\n",
- (u_int32_t)lft->sadb_lifetime_addtime,
- (u_int32_t)lft->sadb_lifetime_usetime);
-
- return;
+ printf(" sadb_lifetime { alloc=%u, bytes=%u",
+ lft->sadb_lifetime_allocations,
+ (u_int32_t)lft->sadb_lifetime_bytes);
+ printf(" addtime=%u, usetime=%u }",
+ (u_int32_t)lft->sadb_lifetime_addtime,
+ (u_int32_t)lft->sadb_lifetime_usetime);
}
static void
@@ -314,15 +300,13 @@ kdebug_sadb_sa(const struct sadb_ext *ex
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_sa: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_sa{ spi=%u replay=%u state=%u\n",
+ printf(" sadb_sa { spi=%u replay=%u state=%u",
(u_int32_t)ntohl(sa->sadb_sa_spi), sa->sadb_sa_replay,
sa->sadb_sa_state);
- printf(" auth=%u encrypt=%u flags=0x%08x }\n",
+ printf(" auth=%u encrypt=%u flags=%#08x }",
sa->sadb_sa_auth, sa->sadb_sa_encrypt, sa->sadb_sa_flags);
-
- return;
}
static void
@@ -332,16 +316,15 @@ kdebug_sadb_address(const struct sadb_ex
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_address: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_address{ proto=%u prefixlen=%u reserved=0x%02x%02x }\n",
+ printf(" sadb_address { proto=%u prefixlen=%u reserved=%#02x%02x }",
addr->sadb_address_proto, addr->sadb_address_prefixlen,
((const u_char *)&addr->sadb_address_reserved)[0],
((const u_char *)&addr->sadb_address_reserved)[1]);
- kdebug_sockaddr((const struct sockaddr *)((const char *)ext + sizeof(*addr)));
-
- return;
+ kdebug_sockaddr((const struct sockaddr *)
+ ((const char *)ext + sizeof(*addr)));
}
static void
@@ -351,24 +334,21 @@ kdebug_sadb_key(const struct sadb_ext *e
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_key: NULL pointer was passed");
-
- printf("sadb_key{ bits=%u reserved=%u\n",
- key->sadb_key_bits, key->sadb_key_reserved);
- printf(" key=");
+ panic("%s: NULL pointer was passed", __func__);
/* sanity check 2 */
if ((key->sadb_key_bits >> 3) >
- (PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key))) {
- printf("kdebug_sadb_key: key length mismatch, bit:%d len:%ld.\n",
- key->sadb_key_bits >> 3,
- (long)PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key));
+ (PFKEY_UNUNIT64(key->sadb_key_len) - sizeof(struct sadb_key))) {
+ panic("%s: key length mismatch, bit:%d len:%ld ", __func__,
+ key->sadb_key_bits >> 3,
+ (long)PFKEY_UNUNIT64(key->sadb_key_len)
+ - sizeof(struct sadb_key));
}
- ipsec_hexdump((const char *)key + sizeof(struct sadb_key),
- key->sadb_key_bits >> 3);
- printf(" }\n");
- return;
+ printf(" sadb_key { bits=%u reserved=%u",
+ key->sadb_key_bits, key->sadb_key_reserved);
+ kdebug_hexdump("key", key + 1, key->sadb_key_bits >> 3);
+ printf(" }");
}
static void
@@ -378,18 +358,16 @@ kdebug_sadb_x_sa2(const struct sadb_ext
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_x_sa2: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_x_sa2{ mode=%u reqid=%u\n",
+ printf(" sadb_x_sa2 { mode=%u reqid=%u",
sa2->sadb_x_sa2_mode, sa2->sadb_x_sa2_reqid);
- printf(" reserved1=%u reserved2=%u sequence=%u }\n",
+ printf(" reserved1=%u reserved2=%u sequence=%u }",
sa2->sadb_x_sa2_reserved1, sa2->sadb_x_sa2_reserved2,
sa2->sadb_x_sa2_sequence);
-
- return;
}
-void
+static void
kdebug_sadb_x_policy(const struct sadb_ext *ext)
{
const struct sadb_x_policy *xpl = (const struct sadb_x_policy *)ext;
@@ -397,9 +375,9 @@ kdebug_sadb_x_policy(const struct sadb_e
/* sanity check */
if (ext == NULL)
- panic("kdebug_sadb_x_policy: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("sadb_x_policy{ type=%u dir=%u id=%x }\n",
+ printf(" sadb_x_policy { type=%u dir=%u id=%x }",
xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir,
xpl->sadb_x_policy_id);
@@ -411,147 +389,151 @@ kdebug_sadb_x_policy(const struct sadb_e
xisr = (const struct sadb_x_ipsecrequest *)(xpl + 1);
while (tlen > 0) {
- printf(" { len=%u proto=%u mode=%u level=%u reqid=%u\n",
- xisr->sadb_x_ipsecrequest_len,
- xisr->sadb_x_ipsecrequest_proto,
- xisr->sadb_x_ipsecrequest_mode,
- xisr->sadb_x_ipsecrequest_level,
- xisr->sadb_x_ipsecrequest_reqid);
+ printf(" { len=%u proto=%u mode=%u level=%u reqid=%u",
+ xisr->sadb_x_ipsecrequest_len,
+ xisr->sadb_x_ipsecrequest_proto,
+ xisr->sadb_x_ipsecrequest_mode,
+ xisr->sadb_x_ipsecrequest_level,
+ xisr->sadb_x_ipsecrequest_reqid);
if (xisr->sadb_x_ipsecrequest_len > sizeof(*xisr)) {
- addr = (const struct sockaddr *)(xisr + 1);
+ addr = (const void *)(xisr + 1);
kdebug_sockaddr(addr);
- addr = (const struct sockaddr *)((const char *)addr
- + addr->sa_len);
+ addr = (const void *)((const char *)addr
+ + addr->sa_len);
kdebug_sockaddr(addr);
}
- printf(" }\n");
+ printf(" }");
/* prevent infinite loop */
if (xisr->sadb_x_ipsecrequest_len <= 0) {
- printf("kdebug_sadb_x_policy: wrong policy struct.\n");
- return;
+ panic("%s: wrong policy struct", __func__);
}
/* prevent overflow */
if (xisr->sadb_x_ipsecrequest_len > tlen) {
- printf("invalid ipsec policy length\n");
- return;
+ panic("%s: invalid ipsec policy length",
+ __func__);
}
tlen -= xisr->sadb_x_ipsecrequest_len;
- 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);
}
if (tlen != 0)
- panic("kdebug_sadb_x_policy: wrong policy struct");
+ panic("%s: wrong policy struct", __func__);
}
-
- return;
}
#ifdef _KERNEL
+
+void
+kdebug_sadb_xpolicy(const char *msg, const struct sadb_ext *ext)
+{
+ printf("%s:", msg);
+ kdebug_sadb_x_policy(ext);
+ printf("\n");
+}
+
/* %%%: about SPD and SAD */
void
kdebug_secpolicy(const struct secpolicy *sp)
{
/* sanity check */
if (sp == NULL)
- panic("kdebug_secpolicy: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("secpolicy{ refcnt=%u state=%u policy=%u\n",
+ printf(" secpolicy { refcnt=%u state=%u policy=%u",
key_sp_refcnt(sp), sp->state, sp->policy);
- kdebug_secpolicyindex(&sp->spidx);
+ kdebug__secpolicyindex(&sp->spidx);
+ printf(" type=");
switch (sp->policy) {
case IPSEC_POLICY_DISCARD:
- printf(" type=discard }\n");
+ printf("discard");
break;
case IPSEC_POLICY_NONE:
- printf(" type=none }\n");
+ printf("none");
break;
case IPSEC_POLICY_IPSEC:
{
+ printf("ipsec {");
struct ipsecrequest *isr;
for (isr = sp->req; isr != NULL; isr = isr->next) {
-
- printf(" level=%u\n", isr->level);
+ printf(" level=%u", isr->level);
kdebug_secasindex(&isr->saidx);
}
- printf(" }\n");
+ printf(" }");
}
break;
case IPSEC_POLICY_BYPASS:
- printf(" type=bypass }\n");
+ printf("bypass");
break;
case IPSEC_POLICY_ENTRUST:
- printf(" type=entrust }\n");
+ printf("entrust");
break;
default:
- printf("kdebug_secpolicy: Invalid policy found. %d\n",
- sp->policy);
- break;
+ panic("%s: Invalid policy found. %d", __func__, sp->policy);
}
-
- return;
+ printf(" }\n");
}
void
-kdebug_secpolicyindex(const struct secpolicyindex *spidx)
+kdebug_secpolicyindex(const char *msg, const struct secpolicyindex *spidx)
+{
+ printf("%s:", msg);
+ kdebug__secpolicyindex(spidx);
+ printf("\n");
+}
+
+
+static void
+kdebug__secpolicyindex(const struct secpolicyindex *spidx)
{
/* sanity check */
if (spidx == NULL)
- panic("kdebug_secpolicyindex: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u\n",
+ printf(" secpolicy { dir=%u prefs=%u prefd=%u ul_proto=%u",
spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto);
- ipsec_hexdump((const char *)&spidx->src,
- spidx->src.sa.sa_len);
- printf("\n");
- ipsec_hexdump((const char *)&spidx->dst,
- spidx->dst.sa.sa_len);
- printf("}\n");
-
- return;
+ kdebug_hexdump("src", &spidx->src, spidx->src.sa.sa_len);
+ kdebug_hexdump("dst", &spidx->dst, spidx->dst.sa.sa_len);
+ printf(" }");
}
-void
+static void
kdebug_secasindex(const struct secasindex *saidx)
{
/* sanity check */
if (saidx == NULL)
- panic("kdebug_secpolicyindex: NULL pointer was passed");
-
- printf("secasindex{ mode=%u proto=%u\n",
- saidx->mode, saidx->proto);
-
- ipsec_hexdump((const char *)&saidx->src,
- saidx->src.sa.sa_len);
- printf("\n");
- ipsec_hexdump((const char *)&saidx->dst,
- saidx->dst.sa.sa_len);
- printf("\n");
+ panic("%s: NULL pointer was passed", __func__);
- return;
+ printf(" secasindex { mode=%u proto=%u",
+ saidx->mode, saidx->proto);
+ kdebug_hexdump("src", &saidx->src, saidx->src.sa.sa_len);
+ kdebug_hexdump("dst", &saidx->dst, saidx->dst.sa.sa_len);
+ printf(" }");
}
-void
+#if 0
+static void
kdebug_secasv(const struct secasvar *sav)
{
/* sanity check */
if (sav == NULL)
- panic("kdebug_secasv: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf("secas{");
+ printf(" secasv {", );
kdebug_secasindex(&sav->sah->saidx);
- printf(" refcnt=%u state=%u auth=%u enc=%u\n",
+ printf(" refcnt=%u state=%u auth=%u enc=%u",
key_sa_refcnt(sav), sav->state, sav->alg_auth, sav->alg_enc);
- printf(" spi=%u flags=%u\n",
+ printf(" spi=%u flags=%u",
(u_int32_t)ntohl(sav->spi), sav->flags);
if (sav->key_auth != NULL)
@@ -568,11 +550,7 @@ kdebug_secasv(const struct secasvar *sav
if (sav->lft_s != NULL)
kdebug_sadb_lifetime((struct sadb_ext *)sav->lft_s);
-#if notyet
/* XXX: misc[123] ? */
-#endif
-
- return;
}
static void
@@ -582,79 +560,73 @@ kdebug_secreplay(const struct secreplay
/* sanity check */
if (rpl == NULL)
- panic("kdebug_secreplay: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
- printf(" secreplay{ count=%u wsize=%u seq=%u lastseq=%u",
+ printf(" secreplay { count=%u wsize=%u seq=%u lastseq=%u",
rpl->count, rpl->wsize, rpl->seq, rpl->lastseq);
if (rpl->bitmap == NULL) {
- printf(" }\n");
+ printf(" }");
return;
}
- printf("\n bitmap { ");
+ printf(" bitmap {");
for (len = 0; len < rpl->wsize; len++) {
for (l = 7; l >= 0; l--)
- printf("%u", (((rpl->bitmap)[len] >> l) & 1) ? 1 : 0);
+ printf(" %u", (((rpl->bitmap)[len] >> l) & 1) ? 1 : 0);
}
- printf(" }\n");
-
- return;
+ printf(" } }");
}
+#endif
-void
+static void
kdebug_mbufhdr(const struct mbuf *m)
{
/* sanity check */
if (m == NULL)
return;
- printf("mbuf(%p){ m_next:%p m_nextpkt:%p m_data:%p "
- "m_len:%d m_type:0x%02x m_flags:0x%02x }\n",
+ printf(" mbuf(%p) { m_next:%p m_nextpkt:%p m_data:%p "
+ "m_len:%d m_type:%#02x m_flags:%#02x }",
m, m->m_next, m->m_nextpkt, m->m_data,
m->m_len, m->m_type, m->m_flags);
if (m->m_flags & M_PKTHDR) {
- printf(" m_pkthdr{ len:%d rcvif:%p }\n",
+ printf(" m_pkthdr { len:%d rcvif:%p }",
m->m_pkthdr.len, m_get_rcvif_NOMPSAFE(m));
}
if (m->m_flags & M_EXT) {
- printf(" m_ext{ ext_buf:%p ext_free:%p "
- "ext_size:%zu ext_refcnt:%u }\n",
- m->m_ext.ext_buf, m->m_ext.ext_free,
- m->m_ext.ext_size, m->m_ext.ext_refcnt);
+ printf(" m_ext { ext_buf:%p ext_free:%p "
+ "ext_size:%zu ext_refcnt:%u }",
+ m->m_ext.ext_buf, m->m_ext.ext_free,
+ m->m_ext.ext_size, m->m_ext.ext_refcnt);
}
-
- return;
}
void
-kdebug_mbuf(const struct mbuf *m0)
+kdebug_mbuf(const char *msg, const struct mbuf *m0)
{
const struct mbuf *m = m0;
int i, j;
+ printf("%s:", msg);
for (j = 0; m; m = m->m_next) {
kdebug_mbufhdr(m);
- printf(" m_data:\n");
+ printf(" m_data:");
for (i = 0; i < m->m_len; i++) {
- if (i && i % 32 == 0)
- printf("\n");
if (i % 4 == 0)
printf(" ");
printf("%02x", mtod(m, u_char *)[i]);
j++;
}
- printf("\n");
}
-
- return;
+ printf("\n");
}
#endif /* _KERNEL */
-void
+static void
kdebug_sockaddr(const struct sockaddr *addr)
{
const struct sockaddr_in *sin4;
@@ -664,58 +636,43 @@ kdebug_sockaddr(const struct sockaddr *a
/* sanity check */
if (addr == NULL)
- panic("kdebug_sockaddr: NULL pointer was passed");
+ panic("%s: NULL pointer was passed", __func__);
/* NOTE: We deal with port number as host byte order. */
- printf("sockaddr{ len=%u family=%u", addr->sa_len, addr->sa_family);
+ printf(" sockaddr { len=%u family=%u",
+ addr->sa_len, addr->sa_family);
switch (addr->sa_family) {
case AF_INET:
sin4 = (const struct sockaddr_in *)addr;
- printf(" port=%u\n", ntohs(sin4->sin_port));
- ipsec_hexdump((const char *)&sin4->sin_addr, sizeof(sin4->sin_addr));
+ printf(" port=%u", ntohs(sin4->sin_port));
+ kdebug_hexdump("addr", &sin4->sin_addr, sizeof(sin4->sin_addr));
break;
#ifdef INET6
case AF_INET6:
sin6 = (const struct sockaddr_in6 *)addr;
- printf(" port=%u\n", ntohs(sin6->sin6_port));
- printf(" flowinfo=0x%08x, scope_id=0x%08x\n",
+ printf(" port=%u", ntohs(sin6->sin6_port));
+ printf(" flowinfo=%#08x, scope_id=%#08x",
sin6->sin6_flowinfo, sin6->sin6_scope_id);
- ipsec_hexdump((const char *)&sin6->sin6_addr, sizeof(sin6->sin6_addr));
+ kdebug_hexdump("addr", &sin6->sin6_addr, sizeof(sin6->sin6_addr));
break;
#endif
}
- printf(" }\n");
-
- return;
+ printf(" }");
}
-void
-ipsec_bindump(const char *buf, int len)
+static void
+kdebug_hexdump(const char *tag, const void *v, size_t len)
{
- int i;
-
- for (i = 0; i < len; i++)
- printf("%c", (unsigned char)buf[i]);
-
- return;
-}
-
+ size_t i;
+ const unsigned char *buf = v;
-void
-ipsec_hexdump(const char *buf, int len)
-{
- int i;
+ if (len)
+ printf(" %s=", tag);
for (i = 0; i < len; i++) {
- if (i != 0 && i % 32 == 0) printf("\n");
- if (i % 4 == 0) printf(" ");
- printf("%02x", (unsigned char)buf[i]);
+ if (i && i % 4 == 0) printf(" ");
+ printf("%02x", buf[i]);
}
-#if 0
- if (i % 32 != 0) printf("\n");
-#endif
-
- return;
}
Index: src/sys/netipsec/key_debug.h
diff -u src/sys/netipsec/key_debug.h:1.8 src/sys/netipsec/key_debug.h:1.9
--- src/sys/netipsec/key_debug.h:1.8 Tue Apr 18 23:42:11 2017
+++ src/sys/netipsec/key_debug.h Thu Sep 28 13:21:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: key_debug.h,v 1.8 2017/04/19 03:42:11 ozaki-r Exp $ */
+/* $NetBSD: key_debug.h,v 1.9 2017/09/28 17:21:42 christos Exp $ */
/* $FreeBSD: src/sys/netipsec/key_debug.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */
/* $KAME: key_debug.h,v 1.10 2001/08/05 08:37:52 itojun Exp $ */
@@ -69,8 +69,8 @@ extern u_int32_t key_debug_level;
struct sadb_msg;
struct sadb_ext;
-void kdebug_sadb (const struct sadb_msg *);
-void kdebug_sadb_x_policy (const struct sadb_ext *);
+void kdebug_sadb(const struct sadb_msg *);
+void kdebug_sadb_xpolicy(const char *, const struct sadb_ext *);
#ifdef _KERNEL
struct secpolicy;
@@ -79,18 +79,9 @@ struct secasindex;
struct secasvar;
struct secreplay;
struct mbuf;
-void kdebug_secpolicy (const struct secpolicy *);
-void kdebug_secpolicyindex (const struct secpolicyindex *);
-void kdebug_secasindex (const struct secasindex *);
-void kdebug_secasv (const struct secasvar *);
-void kdebug_mbufhdr (const struct mbuf *);
-void kdebug_mbuf (const struct mbuf *);
+void kdebug_secpolicy(const struct secpolicy *);
+void kdebug_secpolicyindex(const char *, const struct secpolicyindex *);
+void kdebug_mbuf(const char *, const struct mbuf *);
#endif /*_KERNEL*/
-struct sockaddr;
-void kdebug_sockaddr (const struct sockaddr *);
-
-void ipsec_hexdump (const char *, int);
-void ipsec_bindump (const char *, int);
-
#endif /* !_NETIPSEC_KEY_DEBUG_H_ */
Index: src/sys/netipsec/keysock.c
diff -u src/sys/netipsec/keysock.c:1.61 src/sys/netipsec/keysock.c:1.62
--- src/sys/netipsec/keysock.c:1.61 Sun Sep 24 21:56:22 2017
+++ src/sys/netipsec/keysock.c Thu Sep 28 13:21:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: keysock.c,v 1.61 2017/09/25 01:56:22 ozaki-r Exp $ */
+/* $NetBSD: keysock.c,v 1.62 2017/09/28 17:21:42 christos Exp $ */
/* $FreeBSD: src/sys/netipsec/keysock.c,v 1.3.2.1 2003/01/24 05:11:36 sam Exp $ */
/* $KAME: keysock.c,v 1.25 2001/08/13 20:07:41 itojun Exp $ */
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: keysock.c,v 1.61 2017/09/25 01:56:22 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: keysock.c,v 1.62 2017/09/28 17:21:42 christos Exp $");
/* This code has derived from sys/net/rtsock.c on FreeBSD2.2.5 */
@@ -137,7 +137,7 @@ key_output(struct mbuf *m, struct socket
KASSERT((m->m_flags & M_PKTHDR) != 0);
if (KEYDEBUG_ON(KEYDEBUG_KEY_DUMP))
- kdebug_mbuf(m);
+ kdebug_mbuf(__func__, m);
msg = mtod(m, struct sadb_msg *);
PFKEY_STATINC(PFKEY_STAT_OUT_MSGTYPE + msg->sadb_msg_type);