From: Xufeng Zhang <xufeng.zhang@windriver.com>
To: <steffen.klassert@secunet.com>, <herbert@gondor.apana.org.au>,
<davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH] af_key: return error when meet errors on sendmsg() syscall
Date: Fri, 9 May 2014 13:47:35 +0800 [thread overview]
Message-ID: <1399614455-10551-1-git-send-email-xufeng.zhang@windriver.com> (raw)
Current implementation for pfkey_sendmsg() always return success
no matter whether or not error happens during this syscall,
this is incompatible with the general send()/sendmsg() API:
man send
RETURN VALUE
On success, these calls return the number of characters sent.
On error, -1 is returned, and errno is set appropriately.
One side effect this problem introduces is that we can't determine
when to resend the message when the previous send() fails because
it was interrupted by signals.
We detect such a problem when racoon is sending SADBADD message to
add SAD entry in the kernel, but sometimes kernel is responding with
"Interrupted system call"(-EINTR) error.
Check the send implementation of strongswan, it has below logic:
pfkey_send_socket()
{
...
while (TRUE)
{
len = send(socket, in, in_len, 0);
if (len != in_len)
{
case EINTR:
/* interrupted, try again */
continue;
...
}
}
...
}
So it makes sense to return errors for send() syscall.
Signed-off-by: Xufeng Zhang <xufeng.zhang@windriver.com>
---
net/key/af_key.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/key/af_key.c b/net/key/af_key.c
index f3c8307..9e4bc8c 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -335,7 +335,7 @@ static int pfkey_error(const struct sadb_msg *orig, int err, struct sock *sk)
pfkey_broadcast(skb, GFP_KERNEL, BROADCAST_ONE, sk, sock_net(sk));
- return 0;
+ return -err;
}
static const u8 sadb_ext_min_len[] = {
@@ -3644,8 +3644,8 @@ static int pfkey_sendmsg(struct kiocb *kiocb,
mutex_unlock(&net->xfrm.xfrm_cfg_mutex);
out:
- if (err && hdr && pfkey_error(hdr, err, sk) == 0)
- err = 0;
+ if (err && hdr)
+ err = pfkey_error(hdr, err, sk);
kfree_skb(skb);
return err ? : len;
--
1.7.0.2
next reply other threads:[~2014-05-09 5:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-09 5:47 Xufeng Zhang [this message]
2014-05-12 5:11 ` [RFC][PATCH] af_key: return error when meet errors on sendmsg() syscall David Miller
2014-05-12 6:05 ` Xufeng Zhang
2014-05-12 14:41 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399614455-10551-1-git-send-email-xufeng.zhang@windriver.com \
--to=xufeng.zhang@windriver.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).