summaryrefslogtreecommitdiff
path: root/usr/src/cmd/flowstat/flowstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/flowstat/flowstat.c')
-rw-r--r--usr/src/cmd/flowstat/flowstat.c52
1 files changed, 20 insertions, 32 deletions
diff --git a/usr/src/cmd/flowstat/flowstat.c b/usr/src/cmd/flowstat/flowstat.c
index 1f8c65c957..ab1797922c 100644
--- a/usr/src/cmd/flowstat/flowstat.c
+++ b/usr/src/cmd/flowstat/flowstat.c
@@ -23,6 +23,10 @@
* Use is subject to license terms.
*/
+/*
+ * Copyright 2017 Joyent, Inc.
+ */
+
#include <stdio.h>
#include <locale.h>
#include <stdarg.h>
@@ -86,7 +90,6 @@ static void warn(const char *, ...);
/* callback functions for printing output */
static ofmt_cb_t print_default_cb, print_flow_stats_cb;
-static void flowstat_ofmt_check(ofmt_status_t, boolean_t, ofmt_handle_t);
#define NULL_OFMT {NULL, 0, 0, NULL}
@@ -190,9 +193,9 @@ static char *progname;
static dladm_handle_t handle = NULL;
const char *usage_ermsg = "flowstat [-r | -t] [-i interval] "
- "[-l link] [flow]\n"
+ "[-l link] [-z zonename] [flow]\n"
" flowstat [-A] [-i interval] [-p] [ -o field[,...]]\n"
- " [-u R|K|M|G|T|P] [-l link] [flow]\n"
+ " [-u R|K|M|G|T|P] [-l link] [-z zonename] [flow]\n"
" flowstat -h [-a] [-d] [-F format]"
" [-s <DD/MM/YYYY,HH:MM:SS>]\n"
" [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> "
@@ -555,6 +558,7 @@ main(int argc, char *argv[])
show_flow_state_t state;
char *fields_str = NULL;
char *o_fields_str = NULL;
+ char *zonename = NULL;
char *total_stat_fields =
"flow,ipkts,rbytes,ierrs,opkts,obytes,oerrs";
@@ -581,10 +585,11 @@ main(int argc, char *argv[])
if ((status = dladm_open(&handle)) != DLADM_STATUS_OK)
die_dlerr(status, "could not open /dev/dld");
+ linkname[0] = '\0';
bzero(&state, sizeof (state));
opterr = 0;
- while ((option = getopt_long(argc, argv, ":rtApi:o:u:l:h",
+ while ((option = getopt_long(argc, argv, ":rtApi:o:u:l:hz:",
NULL, NULL)) != -1) {
switch (option) {
case 'r':
@@ -636,9 +641,6 @@ main(int argc, char *argv[])
if (strlcpy(linkname, optarg, MAXLINKNAMELEN)
>= MAXLINKNAMELEN)
die("link name too long\n");
- if (dladm_name2info(handle, linkname, &linkid, NULL,
- NULL, NULL) != DLADM_STATUS_OK)
- die("invalid link '%s'", linkname);
break;
case 'h':
if (r_arg || t_arg || p_arg || o_arg || u_arg ||
@@ -649,6 +651,9 @@ main(int argc, char *argv[])
do_show_history(argc, argv);
return (0);
break;
+ case 'z':
+ zonename = optarg;
+ break;
default:
die_opterr(optopt, option, usage_ermsg);
break;
@@ -672,6 +677,12 @@ main(int argc, char *argv[])
die("the option -A is not compatible with "
"-r, -t, -p, -o, -u, -i");
+ if (linkname[0] != '\0') {
+ if (dladm_zname2info(handle, zonename, linkname, &linkid, NULL,
+ NULL, NULL) != DLADM_STATUS_OK)
+ die("invalid link '%s'", linkname);
+ }
+
/* get flow name (optional last argument) */
if (optind == (argc-1)) {
if (strlcpy(flowname, argv[optind], MAXFLOWNAMELEN)
@@ -710,7 +721,7 @@ main(int argc, char *argv[])
}
oferr = ofmt_open(fields_str, flow_s_fields, ofmtflags, 0, &ofmt);
- flowstat_ofmt_check(oferr, state.fs_parsable, ofmt);
+ ofmt_check(oferr, state.fs_parsable, ofmt, die, warn);
state.fs_ofmt = ofmt;
for (;;) {
@@ -978,7 +989,7 @@ do_show_history(int argc, char *argv[])
0, &ofmt);
}
- flowstat_ofmt_check(oferr, state.us_parsable, ofmt);
+ ofmt_check(oferr, state.us_parsable, ofmt, die, warn);
state.us_ofmt = ofmt;
if (F_arg && d_arg)
@@ -1107,26 +1118,3 @@ print_default_cb(ofmt_arg_t *of_arg, char *buf, uint_t bufsize)
(void) strlcpy(buf, value, bufsize);
return (B_TRUE);
}
-
-static void
-flowstat_ofmt_check(ofmt_status_t oferr, boolean_t parsable,
- ofmt_handle_t ofmt)
-{
- char buf[OFMT_BUFSIZE];
-
- if (oferr == OFMT_SUCCESS)
- return;
- (void) ofmt_strerror(ofmt, oferr, buf, sizeof (buf));
- /*
- * All errors are considered fatal in parsable mode.
- * NOMEM errors are always fatal, regardless of mode.
- * For other errors, we print diagnostics in human-readable
- * mode and processs what we can.
- */
- if (parsable || oferr == OFMT_ENOFIELDS) {
- ofmt_close(ofmt);
- die(buf);
- } else {
- warn(buf);
- }
-}