summaryrefslogtreecommitdiff
path: root/usr/src/cmd/flowadm
diff options
context:
space:
mode:
authorMichael Lim <Michael.Lim@Sun.COM>2009-01-26 15:20:41 -0800
committerMichael Lim <Michael.Lim@Sun.COM>2009-01-26 15:20:41 -0800
commitad091ee10b4de077c116313fba8195f16565e722 (patch)
tree38f096aca1caa55b3220b5876fb7e9bce72bac0d /usr/src/cmd/flowadm
parentb4059b01d62d4bc3032cf192d365aff4f632526b (diff)
downloadillumos-joyent-ad091ee10b4de077c116313fba8195f16565e722.tar.gz
6770845 dladm show-vnic, flowadm show-flow and flowadm show-flowprop need to have parseable output updated
6778821 flowadm show-flow -S only shows stats for flows on the 1st link 6599076 flowadm should use die, die_opterr, warn and warn_flowerr instead of exit()
Diffstat (limited to 'usr/src/cmd/flowadm')
-rw-r--r--usr/src/cmd/flowadm/flowadm.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/usr/src/cmd/flowadm/flowadm.c b/usr/src/cmd/flowadm/flowadm.c
index eee3685dc1..091b175869 100644
--- a/usr/src/cmd/flowadm/flowadm.c
+++ b/usr/src/cmd/flowadm/flowadm.c
@@ -226,13 +226,13 @@ static print_field_t flow_fields[] = {
offsetof(flow_fields_buf_t, flow_name), CMD_TYPE_ANY},
{ "link", "LINK", 11,
offsetof(flow_fields_buf_t, flow_link), CMD_TYPE_ANY},
-{ "ipaddr", "IP ADDR", 30,
+{ "ipaddr", "IPADDR", 30,
offsetof(flow_fields_buf_t, flow_ipaddr), CMD_TYPE_ANY},
-{ "transport", "PROTO", 6,
+{ "proto", "PROTO", 6,
offsetof(flow_fields_buf_t, flow_proto), CMD_TYPE_ANY},
{ "port", "PORT", 7,
offsetof(flow_fields_buf_t, flow_port), CMD_TYPE_ANY},
-{ "dsfield", "DSFLD", 9,
+{ "dsfld", "DSFLD", 9,
offsetof(flow_fields_buf_t, flow_dsfield), CMD_TYPE_ANY}}
;
@@ -436,7 +436,7 @@ main(int argc, char *argv[])
cmdp->c_fn(argc - 1, &argv[1]);
dladm_close(handle);
- exit(0);
+ exit(EXIT_SUCCESS);
}
}
@@ -1114,7 +1114,7 @@ do_show_flow(int argc, char *argv[])
print_field_t **fields;
uint_t nfields;
char *all_fields =
- "flow,link,ipaddr,transport,port,dsfield";
+ "flow,link,ipaddr,proto,port,dsfld";
bzero(&state, sizeof (state));
@@ -1173,6 +1173,12 @@ do_show_flow(int argc, char *argv[])
break;
}
}
+ if (state.fs_parseable && !o_arg)
+ die("-p requires -o");
+
+ if (state.fs_parseable && strcasecmp(fields_str, "all") == 0)
+ die("\"-o all\" is invalid with -p");
+
if (i_arg && !(s_arg || S_arg))
die("the -i option can be used only with -s or -S");
@@ -1405,7 +1411,7 @@ done:
dladm_free_props(proplist);
if (status != DLADM_STATUS_OK) {
dladm_close(handle);
- exit(1);
+ exit(EXIT_FAILURE);
}
}
@@ -1692,6 +1698,7 @@ static void
do_show_flowprop(int argc, char **argv)
{
int option;
+ boolean_t o_arg = B_FALSE;
dladm_arg_list_t *proplist = NULL;
show_flowprop_state_t state;
char *fields_str = NULL;
@@ -1731,6 +1738,7 @@ do_show_flowprop(int argc, char **argv)
die("invalid link '%s'", optarg);
break;
case 'o':
+ o_arg = B_TRUE;
if (strcasecmp(optarg, "all") == 0)
fields_str = all_fields;
else
@@ -1742,6 +1750,12 @@ do_show_flowprop(int argc, char **argv)
}
}
+ if (state.fs_parseable && !o_arg)
+ die("-p requires -o");
+
+ if (state.fs_parseable && strcasecmp(fields_str, "all") == 0)
+ die("\"-o all\" is invalid with -p");
+
if (optind == (argc - 1)) {
if (strlen(argv[optind]) >= MAXFLOWNAMELEN)
die("flow name too long");
@@ -1969,19 +1983,38 @@ print_field(print_state_t *statep, print_field_t *pfp, const char *value,
boolean_t parseable)
{
uint_t width = pfp->pf_width;
- uint_t valwidth = strlen(value);
+ uint_t valwidth;
uint_t compress;
+ /*
+ * Parsable fields are separated by ':'. If such a field contains
+ * a ':' or '\', this character is prefixed by a '\'.
+ */
if (parseable) {
- (void) printf("%s=\"%s\"", pfp->pf_header, value);
+ char c;
+
+ if (statep->ps_nfields == 1) {
+ (void) printf("%s", value);
+ return;
+ }
+ while ((c = *value++) != '\0') {
+ if (c == ':' || c == '\\')
+ (void) putchar('\\');
+ (void) putchar(c);
+ }
+ if (!statep->ps_lastfield)
+ (void) putchar(':');
+ return;
} else {
if (value[0] == '\0')
value = STR_UNDEF_VAL;
if (statep->ps_lastfield) {
(void) printf("%s", value);
+ statep->ps_overflow = 0;
return;
}
+ valwidth = strlen(value);
if (valwidth > width) {
statep->ps_overflow += valwidth - width;
} else if (valwidth < width && statep->ps_overflow > 0) {