mptcp: generate the data checksum
[linux-block.git] / include / net / mptcp.h
CommitLineData
3ee17bc7
MM
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
85712484 11#include <linux/skbuff.h>
eda7acdd 12#include <linux/tcp.h>
3ee17bc7
MM
13#include <linux/types.h>
14
fc518953
FW
15struct seq_file;
16
3ee17bc7
MM
17/* MPTCP sk_buff extension data */
18struct mptcp_ext {
a0c1d0ea
CP
19 union {
20 u64 data_ack;
21 u32 data_ack32;
22 };
3ee17bc7
MM
23 u64 data_seq;
24 u32 subflow_seq;
25 u16 data_len;
d0cc2987 26 __sum16 csum;
3ee17bc7
MM
27 u8 use_map:1,
28 dsn64:1,
29 data_fin:1,
30 use_ack:1,
31 ack64:1,
cc7972ea 32 mpc_map:1,
5a369ca6 33 frozen:1,
dc87efdb
FW
34 reset_transient:1;
35 u8 reset_reason:4;
3ee17bc7
MM
36};
37
6445e17a
GT
38#define MPTCP_RM_IDS_MAX 8
39
40struct mptcp_rm_list {
41 u8 ids[MPTCP_RM_IDS_MAX];
42 u8 nr;
43};
44
30f60bae
GT
45struct mptcp_addr_info {
46 u8 id;
47 sa_family_t family;
48 __be16 port;
49 union {
50 struct in_addr addr;
51#if IS_ENABLED(CONFIG_MPTCP_IPV6)
52 struct in6_addr addr6;
53#endif
54 };
55};
56
eda7acdd
PK
57struct mptcp_out_options {
58#if IS_ENABLED(CONFIG_MPTCP)
59 u16 suboptions;
60 u64 sndr_key;
61 u64 rcvr_key;
3df523ab 62 u64 ahmac;
30f60bae 63 struct mptcp_addr_info addr;
6445e17a 64 struct mptcp_rm_list rm_list;
f296234c
PK
65 u8 join_id;
66 u8 backup;
dc87efdb
FW
67 u8 reset_reason:4;
68 u8 reset_transient:1;
f296234c
PK
69 u32 nonce;
70 u64 thmac;
ec3edaa7
PK
71 u32 token;
72 u8 hmac[20];
6d0060f6 73 struct mptcp_ext ext_copy;
eda7acdd
PK
74#endif
75};
76
85712484 77#ifdef CONFIG_MPTCP
08b8d080 78extern struct request_sock_ops mptcp_subflow_request_sock_ops;
85712484 79
f870fa0b
MM
80void mptcp_init(void);
81
cec37a6e
PK
82static inline bool sk_is_mptcp(const struct sock *sk)
83{
84 return tcp_sk(sk)->is_mptcp;
85}
86
87static inline bool rsk_is_mptcp(const struct request_sock *req)
88{
89 return tcp_rsk(req)->is_mptcp;
90}
91
90bf4513
PA
92static inline bool rsk_drop_req(const struct request_sock *req)
93{
94 return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
95}
96
071c8ed6 97void mptcp_space(const struct sock *ssk, int *space, int *full_space);
cc7972ea
CP
98bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
99 unsigned int *size, struct mptcp_out_options *opts);
cec37a6e
PK
100bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
101 struct mptcp_out_options *opts);
102bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
103 unsigned int *size, unsigned int remaining,
104 struct mptcp_out_options *opts);
77d0cab9 105void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
cec37a6e 106
fa3fe2b1
FW
107void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
108 struct mptcp_out_options *opts);
eda7acdd 109
85712484
MM
110/* move the skb extension owership, with the assumption that 'to' is
111 * newly allocated
112 */
113static inline void mptcp_skb_ext_move(struct sk_buff *to,
114 struct sk_buff *from)
115{
116 if (!skb_ext_exist(from, SKB_EXT_MPTCP))
117 return;
118
119 if (WARN_ON_ONCE(to->active_extensions))
120 skb_ext_put(to);
121
122 to->active_extensions = from->active_extensions;
123 to->extensions = from->extensions;
124 from->active_extensions = 0;
125}
126
5a369ca6
PA
127static inline void mptcp_skb_ext_copy(struct sk_buff *to,
128 struct sk_buff *from)
129{
130 struct mptcp_ext *from_ext;
131
132 from_ext = skb_ext_find(from, SKB_EXT_MPTCP);
133 if (!from_ext)
134 return;
135
136 from_ext->frozen = 1;
137 skb_ext_copy(to, from);
138}
139
85712484
MM
140static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
141 const struct mptcp_ext *from_ext)
142{
143 /* MPTCP always clears the ext when adding it to the skb, so
144 * holes do not bother us here
145 */
146 return !from_ext ||
147 (to_ext && from_ext &&
148 !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
149}
150
151/* check if skbs can be collapsed.
152 * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
153 * mapping, or if the extension of @to is the same as @from.
154 * Collapsing is not possible if @to lacks an extension, but @from carries one.
155 */
156static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
157 const struct sk_buff *from)
158{
159 return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
160 skb_ext_find(from, SKB_EXT_MPTCP));
161}
162
fc518953 163void mptcp_seq_show(struct seq_file *seq);
c83a47e5
FW
164int mptcp_subflow_init_cookie_req(struct request_sock *req,
165 const struct sock *sk_listener,
166 struct sk_buff *skb);
dc87efdb
FW
167
168__be32 mptcp_get_reset_option(const struct sk_buff *skb);
169
170static inline __be32 mptcp_reset_option(const struct sk_buff *skb)
171{
172 if (skb_ext_exist(skb, SKB_EXT_MPTCP))
173 return mptcp_get_reset_option(skb);
174
175 return htonl(0u);
176}
85712484
MM
177#else
178
f870fa0b
MM
179static inline void mptcp_init(void)
180{
181}
182
cec37a6e
PK
183static inline bool sk_is_mptcp(const struct sock *sk)
184{
185 return false;
186}
187
188static inline bool rsk_is_mptcp(const struct request_sock *req)
189{
190 return false;
191}
192
90bf4513
PA
193static inline bool rsk_drop_req(const struct request_sock *req)
194{
195 return false;
196}
197
cc7972ea
CP
198static inline void mptcp_parse_option(const struct sk_buff *skb,
199 const unsigned char *ptr, int opsize,
eda7acdd
PK
200 struct tcp_options_received *opt_rx)
201{
202}
203
cc7972ea
CP
204static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
205 unsigned int *size,
cec37a6e
PK
206 struct mptcp_out_options *opts)
207{
208 return false;
209}
210
cec37a6e
PK
211static inline bool mptcp_synack_options(const struct request_sock *req,
212 unsigned int *size,
213 struct mptcp_out_options *opts)
214{
215 return false;
216}
217
218static inline bool mptcp_established_options(struct sock *sk,
219 struct sk_buff *skb,
220 unsigned int *size,
221 unsigned int remaining,
222 struct mptcp_out_options *opts)
223{
224 return false;
225}
226
648ef4b8 227static inline void mptcp_incoming_options(struct sock *sk,
77d0cab9 228 struct sk_buff *skb)
648ef4b8
MM
229{
230}
231
85712484
MM
232static inline void mptcp_skb_ext_move(struct sk_buff *to,
233 const struct sk_buff *from)
234{
235}
236
5a369ca6
PA
237static inline void mptcp_skb_ext_copy(struct sk_buff *to,
238 struct sk_buff *from)
239{
240}
241
85712484
MM
242static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
243 const struct sk_buff *from)
244{
245 return true;
246}
247
071c8ed6 248static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
fc518953 249static inline void mptcp_seq_show(struct seq_file *seq) { }
c83a47e5
FW
250
251static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,
252 const struct sock *sk_listener,
253 struct sk_buff *skb)
254{
255 return 0; /* TCP fallback */
256}
dc87efdb
FW
257
258static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); }
85712484 259#endif /* CONFIG_MPTCP */
f870fa0b
MM
260
261#if IS_ENABLED(CONFIG_MPTCP_IPV6)
262int mptcpv6_init(void);
31484d56 263void mptcpv6_handle_mapped(struct sock *sk, bool mapped);
f870fa0b 264#elif IS_ENABLED(CONFIG_IPV6)
31484d56
GU
265static inline int mptcpv6_init(void) { return 0; }
266static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
f870fa0b
MM
267#endif
268
3ee17bc7 269#endif /* __NET_MPTCP_H */