From: Victor Julien Date: Tue, 28 Feb 2023 14:00:09 +0000 (+0100) Subject: stream: add seq min and max; use in segment compare X-Git-Tag: suricata-7.0.0-rc2~545 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8563%2Fhead;p=thirdparty%2Fsuricata.git stream: add seq min and max; use in segment compare --- diff --git a/src/stream-tcp-inline.c b/src/stream-tcp-inline.c index c68df6f04a..80783ef035 100644 --- a/src/stream-tcp-inline.c +++ b/src/stream-tcp-inline.c @@ -85,10 +85,10 @@ int StreamTcpInlineSegmentCompare(const TcpStream *stream, SCLogDebug("pkt_end %u, seg_end %u", pkt_end, seg_end); /* get the minimal seg*_end */ - uint32_t end = (SEQ_GT(pkt_end, seg_end)) ? seg_end : pkt_end; + uint32_t end = SEQ_MIN(seg_end, pkt_end); /* and the max seq */ - uint32_t seq = (SEQ_LT(pkt_seq, seg_seq)) ? seg->seq : pkt_seq; - seq = (SEQ_GT(seq, stream->base_seq)) ? seq : stream->base_seq; + uint32_t seq = SEQ_MAX(pkt_seq, seg_seq); + seq = SEQ_MAX(seq, stream->base_seq); SCLogDebug("seq %u, end %u", seq, end); uint32_t pkt_off = seq - pkt_seq; diff --git a/src/stream-tcp-private.h b/src/stream-tcp-private.h index c148225ab1..d1a33989ba 100644 --- a/src/stream-tcp-private.h +++ b/src/stream-tcp-private.h @@ -254,6 +254,8 @@ enum TcpState { #define SEQ_LEQ(a,b) ((int32_t)((a) - (b)) <= 0) #define SEQ_GT(a,b) ((int32_t)((a) - (b)) > 0) #define SEQ_GEQ(a,b) ((int32_t)((a) - (b)) >= 0) +#define SEQ_MIN(a, b) (SEQ_LT((a), (b)) ? (a) : (b)) +#define SEQ_MAX(a, b) (SEQ_GT((a), (b)) ? (a) : (b)) #define STREAMTCP_SET_RA_BASE_SEQ(stream, seq) { \ do { \