From nobody@FreeBSD.org  Sat Sep 21 02:18:26 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E047837B401
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Sep 2002 02:18:26 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 83E8143E6A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Sep 2002 02:18:26 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g8L9IQ7R006830
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Sep 2002 02:18:26 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.6/8.12.6/Submit) id g8L9IQUi006829;
	Sat, 21 Sep 2002 02:18:26 -0700 (PDT)
Message-Id: <200209210918.g8L9IQUi006829@www.freebsd.org>
Date: Sat, 21 Sep 2002 02:18:26 -0700 (PDT)
From: Neelkanth Natu <neelnatu@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: tunwrite() does not allocate clusters for packet_size >= MINCLSIZE
X-Send-Pr-Version: www-1.0

>Number:         43154
>Category:       kern
>Synopsis:       [if_tun] [4.x] [patch] tunwrite() does not allocate clusters for packet_size >= MINCLSIZE
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 21 02:20:01 PDT 2002
>Closed-Date:    Wed Feb 07 21:46:44 GMT 2007
>Last-Modified:  Wed Feb 07 21:46:44 GMT 2007
>Originator:     Neelkanth Natu
>Release:        4.7-RC
>Organization:
>Environment:
FreeBSD localhost.neel.com 4.7-RC FreeBSD 4.7-RC #2: Thu Sep 19 03:07:57 PDT 2002     neel@localhost.neel.com:/usr/obj/usr/src/sys/NEEL  i386

>Description:
The copy of the email sent to freebsd-net describes the problem:

Hi,

I noticed that tunwrite() does not allocate a cluster, even if the size of the
packet is greater than or equal to MINCLSIZE. Rather it stores the packet
in a mbuf chain.

Is there any reason why this is so ? I thought that packets with
size >= MINCLSIZE are traditionally stored in clusters.

Can someone please take a look at the patch for -current below ?

thanks
Neel

--- /home/neel/if_tun.c.current Thu Sep 19 21:19:19 2002
+++ if_tun.c    Thu Sep 19 21:32:05 2002
@@ -717,27 +717,32 @@
        }
        tlen = uio->uio_resid;

-       /* get a header mbuf */
-       MGETHDR(m, M_DONTWAIT, MT_DATA);
-       if (m == NULL)
-               return (ENOBUFS);
-       mlen = MHLEN;
-
        top = 0;
        mp = &top;
        while (error == 0 && uio->uio_resid > 0) {
+               if (top == 0) {
+                       MGETHDR(m, M_DONTWAIT, MT_DATA);
+                       mlen = MHLEN;
+               } else {
+                       MGET(m, M_DONTWAIT, MT_DATA);
+                       mlen = MLEN;
+               }
+               if (m == 0) {
+                       error = ENOBUFS;
+                       break;
+               }
+               if (uio->uio_resid >= MINCLSIZE) {
+                       MCLGET(m, M_DONTWAIT);
+                       if (m->m_flags & M_EXT) {
+                               mlen = MCLBYTES;
+                       } else {
+                               /* store the data in the mbuf itself */
+                       }
+               }
                m->m_len = min(mlen, uio->uio_resid);
                error = uiomove(mtod (m, caddr_t), m->m_len, uio);
                *mp = m;
                mp = &m->m_next;
-               if (uio->uio_resid > 0) {
-                       MGET (m, M_DONTWAIT, MT_DATA);
-                       if (m == 0) {
-                               error = ENOBUFS;
-                               break;
-                       }
-                       mlen = MLEN;
-               }
        }
        if (error) {
                if (top)
>How-To-Repeat:

>Fix:
See description for the patch to -current.
The diff is against if_tun.c version 1.107.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: bms 
State-Changed-When: Fri Feb 2 21:34:12 UTC 2007 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=43154 
State-Changed-From-To: suspended->open 
State-Changed-By: bms 
State-Changed-When: Fri Feb 2 21:35:20 UTC 2007 
State-Changed-Why:  
reopen PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43154 
State-Changed-From-To: open->suspended 
State-Changed-By: bms 
State-Changed-When: Fri Feb 2 21:35:44 UTC 2007 
State-Changed-Why:  
Mark as suspended. 
This PR only affects FreeBSD 4.x, which is no longer supported. 
FreeBSD 5.x and older use m_uiotombuf(), so mbuf chains are automatically 
sized correctly (and clusters are used where needed). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43154 
State-Changed-From-To: suspended->closed 
State-Changed-By: bms 
State-Changed-When: Wed Feb 7 21:46:27 UTC 2007 
State-Changed-Why:  
close old PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43154 
>Unformatted:
