Skip to content

Commit ac1321e

Browse files
qsnklassert
authored andcommitted
espintcp: support non-blocking sends
Currently, non-blocking sends from userspace result in EOPNOTSUPP. To support this, we need to tell espintcp_sendskb_locked() and espintcp_sendskmsg_locked() that non-blocking operation was requested from espintcp_sendmsg(). Fixes: e27cca9 ("xfrm: add espintcp (RFC 8229)") Reported-by: Andrew Cagney <[email protected]> Tested-by: Andrew Cagney <[email protected]> Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 17175d1 commit ac1321e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

net/xfrm/espintcp.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int espintcp_sendskmsg_locked(struct sock *sk,
213213
return 0;
214214
}
215215

216-
static int espintcp_push_msgs(struct sock *sk)
216+
static int espintcp_push_msgs(struct sock *sk, int flags)
217217
{
218218
struct espintcp_ctx *ctx = espintcp_getctx(sk);
219219
struct espintcp_msg *emsg = &ctx->partial;
@@ -227,12 +227,12 @@ static int espintcp_push_msgs(struct sock *sk)
227227
ctx->tx_running = 1;
228228

229229
if (emsg->skb)
230-
err = espintcp_sendskb_locked(sk, emsg, 0);
230+
err = espintcp_sendskb_locked(sk, emsg, flags);
231231
else
232-
err = espintcp_sendskmsg_locked(sk, emsg, 0);
232+
err = espintcp_sendskmsg_locked(sk, emsg, flags);
233233
if (err == -EAGAIN) {
234234
ctx->tx_running = 0;
235-
return 0;
235+
return flags & MSG_DONTWAIT ? -EAGAIN : 0;
236236
}
237237
if (!err)
238238
memset(emsg, 0, sizeof(*emsg));
@@ -257,7 +257,7 @@ int espintcp_push_skb(struct sock *sk, struct sk_buff *skb)
257257
offset = skb_transport_offset(skb);
258258
len = skb->len - offset;
259259

260-
espintcp_push_msgs(sk);
260+
espintcp_push_msgs(sk, 0);
261261

262262
if (emsg->len) {
263263
kfree_skb(skb);
@@ -270,7 +270,7 @@ int espintcp_push_skb(struct sock *sk, struct sk_buff *skb)
270270
emsg->len = len;
271271
emsg->skb = skb;
272272

273-
espintcp_push_msgs(sk);
273+
espintcp_push_msgs(sk, 0);
274274

275275
return 0;
276276
}
@@ -287,7 +287,7 @@ static int espintcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
287287
char buf[2] = {0};
288288
int err, end;
289289

290-
if (msg->msg_flags)
290+
if (msg->msg_flags & ~MSG_DONTWAIT)
291291
return -EOPNOTSUPP;
292292

293293
if (size > MAX_ESPINTCP_MSG)
@@ -298,9 +298,10 @@ static int espintcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
298298

299299
lock_sock(sk);
300300

301-
err = espintcp_push_msgs(sk);
301+
err = espintcp_push_msgs(sk, msg->msg_flags & MSG_DONTWAIT);
302302
if (err < 0) {
303-
err = -ENOBUFS;
303+
if (err != -EAGAIN || !(msg->msg_flags & MSG_DONTWAIT))
304+
err = -ENOBUFS;
304305
goto unlock;
305306
}
306307

@@ -337,10 +338,9 @@ static int espintcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
337338

338339
tcp_rate_check_app_limited(sk);
339340

340-
err = espintcp_push_msgs(sk);
341+
err = espintcp_push_msgs(sk, msg->msg_flags & MSG_DONTWAIT);
341342
/* this message could be partially sent, keep it */
342-
if (err < 0)
343-
goto unlock;
343+
344344
release_sock(sk);
345345

346346
return size;
@@ -374,7 +374,7 @@ static void espintcp_tx_work(struct work_struct *work)
374374

375375
lock_sock(sk);
376376
if (!ctx->tx_running)
377-
espintcp_push_msgs(sk);
377+
espintcp_push_msgs(sk, 0);
378378
release_sock(sk);
379379
}
380380

0 commit comments

Comments
 (0)