xref: /freebsd/lib/libipsec/pfkey_dump.c (revision 1922fd129e288c22e9c0175a84c13c33cb9345cb)
1bd9f52d5SHajimu UMEMOTO /*	$KAME: pfkey_dump.c,v 1.45 2003/09/08 10:14:56 itojun Exp $	*/
23c62e87aSJun-ichiro itojun Hagino 
39a4365d0SYoshinobu Inoue /*
49a4365d0SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
59a4365d0SYoshinobu Inoue  * All rights reserved.
69a4365d0SYoshinobu Inoue  *
79a4365d0SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
89a4365d0SYoshinobu Inoue  * modification, are permitted provided that the following conditions
99a4365d0SYoshinobu Inoue  * are met:
109a4365d0SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
119a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
129a4365d0SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
139a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
149a4365d0SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
159a4365d0SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
169a4365d0SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
179a4365d0SYoshinobu Inoue  *    without specific prior written permission.
189a4365d0SYoshinobu Inoue  *
199a4365d0SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
209a4365d0SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
219a4365d0SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
229a4365d0SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
239a4365d0SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
249a4365d0SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
259a4365d0SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
269a4365d0SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
279a4365d0SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
289a4365d0SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
299a4365d0SYoshinobu Inoue  * SUCH DAMAGE.
309a4365d0SYoshinobu Inoue  */
319a4365d0SYoshinobu Inoue 
3246a50f4eSMatthew Dillon #include <sys/cdefs.h>
3346a50f4eSMatthew Dillon __FBSDID("$FreeBSD$");
3446a50f4eSMatthew Dillon 
359a4365d0SYoshinobu Inoue #include <sys/types.h>
369a4365d0SYoshinobu Inoue #include <sys/param.h>
379a4365d0SYoshinobu Inoue #include <sys/socket.h>
389a4365d0SYoshinobu Inoue #include <netinet6/ipsec.h>
399a4365d0SYoshinobu Inoue #include <net/pfkeyv2.h>
409a4365d0SYoshinobu Inoue #include <netkey/key_var.h>
419a4365d0SYoshinobu Inoue #include <netkey/key_debug.h>
429a4365d0SYoshinobu Inoue 
439a4365d0SYoshinobu Inoue #include <netinet/in.h>
449a4365d0SYoshinobu Inoue #include <netinet6/ipsec.h>
459a4365d0SYoshinobu Inoue #include <arpa/inet.h>
469a4365d0SYoshinobu Inoue 
479a4365d0SYoshinobu Inoue #include <stdlib.h>
489a4365d0SYoshinobu Inoue #include <unistd.h>
499a4365d0SYoshinobu Inoue #include <stdio.h>
509a4365d0SYoshinobu Inoue #include <string.h>
519a4365d0SYoshinobu Inoue #include <time.h>
523c62e87aSJun-ichiro itojun Hagino #include <netdb.h>
539a4365d0SYoshinobu Inoue 
549a4365d0SYoshinobu Inoue #include "ipsec_strerror.h"
553c62e87aSJun-ichiro itojun Hagino #include "libpfkey.h"
569a4365d0SYoshinobu Inoue 
5733841545SHajimu UMEMOTO /* cope with old kame headers - ugly */
5833841545SHajimu UMEMOTO #ifndef SADB_X_AALG_MD5
5933841545SHajimu UMEMOTO #define SADB_X_AALG_MD5		SADB_AALG_MD5
6033841545SHajimu UMEMOTO #endif
6133841545SHajimu UMEMOTO #ifndef SADB_X_AALG_SHA
6233841545SHajimu UMEMOTO #define SADB_X_AALG_SHA		SADB_AALG_SHA
6333841545SHajimu UMEMOTO #endif
6433841545SHajimu UMEMOTO #ifndef SADB_X_AALG_NULL
6533841545SHajimu UMEMOTO #define SADB_X_AALG_NULL	SADB_AALG_NULL
6633841545SHajimu UMEMOTO #endif
6733841545SHajimu UMEMOTO 
6833841545SHajimu UMEMOTO #ifndef SADB_X_EALG_BLOWFISHCBC
6933841545SHajimu UMEMOTO #define SADB_X_EALG_BLOWFISHCBC	SADB_EALG_BLOWFISHCBC
7033841545SHajimu UMEMOTO #endif
7133841545SHajimu UMEMOTO #ifndef SADB_X_EALG_CAST128CBC
7233841545SHajimu UMEMOTO #define SADB_X_EALG_CAST128CBC	SADB_EALG_CAST128CBC
7333841545SHajimu UMEMOTO #endif
7433841545SHajimu UMEMOTO #ifndef SADB_X_EALG_RC5CBC
7533841545SHajimu UMEMOTO #ifdef SADB_EALG_RC5CBC
7633841545SHajimu UMEMOTO #define SADB_X_EALG_RC5CBC	SADB_EALG_RC5CBC
7733841545SHajimu UMEMOTO #endif
7833841545SHajimu UMEMOTO #endif
7933841545SHajimu UMEMOTO 
809a4365d0SYoshinobu Inoue #define GETMSGSTR(str, num) \
813c62e87aSJun-ichiro itojun Hagino do { \
829a4365d0SYoshinobu Inoue 	if (sizeof((str)[0]) == 0 \
839a4365d0SYoshinobu Inoue 	 || num >= sizeof(str)/sizeof((str)[0])) \
849713f5c1SHajimu UMEMOTO 		printf("%u ", (num)); \
859a4365d0SYoshinobu Inoue 	else if (strlen((str)[(num)]) == 0) \
869713f5c1SHajimu UMEMOTO 		printf("%u ", (num)); \
879a4365d0SYoshinobu Inoue 	else \
889a4365d0SYoshinobu Inoue 		printf("%s ", (str)[(num)]); \
893c62e87aSJun-ichiro itojun Hagino } while (0)
909a4365d0SYoshinobu Inoue 
9133841545SHajimu UMEMOTO #define GETMSGV2S(v2s, num) \
9233841545SHajimu UMEMOTO do { \
9333841545SHajimu UMEMOTO 	struct val2str *p;  \
9433841545SHajimu UMEMOTO 	for (p = (v2s); p && p->str; p++) { \
9533841545SHajimu UMEMOTO 		if (p->val == (num)) \
9633841545SHajimu UMEMOTO 			break; \
9733841545SHajimu UMEMOTO 	} \
9833841545SHajimu UMEMOTO 	if (p && p->str) \
9933841545SHajimu UMEMOTO 		printf("%s ", p->str); \
10033841545SHajimu UMEMOTO 	else \
1019713f5c1SHajimu UMEMOTO 		printf("%u ", (num)); \
10233841545SHajimu UMEMOTO } while (0)
10333841545SHajimu UMEMOTO 
10469160b1eSDavid E. O'Brien static char *str_ipaddr(struct sockaddr *);
105bd9f52d5SHajimu UMEMOTO static char *str_prefport(u_int, u_int, u_int, u_int);
106bd9f52d5SHajimu UMEMOTO static void str_upperspec(u_int, u_int, u_int);
10769160b1eSDavid E. O'Brien static char *str_time(time_t);
10869160b1eSDavid E. O'Brien static void str_lifetime_byte(struct sadb_lifetime *, char *);
1099a4365d0SYoshinobu Inoue 
11033841545SHajimu UMEMOTO struct val2str {
11133841545SHajimu UMEMOTO 	int val;
11233841545SHajimu UMEMOTO 	const char *str;
11333841545SHajimu UMEMOTO };
11433841545SHajimu UMEMOTO 
1159a4365d0SYoshinobu Inoue /*
1169a4365d0SYoshinobu Inoue  * Must to be re-written about following strings.
1179a4365d0SYoshinobu Inoue  */
11833841545SHajimu UMEMOTO static char *str_satype[] = {
1199a4365d0SYoshinobu Inoue 	"unspec",
1209a4365d0SYoshinobu Inoue 	"unknown",
1219a4365d0SYoshinobu Inoue 	"ah",
1229a4365d0SYoshinobu Inoue 	"esp",
1239a4365d0SYoshinobu Inoue 	"unknown",
1249a4365d0SYoshinobu Inoue 	"rsvp",
1259a4365d0SYoshinobu Inoue 	"ospfv2",
1269a4365d0SYoshinobu Inoue 	"ripv2",
1279a4365d0SYoshinobu Inoue 	"mip",
1289a4365d0SYoshinobu Inoue 	"ipcomp",
1291922fd12SBruce M Simpson 	"policy",
1301922fd12SBruce M Simpson 	"tcp"
1319a4365d0SYoshinobu Inoue };
1329a4365d0SYoshinobu Inoue 
13333841545SHajimu UMEMOTO static char *str_mode[] = {
1349a4365d0SYoshinobu Inoue 	"any",
1359a4365d0SYoshinobu Inoue 	"transport",
1369a4365d0SYoshinobu Inoue 	"tunnel",
1379a4365d0SYoshinobu Inoue };
1389a4365d0SYoshinobu Inoue 
13933841545SHajimu UMEMOTO static char *str_state[] = {
1409a4365d0SYoshinobu Inoue 	"larval",
1419a4365d0SYoshinobu Inoue 	"mature",
1429a4365d0SYoshinobu Inoue 	"dying",
1439a4365d0SYoshinobu Inoue 	"dead",
1449a4365d0SYoshinobu Inoue };
1459a4365d0SYoshinobu Inoue 
14633841545SHajimu UMEMOTO static struct val2str str_alg_auth[] = {
14733841545SHajimu UMEMOTO 	{ SADB_AALG_NONE, "none", },
14833841545SHajimu UMEMOTO 	{ SADB_AALG_MD5HMAC, "hmac-md5", },
14933841545SHajimu UMEMOTO 	{ SADB_AALG_SHA1HMAC, "hmac-sha1", },
15033841545SHajimu UMEMOTO 	{ SADB_X_AALG_MD5, "md5", },
15133841545SHajimu UMEMOTO 	{ SADB_X_AALG_SHA, "sha", },
15233841545SHajimu UMEMOTO 	{ SADB_X_AALG_NULL, "null", },
1531922fd12SBruce M Simpson 	{ SADB_X_AALG_TCP_MD5, "tcp-md5", },
15433841545SHajimu UMEMOTO #ifdef SADB_X_AALG_SHA2_256
15533841545SHajimu UMEMOTO 	{ SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
15633841545SHajimu UMEMOTO #endif
15733841545SHajimu UMEMOTO #ifdef SADB_X_AALG_SHA2_384
15833841545SHajimu UMEMOTO 	{ SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
15933841545SHajimu UMEMOTO #endif
16033841545SHajimu UMEMOTO #ifdef SADB_X_AALG_SHA2_512
16133841545SHajimu UMEMOTO 	{ SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
16233841545SHajimu UMEMOTO #endif
163492528c0SHajimu UMEMOTO #ifdef SADB_X_AALG_RIPEMD160HMAC
164492528c0SHajimu UMEMOTO 	{ SADB_X_AALG_RIPEMD160HMAC, "hmac-ripemd160", },
165492528c0SHajimu UMEMOTO #endif
166c65ee7c7SHajimu UMEMOTO #ifdef SADB_X_AALG_AES_XCBC_MAC
167c65ee7c7SHajimu UMEMOTO 	{ SADB_X_AALG_AES_XCBC_MAC, "aes-xcbc-mac", },
168c65ee7c7SHajimu UMEMOTO #endif
16933841545SHajimu UMEMOTO 	{ -1, NULL, },
1709a4365d0SYoshinobu Inoue };
1719a4365d0SYoshinobu Inoue 
17233841545SHajimu UMEMOTO static struct val2str str_alg_enc[] = {
17333841545SHajimu UMEMOTO 	{ SADB_EALG_NONE, "none", },
17433841545SHajimu UMEMOTO 	{ SADB_EALG_DESCBC, "des-cbc", },
17533841545SHajimu UMEMOTO 	{ SADB_EALG_3DESCBC, "3des-cbc", },
17633841545SHajimu UMEMOTO 	{ SADB_EALG_NULL, "null", },
17733841545SHajimu UMEMOTO #ifdef SADB_X_EALG_RC5CBC
17833841545SHajimu UMEMOTO 	{ SADB_X_EALG_RC5CBC, "rc5-cbc", },
17933841545SHajimu UMEMOTO #endif
18033841545SHajimu UMEMOTO 	{ SADB_X_EALG_CAST128CBC, "cast128-cbc", },
18133841545SHajimu UMEMOTO 	{ SADB_X_EALG_BLOWFISHCBC, "blowfish-cbc", },
18233841545SHajimu UMEMOTO #ifdef SADB_X_EALG_RIJNDAELCBC
18333841545SHajimu UMEMOTO 	{ SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
18433841545SHajimu UMEMOTO #endif
18533841545SHajimu UMEMOTO #ifdef SADB_X_EALG_TWOFISHCBC
18633841545SHajimu UMEMOTO 	{ SADB_X_EALG_TWOFISHCBC, "twofish-cbc", },
18733841545SHajimu UMEMOTO #endif
188b42ac57fSHajimu UMEMOTO #ifdef SADB_X_EALG_AESCTR
189b42ac57fSHajimu UMEMOTO 	{ SADB_X_EALG_AESCTR, "aes-ctr", },
190b42ac57fSHajimu UMEMOTO #endif
19133841545SHajimu UMEMOTO 	{ -1, NULL, },
1929a4365d0SYoshinobu Inoue };
1939a4365d0SYoshinobu Inoue 
19433841545SHajimu UMEMOTO static struct val2str str_alg_comp[] = {
19533841545SHajimu UMEMOTO 	{ SADB_X_CALG_NONE, "none", },
19633841545SHajimu UMEMOTO 	{ SADB_X_CALG_OUI, "oui", },
19733841545SHajimu UMEMOTO 	{ SADB_X_CALG_DEFLATE, "deflate", },
19833841545SHajimu UMEMOTO 	{ SADB_X_CALG_LZS, "lzs", },
19933841545SHajimu UMEMOTO 	{ -1, NULL, },
2009a4365d0SYoshinobu Inoue };
2019a4365d0SYoshinobu Inoue 
2029a4365d0SYoshinobu Inoue /*
2039a4365d0SYoshinobu Inoue  * dump SADB_MSG formated.  For debugging, you should use kdebug_sadb().
2049a4365d0SYoshinobu Inoue  */
2059a4365d0SYoshinobu Inoue void
2069a4365d0SYoshinobu Inoue pfkey_sadump(m)
2079a4365d0SYoshinobu Inoue 	struct sadb_msg *m;
2089a4365d0SYoshinobu Inoue {
2099a4365d0SYoshinobu Inoue 	caddr_t mhp[SADB_EXT_MAX + 1];
2109a4365d0SYoshinobu Inoue 	struct sadb_sa *m_sa;
2113c62e87aSJun-ichiro itojun Hagino 	struct sadb_x_sa2 *m_sa2;
2129a4365d0SYoshinobu Inoue 	struct sadb_lifetime *m_lftc, *m_lfth, *m_lfts;
2139a4365d0SYoshinobu Inoue 	struct sadb_address *m_saddr, *m_daddr, *m_paddr;
2149a4365d0SYoshinobu Inoue 	struct sadb_key *m_auth, *m_enc;
2159a4365d0SYoshinobu Inoue 	struct sadb_ident *m_sid, *m_did;
2169a4365d0SYoshinobu Inoue 	struct sadb_sens *m_sens;
2179a4365d0SYoshinobu Inoue 
2189a4365d0SYoshinobu Inoue 	/* check pfkey message. */
2199a4365d0SYoshinobu Inoue 	if (pfkey_align(m, mhp)) {
2209a4365d0SYoshinobu Inoue 		printf("%s\n", ipsec_strerror());
2219a4365d0SYoshinobu Inoue 		return;
2229a4365d0SYoshinobu Inoue 	}
2239a4365d0SYoshinobu Inoue 	if (pfkey_check(mhp)) {
2249a4365d0SYoshinobu Inoue 		printf("%s\n", ipsec_strerror());
2259a4365d0SYoshinobu Inoue 		return;
2269a4365d0SYoshinobu Inoue 	}
2279a4365d0SYoshinobu Inoue 
2289a4365d0SYoshinobu Inoue 	m_sa = (struct sadb_sa *)mhp[SADB_EXT_SA];
2293c62e87aSJun-ichiro itojun Hagino 	m_sa2 = (struct sadb_x_sa2 *)mhp[SADB_X_EXT_SA2];
2309a4365d0SYoshinobu Inoue 	m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
2319a4365d0SYoshinobu Inoue 	m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
2329a4365d0SYoshinobu Inoue 	m_lfts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
2339a4365d0SYoshinobu Inoue 	m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
2349a4365d0SYoshinobu Inoue 	m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
2359a4365d0SYoshinobu Inoue 	m_paddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_PROXY];
2369a4365d0SYoshinobu Inoue 	m_auth = (struct sadb_key *)mhp[SADB_EXT_KEY_AUTH];
2379a4365d0SYoshinobu Inoue 	m_enc = (struct sadb_key *)mhp[SADB_EXT_KEY_ENCRYPT];
2389a4365d0SYoshinobu Inoue 	m_sid = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
2393c62e87aSJun-ichiro itojun Hagino 	m_did = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_DST];
2409a4365d0SYoshinobu Inoue 	m_sens = (struct sadb_sens *)mhp[SADB_EXT_SENSITIVITY];
2419a4365d0SYoshinobu Inoue 
2429a4365d0SYoshinobu Inoue 	/* source address */
2439a4365d0SYoshinobu Inoue 	if (m_saddr == NULL) {
2449a4365d0SYoshinobu Inoue 		printf("no ADDRESS_SRC extension.\n");
2459a4365d0SYoshinobu Inoue 		return;
2469a4365d0SYoshinobu Inoue 	}
2473c62e87aSJun-ichiro itojun Hagino 	printf("%s ", str_ipaddr((struct sockaddr *)(m_saddr + 1)));
2489a4365d0SYoshinobu Inoue 
2499a4365d0SYoshinobu Inoue 	/* destination address */
2509a4365d0SYoshinobu Inoue 	if (m_daddr == NULL) {
2519a4365d0SYoshinobu Inoue 		printf("no ADDRESS_DST extension.\n");
2529a4365d0SYoshinobu Inoue 		return;
2539a4365d0SYoshinobu Inoue 	}
2543c62e87aSJun-ichiro itojun Hagino 	printf("%s ", str_ipaddr((struct sockaddr *)(m_daddr + 1)));
2559a4365d0SYoshinobu Inoue 
2569a4365d0SYoshinobu Inoue 	/* SA type */
2579a4365d0SYoshinobu Inoue 	if (m_sa == NULL) {
2589a4365d0SYoshinobu Inoue 		printf("no SA extension.\n");
2599a4365d0SYoshinobu Inoue 		return;
2609a4365d0SYoshinobu Inoue 	}
2613c62e87aSJun-ichiro itojun Hagino 	if (m_sa2 == NULL) {
2623c62e87aSJun-ichiro itojun Hagino 		printf("no SA2 extension.\n");
2633c62e87aSJun-ichiro itojun Hagino 		return;
2643c62e87aSJun-ichiro itojun Hagino 	}
2659a4365d0SYoshinobu Inoue 	printf("\n\t");
2669a4365d0SYoshinobu Inoue 
26733841545SHajimu UMEMOTO 	GETMSGSTR(str_satype, m->sadb_msg_satype);
2689a4365d0SYoshinobu Inoue 
2699a4365d0SYoshinobu Inoue 	printf("mode=");
27033841545SHajimu UMEMOTO 	GETMSGSTR(str_mode, m_sa2->sadb_x_sa2_mode);
2719a4365d0SYoshinobu Inoue 
2723c62e87aSJun-ichiro itojun Hagino 	printf("spi=%u(0x%08x) reqid=%u(0x%08x)\n",
2739a4365d0SYoshinobu Inoue 		(u_int32_t)ntohl(m_sa->sadb_sa_spi),
2749a4365d0SYoshinobu Inoue 		(u_int32_t)ntohl(m_sa->sadb_sa_spi),
2753c62e87aSJun-ichiro itojun Hagino 		(u_int32_t)m_sa2->sadb_x_sa2_reqid,
2763c62e87aSJun-ichiro itojun Hagino 		(u_int32_t)m_sa2->sadb_x_sa2_reqid);
2779a4365d0SYoshinobu Inoue 
2789a4365d0SYoshinobu Inoue 	/* encryption key */
2799a4365d0SYoshinobu Inoue 	if (m->sadb_msg_satype == SADB_X_SATYPE_IPCOMP) {
2809a4365d0SYoshinobu Inoue 		printf("\tC: ");
28133841545SHajimu UMEMOTO 		GETMSGV2S(str_alg_comp, m_sa->sadb_sa_encrypt);
2829a4365d0SYoshinobu Inoue 	} else if (m->sadb_msg_satype == SADB_SATYPE_ESP) {
2839a4365d0SYoshinobu Inoue 		if (m_enc != NULL) {
2849a4365d0SYoshinobu Inoue 			printf("\tE: ");
28533841545SHajimu UMEMOTO 			GETMSGV2S(str_alg_enc, m_sa->sadb_sa_encrypt);
2869a4365d0SYoshinobu Inoue 			ipsec_hexdump((caddr_t)m_enc + sizeof(*m_enc),
2879a4365d0SYoshinobu Inoue 				      m_enc->sadb_key_bits / 8);
2889a4365d0SYoshinobu Inoue 			printf("\n");
2899a4365d0SYoshinobu Inoue 		}
2909a4365d0SYoshinobu Inoue 	}
2919a4365d0SYoshinobu Inoue 
2929a4365d0SYoshinobu Inoue 	/* authentication key */
2939a4365d0SYoshinobu Inoue 	if (m_auth != NULL) {
2949a4365d0SYoshinobu Inoue 		printf("\tA: ");
29533841545SHajimu UMEMOTO 		GETMSGV2S(str_alg_auth, m_sa->sadb_sa_auth);
2969a4365d0SYoshinobu Inoue 		ipsec_hexdump((caddr_t)m_auth + sizeof(*m_auth),
2979a4365d0SYoshinobu Inoue 		              m_auth->sadb_key_bits / 8);
2989a4365d0SYoshinobu Inoue 		printf("\n");
2999a4365d0SYoshinobu Inoue 	}
3009a4365d0SYoshinobu Inoue 
3013c62e87aSJun-ichiro itojun Hagino 	/* replay windoe size & flags */
302232bdaf6SHajimu UMEMOTO 	printf("\tseq=0x%08x replay=%u flags=0x%08x ",
303232bdaf6SHajimu UMEMOTO 		m_sa2->sadb_x_sa2_sequence,
3043c62e87aSJun-ichiro itojun Hagino 		m_sa->sadb_sa_replay,
3053c62e87aSJun-ichiro itojun Hagino 		m_sa->sadb_sa_flags);
3063c62e87aSJun-ichiro itojun Hagino 
3079a4365d0SYoshinobu Inoue 	/* state */
3083c62e87aSJun-ichiro itojun Hagino 	printf("state=");
30933841545SHajimu UMEMOTO 	GETMSGSTR(str_state, m_sa->sadb_sa_state);
310232bdaf6SHajimu UMEMOTO 	printf("\n");
3119a4365d0SYoshinobu Inoue 
3129a4365d0SYoshinobu Inoue 	/* lifetime */
3139a4365d0SYoshinobu Inoue 	if (m_lftc != NULL) {
3149a4365d0SYoshinobu Inoue 		time_t tmp_time = time(0);
3159a4365d0SYoshinobu Inoue 
3169a4365d0SYoshinobu Inoue 		printf("\tcreated: %s",
3173c62e87aSJun-ichiro itojun Hagino 			str_time(m_lftc->sadb_lifetime_addtime));
3183c62e87aSJun-ichiro itojun Hagino 		printf("\tcurrent: %s\n", str_time(tmp_time));
3199a4365d0SYoshinobu Inoue 		printf("\tdiff: %lu(s)",
3209a4365d0SYoshinobu Inoue 			(u_long)(m_lftc->sadb_lifetime_addtime == 0 ?
3219a4365d0SYoshinobu Inoue 			0 : (tmp_time - m_lftc->sadb_lifetime_addtime)));
3229a4365d0SYoshinobu Inoue 
3239a4365d0SYoshinobu Inoue 		printf("\thard: %lu(s)",
3249a4365d0SYoshinobu Inoue 			(u_long)(m_lfth == NULL ?
3259a4365d0SYoshinobu Inoue 			0 : m_lfth->sadb_lifetime_addtime));
3269a4365d0SYoshinobu Inoue 		printf("\tsoft: %lu(s)\n",
3279a4365d0SYoshinobu Inoue 			(u_long)(m_lfts == NULL ?
3289a4365d0SYoshinobu Inoue 			0 : m_lfts->sadb_lifetime_addtime));
3299a4365d0SYoshinobu Inoue 
3309a4365d0SYoshinobu Inoue 		printf("\tlast: %s",
3313c62e87aSJun-ichiro itojun Hagino 			str_time(m_lftc->sadb_lifetime_usetime));
3329a4365d0SYoshinobu Inoue 		printf("\thard: %lu(s)",
3339a4365d0SYoshinobu Inoue 			(u_long)(m_lfth == NULL ?
3349a4365d0SYoshinobu Inoue 			0 : m_lfth->sadb_lifetime_usetime));
3359a4365d0SYoshinobu Inoue 		printf("\tsoft: %lu(s)\n",
3369a4365d0SYoshinobu Inoue 			(u_long)(m_lfts == NULL ?
3379a4365d0SYoshinobu Inoue 			0 : m_lfts->sadb_lifetime_usetime));
3389a4365d0SYoshinobu Inoue 
3393c62e87aSJun-ichiro itojun Hagino 		str_lifetime_byte(m_lftc, "current");
3403c62e87aSJun-ichiro itojun Hagino 		str_lifetime_byte(m_lfth, "hard");
3413c62e87aSJun-ichiro itojun Hagino 		str_lifetime_byte(m_lfts, "soft");
3429a4365d0SYoshinobu Inoue 		printf("\n");
3439a4365d0SYoshinobu Inoue 
3449a4365d0SYoshinobu Inoue 		printf("\tallocated: %lu",
3459a4365d0SYoshinobu Inoue 			(unsigned long)m_lftc->sadb_lifetime_allocations);
3469a4365d0SYoshinobu Inoue 		printf("\thard: %lu",
3479a4365d0SYoshinobu Inoue 			(u_long)(m_lfth == NULL ?
3489a4365d0SYoshinobu Inoue 			0 : m_lfth->sadb_lifetime_allocations));
3499a4365d0SYoshinobu Inoue 		printf("\tsoft: %lu\n",
3509a4365d0SYoshinobu Inoue 			(u_long)(m_lfts == NULL ?
3519a4365d0SYoshinobu Inoue 			0 : m_lfts->sadb_lifetime_allocations));
3529a4365d0SYoshinobu Inoue 	}
3539a4365d0SYoshinobu Inoue 
354232bdaf6SHajimu UMEMOTO 	printf("\tsadb_seq=%lu pid=%lu ",
355232bdaf6SHajimu UMEMOTO 		(u_long)m->sadb_msg_seq,
356232bdaf6SHajimu UMEMOTO 		(u_long)m->sadb_msg_pid);
357232bdaf6SHajimu UMEMOTO 
3589a4365d0SYoshinobu Inoue 	/* XXX DEBUG */
359232bdaf6SHajimu UMEMOTO 	printf("refcnt=%u\n", m->sadb_msg_reserved);
3609a4365d0SYoshinobu Inoue 
3619a4365d0SYoshinobu Inoue 	return;
3629a4365d0SYoshinobu Inoue }
3639a4365d0SYoshinobu Inoue 
3649a4365d0SYoshinobu Inoue void
3659a4365d0SYoshinobu Inoue pfkey_spdump(m)
3669a4365d0SYoshinobu Inoue 	struct sadb_msg *m;
3679a4365d0SYoshinobu Inoue {
3683c62e87aSJun-ichiro itojun Hagino 	char pbuf[NI_MAXSERV];
3699a4365d0SYoshinobu Inoue 	caddr_t mhp[SADB_EXT_MAX + 1];
3709a4365d0SYoshinobu Inoue 	struct sadb_address *m_saddr, *m_daddr;
3719a4365d0SYoshinobu Inoue 	struct sadb_x_policy *m_xpl;
372bd9f52d5SHajimu UMEMOTO 	struct sadb_lifetime *m_lftc = NULL, *m_lfth = NULL;
3733c62e87aSJun-ichiro itojun Hagino 	struct sockaddr *sa;
374bd9f52d5SHajimu UMEMOTO 	u_int16_t sport = 0, dport = 0;
3759a4365d0SYoshinobu Inoue 
3769a4365d0SYoshinobu Inoue 	/* check pfkey message. */
3779a4365d0SYoshinobu Inoue 	if (pfkey_align(m, mhp)) {
3789a4365d0SYoshinobu Inoue 		printf("%s\n", ipsec_strerror());
3799a4365d0SYoshinobu Inoue 		return;
3809a4365d0SYoshinobu Inoue 	}
3819a4365d0SYoshinobu Inoue 	if (pfkey_check(mhp)) {
3829a4365d0SYoshinobu Inoue 		printf("%s\n", ipsec_strerror());
3839a4365d0SYoshinobu Inoue 		return;
3849a4365d0SYoshinobu Inoue 	}
3859a4365d0SYoshinobu Inoue 
3869a4365d0SYoshinobu Inoue 	m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
3879a4365d0SYoshinobu Inoue 	m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
3889a4365d0SYoshinobu Inoue 	m_xpl = (struct sadb_x_policy *)mhp[SADB_X_EXT_POLICY];
389bd9f52d5SHajimu UMEMOTO 	m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
390bd9f52d5SHajimu UMEMOTO 	m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
3919a4365d0SYoshinobu Inoue 
392bd9f52d5SHajimu UMEMOTO 	if (m_saddr && m_daddr) {
3939a4365d0SYoshinobu Inoue 		/* source address */
3943c62e87aSJun-ichiro itojun Hagino 		sa = (struct sockaddr *)(m_saddr + 1);
3953c62e87aSJun-ichiro itojun Hagino 		switch (sa->sa_family) {
3963c62e87aSJun-ichiro itojun Hagino 		case AF_INET:
3973c62e87aSJun-ichiro itojun Hagino 		case AF_INET6:
398bd9f52d5SHajimu UMEMOTO 			if (getnameinfo(sa, sa->sa_len, NULL, 0,
399bd9f52d5SHajimu UMEMOTO 			    pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
400bd9f52d5SHajimu UMEMOTO 				sport = 0;	/*XXX*/
4013c62e87aSJun-ichiro itojun Hagino 			else
402bd9f52d5SHajimu UMEMOTO 				sport = atoi(pbuf);
4033c62e87aSJun-ichiro itojun Hagino 			printf("%s%s ", str_ipaddr(sa),
4043c62e87aSJun-ichiro itojun Hagino 				str_prefport(sa->sa_family,
405bd9f52d5SHajimu UMEMOTO 				    m_saddr->sadb_address_prefixlen, sport,
406bd9f52d5SHajimu UMEMOTO 				    m_saddr->sadb_address_proto));
4073c62e87aSJun-ichiro itojun Hagino 			break;
4083c62e87aSJun-ichiro itojun Hagino 		default:
4093c62e87aSJun-ichiro itojun Hagino 			printf("unknown-af ");
4103c62e87aSJun-ichiro itojun Hagino 			break;
4113c62e87aSJun-ichiro itojun Hagino 		}
4129a4365d0SYoshinobu Inoue 
4139a4365d0SYoshinobu Inoue 		/* destination address */
4143c62e87aSJun-ichiro itojun Hagino 		sa = (struct sockaddr *)(m_daddr + 1);
4153c62e87aSJun-ichiro itojun Hagino 		switch (sa->sa_family) {
4163c62e87aSJun-ichiro itojun Hagino 		case AF_INET:
4173c62e87aSJun-ichiro itojun Hagino 		case AF_INET6:
418bd9f52d5SHajimu UMEMOTO 			if (getnameinfo(sa, sa->sa_len, NULL, 0,
419bd9f52d5SHajimu UMEMOTO 			    pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
420bd9f52d5SHajimu UMEMOTO 				dport = 0;	/*XXX*/
4213c62e87aSJun-ichiro itojun Hagino 			else
422bd9f52d5SHajimu UMEMOTO 				dport = atoi(pbuf);
4233c62e87aSJun-ichiro itojun Hagino 			printf("%s%s ", str_ipaddr(sa),
4243c62e87aSJun-ichiro itojun Hagino 				str_prefport(sa->sa_family,
425bd9f52d5SHajimu UMEMOTO 				    m_daddr->sadb_address_prefixlen, dport,
426bd9f52d5SHajimu UMEMOTO 				    m_saddr->sadb_address_proto));
4273c62e87aSJun-ichiro itojun Hagino 			break;
4283c62e87aSJun-ichiro itojun Hagino 		default:
4293c62e87aSJun-ichiro itojun Hagino 			printf("unknown-af ");
4303c62e87aSJun-ichiro itojun Hagino 			break;
4313c62e87aSJun-ichiro itojun Hagino 		}
4329a4365d0SYoshinobu Inoue 
4339a4365d0SYoshinobu Inoue 		/* upper layer protocol */
434bd9f52d5SHajimu UMEMOTO 		if (m_saddr->sadb_address_proto !=
435bd9f52d5SHajimu UMEMOTO 		    m_daddr->sadb_address_proto) {
4369a4365d0SYoshinobu Inoue 			printf("upper layer protocol mismatched.\n");
4379a4365d0SYoshinobu Inoue 			return;
4389a4365d0SYoshinobu Inoue 		}
439bd9f52d5SHajimu UMEMOTO 		str_upperspec(m_saddr->sadb_address_proto, sport, dport);
440bd9f52d5SHajimu UMEMOTO 	}
4419a4365d0SYoshinobu Inoue 	else
442bd9f52d5SHajimu UMEMOTO 		printf("(no selector, probably per-socket policy) ");
4439a4365d0SYoshinobu Inoue 
4449a4365d0SYoshinobu Inoue 	/* policy */
4459a4365d0SYoshinobu Inoue     {
4469a4365d0SYoshinobu Inoue 	char *d_xpl;
4479a4365d0SYoshinobu Inoue 
4489a4365d0SYoshinobu Inoue 	if (m_xpl == NULL) {
4499a4365d0SYoshinobu Inoue 		printf("no X_POLICY extension.\n");
4509a4365d0SYoshinobu Inoue 		return;
4519a4365d0SYoshinobu Inoue 	}
4529a4365d0SYoshinobu Inoue 	d_xpl = ipsec_dump_policy((char *)m_xpl, "\n\t");
4539a4365d0SYoshinobu Inoue 
4549a4365d0SYoshinobu Inoue 	/* dump SPD */
4559a4365d0SYoshinobu Inoue 	printf("\n\t%s\n", d_xpl);
4569a4365d0SYoshinobu Inoue 	free(d_xpl);
4579a4365d0SYoshinobu Inoue     }
4589a4365d0SYoshinobu Inoue 
45933841545SHajimu UMEMOTO 	/* lifetime */
460bd9f52d5SHajimu UMEMOTO 	if (m_lftc) {
461bd9f52d5SHajimu UMEMOTO 		printf("\tcreated: %s  ",
462bd9f52d5SHajimu UMEMOTO 			str_time(m_lftc->sadb_lifetime_addtime));
463bd9f52d5SHajimu UMEMOTO 		printf("lastused: %s\n",
464bd9f52d5SHajimu UMEMOTO 			str_time(m_lftc->sadb_lifetime_usetime));
46533841545SHajimu UMEMOTO 	}
466bd9f52d5SHajimu UMEMOTO 	if (m_lfth) {
467bd9f52d5SHajimu UMEMOTO 		printf("\tlifetime: %lu(s) ",
468bd9f52d5SHajimu UMEMOTO 			(u_long)m_lfth->sadb_lifetime_addtime);
469bd9f52d5SHajimu UMEMOTO 		printf("validtime: %lu(s)\n",
470bd9f52d5SHajimu UMEMOTO 			(u_long)m_lfth->sadb_lifetime_usetime);
471bd9f52d5SHajimu UMEMOTO 	}
472bd9f52d5SHajimu UMEMOTO 
47333841545SHajimu UMEMOTO 
4743c62e87aSJun-ichiro itojun Hagino 	printf("\tspid=%ld seq=%ld pid=%ld\n",
4753c62e87aSJun-ichiro itojun Hagino 		(u_long)m_xpl->sadb_x_policy_id,
4769a4365d0SYoshinobu Inoue 		(u_long)m->sadb_msg_seq,
4779a4365d0SYoshinobu Inoue 		(u_long)m->sadb_msg_pid);
4789a4365d0SYoshinobu Inoue 
4799a4365d0SYoshinobu Inoue 	/* XXX TEST */
4803c62e87aSJun-ichiro itojun Hagino 	printf("\trefcnt=%u\n", m->sadb_msg_reserved);
4819a4365d0SYoshinobu Inoue 
4829a4365d0SYoshinobu Inoue 	return;
4839a4365d0SYoshinobu Inoue }
4849a4365d0SYoshinobu Inoue 
4859a4365d0SYoshinobu Inoue /*
4869a4365d0SYoshinobu Inoue  * set "ipaddress" to buffer.
4879a4365d0SYoshinobu Inoue  */
4889a4365d0SYoshinobu Inoue static char *
4893c62e87aSJun-ichiro itojun Hagino str_ipaddr(sa)
4903c62e87aSJun-ichiro itojun Hagino 	struct sockaddr *sa;
4919a4365d0SYoshinobu Inoue {
4923c62e87aSJun-ichiro itojun Hagino 	static char buf[NI_MAXHOST];
4933c62e87aSJun-ichiro itojun Hagino 	const int niflag = NI_NUMERICHOST;
4949a4365d0SYoshinobu Inoue 
4953c62e87aSJun-ichiro itojun Hagino 	if (sa == NULL)
4969a4365d0SYoshinobu Inoue 		return "";
4979a4365d0SYoshinobu Inoue 
4983c62e87aSJun-ichiro itojun Hagino 	if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0, niflag) == 0)
4999a4365d0SYoshinobu Inoue 		return buf;
5003c62e87aSJun-ichiro itojun Hagino 	return NULL;
5019a4365d0SYoshinobu Inoue }
5029a4365d0SYoshinobu Inoue 
5039a4365d0SYoshinobu Inoue /*
5049a4365d0SYoshinobu Inoue  * set "/prefix[port number]" to buffer.
5059a4365d0SYoshinobu Inoue  */
5069a4365d0SYoshinobu Inoue static char *
507bd9f52d5SHajimu UMEMOTO str_prefport(family, pref, port, ulp)
508bd9f52d5SHajimu UMEMOTO 	u_int family, pref, port, ulp;
5099a4365d0SYoshinobu Inoue {
5109a4365d0SYoshinobu Inoue 	static char buf[128];
511296e054fSMunechika SUMIKAWA 	char prefbuf[128];
512296e054fSMunechika SUMIKAWA 	char portbuf[128];
5133c62e87aSJun-ichiro itojun Hagino 	int plen;
5149a4365d0SYoshinobu Inoue 
5153c62e87aSJun-ichiro itojun Hagino 	switch (family) {
5163c62e87aSJun-ichiro itojun Hagino 	case AF_INET:
5173c62e87aSJun-ichiro itojun Hagino 		plen = sizeof(struct in_addr) << 3;
5183c62e87aSJun-ichiro itojun Hagino 		break;
5193c62e87aSJun-ichiro itojun Hagino 	case AF_INET6:
5203c62e87aSJun-ichiro itojun Hagino 		plen = sizeof(struct in6_addr) << 3;
5213c62e87aSJun-ichiro itojun Hagino 		break;
5223c62e87aSJun-ichiro itojun Hagino 	default:
5233c62e87aSJun-ichiro itojun Hagino 		return "?";
5243c62e87aSJun-ichiro itojun Hagino 	}
5253c62e87aSJun-ichiro itojun Hagino 
5263c62e87aSJun-ichiro itojun Hagino 	if (pref == plen)
5279a4365d0SYoshinobu Inoue 		prefbuf[0] = '\0';
5289a4365d0SYoshinobu Inoue 	else
5299a4365d0SYoshinobu Inoue 		snprintf(prefbuf, sizeof(prefbuf), "/%u", pref);
5309a4365d0SYoshinobu Inoue 
531bd9f52d5SHajimu UMEMOTO 	if (ulp == IPPROTO_ICMPV6)
532bd9f52d5SHajimu UMEMOTO 		memset(portbuf, 0, sizeof(portbuf));
533bd9f52d5SHajimu UMEMOTO 	else {
5349a4365d0SYoshinobu Inoue 		if (port == IPSEC_PORT_ANY)
5359a4365d0SYoshinobu Inoue 			snprintf(portbuf, sizeof(portbuf), "[%s]", "any");
5369a4365d0SYoshinobu Inoue 		else
5373c62e87aSJun-ichiro itojun Hagino 			snprintf(portbuf, sizeof(portbuf), "[%u]", port);
538bd9f52d5SHajimu UMEMOTO 	}
5399a4365d0SYoshinobu Inoue 
5409a4365d0SYoshinobu Inoue 	snprintf(buf, sizeof(buf), "%s%s", prefbuf, portbuf);
5419a4365d0SYoshinobu Inoue 
5429a4365d0SYoshinobu Inoue 	return buf;
5439a4365d0SYoshinobu Inoue }
5449a4365d0SYoshinobu Inoue 
545bd9f52d5SHajimu UMEMOTO static void
546bd9f52d5SHajimu UMEMOTO str_upperspec(ulp, p1, p2)
547bd9f52d5SHajimu UMEMOTO 	u_int ulp, p1, p2;
548bd9f52d5SHajimu UMEMOTO {
549bd9f52d5SHajimu UMEMOTO 	if (ulp == IPSEC_ULPROTO_ANY)
550bd9f52d5SHajimu UMEMOTO 		printf("any");
551bd9f52d5SHajimu UMEMOTO 	else if (ulp == IPPROTO_ICMPV6) {
552bd9f52d5SHajimu UMEMOTO 		printf("icmp6");
553bd9f52d5SHajimu UMEMOTO 		if (!(p1 == IPSEC_PORT_ANY && p2 == IPSEC_PORT_ANY))
554bd9f52d5SHajimu UMEMOTO 			printf(" %u,%u", p1, p2);
555bd9f52d5SHajimu UMEMOTO 	} else {
556bd9f52d5SHajimu UMEMOTO 		struct protoent *ent;
557bd9f52d5SHajimu UMEMOTO 
558bd9f52d5SHajimu UMEMOTO 		switch (ulp) {
559bd9f52d5SHajimu UMEMOTO 		case IPPROTO_IPV4:
560bd9f52d5SHajimu UMEMOTO 			printf("ip4");
561bd9f52d5SHajimu UMEMOTO 			break;
562bd9f52d5SHajimu UMEMOTO 		default:
563bd9f52d5SHajimu UMEMOTO 			ent = getprotobynumber(ulp);
564bd9f52d5SHajimu UMEMOTO 			if (ent)
565bd9f52d5SHajimu UMEMOTO 				printf("%s", ent->p_name);
566bd9f52d5SHajimu UMEMOTO 			else
567bd9f52d5SHajimu UMEMOTO 				printf("%u", ulp);
568bd9f52d5SHajimu UMEMOTO 
569bd9f52d5SHajimu UMEMOTO 			endprotoent();
570bd9f52d5SHajimu UMEMOTO 			break;
571bd9f52d5SHajimu UMEMOTO 		}
572bd9f52d5SHajimu UMEMOTO 	}
573bd9f52d5SHajimu UMEMOTO }
574bd9f52d5SHajimu UMEMOTO 
5759a4365d0SYoshinobu Inoue /*
5769a4365d0SYoshinobu Inoue  * set "Mon Day Time Year" to buffer
5779a4365d0SYoshinobu Inoue  */
5789a4365d0SYoshinobu Inoue static char *
5793c62e87aSJun-ichiro itojun Hagino str_time(t)
5809a4365d0SYoshinobu Inoue 	time_t t;
5819a4365d0SYoshinobu Inoue {
5829a4365d0SYoshinobu Inoue 	static char buf[128];
5839a4365d0SYoshinobu Inoue 
5849a4365d0SYoshinobu Inoue 	if (t == 0) {
5859a4365d0SYoshinobu Inoue 		int i = 0;
5869a4365d0SYoshinobu Inoue 		for (;i < 20;) buf[i++] = ' ';
5879a4365d0SYoshinobu Inoue 	} else {
5889a4365d0SYoshinobu Inoue 		char *t0;
5899a4365d0SYoshinobu Inoue 		t0 = ctime(&t);
5909a4365d0SYoshinobu Inoue 		memcpy(buf, t0 + 4, 20);
5919a4365d0SYoshinobu Inoue 	}
5929a4365d0SYoshinobu Inoue 
5939a4365d0SYoshinobu Inoue 	buf[20] = '\0';
5949a4365d0SYoshinobu Inoue 
5959a4365d0SYoshinobu Inoue 	return(buf);
5969a4365d0SYoshinobu Inoue }
5979a4365d0SYoshinobu Inoue 
5989a4365d0SYoshinobu Inoue static void
5993c62e87aSJun-ichiro itojun Hagino str_lifetime_byte(x, str)
6009a4365d0SYoshinobu Inoue 	struct sadb_lifetime *x;
6019a4365d0SYoshinobu Inoue 	char *str;
6029a4365d0SYoshinobu Inoue {
6039a4365d0SYoshinobu Inoue 	double y;
6049a4365d0SYoshinobu Inoue 	char *unit;
6059a4365d0SYoshinobu Inoue 	int w;
6069a4365d0SYoshinobu Inoue 
6079a4365d0SYoshinobu Inoue 	if (x == NULL) {
6089a4365d0SYoshinobu Inoue 		printf("\t%s: 0(bytes)", str);
6099a4365d0SYoshinobu Inoue 		return;
6109a4365d0SYoshinobu Inoue 	}
6119a4365d0SYoshinobu Inoue 
6123c62e87aSJun-ichiro itojun Hagino #if 0
6133c62e87aSJun-ichiro itojun Hagino 	if ((x->sadb_lifetime_bytes) / 1024 / 1024) {
6143c62e87aSJun-ichiro itojun Hagino 		y = (x->sadb_lifetime_bytes) * 1.0 / 1024 / 1024;
6153c62e87aSJun-ichiro itojun Hagino 		unit = "M";
6163c62e87aSJun-ichiro itojun Hagino 		w = 1;
6173c62e87aSJun-ichiro itojun Hagino 	} else if ((x->sadb_lifetime_bytes) / 1024) {
6183c62e87aSJun-ichiro itojun Hagino 		y = (x->sadb_lifetime_bytes) * 1.0 / 1024;
6193c62e87aSJun-ichiro itojun Hagino 		unit = "K";
6203c62e87aSJun-ichiro itojun Hagino 		w = 1;
6213c62e87aSJun-ichiro itojun Hagino 	} else {
6229a4365d0SYoshinobu Inoue 		y = (x->sadb_lifetime_bytes) * 1.0;
6239a4365d0SYoshinobu Inoue 		unit = "";
6249a4365d0SYoshinobu Inoue 		w = 0;
6253c62e87aSJun-ichiro itojun Hagino 	}
6263c62e87aSJun-ichiro itojun Hagino #else
6273c62e87aSJun-ichiro itojun Hagino 	y = (x->sadb_lifetime_bytes) * 1.0;
6283c62e87aSJun-ichiro itojun Hagino 	unit = "";
6293c62e87aSJun-ichiro itojun Hagino 	w = 0;
6303c62e87aSJun-ichiro itojun Hagino #endif
6319a4365d0SYoshinobu Inoue 	printf("\t%s: %.*f(%sbytes)", str, w, y, unit);
6329a4365d0SYoshinobu Inoue }
633