FD.io VPP  v20.05-21-gb1500e9ff
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 
26 #define foreach_session_endpoint_fields \
27  foreach_transport_endpoint_cfg_fields \
28  _(u8, transport_proto) \
29 
30 typedef struct _session_endpoint
31 {
32 #define _(type, name) type name;
34 #undef _
36 
37 typedef struct _session_endpoint_cfg
38 {
39 #define _(type, name) type name;
41 #undef _
42  u32 app_wrk_index;
43  u32 opaque;
44  u32 ns_index;
45  u8 original_tp;
46  u8 *hostname;
47  u64 parent_handle;
48  u32 ckpair_index;
49  u8 crypto_engine;
50  u8 flags;
52 
53 #define SESSION_IP46_ZERO \
54 { \
55  .ip6 = { \
56  { 0, 0, }, \
57  }, \
58 }
59 
60 #define TRANSPORT_ENDPOINT_NULL \
61 { \
62  .sw_if_index = ENDPOINT_INVALID_INDEX, \
63  .ip = SESSION_IP46_ZERO, \
64  .fib_index = ENDPOINT_INVALID_INDEX, \
65  .is_ip4 = 0, \
66  .port = 0, \
67 }
68 #define SESSION_ENDPOINT_NULL \
69 { \
70  .sw_if_index = ENDPOINT_INVALID_INDEX, \
71  .ip = SESSION_IP46_ZERO, \
72  .fib_index = ENDPOINT_INVALID_INDEX, \
73  .is_ip4 = 0, \
74  .port = 0, \
75  .peer = TRANSPORT_ENDPOINT_NULL, \
76  .transport_proto = 0, \
77 }
78 #define SESSION_ENDPOINT_CFG_NULL \
79 { \
80  .sw_if_index = ENDPOINT_INVALID_INDEX, \
81  .ip = SESSION_IP46_ZERO, \
82  .fib_index = ENDPOINT_INVALID_INDEX, \
83  .is_ip4 = 0, \
84  .port = 0, \
85  .peer = TRANSPORT_ENDPOINT_NULL, \
86  .transport_proto = 0, \
87  .app_wrk_index = ENDPOINT_INVALID_INDEX, \
88  .opaque = ENDPOINT_INVALID_INDEX, \
89  .hostname = 0, \
90  .parent_handle = SESSION_INVALID_HANDLE, \
91  .ckpair_index = 0 \
92 }
93 
94 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
95 #define session_endpoint_to_transport_cfg(_sep) \
96  ((transport_endpoint_cfg_t *)_sep)
97 
99 session_endpoint_fib_proto (session_endpoint_t * sep)
100 {
101  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
102 }
103 
104 static inline u8
105 session_endpoint_is_local (session_endpoint_t * sep)
106 {
107  return (ip_is_zero (&sep->ip, sep->is_ip4)
108  || ip_is_local_host (&sep->ip, sep->is_ip4));
109 }
110 
111 static inline u8
112 session_endpoint_is_zero (session_endpoint_t * sep)
113 {
114  return ip_is_zero (&sep->ip, sep->is_ip4);
115 }
116 
119 
120 typedef enum
121 {
125 
126 typedef enum session_ft_action_
127 {
132 
133 /*
134  * Session states
135  */
136 #define foreach_session_state \
137  _(CREATED, "created") \
138  _(LISTENING, "listening") \
139  _(CONNECTING, "connecting") \
140  _(ACCEPTING, "accepting") \
141  _(READY, "ready") \
142  _(OPENED, "opened") \
143  _(TRANSPORT_CLOSING, "transport-closing") \
144  _(CLOSING, "closing") \
145  _(APP_CLOSED, "app-closed") \
146  _(TRANSPORT_CLOSED, "transport-closed") \
147  _(CLOSED, "closed") \
148  _(TRANSPORT_DELETED, "transport-deleted") \
149 
150 typedef enum
151 {
152 #define _(sym, str) SESSION_STATE_ ## sym,
154 #undef _
157 
158 #define foreach_session_flag \
159  _(RX_EVT, "rx-event") \
160  _(PROXY, "proxy") \
161  _(CUSTOM_TX, "custom-tx") \
162  _(IS_MIGRATING, "migrating") \
163  _(UNIDIRECTIONAL, "unidirectional") \
164  _(CUSTOM_FIFO_TUNING, "custom-fifo-tuning") \
165 
167 {
168 #define _(sym, str) SESSION_F_BIT_ ## sym,
170 #undef _
173 
174 typedef enum session_flags_
175 {
176 #define _(sym, str) SESSION_F_ ## sym = 1 << SESSION_F_BIT_ ## sym,
178 #undef _
180 
181 typedef struct session_
182 {
183  /** Pointers to rx/tx buffers. Once allocated, these do not move */
186 
187  /** Type built from transport and network protocol types */
188  session_type_t session_type;
189 
190  /** State in session layer state machine. See @ref session_state_t */
191  volatile u8 session_state;
192 
193  /** Index in thread pool where session was allocated */
195 
196  /** Index of the app worker that owns the session */
198 
199  /** Index of the thread that allocated the session */
201 
202  /** Session flags. See @ref session_flags_t */
204 
205  /** Index of the transport connection associated to the session */
207 
208  /** Index of application that owns the listener. Set only if a listener */
210 
211  union
212  {
213  /** Parent listener session index if the result of an accept */
214  session_handle_t listener_handle;
215 
216  /** App listener index in app's listener pool if a listener */
218  };
219 
220  /** Opaque, for general use */
222 
224 } session_t;
225 
226 always_inline session_type_t
228 {
229  return (proto << 1 | is_ip4);
230 }
231 
233 session_type_transport_proto (session_type_t st)
234 {
235  return (st >> 1);
236 }
237 
239 session_type_is_ip4 (session_type_t st)
240 {
241  return (st & 1);
242 }
243 
246 {
247  return (s->session_type >> 1);
248 }
249 
252 {
253  u8 is_ip4 = s->session_type & 1;
254  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
255 }
256 
259 {
260  return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
261 }
262 
263 static inline transport_service_type_t
265 {
269 }
270 
271 static inline transport_tx_fn_type_t
273 {
276  return transport_protocol_tx_fn_type (tp);
277 }
278 
279 static inline u8
281 {
283 }
284 
285 always_inline session_handle_t
287 {
288  return ((u64) s->thread_index << 32) | (u64) s->session_index;
289 }
290 
292 session_index_from_handle (session_handle_t handle)
293 {
294  return handle & 0xFFFFFFFF;
295 }
296 
298 session_thread_from_handle (session_handle_t handle)
299 {
300  return handle >> 32;
301 }
302 
303 always_inline void
304 session_parse_handle (session_handle_t handle, u32 * index,
305  u32 * thread_index)
306 {
307  *index = session_index_from_handle (handle);
308  *thread_index = session_thread_from_handle (handle);
309 }
310 
311 static inline session_handle_t
312 session_make_handle (u32 session_index, u32 data)
313 {
314  return (((u64) data << 32) | (u64) session_index);
315 }
316 
318 session_handle_index (session_handle_t ho_handle)
319 {
320  return (ho_handle & 0xffffffff);
321 }
322 
324 session_handle_data (session_handle_t ho_handle)
325 {
326  return (ho_handle >> 32);
327 }
328 
329 typedef enum
330 {
362 
363 #define foreach_session_ctrl_evt \
364  _(LISTEN, listen) \
365  _(LISTEN_URI, listen_uri) \
366  _(BOUND, bound) \
367  _(UNLISTEN, unlisten) \
368  _(UNLISTEN_REPLY, unlisten_reply) \
369  _(ACCEPTED, accepted) \
370  _(ACCEPTED_REPLY, accepted_reply) \
371  _(CONNECT, connect) \
372  _(CONNECT_URI, connect_uri) \
373  _(CONNECTED, connected) \
374  _(DISCONNECT, disconnect) \
375  _(DISCONNECTED, disconnected) \
376  _(DISCONNECTED_REPLY, disconnected_reply) \
377  _(RESET_REPLY, reset_reply) \
378  _(REQ_WORKER_UPDATE, req_worker_update) \
379  _(WORKER_UPDATE, worker_update) \
380  _(WORKER_UPDATE_REPLY, worker_update_reply) \
381  _(APP_DETACH, app_detach) \
382  _(APP_ADD_SEGMENT, app_add_segment) \
383  _(APP_DEL_SEGMENT, app_del_segment) \
384  _(MIGRATED, migrated) \
385  _(CLEANUP, cleanup) \
386 
387 /* Deprecated and will be removed. Use types above */
388 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
389 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
390 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
391 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
392 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
393 
394 typedef enum
395 {
400 
401 typedef struct
402 {
403  void *fp;
404  void *arg;
406 
407 typedef struct
408 {
409  u8 event_type;
410  u8 postponed;
411  union
412  {
413  u32 session_index;
414  session_handle_t session_handle;
415  session_rpc_args_t rpc_args;
416  u32 ctrl_data_index;
417  struct
418  {
419  u8 data[0];
420  };
421  };
422 } __clib_packed session_event_t;
423 
424 #define SESSION_MSG_NULL { }
425 
427 {
431 
432 typedef struct session_dgram_header_
433 {
436  ip46_address_t rmt_ip;
437  ip46_address_t lcl_ip;
441 } __clib_packed session_dgram_hdr_t;
442 
443 #define SESSION_CONN_ID_LEN 37
444 #define SESSION_CONN_HDR_LEN 45
445 
446 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
447  "session conn id wrong length");
448 
449 #define foreach_session_error \
450  _(NONE, "no error") \
451  _(UNKNOWN, "generic/unknown error") \
452  _(REFUSED, "refused") \
453  _(TIMEDOUT, "timedout") \
454  _(ALLOC, "obj/memory allocation error") \
455  _(OWNER, "object not owned by application") \
456  _(NOROUTE, "no route") \
457  _(NOINTF, "no resolving interface") \
458  _(NOIP, "no ip for lcl interface") \
459  _(NOPORT, "no lcl port") \
460  _(NOSUPPORT, "not supported") \
461  _(NOLISTEN, "not listening") \
462  _(NOSESSION, "session does not exist") \
463  _(NOAPP, "app not attached") \
464  _(PORTINUSE, "lcl port in use") \
465  _(IPINUSE, "ip in use") \
466  _(ALREADY_LISTENING, "ip port pair already listened on") \
467  _(INVALID_RMT_IP, "invalid remote ip") \
468  _(INVALID_APPWRK, "invalid app worker") \
469  _(INVALID_NS, "invalid namespace") \
470  _(SEG_NO_SPACE, "Couldn't allocate a fifo pair") \
471  _(SEG_NO_SPACE2, "Created segment, couldn't allocate a fifo pair") \
472  _(SEG_CREATE, "Couldn't create a new segment") \
473  _(FILTERED, "session filtered") \
474  _(SCOPE, "scope not supported") \
475  _(BAPI_NO_FD, "bapi doesn't have a socket fd") \
476  _(BAPI_SEND_FD, "couldn't send fd over bapi socket fd") \
477  _(BAPI_NO_REG, "app bapi registration not found") \
478  _(MQ_MSG_ALLOC, "failed to alloc mq msg") \
479  _(TLS_HANDSHAKE, "failed tls handshake") \
480 
481 typedef enum session_error_p_
482 {
483 #define _(sym, str) SESSION_EP_##sym,
485 #undef _
488 
489 typedef enum session_error_
490 {
491 #define _(sym, str) SESSION_E_##sym = -SESSION_EP_##sym,
493 #undef _
495 
496 /* Maintained for compatibility. Will be deprecated */
497 #define SESSION_ERROR_SEG_CREATE SESSION_E_SEG_CREATE
498 #define SESSION_ERROR_NO_SPACE SESSION_E_SEG_NO_SPACE
499 #define SESSION_ERROR_NEW_SEG_NO_SPACE SESSION_E_SEG_NO_SPACE2
500 
501 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
502 
503 /*
504  * fd.io coding-style-patch-verification: ON
505  *
506  * Local Variables:
507  * eval: (c-set-style "gnu")
508  * End:
509  */
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.
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)
Definition: session_types.h:99
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
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:50
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
u32 flags
Definition: vhost_user.h:248
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:26
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
u8 data[128]
Definition: ipsec_types.api:89
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
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