From 10eb218fb022f435d75fa6e8e6fc6234e66f31b9 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Wed, 13 Aug 2014 21:48:47 +0800
Subject: [PATCH] Don't send SSH_MSG_UNIMPLEMENTED for keepalive responses

---
 cli-session.c    | 2 ++
 common-session.c | 5 +++++
 session.h        | 1 +
 svr-session.c    | 1 +
 4 files changed, 9 insertions(+)

diff --git a/cli-session.c b/cli-session.c
index d5ff02d0..ecefe46a 100644
--- a/cli-session.c
+++ b/cli-session.c
@@ -73,6 +73,8 @@ static const packettype cli_packettypes[] = {
 #ifdef  ENABLE_CLI_REMOTETCPFWD
 	{SSH_MSG_REQUEST_SUCCESS, cli_recv_msg_request_success}, /* client */
 	{SSH_MSG_REQUEST_FAILURE, cli_recv_msg_request_failure}, /* client */
+#else
+	{SSH_MSG_REQUEST_FAILURE, ignore_recv_msg_request_failure}, /* for keepalive */
 #endif
 	{0, 0} /* End */
 };
diff --git a/common-session.c b/common-session.c
index cebd7877..ee5f1e96 100644
--- a/common-session.c
+++ b/common-session.c
@@ -394,6 +394,11 @@ static int ident_readln(int fd, char* buf, int count) {
 	return pos+1;
 }
 
+void ignore_recv_msg_request_failure() {
+	// Do nothing
+	TRACE(("Ignored msg_request_failure"))
+}
+
 static void send_msg_keepalive() {
 	CHECKCLEARTOWRITE();
 	time_t old_time_idle = ses.last_packet_time_idle;
diff --git a/session.h b/session.h
index b09fa448..5d555faf 100644
--- a/session.h
+++ b/session.h
@@ -47,6 +47,7 @@ void session_loop(void(*loophandler)());
 void session_cleanup();
 void send_session_identification();
 void send_msg_ignore();
+void ignore_recv_msg_request_failure();
 
 void update_channel_prio();
 
diff --git a/svr-session.c b/svr-session.c
index 4d3c058a..74a7b16c 100644
--- a/svr-session.c
+++ b/svr-session.c
@@ -58,6 +58,7 @@ static const packettype svr_packettypes[] = {
 	{SSH_MSG_CHANNEL_OPEN, recv_msg_channel_open},
 	{SSH_MSG_CHANNEL_EOF, recv_msg_channel_eof},
 	{SSH_MSG_CHANNEL_CLOSE, recv_msg_channel_close},
+	{SSH_MSG_REQUEST_FAILURE, ignore_recv_msg_request_failure}, /* for keepalive */
 #ifdef USING_LISTENERS
 	{SSH_MSG_CHANNEL_OPEN_CONFIRMATION, recv_msg_channel_open_confirmation},
 	{SSH_MSG_CHANNEL_OPEN_FAILURE, recv_msg_channel_open_failure},
-- 
GitLab