Commit 35560b7f authored by Jakub Kicinski's avatar Jakub Kicinski

tls: rx: make tls_wait_data() return an recvmsg retcode

tls_wait_data() sets the return code as an output parameter
and always returns ctx->recv_pkt on success.

Return the error code directly and let the caller read the skb
from the context. Use positive return code to indicate ctx->recv_pkt
is ready.

While touching the definition of the function rename it.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 58790314
...@@ -1302,54 +1302,50 @@ int tls_sw_sendpage(struct sock *sk, struct page *page, ...@@ -1302,54 +1302,50 @@ int tls_sw_sendpage(struct sock *sk, struct page *page,
return ret; return ret;
} }
static struct sk_buff *tls_wait_data(struct sock *sk, struct sk_psock *psock, static int
bool nonblock, long timeo, int *err) tls_rx_rec_wait(struct sock *sk, struct sk_psock *psock, bool nonblock,
long timeo)
{ {
struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_context *tls_ctx = tls_get_ctx(sk);
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx); struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
struct sk_buff *skb;
DEFINE_WAIT_FUNC(wait, woken_wake_function); DEFINE_WAIT_FUNC(wait, woken_wake_function);
while (!(skb = ctx->recv_pkt) && sk_psock_queue_empty(psock)) { while (!ctx->recv_pkt) {
if (sk->sk_err) { if (!sk_psock_queue_empty(psock))
*err = sock_error(sk); return 0;
return NULL;
} if (sk->sk_err)
return sock_error(sk);
if (!skb_queue_empty(&sk->sk_receive_queue)) { if (!skb_queue_empty(&sk->sk_receive_queue)) {
__strp_unpause(&ctx->strp); __strp_unpause(&ctx->strp);
if (ctx->recv_pkt) if (ctx->recv_pkt)
return ctx->recv_pkt; break;
} }
if (sk->sk_shutdown & RCV_SHUTDOWN) if (sk->sk_shutdown & RCV_SHUTDOWN)
return NULL; return 0;
if (sock_flag(sk, SOCK_DONE)) if (sock_flag(sk, SOCK_DONE))
return NULL; return 0;
if (nonblock || !timeo) { if (nonblock || !timeo)
*err = -EAGAIN; return -EAGAIN;
return NULL;
}
add_wait_queue(sk_sleep(sk), &wait); add_wait_queue(sk_sleep(sk), &wait);
sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk);
sk_wait_event(sk, &timeo, sk_wait_event(sk, &timeo,
ctx->recv_pkt != skb || ctx->recv_pkt || !sk_psock_queue_empty(psock),
!sk_psock_queue_empty(psock),
&wait); &wait);
sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk);
remove_wait_queue(sk_sleep(sk), &wait); remove_wait_queue(sk_sleep(sk), &wait);
/* Handle signals */ /* Handle signals */
if (signal_pending(current)) { if (signal_pending(current))
*err = sock_intr_errno(timeo); return sock_intr_errno(timeo);
return NULL;
}
} }
return skb; return 1;
} }
static int tls_setup_from_iter(struct iov_iter *from, static int tls_setup_from_iter(struct iov_iter *from,
...@@ -1812,8 +1808,8 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -1812,8 +1808,8 @@ int tls_sw_recvmsg(struct sock *sk,
struct tls_decrypt_arg darg = {}; struct tls_decrypt_arg darg = {};
int to_decrypt, chunk; int to_decrypt, chunk;
skb = tls_wait_data(sk, psock, flags & MSG_DONTWAIT, timeo, &err); err = tls_rx_rec_wait(sk, psock, flags & MSG_DONTWAIT, timeo);
if (!skb) { if (err <= 0) {
if (psock) { if (psock) {
chunk = sk_msg_recvmsg(sk, psock, msg, len, chunk = sk_msg_recvmsg(sk, psock, msg, len,
flags); flags);
...@@ -1823,6 +1819,7 @@ int tls_sw_recvmsg(struct sock *sk, ...@@ -1823,6 +1819,7 @@ int tls_sw_recvmsg(struct sock *sk,
goto recv_end; goto recv_end;
} }
skb = ctx->recv_pkt;
rxm = strp_msg(skb); rxm = strp_msg(skb);
tlm = tls_msg(skb); tlm = tls_msg(skb);
...@@ -1989,11 +1986,13 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, ...@@ -1989,11 +1986,13 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
} else { } else {
struct tls_decrypt_arg darg = {}; struct tls_decrypt_arg darg = {};
skb = tls_wait_data(sk, NULL, flags & SPLICE_F_NONBLOCK, timeo, err = tls_rx_rec_wait(sk, NULL, flags & SPLICE_F_NONBLOCK,
&err); timeo);
if (!skb) if (err <= 0)
goto splice_read_end; goto splice_read_end;
skb = ctx->recv_pkt;
err = decrypt_skb_update(sk, skb, NULL, &darg); err = decrypt_skb_update(sk, skb, NULL, &darg);
if (err < 0) { if (err < 0) {
tls_err_abort(sk, -EBADMSG); tls_err_abort(sk, -EBADMSG);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment