mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
Fix endpoint lifecycle ordering and device reconfiguration
This commit is contained in:
@@ -478,10 +478,10 @@ func (e *Endpoint) readLoop(ctx context.Context) {
|
||||
err = e.device.WriteInboundBuffers(packetBuffers)
|
||||
buf.ReleaseMulti(packetBuffers)
|
||||
if err != nil {
|
||||
err = E.Cause(err, "write packet to device")
|
||||
e.logger.Error(err)
|
||||
e.setTerminalError(err)
|
||||
return
|
||||
if E.IsCanceled(err) || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
e.logger.Debug(E.Cause(err, "write packet to device"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,10 +654,10 @@ func (c *ClientEndpoint) readLoop(ctx context.Context) {
|
||||
err = c.device.WriteInboundBuffers(packetBuffers)
|
||||
buf.ReleaseMulti(packetBuffers)
|
||||
if err != nil {
|
||||
err = E.Cause(err, "write packet to device")
|
||||
c.logger.Error(err)
|
||||
c.setTerminalError(err)
|
||||
return
|
||||
if E.IsCanceled(err) || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
c.logger.Debug(E.Cause(err, "write packet to device"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,8 +627,10 @@ func (s *ServerEndpoint) readLoop(ctx context.Context) {
|
||||
err = s.device.WriteInboundBuffers(packetBuffers)
|
||||
buf.ReleaseMulti(packetBuffers)
|
||||
if err != nil {
|
||||
s.logger.Error(E.Cause(err, "write packet to device"))
|
||||
return
|
||||
if E.IsCanceled(err) || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
s.logger.Debug(E.Cause(err, "write packet to device"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (w *Endpoint) DetachReturn(returnPath tun.Return) error {
|
||||
|
||||
func (w *Endpoint) JudgeFlow(network uint8, source netip.AddrPort, destination netip.AddrPort, firstPacket []byte) tun.FlowVerdict {
|
||||
for _, localPrefix := range w.localAddresses {
|
||||
if localPrefix.Contains(destination.Addr()) {
|
||||
if destination.Addr() == localPrefix.Addr() {
|
||||
return tun.FlowVerdict{Action: tun.ActionAccept}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (w *Endpoint) NewConnectionEx(ctx context.Context, conn net.Conn, source M.
|
||||
metadata.InboundType = w.Type()
|
||||
metadata.Source = source
|
||||
for _, localPrefix := range w.localAddresses {
|
||||
if localPrefix.Contains(destination.Addr) {
|
||||
if destination.Addr == localPrefix.Addr() {
|
||||
metadata.OriginDestination = destination
|
||||
if destination.Addr.Is4() {
|
||||
destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
||||
@@ -258,7 +258,7 @@ func (w *Endpoint) NewPacketConnectionEx(ctx context.Context, conn N.PacketConn,
|
||||
metadata.Source = source
|
||||
metadata.Destination = destination
|
||||
for _, localPrefix := range w.localAddresses {
|
||||
if localPrefix.Contains(destination.Addr) {
|
||||
if destination.Addr == localPrefix.Addr() {
|
||||
metadata.OriginDestination = destination
|
||||
if destination.Addr.Is4() {
|
||||
metadata.Destination.Addr = netip.AddrFrom4([4]uint8{127, 0, 0, 1})
|
||||
|
||||
Reference in New Issue
Block a user