PERFORCE change 166836 for review

Gabor Pali pgj at FreeBSD.org
Thu Jul 30 20:43:03 UTC 2009


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

Change 166836 by pgj at petymeg-current on 2009/07/30 20:42:55

	Rewrite pfkey_stats() of netstat(1) to call libnetstat(3).

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/Makefile#4 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#26 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#34 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/pfkey.c#3 edit

Differences ...

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

@@ -5,12 +5,14 @@
 
 PROG=	netstat
 SRCS=	if.c inet.c main.c mbuf.c mroute.c route.c \
-	unix.c atalk.c mroute6.c ipsec.c bpf.c pfkey.c sctp.c
+	unix.c atalk.c mroute6.c ipsec.c bpf.c sctp.c
 
 WARNS?=	3
 CFLAGS+=-fno-strict-aliasing
 
 CFLAGS+=-DIPSEC
+SRCS+=	pfkey.c
+
 CFLAGS+=-DSCTP
 
 .if ${MK_INET6_SUPPORT} != "no"

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

@@ -91,6 +91,7 @@
 void	esp_stats(u_long, const char *, int, int);
 void	ah_stats(u_long, const char *, int, int);
 void	ipcomp_stats(u_long, const char *, int, int);
+void	pfkey_stats(const struct stat_type *);
 #endif
 
 #ifdef INET6
@@ -110,10 +111,6 @@
 void	inet6print(struct in6_addr *, int, const char *, int);
 #endif /*INET6*/
 
-#ifdef IPSEC
-void	pfkey_stats(u_long, const char *, int, int);
-#endif
-
 void	mbpr(void *);
 
 void	hostpr(u_long, u_long);

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

@@ -105,17 +105,15 @@
 	{ .n_name = "_mf6ctable" },
 #define	N_MIF6TABLE	13
 	{ .n_name = "_mif6table" },
-#define	N_PFKEYSTAT	14
-	{ .n_name = "_pfkeystat" },
-#define	N_RTTRASH	15
+#define	N_RTTRASH	14
 	{ .n_name = "_rttrash" },
-#define	N_AHSTAT	16
+#define	N_AHSTAT	15
 	{ .n_name = "_ahstat" },
-#define	N_ESPSTAT	17
+#define	N_ESPSTAT	16
 	{ .n_name = "_espstat" },
-#define	N_IPCOMPSTAT	18
+#define	N_IPCOMPSTAT	17
 	{ .n_name = "_ipcompstat" },
-#define	N_MFCTABLESIZE	19
+#define	N_MFCTABLESIZE	18
 	{ .n_name = "_mfctablesize" },
 	{ .n_name = NULL },
 };
@@ -198,8 +196,8 @@
 
 #ifdef IPSEC
 struct protox pfkeyprotox[] = {
-	{ -1,		N_PFKEYSTAT,	1,	NULL,	NULL, stat_MAX,
-	  pfkey_stats,	NULL,		"pfkey", 0,	0 },
+	{ -1,		0,		1,	NULL,	pfkey_stats, stat_pfkey,
+	  NULL,		NULL,		"pfkey", 0,	0 },
 	{ -1,		-1,		0,	NULL,	NULL, stat_MAX,
 	  NULL,		NULL,		NULL,	0,	0 }
 };

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

@@ -2,6 +2,7 @@
 /*	$KAME: ipsec.c,v 1.25 2001/03/12 09:04:39 itojun Exp $	*/
 /*-
  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
+ * Copyright (c) 2009 Gabor Pali
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -70,78 +71,35 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/usr.bin/netstat/pfkey.c,v 1.6 2008/01/02 23:26:11 obrien Exp $");
 
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-
-#include <netinet/in.h>
-
-#ifdef IPSEC
-#include <netipsec/keysock.h>
-#endif
+#include <sys/types.h>
 
-#include <stdint.h>
 #include <stdio.h>
-#include <string.h>
-#include <unistd.h>
+#include <netstat.h>
 #include "extern.h"
 
-#ifdef IPSEC
-
-static const char *pfkey_msgtypenames[] = {
-	"reserved", "getspi", "update", "add", "delete",
-	"get", "acquire", "register", "expire", "flush",
-	"dump", "x_promisc", "x_pchange", "x_spdupdate", "x_spdadd",
-	"x_spddelete", "x_spdget", "x_spdacquire", "x_spddump", "x_spdflush",
-	"x_spdsetidx", "x_spdexpire", "x_spddelete2"
-};
-
-static const char *pfkey_msgtype_names (int);
-
-
-static const char *
-pfkey_msgtype_names(int x)
-{
-	const int max =
-	    sizeof(pfkey_msgtypenames)/sizeof(pfkey_msgtypenames[0]);
-	static char buf[20];
-
-	if (x < max && pfkey_msgtypenames[x])
-		return pfkey_msgtypenames[x];
-	snprintf(buf, sizeof(buf), "#%d", x);
-	return buf;
-}
-
 void
-pfkey_stats(u_long off, const char *name, int family __unused,
-    int proto __unused)
+pfkey_stats(const struct stat_type *sttp)
 {
-	struct pfkeystat pfkeystat;
+	const struct pfkey_stat *s;
 	unsigned first, type;
 
-	if (off == 0)
-		return;
-	printf ("%s:\n", name);
-	kread(off, (char *)&pfkeystat, sizeof(pfkeystat));
-
-#define	p(f, m) if (pfkeystat.f || sflag <= 1) \
-    printf(m, (uintmax_t)pfkeystat.f, plural(pfkeystat.f))
-
-	/* userland -> kernel */
+	s = netstat_get_pfkeystats(sttp);
+#define	p(f, m) if (netstat_pfkeys_get_##f(s) || sflag <= 1) \
+    printf(m, netstat_pfkeys_get_##f(s), plural(netstat_pfkeys_get_##f(s)))
+#define	pa(f,i,m) if (netstat_pfkeys_get_##f(s,i) || sflag <= 1) \
+    printf(m, netstat_pfkeys_get_##f(s,i), plural(netstat_pfkeys_get_##f(s,i)))
 	p(out_total, "\t%ju request%s sent from userland\n");
 	p(out_bytes, "\t%ju byte%s sent from userland\n");
-	for (first = 1, type = 0;
-	     type < sizeof(pfkeystat.out_msgtype)/sizeof(pfkeystat.out_msgtype[0]);
-	     type++) {
-		if (pfkeystat.out_msgtype[type] <= 0)
+	for (first = 1, type = 0; type < NETSTAT_PFKEY_OUT_MSGTYPE_MAX;
+	    type++) {
+		if (netstat_pfkeys_get_out_msgtype(s, type) <= 0)
 			continue;
 		if (first) {
 			printf("\thistogram by message type:\n");
 			first = 0;
 		}
-		printf("\t\t%s: %ju\n", pfkey_msgtype_names(type),
-			(uintmax_t)pfkeystat.out_msgtype[type]);
+		printf("\t\t%s: %ju\n", netstat_pfkey_msgtype_name(type),
+		    netstat_pfkeys_get_out_msgtype(s, type));
 	}
 	p(out_invlen, "\t%ju message%s with invalid length field\n");
 	p(out_invver, "\t%ju message%s with invalid version field\n");
@@ -152,29 +110,26 @@
 	p(out_invexttype, "\t%ju message%s with invalid extension type\n");
 	p(out_invsatype, "\t%ju message%s with invalid sa type\n");
 	p(out_invaddr, "\t%ju message%s with invalid address extension\n");
-
-	/* kernel -> userland */
 	p(in_total, "\t%ju request%s sent to userland\n");
 	p(in_bytes, "\t%ju byte%s sent to userland\n");
-	for (first = 1, type = 0;
-	     type < sizeof(pfkeystat.in_msgtype)/sizeof(pfkeystat.in_msgtype[0]);
-	     type++) {
-		if (pfkeystat.in_msgtype[type] <= 0)
+	for (first = 1, type = 0; type < NETSTAT_PFKEY_IN_MSGTYPE_MAX;
+	    type++) {
+		if (netstat_pfkeys_get_in_msgtype(s, type) <= 0)
 			continue;
 		if (first) {
 			printf("\thistogram by message type:\n");
 			first = 0;
 		}
-		printf("\t\t%s: %ju\n", pfkey_msgtype_names(type),
-			(uintmax_t)pfkeystat.in_msgtype[type]);
+		printf("\t\t%s: %ju\n", netstat_pfkey_msgtype_name(type),
+		    netstat_pfkeys_get_in_msgtype(s, type));
 	}
-	p(in_msgtarget[KEY_SENDUP_ONE],
+	pa(in_msgtarget,pfkey_Sendup_One,
 	    "\t%ju message%s toward single socket\n");
-	p(in_msgtarget[KEY_SENDUP_ALL],
+	pa(in_msgtarget,pfkey_Sendup_All,
 	    "\t%ju message%s toward all sockets\n");
-	p(in_msgtarget[KEY_SENDUP_REGISTERED],
+	pa(in_msgtarget,pfkey_Sendup_Registered,
 	    "\t%ju message%s toward registered sockets\n");
 	p(in_nomem, "\t%ju message%s with memory allocation failure\n");
 #undef p
+#undef pa
 }
-#endif /* IPSEC */


More information about the p4-projects mailing list