From owner-svn-src-all@freebsd.org Tue May 17 11:22:10 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2556FB3E009; Tue, 17 May 2016 11:22:10 +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 mx1.freebsd.org (Postfix) with ESMTPS id EA716134E; Tue, 17 May 2016 11:22:09 +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 u4HBM9Dh007705; Tue, 17 May 2016 11:22:09 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4HBM9sG007704; Tue, 17 May 2016 11:22:09 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201605171122.u4HBM9sG007704@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 17 May 2016 11:22:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300045 - head/sbin/ipfw X-SVN-Group: head 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.22 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: Tue, 17 May 2016 11:22:10 -0000 Author: ae Date: Tue May 17 11:22:08 2016 New Revision: 300045 URL: https://svnweb.freebsd.org/changeset/base/300045 Log: Make `ipfw internal olist` output more user friendly. Print object type as string for known types. Obtained from: Yandex LLC Sponsored by: Yandex LLC Modified: head/sbin/ipfw/ipfw2.c Modified: head/sbin/ipfw/ipfw2.c ============================================================================== --- head/sbin/ipfw/ipfw2.c Tue May 17 11:10:44 2016 (r300044) +++ head/sbin/ipfw/ipfw2.c Tue May 17 11:22:08 2016 (r300045) @@ -5131,11 +5131,35 @@ static struct _s_x intcmds[] = { { NULL, 0 } }; +static struct _s_x otypes[] = { + { "EACTION", IPFW_TLV_EACTION }, + { NULL, 0 } +}; + +static const char* +lookup_eaction_name(ipfw_obj_ntlv *ntlv, int cnt, uint16_t type) +{ + const char *name; + int i; + + name = NULL; + for (i = 0; i < cnt; i++) { + if (ntlv[i].head.type != IPFW_TLV_EACTION) + continue; + if (IPFW_TLV_EACTION_NAME(ntlv[i].idx) != type) + continue; + name = ntlv[i].name; + break; + } + return (name); +} + static void ipfw_list_objects(int ac, char *av[]) { ipfw_obj_lheader req, *olh; ipfw_obj_ntlv *ntlv; + const char *name; size_t sz; int i; @@ -5161,8 +5185,17 @@ ipfw_list_objects(int ac, char *av[]) printf("There are no objects\n"); ntlv = (ipfw_obj_ntlv *)(olh + 1); for (i = 0; i < olh->count; i++) { - printf(" kidx: %4d\ttype: %6d\tname: %s\n", ntlv->idx, - ntlv->head.type, ntlv->name); + name = match_value(otypes, ntlv->head.type); + if (name == NULL) + name = lookup_eaction_name( + (ipfw_obj_ntlv *)(olh + 1), olh->count, + ntlv->head.type); + if (name == NULL) + printf(" kidx: %4d\ttype: %10d\tname: %s\n", + ntlv->idx, ntlv->head.type, ntlv->name); + else + printf(" kidx: %4d\ttype: %10s\tname: %s\n", + ntlv->idx, name, ntlv->name); ntlv++; } free(olh);