Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/netstat/if.c
Context not available. | |||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/if_dl.h> | #include <net/if_dl.h> | ||||
#include <net/if_mib.h> | |||||
#include <net/if_types.h> | #include <net/if_types.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
Context not available. | |||||
/* NOTREACHED */ | /* NOTREACHED */ | ||||
} | } | ||||
void | |||||
ring_stats(char *name) | |||||
{ | |||||
static int mib[] = { CTL_NET, | |||||
PF_LINK, | |||||
NETLINK_GENERIC, | |||||
IFMIB_IFDATA, | |||||
0/* index */, | |||||
IFDATA_RINGINFO }; | |||||
size_t datalen = 0; | |||||
struct ifmibdata *data; | |||||
struct if_ring_data *ifrd; | |||||
struct xifrstat *ifrs; | |||||
int nrings, ncpus; | |||||
int ri, cpu, i; | |||||
if ((mib[4] = if_nametoindex(name)) == 0) | |||||
xo_err(EX_DATAERR, "if_nametoindex(%s)", name); | |||||
if (sysctl(mib, 6, NULL, &datalen, NULL, 0) < 0) | |||||
xo_err(EX_OSERR, "sysctl: net.link.generic.ifdata"); | |||||
if ((data = malloc(datalen)) == NULL) | |||||
xo_err(EX_OSERR, "malloc %lu bytes", (u_long)datalen); | |||||
if (sysctl(mib, 6, data, &datalen, NULL, 0) < 0) | |||||
xo_err(EX_OSERR, "sysctl: net.link.generic.ifdata"); | |||||
ifrd = &data->ifmd_ring_data; | |||||
ifrs = ifrd->ifrd_stats; | |||||
nrings = ifrd->ifrd_nrings; | |||||
ncpus = ifrd->ifrd_ncpus; | |||||
xo_open_instance("interface"); | |||||
for (i = 27; i > 0; i--) | |||||
xo_emit("-"); | |||||
xo_emit(" {tk:name/%s} ", name); | |||||
for (i = 28 - (int)strlen(name); i > 0; i--) | |||||
xo_emit("-"); | |||||
xo_emit("\n"); | |||||
xo_open_list("ring"); | |||||
for (ri = 0; ri < nrings; ri++) { | |||||
xo_open_instance("ring"); | |||||
xo_emit("\nring{tk:ring-id/%d}:\n", ri); | |||||
xo_emit("{T:/%-8s} ", ""); | |||||
for (cpu = 0; cpu < ncpus; cpu++) { | |||||
char string[32]; | |||||
snprintf(string, sizeof(string), "cpu%d", cpu); | |||||
xo_emit("{T:/%12s}", string); | |||||
} | |||||
xo_emit("\n"); | |||||
#define DUMP_LAYER(layer) \ | |||||
do { \ | |||||
xo_open_instance("layer"); \ | |||||
xo_emit("{tk:name/%-8s}:", #layer); \ | |||||
for (cpu = 0; cpu < ncpus; cpu++) { \ | |||||
char format[32]; \ | |||||
snprintf(format, sizeof(format), "{tk:cpu%d/%%12lu}", cpu);\ | |||||
xo_emit(format, ifrs[ri * ncpus + cpu].ifrs_##layer); \ | |||||
} \ | |||||
xo_emit("\n"); \ | |||||
xo_close_instance("layer"); \ | |||||
} while (0) | |||||
xo_open_list("layer"); | |||||
DUMP_LAYER(ifinput); | |||||
DUMP_LAYER(netisr); | |||||
DUMP_LAYER(ether); | |||||
DUMP_LAYER(ip); | |||||
DUMP_LAYER(ip6); | |||||
DUMP_LAYER(tcp); | |||||
DUMP_LAYER(udp); | |||||
xo_close_list("layer"); | |||||
xo_close_instance("ring"); | |||||
} | |||||
xo_close_list("ring"); | |||||
xo_close_instance("interface"); | |||||
free(data); | |||||
} | |||||
Context not available. |