From 638afbfe26ca92fef3a6814a42ec2eb750d940b4 Mon Sep 17 00:00:00 2001 From: jonathan Date: Thu, 22 Jan 2004 00:32:41 +0000 Subject: [PATCH] Make bpf_maxbufsize writable via sysctl, as written by Andrew Brown. --- sys/net/bpf.c | 55 +++++++++++++++++++++++++++++++++++++++++++++------ sys/net/bpf.h | 5 +++-- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index a1c561aed228..c354469f8c3b 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -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 @@ -39,7 +39,7 @@ */ #include -__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" @@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.88 2004/01/21 23:59:12 jonathan Exp $"); #include #include #include +#include #include @@ -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 */ /* - * The default read buffer size, and limit for BIOCSBLEN, is patchable. - * XXX both should be made sysctl'able, and the defaults computed - * dynamically based on available memory size and available mbuf clusters. + * The default read buffer size, and limit for BIOCSBLEN, is sysctl'able. + * XXX the default values should be computed dynamically based + * on available memory size and available mbuf clusters. */ 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 @@ -1493,3 +1494,45 @@ bpf_setdlt(d, dlt) splx(s); 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); +} diff --git a/sys/net/bpf.h b/sys/net/bpf.h index 8d5581f4a7ee..3a3623696fe3 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -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 @@ -56,7 +56,8 @@ typedef u_int bpf_u_int32; #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1)) #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 /*