diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-02-07 14:34:15 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-02-07 15:14:27 +0900 |
commit | b2628b54fb08ff0c91b352c4cfc09923a0896027 (patch) | |
tree | 1c77df426e9636c796e4568ac5cd12114b052a9d /patch | |
parent | a9c59f744a29f921ab55518a3b2b5b5c7ca6b95d (diff) |
add -4 and -6 options to use either IPv4 or IPv6
Diffstat (limited to 'patch')
-rw-r--r-- | patch/libssh-0.10.6-2-g6f1b1e76.patch | 112 |
1 files changed, 100 insertions, 12 deletions
diff --git a/patch/libssh-0.10.6-2-g6f1b1e76.patch b/patch/libssh-0.10.6-2-g6f1b1e76.patch index 2786da8..b5c88bc 100644 --- a/patch/libssh-0.10.6-2-g6f1b1e76.patch +++ b/patch/libssh-0.10.6-2-g6f1b1e76.patch @@ -37,10 +37,18 @@ index 1fce7b76..b64d1455 100644 int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len); diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h -index 669a0a96..b6a93ac7 100644 +index 669a0a96..da5b4099 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h -@@ -402,6 +402,7 @@ enum ssh_options_e { +@@ -368,6 +368,7 @@ enum ssh_options_e { + SSH_OPTIONS_HOST, + SSH_OPTIONS_PORT, + SSH_OPTIONS_PORT_STR, ++ SSH_OPTIONS_AI_FAMILY, + SSH_OPTIONS_FD, + SSH_OPTIONS_USER, + SSH_OPTIONS_SSH_DIR, +@@ -402,6 +403,7 @@ enum ssh_options_e { SSH_OPTIONS_GSSAPI_AUTH, SSH_OPTIONS_GLOBAL_KNOWNHOSTS, SSH_OPTIONS_NODELAY, @@ -48,7 +56,7 @@ index 669a0a96..b6a93ac7 100644 SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES, SSH_OPTIONS_PROCESS_CONFIG, SSH_OPTIONS_REKEY_DATA, -@@ -833,6 +834,7 @@ LIBSSH_API const char* ssh_get_hmac_in(ssh_session session); +@@ -833,6 +835,7 @@ LIBSSH_API const char* ssh_get_hmac_in(ssh_session session); LIBSSH_API const char* ssh_get_hmac_out(ssh_session session); LIBSSH_API ssh_buffer ssh_buffer_new(void); @@ -56,7 +64,7 @@ index 669a0a96..b6a93ac7 100644 LIBSSH_API void ssh_buffer_free(ssh_buffer buffer); #define SSH_BUFFER_FREE(x) \ do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0) -@@ -843,6 +845,8 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer); +@@ -843,6 +846,8 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer); LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer); LIBSSH_API int ssh_session_set_disconnect_message(ssh_session session, const char *message); @@ -66,10 +74,18 @@ index 669a0a96..b6a93ac7 100644 #include "libssh/legacy.h" #endif diff --git a/include/libssh/session.h b/include/libssh/session.h -index 97936195..e4a7f80c 100644 +index 97936195..e4fc4fce 100644 --- a/include/libssh/session.h +++ b/include/libssh/session.h -@@ -258,6 +258,7 @@ struct ssh_session_struct { +@@ -249,6 +249,7 @@ struct ssh_session_struct { + unsigned long timeout; /* seconds */ + unsigned long timeout_usec; + uint16_t port; ++ int ai_family; + socket_t fd; + int StrictHostKeyChecking; + char compressionlevel; +@@ -258,6 +259,7 @@ struct ssh_session_struct { int flags; int exp_flags; int nodelay; @@ -204,9 +220,27 @@ index 8991e006..e0414801 100644 * @brief Ensure the buffer has at least a certain preallocated size. * diff --git a/src/connect.c b/src/connect.c -index 15cae644..e7520f40 100644 +index 15cae644..02ef43b4 100644 --- a/src/connect.c +++ b/src/connect.c +@@ -114,7 +114,7 @@ static int ssh_connect_socket_close(socket_t s) + #endif + } + +-static int getai(const char *host, int port, struct addrinfo **ai) ++static int getai(const char *host, int port, int ai_family, struct addrinfo **ai) + { + const char *service = NULL; + struct addrinfo hints; +@@ -123,7 +123,7 @@ static int getai(const char *host, int port, struct addrinfo **ai) + ZERO_STRUCT(hints); + + hints.ai_protocol = IPPROTO_TCP; +- hints.ai_family = PF_UNSPEC; ++ hints.ai_family = ai_family > 0 ? ai_family : PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if (port == 0) { @@ -156,6 +156,20 @@ static int set_tcp_nodelay(socket_t socket) sizeof(opt)); } @@ -228,6 +262,24 @@ index 15cae644..e7520f40 100644 /** * @internal * +@@ -173,7 +187,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, + struct addrinfo *ai = NULL; + struct addrinfo *itr = NULL; + +- rc = getai(host, port, &ai); ++ rc = getai(host, port, session->opts.ai_family, &ai); + if (rc != 0) { + ssh_set_error(session, SSH_FATAL, + "Failed to resolve hostname %s (%s)", +@@ -199,7 +213,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, + + SSH_LOG(SSH_LOG_PACKET, "Resolving %s", bind_addr); + +- rc = getai(bind_addr, 0, &bind_ai); ++ rc = getai(bind_addr, 0, session->opts.ai_family, &bind_ai); + if (rc != 0) { + ssh_set_error(session, SSH_FATAL, + "Failed to resolve bind address %s (%s)", @@ -256,6 +270,18 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host, } } @@ -248,7 +300,7 @@ index 15cae644..e7520f40 100644 rc = connect(s, itr->ai_addr, itr->ai_addrlen); if (rc == -1 && (errno != 0) && (errno != EINPROGRESS)) { diff --git a/src/options.c b/src/options.c -index b3ecffe1..fb966fa1 100644 +index b3ecffe1..8de24ed6 100644 --- a/src/options.c +++ b/src/options.c @@ -217,6 +217,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) @@ -259,7 +311,17 @@ index b3ecffe1..fb966fa1 100644 new->opts.config_processed = src->opts.config_processed; new->common.log_verbosity = src->common.log_verbosity; new->common.callbacks = src->common.callbacks; -@@ -458,6 +459,10 @@ int ssh_options_set_algo(ssh_session session, +@@ -268,6 +269,9 @@ int ssh_options_set_algo(ssh_session session, + * - SSH_OPTIONS_PORT_STR: + * The port to connect to (const char *). + * ++ * - SSH_OPTIONS_AI_FAMILY: ++ * The address family for connecting (int *). ++ * + * - SSH_OPTIONS_FD: + * The file descriptor to use (socket_t).\n + * \n +@@ -458,6 +462,10 @@ int ssh_options_set_algo(ssh_session session, * Set it to disable Nagle's Algorithm (TCP_NODELAY) on the * session socket. (int, 0=false) * @@ -270,7 +332,29 @@ index b3ecffe1..fb966fa1 100644 * - SSH_OPTIONS_PROCESS_CONFIG * Set it to false to disable automatic processing of per-user * and system-wide OpenSSH configuration files. LibSSH -@@ -1017,6 +1022,20 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, +@@ -571,6 +579,21 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, + session->opts.port = i & 0xffffU; + } + break; ++ case SSH_OPTIONS_AI_FAMILY: ++ if (value == NULL) { ++ session->opts.ai_family = 0; ++ ssh_set_error_invalid(session); ++ return -1; ++ } else { ++ int *x = (int *) value; ++ if (*x < 0) { ++ session->opts.ai_family = 0; ++ ssh_set_error_invalid(session); ++ return -1; ++ } ++ session->opts.ai_family = *x; ++ } ++ break; + case SSH_OPTIONS_FD: + if (value == NULL) { + session->opts.fd = SSH_INVALID_SOCKET; +@@ -1017,6 +1040,20 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0; } break; @@ -292,10 +376,14 @@ index b3ecffe1..fb966fa1 100644 if (value == NULL) { ssh_set_error_invalid(session); diff --git a/src/session.c b/src/session.c -index 8c509699..88602b6a 100644 +index 8c509699..307388e5 100644 --- a/src/session.c +++ b/src/session.c -@@ -108,6 +108,7 @@ ssh_session ssh_new(void) +@@ -105,9 +105,11 @@ ssh_session ssh_new(void) + /* OPTIONS */ + session->opts.StrictHostKeyChecking = 1; + session->opts.port = 22; ++ session->opts.ai_family = 0; session->opts.fd = -1; session->opts.compressionlevel = 7; session->opts.nodelay = 0; |