/* ARGSUSED */ static int show_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg) { show_flow_state_t *state = (show_flow_state_t *)arg; char *name = attr->fa_flowname; pktsum_t stats, diff_stats; flow_args_t fargs; if (state->fs_firstonly) { if (state->fs_donefirst) return (DLADM_WALK_TERMINATE); state->fs_donefirst = B_TRUE; } else { bzero(&state->fs_prevstats, sizeof (state->fs_prevstats)); } get_flow_stats(name, &stats); dladm_stats_diff(&diff_stats, &stats, &state->fs_prevstats); fargs.flow_s_flow = name; fargs.flow_s_psum = &diff_stats; ofmt_print(state->fs_ofmt, (void *)&fargs); state->fs_prevstats = stats; return (DLADM_WALK_CONTINUE); }
/* ARGSUSED */ static ilb_status_t ilbadm_print_hc_result(ilb_handle_t h, ilb_hc_srv_t *srv, void *arg) { ofmt_handle_t ofmt_h = arg; ofmt_print(ofmt_h, srv); return (ILB_STATUS_OK); }
/* ARGSUSED */ static ilb_status_t ilbadm_print_hc(ilb_handle_t h, ilb_hc_info_t *hc_info, void *arg) { ofmt_handle_t ofmt_h = arg; ofmt_print(ofmt_h, hc_info); return (ILB_STATUS_OK); }
/* * Outputs one row of values. The values to output are obtained through the * callback function pointers. The actual values are computed from the `ih' * and `arg' structures passed to the callback function. */ static void ofmt_output(const ofmt_handle_t ofmt, ipmp_handle_t ih, void *arg) { ipmpstat_sfunc_arg_t sfunc_arg; sfunc_arg.sa_ih = ih; sfunc_arg.sa_data = arg; ofmt_print(ofmt, &sfunc_arg); }
ilbadm_status_t i_list_sg_srv_ofmt(char *sgname, ilb_server_data_t *sd, void *arg) { list_arg_t *larg = (list_arg_t *)arg; sg_srv_o_arg_t line_arg; line_arg.sgname = sgname; line_arg.sd = sd; ofmt_print(larg->oh, &line_arg); return (ILBADM_OK); }
/* * 'show-router' one VRRP router. */ static vrrp_err_t do_show_router(const char *vn, ofmt_handle_t ofmt) { vrrp_queryinfo_t *vq; vrrp_err_t err; if ((err = vrrp_query(vrrp_vh, vn, &vq)) != VRRP_SUCCESS) return (err); ofmt_print(ofmt, vq); free(vq); return (VRRP_SUCCESS); }
static int show_one_flowprop(void *arg, const char *propname) { show_flowprop_state_t *statep = arg; flowprop_args_t fs_arg; bzero(&fs_arg, sizeof (fs_arg)); fs_arg.fs_state = statep; fs_arg.fs_propname = (char *)propname; fs_arg.fs_flowname = (char *)statep->fs_flow; ofmt_print(statep->fs_ofmt, (void *)&fs_arg); return (DLADM_WALK_CONTINUE); }
/* ARGSUSED */ static int query_flow_stats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg) { show_flow_state_t *state = arg; flow_chain_t *flow_node; flow_stat_t *curr_stat; flow_stat_t *prev_stat; flow_stat_t *diff_stat; char *flowname = attr->fa_flowname; flow_args_t fargs; /* Get previous stats for the flow */ flow_node = get_flow_prev_stat(flowname, arg); if (flow_node == NULL) goto done; flow_node->fc_visited = B_TRUE; prev_stat = flow_node->fc_stat; /* Query library for current stats */ curr_stat = dladm_flow_stat_query(flowname); if (curr_stat == NULL) goto done; /* current stats - prev iteration stats */ diff_stat = dladm_flow_stat_diff(curr_stat, prev_stat); /* Free prev stats */ dladm_flow_stat_free(prev_stat); /* Prev <- curr stats */ flow_node->fc_stat = curr_stat; if (diff_stat == NULL) goto done; /* Print stats */ fargs.flow_s_flow = flowname; fargs.flow_s_stat = diff_stat; fargs.flow_s_unit = state->fs_unit; fargs.flow_s_parsable = state->fs_parsable; ofmt_print(state->fs_ofmt, &fargs); /* Free diff stats */ dladm_flow_stat_free(diff_stat); done: return (DLADM_WALK_CONTINUE); }
/* ARGSUSED */ ilbadm_status_t ilbadm_show_hc(int argc, char *argv[]) { ilb_handle_t h = ILB_INVALID_HANDLE; ilb_status_t rclib; ofmt_handle_t ofmt_h; ofmt_status_t ofmt_ret; if ((ofmt_ret = ofmt_open("all", hc_fields, 0, SHOW_HC_COLS, &ofmt_h)) != OFMT_SUCCESS) { char err_buf[SHOW_HC_COLS]; ilbadm_err(gettext("ofmt_open failed: %s"), ofmt_strerror(ofmt_h, ofmt_ret, err_buf, SHOW_HC_COLS)); return (ILBADM_LIBERR); } rclib = ilb_open(&h); if (rclib != ILB_STATUS_OK) goto out; if (argc == 1) { rclib = ilb_walk_hc(h, ilbadm_print_hc, ofmt_h); } else { ilb_hc_info_t hc_info; int i; for (i = 1; i < argc; i++) { rclib = ilb_get_hc_info(h, argv[i], &hc_info); if (rclib == ILB_STATUS_OK) ofmt_print(ofmt_h, &hc_info); else break; } } out: ofmt_close(ofmt_h); if (h != ILB_INVALID_HANDLE) (void) ilb_close(h); if (rclib != ILB_STATUS_OK) { ilbadm_err(ilb_errstr(rclib)); return (ILBADM_LIBERR); } return (ILBADM_OK); }
static int show_history_res(dladm_usage_t *history, void *arg) { show_history_state_t *state = (show_history_state_t *)arg; char buf[DLADM_STRSIZE]; history_fields_buf_t ubuf; dladm_flow_attr_t attr; dladm_status_t status; /* * Only show historical information for existing flows unless '-a' * is specified. */ if (!state->us_showall && ((status = dladm_flow_info(handle, history->du_name, &attr)) != DLADM_STATUS_OK)) { return (status); } bzero(&ubuf, sizeof (ubuf)); (void) snprintf(ubuf.history_flow, sizeof (ubuf.history_flow), "%s", history->du_name); (void) snprintf(ubuf.history_duration, sizeof (ubuf.history_duration), "%llu", history->du_duration); (void) snprintf(ubuf.history_ipackets, sizeof (ubuf.history_ipackets), "%llu", history->du_ipackets); (void) snprintf(ubuf.history_rbytes, sizeof (ubuf.history_rbytes), "%llu", history->du_rbytes); (void) snprintf(ubuf.history_opackets, sizeof (ubuf.history_opackets), "%llu", history->du_opackets); (void) snprintf(ubuf.history_obytes, sizeof (ubuf.history_obytes), "%llu", history->du_obytes); (void) snprintf(ubuf.history_bandwidth, sizeof (ubuf.history_bandwidth), "%s Mbps", dladm_bw2str(history->du_bandwidth, buf)); ofmt_print(state->us_ofmt, (void *)&ubuf); return (DLADM_STATUS_OK); }
/*ARGSUSED*/ static int show_flow(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg) { show_flow_state_t *statep = arg; dladm_status_t status; flow_fields_buf_t fbuf; /* * first get all the flow attributes into fbuf; */ bzero(&fbuf, sizeof (fbuf)); status = print_flow(statep, attr, &fbuf); if (status != DLADM_STATUS_OK) goto done; ofmt_print(statep->fs_ofmt, (void *)&fbuf); done: statep->fs_status = status; return (DLADM_WALK_CONTINUE); }
static int show_history_time(dladm_usage_t *history, void *arg) { show_history_state_t *state = (show_history_state_t *)arg; char buf[DLADM_STRSIZE]; history_l_fields_buf_t ubuf; time_t time; double bw; dladm_flow_attr_t attr; dladm_status_t status; /* * Only show historical information for existing flows unless '-a' * is specified. */ if (!state->us_showall && ((status = dladm_flow_info(handle, history->du_name, &attr)) != DLADM_STATUS_OK)) { return (status); } if (state->us_plot) { if (!state->us_printheader) { if (state->us_first) { (void) printf("# Time"); state->us_first = B_FALSE; } (void) printf(" %s", history->du_name); if (history->du_last) { (void) printf("\n"); state->us_first = B_TRUE; state->us_printheader = B_TRUE; } } else { if (state->us_first) { time = history->du_etime; (void) strftime(buf, sizeof (buf), "%T", localtime(&time)); state->us_first = B_FALSE; (void) printf("%s", buf); } bw = (double)history->du_bandwidth/1000; (void) printf(" %.2f", bw); if (history->du_last) { (void) printf("\n"); state->us_first = B_TRUE; } } return (DLADM_STATUS_OK); } bzero(&ubuf, sizeof (ubuf)); (void) snprintf(ubuf.history_l_flow, sizeof (ubuf.history_l_flow), "%s", history->du_name); time = history->du_stime; (void) strftime(buf, sizeof (buf), "%T", localtime(&time)); (void) snprintf(ubuf.history_l_stime, sizeof (ubuf.history_l_stime), "%s", buf); time = history->du_etime; (void) strftime(buf, sizeof (buf), "%T", localtime(&time)); (void) snprintf(ubuf.history_l_etime, sizeof (ubuf.history_l_etime), "%s", buf); (void) snprintf(ubuf.history_l_rbytes, sizeof (ubuf.history_l_rbytes), "%llu", history->du_rbytes); (void) snprintf(ubuf.history_l_obytes, sizeof (ubuf.history_l_obytes), "%llu", history->du_obytes); (void) snprintf(ubuf.history_l_bandwidth, sizeof (ubuf.history_l_bandwidth), "%s Mbps", dladm_bw2str(history->du_bandwidth, buf)); ofmt_print(state->us_ofmt, (void *)&ubuf); return (DLADM_STATUS_OK); }