svn commit: r223788 - head/usr.sbin/flowctl

2011-07-05 Thread Gleb Smirnoff
Author: glebius
Date: Tue Jul  5 14:50:06 2011
New Revision: 223788
URL: http://svn.freebsd.org/changeset/base/223788

Log:
  Rewrite the flowctl utility to add it support for displaying
  both IPv4 and IPv4 flows.

Modified:
  head/usr.sbin/flowctl/Makefile
  head/usr.sbin/flowctl/flowctl.c

Modified: head/usr.sbin/flowctl/Makefile
==
--- head/usr.sbin/flowctl/Makefile  Tue Jul  5 14:48:39 2011
(r223787)
+++ head/usr.sbin/flowctl/Makefile  Tue Jul  5 14:50:06 2011
(r223788)
@@ -2,6 +2,8 @@
 # $FreeBSD$
 #
 
+.include bsd.own.mk
+   
 PROG=  flowctl
 MAN=   flowctl.8
 
@@ -9,4 +11,10 @@ WARNS?= 2
 DPADD=  ${LIBNETGRAPH}
 LDADD=  -lnetgraph
 
+.if ${MK_INET6_SUPPORT} != no
+CFLAGS+= -DINET6
+.endif
+
+CFLAGS+= -I.
+
 .include bsd.prog.mk

Modified: head/usr.sbin/flowctl/flowctl.c
==
--- head/usr.sbin/flowctl/flowctl.c Tue Jul  5 14:48:39 2011
(r223787)
+++ head/usr.sbin/flowctl/flowctl.c Tue Jul  5 14:50:06 2011
(r223788)
@@ -46,6 +46,7 @@ static const char rcs_id[] =
 #include stdio.h
 #include stdlib.h
 #include string.h
+#include sysexits.h
 #include unistd.h
 
 #include netgraph.h
@@ -54,21 +55,32 @@ static const char rcs_id[] =
 #defineCISCO_SH_FLOW_HEADERSrcIf SrcIPaddressDstIf
 DstIPaddressPr SrcP DstP  Pkts\n
 #defineCISCO_SH_FLOW   %-13s %-15s %-13s %-15s %2u %4.4x %4.4x %6lu\n
 
+#defineCISCO_SH_FLOW6_HEADER   SrcIf SrcIPaddress 
  DstIf DstIPaddress   Pr SrcP DstP  Pkts\n
+#defineCISCO_SH_FLOW6  %-13s %-30s %-13s %-30s %2u %4.4x %4.4x %6lu\n
+
 #defineCISCO_SH_VERB_FLOW_HEADER SrcIf  SrcIPaddressDstIf 
 DstIPaddressPr TOS Flgs  Pkts\n \
 Port Msk ASPort Msk ASNextHop  B/Pk  
Active\n
 
 #defineCISCO_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
 
-static int flow_cache_print(struct ngnf_flows *recs);
-static int flow_cache_print_verbose(struct ngnf_flows *recs);
-static int ctl_show(int, char **);
+#defineCISCO_SH_VERB_FLOW6_HEADER SrcIf  SrcIPaddress 
  DstIf  DstIPaddress   Pr TOS Flgs  Pkts\n \
+Port Msk ASPort Msk ASNextHop 
B/Pk  Active\n
+
+#defineCISCO_SH_VERB_FLOW6 %-14s %-30s %-14s %-30s %2u %3x %4x 
%6lu\n \
+   %4.4x /%-2u %-5u %4.4x /%-2u %-5u %-30s %9u %8u\n\n
+static void flow_cache_print(struct ngnf_show_header *resp);
+static void flow_cache_print6(struct ngnf_show_header *resp);
+static void flow_cache_print_verbose(struct ngnf_show_header *resp);
+static void flow_cache_print6_verbose(struct ngnf_show_header *resp);
+static void ctl_show(int, char **);
+static void do_show(int, void (*func)(struct ngnf_show_header *));
 static void help(void);
 static void execute_command(int, char **);
 
 struct ip_ctl_cmd {
char*cmd_name;
-   int (*cmd_func)(int argc, char **argv);
+   void(*cmd_func)(int argc, char **argv);
 };
 
 struct ip_ctl_cmd cmds[] = {
@@ -77,7 +89,7 @@ struct ip_ctl_cmd cmds[] = {
 };
 
 intcs;
-char   ng_nodename[NG_PATHSIZ];
+char   *ng_path;
 
 int
 main(int argc, char **argv)
@@ -85,7 +97,6 @@ main(int argc, char **argv)
int c;
char sname[NG_NODESIZ];
int rcvbuf = SORCVBUF_SIZE;
-   char*ng_name;
 
/* parse options */
while ((c = getopt(argc, argv, d:)) != -1) {
@@ -98,14 +109,12 @@ main(int argc, char **argv)
 
argc -= optind;
argv += optind;
-   ng_name = argv[0];
-   if (ng_name == NULL)
+   ng_path = argv[0];
+   if (ng_path == NULL || (strlen(ng_path)  NG_PATHSIZ))
help();
argc--;
argv++;
 
-   snprintf(ng_nodename, sizeof(ng_nodename), %s:, ng_name);
-
/* create control socket. */
snprintf(sname, sizeof(sname), flowctl%i, getpid());
 
@@ -145,74 +154,99 @@ execute_command(int argc, char **argv)
(*cmds[cindex].cmd_func)(argc, argv);
 }
 
-static int
+static void
 ctl_show(int argc, char **argv)
 {
-   struct ng_mesg *ng_mesg;
-   struct ngnf_flows *data;
-   char path[NG_PATHSIZ];
-   int token, nread, last = 0;
-   int verbose = 0;
+   int ipv4 = 1, ipv6 = 1, verbose = 0;
+
+   if (argc  0  !strncmp(argv[0], ipv4, 4)) {
+   ipv6 = 0;
+   argc--;
+   argv++;
+   }
+   if (argc  0  !strncmp(argv[0], ipv6, 4)) {
+   ipv4 = 0;
+   argc--;
+   argv++;
+   }
 
if (argc  0  !strncmp(argv[0], verbose, strlen(argv[0])))
verbose = 1;
 
+   if (ipv4) {
+

Re: svn commit: r223788 - head/usr.sbin/flowctl

2011-07-05 Thread Sergey Kandaurov
On 5 July 2011 18:50, Gleb Smirnoff gleb...@freebsd.org wrote:
 Author: glebius
 Date: Tue Jul  5 14:50:06 2011
 New Revision: 223788
 URL: http://svn.freebsd.org/changeset/base/223788

 Log:
  Rewrite the flowctl utility to add it support for displaying
  both IPv4 and IPv4 flows.

 Modified:
  head/usr.sbin/flowctl/Makefile
  head/usr.sbin/flowctl/flowctl.c

 Modified: head/usr.sbin/flowctl/Makefile
 ==
 --- head/usr.sbin/flowctl/Makefile      Tue Jul  5 14:48:39 2011        
 (r223787)
 +++ head/usr.sbin/flowctl/Makefile      Tue Jul  5 14:50:06 2011        
 (r223788)
 @@ -2,6 +2,8 @@
  # $FreeBSD$
  #

 +.include bsd.own.mk
 +
  PROG=  flowctl
  MAN=   flowctl.8

 @@ -9,4 +11,10 @@ WARNS?= 2
  DPADD=  ${LIBNETGRAPH}
  LDADD=  -lnetgraph

 +.if ${MK_INET6_SUPPORT} != no
 +CFLAGS+= -DINET6
 +.endif
[...]

It's broken for WITHOUT_INET6=yes.
Please consider taking a look at the change below on top of r223788.
The patch adds handling for WITHOUT_INET, too.

Index: usr.sbin/flowctl/flowctl.c
===
--- usr.sbin/flowctl/flowctl.c  (revision 223792)
+++ usr.sbin/flowctl/flowctl.c  (working copy)
@@ -69,12 +69,18 @@

 #defineCISCO_SH_VERB_FLOW6 %-14s %-30s %-14s %-30s %2u %3x
%4x %6lu\n \
%4.4x /%-2u %-5u %4.4x /%-2u %-5u %-30s %9u %8u\n\n
+#ifdef INET
 static void flow_cache_print(struct ngnf_show_header *resp);
+static void flow_cache_print_verbose(struct ngnf_show_header *resp);
+#endif
+#ifdef INET6
 static void flow_cache_print6(struct ngnf_show_header *resp);
-static void flow_cache_print_verbose(struct ngnf_show_header *resp);
 static void flow_cache_print6_verbose(struct ngnf_show_header *resp);
+#endif
 static void ctl_show(int, char **);
+#if defined(INET) || defined(INET6)
 static void do_show(int, void (*func)(struct ngnf_show_header *));
+#endif
 static void help(void);
 static void execute_command(int, char **);

@@ -157,8 +163,11 @@
 static void
 ctl_show(int argc, char **argv)
 {
-   int ipv4 = 1, ipv6 = 1, verbose = 0;
+   int ipv4, ipv6, verbose = 0;

+   ipv4 = feature_present(inet);
+   ipv6 = feature_present(inet6);
+
if (argc  0  !strncmp(argv[0], ipv4, 4)) {
ipv6 = 0;
argc--;
@@ -173,21 +182,26 @@
if (argc  0  !strncmp(argv[0], verbose, strlen(argv[0])))
verbose = 1;

+#ifdef INET
if (ipv4) {
if (verbose)
do_show(4, flow_cache_print_verbose);
else
do_show(4, flow_cache_print);
}
+#endif

+#ifdef INET6
if (ipv6) {
if (verbose)
do_show(6, flow_cache_print6_verbose);
else
do_show(6, flow_cache_print6);
}
+#endif
 }

+#if defined(INET) || defined(INET6)
 static void
 do_show(int version, void (*func)(struct ngnf_show_header *))
 {
@@ -230,7 +244,9 @@
req.list_id = resp-list_id;
}
 }
+#endif

+#ifdef INET
 static void
 flow_cache_print(struct ngnf_show_header *resp)
 {
@@ -261,6 +277,7 @@

}
 }
+#endif

 #ifdef INET6
 static void
@@ -295,6 +312,7 @@
 }
 #endif

+#ifdef INET
 static void
 flow_cache_print_verbose(struct ngnf_show_header *resp)
 {
@@ -335,6 +353,7 @@

}
 }
+#endif

 #ifdef INET6
 static void
Index: usr.sbin/flowctl/Makefile
===
--- usr.sbin/flowctl/Makefile   (revision 223792)
+++ usr.sbin/flowctl/Makefile   (working copy)
@@ -14,7 +14,8 @@
 .if ${MK_INET6_SUPPORT} != no
 CFLAGS+= -DINET6
 .endif
+.if ${MK_INET_SUPPORT} != no
+CFLAGS+= -DINET
+.endif

-CFLAGS+= -I.
-
 .include bsd.prog.mk

-- 
wbr,
pluknet
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to svn-src-head-unsubscr...@freebsd.org