Make bpf_maxbufsize writable via sysctl, as written by Andrew Brown.

This commit is contained in:
jonathan 2004-01-22 00:32:41 +00:00
parent 9369f19096
commit 638afbfe26
2 changed files with 52 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpf.c,v 1.88 2004/01/21 23:59:12 jonathan Exp $ */ /* $NetBSD: bpf.c,v 1.89 2004/01/22 00:32:41 jonathan Exp $ */
/* /*
* Copyright (c) 1990, 1991, 1993 * Copyright (c) 1990, 1991, 1993
@ -39,7 +39,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.88 2004/01/21 23:59:12 jonathan Exp $"); __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.89 2004/01/22 00:32:41 jonathan Exp $");
#include "bpfilter.h" #include "bpfilter.h"
@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.88 2004/01/21 23:59:12 jonathan Exp $");
#include <sys/errno.h> #include <sys/errno.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/sysctl.h>
#include <net/if.h> #include <net/if.h>
@ -90,12 +91,12 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.88 2004/01/21 23:59:12 jonathan Exp $");
#define PRINET 26 /* interruptible */ #define PRINET 26 /* interruptible */
/* /*
* The default read buffer size, and limit for BIOCSBLEN, is patchable. * The default read buffer size, and limit for BIOCSBLEN, is sysctl'able.
* XXX both should be made sysctl'able, and the defaults computed * XXX the default values should be computed dynamically based
* dynamically based on available memory size and available mbuf clusters. * on available memory size and available mbuf clusters.
*/ */
int bpf_bufsize = BPF_BUFSIZE; int bpf_bufsize = BPF_BUFSIZE;
int bpf_maxbufsize = (1024 * 1024); /* XXX set dynamically, see above */ int bpf_maxbufsize = BPF_DFLTBUFSIZE; /* XXX set dynamically, see above */
/* /*
* bpf_iflist is the list of interfaces; each corresponds to an ifnet * bpf_iflist is the list of interfaces; each corresponds to an ifnet
@ -1493,3 +1494,45 @@ bpf_setdlt(d, dlt)
splx(s); splx(s);
return 0; return 0;
} }
static int
sysctl_net_bpf_maxbufsize(SYSCTLFN_ARGS)
{
int newsize, error;
struct sysctlnode node;
node = *rnode;
node.sysctl_data = &newsize;
newsize = bpf_maxbufsize;
error = sysctl_lookup(SYSCTLFN_CALL(&node));
if (error || newp == NULL)
return (error);
if (newsize < BPF_MINBUFSIZE || newsize > BPF_MAXBUFSIZE)
return (EINVAL);
bpf_maxbufsize = newsize;
return (0);
}
SYSCTL_SETUP(sysctl_net_bfp_setup, "sysctl net.bpf subtree setup")
{
struct sysctlnode *node;
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "net", NULL,
NULL, 0, NULL, 0,
CTL_NET, CTL_EOL);
node = NULL;
sysctl_createv(SYSCTL_PERMANENT,
CTLTYPE_NODE, "bpf", &node,
NULL, 0, NULL, 0,
CTL_NET, CTL_CREATE, CTL_EOL);
if (node != NULL)
sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
CTLTYPE_INT, "maxbufsize", NULL,
sysctl_net_bpf_maxbufsize, 0, &bpf_maxbufsize, 0,
CTL_NET, node->sysctl_num, CTL_CREATE, CTL_EOL);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpf.h,v 1.32 2003/08/07 16:32:47 agc Exp $ */ /* $NetBSD: bpf.h,v 1.33 2004/01/22 00:32:41 jonathan Exp $ */
/* /*
* Copyright (c) 1990, 1991, 1993 * Copyright (c) 1990, 1991, 1993
@ -56,7 +56,8 @@ typedef u_int bpf_u_int32;
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
#define BPF_MAXINSNS 512 #define BPF_MAXINSNS 512
#define BPF_MAXBUFSIZE 0x8000 #define BPF_DFLTBUFSIZE (1024*1024) /* default static upper limit */
#define BPF_MAXBUFSIZE (1024*1024*16) /* hard limit on sysctl'able value */
#define BPF_MINBUFSIZE 32 #define BPF_MINBUFSIZE 32
/* /*