From 957e5a6b15b4d2a269b55d293f4a5feaebabfbd6 Mon Sep 17 00:00:00 2001 From: LjhAUMEM Date: Fri, 6 Feb 2026 16:44:50 +0800 Subject: [PATCH] XICMP finalmask: Refine seq (#5652) Example: https://github.com/XTLS/Xray-core/pull/5633#issue-3881559866 --- transport/internet/finalmask/xicmp/client.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/transport/internet/finalmask/xicmp/client.go b/transport/internet/finalmask/xicmp/client.go index fa7c6a4f..5530861b 100644 --- a/transport/internet/finalmask/xicmp/client.go +++ b/transport/internet/finalmask/xicmp/client.go @@ -20,6 +20,7 @@ const ( maxPollDelay = 10 * time.Second pollDelayMultiplier = 2.0 pollLimit = 16 + windowSize = 1000 ) type packet struct { @@ -30,7 +31,6 @@ type packet struct { type seqStatus struct { needSeqByte bool seqByte byte - received bool } type xicmpConnClient struct { @@ -129,12 +129,14 @@ func (c *xicmpConnClient) encode(p []byte) ([]byte, error) { c.seqStatus[c.seq] = &seqStatus{ needSeqByte: needSeqByte, seqByte: seqByte, - received: false, } + delete(c.seqStatus, int(uint16(c.seq-windowSize))) + c.seq++ if c.seq == 65536 { + delete(c.seqStatus, int(uint16(c.seq-windowSize))) c.seq = 1 } @@ -168,16 +170,14 @@ func (c *xicmpConnClient) recvLoop() { continue } + c.mutex.Lock() seqStatus, ok := c.seqStatus[echo.Seq] + c.mutex.Unlock() if !ok { continue } - if seqStatus.received { - continue - } - if seqStatus.needSeqByte { if len(echo.Data) <= 1 { continue @@ -189,7 +189,9 @@ func (c *xicmpConnClient) recvLoop() { } if len(echo.Data) > 0 { - seqStatus.received = true + c.mutex.Lock() + delete(c.seqStatus, echo.Seq) + c.mutex.Unlock() buf := make([]byte, len(echo.Data)) copy(buf, echo.Data)