Add ping proxy implementation

This commit is contained in:
世界 2025-08-22 14:21:21 +08:00
parent 933bd2b2d5
commit 036d61a0aa
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
9 changed files with 348 additions and 7 deletions

View file

@ -0,0 +1,22 @@
//go:build with_gvisor
package tun
import (
"net/netip"
"github.com/sagernet/gvisor/pkg/tcpip/stack"
)
func (d *UnprivilegedICMPDestination) WritePacketBuffer(packetBuffer *stack.PacketBuffer) error {
ipHdr := packetBuffer.Network()
if !d.isIPv6 {
d.localAddr.Store(netip.AddrFrom4(ipHdr.SourceAddress().As4()))
} else {
d.localAddr.Store(netip.AddrFrom16(ipHdr.SourceAddress().As16()))
}
packetSlice := packetBuffer.TransportHeader().Slice()
packetSlice = append(packetSlice, packetBuffer.Data().AsRange().ToSlice()...)
_, err := d.rawConn.Write(packetSlice)
return err
}