diff --git a/outbound/direct.go b/outbound/direct.go index 3925d2c8..2d3e6f84 100644 --- a/outbound/direct.go +++ b/outbound/direct.go @@ -148,7 +148,7 @@ func (h *Direct) ListenPacket(ctx context.Context, destination M.Socksaddr) (net if err != nil { return nil, err } - conn = h.loopBack.NewPacketConn(conn) + conn = h.loopBack.NewPacketConn(bufio.NewPacketConn(conn)) if originDestination != destination { conn = bufio.NewNATPacketConn(bufio.NewPacketConn(conn), destination, originDestination) } diff --git a/outbound/direct_loopback_detect.go b/outbound/direct_loopback_detect.go index 22e15cb7..41cd26bc 100644 --- a/outbound/direct_loopback_detect.go +++ b/outbound/direct_loopback_detect.go @@ -6,6 +6,7 @@ import ( "sync" M "github.com/sagernet/sing/common/metadata" + N "github.com/sagernet/sing/common/network" ) type loopBackDetector struct { @@ -40,7 +41,7 @@ func (l *loopBackDetector) NewConn(conn net.Conn) net.Conn { } } -func (l *loopBackDetector) NewPacketConn(conn net.PacketConn) net.PacketConn { +func (l *loopBackDetector) NewPacketConn(conn N.NetPacketConn) N.NetPacketConn { connAddr := M.AddrPortFromNet(conn.LocalAddr()) if !connAddr.IsValid() { return conn @@ -48,7 +49,7 @@ func (l *loopBackDetector) NewPacketConn(conn net.PacketConn) net.PacketConn { l.packetConnAccess.Lock() l.packetConnMap[connAddr] = true l.packetConnAccess.Unlock() - return &loopBackDetectPacketWrapper{PacketConn: conn, detector: l, connAddr: connAddr} + return &loopBackDetectPacketWrapper{NetPacketConn: conn, detector: l, connAddr: connAddr} } func (l *loopBackDetector) CheckConn(connAddr netip.AddrPort) bool { @@ -92,7 +93,7 @@ func (w *loopBackDetectWrapper) Upstream() any { } type loopBackDetectPacketWrapper struct { - net.PacketConn + N.NetPacketConn detector *loopBackDetector connAddr netip.AddrPort closeOnce sync.Once @@ -104,7 +105,7 @@ func (w *loopBackDetectPacketWrapper) Close() error { delete(w.detector.packetConnMap, w.connAddr) w.detector.packetConnAccess.Unlock() }) - return w.PacketConn.Close() + return w.NetPacketConn.Close() } func (w *loopBackDetectPacketWrapper) ReaderReplaceable() bool { @@ -116,7 +117,7 @@ func (w *loopBackDetectPacketWrapper) WriterReplaceable() bool { } func (w *loopBackDetectPacketWrapper) Upstream() any { - return w.PacketConn + return w.NetPacketConn } type abstractUDPConn interface {