diff --git a/stack_gvisor_udp.go b/stack_gvisor_udp.go index f91a2b3..0c96213 100644 --- a/stack_gvisor_udp.go +++ b/stack_gvisor_udp.go @@ -38,7 +38,7 @@ func NewUDPForwarder(ctx context.Context, stack *stack.Stack, handler Handler, t stack: stack, handler: handler, } - forwarder.udpNat = udpnat.New(handler, forwarder.PreparePacketConnection, timeout, true) + forwarder.udpNat = udpnat.New(handler, forwarder.PreparePacketConnection, timeout, false) return forwarder } diff --git a/stack_mixed.go b/stack_mixed.go index 8836d6b..4c0a203 100644 --- a/stack_mixed.go +++ b/stack_mixed.go @@ -130,7 +130,7 @@ func (m *Mixed) wintunLoop(winTun WinTun) { func (m *Mixed) batchLoopLinux(linuxTUN LinuxTUN, batchSize int) { packetBuffers := make([][]byte, batchSize) - writeBuffers := make([][]byte, batchSize) + writeBuffers := make([][]byte, 0, batchSize) packetSizes := make([]int, batchSize) for i := range packetBuffers { packetBuffers[i] = make([]byte, m.mtu+PacketOffset+m.frontHeadroom) diff --git a/stack_system.go b/stack_system.go index 031e87f..d834548 100644 --- a/stack_system.go +++ b/stack_system.go @@ -229,7 +229,7 @@ func (s *System) wintunLoop(winTun WinTun) { func (s *System) batchLoopLinux(linuxTUN LinuxTUN, batchSize int) { packetBuffers := make([][]byte, batchSize) - writeBuffers := make([][]byte, batchSize) + writeBuffers := make([][]byte, 0, batchSize) packetSizes := make([]int, batchSize) for i := range packetBuffers { packetBuffers[i] = make([]byte, s.mtu+s.frontHeadroom) diff --git a/tun_darwin_gvisor.go b/tun_darwin_gvisor.go index ef940c3..b506db4 100644 --- a/tun_darwin_gvisor.go +++ b/tun_darwin_gvisor.go @@ -43,12 +43,13 @@ func (t *NativeTun) WritePacket(pkt *stack.PacketBuffer) (int, error) { func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) { ep, err := fdbased.New(&fdbased.Options{ - FDs: []int{t.tunFd}, - MTU: t.options.MTU, - RXChecksumOffload: true, - PacketDispatchMode: fdbased.RecvMMsg, - MultiPendingPackets: t.options.EXP_MultiPendingPackets, - SendMsgX: t.options.EXP_SendMsgX, + FDs: []int{t.tunFd}, + MTU: t.options.MTU, + ProcessorsPerChannel: 1, + RXChecksumOffload: true, + PacketDispatchMode: fdbased.RecvMMsg, + MultiPendingPackets: t.options.EXP_MultiPendingPackets, + SendMsgX: t.options.EXP_SendMsgX, }) if err != nil { return nil, stack.NICOptions{}, err diff --git a/tun_linux_gvisor.go b/tun_linux_gvisor.go index 8adf4c5..ac4a76e 100644 --- a/tun_linux_gvisor.go +++ b/tun_linux_gvisor.go @@ -74,12 +74,13 @@ func (t *NativeTun) WritePacket(pkt *stack.PacketBuffer) (int, error) { func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) { if t.vnetHdr { ep, err := fdbased.New(&fdbased.Options{ - FDs: []int{t.tunFd}, - MTU: t.options.MTU, - GSOMaxSize: gsoMaxSize, - GRO: true, - RXChecksumOffload: true, - TXChecksumOffload: t.txChecksumOffload, + FDs: []int{t.tunFd}, + MTU: t.options.MTU, + ProcessorsPerChannel: 1, + GSOMaxSize: gsoMaxSize, + GRO: true, + RXChecksumOffload: true, + TXChecksumOffload: t.txChecksumOffload, }) if err != nil { return nil, stack.NICOptions{}, err @@ -87,10 +88,11 @@ func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) return ep, stack.NICOptions{}, nil } else { ep, err := fdbased.New(&fdbased.Options{ - FDs: []int{t.tunFd}, - MTU: t.options.MTU, - RXChecksumOffload: true, - TXChecksumOffload: t.txChecksumOffload, + FDs: []int{t.tunFd}, + MTU: t.options.MTU, + ProcessorsPerChannel: 1, + RXChecksumOffload: true, + TXChecksumOffload: t.txChecksumOffload, }) if err != nil { return nil, stack.NICOptions{}, err