some strange constructs (bugs?) in if_tun.c
Martin Birgmeier
la5lbtyi at aon.at
Thu Jun 2 16:51:08 UTC 2011
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
More information about the freebsd-hackers
mailing list