Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #ifndef __included_session_h__ |
| 16 | #define __included_session_h__ |
| 17 | |
| 18 | #include <vnet/session/transport.h> |
| 19 | #include <vlibmemory/unix_shared_memory_queue.h> |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 20 | #include <vnet/session/session_debug.h> |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 21 | #include <vnet/session/segment_manager.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | |
| 23 | #define HALF_OPEN_LOOKUP_INVALID_VALUE ((u64)~0) |
| 24 | #define INVALID_INDEX ((u32)~0) |
| 25 | |
| 26 | /* TODO decide how much since we have pre-data as well */ |
| 27 | #define MAX_HDRS_LEN 100 /* Max number of bytes for headers */ |
| 28 | |
| 29 | typedef enum |
| 30 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 31 | FIFO_EVENT_APP_RX, |
| 32 | FIFO_EVENT_APP_TX, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 33 | FIFO_EVENT_TIMEOUT, |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 34 | FIFO_EVENT_DISCONNECT, |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 35 | FIFO_EVENT_BUILTIN_RX |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 36 | } fifo_event_type_t; |
| 37 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 38 | #define foreach_session_input_error \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 39 | _(NO_SESSION, "No session drops") \ |
| 40 | _(NO_LISTENER, "No listener for dst port drops") \ |
| 41 | _(ENQUEUED, "Packets pushed into rx fifo") \ |
| 42 | _(NOT_READY, "Session not ready packets") \ |
| 43 | _(FIFO_FULL, "Packets dropped for lack of rx fifo space") \ |
| 44 | _(EVENT_FIFO_FULL, "Events not sent for lack of event fifo space") \ |
| 45 | _(API_QUEUE_FULL, "Sessions not created for lack of API queue space") \ |
| 46 | _(NEW_SEG_NO_SPACE, "Created segment, couldn't allocate a fifo pair") \ |
| 47 | _(NO_SPACE, "Couldn't allocate a fifo pair") |
| 48 | |
| 49 | typedef enum |
| 50 | { |
| 51 | #define _(sym,str) SESSION_ERROR_##sym, |
| 52 | foreach_session_input_error |
| 53 | #undef _ |
| 54 | SESSION_N_ERROR, |
| 55 | } session_error_t; |
| 56 | |
| 57 | /* Event queue input node static next indices */ |
| 58 | typedef enum |
| 59 | { |
| 60 | SESSION_QUEUE_NEXT_DROP, |
| 61 | SESSION_QUEUE_NEXT_TCP_IP4_OUTPUT, |
| 62 | SESSION_QUEUE_NEXT_IP4_LOOKUP, |
| 63 | SESSION_QUEUE_NEXT_TCP_IP6_OUTPUT, |
| 64 | SESSION_QUEUE_NEXT_IP6_LOOKUP, |
| 65 | SESSION_QUEUE_N_NEXT, |
| 66 | } session_queue_next_t; |
| 67 | |
| 68 | #define foreach_session_type \ |
| 69 | _(IP4_TCP, ip4_tcp) \ |
| 70 | _(IP4_UDP, ip4_udp) \ |
| 71 | _(IP6_TCP, ip6_tcp) \ |
| 72 | _(IP6_UDP, ip6_udp) |
| 73 | |
| 74 | typedef enum |
| 75 | { |
| 76 | #define _(A, a) SESSION_TYPE_##A, |
| 77 | foreach_session_type |
| 78 | #undef _ |
| 79 | SESSION_N_TYPES, |
| 80 | } session_type_t; |
| 81 | |
| 82 | /* |
| 83 | * Application session state |
| 84 | */ |
| 85 | typedef enum |
| 86 | { |
| 87 | SESSION_STATE_LISTENING, |
| 88 | SESSION_STATE_CONNECTING, |
| 89 | SESSION_STATE_READY, |
| 90 | SESSION_STATE_CLOSED, |
| 91 | SESSION_STATE_N_STATES, |
| 92 | } stream_session_state_t; |
| 93 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 94 | /* *INDENT-OFF* */ |
| 95 | typedef CLIB_PACKED (struct { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 96 | union |
| 97 | { |
| 98 | svm_fifo_t * fifo; |
| 99 | u64 session_handle; |
| 100 | }; |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 101 | u8 event_type; |
| 102 | u16 event_id; |
| 103 | }) session_fifo_event_t; |
| 104 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 105 | |
| 106 | typedef struct _stream_session_t |
| 107 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 108 | /** fifo pointers. Once allocated, these do not move */ |
| 109 | svm_fifo_t *server_rx_fifo; |
| 110 | svm_fifo_t *server_tx_fifo; |
| 111 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 112 | /** svm segment index where fifos were allocated */ |
| 113 | u32 svm_segment_index; |
| 114 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 115 | /** Type */ |
| 116 | u8 session_type; |
| 117 | |
| 118 | /** State */ |
| 119 | u8 session_state; |
| 120 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 121 | u8 thread_index; |
| 122 | |
| 123 | /** used during unbind processing */ |
| 124 | u8 is_deleted; |
| 125 | |
| 126 | /** To avoid n**2 "one event per frame" check */ |
| 127 | u8 enqueue_epoch; |
| 128 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 129 | /** Session index in per_thread pool */ |
| 130 | u32 session_index; |
| 131 | |
| 132 | /** Transport specific */ |
| 133 | u32 connection_index; |
| 134 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 135 | /** Application specific */ |
| 136 | u32 pid; |
| 137 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 138 | /** stream server pool index */ |
| 139 | u32 app_index; |
| 140 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 141 | /** Parent listener session if the result of an accept */ |
| 142 | u32 listener_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 143 | } stream_session_t; |
| 144 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 145 | /* Forward definition */ |
| 146 | typedef struct _session_manager_main session_manager_main_t; |
| 147 | |
| 148 | typedef int |
| 149 | (session_fifo_rx_fn) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 150 | session_manager_main_t * smm, |
| 151 | session_fifo_event_t * e0, stream_session_t * s0, |
| 152 | u32 thread_index, int *n_tx_pkts); |
| 153 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 154 | extern session_fifo_rx_fn session_tx_fifo_peek_and_snd; |
| 155 | extern session_fifo_rx_fn session_tx_fifo_dequeue_and_snd; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 156 | |
| 157 | struct _session_manager_main |
| 158 | { |
| 159 | /** Lookup tables for established sessions and listeners */ |
| 160 | clib_bihash_16_8_t v4_session_hash; |
| 161 | clib_bihash_48_8_t v6_session_hash; |
| 162 | |
| 163 | /** Lookup tables for half-open sessions */ |
| 164 | clib_bihash_16_8_t v4_half_open_hash; |
| 165 | clib_bihash_48_8_t v6_half_open_hash; |
| 166 | |
| 167 | /** Per worker thread session pools */ |
| 168 | stream_session_t **sessions; |
| 169 | |
| 170 | /** Pool of listen sessions. Same type as stream sessions to ease lookups */ |
| 171 | stream_session_t *listen_sessions[SESSION_N_TYPES]; |
| 172 | |
| 173 | /** Sparse vector to map dst port to stream server */ |
| 174 | u16 *stream_server_by_dst_port[SESSION_N_TYPES]; |
| 175 | |
| 176 | /** per-worker enqueue epoch counters */ |
| 177 | u8 *current_enqueue_epoch; |
| 178 | |
| 179 | /** Per-worker thread vector of sessions to enqueue */ |
| 180 | u32 **session_indices_to_enqueue_by_thread; |
| 181 | |
| 182 | /** per-worker tx buffer free lists */ |
| 183 | u32 **tx_buffers; |
| 184 | |
| 185 | /** Per worker-thread vector of partially read events */ |
| 186 | session_fifo_event_t **evts_partially_read; |
| 187 | |
| 188 | /** per-worker active event vectors */ |
| 189 | session_fifo_event_t **fifo_events; |
| 190 | |
| 191 | /** vpp fifo event queue */ |
| 192 | unix_shared_memory_queue_t **vpp_event_queues; |
| 193 | |
| 194 | /** Unique segment name counter */ |
| 195 | u32 unique_segment_name_counter; |
| 196 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 197 | /** Per transport rx function that can either dequeue or peek */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 198 | session_fifo_rx_fn *session_tx_fns[SESSION_N_TYPES]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 199 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 200 | u8 is_enabled; |
| 201 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 202 | /* Convenience */ |
| 203 | vlib_main_t *vlib_main; |
| 204 | vnet_main_t *vnet_main; |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 205 | |
| 206 | #if SESSION_DBG |
| 207 | /** |
| 208 | * last event poll time by thread |
| 209 | * Debug only. Will cause false cache-line sharing as-is |
| 210 | */ |
| 211 | f64 *last_event_poll_by_thread; |
| 212 | #endif |
| 213 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | extern session_manager_main_t session_manager_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 217 | extern vlib_node_registration_t session_queue_node; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 218 | |
| 219 | /* |
| 220 | * Session manager function |
| 221 | */ |
| 222 | always_inline session_manager_main_t * |
| 223 | vnet_get_session_manager_main () |
| 224 | { |
| 225 | return &session_manager_main; |
| 226 | } |
| 227 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 228 | /* |
| 229 | * Stream session functions |
| 230 | */ |
| 231 | |
| 232 | stream_session_t *stream_session_lookup_listener4 (ip4_address_t * lcl, |
| 233 | u16 lcl_port, u8 proto); |
| 234 | stream_session_t *stream_session_lookup4 (ip4_address_t * lcl, |
| 235 | ip4_address_t * rmt, u16 lcl_port, |
| 236 | u16 rmt_port, u8 proto, |
| 237 | u32 thread_index); |
| 238 | stream_session_t *stream_session_lookup_listener6 (ip6_address_t * lcl, |
| 239 | u16 lcl_port, u8 proto); |
| 240 | stream_session_t *stream_session_lookup6 (ip6_address_t * lcl, |
| 241 | ip6_address_t * rmt, u16 lcl_port, |
| 242 | u16 rmt_port, u8, u32 thread_index); |
| 243 | transport_connection_t |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 244 | * stream_session_lookup_transport4 (ip4_address_t * lcl, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 245 | ip4_address_t * rmt, u16 lcl_port, |
| 246 | u16 rmt_port, u8 proto, |
| 247 | u32 thread_index); |
| 248 | transport_connection_t |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 249 | * stream_session_lookup_transport6 (ip6_address_t * lcl, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 250 | ip6_address_t * rmt, u16 lcl_port, |
| 251 | u16 rmt_port, u8 proto, |
| 252 | u32 thread_index); |
| 253 | stream_session_t *stream_session_lookup_listener (ip46_address_t * lcl, |
| 254 | u16 lcl_port, u8 proto); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 255 | void stream_session_table_add_for_tc (transport_connection_t * tc, u64 value); |
| 256 | int stream_session_table_del_for_tc (transport_connection_t * tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 257 | |
| 258 | always_inline stream_session_t * |
| 259 | stream_session_get_tsi (u64 ti_and_si, u32 thread_index) |
| 260 | { |
| 261 | ASSERT ((u32) (ti_and_si >> 32) == thread_index); |
| 262 | return pool_elt_at_index (session_manager_main.sessions[thread_index], |
| 263 | ti_and_si & 0xFFFFFFFFULL); |
| 264 | } |
| 265 | |
| 266 | always_inline stream_session_t * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 267 | stream_session_get (u32 si, u32 thread_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 268 | { |
| 269 | return pool_elt_at_index (session_manager_main.sessions[thread_index], si); |
| 270 | } |
| 271 | |
| 272 | always_inline stream_session_t * |
| 273 | stream_session_get_if_valid (u64 si, u32 thread_index) |
| 274 | { |
| 275 | if (thread_index >= vec_len (session_manager_main.sessions)) |
| 276 | return 0; |
| 277 | |
| 278 | if (pool_is_free_index (session_manager_main.sessions[thread_index], si)) |
| 279 | return 0; |
| 280 | |
| 281 | return pool_elt_at_index (session_manager_main.sessions[thread_index], si); |
| 282 | } |
| 283 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 284 | always_inline u64 |
| 285 | stream_session_handle (stream_session_t * s) |
| 286 | { |
| 287 | return ((u64) s->thread_index << 32) | (u64) s->session_index; |
| 288 | } |
| 289 | |
| 290 | always_inline u32 |
| 291 | stream_session_index_from_handle (u64 handle) |
| 292 | { |
| 293 | return handle & 0xFFFFFFFF; |
| 294 | } |
| 295 | |
| 296 | always_inline u32 |
| 297 | stream_session_thread_from_handle (u64 handle) |
| 298 | { |
| 299 | return handle >> 32; |
| 300 | } |
| 301 | |
| 302 | always_inline void |
| 303 | stream_session_parse_handle (u64 handle, u32 * index, u32 * thread_index) |
| 304 | { |
| 305 | *index = stream_session_index_from_handle (handle); |
| 306 | *thread_index = stream_session_thread_from_handle (handle); |
| 307 | } |
| 308 | |
| 309 | always_inline stream_session_t * |
| 310 | stream_session_get_from_handle (u64 handle) |
| 311 | { |
| 312 | session_manager_main_t *smm = &session_manager_main; |
| 313 | return pool_elt_at_index (smm->sessions[stream_session_thread_from_handle |
| 314 | (handle)], |
| 315 | stream_session_index_from_handle (handle)); |
| 316 | } |
| 317 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 318 | always_inline stream_session_t * |
| 319 | stream_session_listener_get (u8 sst, u64 si) |
| 320 | { |
| 321 | return pool_elt_at_index (session_manager_main.listen_sessions[sst], si); |
| 322 | } |
| 323 | |
| 324 | always_inline u32 |
| 325 | stream_session_get_index (stream_session_t * s) |
| 326 | { |
| 327 | if (s->session_state == SESSION_STATE_LISTENING) |
| 328 | return s - session_manager_main.listen_sessions[s->session_type]; |
| 329 | |
| 330 | return s - session_manager_main.sessions[s->thread_index]; |
| 331 | } |
| 332 | |
| 333 | always_inline u32 |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 334 | stream_session_max_rx_enqueue (transport_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 335 | { |
| 336 | stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index); |
| 337 | return svm_fifo_max_enqueue (s->server_rx_fifo); |
| 338 | } |
| 339 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 340 | always_inline u32 |
| 341 | stream_session_fifo_size (transport_connection_t * tc) |
| 342 | { |
| 343 | stream_session_t *s = stream_session_get (tc->s_index, tc->thread_index); |
| 344 | return s->server_rx_fifo->nitems; |
| 345 | } |
| 346 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 347 | int |
| 348 | stream_session_enqueue_data (transport_connection_t * tc, u8 * data, u16 len, |
| 349 | u8 queue_event); |
| 350 | u32 |
| 351 | stream_session_peek_bytes (transport_connection_t * tc, u8 * buffer, |
| 352 | u32 offset, u32 max_bytes); |
| 353 | u32 stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes); |
| 354 | |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 355 | void stream_session_connect_notify (transport_connection_t * tc, u8 sst, |
| 356 | u8 is_fail); |
| 357 | void stream_session_init_fifos_pointers (transport_connection_t * tc, |
| 358 | u32 rx_pointer, u32 tx_pointer); |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 359 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 360 | void stream_session_accept_notify (transport_connection_t * tc); |
| 361 | void stream_session_disconnect_notify (transport_connection_t * tc); |
| 362 | void stream_session_delete_notify (transport_connection_t * tc); |
| 363 | void stream_session_reset_notify (transport_connection_t * tc); |
| 364 | int |
| 365 | stream_session_accept (transport_connection_t * tc, u32 listener_index, |
| 366 | u8 sst, u8 notify); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 367 | int |
| 368 | stream_session_open (u32 app_index, session_type_t st, |
| 369 | transport_endpoint_t * tep, |
| 370 | transport_connection_t ** tc); |
| 371 | int stream_session_listen (stream_session_t * s, transport_endpoint_t * tep); |
| 372 | int stream_session_stop_listen (stream_session_t * s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 373 | void stream_session_disconnect (stream_session_t * s); |
| 374 | void stream_session_cleanup (stream_session_t * s); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 375 | void session_send_session_evt_to_thread (u64 session_handle, |
| 376 | fifo_event_type_t evt_type, |
| 377 | u32 thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 378 | u8 *format_stream_session (u8 * s, va_list * args); |
| 379 | |
| 380 | void session_register_transport (u8 type, const transport_proto_vft_t * vft); |
| 381 | transport_proto_vft_t *session_get_transport_vft (u8 type); |
| 382 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 383 | clib_error_t *vnet_session_enable_disable (vlib_main_t * vm, u8 is_en); |
| 384 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 385 | always_inline unix_shared_memory_queue_t * |
| 386 | session_manager_get_vpp_event_queue (u32 thread_index) |
| 387 | { |
| 388 | return session_manager_main.vpp_event_queues[thread_index]; |
| 389 | } |
| 390 | |
| 391 | int session_manager_flush_enqueue_events (u32 thread_index); |
| 392 | |
| 393 | always_inline u64 |
| 394 | listen_session_get_handle (stream_session_t * s) |
| 395 | { |
| 396 | ASSERT (s->session_state == SESSION_STATE_LISTENING); |
| 397 | return ((u64) s->session_type << 32) | s->session_index; |
| 398 | } |
| 399 | |
| 400 | always_inline stream_session_t * |
| 401 | listen_session_get_from_handle (u64 handle) |
| 402 | { |
| 403 | session_manager_main_t *smm = &session_manager_main; |
| 404 | stream_session_t *s; |
| 405 | u32 type, index; |
| 406 | type = handle >> 32; |
| 407 | index = handle & 0xFFFFFFFF; |
| 408 | |
| 409 | if (pool_is_free_index (smm->listen_sessions[type], index)) |
| 410 | return 0; |
| 411 | |
| 412 | s = pool_elt_at_index (smm->listen_sessions[type], index); |
| 413 | ASSERT (s->session_state == SESSION_STATE_LISTENING); |
| 414 | return s; |
| 415 | } |
| 416 | |
| 417 | always_inline stream_session_t * |
| 418 | listen_session_new (session_type_t type) |
| 419 | { |
| 420 | stream_session_t *s; |
| 421 | pool_get (session_manager_main.listen_sessions[type], s); |
| 422 | memset (s, 0, sizeof (*s)); |
| 423 | |
| 424 | s->session_type = type; |
| 425 | s->session_state = SESSION_STATE_LISTENING; |
| 426 | s->session_index = s - session_manager_main.listen_sessions[type]; |
| 427 | |
| 428 | return s; |
| 429 | } |
| 430 | |
| 431 | always_inline stream_session_t * |
| 432 | listen_session_get (session_type_t type, u32 index) |
| 433 | { |
| 434 | return pool_elt_at_index (session_manager_main.listen_sessions[type], |
| 435 | index); |
| 436 | } |
| 437 | |
| 438 | always_inline void |
| 439 | listen_session_del (stream_session_t * s) |
| 440 | { |
| 441 | pool_put (session_manager_main.listen_sessions[s->session_type], s); |
| 442 | } |
| 443 | |
| 444 | always_inline u8 |
| 445 | session_manager_is_enabled () |
| 446 | { |
| 447 | return session_manager_main.is_enabled == 1; |
| 448 | } |
| 449 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 450 | #endif /* __included_session_h__ */ |
| 451 | |
| 452 | /* |
| 453 | * fd.io coding-style-patch-verification: ON |
| 454 | * |
| 455 | * Local Variables: |
| 456 | * eval: (c-set-style "gnu") |
| 457 | * End: |
| 458 | */ |