application_t *app;
stream_session_t *new_s = 0;
u64 handle;
- u32 api_context = 0;
+ u32 opaque = 0;
int error = 0;
handle = stream_session_half_open_lookup_handle (&tc->lcl_ip, &tc->rmt_ip,
return -1;
}
- /* Get the app's index from the handle we stored when opening connection */
+ /* Get the app's index from the handle we stored when opening connection
+ * and the opaque (api_context for external apps) from transport session
+ * index*/
app = application_get (handle >> 32);
- api_context = tc->s_index;
+ opaque = tc->s_index;
if (!is_fail)
{
}
/* Notify client application */
- if (app->cb_fns.session_connected_callback (app->index, api_context, new_s,
+ if (app->cb_fns.session_connected_callback (app->index, opaque, new_s,
is_fail))
{
clib_warning ("failed to notify app");
tcp_connection_t *tc;
tc = tcp_half_open_connection_get (conn_index);
- tc->timers[TCP_TIMER_ESTABLISH] = TCP_TIMER_HANDLE_INVALID;
-
- ASSERT (tc->state == TCP_STATE_SYN_SENT);
- stream_session_connect_notify (&tc->connection, 1 /* fail */ );
+ if (tc)
+ {
+ ASSERT (tc->state == TCP_STATE_SYN_SENT);
+ tc->timers[TCP_TIMER_ESTABLISH] = TCP_TIMER_HANDLE_INVALID;
+ stream_session_connect_notify (&tc->connection, 1 /* fail */ );
+ }
+ else
+ {
+ tc = tcp_connection_get (conn_index, vlib_get_thread_index ());
+ ASSERT (tc->state == TCP_STATE_SYN_RCVD);
+ }
tcp_connection_cleanup (tc);
}
tc0->snd_wl2 = vnet_buffer (b0)->tcp.ack_number;
stream_session_accept_notify (&tc0->connection);
- /* Reset SYN-ACK retransmit timer */
+ /* Reset SYN-ACK retransmit and SYN_RCV establish timers */
tcp_retransmit_timer_reset (tc0);
+ tcp_timer_reset (tc0, TCP_TIMER_ESTABLISH);
break;
case TCP_STATE_ESTABLISHED:
/* We can get packets in established state here because they
/* If FIN is ACKed */
else if (tc0->snd_una == tc0->snd_una_max)
{
- ASSERT (tcp_fin (tcp0));
tc0->rcv_nxt += 1;
tc0->state = TCP_STATE_FIN_WAIT_2;
TCP_EVT_DBG (TCP_EVT_STATE_CHANGE, tc0);
- /* Stop all timers, 2MSL will be set lower */
- tcp_connection_timers_reset (tc0);
+ if (tcp_fin (tcp0))
+ {
+ /* Stop all timers, 2MSL will be set lower */
+ tcp_connection_timers_reset (tc0);
+ }
+ else
+ {
+ /* Wait for peer to finish sending its data */
+ tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE,
+ TCP_2MSL_TIME);
+ }
}
break;
case TCP_STATE_FIN_WAIT_2:
* acknowledged ("ok") but do not delete the TCB. */
if (tcp_rcv_ack (tc0, b0, tcp0, &next0, &error0))
goto drop;
-
- /* check if rtx queue is empty and ack CLOSE TODO */
break;
case TCP_STATE_CLOSE_WAIT:
/* Do the same processing as for the ESTABLISHED state. */
if (tcp_rcv_ack (tc0, b0, tcp0, &next0, &error0))
goto drop;
- /* XXX test that send queue empty */
tc0->state = TCP_STATE_TIME_WAIT;
TCP_EVT_DBG (TCP_EVT_STATE_CHANGE, tc0);
+ tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
goto drop;
break;
/* move along .. */
break;
case TCP_STATE_FIN_WAIT_1:
- tc0->state = TCP_STATE_TIME_WAIT;
- tcp_connection_timers_reset (tc0);
- tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
+ tc0->state = TCP_STATE_CLOSING;
+ tcp_make_ack (tc0, b0);
+ next0 = tcp_next_output (is_ip4);
TCP_EVT_DBG (TCP_EVT_STATE_CHANGE, tc0);
+ /* Wait for ACK but not forever */
+ tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
break;
case TCP_STATE_FIN_WAIT_2:
/* Got FIN, send ACK! */
/* Reuse buffer to make syn-ack and send */
tcp_make_synack (child0, b0);
next0 = tcp_next_output (is_ip4);
+ tcp_timer_set (child0, TCP_TIMER_ESTABLISH, TCP_SYN_RCVD_TIME);
drop:
if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))