listener->c_lcl_port = clib_host_to_net_u16 (port_host_byte_order);
if (is_ip4)
- listener->c_lcl_ip4.as_u32 = ip->ip4.as_u32;
+ {
+ listener->c_lcl_ip4.as_u32 = ip->ip4.as_u32;
+ listener->c_is_ip4 = 1;
+ listener->c_proto = SESSION_TYPE_IP4_TCP;
+ }
else
- clib_memcpy (&listener->c_lcl_ip6, &ip->ip6, sizeof (ip6_address_t));
+ {
+ clib_memcpy (&listener->c_lcl_ip6, &ip->ip6, sizeof (ip6_address_t));
+ listener->c_proto = SESSION_TYPE_IP6_TCP;
+ }
listener->c_s_index = session_index;
- listener->c_proto = SESSION_TYPE_IP4_TCP;
listener->state = TCP_STATE_LISTEN;
- listener->c_is_ip4 = 1;
tcp_connection_timers_init (listener);
u16 port_host_byte_order)
{
return tcp_connection_bind (session_index, ip, port_host_byte_order, 0);
-
}
static void
void
tcp_connection_reset (tcp_connection_t * tc)
{
- if (tc->state == TCP_STATE_CLOSED)
- return;
+ switch (tc->state)
+ {
+ case TCP_STATE_SYN_RCVD:
+ /* Cleanup everything. App wasn't notified yet */
+ stream_session_delete_notify (&tc->connection);
+ tcp_connection_cleanup (tc);
+ break;
+ case TCP_STATE_SYN_SENT:
+ case TCP_STATE_ESTABLISHED:
+ case TCP_STATE_CLOSE_WAIT:
+ case TCP_STATE_FIN_WAIT_1:
+ case TCP_STATE_FIN_WAIT_2:
+ case TCP_STATE_CLOSING:
+ tc->state = TCP_STATE_CLOSED;
+
+ /* Make sure all timers are cleared */
+ tcp_connection_timers_reset (tc);
+
+ stream_session_reset_notify (&tc->connection);
+ break;
+ case TCP_STATE_CLOSED:
+ return;
+ }
- tc->state = TCP_STATE_CLOSED;
- stream_session_reset_notify (&tc->connection);
}
/**
tcp_connection_init_vars (tcp_connection_t * tc)
{
tcp_connection_timers_init (tc);
- tcp_set_snd_mss (tc);
+ tcp_init_mss (tc);
scoreboard_init (&tc->sack_sb);
tcp_cc_init (tc);
}
tc->c_lcl_port = clib_host_to_net_u16 (lcl_port);
tc->c_c_index = tc - tm->half_open_connections;
tc->c_is_ip4 = is_ip4;
+ tc->c_proto = is_ip4 ? SESSION_TYPE_IP4_TCP : SESSION_TYPE_IP6_TCP;
/* The other connection vars will be initialized after SYN ACK */
tcp_connection_timers_init (tc);
if (*state < TCP_N_STATES)
s = format (s, "%s", tcp_fsm_states[*state]);
else
- s = format (s, "UNKNOWN");
+ s = format (s, "UNKNOWN (%d (0x%x))", *state, *state);
return s;
}
format_tcp_connection (u8 * s, va_list * args)
{
tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
-
+ if (!tc)
+ return s;
if (tc->c_is_ip4)
{
s = format (s, "[#%d][%s] %U:%d->%U:%d", tc->c_thread_index, "T",
tcp_connection_t *tc;
tc = tcp_connection_get (tci, thread_index);
- return format (s, "%U", format_tcp_connection, tc);
+ if (tc)
+ return format (s, "%U", format_tcp_connection, tc);
+ else
+ return format (s, "empty");
}
u8 *
return &tc->connection;
}
+/**
+ * Compute maximum segment size for session layer.
+ *
+ * Since the result needs to be the actual data length, it first computes
+ * the tcp options to be used in the next burst and subtracts their
+ * length from the connection's snd_mss.
+ */
u16
tcp_session_send_mss (transport_connection_t * trans_conn)
{
tcp_connection_t *tc = (tcp_connection_t *) trans_conn;
+
+ /* Ensure snd_mss does accurately reflect the amount of data we can push
+ * in a segment. This also makes sure that options are updated according to
+ * the current state of the connection. */
+ tcp_update_snd_mss (tc);
+
return tc->snd_mss;
}
+always_inline u32
+tcp_round_snd_space (tcp_connection_t * tc, u32 snd_space)
+{
+ if (tc->snd_wnd < tc->snd_mss)
+ {
+ return tc->snd_wnd <= snd_space ? tc->snd_wnd : 0;
+ }
+
+ /* If we can't write at least a segment, don't try at all */
+ if (snd_space < tc->snd_mss)
+ return 0;
+
+ /* round down to mss multiple */
+ return snd_space - (snd_space % tc->snd_mss);
+}
+
/**
* Compute tx window session is allowed to fill.
*/
u32
tcp_session_send_space (transport_connection_t * trans_conn)
{
- u32 snd_space;
+ int snd_space;
tcp_connection_t *tc = (tcp_connection_t *) trans_conn;
/* If we haven't gotten dupacks or if we did and have gotten sacked bytes
* then we can still send */
- if (PREDICT_TRUE (tcp_in_fastrecovery (tc) == 0
+ if (PREDICT_TRUE (tcp_in_cong_recovery (tc) == 0
&& (tc->rcv_dupacks == 0
|| tc->sack_sb.last_sacked_bytes)))
{
snd_space = tcp_available_snd_space (tc);
+ return tcp_round_snd_space (tc, snd_space);
+ }
- /* If we can't write at least a segment, don't try at all */
- if (snd_space < tc->snd_mss)
+ if (tcp_in_recovery (tc))
+ {
+ tc->snd_nxt = tc->snd_una_max;
+ snd_space = tcp_available_wnd (tc) - tc->rtx_bytes
+ - (tc->snd_una_max - tc->snd_congestion);
+ if (snd_space <= 0 || (tc->snd_una_max - tc->snd_una) >= tc->snd_wnd)
return 0;
-
- /* round down to mss multiple */
- return snd_space - (snd_space % tc->snd_mss);
+ return tcp_round_snd_space (tc, snd_space);
}
/* If in fast recovery, send 1 SMSS if wnd allows */
tcp_initialize_timer_wheels (tcp_main_t * tm)
{
tw_timer_wheel_16t_2w_512sl_t *tw;
- vec_foreach (tw, tm->timer_wheels)
- {
+ /* *INDENT-OFF* */
+ foreach_vlib_main (({
+ tw = &tm->timer_wheels[ii];
tw_timer_wheel_init_16t_2w_512sl (tw, tcp_expired_timers_dispatch,
100e-3 /* timer period 100ms */ , ~0);
- tw->last_run_time = vlib_time_now (tm->vlib_main);
- }
+ tw->last_run_time = vlib_time_now (this_vlib_main);
+ }));
+ /* *INDENT-ON* */
}
clib_error_t *