From owner-p4-projects@FreeBSD.ORG Mon Jul 27 20:46:26 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id ACE9A1065748; Mon, 27 Jul 2009 20:46:25 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 68F361065746 for ; Mon, 27 Jul 2009 20:46:25 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 56BFD8FC0A for ; Mon, 27 Jul 2009 20:46:25 +0000 (UTC) (envelope-from pgj@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6RKkPxf032041 for ; Mon, 27 Jul 2009 20:46:25 GMT (envelope-from pgj@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6RKkPjp032039 for perforce@freebsd.org; Mon, 27 Jul 2009 20:46:25 GMT (envelope-from pgj@FreeBSD.org) Date: Mon, 27 Jul 2009 20:46:25 GMT Message-Id: <200907272046.n6RKkPjp032039@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to pgj@FreeBSD.org using -f From: Gabor Pali To: Perforce Change Reviews Cc: Subject: PERFORCE change 166653 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Jul 2009 20:46:27 -0000 http://perforce.freebsd.org/chv.cgi?CH=166653 Change 166653 by pgj@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 #include #include +#include +#include #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 #include #include +#include +#include #include #include @@ -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)