blob: bd66e74155158a4e73c3a3ad175bb3fbab4a87f9 [file] [log] [blame]
Mat Martineauf870fa02020-01-21 16:56:15 -08001/* 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
Peter Krystadeda7acd2020-01-21 16:56:16 -080010#define MPTCP_SUPPORTED_VERSION 0
11
12/* MPTCP option bits */
13#define OPTION_MPTCP_MPC_SYN BIT(0)
14#define OPTION_MPTCP_MPC_SYNACK BIT(1)
15#define OPTION_MPTCP_MPC_ACK BIT(2)
16
17/* MPTCP option subtypes */
18#define MPTCPOPT_MP_CAPABLE 0
19#define MPTCPOPT_MP_JOIN 1
20#define MPTCPOPT_DSS 2
21#define MPTCPOPT_ADD_ADDR 3
22#define MPTCPOPT_RM_ADDR 4
23#define MPTCPOPT_MP_PRIO 5
24#define MPTCPOPT_MP_FAIL 6
25#define MPTCPOPT_MP_FASTCLOSE 7
26
27/* MPTCP suboption lengths */
28#define TCPOLEN_MPTCP_MPC_SYN 12
29#define TCPOLEN_MPTCP_MPC_SYNACK 12
30#define TCPOLEN_MPTCP_MPC_ACK 20
31
32/* MPTCP MP_CAPABLE flags */
33#define MPTCP_VERSION_MASK (0x0F)
34#define MPTCP_CAP_CHECKSUM_REQD BIT(7)
35#define MPTCP_CAP_EXTENSIBILITY BIT(6)
36#define MPTCP_CAP_HMAC_SHA1 BIT(0)
37#define MPTCP_CAP_FLAG_MASK (0x3F)
38
Mat Martineauf870fa02020-01-21 16:56:15 -080039/* MPTCP connection sock */
40struct mptcp_sock {
41 /* inet_connection_sock must be the first member */
42 struct inet_connection_sock sk;
Peter Krystadcec37a62020-01-21 16:56:18 -080043 u64 local_key;
44 u64 remote_key;
45 struct list_head conn_list;
Mat Martineauf870fa02020-01-21 16:56:15 -080046 struct socket *subflow; /* outgoing connect/listener/!mp_capable */
47};
48
Peter Krystadcec37a62020-01-21 16:56:18 -080049#define mptcp_for_each_subflow(__msk, __subflow) \
50 list_for_each_entry(__subflow, &((__msk)->conn_list), node)
51
Mat Martineauf870fa02020-01-21 16:56:15 -080052static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
53{
54 return (struct mptcp_sock *)sk;
55}
56
Peter Krystadcec37a62020-01-21 16:56:18 -080057struct mptcp_subflow_request_sock {
58 struct tcp_request_sock sk;
59 u8 mp_capable : 1,
60 mp_join : 1,
61 backup : 1;
62 u64 local_key;
63 u64 remote_key;
64};
65
66static inline struct mptcp_subflow_request_sock *
67mptcp_subflow_rsk(const struct request_sock *rsk)
68{
69 return (struct mptcp_subflow_request_sock *)rsk;
70}
71
Peter Krystad2303f992020-01-21 16:56:17 -080072/* MPTCP subflow context */
73struct mptcp_subflow_context {
Peter Krystadcec37a62020-01-21 16:56:18 -080074 struct list_head node;/* conn_list of subflows */
75 u64 local_key;
76 u64 remote_key;
77 u32 request_mptcp : 1, /* send MP_CAPABLE */
78 mp_capable : 1, /* remote is MPTCP capable */
79 fourth_ack : 1, /* send initial DSS */
80 conn_finished : 1;
Peter Krystad2303f992020-01-21 16:56:17 -080081 struct sock *tcp_sock; /* tcp sk backpointer */
82 struct sock *conn; /* parent mptcp_sock */
Peter Krystadcec37a62020-01-21 16:56:18 -080083 const struct inet_connection_sock_af_ops *icsk_af_ops;
Peter Krystad2303f992020-01-21 16:56:17 -080084 struct rcu_head rcu;
85};
86
87static inline struct mptcp_subflow_context *
88mptcp_subflow_ctx(const struct sock *sk)
89{
90 struct inet_connection_sock *icsk = inet_csk(sk);
91
92 /* Use RCU on icsk_ulp_data only for sock diag code */
93 return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;
94}
95
96static inline struct sock *
97mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
98{
99 return subflow->tcp_sock;
100}
101
102void mptcp_subflow_init(void);
103int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
104
Peter Krystadcec37a62020-01-21 16:56:18 -0800105extern const struct inet_connection_sock_af_ops ipv4_specific;
106#if IS_ENABLED(CONFIG_MPTCP_IPV6)
107extern const struct inet_connection_sock_af_ops ipv6_specific;
108#endif
109
110void mptcp_get_options(const struct sk_buff *skb,
111 struct tcp_options_received *opt_rx);
112
113void mptcp_finish_connect(struct sock *sk);
114
Mat Martineauf870fa02020-01-21 16:56:15 -0800115#endif /* __MPTCP_PROTOCOL_H */