diff --git a/stack_mixed.go b/stack_mixed.go index 36eef1e..ffab459 100644 --- a/stack_mixed.go +++ b/stack_mixed.go @@ -77,7 +77,7 @@ func (m *Mixed) tunLoop() { return } } - if darwinTUN, isDarwinTUN := m.tun.(DarwinTUN); isDarwinTUN { + if darwinTUN, isDarwinTUN := m.tun.(DarwinTUN); isDarwinTUN && m.mtu < 49152 { m.batchLoopDarwin(darwinTUN) return } diff --git a/stack_system.go b/stack_system.go index 6b2fde4..1feba5a 100644 --- a/stack_system.go +++ b/stack_system.go @@ -174,7 +174,7 @@ func (s *System) tunLoop() { return } } - if darwinTUN, isDarwinTUN := s.tun.(DarwinTUN); isDarwinTUN { + if darwinTUN, isDarwinTUN := s.tun.(DarwinTUN); isDarwinTUN && s.mtu < 49152 { s.batchLoopDarwin(darwinTUN) return } diff --git a/tun_darwin.go b/tun_darwin.go index 80e5e94..53950a6 100644 --- a/tun_darwin.go +++ b/tun_darwin.go @@ -386,6 +386,7 @@ func (t *NativeTun) BatchRead() ([]*buf.Buffer, error) { func (t *NativeTun) BatchWrite(buffers []*buf.Buffer) error { for i, buffer := range buffers { iovecs := t.iovecsOutput[i].nextIovecsOutput(buffer) + t.msgHdrsOutput[i] = rawfile.MsgHdrX{} t.msgHdrsOutput[i].Msg.Iov = &iovecs[0] t.msgHdrsOutput[i].Msg.Iovlen = 2 } diff --git a/tun_darwin_gvisor.go b/tun_darwin_gvisor.go index 6a2286d..cae8678 100644 --- a/tun_darwin_gvisor.go +++ b/tun_darwin_gvisor.go @@ -20,9 +20,7 @@ func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) if err != nil { return nil, stack.NICOptions{}, err } - var nicOptions stack.NICOptions - if t.options.MTU < 49152 { - nicOptions.QDisc = fifo.New(ep, 1, 1000) - } - return ep, nicOptions, nil + return ep, stack.NICOptions{ + QDisc: fifo.New(ep, 1, 1000), + }, nil } diff --git a/tun_linux_gvisor.go b/tun_linux_gvisor.go index 680d6f5..3e26e18 100644 --- a/tun_linux_gvisor.go +++ b/tun_linux_gvisor.go @@ -7,6 +7,10 @@ import ( "github.com/sagernet/gvisor/pkg/tcpip/stack" ) +func init() { + fdbased.BufConfig = []int{65535} +} + var _ GVisorTun = (*NativeTun)(nil) func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) {