@@ -1232,29 +1232,43 @@ channel_pre_connecting(struct ssh *ssh, Channel *c)
12321232 c -> io_want = SSH_CHAN_IO_SOCK_W ;
12331233}
12341234
1235+ #include <linux/tcp.h>
12351236static int
12361237channel_tcpwinsz (struct ssh * ssh )
12371238{
12381239 u_int32_t tcpwinsz = 0 ;
1239- socklen_t optsz = sizeof (tcpwinsz );
12401240 int ret = -1 ;
12411241
12421242 /* if we aren't on a socket return 128KB */
12431243 if (!ssh_packet_connection_is_on_socket (ssh ))
12441244 return 128 * 1024 ;
12451245
1246+ #ifdef TCP_INFO
1247+ size_t tcpi_len ;
1248+ struct tcp_info local_tcp_info ;
1249+ tcpi_len = (size_t )sizeof (local_tcp_info );
1250+ ret = getsockopt (ssh_packet_get_connection_in (ssh ), IPPROTO_TCP , TCP_INFO ,
1251+ (void * )& local_tcp_info , (socklen_t * )& tcpi_len );
1252+ tcpwinsz = local_tcp_info .tcpi_rcv_space ;
1253+ #else
1254+ socklen_t optsz = sizeof (tcpwinsz );
12461255 ret = getsockopt (ssh_packet_get_connection_in (ssh ),
12471256 SOL_SOCKET , SO_RCVBUF , & tcpwinsz , & optsz );
1257+ #endif
1258+
12481259 /* return no more than SSHBUF_SIZE_MAX (currently 256MB) */
12491260 if ((ret == 0 ) && tcpwinsz > SSHBUF_SIZE_MAX )
12501261 tcpwinsz = SSHBUF_SIZE_MAX ;
1262+
1263+ debug ("RCV SPACE = %d, winsz = %d" , local_tcp_info .tcpi_rcv_space , tcpwinsz );
12511264 /* if the remote side is OpenSSH after version 8.8 we need to restrict
12521265 * the size of the advertised window. Now this means that any HPN to non-HPN
12531266 * connection will be window limited to 15MB of receive space. This is a
12541267 * non-optimal solution.
12551268 */
12561269
1257- if ((ssh -> compat & SSH_RESTRICT_WINDOW ) && (tcpwinsz > NON_HPN_WINDOW_MAX ))
1270+ if ((ssh -> compat & SSH_RESTRICT_WINDOW ) &&
1271+ (tcpwinsz > NON_HPN_WINDOW_MAX ))
12581272 tcpwinsz = NON_HPN_WINDOW_MAX ;
12591273 return (tcpwinsz );
12601274}
0 commit comments