Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Jun 2011 18:24:21 +0200
From:      Martin Birgmeier <la5lbtyi@aon.at>
To:        freebsd-hackers@freebsd.org
Subject:   some strange constructs (bugs?) in if_tun.c
Message-ID:  <4DE7B935.9040004@aon.at>

next in thread | raw e-mail | index | archive | help
I am looking at net/if_tun.c, function tunwrite() (this is 7.4, but 8.2 
is nearly the same):

There is a local variable "error" which is initialized to zero and then 
seemingly never changed, until it is used as a return value if 
m_uiotombuf() fails:

...
         int             error = 0;
...
         if ((m = m_uiotombuf(uio, M_DONTWAIT, 0, 0, M_PKTHDR)) == NULL) {
                 ifp->if_ierrors++;
                 return (error);
         }
...
a little further down, we see
...
                 if (m->m_len < sizeof(family) &&
                     (m = m_pullup(m, sizeof(family))) == NULL)
                         return (ENOBUFS);
...

As far as I can see, the first return amounts to "drop the packet, but 
don't tell anything about it", whereas the second amounts to "drop the 
packet and say it's due to ENOBUFS".

However, the first case is much more like ENOBUFS, so shouldn't we 
simply say "return (ENOBUFS)" there and remove the "error" variable 
altogether?

There seem to be other functions in if_tun.c with a similar strange 
usage of an "error" variable.

Regards,

Martin




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DE7B935.9040004>