FD.io VPP  v21.01.1
Vector Packet Processing
session_types.h
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 #ifndef SRC_VNET_SESSION_SESSION_TYPES_H_
17 #define SRC_VNET_SESSION_SESSION_TYPES_H_
18 
19 #include <svm/svm_fifo.h>
21 
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_NODE_FRAME_SIZE 128
26 
27 #define foreach_session_endpoint_fields \
28  foreach_transport_endpoint_cfg_fields \
29  _(u8, transport_proto) \
30 
31 typedef struct _session_endpoint
32 {
33 #define _(type, name) type name;
35 #undef _
37 
38 typedef struct _session_endpoint_cfg
39 {
40 #define _(type, name) type name;
42 #undef _
43  u32 app_wrk_index;
44  u32 opaque;
45  u32 ns_index;
46  u8 original_tp;
47  u8 *hostname;
48  u64 parent_handle;
49  u32 ckpair_index;
50  u8 crypto_engine;
51  u8 flags;
53 
54 #define SESSION_IP46_ZERO \
55 { \
56  .ip6 = { \
57  { 0, 0, }, \
58  }, \
59 }
60 
61 #define TRANSPORT_ENDPOINT_NULL \
62 { \
63  .sw_if_index = ENDPOINT_INVALID_INDEX, \
64  .ip = SESSION_IP46_ZERO, \
65  .fib_index = ENDPOINT_INVALID_INDEX, \
66  .is_ip4 = 0, \
67  .port = 0, \
68 }
69 #define SESSION_ENDPOINT_NULL \
70 { \
71  .sw_if_index = ENDPOINT_INVALID_INDEX, \
72  .ip = SESSION_IP46_ZERO, \
73  .fib_index = ENDPOINT_INVALID_INDEX, \
74  .is_ip4 = 0, \
75  .port = 0, \
76  .peer = TRANSPORT_ENDPOINT_NULL, \
77  .transport_proto = 0, \
78 }
79 #define SESSION_ENDPOINT_CFG_NULL \
80 { \
81  .sw_if_index = ENDPOINT_INVALID_INDEX, \
82  .ip = SESSION_IP46_ZERO, \
83  .fib_index = ENDPOINT_INVALID_INDEX, \
84  .is_ip4 = 0, \
85  .port = 0, \
86  .peer = TRANSPORT_ENDPOINT_NULL, \
87  .transport_proto = 0, \
88  .app_wrk_index = ENDPOINT_INVALID_INDEX, \
89  .opaque = ENDPOINT_INVALID_INDEX, \
90  .hostname = 0, \
91  .parent_handle = SESSION_INVALID_HANDLE, \
92  .ckpair_index = 0 \
93 }
94 
95 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
96 #define session_endpoint_to_transport_cfg(_sep) \
97  ((transport_endpoint_cfg_t *)_sep)
98 
100 session_endpoint_fib_proto (session_endpoint_t * sep)
101 {
102  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
103 }
104 
105 static inline u8
106 session_endpoint_is_local (session_endpoint_t * sep)
107 {
108  return (ip_is_zero (&sep->ip, sep->is_ip4)
109  || ip_is_local_host (&sep->ip, sep->is_ip4));
110 }
111 
112 static inline u8
113 session_endpoint_is_zero (session_endpoint_t * sep)
114 {
115  return ip_is_zero (&sep->ip, sep->is_ip4);
116 }
117 
120 
121 typedef enum
122 {
126 
127 typedef enum session_ft_action_
128 {
133 
134 /*
135  * Session states
136  */
137 #define foreach_session_state \
138  _(CREATED, "created") \
139  _(LISTENING, "listening") \
140  _(CONNECTING, "connecting") \
141  _(ACCEPTING, "accepting") \
142  _(READY, "ready") \
143  _(OPENED, "opened") \
144  _(TRANSPORT_CLOSING, "transport-closing") \
145  _(CLOSING, "closing") \
146  _(APP_CLOSED, "app-closed") \
147  _(TRANSPORT_CLOSED, "transport-closed") \
148  _(CLOSED, "closed") \
149  _(TRANSPORT_DELETED, "transport-deleted") \
150 
151 typedef enum
152 {
153 #define _(sym, str) SESSION_STATE_ ## sym,
155 #undef _
158 
159 #define foreach_session_flag \
160  _(RX_EVT, "rx-event") \
161  _(PROXY, "proxy") \
162  _(CUSTOM_TX, "custom-tx") \
163  _(IS_MIGRATING, "migrating") \
164  _(UNIDIRECTIONAL, "unidirectional") \
165  _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
166 
168 {
169 #define _(sym, str) SESSION_F_BIT_ ## sym,
171 #undef _
174 
175 typedef enum session_flags_
176 {
177 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
179 #undef _
181 
182 typedef struct session_
183 {
184  /** Pointers to rx/tx buffers. Once allocated, these do not move */
187 
188  /** Type built from transport and network protocol types */
189  session_type_t session_type;
190 
191  /** State in session layer state machine. See @ref session_state_t */
192  volatile u8 session_state;
193 
194  /** Index in thread pool where session was allocated */
196 
197  /** Index of the app worker that owns the session */
199 
200  /** Index of the thread that allocated the session */
202 
203  /** Session flags. See @ref session_flags_t */
205 
206  /** Index of the transport connection associated to the session */
208 
209  /** Index of application that owns the listener. Set only if a listener */
211 
212  union
213  {
214  /** Parent listener session index if the result of an accept */
215  session_handle_t listener_handle;
216 
217  /** App listener index in app's listener pool if a listener */
219  };
220 
221  /** Opaque, for general use */
223 
225 } session_t;
226 
227 always_inline session_type_t
229 {
230  return (proto << 1 | is_ip4);
231 }
232 
234 session_type_transport_proto (session_type_t st)
235 {
236  return (st >> 1);
237 }
238 
240 session_type_is_ip4 (session_type_t st)
241 {
242  return (st & 1);
243 }
244 
247 {
248  return (s->session_type >> 1);
249 }
250 
253 {
254  u8 is_ip4 = s->session_type & 1;
255  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
256 }
257 
260 {
261  return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
262 }
263 
264 static inline transport_service_type_t
266 {
270 }
271 
272 static inline transport_tx_fn_type_t
274 {
277  return transport_protocol_tx_fn_type (tp);
278 }
279 
280 static inline u8
282 {
284 }
285 
286 always_inline session_handle_t
288 {
289  return ((u64) s->thread_index << 32) | (u64) s->session_index;
290 }
291 
293 session_index_from_handle (session_handle_t handle)
294 {
295  return handle & 0xFFFFFFFF;
296 }
297 
299 session_thread_from_handle (session_handle_t handle)
300 {
301  return handle >> 32;
302 }
303 
304 always_inline void
305 session_parse_handle (session_handle_t handle, u32 * index,
306  u32 * thread_index)
307 {
308  *index = session_index_from_handle (handle);
309  *thread_index = session_thread_from_handle (handle);
310 }
311 
312 static inline session_handle_t
313 session_make_handle (u32 session_index, u32 data)
314 {
315  return (((u64) data << 32) | (u64) session_index);
316 }
317 
319 session_handle_index (session_handle_t ho_handle)
320 {
321  return (ho_handle & 0xffffffff);
322 }
323 
325 session_handle_data (session_handle_t ho_handle)
326 {
327  return (ho_handle >> 32);
328 }
329 
330 typedef enum
331 {
364 
365 #define foreach_session_ctrl_evt \
366  _(LISTEN, listen) \
367  _(LISTEN_URI, listen_uri) \
368  _(BOUND, bound) \
369  _(UNLISTEN, unlisten) \
370  _(UNLISTEN_REPLY, unlisten_reply) \
371  _(ACCEPTED, accepted) \
372  _(ACCEPTED_REPLY, accepted_reply) \
373  _(CONNECT, connect) \
374  _(CONNECT_URI, connect_uri) \
375  _(CONNECTED, connected) \
376  _(DISCONNECT, disconnect) \
377  _(DISCONNECTED, disconnected) \
378  _(DISCONNECTED_REPLY, disconnected_reply) \
379  _(RESET_REPLY, reset_reply) \
380  _(REQ_WORKER_UPDATE, req_worker_update) \
381  _(WORKER_UPDATE, worker_update) \
382  _(WORKER_UPDATE_REPLY, worker_update_reply) \
383  _(APP_DETACH, app_detach) \
384  _(APP_ADD_SEGMENT, app_add_segment) \
385  _(APP_DEL_SEGMENT, app_del_segment) \
386  _(MIGRATED, migrated) \
387  _(CLEANUP, cleanup) \
388  _(APP_WRK_RPC, app_wrk_rpc) \
389 
390 /* Deprecated and will be removed. Use types above */
391 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
392 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
393 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
394 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
395 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
396 
397 typedef enum
398 {
403 
404 typedef struct
405 {
406  void *fp;
407  void *arg;
409 
410 typedef struct
411 {
412  u8 event_type;
413  u8 postponed;
414  union
415  {
416  u32 session_index;
417  session_handle_t session_handle;
418  session_rpc_args_t rpc_args;
419  u32 ctrl_data_index;
420  struct
421  {
422  u8 data[0];
423  };
424  };
425 } __clib_packed session_event_t;
426 
427 #define SESSION_MSG_NULL { }
428 
430 {
434 
435 typedef struct session_dgram_header_
436 {
439  ip46_address_t rmt_ip;
440  ip46_address_t lcl_ip;
444 } __clib_packed session_dgram_hdr_t;
445 
446 #define SESSION_CONN_ID_LEN 37
447 #define SESSION_CONN_HDR_LEN 45
448 
449 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
450  "session conn id wrong length");
451 
452 #define foreach_session_error \
453  _(NONE, "no error") \
454  _(UNKNOWN, "generic/unknown error") \
455  _(REFUSED, "refused") \
456  _(TIMEDOUT, "timedout") \
457  _(ALLOC, "obj/memory allocation error") \
458  _(OWNER, "object not owned by application") \
459  _(NOROUTE, "no route") \
460  _(NOINTF, "no resolving interface") \
461  _(NOIP, "no ip for lcl interface") \
462  _(NOPORT, "no lcl port") \
463  _(NOSUPPORT, "not supported") \
464  _(NOLISTEN, "not listening") \
465  _(NOSESSION, "session does not exist") \
466  _(NOAPP, "app not attached") \
467  _(PORTINUSE, "lcl port in use") \
468  _(IPINUSE, "ip in use") \
469  _(ALREADY_LISTENING, "ip port pair already listened on") \
470  _(INVALID_RMT_IP, "invalid remote ip") \
471  _(INVALID_APPWRK, "invalid app worker") \
472  _(INVALID_NS, "invalid namespace") \
473  _(SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
474  _(SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
475  _(SEG_CREATE, "Couldn't create a new segment") \
476  _(FILTERED, "session filtered") \
477  _(SCOPE, "scope not supported") \
478  _(BAPI_NO_FD, "bapi doesn't have a socket fd") \
479  _(BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
480  _(BAPI_NO_REG, "app bapi registration not found") \
481  _(MQ_MSG_ALLOC, "failed to alloc mq msg") \
482  _(TLS_HANDSHAKE, "failed tls handshake") \
483 
484 typedef enum session_error_p_
485 {
486 #define _(sym, str) SESSION_EP_##sym,
488 #undef _
491 
492 typedef enum session_error_
493 {
494 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
496 #undef _
498 
499 #define SESSION_CLI_ID_LEN "60"
500 #define SESSION_CLI_STATE_LEN "15"
501 
502 /* Maintained for compatibility. Will be deprecated */
503 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
504 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
505 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
506 
507 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
508 
509 /*
510  * fd.io coding-style-patch-verification: ON
511  *
512  * Local Variables:
513  * eval: (c-set-style "gnu")
514  * End:
515  */
string hostname[64]
Definition: dhcp.api:159
u32 al_index
App listener index in app&#39;s listener pool if a listener.
u32 connection_index
Index of the transport connection associated to the session.
session_flags_bits_
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
struct session_ session_t
session_type_t session_type
Type built from transport and network protocol types.
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
svm_fifo_t * tx_fifo
static u8 session_tx_is_dgram(session_t *s)
u32 session_index
Index in thread pool where session was allocated.
unsigned long u64
Definition: types.h:89
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
session_evt_type_t
static transport_proto_t session_get_transport_proto(session_t *s)
transport_tx_fn_type_t transport_protocol_tx_fn_type(transport_proto_t tp)
Definition: transport.c:296
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
u32 flags
Session flags.
static u32 session_handle_data(session_handle_t ho_handle)
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static session_handle_t session_handle(session_t *s)
u8 session_type_t
enum session_ft_action_ session_ft_action_t
session_flags_
ip46_address_t lcl_ip
unsigned int u32
Definition: types.h:88
session_state_t
session_error_p_
struct _session_endpoint_cfg session_endpoint_cfg_t
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
static transport_tx_fn_type_t session_transport_tx_fn_type(session_t *s)
transport_service_type_t transport_protocol_service_type(transport_proto_t tp)
Definition: transport.c:290
vl_api_ip_proto_t proto
Definition: acl_types.api:51
u32 app_index
Index of application that owns the listener.
unsigned short u16
Definition: types.h:57
#define SESSION_CONN_ID_LEN
enum session_flags_ session_flags_t
enum transport_service_type_ transport_service_type_t
#define always_inline
Definition: ipsec.h:28
session_handle_t listener_handle
Parent listener session index if the result of an accept.
enum session_error_p_ session_error_p_t
session_error_
#define foreach_session_endpoint_fields
Definition: session_types.h:27
static transport_proto_t session_type_transport_proto(session_type_t st)
static u32 session_thread_from_handle(session_handle_t handle)
static u32 session_index_from_handle(session_handle_t handle)
#define foreach_session_flag
datagram mode
static fib_protocol_t session_get_fib_proto(session_t *s)
#define foreach_session_state
STATIC_ASSERT(sizeof(session_dgram_hdr_t)==(SESSION_CONN_ID_LEN+8), "session conn id wrong length")
enum _transport_proto transport_proto_t
session_ft_action_
static session_handle_t session_make_handle(u32 session_index, u32 data)
ip46_address_t rmt_ip
u8 thread_index
Index of the thread that allocated the session.
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
Definition: ip.c:20
static u8 session_type_is_ip4(session_type_t st)
static u32 session_handle_index(session_handle_t ho_handle)
u64 session_handle_t
volatile u8 session_state
State in session layer state machine.
u32 opaque
Opaque, for general use.
#define foreach_session_error
static u8 session_endpoint_is_zero(session_endpoint_t *sep)
u8 ip_is_local_host(ip46_address_t *ip46_address, u8 is_ip4)
Definition: ip.c:29
session_mq_rings_e
u32 index
Definition: flow_types.api:221
enum session_flags_bits_ session_flag_bits_t
session_cleanup_ntf_t
static u8 session_has_transport(session_t *s)
enum session_error_ session_error_t
u32 app_wrk_index
Index of the app worker that owns the session.
static u8 session_endpoint_is_local(session_endpoint_t *sep)
struct _session_endpoint session_endpoint_t
struct session_dgram_pre_hdr_ session_dgram_pre_hdr_t
static transport_service_type_t session_transport_service_type(session_t *s)
struct _svm_fifo svm_fifo_t
enum transport_dequeue_type_ transport_tx_fn_type_t
struct session_dgram_header_ session_dgram_hdr_t