Add mixed stack

This commit is contained in:
世界 2023-07-23 14:19:51 +08:00
parent aa8760b454
commit 10d98f2679
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
11 changed files with 276 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import (
"unsafe"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
E "github.com/sagernet/sing/common/exceptions"
N "github.com/sagernet/sing/common/network"
@ -101,6 +102,20 @@ func (t *NativeTun) Write(p []byte) (n int, err error) {
return
}
func (t *NativeTun) CreateVectorisedWriter() N.VectorisedWriter {
return t
}
func (t *NativeTun) WriteVectorised(buffers []*buf.Buffer) error {
var packetHeader []byte
if buffers[0].Byte(0)>>4 == 4 {
packetHeader = packetHeader4[:]
} else {
packetHeader = packetHeader6[:]
}
return t.tunWriter.WriteVectorised(append([]*buf.Buffer{buf.As(packetHeader)}, buffers...))
}
func (t *NativeTun) Close() error {
flushDNSCache()
return t.tunFile.Close()