FD.io VPP  v19.08-27-gf4dcae4
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 
25 #define foreach_session_endpoint_fields \
26  foreach_transport_endpoint_cfg_fields \
27  _(u8, transport_proto) \
28 
29 typedef struct _session_endpoint
30 {
31 #define _(type, name) type name;
33 #undef _
35 
36 typedef struct _session_endpoint_cfg
37 {
38 #define _(type, name) type name;
40 #undef _
41  u32 app_wrk_index;
42  u32 opaque;
43  u32 ns_index;
44  u8 original_tp;
45  u8 *hostname;
46  u64 parent_handle;
48 
49 #define SESSION_IP46_ZERO \
50 { \
51  .ip6 = { \
52  { 0, 0, }, \
53  }, \
54 }
55 
56 #define TRANSPORT_ENDPOINT_NULL \
57 { \
58  .sw_if_index = ENDPOINT_INVALID_INDEX, \
59  .ip = SESSION_IP46_ZERO, \
60  .fib_index = ENDPOINT_INVALID_INDEX, \
61  .is_ip4 = 0, \
62  .port = 0, \
63 }
64 #define SESSION_ENDPOINT_NULL \
65 { \
66  .sw_if_index = ENDPOINT_INVALID_INDEX, \
67  .ip = SESSION_IP46_ZERO, \
68  .fib_index = ENDPOINT_INVALID_INDEX, \
69  .is_ip4 = 0, \
70  .port = 0, \
71  .peer = TRANSPORT_ENDPOINT_NULL, \
72  .transport_proto = 0, \
73 }
74 #define SESSION_ENDPOINT_CFG_NULL \
75 { \
76  .sw_if_index = ENDPOINT_INVALID_INDEX, \
77  .ip = SESSION_IP46_ZERO, \
78  .fib_index = ENDPOINT_INVALID_INDEX, \
79  .is_ip4 = 0, \
80  .port = 0, \
81  .peer = TRANSPORT_ENDPOINT_NULL, \
82  .transport_proto = 0, \
83  .app_wrk_index = ENDPOINT_INVALID_INDEX, \
84  .opaque = ENDPOINT_INVALID_INDEX, \
85  .hostname = 0, \
86  .parent_handle = SESSION_INVALID_HANDLE \
87 }
88 
89 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
90 #define session_endpoint_to_transport_cfg(_sep) \
91  ((transport_endpoint_cfg_t *)_sep)
92 
94 session_endpoint_fib_proto (session_endpoint_t * sep)
95 {
96  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
97 }
98 
99 static inline u8
100 session_endpoint_is_local (session_endpoint_t * sep)
101 {
102  return (ip_is_zero (&sep->ip, sep->is_ip4)
103  || ip_is_local_host (&sep->ip, sep->is_ip4));
104 }
105 
106 static inline u8
107 session_endpoint_is_zero (session_endpoint_t * sep)
108 {
109  return ip_is_zero (&sep->ip, sep->is_ip4);
110 }
111 
114 
115 typedef enum
116 {
120 
121 /*
122  * Session states
123  */
124 typedef enum
125 {
140 
141 typedef enum session_flags_
142 {
144  SESSION_F_PROXY = (1 << 1),
147 
148 typedef struct session_
149 {
150  /** Pointers to rx/tx buffers. Once allocated, these do not move */
153 
154  /** Type built from transport and network protocol types */
155  session_type_t session_type;
156 
157  /** State in session layer state machine. See @ref session_state_t */
158  volatile u8 session_state;
159 
160  /** Index in thread pool where session was allocated */
162 
163  /** Index of the app worker that owns the session */
165 
166  /** Index of the thread that allocated the session */
168 
169  /** Session flags. See @ref session_flags_t */
171 
172  /** Index of the transport connection associated to the session */
174 
175  /** Index of application that owns the listener. Set only if a listener */
177 
178  union
179  {
180  /** Parent listener session index if the result of an accept */
181  session_handle_t listener_handle;
182 
183  /** App listener index in app's listener pool if a listener */
185  };
186 
187  /** Opaque, for general use */
189 
191 } session_t;
192 
193 always_inline session_type_t
195 {
196  return (proto << 1 | is_ip4);
197 }
198 
200 session_type_transport_proto (session_type_t st)
201 {
202  return (st >> 1);
203 }
204 
206 session_type_is_ip4 (session_type_t st)
207 {
208  return (st & 1);
209 }
210 
213 {
214  return (s->session_type >> 1);
215 }
216 
219 {
220  u8 is_ip4 = s->session_type & 1;
221  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
222 }
223 
226 {
228 }
229 
230 static inline transport_service_type_t
232 {
236 }
237 
238 static inline transport_tx_fn_type_t
240 {
243  return transport_protocol_tx_fn_type (tp);
244 }
245 
246 static inline u8
248 {
250 }
251 
252 always_inline session_handle_t
254 {
255  return ((u64) s->thread_index << 32) | (u64) s->session_index;
256 }
257 
259 session_index_from_handle (session_handle_t handle)
260 {
261  return handle & 0xFFFFFFFF;
262 }
263 
265 session_thread_from_handle (session_handle_t handle)
266 {
267  return handle >> 32;
268 }
269 
270 always_inline void
271 session_parse_handle (session_handle_t handle, u32 * index,
272  u32 * thread_index)
273 {
274  *index = session_index_from_handle (handle);
275  *thread_index = session_thread_from_handle (handle);
276 }
277 
278 static inline session_handle_t
279 session_make_handle (u32 session_index, u32 thread_index)
280 {
281  return (((u64) thread_index << 32) | (u64) session_index);
282 }
283 
284 typedef enum
285 {
307 
308 /* Deprecated and will be removed. Use types above */
309 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
310 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
311 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
312 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
313 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
314 
315 typedef enum
316 {
321 
322 typedef struct
323 {
324  void *fp;
325  void *arg;
327 
328 typedef struct
329 {
330  u8 event_type;
331  u8 postponed;
332  union
333  {
334  u32 session_index;
335  session_handle_t session_handle;
336  session_rpc_args_t rpc_args;
337  struct
338  {
339  u8 data[0];
340  };
341  };
342 } __clib_packed session_event_t;
343 
344 #define SESSION_MSG_NULL { }
345 
347 {
351 
352 typedef struct session_dgram_header_
353 {
356  ip46_address_t rmt_ip;
357  ip46_address_t lcl_ip;
361 } __clib_packed session_dgram_hdr_t;
362 
363 #define SESSION_CONN_ID_LEN 37
364 #define SESSION_CONN_HDR_LEN 45
365 
366 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
367  "session conn id wrong length");
368 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
369 
370 /*
371  * fd.io coding-style-patch-verification: ON
372  *
373  * Local Variables:
374  * eval: (c-set-style "gnu")
375  * End:
376  */
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:304
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
Definition: session_types.h:94
u8 data[128]
Definition: ipsec.api:249
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:98
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:298
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
STATIC_ASSERT(sizeof(session_dgram_hdr_t)==(SESSION_CONN_ID_LEN+8),"session conn id wrong length")
session_handle_t listener_handle
Parent listener session index if the result of an accept.
#define foreach_session_endpoint_fields
Definition: session_types.h:25
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)
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