4242#include "session_p.h"
4343#include "session_server.h"
4444#include "session_server_ch.h"
45+ #include "session_server_ssh_wrapper.h"
4546
4647#ifdef NC_ENABLED_SSH_TLS
4748
@@ -2294,6 +2295,34 @@ nc_server_send_reply_io(struct nc_session *session, int io_timeout, const struct
22942295 return ret ;
22952296}
22962297
2298+ #ifdef NC_ENABLED_SSH_TLS
2299+ /**
2300+ * @brief Scan the session ring for a newly established NETCONF SSH channel.
2301+ *
2302+ * @param[in] session Session whose SSH channel ring to scan.
2303+ * @return Pointer to the new starting NETCONF session if found, NULL otherwise.
2304+ */
2305+ static struct nc_session *
2306+ nc_ps_ssh_find_new_channel (struct nc_session * session )
2307+ {
2308+ struct nc_session * new ;
2309+
2310+ if (!session -> ti .libssh .next ) {
2311+ return NULL ;
2312+ }
2313+
2314+ for (new = session -> ti .libssh .next ; new != session ; new = new -> ti .libssh .next ) {
2315+ if ((new -> status == NC_STATUS_STARTING ) && new -> ti .libssh .channel &&
2316+ (new -> flags & NC_SESSION_SSH_SUBSYS_NETCONF )) {
2317+ return new ;
2318+ }
2319+ }
2320+
2321+ return NULL ;
2322+ }
2323+
2324+ #endif /* NC_ENABLED_SSH_TLS */
2325+
22972326/**
22982327 * @brief Poll a session from pspoll acquiring IO lock as needed.
22992328 * Session must be running and session RPC lock held!
@@ -2317,8 +2346,9 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon
23172346 uint16_t idle_timeout ;
23182347
23192348#ifdef NC_ENABLED_SSH_TLS
2349+ #if !LIBSSH_0_12
23202350 ssh_message ssh_msg ;
2321- struct nc_session * new ;
2351+ #endif
23222352#endif /* NC_ENABLED_SSH_TLS */
23232353
23242354 /* check timeout first */
@@ -2341,36 +2371,33 @@ nc_ps_poll_session_io(struct nc_session *session, int io_timeout, time_t now_mon
23412371 switch (session -> ti_type ) {
23422372#ifdef NC_ENABLED_SSH_TLS
23432373 case NC_TI_SSH :
2374+ #if LIBSSH_0_12
2375+ if (nc_ps_ssh_find_new_channel (session )) {
2376+ ret = NC_PSPOLL_SSH_CHANNEL ;
2377+ break ;
2378+ }
2379+ #else
23442380 ssh_msg = ssh_message_get (session -> ti .libssh .session );
23452381 if (ssh_msg ) {
23462382 if (nc_session_ssh_msg (session , NULL , ssh_msg , NULL )) {
23472383 ssh_message_reply_default (ssh_msg );
23482384 }
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- }
2385+ if (nc_ps_ssh_find_new_channel (session )) {
2386+ ret = NC_PSPOLL_SSH_CHANNEL ;
2387+ ssh_message_free (ssh_msg );
2388+ break ;
23622389 }
23632390 if (!ret ) {
23642391 /* just some SSH message */
23652392 ret = NC_PSPOLL_SSH_MSG ;
23662393 }
23672394 ssh_message_free (ssh_msg );
2368-
23692395 /* 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
2396+ * and 2) we don't want to delay opening a new channel by waiting for a RPC to get processed
23712397 */
23722398 break ;
23732399 }
2400+ #endif
23742401
23752402 r = ssh_channel_poll_timeout (session -> ti .libssh .channel , 0 , 0 );
23762403 if (r == SSH_EOF ) {
0 commit comments