PERFORCE change 167458 for review
Gabor Pali
pgj at FreeBSD.org
Tue Aug 18 02:54:55 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167458
Change 167458 by pgj at petymeg-current on 2009/08/18 02:54:06
Add support for exporting information on IPv4 virtual interfaces
in a less ABI-sensitive way via sysctl(3).
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/ip_mroute.c#4 edit
.. //depot/projects/soc2009/pgj_libstat/src/sys/netinet/ip_mroute.h#3 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/ip_mroute.c#4 (text+ko) ====
@@ -85,6 +85,7 @@
#include <sys/module.h>
#include <sys/priv.h>
#include <sys/protosw.h>
+#include <sys/sbuf.h>
#include <sys/signalvar.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -181,6 +182,7 @@
&viftable, sizeof(viftable), "S,vif[MAXVIFS]",
"IPv4 Multicast Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)");
+
static struct mtx vif_mtx;
#define VIF_LOCK() mtx_lock(&vif_mtx)
#define VIF_UNLOCK() mtx_unlock(&vif_mtx)
@@ -797,6 +799,66 @@
return 0;
}
+static int
+export_viftable(SYSCTL_HANDLER_ARGS)
+{
+ struct vif_stream vs;
+ struct vif_data vd;
+ struct sbuf sbuf;
+ int error, buflen;
+ char *buffer;
+ struct vif *v;
+ vifi_t vifi;
+
+ error = 0;
+ bzero(&vs, sizeof(vs));
+ vs.vs_version = VIF_STREAM_VERSION;
+
+ VIF_LOCK();
+
+ vs.vs_count = numvifs;
+ buflen = sizeof(vs) + vs.vs_count * sizeof(vd) + 1;
+ buffer = malloc(buflen, M_TEMP, M_WAITOK | M_ZERO);
+ sbuf_new(&sbuf, buffer, buflen, SBUF_FIXEDLEN);
+
+ if (sbuf_bcat(&sbuf, &vs, sizeof(vs)) < 0) {
+ error = ENOMEM;
+ goto out;
+ }
+
+ for (vifi = 0; vifi < numvifs; vifi++) {
+ v = &viftable[vifi];
+
+ bzero(&vd, sizeof(vd));
+ vd.vd_flags = v->v_flags;
+ vd.vd_threshold = v->v_threshold;
+ vd.vd_lcl_addr = v->v_lcl_addr.s_addr;
+ vd.vd_rmt_addr = v->v_rmt_addr.s_addr;
+ vd.vd_if_index = v->v_ifp->if_index;
+ vd.vd_pkt_in = v->v_pkt_in;
+ vd.vd_pkt_out = v->v_pkt_out;
+ vd.vd_bytes_in = v->v_bytes_in;
+ vd.vd_bytes_out = v->v_bytes_out;
+
+ if (sbuf_bcat(&sbuf, &vd, sizeof(vd)) < 0) {
+ error = ENOMEM;
+ goto out;
+ }
+ }
+
+ VIF_UNLOCK();
+
+ sbuf_finish(&sbuf);
+ error = SYSCTL_OUT(req, sbuf_data(&sbuf), sbuf_len(&sbuf));
+out:
+ free(buffer, M_TEMP);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet_ip, OID_AUTO, sviftable, CTLFLAG_RD|CTLTYPE_STRUCT,
+ 0, 0, export_viftable, "s,struct vif_data",
+ "IPv4 Multicast Interfaces (streamed)");
+
/*
* Set PIM assert processing global
*/
==== //depot/projects/soc2009/pgj_libstat/src/sys/netinet/ip_mroute.h#3 (text+ko) ====
@@ -267,6 +267,29 @@
struct route v_route; /* cached route */
};
+/*
+ * Statistics structures to be used by user space monitoring tools.
+ */
+#define VIF_STREAM_VERSION 0x00000001
+
+struct vif_stream {
+ u_int32_t vs_version;
+ u_int32_t vs_count;
+};
+
+struct vif_data {
+ u_int8_t vd_flags;
+ u_int8_t vd_threshold;
+ u_int32_t vd_lcl_addr;
+ u_int32_t vd_rmt_addr;
+ u_int16_t vd_if_index;
+ u_int64_t vd_pkt_in;
+ u_int64_t vd_pkt_out;
+ u_int64_t vd_bytes_in;
+ u_int64_t vd_bytes_out;
+ u_int8_t _vd_pad[22];
+};
+
#ifdef _KERNEL
/*
* The kernel's multicast forwarding cache entry structure
More information about the p4-projects
mailing list