github.com/flowerwrong/netstack@v0.0.0-20191009141956-e5848263af28/tcpip/link/fdbased/packet_dispatchers_linux.go (about)

     1  package fdbased
     2  
     3  import (
     4  	"syscall"
     5  
     6  	"github.com/FlowerWrong/netstack/tcpip/buffer"
     7  	"github.com/FlowerWrong/netstack/tcpip/link/rawfile"
     8  	"github.com/FlowerWrong/netstack/tcpip/stack"
     9  )
    10  
    11  func newRecvMMsgDispatcher(fd int, e *endpoint) (linkDispatcher, error) {
    12  	d := &recvMMsgDispatcher{
    13  		fd: fd,
    14  		e:  e,
    15  	}
    16  	d.views = make([][]buffer.View, MaxMsgsPerRecv)
    17  	for i := range d.views {
    18  		d.views[i] = make([]buffer.View, len(BufConfig))
    19  	}
    20  	d.iovecs = make([][]syscall.Iovec, MaxMsgsPerRecv)
    21  	iovLen := len(BufConfig)
    22  	if d.e.Capabilities()&stack.CapabilityGSO != 0 {
    23  		// virtioNetHdr is prepended before each packet.
    24  		iovLen++
    25  	}
    26  	for i := range d.iovecs {
    27  		d.iovecs[i] = make([]syscall.Iovec, iovLen)
    28  	}
    29  	d.msgHdrs = make([]rawfile.MMsgHdr, MaxMsgsPerRecv)
    30  	for i := range d.msgHdrs {
    31  		d.msgHdrs[i].Msg.Iov = &d.iovecs[i][0]
    32  		d.msgHdrs[i].Msg.Iovlen = uint64(iovLen)
    33  	}
    34  	return d, nil
    35  }