moonchen commented on code in PR #13667:
URL: https://github.com/apache/trafficserver/pull/13667#discussion_r4007270700
##########
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:
This is an intentional tradeoff to keep the length validation simple. We
require an exact-size reply before reading any fields; a shorter reply leaves
all four log fields at `-1`. We understand that this can discard usable fields
when ATS is built against newer headers than the runtime kernel, and prefer
that conservative behavior here to adding field-offset calculations. Keeping
the exact-size check.
--
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]