From: Victor Julien Date: Wed, 27 Mar 2024 08:43:44 +0000 (+0100) Subject: decode/tcp: reduce size needed for tracking WSCALE X-Git-Tag: suricata-8.0.0-beta1~1397 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7be0678c3ac8cb50dc039922dbb5e4bf68bda68d;p=thirdparty%2Fsuricata.git decode/tcp: reduce size needed for tracking WSCALE Part of effort to make Packet more compact. Ticket: #6938. --- diff --git a/src/decode-tcp.c b/src/decode-tcp.c index 8ad96748c4..bec8a364b5 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -89,10 +89,16 @@ static void DecodeTCPOptions(Packet *p, const uint8_t *pkt, uint16_t pktlen) if (olen != TCP_OPT_WS_LEN) { ENGINE_SET_EVENT(p,TCP_OPT_INVALID_LEN); } else { - if (p->tcpvars.ws.type != 0) { + if (p->tcpvars.wscale_set != 0) { ENGINE_SET_EVENT(p,TCP_OPT_DUPLICATE); } else { - SET_OPTS(p->tcpvars.ws, tcp_opts[tcp_opt_cnt]); + p->tcpvars.wscale_set = 1; + const uint8_t wscale = *(tcp_opts[tcp_opt_cnt].data); + if (wscale <= TCP_WSCALE_MAX) { + p->tcpvars.wscale = wscale; + } else { + p->tcpvars.wscale = 0; + } } } break; diff --git a/src/decode-tcp.h b/src/decode-tcp.h index 93d482bedd..66189b1083 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -90,16 +90,14 @@ /** macro for getting the second timestamp from the packet in host order. */ #define TCP_GET_TSECR(p) ((p)->tcpvars.ts_ecr) -#define TCP_HAS_WSCALE(p) ((p)->tcpvars.ws.type == TCP_OPT_WS) +#define TCP_HAS_WSCALE(p) ((p)->tcpvars.wscale_set) #define TCP_HAS_SACK(p) ((p)->tcpvars.sack.type == TCP_OPT_SACK) #define TCP_HAS_TS(p) ((p)->tcpvars.ts_set) #define TCP_HAS_MSS(p) ((p)->tcpvars.mss_set) #define TCP_HAS_TFO(p) ((p)->tcpvars.tfo_set) /** macro for getting the wscale from the packet. */ -#define TCP_GET_WSCALE(p) (TCP_HAS_WSCALE((p)) ? \ - (((*(uint8_t *)(p)->tcpvars.ws.data) <= TCP_WSCALE_MAX) ? \ - (*(uint8_t *)((p)->tcpvars.ws.data)) : 0) : 0) +#define TCP_GET_WSCALE(p) (p)->tcpvars.wscale #define TCP_GET_SACKOK(p) (p)->tcpvars.sack_ok #define TCP_GET_SACK_PTR(p) TCP_HAS_SACK((p)) ? (p)->tcpvars.sack.data : NULL @@ -160,12 +158,13 @@ typedef struct TCPVars_ bool sack_ok; bool mss_set; bool tfo_set; + uint8_t wscale_set : 1; + uint8_t wscale : 4; uint16_t mss; /**< MSS value in host byte order */ uint32_t ts_val; /* host-order */ uint32_t ts_ecr; /* host-order */ uint16_t stream_pkt_flags; TCPOpt sack; - TCPOpt ws; } TCPVars; #define CLEAR_TCP_PACKET(p) \