svn commit: r236808 - head/usr.sbin/flowctl
Alexander V. Chernikov
melifaro at FreeBSD.org
Sat Jun 9 10:10:12 UTC 2012
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 <netgraph.h>
#include <netgraph/netflow/ng_netflow.h>
-#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),
More information about the svn-src-all
mailing list