2

I am creating a TCP connection from my linux program with boost.asio. I wonder how do I get the value of its congestion window (cwnd) from the program? The only way I know of is to parse /proc/net/tcp, but this does not feel right. I'd rather use a dedicated syscall to get this info.

A solution to a similar question (How to monitor cwnd and ssthresh values for a TCP connection?) suggests using TCP Probe, but it feels even less appealing.

So what is the best way to get the value of cwnd?

Mikhail
  • 20,685
  • 7
  • 70
  • 146
  • The congestion window is per side, and it is not communicated to the other side. It also changes constantly, growing until there is a problem, then shrinking before growing again. You could never get the sender's congestion window from the receiver. – Ron Maupin Jan 17 '22 at 23:19
  • I inderstand that and I only want to know _my_ congestion window _now_. – Mikhail Jan 18 '22 at 09:06
  • i think the answer to [this question](https://stackoverflow.com/questions/21960012/linux-how-to-get-tcp-socket-options-given-socket-descriptor) also answers yours – Effie Jan 18 '22 at 09:18
  • also here is [struct tcp_info](https://github.com/torvalds/linux/blob/master/include/uapi/linux/tcp.h#L214). `tcpi_snd_cwnd` (line 246) should be congestion window. – Effie Jan 18 '22 at 09:21

2 Answers2

0

I did this with netlink and INET_DIAG-sockets based on this helpful example: https://github.com/kristrev/inet-diag-example

Mikhail
  • 20,685
  • 7
  • 70
  • 146
0

It turned out getsockopt() is able to return the same tcp_info when called with TCP_INFO option:

  tcp_info tcpi = {};
  socklen_t len = sizeof(tcp_info);
  getsockopt(tcp_socket, SOL_TCP, TCP_INFO, &tcpi, &len);
  tcpi.tcpi_snd_cwnd;  // <-- CWND
Mikhail
  • 20,685
  • 7
  • 70
  • 146