PERFORCE change 166654 for review

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


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

Change 166654 by pgj at petymeg-current on 2009/07/27 20:46:59

	Libnetstatify icmp_stats() of netstat(1).

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#15 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#30 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#23 edit

Differences ...

==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#15 (text+ko) ====

@@ -81,7 +81,7 @@
 void	sctp_stats(u_long, const char *, int, int);
 #endif
 void	ip_stats(const struct stat_type *);
-void	icmp_stats(u_long, const char *, int, int);
+void	icmp_stats(const struct stat_type *);
 void	igmp_stats(u_long, const char *, int, int);
 void	pim_stats(u_long, const char *, int, int);
 void	carp_stats(const struct stat_type *);

==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#30 (text+ko) ====

@@ -489,130 +489,66 @@
 #undef p1a
 }
 
-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 */
-};
-
 /*
  * Dump ICMP statistics.
  */
 void
-icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+icmp_stats(const struct stat_type *sttp)
 {
-	struct icmpstat icmpstat, zerostat;
+	const struct icmp_stat *s;
 	int i, first;
-	size_t len;
 
-	len = sizeof icmpstat;
-	if (live) {
-		if (zflag)
-			memset(&zerostat, 0, len);
-		if (sysctlbyname("net.inet.icmp.stats", &icmpstat, &len,
-		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
-			warn("sysctl: net.inet.icmp.stats");
-			return;
-		}
-	} else
-		kread(off, &icmpstat, len);
-
-	printf("%s:\n", name);
-
-#define	p(f, m) if (icmpstat.f || sflag <= 1) \
-    printf(m, icmpstat.f, plural(icmpstat.f))
-#define	p1a(f, m) if (icmpstat.f || sflag <= 1) \
-    printf(m, icmpstat.f)
-#define	p2(f, m) if (icmpstat.f || sflag <= 1) \
-    printf(m, icmpstat.f, plurales(icmpstat.f))
-
-	p(icps_error, "\t%lu call%s to icmp_error\n");
-	p(icps_oldicmp,
-	    "\t%lu error%s not generated in response to an icmp message\n");
+	s = netstat_get_icmpstats(sttp);
+#define	p(f, m) if (netstat_icmps_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_icmps_get_##f(s), plural(netstat_icmps_get_##f(s)))
+#define	p1a(f, m) if (netstat_icmps_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_icmps_get_##f(s))
+#define	p2(f, m) if (netstat_icmps_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_icmps_get_##f(s), plurales(netstat_icmps_get_##f(s)))
+	p(error, "\t%ju call%s to icmp_error\n");
+	p(oldicmp,
+	    "\t%ju error%s not generated in response to an icmp message\n");
 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
-		if (icmpstat.icps_outhist[i] != 0) {
+		if (netstat_icmps_get_outhist(s, i) != 0) {
 			if (first) {
 				printf("\tOutput histogram:\n");
 				first = 0;
 			}
-			if (icmpnames[i] != NULL)
-				printf("\t\t%s: %lu\n", icmpnames[i],
-					icmpstat.icps_outhist[i]);
+			if (netstat_icmpname(i) != NULL)
+				printf("\t\t%s: %ju\n", netstat_icmpname(i),
+					netstat_icmps_get_outhist(s, i));
 			else
-				printf("\t\tunknown ICMP #%d: %lu\n", i,
-					icmpstat.icps_outhist[i]);
+				printf("\t\tunknown ICMP #%d: %ju\n", i,
+					netstat_icmps_get_outhist(s, i));
 		}
-	p(icps_badcode, "\t%lu message%s with bad code fields\n");
-	p(icps_tooshort, "\t%lu message%s less than the minimum length\n");
-	p(icps_checksum, "\t%lu message%s with bad checksum\n");
-	p(icps_badlen, "\t%lu message%s with bad length\n");
-	p1a(icps_bmcastecho, "\t%lu multicast echo requests ignored\n");
-	p1a(icps_bmcasttstamp, "\t%lu multicast timestamp requests ignored\n");
+	p(badcode, "\t%ju message%s with bad code fields\n");
+	p(tooshort, "\t%ju message%s less than the minimum length\n");
+	p(checksum, "\t%ju message%s with bad checksum\n");
+	p(badlen, "\t%ju message%s with bad length\n");
+	p1a(bmcastecho, "\t%ju multicast echo requests ignored\n");
+	p1a(bmcasttstamp, "\t%ju multicast timestamp requests ignored\n");
 	for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++)
-		if (icmpstat.icps_inhist[i] != 0) {
+		if (netstat_icmps_get_inhist(s, i) != 0) {
 			if (first) {
 				printf("\tInput histogram:\n");
 				first = 0;
 			}
-			if (icmpnames[i] != NULL)
-				printf("\t\t%s: %lu\n", icmpnames[i],
-				    icmpstat.icps_inhist[i]);
+			if (netstat_icmpname(i) != NULL)
+				printf("\t\t%s: %ju\n", netstat_icmpname(i),
+				    netstat_icmps_get_inhist(s, i));
 			else
-				printf("\t\tunknown ICMP #%d: %lu\n", i,
-				    icmpstat.icps_inhist[i]);
+				printf("\t\tunknown ICMP #%d: %ju\n", i,
+				    netstat_icmps_get_inhist(s, i));
 		}
-	p(icps_reflect, "\t%lu message response%s generated\n");
-	p2(icps_badaddr, "\t%lu invalid return address%s\n");
-	p(icps_noroute, "\t%lu no return route%s\n");
+	p(reflect, "\t%ju message response%s generated\n");
+	p2(badaddr, "\t%ju invalid return address%s\n");
+	p(noroute, "\t%ju no return route%s\n");
 #undef p
 #undef p1a
 #undef p2
-	if (live) {
-		len = sizeof i;
-		if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) <
-		    0)
-			return;
+	if (live)
 		printf("\tICMP address mask responses are %sabled\n",
-		    i ? "en" : "dis");
-	}
+		    netstat_icmp_get_maskrepl(NULL) ? "en" : "dis");
 }
 
 #ifndef BURN_BRIDGES

==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#23 (text+ko) ====

@@ -127,17 +127,15 @@
 	{ .n_name = "_espstat" },
 #define	N_IPCOMPSTAT	24
 	{ .n_name = "_ipcompstat" },
-#define	N_ICMPSTAT	25
-	{ .n_name = "_icmpstat" },
-#define	N_IGMPSTAT	26
+#define	N_IGMPSTAT	25
 	{ .n_name = "_igmpstat" },
-#define	N_PIMSTAT	27
+#define	N_PIMSTAT	26
 	{ .n_name = "_pimstat" },
-#define	N_RIP6STAT	28
+#define	N_RIP6STAT	27
 	{ .n_name = "_rip6stat" },
-#define	N_SCTPSTAT	29
+#define	N_SCTPSTAT	28
 	{ .n_name = "_sctpstat" },
-#define	N_MFCTABLESIZE	30
+#define	N_MFCTABLESIZE	29
 	{ .n_name = "_mfctablesize" },
 	{ .n_name = NULL },
 };
@@ -169,8 +167,8 @@
 	  NULL,		NULL,		"divert", 1,	IPPROTO_DIVERT },
 	{ 0,		0,		1,	NULL,	ip_stats, stat_IP,
 	  NULL,		NULL,		"ip",	1,	IPPROTO_RAW },
-	{ 0,		N_ICMPSTAT,	1,	NULL,	NULL, stat_MAX,
-	  icmp_stats,	NULL,		"icmp",	1,	IPPROTO_ICMP },
+	{ 0,		0,		1,	NULL,	icmp_stats, stat_ICMP,
+	  NULL,	    	NULL,		"icmp",	1,	IPPROTO_ICMP },
 	{ 0,		N_IGMPSTAT,	1,	NULL,	NULL, stat_MAX,
 	  igmp_stats,	NULL,		"igmp",	1,	IPPROTO_IGMP },
 #ifdef IPSEC


More information about the p4-projects mailing list