10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright 2017 Joyent, Inc.
28 */
29
30 #include <stdio.h>
31 #include <locale.h>
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <fcntl.h>
35 #include <string.h>
36 #include <stropts.h>
37 #include <errno.h>
38 #include <strings.h>
39 #include <getopt.h>
40 #include <unistd.h>
41 #include <priv.h>
42 #include <netdb.h>
43 #include <libintl.h>
44 #include <libdlflow.h>
45 #include <libdllink.h>
46 #include <libdlstat.h>
47 #include <sys/types.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
409 static int
410 query_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg)
411 {
412 show_flow_state_t *state = arg;
413 flow_chain_t *flow_node;
414 flow_stat_t *curr_stat;
415 flow_stat_t *prev_stat;
416 flow_stat_t *diff_stat;
417 char *flowname = attr->fa_flowname;
418 flow_args_t fargs;
419
420 /* Get previous stats for the flow */
421 flow_node = get_flow_prev_stat(flowname, arg);
422 if (flow_node == NULL)
423 goto done;
424
425 flow_node->fc_visited = B_TRUE;
426 prev_stat = flow_node->fc_stat;
427
428 /* Query library for current stats */
429 curr_stat = dladm_flow_stat_query(flowname);
430 if (curr_stat == NULL)
431 goto done;
432
433 /* current stats - prev iteration stats */
434 diff_stat = dladm_flow_stat_diff(curr_stat, prev_stat);
435
436 /* Free prev stats */
437 dladm_flow_stat_free(prev_stat);
438
439 /* Prev <- curr stats */
440 flow_node->fc_stat = curr_stat;
441
442 if (diff_stat == NULL)
443 goto done;
444
445 /* Print stats */
446 fargs.flow_s_flow = flowname;
447 fargs.flow_s_stat = diff_stat;
448 fargs.flow_s_unit = state->fs_unit;
449 fargs.flow_s_parsable = state->fs_parsable;
474 print_all_stats(name_value_stat_entry_t *stat_entry)
475 {
476 name_value_stat_t *curr_stat;
477
478 printf("%s\n", stat_entry->nve_header);
479
480 for (curr_stat = stat_entry->nve_stats; curr_stat != NULL;
481 curr_stat = curr_stat->nv_nextstat) {
482 printf("\t%15s", curr_stat->nv_statname);
483 printf("\t%15llu\n", curr_stat->nv_statval);
484 }
485 }
486
487 /* ARGSUSED */
488 static int
489 dump_one_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg)
490 {
491 char *flowname = attr->fa_flowname;
492 void *stat;
493
494 stat = dladm_flow_stat_query_all(flowname);
495 if (stat == NULL)
496 goto done;
497 print_all_stats(stat);
498 dladm_flow_stat_query_all_free(stat);
499
500 done:
501 return (DLADM_WALK_CONTINUE);
502 }
503
504 /*
505 * Wrapper of dladm_walk_flow(query_flow_stats,...) to make it usable for
506 * dladm_walk_datalink_id(). Used for showing flow stats for
507 * all flows on all links.
508 */
509 static int
510 dump_link_flow_stats(dladm_handle_t dh, datalink_id_t linkid, void * arg)
511 {
512 if (dladm_walk_flow(dump_one_flow_stats, dh, linkid, arg, B_FALSE)
513 == DLADM_STATUS_OK)
514 return (DLADM_WALK_CONTINUE);
|
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright 2017 Joyent, Inc.
28 */
29
30 /*
31 * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
32 */
33
34 #include <stdio.h>
35 #include <locale.h>
36 #include <stdarg.h>
37 #include <stdlib.h>
38 #include <fcntl.h>
39 #include <string.h>
40 #include <stropts.h>
41 #include <errno.h>
42 #include <strings.h>
43 #include <getopt.h>
44 #include <unistd.h>
45 #include <priv.h>
46 #include <netdb.h>
47 #include <libintl.h>
48 #include <libdlflow.h>
49 #include <libdllink.h>
50 #include <libdlstat.h>
51 #include <sys/types.h>
52 #include <sys/socket.h>
53 #include <netinet/in.h>
413 static int
414 query_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg)
415 {
416 show_flow_state_t *state = arg;
417 flow_chain_t *flow_node;
418 flow_stat_t *curr_stat;
419 flow_stat_t *prev_stat;
420 flow_stat_t *diff_stat;
421 char *flowname = attr->fa_flowname;
422 flow_args_t fargs;
423
424 /* Get previous stats for the flow */
425 flow_node = get_flow_prev_stat(flowname, arg);
426 if (flow_node == NULL)
427 goto done;
428
429 flow_node->fc_visited = B_TRUE;
430 prev_stat = flow_node->fc_stat;
431
432 /* Query library for current stats */
433 curr_stat = dladm_flow_stat_query(handle, flowname);
434 if (curr_stat == NULL)
435 goto done;
436
437 /* current stats - prev iteration stats */
438 diff_stat = dladm_flow_stat_diff(curr_stat, prev_stat);
439
440 /* Free prev stats */
441 dladm_flow_stat_free(prev_stat);
442
443 /* Prev <- curr stats */
444 flow_node->fc_stat = curr_stat;
445
446 if (diff_stat == NULL)
447 goto done;
448
449 /* Print stats */
450 fargs.flow_s_flow = flowname;
451 fargs.flow_s_stat = diff_stat;
452 fargs.flow_s_unit = state->fs_unit;
453 fargs.flow_s_parsable = state->fs_parsable;
478 print_all_stats(name_value_stat_entry_t *stat_entry)
479 {
480 name_value_stat_t *curr_stat;
481
482 printf("%s\n", stat_entry->nve_header);
483
484 for (curr_stat = stat_entry->nve_stats; curr_stat != NULL;
485 curr_stat = curr_stat->nv_nextstat) {
486 printf("\t%15s", curr_stat->nv_statname);
487 printf("\t%15llu\n", curr_stat->nv_statval);
488 }
489 }
490
491 /* ARGSUSED */
492 static int
493 dump_one_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg)
494 {
495 char *flowname = attr->fa_flowname;
496 void *stat;
497
498 stat = dladm_flow_stat_query_all(handle, flowname);
499 if (stat == NULL)
500 goto done;
501 print_all_stats(stat);
502 dladm_flow_stat_query_all_free(stat);
503
504 done:
505 return (DLADM_WALK_CONTINUE);
506 }
507
508 /*
509 * Wrapper of dladm_walk_flow(query_flow_stats,...) to make it usable for
510 * dladm_walk_datalink_id(). Used for showing flow stats for
511 * all flows on all links.
512 */
513 static int
514 dump_link_flow_stats(dladm_handle_t dh, datalink_id_t linkid, void * arg)
515 {
516 if (dladm_walk_flow(dump_one_flow_stats, dh, linkid, arg, B_FALSE)
517 == DLADM_STATUS_OK)
518 return (DLADM_WALK_CONTINUE);
|