mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 20:11:28 +00:00
28 lines
604 B
Go
28 lines
604 B
Go
|
//go:build with_gvisor
|
||
|
|
||
|
package wireguard
|
||
|
|
||
|
import (
|
||
|
"github.com/sagernet/sing/common"
|
||
|
"github.com/sagernet/sing/common/buf"
|
||
|
|
||
|
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||
|
)
|
||
|
|
||
|
func (d *natDestinationWrapper) WritePacketBuffer(buffer *stack.PacketBuffer) error {
|
||
|
defer buffer.DecRef()
|
||
|
if d.device.writer != nil {
|
||
|
d.device.writer.RewritePacketBuffer(buffer)
|
||
|
}
|
||
|
var packetLen int
|
||
|
for _, slice := range buffer.AsSlices() {
|
||
|
packetLen += len(slice)
|
||
|
}
|
||
|
packet := buf.NewSize(packetLen)
|
||
|
for _, slice := range buffer.AsSlices() {
|
||
|
common.Must1(packet.Write(slice))
|
||
|
}
|
||
|
d.device.outbound <- packet
|
||
|
return nil
|
||
|
}
|