1 /* $KAME: pfkey_dump.c,v 1.45 2003/09/08 10:14:56 itojun Exp $ */
4 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #ifdef HAVE_NETINET6_IPSEC
40 # include <netinet6/ipsec.h>
42 # include <netinet/ipsec.h>
45 #include <net/pfkeyv2.h>
47 #include <netinet/in.h>
48 #include <arpa/inet.h>
57 #include "ipsec_strerror.h"
60 /* cope with old kame headers - ugly */
61 #ifndef SADB_X_AALG_MD5
62 #define SADB_X_AALG_MD5 SADB_AALG_MD5
64 #ifndef SADB_X_AALG_SHA
65 #define SADB_X_AALG_SHA SADB_AALG_SHA
67 #ifndef SADB_X_AALG_NULL
68 #define SADB_X_AALG_NULL SADB_AALG_NULL
71 #ifndef SADB_X_EALG_BLOWFISHCBC
72 #define SADB_X_EALG_BLOWFISHCBC SADB_EALG_BLOWFISHCBC
74 #ifndef SADB_X_EALG_CAST128CBC
75 #define SADB_X_EALG_CAST128CBC SADB_EALG_CAST128CBC
77 #ifndef SADB_X_EALG_RC5CBC
78 #ifdef SADB_EALG_RC5CBC
79 #define SADB_X_EALG_RC5CBC SADB_EALG_RC5CBC
83 #define GETMSGSTR(str, num) \
86 if (sizeof((str)[0]) == 0 \
87 || num >= sizeof(str)/sizeof((str)[0])) \
88 printf("%u ", (num)); \
89 else if (strlen((str)[(num)]) == 0) \
90 printf("%u ", (num)); \
92 printf("%s ", (str)[(num)]); \
93 } while (/*CONSTCOND*/0)
95 #define GETMSGV2S(v2s, num) \
98 for (p = (v2s); p && p->str; p++) { \
99 if (p->val == (num)) \
103 printf("%s ", p->str); \
105 printf("%u ", (num)); \
106 } while (/*CONSTCOND*/0)
108 static char *str_ipaddr (struct sockaddr
*);
109 static char *str_ipport (struct sockaddr
*);
110 static char *str_prefport (u_int
, u_int
, u_int
, u_int
);
111 static void str_upperspec (u_int
, u_int
, u_int
);
112 static char *str_time (time_t);
113 static void str_lifetime_byte (struct sadb_lifetime
*, char *);
114 static void pfkey_sadump1 (struct sadb_msg
*, int);
115 static void pfkey_spdump1 (struct sadb_msg
*, int);
123 * Must to be re-written about following strings.
125 static char *str_satype
[] = {
140 static char *str_mode
[] = {
146 static char *str_state
[] = {
153 static struct val2str str_alg_auth
[] = {
154 { SADB_AALG_NONE
, "none", },
155 { SADB_AALG_MD5HMAC
, "hmac-md5", },
156 { SADB_AALG_SHA1HMAC
, "hmac-sha1", },
157 { SADB_X_AALG_MD5
, "md5", },
158 { SADB_X_AALG_SHA
, "sha", },
159 { SADB_X_AALG_NULL
, "null", },
160 #ifdef SADB_X_AALG_TCP_MD5
161 { SADB_X_AALG_TCP_MD5
, "tcp-md5", },
163 #ifdef SADB_X_AALG_SHA2_256
164 { SADB_X_AALG_SHA2_256
, "hmac-sha256", },
166 #ifdef SADB_X_AALG_SHA2_384
167 { SADB_X_AALG_SHA2_384
, "hmac-sha384", },
169 #ifdef SADB_X_AALG_SHA2_512
170 { SADB_X_AALG_SHA2_512
, "hmac-sha512", },
172 #ifdef SADB_X_AALG_RIPEMD160HMAC
173 { SADB_X_AALG_RIPEMD160HMAC
, "hmac-ripemd160", },
175 #ifdef SADB_X_AALG_AES_XCBC_MAC
176 { SADB_X_AALG_AES_XCBC_MAC
, "aes-xcbc-mac", },
181 static struct val2str str_alg_enc
[] = {
182 { SADB_EALG_NONE
, "none", },
183 { SADB_EALG_DESCBC
, "des-cbc", },
184 { SADB_EALG_3DESCBC
, "3des-cbc", },
185 { SADB_EALG_NULL
, "null", },
186 #ifdef SADB_X_EALG_RC5CBC
187 { SADB_X_EALG_RC5CBC
, "rc5-cbc", },
189 { SADB_X_EALG_CAST128CBC
, "cast128-cbc", },
190 { SADB_X_EALG_BLOWFISHCBC
, "blowfish-cbc", },
191 #ifdef SADB_X_EALG_AESCBC
192 { SADB_X_EALG_AESCBC
, "aes-cbc", },
194 #ifdef SADB_X_EALG_TWOFISHCBC
195 { SADB_X_EALG_TWOFISHCBC
, "twofish-cbc", },
197 #ifdef SADB_X_EALG_AESCTR
198 { SADB_X_EALG_AESCTR
, "aes-ctr", },
203 static struct val2str str_alg_comp
[] = {
204 { SADB_X_CALG_NONE
, "none", },
205 { SADB_X_CALG_OUI
, "oui", },
206 { SADB_X_CALG_DEFLATE
, "deflate", },
207 { SADB_X_CALG_LZS
, "lzs", },
212 * dump SADB_MSG formated. For debugging, you should use kdebug_sadb().
223 pfkey_sadump_withports(m
)
230 pfkey_sadump1(m
, withports
)
234 caddr_t mhp
[SADB_EXT_MAX
+ 1];
235 struct sadb_sa
*m_sa
;
236 struct sadb_x_sa2
*m_sa2
;
237 struct sadb_lifetime
*m_lftc
, *m_lfth
, *m_lfts
;
238 struct sadb_address
*m_saddr
, *m_daddr
;
240 struct sadb_address
*m_paddr
;
242 struct sadb_key
*m_auth
, *m_enc
;
244 struct sadb_ident
*m_sid
, *m_did
;
245 struct sadb_sens
*m_sens
;
247 #ifdef SADB_X_EXT_NAT_T_TYPE
248 struct sadb_x_nat_t_type
*natt_type
;
249 struct sadb_x_nat_t_port
*natt_sport
, *natt_dport
;
250 struct sadb_address
*natt_oa
;
254 struct sadb_x_ipsecif
*m_ipif
= NULL
;
257 /* check pfkey message. */
258 if (pfkey_align(m
, mhp
)) {
259 printf("%s\n", ipsec_strerror());
262 if (pfkey_check(mhp
)) {
263 printf("%s\n", ipsec_strerror());
267 m_sa
= (void *)mhp
[SADB_EXT_SA
];
268 m_sa2
= (void *)mhp
[SADB_X_EXT_SA2
];
269 m_lftc
= (void *)mhp
[SADB_EXT_LIFETIME_CURRENT
];
270 m_lfth
= (void *)mhp
[SADB_EXT_LIFETIME_HARD
];
271 m_lfts
= (void *)mhp
[SADB_EXT_LIFETIME_SOFT
];
272 m_saddr
= (void *)mhp
[SADB_EXT_ADDRESS_SRC
];
273 m_daddr
= (void *)mhp
[SADB_EXT_ADDRESS_DST
];
275 m_paddr
= (void *)mhp
[SADB_EXT_ADDRESS_PROXY
];
277 m_auth
= (void *)mhp
[SADB_EXT_KEY_AUTH
];
278 m_enc
= (void *)mhp
[SADB_EXT_KEY_ENCRYPT
];
280 m_sid
= (void *)mhp
[SADB_EXT_IDENTITY_SRC
];
281 m_did
= (void *)mhp
[SADB_EXT_IDENTITY_DST
];
282 m_sens
= (void *)mhp
[SADB_EXT_SENSITIVITY
];
284 #ifdef SADB_X_EXT_NAT_T_TYPE
285 natt_type
= (void *)mhp
[SADB_X_EXT_NAT_T_TYPE
];
286 natt_sport
= (void *)mhp
[SADB_X_EXT_NAT_T_SPORT
];
287 natt_dport
= (void *)mhp
[SADB_X_EXT_NAT_T_DPORT
];
288 natt_oa
= (void *)mhp
[SADB_X_EXT_NAT_T_OA
];
290 if (natt_type
&& natt_type
->sadb_x_nat_t_type_type
)
293 m_ipif
= (void *)mhp
[SADB_X_EXT_IPSECIF
];
295 if (m_saddr
== NULL
) {
296 printf("no ADDRESS_SRC extension.\n");
299 sa
= (void *)(m_saddr
+ 1);
301 printf("%s[%s]", str_ipaddr(sa
), str_ipport(sa
));
303 printf("%s", str_ipaddr(sa
));
304 #ifdef SADB_X_EXT_NAT_T_TYPE
305 if (use_natt
&& natt_sport
)
306 printf("[%u]", ntohs(natt_sport
->sadb_x_nat_t_port_port
));
310 /* destination address */
311 if (m_daddr
== NULL
) {
312 printf(" no ADDRESS_DST extension.\n");
315 sa
= (void *)(m_daddr
+ 1);
317 printf("%s[%s]", str_ipaddr(sa
), str_ipport(sa
));
319 printf("%s", str_ipaddr(sa
));
320 #ifdef SADB_X_EXT_NAT_T_TYPE
321 if (use_natt
&& natt_dport
)
322 printf("[%u]", ntohs(natt_dport
->sadb_x_nat_t_port_port
));
328 printf("no SA extension.\n");
332 printf("no SA2 extension.\n");
337 #ifdef SADB_X_EXT_NAT_T_TYPE
338 if (use_natt
&& m
->sadb_msg_satype
== SADB_SATYPE_ESP
)
343 if (!use_natt
|| m
->sadb_msg_satype
!= SADB_SATYPE_ESP
)
345 GETMSGSTR(str_satype
, m
->sadb_msg_satype
);
348 GETMSGSTR(str_mode
, m_sa2
->sadb_x_sa2_mode
);
350 printf("spi=%u(0x%08x) reqid=%u(0x%08x)\n",
351 (u_int32_t
)ntohl(m_sa
->sadb_sa_spi
),
352 (u_int32_t
)ntohl(m_sa
->sadb_sa_spi
),
353 (u_int32_t
)m_sa2
->sadb_x_sa2_reqid
,
354 (u_int32_t
)m_sa2
->sadb_x_sa2_reqid
);
356 #ifdef SADB_X_EXT_NAT_T_TYPE
357 /* other NAT-T information */
358 if (use_natt
&& natt_oa
)
359 printf("\tNAT OA=%s\n",
360 str_ipaddr((void *)(natt_oa
+ 1)));
364 if (m
->sadb_msg_satype
== SADB_X_SATYPE_IPCOMP
) {
366 GETMSGV2S(str_alg_comp
, m_sa
->sadb_sa_encrypt
);
367 } else if (m
->sadb_msg_satype
== SADB_SATYPE_ESP
) {
370 GETMSGV2S(str_alg_enc
, m_sa
->sadb_sa_encrypt
);
371 ipsec_hexdump((caddr_t
)(void *)m_enc
+ sizeof(*m_enc
),
372 m_enc
->sadb_key_bits
/ 8);
377 /* authentication key */
378 if (m_auth
!= NULL
) {
380 GETMSGV2S(str_alg_auth
, m_sa
->sadb_sa_auth
);
381 ipsec_hexdump((caddr_t
)(void *)m_auth
+ sizeof(*m_auth
),
382 m_auth
->sadb_key_bits
/ 8);
386 /* replay windoe size & flags */
387 printf("\tseq=0x%08x replay=%u flags=0x%08x ",
388 m_sa2
->sadb_x_sa2_sequence
,
389 m_sa
->sadb_sa_replay
,
390 m_sa
->sadb_sa_flags
);
392 #ifdef SADB_X_EXT_SA2_DELETE_ON_DETACH
393 printf("flags2=0x%08x ",
394 m_sa2
->sadb_x_sa2_flags
);
399 GETMSGSTR(str_state
, m_sa
->sadb_sa_state
);
404 if (m_ipif
->sadb_x_ipsecif_internal_if
[0])
405 printf("internal_if: %s ", m_ipif
->sadb_x_ipsecif_internal_if
);
406 if (m_ipif
->sadb_x_ipsecif_outgoing_if
[0])
407 printf("outgoing_if: %s ", m_ipif
->sadb_x_ipsecif_outgoing_if
);
408 if (m_ipif
->sadb_x_ipsecif_ipsec_if
[0])
409 printf("ipsec_if: %s ", m_ipif
->sadb_x_ipsecif_ipsec_if
);
410 printf("disabled: %d\n", m_ipif
->sadb_x_ipsecif_init_disabled
);
414 if (m_lftc
!= NULL
) {
415 time_t tmp_time
= time(0);
417 printf("\tcreated: %s",
418 str_time((long)m_lftc
->sadb_lifetime_addtime
));
419 printf("\tcurrent: %s\n", str_time(tmp_time
));
420 printf("\tdiff: %lu(s)",
421 (u_long
)(m_lftc
->sadb_lifetime_addtime
== 0 ?
422 0 : (tmp_time
- m_lftc
->sadb_lifetime_addtime
)));
424 printf("\thard: %lu(s)",
425 (u_long
)(m_lfth
== NULL
?
426 0 : m_lfth
->sadb_lifetime_addtime
));
427 printf("\tsoft: %lu(s)\n",
428 (u_long
)(m_lfts
== NULL
?
429 0 : m_lfts
->sadb_lifetime_addtime
));
432 str_time((long)m_lftc
->sadb_lifetime_usetime
));
433 printf("\thard: %lu(s)",
434 (u_long
)(m_lfth
== NULL
?
435 0 : m_lfth
->sadb_lifetime_usetime
));
436 printf("\tsoft: %lu(s)\n",
437 (u_long
)(m_lfts
== NULL
?
438 0 : m_lfts
->sadb_lifetime_usetime
));
440 str_lifetime_byte(m_lftc
, "current");
441 str_lifetime_byte(m_lfth
, "hard");
442 str_lifetime_byte(m_lfts
, "soft");
445 printf("\tallocated: %lu",
446 (unsigned long)m_lftc
->sadb_lifetime_allocations
);
447 printf("\thard: %lu",
448 (u_long
)(m_lfth
== NULL
?
449 0 : m_lfth
->sadb_lifetime_allocations
));
450 printf("\tsoft: %lu\n",
451 (u_long
)(m_lfts
== NULL
?
452 0 : m_lfts
->sadb_lifetime_allocations
));
455 printf("\tsadb_seq=%lu pid=%lu ",
456 (u_long
)m
->sadb_msg_seq
,
457 (u_long
)m
->sadb_msg_pid
);
460 printf("refcnt=%u\n", m
->sadb_msg_reserved
);
473 pfkey_spdump_withports(m
)
480 pfkey_dump_single_address (struct sadb_address
*addr
)
483 char pbuf
[NI_MAXSERV
];
485 sa
= (void *)(addr
+ 1);
486 switch (sa
->sa_family
) {
489 if (getnameinfo(sa
, (socklen_t
)sysdep_sa_len((struct sockaddr
*)sa
), NULL
,
490 0, pbuf
, sizeof(pbuf
), NI_NUMERICSERV
) != 0)
494 printf("%s%s", str_ipaddr(sa
),
495 str_prefport((u_int
)sa
->sa_family
,
496 (u_int
)addr
->sadb_address_prefixlen
,
498 (u_int
)addr
->sadb_address_proto
));
501 printf("unknown-af");
508 pfkey_spdump1(m
, withports
)
512 char pbuf
[NI_MAXSERV
];
513 caddr_t mhp
[SADB_EXT_MAX
+ 1];
514 struct sadb_address
*m_saddr
, *m_daddr
;
515 struct sadb_address
*m_saddr_s
, *m_saddr_e
, *m_daddr_s
, *m_daddr_e
;
516 #ifdef SADB_X_EXT_TAG
517 struct sadb_x_tag
*m_tag
;
519 struct sadb_x_policy
*m_xpl
;
520 struct sadb_lifetime
*m_lftc
= NULL
, *m_lfth
= NULL
;
521 struct sadb_x_ipsecif
*m_ipif
= NULL
;
523 u_int16_t sport
= 0, dport
= 0;
525 /* check pfkey message. */
526 if (pfkey_align(m
, mhp
)) {
527 printf("%s\n", ipsec_strerror());
530 if (pfkey_check(mhp
)) {
531 printf("%s\n", ipsec_strerror());
535 m_saddr
= (void *)mhp
[SADB_EXT_ADDRESS_SRC
];
536 m_daddr
= (void *)mhp
[SADB_EXT_ADDRESS_DST
];
537 m_saddr_s
= (void *)mhp
[SADB_X_EXT_ADDR_RANGE_SRC_START
];
538 m_saddr_e
= (void *)mhp
[SADB_X_EXT_ADDR_RANGE_SRC_END
];
539 m_daddr_s
= (void *)mhp
[SADB_X_EXT_ADDR_RANGE_DST_START
];
540 m_daddr_e
= (void *)mhp
[SADB_X_EXT_ADDR_RANGE_DST_END
];
541 #ifdef SADB_X_EXT_TAG
542 m_tag
= (void *)mhp
[SADB_X_EXT_TAG
];
544 m_xpl
= (void *)mhp
[SADB_X_EXT_POLICY
];
545 m_lftc
= (void *)mhp
[SADB_EXT_LIFETIME_CURRENT
];
546 m_lfth
= (void *)mhp
[SADB_EXT_LIFETIME_HARD
];
547 m_ipif
= (void *)mhp
[SADB_X_EXT_IPSECIF
];
549 if ((m_saddr
|| (m_saddr_s
&& m_saddr_e
)) && (m_daddr
|| (m_daddr_s
&& m_daddr_e
))) {
551 if (m_saddr_s
&& m_saddr_e
) {
552 pfkey_dump_single_address(m_saddr_s
);
554 pfkey_dump_single_address(m_saddr_e
);
556 } else if (m_saddr
) {
557 sa
= (void *)(m_saddr
+ 1);
558 switch (sa
->sa_family
) {
561 if (getnameinfo(sa
, (socklen_t
)sysdep_sa_len((struct sockaddr
*)sa
), NULL
,
562 0, pbuf
, sizeof(pbuf
), NI_NUMERICSERV
) != 0)
566 printf("%s%s ", str_ipaddr(sa
),
567 str_prefport((u_int
)sa
->sa_family
,
568 (u_int
)m_saddr
->sadb_address_prefixlen
,
570 (u_int
)m_saddr
->sadb_address_proto
));
573 printf("unknown-af ");
578 /* destination address */
579 if (m_daddr_s
&& m_daddr_e
) {
580 pfkey_dump_single_address(m_daddr_s
);
582 pfkey_dump_single_address(m_daddr_e
);
584 } else if (m_daddr
) {
585 sa
= (void *)(m_daddr
+ 1);
586 switch (sa
->sa_family
) {
589 if (getnameinfo(sa
, (socklen_t
)sysdep_sa_len((struct sockaddr
*)sa
), NULL
,
590 0, pbuf
, sizeof(pbuf
), NI_NUMERICSERV
) != 0)
594 printf("%s%s ", str_ipaddr(sa
),
595 str_prefport((u_int
)sa
->sa_family
,
596 (u_int
)m_daddr
->sadb_address_prefixlen
,
598 (u_int
)m_daddr
->sadb_address_proto
));
601 printf("unknown-af ");
606 /* upper layer protocol */
607 if (m_saddr
&& m_daddr
) {
608 if (m_saddr
->sadb_address_proto
!=
609 m_daddr
->sadb_address_proto
) {
610 printf("upper layer protocol mismatched.\n");
613 str_upperspec((u_int
)m_saddr
->sadb_address_proto
, (u_int
)sport
,
617 #ifdef SADB_X_EXT_TAG
619 printf("tagged \"%s\" ", m_tag
->sadb_x_tag_name
);
622 printf("(no selector, probably per-socket policy) ");
629 printf("no X_POLICY extension.\n");
633 d_xpl
= ipsec_dump_policy_withports(m_xpl
, "\n\t");
635 d_xpl
= ipsec_dump_policy((ipsec_policy_t
)m_xpl
, "\n\t");
638 printf("\n\tPolicy:[%s]\n", ipsec_strerror());
641 printf("\n\t%s\n", d_xpl
);
648 printf("\tcreated: %s ",
649 str_time((long)m_lftc
->sadb_lifetime_addtime
));
650 printf("lastused: %s\n",
651 str_time((long)m_lftc
->sadb_lifetime_usetime
));
654 printf("\tlifetime: %lu(s) ",
655 (u_long
)m_lfth
->sadb_lifetime_addtime
);
656 printf("validtime: %lu(s)\n",
657 (u_long
)m_lfth
->sadb_lifetime_usetime
);
662 if (m_ipif
->sadb_x_ipsecif_internal_if
[0])
663 printf("internal_if: %s ", m_ipif
->sadb_x_ipsecif_internal_if
);
664 if (m_ipif
->sadb_x_ipsecif_outgoing_if
[0])
665 printf("outgoing_if: %s ", m_ipif
->sadb_x_ipsecif_outgoing_if
);
666 if (m_ipif
->sadb_x_ipsecif_ipsec_if
[0])
667 printf("ipsec_if: %s ", m_ipif
->sadb_x_ipsecif_ipsec_if
);
668 printf("disabled: %d\n", m_ipif
->sadb_x_ipsecif_init_disabled
);
671 printf("\tspid=%ld seq=%ld pid=%ld\n",
672 (u_long
)m_xpl
->sadb_x_policy_id
,
673 (u_long
)m
->sadb_msg_seq
,
674 (u_long
)m
->sadb_msg_pid
);
677 printf("\trefcnt=%u\n", m
->sadb_msg_reserved
);
683 * set "ipaddress" to buffer.
689 static char buf
[NI_MAXHOST
];
690 const int niflag
= NI_NUMERICHOST
;
695 if (getnameinfo(sa
, (socklen_t
)sysdep_sa_len(sa
), buf
, sizeof(buf
),
696 NULL
, 0, niflag
) == 0)
702 * set "port" to buffer.
708 static char buf
[NI_MAXHOST
];
709 const int niflag
= NI_NUMERICSERV
;
714 if (getnameinfo(sa
, (socklen_t
)sysdep_sa_len(sa
), NULL
, 0,
715 buf
, sizeof(buf
), niflag
) == 0)
722 * set "/prefix[port number]" to buffer.
725 str_prefport(family
, pref
, port
, ulp
)
726 u_int family
, pref
, port
, ulp
;
728 static char buf
[128];
735 plen
= sizeof(struct in_addr
) << 3;
738 plen
= sizeof(struct in6_addr
) << 3;
747 snprintf(prefbuf
, sizeof(prefbuf
), "/%u", pref
);
749 if (ulp
== IPPROTO_ICMPV6
)
750 memset(portbuf
, 0, sizeof(portbuf
));
752 if (port
== IPSEC_PORT_ANY
)
753 snprintf(portbuf
, sizeof(portbuf
), "[%s]", "any");
755 snprintf(portbuf
, sizeof(portbuf
), "[%u]", port
);
758 snprintf(buf
, sizeof(buf
), "%s%s", prefbuf
, portbuf
);
764 str_upperspec(ulp
, p1
, p2
)
767 if (ulp
== IPSEC_ULPROTO_ANY
)
769 else if (ulp
== IPPROTO_ICMPV6
) {
771 if (!(p1
== IPSEC_PORT_ANY
&& p2
== IPSEC_PORT_ANY
))
772 printf(" %u,%u", p1
, p2
);
774 struct protoent
*ent
;
781 ent
= getprotobynumber((int)ulp
);
783 printf("%s", ent
->p_name
);
794 * set "Mon Day Time Year" to buffer
800 static char buf
[128];
804 for (;i
< 20;) buf
[i
++] = ' ';
808 memcpy(buf
, t0
+ 4, 20);
817 str_lifetime_byte(x
, str
)
818 struct sadb_lifetime
*x
;
826 printf("\t%s: 0(bytes)", str
);
831 if ((x
->sadb_lifetime_bytes
) / 1024 / 1024) {
832 y
= (x
->sadb_lifetime_bytes
) * 1.0 / 1024 / 1024;
835 } else if ((x
->sadb_lifetime_bytes
) / 1024) {
836 y
= (x
->sadb_lifetime_bytes
) * 1.0 / 1024;
840 y
= (x
->sadb_lifetime_bytes
) * 1.0;
845 y
= (x
->sadb_lifetime_bytes
) * 1.0;
849 printf("\t%s: %.*f(%sbytes)", str
, w
, y
, unit
);