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 #define foreach_session_endpoint_fields \
29 foreach_transport_endpoint_cfg_fields \
30 _(u8, transport_proto) \
32 typedef struct _session_endpoint
34 #define _(type, name) type name;
35 foreach_session_endpoint_fields
39 #define foreach_session_endpoint_cfg_flags _ (PROXY_LISTEN, "proxy listener")
41 typedef enum session_endpoint_cfg_flags_bits_
43 #define _(sym, str) SESSION_ENDPT_CFG_F_BIT_##sym,
44 foreach_session_endpoint_cfg_flags
46 } __clib_packed session_endpoint_cfg_flags_bits_t;
48 typedef enum session_endpoint_cfg_flags_
51 SESSION_ENDPT_CFG_F_##sym = 1 << SESSION_ENDPT_CFG_F_BIT_##sym,
52 foreach_session_endpoint_cfg_flags
54 } __clib_packed session_endpoint_cfg_flags_t;
56 typedef struct _session_endpoint_cfg
58 #define _(type, name) type name;
59 foreach_session_endpoint_fields
66 session_endpoint_cfg_flags_t flags;
67 transport_endpt_ext_cfg_t *ext_cfg;
68 } session_endpoint_cfg_t;
70 #define SESSION_IP46_ZERO \
77 #define TRANSPORT_ENDPOINT_NULL \
79 .sw_if_index = ENDPOINT_INVALID_INDEX, \
80 .ip = SESSION_IP46_ZERO, \
81 .fib_index = ENDPOINT_INVALID_INDEX, \
85 #define SESSION_ENDPOINT_NULL \
87 .sw_if_index = ENDPOINT_INVALID_INDEX, \
88 .ip = SESSION_IP46_ZERO, \
89 .fib_index = ENDPOINT_INVALID_INDEX, \
92 .peer = TRANSPORT_ENDPOINT_NULL, \
93 .transport_proto = 0, \
95 #define SESSION_ENDPOINT_CFG_NULL \
97 .sw_if_index = ENDPOINT_INVALID_INDEX, .ip = SESSION_IP46_ZERO, \
98 .fib_index = ENDPOINT_INVALID_INDEX, .is_ip4 = 0, .port = 0, \
99 .peer = TRANSPORT_ENDPOINT_NULL, .transport_proto = 0, \
100 .app_wrk_index = ENDPOINT_INVALID_INDEX, \
101 .opaque = ENDPOINT_INVALID_INDEX, \
102 .parent_handle = SESSION_INVALID_HANDLE, .ext_cfg = 0, \
105 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
106 #define session_endpoint_to_transport_cfg(_sep) \
107 ((transport_endpoint_cfg_t *)_sep)
110 session_endpoint_fib_proto (session_endpoint_t * sep)
112 return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
116 session_endpoint_is_local (session_endpoint_t * sep)
118 return (ip_is_zero (&sep->ip, sep->is_ip4)
119 || ip_is_local_host (&sep->ip, sep->is_ip4));
123 session_endpoint_is_zero (session_endpoint_t * sep)
125 return ip_is_zero (&sep->ip, sep->is_ip4);
128 typedef u8 session_type_t;
129 typedef u64 session_handle_t;
133 SESSION_CLEANUP_TRANSPORT,
134 SESSION_CLEANUP_SESSION,
135 } session_cleanup_ntf_t;
137 typedef enum session_ft_action_
139 SESSION_FT_ACTION_ENQUEUED,
140 SESSION_FT_ACTION_DEQUEUED,
141 SESSION_FT_ACTION_N_ACTIONS
142 } session_ft_action_t;
147 #define foreach_session_state \
148 _(CREATED, "created") \
149 _(LISTENING, "listening") \
150 _(CONNECTING, "connecting") \
151 _(ACCEPTING, "accepting") \
153 _(OPENED, "opened") \
154 _(TRANSPORT_CLOSING, "transport-closing") \
155 _(CLOSING, "closing") \
156 _(APP_CLOSED, "app-closed") \
157 _(TRANSPORT_CLOSED, "transport-closed") \
158 _(CLOSED, "closed") \
159 _(TRANSPORT_DELETED, "transport-deleted") \
163 #define _(sym, str) SESSION_STATE_ ## sym,
164 foreach_session_state
169 #define foreach_session_flag \
170 _ (RX_EVT, "rx-event") \
172 _ (CUSTOM_TX, "custom-tx") \
173 _ (IS_MIGRATING, "migrating") \
174 _ (UNIDIRECTIONAL, "unidirectional") \
175 _ (CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
176 _ (HALF_OPEN, "half-open") \
177 _ (APP_CLOSED, "app-closed")
179 typedef enum session_flags_bits_
181 #define _(sym, str) SESSION_F_BIT_ ## sym,
185 } session_flag_bits_t;
187 typedef enum session_flags_
189 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
194 typedef struct session_
196 /** Pointers to rx/tx buffers. Once allocated, these do not move */
200 /** Type built from transport and network protocol types */
201 session_type_t session_type;
203 /** State in session layer state machine. See @ref session_state_t */
204 volatile u8 session_state;
206 /** Index in thread pool where session was allocated */
209 /** Index of the app worker that owns the session */
212 /** Index of the thread that allocated the session */
215 /** Session flags. See @ref session_flags_t */
218 /** Index of the transport connection associated to the session */
219 u32 connection_index;
221 /** Index of application that owns the listener. Set only if a listener */
226 /** Parent listener session index if the result of an accept */
227 session_handle_t listener_handle;
229 /** App listener index in app's listener pool if a listener */
232 /** Index in app worker's half-open table if a half-open */
236 /** Opaque, for general use */
239 CLIB_CACHE_LINE_ALIGN_MARK (pad);
242 always_inline session_type_t
243 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
245 return (proto << 1 | is_ip4);
248 always_inline transport_proto_t
249 session_type_transport_proto (session_type_t st)
255 session_type_is_ip4 (session_type_t st)
260 always_inline transport_proto_t
261 session_get_transport_proto (session_t * s)
263 return (s->session_type >> 1);
266 always_inline fib_protocol_t
267 session_get_fib_proto (session_t * s)
269 u8 is_ip4 = s->session_type & 1;
270 return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
274 session_has_transport (session_t * s)
276 return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
279 static inline transport_service_type_t
280 session_transport_service_type (session_t * s)
282 transport_proto_t tp;
283 tp = session_get_transport_proto (s);
284 return transport_protocol_service_type (tp);
287 static inline transport_tx_fn_type_t
288 session_transport_tx_fn_type (session_t * s)
290 transport_proto_t tp;
291 tp = session_get_transport_proto (s);
292 return transport_protocol_tx_fn_type (tp);
296 session_tx_is_dgram (session_t * s)
298 return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
301 always_inline session_handle_t
302 session_handle (session_t * s)
304 return ((u64) s->thread_index << 32) | (u64) s->session_index;
308 session_index_from_handle (session_handle_t handle)
310 return handle & 0xFFFFFFFF;
314 session_thread_from_handle (session_handle_t handle)
320 session_parse_handle (session_handle_t handle, u32 * index,
323 *index = session_index_from_handle (handle);
324 *thread_index = session_thread_from_handle (handle);
327 static inline session_handle_t
328 session_make_handle (u32 session_index, u32 data)
330 return (((u64) data << 32) | (u64) session_index);
334 session_handle_index (session_handle_t ho_handle)
336 return (ho_handle & 0xffffffff);
340 session_handle_data (session_handle_t ho_handle)
342 return (ho_handle >> 32);
349 SESSION_IO_EVT_TX_FLUSH,
350 SESSION_IO_EVT_BUILTIN_RX,
351 SESSION_IO_EVT_TX_MAIN,
352 SESSION_CTRL_EVT_RPC,
353 SESSION_CTRL_EVT_HALF_CLOSE,
354 SESSION_CTRL_EVT_CLOSE,
355 SESSION_CTRL_EVT_RESET,
356 SESSION_CTRL_EVT_BOUND,
357 SESSION_CTRL_EVT_UNLISTEN_REPLY,
358 SESSION_CTRL_EVT_ACCEPTED,
359 SESSION_CTRL_EVT_ACCEPTED_REPLY,
360 SESSION_CTRL_EVT_CONNECTED,
361 SESSION_CTRL_EVT_DISCONNECTED,
362 SESSION_CTRL_EVT_DISCONNECTED_REPLY,
363 SESSION_CTRL_EVT_RESET_REPLY,
364 SESSION_CTRL_EVT_REQ_WORKER_UPDATE,
365 SESSION_CTRL_EVT_WORKER_UPDATE,
366 SESSION_CTRL_EVT_WORKER_UPDATE_REPLY,
367 SESSION_CTRL_EVT_SHUTDOWN,
368 SESSION_CTRL_EVT_DISCONNECT,
369 SESSION_CTRL_EVT_CONNECT,
370 SESSION_CTRL_EVT_CONNECT_URI,
371 SESSION_CTRL_EVT_LISTEN,
372 SESSION_CTRL_EVT_LISTEN_URI,
373 SESSION_CTRL_EVT_UNLISTEN,
374 SESSION_CTRL_EVT_APP_DETACH,
375 SESSION_CTRL_EVT_APP_ADD_SEGMENT,
376 SESSION_CTRL_EVT_APP_DEL_SEGMENT,
377 SESSION_CTRL_EVT_MIGRATED,
378 SESSION_CTRL_EVT_CLEANUP,
379 SESSION_CTRL_EVT_APP_WRK_RPC,
380 SESSION_CTRL_EVT_TRANSPORT_ATTR,
381 SESSION_CTRL_EVT_TRANSPORT_ATTR_REPLY,
382 } session_evt_type_t;
384 #define foreach_session_ctrl_evt \
386 _ (LISTEN_URI, listen_uri) \
388 _ (UNLISTEN, unlisten) \
389 _ (UNLISTEN_REPLY, unlisten_reply) \
390 _ (ACCEPTED, accepted) \
391 _ (ACCEPTED_REPLY, accepted_reply) \
392 _ (CONNECT, connect) \
393 _ (CONNECT_URI, connect_uri) \
394 _ (CONNECTED, connected) \
395 _ (SHUTDOWN, shutdown) \
396 _ (DISCONNECT, disconnect) \
397 _ (DISCONNECTED, disconnected) \
398 _ (DISCONNECTED_REPLY, disconnected_reply) \
399 _ (RESET_REPLY, reset_reply) \
400 _ (REQ_WORKER_UPDATE, req_worker_update) \
401 _ (WORKER_UPDATE, worker_update) \
402 _ (WORKER_UPDATE_REPLY, worker_update_reply) \
403 _ (APP_DETACH, app_detach) \
404 _ (APP_ADD_SEGMENT, app_add_segment) \
405 _ (APP_DEL_SEGMENT, app_del_segment) \
406 _ (MIGRATED, migrated) \
407 _ (CLEANUP, cleanup) \
408 _ (APP_WRK_RPC, app_wrk_rpc) \
409 _ (TRANSPORT_ATTR, transport_attr) \
410 _ (TRANSPORT_ATTR_REPLY, transport_attr_reply) \
411 /* Deprecated and will be removed. Use types above */
412 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
413 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
414 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
415 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
419 SESSION_MQ_IO_EVT_RING,
420 SESSION_MQ_CTRL_EVT_RING,
422 } session_mq_rings_e;
428 } session_rpc_args_t;
437 session_handle_t session_handle;
438 session_rpc_args_t rpc_args;
445 } __clib_packed session_event_t;
447 #define SESSION_MSG_NULL { }
449 typedef struct session_dgram_pre_hdr_
453 } session_dgram_pre_hdr_t;
455 typedef struct session_dgram_header_
459 ip46_address_t rmt_ip;
460 ip46_address_t lcl_ip;
465 } __clib_packed session_dgram_hdr_t;
467 #define SESSION_CONN_ID_LEN 37
468 #define SESSION_CONN_HDR_LEN 47
469 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 10),
470 "session conn id wrong length");
472 #define foreach_session_error \
473 _ (NONE, "no error") \
474 _ (UNKNOWN, "generic/unknown error") \
475 _ (REFUSED, "refused") \
476 _ (TIMEDOUT, "timedout") \
477 _ (ALLOC, "obj/memory allocation error") \
478 _ (OWNER, "object not owned by application") \
479 _ (NOROUTE, "no route") \
480 _ (NOINTF, "no resolving interface") \
481 _ (NOIP, "no ip for lcl interface") \
482 _ (NOPORT, "no lcl port") \
483 _ (NOSUPPORT, "not supported") \
484 _ (NOLISTEN, "not listening") \
485 _ (NOSESSION, "session does not exist") \
486 _ (NOAPP, "app not attached") \
487 _ (APP_ATTACHED, "app already attached") \
488 _ (PORTINUSE, "lcl port in use") \
489 _ (IPINUSE, "ip in use") \
490 _ (ALREADY_LISTENING, "ip port pair already listened on") \
491 _ (ADDR_NOT_IN_USE, "address not in use") \
492 _ (INVALID, "invalid value") \
493 _ (INVALID_RMT_IP, "invalid remote ip") \
494 _ (INVALID_APPWRK, "invalid app worker") \
495 _ (INVALID_NS, "invalid namespace") \
496 _ (SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
497 _ (SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
498 _ (SEG_CREATE, "Couldn't create a new segment") \
499 _ (FILTERED, "session filtered") \
500 _ (SCOPE, "scope not supported") \
501 _ (BAPI_NO_FD, "bapi doesn't have a socket fd") \
502 _ (BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
503 _ (BAPI_NO_REG, "app bapi registration not found") \
504 _ (MQ_MSG_ALLOC, "failed to alloc mq msg") \
505 _ (TLS_HANDSHAKE, "failed tls handshake") \
506 _ (EVENTFD_ALLOC, "failed to alloc eventfd") \
507 _ (NOEXTCFG, "no extended transport config") \
508 _ (NOCRYPTOENG, "no crypto engine") \
509 _ (NOCRYPTOCKP, "cert key pair not found ") \
510 _ (LOCAL_CONNECT, "could not connect with local scope") \
511 _ (WRONG_NS_SECRET, "wrong ns secret") \
512 _ (SYSCALL, "system call error") \
513 _ (TRANSPORT_NO_REG, "transport was not registered")
515 typedef enum session_error_p_
517 #define _(sym, str) SESSION_EP_##sym,
518 foreach_session_error
523 typedef enum session_error_
525 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
526 foreach_session_error
530 #define SESSION_CLI_ID_LEN "60"
531 #define SESSION_CLI_STATE_LEN "15"
533 /* Maintained for compatibility. Will be deprecated */
534 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
535 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
536 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
538 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
541 * fd.io coding-style-patch-verification: ON
544 * eval: (c-set-style "gnu")