xref: /openbmc/linux/include/net/mptcp.h (revision 85712484110df308215077be6ee21c4e57d7dec2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Multipath TCP
4  *
5  * Copyright (c) 2017 - 2019, Intel Corporation.
6  */
7 
8 #ifndef __NET_MPTCP_H
9 #define __NET_MPTCP_H
10 
11 #include <linux/skbuff.h>
12 #include <linux/types.h>
13 
14 /* MPTCP sk_buff extension data */
15 struct mptcp_ext {
16 	u64		data_ack;
17 	u64		data_seq;
18 	u32		subflow_seq;
19 	u16		data_len;
20 	u8		use_map:1,
21 			dsn64:1,
22 			data_fin:1,
23 			use_ack:1,
24 			ack64:1,
25 			__unused:3;
26 	/* one byte hole */
27 };
28 
29 #ifdef CONFIG_MPTCP
30 
31 /* move the skb extension owership, with the assumption that 'to' is
32  * newly allocated
33  */
34 static inline void mptcp_skb_ext_move(struct sk_buff *to,
35 				      struct sk_buff *from)
36 {
37 	if (!skb_ext_exist(from, SKB_EXT_MPTCP))
38 		return;
39 
40 	if (WARN_ON_ONCE(to->active_extensions))
41 		skb_ext_put(to);
42 
43 	to->active_extensions = from->active_extensions;
44 	to->extensions = from->extensions;
45 	from->active_extensions = 0;
46 }
47 
48 static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
49 				     const struct mptcp_ext *from_ext)
50 {
51 	/* MPTCP always clears the ext when adding it to the skb, so
52 	 * holes do not bother us here
53 	 */
54 	return !from_ext ||
55 	       (to_ext && from_ext &&
56 	        !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
57 }
58 
59 /* check if skbs can be collapsed.
60  * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
61  * mapping, or if the extension of @to is the same as @from.
62  * Collapsing is not possible if @to lacks an extension, but @from carries one.
63  */
64 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
65 					  const struct sk_buff *from)
66 {
67 	return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
68 				 skb_ext_find(from, SKB_EXT_MPTCP));
69 }
70 
71 #else
72 
73 static inline void mptcp_skb_ext_move(struct sk_buff *to,
74 				      const struct sk_buff *from)
75 {
76 }
77 
78 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
79 					  const struct sk_buff *from)
80 {
81 	return true;
82 }
83 
84 #endif /* CONFIG_MPTCP */
85 #endif /* __NET_MPTCP_H */
86