summaryrefslogtreecommitdiffstats
path: root/src/vcl
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-10-14 16:35:58 -0700
committerFlorin Coras <florin.coras@gmail.com>2020-10-15 16:59:55 +0000
commitc127d5ad0a9c09b25facabf28288324f125701ad (patch)
tree25d310d446781014c11c44a4055f6d369e227b49 /src/vcl
parente8346c8fd49d611d4093f62e414c15470254d436 (diff)
vcl: refactor session state enum
Only allow one state instead of using flags. Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I08ffccbf8c3f6e2f61533996bb36c799cbc931e7
Diffstat (limited to 'src/vcl')
-rw-r--r--src/vcl/vcl_locked.c20
-rw-r--r--src/vcl/vcl_private.c61
-rw-r--r--src/vcl/vcl_private.h65
-rw-r--r--src/vcl/vppcom.c172
4 files changed, 159 insertions, 159 deletions
diff --git a/src/vcl/vcl_locked.c b/src/vcl/vcl_locked.c
index 678499cd71c..5758dc4b12d 100644
--- a/src/vcl/vcl_locked.c
+++ b/src/vcl/vcl_locked.c
@@ -566,10 +566,10 @@ vls_listener_wrk_stop_listen (vcl_locked_session_t * vls, u32 wrk_index)
wrk = vcl_worker_get (wrk_index);
s = vcl_session_get (wrk, vls->session_index);
- if (s->session_state != STATE_LISTEN)
+ if (s->session_state != VCL_STATE_LISTEN)
return;
vcl_send_session_unlisten (wrk, s);
- s->session_state = STATE_LISTEN_NO_MQ;
+ s->session_state = VCL_STATE_LISTEN_NO_MQ;
vls_listener_wrk_set (vls, wrk_index, 0 /* is_active */ );
}
@@ -599,7 +599,7 @@ vls_unshare_session (vcl_locked_session_t * vls, vcl_worker_t * wrk)
return 0;
s = vcl_session_get (wrk, vls->session_index);
- if (s->session_state == STATE_LISTEN)
+ if (s->session_state == VCL_STATE_LISTEN)
vls_listener_wrk_set (vls, wrk->wrk_index, 0 /* is_active */ );
vls_shared_data_pool_rlock ();
@@ -629,7 +629,7 @@ vls_unshare_session (vcl_locked_session_t * vls, vcl_worker_t * wrk)
* Cleanup vcl state
*/
n_subscribers = vec_len (vls_shd->workers_subscribed);
- do_disconnect = s->session_state == STATE_LISTEN || !n_subscribers;
+ do_disconnect = s->session_state == VCL_STATE_LISTEN || !n_subscribers;
vcl_session_cleanup (wrk, s, vcl_session_handle (s), do_disconnect);
/*
@@ -724,9 +724,9 @@ vls_share_session (vls_worker_t * vls_wrk, vcl_locked_session_t * vls)
svm_fifo_add_subscriber (s->rx_fifo, vcl_wrk->vpp_wrk_index);
svm_fifo_add_subscriber (s->tx_fifo, vcl_wrk->vpp_wrk_index);
}
- else if (s->session_state == STATE_LISTEN)
+ else if (s->session_state == VCL_STATE_LISTEN)
{
- s->session_state = STATE_LISTEN_NO_MQ;
+ s->session_state = VCL_STATE_LISTEN_NO_MQ;
}
}
@@ -904,7 +904,7 @@ vls_mt_session_migrate (vcl_locked_session_t * vls)
return;
}
else if (PREDICT_FALSE (!session->is_vep &&
- session->session_state != STATE_CLOSED))
+ session->session_state != VCL_STATE_CLOSED))
{
/* TODO: rollback? */
VERR ("migrate NOT supported, session_status (%u)",
@@ -1099,7 +1099,7 @@ vls_mp_checks (vcl_locked_session_t * vls, int is_add)
s = vcl_session_get (wrk, vls->session_index);
switch (s->session_state)
{
- case STATE_LISTEN:
+ case VCL_STATE_LISTEN:
if (is_add)
{
vls_listener_wrk_set (vls, vls->worker_index, 1 /* is_active */ );
@@ -1107,7 +1107,7 @@ vls_mp_checks (vcl_locked_session_t * vls, int is_add)
}
vls_listener_wrk_stop_listen (vls, vls->worker_index);
break;
- case STATE_LISTEN_NO_MQ:
+ case VCL_STATE_LISTEN_NO_MQ:
if (!is_add)
break;
@@ -1339,7 +1339,7 @@ vls_select_mp_checks (vcl_si_set * read_map)
/* *INDENT-OFF* */
clib_bitmap_foreach (si, read_map, ({
s = vcl_session_get (wrk, si);
- if (s->session_state == STATE_LISTEN)
+ if (s->session_state == VCL_STATE_LISTEN)
{
vls = vls_get (vls_session_index_to_vlsh (si));
vls_mp_checks (vls, 1 /* is_add */);
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index fd35db0b678..a1c252d9e99 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -226,46 +226,48 @@ vcl_worker_ctrl_mq (vcl_worker_t * wrk)
}
int
-vcl_session_read_ready (vcl_session_t * session)
+vcl_session_read_ready (vcl_session_t * s)
{
u32 max_deq;
/* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
+ if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "ERROR: session %u: cannot read from an epoll session!",
- session->session_index);
+ s->session_index);
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN))))
+ if (PREDICT_FALSE (!(vcl_session_is_ready (s)
+ || s->session_state == VCL_STATE_LISTEN)))
{
- vcl_session_state_t state = session->session_state;
+ vcl_session_state_t state = s->session_state;
int rv;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ rv = (state == VCL_STATE_DISCONNECT) ?
+ VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
VDBG (1, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
- session->session_index, session->vpp_handle, state,
+ s->session_index, s->vpp_handle, state,
vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
return rv;
}
- if (session->session_state & STATE_LISTEN)
- return clib_fifo_elts (session->accept_evts_fifo);
+ if (s->session_state == VCL_STATE_LISTEN)
+ return clib_fifo_elts (s->accept_evts_fifo);
- if (vcl_session_is_ct (session))
- return svm_fifo_max_dequeue_cons (session->ct_rx_fifo);
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_dequeue_cons (s->ct_rx_fifo);
- max_deq = svm_fifo_max_dequeue_cons (session->rx_fifo);
+ max_deq = svm_fifo_max_dequeue_cons (s->rx_fifo);
- if (session->is_dgram)
+ if (s->is_dgram)
{
session_dgram_pre_hdr_t ph;
if (max_deq <= SESSION_CONN_HDR_LEN)
return 0;
- if (svm_fifo_peek (session->rx_fifo, 0, sizeof (ph), (u8 *) & ph) < 0)
+ if (svm_fifo_peek (s->rx_fifo, 0, sizeof (ph), (u8 *) & ph) < 0)
return 0;
if (ph.data_length + SESSION_CONN_HDR_LEN > max_deq)
return 0;
@@ -277,49 +279,50 @@ vcl_session_read_ready (vcl_session_t * session)
}
int
-vcl_session_write_ready (vcl_session_t * session)
+vcl_session_write_ready (vcl_session_t * s)
{
/* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
+ if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
- session->session_index, session->vpp_handle);
+ s->session_index, s->vpp_handle);
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
+ if (PREDICT_FALSE (s->session_state == VCL_STATE_LISTEN))
{
- if (session->tx_fifo)
- return svm_fifo_max_enqueue_prod (session->tx_fifo);
+ if (s->tx_fifo)
+ return svm_fifo_max_enqueue_prod (s->tx_fifo);
else
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(session->session_state & STATE_OPEN)))
+ if (PREDICT_FALSE (!vcl_session_is_ready (s)))
{
- vcl_session_state_t state = session->session_state;
+ vcl_session_state_t state = s->session_state;
int rv;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ rv = (state == VCL_STATE_DISCONNECT) ?
+ VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
VDBG (0, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
- session->session_index, session->vpp_handle, state,
+ s->session_index, s->vpp_handle, state,
vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
return rv;
}
- if (vcl_session_is_ct (session))
- return svm_fifo_max_enqueue_prod (session->ct_tx_fifo);
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_enqueue_prod (s->ct_tx_fifo);
- if (session->is_dgram)
+ if (s->is_dgram)
{
- u32 max_enq = svm_fifo_max_enqueue_prod (session->tx_fifo);
+ u32 max_enq = svm_fifo_max_enqueue_prod (s->tx_fifo);
if (max_enq <= sizeof (session_dgram_hdr_t))
return 0;
return max_enq - sizeof (session_dgram_hdr_t);
}
- return svm_fifo_max_enqueue_prod (session->tx_fifo);
+ return svm_fifo_max_enqueue_prod (s->tx_fifo);
}
int
diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h
index 89151faa316..e03804f6c11 100644
--- a/src/vcl/vcl_private.h
+++ b/src/vcl/vcl_private.h
@@ -62,23 +62,19 @@ typedef enum
STATE_APP_READY
} vcl_bapi_app_state_t;
-typedef enum
-{
- STATE_CLOSED = 0,
- STATE_CONNECT = 0x01,
- STATE_LISTEN = 0x02,
- STATE_ACCEPT = 0x04,
- STATE_VPP_CLOSING = 0x08,
- STATE_DISCONNECT = 0x10,
- STATE_DETACHED = 0x20,
- STATE_UPDATED = 0x40,
- STATE_LISTEN_NO_MQ = 0x80,
+typedef enum vcl_session_state_
+{
+ VCL_STATE_CLOSED,
+ VCL_STATE_CONNECT,
+ VCL_STATE_LISTEN,
+ VCL_STATE_ACCEPT,
+ VCL_STATE_VPP_CLOSING,
+ VCL_STATE_DISCONNECT,
+ VCL_STATE_DETACHED,
+ VCL_STATE_UPDATED,
+ VCL_STATE_LISTEN_NO_MQ,
} vcl_session_state_t;
-#define SERVER_STATE_OPEN (STATE_ACCEPT|STATE_VPP_CLOSING)
-#define CLIENT_STATE_OPEN (STATE_CONNECT|STATE_VPP_CLOSING)
-#define STATE_OPEN (SERVER_STATE_OPEN | CLIENT_STATE_OPEN)
-
typedef struct epoll_event vppcom_epoll_event_t;
typedef struct
@@ -509,18 +505,18 @@ vcl_session_is_connectable_listener (vcl_worker_t * wrk,
if (session->session_type != VPPCOM_PROTO_QUIC)
return 0;
if (session->listener_index == VCL_INVALID_SESSION_INDEX)
- return !(session->session_state & STATE_LISTEN);
+ return !(session->session_state == VCL_STATE_LISTEN);
ls = vcl_session_get_w_handle (wrk, session->listener_index);
if (!ls)
return VPPCOM_EBADFD;
- return ls->session_state & STATE_LISTEN;
+ return ls->session_state == VCL_STATE_LISTEN;
}
static inline vcl_session_t *
vcl_session_table_lookup_listener (vcl_worker_t * wrk, u64 handle)
{
uword *p;
- vcl_session_t *session;
+ vcl_session_t *s;
p = hash_get (wrk->session_index_by_vpp_handles, handle);
if (!p)
@@ -529,16 +525,17 @@ vcl_session_table_lookup_listener (vcl_worker_t * wrk, u64 handle)
" %llx", handle);
return 0;
}
- session = vcl_session_get (wrk, p[0]);
- if (!session)
+ s = vcl_session_get (wrk, p[0]);
+ if (!s)
{
VDBG (1, "invalid listen session index (%u)", p[0]);
return 0;
}
- ASSERT ((session->session_state & (STATE_LISTEN | STATE_LISTEN_NO_MQ)) ||
- vcl_session_is_connectable_listener (wrk, session));
- return session;
+ ASSERT (s->session_state == VCL_STATE_LISTEN
+ || s->session_state == VCL_STATE_LISTEN_NO_MQ
+ || vcl_session_is_connectable_listener (wrk, s));
+ return s;
}
const char *vppcom_session_state_str (vcl_session_state_t state);
@@ -558,37 +555,45 @@ vcl_session_is_cl (vcl_session_t * s)
}
static inline u8
+vcl_session_is_ready (vcl_session_t * s)
+{
+ return (s->session_state == VCL_STATE_ACCEPT
+ || s->session_state == VCL_STATE_CONNECT
+ || s->session_state == VCL_STATE_VPP_CLOSING);
+}
+
+static inline u8
vcl_session_is_open (vcl_session_t * s)
{
- return ((s->session_state & STATE_OPEN)
- || (s->session_state == STATE_LISTEN
+ return ((vcl_session_is_ready (s))
+ || (s->session_state == VCL_STATE_LISTEN
&& s->session_type == VPPCOM_PROTO_UDP));
}
static inline u8
vcl_session_is_closing (vcl_session_t * s)
{
- return (s->session_state == STATE_VPP_CLOSING
- || s->session_state == STATE_DISCONNECT);
+ return (s->session_state == VCL_STATE_VPP_CLOSING
+ || s->session_state == VCL_STATE_DISCONNECT);
}
static inline u8
vcl_session_is_closed (vcl_session_t * s)
{
- return (!s || (s->session_state == STATE_CLOSED));
+ return (!s || (s->session_state == VCL_STATE_CLOSED));
}
static inline int
vcl_session_closing_error (vcl_session_t * s)
{
/* Return 0 on closing sockets */
- return s->session_state == STATE_DISCONNECT ? VPPCOM_ECONNRESET : 0;
+ return s->session_state == VCL_STATE_DISCONNECT ? VPPCOM_ECONNRESET : 0;
}
static inline int
vcl_session_closed_error (vcl_session_t * s)
{
- return s->session_state == STATE_DISCONNECT
+ return s->session_state == VCL_STATE_DISCONNECT
? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
}
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index 6b9e36c2d7d..ca20ffcdb30 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -60,42 +60,33 @@ vppcom_session_state_str (vcl_session_state_t state)
switch (state)
{
- case STATE_CLOSED:
+ case VCL_STATE_CLOSED:
st = "STATE_CLOSED";
break;
-
- case STATE_CONNECT:
+ case VCL_STATE_CONNECT:
st = "STATE_CONNECT";
break;
-
- case STATE_LISTEN:
+ case VCL_STATE_LISTEN:
st = "STATE_LISTEN";
break;
-
- case STATE_ACCEPT:
+ case VCL_STATE_ACCEPT:
st = "STATE_ACCEPT";
break;
-
- case STATE_VPP_CLOSING:
+ case VCL_STATE_VPP_CLOSING:
st = "STATE_VPP_CLOSING";
break;
-
- case STATE_DISCONNECT:
+ case VCL_STATE_DISCONNECT:
st = "STATE_DISCONNECT";
break;
-
- case STATE_DETACHED:
+ case VCL_STATE_DETACHED:
st = "STATE_DETACHED";
break;
-
- case STATE_UPDATED:
+ case VCL_STATE_UPDATED:
st = "STATE_UPDATED";
break;
-
- case STATE_LISTEN_NO_MQ:
+ case VCL_STATE_LISTEN_NO_MQ:
st = "STATE_LISTEN_NO_MQ";
break;
-
default:
st = "UNKNOWN_STATE";
break;
@@ -427,7 +418,7 @@ vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp,
session->rx_fifo = rx_fifo;
session->tx_fifo = tx_fifo;
- session->session_state = STATE_ACCEPT;
+ session->session_state = VCL_STATE_ACCEPT;
session->transport.rmt_port = mp->rmt.port;
session->transport.is_ip4 = mp->rmt.is_ip4;
clib_memcpy_fast (&session->transport.rmt_ip, &mp->rmt.ip,
@@ -481,7 +472,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
{
VDBG (0, "ERROR: session index %u: connect failed! %U",
session_index, format_session_error, mp->retval);
- session->session_state = STATE_DETACHED | STATE_DISCONNECT;
+ session->session_state = VCL_STATE_DETACHED;
session->vpp_handle = mp->handle;
return session_index;
}
@@ -495,7 +486,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
{
VDBG (0, "segment for session %u is not mounted!",
session->session_index);
- session->session_state = STATE_DETACHED | STATE_DISCONNECT;
+ session->session_state = VCL_STATE_DETACHED;
vcl_send_session_disconnect (wrk, session);
return session_index;
}
@@ -517,7 +508,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
{
VDBG (0, "ct segment for session %u is not mounted!",
session->session_index);
- session->session_state = STATE_DETACHED | STATE_DISCONNECT;
+ session->session_state = VCL_STATE_DETACHED;
vcl_send_session_disconnect (wrk, session);
return session_index;
}
@@ -533,10 +524,10 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
/* Application closed session before connect reply */
if (VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK)
- && session->session_state == STATE_CLOSED)
+ && session->session_state == VCL_STATE_CLOSED)
vcl_send_session_disconnect (wrk, session);
else
- session->session_state = STATE_CONNECT;
+ session->session_state = VCL_STATE_CONNECT;
/* Add it to lookup table */
vcl_session_table_add_vpp_handle (wrk, mp->handle, session_index);
@@ -582,7 +573,7 @@ vcl_session_reset_handler (vcl_worker_t * wrk,
}
/* Caught a reset before actually accepting the session */
- if (session->session_state == STATE_LISTEN)
+ if (session->session_state == VCL_STATE_LISTEN)
{
if (!vcl_flag_accepted_session (session, reset_msg->handle,
@@ -591,8 +582,8 @@ vcl_session_reset_handler (vcl_worker_t * wrk,
return VCL_INVALID_SESSION_INDEX;
}
- if (session->session_state != STATE_CLOSED)
- session->session_state = STATE_DISCONNECT;
+ if (session->session_state != VCL_STATE_CLOSED)
+ session->session_state = VCL_STATE_DISCONNECT;
VDBG (0, "reset session %u [0x%llx]", sid, reset_msg->handle);
return sid;
}
@@ -610,7 +601,7 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp)
format_session_error, mp->retval);
if (session)
{
- session->session_state = STATE_DETACHED;
+ session->session_state = VCL_STATE_DETACHED;
session->vpp_handle = mp->handle;
return sid;
}
@@ -628,7 +619,7 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp)
sizeof (ip46_address_t));
session->transport.lcl_port = mp->lcl_port;
vcl_session_table_add_listener (wrk, mp->handle, sid);
- session->session_state = STATE_LISTEN;
+ session->session_state = VCL_STATE_LISTEN;
session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
vec_validate (wrk->vpp_event_queues, 0);
@@ -662,11 +653,11 @@ vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data)
VDBG (0, "Unlisten reply with wrong handle %llx", mp->handle);
return;
}
- if (s->session_state != STATE_DISCONNECT)
+ if (s->session_state != VCL_STATE_DISCONNECT)
{
/* Connected udp listener */
if (s->session_type == VPPCOM_PROTO_UDP
- && s->session_state == STATE_CLOSED)
+ && s->session_state == VCL_STATE_CLOSED)
return;
VDBG (0, "Unlisten session in wrong state %llx", mp->handle);
@@ -758,11 +749,11 @@ vcl_session_disconnected_handler (vcl_worker_t * wrk,
}
/* Late disconnect notification on a session that has been closed */
- if (session->session_state == STATE_CLOSED)
+ if (session->session_state == VCL_STATE_CLOSED)
return 0;
/* Caught a disconnect before actually accepting the session */
- if (session->session_state == STATE_LISTEN)
+ if (session->session_state == VCL_STATE_LISTEN)
{
if (!vcl_flag_accepted_session (session, msg->handle,
VCL_ACCEPTED_F_CLOSED))
@@ -771,8 +762,8 @@ vcl_session_disconnected_handler (vcl_worker_t * wrk,
}
/* If not already reset change state */
- if (session->session_state != STATE_DISCONNECT)
- session->session_state = STATE_VPP_CLOSING;
+ if (session->session_state != VCL_STATE_DISCONNECT)
+ session->session_state = VCL_STATE_VPP_CLOSING;
return session;
}
@@ -796,7 +787,7 @@ vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data)
/* Transport was cleaned up before we confirmed close. Probably the
* app is still waiting for some data that cannot be delivered.
* Confirm close to make sure everything is cleaned up */
- if (session->session_state == STATE_VPP_CLOSING)
+ if (session->session_state == VCL_STATE_VPP_CLOSING)
vcl_session_cleanup (wrk, session, vcl_session_handle (session),
1 /* do_disconnect */ );
return;
@@ -804,10 +795,10 @@ vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data)
vcl_session_table_del_vpp_handle (wrk, msg->handle);
/* Should not happen. App did not close the connection so don't free it. */
- if (session->session_state != STATE_CLOSED)
+ if (session->session_state != VCL_STATE_CLOSED)
{
VDBG (0, "app did not close session %d", session->session_index);
- session->session_state = STATE_DETACHED;
+ session->session_state = VCL_STATE_DETACHED;
session->vpp_handle = VCL_INVALID_SESSION_HANDLE;
return;
}
@@ -857,7 +848,7 @@ vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
s->rx_fifo->client_thread_index = wrk->wrk_index;
s->tx_fifo->client_thread_index = wrk->wrk_index;
}
- s->session_state = STATE_UPDATED;
+ s->session_state = VCL_STATE_UPDATED;
VDBG (0, "session %u[0x%llx] moved to worker %u", s->session_index,
s->vpp_handle, wrk->wrk_index);
@@ -928,14 +919,14 @@ static int
vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
{
session_disconnected_msg_t *disconnected_msg;
- vcl_session_t *session;
+ vcl_session_t *s;
switch (e->event_type)
{
case SESSION_IO_EVT_RX:
case SESSION_IO_EVT_TX:
- session = vcl_session_get (wrk, e->session_index);
- if (!session || !(session->session_state & STATE_OPEN))
+ s = vcl_session_get (wrk, e->session_index);
+ if (!s || !(vcl_session_is_ready (s)))
break;
vec_add1 (wrk->unhandled_evts_vector, *e);
break;
@@ -948,11 +939,11 @@ vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
break;
case SESSION_CTRL_EVT_DISCONNECTED:
disconnected_msg = (session_disconnected_msg_t *) e->data;
- session = vcl_session_disconnected_handler (wrk, disconnected_msg);
- if (!session)
+ s = vcl_session_disconnected_handler (wrk, disconnected_msg);
+ if (!s)
break;
- VDBG (0, "disconnected session %u [0x%llx]", session->session_index,
- session->vpp_handle);
+ VDBG (0, "disconnected session %u [0x%llx]", s->session_index,
+ s->vpp_handle);
break;
case SESSION_CTRL_EVT_RESET:
vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data);
@@ -1012,7 +1003,7 @@ vppcom_wait_for_session_state_change (u32 session_index,
{
return VPPCOM_OK;
}
- if (session->session_state & STATE_DETACHED)
+ if (session->session_state == VCL_STATE_DETACHED)
{
return VPPCOM_ECONNREFUSED;
}
@@ -1050,7 +1041,8 @@ vcl_handle_pending_wrk_updates (vcl_worker_t * wrk)
s = vcl_session_get (wrk, *sip);
vcl_send_session_worker_update (wrk, s, wrk->wrk_index);
state = s->session_state;
- vppcom_wait_for_session_state_change (s->session_index, STATE_UPDATED, 5);
+ vppcom_wait_for_session_state_change (s->session_index, VCL_STATE_UPDATED,
+ 5);
s->session_state = state;
}
vec_reset_length (wrk->pending_session_wrk_updates);
@@ -1112,7 +1104,7 @@ vppcom_session_unbind (u32 session_handle)
vcl_evt (VCL_EVT_UNBIND, session);
session->vpp_handle = ~0;
- session->session_state = STATE_DISCONNECT;
+ session->session_state = VCL_STATE_DISCONNECT;
return VPPCOM_OK;
}
@@ -1136,13 +1128,13 @@ vppcom_session_disconnect (u32 session_handle)
VDBG (1, "session %u [0x%llx] state 0x%x (%s)", session->session_index,
vpp_handle, state, vppcom_session_state_str (state));
- if (PREDICT_FALSE (state & STATE_LISTEN))
+ if (PREDICT_FALSE (state == VCL_STATE_LISTEN))
{
VDBG (0, "ERROR: Cannot disconnect a listen socket!");
return VPPCOM_EBADFD;
}
- if (state & STATE_VPP_CLOSING)
+ if (state == VCL_STATE_VPP_CLOSING)
{
vpp_evt_q = vcl_session_vpp_evt_q (wrk, session);
vcl_send_session_disconnected_reply (vpp_evt_q, wrk->api_client_handle,
@@ -1294,7 +1286,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking)
session = vcl_session_alloc (wrk);
session->session_type = proto;
- session->session_state = STATE_CLOSED;
+ session->session_state = VCL_STATE_CLOSED;
session->vpp_handle = ~0;
session->is_dgram = vcl_proto_is_dgram (proto);
@@ -1310,7 +1302,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking)
}
int
-vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session,
+vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * s,
vcl_session_handle_t sh, u8 do_disconnect)
{
vcl_session_state_t state;
@@ -1319,13 +1311,13 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session,
u64 vpp_handle;
u8 is_vep;
- is_vep = session->is_vep;
- next_sh = session->vep.next_sh;
- vep_sh = session->vep.vep_sh;
- state = session->session_state;
- vpp_handle = session->vpp_handle;
+ is_vep = s->is_vep;
+ next_sh = s->vep.next_sh;
+ vep_sh = s->vep.vep_sh;
+ state = s->session_state;
+ vpp_handle = s->vpp_handle;
- VDBG (1, "session %u [0x%llx] closing", session->session_index, vpp_handle);
+ VDBG (1, "session %u [0x%llx] closing", s->session_index, vpp_handle);
if (is_vep)
{
@@ -1337,59 +1329,59 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session,
" failed! rv %d (%s)", vpp_handle, next_sh, vep_sh, rv,
vppcom_retval_str (rv));
- next_sh = session->vep.next_sh;
+ next_sh = s->vep.next_sh;
}
goto cleanup;
}
- if (session->is_vep_session)
+ if (s->is_vep_session)
{
rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, sh, 0);
if (rv < 0)
VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u "
- "failed! rv %d (%s)", session->session_index, vpp_handle,
+ "failed! rv %d (%s)", s->session_index, vpp_handle,
vep_sh, rv, vppcom_retval_str (rv));
}
if (!do_disconnect)
{
VDBG (1, "session %u [0x%llx] disconnect skipped",
- session->session_index, vpp_handle);
+ s->session_index, vpp_handle);
goto cleanup;
}
- if (state & STATE_LISTEN)
+ if (state == VCL_STATE_LISTEN)
{
rv = vppcom_session_unbind (sh);
if (PREDICT_FALSE (rv < 0))
VDBG (0, "session %u [0x%llx]: listener unbind failed! "
- "rv %d (%s)", session->session_index, vpp_handle, rv,
+ "rv %d (%s)", s->session_index, vpp_handle, rv,
vppcom_retval_str (rv));
return rv;
}
- else if ((state & STATE_OPEN)
- || (vcl_session_is_connectable_listener (wrk, session)))
+ else if ((vcl_session_is_ready (s))
+ || (vcl_session_is_connectable_listener (wrk, s)))
{
rv = vppcom_session_disconnect (sh);
if (PREDICT_FALSE (rv < 0))
VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!"
- " rv %d (%s)", session->session_index, vpp_handle,
+ " rv %d (%s)", s->session_index, vpp_handle,
rv, vppcom_retval_str (rv));
}
- else if (state == STATE_DISCONNECT)
+ else if (state == VCL_STATE_DISCONNECT)
{
- svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session);
+ svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, s);
vcl_send_session_reset_reply (mq, wrk->api_client_handle,
- session->vpp_handle, 0);
+ s->vpp_handle, 0);
}
- else if (state == STATE_DETACHED)
+ else if (state == VCL_STATE_DETACHED)
{
/* Should not happen. VPP cleaned up before app confirmed close */
- VDBG (0, "vpp freed session %d before close", session->session_index);
+ VDBG (0, "vpp freed session %d before close", s->session_index);
goto free_session;
}
- session->session_state = STATE_CLOSED;
+ s->session_state = VCL_STATE_CLOSED;
/* Session is removed only after vpp confirms the disconnect */
return rv;
@@ -1397,8 +1389,8 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session,
cleanup:
vcl_session_table_del_vpp_handle (wrk, vpp_handle);
free_session:
- vcl_session_free (wrk, session);
- vcl_evt (VCL_EVT_CLOSE, session, rv);
+ vcl_session_free (wrk, s);
+ vcl_evt (VCL_EVT_CLOSE, s, rv);
return rv;
}
@@ -1476,7 +1468,7 @@ vppcom_session_listen (uint32_t listen_sh, uint32_t q_len)
q_len = vcm->cfg.listen_queue_size;
listen_vpp_handle = listen_session->vpp_handle;
- if (listen_session->session_state & STATE_LISTEN)
+ if (listen_session->session_state == VCL_STATE_LISTEN)
{
VDBG (0, "session %u [0x%llx]: already in listen state!",
listen_sh, listen_vpp_handle);
@@ -1490,7 +1482,7 @@ vppcom_session_listen (uint32_t listen_sh, uint32_t q_len)
*/
vcl_send_session_listen (wrk, listen_session);
rv = vppcom_wait_for_session_state_change (listen_session->session_index,
- STATE_LISTEN,
+ VCL_STATE_LISTEN,
vcm->cfg.session_timeout);
if (PREDICT_FALSE (rv))
@@ -1515,7 +1507,7 @@ validate_args_session_accept_ (vcl_worker_t * wrk, vcl_session_t * ls)
return VPPCOM_EBADFD;
}
- if ((ls->session_state != STATE_LISTEN)
+ if ((ls->session_state != VCL_STATE_LISTEN)
&& (!vcl_session_is_connectable_listener (wrk, ls)))
{
VDBG (0,
@@ -1653,9 +1645,9 @@ handle:
if (accept_flags)
{
if (accept_flags & VCL_ACCEPTED_F_CLOSED)
- client_session->session_state = STATE_VPP_CLOSING;
+ client_session->session_state = VCL_STATE_VPP_CLOSING;
else if (accept_flags & VCL_ACCEPTED_F_RESET)
- client_session->session_state = STATE_DISCONNECT;
+ client_session->session_state = VCL_STATE_DISCONNECT;
}
return vcl_session_handle (client_session);
}
@@ -1680,7 +1672,7 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (session->session_state & CLIENT_STATE_OPEN))
+ if (PREDICT_FALSE (vcl_session_is_ready (session)))
{
VDBG (0, "session handle %u [0x%llx]: session already "
"connected to %s %U port %d proto %s, state 0x%x (%s)",
@@ -1695,12 +1687,12 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
}
/* Attempt to connect a connectionless listener */
- if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
+ if (PREDICT_FALSE (session->session_state == VCL_STATE_LISTEN))
{
if (session->session_type != VPPCOM_PROTO_UDP)
return VPPCOM_EINVAL;
vcl_send_session_unlisten (wrk, session);
- session->session_state = STATE_CLOSED;
+ session->session_state = VCL_STATE_CLOSED;
}
session->transport.is_ip4 = server_ep->is_ip4;
@@ -1726,14 +1718,14 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
/* State set to STATE_UPDATED to ensure the session is not assumed
* to be open and to also allow the app to close it prior to vpp's
* connected reply. */
- session->session_state = STATE_UPDATED;
+ session->session_state = VCL_STATE_UPDATED;
return VPPCOM_EINPROGRESS;
}
/*
* Wait for reply from vpp if blocking
*/
- rv = vppcom_wait_for_session_state_change (session_index, STATE_CONNECT,
+ rv = vppcom_wait_for_session_state_change (session_index, VCL_STATE_CONNECT,
vcm->cfg.session_timeout);
session = vcl_session_get (wrk, session_index);
@@ -1768,7 +1760,7 @@ vppcom_session_stream_connect (uint32_t session_handle,
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (session->session_state & CLIENT_STATE_OPEN))
+ if (PREDICT_FALSE (vcl_session_is_ready (session)))
{
VDBG (0, "session handle %u [0x%llx]: session already "
"connected to session %u [0x%llx] proto %s, state 0x%x (%s)",
@@ -1792,7 +1784,7 @@ vppcom_session_stream_connect (uint32_t session_handle,
* Send connect request and wait for reply from vpp
*/
vcl_send_session_connect (wrk, session);
- rv = vppcom_wait_for_session_state_change (session_index, STATE_CONNECT,
+ rv = vppcom_wait_for_session_state_change (session_index, VCL_STATE_CONNECT,
vcm->cfg.session_timeout);
session->listener_index = parent_session_index;
@@ -2855,7 +2847,7 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
add_event = 1;
events[*num_ev].events |= EPOLLOUT;
session_evt_data = session->vep.ev.data.u64;
- if (session->session_state & STATE_DETACHED)
+ if (session->session_state == VCL_STATE_DETACHED)
events[*num_ev].events |= EPOLLHUP;
break;
case SESSION_CTRL_EVT_DISCONNECTED:
@@ -3696,7 +3688,7 @@ vppcom_session_sendto (uint32_t session_handle, void *buffer,
return VPPCOM_EINVAL;
/* Session not connected/bound in vpp. Create it by 'connecting' it */
- if (PREDICT_FALSE (s->session_state == STATE_CLOSED))
+ if (PREDICT_FALSE (s->session_state == VCL_STATE_CLOSED))
{
vcl_send_session_connect (wrk, s);
}