FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
application_local.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 
17 #include <vnet/session/session.h>
18 
19 typedef struct ct_main_
20 {
21  ct_connection_t **connections; /**< Per-worker connection pools */
22  u32 n_workers; /**< Number of vpp workers */
23  u32 n_sessions; /**< Cumulative sessions counter */
24  u32 *ho_reusable; /**< Vector of reusable ho indices */
25  clib_spinlock_t ho_reuseable_lock; /**< Lock for reusable ho indices */
26 } ct_main_t;
27 
29 
30 static ct_connection_t *
32 {
33  ct_connection_t *ct;
34 
36  ct->c_c_index = ct - ct_main.connections[thread_index];
37  ct->c_thread_index = thread_index;
38  ct->client_wrk = ~0;
39  ct->server_wrk = ~0;
40  return ct;
41 }
42 
43 static ct_connection_t *
45 {
47  return 0;
49 }
50 
51 static void
53 {
54  if (CLIB_DEBUG)
55  {
56  u32 thread_index = ct->c_thread_index;
57  memset (ct, 0xfc, sizeof (*ct));
59  return;
60  }
61  pool_put (ct_main.connections[ct->c_thread_index], ct);
62 }
63 
64 static ct_connection_t *
66 {
67  ct_main_t *cm = &ct_main;
68  u32 *hip;
69 
70  clib_spinlock_lock (&cm->ho_reuseable_lock);
71  vec_foreach (hip, cm->ho_reusable)
72  pool_put_index (cm->connections[0], *hip);
73  vec_reset_length (cm->ho_reusable);
74  clib_spinlock_unlock (&cm->ho_reuseable_lock);
75 
76  return ct_connection_alloc (0);
77 }
78 
79 void
81 {
82  ct_main_t *cm = &ct_main;
83 
84  clib_spinlock_lock (&cm->ho_reuseable_lock);
85  vec_add1 (cm->ho_reusable, ho_index);
86  clib_spinlock_unlock (&cm->ho_reuseable_lock);
87 }
88 
89 session_t *
91 {
92  ct_connection_t *ct, *peer_ct;
94  peer_ct = ct_connection_get (ct->peer_index, s->thread_index);
95  return session_get (peer_ct->c_s_index, s->thread_index);
96 }
97 
98 void
100 {
101  ct_connection_t *ct;
103  sep->transport_proto = ct->actual_tp;
104  sep->port = ct->c_lcl_port;
105  sep->is_ip4 = ct->c_is_ip4;
106  ip_copy (&sep->ip, &ct->c_lcl_ip, ct->c_is_ip4);
107 }
108 
109 int
111 {
112  u32 ss_index, opaque, thread_index;
113  ct_connection_t *sct, *cct;
114  app_worker_t *client_wrk;
115  segment_manager_t *sm;
116  fifo_segment_t *seg;
117  u64 segment_handle;
118  int err = 0;
119  session_t *cs;
120 
121  ss_index = ss->session_index;
123  sct = (ct_connection_t *) session_get_transport (ss);
124  client_wrk = app_worker_get (sct->client_wrk);
125  opaque = sct->client_opaque;
126 
127  sm = segment_manager_get (ss->rx_fifo->segment_manager);
128  seg = segment_manager_get_segment_w_lock (sm, ss->rx_fifo->segment_index);
129  segment_handle = segment_manager_segment_handle (sm, seg);
130 
131  if ((err = app_worker_add_segment_notify (client_wrk, segment_handle)))
132  {
133  clib_warning ("failed to notify client %u of new segment",
134  sct->client_wrk);
136  session_close (ss);
137  goto error;
138  }
139  else
140  {
142  }
143 
144  /*
145  * Alloc client session
146  */
148 
149  /* Client closed while waiting for reply from server */
150  if (!cct)
151  {
154  ct_connection_free (sct);
155  return 0;
156  }
157 
159  cct->flags &= ~CT_CONN_F_HALF_OPEN;
160 
162  ss = session_get (ss_index, thread_index);
163  cs->session_type = ss->session_type;
165  cs->session_state = SESSION_STATE_CONNECTING;
166  cs->app_wrk_index = client_wrk->wrk_index;
167  cs->connection_index = cct->c_c_index;
168 
169  cct->c_s_index = cs->session_index;
170  cct->client_rx_fifo = ss->tx_fifo;
171  cct->client_tx_fifo = ss->rx_fifo;
172 
173  cct->client_rx_fifo->refcnt++;
174  cct->client_tx_fifo->refcnt++;
175 
176  /* This will allocate fifos for the session. They won't be used for
177  * exchanging data but they will be used to close the connection if
178  * the segment manager/worker is freed */
179  if ((err = app_worker_init_connected (client_wrk, cs)))
180  {
181  session_close (ss);
182  session_free (cs);
183  goto error;
184  }
185 
186  cs->session_state = SESSION_STATE_CONNECTING;
187 
188  if (app_worker_connect_notify (client_wrk, cs, err, opaque))
189  {
190  session_close (ss);
192  session_free (cs);
193  return -1;
194  }
195 
196  cs = session_get (cct->c_s_index, cct->c_thread_index);
197  cs->session_state = SESSION_STATE_READY;
198 
199  return 0;
200 
201 error:
202  app_worker_connect_notify (client_wrk, 0, err, opaque);
203  return -1;
204 }
205 
206 static int
208  ct_connection_t * ct, session_t * ls,
209  session_t * ll)
210 {
211  u32 round_rx_fifo_sz, round_tx_fifo_sz, sm_index, seg_size;
213  application_t *server;
214  segment_manager_t *sm;
215  u32 margin = 16 << 10;
216  fifo_segment_t *seg;
217  u64 segment_handle;
218  int seg_index, rv;
219 
220  server = application_get (server_wrk->app_index);
221 
223  round_rx_fifo_sz = 1 << max_log2 (props->rx_fifo_size);
224  round_tx_fifo_sz = 1 << max_log2 (props->tx_fifo_size);
225  /* Increase size because of inefficient chunk allocations. Depending on
226  * how data is consumed, it may happen that more chunks than needed are
227  * allocated.
228  * TODO should remove once allocations are done more efficiently */
229  seg_size = 4 * (round_rx_fifo_sz + round_tx_fifo_sz + margin);
230 
231  sm = app_worker_get_listen_segment_manager (server_wrk, ll);
232  seg_index = segment_manager_add_segment (sm, seg_size, 0);
233  if (seg_index < 0)
234  {
235  clib_warning ("failed to add new cut-through segment");
236  return seg_index;
237  }
238  seg = segment_manager_get_segment_w_lock (sm, seg_index);
239 
241  props->rx_fifo_size,
242  props->tx_fifo_size, &ls->rx_fifo,
243  &ls->tx_fifo);
244  if (rv)
245  {
246  clib_warning ("failed to add fifos in cut-through segment");
248  goto failed;
249  }
250 
251  sm_index = segment_manager_index (sm);
252  ls->rx_fifo->shr->master_session_index = ls->session_index;
253  ls->tx_fifo->shr->master_session_index = ls->session_index;
254  ls->rx_fifo->master_thread_index = ls->thread_index;
255  ls->tx_fifo->master_thread_index = ls->thread_index;
256  ls->rx_fifo->segment_manager = sm_index;
257  ls->tx_fifo->segment_manager = sm_index;
258  ls->rx_fifo->segment_index = seg_index;
259  ls->tx_fifo->segment_index = seg_index;
260 
261  segment_handle = segment_manager_segment_handle (sm, seg);
262  if ((rv = app_worker_add_segment_notify (server_wrk, segment_handle)))
263  {
264  clib_warning ("failed to notify server of new segment");
266  goto failed;
267  }
269  ct->segment_handle = segment_handle;
270 
271  return 0;
272 
273 failed:
274  segment_manager_lock_and_del_segment (sm, seg_index);
275  return rv;
276 }
277 
278 static void
279 ct_accept_rpc_wrk_handler (void *accept_args)
280 {
281  u32 cct_index, ho_index, thread_index, ll_index;
282  ct_connection_t *sct, *cct, *ho;
283  transport_connection_t *ll_ct;
284  app_worker_t *server_wrk;
285  session_t *ss, *ll;
286 
287  /*
288  * Alloc client ct and initialize from ho
289  */
292  cct_index = cct->c_c_index;
293 
294  ho_index = pointer_to_uword (accept_args);
295  ho = ct_connection_get (ho_index, 0);
296 
297  /* Unlikely but half-open session and transport could have been freed */
298  if (PREDICT_FALSE (!ho))
299  {
300  ct_connection_free (cct);
301  return;
302  }
303 
304  clib_memcpy (cct, ho, sizeof (*ho));
305  cct->c_c_index = cct_index;
306  cct->c_thread_index = thread_index;
307  cct->flags |= CT_CONN_F_HALF_OPEN;
308 
309  /* Notify session layer that half-open is on a different thread
310  * and mark ho connection index reusable. Avoids another rpc
311  */
314  ct_half_open_add_reusable (ho_index);
315 
316  /*
317  * Alloc and init server transport
318  */
319 
320  ll_index = cct->peer_index;
321  ll = listen_session_get (ll_index);
323  /* Transport not necessarily ct but it might, so grab after sct alloc */
324  ll_ct = listen_session_get_transport (ll);
325 
326  /* Make sure cct is valid after sct alloc */
327  cct = ct_connection_get (cct_index, thread_index);
328 
329  sct->c_rmt_port = 0;
330  sct->c_lcl_port = ll_ct->lcl_port;
331  sct->c_is_ip4 = cct->c_is_ip4;
332  clib_memcpy (&sct->c_lcl_ip, &ll_ct->lcl_ip, sizeof (ll_ct->lcl_ip));
333  sct->client_wrk = cct->client_wrk;
334  sct->c_proto = TRANSPORT_PROTO_NONE;
335  sct->client_opaque = cct->client_opaque;
336  sct->actual_tp = cct->actual_tp;
337 
338  sct->peer_index = cct->c_c_index;
339  cct->peer_index = sct->c_c_index;
340 
341  /*
342  * Accept server session. Client session is created only after
343  * server confirms accept.
344  */
346  ll = listen_session_get (ll_index);
347  ss->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE,
348  sct->c_is_ip4);
349  ss->connection_index = sct->c_c_index;
351  ss->session_state = SESSION_STATE_CREATED;
352 
353  server_wrk = application_listener_select_worker (ll);
354  ss->app_wrk_index = server_wrk->wrk_index;
355 
356  sct->c_s_index = ss->session_index;
357  sct->server_wrk = ss->app_wrk_index;
358 
359  if (ct_init_accepted_session (server_wrk, sct, ss, ll))
360  {
361  ct_connection_free (sct);
362  session_free (ss);
363  return;
364  }
365 
366  ss->session_state = SESSION_STATE_ACCEPTING;
367  if (app_worker_accept_notify (server_wrk, ss))
368  {
369  ct_connection_free (sct);
371  session_free (ss);
372  return;
373  }
374 
375  cct->segment_handle = sct->segment_handle;
376 }
377 
378 static int
379 ct_connect (app_worker_t * client_wrk, session_t * ll,
381 {
382  u32 thread_index, ho_index;
383  ct_main_t *cm = &ct_main;
384  ct_connection_t *ho;
385 
386  /* Simple round-robin policy for spreading sessions over workers. We skip
387  * thread index 0, i.e., offset the index by 1, when we have workers as it
388  * is the one dedicated to main thread. Note that n_workers does not include
389  * main thread */
390  cm->n_sessions += 1;
391  thread_index = cm->n_workers ? (cm->n_sessions % cm->n_workers) + 1 : 0;
392 
393  /*
394  * Alloc and init client half-open transport
395  */
396 
397  ho = ct_half_open_alloc ();
398  ho_index = ho->c_c_index;
399  ho->c_rmt_port = sep->port;
400  ho->c_lcl_port = 0;
401  ho->c_is_ip4 = sep->is_ip4;
402  ho->client_opaque = sep->opaque;
403  ho->client_wrk = client_wrk->wrk_index;
404  ho->peer_index = ll->session_index;
405  ho->c_proto = TRANSPORT_PROTO_NONE;
406  ho->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
407  clib_memcpy (&ho->c_rmt_ip, &sep->ip, sizeof (sep->ip));
408  ho->flags |= CT_CONN_F_CLIENT;
409  ho->c_s_index = ~0;
410  ho->actual_tp = sep->transport_proto;
411 
412  /*
413  * Accept connection on thread selected above. Connected reply comes
414  * after server accepts the connection.
415  */
416 
419  uword_to_pointer (ho_index, void *));
420 
421  return ho_index;
422 }
423 
424 static u32
425 ct_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
426 {
428  ct_connection_t *ct;
429 
430  sep = (session_endpoint_cfg_t *) tep;
431  ct = ct_connection_alloc (0);
432  ct->server_wrk = sep->app_wrk_index;
433  ct->c_is_ip4 = sep->is_ip4;
434  clib_memcpy (&ct->c_lcl_ip, &sep->ip, sizeof (sep->ip));
435  ct->c_lcl_port = sep->port;
436  ct->c_s_index = app_listener_index;
437  ct->actual_tp = sep->transport_proto;
438  return ct->c_c_index;
439 }
440 
441 static u32
442 ct_stop_listen (u32 ct_index)
443 {
444  ct_connection_t *ct;
445  ct = ct_connection_get (ct_index, 0);
446  ct_connection_free (ct);
447  return 0;
448 }
449 
450 static transport_connection_t *
452 {
453  return (transport_connection_t *) ct_connection_get (ct_index, 0);
454 }
455 
456 static transport_connection_t *
458 {
459  return (transport_connection_t *) ct_connection_get (ct_index, 0);
460 }
461 
462 static void
464 {
465  ct_connection_t *ct, *peer_ct;
466 
467  ct = ct_connection_get (conn_index, thread_index);
468  if (!ct)
469  return;
470 
471  peer_ct = ct_connection_get (ct->peer_index, thread_index);
472  if (peer_ct)
473  peer_ct->peer_index = ~0;
474 
475  ct_connection_free (ct);
476 }
477 
478 static void
479 ct_cleanup_ho (u32 ho_index)
480 {
481  ct_connection_free (ct_connection_get (ho_index, 0));
482 }
483 
484 static int
486 {
487  session_endpoint_cfg_t *sep_ext;
488  session_endpoint_t _sep, *sep = &_sep;
489  app_worker_t *app_wrk;
490  session_handle_t lh;
491  application_t *app;
492  app_listener_t *al;
493  u32 table_index;
494  session_t *ll;
495  u8 fib_proto;
496 
497  sep_ext = (session_endpoint_cfg_t *) tep;
498  _sep = *(session_endpoint_t *) tep;
499  app_wrk = app_worker_get (sep_ext->app_wrk_index);
500  app = application_get (app_wrk->app_index);
501 
502  sep->transport_proto = sep_ext->original_tp;
503  table_index = application_local_session_table (app);
504  lh = session_lookup_local_endpoint (table_index, sep);
505  if (lh == SESSION_DROP_HANDLE)
506  return SESSION_E_FILTERED;
507 
508  if (lh == SESSION_INVALID_HANDLE)
509  goto global_scope;
510 
512  al = app_listener_get_w_session (ll);
513 
514  /*
515  * Break loop if rule in local table points to connecting app. This
516  * can happen if client is a generic proxy. Route connect through
517  * global table instead.
518  */
519  if (al->app_index == app->app_index)
520  goto global_scope;
521 
522  return ct_connect (app_wrk, ll, sep_ext);
523 
524  /*
525  * If nothing found, check the global scope for locally attached
526  * destinations. Make sure first that we're allowed to.
527  */
528 
529 global_scope:
530  if (session_endpoint_is_local (sep))
531  return SESSION_E_NOROUTE;
532 
533  if (!application_has_global_scope (app))
534  return SESSION_E_SCOPE;
535 
536  fib_proto = session_endpoint_fib_proto (sep);
537  table_index = session_lookup_get_index_for_fib (fib_proto, sep->fib_index);
538  ll = session_lookup_listener_wildcard (table_index, sep);
539 
540  /* Avoid connecting app to own listener */
541  if (ll && ll->app_index != app->app_index)
542  return ct_connect (app_wrk, ll, sep_ext);
543 
544  /* Failed to connect but no error */
545  return SESSION_E_LOCAL_CONNECT;
546 }
547 
548 static void
550 {
551  ct_connection_t *ct, *peer_ct;
552  app_worker_t *app_wrk;
553  session_t *s;
554 
555  ct = ct_connection_get (ct_index, thread_index);
556  peer_ct = ct_connection_get (ct->peer_index, thread_index);
557  if (peer_ct)
558  {
559  peer_ct->peer_index = ~0;
560  /* Make sure session was allocated */
561  if (peer_ct->flags & CT_CONN_F_HALF_OPEN)
562  {
563  app_wrk = app_worker_get (peer_ct->client_wrk);
564  app_worker_connect_notify (app_wrk, 0, SESSION_E_REFUSED,
565  peer_ct->client_opaque);
566  }
567  else if (peer_ct->c_s_index != ~0)
569  else
570  ct_connection_free (peer_ct);
571  }
572 
573  s = session_get (ct->c_s_index, ct->c_thread_index);
574  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
575  if (app_wrk)
578  if (ct->flags & CT_CONN_F_CLIENT)
580 
581  ct_connection_free (ct);
582 }
583 
584 static transport_connection_t *
586 {
587  return (transport_connection_t *) ct_connection_get (ct_index,
588  thread_index);
589 }
590 
591 static u8 *
592 format_ct_connection_id (u8 * s, va_list * args)
593 {
594  ct_connection_t *ct = va_arg (*args, ct_connection_t *);
595  if (!ct)
596  return s;
597  if (ct->c_is_ip4)
598  {
599  s = format (s, "[%d:%d][CT:%U] %U:%d->%U:%d", ct->c_thread_index,
600  ct->c_s_index, format_transport_proto_short, ct->actual_tp,
601  format_ip4_address, &ct->c_lcl_ip4,
602  clib_net_to_host_u16 (ct->c_lcl_port), format_ip4_address,
603  &ct->c_rmt_ip4, clib_net_to_host_u16 (ct->c_rmt_port));
604  }
605  else
606  {
607  s = format (s, "[%d:%d][CT:%U] %U:%d->%U:%d", ct->c_thread_index,
608  ct->c_s_index, format_transport_proto_short, ct->actual_tp,
609  format_ip6_address, &ct->c_lcl_ip6,
610  clib_net_to_host_u16 (ct->c_lcl_port), format_ip6_address,
611  &ct->c_rmt_ip6, clib_net_to_host_u16 (ct->c_rmt_port));
612  }
613 
614  return s;
615 }
616 
617 static int
619 {
620  session_t *s = (session_t *) session;
621  if (session_has_transport (s))
622  return 0;
623  /* If event enqueued towards peer, remove from scheduler and remove
624  * session tx flag, i.e., accept new tx events. Unset fifo flag now to
625  * avoid missing events if peer did not clear fifo flag yet, which is
626  * interpreted as successful notification and session is descheduled. */
628  if (!ct_session_tx (s))
630 
631  /* The scheduler uses packet count as a means of upper bounding the amount
632  * of work done per dispatch. So make it look like we have sent something */
633  return 1;
634 }
635 
636 static int
638 {
639  ct_connection_t *ct = (ct_connection_t *) tc, *peer_ct;
640  session_t *ps;
641 
642  peer_ct = ct_connection_get (ct->peer_index, tc->thread_index);
643  if (!peer_ct)
644  return -1;
645  ps = session_get (peer_ct->c_s_index, peer_ct->c_thread_index);
646  return session_dequeue_notify (ps);
647 }
648 
649 static u8 *
650 format_ct_listener (u8 * s, va_list * args)
651 {
652  u32 tc_index = va_arg (*args, u32);
653  u32 __clib_unused thread_index = va_arg (*args, u32);
654  u32 __clib_unused verbose = va_arg (*args, u32);
655  ct_connection_t *ct = ct_connection_get (tc_index, 0);
656  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
657  if (verbose)
658  s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "LISTEN");
659  return s;
660 }
661 
662 static u8 *
663 format_ct_half_open (u8 *s, va_list *args)
664 {
665  u32 ho_index = va_arg (*args, u32);
666  u32 verbose = va_arg (*args, u32);
667  ct_connection_t *ct = ct_connection_get (ho_index, 0);
668  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
669  if (verbose)
670  s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "HALF-OPEN");
671  return s;
672 }
673 
674 static u8 *
675 format_ct_connection (u8 * s, va_list * args)
676 {
677  ct_connection_t *ct = va_arg (*args, ct_connection_t *);
678  u32 verbose = va_arg (*args, u32);
679 
680  if (!ct)
681  return s;
682  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
683  if (verbose)
684  {
685  s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "ESTABLISHED");
686  if (verbose > 1)
687  {
688  s = format (s, "\n");
689  }
690  }
691  return s;
692 }
693 
694 static u8 *
695 format_ct_session (u8 * s, va_list * args)
696 {
697  u32 ct_index = va_arg (*args, u32);
698  u32 thread_index = va_arg (*args, u32);
699  u32 verbose = va_arg (*args, u32);
700  ct_connection_t *ct;
701 
702  ct = ct_connection_get (ct_index, thread_index);
703  if (!ct)
704  {
705  s = format (s, "empty\n");
706  return s;
707  }
708 
709  s = format (s, "%U", format_ct_connection, ct, verbose);
710  return s;
711 }
712 
713 clib_error_t *
715 {
716  ct_main_t *cm = &ct_main;
717 
718  cm->n_workers = vlib_num_workers ();
719  vec_validate (cm->connections, cm->n_workers);
720  clib_spinlock_init (&cm->ho_reuseable_lock);
721 
722  return 0;
723 }
724 
725 /* *INDENT-OFF* */
727  .enable = ct_enable_disable,
728  .start_listen = ct_start_listen,
729  .stop_listen = ct_stop_listen,
730  .get_connection = ct_session_get,
731  .get_listener = ct_listener_get,
732  .get_half_open = ct_half_open_get,
733  .cleanup = ct_session_cleanup,
734  .cleanup_ho = ct_cleanup_ho,
735  .connect = ct_session_connect,
736  .close = ct_session_close,
737  .custom_tx = ct_custom_tx,
738  .app_rx_evt = ct_app_rx_evt,
739  .format_listener = format_ct_listener,
740  .format_half_open = format_ct_half_open,
741  .format_connection = format_ct_session,
742  .transport_options = {
743  .name = "ct",
744  .short_name = "C",
745  .tx_type = TRANSPORT_TX_INTERNAL,
746  .service_type = TRANSPORT_SERVICE_VC,
747  },
748 };
749 /* *INDENT-ON* */
750 
751 int
753 {
754  ct_connection_t *ct, *peer_ct;
755  session_t *peer_s;
756 
758  peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
759  if (!peer_ct)
760  return 0;
761  peer_s = session_get (peer_ct->c_s_index, peer_ct->c_thread_index);
762  if (peer_s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
763  return 0;
764  return session_enqueue_notify (peer_s);
765 }
766 
767 static clib_error_t *
769 {
770  transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
771  FIB_PROTOCOL_IP4, ~0);
772  transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
773  FIB_PROTOCOL_IP6, ~0);
774  return 0;
775 }
776 
778 
779 /*
780  * fd.io coding-style-patch-verification: ON
781  *
782  * Local Variables:
783  * eval: (c-set-style "gnu")
784  * End:
785  */
vec_reset_length
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
Definition: vec_bootstrap.h:194
segment_manager_get_segment_w_lock
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool and acquires reader lock.
Definition: segment_manager.c:296
ct_connection_
Definition: application_local.h:41
clib_spinlock_init
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
SESSION_CLI_STATE_LEN
#define SESSION_CLI_STATE_LEN
Definition: session_types.h:507
format_ct_listener
static u8 * format_ct_listener(u8 *s, va_list *args)
Definition: application_local.c:650
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:354
app_worker_::wrk_index
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
ct_half_open_alloc
static ct_connection_t * ct_half_open_alloc(void)
Definition: application_local.c:65
session_enqueue_notify
int session_enqueue_notify(session_t *s)
Definition: session.c:778
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
segment_manager_get
segment_manager_t * segment_manager_get(u32 index)
Definition: segment_manager.c:532
failed
description security check failed
Definition: map.api:373
session_dequeue_notify
int session_dequeue_notify(session_t *s)
Definition: session.c:816
session_::session_index
u32 session_index
Index in thread pool where session was allocated.
Definition: session_types.h:188
svm_fifo_unset_event
static void svm_fifo_unset_event(svm_fifo_t *f)
Unset fifo event flag.
Definition: svm_fifo.h:803
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
SESSION_CLI_ID_LEN
#define SESSION_CLI_ID_LEN
Definition: session_types.h:506
session_close
void session_close(session_t *s)
Initialize session closing procedure.
Definition: session.c:1496
ct_start_listen
static u32 ct_start_listen(u32 app_listener_index, transport_endpoint_t *tep)
Definition: application_local.c:425
session_transport_closing_notify
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
Definition: session.c:1062
ct_connection_alloc
static ct_connection_t * ct_connection_alloc(u32 thread_index)
Definition: application_local.c:31
pointer_to_uword
static uword pointer_to_uword(const void *p)
Definition: types.h:131
session_half_open_delete_notify
void session_half_open_delete_notify(transport_connection_t *tc)
Definition: session.c:347
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
ct_custom_tx
static int ct_custom_tx(void *session, transport_send_params_t *sp)
Definition: application_local.c:618
listen_session_get_handle
static u64 listen_session_get_handle(session_t *s)
Definition: session.h:622
ct_session_get_peer
session_t * ct_session_get_peer(session_t *s)
Definition: application_local.c:90
session_::tx_fifo
svm_fifo_t * tx_fifo
Definition: session_types.h:179
ct_half_open_add_reusable
void ct_half_open_add_reusable(u32 ho_index)
Definition: application_local.c:80
fifo_segment_t
Definition: fifo_segment.h:67
app_worker_get_listen_segment_manager
segment_manager_t * app_worker_get_listen_segment_manager(app_worker_t *, session_t *)
Definition: application_worker.c:531
session_
Definition: session_types.h:175
segment_manager_t
struct _segment_manager segment_manager_t
session_endpoint_cfg_t
struct _session_endpoint_cfg session_endpoint_cfg_t
application_segment_manager_properties
segment_manager_props_t * application_segment_manager_properties(application_t *app)
Definition: application.c:1636
session_handle_t
u64 session_handle_t
Definition: session_types.h:111
transport_proto_vft_t
struct _transport_proto_vft transport_proto_vft_t
listen_session_get
static session_t * listen_session_get(u32 ls_index)
Definition: session.h:653
application_::app_index
u32 app_index
App index in app pool.
Definition: application.h:111
session_half_open_migrated_notify
int session_half_open_migrated_notify(transport_connection_t *tc)
Definition: session.c:373
ct_connection_::server_wrk
u32 server_wrk
Definition: application_local.h:45
session_::thread_index
u8 thread_index
Index of the thread that allocated the session.
Definition: session_types.h:194
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
session_::session_type
session_type_t session_type
Type built from transport and network protocol types.
Definition: session_types.h:182
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
ct_main_::ho_reusable
u32 * ho_reusable
Vector of reusable ho indices.
Definition: application_local.c:24
session_endpoint_is_local
static u8 session_endpoint_is_local(session_endpoint_t *sep)
Definition: session_types.h:98
ct_connection_::flags
ct_connection_flags_t flags
Definition: application_local.h:52
application_
Definition: application.h:108
transport_connection_t
struct _transport_connection transport_connection_t
app_worker_del_segment_notify
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Definition: application_worker.c:600
transport_endpoint_pair_
Definition: transport_types.h:212
session_free
void session_free(session_t *s)
Definition: session.c:227
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
error
Definition: cJSON.c:88
application_local.h
max_log2
static uword max_log2(uword x)
Definition: clib.h:223
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
application_get
application_t * application_get(u32 app_index)
Definition: application.c:710
ct_session_connect_notify
int ct_session_connect_notify(session_t *ss)
Definition: application_local.c:110
session_::app_wrk_index
u32 app_wrk_index
Index of the app worker that owns the session.
Definition: session_types.h:191
application_has_global_scope
u8 application_has_global_scope(application_t *app)
Definition: application.c:1490
app_worker_init_connected
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:358
TRANSPORT_SND_F_DESCHED
@ TRANSPORT_SND_F_DESCHED
Definition: transport.h:40
session_::rx_fifo
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
Definition: session_types.h:178
ct_session_close
static void ct_session_close(u32 ct_index, u32 thread_index)
Definition: application_local.c:549
app_listener_::app_index
u32 app_index
owning app index
Definition: application.h:84
session_::app_index
u32 app_index
Index of application that owns the listener.
Definition: session_types.h:203
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
segment_manager_dealloc_fifos
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
Definition: segment_manager.c:810
session_get_transport
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1745
ct_listener_get
static transport_connection_t * ct_listener_get(u32 ct_index)
Definition: application_local.c:451
session_lookup_listener_wildcard
session_t * session_lookup_listener_wildcard(u32 table_index, session_endpoint_t *sep)
Lookup listener wildcard match.
Definition: session_lookup.c:761
segment_manager_props_t
struct _segment_manager_props segment_manager_props_t
ct_connection_::segment_handle
u64 segment_handle
Definition: application_local.h:49
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_get_thread_index
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:208
app_worker_get_if_valid
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
Definition: application_worker.c:47
application_listener_select_worker
app_worker_t * application_listener_select_worker(session_t *ls)
Definition: application.c:972
clib_spinlock_lock
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
clib_spinlock_s
Definition: lock.h:51
session_endpoint_fib_proto
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
Definition: session_types.h:92
ct_connection_::client_rx_fifo
svm_fifo_t * client_rx_fifo
Definition: application_local.h:50
segment_manager_segment_reader_unlock
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
Definition: segment_manager.c:309
segment_manager_add_segment
int segment_manager_add_segment(segment_manager_t *sm, uword segment_size, u8 notify_app)
Adds segment to segment manager's pool.
Definition: segment_manager.c:91
ct_connection_::peer_index
u32 peer_index
Definition: application_local.h:48
session_half_open_migrate_notify
void session_half_open_migrate_notify(transport_connection_t *tc)
Definition: session.c:363
transport_register_protocol
void transport_register_protocol(transport_proto_t transport_proto, const transport_proto_vft_t *vft, fib_protocol_t fib_proto, u32 output_node)
Register transport virtual function table.
Definition: transport.c:246
segment_manager_segment_handle
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
Definition: segment_manager.c:260
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
segment_manager_lock_and_del_segment
void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
Definition: segment_manager.c:245
session_lookup_local_endpoint
u64 session_lookup_local_endpoint(u32 table_index, session_endpoint_t *sep)
Look up endpoint in local session table.
Definition: session_lookup.c:538
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
ct_connection_get
static ct_connection_t * ct_connection_get(u32 ct_index, u32 thread_index)
Definition: application_local.c:44
format_ct_session
static u8 * format_ct_session(u8 *s, va_list *args)
Definition: application_local.c:695
SESSION_DROP_HANDLE
#define SESSION_DROP_HANDLE
Definition: session_table.h:58
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
format_ct_connection_id
static u8 * format_ct_connection_id(u8 *s, va_list *args)
Definition: application_local.c:592
segment_manager_index
u32 segment_manager_index(segment_manager_t *sm)
Definition: segment_manager.c:546
session_get
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:336
session_transport_delete_notify
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
Definition: session.c:1084
app_worker_connect_notify
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, session_error_t err, u32 opaque)
Definition: application_worker.c:375
ct_main_::n_workers
u32 n_workers
Number of vpp workers.
Definition: application_local.c:22
ct_connection_::actual_tp
transport_proto_t actual_tp
Definition: application_local.h:46
TRANSPORT_TX_INTERNAL
@ TRANSPORT_TX_INTERNAL
apps acting as transports
Definition: transport_types.h:32
session_::listener_handle
session_handle_t listener_handle
Parent listener session index if the result of an accept.
Definition: session_types.h:208
session_type_from_proto_and_ip
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
Definition: session_types.h:224
transport_send_params_
Definition: transport.h:45
TRANSPORT_SERVICE_VC
@ TRANSPORT_SERVICE_VC
virtual circuit service
Definition: transport_types.h:39
application_local_session_table
u32 application_local_session_table(application_t *app)
Definition: application.c:373
ct_connection_::connection
transport_connection_t connection
Definition: application_local.h:43
ct_stop_listen
static u32 ct_stop_listen(u32 ct_index)
Definition: application_local.c:442
ct_init_accepted_session
static int ct_init_accepted_session(app_worker_t *server_wrk, ct_connection_t *ct, session_t *ls, session_t *ll)
Definition: application_local.c:207
TRANSPORT_CONNECTION_F_NO_LOOKUP
@ TRANSPORT_CONNECTION_F_NO_LOOKUP
Don't register connection in lookup.
Definition: transport_types.h:52
u64
unsigned long u64
Definition: types.h:89
format
description fragment has unexpected format
Definition: map.api:433
ct_half_open_get
static transport_connection_t * ct_half_open_get(u32 ct_index)
Definition: application_local.c:457
ct_main_t
struct ct_main_ ct_main_t
app_worker_add_segment_notify
int app_worker_add_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Send an API message to the external app, to map new segment.
Definition: application_worker.c:591
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
listen_session_get_transport
transport_connection_t * listen_session_get_transport(session_t *s)
Definition: session.c:1780
ip_copy
void ip_copy(ip46_address_t *dst, ip46_address_t *src, u8 is_ip4)
Definition: ip.c:83
transport_endpoint_
Definition: transport_types.h:193
ct_main_::n_sessions
u32 n_sessions
Cumulative sessions counter.
Definition: application_local.c:23
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
app_worker_get
app_worker_t * app_worker_get(u32 wrk_index)
Definition: application_worker.c:41
app_worker_
Definition: application.h:32
ct_main_::connections
ct_connection_t ** connections
Per-worker connection pools.
Definition: application_local.c:21
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
ct_connection_::client_opaque
u32 client_opaque
Definition: application_local.h:47
ct_cleanup_ho
static void ct_cleanup_ho(u32 ho_index)
Definition: application_local.c:479
session_endpoint_t
struct _session_endpoint session_endpoint_t
ct_connection_free
static void ct_connection_free(ct_connection_t *ct)
Definition: application_local.c:52
ct_connection_::client_tx_fifo
svm_fifo_t * client_tx_fifo
Definition: application_local.h:51
clib_spinlock_unlock
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
SESSION_INVALID_HANDLE
#define SESSION_INVALID_HANDLE
Definition: session_types.h:23
ct_transport_init
static clib_error_t * ct_transport_init(vlib_main_t *vm)
Definition: application_local.c:768
ct_session_tx
int ct_session_tx(session_t *s)
Definition: application_local.c:752
vlib_main_t
Definition: main.h:102
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
ct_session_endpoint
void ct_session_endpoint(session_t *ll, session_endpoint_t *sep)
Definition: application_local.c:99
uword_to_pointer
#define uword_to_pointer(u, type)
Definition: types.h:136
session.h
cut_thru_proto
static const transport_proto_vft_t cut_thru_proto
Definition: application_local.c:726
transport_send_params_::flags
transport_snd_flags_t flags
Definition: transport.h:62
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
ct_app_rx_evt
static int ct_app_rx_evt(transport_connection_t *tc)
Definition: application_local.c:637
ct_main
static ct_main_t ct_main
Definition: application_local.c:28
format_ct_connection
static u8 * format_ct_connection(u8 *s, va_list *args)
Definition: application_local.c:675
rv
int __clib_unused rv
Definition: application.c:491
session_free_w_fifos
void session_free_w_fifos(session_t *s)
Definition: session.c:279
app_listener_get_w_session
app_listener_t * app_listener_get_w_session(session_t *ls)
Definition: application.c:67
ct_session_get
static transport_connection_t * ct_session_get(u32 ct_index, u32 thread_index)
Definition: application_local.c:585
format_ct_half_open
static u8 * format_ct_half_open(u8 *s, va_list *args)
Definition: application_local.c:663
ct_main_::ho_reuseable_lock
clib_spinlock_t ho_reuseable_lock
Lock for reusable ho indices.
Definition: application_local.c:25
ct_connection_::client_wrk
u32 client_wrk
Definition: application_local.h:44
app_worker_::app_index
u32 app_index
Index of owning app.
Definition: application.h:43
session_has_transport
static u8 session_has_transport(session_t *s)
Definition: session_types.h:255
ct_main_
Definition: application_local.c:19
ct_session_cleanup
static void ct_session_cleanup(u32 conn_index, u32 thread_index)
Definition: application_local.c:463
ct_connect
static int ct_connect(app_worker_t *client_wrk, session_t *ll, session_endpoint_cfg_t *sep)
Definition: application_local.c:379
format_transport_proto_short
u8 * format_transport_proto_short(u8 *s, va_list *args)
Definition: transport.c:65
session_lookup_get_index_for_fib
u32 session_lookup_get_index_for_fib(u32 fib_proto, u32 fib_index)
Definition: session_lookup.c:210
ct_enable_disable
clib_error_t * ct_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: application_local.c:714
app_worker_accept_notify
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
Definition: application_worker.c:351
session_alloc
session_t * session_alloc(u32 thread_index)
Definition: session.c:201
ct_session_connect
static int ct_session_connect(transport_endpoint_cfg_t *tep)
Definition: application_local.c:485
session_::session_state
volatile u8 session_state
State in session layer state machine.
Definition: session_types.h:185
session_::connection_index
u32 connection_index
Index of the transport connection associated to the session.
Definition: session_types.h:200
ct_accept_rpc_wrk_handler
static void ct_accept_rpc_wrk_handler(void *accept_args)
Definition: application_local.c:279
segment_manager_try_alloc_fifos
int segment_manager_try_alloc_fifos(fifo_segment_t *fifo_segment, u32 thread_index, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
Definition: segment_manager.c:683
listen_session_get_from_handle
static session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:630
session_send_rpc_evt_to_thread_force
void session_send_rpc_evt_to_thread_force(u32 thread_index, void *fp, void *rpc_args)
Definition: session.c:108
app_listener_
Definition: application.h:79