From: Yonglong Li <liyonglong@chinatelecom.cn>
To: Paolo Abeni <pabeni@redhat.com>, mptcp@lists.linux.dev
Cc: mathew.j.martineau@linux.intel.com, matthieu.baerts@tessares.net,
fw@strlen.de, wujianguo@chinatelecom.cn
Subject: Re: [PATCH v2 1/2] mptcp: add MSG_PEEK support
Date: Fri, 16 Apr 2021 09:30:30 +0800 [thread overview]
Message-ID: <dce8edda-f8d6-c7d3-3325-e645883471b8@chinatelecom.cn> (raw)
In-Reply-To: <cb2f684fa9dc1db6d8ddab1e091249cb08798758.camel@redhat.com>
On 2021/4/15 19:54, Paolo Abeni wrote:
> On Thu, 2021-04-15 at 11:19 +0800, Yonglong Li wrote:
>> This patch adds support for MSG_PEEK flag. Packets are not removed
>> from the receive_queue if MSG_PEEK set in recv() system call.
>>
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>> net/mptcp/protocol.c | 28 ++++++++++++++++------------
>> 1 file changed, 16 insertions(+), 12 deletions(-)
>>
>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
>> index 0437fe4..521e67b 100644
>> --- a/net/mptcp/protocol.c
>> +++ b/net/mptcp/protocol.c
>> @@ -1739,12 +1739,12 @@ static void mptcp_wait_data(struct sock *sk, long *timeo)
>>
>> static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
>> struct msghdr *msg,
>> - size_t len)
>> + size_t len, int flags)
>> {
>> - struct sk_buff *skb;
>> + struct sk_buff *skb, *tmp;
>> int copied = 0;
>>
>> - while ((skb = skb_peek(&msk->receive_queue)) != NULL) {
>> + skb_queue_walk_safe(&msk->receive_queue, skb, tmp) {
>> u32 offset = MPTCP_SKB_CB(skb)->offset;
>> u32 data_len = skb->len - offset;
>> u32 count = min_t(size_t, len - copied, data_len);
>> @@ -1760,15 +1760,18 @@ static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
>> copied += count;
>>
>> if (count < data_len) {
>> - MPTCP_SKB_CB(skb)->offset += count;
>> + if (!(flags & MSG_PEEK))
>> + MPTCP_SKB_CB(skb)->offset += count;
>> break;
>> }
>>
>> - /* we will bulk release the skb memory later */
>> - skb->destructor = NULL;
>> - msk->rmem_released += skb->truesize;
>> - __skb_unlink(skb, &msk->receive_queue);
>> - __kfree_skb(skb);
>> + if (!(flags & MSG_PEEK)) {
>> + /* we will bulk release the skb memory later */
>> + skb->destructor = NULL;
>> + msk->rmem_released += skb->truesize;
>> + __skb_unlink(skb, &msk->receive_queue);
>> + __kfree_skb(skb);
>> + }
>>
>> if (copied >= len)
>> break;
>> @@ -1945,7 +1948,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
>> int target;
>> long timeo;
>>
>> - if (msg->msg_flags & ~(MSG_WAITALL | MSG_DONTWAIT))
>> + if (flags & ~(MSG_PEEK | MSG_WAITALL | MSG_DONTWAIT))
>> return -EOPNOTSUPP;
>
> Ooops... the existing code (prior to your patch) is pure nonsense here.
>
> Is probably better just drop this check entirely.
>
ok, I will drop this check entirely in next patch.
next prev parent reply other threads:[~2021-04-16 1:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-15 3:19 [PATCH v2 1/2] mptcp: add MSG_PEEK support Yonglong Li
2021-04-15 3:19 ` [PATCH v2 2/2] selftests: mptcp: add a test case for MSG_PEEK Yonglong Li
2021-04-15 9:42 ` Paolo Abeni
2021-04-15 10:20 ` Matthieu Baerts
2021-04-16 1:31 ` Yonglong Li
2021-04-15 11:54 ` [PATCH v2 1/2] mptcp: add MSG_PEEK support Paolo Abeni
2021-04-16 1:30 ` Yonglong Li [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-04-15 1:58 Yonglong Li
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=dce8edda-f8d6-c7d3-3325-e645883471b8@chinatelecom.cn \
--to=liyonglong@chinatelecom.cn \
--cc=fw@strlen.de \
--cc=mathew.j.martineau@linux.intel.com \
--cc=matthieu.baerts@tessares.net \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=wujianguo@chinatelecom.cn \
/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).