From 18bcc4fe73bd8245cde001c939b400693a0d9410 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 17 Aug 2022 22:07:35 -0400 Subject: [Feature] Add TCP information (RTT and Cwnd) to Logging This patch adds support for logging the underlying RTT and Cwnd of the TCP connection used when doing probes. More work to follow in order to add support for this information on Windows and Darwin. --- extendedstats/other.go | 6 +++++- extendedstats/unix.go | 29 +++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'extendedstats') diff --git a/extendedstats/other.go b/extendedstats/other.go index b4eae18..50caef6 100644 --- a/extendedstats/other.go +++ b/extendedstats/other.go @@ -11,7 +11,7 @@ import ( type ExtendedStats struct{} func (es *ExtendedStats) IncorporateConnectionStats(conn net.Conn) error { - return fmt.Errorf("OOPS: IncorporateConnectionStats is not supported on this platform") + return fmt.Errorf("IncorporateConnectionStats is not supported on this platform") } func (es *ExtendedStats) Repr() string { @@ -21,3 +21,7 @@ func (es *ExtendedStats) Repr() string { func ExtendedStatsAvailable() bool { return false } + +func GetTCPInfo(basicConn net.Conn) (interface, error) { + return nil, fmt.Errorf("GetTCPInfo is not supported on this platform") +} diff --git a/extendedstats/unix.go b/extendedstats/unix.go index a2d4d30..3db94fc 100644 --- a/extendedstats/unix.go +++ b/extendedstats/unix.go @@ -27,20 +27,8 @@ func ExtendedStatsAvailable() bool { return true } -func (es *ExtendedStats) IncorporateConnectionStats(rawConn net.Conn) error { - tlsConn, ok := rawConn.(*tls.Conn) - if !ok { - return fmt.Errorf( - "OOPS: Could not get the TCP info for the connection (not a TLS connection)", - ) - } - tcpConn, ok := tlsConn.NetConn().(*net.TCPConn) - if !ok { - return fmt.Errorf( - "OOPS: Could not get the TCP info for the connection (not a TCP connection)", - ) - } - if info, err := getTCPInfo(tcpConn); err != nil { +func (es *ExtendedStats) IncorporateConnectionStats(basicConn net.Conn) error { + if info, err := GetTCPInfo(basicConn); err != nil { return fmt.Errorf("OOPS: Could not get the TCP info for the connection: %v", err) } else { es.MaxPathMtu = utilities.Max(es.MaxPathMtu, uint64(info.Pmtu)) @@ -67,16 +55,21 @@ func (es *ExtendedStats) Repr() string { `, es.MaxPathMtu, es.MaxSendMss, es.MaxRecvMss, es.TotalRetransmissions, es.TotalReorderings, es.AverageRtt) } -func getTCPInfo(connection net.Conn) (*unix.TCPInfo, error) { - tcpConn, ok := connection.(*net.TCPConn) +func GetTCPInfo(basicConn net.Conn) (*unix.TCPInfo, error) { + tlsConn, ok := basicConn.(*tls.Conn) if !ok { - return nil, fmt.Errorf("connection is not a net.TCPConn") + return nil, fmt.Errorf("OOPS: Outermost connection is not a TLS connection") + } + tcpConn, ok := tlsConn.NetConn().(*net.TCPConn) + if !ok { + return nil, fmt.Errorf( + "OOPS: Could not get the TCP info for the connection (not a TCP connection)", + ) } rawConn, err := tcpConn.SyscallConn() if err != nil { return nil, err } - var info *unix.TCPInfo = nil rawConn.Control(func(fd uintptr) { info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO) -- cgit v1.2.3