Skip to content

Commit 04e4cd4

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: cleanup mptcp_subflow_discard_data()
There is no need to use the tcp_read_sock(), we can simply drop the skb. Additionally try to look at the next buffer for in order data. This both simplifies the code and avoid unneeded indirect calls. Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ab174ad commit 04e4cd4

File tree

2 files changed

+14
-45
lines changed

2 files changed

+14
-45
lines changed

net/mptcp/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ int mptcp_is_enabled(struct net *net);
355355
void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
356356
struct mptcp_options_received *mp_opt);
357357
bool mptcp_subflow_data_available(struct sock *sk);
358-
int mptcp_subflow_discard_data(struct sock *sk, unsigned int limit);
359358
void __init mptcp_subflow_init(void);
360359

361360
/* called with sk socket lock held */

net/mptcp/subflow.c

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -805,50 +805,22 @@ static enum mapping_status get_mapping_status(struct sock *ssk,
805805
return MAPPING_OK;
806806
}
807807

808-
static int subflow_read_actor(read_descriptor_t *desc,
809-
struct sk_buff *skb,
810-
unsigned int offset, size_t len)
808+
static void mptcp_subflow_discard_data(struct sock *ssk, struct sk_buff *skb,
809+
unsigned int limit)
811810
{
812-
size_t copy_len = min(desc->count, len);
813-
814-
desc->count -= copy_len;
811+
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
812+
bool fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
813+
u32 incr;
815814

816-
pr_debug("flushed %zu bytes, %zu left", copy_len, desc->count);
817-
return copy_len;
818-
}
815+
incr = limit >= skb->len ? skb->len + fin : limit;
819816

820-
int mptcp_subflow_discard_data(struct sock *ssk, unsigned int limit)
821-
{
822-
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
823-
u32 map_remaining;
824-
size_t delta;
825-
826-
map_remaining = subflow->map_data_len -
827-
mptcp_subflow_get_map_offset(subflow);
828-
delta = min_t(size_t, limit, map_remaining);
829-
830-
/* discard mapped data */
831-
pr_debug("discarding %zu bytes, current map len=%d", delta,
832-
map_remaining);
833-
if (delta) {
834-
read_descriptor_t desc = {
835-
.count = delta,
836-
};
837-
int ret;
838-
839-
ret = tcp_read_sock(ssk, &desc, subflow_read_actor);
840-
if (ret < 0) {
841-
ssk->sk_err = -ret;
842-
return ret;
843-
}
844-
if (ret < delta)
845-
return 0;
846-
if (delta == map_remaining) {
847-
subflow->data_avail = 0;
848-
subflow->map_valid = 0;
849-
}
850-
}
851-
return 0;
817+
pr_debug("discarding=%d len=%d seq=%d", incr, skb->len,
818+
subflow->map_subflow_seq);
819+
tcp_sk(ssk)->copied_seq += incr;
820+
if (!before(tcp_sk(ssk)->copied_seq, TCP_SKB_CB(skb)->end_seq))
821+
sk_eat_skb(ssk, skb);
822+
if (mptcp_subflow_get_map_offset(subflow) >= subflow->map_data_len)
823+
subflow->map_valid = 0;
852824
}
853825

854826
static bool subflow_check_data_avail(struct sock *ssk)
@@ -923,9 +895,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
923895
/* only accept in-sequence mapping. Old values are spurious
924896
* retransmission
925897
*/
926-
if (mptcp_subflow_discard_data(ssk, old_ack - ack_seq))
927-
goto fatal;
928-
return false;
898+
mptcp_subflow_discard_data(ssk, skb, old_ack - ack_seq);
929899
}
930900
return true;
931901

0 commit comments

Comments
 (0)