From owner-svn-src-all@freebsd.org Fri Jun 29 13:59:34 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69C4DEF88F9; Fri, 29 Jun 2018 13:59:34 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1B28A8C42A; Fri, 29 Jun 2018 13:59:34 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB59121BBF; Fri, 29 Jun 2018 13:59:33 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5TDxXsH092220; Fri, 29 Jun 2018 13:59:33 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5TDxXPS092219; Fri, 29 Jun 2018 13:59:33 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201806291359.w5TDxXPS092219@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Fri, 29 Jun 2018 13:59:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335795 - head/sys/netipsec X-SVN-Group: head X-SVN-Commit-Author: ae X-SVN-Commit-Paths: head/sys/netipsec X-SVN-Commit-Revision: 335795 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jun 2018 13:59:34 -0000 Author: ae Date: Fri Jun 29 13:59:33 2018 New Revision: 335795 URL: https://svnweb.freebsd.org/changeset/base/335795 Log: Make debug output produced by `setkey -x` command a more human readable. Add text names of SADB message types and extension headers to the output. Obtained from: Yandex LLC MFC after: 2 weeks Sponsored by: Yandex LLC Differential Revision: https://reviews.freebsd.org/D16036 Modified: head/sys/netipsec/key_debug.c Modified: head/sys/netipsec/key_debug.c ============================================================================== --- head/sys/netipsec/key_debug.c Fri Jun 29 12:41:36 2018 (r335794) +++ head/sys/netipsec/key_debug.c Fri Jun 29 13:59:33 2018 (r335795) @@ -85,6 +85,85 @@ static void kdebug_sadb_x_natt(struct sadb_ext *); /* NOTE: host byte order */ +const char* +kdebug_sadb_type(uint8_t type) +{ +#define SADB_NAME(n) case SADB_ ## n: return (#n) + + switch (type) { + SADB_NAME(RESERVED); + SADB_NAME(GETSPI); + SADB_NAME(UPDATE); + SADB_NAME(ADD); + SADB_NAME(DELETE); + SADB_NAME(GET); + SADB_NAME(ACQUIRE); + SADB_NAME(REGISTER); + SADB_NAME(EXPIRE); + SADB_NAME(FLUSH); + SADB_NAME(DUMP); + SADB_NAME(X_PROMISC); + SADB_NAME(X_PCHANGE); + SADB_NAME(X_SPDUPDATE); + SADB_NAME(X_SPDADD); + SADB_NAME(X_SPDDELETE); + SADB_NAME(X_SPDGET); + SADB_NAME(X_SPDACQUIRE); + SADB_NAME(X_SPDDUMP); + SADB_NAME(X_SPDFLUSH); + SADB_NAME(X_SPDSETIDX); + SADB_NAME(X_SPDEXPIRE); + SADB_NAME(X_SPDDELETE2); + default: + return ("UNKNOWN"); + } +#undef SADB_NAME +} + +const char* +kdebug_sadb_exttype(uint16_t type) +{ +#define EXT_NAME(n) case SADB_EXT_ ## n: return (#n) +#define X_NAME(n) case SADB_X_EXT_ ## n: return (#n) + + switch (type) { + EXT_NAME(RESERVED); + EXT_NAME(SA); + EXT_NAME(LIFETIME_CURRENT); + EXT_NAME(LIFETIME_HARD); + EXT_NAME(LIFETIME_SOFT); + EXT_NAME(ADDRESS_SRC); + EXT_NAME(ADDRESS_DST); + EXT_NAME(ADDRESS_PROXY); + EXT_NAME(KEY_AUTH); + EXT_NAME(KEY_ENCRYPT); + EXT_NAME(IDENTITY_SRC); + EXT_NAME(IDENTITY_DST); + EXT_NAME(SENSITIVITY); + EXT_NAME(PROPOSAL); + EXT_NAME(SUPPORTED_AUTH); + EXT_NAME(SUPPORTED_ENCRYPT); + EXT_NAME(SPIRANGE); + X_NAME(KMPRIVATE); + X_NAME(POLICY); + X_NAME(SA2); + X_NAME(NAT_T_TYPE); + X_NAME(NAT_T_SPORT); + X_NAME(NAT_T_DPORT); + X_NAME(NAT_T_OAI); + X_NAME(NAT_T_OAR); + X_NAME(NAT_T_FRAG); + X_NAME(SA_REPLAY); + X_NAME(NEW_ADDRESS_SRC); + X_NAME(NEW_ADDRESS_DST); + default: + return ("UNKNOWN"); + }; +#undef EXT_NAME +#undef X_NAME +} + + /* %%%: about struct sadb_msg */ void kdebug_sadb(struct sadb_msg *base) @@ -96,8 +175,9 @@ kdebug_sadb(struct sadb_msg *base) if (base == NULL) panic("%s: NULL pointer was passed.\n", __func__); - printf("sadb_msg{ version=%u type=%u errno=%u satype=%u\n", + printf("sadb_msg{ version=%u type=%u(%s) errno=%u satype=%u\n", base->sadb_msg_version, base->sadb_msg_type, + kdebug_sadb_type(base->sadb_msg_type), base->sadb_msg_errno, base->sadb_msg_satype); printf(" len=%u reserved=%u seq=%u pid=%u\n", base->sadb_msg_len, base->sadb_msg_reserved, @@ -107,8 +187,9 @@ kdebug_sadb(struct sadb_msg *base) ext = (struct sadb_ext *)((caddr_t)base + sizeof(struct sadb_msg)); while (tlen > 0) { - printf("sadb_ext{ len=%u type=%u }\n", - ext->sadb_ext_len, ext->sadb_ext_type); + printf("sadb_ext{ len=%u type=%u(%s) }\n", + ext->sadb_ext_len, ext->sadb_ext_type, + kdebug_sadb_exttype(ext->sadb_ext_type)); if (ext->sadb_ext_len == 0) { printf("%s: invalid ext_len=0 was passed.\n", __func__);