FD.io VPP  v17.04-9-g99c0734
Vector Packet Processing
tcp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vnet/tcp/tcp.h>
17 #include <vnet/session/session.h>
18 #include <vnet/fib/fib.h>
19 #include <math.h>
20 
22 
23 static u32
24 tcp_connection_bind (u32 session_index, ip46_address_t * ip,
25  u16 port_host_byte_order, u8 is_ip4)
26 {
27  tcp_main_t *tm = &tcp_main;
28  tcp_connection_t *listener;
29 
30  pool_get (tm->listener_pool, listener);
31  memset (listener, 0, sizeof (*listener));
32 
33  listener->c_c_index = listener - tm->listener_pool;
34  listener->c_lcl_port = clib_host_to_net_u16 (port_host_byte_order);
35 
36  if (is_ip4)
37  listener->c_lcl_ip4.as_u32 = ip->ip4.as_u32;
38  else
39  clib_memcpy (&listener->c_lcl_ip6, &ip->ip6, sizeof (ip6_address_t));
40 
41  listener->c_s_index = session_index;
42  listener->c_proto = SESSION_TYPE_IP4_TCP;
43  listener->state = TCP_STATE_LISTEN;
44  listener->c_is_ip4 = 1;
45 
46  tcp_connection_timers_init (listener);
47 
48  TCP_EVT_DBG (TCP_EVT_BIND, listener);
49 
50  return listener->c_c_index;
51 }
52 
53 u32
54 tcp_session_bind_ip4 (u32 session_index, ip46_address_t * ip,
55  u16 port_host_byte_order)
56 {
57  return tcp_connection_bind (session_index, ip, port_host_byte_order, 1);
58 }
59 
60 u32
61 tcp_session_bind_ip6 (u32 session_index, ip46_address_t * ip,
62  u16 port_host_byte_order)
63 {
64  return tcp_connection_bind (session_index, ip, port_host_byte_order, 0);
65 
66 }
67 
68 static void
69 tcp_connection_unbind (u32 listener_index)
70 {
72  TCP_EVT_DBG (TCP_EVT_UNBIND,
73  pool_elt_at_index (tm->listener_pool, listener_index));
74  pool_put_index (tm->listener_pool, listener_index);
75 }
76 
77 u32
78 tcp_session_unbind (u32 listener_index)
79 {
80  tcp_connection_unbind (listener_index);
81  return 0;
82 }
83 
85 tcp_session_get_listener (u32 listener_index)
86 {
88  tcp_connection_t *tc;
89  tc = pool_elt_at_index (tm->listener_pool, listener_index);
90  return &tc->connection;
91 }
92 
93 /**
94  * Cleans up connection state.
95  *
96  * No notifications.
97  */
98 void
100 {
101  tcp_main_t *tm = &tcp_main;
102  u32 tepi;
104 
105  /* Cleanup local endpoint if this was an active connect */
106  tepi = transport_endpoint_lookup (&tm->local_endpoints_table, &tc->c_lcl_ip,
107  tc->c_lcl_port);
108 
109  /*XXX lock */
111  {
112  tep = pool_elt_at_index (tm->local_endpoints, tepi);
113  transport_endpoint_table_del (&tm->local_endpoints_table, tep);
114  pool_put (tm->local_endpoints, tep);
115  }
116 
117  /* Make sure all timers are cleared */
119 
120  /* Check if half-open */
121  if (tc->state == TCP_STATE_SYN_SENT)
122  pool_put (tm->half_open_connections, tc);
123  else
124  pool_put (tm->connections[tc->c_thread_index], tc);
125 }
126 
127 /**
128  * Connection removal.
129  *
130  * This should be called only once connection enters CLOSED state. Note
131  * that it notifies the session of the removal event, so if the goal is to
132  * just remove the connection, call tcp_connection_cleanup instead.
133  */
134 void
136 {
137  TCP_EVT_DBG (TCP_EVT_DELETE, tc);
138  stream_session_delete_notify (&tc->connection);
140 }
141 
142 /** Notify session that connection has been reset.
143  *
144  * Switch state to closed and wait for session to call cleanup.
145  */
146 void
148 {
149  if (tc->state == TCP_STATE_CLOSED)
150  return;
151 
152  tc->state = TCP_STATE_CLOSED;
153  stream_session_reset_notify (&tc->connection);
154 }
155 
156 /**
157  * Begin connection closing procedure.
158  *
159  * If at the end the connection is not in CLOSED state, it is not removed.
160  * Instead, we rely on on TCP to advance through state machine to either
161  * 1) LAST_ACK (passive close) whereby when the last ACK is received
162  * tcp_connection_del is called. This notifies session of the delete and
163  * calls cleanup.
164  * 2) TIME_WAIT (active close) whereby after 2MSL the 2MSL timer triggers
165  * and cleanup is called.
166  *
167  * N.B. Half-close connections are not supported
168  */
169 void
171 {
172  TCP_EVT_DBG (TCP_EVT_CLOSE, tc);
173 
174  /* Send FIN if needed */
175  if (tc->state == TCP_STATE_ESTABLISHED || tc->state == TCP_STATE_SYN_RCVD
176  || tc->state == TCP_STATE_CLOSE_WAIT)
177  tcp_send_fin (tc);
178 
179  /* Switch state */
180  if (tc->state == TCP_STATE_ESTABLISHED || tc->state == TCP_STATE_SYN_RCVD)
181  tc->state = TCP_STATE_FIN_WAIT_1;
182  else if (tc->state == TCP_STATE_SYN_SENT)
183  tc->state = TCP_STATE_CLOSED;
184  else if (tc->state == TCP_STATE_CLOSE_WAIT)
185  tc->state = TCP_STATE_LAST_ACK;
186 
187  /* If in CLOSED and WAITCLOSE timer is not set, delete connection now */
188  if (tc->timers[TCP_TIMER_WAITCLOSE] == TCP_TIMER_HANDLE_INVALID
189  && tc->state == TCP_STATE_CLOSED)
190  tcp_connection_del (tc);
191 }
192 
193 void
194 tcp_session_close (u32 conn_index, u32 thread_index)
195 {
196  tcp_connection_t *tc;
197  tc = tcp_connection_get (conn_index, thread_index);
199 }
200 
201 void
202 tcp_session_cleanup (u32 conn_index, u32 thread_index)
203 {
204  tcp_connection_t *tc;
205  tc = tcp_connection_get (conn_index, thread_index);
206 
207  /* Wait for the session tx events to clear */
208  tc->state = TCP_STATE_CLOSED;
209  tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME);
210 }
211 
212 void *
213 ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4)
214 {
217  ip_interface_address_t *ia = 0;
218 
219  if (is_ip4)
220  {
221  /* *INDENT-OFF* */
222  foreach_ip_interface_address (lm4, ia, sw_if_index, 1 /* unnumbered */ ,
223  ({
224  return ip_interface_address_get_address (lm4, ia);
225  }));
226  /* *INDENT-ON* */
227  }
228  else
229  {
230  /* *INDENT-OFF* */
231  foreach_ip_interface_address (lm6, ia, sw_if_index, 1 /* unnumbered */ ,
232  ({
233  return ip_interface_address_get_address (lm6, ia);
234  }));
235  /* *INDENT-ON* */
236  }
237 
238  return 0;
239 }
240 
241 #define PORT_MASK ((1 << 16)- 1)
242 /**
243  * Allocate local port and add if successful add entry to local endpoint
244  * table to mark the pair as used.
245  */
246 u16
247 tcp_allocate_local_port (tcp_main_t * tm, ip46_address_t * ip)
248 {
250  u32 time_now, tei;
251  u16 min = 1024, max = 65535; /* XXX configurable ? */
252  int tries;
253 
254  tries = max - min;
255  time_now = tcp_time_now ();
256 
257  /* Start at random point or max */
258  pool_get (tm->local_endpoints, tep);
259  clib_memcpy (&tep->ip, ip, sizeof (*ip));
260 
261  /* Search for first free slot */
262  for (; tries >= 0; tries--)
263  {
264  u16 port = 0;
265 
266  /* Find a port in the specified range */
267  while (1)
268  {
269  port = random_u32 (&time_now) & PORT_MASK;
270  if (PREDICT_TRUE (port >= min && port < max))
271  break;
272  }
273 
274  tep->port = port;
275 
276  /* Look it up */
277  tei = transport_endpoint_lookup (&tm->local_endpoints_table, &tep->ip,
278  tep->port);
279  /* If not found, we're done */
281  {
282  transport_endpoint_table_add (&tm->local_endpoints_table, tep,
283  tep - tm->local_endpoints);
284  return tep->port;
285  }
286  }
287  /* No free ports */
288  pool_put (tm->local_endpoints, tep);
289  return -1;
290 }
291 
292 /**
293  * Initialize all connection timers as invalid
294  */
295 void
297 {
298  int i;
299 
300  /* Set all to invalid */
301  for (i = 0; i < TCP_N_TIMERS; i++)
302  {
303  tc->timers[i] = TCP_TIMER_HANDLE_INVALID;
304  }
305 
306  tc->rto = TCP_RTO_INIT;
307 }
308 
309 /**
310  * Stop all connection timers
311  */
312 void
314 {
315  int i;
316  for (i = 0; i < TCP_N_TIMERS; i++)
317  {
318  tcp_timer_reset (tc, i);
319  }
320 }
321 
322 /** Initialize tcp connection variables
323  *
324  * Should be called after having received a msg from the peer, i.e., a SYN or
325  * a SYNACK, such that connection options have already been exchanged. */
326 void
328 {
330  tcp_set_snd_mss (tc);
331  tc->sack_sb.head = TCP_INVALID_SACK_HOLE_INDEX;
332  tcp_cc_init (tc);
333 }
334 
335 int
336 tcp_connection_open (ip46_address_t * rmt_addr, u16 rmt_port, u8 is_ip4)
337 {
338  tcp_main_t *tm = vnet_get_tcp_main ();
339  tcp_connection_t *tc;
340  fib_prefix_t prefix;
341  u32 fei, sw_if_index;
342  ip46_address_t lcl_addr;
343  u16 lcl_port;
344 
345  /*
346  * Find the local address and allocate port
347  */
348  memset (&lcl_addr, 0, sizeof (lcl_addr));
349 
350  /* Find a FIB path to the destination */
351  clib_memcpy (&prefix.fp_addr, rmt_addr, sizeof (*rmt_addr));
352  prefix.fp_proto = is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
353  prefix.fp_len = is_ip4 ? 32 : 128;
354 
355  fei = fib_table_lookup (0, &prefix);
356 
357  /* Couldn't find route to destination. Bail out. */
358  if (fei == FIB_NODE_INDEX_INVALID)
359  return -1;
360 
361  sw_if_index = fib_entry_get_resolving_interface (fei);
362 
363  if (sw_if_index == (u32) ~ 0)
364  return -1;
365 
366  if (is_ip4)
367  {
368  ip4_address_t *ip4;
369  ip4 = ip_interface_get_first_ip (sw_if_index, 1);
370  lcl_addr.ip4.as_u32 = ip4->as_u32;
371  }
372  else
373  {
374  ip6_address_t *ip6;
375  ip6 = ip_interface_get_first_ip (sw_if_index, 0);
376  clib_memcpy (&lcl_addr.ip6, ip6, sizeof (*ip6));
377  }
378 
379  /* Allocate source port */
380  lcl_port = tcp_allocate_local_port (tm, &lcl_addr);
381  if (lcl_port < 1)
382  {
383  clib_warning ("Failed to allocate src port");
384  return -1;
385  }
386 
387  /*
388  * Create connection and send SYN
389  */
390 
391  pool_get (tm->half_open_connections, tc);
392  memset (tc, 0, sizeof (*tc));
393 
394  clib_memcpy (&tc->c_rmt_ip, rmt_addr, sizeof (ip46_address_t));
395  clib_memcpy (&tc->c_lcl_ip, &lcl_addr, sizeof (ip46_address_t));
396  tc->c_rmt_port = clib_host_to_net_u16 (rmt_port);
397  tc->c_lcl_port = clib_host_to_net_u16 (lcl_port);
398  tc->c_c_index = tc - tm->half_open_connections;
399  tc->c_is_ip4 = is_ip4;
400 
401  /* The other connection vars will be initialized after SYN ACK */
403 
404  tcp_send_syn (tc);
405 
406  tc->state = TCP_STATE_SYN_SENT;
407 
408  TCP_EVT_DBG (TCP_EVT_OPEN, tc);
409 
410  return tc->c_c_index;
411 }
412 
413 int
414 tcp_session_open_ip4 (ip46_address_t * addr, u16 port)
415 {
416  return tcp_connection_open (addr, port, 1);
417 }
418 
419 int
420 tcp_session_open_ip6 (ip46_address_t * addr, u16 port)
421 {
422  return tcp_connection_open (addr, port, 0);
423 }
424 
425 const char *tcp_dbg_evt_str[] = {
426 #define _(sym, str) str,
428 #undef _
429 };
430 
431 const char *tcp_fsm_states[] = {
432 #define _(sym, str) str,
434 #undef _
435 };
436 
437 u8 *
438 format_tcp_state (u8 * s, va_list * args)
439 {
440  tcp_state_t *state = va_arg (*args, tcp_state_t *);
441 
442  if (*state < TCP_N_STATES)
443  s = format (s, "%s", tcp_fsm_states[*state]);
444  else
445  s = format (s, "UNKNOWN");
446 
447  return s;
448 }
449 
450 const char *tcp_conn_timers[] = {
451 #define _(sym, str) str,
453 #undef _
454 };
455 
456 u8 *
457 format_tcp_timers (u8 * s, va_list * args)
458 {
459  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
460  int i, last = 0;
461 
462  for (i = 0; i < TCP_N_TIMERS; i++)
463  if (tc->timers[i] != TCP_TIMER_HANDLE_INVALID)
464  last = i;
465 
466  s = format (s, "[");
467  for (i = 0; i < last; i++)
468  {
469  if (tc->timers[i] != TCP_TIMER_HANDLE_INVALID)
470  s = format (s, "%s,", tcp_conn_timers[i]);
471  }
472 
473  if (last > 0)
474  s = format (s, "%s]", tcp_conn_timers[i]);
475  else
476  s = format (s, "]");
477 
478  return s;
479 }
480 
481 u8 *
482 format_tcp_connection (u8 * s, va_list * args)
483 {
484  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
485 
486  if (tc->c_is_ip4)
487  {
488  s = format (s, "[#%d][%s] %U:%d->%U:%d", tc->c_thread_index, "T",
489  format_ip4_address, &tc->c_lcl_ip4,
490  clib_net_to_host_u16 (tc->c_lcl_port), format_ip4_address,
491  &tc->c_rmt_ip4, clib_net_to_host_u16 (tc->c_rmt_port));
492  }
493  else
494  {
495  s = format (s, "[#%d][%s] %U:%d->%U:%d", tc->c_thread_index, "T",
496  format_ip6_address, &tc->c_lcl_ip6,
497  clib_net_to_host_u16 (tc->c_lcl_port), format_ip6_address,
498  &tc->c_rmt_ip6, clib_net_to_host_u16 (tc->c_rmt_port));
499  }
500 
501  return s;
502 }
503 
504 u8 *
505 format_tcp_connection_verbose (u8 * s, va_list * args)
506 {
507  tcp_connection_t *tc = va_arg (*args, tcp_connection_t *);
508  s = format (s, "%U %U %U", format_tcp_connection, tc, format_tcp_state,
509  &tc->state, format_tcp_timers, tc);
510  return s;
511 }
512 
513 u8 *
514 format_tcp_session (u8 * s, va_list * args)
515 {
516  u32 tci = va_arg (*args, u32);
517  u32 thread_index = va_arg (*args, u32);
518  tcp_connection_t *tc;
519 
520  tc = tcp_connection_get (tci, thread_index);
521  return format (s, "%U", format_tcp_connection, tc);
522 }
523 
524 u8 *
525 format_tcp_listener_session (u8 * s, va_list * args)
526 {
527  u32 tci = va_arg (*args, u32);
529  return format (s, "%U", format_tcp_connection, tc);
530 }
531 
532 u8 *
533 format_tcp_half_open_session (u8 * s, va_list * args)
534 {
535  u32 tci = va_arg (*args, u32);
537  return format (s, "%U", format_tcp_connection, tc);
538 }
539 
541 tcp_session_get_transport (u32 conn_index, u32 thread_index)
542 {
543  tcp_connection_t *tc = tcp_connection_get (conn_index, thread_index);
544  return &tc->connection;
545 }
546 
549 {
551  return &tc->connection;
552 }
553 
554 u16
556 {
557  tcp_connection_t *tc = (tcp_connection_t *) trans_conn;
558  return tc->snd_mss;
559 }
560 
561 u32
563 {
564  tcp_connection_t *tc = (tcp_connection_t *) trans_conn;
565  return tcp_available_snd_space (tc);
566 }
567 
568 u32
570 {
571  tcp_connection_t *tc = (tcp_connection_t *) trans_conn;
572  return (tc->snd_nxt - tc->snd_una);
573 }
574 
575 /* *INDENT-OFF* */
577  .bind = tcp_session_bind_ip4,
578  .unbind = tcp_session_unbind,
579  .push_header = tcp_push_header,
580  .get_connection = tcp_session_get_transport,
581  .get_listener = tcp_session_get_listener,
582  .get_half_open = tcp_half_open_session_get_transport,
583  .open = tcp_session_open_ip4,
584  .close = tcp_session_close,
585  .cleanup = tcp_session_cleanup,
586  .send_mss = tcp_session_send_mss,
587  .send_space = tcp_session_send_space,
588  .tx_fifo_offset = tcp_session_tx_fifo_offset,
589  .format_connection = format_tcp_session,
590  .format_listener = format_tcp_listener_session,
591  .format_half_open = format_tcp_half_open_session,
592 };
593 
595  .bind = tcp_session_bind_ip6,
596  .unbind = tcp_session_unbind,
597  .push_header = tcp_push_header,
598  .get_connection = tcp_session_get_transport,
599  .get_listener = tcp_session_get_listener,
600  .get_half_open = tcp_half_open_session_get_transport,
601  .open = tcp_session_open_ip6,
602  .close = tcp_session_close,
603  .cleanup = tcp_session_cleanup,
604  .send_mss = tcp_session_send_mss,
605  .send_space = tcp_session_send_space,
606  .tx_fifo_offset = tcp_session_tx_fifo_offset,
607  .format_connection = format_tcp_session,
608  .format_listener = format_tcp_listener_session,
609  .format_half_open = format_tcp_half_open_session,
610 };
611 /* *INDENT-ON* */
612 
613 void
615 {
616  u32 cpu_index = os_get_cpu_number ();
617  tcp_connection_t *tc;
618 
619  tc = tcp_connection_get (conn_index, cpu_index);
620  tc->timers[TCP_TIMER_KEEP] = TCP_TIMER_HANDLE_INVALID;
621 
623 }
624 
625 void
627 {
628  tcp_connection_t *tc;
629  u8 sst;
630 
631  tc = tcp_half_open_connection_get (conn_index);
632  tc->timers[TCP_TIMER_ESTABLISH] = TCP_TIMER_HANDLE_INVALID;
633 
634  ASSERT (tc->state == TCP_STATE_SYN_SENT);
635 
636  sst = tc->c_is_ip4 ? SESSION_TYPE_IP4_TCP : SESSION_TYPE_IP6_TCP;
637  stream_session_connect_notify (&tc->connection, sst, 1 /* fail */ );
638 
640 }
641 
642 void
644 {
645  u32 cpu_index = os_get_cpu_number ();
646  tcp_connection_t *tc;
647 
648  tc = tcp_connection_get (conn_index, cpu_index);
649  tc->timers[TCP_TIMER_WAITCLOSE] = TCP_TIMER_HANDLE_INVALID;
650 
651  /* Session didn't come back with a close(). Send FIN either way
652  * and switch to LAST_ACK. */
653  if (tc->state == TCP_STATE_CLOSE_WAIT)
654  {
655  if (tc->flags & TCP_CONN_FINSNT)
656  {
657  clib_warning ("FIN was sent and still in CLOSE WAIT. Weird!");
658  }
659 
660  tcp_send_fin (tc);
661  tc->state = TCP_STATE_LAST_ACK;
662 
663  /* Make sure we don't wait in LAST ACK forever */
664  tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
665 
666  /* Don't delete the connection yet */
667  return;
668  }
669 
670  tcp_connection_del (tc);
671 }
672 
673 /* *INDENT-OFF* */
675 {
678  0,
683 };
684 /* *INDENT-ON* */
685 
686 static void
688 {
689  int i;
690  u32 connection_index, timer_id;
691 
692  for (i = 0; i < vec_len (expired_timers); i++)
693  {
694  /* Get session index and timer id */
695  connection_index = expired_timers[i] & 0x0FFFFFFF;
696  timer_id = expired_timers[i] >> 28;
697 
698  TCP_EVT_DBG (TCP_EVT_TIMER_POP, connection_index, timer_id);
699 
700  /* Handle expiration */
701  (*timer_expiration_handlers[timer_id]) (connection_index);
702  }
703 }
704 
705 void
707 {
708  tw_timer_wheel_16t_2w_512sl_t *tw;
709  vec_foreach (tw, tm->timer_wheels)
710  {
711  tw_timer_wheel_init_16t_2w_512sl (tw, tcp_expired_timers_dispatch,
712  100e-3 /* timer period 100ms */ , ~0);
713  tw->last_run_time = vlib_time_now (tm->vlib_main);
714  }
715 }
716 
717 clib_error_t *
719 {
720  tcp_main_t *tm = vnet_get_tcp_main ();
721  ip_protocol_info_t *pi;
722  ip_main_t *im = &ip_main;
724  clib_error_t *error = 0;
725  u32 num_threads;
726 
727  if ((error = vlib_call_init_function (vm, ip_main_init)))
728  return error;
729  if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
730  return error;
731  if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
732  return error;
733 
734  /*
735  * Registrations
736  */
737 
738  /* Register with IP */
739  pi = ip_get_protocol_info (im, IP_PROTOCOL_TCP);
740  if (pi == 0)
741  return clib_error_return (0, "TCP protocol info AWOL");
744 
745  ip4_register_protocol (IP_PROTOCOL_TCP, tcp4_input_node.index);
746 
747  /* Register as transport with URI */
748  session_register_transport (SESSION_TYPE_IP4_TCP, &tcp4_proto);
749  session_register_transport (SESSION_TYPE_IP6_TCP, &tcp6_proto);
750 
751  /*
752  * Initialize data structures
753  */
754 
755  num_threads = 1 /* main thread */ + vtm->n_threads;
756  vec_validate (tm->connections, num_threads - 1);
757 
758  /* Initialize per worker thread tx buffers (used for control messages) */
759  vec_validate (tm->tx_buffers, num_threads - 1);
760 
761  /* Initialize timer wheels */
762  vec_validate (tm->timer_wheels, num_threads - 1);
764 
765  vec_validate (tm->delack_connections, num_threads - 1);
766 
767  /* Initialize clocks per tick for TCP timestamp. Used to compute
768  * monotonically increasing timestamps. */
769  tm->tstamp_ticks_per_clock = vm->clib_time.seconds_per_clock
771 
772  clib_bihash_init_24_8 (&tm->local_endpoints_table, "local endpoint table",
773  200000 /* $$$$ config parameter nbuckets */ ,
774  (64 << 20) /*$$$ config parameter table size */ );
775 
776  return error;
777 }
778 
779 clib_error_t *
781 {
782  if (is_en)
783  {
784  if (tcp_main.is_enabled)
785  return 0;
786 
787  return tcp_main_enable (vm);
788  }
789  else
790  {
791  tcp_main.is_enabled = 0;
792  }
793 
794  return 0;
795 }
796 
797 clib_error_t *
799 {
800  tcp_main_t *tm = vnet_get_tcp_main ();
801 
802  tm->vlib_main = vm;
803  tm->vnet_main = vnet_get_main ();
804  tm->is_enabled = 0;
805 
806  return 0;
807 }
808 
810 
811 /*
812  * fd.io coding-style-patch-verification: ON
813  *
814  * Local Variables:
815  * eval: (c-set-style "gnu")
816  * End:
817  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:436
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:417
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
#define TCP_2MSL_TIME
Definition: tcp.h:92
void tcp_timer_keep_handler(u32 conn_index)
Definition: tcp.c:614
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
const char * tcp_fsm_states[]
Definition: tcp.c:431
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
Definition: tcp.c:213
void stream_session_connect_notify(transport_connection_t *tc, u8 sst, u8 is_fail)
Definition: session.c:967
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
struct _transport_connection transport_connection_t
u32 tcp_session_unbind(u32 listener_index)
Definition: tcp.c:78
#define PREDICT_TRUE(x)
Definition: clib.h:98
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:185
static tcp_connection_t * tcp_half_open_connection_get(u32 conn_index)
Definition: tcp.h:369
struct _tcp_main tcp_main_t
void tcp_connection_timers_reset(tcp_connection_t *tc)
Stop all connection timers.
Definition: tcp.c:313
timer_expiration_handler tcp_timer_retransmit_handler
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
ip_lookup_main_t lookup_main
Definition: ip4.h:109
struct _tcp_connection tcp_connection_t
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
clib_time_t clib_time
Definition: main.h:62
Definition: ip.h:106
transport_connection_t * tcp_half_open_session_get_transport(u32 conn_index)
Definition: tcp.c:548
u16 tcp_allocate_local_port(tcp_main_t *tm, ip46_address_t *ip)
Allocate local port and add if successful add entry to local endpoint table to mark the pair as used...
Definition: tcp.c:247
void tcp_timer_establish_handler(u32 conn_index)
Definition: tcp.c:626
void ip4_register_protocol(u32 protocol, u32 node_index)
Definition: ip4_forward.c:1932
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:200
static u32 tcp_available_snd_space(const tcp_connection_t *tc)
Definition: tcp.h:432
u32 tcp_session_tx_fifo_offset(transport_connection_t *trans_conn)
Definition: tcp.c:569
#define TCP_RTO_INIT
Definition: tcp.h:99
format_function_t format_ip4_address
Definition: format.h:79
unformat_function_t * unformat_pg_edit
Definition: ip.h:87
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
void tcp_connection_timers_init(tcp_connection_t *tc)
Initialize all connection timers as invalid.
Definition: tcp.c:296
tcp_main_t tcp_main
Definition: tcp.c:21
void transport_endpoint_table_del(transport_endpoint_table_t *ht, transport_endpoint_t *te)
Definition: transport.c:51
static void tcp_connection_unbind(u32 listener_index)
Definition: tcp.c:69
clib_error_t * tcp_main_enable(vlib_main_t *vm)
Definition: tcp.c:718
Aggregrate type for a prefix.
Definition: fib_types.h:160
enum _tcp_state tcp_state_t
#define clib_error_return(e, args...)
Definition: error.h:111
void stream_session_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
Definition: session.c:1097
timer_expiration_handler tcp_timer_retransmit_syn_handler
static u32 tcp_time_now(void)
Definition: tcp.h:448
u16 fp_len
The mask length.
Definition: fib_types.h:164
#define vlib_call_init_function(vm, x)
Definition: init.h:162
u32 tcp_session_bind_ip4(u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
Definition: tcp.c:54
#define TCP_EVT_DBG(_evt, _args...)
Definition: tcp_debug.h:302
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
Definition: fib_table.c:66
u8 * format_tcp_connection_verbose(u8 *s, va_list *args)
Definition: tcp.c:505
struct _transport_proto_vft transport_proto_vft_t
#define TRANSPORT_ENDPOINT_INVALID_INDEX
Definition: transport.h:244
static void tcp_timer_set(tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp.h:473
static timer_expiration_handler * timer_expiration_handlers[TCP_N_TIMERS]
Definition: tcp.c:674
#define TCP_INVALID_SACK_HOLE_INDEX
Definition: tcp.h:151
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:397
transport_connection_t * tcp_session_get_listener(u32 listener_index)
Definition: tcp.c:85
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
Definition: ip.h:133
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:183
format_function_t * format_header
Definition: ip.h:78
void tcp_session_cleanup(u32 conn_index, u32 thread_index)
Definition: tcp.c:202
void tcp_send_syn(tcp_connection_t *tc)
Send SYN.
Definition: tcp_output.c:734
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
static const transport_proto_vft_t tcp4_proto
Definition: tcp.c:576
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:241
static void tcp_expired_timers_dispatch(u32 *expired_timers)
Definition: tcp.c:687
#define TCP_TIMER_HANDLE_INVALID
Definition: tcp.h:85
void tcp_timer_waitclose_handler(u32 conn_index)
Definition: tcp.c:643
#define TCP_CLEANUP_TIME
Definition: tcp.h:94
clib_error_t * vnet_tcp_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: tcp.c:780
f64 seconds_per_clock
Definition: time.h:57
u32 tcp_push_header(transport_connection_t *tconn, vlib_buffer_t *b)
Definition: tcp_output.c:1336
void transport_endpoint_table_add(transport_endpoint_table_t *ht, transport_endpoint_t *te, u32 value)
Definition: transport.c:37
void tcp_session_close(u32 conn_index, u32 thread_index)
Definition: tcp.c:194
void( timer_expiration_handler)(u32 index)
Definition: tcp.h:79
static u32 tcp_connection_bind(u32 session_index, ip46_address_t *ip, u16 port_host_byte_order, u8 is_ip4)
Definition: tcp.c:24
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1321
static void tcp_timer_reset(tcp_connection_t *tc, u8 timer_id)
Definition: tcp.h:489
u8 * format_tcp_half_open_session(u8 *s, va_list *args)
Definition: tcp.c:533
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
format_function_t format_ip6_address
Definition: format.h:95
vlib_main_t * vm
Definition: buffer.c:276
void tcp_cc_init(tcp_connection_t *tc)
Definition: tcp_input.c:679
ip_main_t ip_main
Definition: ip_init.c:42
void tcp_connection_close(tcp_connection_t *tc)
Begin connection closing procedure.
Definition: tcp.c:170
void tcp_set_snd_mss(tcp_connection_t *tc)
Definition: tcp_output.c:64
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:69
u8 * format_tcp_session(u8 *s, va_list *args)
Definition: tcp.c:514
format_function_t format_tcp_header
Definition: format.h:102
int tcp_session_open_ip6(ip46_address_t *addr, u16 port)
Definition: tcp.c:420
const char * tcp_dbg_evt_str[]
Definition: tcp.c:425
int tcp_connection_open(ip46_address_t *rmt_addr, u16 rmt_port, u8 is_ip4)
Definition: tcp.c:336
u16 tcp_session_send_mss(transport_connection_t *trans_conn)
Definition: tcp.c:555
static void tcp_timer_update(tcp_connection_t *tc, u8 timer_id, u32 interval)
Definition: tcp.h:500
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:255
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
ip6_main_t ip6_main
Definition: ip6_forward.c:2846
ip_lookup_main_t lookup_main
Definition: ip6.h:151
unformat_function_t unformat_pg_tcp_header
Definition: format.h:104
vhost_vring_state_t state
Definition: vhost-user.h:83
u32 transport_endpoint_lookup(transport_endpoint_table_t *ht, ip46_address_t *ip, u16 port)
Definition: transport.c:19
void stream_session_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
Definition: session.c:1114
clib_error_t * ip4_lookup_init(vlib_main_t *vm)
Definition: ip4_forward.c:1120
void session_register_transport(u8 type, const transport_proto_vft_t *vft)
Definition: session.c:1222
u8 * format_tcp_timers(u8 *s, va_list *args)
Definition: tcp.c:457
unsigned short u16
Definition: types.h:57
void tcp_connection_reset(tcp_connection_t *tc)
Notify session that connection has been reset.
Definition: tcp.c:147
vlib_node_registration_t tcp4_input_node
(constructor) VLIB_REGISTER_NODE (tcp4_input_node)
Definition: tcp_input.c:2220
#define PORT_MASK
Definition: tcp.c:241
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
int tcp_session_open_ip4(ip46_address_t *addr, u16 port)
Definition: tcp.c:414
#define foreach_tcp_fsm_state
TCP FSM state definitions as per RFC793.
Definition: tcp.h:38
void tcp_send_fin(tcp_connection_t *tc)
Send FIN.
Definition: tcp_output.c:811
#define foreach_tcp_timer
TCP timers.
Definition: tcp.h:62
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
struct _transport_endpoint transport_endpoint_t
void tcp_connection_init_vars(tcp_connection_t *tc)
Initialize tcp connection variables.
Definition: tcp.c:327
const char * tcp_conn_timers[]
Definition: tcp.c:450
clib_error_t * tcp_init(vlib_main_t *vm)
Definition: tcp.c:798
u8 * format_tcp_connection(u8 *s, va_list *args)
Definition: tcp.c:482
static tcp_connection_t * tcp_connection_get(u32 conn_index, u32 thread_index)
Definition: tcp.h:337
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1117
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
void tcp_connection_cleanup(tcp_connection_t *tc)
Cleans up connection state.
Definition: tcp.c:99
void tcp_connection_del(tcp_connection_t *tc)
Connection removal.
Definition: tcp.c:135
#define vec_foreach(var, vec)
Vector iterator.
#define TCP_TSTAMP_RESOLUTION
Time stamp resolution.
Definition: tcp.h:29
vhost_vring_addr_t addr
Definition: vhost-user.h:84
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:410
static const transport_proto_vft_t tcp6_proto
Definition: tcp.c:594
u8 * format_tcp_state(u8 *s, va_list *args)
Definition: tcp.c:438
u32 tcp_session_send_space(transport_connection_t *trans_conn)
Definition: tcp.c:562
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2849
static tcp_main_t * vnet_get_tcp_main()
Definition: tcp.h:329
timer_expiration_handler tcp_timer_delack_handler
u32 tcp_session_bind_ip6(u32 session_index, ip46_address_t *ip, u16 port_host_byte_order)
Definition: tcp.c:61
transport_connection_t * tcp_session_get_transport(u32 conn_index, u32 thread_index)
Definition: tcp.c:541
u8 * format_tcp_listener_session(u8 *s, va_list *args)
Definition: tcp.c:525
void tcp_initialize_timer_wheels(tcp_main_t *tm)
Definition: tcp.c:706
static tcp_connection_t * tcp_listener_get(u32 tli)
Definition: tcp.h:363