PERFORCE change 166843 for review

Gabor Pali pgj at FreeBSD.org
Thu Jul 30 22:36:08 UTC 2009


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

Change 166843 by pgj at petymeg-current on 2009/07/30 22:35:19

	- Libnetstatify ah_stats().
	- Some minor nits for esp_stats() as well.

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#28 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/ipsec.c#4 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#36 edit

Differences ...

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

@@ -89,7 +89,7 @@
 #ifdef IPSEC
 void	ipsec_stats(u_long, const char *, int, int);
 void	esp_stats(const struct stat_type *);
-void	ah_stats(u_long, const char *, int, int);
+void	ah_stats(const struct stat_type *);
 void	ipcomp_stats(u_long, const char *, int, int);
 void	pfkey_stats(const struct stat_type *);
 #endif

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

@@ -277,7 +277,6 @@
 
 static void ipsec_hist_new(const u_int32_t *hist, size_t histmax,
 			   const struct val2str *name, const char *title);
-static void print_ahstats(const struct ahstat *ahstat);
 static void print_ipcompstats(const struct ipcompstat *ipcompstat);
 
 /*
@@ -312,56 +311,52 @@
 	}
 }
 
-static void
-print_ahstats(const struct ahstat *ahstat)
+void
+ah_stats(const struct stat_type *sttp)
 {
-#define	p32(f, m) if (ahstat->f || sflag <= 1) \
-    printf("\t%u" m, (unsigned int)ahstat->f, plural(ahstat->f))
-#define	p64(f, m) if (ahstat->f || sflag <= 1) \
-    printf("\t%ju" m, (uintmax_t)ahstat->f, plural(ahstat->f))
-#define	hist(f, n, t) \
-    ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));
+	const struct ah_stat *s;
+	int first, proto;
 
-	p32(ahs_hdrops, " packet%s shorter than header shows\n");
-	p32(ahs_nopf, " packet%s dropped; protocol family not supported\n");
-	p32(ahs_notdb, " packet%s dropped; no TDB\n");
-	p32(ahs_badkcr, " packet%s dropped; bad KCR\n");
-	p32(ahs_qfull, " packet%s dropped; queue full\n");
-	p32(ahs_noxform, " packet%s dropped; no transform\n");
-	p32(ahs_wrap, " replay counter wrap%s\n");
-	p32(ahs_badauth, " packet%s dropped; bad authentication detected\n");
-	p32(ahs_badauthl, " packet%s dropped; bad authentication length\n");
-	p32(ahs_replay, " possible replay packet%s detected\n");
-	p32(ahs_input, " packet%s in\n");
-	p32(ahs_output, " packet%s out\n");
-	p32(ahs_invalid, " packet%s dropped; invalid TDB\n");
-	p64(ahs_ibytes, " byte%s in\n");
-	p64(ahs_obytes, " byte%s out\n");
-	p32(ahs_toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
-	p32(ahs_pdrops, " packet%s blocked due to policy\n");
-	p32(ahs_crypto, " crypto processing failure%s\n");
-	p32(ahs_tunnel, " tunnel sanity check failure%s\n");
-	hist(ahstat->ahs_hist, ipsec_ahnames, "AH output");
-
+	s = netstat_get_ahstats(sttp);
+#define	p32(f, m) if (netstat_ahs_get_##f(s) || sflag <= 1) \
+    printf("\t%u" m, netstat_ahs_get_##f(s), plural(netstat_ahs_get_##f(s)))
+#define	p64(f, m) if (netstat_ahs_get_##f(s) || sflag <= 1) \
+    printf("\t%ju" m, netstat_ahs_get_##f(s), plural(netstat_ahs_get_##f(s)))
+	p32(hdrops, " packet%s shorter than header shows\n");
+	p32(nopf, " packet%s dropped; protocol family not supported\n");
+	p32(notdb, " packet%s dropped; no TDB\n");
+	p32(badkcr, " packet%s dropped; bad KCR\n");
+	p32(qfull, " packet%s dropped; queue full\n");
+	p32(noxform, " packet%s dropped; no transform\n");
+	p32(wrap, " replay counter wrap%s\n");
+	p32(badauth, " packet%s dropped; bad authentication detected\n");
+	p32(badauthl, " packet%s dropped; bad authentication length\n");
+	p32(replay, " possible replay packet%s detected\n");
+	p32(input, " packet%s in\n");
+	p32(output, " packet%s out\n");
+	p32(invalid, " packet%s dropped; invalid TDB\n");
+	p64(ibytes, " byte%s in\n");
+	p64(obytes, " byte%s out\n");
+	p32(toobig, " packet%s dropped; larger than IP_MAXPACKET\n");
+	p32(pdrops, " packet%s blocked due to policy\n");
+	p32(crypto, " crypto processing failure%s\n");
+	p32(tunnel, " tunnel sanity check failure%s\n");
+	first = 1;
+	for (proto = 0; proto < NETSTAT_AH_HIST_MAX; proto++) {
+		if (netstat_ahs_get_hist(s, proto) == 0)
+			continue;
+		if (first != 0) {
+			printf("\tAH output histogram:\n");
+			first = 0;
+		}
+		printf("\t\t%s: %u\n", netstat_ipsec_ahname(proto),
+		    netstat_ahs_get_hist(s, proto));
+	}
 #undef p32
 #undef p64
-#undef hist
 }
 
 void
-ah_stats(u_long off, const char *name, int family __unused, int proto __unused)
-{
-	struct ahstat ahstat;
-
-	if (off == 0)
-		return;
-	printf ("%s:\n", name);
-	kread(off, (char *)&ahstat, sizeof(ahstat));
-
-	print_ahstats(&ahstat);
-}
-
-void
 esp_stats(const struct stat_type *sttp)
 {
 	const struct esp_stat *s;
@@ -372,8 +367,6 @@
     printf("\t%u" m, netstat_esps_get_##f(s), plural(netstat_esps_get_##f(s)))
 #define	p64(f, m) if (netstat_esps_get_##f(s) || sflag <= 1) \
     printf("\t%ju" m, netstat_esps_get_##f(s), plural(netstat_esps_get_##f(s)))
-#define	hist(f, n, t) \
-    ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t));
 	p32(hdrops, " packet%s shorter than header shows\n");
 	p32(nopf, " packet%s dropped; protocol family not supported\n");
 	p32(notdb, " packet%s dropped; no TDB\n");
@@ -407,7 +400,6 @@
 	}
 #undef p32
 #undef p64
-#undef hist
 }
 
 static void

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

@@ -107,11 +107,9 @@
 	{ .n_name = "_mif6table" },
 #define	N_RTTRASH	14
 	{ .n_name = "_rttrash" },
-#define	N_AHSTAT	15
-	{ .n_name = "_ahstat" },
-#define	N_IPCOMPSTAT	16
+#define	N_IPCOMPSTAT	15
 	{ .n_name = "_ipcompstat" },
-#define	N_MFCTABLESIZE	17
+#define	N_MFCTABLESIZE	16
 	{ .n_name = "_mfctablesize" },
 	{ .n_name = NULL },
 };
@@ -150,8 +148,8 @@
 #ifdef IPSEC
 	{ -1,		N_IPSECSTAT,	1,	NULL,	NULL, stat_MAX, /* keep as compat */
 	  ipsec_stats,	NULL,		"ipsec", 0,	0},
-	{ -1,		N_AHSTAT,	1,	NULL,	NULL, stat_MAX,
-	  ah_stats,	NULL,		"ah",	0,	0},
+	{ -1,		0,		1,	NULL,	ah_stats, stat_AH,
+	  NULL,		NULL,		"ah",	0,	0},
 	{ -1,		0,		1,	NULL,	esp_stats, stat_ESP,
 	  NULL,		NULL,		"esp",	0,	0},
 	{ -1,		N_IPCOMPSTAT,	1,	NULL,	NULL, stat_MAX,


More information about the p4-projects mailing list