summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2004-02-24 21:43:57 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2004-02-24 21:43:57 +0000
commit4d6522e360a3bd08408dd444cb266f97602c8aea (patch)
treebcb1adbc419ce7ff0afccfd5f82e3242e84c8a1d /sys
parentbfb169d07fee20a3444af8c5040902105d60c553 (diff)
sysctl knob for bpf tunables. some tips from canacar@
ok canacar@ deraadt@ mcbride@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/uipc_domain.c9
-rw-r--r--sys/net/bpf.c38
-rw-r--r--sys/sys/socket.h18
-rw-r--r--sys/sys/sysctl.h4
4 files changed, 65 insertions, 4 deletions
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index 285d37dc70b..74d52f8a2e8 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_domain.c,v 1.15 2003/06/02 23:28:06 millert Exp $ */
+/* $OpenBSD: uipc_domain.c,v 1.16 2004/02/24 21:43:55 tedu Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/*
@@ -45,6 +45,8 @@
#include <sys/sysctl.h>
#include <sys/timeout.h>
+#include "bpfilter.h"
+
struct domain *domains;
void pffasttimo(void *);
@@ -207,6 +209,11 @@ net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
for (dp = domains; dp; dp = dp->dom_next)
if (dp->dom_family == family)
goto found;
+#if NBPFILTER > 0
+ if (family == PF_BPF)
+ return (bpf_sysctl(name + 1, namelen - 1, oldp, oldlenp,
+ newp, newlen));
+#endif
return (ENOPROTOOPT);
found:
switch (family) {
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 7baa0c8acbc..d95392943a0 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.43 2004/02/06 22:38:58 tedu Exp $ */
+/* $OpenBSD: bpf.c,v 1.44 2004/02/24 21:43:55 tedu Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -50,6 +50,7 @@
#include <sys/socket.h>
#include <sys/poll.h>
#include <sys/kernel.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/bpf.h>
@@ -1378,3 +1379,38 @@ bpfdetach(ifp)
}
ifp->if_bpf = NULL;
}
+
+int
+bpf_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
+ size_t newlen)
+{
+ int newval;
+ int error;
+
+ if (namelen != 1)
+ return (ENOTDIR);
+
+ switch (name[0]) {
+ case NET_BPF_BUFSIZE:
+ newval = bpf_bufsize;
+ error = sysctl_int(oldp, oldlenp, newp, newlen, &newval);
+ if (error)
+ return (error);
+ if (newval < BPF_MINBUFSIZE || newval > bpf_maxbufsize)
+ return (EINVAL);
+ bpf_bufsize = newval;
+ break;
+ case NET_BPF_MAXBUFSIZE:
+ newval = bpf_maxbufsize;
+ error = sysctl_int(oldp, oldlenp, newp, newlen, &newval);
+ if (error)
+ return (error);
+ if (newval < BPF_MINBUFSIZE)
+ return (EINVAL);
+ bpf_maxbufsize = newval;
+ break;
+ default:
+ return (EOPNOTSUPP);
+ }
+ return (0);
+}
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index d2447ba8126..6fdb8135d12 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.h,v 1.46 2003/06/02 23:28:21 millert Exp $ */
+/* $OpenBSD: socket.h,v 1.47 2004/02/24 21:43:56 tedu Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
/*
@@ -209,6 +209,7 @@ struct sockproto {
#define PF_ENCAP AF_ENCAP
#define PF_SIP AF_SIP
#define PF_KEY AF_KEY
+#define PF_BPF pseudo_AF_HDRCMPLT
#define PF_MAX AF_MAX
/*
@@ -278,6 +279,7 @@ struct sockcred {
{ "encap", CTLTYPE_NODE }, \
{ "sip", CTLTYPE_NODE }, \
{ "key", CTLTYPE_NODE }, \
+ { "bpf", CTLTYPE_NODE }, \
}
/*
@@ -301,6 +303,20 @@ struct sockcred {
}
/*
+ * PF_BPF not really a family, but connected under CTL_NET
+ */
+#define NET_BPF_BUFSIZE 1 /* default buffer size */
+#define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */
+#define NET_BPF_MAXID 3
+
+#define CTL_NET_BPF_NAMES { \
+ { 0, 0 }, \
+ { "bufsize", CTLTYPE_INT }, \
+ { "maxbufsize", CTLTYPE_INT }, \
+}
+
+
+/*
* Maximum queue length specifiable by listen(2).
*/
#define SOMAXCONN 128
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
index a0a326a2582..dd744013255 100644
--- a/sys/sys/sysctl.h
+++ b/sys/sys/sysctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.h,v 1.73 2004/02/15 11:14:45 markus Exp $ */
+/* $OpenBSD: sysctl.h,v 1.74 2004/02/24 21:43:56 tedu Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
@@ -681,6 +681,8 @@ int sysctl_wdog(int *, u_int, void *, size_t *, void *, size_t);
extern int (*cpu_cpuspeed)(int *);
extern int (*cpu_setperf)(int);
+int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+
void sysctl_init(void);
#else /* !_KERNEL */