session: stricter tx checks for ct sessions

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ied4fe0f2b35eeca4e3e82fa21346de7f243aa52a
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index 1bf5d93..6d1c965 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -1131,7 +1131,7 @@
 ct_custom_tx (void *session, transport_send_params_t * sp)
 {
   session_t *s = (session_t *) session;
-  if (session_has_transport (s) || s->session_state < SESSION_STATE_READY)
+  if (session_has_transport (s))
     return 0;
   /* If event enqueued towards peer, remove from scheduler and remove
    * session tx flag, i.e., accept new tx events. Unset fifo flag now to
@@ -1267,12 +1267,22 @@
 };
 /* *INDENT-ON* */
 
+static inline int
+ct_session_can_tx (session_t *s)
+{
+  return (s->session_state == SESSION_STATE_READY ||
+	  s->session_state == SESSION_STATE_CLOSING ||
+	  s->session_state == SESSION_STATE_APP_CLOSED);
+}
+
 int
 ct_session_tx (session_t * s)
 {
   ct_connection_t *ct, *peer_ct;
   session_t *peer_s;
 
+  if (!ct_session_can_tx (s))
+    return 0;
   ct = (ct_connection_t *) session_get_transport (s);
   peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
   if (!peer_ct)