Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147727015
D3422.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D3422.diff
View Options
Index: usr.bin/netstat/if.c
===================================================================
--- usr.bin/netstat/if.c
+++ usr.bin/netstat/if.c
@@ -46,6 +46,7 @@
#include <net/if.h>
#include <net/if_dl.h>
+#include <net/if_mib.h>
#include <net/if_types.h>
#include <net/ethernet.h>
#include <netinet/in.h>
@@ -680,3 +681,87 @@
/* 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);
+}
Index: usr.bin/netstat/main.c
===================================================================
--- usr.bin/netstat/main.c
+++ usr.bin/netstat/main.c
@@ -545,7 +545,10 @@
#endif
if (iflag && !sflag) {
xo_open_container("statistics");
- intpr(interval, NULL, af);
+ if (Rflag)
+ intpr(interval, ring_stats, af);
+ else
+ intpr(interval, NULL, af);
xo_close_container("statistics");
xo_finish();
exit(0);
Index: usr.bin/netstat/netstat.h
===================================================================
--- usr.bin/netstat/netstat.h
+++ usr.bin/netstat/netstat.h
@@ -157,3 +157,4 @@
void mroutepr(void);
void mrt_stats(void);
void bpf_stats(char *);
+void ring_stats(char *);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 14, 5:54 AM (13 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29655502
Default Alt Text
D3422.diff (3 KB)
Attached To
Mode
D3422: Extend netstat(1) to report the statistics of ifring
Attached
Detach File
Event Timeline
Log In to Comment