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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef SRC_VNET_SESSION_SESSION_TYPES_H_
17 #define SRC_VNET_SESSION_SESSION_TYPES_H_
19 #include <svm/svm_fifo.h>
20 #include <vnet/session/transport_types.h>
22 #define SESSION_INVALID_INDEX ((u32)~0)
23 #define SESSION_INVALID_HANDLE ((u64)~0)
24 #define SESSION_CTRL_MSG_MAX_SIZE 86
25 #define SESSION_CTRL_MSG_TX_MAX_SIZE 160
26 #define SESSION_NODE_FRAME_SIZE 128
28 typedef u8 session_type_t;
29 typedef u64 session_handle_t;
31 typedef union session_handle_tu_
33 session_handle_t handle;
39 } __attribute__ ((__transparent_union__)) session_handle_tu_t;
41 #define foreach_session_endpoint_fields \
42 foreach_transport_endpoint_cfg_fields \
43 _(u8, transport_proto) \
45 typedef struct _session_endpoint
47 #define _(type, name) type name;
48 foreach_session_endpoint_fields
52 #define foreach_session_endpoint_cfg_flags _ (PROXY_LISTEN, "proxy listener")
54 typedef enum session_endpoint_cfg_flags_bits_
56 #define _(sym, str) SESSION_ENDPT_CFG_F_BIT_##sym,
57 foreach_session_endpoint_cfg_flags
59 } __clib_packed session_endpoint_cfg_flags_bits_t;
61 typedef enum session_endpoint_cfg_flags_
64 SESSION_ENDPT_CFG_F_##sym = 1 << SESSION_ENDPT_CFG_F_BIT_##sym,
65 foreach_session_endpoint_cfg_flags
67 } __clib_packed session_endpoint_cfg_flags_t;
69 typedef struct _session_endpoint_cfg
71 #define _(type, name) type name;
72 foreach_session_endpoint_fields
79 session_endpoint_cfg_flags_t flags;
80 transport_endpt_ext_cfg_t *ext_cfg;
81 } session_endpoint_cfg_t;
83 #define SESSION_IP46_ZERO \
90 #define TRANSPORT_ENDPOINT_NULL \
92 .sw_if_index = ENDPOINT_INVALID_INDEX, \
93 .ip = SESSION_IP46_ZERO, \
94 .fib_index = ENDPOINT_INVALID_INDEX, \
98 #define SESSION_ENDPOINT_NULL \
100 .sw_if_index = ENDPOINT_INVALID_INDEX, \
101 .ip = SESSION_IP46_ZERO, \
102 .fib_index = ENDPOINT_INVALID_INDEX, \
105 .peer = TRANSPORT_ENDPOINT_NULL, \
106 .transport_proto = 0, \
108 #define SESSION_ENDPOINT_CFG_NULL \
110 .sw_if_index = ENDPOINT_INVALID_INDEX, .ip = SESSION_IP46_ZERO, \
111 .fib_index = ENDPOINT_INVALID_INDEX, .is_ip4 = 0, .port = 0, \
112 .peer = TRANSPORT_ENDPOINT_NULL, .transport_proto = 0, \
113 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
114 .opaque = ENDPOINT_INVALID_INDEX, \
115 .parent_handle = SESSION_INVALID_HANDLE, .ext_cfg = 0, \
118 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
119 #define session_endpoint_to_transport_cfg(_sep) \
120 ((transport_endpoint_cfg_t *)_sep)
123 session_endpoint_fib_proto (session_endpoint_t * sep)
125 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
129 session_endpoint_is_local (session_endpoint_t * sep)
131 return (ip_is_zero (&sep->ip, sep->is_ip4)
132 || ip_is_local_host (&sep->ip, sep->is_ip4));
136 session_endpoint_is_zero (session_endpoint_t * sep)
138 return ip_is_zero (&sep->ip, sep->is_ip4);
143 SESSION_CLEANUP_TRANSPORT,
144 SESSION_CLEANUP_SESSION,
145 } session_cleanup_ntf_t;
147 typedef enum session_ft_action_
149 SESSION_FT_ACTION_ENQUEUED,
150 SESSION_FT_ACTION_DEQUEUED,
151 SESSION_FT_ACTION_N_ACTIONS
152 } session_ft_action_t;
157 #define foreach_session_state \
158 _ (CREATED, "created") \
159 _ (LISTENING, "listening") \
160 _ (CONNECTING, "connecting") \
161 _ (ACCEPTING, "accepting") \
163 _ (OPENED, "opened") \
164 _ (TRANSPORT_CLOSING, "transport-closing") \
165 _ (CLOSING, "closing") \
166 _ (APP_CLOSED, "app-closed") \
167 _ (TRANSPORT_CLOSED, "transport-closed") \
168 _ (CLOSED, "closed") \
169 _ (TRANSPORT_DELETED, "transport-deleted")
173 #define _(sym, str) SESSION_STATE_ ## sym,
174 foreach_session_state
177 } __clib_packed session_state_t;
179 #define foreach_session_flag \
180 _ (RX_EVT, "rx-event") \
182 _ (CUSTOM_TX, "custom-tx") \
183 _ (IS_MIGRATING, "migrating") \
184 _ (UNIDIRECTIONAL, "unidirectional") \
185 _ (CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
186 _ (HALF_OPEN, "half-open") \
187 _ (APP_CLOSED, "app-closed") \
188 _ (IS_CLESS, "connectionless")
190 typedef enum session_flags_bits_
192 #define _(sym, str) SESSION_F_BIT_ ## sym,
196 } session_flag_bits_t;
198 typedef enum session_flags_
200 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
205 typedef struct session_
207 /** Pointers to rx/tx buffers. Once allocated, these do not move */
213 session_handle_t handle;
216 /** Index in thread pool where session was allocated */
219 /** Index of the thread that allocated the session */
224 /** Type built from transport and network protocol types */
225 session_type_t session_type;
227 /** State in session layer state machine. See @ref session_state_t */
228 volatile session_state_t session_state;
230 /** Index of the app worker that owns the session */
233 /** Session flags. See @ref session_flags_t */
234 session_flags_t flags;
236 /** Index of the transport connection associated to the session */
237 u32 connection_index;
239 /** App listener index in app's listener pool if a listener */
244 /** Parent listener session index if the result of an accept */
245 session_handle_t listener_handle;
247 /** Index in app worker's half-open table if a half-open */
251 /** Opaque, for general use */
254 CLIB_CACHE_LINE_ALIGN_MARK (pad);
257 always_inline session_type_t
258 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
260 return (proto << 1 | is_ip4);
263 always_inline transport_proto_t
264 session_type_transport_proto (session_type_t st)
270 session_type_is_ip4 (session_type_t st)
275 always_inline transport_proto_t
276 session_get_transport_proto (session_t * s)
278 return (s->session_type >> 1);
281 always_inline fib_protocol_t
282 session_get_fib_proto (session_t * s)
284 u8 is_ip4 = s->session_type & 1;
285 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
289 session_has_transport (session_t * s)
291 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
294 static inline transport_service_type_t
295 session_transport_service_type (session_t * s)
297 transport_proto_t tp;
298 tp = session_get_transport_proto (s);
299 return transport_protocol_service_type (tp);
302 static inline transport_tx_fn_type_t
303 session_transport_tx_fn_type (session_t * s)
305 transport_proto_t tp;
306 tp = session_get_transport_proto (s);
307 return transport_protocol_tx_fn_type (tp);
311 session_tx_is_dgram (session_t * s)
313 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
316 always_inline session_handle_t
317 session_handle (session_t * s)
323 session_index_from_handle (session_handle_tu_t handle)
325 return handle.session_index;
329 session_thread_from_handle (session_handle_tu_t handle)
331 return handle.thread_index;
335 session_parse_handle (session_handle_tu_t handle, u32 *index,
338 *index = handle.session_index;
339 *thread_index = handle.thread_index;
342 static inline session_handle_t
343 session_make_handle (u32 session_index, u32 data)
345 return ((session_handle_tu_t){ .session_index = session_index,
346 .thread_index = data })
354 SESSION_IO_EVT_TX_FLUSH,
355 SESSION_IO_EVT_BUILTIN_RX,
356 SESSION_IO_EVT_TX_MAIN,
357 SESSION_CTRL_EVT_RPC,
358 SESSION_CTRL_EVT_HALF_CLOSE,
359 SESSION_CTRL_EVT_CLOSE,
360 SESSION_CTRL_EVT_RESET,
361 SESSION_CTRL_EVT_BOUND,
362 SESSION_CTRL_EVT_UNLISTEN_REPLY,
363 SESSION_CTRL_EVT_ACCEPTED,
364 SESSION_CTRL_EVT_ACCEPTED_REPLY,
365 SESSION_CTRL_EVT_CONNECTED,
366 SESSION_CTRL_EVT_DISCONNECTED,
367 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
368 SESSION_CTRL_EVT_RESET_REPLY,
369 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
370 SESSION_CTRL_EVT_WORKER_UPDATE,
371 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
372 SESSION_CTRL_EVT_SHUTDOWN,
373 SESSION_CTRL_EVT_DISCONNECT,
374 SESSION_CTRL_EVT_CONNECT,
375 SESSION_CTRL_EVT_CONNECT_URI,
376 SESSION_CTRL_EVT_LISTEN,
377 SESSION_CTRL_EVT_LISTEN_URI,
378 SESSION_CTRL_EVT_UNLISTEN,
379 SESSION_CTRL_EVT_APP_DETACH,
380 SESSION_CTRL_EVT_APP_ADD_SEGMENT,
381 SESSION_CTRL_EVT_APP_DEL_SEGMENT,
382 SESSION_CTRL_EVT_MIGRATED,
383 SESSION_CTRL_EVT_CLEANUP,
384 SESSION_CTRL_EVT_APP_WRK_RPC,
385 SESSION_CTRL_EVT_TRANSPORT_ATTR,
386 SESSION_CTRL_EVT_TRANSPORT_ATTR_REPLY,
387 SESSION_CTRL_EVT_TRANSPORT_CLOSED,
388 SESSION_CTRL_EVT_HALF_CLEANUP,
389 } session_evt_type_t;
391 #define foreach_session_ctrl_evt \
393 _ (LISTEN_URI, listen_uri) \
395 _ (UNLISTEN, unlisten) \
396 _ (UNLISTEN_REPLY, unlisten_reply) \
397 _ (ACCEPTED, accepted) \
398 _ (ACCEPTED_REPLY, accepted_reply) \
399 _ (CONNECT, connect) \
400 _ (CONNECT_URI, connect_uri) \
401 _ (CONNECTED, connected) \
402 _ (SHUTDOWN, shutdown) \
403 _ (DISCONNECT, disconnect) \
404 _ (DISCONNECTED, disconnected) \
405 _ (DISCONNECTED_REPLY, disconnected_reply) \
406 _ (RESET_REPLY, reset_reply) \
407 _ (REQ_WORKER_UPDATE, req_worker_update) \
408 _ (WORKER_UPDATE, worker_update) \
409 _ (WORKER_UPDATE_REPLY, worker_update_reply) \
410 _ (APP_DETACH, app_detach) \
411 _ (APP_ADD_SEGMENT, app_add_segment) \
412 _ (APP_DEL_SEGMENT, app_del_segment) \
413 _ (MIGRATED, migrated) \
414 _ (CLEANUP, cleanup) \
415 _ (APP_WRK_RPC, app_wrk_rpc) \
416 _ (TRANSPORT_ATTR, transport_attr) \
417 _ (TRANSPORT_ATTR_REPLY, transport_attr_reply) \
418 /* Deprecated and will be removed. Use types above */
419 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
420 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
421 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
422 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
426 SESSION_MQ_IO_EVT_RING,
427 SESSION_MQ_CTRL_EVT_RING,
429 } session_mq_rings_e;
435 } session_rpc_args_t;
444 session_handle_t session_handle;
445 session_rpc_args_t rpc_args;
453 } __clib_packed session_event_t;
455 #define SESSION_MSG_NULL { }
457 typedef struct session_dgram_pre_hdr_
461 } session_dgram_pre_hdr_t;
463 typedef struct session_dgram_header_
467 ip46_address_t rmt_ip;
468 ip46_address_t lcl_ip;
473 } __clib_packed session_dgram_hdr_t;
475 #define SESSION_CONN_ID_LEN 37
476 #define SESSION_CONN_HDR_LEN 47
477 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 10),
478 "session conn id wrong length");
480 #define foreach_session_error \
481 _ (NONE, "no error") \
482 _ (UNKNOWN, "generic/unknown error") \
483 _ (REFUSED, "refused") \
484 _ (TIMEDOUT, "timedout") \
485 _ (ALLOC, "obj/memory allocation error") \
486 _ (OWNER, "object not owned by application") \
487 _ (NOROUTE, "no route") \
488 _ (NOINTF, "no resolving interface") \
489 _ (NOIP, "no ip for lcl interface") \
490 _ (NOPORT, "no lcl port") \
491 _ (NOSUPPORT, "not supported") \
492 _ (NOLISTEN, "not listening") \
493 _ (NOSESSION, "session does not exist") \
494 _ (NOAPP, "app not attached") \
495 _ (APP_ATTACHED, "app already attached") \
496 _ (PORTINUSE, "lcl port in use") \
497 _ (IPINUSE, "ip in use") \
498 _ (ALREADY_LISTENING, "ip port pair already listened on") \
499 _ (ADDR_NOT_IN_USE, "address not in use") \
500 _ (INVALID, "invalid value") \
501 _ (INVALID_RMT_IP, "invalid remote ip") \
502 _ (INVALID_APPWRK, "invalid app worker") \
503 _ (INVALID_NS, "invalid namespace") \
504 _ (SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
505 _ (SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
506 _ (SEG_CREATE, "Couldn't create a new segment") \
507 _ (FILTERED, "session filtered") \
508 _ (SCOPE, "scope not supported") \
509 _ (BAPI_NO_FD, "bapi doesn't have a socket fd") \
510 _ (BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
511 _ (BAPI_NO_REG, "app bapi registration not found") \
512 _ (MQ_MSG_ALLOC, "failed to alloc mq msg") \
513 _ (TLS_HANDSHAKE, "failed tls handshake") \
514 _ (EVENTFD_ALLOC, "failed to alloc eventfd") \
515 _ (NOEXTCFG, "no extended transport config") \
516 _ (NOCRYPTOENG, "no crypto engine") \
517 _ (NOCRYPTOCKP, "cert key pair not found ") \
518 _ (LOCAL_CONNECT, "could not connect with local scope") \
519 _ (WRONG_NS_SECRET, "wrong ns secret") \
520 _ (SYSCALL, "system call error") \
521 _ (TRANSPORT_NO_REG, "transport was not registered")
523 typedef enum session_error_p_
525 #define _(sym, str) SESSION_EP_##sym,
526 foreach_session_error
531 typedef enum session_error_
533 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
534 foreach_session_error
538 #define SESSION_CLI_ID_LEN "60"
539 #define SESSION_CLI_STATE_LEN "15"
541 /* Maintained for compatibility. Will be deprecated */
542 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
543 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
544 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
546 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
549 * fd.io coding-style-patch-verification: ON
552 * eval: (c-set-style "gnu")