1

As socks5 rfc says,

A UDP association terminates when the TCP connection that the UDP ASSOCIATE request arrived on terminates.

I wonder, doesn't "the TCP connection that the UDP ASSOCIATE request arrived on" just terminate when it timeouts? As there is no more data need to be sent in that TCP connection.

Should the client send meaningless data in that TCP connection just to keep it alive while it need the UDP association?

Malt
  • 28,965
  • 9
  • 65
  • 105
badeggg
  • 13
  • 3

1 Answers1

0

I wonder, doesn't "the TCP connection that the UDP ASSOCIATE request arrived on" just terminate when it timeouts?

No. The TCP connection is kept alive as a signal that the proxied UDP socket is still valid. Without it the client has no way of knowing whether the server is still reachable or whether the UDP socket is still allocated.

Similarly, without the TCP connection the server has no other way of knowing whether the client is still connected.

Should the client send meaningless data in that TCP connection just to keep it alive while it need the UDP association?

There's no need to send meaningless data. Just keep the connection alive. TCP has a built-in keepalive mechanism which can be turned on.

Edit: It's worth pointing out that the default TCP keepalive times on both Linux and Windows is fairly long. See this question on ways of tweaking it for specific sockets.

Malt
  • 28,965
  • 9
  • 65
  • 105
  • So socks5 client should turn on keep alive option to keep the connection alive. Am I right? – badeggg Dec 14 '21 at 06:40
  • Yeah. But note that the TCP keepalive period is determined by the operating system. In some cases, you might need to tweak it to make sure keepalives are sent frequently enough. – Malt Dec 14 '21 at 07:36
  • Since you mentioned the keep alive probe frequency, I can't help ask, why the default tcp_keepalive_time value is 7200 sec? Isn't is too large? – badeggg Dec 14 '21 at 08:03
  • That's honestly a good question. I don't know how that default was chosen. – Malt Dec 14 '21 at 09:38
  • @badeggg take a look at https://stackoverflow.com/questions/12248132/how-to-change-tcp-keepalive-timer-using-python-script for ways to change the keepalive timer for specific sockets. – Malt Dec 14 '21 at 09:41
  • Thank you, I am implementing a socks5 server actually. – badeggg Dec 14 '21 at 11:11
  • @badeggg Despite its name, TCP keepalive doesn't keep the connection alive. Rather, it detects dead idle connections. – user207421 May 11 '22 at 01:02