- /* Assumes that caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE ((session_index == ~0) ||
- pool_is_free_index (vcm->sessions, session_index)))
- {
- clib_warning ("VCL<%d>: invalid session, sid (%u) has been closed!",
- getpid (), session_index);
- return VPPCOM_EBADFD;
- }
- *sess = pool_elt_at_index (vcm->sessions, session_index);
- return VPPCOM_OK;
+ vcl_session_t *s;
+ pool_get (wrk->sessions, s);
+ memset (s, 0, sizeof (*s));
+ s->session_index = s - wrk->sessions;
+ s->listener_index = VCL_INVALID_SESSION_INDEX;
+ return s;
+}
+
+static inline void
+vcl_session_free (vcl_worker_t * wrk, vcl_session_t * s)
+{
+ pool_put (wrk->sessions, s);
+}
+
+static inline vcl_session_t *
+vcl_session_get (vcl_worker_t * wrk, u32 session_index)
+{
+ if (pool_is_free_index (wrk->sessions, session_index))
+ return 0;
+ return pool_elt_at_index (wrk->sessions, session_index);
+}
+
+static inline vcl_session_handle_t
+vcl_session_handle_from_index (u32 session_index)
+{
+ ASSERT (session_index < 2 << 24);
+ return (vcl_get_worker_index () << 24 | session_index);
+}
+
+static inline vcl_session_handle_t
+vcl_session_handle (vcl_session_t * s)
+{
+ return vcl_session_handle_from_index (s->session_index);
+}
+
+static inline void
+vcl_session_handle_parse (u32 handle, u32 * wrk_index, u32 * session_index)
+{
+ *wrk_index = handle >> 24;
+ *session_index = handle & 0xFFFFFF;
+}
+
+static inline vcl_session_t *
+vcl_session_get_w_handle (vcl_worker_t * wrk, u32 session_handle)
+{
+ u32 session_index, wrk_index;
+ vcl_session_handle_parse (session_handle, &wrk_index, &session_index);
+ ASSERT (wrk_index == wrk->wrk_index);
+ return vcl_session_get (wrk, session_index);
+}
+
+static inline vcl_session_t *
+vcl_session_get_w_vpp_handle (vcl_worker_t * wrk, u64 vpp_handle)
+{
+ uword *p;
+ if ((p = hash_get (wrk->session_index_by_vpp_handles, vpp_handle)))
+ return vcl_session_get (wrk, (u32) p[0]);
+ return 0;
+}
+
+static inline u32
+vcl_session_index_from_vpp_handle (vcl_worker_t * wrk, u64 vpp_handle)
+{
+ uword *p;
+ if ((p = hash_get (wrk->session_index_by_vpp_handles, vpp_handle)))
+ return p[0];
+ return VCL_INVALID_SESSION_INDEX;