FD.io VPP  v19.04.4-rc0-5-ge88582fac
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_LISTENER_PREFIX 0x5FFFFFFF
23 
24 #define foreach_session_endpoint_fields \
25  foreach_transport_endpoint_cfg_fields \
26  _(u8, transport_proto) \
27 
28 typedef struct _session_endpoint
29 {
30 #define _(type, name) type name;
32 #undef _
34 
35 typedef struct _session_endpoint_cfg
36 {
37 #define _(type, name) type name;
39 #undef _
40  u32 app_wrk_index;
41  u32 opaque;
42  u32 ns_index;
43  u8 original_tp;
44  u8 *hostname;
46 
47 #define SESSION_IP46_ZERO \
48 { \
49  .ip6 = { \
50  { 0, 0, }, \
51  }, \
52 }
53 
54 #define TRANSPORT_ENDPOINT_NULL \
55 { \
56  .sw_if_index = ENDPOINT_INVALID_INDEX, \
57  .ip = SESSION_IP46_ZERO, \
58  .fib_index = ENDPOINT_INVALID_INDEX, \
59  .is_ip4 = 0, \
60  .port = 0, \
61 }
62 #define SESSION_ENDPOINT_NULL \
63 { \
64  .sw_if_index = ENDPOINT_INVALID_INDEX, \
65  .ip = SESSION_IP46_ZERO, \
66  .fib_index = ENDPOINT_INVALID_INDEX, \
67  .is_ip4 = 0, \
68  .port = 0, \
69  .peer = TRANSPORT_ENDPOINT_NULL, \
70  .transport_proto = 0, \
71 }
72 #define SESSION_ENDPOINT_CFG_NULL \
73 { \
74  .sw_if_index = ENDPOINT_INVALID_INDEX, \
75  .ip = SESSION_IP46_ZERO, \
76  .fib_index = ENDPOINT_INVALID_INDEX, \
77  .is_ip4 = 0, \
78  .port = 0, \
79  .peer = TRANSPORT_ENDPOINT_NULL, \
80  .transport_proto = 0, \
81  .app_wrk_index = ENDPOINT_INVALID_INDEX, \
82  .opaque = ENDPOINT_INVALID_INDEX, \
83  .hostname = 0, \
84 }
85 
86 #define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
87 #define session_endpoint_to_transport_cfg(_sep) \
88  ((transport_endpoint_cfg_t *)_sep)
89 
91 session_endpoint_fib_proto (session_endpoint_t * sep)
92 {
93  return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
94 }
95 
96 static inline u8
97 session_endpoint_is_local (session_endpoint_t * sep)
98 {
99  return (ip_is_zero (&sep->ip, sep->is_ip4)
100  || ip_is_local_host (&sep->ip, sep->is_ip4));
101 }
102 
103 static inline u8
104 session_endpoint_is_zero (session_endpoint_t * sep)
105 {
106  return ip_is_zero (&sep->ip, sep->is_ip4);
107 }
108 
111 
112 /*
113  * Session states
114  */
115 typedef enum
116 {
130 
131 typedef enum session_flags_
132 {
134  SESSION_F_PROXY = (1 << 1),
136 
137 typedef struct session_
138 {
139  /** Pointers to rx/tx buffers. Once allocated, these do not move */
142 
143  /** Type built from transport and network protocol types */
144  session_type_t session_type;
145 
146  /** State in session layer state machine. See @ref session_state_t */
147  volatile u8 session_state;
148 
149  /** Index in thread pool where session was allocated */
151 
152  /** Index of the app worker that owns the session */
154 
155  /** Index of the thread that allocated the session */
157 
158  /** Session flags. See @ref session_flags_t */
160 
161  /** Index of the transport connection associated to the session */
163 
164  /** Index of application that owns the listener. Set only if a listener */
166 
167  union
168  {
169  /** Parent listener session index if the result of an accept */
171 
172  /** App listener index in app's listener pool if a listener */
174  };
175 
176  /** Opaque, for general use */
178 
180 } session_t;
181 
182 always_inline session_type_t
184 {
185  return (proto << 1 | is_ip4);
186 }
187 
189 session_type_transport_proto (session_type_t st)
190 {
191  return (st >> 1);
192 }
193 
195 session_type_is_ip4 (session_type_t st)
196 {
197  return (st & 1);
198 }
199 
202 {
203  return (s->session_type >> 1);
204 }
205 
208 {
209  u8 is_ip4 = s->session_type & 1;
210  return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
211 }
212 
215 {
217 }
218 
219 static inline transport_service_type_t
221 {
225 }
226 
227 static inline transport_tx_fn_type_t
229 {
232  return transport_protocol_tx_fn_type (tp);
233 }
234 
235 static inline u8
237 {
239 }
240 
241 always_inline session_handle_t
243 {
244  return ((u64) s->thread_index << 32) | (u64) s->session_index;
245 }
246 
248 session_index_from_handle (session_handle_t handle)
249 {
250  return handle & 0xFFFFFFFF;
251 }
252 
254 session_thread_from_handle (session_handle_t handle)
255 {
256  return handle >> 32;
257 }
258 
259 always_inline void
260 session_parse_handle (session_handle_t handle, u32 * index,
261  u32 * thread_index)
262 {
263  *index = session_index_from_handle (handle);
264  *thread_index = session_thread_from_handle (handle);
265 }
266 
267 typedef enum
268 {
290 
291 /* Deprecated and will be removed. Use types above */
292 #define FIFO_EVENT_APP_RX SESSION_IO_EVT_RX
293 #define FIFO_EVENT_APP_TX SESSION_IO_EVT_TX
294 #define FIFO_EVENT_DISCONNECT SESSION_CTRL_EVT_CLOSE
295 #define FIFO_EVENT_BUILTIN_RX SESSION_IO_EVT_BUILTIN_RX
296 #define FIFO_EVENT_BUILTIN_TX SESSION_IO_EVT_BUILTIN_TX
297 
298 typedef enum
299 {
304 
305 typedef struct
306 {
307  void *fp;
308  void *arg;
310 
311 typedef struct
312 {
313  u8 event_type;
314  u8 postponed;
315  union
316  {
317  u32 session_index;
318  session_handle_t session_handle;
319  session_rpc_args_t rpc_args;
320  struct
321  {
322  u8 data[0];
323  };
324  };
325 } __clib_packed session_event_t;
326 
327 #define SESSION_MSG_NULL { }
328 
330 {
334 
335 typedef struct session_dgram_header_
336 {
339  ip46_address_t rmt_ip;
340  ip46_address_t lcl_ip;
344 } __clib_packed session_dgram_hdr_t;
345 
346 #define SESSION_CONN_ID_LEN 37
347 #define SESSION_CONN_HDR_LEN 45
348 
349 STATIC_ASSERT (sizeof (session_dgram_hdr_t) == (SESSION_CONN_ID_LEN + 8),
350  "session conn id wrong length");
351 #endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
352 
353 /*
354  * fd.io coding-style-patch-verification: ON
355  *
356  * Local Variables:
357  * eval: (c-set-style "gnu")
358  * End:
359  */
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:280
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
Definition: session_types.h:91
u8 data[128]
Definition: ipsec.api:248
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:274
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 foreach_session_endpoint_fields
Definition: session_types.h:24
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)
datagram mode
static fib_protocol_t session_get_fib_proto(session_t *s)
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
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)
Definition: session_types.h:97
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
u32 listener_index
Parent listener session index if the result of an accept.