freebsd11_network: Actually set numBytes instead of silently truncating it.
If numBytes was greater than MCLBYTES (presently 1 << 11 = 2048), then the data beyond MCLBYTES would be silently discarded instead of being written. Now, we store the result of the min_c in numBytes, so the caller knows how much was written. I turn on the printf that's commented out here and found that in practice this seems to never happen (it's larger than the ethernet limit), so it seems unlikely to fix any "transmission mysteriously failed" bugs. Also backported this to the FreeBSD 9 layer.
This commit is contained in:
parent
688153aaec
commit
a549026d25
@ -165,17 +165,19 @@ compat_write(void *cookie, off_t position, const void *buffer,
|
||||
//if_printf(ifp, "compat_write(%lld, %p, [%lu])\n", position,
|
||||
// buffer, *numBytes);
|
||||
|
||||
if (*numBytes > MHLEN)
|
||||
if (*numBytes > MHLEN) {
|
||||
mb = m_getcl(0, MT_DATA, M_PKTHDR);
|
||||
else
|
||||
*numBytes = min_c(*numBytes, (size_t)MCLBYTES);
|
||||
} else {
|
||||
mb = m_gethdr(0, MT_DATA);
|
||||
}
|
||||
|
||||
if (mb == NULL)
|
||||
return ENOBUFS;
|
||||
|
||||
// if we waited, check after if the ifp is still valid
|
||||
|
||||
mb->m_pkthdr.len = mb->m_len = min_c(*numBytes, (size_t)MCLBYTES);
|
||||
mb->m_pkthdr.len = mb->m_len = *numBytes;
|
||||
memcpy(mtod(mb, void *), buffer, mb->m_len);
|
||||
|
||||
return ifp->if_output(ifp, mb, NULL, NULL);
|
||||
|
@ -165,17 +165,19 @@ compat_write(void *cookie, off_t position, const void *buffer,
|
||||
//if_printf(ifp, "compat_write(%lld, %p, [%lu])\n", position,
|
||||
// buffer, *numBytes);
|
||||
|
||||
if (*numBytes > MHLEN)
|
||||
if (*numBytes > MHLEN) {
|
||||
mb = m_getcl(0, MT_DATA, M_PKTHDR);
|
||||
else
|
||||
*numBytes = min_c(*numBytes, (size_t)MCLBYTES);
|
||||
} else {
|
||||
mb = m_gethdr(0, MT_DATA);
|
||||
}
|
||||
|
||||
if (mb == NULL)
|
||||
return ENOBUFS;
|
||||
|
||||
// if we waited, check after if the ifp is still valid
|
||||
|
||||
mb->m_pkthdr.len = mb->m_len = min_c(*numBytes, (size_t)MCLBYTES);
|
||||
mb->m_pkthdr.len = mb->m_len = *numBytes;
|
||||
memcpy(mtod(mb, void *), buffer, mb->m_len);
|
||||
|
||||
return ifp->if_output(ifp, mb, NULL, NULL);
|
||||
|
Loading…
x
Reference in New Issue
Block a user