PERFORCE change 166653 for review

Gabor Pali pgj at FreeBSD.org
Mon Jul 27 20:46:27 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=166653

Change 166653 by pgj at petymeg-current on 2009/07/27 20:45:40

	Add support for ICMP statistics.

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#37 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#35 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#5 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#41 edit

Differences ...

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#37 (text+ko) ====

@@ -119,6 +119,7 @@
     stat_UDP,
     stat_CARP,
     stat_IP,
+    stat_ICMP,
     stat_MAX,
     stat_Invalid,
 };
@@ -148,6 +149,7 @@
 struct udp_stat;
 struct carp_stat;
 struct ip_stat;
+struct icmp_stat;
 
 __BEGIN_DECLS
 const char		    *netstat_strerror(int);
@@ -500,4 +502,23 @@
 u_int64_t   netstat_ips_get_notmember(const struct ip_stat *);
 u_int64_t   netstat_ips_get_nogif(const struct ip_stat *);
 u_int64_t   netstat_ips_get_badaddr(const struct ip_stat *);
+
+const struct icmp_stat	*netstat_get_icmpstats(const struct stat_type *);
+
+u_int64_t   netstat_icmps_get_error(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_oldshort(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_oldicmp(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_outhist(const struct icmp_stat *, int);
+u_int64_t   netstat_icmps_get_badcode(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_tooshort(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_checksum(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_badlen(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_reflect(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_inhist(const struct icmp_stat *, int);
+u_int64_t   netstat_icmps_get_bmcastecho(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_bmcasttstamp(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_badaddr(const struct icmp_stat *);
+u_int64_t   netstat_icmps_get_noroute(const struct icmp_stat *);
+const char  *netstat_icmpname(int);
+int	    netstat_icmp_get_maskrepl(void *kvm_handle);
 #endif /* !_NETSTAT_H_ */

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#35 (text+ko) ====

@@ -45,6 +45,8 @@
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
 #include <netinet/ip_carp.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/icmp_var.h>
 
 #include "netstat.h"
 
@@ -298,6 +300,10 @@
 	struct ipstat	s;
 };
 
+struct icmp_stat {
+	struct icmpstat	s;
+};
+
 int kread_data(kvm_t *kvm, u_long kvm_pointer, void *address, size_t size);
 int kread_string(kvm_t *kvm, u_long kvm_pointer, char *buffer, int buflen);
 

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#5 (text+ko) ====

@@ -36,6 +36,8 @@
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
 #include <netinet/ip_carp.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/icmp_var.h>
 
 #include <err.h>
 #include <kvm.h>
@@ -59,6 +61,7 @@
 	{ UDPSTAT_VERSION, "net.inet.udp.stats", "_udpstat" },
 	{ CARPSTAT_VERSION, "net.inet.carp.stats", "_carpstats" },
 	{ IPSTAT_VERSION, "net.inet.ip.stats", "_ipstat" },
+	{ ICMPSTAT_VERSION, "net.inet.icmp.stats", "_icmpstat" },
 };
 
 int
@@ -132,6 +135,30 @@
 }
 
 int
+netstat_icmp_get_maskrepl(void *kvm_handle)
+{
+	int res;
+
+	res = 0;
+
+	if (kvm_handle == NULL) {
+		if (read_sysctl("net.inet.icmp.maskrepl", &res,
+		    sizeof(res)) < 0) {
+			warn("netstat_icmp_get_maskrepl");
+			return (res);
+		}
+	} else {
+		if (read_kvm(kvm_handle, "_icmpmaskrepl", &res,
+		    sizeof(res)) < 0) {
+			warn("netstat_icmp_get_maskrepl");
+			return (res);
+		}
+	}
+
+	return (res);
+}
+
+int
 read_sysctl(const char *mib_symbol, void *addr, size_t len)
 {
 	if (sysctlbyname(mib_symbol, addr, &len, 0, 0) < 0) {

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#41 (text+ko) ====

@@ -2181,6 +2181,157 @@
 	return (isp->s.ips_badaddr);
 }
 
+const struct icmp_stat *
+netstat_get_icmpstats(const struct stat_type *sttp)
+{
+	if (sttp->stt_type == stat_ICMP) {
+		return ((const struct icmp_stat *) sttp->stt_data);
+	}
+	return (NULL);
+}
+
+u_int64_t
+netstat_icmps_get_error(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_error);
+}
+
+u_int64_t
+netstat_icmps_get_oldshort(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_oldshort);
+}
+
+u_int64_t
+netstat_icmps_get_oldicmp(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_oldicmp);
+}
+
+u_int64_t
+netstat_icmps_get_outhist(const struct icmp_stat *isp, int i)
+{
+	if (0 <= i && i < ICMP_MAXTYPE)
+		return (isp->s.icps_outhist[i]);
+	return (0);
+}
+
+u_int64_t
+netstat_icmps_get_badcode(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_badcode);
+}
+
+u_int64_t
+netstat_icmps_get_tooshort(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_tooshort);
+}
+
+u_int64_t
+netstat_icmps_get_checksum(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_checksum);
+}
+
+u_int64_t
+netstat_icmps_get_badlen(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_badlen);
+}
+
+u_int64_t
+netstat_icmps_get_reflect(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_reflect);
+}
+
+u_int64_t
+netstat_icmps_get_inhist(const struct icmp_stat *isp, int i)
+{
+	if (0 <= i && i < ICMP_MAXTYPE)
+		return (isp->s.icps_inhist[i]);
+	return (0);
+}
+
+u_int64_t
+netstat_icmps_get_bmcastecho(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_bmcastecho);
+}
+
+u_int64_t
+netstat_icmps_get_bmcasttstamp(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_bmcasttstamp);
+}
+
+u_int64_t
+netstat_icmps_get_badaddr(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_badaddr);
+}
+
+u_int64_t
+netstat_icmps_get_noroute(const struct icmp_stat *isp)
+{
+	return (isp->s.icps_noroute);
+}
+
+
+
+static	const char *icmpnames[ICMP_MAXTYPE + 1] = {
+	"echo reply",			/* RFC 792 */
+	"#1",
+	"#2",
+	"destination unreachable",	/* RFC 792 */
+	"source quench",		/* RFC 792 */
+	"routing redirect",		/* RFC 792 */
+	"#6",
+	"#7",
+	"echo",				/* RFC 792 */
+	"router advertisement",		/* RFC 1256 */
+	"router solicitation",		/* RFC 1256 */
+	"time exceeded",		/* RFC 792 */
+	"parameter problem",		/* RFC 792 */
+	"time stamp",			/* RFC 792 */
+	"time stamp reply",		/* RFC 792 */
+	"information request",		/* RFC 792 */
+	"information request reply",	/* RFC 792 */
+	"address mask request",		/* RFC 950 */
+	"address mask reply",		/* RFC 950 */
+	"#19",
+	"#20",
+	"#21",
+	"#22",
+	"#23",
+	"#24",
+	"#25",
+	"#26",
+	"#27",
+	"#28",
+	"#29",
+	"icmp traceroute",		/* RFC 1393 */
+	"datagram conversion error",	/* RFC 1475 */
+	"mobile host redirect",
+	"IPv6 where-are-you",
+	"IPv6 i-am-here",
+	"mobile registration req",
+	"mobile registration reply",
+	"domain name request",		/* RFC 1788 */
+	"domain name reply",		/* RFC 1788 */
+	"icmp SKIP",
+	"icmp photuris",		/* RFC 2521 */
+};
+
+const char *
+netstat_icmpname(int type)
+{
+    if (0 <= type && type < ICMP_MAXTYPE) {
+	    return (icmpnames[type]);
+    }
+    return (NULL);
+}
 
 const char *
 routename(in_addr_t in, int numeric)


More information about the p4-projects mailing list