PERFORCE change 166643 for review

Gabor Pali pgj at FreeBSD.org
Mon Jul 27 18:35:01 UTC 2009


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

Change 166643 by pgj at petymeg-current on 2009/07/27 18:34:20

	Modify netstat(1) to display IP statistics by libnetstat(3).

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#14 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#29 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#22 edit

Differences ...

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

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

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

@@ -443,62 +443,48 @@
  * Dump IP statistics structure.
  */
 void
-ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+ip_stats(const struct stat_type *sttp)
 {
-	struct ipstat ipstat, zerostat;
-	size_t len = sizeof ipstat;
+	const struct ip_stat *s;
 
-	if (live) {
-		if (zflag)
-			memset(&zerostat, 0, len);
-		if (sysctlbyname("net.inet.ip.stats", &ipstat, &len,
-		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
-			warn("sysctl: net.inet.ip.stats");
-			return;
-		}
-	} else
-		kread(off, &ipstat, len);
-
-	printf("%s:\n", name);
-
-#define	p(f, m) if (ipstat.f || sflag <= 1) \
-    printf(m, ipstat.f, plural(ipstat.f))
-#define	p1a(f, m) if (ipstat.f || sflag <= 1) \
-    printf(m, ipstat.f)
-
-	p(ips_total, "\t%lu total packet%s received\n");
-	p(ips_badsum, "\t%lu bad header checksum%s\n");
-	p1a(ips_toosmall, "\t%lu with size smaller than minimum\n");
-	p1a(ips_tooshort, "\t%lu with data size < data length\n");
-	p1a(ips_toolong, "\t%lu with ip length > max ip packet size\n");
-	p1a(ips_badhlen, "\t%lu with header length < data size\n");
-	p1a(ips_badlen, "\t%lu with data length < header length\n");
-	p1a(ips_badoptions, "\t%lu with bad options\n");
-	p1a(ips_badvers, "\t%lu with incorrect version number\n");
-	p(ips_fragments, "\t%lu fragment%s received\n");
-	p(ips_fragdropped, "\t%lu fragment%s dropped (dup or out of space)\n");
-	p(ips_fragtimeout, "\t%lu fragment%s dropped after timeout\n");
-	p(ips_reassembled, "\t%lu packet%s reassembled ok\n");
-	p(ips_delivered, "\t%lu packet%s for this host\n");
-	p(ips_noproto, "\t%lu packet%s for unknown/unsupported protocol\n");
-	p(ips_forward, "\t%lu packet%s forwarded");
-	p(ips_fastforward, " (%lu packet%s fast forwarded)");
-	if (ipstat.ips_forward || sflag <= 1)
+	s = netstat_get_ipstats(sttp);
+#define	p(f, m) if (netstat_ips_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_ips_get_##f(s), plural(netstat_ips_get_##f(s)))
+#define	p1a(f, m) if (netstat_ips_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_ips_get_##f(s))
+	p(total, "\t%ju total packet%s received\n");
+	p(badsum, "\t%ju bad header checksum%s\n");
+	p1a(toosmall, "\t%ju with size smaller than minimum\n");
+	p1a(tooshort, "\t%ju with data size < data length\n");
+	p1a(toolong, "\t%ju with ip length > max ip packet size\n");
+	p1a(badhlen, "\t%ju with header length < data size\n");
+	p1a(badlen, "\t%ju with data length < header 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(reassembled, "\t%ju packet%s reassembled ok\n");
+	p(delivered, "\t%ju packet%s for this host\n");
+	p(noproto, "\t%ju packet%s for unknown/unsupported protocol\n");
+	p(forward, "\t%ju packet%s forwarded");
+	p(fastforward, " (%ju packet%s fast forwarded)");
+	if (netstat_ips_get_forward(s) || sflag <= 1)
 		putchar('\n');
-	p(ips_cantforward, "\t%lu packet%s not forwardable\n");
-	p(ips_notmember,
-	    "\t%lu packet%s received for unknown multicast group\n");
-	p(ips_redirectsent, "\t%lu redirect%s sent\n");
-	p(ips_localout, "\t%lu packet%s sent from this host\n");
-	p(ips_rawout, "\t%lu packet%s sent with fabricated ip header\n");
-	p(ips_odropped,
-	    "\t%lu output packet%s dropped due to no bufs, etc.\n");
-	p(ips_noroute, "\t%lu output packet%s discarded due to no route\n");
-	p(ips_fragmented, "\t%lu output datagram%s fragmented\n");
-	p(ips_ofragments, "\t%lu fragment%s created\n");
-	p(ips_cantfrag, "\t%lu datagram%s that can't be fragmented\n");
-	p(ips_nogif, "\t%lu tunneling packet%s that can't find gif\n");
-	p(ips_badaddr, "\t%lu datagram%s with bad address in header\n");
+	p(cantforward, "\t%ju packet%s not forwardable\n");
+	p(notmember,
+	    "\t%ju packet%s received for unknown multicast group\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(nogif, "\t%ju tunneling packet%s that can't find gif\n");
+	p(badaddr, "\t%ju datagram%s with bad address in header\n");
 #undef p
 #undef p1a
 }

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

@@ -127,19 +127,17 @@
 	{ .n_name = "_espstat" },
 #define	N_IPCOMPSTAT	24
 	{ .n_name = "_ipcompstat" },
-#define	N_IPSTAT	25
-	{ .n_name = "_ipstat" },
-#define	N_ICMPSTAT	26
+#define	N_ICMPSTAT	25
 	{ .n_name = "_icmpstat" },
-#define	N_IGMPSTAT	27
+#define	N_IGMPSTAT	26
 	{ .n_name = "_igmpstat" },
-#define	N_PIMSTAT	28
+#define	N_PIMSTAT	27
 	{ .n_name = "_pimstat" },
-#define	N_RIP6STAT	29
+#define	N_RIP6STAT	28
 	{ .n_name = "_rip6stat" },
-#define	N_SCTPSTAT	30
+#define	N_SCTPSTAT	29
 	{ .n_name = "_sctpstat" },
-#define	N_MFCTABLESIZE	31
+#define	N_MFCTABLESIZE	30
 	{ .n_name = "_mfctablesize" },
 	{ .n_name = NULL },
 };
@@ -169,8 +167,8 @@
 #endif
 	{ 0,		-1,		1,	NULL,	NULL, stat_MAX,
 	  NULL,		NULL,		"divert", 1,	IPPROTO_DIVERT },
-	{ 0,		N_IPSTAT,	1,	NULL,	NULL, stat_MAX,
-	  ip_stats,	NULL,		"ip",	1,	IPPROTO_RAW },
+	{ 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,		N_IGMPSTAT,	1,	NULL,	NULL, stat_MAX,


More information about the p4-projects mailing list