From 2895f49fd260d2d974fce521f28d2329275b418c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 3 Aug 2022 10:07:47 +0800 Subject: [PATCH] Fix windows read packet --- tun_windows.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tun_windows.go b/tun_windows.go index 2643546..3717111 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -310,21 +310,22 @@ func (e *WintunEndpoint) dispatchLoop() { defer common.KeepAlive(_buffer) buffer := common.Dup(_buffer) defer buffer.Release() + data := buffer.FreeBytes() for { - n, err := e.tun.Read(buffer.FreeBytes()) + n, err := e.tun.Read(data) if err != nil { break } - var view gBuffer.View - view.Append(buffer.To(n)) + packet := make([]byte, n) + copy(packet, data[:n]) pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ - Payload: view, + Payload: gBuffer.NewWithData(packet), IsForwardedPacket: true, }) - defer pkt.DecRef() var p tcpip.NetworkProtocolNumber ipHeader, ok := pkt.Data().PullUp(1) if !ok { + pkt.DecRef() continue } switch header.IPVersion(ipHeader) { @@ -336,6 +337,7 @@ func (e *WintunEndpoint) dispatchLoop() { continue } e.dispatcher.DeliverNetworkPacket(p, pkt) + pkt.DecRef() } }