Commit | Line | Data |
---|---|---|
f870fa0b MM |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* Multipath TCP | |
3 | * | |
4 | * Copyright (c) 2017 - 2019, Intel Corporation. | |
5 | */ | |
6 | ||
7 | #ifndef __MPTCP_PROTOCOL_H | |
8 | #define __MPTCP_PROTOCOL_H | |
9 | ||
79c0949e PK |
10 | #include <linux/random.h> |
11 | #include <net/tcp.h> | |
12 | #include <net/inet_connection_sock.h> | |
13 | ||
cc7972ea | 14 | #define MPTCP_SUPPORTED_VERSION 1 |
eda7acdd PK |
15 | |
16 | /* MPTCP option bits */ | |
17 | #define OPTION_MPTCP_MPC_SYN BIT(0) | |
18 | #define OPTION_MPTCP_MPC_SYNACK BIT(1) | |
19 | #define OPTION_MPTCP_MPC_ACK BIT(2) | |
f296234c PK |
20 | #define OPTION_MPTCP_MPJ_SYN BIT(3) |
21 | #define OPTION_MPTCP_MPJ_SYNACK BIT(4) | |
22 | #define OPTION_MPTCP_MPJ_ACK BIT(5) | |
3df523ab PK |
23 | #define OPTION_MPTCP_ADD_ADDR BIT(6) |
24 | #define OPTION_MPTCP_ADD_ADDR6 BIT(7) | |
25 | #define OPTION_MPTCP_RM_ADDR BIT(8) | |
eda7acdd PK |
26 | |
27 | /* MPTCP option subtypes */ | |
28 | #define MPTCPOPT_MP_CAPABLE 0 | |
29 | #define MPTCPOPT_MP_JOIN 1 | |
30 | #define MPTCPOPT_DSS 2 | |
31 | #define MPTCPOPT_ADD_ADDR 3 | |
32 | #define MPTCPOPT_RM_ADDR 4 | |
33 | #define MPTCPOPT_MP_PRIO 5 | |
34 | #define MPTCPOPT_MP_FAIL 6 | |
35 | #define MPTCPOPT_MP_FASTCLOSE 7 | |
36 | ||
37 | /* MPTCP suboption lengths */ | |
cc7972ea | 38 | #define TCPOLEN_MPTCP_MPC_SYN 4 |
eda7acdd PK |
39 | #define TCPOLEN_MPTCP_MPC_SYNACK 12 |
40 | #define TCPOLEN_MPTCP_MPC_ACK 20 | |
cc7972ea | 41 | #define TCPOLEN_MPTCP_MPC_ACK_DATA 22 |
f296234c PK |
42 | #define TCPOLEN_MPTCP_MPJ_SYN 12 |
43 | #define TCPOLEN_MPTCP_MPJ_SYNACK 16 | |
44 | #define TCPOLEN_MPTCP_MPJ_ACK 24 | |
6d0060f6 | 45 | #define TCPOLEN_MPTCP_DSS_BASE 4 |
648ef4b8 | 46 | #define TCPOLEN_MPTCP_DSS_ACK32 4 |
6d0060f6 | 47 | #define TCPOLEN_MPTCP_DSS_ACK64 8 |
648ef4b8 | 48 | #define TCPOLEN_MPTCP_DSS_MAP32 10 |
6d0060f6 MM |
49 | #define TCPOLEN_MPTCP_DSS_MAP64 14 |
50 | #define TCPOLEN_MPTCP_DSS_CHECKSUM 2 | |
3df523ab PK |
51 | #define TCPOLEN_MPTCP_ADD_ADDR 16 |
52 | #define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 | |
53 | #define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 | |
54 | #define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 | |
55 | #define TCPOLEN_MPTCP_ADD_ADDR6 28 | |
56 | #define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 | |
57 | #define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 | |
58 | #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 | |
59 | #define TCPOLEN_MPTCP_PORT_LEN 2 | |
60 | #define TCPOLEN_MPTCP_RM_ADDR_BASE 4 | |
eda7acdd | 61 | |
ec3edaa7 | 62 | /* MPTCP MP_JOIN flags */ |
f296234c PK |
63 | #define MPTCPOPT_BACKUP BIT(0) |
64 | #define MPTCPOPT_HMAC_LEN 20 | |
ec3edaa7 | 65 | #define MPTCPOPT_THMAC_LEN 8 |
f296234c | 66 | |
eda7acdd PK |
67 | /* MPTCP MP_CAPABLE flags */ |
68 | #define MPTCP_VERSION_MASK (0x0F) | |
69 | #define MPTCP_CAP_CHECKSUM_REQD BIT(7) | |
70 | #define MPTCP_CAP_EXTENSIBILITY BIT(6) | |
65492c5a | 71 | #define MPTCP_CAP_HMAC_SHA256 BIT(0) |
eda7acdd PK |
72 | #define MPTCP_CAP_FLAG_MASK (0x3F) |
73 | ||
6d0060f6 MM |
74 | /* MPTCP DSS flags */ |
75 | #define MPTCP_DSS_DATA_FIN BIT(4) | |
76 | #define MPTCP_DSS_DSN64 BIT(3) | |
77 | #define MPTCP_DSS_HAS_MAP BIT(2) | |
78 | #define MPTCP_DSS_ACK64 BIT(1) | |
79 | #define MPTCP_DSS_HAS_ACK BIT(0) | |
648ef4b8 MM |
80 | #define MPTCP_DSS_FLAG_MASK (0x1F) |
81 | ||
3df523ab PK |
82 | /* MPTCP ADD_ADDR flags */ |
83 | #define MPTCP_ADDR_ECHO BIT(0) | |
3df523ab PK |
84 | #define MPTCP_ADDR_IPVERSION_4 4 |
85 | #define MPTCP_ADDR_IPVERSION_6 6 | |
86 | ||
648ef4b8 | 87 | /* MPTCP socket flags */ |
d99bfed5 | 88 | #define MPTCP_DATA_READY 0 |
8edf0864 | 89 | #define MPTCP_NOSPACE 1 |
3b1d6210 | 90 | #define MPTCP_WORK_RTX 2 |
59832e24 | 91 | #define MPTCP_WORK_EOF 3 |
e1ff9e82 | 92 | #define MPTCP_FALLBACK_DONE 4 |
0e4f35d7 | 93 | #define MPTCP_WORK_CLOSE_SUBFLOW 5 |
6d0060f6 | 94 | |
eaa2ffab PA |
95 | static inline bool before64(__u64 seq1, __u64 seq2) |
96 | { | |
97 | return (__s64)(seq1 - seq2) < 0; | |
98 | } | |
99 | ||
100 | #define after64(seq2, seq1) before64(seq1, seq2) | |
101 | ||
cfde141e PA |
102 | struct mptcp_options_received { |
103 | u64 sndr_key; | |
104 | u64 rcvr_key; | |
105 | u64 data_ack; | |
106 | u64 data_seq; | |
107 | u32 subflow_seq; | |
108 | u16 data_len; | |
109 | u16 mp_capable : 1, | |
110 | mp_join : 1, | |
111 | dss : 1, | |
112 | add_addr : 1, | |
113 | rm_addr : 1, | |
114 | family : 4, | |
115 | echo : 1, | |
116 | backup : 1; | |
117 | u32 token; | |
118 | u32 nonce; | |
119 | u64 thmac; | |
120 | u8 hmac[20]; | |
121 | u8 join_id; | |
122 | u8 use_map:1, | |
123 | dsn64:1, | |
124 | data_fin:1, | |
125 | use_ack:1, | |
126 | ack64:1, | |
127 | mpc_map:1, | |
128 | __unused:2; | |
129 | u8 addr_id; | |
130 | u8 rm_id; | |
131 | union { | |
132 | struct in_addr addr; | |
133 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) | |
134 | struct in6_addr addr6; | |
135 | #endif | |
136 | }; | |
137 | u64 ahmac; | |
138 | u16 port; | |
139 | }; | |
140 | ||
3df523ab PK |
141 | static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) |
142 | { | |
143 | return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) | | |
144 | ((nib & 0xF) << 8) | field); | |
145 | } | |
146 | ||
1b1c7a0e PK |
147 | struct mptcp_addr_info { |
148 | sa_family_t family; | |
149 | __be16 port; | |
150 | u8 id; | |
ef0da3b8 PA |
151 | u8 flags; |
152 | int ifindex; | |
1b1c7a0e PK |
153 | union { |
154 | struct in_addr addr; | |
155 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) | |
156 | struct in6_addr addr6; | |
157 | #endif | |
158 | }; | |
159 | }; | |
160 | ||
161 | enum mptcp_pm_status { | |
162 | MPTCP_PM_ADD_ADDR_RECEIVED, | |
84dfe367 | 163 | MPTCP_PM_ADD_ADDR_SEND_ACK, |
d0876b22 | 164 | MPTCP_PM_RM_ADDR_RECEIVED, |
1b1c7a0e PK |
165 | MPTCP_PM_ESTABLISHED, |
166 | MPTCP_PM_SUBFLOW_ESTABLISHED, | |
167 | }; | |
168 | ||
d91d322a GT |
169 | enum mptcp_add_addr_status { |
170 | MPTCP_ADD_ADDR_SIGNAL, | |
171 | MPTCP_ADD_ADDR_ECHO, | |
84dfe367 | 172 | MPTCP_ADD_ADDR_IPV6, |
d91d322a GT |
173 | }; |
174 | ||
1b1c7a0e PK |
175 | struct mptcp_pm_data { |
176 | struct mptcp_addr_info local; | |
177 | struct mptcp_addr_info remote; | |
b6c08380 | 178 | struct list_head anno_list; |
1b1c7a0e PK |
179 | |
180 | spinlock_t lock; /*protects the whole PM data */ | |
181 | ||
d91d322a | 182 | u8 add_addr_signal; |
5cb104ae | 183 | bool rm_addr_signal; |
1b1c7a0e PK |
184 | bool server_side; |
185 | bool work_pending; | |
186 | bool accept_addr; | |
187 | bool accept_subflow; | |
188 | u8 add_addr_signaled; | |
189 | u8 add_addr_accepted; | |
190 | u8 local_addr_used; | |
191 | u8 subflows; | |
192 | u8 add_addr_signal_max; | |
193 | u8 add_addr_accept_max; | |
194 | u8 local_addr_max; | |
195 | u8 subflows_max; | |
196 | u8 status; | |
5cb104ae | 197 | u8 rm_id; |
1b1c7a0e PK |
198 | }; |
199 | ||
18b683bf PA |
200 | struct mptcp_data_frag { |
201 | struct list_head list; | |
202 | u64 data_seq; | |
f0e6a4cf PA |
203 | u16 data_len; |
204 | u16 offset; | |
205 | u16 overhead; | |
206 | u16 already_sent; | |
18b683bf PA |
207 | struct page *page; |
208 | }; | |
209 | ||
f870fa0b MM |
210 | /* MPTCP connection sock */ |
211 | struct mptcp_sock { | |
212 | /* inet_connection_sock must be the first member */ | |
213 | struct inet_connection_sock sk; | |
cec37a6e PK |
214 | u64 local_key; |
215 | u64 remote_key; | |
6d0060f6 | 216 | u64 write_seq; |
eaa2ffab | 217 | u64 snd_nxt; |
6d0060f6 | 218 | u64 ack_seq; |
fa3fe2b1 | 219 | u64 rcv_wnd_sent; |
3721b9b6 | 220 | u64 rcv_data_fin_seq; |
e93da928 | 221 | int wmem_reserved; |
d5f49190 PA |
222 | struct sock *last_snd; |
223 | int snd_burst; | |
ea4ca586 | 224 | int old_wspace; |
cc9d2566 | 225 | atomic64_t snd_una; |
6f8a612a | 226 | atomic64_t wnd_end; |
b51f9b80 | 227 | unsigned long timer_ival; |
79c0949e | 228 | u32 token; |
ea4ca586 | 229 | int rmem_pending; |
648ef4b8 | 230 | unsigned long flags; |
d22f4988 | 231 | bool can_ack; |
b93df08c | 232 | bool fully_established; |
3721b9b6 | 233 | bool rcv_data_fin; |
7279da61 | 234 | bool snd_data_fin_enable; |
37198e93 | 235 | bool use_64bit_ack; /* Set when we received a 64-bit DSN */ |
ec3edaa7 | 236 | spinlock_t join_list_lock; |
ea4ca586 | 237 | struct sock *ack_hint; |
80992017 | 238 | struct work_struct work; |
ab174ad8 PA |
239 | struct sk_buff *ooo_last_skb; |
240 | struct rb_root out_of_order_queue; | |
cec37a6e | 241 | struct list_head conn_list; |
18b683bf | 242 | struct list_head rtx_queue; |
f0e6a4cf | 243 | struct mptcp_data_frag *first_pending; |
ec3edaa7 | 244 | struct list_head join_list; |
6d0060f6 | 245 | struct skb_ext *cached_ext; /* for the next sendmsg */ |
f870fa0b | 246 | struct socket *subflow; /* outgoing connect/listener/!mp_capable */ |
8ab183de | 247 | struct sock *first; |
1b1c7a0e | 248 | struct mptcp_pm_data pm; |
a6b118fe FW |
249 | struct { |
250 | u32 space; /* bytes copied in last measurement window */ | |
251 | u32 copied; /* bytes copied in this measurement window */ | |
252 | u64 time; /* start time of measurement window */ | |
253 | u64 rtt_us; /* last maximum rtt of subflows */ | |
254 | } rcvq_space; | |
f870fa0b MM |
255 | }; |
256 | ||
ad80b0fc PA |
257 | #define mptcp_lock_sock(___sk, cb) do { \ |
258 | struct sock *__sk = (___sk); /* silence macro reuse warning */ \ | |
259 | might_sleep(); \ | |
260 | spin_lock_bh(&__sk->sk_lock.slock); \ | |
261 | if (__sk->sk_lock.owned) \ | |
262 | __lock_sock(__sk); \ | |
263 | cb; \ | |
264 | __sk->sk_lock.owned = 1; \ | |
265 | spin_unlock(&__sk->sk_lock.slock); \ | |
266 | mutex_acquire(&__sk->sk_lock.dep_map, 0, 0, _RET_IP_); \ | |
267 | local_bh_enable(); \ | |
268 | } while (0) | |
269 | ||
cec37a6e PK |
270 | #define mptcp_for_each_subflow(__msk, __subflow) \ |
271 | list_for_each_entry(__subflow, &((__msk)->conn_list), node) | |
272 | ||
f870fa0b MM |
273 | static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) |
274 | { | |
275 | return (struct mptcp_sock *)sk; | |
276 | } | |
277 | ||
ea4ca586 PA |
278 | static inline int __mptcp_space(const struct sock *sk) |
279 | { | |
280 | return tcp_space(sk) + READ_ONCE(mptcp_sk(sk)->rmem_pending); | |
281 | } | |
282 | ||
f0e6a4cf PA |
283 | static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk) |
284 | { | |
285 | const struct mptcp_sock *msk = mptcp_sk(sk); | |
286 | ||
287 | return READ_ONCE(msk->first_pending); | |
288 | } | |
289 | ||
290 | static inline struct mptcp_data_frag *mptcp_send_next(struct sock *sk) | |
291 | { | |
292 | struct mptcp_sock *msk = mptcp_sk(sk); | |
293 | struct mptcp_data_frag *cur; | |
294 | ||
295 | cur = msk->first_pending; | |
296 | return list_is_last(&cur->list, &msk->rtx_queue) ? NULL : | |
297 | list_next_entry(cur, list); | |
298 | } | |
299 | ||
300 | static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk) | |
301 | { | |
302 | struct mptcp_sock *msk = mptcp_sk(sk); | |
303 | ||
304 | if (!msk->first_pending) | |
305 | return NULL; | |
306 | ||
307 | if (WARN_ON_ONCE(list_empty(&msk->rtx_queue))) | |
308 | return NULL; | |
309 | ||
310 | return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); | |
311 | } | |
312 | ||
18b683bf PA |
313 | static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk) |
314 | { | |
315 | struct mptcp_sock *msk = mptcp_sk(sk); | |
316 | ||
eaa2ffab | 317 | if (!before64(msk->snd_nxt, atomic64_read(&msk->snd_una))) |
18b683bf PA |
318 | return NULL; |
319 | ||
320 | return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); | |
321 | } | |
322 | ||
7948f6cc FW |
323 | static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk) |
324 | { | |
325 | struct mptcp_sock *msk = mptcp_sk(sk); | |
326 | ||
a386bc5b | 327 | return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list); |
7948f6cc FW |
328 | } |
329 | ||
cec37a6e PK |
330 | struct mptcp_subflow_request_sock { |
331 | struct tcp_request_sock sk; | |
d22f4988 | 332 | u16 mp_capable : 1, |
cec37a6e | 333 | mp_join : 1, |
fca5c82c | 334 | backup : 1; |
1b1c7a0e | 335 | u8 local_id; |
f296234c | 336 | u8 remote_id; |
cec37a6e | 337 | u64 local_key; |
79c0949e PK |
338 | u64 idsn; |
339 | u32 token; | |
648ef4b8 | 340 | u32 ssn_offset; |
f296234c PK |
341 | u64 thmac; |
342 | u32 local_nonce; | |
343 | u32 remote_nonce; | |
8fd4de12 | 344 | struct mptcp_sock *msk; |
2c5ebd00 | 345 | struct hlist_nulls_node token_node; |
cec37a6e PK |
346 | }; |
347 | ||
348 | static inline struct mptcp_subflow_request_sock * | |
349 | mptcp_subflow_rsk(const struct request_sock *rsk) | |
350 | { | |
351 | return (struct mptcp_subflow_request_sock *)rsk; | |
352 | } | |
353 | ||
6719331c PA |
354 | enum mptcp_data_avail { |
355 | MPTCP_SUBFLOW_NODATA, | |
356 | MPTCP_SUBFLOW_DATA_AVAIL, | |
357 | MPTCP_SUBFLOW_OOO_DATA | |
358 | }; | |
359 | ||
2303f994 PK |
360 | /* MPTCP subflow context */ |
361 | struct mptcp_subflow_context { | |
cec37a6e PK |
362 | struct list_head node;/* conn_list of subflows */ |
363 | u64 local_key; | |
364 | u64 remote_key; | |
79c0949e | 365 | u64 idsn; |
648ef4b8 | 366 | u64 map_seq; |
cc7972ea | 367 | u32 snd_isn; |
79c0949e | 368 | u32 token; |
6d0060f6 | 369 | u32 rel_write_seq; |
648ef4b8 MM |
370 | u32 map_subflow_seq; |
371 | u32 ssn_offset; | |
372 | u32 map_data_len; | |
cec37a6e | 373 | u32 request_mptcp : 1, /* send MP_CAPABLE */ |
ec3edaa7 PK |
374 | request_join : 1, /* send MP_JOIN */ |
375 | request_bkup : 1, | |
cec37a6e | 376 | mp_capable : 1, /* remote is MPTCP capable */ |
f296234c | 377 | mp_join : 1, /* remote is JOINing */ |
0be534f5 | 378 | fully_established : 1, /* path validated */ |
f296234c | 379 | pm_notified : 1, /* PM hook called for established status */ |
648ef4b8 MM |
380 | conn_finished : 1, |
381 | map_valid : 1, | |
d22f4988 | 382 | mpc_map : 1, |
f296234c | 383 | backup : 1, |
d22f4988 | 384 | rx_eof : 1, |
e16163b6 PA |
385 | can_ack : 1, /* only after processing the remote a key */ |
386 | disposable : 1; /* ctx can be free at ulp release time */ | |
6719331c | 387 | enum mptcp_data_avail data_avail; |
f296234c PK |
388 | u32 remote_nonce; |
389 | u64 thmac; | |
390 | u32 local_nonce; | |
ec3edaa7 PK |
391 | u32 remote_token; |
392 | u8 hmac[MPTCPOPT_HMAC_LEN]; | |
f296234c PK |
393 | u8 local_id; |
394 | u8 remote_id; | |
648ef4b8 | 395 | |
2303f994 PK |
396 | struct sock *tcp_sock; /* tcp sk backpointer */ |
397 | struct sock *conn; /* parent mptcp_sock */ | |
cec37a6e | 398 | const struct inet_connection_sock_af_ops *icsk_af_ops; |
648ef4b8 MM |
399 | void (*tcp_data_ready)(struct sock *sk); |
400 | void (*tcp_state_change)(struct sock *sk); | |
401 | void (*tcp_write_space)(struct sock *sk); | |
402 | ||
2303f994 PK |
403 | struct rcu_head rcu; |
404 | }; | |
405 | ||
406 | static inline struct mptcp_subflow_context * | |
407 | mptcp_subflow_ctx(const struct sock *sk) | |
408 | { | |
409 | struct inet_connection_sock *icsk = inet_csk(sk); | |
410 | ||
411 | /* Use RCU on icsk_ulp_data only for sock diag code */ | |
412 | return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; | |
413 | } | |
414 | ||
415 | static inline struct sock * | |
416 | mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) | |
417 | { | |
418 | return subflow->tcp_sock; | |
419 | } | |
420 | ||
648ef4b8 MM |
421 | static inline u64 |
422 | mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow) | |
423 | { | |
424 | return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq - | |
425 | subflow->ssn_offset - | |
426 | subflow->map_subflow_seq; | |
427 | } | |
428 | ||
429 | static inline u64 | |
430 | mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow) | |
431 | { | |
432 | return subflow->map_seq + mptcp_subflow_get_map_offset(subflow); | |
433 | } | |
434 | ||
0397c6d8 PA |
435 | static inline void mptcp_add_pending_subflow(struct mptcp_sock *msk, |
436 | struct mptcp_subflow_context *subflow) | |
437 | { | |
438 | sock_hold(mptcp_subflow_tcp_sock(subflow)); | |
439 | spin_lock_bh(&msk->join_list_lock); | |
440 | list_add_tail(&subflow->node, &msk->join_list); | |
441 | spin_unlock_bh(&msk->join_list_lock); | |
442 | } | |
443 | ||
648ef4b8 | 444 | int mptcp_is_enabled(struct net *net); |
93f323b9 | 445 | unsigned int mptcp_get_add_addr_timeout(struct net *net); |
b93df08c PA |
446 | void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, |
447 | struct mptcp_options_received *mp_opt); | |
648ef4b8 | 448 | bool mptcp_subflow_data_available(struct sock *sk); |
d39dceca | 449 | void __init mptcp_subflow_init(void); |
d0876b22 GT |
450 | void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how); |
451 | void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, | |
e16163b6 | 452 | struct mptcp_subflow_context *subflow); |
d5824847 | 453 | void mptcp_subflow_reset(struct sock *ssk); |
ec3edaa7 PK |
454 | |
455 | /* called with sk socket lock held */ | |
ef0da3b8 | 456 | int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, |
ec3edaa7 | 457 | const struct mptcp_addr_info *remote); |
2303f994 PK |
458 | int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock); |
459 | ||
648ef4b8 MM |
460 | static inline void mptcp_subflow_tcp_fallback(struct sock *sk, |
461 | struct mptcp_subflow_context *ctx) | |
462 | { | |
463 | sk->sk_data_ready = ctx->tcp_data_ready; | |
464 | sk->sk_state_change = ctx->tcp_state_change; | |
465 | sk->sk_write_space = ctx->tcp_write_space; | |
466 | ||
467 | inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops; | |
468 | } | |
469 | ||
d39dceca | 470 | void __init mptcp_proto_init(void); |
784325e9 | 471 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
d39dceca | 472 | int __init mptcp_proto_v6_init(void); |
784325e9 | 473 | #endif |
648ef4b8 | 474 | |
fca5c82c | 475 | struct sock *mptcp_sk_clone(const struct sock *sk, |
cfde141e | 476 | const struct mptcp_options_received *mp_opt, |
fca5c82c | 477 | struct request_sock *req); |
cec37a6e | 478 | void mptcp_get_options(const struct sk_buff *skb, |
cfde141e | 479 | struct mptcp_options_received *mp_opt); |
cec37a6e PK |
480 | |
481 | void mptcp_finish_connect(struct sock *sk); | |
b93df08c PA |
482 | static inline bool mptcp_is_fully_established(struct sock *sk) |
483 | { | |
484 | return inet_sk_state_load(sk) == TCP_ESTABLISHED && | |
485 | READ_ONCE(mptcp_sk(sk)->fully_established); | |
486 | } | |
a6b118fe | 487 | void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk); |
2e52213c | 488 | void mptcp_data_ready(struct sock *sk, struct sock *ssk); |
f296234c | 489 | bool mptcp_finish_join(struct sock *sk); |
ba8f48f7 | 490 | bool mptcp_schedule_work(struct sock *sk); |
b51f9b80 | 491 | void mptcp_data_acked(struct sock *sk); |
59832e24 | 492 | void mptcp_subflow_eof(struct sock *sk); |
1a49b2c2 | 493 | bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit); |
84dfe367 | 494 | void __mptcp_flush_join_list(struct mptcp_sock *msk); |
e16163b6 PA |
495 | static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk) |
496 | { | |
497 | return READ_ONCE(msk->snd_data_fin_enable) && | |
498 | READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt); | |
499 | } | |
500 | ||
5c8c1640 | 501 | void mptcp_destroy_common(struct mptcp_sock *msk); |
cec37a6e | 502 | |
2c5ebd00 PA |
503 | void __init mptcp_token_init(void); |
504 | static inline void mptcp_token_init_request(struct request_sock *req) | |
505 | { | |
506 | mptcp_subflow_rsk(req)->token_node.pprev = NULL; | |
507 | } | |
508 | ||
79c0949e | 509 | int mptcp_token_new_request(struct request_sock *req); |
2c5ebd00 | 510 | void mptcp_token_destroy_request(struct request_sock *req); |
79c0949e | 511 | int mptcp_token_new_connect(struct sock *sk); |
2c5ebd00 PA |
512 | void mptcp_token_accept(struct mptcp_subflow_request_sock *r, |
513 | struct mptcp_sock *msk); | |
c83a47e5 | 514 | bool mptcp_token_exists(u32 token); |
f296234c | 515 | struct mptcp_sock *mptcp_token_get_sock(u32 token); |
96d890da PA |
516 | struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot, |
517 | long *s_num); | |
2c5ebd00 | 518 | void mptcp_token_destroy(struct mptcp_sock *msk); |
79c0949e PK |
519 | |
520 | void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn); | |
79c0949e | 521 | |
3df523ab | 522 | void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac); |
79c0949e | 523 | |
d39dceca | 524 | void __init mptcp_pm_init(void); |
1b1c7a0e PK |
525 | void mptcp_pm_data_init(struct mptcp_sock *msk); |
526 | void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side); | |
527 | void mptcp_pm_fully_established(struct mptcp_sock *msk); | |
528 | bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk); | |
529 | void mptcp_pm_connection_closed(struct mptcp_sock *msk); | |
530 | void mptcp_pm_subflow_established(struct mptcp_sock *msk, | |
531 | struct mptcp_subflow_context *subflow); | |
532 | void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id); | |
533 | void mptcp_pm_add_addr_received(struct mptcp_sock *msk, | |
534 | const struct mptcp_addr_info *addr); | |
84dfe367 | 535 | void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk); |
d0876b22 | 536 | void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id); |
b6c08380 | 537 | void mptcp_pm_free_anno_list(struct mptcp_sock *msk); |
00cfd77b GT |
538 | struct mptcp_pm_add_entry * |
539 | mptcp_pm_del_add_timer(struct mptcp_sock *msk, | |
540 | struct mptcp_addr_info *addr); | |
1b1c7a0e PK |
541 | |
542 | int mptcp_pm_announce_addr(struct mptcp_sock *msk, | |
6a6c05a8 GT |
543 | const struct mptcp_addr_info *addr, |
544 | bool echo); | |
1b1c7a0e | 545 | int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id); |
0ee4261a | 546 | int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id); |
1b1c7a0e | 547 | |
f643b803 | 548 | static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) |
1b1c7a0e | 549 | { |
d91d322a GT |
550 | return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL); |
551 | } | |
552 | ||
553 | static inline bool mptcp_pm_should_add_signal_echo(struct mptcp_sock *msk) | |
554 | { | |
555 | return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_ECHO); | |
1b1c7a0e PK |
556 | } |
557 | ||
84dfe367 GT |
558 | static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk) |
559 | { | |
560 | return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_IPV6); | |
561 | } | |
562 | ||
5cb104ae GT |
563 | static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk) |
564 | { | |
565 | return READ_ONCE(msk->pm.rm_addr_signal); | |
566 | } | |
567 | ||
456afe01 | 568 | static inline unsigned int mptcp_add_addr_len(int family, bool echo) |
1b1c7a0e PK |
569 | { |
570 | if (family == AF_INET) | |
456afe01 MB |
571 | return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE |
572 | : TCPOLEN_MPTCP_ADD_ADDR; | |
573 | return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6; | |
1b1c7a0e PK |
574 | } |
575 | ||
f643b803 | 576 | bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
6a6c05a8 | 577 | struct mptcp_addr_info *saddr, bool *echo); |
5cb104ae GT |
578 | bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
579 | u8 *rm_id); | |
1b1c7a0e PK |
580 | int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
581 | ||
d39dceca | 582 | void __init mptcp_pm_nl_init(void); |
01cacb00 PA |
583 | void mptcp_pm_nl_data_init(struct mptcp_sock *msk); |
584 | void mptcp_pm_nl_fully_established(struct mptcp_sock *msk); | |
585 | void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk); | |
586 | void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk); | |
84dfe367 | 587 | void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk); |
d0876b22 | 588 | void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk); |
0ee4261a | 589 | void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id); |
01cacb00 PA |
590 | int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
591 | ||
6d0060f6 MM |
592 | static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb) |
593 | { | |
594 | return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); | |
595 | } | |
596 | ||
5147dfb5 DC |
597 | void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops); |
598 | ||
d5f49190 | 599 | static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk) |
e1ff9e82 DC |
600 | { |
601 | return test_bit(MPTCP_FALLBACK_DONE, &msk->flags); | |
602 | } | |
603 | ||
d5f49190 | 604 | static inline bool mptcp_check_fallback(const struct sock *sk) |
e1ff9e82 DC |
605 | { |
606 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); | |
607 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); | |
608 | ||
609 | return __mptcp_check_fallback(msk); | |
610 | } | |
611 | ||
612 | static inline void __mptcp_do_fallback(struct mptcp_sock *msk) | |
613 | { | |
614 | if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags)) { | |
615 | pr_debug("TCP fallback already done (msk=%p)", msk); | |
616 | return; | |
617 | } | |
618 | set_bit(MPTCP_FALLBACK_DONE, &msk->flags); | |
619 | } | |
620 | ||
621 | static inline void mptcp_do_fallback(struct sock *sk) | |
622 | { | |
623 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); | |
624 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); | |
625 | ||
626 | __mptcp_do_fallback(msk); | |
627 | } | |
628 | ||
629 | #define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=%p)", __func__, a) | |
630 | ||
8fd73804 DC |
631 | static inline bool subflow_simultaneous_connect(struct sock *sk) |
632 | { | |
633 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); | |
634 | struct sock *parent = subflow->conn; | |
635 | ||
636 | return sk->sk_state == TCP_ESTABLISHED && | |
637 | !mptcp_sk(parent)->pm.server_side && | |
638 | !subflow->conn_finished; | |
639 | } | |
640 | ||
9466a1cc FW |
641 | #ifdef CONFIG_SYN_COOKIES |
642 | void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req, | |
643 | struct sk_buff *skb); | |
644 | bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req, | |
645 | struct sk_buff *skb); | |
646 | void __init mptcp_join_cookie_init(void); | |
647 | #else | |
648 | static inline void | |
649 | subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req, | |
650 | struct sk_buff *skb) {} | |
651 | static inline bool | |
652 | mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req, | |
653 | struct sk_buff *skb) | |
654 | { | |
655 | return false; | |
656 | } | |
657 | ||
658 | static inline void mptcp_join_cookie_init(void) {} | |
659 | #endif | |
660 | ||
f870fa0b | 661 | #endif /* __MPTCP_PROTOCOL_H */ |