From hans@truk.brandinnovators.com  Mon Dec 23 05:11:53 1996
Received: from news.IAEhv.nl (root@news.IAEhv.nl [194.151.64.4])
          by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id FAA03299
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 23 Dec 1996 05:11:51 -0800 (PST)
Received: from truk.brandinnovators.com (uucp@localhost) 
          by news.IAEhv.nl (8.6.13/1.63) with IAEhv.nl; pid 9731
          on Mon, 23 Dec 1996 14:04:20 +0100; id OAA09731
          efrom: hans@truk.brandinnovators.com; eto: FreeBSD-gnats-submit@freebsd.org
Received: by truk.brandinnovators.com (8.7.5/BI96070101) 
    for <> id NAA01354; Mon, 23 Dec 1996 13:59:06 GMT
Message-Id: <199612231359.NAA01354@truk.brandinnovators.com>
Date: Mon, 23 Dec 1996 13:59:06 GMT
From: hans@brandinnovators.com (Hans Zuidam)
Reply-To: hans@brandinnovators.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: FIONREAD in if_tun.c wrong
X-Send-Pr-Version: 3.2

>Number:         2271
>Category:       kern
>Synopsis:       FIONREAD on tunnel device returns incorrect value.
>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:   Mon Dec 23 05:20:01 PST 1996
>Closed-Date:    Sat Jul 5 14:00:41 PDT 1997
>Last-Modified:  Sat Jul  5 14:02:04 PDT 1997
>Originator:     Hans Zuidam
>Release:        FreeBSD 2.1.5-RELEASE i386
>Organization:
Brand Innovators B.V.

>Environment:

	tunnel device configured

>Description:

	When doing a FIONREAD ioctl on the tunnel device, it returns
	the value of m_len, while it should return the value of
	m_pkthdr.len (if M_PKTHDR is set.)

>How-To-Repeat:

	Using a propriatary TCP/IP stack it was discovered that large TCP
	packets would not be read correctly.  The FIONREAD would report
	that there were 40 bytes in the packet, while there were actually
	many more.

	Note: none of the programs supplied with FreeBSD that use the tunnel
	device, use FIONREAD.  All request as much as possible from a read.

>Fix:
	
	Workaround by doing MAXINT reads (or something similar...) on a
	/dev/tun.  Below is a patch which is believed to be correct.

*** sys.org/net/if_tun.c        Fri Dec 20 15:20:00 1996
--- sys/net/if_tun.c    Mon Dec 23 09:51:22 1996
***************
*** 418,425 ****
                break;
        case FIONREAD:
                s = splimp();
!               if (tp->tun_if.if_snd.ifq_head)
!                       *(int *)data = tp->tun_if.if_snd.ifq_head->m_len;
                else
                        *(int *)data = 0;
                splx(s);
--- 418,429 ----
                break;
        case FIONREAD:
                s = splimp();
!               if (tp->tun_if.if_snd.ifq_head) {
!                       if (tp->tun_if.if_snd.ifq_head->m_flags & M_PKTHDR)
!                               *(int *)data = tp->tun_if.if_snd.ifq_head->m_pkthdr.len;
!                       else
!                               *(int *)data = tp->tun_if.if_snd.ifq_head->m_len;
!               }
                else
                        *(int *)data = 0;
                splx(s);
>Release-Note:
>Audit-Trail:

From: Bill Fenner <fenner@parc.xerox.com>
To: hans@brandinnovators.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/2271: FIONREAD in if_tun.c wrong 
Date: Mon, 23 Dec 1996 14:45:10 PST

 I think it's an error to send a non-PKTHDR mbuf to an interface output
 routine, so it's probably safe to get rid of the if and just use
 m_pkthdr.len unconditionally.
 
   Bill
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Sat Jul 5 14:00:41 PDT 1997 
State-Changed-Why:  
Fixed in rev 1.19 of if_tun.c .  This fix never made it into 2.1.x 
but is in 2.2.x and 3.0 . 
>Unformatted:
