Add ping proxy implementation
This commit is contained in:
parent
933bd2b2d5
commit
036d61a0aa
9 changed files with 348 additions and 7 deletions
22
icmp_privileged_gvisor.go
Normal file
22
icmp_privileged_gvisor.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//go:build with_gvisor
|
||||
|
||||
package tun
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
func (d *PrivilegedICMPDestination) 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue