Add ping proxy implementation
This commit is contained in:
parent
933bd2b2d5
commit
036d61a0aa
9 changed files with 348 additions and 7 deletions
29
icmp.go
Normal file
29
icmp.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package tun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func NewICMPDestination(ctx context.Context, logger logger.Logger, dialer net.Dialer, network string, address netip.Addr, routeContext DirectRouteContext) (DirectRouteDestination, error) {
|
||||
if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
|
||||
return NewUnprivilegedICMPDestination(ctx, logger, dialer, network, address, routeContext)
|
||||
} else {
|
||||
destination, err := NewPrivilegedICMPDestination(ctx, logger, dialer, network, address, routeContext)
|
||||
if err != nil {
|
||||
if E.IsMulti(err, os.ErrPermission, unix.EPERM) {
|
||||
return NewUnprivilegedICMPDestination(ctx, logger, dialer, network, address, routeContext)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return destination, nil
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue