diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2015-12-07 14:58:33 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2015-12-07 14:58:33 +0000 |
commit | baef2f5cb916acb42bdcfa12530e8a2815d90bc6 (patch) | |
tree | 4a3d83dfcb3a3f956f3e5fd51268fe174ef922a4 /usr/src/lib/libdladm | |
parent | 1d5a53363c27489cc8b2086775b98eaec3cdb458 (diff) | |
parent | 5690df7e59608f4ee5c051c27524c9d55186cf58 (diff) | |
download | illumos-joyent-baef2f5cb916acb42bdcfa12530e8a2815d90bc6.tar.gz |
[illumos-gate merge]
commit 5690df7e59608f4ee5c051c27524c9d55186cf58
6498 typo in libavl(3LIB) man page
commit ba9ca9119d43e9c8e21e14f2129dce27d2dc0cdc
5468 Missing dependencies in lib/Makefile
commit 62ef8476c4f1cb016de161827d921418dee4b031
4008 libdladm should not have a curses UI inside
commit e8ea23086f5fd6f2b2f60c03b98d019041a374a2
6485 sun-ssh isn't happy with /etc/ssh/moduli contents after 6440
Conflicts:
usr/src/lib/libdladm/Makefile.com
usr/src/cmd/ssh/etc/Makefile
usr/src/lib/Makefile
usr/src/cmd/flowstat/flowstat.c
usr/src/cmd/dladm/dladm.c
Diffstat (limited to 'usr/src/lib/libdladm')
-rw-r--r-- | usr/src/lib/libdladm/Makefile.com | 2 | ||||
-rw-r--r-- | usr/src/lib/libdladm/common/libdlstat.c | 483 | ||||
-rw-r--r-- | usr/src/lib/libdladm/common/libdlstat.h | 3 | ||||
-rw-r--r-- | usr/src/lib/libdladm/common/mapfile-vers | 1 |
4 files changed, 4 insertions, 485 deletions
diff --git a/usr/src/lib/libdladm/Makefile.com b/usr/src/lib/libdladm/Makefile.com index 1cb28706a7..f9270f9769 100644 --- a/usr/src/lib/libdladm/Makefile.com +++ b/usr/src/lib/libdladm/Makefile.com @@ -38,7 +38,7 @@ include ../../Makefile.rootfs LIBS = $(DYNLIB) $(LINTLIB) LDLIBS += -ldevinfo -lc -linetutil -lsocket -lscf -lrcm -lnvpair \ - -lexacct -lnsl -lkstat -lcurses -lpool -lvarpd + -lexacct -lnsl -lkstat -lpool -lvarpd SRCDIR = ../common $(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC) diff --git a/usr/src/lib/libdladm/common/libdlstat.c b/usr/src/lib/libdladm/common/libdlstat.c index 264c5f179f..a4f9307bd7 100644 --- a/usr/src/lib/libdladm/common/libdlstat.c +++ b/usr/src/lib/libdladm/common/libdlstat.c @@ -23,6 +23,7 @@ * Use is subject to license terms. */ +#include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <strings.h> @@ -41,15 +42,6 @@ #include <libdlstat.h> #include <libdlaggr.h> -/* - * x86 <sys/regs> ERR conflicts with <curses.h> ERR. - * Include curses.h last. - */ -#if defined(ERR) -#undef ERR -#endif -#include <curses.h> - struct flowlist { char flowname[MAXFLOWNAMELEN]; char linkname[MAXLINKNAMELEN]; @@ -62,487 +54,17 @@ struct flowlist { pktsum_t diffstats; }; -static int maxx, maxy, redraw = 0; -static volatile uint_t handle_resize = 0, handle_break = 0; - pktsum_t totalstats; struct flowlist *stattable = NULL; -static int statentry = -1, maxstatentries = 0; #define STATGROWSIZE 16 -/* - * Search for flowlist entry in stattable which matches - * the flowname and linkid. If no match is found, use - * next available slot. If no slots are available, - * reallocate table with more slots. - * - * Return: *flowlist of matching flow - * NULL if realloc fails - */ - -static struct flowlist * -findstat(const char *flowname, datalink_id_t linkid) -{ - int match = 0; - struct flowlist *flist; - - /* Look for match in the stattable */ - for (match = 0, flist = stattable; - match <= statentry; - match++, flist++) { - - if (flist == NULL) - break; - /* match the flowname */ - if (flowname != NULL) { - if (strncmp(flowname, flist->flowname, MAXFLOWNAMELEN) - == NULL) - return (flist); - /* match the linkid */ - } else { - if (linkid == flist->linkid) - return (flist); - } - } - - /* - * No match found in the table. Store statistics in the next slot. - * If necessary, make room for this entry. - */ - statentry++; - if ((maxstatentries == 0) || (maxstatentries == statentry)) { - maxstatentries += STATGROWSIZE; - stattable = realloc(stattable, - maxstatentries * sizeof (struct flowlist)); - if (stattable == NULL) { - perror("realloc"); - return (struct flowlist *)(NULL); - } - } - flist = &stattable[statentry]; - bzero(flist, sizeof (struct flowlist)); - - if (flowname != NULL) - (void) strncpy(flist->flowname, flowname, MAXFLOWNAMELEN); - flist->linkid = linkid; - flist->fd = INT32_MAX; - - return (flist); -} - -/*ARGSUSED*/ -static void -print_flow_stats(dladm_handle_t handle, struct flowlist *flist) -{ - struct flowlist *fcurr; - double ikbs, okbs; - double ipks, opks; - double dlt; - int fcount; - static boolean_t first = B_TRUE; - - if (first) { - first = B_FALSE; - (void) printw("please wait...\n"); - return; - } - - for (fcount = 0, fcurr = flist; - fcount <= statentry; - fcount++, fcurr++) { - if (fcurr->flowname && fcurr->display) { - dlt = (double)fcurr->diffstats.snaptime/(double)NANOSEC; - ikbs = fcurr->diffstats.rbytes * 8 / dlt / 1024; - okbs = fcurr->diffstats.obytes * 8 / dlt / 1024; - ipks = fcurr->diffstats.ipackets / dlt; - opks = fcurr->diffstats.opackets / dlt; - (void) printw("%-15.15s", fcurr->flowname); - (void) printw("%-10.10s", fcurr->linkname); - (void) printw("%9.2f %9.2f %9.2f %9.2f ", - ikbs, okbs, ipks, opks); - (void) printw("\n"); - } - } -} - -/*ARGSUSED*/ -static int -flow_kstats(dladm_handle_t handle, dladm_flow_attr_t *attr, void *arg) -{ - kstat_ctl_t *kcp = (kstat_ctl_t *)arg; - kstat_t *ksp; - struct flowlist *flist; - pktsum_t currstats, *prevstats, *diffstats; - - flist = findstat(attr->fa_flowname, attr->fa_linkid); - if (flist == NULL) - return (DLADM_WALK_CONTINUE); - - flist->display = B_FALSE; - prevstats = &flist->prevstats; - diffstats = &flist->diffstats; - - (void) dladm_datalink_id2info(handle, attr->fa_linkid, NULL, NULL, - NULL, flist->linkname, sizeof (flist->linkname)); - - - /* lookup kstat entry */ - ksp = dladm_kstat_lookup(kcp, NULL, -1, attr->fa_flowname, "flow"); - - if (ksp == NULL) - return (DLADM_WALK_CONTINUE); - - /* read packet and byte stats */ - dladm_get_stats(kcp, ksp, &currstats); - - if (flist->ifspeed == 0) - (void) dladm_kstat_value(ksp, "ifspeed", KSTAT_DATA_UINT64, - &flist->ifspeed); - - if (flist->first) { - flist->first = B_FALSE; - } else { - dladm_stats_diff(diffstats, &currstats, prevstats); - if (diffstats->snaptime == 0) - return (DLADM_WALK_CONTINUE); - dladm_stats_total(&totalstats, diffstats, &totalstats); - } - - bcopy(&currstats, prevstats, sizeof (pktsum_t)); - flist->display = B_TRUE; - - return (DLADM_WALK_CONTINUE); -} - -/*ARGSUSED*/ -static void -print_link_stats(dladm_handle_t handle, struct flowlist *flist) -{ - struct flowlist *fcurr; - double ikbs, okbs; - double ipks, opks; - double util; - double dlt; - int fcount; - static boolean_t first = B_TRUE; - - if (first) { - first = B_FALSE; - (void) printw("please wait...\n"); - return; - } - - for (fcount = 0, fcurr = flist; - fcount <= statentry; - fcount++, fcurr++) { - if ((fcurr->linkid != DATALINK_INVALID_LINKID) && - fcurr->display) { - dlt = (double)fcurr->diffstats.snaptime/(double)NANOSEC; - ikbs = (double)fcurr->diffstats.rbytes * 8 / dlt / 1024; - okbs = (double)fcurr->diffstats.obytes * 8 / dlt / 1024; - ipks = (double)fcurr->diffstats.ipackets / dlt; - opks = (double)fcurr->diffstats.opackets / dlt; - (void) printw("%-10.10s", fcurr->linkname); - (void) printw("%9.2f %9.2f %9.2f %9.2f ", - ikbs, okbs, ipks, opks); - if (fcurr->ifspeed != 0) - util = ((ikbs + okbs) * 1024) * - 100/ fcurr->ifspeed; - else - util = (double)0; - (void) attron(A_BOLD); - (void) printw(" %6.2f", util); - (void) attroff(A_BOLD); - (void) printw("\n"); - } - } -} - -/* - * This function is called through the dladm_walk_datalink_id() walker and - * calls the dladm_walk_flow() walker. - */ - -/*ARGSUSED*/ -static int -link_flowstats(dladm_handle_t handle, datalink_id_t linkid, void *arg) -{ - dladm_status_t status; - - status = dladm_walk_flow(flow_kstats, handle, linkid, arg, B_FALSE); - if (status == DLADM_STATUS_OK) - return (DLADM_WALK_CONTINUE); - else - return (DLADM_WALK_TERMINATE); -} - -/*ARGSUSED*/ -static int -link_kstats(dladm_handle_t handle, datalink_id_t linkid, void *arg) -{ - kstat_ctl_t *kcp = (kstat_ctl_t *)arg; - struct flowlist *flist; - pktsum_t currstats, *prevstats, *diffstats; - datalink_class_t class; - kstat_t *ksp; - char dnlink[MAXPATHLEN]; - - /* find the flist entry */ - flist = findstat(NULL, linkid); - flist->display = B_FALSE; - if (flist != NULL) { - prevstats = &flist->prevstats; - diffstats = &flist->diffstats; - } else { - return (DLADM_WALK_CONTINUE); - } - - if (dladm_datalink_id2info(handle, linkid, NULL, &class, NULL, - flist->linkname, sizeof (flist->linkname)) != DLADM_STATUS_OK) - return (DLADM_WALK_CONTINUE); - - if (flist->fd == INT32_MAX) { - if (class == DATALINK_CLASS_PHYS) { - (void) snprintf(dnlink, MAXPATHLEN, "/dev/net/%s", - flist->linkname); - if ((flist->fd = open(dnlink, O_RDWR)) < 0) - return (DLADM_WALK_CONTINUE); - } else { - flist->fd = -1; - } - (void) kstat_chain_update(kcp); - } - - /* lookup kstat entry */ - ksp = dladm_kstat_lookup(kcp, NULL, -1, flist->linkname, "net"); - - if (ksp == NULL) - return (DLADM_WALK_CONTINUE); - - /* read packet and byte stats */ - dladm_get_stats(kcp, ksp, &currstats); - - if (flist->ifspeed == 0) - (void) dladm_kstat_value(ksp, "ifspeed", KSTAT_DATA_UINT64, - &flist->ifspeed); - - if (flist->first) { - flist->first = B_FALSE; - } else { - dladm_stats_diff(diffstats, &currstats, prevstats); - if (diffstats->snaptime == 0) - return (DLADM_WALK_CONTINUE); - } - - bcopy(&currstats, prevstats, sizeof (*prevstats)); - flist->display = B_TRUE; - - return (DLADM_WALK_CONTINUE); -} - -static void -closedevnet() -{ - int index = 0; - struct flowlist *flist; - - /* Close all open /dev/net/ files */ - - for (flist = stattable; index < maxstatentries; index++, flist++) { - if (flist->linkid == DATALINK_INVALID_LINKID) - break; - if (flist->fd != -1 && flist->fd != INT32_MAX) - (void) close(flist->fd); - } -} - -/*ARGSUSED*/ -static void -sig_break(int s) -{ - handle_break = 1; -} - -/*ARGSUSED*/ -static void -sig_resize(int s) -{ - handle_resize = 1; -} - -static void -curses_init() -{ - maxx = maxx; /* lint */ - maxy = maxy; /* lint */ - - /* Install signal handlers */ - (void) signal(SIGINT, sig_break); - (void) signal(SIGQUIT, sig_break); - (void) signal(SIGTERM, sig_break); - (void) signal(SIGWINCH, sig_resize); - - /* Initialize ncurses */ - (void) initscr(); - (void) cbreak(); - (void) noecho(); - (void) curs_set(0); - timeout(0); - getmaxyx(stdscr, maxy, maxx); -} - -static void -curses_fin() -{ - (void) printw("\n"); - (void) curs_set(1); - (void) nocbreak(); - (void) endwin(); - - free(stattable); -} - -static void -stat_report(dladm_handle_t handle, kstat_ctl_t *kcp, datalink_id_t linkid, - const char *flowname, int opt) -{ - - double dlt, ikbs, okbs, ipks, opks; - - struct flowlist *fstable = stattable; - - if ((opt != LINK_REPORT) && (opt != FLOW_REPORT)) - return; - - /* Handle window resizes */ - if (handle_resize) { - (void) endwin(); - (void) initscr(); - (void) cbreak(); - (void) noecho(); - (void) curs_set(0); - timeout(0); - getmaxyx(stdscr, maxy, maxx); - redraw = 1; - handle_resize = 0; - } - - /* Print title */ - (void) erase(); - (void) attron(A_BOLD); - (void) move(0, 0); - if (opt == FLOW_REPORT) - (void) printw("%-15.15s", "Flow"); - (void) printw("%-10.10s", "Link"); - (void) printw("%9.9s %9.9s %9.9s %9.9s ", - "iKb/s", "oKb/s", "iPk/s", "oPk/s"); - if (opt == LINK_REPORT) - (void) printw(" %6.6s", "%Util"); - (void) printw("\n"); - (void) attroff(A_BOLD); - - (void) move(2, 0); - - /* Print stats for each link or flow */ - bzero(&totalstats, sizeof (totalstats)); - if (opt == LINK_REPORT) { - /* Display all links */ - if (linkid == DATALINK_ALL_LINKID) { - (void) dladm_walk_datalink_id(link_kstats, handle, - (void *)kcp, DATALINK_CLASS_ALL, - DATALINK_ANY_MEDIATYPE, DLADM_OPT_ACTIVE); - /* Display 1 link */ - } else { - (void) link_kstats(handle, linkid, kcp); - } - print_link_stats(handle, fstable); - - } else if (opt == FLOW_REPORT) { - /* Display 1 flow */ - if (flowname != NULL) { - dladm_flow_attr_t fattr; - if (dladm_flow_info(handle, flowname, &fattr) != - DLADM_STATUS_OK) - return; - (void) flow_kstats(handle, &fattr, kcp); - /* Display all flows on all links */ - } else if (linkid == DATALINK_ALL_LINKID) { - (void) dladm_walk_datalink_id(link_flowstats, handle, - (void *)kcp, DATALINK_CLASS_ALL, - DATALINK_ANY_MEDIATYPE, DLADM_OPT_ACTIVE); - /* Display all flows on a link */ - } else if (linkid != DATALINK_INVALID_LINKID) { - (void) dladm_walk_flow(flow_kstats, handle, linkid, kcp, - B_FALSE); - } - print_flow_stats(handle, fstable); - - /* Print totals */ - (void) attron(A_BOLD); - dlt = (double)totalstats.snaptime / (double)NANOSEC; - ikbs = totalstats.rbytes / dlt / 1024; - okbs = totalstats.obytes / dlt / 1024; - ipks = totalstats.ipackets / dlt; - opks = totalstats.opackets / dlt; - (void) printw("\n%-25.25s", "Totals"); - (void) printw("%9.2f %9.2f %9.2f %9.2f ", - ikbs, okbs, ipks, opks); - (void) attroff(A_BOLD); - } - - if (redraw) - (void) clearok(stdscr, 1); - - if (refresh() == ERR) - return; - - if (redraw) { - (void) clearok(stdscr, 0); - redraw = 0; - } -} - /* Exported functions */ /* - * Continuously display link or flow statstics using a libcurses - * based display. - */ - -void -dladm_continuous(dladm_handle_t handle, datalink_id_t linkid, - const char *flowname, int interval, int opt) -{ - kstat_ctl_t *kcp; - - if ((kcp = kstat_open()) == NULL) { - warn("kstat open operation failed"); - return; - } - - curses_init(); - - for (;;) { - - if (handle_break) - break; - - stat_report(handle, kcp, linkid, flowname, opt); - - (void) sleep(max(1, interval)); - } - - closedevnet(); - curses_fin(); - (void) kstat_close(kcp); -} - -/* * dladm_kstat_lookup() is a modified version of kstat_lookup which * adds the class as a selector. */ - kstat_t * dladm_kstat_lookup(kstat_ctl_t *kcp, const char *module, int instance, const char *name, const char *class) @@ -2496,7 +2018,8 @@ done: /*ARGSUSED*/ static boolean_t i_dlstat_total_match(void *arg1, void *arg2) -{ /* Always single entry for total */ +{ + /* Always single entry for total */ return (B_TRUE); } diff --git a/usr/src/lib/libdladm/common/libdlstat.h b/usr/src/lib/libdladm/common/libdlstat.h index 381dafe22d..c799723a91 100644 --- a/usr/src/lib/libdladm/common/libdlstat.h +++ b/usr/src/lib/libdladm/common/libdlstat.h @@ -261,9 +261,6 @@ typedef struct pktsum_s { uint64_t oerrors; } pktsum_t; -extern void dladm_continuous(dladm_handle_t, datalink_id_t, - const char *, int, int); - extern kstat_t *dladm_kstat_lookup(kstat_ctl_t *, const char *, int, const char *, const char *); extern void dladm_get_stats(kstat_ctl_t *, kstat_t *, pktsum_t *); diff --git a/usr/src/lib/libdladm/common/mapfile-vers b/usr/src/lib/libdladm/common/mapfile-vers index f2847cab55..589bbf5330 100644 --- a/usr/src/lib/libdladm/common/mapfile-vers +++ b/usr/src/lib/libdladm/common/mapfile-vers @@ -208,7 +208,6 @@ SYMBOL_VERSION SUNWprivate_1.1 { dladm_parselink; - dladm_continuous; dladm_kstat_lookup; dladm_get_stats; dladm_kstat_value; |