4545
4646#ifdef NC_ENABLED_SSH_TLS
4747
48+ #include "session_server_ssh_wrapper.h"
4849#include "session_wrapper.h"
4950
5051#include <curl/curl.h>
@@ -102,7 +103,6 @@ nc_server_endpt_get(const char *name, struct nc_endpt **endpt)
102103 }
103104 }
104105
105- ERR (NULL , "Endpoint \"%s\" not found in the configuration." , name );
106106 return 1 ;
107107}
108108
@@ -2294,6 +2294,34 @@ nc_server_send_reply_io(struct nc_session *session, int io_timeout, const struct
22942294 return ret ;
22952295}
22962296
2297+ #ifdef NC_ENABLED_SSH_TLS
2298+ /**
2299+ * @brief Scan the session ring for a newly established NETCONF SSH channel.
2300+ *
2301+ * @param[in] session Session whose SSH channel ring to scan.
2302+ * @return 1 if a new SSH channel is found, 0 otherwise.
2303+ */
2304+ static int
2305+ nc_ps_ssh_find_new_channel (struct nc_session * session )
2306+ {
2307+ struct nc_session * new ;
2308+
2309+ if (!session -> ti .libssh .next ) {
2310+ return 0 ;
2311+ }
2312+
2313+ for (new = session -> ti .libssh .next ; new != session ; new = new -> ti .libssh .next ) {
2314+ if ((new -> status == NC_STATUS_STARTING ) && new -> ti .libssh .channel &&
2315+ (new -> flags & NC_SESSION_SSH_SUBSYS_NETCONF )) {
2316+ return 1 ;
2317+ }
2318+ }
2319+
2320+ return 0 ;
2321+ }
2322+
2323+ #endif /* NC_ENABLED_SSH_TLS */
2324+
22972325/**
22982326 * @brief Poll a session from pspoll acquiring IO lock as needed.
22992327 * Session must be running and session RPC lock held!
@@ -2317,8 +2345,9 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon
23172345 uint16_t idle_timeout ;
23182346
23192347#ifdef NC_ENABLED_SSH_TLS
2348+ #if !LIBSSH_0_12
23202349 ssh_message ssh_msg ;
2321- struct nc_session * new ;
2350+ #endif
23222351#endif /* NC_ENABLED_SSH_TLS */
23232352
23242353 /* check timeout first */
@@ -2341,36 +2370,33 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon
23412370 switch (session -> ti_type ) {
23422371#ifdef NC_ENABLED_SSH_TLS
23432372 case NC_TI_SSH :
2373+ #if LIBSSH_0_12
2374+ if (nc_ps_ssh_find_new_channel (session )) {
2375+ ret = NC_PSPOLL_SSH_CHANNEL ;
2376+ break ;
2377+ }
2378+ #else
23442379 ssh_msg = ssh_message_get (session -> ti .libssh .session );
23452380 if (ssh_msg ) {
23462381 if (nc_session_ssh_msg (session , NULL , ssh_msg , NULL )) {
23472382 ssh_message_reply_default (ssh_msg );
23482383 }
2349- if (session -> ti .libssh .next ) {
2350- for (new = session -> ti .libssh .next ; new != session ; new = new -> ti .libssh .next ) {
2351- if ((new -> status == NC_STATUS_STARTING ) && new -> ti .libssh .channel &&
2352- (new -> flags & NC_SESSION_SSH_SUBSYS_NETCONF )) {
2353- /* new NETCONF SSH channel */
2354- ret = NC_PSPOLL_SSH_CHANNEL ;
2355- break ;
2356- }
2357- }
2358- if (new != session ) {
2359- ssh_message_free (ssh_msg );
2360- break ;
2361- }
2384+ if (nc_ps_ssh_find_new_channel (session )) {
2385+ ret = NC_PSPOLL_SSH_CHANNEL ;
2386+ ssh_message_free (ssh_msg );
2387+ break ;
23622388 }
23632389 if (!ret ) {
23642390 /* just some SSH message */
23652391 ret = NC_PSPOLL_SSH_MSG ;
23662392 }
23672393 ssh_message_free (ssh_msg );
2368-
23692394 /* break because 1) we don't want to return anything here ORred with NC_PSPOLL_RPC
2370- * and 2) we don't want to delay openning a new channel by waiting for a RPC to get processed
2395+ * and 2) we don't want to delay opening a new channel by waiting for a RPC to get processed
23712396 */
23722397 break ;
23732398 }
2399+ #endif
23742400
23752401 r = ssh_channel_poll_timeout (session -> ti .libssh .channel , 0 , 0 );
23762402 if (r == SSH_EOF ) {
0 commit comments