Fix gvisor icmp destination

This commit is contained in:
世界 2025-08-23 16:21:48 +08:00
parent 8dbb51cfb7
commit f46791bc0d
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 24 additions and 27 deletions

View file

@ -1,6 +1,7 @@
package ping
import (
"context"
"errors"
"net/netip"
"os"
@ -16,12 +17,13 @@ import (
var _ tun.DirectRouteDestination = (*Destination)(nil)
type Destination struct {
logger logger.Logger
ctx context.Context
logger logger.ContextLogger
routeContext tun.DirectRouteContext
conn *Conn
}
func ConnectDestination(logger logger.Logger, controlFunc control.Func, address netip.Addr, routeContext tun.DirectRouteContext) (tun.DirectRouteDestination, error) {
func ConnectDestination(ctx context.Context, logger logger.ContextLogger, controlFunc control.Func, address netip.Addr, routeContext tun.DirectRouteContext) (tun.DirectRouteDestination, error) {
var (
conn *Conn
err error
@ -39,6 +41,7 @@ func ConnectDestination(logger logger.Logger, controlFunc control.Func, address
return nil, err
}
d := &Destination{
ctx: ctx,
logger: logger,
routeContext: routeContext,
conn: conn,
@ -54,13 +57,13 @@ func (d *Destination) loopRead() {
if err != nil {
buffer.Release()
if !E.IsClosed(err) {
d.logger.Error(E.Cause(err, "receive ICMP echo reply"))
d.logger.ErrorContext(d.ctx, E.Cause(err, "receive ICMP echo reply"))
}
return
}
err = d.routeContext.WritePacket(buffer.Bytes())
if err != nil {
d.logger.Error(E.Cause(err, "write ICMP echo reply"))
d.logger.Error(d.ctx, E.Cause(err, "write ICMP echo reply"))
}
buffer.Release()
}

View file

@ -12,6 +12,7 @@ import (
"github.com/sagernet/sing/common/control"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
"golang.org/x/sys/unix"
)