Skip to content

Commit

Permalink
mptcp: add MSG_PEEK support
Browse files Browse the repository at this point in the history
This patch adds support for MSG_PEEK flag. Packets are not removed
from the receive_queue if MSG_PEEK set in recv() system call.

Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
  • Loading branch information
Yonglong Li authored and matttbe committed Apr 22, 2021
1 parent b2c639b commit 87f9d82
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,10 +1753,10 @@ static int __mptcp_recvmsg_mskq(struct mptcp_sock *msk,
struct msghdr *msg,
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);
Expand All @@ -1774,15 +1774,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;
Expand Down Expand Up @@ -2061,7 +2064,8 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
pr_debug("msk=%p data_ready=%d rx queue empty=%d copied=%d",
msk, test_bit(MPTCP_DATA_READY, &msk->flags),
skb_queue_empty_lockless(&sk->sk_receive_queue), copied);
mptcp_rcv_space_adjust(msk, copied);
if (!(flags & MSG_PEEK))
mptcp_rcv_space_adjust(msk, copied);

release_sock(sk);
return copied;
Expand Down

0 comments on commit 87f9d82

Please sign in to comment.