+/* $FreeBSD: src/sys/netkey/key_debug.c,v 1.10.2.5 2002/04/28 05:40:28 suz Exp $ */
+/* $KAME: key_debug.c,v 1.26 2001/06/27 10:46:50 sakane Exp $ */
+
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* SUCH DAMAGE.
*/
-/* KAME @(#)$Id: key_debug.c,v 1.2 2000/09/14 20:35:26 lindak Exp $ */
-
-#ifdef KERNEL
-# define _KERNEL
-#endif
-
-#ifdef KERNEL
-#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
-#include "opt_inet.h"
-#endif
-#endif
-
#include <sys/types.h>
#include <sys/param.h>
-#if defined(KERNEL)
+#ifdef KERNEL
#include <sys/systm.h>
#include <sys/mbuf.h>
+#include <sys/queue.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet6/ipsec.h>
-#if !defined(KERNEL)
+#ifndef KERNEL
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
-#endif /* defined(KERNEL) */
+#endif /* !KERNEL */
-#if !defined(_KERNEL) || (defined(_KERNEL) && defined(IPSEC_DEBUG))
+#if !defined(KERNEL) || (defined(KERNEL) && defined(IPSEC_DEBUG))
-static void kdebug_sadb_prop __P((struct sadb_ext *));
-static void kdebug_sadb_identity __P((struct sadb_ext *));
-static void kdebug_sadb_supported __P((struct sadb_ext *));
-static void kdebug_sadb_lifetime __P((struct sadb_ext *));
-static void kdebug_sadb_sa __P((struct sadb_ext *));
-static void kdebug_sadb_address __P((struct sadb_ext *));
-static void kdebug_sadb_key __P((struct sadb_ext *));
+static void kdebug_sadb_prop(struct sadb_ext *);
+static void kdebug_sadb_identity(struct sadb_ext *);
+static void kdebug_sadb_supported(struct sadb_ext *);
+static void kdebug_sadb_lifetime(struct sadb_ext *);
+static void kdebug_sadb_sa(struct sadb_ext *);
+static void kdebug_sadb_address(struct sadb_ext *);
+static void kdebug_sadb_key(struct sadb_ext *);
+static void kdebug_sadb_x_sa2(struct sadb_ext *);
#ifdef KERNEL
-static void kdebug_secreplay __P((struct secreplay *));
+static void kdebug_secreplay(struct secreplay *);
#endif
#ifndef KERNEL
printf("sadb_msg{ version=%u type=%u errno=%u satype=%u\n",
base->sadb_msg_version, base->sadb_msg_type,
base->sadb_msg_errno, base->sadb_msg_satype);
- printf(" len=%u mode=%u seq=%u pid=%u reqid=%u\n",
- base->sadb_msg_len, base->sadb_msg_mode,
- base->sadb_msg_seq, base->sadb_msg_pid, base->sadb_msg_reqid);
- printf(" reserved1=%u reserved2=%u\n",
- base->sadb_msg_reserved1, base->sadb_msg_reserved2);
+ printf(" len=%u reserved=%u seq=%u pid=%u\n",
+ 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 = (struct sadb_ext *)((caddr_t)base + sizeof(struct sadb_msg));
case SADB_X_EXT_POLICY:
kdebug_sadb_x_policy(ext);
break;
+ case SADB_X_EXT_SA2:
+ kdebug_sadb_x_sa2(ext);
+ break;
+ case SADB_EXT_SESSION_ID:
+ kdebug_sadb_session_id(ext);
+ break;
+ case SADB_EXT_SASTAT:
+ kdebug_sadb_sastat(ext);
+ break;
default:
printf("kdebug_sadb: invalid ext_type %u was passed.\n",
ext->sadb_ext_type);
"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);
+ (u_int32_t)comb->sadb_comb_soft_bytes,
+ (u_int32_t)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);
+ (u_int32_t)comb->sadb_comb_soft_addtime,
+ (u_int32_t)comb->sadb_comb_hard_addtime,
+ (u_int32_t)comb->sadb_comb_soft_usetime,
+ (u_int32_t)comb->sadb_comb_hard_usetime);
comb++;
}
printf("}\n");
{
struct sadb_ident *id = (struct sadb_ident *)ext;
int len;
- union sadb_x_ident_id *aid;
/* sanity check */
if (ext == NULL)
printf("sadb_ident_%s{",
id->sadb_ident_exttype == SADB_EXT_IDENTITY_SRC ? "src" : "dst");
switch (id->sadb_ident_type) {
- case SADB_X_IDENTTYPE_ADDR:
- aid = (union sadb_x_ident_id *)&id->sadb_ident_id;
-
- printf(" type=%d prefix=%u ul_proto=%u\n",
- id->sadb_ident_type,
- aid->sadb_x_ident_id_addr.prefix,
- aid->sadb_x_ident_id_addr.ul_proto);
- kdebug_sockaddr((struct sockaddr *)(id + 1));
- break;
-
default:
printf(" type=%d id=%lu",
- id->sadb_ident_type, (u_long)id->sadb_ident_id);
+ id->sadb_ident_type, (u_int32_t)id->sadb_ident_id);
if (len) {
#ifdef KERNEL
ipsec_hexdump((caddr_t)(id + 1), len); /*XXX cast ?*/
return;
}
+static void
+kdebug_sadb_x_sa2(ext)
+ struct sadb_ext *ext;
+{
+ struct sadb_x_sa2 *sa2 = (struct sadb_x_sa2 *)ext;
+
+ /* sanity check */
+ if (ext == NULL)
+ panic("kdebug_sadb_x_sa2: NULL pointer was passed.\n");
+
+ printf("sadb_x_sa2{ mode=%u reqid=%u\n",
+ sa2->sadb_x_sa2_mode, sa2->sadb_x_sa2_reqid);
+ printf(" reserved1=%u reserved2=%u sequence=%u }\n",
+ sa2->sadb_x_sa2_reserved1, sa2->sadb_x_sa2_reserved2,
+ sa2->sadb_x_sa2_sequence);
+
+ return;
+}
+
+static void
+kdebug_sadb_session_id(ext)
+ struct sadb_ext *ext;
+{
+ struct sadb_session_id *p = (__typeof__(p))ext;
+
+ /* sanity check */
+ if (ext == NULL)
+ panic("kdebug_sadb_session_id: NULL pointer was passed.\n");
+
+ printf("sadb_session_id{ id0=%llx, id1=%llx}\n",
+ p->sadb_session_id_v[0],
+ p->sadb_session_id_v[1]);
+
+ return;
+}
+
+static void
+kdebug_sadb_sastat(ext)
+ struct sadb_ext *ext;
+{
+ struct sadb_sastat *p = (__typeof__(p))ext;
+ struct sastat *stats;
+ int i;
+
+ /* sanity check */
+ if (ext == NULL)
+ panic("kdebug_sadb_sastat: NULL pointer was passed.\n");
+
+ printf("sadb_sastat{ dir=%u num=%u\n",
+ p->sadb_sastat_dir, p->sadb_sastat_list_len);
+ stats = (__typeof__(stats))(p + 1);
+ for (i = 0; i < p->sadb_sastat_list_len; i++) {
+ printf(" spi=%x,\n",
+ stats[i].spi);
+ }
+ printf("}\n");
+
+ return;
+}
+
void
kdebug_sadb_x_policy(ext)
struct sadb_ext *ext;
if (ext == NULL)
panic("kdebug_sadb_x_policy: NULL pointer was passed.\n");
- printf("sadb_x_policy{ type=%u dir=%u reserved=%x }\n",
+ printf("sadb_x_policy{ type=%u dir=%u id=%x }\n",
xpl->sadb_x_policy_type, xpl->sadb_x_policy_dir,
- xpl->sadb_x_policy_reserved);
+ xpl->sadb_x_policy_id);
if (xpl->sadb_x_policy_type == IPSEC_POLICY_IPSEC) {
int tlen;
switch (sp->policy) {
case IPSEC_POLICY_DISCARD:
+ case IPSEC_POLICY_GENERATE:
printf(" type=discard }\n");
break;
case IPSEC_POLICY_NONE:
printf(" level=%u\n", isr->level);
kdebug_secasindex(&isr->saidx);
- if (isr->sav != NULL)
- kdebug_secasv(isr->sav);
}
printf(" }\n");
}
if (spidx == NULL)
panic("kdebug_secpolicyindex: NULL pointer was passed.\n");
- printf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u\n",
- spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto);
+ printf("secpolicyindex{ dir=%u prefs=%u prefd=%u ul_proto=%u internal_if=%s\n",
+ spidx->dir, spidx->prefs, spidx->prefd, spidx->ul_proto,
+ (spidx->internal_if) ? spidx->internal_if->if_xname : "N/A");
ipsec_hexdump((caddr_t)&spidx->src,
((struct sockaddr *)&spidx->src)->sa_len);
return;
}
- printf("\n bitmap { ");
+ printf("\n bitmap { ");
for (len = 0; len < rpl->wsize; len++) {
for (l = 7; l >= 0; l--)
{
/* sanity check */
if (m == NULL)
- panic("debug_mbufhdr: NULL pointer was passed.\n");
+ 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",
- m, m->m_next, m->m_nextpkt, m->m_data,
- m->m_len, m->m_type, m->m_flags);
+ printf("mbuf(0x%llx){ m_next:0x%llx m_nextpkt:0x%llx m_data:0x%llx "
+ "m_len:%d m_type:0x%02x m_flags:0x%02x }\n",
+ (uint64_t)VM_KERNEL_ADDRPERM(m),
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_next),
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_nextpkt),
+ (uint64_t)VM_KERNEL_ADDRPERM(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",
- m->m_pkthdr.len, m->m_pkthdr.rcvif);
+ printf(" m_pkthdr{ len:%d rcvif:0x%llx }\n",
+ m->m_pkthdr.len,
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_pkthdr.rcvif));
}
-#ifdef __FreeBSD__
if (m->m_flags & M_EXT) {
- printf(" m_ext{ ext_buf:%p ext_free:%p "
- "ext_size:%u ext_ref:%p }\n",
- m->m_ext.ext_buf, m->m_ext.ext_free,
- m->m_ext.ext_size, m->m_ext.ext_ref);
+ printf(" m_ext{ ext_buf:0x%llx ext_free:0x%llx "
+ "ext_size:%u ext_ref:0x%llx }\n",
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_ext.ext_buf),
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_ext.ext_free),
+ m->m_ext.ext_size,
+ (uint64_t)VM_KERNEL_ADDRPERM(m->m_ext.ext_refs));
}
-#endif
return;
}
struct mbuf *m = m0;
int i, j;
- kdebug_mbufhdr(m);
- printf(" m_data=\n");
for (j = 0; m; m = m->m_next) {
+ kdebug_mbufhdr(m);
+ printf(" m_data:\n");
for (i = 0; i < m->m_len; i++) {
- if (i != 0 && i % 32 == 0) printf("\n");
- if (i % 4 == 0) printf(" ");
+ if (i && i % 32 == 0)
+ printf("\n");
+ if (i % 4 == 0)
+ printf(" ");
printf("%02x", mtod(m, u_char *)[i]);
j++;
}
+ printf("\n");
}
- printf("\n");
-
return;
}
#endif /* KERNEL */
kdebug_sockaddr(addr)
struct sockaddr *addr;
{
+ struct sockaddr_in *sin4;
+#ifdef INET6
+ struct sockaddr_in6 *sin6;
+#endif
+
/* sanity check */
if (addr == NULL)
panic("kdebug_sockaddr: NULL pointer was passed.\n");
/* NOTE: We deal with port number as host byte order. */
- printf("sockaddr{ len=%u family=%u port=%u\n",
- addr->sa_len, addr->sa_family, ntohs(_INPORTBYSA(addr)));
+ printf("sockaddr{ len=%u family=%u", addr->sa_len, addr->sa_family);
+ switch (addr->sa_family) {
+ case AF_INET:
+ sin4 = (struct sockaddr_in *)addr;
+ printf(" port=%u\n", ntohs(sin4->sin_port));
+ ipsec_hexdump((caddr_t)&sin4->sin_addr, sizeof(sin4->sin_addr));
+ break;
#ifdef INET6
- if (addr->sa_family == PF_INET6) {
- struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr;
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *)addr;
+ printf(" port=%u\n", ntohs(sin6->sin6_port));
printf(" flowinfo=0x%08x, scope_id=0x%08x\n",
- in6->sin6_flowinfo, in6->sin6_scope_id);
- }
+ sin6->sin6_flowinfo, sin6->sin6_scope_id);
+ ipsec_hexdump((caddr_t)&sin6->sin6_addr,
+ sizeof(sin6->sin6_addr));
+ break;
#endif
-
- ipsec_hexdump(_INADDRBYSA(addr), _INALENBYAF(addr->sa_family));
+ }
printf(" }\n");
return;
}
-#endif /* !defined(KERNEL) || (defined(KERNEL) && defined(IPSEC_DEBUG)) */
-
void
ipsec_bindump(buf, len)
caddr_t buf;
return;
}
+#endif /* !defined(KERNEL) || (defined(KERNEL) && defined(IPSEC_DEBUG)) */