session: api to add new transport types
[vpp.git] / src / vnet / tcp / tcp.c
index 4a0ffc1..25a3a44 100644 (file)
@@ -707,6 +707,51 @@ tcp_connection_init_vars (tcp_connection_t * tc)
   tc->start_ts = tcp_time_now_us (tc->c_thread_index);
 }
 
+void
+tcp_init_w_buffer (tcp_connection_t * tc, vlib_buffer_t * b, u8 is_ip4)
+{
+  tcp_header_t *th = tcp_buffer_hdr (b);
+
+  tc->c_lcl_port = th->dst_port;
+  tc->c_rmt_port = th->src_port;
+  tc->c_is_ip4 = is_ip4;
+
+  if (is_ip4)
+    {
+      ip4_header_t *ip4 = vlib_buffer_get_current (b);
+      tc->c_lcl_ip4.as_u32 = ip4->dst_address.as_u32;
+      tc->c_rmt_ip4.as_u32 = ip4->src_address.as_u32;
+    }
+  else
+    {
+      ip6_header_t *ip6 = vlib_buffer_get_current (b);
+      clib_memcpy_fast (&tc->c_lcl_ip6, &ip6->dst_address,
+                       sizeof (ip6_address_t));
+      clib_memcpy_fast (&tc->c_rmt_ip6, &ip6->src_address,
+                       sizeof (ip6_address_t));
+    }
+
+  tc->irs = vnet_buffer (b)->tcp.seq_number;
+  tc->rcv_nxt = vnet_buffer (b)->tcp.seq_number + 1;
+  tc->rcv_las = tc->rcv_nxt;
+  tc->sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
+  tc->snd_wl1 = vnet_buffer (b)->tcp.seq_number;
+  tc->snd_wl2 = vnet_buffer (b)->tcp.ack_number;
+
+  /* RFC1323: TSval timestamps sent on {SYN} and {SYN,ACK}
+   * segments are used to initialize PAWS. */
+  if (tcp_opts_tstamp (&tc->rcv_opts))
+    {
+      tc->tsval_recent = tc->rcv_opts.tsval;
+      tc->tsval_recent_age = tcp_time_now ();
+    }
+
+  if (tcp_opts_wscale (&tc->rcv_opts))
+    tc->snd_wscale = tc->rcv_opts.wscale;
+
+  tc->snd_wnd = clib_net_to_host_u16 (th->window) << tc->snd_wscale;
+}
+
 static int
 tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr,
                                 u16 * lcl_port, u8 is_ip4)
@@ -1281,14 +1326,7 @@ tcp_session_send_params (transport_connection_t * trans_conn,
   /* This still works if fast retransmit is on */
   sp->tx_offset = tc->snd_nxt - tc->snd_una;
 
-  sp->flags = 0;
-  if (!tc->snd_wnd)
-    {
-      if (tcp_timer_is_active (tc, TCP_TIMER_PERSIST))
-       sp->flags = TRANSPORT_SND_F_DESCHED;
-      else
-       sp->flags = TRANSPORT_SND_F_POSTPONE;
-    }
+  sp->flags = sp->snd_space ? 0 : TRANSPORT_SND_F_DESCHED;
 
   return 0;
 }
@@ -1510,6 +1548,8 @@ const static transport_proto_vft_t tcp_proto = {
   .format_listener = format_tcp_listener_session,
   .format_half_open = format_tcp_half_open_session,
   .transport_options = {
+    .name = "tcp",
+    .short_name = "T",
     .tx_type = TRANSPORT_TX_PEEK,
     .service_type = TRANSPORT_SERVICE_VC,
   },
@@ -1540,6 +1580,13 @@ tcp_connection_tx_pacer_reset (tcp_connection_t * tc, u32 window,
                                       srtt * CLIB_US_TIME_FREQ);
 }
 
+void
+tcp_reschedule (tcp_connection_t * tc)
+{
+  if (tcp_in_cong_recovery (tc) || tcp_snd_space_inline (tc))
+    transport_connection_reschedule (&tc->connection);
+}
+
 static void
 tcp_expired_timers_dispatch (u32 * expired_timers)
 {