From owner-svn-src-all@FreeBSD.ORG Sat Jun 9 10:10:12 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D47DD106564A; Sat, 9 Jun 2012 10:10:12 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B5E308FC15; Sat, 9 Jun 2012 10:10:12 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q59AACbY022494; Sat, 9 Jun 2012 10:10:12 GMT (envelope-from melifaro@svn.freebsd.org) Received: (from melifaro@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q59AACkC022491; Sat, 9 Jun 2012 10:10:12 GMT (envelope-from melifaro@svn.freebsd.org) Message-Id: <201206091010.q59AACkC022491@svn.freebsd.org> From: "Alexander V. Chernikov" Date: Sat, 9 Jun 2012 10:10:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236808 - head/usr.sbin/flowctl X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Sat, 09 Jun 2012 10:10:12 -0000 Author: melifaro Date: Sat Jun 9 10:10:12 2012 New Revision: 236808 URL: http://svn.freebsd.org/changeset/base/236808 Log: Add "human" option to print IPv4/IPv6 flows in human-readable format. Show IPv4/IPv6 header IFF there are some flows following. Wrap some long lines. Sponsored by Yandex LLC Reviewed by: glebius (previous version) Approved by: ae(mentor) MFC after: 1 week Modified: head/usr.sbin/flowctl/flowctl.8 head/usr.sbin/flowctl/flowctl.c Modified: head/usr.sbin/flowctl/flowctl.8 ============================================================================== --- head/usr.sbin/flowctl/flowctl.8 Sat Jun 9 10:06:49 2012 (r236807) +++ head/usr.sbin/flowctl/flowctl.8 Sat Jun 9 10:10:12 2012 (r236808) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 5, 2011 +.Dd June 8, 2012 .Dt FLOWCTL 8 .Os .Sh NAME @@ -55,7 +55,7 @@ Currently, .Nm supports only one command. .Bl -tag -width ".Cm show" -.It Cm show Op Cm ipv4|ipv6 +.It Cm show Oo Cm ipv4|ipv6 Oc Op Cm human|verbose This command is the analog of the .Dq "show ip cache flow" command of a Cisco router. @@ -69,7 +69,9 @@ It has optional parameter .Cm verbose , which is analog of the .Dq "show ip cache verbose flow" -command. +command. Additionally, +.Cm human +parameter can be specify to show selected flows in human-readable format. .El .Sh EXIT STATUS .Ex -std Modified: head/usr.sbin/flowctl/flowctl.c ============================================================================== --- head/usr.sbin/flowctl/flowctl.c Sat Jun 9 10:06:49 2012 (r236807) +++ head/usr.sbin/flowctl/flowctl.c Sat Jun 9 10:10:12 2012 (r236808) @@ -52,19 +52,33 @@ static const char rcs_id[] = #include #include -#define CISCO_SH_FLOW_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr SrcP DstP Pkts\n" +#define CISCO_SH_FLOW_HEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Pr SrcP DstP Pkts\n" #define CISCO_SH_FLOW "%-13s %-15s %-13s %-15s %2u %4.4x %4.4x %6lu\n" -#define CISCO_SH_FLOW6_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr SrcP DstP Pkts\n" -#define CISCO_SH_FLOW6 "%-13s %-30s %-13s %-30s %2u %4.4x %4.4x %6lu\n" +/* human-readable IPv4 header */ +#define CISCO_SH_FLOW_HHEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Proto SrcPort DstPort Pkts\n" +#define CISCO_SH_FLOW_H "%-13s %-15s %-13s %-15s %5u %8d %8d %8lu\n" + +#define CISCO_SH_FLOW6_HEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Pr SrcP DstP Pkts\n" +#define CISCO_SH_FLOW6 "%-13s %-30s %-13s %-30s %2u %4.4x %4.4x %6lu\n" + +/* Human-readable IPv6 headers */ +#define CISCO_SH_FLOW6_HHEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Proto SrcPort DstPort Pkts\n" +#define CISCO_SH_FLOW6_H "%-13s %-36s %-13s %-36s %5u %8d %8d %8lu\n" -#define CISCO_SH_VERB_FLOW_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr TOS Flgs Pkts\n" \ +#define CISCO_SH_VERB_FLOW_HEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Pr TOS Flgs Pkts\n" \ "Port Msk AS Port Msk AS NextHop B/Pk Active\n" #define CISCO_SH_VERB_FLOW "%-14s %-15s %-14s %-15s %2u %3x %4x %6lu\n" \ "%4.4x /%-2u %-5u %4.4x /%-2u %-5u %-15s %9u %8u\n\n" -#define CISCO_SH_VERB_FLOW6_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr TOS Flgs Pkts\n" \ +#define CISCO_SH_VERB_FLOW6_HEADER "SrcIf SrcIPaddress " \ +"DstIf DstIPaddress Pr TOS Flgs Pkts\n" \ "Port Msk AS Port Msk AS NextHop B/Pk Active\n" #define CISCO_SH_VERB_FLOW6 "%-14s %-30s %-14s %-30s %2u %3x %4x %6lu\n" \ @@ -94,7 +108,7 @@ struct ip_ctl_cmd cmds[] = { {NULL, NULL}, }; -int cs; +int cs, human = 0; char *ng_path; int @@ -182,6 +196,9 @@ ctl_show(int argc, char **argv) if (argc > 0 && !strncmp(argv[0], "verbose", strlen(argv[0]))) verbose = 1; + if (argc > 0 && !strncmp(argv[0], "human", strlen(argv[0]))) + human = 1; + #ifdef INET if (ipv4) { if (verbose) @@ -259,13 +276,14 @@ flow_cache_print(struct ngnf_show_header errx(EX_SOFTWARE, "%s: version mismatch: %u", __func__, resp->version); - printf(CISCO_SH_FLOW_HEADER); + if (resp->nentries > 0) + printf(human ? CISCO_SH_FLOW_HHEADER : CISCO_SH_FLOW_HEADER); fle = (struct flow_entry_data *)(resp + 1); for (i = 0; i < resp->nentries; i++, fle++) { inet_ntop(AF_INET, &fle->r.r_src, src, sizeof(src)); inet_ntop(AF_INET, &fle->r.r_dst, dst, sizeof(dst)); - printf(CISCO_SH_FLOW, + printf(human ? CISCO_SH_FLOW_H : CISCO_SH_FLOW, if_indextoname(fle->fle_i_ifx, src_if), src, if_indextoname(fle->fle_o_ifx, dst_if), @@ -292,13 +310,14 @@ flow_cache_print6(struct ngnf_show_heade errx(EX_SOFTWARE, "%s: version mismatch: %u", __func__, resp->version); - printf(CISCO_SH_FLOW6_HEADER); + if (resp->nentries > 0) + printf(human ? CISCO_SH_FLOW6_HHEADER : CISCO_SH_FLOW6_HEADER); fle6 = (struct flow6_entry_data *)(resp + 1); for (i = 0; i < resp->nentries; i++, fle6++) { inet_ntop(AF_INET6, &fle6->r.src.r_src6, src6, sizeof(src6)); inet_ntop(AF_INET6, &fle6->r.dst.r_dst6, dst6, sizeof(dst6)); - printf(CISCO_SH_FLOW6, + printf(human ? CISCO_SH_FLOW6_H : CISCO_SH_FLOW6, if_indextoname(fle6->fle_i_ifx, src_if), src6, if_indextoname(fle6->fle_o_ifx, dst_if),