PERFORCE change 166630 for review

Gabor Pali pgj at FreeBSD.org
Mon Jul 27 16:09:23 UTC 2009


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

Change 166630 by pgj at petymeg-current on 2009/07/27 16:08:46

	Modify carp_stats() to call libnetstat(3).

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#12 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#27 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#20 edit

Differences ...

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

@@ -84,7 +84,7 @@
 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);
-void	carp_stats(u_long, const char *, int, int);
+void	carp_stats(void *, const char *);
 void	pfsync_stats(u_long, const char *, int, int);
 #ifdef IPSEC
 void	ipsec_stats(u_long, const char *, int, int);

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

@@ -474,49 +474,63 @@
  * Dump CARP statistics structure.
  */
 void
-carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
+carp_stats(void *kvmd, const char *name)
 {
-	struct carpstats carpstat, zerostat;
-	size_t len = sizeof(struct carpstats);
+	const struct carp_stat *s;
+	struct stat_type *sttp;
+	int stt_flags, error;
+
+	if (zflag) {
+		netstat_zerostat(stat_CARP);
+		return;
+	}
+
+	stt_flags = 0;
+	if (!live)
+		stt_flags |= NETSTAT_STAT_KVM;
+
+	sttp = netstat_stat_alloc();
+	if (sttp == NULL) {
+		warn("netstat_stat_alloc");
+		return;
+	}
 
-	if (live) {
-		if (zflag)
-			memset(&zerostat, 0, len);
-		if (sysctlbyname("net.inet.carp.stats", &carpstat, &len,
-		    zflag ? &zerostat : NULL, zflag ? len : 0) < 0) {
-			if (errno != ENOENT)
-				warn("sysctl: net.inet.carp.stats");
-			return;
-		}
-	} else {
-		if (off == 0)
-			return;
-		kread(off, &carpstat, len);
+	if (netstat_stat(stat_CARP, sttp, stt_flags, kvmd) < 0) {
+		error = netstat_stat_geterror(sttp);
+		if (error == NETSTAT_ERROR_KVM)
+			warnx("netstat_stat: %s", kvm_geterr(kvmd));
+		else
+			warnx("netstat_stat: %s", netstat_strerror(error));
+		goto out;
 	}
 
+	s = netstat_get_carpstats(sttp);
+
 	printf("%s:\n", name);
 
-#define	p(f, m) if (carpstat.f || sflag <= 1) \
-	printf(m, (uintmax_t)carpstat.f, plural(carpstat.f))
-#define	p2(f, m) if (carpstat.f || sflag <= 1) \
-	printf(m, (uintmax_t)carpstat.f)
+#define	p(f, m) if (netstat_carps_get_##f(s) || sflag <= 1) \
+	printf(m, netstat_carps_get_##f(s), plural(netstat_carps_get_##f(s)))
+#define	p2(f, m) if (netstat_carps_get_##f(s) || sflag <= 1) \
+	printf(m, netstat_carps_get_##f(s))
 
-	p(carps_ipackets, "\t%ju packet%s received (IPv4)\n");
-	p(carps_ipackets6, "\t%ju packet%s received (IPv6)\n");
-	p(carps_badttl, "\t\t%ju packet%s discarded for wrong TTL\n");
-	p(carps_hdrops, "\t\t%ju packet%s shorter than header\n");
-	p(carps_badsum, "\t\t%ju discarded for bad checksum%s\n");
-	p(carps_badver,	"\t\t%ju discarded packet%s with a bad version\n");
-	p2(carps_badlen, "\t\t%ju discarded because packet too short\n");
-	p2(carps_badauth, "\t\t%ju discarded for bad authentication\n");
-	p2(carps_badvhid, "\t\t%ju discarded for bad vhid\n");
-	p2(carps_badaddrs, "\t\t%ju discarded because of a bad address list\n");
-	p(carps_opackets, "\t%ju packet%s sent (IPv4)\n");
-	p(carps_opackets6, "\t%ju packet%s sent (IPv6)\n");
-	p2(carps_onomem, "\t\t%ju send failed due to mbuf memory error\n");
+	p(ipackets, "\t%ju packet%s received (IPv4)\n");
+	p(ipackets6, "\t%ju packet%s received (IPv6)\n");
+	p(badttl, "\t\t%ju packet%s discarded for wrong TTL\n");
+	p(hdrops, "\t\t%ju packet%s shorter than header\n");
+	p(badsum, "\t\t%ju discarded for bad checksum%s\n");
+	p(badver, "\t\t%ju discarded packet%s with a bad version\n");
+	p2(badlen, "\t\t%ju discarded because packet too short\n");
+	p2(badauth, "\t\t%ju discarded for bad authentication\n");
+	p2(badvhid, "\t\t%ju discarded for bad vhid\n");
+	p2(badaddrs, "\t\t%ju discarded because of a bad address list\n");
+	p(opackets, "\t%ju packet%s sent (IPv4)\n");
+	p(opackets6, "\t%ju packet%s sent (IPv6)\n");
+	p2(onomem, "\t\t%ju send failed due to mbuf memory error\n");
 #if notyet
-	p(carps_ostates, "\t\t%s state update%s sent\n");
+	p(ostates, "\t\t%s state update%s sent\n");
 #endif
+out:
+	netstat_stat_free(sttp);
 #undef p
 #undef p2
 }

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

@@ -119,29 +119,27 @@
 	{ .n_name = "_pfkeystat" },
 #define	N_RTTRASH	20
 	{ .n_name = "_rttrash" },
-#define	N_CARPSTAT	21
-	{ .n_name = "_carpstats" },
-#define	N_PFSYNCSTAT	22
+#define	N_PFSYNCSTAT	21
 	{ .n_name = "_pfsyncstats" },
-#define	N_AHSTAT	23
+#define	N_AHSTAT	22
 	{ .n_name = "_ahstat" },
-#define	N_ESPSTAT	24
+#define	N_ESPSTAT	23
 	{ .n_name = "_espstat" },
-#define	N_IPCOMPSTAT	25
+#define	N_IPCOMPSTAT	24
 	{ .n_name = "_ipcompstat" },
-#define	N_IPSTAT	26
+#define	N_IPSTAT	25
 	{ .n_name = "_ipstat" },
-#define	N_ICMPSTAT	27
+#define	N_ICMPSTAT	26
 	{ .n_name = "_icmpstat" },
-#define	N_IGMPSTAT	28
+#define	N_IGMPSTAT	27
 	{ .n_name = "_igmpstat" },
-#define	N_PIMSTAT	29
+#define	N_PIMSTAT	28
 	{ .n_name = "_pimstat" },
-#define	N_RIP6STAT	30
+#define	N_RIP6STAT	29
 	{ .n_name = "_rip6stat" },
-#define	N_SCTPSTAT	31
+#define	N_SCTPSTAT	30
 	{ .n_name = "_sctpstat" },
-#define	N_MFCTABLESIZE	32
+#define	N_MFCTABLESIZE	31
 	{ .n_name = "_mfctablesize" },
 	{ .n_name = NULL },
 };
@@ -187,8 +185,8 @@
 #endif
 	{ 0,		N_PIMSTAT,	1,	NULL,
 	  pim_stats,	NULL,		"pim",	1,	IPPROTO_PIM },
-	{ -1,		N_CARPSTAT,	1,	NULL,
-	  carp_stats,	NULL,		"carp",	1,	0 },
+	{ -1,		0,		1,	NULL,
+	  NULL,		NULL,		"carp",	1,	0 },
 	{ -1,		N_PFSYNCSTAT,	1,	NULL,
 	  pfsync_stats,	NULL,		"pfsync", 1,	0 },
 	{ -1,		-1,		0,	NULL,
@@ -651,14 +649,13 @@
 			return;
 		} else {
 			/* XXX: temp. hack */
-			switch (tp->pr_protocol) {
-			case IPPROTO_TCP:
-				tcp_stats(kvmd, "tcp");
-				break;
-			case IPPROTO_UDP:
-				udp_stats(kvmd, "udp");
-				break;
-			default:
+			if (strcmp(tp->pr_name, "udp") == 0)
+				tcp_stats(kvmd, tp->pr_name);
+			else if (strcmp(tp->pr_name, "tcp") == 0)
+				udp_stats(kvmd, tp->pr_name);
+			else if (strcmp(tp->pr_name, "carp") == 0)
+				carp_stats(kvmd, tp->pr_name);
+			else {
 				pr = tp->pr_stats;
 				if (!pr) {
 					if (pflag)
@@ -676,7 +673,6 @@
 					return;
 				} else
 					off = nl[tp->pr_sindex].n_value;
-				break;
 			}
 		}
 	} else {


More information about the p4-projects mailing list