FD.io VPP  v19.08.1-401-g8e4ed521a
Vector Packet Processing
session.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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 /**
16  * @file
17  * @brief Session and session manager
18  */
19 
20 #include <vnet/session/session.h>
23 #include <vnet/dpo/load_balance.h>
24 #include <vnet/fib/ip4_fib.h>
25 
27 
28 static inline int
29 session_send_evt_to_thread (void *data, void *args, u32 thread_index,
30  session_evt_type_t evt_type)
31 {
32  session_event_t *evt;
33  svm_msg_q_msg_t msg;
34  svm_msg_q_t *mq;
35 
36  mq = session_main_get_vpp_event_queue (thread_index);
37  if (PREDICT_FALSE (svm_msg_q_lock (mq)))
38  return -1;
40  {
41  svm_msg_q_unlock (mq);
42  return -2;
43  }
44  switch (evt_type)
45  {
48  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
49  evt->rpc_args.fp = data;
50  evt->rpc_args.arg = args;
51  break;
52  case SESSION_IO_EVT_RX:
53  case SESSION_IO_EVT_TX:
57  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
58  evt->session_index = *(u32 *) data;
59  break;
64  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
65  evt->session_handle = session_handle ((session_t *) data);
66  break;
67  default:
68  clib_warning ("evt unhandled!");
69  svm_msg_q_unlock (mq);
70  return -1;
71  }
72  evt->event_type = evt_type;
73 
74  svm_msg_q_add_and_unlock (mq, &msg);
75  return 0;
76 }
77 
78 int
80 {
81  return session_send_evt_to_thread (&f->master_session_index, 0,
82  f->master_thread_index, evt_type);
83 }
84 
85 int
87  session_evt_type_t evt_type)
88 {
89  return session_send_evt_to_thread (data, 0, thread_index, evt_type);
90 }
91 
92 int
94 {
95  /* only events supported are disconnect and reset */
96  ASSERT (evt_type == SESSION_CTRL_EVT_CLOSE
97  || evt_type == SESSION_CTRL_EVT_RESET);
98  return session_send_evt_to_thread (s, 0, s->thread_index, evt_type);
99 }
100 
101 void
103  void *rpc_args)
104 {
105  session_send_evt_to_thread (fp, rpc_args, thread_index,
107 }
108 
109 void
110 session_send_rpc_evt_to_thread (u32 thread_index, void *fp, void *rpc_args)
111 {
112  if (thread_index != vlib_get_thread_index ())
113  session_send_rpc_evt_to_thread_force (thread_index, fp, rpc_args);
114  else
115  {
116  void (*fnp) (void *) = fp;
117  fnp (rpc_args);
118  }
119 }
120 
121 void
123 {
124  session_t *s;
125 
126  s = session_get (tc->s_index, tc->thread_index);
128  ASSERT (s->session_state != SESSION_STATE_TRANSPORT_DELETED);
129  if (!(s->flags & SESSION_F_CUSTOM_TX))
130  {
132  if (svm_fifo_set_event (s->tx_fifo))
133  {
134  session_worker_t *wrk;
135  session_evt_elt_t *elt;
136  wrk = session_main_get_worker (tc->thread_index);
137  if (has_prio)
138  elt = session_evt_alloc_new (wrk);
139  else
140  elt = session_evt_alloc_old (wrk);
141  elt->evt.session_index = tc->s_index;
142  elt->evt.event_type = SESSION_IO_EVT_TX;
143  }
144  }
145 }
146 
147 static void
149 {
150  u32 thread_index = vlib_get_thread_index ();
151  session_evt_elt_t *elt;
152  session_worker_t *wrk;
153 
154  /* If we are in the handler thread, or being called with the worker barrier
155  * held, just append a new event to pending disconnects vector. */
156  if (vlib_thread_is_main_w_barrier () || thread_index == s->thread_index)
157  {
159  elt = session_evt_alloc_ctrl (wrk);
160  clib_memset (&elt->evt, 0, sizeof (session_event_t));
161  elt->evt.session_handle = session_handle (s);
162  elt->evt.event_type = evt;
163  }
164  else
166 }
167 
168 session_t *
169 session_alloc (u32 thread_index)
170 {
171  session_worker_t *wrk = &session_main.wrk[thread_index];
172  session_t *s;
173  u8 will_expand = 0;
174  pool_get_aligned_will_expand (wrk->sessions, will_expand,
176  /* If we have peekers, let them finish */
177  if (PREDICT_FALSE (will_expand && vlib_num_workers ()))
178  {
182  }
183  else
184  {
186  }
187  clib_memset (s, 0, sizeof (*s));
188  s->session_index = s - wrk->sessions;
189  s->thread_index = thread_index;
191  return s;
192 }
193 
194 void
196 {
197  if (CLIB_DEBUG)
198  {
199  u8 thread_index = s->thread_index;
200  clib_memset (s, 0xFA, sizeof (*s));
201  pool_put (session_main.wrk[thread_index].sessions, s);
202  return;
203  }
204  SESSION_EVT (SESSION_EVT_FREE, s);
205  pool_put (session_main.wrk[s->thread_index].sessions, s);
206 }
207 
208 u8
209 session_is_valid (u32 si, u8 thread_index)
210 {
211  session_t *s;
213 
214  s = pool_elt_at_index (session_main.wrk[thread_index].sessions, si);
215 
216  if (!s)
217  return 1;
218 
219  if (s->thread_index != thread_index || s->session_index != si)
220  return 0;
221 
222  if (s->session_state == SESSION_STATE_TRANSPORT_DELETED
223  || s->session_state <= SESSION_STATE_LISTENING)
224  return 1;
225 
226  tc = session_get_transport (s);
227  if (s->connection_index != tc->c_index
228  || s->thread_index != tc->thread_index || tc->s_index != si)
229  return 0;
230 
231  return 1;
232 }
233 
234 static void
236 {
237  app_worker_t *app_wrk;
238 
239  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
240  if (!app_wrk)
241  return;
242  app_worker_cleanup_notify (app_wrk, s, ntf);
243 }
244 
245 void
247 {
250  session_free (s);
251 }
252 
253 /**
254  * Cleans up session and lookup table.
255  *
256  * Transport connection must still be valid.
257  */
258 static void
260 {
261  int rv;
262 
263  /* Delete from the main lookup table. */
264  if ((rv = session_lookup_del_session (s)))
265  clib_warning ("session %u hash delete rv %d", s->session_index, rv);
266 
268 }
269 
270 static session_t *
272 {
273  session_t *s;
274  u32 thread_index = tc->thread_index;
275 
276  ASSERT (thread_index == vlib_get_thread_index ()
277  || transport_protocol_is_cl (tc->proto));
278 
279  s = session_alloc (thread_index);
280  s->session_type = session_type_from_proto_and_ip (tc->proto, tc->is_ip4);
281  s->session_state = SESSION_STATE_CLOSED;
282 
283  /* Attach transport to session and vice versa */
284  s->connection_index = tc->c_index;
285  tc->s_index = s->session_index;
286  return s;
287 }
288 
289 /**
290  * Discards bytes from buffer chain
291  *
292  * It discards n_bytes_to_drop starting at first buffer after chain_b
293  */
294 always_inline void
296  vlib_buffer_t ** chain_b,
297  u32 n_bytes_to_drop)
298 {
299  vlib_buffer_t *next = *chain_b;
300  u32 to_drop = n_bytes_to_drop;
301  ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
302  while (to_drop && (next->flags & VLIB_BUFFER_NEXT_PRESENT))
303  {
304  next = vlib_get_buffer (vm, next->next_buffer);
305  if (next->current_length > to_drop)
306  {
307  vlib_buffer_advance (next, to_drop);
308  to_drop = 0;
309  }
310  else
311  {
312  to_drop -= next->current_length;
313  next->current_length = 0;
314  }
315  }
316  *chain_b = next;
317 
318  if (to_drop == 0)
319  b->total_length_not_including_first_buffer -= n_bytes_to_drop;
320 }
321 
322 /**
323  * Enqueue buffer chain tail
324  */
325 always_inline int
327  u32 offset, u8 is_in_order)
328 {
329  vlib_buffer_t *chain_b;
330  u32 chain_bi, len, diff;
332  u8 *data;
333  u32 written = 0;
334  int rv = 0;
335 
336  if (is_in_order && offset)
337  {
338  diff = offset - b->current_length;
340  return 0;
341  chain_b = b;
342  session_enqueue_discard_chain_bytes (vm, b, &chain_b, diff);
343  chain_bi = vlib_get_buffer_index (vm, chain_b);
344  }
345  else
346  chain_bi = b->next_buffer;
347 
348  do
349  {
350  chain_b = vlib_get_buffer (vm, chain_bi);
351  data = vlib_buffer_get_current (chain_b);
352  len = chain_b->current_length;
353  if (!len)
354  continue;
355  if (is_in_order)
356  {
357  rv = svm_fifo_enqueue (s->rx_fifo, len, data);
358  if (rv == len)
359  {
360  written += rv;
361  }
362  else if (rv < len)
363  {
364  return (rv > 0) ? (written + rv) : written;
365  }
366  else if (rv > len)
367  {
368  written += rv;
369 
370  /* written more than what was left in chain */
372  return written;
373 
374  /* drop the bytes that have already been delivered */
375  session_enqueue_discard_chain_bytes (vm, b, &chain_b, rv - len);
376  }
377  }
378  else
379  {
380  rv = svm_fifo_enqueue_with_offset (s->rx_fifo, offset, len, data);
381  if (rv)
382  {
383  clib_warning ("failed to enqueue multi-buffer seg");
384  return -1;
385  }
386  offset += len;
387  }
388  }
389  while ((chain_bi = (chain_b->flags & VLIB_BUFFER_NEXT_PRESENT)
390  ? chain_b->next_buffer : 0));
391 
392  if (is_in_order)
393  return written;
394 
395  return 0;
396 }
397 
398 /*
399  * Enqueue data for delivery to session peer. Does not notify peer of enqueue
400  * event but on request can queue notification events for later delivery by
401  * calling stream_server_flush_enqueue_events().
402  *
403  * @param tc Transport connection which is to be enqueued data
404  * @param b Buffer to be enqueued
405  * @param offset Offset at which to start enqueueing if out-of-order
406  * @param queue_event Flag to indicate if peer is to be notified or if event
407  * is to be queued. The former is useful when more data is
408  * enqueued and only one event is to be generated.
409  * @param is_in_order Flag to indicate if data is in order
410  * @return Number of bytes enqueued or a negative value if enqueueing failed.
411  */
412 int
414  vlib_buffer_t * b, u32 offset,
415  u8 queue_event, u8 is_in_order)
416 {
417  session_t *s;
418  int enqueued = 0, rv, in_order_off;
419 
420  s = session_get (tc->s_index, tc->thread_index);
421 
422  if (is_in_order)
423  {
424  enqueued = svm_fifo_enqueue (s->rx_fifo,
425  b->current_length,
427  if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT)
428  && enqueued >= 0))
429  {
430  in_order_off = enqueued > b->current_length ? enqueued : 0;
431  rv = session_enqueue_chain_tail (s, b, in_order_off, 1);
432  if (rv > 0)
433  enqueued += rv;
434  }
435  }
436  else
437  {
438  rv = svm_fifo_enqueue_with_offset (s->rx_fifo, offset,
439  b->current_length,
441  if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && !rv))
442  session_enqueue_chain_tail (s, b, offset + b->current_length, 0);
443  /* if something was enqueued, report even this as success for ooo
444  * segment handling */
445  return rv;
446  }
447 
448  if (queue_event)
449  {
450  /* Queue RX event on this fifo. Eventually these will need to be flushed
451  * by calling stream_server_flush_enqueue_events () */
452  session_worker_t *wrk;
453 
455  if (!(s->flags & SESSION_F_RX_EVT))
456  {
457  s->flags |= SESSION_F_RX_EVT;
458  vec_add1 (wrk->session_to_enqueue[tc->proto], s->session_index);
459  }
460  }
461 
462  return enqueued;
463 }
464 
465 int
467  session_dgram_hdr_t * hdr,
468  vlib_buffer_t * b, u8 proto, u8 queue_event)
469 {
470  int enqueued = 0, rv, in_order_off;
471 
473  >= b->current_length + sizeof (*hdr));
474 
475  svm_fifo_enqueue (s->rx_fifo, sizeof (session_dgram_hdr_t), (u8 *) hdr);
476  enqueued = svm_fifo_enqueue (s->rx_fifo, b->current_length,
478  if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && enqueued >= 0))
479  {
480  in_order_off = enqueued > b->current_length ? enqueued : 0;
481  rv = session_enqueue_chain_tail (s, b, in_order_off, 1);
482  if (rv > 0)
483  enqueued += rv;
484  }
485  if (queue_event)
486  {
487  /* Queue RX event on this fifo. Eventually these will need to be flushed
488  * by calling stream_server_flush_enqueue_events () */
489  session_worker_t *wrk;
490 
492  if (!(s->flags & SESSION_F_RX_EVT))
493  {
494  s->flags |= SESSION_F_RX_EVT;
495  vec_add1 (wrk->session_to_enqueue[proto], s->session_index);
496  }
497  }
498  return enqueued;
499 }
500 
501 int
503  u32 offset, u32 max_bytes)
504 {
505  session_t *s = session_get (tc->s_index, tc->thread_index);
506  return svm_fifo_peek (s->tx_fifo, offset, max_bytes, buffer);
507 }
508 
509 u32
511 {
512  session_t *s = session_get (tc->s_index, tc->thread_index);
513  u32 rv;
514 
515  rv = svm_fifo_dequeue_drop (s->tx_fifo, max_bytes);
516 
517  if (svm_fifo_needs_deq_ntf (s->tx_fifo, max_bytes))
519 
520  return rv;
521 }
522 
523 static inline int
525  svm_fifo_t * f, session_evt_type_t evt_type)
526 {
527  app_worker_t *app_wrk;
528  application_t *app;
529  int i;
530 
531  app = application_get (app_index);
532  if (!app)
533  return -1;
534 
535  for (i = 0; i < f->n_subscribers; i++)
536  {
537  app_wrk = application_get_worker (app, f->subscribers[i]);
538  if (!app_wrk)
539  continue;
540  if (app_worker_lock_and_send_event (app_wrk, s, evt_type))
541  return -1;
542  }
543 
544  return 0;
545 }
546 
547 /**
548  * Notify session peer that new data has been enqueued.
549  *
550  * @param s Stream session for which the event is to be generated.
551  * @param lock Flag to indicate if call should lock message queue.
552  *
553  * @return 0 on success or negative number if failed to send notification.
554  */
555 static inline int
557 {
558  app_worker_t *app_wrk;
559  u32 session_index;
560  u8 n_subscribers;
561 
562  session_index = s->session_index;
563  n_subscribers = svm_fifo_n_subscribers (s->rx_fifo);
564 
565  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
566  if (PREDICT_FALSE (!app_wrk))
567  {
568  SESSION_DBG ("invalid s->app_index = %d", s->app_wrk_index);
569  return 0;
570  }
571 
572  SESSION_EVT (SESSION_EVT_ENQ, s, svm_fifo_max_dequeue_prod (s->rx_fifo));
573 
574  s->flags &= ~SESSION_F_RX_EVT;
577  return -1;
578 
579  if (PREDICT_FALSE (n_subscribers))
580  {
581  s = session_get (session_index, vlib_get_thread_index ());
582  return session_notify_subscribers (app_wrk->app_index, s,
584  }
585 
586  return 0;
587 }
588 
589 int
591 {
593 }
594 
595 static void
597 {
598  u32 session_index = pointer_to_uword (arg);
599  session_t *s;
600 
601  s = session_get_if_valid (session_index, vlib_get_thread_index ());
602  if (!s)
603  return;
604 
606 }
607 
608 /**
609  * Like session_enqueue_notify, but can be called from a thread that does not
610  * own the session.
611  */
612 void
614 {
615  u32 thread_index = session_thread_from_handle (sh);
616  u32 session_index = session_index_from_handle (sh);
617 
618  /*
619  * Pass session index (u32) as opposed to handle (u64) in case pointers
620  * are not 64-bit.
621  */
622  session_send_rpc_evt_to_thread (thread_index,
624  uword_to_pointer (session_index, void *));
625 }
626 
627 int
629 {
630  app_worker_t *app_wrk;
631 
633 
634  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
635  if (PREDICT_FALSE (!app_wrk))
636  return -1;
637 
640  return -1;
641 
642  if (PREDICT_FALSE (s->tx_fifo->n_subscribers))
643  return session_notify_subscribers (app_wrk->app_index, s,
645 
646  return 0;
647 }
648 
649 /**
650  * Flushes queue of sessions that are to be notified of new data
651  * enqueued events.
652  *
653  * @param thread_index Thread index for which the flush is to be performed.
654  * @return 0 on success or a positive number indicating the number of
655  * failures due to API queue being full.
656  */
657 int
658 session_main_flush_enqueue_events (u8 transport_proto, u32 thread_index)
659 {
660  session_worker_t *wrk = session_main_get_worker (thread_index);
661  session_t *s;
662  int i, errors = 0;
663  u32 *indices;
664 
665  indices = wrk->session_to_enqueue[transport_proto];
666 
667  for (i = 0; i < vec_len (indices); i++)
668  {
669  s = session_get_if_valid (indices[i], thread_index);
670  if (PREDICT_FALSE (!s))
671  {
672  errors++;
673  continue;
674  }
675 
677  errors++;
678  }
679 
680  vec_reset_length (indices);
681  wrk->session_to_enqueue[transport_proto] = indices;
682 
683  return errors;
684 }
685 
686 int
688 {
690  int i, errors = 0;
691  for (i = 0; i < 1 + vtm->n_threads; i++)
692  errors += session_main_flush_enqueue_events (transport_proto, i);
693  return errors;
694 }
695 
696 static inline int
698  session_state_t opened_state)
699 {
700  u32 opaque = 0, new_ti, new_si;
701  app_worker_t *app_wrk;
702  session_t *s = 0;
703  u64 ho_handle;
704 
705  /*
706  * Find connection handle and cleanup half-open table
707  */
708  ho_handle = session_lookup_half_open_handle (tc);
709  if (ho_handle == HALF_OPEN_LOOKUP_INVALID_VALUE)
710  {
711  SESSION_DBG ("half-open was removed!");
712  return -1;
713  }
715 
716  /* Get the app's index from the handle we stored when opening connection
717  * and the opaque (api_context for external apps) from transport session
718  * index */
719  app_wrk = app_worker_get_if_valid (ho_handle >> 32);
720  if (!app_wrk)
721  return -1;
722 
723  opaque = tc->s_index;
724 
725  if (is_fail)
726  return app_worker_connect_notify (app_wrk, s, opaque);
727 
729  s->session_state = SESSION_STATE_CONNECTING;
730  s->app_wrk_index = app_wrk->wrk_index;
731  new_si = s->session_index;
732  new_ti = s->thread_index;
733 
734  if (app_worker_init_connected (app_wrk, s))
735  {
736  session_free (s);
737  app_worker_connect_notify (app_wrk, 0, opaque);
738  return -1;
739  }
740 
741  s = session_get (new_si, new_ti);
742  s->session_state = opened_state;
744 
745  if (app_worker_connect_notify (app_wrk, s, opaque))
746  {
747  s = session_get (new_si, new_ti);
749  return -1;
750  }
751 
752  return 0;
753 }
754 
755 int
757 {
758  return session_stream_connect_notify_inline (tc, is_fail,
759  SESSION_STATE_READY);
760 }
761 
762 int
764 {
765  return session_stream_connect_notify_inline (tc, is_fail,
766  SESSION_STATE_OPENED);
767 }
768 
769 typedef struct _session_switch_pool_args
770 {
771  u32 session_index;
772  u32 thread_index;
773  u32 new_thread_index;
774  u32 new_session_index;
776 
777 /**
778  * Notify old thread of the session pool switch
779  */
780 static void
781 session_switch_pool (void *cb_args)
782 {
784  app_worker_t *app_wrk;
785  session_t *s;
786 
787  ASSERT (args->thread_index == vlib_get_thread_index ());
788  s = session_get (args->session_index, args->thread_index);
789  s->tx_fifo->master_session_index = args->new_session_index;
790  s->tx_fifo->master_thread_index = args->new_thread_index;
792  s->thread_index);
793 
794  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
795  if (app_wrk)
796  {
797  session_handle_t new_sh;
798  new_sh = session_make_handle (args->new_session_index,
799  args->new_thread_index);
800  app_worker_migrate_notify (app_wrk, s, new_sh);
801 
802  /* Trigger app read on the new thread */
804  }
805 
806  session_free (s);
807  clib_mem_free (cb_args);
808 }
809 
810 /**
811  * Move dgram session to the right thread
812  */
813 int
815  u32 old_thread_index, session_t ** new_session)
816 {
817  session_t *new_s;
818  session_switch_pool_args_t *rpc_args;
819 
820  /*
821  * Clone half-open session to the right thread.
822  */
823  new_s = session_clone_safe (tc->s_index, old_thread_index);
824  new_s->connection_index = tc->c_index;
825  new_s->rx_fifo->master_session_index = new_s->session_index;
826  new_s->rx_fifo->master_thread_index = new_s->thread_index;
827  new_s->session_state = SESSION_STATE_READY;
829 
830  /*
831  * Ask thread owning the old session to clean it up and make us the tx
832  * fifo owner
833  */
834  rpc_args = clib_mem_alloc (sizeof (*rpc_args));
835  rpc_args->new_session_index = new_s->session_index;
836  rpc_args->new_thread_index = new_s->thread_index;
837  rpc_args->session_index = tc->s_index;
838  rpc_args->thread_index = old_thread_index;
839  session_send_rpc_evt_to_thread (rpc_args->thread_index, session_switch_pool,
840  rpc_args);
841 
842  tc->s_index = new_s->session_index;
843  new_s->connection_index = tc->c_index;
844  *new_session = new_s;
845  return 0;
846 }
847 
848 /**
849  * Notification from transport that connection is being closed.
850  *
851  * A disconnect is sent to application but state is not removed. Once
852  * disconnect is acknowledged by application, session disconnect is called.
853  * Ultimately this leads to close being called on transport (passive close).
854  */
855 void
857 {
858  app_worker_t *app_wrk;
859  session_t *s;
860 
861  s = session_get (tc->s_index, tc->thread_index);
862  if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
863  return;
864  s->session_state = SESSION_STATE_TRANSPORT_CLOSING;
865  app_wrk = app_worker_get (s->app_wrk_index);
866  app_worker_close_notify (app_wrk, s);
867 }
868 
869 /**
870  * Notification from transport that connection is being deleted
871  *
872  * This removes the session if it is still valid. It should be called only on
873  * previously fully established sessions. For instance failed connects should
874  * call stream_session_connect_notify and indicate that the connect has
875  * failed.
876  */
877 void
879 {
880  session_t *s;
881 
882  /* App might've been removed already */
883  if (!(s = session_get_if_valid (tc->s_index, tc->thread_index)))
884  return;
885 
886  switch (s->session_state)
887  {
888  case SESSION_STATE_CREATED:
889  /* Session was created but accept notification was not yet sent to the
890  * app. Cleanup everything. */
893  session_free (s);
894  break;
895  case SESSION_STATE_ACCEPTING:
896  case SESSION_STATE_TRANSPORT_CLOSING:
897  case SESSION_STATE_CLOSING:
898  case SESSION_STATE_TRANSPORT_CLOSED:
899  /* If transport finishes or times out before we get a reply
900  * from the app, mark transport as closed and wait for reply
901  * before removing the session. Cleanup session table in advance
902  * because transport will soon be closed and closed sessions
903  * are assumed to have been removed from the lookup table */
905  s->session_state = SESSION_STATE_TRANSPORT_DELETED;
908  break;
909  case SESSION_STATE_APP_CLOSED:
910  /* Cleanup lookup table as transport needs to still be valid.
911  * Program transport close to ensure that all session events
912  * have been cleaned up. Once transport close is called, the
913  * session is just removed because both transport and app have
914  * confirmed the close*/
916  s->session_state = SESSION_STATE_TRANSPORT_DELETED;
920  break;
921  case SESSION_STATE_TRANSPORT_DELETED:
922  break;
923  case SESSION_STATE_CLOSED:
925  session_delete (s);
926  break;
927  default:
928  clib_warning ("session state %u", s->session_state);
930  session_delete (s);
931  break;
932  }
933 }
934 
935 /**
936  * Notification from transport that it is closed
937  *
938  * Should be called by transport, prior to calling delete notify, once it
939  * knows that no more data will be exchanged. This could serve as an
940  * early acknowledgment of an active close especially if transport delete
941  * can be delayed a long time, e.g., tcp time-wait.
942  */
943 void
945 {
946  app_worker_t *app_wrk;
947  session_t *s;
948 
949  if (!(s = session_get_if_valid (tc->s_index, tc->thread_index)))
950  return;
951 
952  /* Transport thinks that app requested close but it actually didn't.
953  * Can happen for tcp if fin and rst are received in close succession. */
954  if (s->session_state == SESSION_STATE_READY)
955  {
958  s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
959  }
960  /* If app close has not been received or has not yet resulted in
961  * a transport close, only mark the session transport as closed */
962  else if (s->session_state <= SESSION_STATE_CLOSING)
963  {
964  s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
965  }
966  /* If app also closed, switch to closed */
967  else if (s->session_state == SESSION_STATE_APP_CLOSED)
968  s->session_state = SESSION_STATE_CLOSED;
969 
970  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
971  if (app_wrk)
973 }
974 
975 /**
976  * Notify application that connection has been reset.
977  */
978 void
980 {
981  app_worker_t *app_wrk;
982  session_t *s;
983 
984  s = session_get (tc->s_index, tc->thread_index);
986  if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
987  return;
988  s->session_state = SESSION_STATE_TRANSPORT_CLOSING;
989  app_wrk = app_worker_get (s->app_wrk_index);
990  app_worker_reset_notify (app_wrk, s);
991 }
992 
993 int
995 {
996  app_worker_t *app_wrk;
997  session_t *s;
998 
999  s = session_get (tc->s_index, tc->thread_index);
1000  app_wrk = app_worker_get_if_valid (s->app_wrk_index);
1001  if (!app_wrk)
1002  return -1;
1003  s->session_state = SESSION_STATE_ACCEPTING;
1004  return app_worker_accept_notify (app_wrk, s);
1005 }
1006 
1007 /**
1008  * Accept a stream session. Optionally ping the server by callback.
1009  */
1010 int
1012  u32 thread_index, u8 notify)
1013 {
1014  session_t *s;
1015  int rv;
1016 
1018  s->listener_handle = ((u64) thread_index << 32) | (u64) listener_index;
1019  s->session_state = SESSION_STATE_CREATED;
1020 
1021  if ((rv = app_worker_init_accepted (s)))
1022  return rv;
1023 
1025 
1026  /* Shoulder-tap the server */
1027  if (notify)
1028  {
1029  app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
1030  return app_worker_accept_notify (app_wrk, s);
1031  }
1032 
1033  return 0;
1034 }
1035 
1036 int
1037 session_open_cl (u32 app_wrk_index, session_endpoint_t * rmt, u32 opaque)
1038 {
1041  app_worker_t *app_wrk;
1042  session_handle_t sh;
1043  session_t *s;
1044  int rv;
1045 
1047  rv = transport_connect (rmt->transport_proto, tep);
1048  if (rv < 0)
1049  {
1050  SESSION_DBG ("Transport failed to open connection.");
1051  return VNET_API_ERROR_SESSION_CONNECT;
1052  }
1053 
1054  tc = transport_get_half_open (rmt->transport_proto, (u32) rv);
1055 
1056  /* For dgram type of service, allocate session and fifos now */
1057  app_wrk = app_worker_get (app_wrk_index);
1059  s->app_wrk_index = app_wrk->wrk_index;
1060  s->session_state = SESSION_STATE_OPENED;
1061  if (app_worker_init_connected (app_wrk, s))
1062  {
1063  session_free (s);
1064  return -1;
1065  }
1066 
1067  sh = session_handle (s);
1069  return app_worker_connect_notify (app_wrk, s, opaque);
1070 }
1071 
1072 int
1073 session_open_vc (u32 app_wrk_index, session_endpoint_t * rmt, u32 opaque)
1074 {
1077  u64 handle;
1078  int rv;
1079 
1081  rv = transport_connect (rmt->transport_proto, tep);
1082  if (rv < 0)
1083  {
1084  SESSION_DBG ("Transport failed to open connection.");
1085  return VNET_API_ERROR_SESSION_CONNECT;
1086  }
1087 
1088  tc = transport_get_half_open (rmt->transport_proto, (u32) rv);
1089 
1090  /* If transport offers a stream service, only allocate session once the
1091  * connection has been established.
1092  * Add connection to half-open table and save app and tc index. The
1093  * latter is needed to help establish the connection while the former
1094  * is needed when the connect notify comes and we have to notify the
1095  * external app
1096  */
1097  handle = (((u64) app_wrk_index) << 32) | (u64) tc->c_index;
1098  session_lookup_add_half_open (tc, handle);
1099 
1100  /* Store api_context (opaque) for when the reply comes. Not the nicest
1101  * thing but better than allocating a separate half-open pool.
1102  */
1103  tc->s_index = opaque;
1104  if (transport_half_open_has_fifos (rmt->transport_proto))
1105  return session_ho_stream_connect_notify (tc, 0 /* is_fail */ );
1106  return 0;
1107 }
1108 
1109 int
1110 session_open_app (u32 app_wrk_index, session_endpoint_t * rmt, u32 opaque)
1111 {
1114 
1115  sep->app_wrk_index = app_wrk_index;
1116  sep->opaque = opaque;
1117 
1118  return transport_connect (rmt->transport_proto, tep_cfg);
1119 }
1120 
1122 
1123 /* *INDENT-OFF* */
1128 };
1129 /* *INDENT-ON* */
1130 
1131 /**
1132  * Ask transport to open connection to remote transport endpoint.
1133  *
1134  * Stores handle for matching request with reply since the call can be
1135  * asynchronous. For instance, for TCP the 3-way handshake must complete
1136  * before reply comes. Session is only created once connection is established.
1137  *
1138  * @param app_index Index of the application requesting the connect
1139  * @param st Session type requested.
1140  * @param tep Remote transport endpoint
1141  * @param opaque Opaque data (typically, api_context) the application expects
1142  * on open completion.
1143  */
1144 int
1145 session_open (u32 app_wrk_index, session_endpoint_t * rmt, u32 opaque)
1146 {
1148  tst = transport_protocol_service_type (rmt->transport_proto);
1149  return session_open_srv_fns[tst] (app_wrk_index, rmt, opaque);
1150 }
1151 
1152 /**
1153  * Ask transport to listen on session endpoint.
1154  *
1155  * @param s Session for which listen will be called. Note that unlike
1156  * established sessions, listen sessions are not associated to a
1157  * thread.
1158  * @param sep Local endpoint to be listened on.
1159  */
1160 int
1162 {
1163  transport_endpoint_t *tep;
1164  u32 tc_index, s_index;
1165 
1166  /* Transport bind/listen */
1167  tep = session_endpoint_to_transport (sep);
1168  s_index = ls->session_index;
1170  s_index, tep);
1171 
1172  if (tc_index == (u32) ~ 0)
1173  return -1;
1174 
1175  /* Attach transport to session. Lookup tables are populated by the app
1176  * worker because local tables (for ct sessions) are not backed by a fib */
1177  ls = listen_session_get (s_index);
1178  ls->connection_index = tc_index;
1179 
1180  return 0;
1181 }
1182 
1183 /**
1184  * Ask transport to stop listening on local transport endpoint.
1185  *
1186  * @param s Session to stop listening on. It must be in state LISTENING.
1187  */
1188 int
1190 {
1193 
1194  if (s->session_state != SESSION_STATE_LISTENING)
1195  return -1;
1196 
1198  if (!tc)
1199  return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
1200 
1201  if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
1204  return 0;
1205 }
1206 
1207 /**
1208  * Initialize session closing procedure.
1209  *
1210  * Request is always sent to session node to ensure that all outstanding
1211  * requests are served before transport is notified.
1212  */
1213 void
1215 {
1216  if (!s)
1217  return;
1218 
1219  if (s->session_state >= SESSION_STATE_CLOSING)
1220  {
1221  /* Session will only be removed once both app and transport
1222  * acknowledge the close */
1223  if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED
1224  || s->session_state == SESSION_STATE_TRANSPORT_DELETED)
1226  return;
1227  }
1228 
1229  s->session_state = SESSION_STATE_CLOSING;
1231 }
1232 
1233 /**
1234  * Force a close without waiting for data to be flushed
1235  */
1236 void
1238 {
1239  if (s->session_state >= SESSION_STATE_CLOSING)
1240  return;
1241  /* Drop all outstanding tx data */
1243  s->session_state = SESSION_STATE_CLOSING;
1245 }
1246 
1247 /**
1248  * Notify transport the session can be disconnected. This should eventually
1249  * result in a delete notification that allows us to cleanup session state.
1250  * Called for both active/passive disconnects.
1251  *
1252  * Must be called from the session's thread.
1253  */
1254 void
1256 {
1257  if (s->session_state >= SESSION_STATE_APP_CLOSED)
1258  {
1259  if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED)
1260  s->session_state = SESSION_STATE_CLOSED;
1261  /* If transport is already deleted, just free the session */
1262  else if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
1264  return;
1265  }
1266 
1267  /* If the tx queue wasn't drained, the transport can continue to try
1268  * sending the outstanding data (in closed state it cannot). It MUST however
1269  * at one point, either after sending everything or after a timeout, call
1270  * delete notify. This will finally lead to the complete cleanup of the
1271  * session.
1272  */
1273  s->session_state = SESSION_STATE_APP_CLOSED;
1274 
1276  s->thread_index);
1277 }
1278 
1279 /**
1280  * Force transport close
1281  */
1282 void
1284 {
1285  if (s->session_state >= SESSION_STATE_APP_CLOSED)
1286  {
1287  if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED)
1288  s->session_state = SESSION_STATE_CLOSED;
1289  else if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
1291  return;
1292  }
1293 
1294  s->session_state = SESSION_STATE_APP_CLOSED;
1296  s->thread_index);
1297 }
1298 
1299 /**
1300  * Cleanup transport and session state.
1301  *
1302  * Notify transport of the cleanup and free the session. This should
1303  * be called only if transport reported some error and is already
1304  * closed.
1305  */
1306 void
1308 {
1309  /* Delete from main lookup table before we axe the the transport */
1311  if (s->session_state != SESSION_STATE_TRANSPORT_DELETED)
1313  s->thread_index);
1314  /* Since we called cleanup, no delete notification will come. So, make
1315  * sure the session is properly freed. */
1317 }
1318 
1319 /**
1320  * Allocate event queues in the shared-memory segment
1321  *
1322  * That can either be a newly created memfd segment, that will need to be
1323  * mapped by all stack users, or the binary api's svm region. The latter is
1324  * assumed to be already mapped. NOTE that this assumption DOES NOT hold if
1325  * api clients bootstrap shm api over sockets (i.e. use memfd segments) and
1326  * vpp uses api svm region for event queues.
1327  */
1328 void
1330 {
1331  u32 evt_q_length = 2048, evt_size = sizeof (session_event_t);
1332  ssvm_private_t *eqs = &smm->evt_qs_segment;
1333  api_main_t *am = &api_main;
1334  uword eqs_size = 64 << 20;
1335  pid_t vpp_pid = getpid ();
1336  void *oldheap;
1337  int i;
1338 
1340  evt_q_length = smm->configured_event_queue_length;
1341 
1342  if (smm->evt_qs_use_memfd_seg)
1343  {
1344  if (smm->evt_qs_segment_size)
1345  eqs_size = smm->evt_qs_segment_size;
1346 
1347  eqs->ssvm_size = eqs_size;
1348  eqs->i_am_master = 1;
1349  eqs->my_pid = vpp_pid;
1350  eqs->name = format (0, "%s%c", "evt-qs-segment", 0);
1351  eqs->requested_va = smm->session_baseva;
1352 
1354  {
1355  clib_warning ("failed to initialize queue segment");
1356  return;
1357  }
1358  }
1359 
1360  if (smm->evt_qs_use_memfd_seg)
1361  oldheap = ssvm_push_heap (eqs->sh);
1362  else
1363  oldheap = svm_push_data_heap (am->vlib_rp);
1364 
1365  for (i = 0; i < vec_len (smm->wrk); i++)
1366  {
1367  svm_msg_q_cfg_t _cfg, *cfg = &_cfg;
1369  {evt_q_length, evt_size, 0}
1370  ,
1371  {evt_q_length >> 1, 256, 0}
1372  };
1373  cfg->consumer_pid = 0;
1374  cfg->n_rings = 2;
1375  cfg->q_nitems = evt_q_length;
1376  cfg->ring_cfgs = rc;
1377  smm->wrk[i].vpp_event_queue = svm_msg_q_alloc (cfg);
1378  if (smm->evt_qs_use_memfd_seg)
1379  {
1381  clib_warning ("eventfd returned");
1382  }
1383  }
1384 
1385  if (smm->evt_qs_use_memfd_seg)
1386  ssvm_pop_heap (oldheap);
1387  else
1388  svm_pop_heap (oldheap);
1389 }
1390 
1393 {
1394  session_main_t *smm = &session_main;
1395  if (smm->evt_qs_use_memfd_seg)
1396  return &smm->evt_qs_segment;
1397  return 0;
1398 }
1399 
1400 u64
1402 {
1403  svm_fifo_t *f;
1404 
1405  if (!s->rx_fifo)
1406  return SESSION_INVALID_HANDLE;
1407 
1408  f = s->rx_fifo;
1409  return segment_manager_make_segment_handle (f->segment_manager,
1410  f->segment_index);
1411 }
1412 
1413 /* *INDENT-OFF* */
1418  session_tx_fifo_dequeue_and_snd
1419 };
1420 /* *INDENT-ON* */
1421 
1422 /**
1423  * Initialize session layer for given transport proto and ip version
1424  *
1425  * Allocates per session type (transport proto + ip version) data structures
1426  * and adds arc from session queue node to session type output node.
1427  */
1428 void
1430  const transport_proto_vft_t * vft, u8 is_ip4,
1431  u32 output_node)
1432 {
1433  session_main_t *smm = &session_main;
1434  session_type_t session_type;
1435  u32 next_index = ~0;
1436 
1437  session_type = session_type_from_proto_and_ip (transport_proto, is_ip4);
1438 
1439  vec_validate (smm->session_type_to_next, session_type);
1440  vec_validate (smm->session_tx_fns, session_type);
1441 
1442  /* *INDENT-OFF* */
1443  if (output_node != ~0)
1444  {
1445  foreach_vlib_main (({
1446  next_index = vlib_node_add_next (this_vlib_main,
1447  session_queue_node.index,
1448  output_node);
1449  }));
1450  }
1451  /* *INDENT-ON* */
1452 
1453  smm->session_type_to_next[session_type] = next_index;
1454  smm->session_tx_fns[session_type] =
1455  session_tx_fns[vft->transport_options.tx_type];
1456 }
1457 
1460 {
1461  if (s->session_state != SESSION_STATE_LISTENING)
1464  else
1466  s->connection_index);
1467 }
1468 
1469 void
1471 {
1472  if (s->session_state != SESSION_STATE_LISTENING)
1474  s->connection_index, s->thread_index, tep,
1475  is_lcl);
1476  else
1478  s->connection_index, tep, is_lcl);
1479 }
1480 
1483 {
1485  s->connection_index);
1486 }
1487 
1488 void
1490 {
1491  ASSERT (vlib_get_thread_index () == 0);
1494 }
1495 
1496 static clib_error_t *
1498 {
1499  segment_manager_main_init_args_t _sm_args = { 0 }, *sm_args = &_sm_args;
1500  session_main_t *smm = &session_main;
1502  u32 num_threads, preallocated_sessions_per_worker;
1503  session_worker_t *wrk;
1504  int i;
1505 
1506  num_threads = 1 /* main thread */ + vtm->n_threads;
1507 
1508  if (num_threads < 1)
1509  return clib_error_return (0, "n_thread_stacks not set");
1510 
1511  /* Allocate cache line aligned worker contexts */
1512  vec_validate_aligned (smm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES);
1513 
1514  for (i = 0; i < num_threads; i++)
1515  {
1516  wrk = &smm->wrk[i];
1517  wrk->ctrl_head = clib_llist_make_head (wrk->event_elts, evt_list);
1518  wrk->new_head = clib_llist_make_head (wrk->event_elts, evt_list);
1519  wrk->old_head = clib_llist_make_head (wrk->event_elts, evt_list);
1520  wrk->vm = vlib_mains[i];
1521  wrk->last_vlib_time = vlib_time_now (vm);
1523 
1524  if (num_threads > 1)
1526  }
1527 
1528  /* Allocate vpp event queues segment and queue */
1530 
1531  /* Initialize fifo segment main baseva and timeout */
1532  sm_args->baseva = smm->session_baseva + smm->evt_qs_segment_size;
1533  sm_args->size = smm->session_va_space_size;
1534  segment_manager_main_init (sm_args);
1535 
1536  /* Preallocate sessions */
1537  if (smm->preallocated_sessions)
1538  {
1539  if (num_threads == 1)
1540  {
1542  }
1543  else
1544  {
1545  int j;
1546  preallocated_sessions_per_worker =
1547  (1.1 * (f64) smm->preallocated_sessions /
1548  (f64) (num_threads - 1));
1549 
1550  for (j = 1; j < num_threads; j++)
1551  {
1552  pool_init_fixed (smm->wrk[j].sessions,
1553  preallocated_sessions_per_worker);
1554  }
1555  }
1556  }
1557 
1560  transport_init ();
1561 
1562  smm->is_enabled = 1;
1563 
1564  /* Enable transports */
1565  transport_enable_disable (vm, 1);
1566  return 0;
1567 }
1568 
1569 void
1571 {
1572  u8 state = is_en ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED;
1574  u8 have_workers = vtm->n_threads != 0;
1575 
1576  /* *INDENT-OFF* */
1577  foreach_vlib_main (({
1578  if (have_workers && ii == 0)
1579  {
1580  vlib_node_set_state (this_vlib_main, session_queue_process_node.index,
1581  state);
1582  if (is_en)
1583  {
1584  vlib_node_t *n = vlib_get_node (this_vlib_main,
1586  vlib_start_process (this_vlib_main, n->runtime_index);
1587  }
1588  else
1589  {
1590  vlib_process_signal_event_mt (this_vlib_main,
1593  }
1594 
1595  continue;
1596  }
1597  vlib_node_set_state (this_vlib_main, session_queue_node.index,
1598  state);
1599  }));
1600  /* *INDENT-ON* */
1601 }
1602 
1603 clib_error_t *
1605 {
1606  clib_error_t *error = 0;
1607  if (is_en)
1608  {
1609  if (session_main.is_enabled)
1610  return 0;
1611 
1612  error = session_manager_main_enable (vm);
1614  }
1615  else
1616  {
1617  session_main.is_enabled = 0;
1619  }
1620 
1621  return error;
1622 }
1623 
1624 clib_error_t *
1626 {
1627  session_main_t *smm = &session_main;
1629 #if (HIGH_SEGMENT_BASEVA > (4ULL << 30))
1630  smm->session_va_space_size = 128ULL << 30;
1631  smm->evt_qs_segment_size = 64 << 20;
1632 #else
1633  smm->session_va_space_size = 128 << 20;
1634  smm->evt_qs_segment_size = 1 << 20;
1635 #endif
1636  smm->is_enabled = 0;
1637  return 0;
1638 }
1639 
1641 
1642 static clib_error_t *
1644 {
1645  session_main_t *smm = &session_main;
1646  u32 nitems;
1647  uword tmp;
1648 
1649  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1650  {
1651  if (unformat (input, "event-queue-length %d", &nitems))
1652  {
1653  if (nitems >= 2048)
1654  smm->configured_event_queue_length = nitems;
1655  else
1656  clib_warning ("event queue length %d too small, ignored", nitems);
1657  }
1658  else if (unformat (input, "preallocated-sessions %d",
1659  &smm->preallocated_sessions))
1660  ;
1661  else if (unformat (input, "v4-session-table-buckets %d",
1663  ;
1664  else if (unformat (input, "v4-halfopen-table-buckets %d",
1666  ;
1667  else if (unformat (input, "v6-session-table-buckets %d",
1669  ;
1670  else if (unformat (input, "v6-halfopen-table-buckets %d",
1672  ;
1673  else if (unformat (input, "v4-session-table-memory %U",
1674  unformat_memory_size, &tmp))
1675  {
1676  if (tmp >= 0x100000000)
1677  return clib_error_return (0, "memory size %llx (%lld) too large",
1678  tmp, tmp);
1680  }
1681  else if (unformat (input, "v4-halfopen-table-memory %U",
1682  unformat_memory_size, &tmp))
1683  {
1684  if (tmp >= 0x100000000)
1685  return clib_error_return (0, "memory size %llx (%lld) too large",
1686  tmp, tmp);
1688  }
1689  else if (unformat (input, "v6-session-table-memory %U",
1690  unformat_memory_size, &tmp))
1691  {
1692  if (tmp >= 0x100000000)
1693  return clib_error_return (0, "memory size %llx (%lld) too large",
1694  tmp, tmp);
1696  }
1697  else if (unformat (input, "v6-halfopen-table-memory %U",
1698  unformat_memory_size, &tmp))
1699  {
1700  if (tmp >= 0x100000000)
1701  return clib_error_return (0, "memory size %llx (%lld) too large",
1702  tmp, tmp);
1704  }
1705  else if (unformat (input, "local-endpoints-table-memory %U",
1706  unformat_memory_size, &tmp))
1707  {
1708  if (tmp >= 0x100000000)
1709  return clib_error_return (0, "memory size %llx (%lld) too large",
1710  tmp, tmp);
1711  smm->local_endpoints_table_memory = tmp;
1712  }
1713  else if (unformat (input, "local-endpoints-table-buckets %d",
1715  ;
1716  else if (unformat (input, "evt_qs_memfd_seg"))
1717  smm->evt_qs_use_memfd_seg = 1;
1718  else if (unformat (input, "evt_qs_seg_size %U", unformat_memory_size,
1719  &smm->evt_qs_segment_size))
1720  ;
1721  else if (unformat (input, "enable"))
1722  vnet_session_enable_disable (vm, 1 /* is_en */ );
1723  else
1724  return clib_error_return (0, "unknown input `%U'",
1725  format_unformat_error, input);
1726  }
1727  return 0;
1728 }
1729 
1731 
1732 /*
1733  * fd.io coding-style-patch-verification: ON
1734  *
1735  * Local Variables:
1736  * eval: (c-set-style "gnu")
1737  * End:
1738  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
#define session_endpoint_to_transport_cfg(_sep)
Definition: session_types.h:91
u32 preallocated_sessions
Preallocate session config parameter.
Definition: session.h:194
int app_worker_lock_and_send_event(app_worker_t *app, session_t *s, u8 evt_type)
Send event to application.
void transport_close(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:266
u64 ssvm_size
Definition: ssvm.h:85
static session_open_service_fn session_open_srv_fns[TRANSPORT_N_SERVICES]
Definition: session.c:1124
u32 connection_index
Index of the transport connection associated to the session.
uword evt_qs_segment_size
Definition: session.h:176
void session_flush_frames_main_thread(vlib_main_t *vm)
Definition: session.c:1489
int app_worker_init_accepted(session_t *s)
void session_transport_reset(session_t *s)
Force transport close.
Definition: session.c:1283
int session_lookup_del_connection(transport_connection_t *tc)
Delete transport connection from session table.
int app_worker_reset_notify(app_worker_t *app_wrk, session_t *s)
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
int session_open(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Ask transport to open connection to remote transport endpoint.
Definition: session.c:1145
static void svm_pop_heap(void *oldheap)
Definition: svm.h:94
session_type_t session_type
Type built from transport and network protocol types.
uword requested_va
Definition: ssvm.h:88
#define SESSION_Q_PROCESS_FLUSH_FRAMES
Definition: session.h:203
svm_msg_q_t * vpp_event_queue
vpp event message queue for worker
Definition: session.h:84
void transport_get_listener_endpoint(transport_proto_t tp, u32 conn_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:334
static u32 svm_fifo_max_enqueue_prod(svm_fifo_t *f)
Maximum number of bytes that can be enqueued into fifo.
Definition: svm_fifo.h:618
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:173
svm_fifo_t * tx_fifo
session_main_t session_main
Definition: session.c:26
int session_tx_fifo_peek_bytes(transport_connection_t *tc, u8 *buffer, u32 offset, u32 max_bytes)
Definition: session.c:502
u32 session_index
Index in thread pool where session was allocated.
int session_stop_listen(session_t *s)
Ask transport to stop listening on local transport endpoint.
Definition: session.c:1189
unsigned long u64
Definition: types.h:89
transport_connection_t * listen_session_get_transport(session_t *s)
Definition: session.c:1482
static svm_msg_q_t * session_main_get_vpp_event_queue(u32 thread_index)
Definition: session.h:605
u32 configured_v4_halfopen_table_buckets
Definition: session.h:182
int session_ho_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
Definition: session.c:763
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void session_transport_delete_notify(transport_connection_t *tc)
Notification from transport that connection is being deleted.
Definition: session.c:878
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1459
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:279
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_worker_t * wrk
Worker contexts.
Definition: session.h:147
static session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:300
void session_add_self_custom_tx_evt(transport_connection_t *tc, u8 has_prio)
Definition: session.c:122
#define pool_get_aligned_will_expand(P, YESNO, A)
See if pool_get will expand the pool or not.
Definition: pool.h:242
int session_enqueue_dgram_connection(session_t *s, session_dgram_hdr_t *hdr, vlib_buffer_t *b, u8 proto, u8 queue_event)
Definition: session.c:466
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static int session_enqueue_notify_inline(session_t *s)
Notify session peer that new data has been enqueued.
Definition: session.c:556
int session_main_flush_enqueue_events(u8 transport_proto, u32 thread_index)
Flushes queue of sessions that are to be notified of new data enqueued events.
Definition: session.c:658
session_evt_type_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static transport_proto_t session_get_transport_proto(session_t *s)
void session_send_rpc_evt_to_thread(u32 thread_index, void *fp, void *rpc_args)
Definition: session.c:110
int svm_fifo_peek(svm_fifo_t *f, u32 offset, u32 len, u8 *dst)
Peek data from fifo.
Definition: svm_fifo.c:1007
void session_transport_reset_notify(transport_connection_t *tc)
Notify application that connection has been reset.
Definition: session.c:979
int i
int session_open_vc(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Definition: session.c:1073
void svm_fifo_dequeue_drop_all(svm_fifo_t *f)
Dequeue and drop all bytes from fifo.
Definition: svm_fifo.c:1061
ssvm_shared_header_t * sh
Definition: ssvm.h:84
u32 transport_start_listen(transport_proto_t tp, u32 session_index, transport_endpoint_t *tep)
Definition: transport.c:281
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:293
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
session_evt_elt_t * event_elts
Pool of session event list elements.
Definition: session.h:105
u8 data[128]
Definition: ipsec.api:251
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
u32 flags
Session flags.
int session_enqueue_stream_connection(transport_connection_t *tc, vlib_buffer_t *b, u32 offset, u8 queue_event, u8 is_in_order)
Definition: session.c:413
u64 session_lookup_half_open_handle(transport_connection_t *tc)
static session_t * session_clone_safe(u32 session_index, u32 thread_index)
Definition: session.h:390
u32 local_endpoints_table_memory
Transport table (preallocation) size parameters.
Definition: session.h:190
void session_node_enable_disable(u8 is_en)
Definition: session.c:1570
vlib_node_registration_t session_queue_node
(constructor) VLIB_REGISTER_NODE (session_queue_node)
vlib_main_t ** vlib_mains
Definition: buffer.c:332
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
app_worker_t * application_get_worker(application_t *app, u32 wrk_map_index)
Definition: application.c:644
session_fifo_rx_fn session_tx_fifo_peek_and_snd
session_t * sessions
Worker session pool.
Definition: session.h:81
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
static session_fifo_rx_fn * session_tx_fns[TRANSPORT_TX_N_FNS]
Definition: session.c:1414
static session_handle_t session_handle(session_t *s)
struct _svm_fifo svm_fifo_t
void session_get_endpoint(session_t *s, transport_endpoint_t *tep, u8 is_lcl)
Definition: session.c:1470
u8 session_type_t
void session_transport_closing_notify(transport_connection_t *tc)
Notification from transport that connection is being closed.
Definition: session.c:856
u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
int session_open_cl(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Definition: session.c:1037
#define clib_llist_make_head(LP, name)
Initialize llist head.
Definition: llist.h:106
static session_worker_t * session_main_get_worker(u32 thread_index)
Definition: session.h:591
void session_free_w_fifos(session_t *s)
Definition: session.c:246
#define session_endpoint_to_transport(_sep)
Definition: session_types.h:90
void app_namespaces_init(void)
vlib_main_t * vm
Convenience pointer to this worker&#39;s vlib_main.
Definition: session.h:93
static clib_error_t * session_config_fn(vlib_main_t *vm, unformat_input_t *input)
Definition: session.c:1643
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
Definition: message_queue.c:40
u8 transport_half_open_has_fifos(transport_proto_t tp)
Definition: transport.c:236
int session_send_ctrl_evt_to_thread(session_t *s, session_evt_type_t evt_type)
Definition: session.c:93
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static void * svm_push_data_heap(svm_region_t *rp)
Definition: svm.h:86
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
#define always_inline
Definition: clib.h:98
clib_llist_index_t new_head
Head of list of elements.
Definition: session.h:114
u32 * session_type_to_next
Per session type output nodes.
Definition: session.h:161
static int session_stream_connect_notify_inline(transport_connection_t *tc, u8 is_fail, session_state_t opened_state)
Definition: session.c:697
static int session_enqueue_chain_tail(session_t *s, vlib_buffer_t *b, u32 offset, u8 is_in_order)
Enqueue buffer chain tail.
Definition: session.c:326
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
Definition: ssvm.h:143
#define clib_error_return(e, args...)
Definition: error.h:99
svm_region_t * vlib_rp
Current binary api segment descriptor.
Definition: api_common.h:256
uword session_baseva
Session ssvm segment configs.
Definition: session.h:174
vhost_vring_state_t state
Definition: vhost_user.h:146
unsigned int u32
Definition: types.h:88
int session_send_io_evt_to_thread(svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:79
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
Definition: ssvm.c:425
u8 session_is_valid(u32 si, u8 thread_index)
Definition: session.c:209
static void ssvm_pop_heap(void *oldheap)
Definition: ssvm.h:151
void transport_reset(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:272
#define HALF_OPEN_LOOKUP_INVALID_VALUE
#define SESSION_INVALID_HANDLE
Definition: session_types.h:23
int session_lookup_del_half_open(transport_connection_t *tc)
session_state_t
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:257
static clib_error_t * session_manager_main_enable(vlib_main_t *vm)
Definition: session.c:1497
struct _transport_proto_vft transport_proto_vft_t
int session_dequeue_notify(session_t *s)
Definition: session.c:628
struct _session_endpoint_cfg session_endpoint_cfg_t
u32 configured_v6_halfopen_table_memory
Definition: session.h:187
u32 configured_v6_session_table_buckets
Definition: session.h:184
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
static void clib_rwlock_init(clib_rwlock_t *p)
Definition: lock.h:133
#define CLIB_US_TIME_FREQ
Definition: time.h:207
int svm_msg_q_alloc_consumer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
session_event_t evt
Definition: session.h:68
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
Definition: transport.c:242
uword session_va_space_size
Definition: session.h:175
void session_send_rpc_evt_to_thread_force(u32 thread_index, void *fp, void *rpc_args)
Definition: session.c:102
u32 configured_v4_session_table_buckets
Session table size parameters.
Definition: session.h:180
void transport_get_endpoint(transport_proto_t tp, u32 conn_index, u32 thread_index, transport_endpoint_t *tep, u8 is_lcl)
Definition: transport.c:318
int app_worker_accept_notify(app_worker_t *app_wrk, session_t *s)
u32 app_index
Index of application that owns the listener.
struct _unformat_input_t unformat_input_t
u32 configured_v6_halfopen_table_buckets
Definition: session.h:186
u32 configured_event_queue_length
vpp fifo event queue configured length
Definition: session.h:171
u8 is_enabled
Session manager is enabled.
Definition: session.h:168
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#define APP_INVALID_INDEX
Definition: application.h:167
int svm_fifo_enqueue(svm_fifo_t *f, u32 len, const u8 *src)
Enqueue data to fifo.
Definition: svm_fifo.c:888
enum transport_service_type_ transport_service_type_t
#define PREDICT_FALSE(x)
Definition: clib.h:111
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:182
int session_lookup_del_session(session_t *s)
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
clib_error_t * session_manager_main_init(vlib_main_t *vm)
Definition: session.c:1625
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
static u32 svm_fifo_max_dequeue_prod(svm_fifo_t *f)
Fifo max bytes to dequeue optimized for producer.
Definition: svm_fifo.h:512
session_fifo_rx_fn ** session_tx_fns
Per transport rx function that can either dequeue or peek.
Definition: session.h:156
u64 session_segment_handle(session_t *s)
Definition: session.c:1401
#define foreach_vlib_main(body)
Definition: threads.h:236
static session_evt_elt_t * session_evt_alloc_old(session_worker_t *wrk)
Definition: session.h:278
void transport_cleanup(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.c:254
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1604
u32 transport_stop_listen(transport_proto_t tp, u32 conn_index)
Definition: transport.c:288
struct _session_switch_pool_args session_switch_pool_args_t
u8 len
Definition: ip_types.api:90
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
clib_rwlock_t peekers_rw_locks
Peekers rw lock.
Definition: session.h:120
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
#define SESSION_DBG(_fmt, _args...)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
Definition: lock.h:187
static u8 svm_fifo_set_event(svm_fifo_t *f)
Set fifo event flag.
Definition: svm_fifo.h:748
u32 n_rings
number of msg rings
Definition: message_queue.h:54
u8 evt_qs_use_memfd_seg
Definition: session.h:177
void transport_init(void)
Definition: transport.c:730
int app_worker_transport_closed_notify(app_worker_t *app_wrk, session_t *s)
session_fifo_rx_fn session_tx_fifo_dequeue_and_snd
ssvm_private_t evt_qs_segment
Event queues memfd segment initialized only if so configured.
Definition: session.h:150
static u8 svm_fifo_needs_deq_ntf(svm_fifo_t *f, u32 n_last_deq)
Check if fifo needs dequeue notification.
Definition: svm_fifo.h:839
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 runtime_index
Definition: node.h:283
session_handle_t listener_handle
Parent listener session index if the result of an accept.
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:213
int transport_connect(transport_proto_t tp, transport_endpoint_cfg_t *tep)
Definition: transport.c:260
vlib_main_t * vm
Definition: buffer.c:323
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
static transport_connection_t * transport_get_connection(transport_proto_t tp, u32 conn_index, u8 thread_index)
Definition: transport.h:117
static void vlib_process_signal_event_mt(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Signal event to process from any thread.
Definition: node_funcs.h:958
static void session_cleanup_notify(session_t *s, session_cleanup_ntf_t ntf)
Definition: session.c:235
void session_free(session_t *s)
Definition: session.c:195
int app_worker_cleanup_notify(app_worker_t *app_wrk, session_t *s, session_cleanup_ntf_t ntf)
#define clib_warning(format, args...)
Definition: error.h:59
static int session_send_evt_to_thread(void *data, void *args, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:29
int session_dgram_connect_notify(transport_connection_t *tc, u32 old_thread_index, session_t **new_session)
Move dgram session to the right thread.
Definition: session.c:814
Don&#39;t register connection in lookup Does not apply to local apps and transports using the network lay...
struct _transport_connection transport_connection_t
#define HIGH_SEGMENT_BASEVA
Definition: svm_common.h:84
int app_worker_init_connected(app_worker_t *app_wrk, session_t *s)
static session_evt_elt_t * session_evt_alloc_new(session_worker_t *wrk)
Definition: session.h:268
u32 my_pid
Definition: ssvm.h:86
void transport_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: transport.c:719
static u8 vlib_thread_is_main_w_barrier(void)
Definition: threads.h:512
#define pool_init_fixed(pool, max_elts)
initialize a fixed-size, preallocated pool
Definition: pool.h:86
application_t * application_get(u32 app_index)
Definition: application.c:418
static u32 session_thread_from_handle(session_handle_t handle)
#define SESSION_Q_PROCESS_STOP
Definition: session.h:204
int session_listen(session_t *ls, session_endpoint_cfg_t *sep)
Ask transport to listen on session endpoint.
Definition: session.c:1161
static u32 session_index_from_handle(session_handle_t handle)
#define uword_to_pointer(u, type)
Definition: types.h:136
void session_vpp_event_queues_allocate(session_main_t *smm)
Allocate event queues in the shared-memory segment.
Definition: session.c:1329
static session_handle_t session_make_handle(u32 session_index, u32 thread_index)
#define ASSERT(truth)
static int session_notify_subscribers(u32 app_index, session_t *s, svm_fifo_t *f, session_evt_type_t evt_type)
Definition: session.c:524
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
int session_main_flush_all_enqueue_events(u8 transport_proto)
Definition: session.c:687
void segment_manager_main_init(segment_manager_main_init_args_t *a)
static void clib_mem_free(void *p)
Definition: mem.h:226
enum _transport_proto transport_proto_t
static void svm_fifo_clear_deq_ntf(svm_fifo_t *f)
Clear the want notification flag and set has notification.
Definition: svm_fifo.h:806
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 len, u8 *src)
Enqueue a future segment.
Definition: svm_fifo.c:931
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
Definition: node_funcs.h:148
clib_time_type_t last_vlib_time
vlib_time_now last time around the track
Definition: session.h:87
u32 configured_v4_halfopen_table_memory
Definition: session.h:183
static session_t * session_alloc_for_connection(transport_connection_t *tc)
Definition: session.c:271
int app_worker_migrate_notify(app_worker_t *app_wrk, session_t *s, session_handle_t new_sh)
u32 configured_v4_session_table_memory
Definition: session.h:181
int session_stream_accept_notify(transport_connection_t *tc)
Definition: session.c:994
static void * clib_mem_alloc(uword size)
Definition: mem.h:153
void session_enqueue_notify_thread(session_handle_t sh)
Like session_enqueue_notify, but can be called from a thread that does not own the session...
Definition: session.c:613
static uword pointer_to_uword(const void *p)
Definition: types.h:131
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
Definition: message_queue.h:55
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u8 * name
Definition: ssvm.h:87
int() session_fifo_rx_fn(session_worker_t *wrk, vlib_node_runtime_t *node, session_evt_elt_t *e, int *n_tx_packets)
Definition: session.h:134
u8 thread_index
Index of the thread that allocated the session.
session_t * session_alloc(u32 thread_index)
Definition: session.c:169
void session_transport_cleanup(session_t *s)
Cleanup transport and session state.
Definition: session.c:1307
static void session_enqueue_discard_chain_bytes(vlib_main_t *vm, vlib_buffer_t *b, vlib_buffer_t **chain_b, u32 n_bytes_to_drop)
Discards bytes from buffer chain.
Definition: session.c:295
template key/value backing page structure
Definition: bihash_doc.h:44
static void session_switch_pool(void *cb_args)
Notify old thread of the session pool switch.
Definition: session.c:781
static transport_connection_t * transport_get_half_open(transport_proto_t tp, u32 conn_index)
Definition: transport.h:130
u32 local_endpoints_table_buckets
Definition: session.h:191
app_worker_t * app_worker_get(u32 wrk_index)
u32 q_nitems
msg queue size (not rings)
Definition: message_queue.h:53
u64 session_handle_t
void session_lookup_init(void)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
session_fifo_rx_fn session_tx_fifo_dequeue_internal
clib_llist_index_t old_head
Head of list of pending events.
Definition: session.h:117
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
volatile u8 session_state
State in session layer state machine.
int session_enqueue_notify(session_t *s)
Definition: session.c:590
void session_transport_closed_notify(transport_connection_t *tc)
Notification from transport that it is closed.
Definition: session.c:944
u32 * session_to_enqueue[TRANSPORT_N_PROTO]
Per-proto vector of sessions to enqueue.
Definition: session.h:96
void session_close(session_t *s)
Initialize session closing procedure.
Definition: session.c:1214
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
void session_reset(session_t *s)
Force a close without waiting for data to be flushed.
Definition: session.c:1237
ssvm_private_t * session_main_get_evt_q_segment(void)
Definition: session.c:1392
session_cleanup_ntf_t
int session_send_io_evt_to_thread_custom(void *data, u32 thread_index, session_evt_type_t evt_type)
Definition: session.c:86
unformat_function_t unformat_memory_size
Definition: format.h:296
static session_evt_elt_t * session_evt_alloc_ctrl(session_worker_t *wrk)
Definition: session.h:244
u32 app_index
Index of owning app.
Definition: application.h:43
static u8 svm_fifo_n_subscribers(svm_fifo_t *f)
Definition: svm_fifo.h:680
int session_lookup_add_connection(transport_connection_t *tc, u64 value)
Add transport connection to a session table.
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
u32 configured_v6_session_table_memory
Definition: session.h:185
clib_us_time_t last_vlib_us_time
vlib_time_now rounded to us precision and as u64
Definition: session.h:90
int session_stream_connect_notify(transport_connection_t *tc, u8 is_fail)
Definition: session.c:756
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
vlib_node_registration_t session_queue_process_node
(constructor) VLIB_REGISTER_NODE (session_queue_process_node)
static u32 vlib_num_workers()
Definition: threads.h:367
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:59
int(* session_open_service_fn)(u32, session_endpoint_t *, u32)
Definition: session.c:1121
u32 app_wrk_index
Index of the app worker that owns the session.
u32 session_tx_fifo_dequeue_drop(transport_connection_t *tc, u32 max_bytes)
Definition: session.c:510
static void session_delete(session_t *s)
Cleans up session and lookup table.
Definition: session.c:259
void session_transport_close(session_t *s)
Notify transport the session can be disconnected.
Definition: session.c:1255
clib_llist_index_t ctrl_head
Head of control events list.
Definition: session.h:111
int app_worker_close_notify(app_worker_t *app_wrk, session_t *s)
struct _session_endpoint session_endpoint_t
int session_stream_accept(transport_connection_t *tc, u32 listener_index, u32 thread_index, u8 notify)
Accept a stream session.
Definition: session.c:1011
int consumer_pid
pid of msg consumer
Definition: message_queue.h:52
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static transport_connection_t * transport_get_listener(transport_proto_t tp, u32 conn_index)
Definition: transport.h:124
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
Definition: buffer.h:167
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 len)
Dequeue and drop bytes from fifo.
Definition: svm_fifo.c:1029
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
static void session_enqueue_notify_rpc(void *arg)
Definition: session.c:596
int session_open_app(u32 app_wrk_index, session_endpoint_t *rmt, u32 opaque)
Definition: session.c:1110
void vlib_start_process(vlib_main_t *vm, uword process_index)
Definition: main.c:1587
void session_register_transport(transport_proto_t transport_proto, const transport_proto_vft_t *vft, u8 is_ip4, u32 output_node)
Initialize session layer for given transport proto and ip version.
Definition: session.c:1429
int session_lookup_add_half_open(transport_connection_t *tc, u64 value)
api_main_t api_main
Definition: api_shared.c:35
u8 transport_protocol_is_cl(transport_proto_t tp)
Definition: transport.c:294
int app_worker_connect_notify(app_worker_t *app_wrk, session_t *s, u32 opaque)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index)
Allocate message buffer on ring.
#define SESSION_EVT(_evt, _args...)
int i_am_master
Definition: ssvm.h:89
static void session_program_transport_ctrl_evt(session_t *s, session_evt_type_t evt)
Definition: session.c:148
static session_t * listen_session_get(u32 ls_index)
Definition: session.h:567
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171