diff options
author | Filip Tehlar <ftehlar@cisco.com> | 2022-02-18 08:49:43 +0000 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2022-02-24 19:21:20 +0000 |
commit | 447e51d4e4ed08df7f370b150d851842bcafa957 (patch) | |
tree | 8e29fd14bda4e0e1ec91ffbaa87b79c71ff36fed /src | |
parent | 26cd0242c95025e0d644db3a80dfe8dee83b6d7a (diff) |
session: fix session layer socket read
This fixes an issue caused by session layer reading expected part of
data (cert + key) before the client actually sends it.
Type: fix
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Change-Id: I6ddddb08f9576211b302e814d7c2b040383e5fb7
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/hs_apps/vcl/vcl_test_client.c | 6 | ||||
-rw-r--r-- | src/vnet/session/session_api.c | 29 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/plugins/hs_apps/vcl/vcl_test_client.c b/src/plugins/hs_apps/vcl/vcl_test_client.c index f0c626ee4bd..182de8f9015 100644 --- a/src/plugins/hs_apps/vcl/vcl_test_client.c +++ b/src/plugins/hs_apps/vcl/vcl_test_client.c @@ -1041,7 +1041,11 @@ main (int argc, char **argv) /* Protos like tls/dtls/quic need init */ if (vt->protos[vcm->proto]->init) - vt->protos[vcm->proto]->init (&ctrl->cfg); + { + rv = vt->protos[vcm->proto]->init (&ctrl->cfg); + if (rv) + vtfail ("client init failed", rv); + } if ((rv = vtc_ctrl_session_init (vcm, ctrl))) vtfail ("vppcom_session_create() ctrl session", rv); diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index f6170debba7..615e2ade59c 100644 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -1372,6 +1372,31 @@ done: clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds); } +/* This is a workaround for the case when session layer starts reading + * the socket before the client actualy sends the data + */ +static clib_error_t * +sapi_socket_receive_wait (clib_socket_t *cs, u8 *msg, u32 msg_len) +{ + clib_error_t *err; + int n_tries = 5; + + while (1) + { + err = clib_socket_recvmsg (cs, msg, msg_len, 0, 0); + if (!err) + break; + + if (!n_tries) + return err; + + n_tries--; + usleep (1); + } + + return err; +} + static void sapi_add_del_cert_key_handler (app_namespace_t *app_ns, clib_socket_t *cs, app_sapi_cert_key_add_del_msg_t *mp) @@ -1395,11 +1420,11 @@ sapi_add_del_cert_key_handler (app_namespace_t *app_ns, clib_socket_t *cs, } vec_validate (certkey, mp->certkey_len - 1); - err = clib_socket_recvmsg (cs, certkey, mp->certkey_len, 0, 0); + + err = sapi_socket_receive_wait (cs, certkey, mp->certkey_len); if (err) { clib_error_report (err); - clib_error_free (err); rv = SESSION_E_INVALID; goto send_reply; } |