summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/uipc_domain.c8
-rw-r--r--sys/net/if_pflow.c21
-rw-r--r--sys/net/if_pflow.h3
-rw-r--r--sys/sys/socket.h18
-rw-r--r--sys/sys/sysctl.h3
-rw-r--r--usr.bin/netstat/inet.c34
-rw-r--r--usr.bin/netstat/main.c9
-rw-r--r--usr.bin/netstat/netstat.h3
8 files changed, 90 insertions, 9 deletions
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index c991d601566..b7ad9e7e5a7 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_domain.c,v 1.27 2008/04/23 10:55:14 norby Exp $ */
+/* $OpenBSD: uipc_domain.c,v 1.28 2008/09/16 15:48:12 gollo Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/*
@@ -47,6 +47,7 @@
#include "bluetooth.h"
#include "bpfilter.h"
+#include "pflow.h"
struct domain *domains;
@@ -202,6 +203,11 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
return (bpf_sysctl(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen));
#endif
+#if NPFLOW > 0
+ if (family == PF_PFLOW)
+ return (pflow_sysctl(name + 1, namelen - 1, oldp, oldlenp,
+ newp, newlen));
+#endif
dp = pffinddomain(family);
if (dp == NULL)
return (ENOPROTOOPT);
diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c
index 2f2950f3a9d..4fb8b0672e3 100644
--- a/sys/net/if_pflow.c
+++ b/sys/net/if_pflow.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pflow.c,v 1.2 2008/09/16 13:58:55 gollo Exp $ */
+/* $OpenBSD: if_pflow.c,v 1.3 2008/09/16 15:48:12 gollo Exp $ */
/*
* Copyright (c) 2008 Henning Brauer <henning@openbsd.org>
@@ -620,3 +620,22 @@ pflow_get_dynport(void)
return (htons(ipport_hilastauto)); /* XXX */
}
+
+int
+pflow_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen)
+{
+ if (namelen != 1)
+ return (ENOTDIR);
+
+ switch (name[0]) {
+ case NET_PFLOW_STATS:
+ if (newp != NULL)
+ return (EPERM);
+ return (sysctl_struct(oldp, oldlenp, newp, newlen,
+ &pflowstats, sizeof(pflowstats)));
+ default:
+ return (EOPNOTSUPP);
+ }
+ return (0);
+}
diff --git a/sys/net/if_pflow.h b/sys/net/if_pflow.h
index cd9d2dcc145..bd4db6b6d57 100644
--- a/sys/net/if_pflow.h
+++ b/sys/net/if_pflow.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pflow.h,v 1.1 2008/09/09 13:56:39 henning Exp $ */
+/* $OpenBSD: if_pflow.h,v 1.2 2008/09/16 15:48:12 gollo Exp $ */
/*
* Copyright (c) 2008 Henning Brauer <henning@openbsd.org>
@@ -118,6 +118,7 @@ struct pflowreq {
#ifdef _KERNEL
int export_pflow(struct pf_state *);
+int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t);
#endif /* _KERNEL */
#endif /* _NET_IF_PFLOW_H_ */
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index b960fbf86b6..76788cf0629 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.h,v 1.58 2008/05/09 02:52:15 markus Exp $ */
+/* $OpenBSD: socket.h,v 1.59 2008/09/16 15:48:12 gollo Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
/*
@@ -137,7 +137,8 @@ struct linger {
in interface output routine */
#define AF_BLUETOOTH 32 /* Bluetooth */
#define AF_MPLS 33 /* MPLS */
-#define AF_MAX 34
+#define pseudo_AF_PFLOW 34 /* pflow */
+#define AF_MAX 35
/*
* Structure used by kernel to store most
@@ -217,6 +218,7 @@ struct sockproto {
#define PF_BPF pseudo_AF_HDRCMPLT
#define PF_BLUETOOTH AF_BLUETOOTH
#define PF_MPLS AF_MPLS
+#define PF_PFLOW pseudo_AF_PFLOW
#define PF_MAX AF_MAX
/*
@@ -289,6 +291,7 @@ struct sockcred {
{ "bpf", CTLTYPE_NODE }, \
{ "bluetooth", CTLTYPE_NODE }, \
{ "mpls", CTLTYPE_NODE }, \
+ { "pflow", CTLTYPE_NODE }, \
}
/*
@@ -341,6 +344,17 @@ struct sockcred {
}
/*
+ * PF_PFLOW not really a family, but connected under CTL_NET
+ */
+#define NET_PFLOW_STATS 1 /* statistics */
+#define NET_PFLOW_MAXID 2
+
+#define CTL_NET_PFLOW_NAMES { \
+ { 0, 0 }, \
+ { "stats", CTLTYPE_STRUCT }, \
+}
+
+/*
* Maximum queue length specifiable by listen(2).
*/
#define SOMAXCONN 128
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index 2d2c48583fd..041e94d2cb1 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.92 2008/02/09 15:10:58 kettenis Exp $ */
+/* $OpenBSD: sysctl.h,v 1.93 2008/09/16 15:48:12 gollo Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -730,6 +730,7 @@ extern int (*cpu_cpuspeed)(int *);
extern void (*cpu_setperf)(int);
int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t);
#else /* !_KERNEL */
#include <sys/cdefs.h>
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 5ce43baabcc..5358fe9b94a 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet.c,v 1.106 2008/05/08 03:13:55 mpf Exp $ */
+/* $OpenBSD: inet.c,v 1.107 2008/09/16 15:48:12 gollo Exp $ */
/* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */
/*
@@ -68,6 +68,7 @@
#include <net/if.h>
#include <net/pfvar.h>
#include <net/if_pfsync.h>
+#include <net/if_pflow.h>
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
@@ -1038,6 +1039,37 @@ pfsync_stats(char *name)
}
/*
+ * Dump pflow statistics structure.
+ */
+void
+pflow_stats(char *name)
+{
+ struct pflowstats flowstats;
+ int mib[] = { CTL_NET, PF_PFLOW, NET_PFLOW_STATS };
+ size_t len = sizeof(struct pflowstats);
+
+ if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &flowstats, &len,
+ NULL, 0) == -1) {
+ if (errno != ENOPROTOOPT)
+ warn(name);
+ return;
+ }
+
+ printf("%s:\n", name);
+#define p(f, m) if (flowstats.f || sflag <= 1) \
+ printf(m, flowstats.f, plural(flowstats.f))
+#define p2(f, m) if (flowstats.f || sflag <= 1) \
+ printf(m, flowstats.f)
+
+ p(pflow_flows, "\t%llu flow%s sent\n");
+ p(pflow_packets, "\t%llu packet%s sent\n");
+ p2(pflow_onomem, "\t\t%llu send failed due to mbuf memory error\n");
+ p2(pflow_oerrors, "\t\t%llu send error\n");
+#undef p
+#undef p2
+}
+
+/*
* Dump IPCOMP statistics structure.
*/
void
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index d3737f7e813..0d960476fd7 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.75 2008/05/08 07:18:47 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.76 2008/09/16 15:48:13 gollo Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -111,6 +111,7 @@ struct protox {
{ -1, NULL, carp_stats, NULL, "carp" },
{ -1, NULL, pfsync_stats, NULL, "pfsync" },
{ -1, NULL, pim_stats, NULL, "pim" },
+ { -1, NULL, pflow_stats, NULL, "pflow" },
{ -1, NULL, NULL, NULL, NULL }
};
@@ -189,6 +190,8 @@ main(int argc, char *argv[])
af = AF_APPLETALK;
else if (strcmp(optarg, "mpls") == 0)
af = AF_MPLS;
+ else if (strcmp(optarg, "pflow") == 0)
+ af = PF_PFLOW;
else if (strcmp(optarg, "mask") == 0)
af = 0xff;
else {
@@ -410,6 +413,10 @@ main(int argc, char *argv[])
}
endprotoent();
}
+ if (af == PF_PFLOW || af == AF_UNSPEC) {
+ tp = name2protox("pflow");
+ printproto(tp, tp->pr_name);
+ }
if (af == AF_INET6 || af == AF_UNSPEC)
for (tp = ip6protox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 4b417bb5ab1..790218746bd 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.47 2008/01/03 21:01:40 claudio Exp $ */
+/* $OpenBSD: netstat.h,v 1.48 2008/09/16 15:48:13 gollo Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -82,6 +82,7 @@ void esp_stats(char *);
void ipip_stats(char *);
void carp_stats (char *);
void pfsync_stats (char *);
+void pflow_stats (char *);
void etherip_stats(char *);
void ipcomp_stats(char *);