2003-11-05 09:41:23 +00:00
|
|
|
/* $KAME: pfkey_dump.c,v 1.45 2003/09/08 10:14:56 itojun Exp $ */
|
2000-07-04 16:22:05 +00:00
|
|
|
|
2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2000-01-06 12:40:54 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 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:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 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
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 21:43:45 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
2017-03-07 00:13:53 +00:00
|
|
|
#include <net/if.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
#include <net/pfkeyv2.h>
|
2017-03-07 00:13:53 +00:00
|
|
|
#include <netipsec/ipsec.h>
|
2007-07-01 12:08:08 +00:00
|
|
|
#include <netipsec/key_var.h>
|
|
|
|
#include <netipsec/key_debug.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2000-07-04 16:22:05 +00:00
|
|
|
#include <netdb.h>
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
#include "ipsec_strerror.h"
|
2000-07-04 16:22:05 +00:00
|
|
|
#include "libpfkey.h"
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* cope with old kame headers - ugly */
|
|
|
|
#ifndef SADB_X_AALG_NULL
|
|
|
|
#define SADB_X_AALG_NULL SADB_AALG_NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SADB_X_EALG_RC5CBC
|
|
|
|
#ifdef SADB_EALG_RC5CBC
|
|
|
|
#define SADB_X_EALG_RC5CBC SADB_EALG_RC5CBC
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
#define GETMSGSTR(str, num) \
|
|
|
|
do { \
|
2000-01-06 12:40:54 +00:00
|
|
|
if (sizeof((str)[0]) == 0 \
|
|
|
|
|| num >= sizeof(str)/sizeof((str)[0])) \
|
2003-10-26 12:00:27 +00:00
|
|
|
printf("%u ", (num)); \
|
2000-01-06 12:40:54 +00:00
|
|
|
else if (strlen((str)[(num)]) == 0) \
|
2003-10-26 12:00:27 +00:00
|
|
|
printf("%u ", (num)); \
|
2000-01-06 12:40:54 +00:00
|
|
|
else \
|
|
|
|
printf("%s ", (str)[(num)]); \
|
2000-07-04 16:22:05 +00:00
|
|
|
} while (0)
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#define GETMSGV2S(v2s, num) \
|
|
|
|
do { \
|
|
|
|
struct val2str *p; \
|
|
|
|
for (p = (v2s); p && p->str; p++) { \
|
|
|
|
if (p->val == (num)) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
if (p && p->str) \
|
|
|
|
printf("%s ", p->str); \
|
|
|
|
else \
|
2003-10-26 12:00:27 +00:00
|
|
|
printf("%u ", (num)); \
|
2001-06-11 12:39:29 +00:00
|
|
|
} while (0)
|
|
|
|
|
2002-03-21 23:54:04 +00:00
|
|
|
static char *str_ipaddr(struct sockaddr *);
|
2003-11-05 09:41:23 +00:00
|
|
|
static char *str_prefport(u_int, u_int, u_int, u_int);
|
|
|
|
static void str_upperspec(u_int, u_int, u_int);
|
2002-03-21 23:54:04 +00:00
|
|
|
static char *str_time(time_t);
|
|
|
|
static void str_lifetime_byte(struct sadb_lifetime *, char *);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
struct val2str {
|
|
|
|
int val;
|
|
|
|
const char *str;
|
|
|
|
};
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* Must to be re-written about following strings.
|
|
|
|
*/
|
2001-06-11 12:39:29 +00:00
|
|
|
static char *str_satype[] = {
|
2000-01-06 12:40:54 +00:00
|
|
|
"unspec",
|
|
|
|
"unknown",
|
|
|
|
"ah",
|
|
|
|
"esp",
|
|
|
|
"unknown",
|
|
|
|
"rsvp",
|
|
|
|
"ospfv2",
|
|
|
|
"ripv2",
|
|
|
|
"mip",
|
|
|
|
"ipcomp",
|
2004-02-11 04:34:34 +00:00
|
|
|
"policy",
|
|
|
|
"tcp"
|
2000-01-06 12:40:54 +00:00
|
|
|
};
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static char *str_mode[] = {
|
2000-01-06 12:40:54 +00:00
|
|
|
"any",
|
|
|
|
"transport",
|
|
|
|
"tunnel",
|
|
|
|
};
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static char *str_state[] = {
|
2000-01-06 12:40:54 +00:00
|
|
|
"larval",
|
|
|
|
"mature",
|
|
|
|
"dying",
|
|
|
|
"dead",
|
|
|
|
};
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static struct val2str str_alg_auth[] = {
|
|
|
|
{ SADB_AALG_NONE, "none", },
|
|
|
|
{ SADB_AALG_SHA1HMAC, "hmac-sha1", },
|
|
|
|
{ SADB_X_AALG_NULL, "null", },
|
2004-02-11 04:34:34 +00:00
|
|
|
{ SADB_X_AALG_TCP_MD5, "tcp-md5", },
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef SADB_X_AALG_SHA2_256
|
|
|
|
{ SADB_X_AALG_SHA2_256, "hmac-sha2-256", },
|
|
|
|
#endif
|
|
|
|
#ifdef SADB_X_AALG_SHA2_384
|
|
|
|
{ SADB_X_AALG_SHA2_384, "hmac-sha2-384", },
|
|
|
|
#endif
|
|
|
|
#ifdef SADB_X_AALG_SHA2_512
|
|
|
|
{ SADB_X_AALG_SHA2_512, "hmac-sha2-512", },
|
2003-10-12 09:41:42 +00:00
|
|
|
#endif
|
2003-10-13 04:54:51 +00:00
|
|
|
#ifdef SADB_X_AALG_AES_XCBC_MAC
|
|
|
|
{ SADB_X_AALG_AES_XCBC_MAC, "aes-xcbc-mac", },
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
|
|
|
{ -1, NULL, },
|
2000-01-06 12:40:54 +00:00
|
|
|
};
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static struct val2str str_alg_enc[] = {
|
|
|
|
{ SADB_EALG_NONE, "none", },
|
|
|
|
{ SADB_EALG_NULL, "null", },
|
|
|
|
#ifdef SADB_X_EALG_RC5CBC
|
|
|
|
{ SADB_X_EALG_RC5CBC, "rc5-cbc", },
|
|
|
|
#endif
|
2020-06-04 22:58:37 +00:00
|
|
|
#ifdef SADB_X_EALG_AESCBC
|
|
|
|
{ SADB_X_EALG_AESCBC, "aes-cbc", },
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SADB_X_EALG_TWOFISHCBC
|
|
|
|
{ SADB_X_EALG_TWOFISHCBC, "twofish-cbc", },
|
2003-10-13 14:57:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SADB_X_EALG_AESCTR
|
|
|
|
{ SADB_X_EALG_AESCTR, "aes-ctr", },
|
2007-05-09 19:37:02 +00:00
|
|
|
#endif
|
2015-07-03 20:09:14 +00:00
|
|
|
#ifdef SADB_X_EALG_AESGCM16
|
|
|
|
{ SADB_X_EALG_AESGCM16, "aes-gcm-16", },
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
|
|
|
{ -1, NULL, },
|
2000-01-06 12:40:54 +00:00
|
|
|
};
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static struct val2str str_alg_comp[] = {
|
|
|
|
{ SADB_X_CALG_NONE, "none", },
|
|
|
|
{ SADB_X_CALG_OUI, "oui", },
|
|
|
|
{ SADB_X_CALG_DEFLATE, "deflate", },
|
|
|
|
{ SADB_X_CALG_LZS, "lzs", },
|
|
|
|
{ -1, NULL, },
|
2000-01-06 12:40:54 +00:00
|
|
|
};
|
|
|
|
|
2017-03-07 00:13:53 +00:00
|
|
|
static struct val2str str_sp_scope[] = {
|
|
|
|
{ IPSEC_POLICYSCOPE_GLOBAL, "global" },
|
|
|
|
{ IPSEC_POLICYSCOPE_IFNET, "ifnet" },
|
|
|
|
{ IPSEC_POLICYSCOPE_PCB, "pcb"},
|
|
|
|
{ -1, NULL },
|
|
|
|
};
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* dump SADB_MSG formated. For debugging, you should use kdebug_sadb().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pfkey_sadump(m)
|
|
|
|
struct sadb_msg *m;
|
|
|
|
{
|
|
|
|
caddr_t mhp[SADB_EXT_MAX + 1];
|
|
|
|
struct sadb_sa *m_sa;
|
2000-07-04 16:22:05 +00:00
|
|
|
struct sadb_x_sa2 *m_sa2;
|
2000-01-06 12:40:54 +00:00
|
|
|
struct sadb_lifetime *m_lftc, *m_lfth, *m_lfts;
|
|
|
|
struct sadb_address *m_saddr, *m_daddr, *m_paddr;
|
|
|
|
struct sadb_key *m_auth, *m_enc;
|
|
|
|
struct sadb_ident *m_sid, *m_did;
|
|
|
|
struct sadb_sens *m_sens;
|
2016-11-25 14:44:49 +00:00
|
|
|
struct sadb_x_sa_replay *m_sa_replay;
|
2017-02-06 08:49:57 +00:00
|
|
|
struct sadb_x_nat_t_type *natt_type;
|
|
|
|
struct sadb_x_nat_t_port *natt_sport, *natt_dport;
|
|
|
|
struct sadb_address *natt_oai, *natt_oar;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* check pfkey message. */
|
|
|
|
if (pfkey_align(m, mhp)) {
|
|
|
|
printf("%s\n", ipsec_strerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pfkey_check(mhp)) {
|
|
|
|
printf("%s\n", ipsec_strerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sa = (struct sadb_sa *)mhp[SADB_EXT_SA];
|
2000-07-04 16:22:05 +00:00
|
|
|
m_sa2 = (struct sadb_x_sa2 *)mhp[SADB_X_EXT_SA2];
|
2000-01-06 12:40:54 +00:00
|
|
|
m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
|
|
|
|
m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
|
|
|
|
m_lfts = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_SOFT];
|
|
|
|
m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
|
|
|
|
m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
|
|
|
|
m_paddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_PROXY];
|
|
|
|
m_auth = (struct sadb_key *)mhp[SADB_EXT_KEY_AUTH];
|
|
|
|
m_enc = (struct sadb_key *)mhp[SADB_EXT_KEY_ENCRYPT];
|
|
|
|
m_sid = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_SRC];
|
2000-07-04 16:22:05 +00:00
|
|
|
m_did = (struct sadb_ident *)mhp[SADB_EXT_IDENTITY_DST];
|
2000-01-06 12:40:54 +00:00
|
|
|
m_sens = (struct sadb_sens *)mhp[SADB_EXT_SENSITIVITY];
|
2016-11-25 14:44:49 +00:00
|
|
|
m_sa_replay = (struct sadb_x_sa_replay *)mhp[SADB_X_EXT_SA_REPLAY];
|
2017-02-06 08:49:57 +00:00
|
|
|
natt_type = (struct sadb_x_nat_t_type *)mhp[SADB_X_EXT_NAT_T_TYPE];
|
|
|
|
natt_sport = (struct sadb_x_nat_t_port *)mhp[SADB_X_EXT_NAT_T_SPORT];
|
|
|
|
natt_dport = (struct sadb_x_nat_t_port *)mhp[SADB_X_EXT_NAT_T_DPORT];
|
|
|
|
natt_oai = (struct sadb_address *)mhp[SADB_X_EXT_NAT_T_OAI];
|
|
|
|
natt_oar = (struct sadb_address *)mhp[SADB_X_EXT_NAT_T_OAR];
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* source address */
|
|
|
|
if (m_saddr == NULL) {
|
|
|
|
printf("no ADDRESS_SRC extension.\n");
|
|
|
|
return;
|
|
|
|
}
|
2017-02-06 08:49:57 +00:00
|
|
|
printf("%s", str_ipaddr((struct sockaddr *)(m_saddr + 1)));
|
|
|
|
if (natt_type != NULL && natt_sport != NULL)
|
|
|
|
printf("[%u]", ntohs(natt_sport->sadb_x_nat_t_port_port));
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* destination address */
|
|
|
|
if (m_daddr == NULL) {
|
2017-02-06 08:49:57 +00:00
|
|
|
printf("\nno ADDRESS_DST extension.\n");
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-06 08:49:57 +00:00
|
|
|
printf(" %s", str_ipaddr((struct sockaddr *)(m_daddr + 1)));
|
|
|
|
if (natt_type != NULL && natt_dport != NULL)
|
|
|
|
printf("[%u]", ntohs(natt_dport->sadb_x_nat_t_port_port));
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* SA type */
|
|
|
|
if (m_sa == NULL) {
|
2017-02-06 08:49:57 +00:00
|
|
|
printf("\nno SA extension.\n");
|
2000-01-06 12:40:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-04 16:22:05 +00:00
|
|
|
if (m_sa2 == NULL) {
|
2017-02-06 08:49:57 +00:00
|
|
|
printf("\nno SA2 extension.\n");
|
2000-07-04 16:22:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
printf("\n\t");
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
if (m->sadb_msg_satype == SADB_SATYPE_ESP && natt_type != NULL)
|
|
|
|
printf("esp-udp ");
|
|
|
|
else
|
|
|
|
GETMSGSTR(str_satype, m->sadb_msg_satype);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
printf("mode=");
|
2001-06-11 12:39:29 +00:00
|
|
|
GETMSGSTR(str_mode, m_sa2->sadb_x_sa2_mode);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
printf("spi=%u(0x%08x) reqid=%u(0x%08x)\n",
|
2000-01-06 12:40:54 +00:00
|
|
|
(u_int32_t)ntohl(m_sa->sadb_sa_spi),
|
|
|
|
(u_int32_t)ntohl(m_sa->sadb_sa_spi),
|
2000-07-04 16:22:05 +00:00
|
|
|
(u_int32_t)m_sa2->sadb_x_sa2_reqid,
|
|
|
|
(u_int32_t)m_sa2->sadb_x_sa2_reqid);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
/* other NAT-T information */
|
|
|
|
if (natt_type != NULL && (natt_oai != NULL || natt_oar != NULL)) {
|
|
|
|
printf("\tNAT:");
|
|
|
|
if (natt_oai != NULL)
|
|
|
|
printf(" OAI=%s",
|
|
|
|
str_ipaddr((struct sockaddr *)(natt_oai + 1)));
|
|
|
|
if (natt_oar != NULL)
|
|
|
|
printf(" OAR=%s",
|
|
|
|
str_ipaddr((struct sockaddr *)(natt_oar + 1)));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* encryption key */
|
|
|
|
if (m->sadb_msg_satype == SADB_X_SATYPE_IPCOMP) {
|
|
|
|
printf("\tC: ");
|
2001-06-11 12:39:29 +00:00
|
|
|
GETMSGV2S(str_alg_comp, m_sa->sadb_sa_encrypt);
|
2000-01-06 12:40:54 +00:00
|
|
|
} else if (m->sadb_msg_satype == SADB_SATYPE_ESP) {
|
|
|
|
if (m_enc != NULL) {
|
|
|
|
printf("\tE: ");
|
2001-06-11 12:39:29 +00:00
|
|
|
GETMSGV2S(str_alg_enc, m_sa->sadb_sa_encrypt);
|
2000-01-06 12:40:54 +00:00
|
|
|
ipsec_hexdump((caddr_t)m_enc + sizeof(*m_enc),
|
|
|
|
m_enc->sadb_key_bits / 8);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* authentication key */
|
|
|
|
if (m_auth != NULL) {
|
|
|
|
printf("\tA: ");
|
2001-06-11 12:39:29 +00:00
|
|
|
GETMSGV2S(str_alg_auth, m_sa->sadb_sa_auth);
|
2000-01-06 12:40:54 +00:00
|
|
|
ipsec_hexdump((caddr_t)m_auth + sizeof(*m_auth),
|
|
|
|
m_auth->sadb_key_bits / 8);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
/* replay windoe size & flags */
|
2001-08-06 19:40:01 +00:00
|
|
|
printf("\tseq=0x%08x replay=%u flags=0x%08x ",
|
|
|
|
m_sa2->sadb_x_sa2_sequence,
|
2016-11-25 14:44:49 +00:00
|
|
|
m_sa_replay ? (m_sa_replay->sadb_x_sa_replay_replay >> 3) :
|
|
|
|
m_sa->sadb_sa_replay,
|
2000-07-04 16:22:05 +00:00
|
|
|
m_sa->sadb_sa_flags);
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* state */
|
2000-07-04 16:22:05 +00:00
|
|
|
printf("state=");
|
2001-06-11 12:39:29 +00:00
|
|
|
GETMSGSTR(str_state, m_sa->sadb_sa_state);
|
2001-08-06 19:40:01 +00:00
|
|
|
printf("\n");
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* lifetime */
|
|
|
|
if (m_lftc != NULL) {
|
|
|
|
time_t tmp_time = time(0);
|
|
|
|
|
|
|
|
printf("\tcreated: %s",
|
2000-07-04 16:22:05 +00:00
|
|
|
str_time(m_lftc->sadb_lifetime_addtime));
|
|
|
|
printf("\tcurrent: %s\n", str_time(tmp_time));
|
2000-01-06 12:40:54 +00:00
|
|
|
printf("\tdiff: %lu(s)",
|
|
|
|
(u_long)(m_lftc->sadb_lifetime_addtime == 0 ?
|
|
|
|
0 : (tmp_time - m_lftc->sadb_lifetime_addtime)));
|
|
|
|
|
|
|
|
printf("\thard: %lu(s)",
|
|
|
|
(u_long)(m_lfth == NULL ?
|
|
|
|
0 : m_lfth->sadb_lifetime_addtime));
|
|
|
|
printf("\tsoft: %lu(s)\n",
|
|
|
|
(u_long)(m_lfts == NULL ?
|
|
|
|
0 : m_lfts->sadb_lifetime_addtime));
|
|
|
|
|
|
|
|
printf("\tlast: %s",
|
2000-07-04 16:22:05 +00:00
|
|
|
str_time(m_lftc->sadb_lifetime_usetime));
|
2000-01-06 12:40:54 +00:00
|
|
|
printf("\thard: %lu(s)",
|
|
|
|
(u_long)(m_lfth == NULL ?
|
|
|
|
0 : m_lfth->sadb_lifetime_usetime));
|
|
|
|
printf("\tsoft: %lu(s)\n",
|
|
|
|
(u_long)(m_lfts == NULL ?
|
|
|
|
0 : m_lfts->sadb_lifetime_usetime));
|
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
str_lifetime_byte(m_lftc, "current");
|
|
|
|
str_lifetime_byte(m_lfth, "hard");
|
|
|
|
str_lifetime_byte(m_lfts, "soft");
|
2000-01-06 12:40:54 +00:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("\tallocated: %lu",
|
|
|
|
(unsigned long)m_lftc->sadb_lifetime_allocations);
|
|
|
|
printf("\thard: %lu",
|
|
|
|
(u_long)(m_lfth == NULL ?
|
|
|
|
0 : m_lfth->sadb_lifetime_allocations));
|
|
|
|
printf("\tsoft: %lu\n",
|
|
|
|
(u_long)(m_lfts == NULL ?
|
|
|
|
0 : m_lfts->sadb_lifetime_allocations));
|
|
|
|
}
|
|
|
|
|
2001-08-06 19:40:01 +00:00
|
|
|
printf("\tsadb_seq=%lu pid=%lu ",
|
|
|
|
(u_long)m->sadb_msg_seq,
|
|
|
|
(u_long)m->sadb_msg_pid);
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/* XXX DEBUG */
|
2001-08-06 19:40:01 +00:00
|
|
|
printf("refcnt=%u\n", m->sadb_msg_reserved);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-07 00:13:53 +00:00
|
|
|
pfkey_spdump(struct sadb_msg *m)
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2000-07-04 16:22:05 +00:00
|
|
|
char pbuf[NI_MAXSERV];
|
2000-01-06 12:40:54 +00:00
|
|
|
caddr_t mhp[SADB_EXT_MAX + 1];
|
|
|
|
struct sadb_address *m_saddr, *m_daddr;
|
|
|
|
struct sadb_x_policy *m_xpl;
|
2003-11-05 09:41:23 +00:00
|
|
|
struct sadb_lifetime *m_lftc = NULL, *m_lfth = NULL;
|
2000-07-04 16:22:05 +00:00
|
|
|
struct sockaddr *sa;
|
2003-11-05 09:41:23 +00:00
|
|
|
u_int16_t sport = 0, dport = 0;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* check pfkey message. */
|
|
|
|
if (pfkey_align(m, mhp)) {
|
|
|
|
printf("%s\n", ipsec_strerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pfkey_check(mhp)) {
|
|
|
|
printf("%s\n", ipsec_strerror());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_saddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_SRC];
|
|
|
|
m_daddr = (struct sadb_address *)mhp[SADB_EXT_ADDRESS_DST];
|
|
|
|
m_xpl = (struct sadb_x_policy *)mhp[SADB_X_EXT_POLICY];
|
2003-11-05 09:41:23 +00:00
|
|
|
m_lftc = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_CURRENT];
|
|
|
|
m_lfth = (struct sadb_lifetime *)mhp[SADB_EXT_LIFETIME_HARD];
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
if (m_saddr && m_daddr) {
|
|
|
|
/* source address */
|
|
|
|
sa = (struct sockaddr *)(m_saddr + 1);
|
|
|
|
switch (sa->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
case AF_INET6:
|
|
|
|
if (getnameinfo(sa, sa->sa_len, NULL, 0,
|
|
|
|
pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
|
|
|
|
sport = 0; /*XXX*/
|
|
|
|
else
|
|
|
|
sport = atoi(pbuf);
|
|
|
|
printf("%s%s ", str_ipaddr(sa),
|
|
|
|
str_prefport(sa->sa_family,
|
|
|
|
m_saddr->sadb_address_prefixlen, sport,
|
|
|
|
m_saddr->sadb_address_proto));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown-af ");
|
|
|
|
break;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
/* destination address */
|
|
|
|
sa = (struct sockaddr *)(m_daddr + 1);
|
|
|
|
switch (sa->sa_family) {
|
|
|
|
case AF_INET:
|
|
|
|
case AF_INET6:
|
|
|
|
if (getnameinfo(sa, sa->sa_len, NULL, 0,
|
|
|
|
pbuf, sizeof(pbuf), NI_NUMERICSERV) != 0)
|
|
|
|
dport = 0; /*XXX*/
|
|
|
|
else
|
|
|
|
dport = atoi(pbuf);
|
|
|
|
printf("%s%s ", str_ipaddr(sa),
|
|
|
|
str_prefport(sa->sa_family,
|
|
|
|
m_daddr->sadb_address_prefixlen, dport,
|
|
|
|
m_saddr->sadb_address_proto));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown-af ");
|
|
|
|
break;
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
/* upper layer protocol */
|
|
|
|
if (m_saddr->sadb_address_proto !=
|
|
|
|
m_daddr->sadb_address_proto) {
|
|
|
|
printf("upper layer protocol mismatched.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
str_upperspec(m_saddr->sadb_address_proto, sport, dport);
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
else
|
2003-11-05 09:41:23 +00:00
|
|
|
printf("(no selector, probably per-socket policy) ");
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* policy */
|
|
|
|
{
|
|
|
|
char *d_xpl;
|
|
|
|
|
|
|
|
if (m_xpl == NULL) {
|
|
|
|
printf("no X_POLICY extension.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d_xpl = ipsec_dump_policy((char *)m_xpl, "\n\t");
|
|
|
|
|
|
|
|
/* dump SPD */
|
|
|
|
printf("\n\t%s\n", d_xpl);
|
|
|
|
free(d_xpl);
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* lifetime */
|
2003-11-05 09:41:23 +00:00
|
|
|
if (m_lftc) {
|
|
|
|
printf("\tcreated: %s ",
|
|
|
|
str_time(m_lftc->sadb_lifetime_addtime));
|
|
|
|
printf("lastused: %s\n",
|
|
|
|
str_time(m_lftc->sadb_lifetime_usetime));
|
|
|
|
}
|
|
|
|
if (m_lfth) {
|
|
|
|
printf("\tlifetime: %lu(s) ",
|
|
|
|
(u_long)m_lfth->sadb_lifetime_addtime);
|
|
|
|
printf("validtime: %lu(s)\n",
|
|
|
|
(u_long)m_lfth->sadb_lifetime_usetime);
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
|
2017-03-07 00:13:53 +00:00
|
|
|
printf("\tspid=%ld seq=%ld pid=%ld scope=",
|
2000-07-04 16:22:05 +00:00
|
|
|
(u_long)m_xpl->sadb_x_policy_id,
|
2000-01-06 12:40:54 +00:00
|
|
|
(u_long)m->sadb_msg_seq,
|
|
|
|
(u_long)m->sadb_msg_pid);
|
2017-03-07 00:13:53 +00:00
|
|
|
GETMSGV2S(str_sp_scope, m_xpl->sadb_x_policy_scope);
|
|
|
|
if (m_xpl->sadb_x_policy_scope == IPSEC_POLICYSCOPE_IFNET &&
|
|
|
|
if_indextoname(m_xpl->sadb_x_policy_ifindex, pbuf) != NULL)
|
|
|
|
printf("ifname=%s", pbuf);
|
|
|
|
printf("\n");
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
/* XXX TEST */
|
2000-07-04 16:22:05 +00:00
|
|
|
printf("\trefcnt=%u\n", m->sadb_msg_reserved);
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set "ipaddress" to buffer.
|
|
|
|
*/
|
|
|
|
static char *
|
2000-07-04 16:22:05 +00:00
|
|
|
str_ipaddr(sa)
|
|
|
|
struct sockaddr *sa;
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
2000-07-04 16:22:05 +00:00
|
|
|
static char buf[NI_MAXHOST];
|
|
|
|
const int niflag = NI_NUMERICHOST;
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
if (sa == NULL)
|
2000-01-06 12:40:54 +00:00
|
|
|
return "";
|
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0, niflag) == 0)
|
|
|
|
return buf;
|
|
|
|
return NULL;
|
2000-01-06 12:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set "/prefix[port number]" to buffer.
|
|
|
|
*/
|
|
|
|
static char *
|
2003-11-05 09:41:23 +00:00
|
|
|
str_prefport(family, pref, port, ulp)
|
|
|
|
u_int family, pref, port, ulp;
|
2000-01-06 12:40:54 +00:00
|
|
|
{
|
|
|
|
static char buf[128];
|
2003-04-17 07:20:00 +00:00
|
|
|
char prefbuf[128];
|
|
|
|
char portbuf[128];
|
2000-07-04 16:22:05 +00:00
|
|
|
int plen;
|
|
|
|
|
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
|
|
|
plen = sizeof(struct in_addr) << 3;
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
plen = sizeof(struct in6_addr) << 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "?";
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
if (pref == plen)
|
2000-01-06 12:40:54 +00:00
|
|
|
prefbuf[0] = '\0';
|
|
|
|
else
|
|
|
|
snprintf(prefbuf, sizeof(prefbuf), "/%u", pref);
|
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
if (ulp == IPPROTO_ICMPV6)
|
|
|
|
memset(portbuf, 0, sizeof(portbuf));
|
|
|
|
else {
|
|
|
|
if (port == IPSEC_PORT_ANY)
|
|
|
|
snprintf(portbuf, sizeof(portbuf), "[%s]", "any");
|
|
|
|
else
|
|
|
|
snprintf(portbuf, sizeof(portbuf), "[%u]", port);
|
|
|
|
}
|
2000-01-06 12:40:54 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s%s", prefbuf, portbuf);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2003-11-05 09:41:23 +00:00
|
|
|
static void
|
|
|
|
str_upperspec(ulp, p1, p2)
|
|
|
|
u_int ulp, p1, p2;
|
|
|
|
{
|
|
|
|
if (ulp == IPSEC_ULPROTO_ANY)
|
|
|
|
printf("any");
|
|
|
|
else if (ulp == IPPROTO_ICMPV6) {
|
|
|
|
printf("icmp6");
|
|
|
|
if (!(p1 == IPSEC_PORT_ANY && p2 == IPSEC_PORT_ANY))
|
|
|
|
printf(" %u,%u", p1, p2);
|
|
|
|
} else {
|
|
|
|
struct protoent *ent;
|
|
|
|
|
|
|
|
switch (ulp) {
|
|
|
|
case IPPROTO_IPV4:
|
|
|
|
printf("ip4");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ent = getprotobynumber(ulp);
|
|
|
|
if (ent)
|
|
|
|
printf("%s", ent->p_name);
|
|
|
|
else
|
|
|
|
printf("%u", ulp);
|
|
|
|
|
|
|
|
endprotoent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-06 12:40:54 +00:00
|
|
|
/*
|
|
|
|
* set "Mon Day Time Year" to buffer
|
|
|
|
*/
|
|
|
|
static char *
|
2000-07-04 16:22:05 +00:00
|
|
|
str_time(t)
|
2000-01-06 12:40:54 +00:00
|
|
|
time_t t;
|
|
|
|
{
|
|
|
|
static char buf[128];
|
|
|
|
|
|
|
|
if (t == 0) {
|
|
|
|
int i = 0;
|
|
|
|
for (;i < 20;) buf[i++] = ' ';
|
|
|
|
} else {
|
|
|
|
char *t0;
|
|
|
|
t0 = ctime(&t);
|
|
|
|
memcpy(buf, t0 + 4, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[20] = '\0';
|
|
|
|
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-04 16:22:05 +00:00
|
|
|
str_lifetime_byte(x, str)
|
2000-01-06 12:40:54 +00:00
|
|
|
struct sadb_lifetime *x;
|
|
|
|
char *str;
|
|
|
|
{
|
|
|
|
double y;
|
|
|
|
char *unit;
|
|
|
|
int w;
|
|
|
|
|
|
|
|
if (x == NULL) {
|
|
|
|
printf("\t%s: 0(bytes)", str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:22:05 +00:00
|
|
|
#if 0
|
|
|
|
if ((x->sadb_lifetime_bytes) / 1024 / 1024) {
|
|
|
|
y = (x->sadb_lifetime_bytes) * 1.0 / 1024 / 1024;
|
|
|
|
unit = "M";
|
|
|
|
w = 1;
|
|
|
|
} else if ((x->sadb_lifetime_bytes) / 1024) {
|
|
|
|
y = (x->sadb_lifetime_bytes) * 1.0 / 1024;
|
|
|
|
unit = "K";
|
|
|
|
w = 1;
|
|
|
|
} else {
|
|
|
|
y = (x->sadb_lifetime_bytes) * 1.0;
|
|
|
|
unit = "";
|
|
|
|
w = 0;
|
|
|
|
}
|
|
|
|
#else
|
2000-01-06 12:40:54 +00:00
|
|
|
y = (x->sadb_lifetime_bytes) * 1.0;
|
|
|
|
unit = "";
|
|
|
|
w = 0;
|
2000-07-04 16:22:05 +00:00
|
|
|
#endif
|
2000-01-06 12:40:54 +00:00
|
|
|
printf("\t%s: %.*f(%sbytes)", str, w, y, unit);
|
|
|
|
}
|