diff options
author | 2011-11-30 10:26:56 +0000 | |
---|---|---|
committer | 2011-11-30 10:26:56 +0000 | |
commit | dff544aefccd2cd42ba158554c605dc3246d1b23 (patch) | |
tree | 458804224f691be65eebc838bcaea5412b6fd812 | |
parent | Fix an issue when uid != euid (e.g. when running shutdown(8) as a (diff) | |
download | wireguard-openbsd-dff544aefccd2cd42ba158554c605dc3246d1b23.tar.xz wireguard-openbsd-dff544aefccd2cd42ba158554c605dc3246d1b23.zip |
this diff introduces the MAXMCLBYTES macro to describe the largest
cluster the generic network stack will be able to give you.
it also recognises that external storage on an mbuf may be bigger than
MCLBYTES. its only when m_pullup or m_pulldown need to allocate
another cluster that they now check the len argument, and now they
do it against MAXMCLBYTES.
this is required for me to do pfsync on jumbo frames as the m_pulldown
for the subregions fail beyond MCLBYTES into the packet.
ok deraadt@ mikeb@ henning@ blambert@
manpage changes ok jmc@
-rw-r--r-- | share/man/man9/mbuf.9 | 13 | ||||
-rw-r--r-- | sys/kern/uipc_mbuf.c | 8 | ||||
-rw-r--r-- | sys/kern/uipc_mbuf2.c | 16 | ||||
-rw-r--r-- | sys/sys/param.h | 4 |
4 files changed, 22 insertions, 19 deletions
diff --git a/share/man/man9/mbuf.9 b/share/man/man9/mbuf.9 index 1d47f9116c8..4e7194e244d 100644 --- a/share/man/man9/mbuf.9 +++ b/share/man/man9/mbuf.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mbuf.9,v 1.54 2011/07/29 12:59:28 blambert Exp $ +.\" $OpenBSD: mbuf.9,v 1.55 2011/11/30 10:26:56 dlg Exp $ .\" .\" Copyright (c) 2001 Jean-Jacques Bernard-Gundol <jjbg@openbsd.org> .\" All rights reserved. @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: July 29 2011 $ +.Dd $Mdocdate: November 30 2011 $ .Dt MBUF 9 .Os .Sh NAME @@ -265,7 +265,7 @@ variable is valid. .Pp An external cluster is used when the data to hold in the mbuf is large. -The size of an external cluster is MCLBYTES +The size of an external cluster is between MCLBYTES and MAXMCLBYTES .Pq also defined in Aq Pa sys/param.h . A cluster should be used when the size of the data reach MINCLSIZE (the minimum size to be held by an external cluster). @@ -467,8 +467,9 @@ Ensure that the data in the mbuf chain starting at and ending at .Fa off+len will be put in a continuous memory region. +If memory must be allocated, then it will fail if the .Fa len -must be smaller than or equal to MCLBYTES. +argument is greater than MAXCLBYTES. The pointer returned points to an mbuf in the chain and the new offset for data in this mbuf is .Fa *offp . @@ -480,9 +481,9 @@ Ensure that the data in the mbuf chain starting at the beginning of the chain and ending at .Fa len will be put in continuous memory region. -The +If memory must be allocated, then it will fail if the .Fa len -argument must be smaller than or equal to MCLBYTES. +argument is greater than MAXCLBYTES. If this function fails, .Fa n is freed. diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 4bc76ed4a4f..07c70db8c63 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.163 2011/11/30 01:16:09 dlg Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.164 2011/11/30 10:26:56 dlg Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -108,7 +108,7 @@ u_int mclsizes[] = { 9 * 1024, 12 * 1024, 16 * 1024, - 64 * 1024 + MAXMCLBYTES /* 64k */ }; static char mclnames[MCLPOOLS][8]; struct pool mclpools[MCLPOOLS]; @@ -949,13 +949,13 @@ m_pullup(struct mbuf *n, int len) n = n->m_next; len -= m->m_len; } else { - if (len > MCLBYTES) + if (len > MAXMCLBYTES) goto bad; MGET(m, M_DONTWAIT, n->m_type); if (m == NULL) goto bad; if (len > MHLEN) { - MCLGET(m, M_DONTWAIT); + MCLGETI(m, M_DONTWAIT, NULL, len); if ((m->m_flags & M_EXT) == 0) { m_free(m); goto bad; diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c index 2ac80632c79..cca045d841b 100644 --- a/sys/kern/uipc_mbuf2.c +++ b/sys/kern/uipc_mbuf2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf2.c,v 1.34 2011/04/05 11:48:28 blambert Exp $ */ +/* $OpenBSD: uipc_mbuf2.c,v 1.35 2011/11/30 10:26:56 dlg Exp $ */ /* $KAME: uipc_mbuf2.c,v 1.29 2001/02/14 13:42:10 itojun Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */ @@ -91,10 +91,6 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp) /* check invalid arguments. */ if (m == NULL) panic("m == NULL in m_pulldown()"); - if (len > MCLBYTES) { - m_freem(m); - return (NULL); /* impossible */ - } if ((n = m_getptr(m, off, &off)) == NULL) { m_freem(m); @@ -180,9 +176,13 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp) * now, we need to do the hard way. don't m_copy as there's no room * on both ends. */ + if (len > MAXMCLBYTES) { + m_freem(m); + return (NULL); + } MGET(o, M_DONTWAIT, m->m_type); if (o && len > MLEN) { - MCLGET(o, M_DONTWAIT); + MCLGETI(o, M_DONTWAIT, NULL, len); if ((o->m_flags & M_EXT) == 0) { m_free(o); o = NULL; @@ -217,7 +217,7 @@ m_dup1(struct mbuf *m, int off, int len, int wait) struct mbuf *n; int l; - if (len > MCLBYTES) + if (len > MAXMCLBYTES) return (NULL); if (off == 0 && (m->m_flags & M_PKTHDR) != 0) { MGETHDR(n, wait, m->m_type); @@ -233,7 +233,7 @@ m_dup1(struct mbuf *m, int off, int len, int wait) l = MLEN; } if (n && len > l) { - MCLGET(n, wait); + MCLGETI(n, wait, NULL, len); if ((n->m_flags & M_EXT) == 0) { m_free(n); n = NULL; diff --git a/sys/sys/param.h b/sys/sys/param.h index 3383ed2cb27..f95051cd68e 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -1,4 +1,4 @@ -/* $OpenBSD: param.h,v 1.92 2011/07/18 07:07:52 deraadt Exp $ */ +/* $OpenBSD: param.h,v 1.93 2011/11/30 10:26:56 dlg Exp $ */ /* $NetBSD: param.h,v 1.23 1996/03/17 01:02:29 thorpej Exp $ */ /*- @@ -138,6 +138,8 @@ #define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */ #define MCLOFSET (MCLBYTES - 1) +#define MAXMCLBYTES (64 * 1024) /* largest cluster from the stack */ + /* * File system parameters and macros. * |