From a011b4cb702b425497331aab9ad66bbbb88d8621 Mon Sep 17 00:00:00 2001 From: Johanna Amann Date: Tue, 9 Nov 2021 15:11:27 +0000 Subject: [PATCH] Packets with TSO: address review feedback. This addresses review feedback of GH-1831 and additionally fixes one case in which PayloadLen was used in a way that would have given problematic results when TSO is enabled. --- src/IP.cc | 8 +++++++- src/IP.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/IP.cc b/src/IP.cc index 04ac1b6676..330f2b5a85 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -384,7 +384,13 @@ RecordValPtr IP_Hdr::ToPktHdrVal(RecordValPtr pkt_hdr, int sindex) const auto tcp_hdr = make_intrusive(tcp_hdr_type); int tcp_hdr_len = tp->th_off * 4; - int data_len = PayloadLen() - tcp_hdr_len; + + // account for cases in which the payload length in the TCP header is not set, + // or is set to an impossible value. In these cases, return 0. + int data_len = 0; + auto payload_len = PayloadLen(); + if ( payload_len >= tcp_hdr_len ) + data_len = payload_len - tcp_hdr_len; tcp_hdr->Assign(0, val_mgr->Port(ntohs(tp->th_sport), TRANSPORT_TCP)); tcp_hdr->Assign(1, val_mgr->Port(ntohs(tp->th_dport), TRANSPORT_TCP)); diff --git a/src/IP.h b/src/IP.h index 2b670cf72e..0488290b00 100644 --- a/src/IP.h +++ b/src/IP.h @@ -411,6 +411,9 @@ public: /** * Returns the length of the IP packet's payload (length of packet minus * header length or, for IPv6, also minus length of all extension headers). + * + * Also returns 0 if the IPv4 length field is set to zero - which is, e.g., + * the case when TCP segment offloading is enabled. */ uint16_t PayloadLen() const {