PERFORCE change 166800 for review
Gabor Pali
pgj at FreeBSD.org
Thu Jul 30 16:30:22 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166800
Change 166800 by pgj at petymeg-current on 2009/07/30 16:29:32
- Add support for ICMP6 statistics.
- Fix buffering technique in netstat_stat().
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#43 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#40 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#10 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#48 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#43 (text+ko) ====
@@ -126,6 +126,9 @@
#ifdef SCTP
stat_SCTP,
#endif
+#ifdef INET6
+ stat_ICMP6,
+#endif
stat_MAX,
stat_Invalid,
};
@@ -164,6 +167,9 @@
#ifdef SCTP
struct sctp_stat;
#endif
+#ifdef INET6
+struct icmp6_stat;
+#endif
__BEGIN_DECLS
const char *netstat_strerror(int);
@@ -537,7 +543,9 @@
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);
+#ifdef INET6
const char *netstat_icmp6name(int);
+#endif
int netstat_icmp_get_maskrepl(void *kvm_handle);
const struct pim_stat *netstat_get_pimstats(const struct stat_type *);
@@ -723,4 +731,40 @@
u_int32_t netstat_sctps_get_send_cwnd_avoid(const struct sctp_stat *);
u_int32_t netstat_sctps_get_fwdtsn_map_over(const struct sctp_stat *);
#endif /* !SCTP */
+
+#ifdef INET6
+const struct icmp6_stat *netstat_get_icmp6stats(const struct stat_type *);
+
+u_int64_t netstat_icmp6s_get_error(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_canterror(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_toofreq(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_outhist(const struct icmp6_stat *, int);
+u_int64_t netstat_icmp6s_get_badcode(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_tooshort(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_checksum(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badlen(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_reflect(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_inhist(const struct icmp6_stat *, int);
+u_int64_t netstat_icmp6s_get_nd_toomanyopt(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_odst_unreach_noroute(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_odst_unreach_admin(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_odst_unreach_beyondscope(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_odst_unreach_addr(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_odst_unreach_noport(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_opacket_too_big(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_otime_exceed_transit(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_otime_exceed_reassembly(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_oparamprob_header(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_oparamprob_nextheader(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_oparamprob_option(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_oredirect(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_ounknown(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_pmtuchg(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_nd_badopt(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badns(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badna(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badrs(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badra(const struct icmp6_stat *);
+u_int64_t netstat_icmp6s_get_badredirect(const struct icmp6_stat *);
+#endif /* !INET6 */
#endif /* !_NETSTAT_H_ */
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#40 (text+ko) ====
@@ -54,6 +54,9 @@
#ifdef SCTP
#include <netinet/sctp_uio.h>
#endif
+#ifdef INET6
+#include <netinet/icmp6.h>
+#endif
#include "netstat.h"
@@ -329,6 +332,12 @@
};
#endif
+#ifdef INET6
+struct icmp6_stat {
+ struct icmp6stat s;
+};
+#endif
+
/* Timestamp type. */
struct timestamp_type {
u_int32_t ts_sec;
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_stat.c#10 (text+ko) ====
@@ -68,13 +68,16 @@
#ifdef SCTP
{ SCTPSTAT_VERSION, "net.inet.sctp.stats", "_sctpstat" },
#endif
+#ifdef INET6
+ { ICMP6STAT_VERSION, "net.inet6.icmp6.stats", "_icmp6stat" },
+#endif
};
int
netstat_stat(enum stat type, struct stat_type *sttp, int flags,
void *kvm_handle)
{
- char buffer[1024];
+ char *buffer;
char symbuf[64];
struct stat_header head;
@@ -100,6 +103,11 @@
sttp->stt_error = NETSTAT_ERROR_VERSION;
return (-1);
}
+ buffer = malloc(head.sth_len);
+ if (buffer == NULL) {
+ sttp->stt_error = NETSTAT_ERROR_NOMEMORY;
+ return (-1);
+ }
res = read_kvm(kvm_handle, stat_info[sttp->stt_type].kvm,
buffer, head.sth_len);
if (res != 0) {
@@ -115,19 +123,18 @@
sttp->stt_error = NETSTAT_ERROR_VERSION;
return (-1);
}
+ buffer = malloc(head.sth_len);
+ if (buffer == NULL) {
+ sttp->stt_error = NETSTAT_ERROR_NOMEMORY;
+ return (-1);
+ }
res = read_sysctl(stat_info[sttp->stt_type].mib, buffer,
head.sth_len);
if (res != 0)
return (res);
}
- sttp->stt_data = malloc(head.sth_len);
- if (sttp->stt_data == NULL) {
- sttp->stt_error = NETSTAT_ERROR_NOMEMORY;
- return (-1);
- }
-
- memcpy(sttp->stt_data, buffer, head.sth_len);
+ sttp->stt_data = buffer;
if (sttp->stt_type == stat_UDP) {
u = (struct udpstat *)sttp->stt_data;
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#48 (text+ko) ====
@@ -1684,6 +1684,49 @@
#undef SCTP_ACC
#endif /* !SCTP */
+#ifdef INET6
+#define ICMP6_ACC(field) \
+ STATS_ACCX(u_int64_t,icmp6,field,icp6s_##field)
+
+#define ICMP6_ACCA(field) \
+ STATS_ACCXA(u_int64_t,icmp6,field,icp6s_##field,256)
+
+STATS_GET(icmp6,ICMP6);
+ICMP6_ACC(error);
+ICMP6_ACC(canterror);
+ICMP6_ACC(toofreq);
+ICMP6_ACCA(outhist);
+ICMP6_ACC(badcode);
+ICMP6_ACC(tooshort);
+ICMP6_ACC(checksum);
+ICMP6_ACC(badlen);
+ICMP6_ACC(reflect);
+ICMP6_ACCA(inhist);
+ICMP6_ACC(nd_toomanyopt);
+ICMP6_ACC(odst_unreach_noroute);
+ICMP6_ACC(odst_unreach_admin);
+ICMP6_ACC(odst_unreach_beyondscope);
+ICMP6_ACC(odst_unreach_addr);
+ICMP6_ACC(odst_unreach_noport);
+ICMP6_ACC(opacket_too_big);
+ICMP6_ACC(otime_exceed_transit);
+ICMP6_ACC(otime_exceed_reassembly);
+ICMP6_ACC(oparamprob_header);
+ICMP6_ACC(oparamprob_nextheader);
+ICMP6_ACC(oparamprob_option);
+ICMP6_ACC(oredirect);
+ICMP6_ACC(ounknown);
+ICMP6_ACC(pmtuchg);
+ICMP6_ACC(nd_badopt);
+ICMP6_ACC(badns);
+ICMP6_ACC(badna);
+ICMP6_ACC(badrs);
+ICMP6_ACC(badra);
+ICMP6_ACC(badredirect);
+#undef ICMP_ACC
+#undef ICMP_ACCA
+
+#endif /* !INET6 */
static const char *icmpnames[ICMP_MAXTYPE + 1] = {
"echo reply", /* RFC 792 */
More information about the p4-projects
mailing list