From a116134e5b3bdb233123f581c05c7d29f1518394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 3 Aug 2022 19:16:50 +0800 Subject: [PATCH] Use buffer for windows packet --- tun_windows.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tun_windows.go b/tun_windows.go index 3717111..4aa27ef 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -316,11 +316,12 @@ func (e *WintunEndpoint) dispatchLoop() { if err != nil { break } - packet := make([]byte, n) - copy(packet, data[:n]) + packet := buf.NewSize(n) + common.Must1(packet.Write(data[:n])) pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ - Payload: gBuffer.NewWithData(packet), + Payload: gBuffer.NewWithData(packet.Bytes()), IsForwardedPacket: true, + OnRelease: packet.Release, }) var p tcpip.NetworkProtocolNumber ipHeader, ok := pkt.Data().PullUp(1)