Date: Thu, 30 Jul 2009 16:31:22 GMT From: Gabor Pali <pgj@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 166801 for review Message-ID: <200907301631.n6UGVMVp080245@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=166801 Change 166801 by pgj@petymeg-current on 2009/07/30 16:31:15 Make netstat(1) to use libnetstat(3) for displaying statistics on ICMP6. Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#20 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet6.c#3 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#28 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#20 (text+ko) ==== @@ -96,7 +96,7 @@ #ifdef INET6 void ip6_stats(u_long, const char *, int, int); void ip6_ifstats(char *); -void icmp6_stats(u_long, const char *, int, int); +void icmp6_stats(const struct stat_type *); void icmp6_ifstats(char *); void pim6_stats(u_long, const char *, int, int); void rip6_stats(u_long, const char *, int, int); ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet6.c#3 (text+ko) ==== @@ -72,6 +72,7 @@ #include <errno.h> #include <string.h> #include <unistd.h> +#include <netstat.h> #include "extern.h" struct socket sockb; @@ -579,349 +580,72 @@ #undef p_5 } -static const char *icmp6names[] = { - "#0", - "unreach", - "packet too big", - "time exceed", - "parameter problem", - "#5", - "#6", - "#7", - "#8", - "#9", - "#10", - "#11", - "#12", - "#13", - "#14", - "#15", - "#16", - "#17", - "#18", - "#19", - "#20", - "#21", - "#22", - "#23", - "#24", - "#25", - "#26", - "#27", - "#28", - "#29", - "#30", - "#31", - "#32", - "#33", - "#34", - "#35", - "#36", - "#37", - "#38", - "#39", - "#40", - "#41", - "#42", - "#43", - "#44", - "#45", - "#46", - "#47", - "#48", - "#49", - "#50", - "#51", - "#52", - "#53", - "#54", - "#55", - "#56", - "#57", - "#58", - "#59", - "#60", - "#61", - "#62", - "#63", - "#64", - "#65", - "#66", - "#67", - "#68", - "#69", - "#70", - "#71", - "#72", - "#73", - "#74", - "#75", - "#76", - "#77", - "#78", - "#79", - "#80", - "#81", - "#82", - "#83", - "#84", - "#85", - "#86", - "#87", - "#88", - "#89", - "#80", - "#91", - "#92", - "#93", - "#94", - "#95", - "#96", - "#97", - "#98", - "#99", - "#100", - "#101", - "#102", - "#103", - "#104", - "#105", - "#106", - "#107", - "#108", - "#109", - "#110", - "#111", - "#112", - "#113", - "#114", - "#115", - "#116", - "#117", - "#118", - "#119", - "#120", - "#121", - "#122", - "#123", - "#124", - "#125", - "#126", - "#127", - "echo", - "echo reply", - "multicast listener query", - "MLDv1 listener report", - "MLDv1 listener done", - "router solicitation", - "router advertisement", - "neighbor solicitation", - "neighbor advertisement", - "redirect", - "router renumbering", - "node information request", - "node information reply", - "inverse neighbor solicitation", - "inverse neighbor advertisement", - "MLDv2 listener report", - "#144", - "#145", - "#146", - "#147", - "#148", - "#149", - "#150", - "#151", - "#152", - "#153", - "#154", - "#155", - "#156", - "#157", - "#158", - "#159", - "#160", - "#161", - "#162", - "#163", - "#164", - "#165", - "#166", - "#167", - "#168", - "#169", - "#170", - "#171", - "#172", - "#173", - "#174", - "#175", - "#176", - "#177", - "#178", - "#179", - "#180", - "#181", - "#182", - "#183", - "#184", - "#185", - "#186", - "#187", - "#188", - "#189", - "#180", - "#191", - "#192", - "#193", - "#194", - "#195", - "#196", - "#197", - "#198", - "#199", - "#200", - "#201", - "#202", - "#203", - "#204", - "#205", - "#206", - "#207", - "#208", - "#209", - "#210", - "#211", - "#212", - "#213", - "#214", - "#215", - "#216", - "#217", - "#218", - "#219", - "#220", - "#221", - "#222", - "#223", - "#224", - "#225", - "#226", - "#227", - "#228", - "#229", - "#230", - "#231", - "#232", - "#233", - "#234", - "#235", - "#236", - "#237", - "#238", - "#239", - "#240", - "#241", - "#242", - "#243", - "#244", - "#245", - "#246", - "#247", - "#248", - "#249", - "#250", - "#251", - "#252", - "#253", - "#254", - "#255", -}; /* * Dump ICMP6 statistics. */ void -icmp6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) +icmp6_stats(const struct stat_type *sttp) { - struct icmp6stat icmp6stat; + const struct icmp6_stat *s; int i, first; - size_t len; - len = sizeof icmp6stat; - if (live) { - memset(&icmp6stat, 0, len); - if (sysctlbyname("net.inet6.icmp6.stats", &icmp6stat, &len, - NULL, 0) < 0) { - if (errno != ENOENT) - warn("sysctl: net.inet6.icmp6.stats"); - return; - } - } else - kread(off, &icmp6stat, len); - - printf("%s:\n", name); - -#define p(f, m) if (icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)icmp6stat.f, plural(icmp6stat.f)) -#define p_5(f, m) if (icmp6stat.f || sflag <= 1) \ - printf(m, (uintmax_t)icmp6stat.f) - - p(icp6s_error, "\t%ju call%s to icmp6_error\n"); - p(icp6s_canterror, + s = netstat_get_icmp6stats(sttp); +#define p(f, m) if (netstat_icmp6s_get_##f(s) || sflag <= 1) \ + printf(m, netstat_icmp6s_get_##f(s), plural(netstat_icmp6s_get_##f(s))) +#define p_5(f, m) if (netstat_icmp6s_get_##f(s) || sflag <= 1) \ + printf(m, netstat_icmp6s_get_##f(s)) + p(error, "\t%ju call%s to icmp6_error\n"); + p(canterror, "\t%ju error%s not generated in response to an icmp6 message\n"); - p(icp6s_toofreq, + p(toofreq, "\t%ju error%s not generated because of rate limitation\n"); -#define NELEM (int)(sizeof(icmp6stat.icp6s_outhist)/sizeof(icmp6stat.icp6s_outhist[0])) - for (first = 1, i = 0; i < NELEM; i++) - if (icmp6stat.icp6s_outhist[i] != 0) { + for (first = 1, i = 0; i < 256; i++) + if (netstat_icmp6s_get_outhist(s, i) != 0) { if (first) { printf("\tOutput histogram:\n"); first = 0; } - printf("\t\t%s: %ju\n", icmp6names[i], - (uintmax_t)icmp6stat.icp6s_outhist[i]); + printf("\t\t%s: %ju\n", netstat_icmp6name(i), + netstat_icmp6s_get_outhist(s, i)); } -#undef NELEM - p(icp6s_badcode, "\t%ju message%s with bad code fields\n"); - p(icp6s_tooshort, "\t%ju message%s < minimum length\n"); - p(icp6s_checksum, "\t%ju bad checksum%s\n"); - p(icp6s_badlen, "\t%ju message%s with bad length\n"); -#define NELEM (int)(sizeof(icmp6stat.icp6s_inhist)/sizeof(icmp6stat.icp6s_inhist[0])) - for (first = 1, i = 0; i < NELEM; i++) - if (icmp6stat.icp6s_inhist[i] != 0) { + p(badcode, "\t%ju message%s with bad code fields\n"); + p(tooshort, "\t%ju message%s < minimum length\n"); + p(checksum, "\t%ju bad checksum%s\n"); + p(badlen, "\t%ju message%s with bad length\n"); + for (first = 1, i = 0; i < 256; i++) + if (netstat_icmp6s_get_inhist(s, i) != 0) { if (first) { printf("\tInput histogram:\n"); first = 0; } - printf("\t\t%s: %ju\n", icmp6names[i], - (uintmax_t)icmp6stat.icp6s_inhist[i]); + printf("\t\t%s: %ju\n", netstat_icmp6name(i), + netstat_icmp6s_get_inhist(s, i)); } -#undef NELEM printf("\tHistogram of error messages to be generated:\n"); - p_5(icp6s_odst_unreach_noroute, "\t\t%ju no route\n"); - p_5(icp6s_odst_unreach_admin, "\t\t%ju administratively prohibited\n"); - p_5(icp6s_odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); - p_5(icp6s_odst_unreach_addr, "\t\t%ju address unreachable\n"); - p_5(icp6s_odst_unreach_noport, "\t\t%ju port unreachable\n"); - p_5(icp6s_opacket_too_big, "\t\t%ju packet too big\n"); - p_5(icp6s_otime_exceed_transit, "\t\t%ju time exceed transit\n"); - p_5(icp6s_otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); - p_5(icp6s_oparamprob_header, "\t\t%ju erroneous header field\n"); - p_5(icp6s_oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); - p_5(icp6s_oparamprob_option, "\t\t%ju unrecognized option\n"); - p_5(icp6s_oredirect, "\t\t%ju redirect\n"); - p_5(icp6s_ounknown, "\t\t%ju unknown\n"); + p_5(odst_unreach_noroute, "\t\t%ju no route\n"); + p_5(odst_unreach_admin, "\t\t%ju administratively prohibited\n"); + p_5(odst_unreach_beyondscope, "\t\t%ju beyond scope\n"); + p_5(odst_unreach_addr, "\t\t%ju address unreachable\n"); + p_5(odst_unreach_noport, "\t\t%ju port unreachable\n"); + p_5(opacket_too_big, "\t\t%ju packet too big\n"); + p_5(otime_exceed_transit, "\t\t%ju time exceed transit\n"); + p_5(otime_exceed_reassembly, "\t\t%ju time exceed reassembly\n"); + p_5(oparamprob_header, "\t\t%ju erroneous header field\n"); + p_5(oparamprob_nextheader, "\t\t%ju unrecognized next header\n"); + p_5(oparamprob_option, "\t\t%ju unrecognized option\n"); + p_5(oredirect, "\t\t%ju redirect\n"); + p_5(ounknown, "\t\t%ju unknown\n"); - p(icp6s_reflect, "\t%ju message response%s generated\n"); - p(icp6s_nd_toomanyopt, "\t%ju message%s with too many ND options\n"); - p(icp6s_nd_badopt, "\t%ju message%s with bad ND options\n"); - p(icp6s_badns, "\t%ju bad neighbor solicitation message%s\n"); - p(icp6s_badna, "\t%ju bad neighbor advertisement message%s\n"); - p(icp6s_badrs, "\t%ju bad router solicitation message%s\n"); - p(icp6s_badra, "\t%ju bad router advertisement message%s\n"); - p(icp6s_badredirect, "\t%ju bad redirect message%s\n"); - p(icp6s_pmtuchg, "\t%ju path MTU change%s\n"); + p(reflect, "\t%ju message response%s generated\n"); + p(nd_toomanyopt, "\t%ju message%s with too many ND options\n"); + p(nd_badopt, "\t%ju message%s with bad ND options\n"); + p(badns, "\t%ju bad neighbor solicitation message%s\n"); + p(badna, "\t%ju bad neighbor advertisement message%s\n"); + p(badrs, "\t%ju bad router solicitation message%s\n"); + p(badra, "\t%ju bad router advertisement message%s\n"); + p(badredirect, "\t%ju bad redirect message%s\n"); + p(pmtuchg, "\t%ju path MTU change%s\n"); #undef p #undef p_5 } ==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#28 (text+ko) ==== @@ -99,35 +99,33 @@ { .n_name = "_ngsocklist"}, #define N_IP6STAT 10 { .n_name = "_ip6stat" }, -#define N_ICMP6STAT 11 - { .n_name = "_icmp6stat" }, -#define N_IPSECSTAT 12 +#define N_IPSECSTAT 11 { .n_name = "_ipsec4stat" }, -#define N_IPSEC6STAT 13 +#define N_IPSEC6STAT 12 { .n_name = "_ipsec6stat" }, -#define N_PIM6STAT 14 +#define N_PIM6STAT 13 { .n_name = "_pim6stat" }, -#define N_MRT6STAT 15 +#define N_MRT6STAT 14 { .n_name = "_mrt6stat" }, -#define N_MF6CTABLE 16 +#define N_MF6CTABLE 15 { .n_name = "_mf6ctable" }, -#define N_MIF6TABLE 17 +#define N_MIF6TABLE 16 { .n_name = "_mif6table" }, -#define N_PFKEYSTAT 18 +#define N_PFKEYSTAT 17 { .n_name = "_pfkeystat" }, -#define N_RTTRASH 19 +#define N_RTTRASH 18 { .n_name = "_rttrash" }, -#define N_PFSYNCSTAT 20 +#define N_PFSYNCSTAT 19 { .n_name = "_pfsyncstats" }, -#define N_AHSTAT 21 +#define N_AHSTAT 20 { .n_name = "_ahstat" }, -#define N_ESPSTAT 22 +#define N_ESPSTAT 21 { .n_name = "_espstat" }, -#define N_IPCOMPSTAT 23 +#define N_IPCOMPSTAT 22 { .n_name = "_ipcompstat" }, -#define N_RIP6STAT 24 +#define N_RIP6STAT 23 { .n_name = "_rip6stat" }, -#define N_MFCTABLESIZE 25 +#define N_MFCTABLESIZE 24 { .n_name = "_mfctablesize" }, { .n_name = NULL }, }; @@ -191,8 +189,8 @@ NULL, NULL, "udp", 1, IPPROTO_UDP }, { 0, N_IP6STAT, 1, NULL, NULL, stat_MAX, ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW }, - { 0, N_ICMP6STAT, 1, NULL, NULL, stat_MAX, - icmp6_stats, icmp6_ifstats, "icmp6", 1, IPPROTO_ICMPV6 }, + { 0, 0, 1, NULL, icmp6_stats, stat_ICMP6, + NULL, icmp6_ifstats, "icmp6", 1, IPPROTO_ICMPV6 }, #ifdef IPSEC { -1, N_IPSEC6STAT, 1, NULL, NULL, stat_MAX, ipsec_stats, NULL, "ipsec6", 0, 0 },
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907301631.n6UGVMVp080245>