git: 2da45e304dba - stable/14 - TCP LRO: convert TCP header fields to host byte order earlier

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Wed, 17 Apr 2024 13:42:35 UTC
The branch stable/14 has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=2da45e304dba8004f953206a6fdfc4f801478251

commit 2da45e304dba8004f953206a6fdfc4f801478251
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2024-01-29 17:41:24 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2024-04-17 13:42:13 +0000

    TCP LRO: convert TCP header fields to host byte order earlier
    
    This is a preparation for adding dtrace hooks in a follow-up commit,
    which are missing in the code path, where packets are directly queued
    to the tcpcb. The dtrace hooks expect the fields to be in host byte
    order. This only applies when TCP HPTS is used.
    No functional change intended.
    
    Reviewed by:            rscheff
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D43594
    
    (cherry picked from commit f30c7d56546b9f36e42351fb385d96e37dbac1d5)
---
 sys/netinet/tcp_lro_hpts.c               | 7 ++++---
 sys/netinet/tcp_stacks/rack_bbr_common.c | 4 ----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/sys/netinet/tcp_lro_hpts.c b/sys/netinet/tcp_lro_hpts.c
index 7724e727d5ce..84944c8db1ce 100644
--- a/sys/netinet/tcp_lro_hpts.c
+++ b/sys/netinet/tcp_lro_hpts.c
@@ -74,15 +74,15 @@ build_ack_entry(struct tcp_ackent *ae, struct tcphdr *th, struct mbuf *m,
 		ae->flags |= TSTMP_LRO;
 	else if (m->m_flags & M_TSTMP)
 		ae->flags |= TSTMP_HDWR;
-	ae->seq = ntohl(th->th_seq);
-	ae->ack = ntohl(th->th_ack);
+	ae->seq = th->th_seq;
+	ae->ack = th->th_ack;
 	ae->flags |= tcp_get_flags(th);
 	if (ts_ptr != NULL) {
 		ae->ts_value = ntohl(ts_ptr[1]);
 		ae->ts_echo = ntohl(ts_ptr[2]);
 		ae->flags |= HAS_TSTMP;
 	}
-	ae->win = ntohs(th->th_win);
+	ae->win = th->th_win;
 	ae->codepoint = iptos;
 }
 
@@ -310,6 +310,7 @@ do_bpf_strip_and_compress(struct tcpcb *tp, struct lro_ctrl *lc,
 	th = tcp_lro_get_th(m);
 
 	th->th_sum = 0;		/* TCP checksum is valid. */
+	tcp_fields_to_host(th);
 
 	/* Check if ACK can be compressed */
 	can_compress = tcp_lro_ack_valid(m, th, &ts_ptr, &other_opts);
diff --git a/sys/netinet/tcp_stacks/rack_bbr_common.c b/sys/netinet/tcp_stacks/rack_bbr_common.c
index b265e8e6f20b..4a4a8af2bd78 100644
--- a/sys/netinet/tcp_stacks/rack_bbr_common.c
+++ b/sys/netinet/tcp_stacks/rack_bbr_common.c
@@ -415,10 +415,6 @@ skip_vnet:
 				break;
 #endif
 			} /* end switch */
-			/*
-			 * Convert TCP protocol specific fields to host format.
-			 */
-			tcp_fields_to_host(th);
 			off = th->th_off << 2;
 			if (off < sizeof (struct tcphdr) || off > tlen) {
 				printf("off:%d < hdrlen:%zu || > tlen:%u -- dump\n",