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/vnet/session/session_api.c | |
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/vnet/session/session_api.c')
-rw-r--r-- | src/vnet/session/session_api.c | 29 |
1 files changed, 27 insertions, 2 deletions
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; } |