Fix windows read packet

This commit is contained in:
世界 2022-08-03 10:07:47 +08:00
parent 69bc471e19
commit 2895f49fd2
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -310,21 +310,22 @@ func (e *WintunEndpoint) dispatchLoop() {
defer common.KeepAlive(_buffer) defer common.KeepAlive(_buffer)
buffer := common.Dup(_buffer) buffer := common.Dup(_buffer)
defer buffer.Release() defer buffer.Release()
data := buffer.FreeBytes()
for { for {
n, err := e.tun.Read(buffer.FreeBytes()) n, err := e.tun.Read(data)
if err != nil { if err != nil {
break break
} }
var view gBuffer.View packet := make([]byte, n)
view.Append(buffer.To(n)) copy(packet, data[:n])
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Payload: view, Payload: gBuffer.NewWithData(packet),
IsForwardedPacket: true, IsForwardedPacket: true,
}) })
defer pkt.DecRef()
var p tcpip.NetworkProtocolNumber var p tcpip.NetworkProtocolNumber
ipHeader, ok := pkt.Data().PullUp(1) ipHeader, ok := pkt.Data().PullUp(1)
if !ok { if !ok {
pkt.DecRef()
continue continue
} }
switch header.IPVersion(ipHeader) { switch header.IPVersion(ipHeader) {
@ -336,6 +337,7 @@ func (e *WintunEndpoint) dispatchLoop() {
continue continue
} }
e.dispatcher.DeliverNetworkPacket(p, pkt) e.dispatcher.DeliverNetworkPacket(p, pkt)
pkt.DecRef()
} }
} }