Re: Reserve space for the L2 header in BPF injected frames

2015-12-15 Thread Mike Belopuhov
On Tue, Dec 15, 2015 at 14:30 +0100, Mike Belopuhov wrote:
> Hi,
> 
> This reserves max_linkhdr bytes for a link layer header in the newly
> allocated cluster in the bpf injection path like it's done for the
> packets originating on the host itself (cf. tcp_output).  Saves us
> time doing costly pool allocations later on.
> 
> I believe this has been tested by Yasuoka-san.
> 
> OK?
> 

I must withdraw the diff.  I've just taken another look at it and
there's already an L2 header handling in this function.  I'm not
certain what led me to believe that additional code is needed here.



Reserve space for the L2 header in BPF injected frames

2015-12-15 Thread Mike Belopuhov
Hi,

This reserves max_linkhdr bytes for a link layer header in the newly
allocated cluster in the bpf injection path like it's done for the
packets originating on the host itself (cf. tcp_output).  Saves us
time doing costly pool allocations later on.

I believe this has been tested by Yasuoka-san.

OK?

diff --git sys/net/bpf.c sys/net/bpf.c
index 86f5f6d..6cdf789 100644
--- sys/net/bpf.c
+++ sys/net/bpf.c
@@ -200,17 +200,18 @@ bpf_movein(struct uio *uio, u_int linktype, struct mbuf 
**mp,
 
MGETHDR(m, M_WAIT, MT_DATA);
m->m_pkthdr.ph_ifidx = 0;
m->m_pkthdr.len = len - hlen;
 
-   if (len > MHLEN) {
-   MCLGETI(m, M_WAIT, NULL, len);
+   if (len + max_linkhdr > MHLEN) {
+   MCLGETI(m, M_WAIT, NULL, len + max_linkhdr);
if ((m->m_flags & M_EXT) == 0) {
error = ENOBUFS;
goto bad;
}
}
+   m->m_data += max_linkhdr;
m->m_len = len;
*mp = m;
 
error = uiomovei(mtod(m, caddr_t), len, uio);
if (error)