Copilot commented on code in PR #13667:
URL: https://github.com/apache/trafficserver/pull/13667#discussion_r3993764254


##########
src/iocore/net/P_UnixNetVConnection.h:
##########
@@ -304,6 +307,48 @@ UnixNetVConnection::set_mptcp_state()
 #endif
 }
 
+// Copy the TCP_INFO fields ATS reports out of the kernel.
+inline bool
+UnixNetVConnection::get_tcp_info(TcpInfoSnapshot &info) const
+{
+#if defined(TCP_INFO) && defined(HAVE_STRUCT_TCP_INFO) && \
+  (HAVE_STRUCT_TCP_INFO_TCPI_TOTAL_RETRANS || 
HAVE_STRUCT_TCP_INFO_TCPI_SND_REXMITPACK)
+  if (con.sock_type != SOCK_STREAM) {
+    return false;
+  }
+
+  struct tcp_info tinfo     = {};
+  int             tinfo_len = sizeof(tinfo);
+  int const       fd        = con.sock.get_fd();
+
+  if (0 != safe_getsockopt(fd, IPPROTO_TCP, TCP_INFO, &tinfo, &tinfo_len)) {
+    Dbg(_dbg_ctl_socket_tcp_info, "failed getsockopt(%d, TCP_INFO): %s", fd, 
strerror(errno));
+    return false;
+  }
+  if (tinfo_len != static_cast<int>(sizeof(tinfo))) {
+    return false;
+  }

Review Comment:
   `TCP_INFO` is an extensible getsockopt structure, so a kernel older than the 
headers used to build ATS can return a shorter `tinfo_len` while still 
supplying the prefix containing the fields this code reads. Requiring the 
returned length to equal the newest `sizeof(tinfo)` silently disables sampling 
on those supported kernels; validate that the returned length covers the 
specific fields being read instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to