Fix support for idle conns in contemporary SSH

This commit is contained in:
Ilia Ross
2025-01-14 15:23:22 +02:00
parent aab912dccf
commit c0f69446b3
6 changed files with 55 additions and 12 deletions

View File

@ -41,7 +41,8 @@ print &ui_table_row($text{'host_user'},
&ui_opt_textbox("user", $user, 20, $text{'host_user_def'}));
# Send keep-alive packets?
$keep = &find_value("KeepAlive", $conf);
$keep = &find_value($version_number >= 3.8 ? 'ServerAliveInterval' : 'KeepAlive',
$conf);
print &ui_table_row($text{'host_keep'},
&yes_no_default_radio("keep", $keep));

View File

@ -94,9 +94,12 @@ if ($version{'type'} eq 'ssh' &&
}
# Send keepalive packets?
$keep = &find_value("KeepAlive", $conf);
$keep = &find_value($version{'number'} >= 3.8 ? 'TCPKeepAlive' : 'KeepAlive',
$conf);
print &ui_table_row($text{'net_keep'},
&ui_yesno_radio("keep", lc($keep) ne 'no'));
&ui_yesno_radio("keep", $version{'number'} >= 3.8 ?
# Defaults to 'No' Defaults to 'Yes'
lc($keep) eq 'yes' : lc($keep) ne 'no'));
# Grace time for logins
$grace = &find_value("LoginGraceTime", $conf);

View File

@ -73,7 +73,7 @@ net_idle_m=minutes
net_idle_h=hours
net_idle_d=days
net_idle_w=weeks
net_keep=Disconnect if client has crashed?
net_keep=Keep inactive clients?
net_listen=Listen on address
net_listen2=Listen on addresses
net_laddress=Address
@ -154,7 +154,7 @@ host_header=Client options for SSH host
host_name=Options for host
host_user=Login as user
host_user_def=Current login
host_keep=Disconnect if server has crashed?
host_keep=Keep idle connections?
host_hostname=Real hostname to connect to
host_hostname_def=Same as above
host_batch=Ask for password if needed?

View File

@ -50,9 +50,28 @@ else {
$in{'user'} =~ /^\S+$/ || &error($text{'host_euser'});
&save_directive("User", $conf, $in{'user'});
}
&save_directive("KeepAlive", $conf,
$in{'keep'} == 2 ? undef : $in{'keep'} ? 'yes' : 'no');
my $keep_now = $in{'keep'} == 2 ? undef : $in{'keep'};
if ($version_number >= 3.8) {
if (!defined($keep_now)) {
# Default
&save_directive("ServerAliveInterval", $conf, undef);
&save_directive("ServerAliveCountMax", $conf, undef);
}
elsif ($keep_now == 1) {
# Enabled
&save_directive("ServerAliveInterval", $conf, 60);
&save_directive("ServerAliveCountMax", $conf, 3);
}
else {
# Disabled
&save_directive("ServerAliveInterval", $conf, 0);
&save_directive("ServerAliveCountMax", $conf, undef);
}
}
else {
&save_directive("KeepAlive", $conf,
$in{'keep'} == 2 ? undef : $in{'keep'} ? 'yes' : 'no');
}
if ($in{'hostname_def'}) {
&save_directive("HostName", $conf);

View File

@ -88,7 +88,27 @@ if ($version{'type'} eq 'ssh' &&
}
}
&save_directive("KeepAlive", $conf, $in{'keep'} ? 'yes' : 'no');
# Determine if the SSH version is 3.8 or higher
my $sshv38 = $version{'number'} >= 3.8;
my $keep_alive_key = $sshv38 ? 'TCPKeepAlive' : 'KeepAlive';
my $keep_curr = &find_value($keep_alive_key, $conf);
my $keep_now = $in{'keep'} ? 'yes' : 'no';
# Check if the current keep-alive value differs from the input value
if ($keep_curr ne $keep_now) {
# Update the keep-alive value based on the input
&save_directive($keep_alive_key, $conf, $keep_now);
# Additional configuration for version 3.8 or higher
if ($sshv38) {
if ($keep_now eq 'yes') {
# Enabled
&save_directive('ClientAliveInterval', $conf, 60);
} else {
# Disabled
&save_directive('ClientAliveInterval', $conf);
}
}
}
if ($in{'grace_def'}) {
&save_directive("LoginGraceTime", $conf);

View File

@ -370,9 +370,9 @@ return ('QUIET', 'FATAL', 'ERROR', 'INFO', 'VERBOSE', 'DEBUG');
sub yes_no_default_radio
{
local ($name, $value) = @_;
return &ui_radio($name, lc($value) eq 'yes' ? 1 :
lc($value) eq 'no' ? 0 : 2,
local ($name, $val) = @_;
return &ui_radio($name, (lc($val) eq 'yes' || $val =~ /^\d+$/ && $val > 0) ? 1 :
(lc($val) eq 'no' || $val =~ /^\d+$/) ? 0 : 2,
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ],
[ 2, $text{'default'} ] ]);
}