PERFORCE change 166870 for review
Gabor Pali
pgj at FreeBSD.org
Fri Jul 31 20:25:59 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166870
Change 166870 by pgj at petymeg-current on 2009/07/31 20:25:49
Modify netstat(1) to call libnetstat(3) for displaying statistics
on IP6 traffic.
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#31 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet6.c#6 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#39 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#31 (text+ko) ====
@@ -95,7 +95,7 @@
#endif
#ifdef INET6
-void ip6_stats(u_long, const char *, int, int);
+void ip6_stats(const struct stat_type *);
void ip6_ifstats(char *);
void icmp6_stats(const struct stat_type *);
void icmp6_ifstats(char *);
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet6.c#6 (text+ko) ====
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/usr.bin/netstat/inet6.c,v 1.35 2009/04/29 09:52:04 bms Exp $");
-#ifdef INET6
+#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -81,446 +81,153 @@
static char ntop_buf[INET6_ADDRSTRLEN];
-static const char *ip6nh[] = {
- "hop by hop",
- "ICMP",
- "IGMP",
- "#3",
- "IP",
- "#5",
- "TCP",
- "#7",
- "#8",
- "#9",
- "#10",
- "#11",
- "#12",
- "#13",
- "#14",
- "#15",
- "#16",
- "UDP",
- "#18",
- "#19",
- "#20",
- "#21",
- "IDP",
- "#23",
- "#24",
- "#25",
- "#26",
- "#27",
- "#28",
- "TP",
- "#30",
- "#31",
- "#32",
- "#33",
- "#34",
- "#35",
- "#36",
- "#37",
- "#38",
- "#39",
- "#40",
- "IP6",
- "#42",
- "routing",
- "fragment",
- "#45",
- "#46",
- "#47",
- "#48",
- "#49",
- "ESP",
- "AH",
- "#52",
- "#53",
- "#54",
- "#55",
- "#56",
- "#57",
- "ICMP6",
- "no next header",
- "destination option",
- "#61",
- "mobility",
- "#63",
- "#64",
- "#65",
- "#66",
- "#67",
- "#68",
- "#69",
- "#70",
- "#71",
- "#72",
- "#73",
- "#74",
- "#75",
- "#76",
- "#77",
- "#78",
- "#79",
- "ISOIP",
- "#81",
- "#82",
- "#83",
- "#84",
- "#85",
- "#86",
- "#87",
- "#88",
- "OSPF",
- "#80",
- "#91",
- "#92",
- "#93",
- "#94",
- "#95",
- "#96",
- "Ethernet",
- "#98",
- "#99",
- "#100",
- "#101",
- "#102",
- "PIM",
- "#104",
- "#105",
- "#106",
- "#107",
- "#108",
- "#109",
- "#110",
- "#111",
- "#112",
- "#113",
- "#114",
- "#115",
- "#116",
- "#117",
- "#118",
- "#119",
- "#120",
- "#121",
- "#122",
- "#123",
- "#124",
- "#125",
- "#126",
- "#127",
- "#128",
- "#129",
- "#130",
- "#131",
- "#132",
- "#133",
- "#134",
- "#135",
- "#136",
- "#137",
- "#138",
- "#139",
- "#140",
- "#141",
- "#142",
- "#143",
- "#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",
-};
-
-static char *srcrule_str[] = {
- "first candidate",
- "same address",
- "appropriate scope",
- "deprecated address",
- "home address",
- "outgoing interface",
- "matching label",
- "public/temporary address",
- "alive interface",
- "preferred interface",
- "rule #10",
- "rule #11",
- "rule #12",
- "rule #13",
- "longest match",
- "rule #15",
-};
-
/*
* Dump IP6 statistics structure.
*/
void
-ip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+ip6_stats(const struct stat_type *sttp)
{
- struct ip6stat ip6stat;
+ const struct ip6_stat *s;
int first, i;
- size_t len;
- len = sizeof ip6stat;
- if (live) {
- memset(&ip6stat, 0, len);
- if (sysctlbyname("net.inet6.ip6.stats", &ip6stat, &len, NULL,
- 0) < 0) {
- if (errno != ENOENT)
- warn("sysctl: net.inet6.ip6.stats");
- return;
- }
- } else
- kread(off, &ip6stat, len);
-
- printf("%s:\n", name);
-
-#define p(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ip6stat.f, plural(ip6stat.f))
-#define p1a(f, m) if (ip6stat.f || sflag <= 1) \
- printf(m, (uintmax_t)ip6stat.f)
-
- p(ip6s_total, "\t%ju total packet%s received\n");
- p1a(ip6s_toosmall, "\t%ju with size smaller than minimum\n");
- p1a(ip6s_tooshort, "\t%ju with data size < data length\n");
- p1a(ip6s_badoptions, "\t%ju with bad options\n");
- p1a(ip6s_badvers, "\t%ju with incorrect version number\n");
- p(ip6s_fragments, "\t%ju fragment%s received\n");
- p(ip6s_fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
- p(ip6s_fragtimeout, "\t%ju fragment%s dropped after timeout\n");
- p(ip6s_fragoverflow, "\t%ju fragment%s that exceeded limit\n");
- p(ip6s_reassembled, "\t%ju packet%s reassembled ok\n");
- p(ip6s_delivered, "\t%ju packet%s for this host\n");
- p(ip6s_forward, "\t%ju packet%s forwarded\n");
- p(ip6s_cantforward, "\t%ju packet%s not forwardable\n");
- p(ip6s_redirectsent, "\t%ju redirect%s sent\n");
- p(ip6s_localout, "\t%ju packet%s sent from this host\n");
- p(ip6s_rawout, "\t%ju packet%s sent with fabricated ip header\n");
- p(ip6s_odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n");
- p(ip6s_noroute, "\t%ju output packet%s discarded due to no route\n");
- p(ip6s_fragmented, "\t%ju output datagram%s fragmented\n");
- p(ip6s_ofragments, "\t%ju fragment%s created\n");
- p(ip6s_cantfrag, "\t%ju datagram%s that can't be fragmented\n");
- p(ip6s_badscope, "\t%ju packet%s that violated scope rules\n");
- p(ip6s_notmember, "\t%ju multicast packet%s which we don't join\n");
- for (first = 1, i = 0; i < 256; i++)
- if (ip6stat.ip6s_nxthist[i] != 0) {
+ s = netstat_get_ip6stats(sttp);
+#define p(f, m) if (netstat_ip6s_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_ip6s_get_##f(s), plural(netstat_ip6s_get_##f(s)))
+#define pa(f,i,m) if (netstat_ip6s_get_##f(s,i) || sflag <= 1) \
+ printf(m, netstat_ip6s_get_##f(s,i), plural(netstat_ip6s_get_##f(s,i)))
+#define p1a(f, m) if (netstat_ip6s_get_##f(s) || sflag <= 1) \
+ printf(m, netstat_ip6s_get_##f(s))
+ p(total, "\t%ju total packet%s received\n");
+ p1a(toosmall, "\t%ju with size smaller than minimum\n");
+ p1a(tooshort, "\t%ju with data size < data length\n");
+ p1a(badoptions, "\t%ju with bad options\n");
+ p1a(badvers, "\t%ju with incorrect version number\n");
+ p(fragments, "\t%ju fragment%s received\n");
+ p(fragdropped, "\t%ju fragment%s dropped (dup or out of space)\n");
+ p(fragtimeout, "\t%ju fragment%s dropped after timeout\n");
+ p(fragoverflow, "\t%ju fragment%s that exceeded limit\n");
+ p(reassembled, "\t%ju packet%s reassembled ok\n");
+ p(delivered, "\t%ju packet%s for this host\n");
+ p(forward, "\t%ju packet%s forwarded\n");
+ p(cantforward, "\t%ju packet%s not forwardable\n");
+ p(redirectsent, "\t%ju redirect%s sent\n");
+ p(localout, "\t%ju packet%s sent from this host\n");
+ p(rawout, "\t%ju packet%s sent with fabricated ip header\n");
+ p(odropped, "\t%ju output packet%s dropped due to no bufs, etc.\n");
+ p(noroute, "\t%ju output packet%s discarded due to no route\n");
+ p(fragmented, "\t%ju output datagram%s fragmented\n");
+ p(ofragments, "\t%ju fragment%s created\n");
+ p(cantfrag, "\t%ju datagram%s that can't be fragmented\n");
+ p(badscope, "\t%ju packet%s that violated scope rules\n");
+ p(notmember, "\t%ju multicast packet%s which we don't join\n");
+ for (first = 1, i = 0; i < NETSTAT_IP6_NHIST_MAX; i++)
+ if (netstat_ip6s_get_nxthist(s, i) != 0) {
if (first) {
printf("\tInput histogram:\n");
first = 0;
}
- printf("\t\t%s: %ju\n", ip6nh[i],
- (uintmax_t)ip6stat.ip6s_nxthist[i]);
+ printf("\t\t%s: %ju\n", netstat_ip6_nhist_name(i),
+ netstat_ip6s_get_nxthist(s, i));
}
printf("\tMbuf statistics:\n");
- printf("\t\t%ju one mbuf\n", (uintmax_t)ip6stat.ip6s_m1);
- for (first = 1, i = 0; i < 32; i++) {
+ printf("\t\t%ju one mbuf\n", netstat_ip6s_get_m1(s));
+ for (first = 1, i = 0; i < NETSTAT_IP6_MBUF_MAX; i++) {
char ifbuf[IFNAMSIZ];
- if (ip6stat.ip6s_m2m[i] != 0) {
+ if (netstat_ip6s_get_m2m(s, i) != 0) {
if (first) {
printf("\t\ttwo or more mbuf:\n");
first = 0;
}
printf("\t\t\t%s= %ju\n",
if_indextoname(i, ifbuf),
- (uintmax_t)ip6stat.ip6s_m2m[i]);
+ netstat_ip6s_get_m2m(s, i));
}
}
- printf("\t\t%ju one ext mbuf\n",
- (uintmax_t)ip6stat.ip6s_mext1);
- printf("\t\t%ju two or more ext mbuf\n",
- (uintmax_t)ip6stat.ip6s_mext2m);
- p(ip6s_exthdrtoolong,
+ printf("\t\t%ju one ext mbuf\n", netstat_ip6s_get_mext1(s));
+ printf("\t\t%ju two or more ext mbuf\n", netstat_ip6s_get_mext2m(s));
+ p(exthdrtoolong,
"\t%ju packet%s whose headers are not continuous\n");
- p(ip6s_nogif, "\t%ju tunneling packet%s that can't find gif\n");
- p(ip6s_toomanyhdr,
+ p(nogif, "\t%ju tunneling packet%s that can't find gif\n");
+ p(toomanyhdr,
"\t%ju packet%s discarded because of too many headers\n");
/* for debugging source address selection */
-#define PRINT_SCOPESTAT(s,i) do {\
+#define PRINT_SCOPESTAT(f,i) do {\
switch(i) { /* XXX hardcoding in each case */\
case 1:\
- p(s, "\t\t%ju node-local%s\n");\
+ pa(f, i, "\t\t%ju node-local%s\n");\
break;\
case 2:\
- p(s,"\t\t%ju link-local%s\n");\
+ pa(f, i, "\t\t%ju link-local%s\n");\
break;\
case 5:\
- p(s,"\t\t%ju site-local%s\n");\
+ pa(f, i, "\t\t%ju site-local%s\n");\
break;\
case 14:\
- p(s,"\t\t%ju global%s\n");\
+ pa(f, i, "\t\t%ju global%s\n");\
break;\
default:\
printf("\t\t%ju addresses scope=%x\n",\
- (uintmax_t)ip6stat.s, i);\
+ netstat_ip6s_get_##f(s,i), i);\
}\
} while (0);
- p(ip6s_sources_none,
- "\t%ju failure%s of source address selection\n");
- for (first = 1, i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_sameif[i]) {
+ p(sources_none, "\t%ju failure%s of source address selection\n");
+ for (first = 1, i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_sameif(s, i)) {
if (first) {
printf("\tsource addresses on an outgoing I/F\n");
first = 0;
}
- PRINT_SCOPESTAT(ip6s_sources_sameif[i], i);
+ PRINT_SCOPESTAT(sources_sameif,i);
}
}
- for (first = 1, i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_otherif[i]) {
+ for (first = 1, i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_otherif(s, i)) {
if (first) {
printf("\tsource addresses on a non-outgoing I/F\n");
first = 0;
}
- PRINT_SCOPESTAT(ip6s_sources_otherif[i], i);
+ PRINT_SCOPESTAT(sources_otherif,i);
}
}
- for (first = 1, i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_samescope[i]) {
+ for (first = 1, i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_samescope(s, i)) {
if (first) {
printf("\tsource addresses of same scope\n");
first = 0;
}
- PRINT_SCOPESTAT(ip6s_sources_samescope[i], i);
+ PRINT_SCOPESTAT(sources_samescope,i);
}
}
- for (first = 1, i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_otherscope[i]) {
+ for (first = 1, i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_otherscope(s, i)) {
if (first) {
printf("\tsource addresses of a different scope\n");
first = 0;
}
- PRINT_SCOPESTAT(ip6s_sources_otherscope[i], i);
+ PRINT_SCOPESTAT(sources_otherscope,i);
}
}
- for (first = 1, i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_deprecated[i]) {
+ for (first = 1, i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_deprecated(s, i)) {
if (first) {
printf("\tdeprecated source addresses\n");
first = 0;
}
- PRINT_SCOPESTAT(ip6s_sources_deprecated[i], i);
+ PRINT_SCOPESTAT(sources_deprecated,i);
}
}
printf("\tSource addresses selection rule applied:\n");
- for (i = 0; i < 16; i++) {
- if (ip6stat.ip6s_sources_rule[i])
+ for (i = 0; i < NETSTAT_IP6_IF_MAX; i++) {
+ if (netstat_ip6s_get_sources_rule(s, i))
printf("\t\t%ju %s\n",
- (uintmax_t)ip6stat.ip6s_sources_rule[i],
- srcrule_str[i]);
+ netstat_ip6s_get_sources_rule(s, i),
+ netstat_ip6_srcrule_name(i));
}
#undef p
+#undef pa
#undef p1a
}
@@ -840,4 +547,3 @@
sizeof(ntop_buf)));
return (line);
}
-#endif /*INET6*/
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#39 (text+ko) ====
@@ -93,17 +93,15 @@
{ .n_name = "_ddpcb"},
#define N_NGSOCKS 7
{ .n_name = "_ngsocklist"},
-#define N_IP6STAT 8
- { .n_name = "_ip6stat" },
-#define N_MRT6STAT 9
+#define N_MRT6STAT 8
{ .n_name = "_mrt6stat" },
-#define N_MF6CTABLE 10
+#define N_MF6CTABLE 9
{ .n_name = "_mf6ctable" },
-#define N_MIF6TABLE 11
+#define N_MIF6TABLE 10
{ .n_name = "_mif6table" },
-#define N_RTTRASH 12
+#define N_RTTRASH 11
{ .n_name = "_rttrash" },
-#define N_MFCTABLESIZE 13
+#define N_MFCTABLESIZE 12
{ .n_name = "_mfctablesize" },
{ .n_name = NULL },
};
@@ -165,8 +163,8 @@
NULL, NULL, "tcp", 1, IPPROTO_TCP },
{ 0, 0, 1, NULL, udp_stats, stat_UDP,
NULL, NULL, "udp", 1, IPPROTO_UDP },
- { 0, N_IP6STAT, 1, NULL, NULL, stat_MAX,
- ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW },
+ { 0, 0, 1, NULL, ip6_stats, stat_IP6,
+ NULL, ip6_ifstats, "ip6", 1, IPPROTO_RAW },
{ 0, 0, 1, NULL, icmp6_stats, stat_ICMP6,
NULL, icmp6_ifstats, "icmp6", 1, IPPROTO_ICMPV6 },
#ifdef IPSEC
More information about the p4-projects
mailing list