FD.io VPP  v19.08.3-2-gbabecb413
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 84
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;
49 
50 #define SESSION_IP46_ZERO \
51 { \
52  .ip6 = { \
53  { 0, 0, }, \
54  }, \
55 }
56 
57 #define TRANSPORT_ENDPOINT_NULL \
58 { \
59  .sw_if_index = ENDPOINT_INVALID_INDEX, \
60  .ip = SESSION_IP46_ZERO, \
61  .fib_index = ENDPOINT_INVALID_INDEX, \
62  .is_ip4 = 0, \
63  .port = 0, \
64 }
65 #define SESSION_ENDPOINT_NULL \
66 { \
67  .sw_if_index = ENDPOINT_INVALID_INDEX, \
68  .ip = SESSION_IP46_ZERO, \
69  .fib_index = ENDPOINT_INVALID_INDEX, \
70  .is_ip4 = 0, \
71  .port = 0, \
72  .peer = TRANSPORT_ENDPOINT_NULL, \
73  .transport_proto = 0, \
74 }
75 #define SESSION_ENDPOINT_CFG_NULL \
76 { \
77  .sw_if_index = ENDPOINT_INVALID_INDEX, \
78  .ip = SESSION_IP46_ZERO, \
79  .fib_index = ENDPOINT_INVALID_INDEX, \
80  .is_ip4 = 0, \
81  .port = 0, \
82  .peer = TRANSPORT_ENDPOINT_NULL, \
83  .transport_proto = 0, \
84  .app_wrk_index = ENDPOINT_INVALID_INDEX, \
85  .opaque = ENDPOINT_INVALID_INDEX, \
86  .hostname = 0, \
87  .parent_handle = SESSION_INVALID_HANDLE \
88 }
89 
90 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
91 #define session_endpoint_to_transport_cfg(_sep) \
92  ((transport_endpoint_cfg_t *)_sep)
93 
95 session_endpoint_fib_proto (session_endpoint_t * sep)
96 {
97  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
98 }
99 
100 static inline u8
101 session_endpoint_is_local (session_endpoint_t * sep)
102 {
103  return (ip_is_zero (&sep->ip, sep->is_ip4)
104  || ip_is_local_host (&sep->ip, sep->is_ip4));
105 }
106 
107 static inline u8
108 session_endpoint_is_zero (session_endpoint_t * sep)
109 {
110  return ip_is_zero (&sep->ip, sep->is_ip4);
111 }
112 
115 
116 typedef enum
117 {
121 
122 /*
123  * Session states
124  */
125 #define foreach_session_state \
126  _(CREATED, "created") \
127  _(LISTENING, "listening") \
128  _(CONNECTING, "connecting") \
129  _(ACCEPTING, "accepting") \
130  _(READY, "ready") \
131  _(OPENED, "opened") \
132  _(TRANSPORT_CLOSING, "transport-closing") \
133  _(CLOSING, "closing") \
134  _(APP_CLOSED, "app-closed") \
135  _(TRANSPORT_CLOSED, "transport-closed") \
136  _(CLOSED, "closed") \
137  _(TRANSPORT_DELETED, "transport-deleted") \
138 
139 typedef enum
140 {
141 #define _(sym, str) SESSION_STATE_ ## sym,
143 #undef _
146 
147 typedef enum session_flags_
148 {
150  SESSION_F_PROXY = (1 << 1),
153 
154 typedef struct session_
155 {
156  /** Pointers to rx/tx buffers. Once allocated, these do not move */
159 
160  /** Type built from transport and network protocol types */
161  session_type_t session_type;
162 
163  /** State in session layer state machine. See @ref session_state_t */
164  volatile u8 session_state;
165 
166  /** Index in thread pool where session was allocated */
168 
169  /** Index of the app worker that owns the session */
171 
172  /** Index of the thread that allocated the session */
174 
175  /** Session flags. See @ref session_flags_t */
177 
178  /** Index of the transport connection associated to the session */
180 
181  /** Index of application that owns the listener. Set only if a listener */
183 
184  union
185  {
186  /** Parent listener session index if the result of an accept */
187  session_handle_t listener_handle;
188 
189  /** App listener index in app's listener pool if a listener */
191  };
192 
193  /** Opaque, for general use */
195 
197 } session_t;
198 
199 always_inline session_type_t
201 {
202  return (proto << 1 | is_ip4);
203 }
204 
206 session_type_transport_proto (session_type_t st)
207 {
208  return (st >> 1);
209 }
210 
212 session_type_is_ip4 (session_type_t st)
213 {
214  return (st & 1);
215 }
216 
219 {
220  return (s->session_type >> 1);
221 }
222 
225 {
226  u8 is_ip4 = s->session_type & 1;
227  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
228 }
229 
232 {
233  return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
234 }
235 
236 static inline transport_service_type_t
238 {
242 }
243 
244 static inline transport_tx_fn_type_t
246 {
249  return transport_protocol_tx_fn_type (tp);
250 }
251 
252 static inline u8
254 {
256 }
257 
258 always_inline session_handle_t
260 {
261  return ((u64) s->thread_index << 32) | (u64) s->session_index;
262 }
263 
265 session_index_from_handle (session_handle_t handle)
266 {
267  return handle & 0xFFFFFFFF;
268 }
269 
271 session_thread_from_handle (session_handle_t handle)
272 {
273  return handle >> 32;
274 }
275 
276 always_inline void
277 session_parse_handle (session_handle_t handle, u32 * index,
278  u32 * thread_index)
279 {
280  *index = session_index_from_handle (handle);
281  *thread_index = session_thread_from_handle (handle);
282 }
283 
284 static inline session_handle_t
285 session_make_handle (u32 session_index, u32 thread_index)
286 {
287  return (((u64) thread_index << 32) | (u64) session_index);
288 }
289 
290 typedef enum
291 {
319 
320 #define foreach_session_ctrl_evt \
321  _(LISTEN, listen) \
322  _(LISTEN_URI, listen_uri) \
323  _(BOUND, bound) \
324  _(UNLISTEN, unlisten) \
325  _(UNLISTEN_REPLY, unlisten_reply) \
326  _(ACCEPTED, accepted) \
327  _(ACCEPTED_REPLY, accepted_reply) \
328  _(CONNECT, connect) \
329  _(CONNECT_URI, connect_uri) \
330  _(CONNECTED, connected) \
331  _(DISCONNECT, disconnect) \
332  _(DISCONNECTED, disconnected) \
333  _(DISCONNECTED_REPLY, disconnected_reply) \
334  _(RESET_REPLY, reset_reply) \
335  _(REQ_WORKER_UPDATE, req_worker_update) \
336  _(WORKER_UPDATE, worker_update) \
337  _(WORKER_UPDATE_REPLY, worker_update_reply) \
338  _(APP_DETACH, app_detach) \
339 
340 
341 /* Deprecated and will be removed. Use types above */
342 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
343 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
344 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
345 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
346 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
347 
348 typedef enum
349 {
354 
355 typedef struct
356 {
357  void *fp;
358  void *arg;
360 
361 typedef struct
362 {
363  u8 event_type;
364  u8 postponed;
365  union
366  {
367  u32 session_index;
368  session_handle_t session_handle;
369  session_rpc_args_t rpc_args;
370  u32 ctrl_data_index;
371  struct
372  {
373  u8 data[0];
374  };
375  };
376 } __clib_packed session_event_t;
377 
378 #define SESSION_MSG_NULL { }
379 
381 {
385 
386 typedef struct session_dgram_header_
387 {
390  ip46_address_t rmt_ip;
391  ip46_address_t lcl_ip;
395 } __clib_packed session_dgram_hdr_t;
396 
397 #define SESSION_CONN_ID_LEN 37
398 #define SESSION_CONN_HDR_LEN 45
399 
400 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
401  "session conn id wrong length");
402 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
403 
404 /*
405  * fd.io coding-style-patch-verification: ON
406  *
407  * Local Variables:
408  * eval: (c-set-style "gnu")
409  * End:
410  */
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.
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:277
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
Definition: session_types.h:95
u8 data[128]
Definition: ipsec.api:251
u32 flags
Session flags.
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)
struct _svm_fifo svm_fifo_t
u8 session_type_t
session_flags_
#define always_inline
Definition: clib.h:99
ip46_address_t lcl_ip
unsigned int u32
Definition: types.h:88
session_state_t
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:271
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
session_handle_t listener_handle
Parent listener session index if the result of an accept.
#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)
static session_handle_t session_make_handle(u32 session_index, u32 thread_index)
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
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)
u64 session_handle_t
volatile u8 session_state
State in session layer state machine.
u32 opaque
Opaque, for general use.
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
session_cleanup_ntf_t
static u8 session_has_transport(session_t *s)
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)
enum transport_dequeue_type_ transport_tx_fn_type_t
struct session_dgram_header_ session_dgram_hdr_t
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125