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