Skip to content

Commit b68d6a9

Browse files
committed
net: tcp: Adjust data length if TCP options are present
Skip the TCP options before giving the data to application. Without this, the TCP options would be passed to the application. Fixes #17055 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent eee564f commit b68d6a9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

subsys/net/ip/tcp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,24 @@ static int send_reset(struct net_context *context,
18841884
return ret;
18851885
}
18861886

1887+
static u16_t adjust_data_len(struct net_pkt *pkt, struct net_tcp_hdr *tcp_hdr,
1888+
u16_t data_len)
1889+
{
1890+
u8_t offset = tcp_hdr->offset >> 4;
1891+
1892+
/* We need to adjust the length of the data part if there
1893+
* are TCP options.
1894+
*/
1895+
if ((offset << 2) > sizeof(struct net_tcp_hdr)) {
1896+
net_pkt_skip(pkt, (offset << 2) -
1897+
sizeof(struct net_tcp_hdr));
1898+
1899+
data_len -= (offset << 2) - sizeof(struct net_tcp_hdr);
1900+
}
1901+
1902+
return data_len;
1903+
}
1904+
18871905
/* This is called when we receive data after the connection has been
18881906
* established. The core TCP logic is located here.
18891907
*
@@ -2043,6 +2061,8 @@ NET_CONN_CB(tcp_established)
20432061
* release the pkt. Otherwise, release the pkt immediately.
20442062
*/
20452063
if (data_len > 0) {
2064+
data_len = adjust_data_len(pkt, tcp_hdr, data_len);
2065+
20462066
ret = net_context_packet_received(conn, pkt, ip_hdr, proto_hdr,
20472067
context->tcp->recv_user_data);
20482068
} else if (data_len == 0U) {

0 commit comments

Comments
 (0)