From 609c60b3257df21ede1ddbfda068d3ab101571b4 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 27 Aug 2022 16:48:53 +1200 Subject: [PATCH] Implemented "set tcp nodelay" for SSH connections (#75) Can't tell if its actually doing anything but I guess no errors means success? --- kermit/k95/ckoshs.c | 6 +++++- kermit/k95/ckoshs.h | 5 ++++- kermit/k95/ckossh.c | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/kermit/k95/ckoshs.c b/kermit/k95/ckoshs.c index 4685ffb0..95fed003 100644 --- a/kermit/k95/ckoshs.c +++ b/kermit/k95/ckoshs.c @@ -89,7 +89,8 @@ ssh_parameters_t* ssh_parameters_new( char* user_known_hosts_file, char* global_known_hosts_file, char* username, char* password, char* terminal_type, int pty_width, int pty_height, char* auth_methods, char* ciphers, int heartbeat, - char* hostkey_algorithms, char* macs, char* key_exchange_methods) { + char* hostkey_algorithms, char* macs, char* key_exchange_methods, + int nodelay) { ssh_parameters_t* params; params = malloc(sizeof(ssh_parameters_t)); @@ -107,6 +108,7 @@ ssh_parameters_t* ssh_parameters_new( params->macs = NULL; params->key_exchange_methods = NULL; params->keepalive_seconds = heartbeat; + params->nodelay = nodelay; /* Copy hostname and port*/ params->hostname = _strdup(hostname); @@ -1185,6 +1187,8 @@ static int configure_session(ssh_client_state_t * state) { &state->parameters->gssapi_delegate_credentials); ssh_options_set(state->session, SSH_OPTIONS_PROCESS_CONFIG, &state->parameters->use_openssh_config); + ssh_options_set(state->session, SSH_OPTIONS_NODELAY, + &state->parameters->nodelay); if (!state->parameters->compression) { ssh_options_set(state->session, SSH_OPTIONS_COMPRESSION_C_S, "no"); ssh_options_set(state->session, SSH_OPTIONS_COMPRESSION_S_C, "no"); diff --git a/kermit/k95/ckoshs.h b/kermit/k95/ckoshs.h index fcf09c8b..f1effaba 100644 --- a/kermit/k95/ckoshs.h +++ b/kermit/k95/ckoshs.h @@ -100,6 +100,7 @@ typedef struct { char* key_exchange_methods; /* Comma separated list */ int keepalive_seconds; /* Keepalive interval in * seconds, 0 disables. */ + int nodelay; /* Set to disable nagles agorithm */ /* Allowed authentication types */ BOOL allow_password_auth; @@ -183,6 +184,7 @@ void get_current_terminal_dimensions(int* rows, int* cols); * @param hostkey_algorithms Comma-separated list of allowed hostkey algorithms * @param macs Comma-separated list of allowed macs * @param key_exchange_methods Comma-separated list of key exchange methods + * @param nodelay Set to disable Nagle's algorithm * @return A new ssh_parameters_t instance. */ ssh_parameters_t* ssh_parameters_new( @@ -192,7 +194,8 @@ ssh_parameters_t* ssh_parameters_new( char* user_known_hosts_file, char* global_known_hosts_file, char* username, char* password, char* terminal_type, int pty_width, int pty_height, char* auth_methods, char* ciphers, int heartbeat, - char* hostkey_algorithms, char* macs, char* key_exchange_methods); + char* hostkey_algorithms, char* macs, char* key_exchange_methods, + int nodelay); /** Frees the ssh_parameters_t struct and all its members. * diff --git a/kermit/k95/ckossh.c b/kermit/k95/ckossh.c index 2c0909b4..2cb63892 100644 --- a/kermit/k95/ckossh.c +++ b/kermit/k95/ckossh.c @@ -70,6 +70,7 @@ char *cksshv = "SSH support, 10.0.0, 28 July 2022"; * char* ssh2_gnh NULL SSH-2 Global Known Hosts file * int pwflg 0 Password has been supplied (/password:) * int ssh_hbt 0 Heartbeat (keepalive) setting + * int tcp_nodelay 0 Enable/disable nagle algorithm * char* pwbuf "\0" Supplied password * char* uidbuf "" Supplied username (if any) * char* ssh2_auth NULL Comma-separated list of allowed auth methods @@ -250,6 +251,7 @@ char *cksshv = "SSH support, 10.0.0, 28 July 2022"; extern char uidbuf[]; /* User ID set via /user: */ extern char pwbuf[]; /* Password set via /password: */ extern int pwflg; /* Password has been set */ +extern int tcp_nodelay; /* Enable/disable Nagle's algorithm */ int ssh_sock; /* TODO: get rid of this (unless its needed for connecting * through a proxy server?) */ @@ -491,7 +493,8 @@ int ssh_open() { ssh_hbt, /* Heartbeat in seconds */ ssh2_hka, /* Allowed host key algorithms */ ssh2_mac, /* Allowed MACs */ - ssh2_kex /* Key exchange methods */ + ssh2_kex, /* Key exchange methods */ + tcp_nodelay /* Enable/disable Nagle's algorithm */ ); if (parameters == NULL) { debug(F100, "ssh_open() - failed to construct parameters struct", "", 0);