From 5171345eb8bb1670bfb563aa7e8a11b6ce13a2aa Mon Sep 17 00:00:00 2001 From: Sergey Fionov Date: Wed, 13 Mar 2024 22:16:35 +0200 Subject: [PATCH] tcp: Fix TCP timestamps for big-endian systems Current parsing code is building reverse-order integer, and then calls htonl() to assign right value to "ts_recent" field of pcb. This works correctly on little-endian machines, where htonl() reverses bytes. However, on big-endian machines, htonl() is no-op, so bytes stay reversed. This patch fixes it by building non-reversed integer. --- src/core/tcp_in.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 1b17e40f..37c6bb61 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -1993,17 +1993,17 @@ tcp_parseopt(struct tcp_pcb *pcb) return; } /* TCP timestamp option with valid length */ - tsval = tcp_get_next_optbyte(); - tsval |= (tcp_get_next_optbyte() << 8); + tsval = (tcp_get_next_optbyte() << 24); tsval |= (tcp_get_next_optbyte() << 16); - tsval |= (tcp_get_next_optbyte() << 24); + tsval |= (tcp_get_next_optbyte() << 8); + tsval |= tcp_get_next_optbyte(); if (flags & TCP_SYN) { - pcb->ts_recent = lwip_ntohl(tsval); + pcb->ts_recent = tsval; /* Enable sending timestamps in every segment now that we know the remote host supports it. */ tcp_set_flags(pcb, TF_TIMESTAMP); } else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno + tcplen)) { - pcb->ts_recent = lwip_ntohl(tsval); + pcb->ts_recent = tsval; } /* Advance to next option (6 bytes already read) */ tcp_optidx += LWIP_TCP_OPT_LEN_TS - 6;