Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 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 | |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 10 | #include <linux/random.h> |
| 11 | #include <net/tcp.h> |
| 12 | #include <net/inet_connection_sock.h> |
| 13 | |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 14 | #define MPTCP_SUPPORTED_VERSION 1 |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 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) |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 20 | #define OPTION_MPTCP_MPJ_SYN BIT(3) |
| 21 | #define OPTION_MPTCP_MPJ_SYNACK BIT(4) |
| 22 | #define OPTION_MPTCP_MPJ_ACK BIT(5) |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 23 | #define OPTION_MPTCP_ADD_ADDR BIT(6) |
| 24 | #define OPTION_MPTCP_ADD_ADDR6 BIT(7) |
| 25 | #define OPTION_MPTCP_RM_ADDR BIT(8) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 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 */ |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 38 | #define TCPOLEN_MPTCP_MPC_SYN 4 |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 39 | #define TCPOLEN_MPTCP_MPC_SYNACK 12 |
| 40 | #define TCPOLEN_MPTCP_MPC_ACK 20 |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 41 | #define TCPOLEN_MPTCP_MPC_ACK_DATA 22 |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 42 | #define TCPOLEN_MPTCP_MPJ_SYN 12 |
| 43 | #define TCPOLEN_MPTCP_MPJ_SYNACK 16 |
| 44 | #define TCPOLEN_MPTCP_MPJ_ACK 24 |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 45 | #define TCPOLEN_MPTCP_DSS_BASE 4 |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 46 | #define TCPOLEN_MPTCP_DSS_ACK32 4 |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 47 | #define TCPOLEN_MPTCP_DSS_ACK64 8 |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 48 | #define TCPOLEN_MPTCP_DSS_MAP32 10 |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 49 | #define TCPOLEN_MPTCP_DSS_MAP64 14 |
| 50 | #define TCPOLEN_MPTCP_DSS_CHECKSUM 2 |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 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 |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 61 | |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 62 | /* MPTCP MP_JOIN flags */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 63 | #define MPTCPOPT_BACKUP BIT(0) |
| 64 | #define MPTCPOPT_HMAC_LEN 20 |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 65 | #define MPTCPOPT_THMAC_LEN 8 |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 66 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 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) |
Paolo Abeni | 65492c5 | 2020-01-21 16:56:30 -0800 | [diff] [blame] | 71 | #define MPTCP_CAP_HMAC_SHA256 BIT(0) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 72 | #define MPTCP_CAP_FLAG_MASK (0x3F) |
| 73 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 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) |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 80 | #define MPTCP_DSS_FLAG_MASK (0x1F) |
| 81 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 82 | /* MPTCP ADD_ADDR flags */ |
| 83 | #define MPTCP_ADDR_ECHO BIT(0) |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 84 | #define MPTCP_ADDR_IPVERSION_4 4 |
| 85 | #define MPTCP_ADDR_IPVERSION_6 6 |
| 86 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 87 | /* MPTCP socket flags */ |
Florian Westphal | d99bfed | 2020-02-17 16:54:38 +0100 | [diff] [blame] | 88 | #define MPTCP_DATA_READY 0 |
| 89 | #define MPTCP_SEND_SPACE 1 |
Paolo Abeni | 3b1d621 | 2020-03-27 14:48:48 -0700 | [diff] [blame] | 90 | #define MPTCP_WORK_RTX 2 |
Florian Westphal | 59832e2 | 2020-04-02 13:44:52 +0200 | [diff] [blame] | 91 | #define MPTCP_WORK_EOF 3 |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 92 | #define MPTCP_FALLBACK_DONE 4 |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 93 | |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 94 | struct mptcp_options_received { |
| 95 | u64 sndr_key; |
| 96 | u64 rcvr_key; |
| 97 | u64 data_ack; |
| 98 | u64 data_seq; |
| 99 | u32 subflow_seq; |
| 100 | u16 data_len; |
| 101 | u16 mp_capable : 1, |
| 102 | mp_join : 1, |
| 103 | dss : 1, |
| 104 | add_addr : 1, |
| 105 | rm_addr : 1, |
| 106 | family : 4, |
| 107 | echo : 1, |
| 108 | backup : 1; |
| 109 | u32 token; |
| 110 | u32 nonce; |
| 111 | u64 thmac; |
| 112 | u8 hmac[20]; |
| 113 | u8 join_id; |
| 114 | u8 use_map:1, |
| 115 | dsn64:1, |
| 116 | data_fin:1, |
| 117 | use_ack:1, |
| 118 | ack64:1, |
| 119 | mpc_map:1, |
| 120 | __unused:2; |
| 121 | u8 addr_id; |
| 122 | u8 rm_id; |
| 123 | union { |
| 124 | struct in_addr addr; |
| 125 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 126 | struct in6_addr addr6; |
| 127 | #endif |
| 128 | }; |
| 129 | u64 ahmac; |
| 130 | u16 port; |
| 131 | }; |
| 132 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 133 | static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) |
| 134 | { |
| 135 | return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) | |
| 136 | ((nib & 0xF) << 8) | field); |
| 137 | } |
| 138 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 139 | struct mptcp_addr_info { |
| 140 | sa_family_t family; |
| 141 | __be16 port; |
| 142 | u8 id; |
| 143 | union { |
| 144 | struct in_addr addr; |
| 145 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 146 | struct in6_addr addr6; |
| 147 | #endif |
| 148 | }; |
| 149 | }; |
| 150 | |
| 151 | enum mptcp_pm_status { |
| 152 | MPTCP_PM_ADD_ADDR_RECEIVED, |
| 153 | MPTCP_PM_ESTABLISHED, |
| 154 | MPTCP_PM_SUBFLOW_ESTABLISHED, |
| 155 | }; |
| 156 | |
| 157 | struct mptcp_pm_data { |
| 158 | struct mptcp_addr_info local; |
| 159 | struct mptcp_addr_info remote; |
| 160 | |
| 161 | spinlock_t lock; /*protects the whole PM data */ |
| 162 | |
| 163 | bool addr_signal; |
| 164 | bool server_side; |
| 165 | bool work_pending; |
| 166 | bool accept_addr; |
| 167 | bool accept_subflow; |
| 168 | u8 add_addr_signaled; |
| 169 | u8 add_addr_accepted; |
| 170 | u8 local_addr_used; |
| 171 | u8 subflows; |
| 172 | u8 add_addr_signal_max; |
| 173 | u8 add_addr_accept_max; |
| 174 | u8 local_addr_max; |
| 175 | u8 subflows_max; |
| 176 | u8 status; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Paolo Abeni | 18b683b | 2020-03-27 14:48:43 -0700 | [diff] [blame] | 179 | struct mptcp_data_frag { |
| 180 | struct list_head list; |
| 181 | u64 data_seq; |
| 182 | int data_len; |
| 183 | int offset; |
| 184 | int overhead; |
| 185 | struct page *page; |
| 186 | }; |
| 187 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 188 | /* MPTCP connection sock */ |
| 189 | struct mptcp_sock { |
| 190 | /* inet_connection_sock must be the first member */ |
| 191 | struct inet_connection_sock sk; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 192 | u64 local_key; |
| 193 | u64 remote_key; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 194 | u64 write_seq; |
| 195 | u64 ack_seq; |
Mat Martineau | 3721b9b | 2020-07-28 15:12:03 -0700 | [diff] [blame] | 196 | u64 rcv_data_fin_seq; |
Paolo Abeni | cc9d256 | 2020-03-27 14:48:42 -0700 | [diff] [blame] | 197 | atomic64_t snd_una; |
Paolo Abeni | b51f9b8 | 2020-03-27 14:48:44 -0700 | [diff] [blame] | 198 | unsigned long timer_ival; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 199 | u32 token; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 200 | unsigned long flags; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 201 | bool can_ack; |
Paolo Abeni | b93df08 | 2020-07-23 13:02:32 +0200 | [diff] [blame] | 202 | bool fully_established; |
Mat Martineau | 3721b9b | 2020-07-28 15:12:03 -0700 | [diff] [blame] | 203 | bool rcv_data_fin; |
Mat Martineau | 7279da6 | 2020-07-28 15:12:02 -0700 | [diff] [blame] | 204 | bool snd_data_fin_enable; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 205 | spinlock_t join_list_lock; |
Paolo Abeni | 8099201 | 2020-02-26 10:14:47 +0100 | [diff] [blame] | 206 | struct work_struct work; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 207 | struct list_head conn_list; |
Paolo Abeni | 18b683b | 2020-03-27 14:48:43 -0700 | [diff] [blame] | 208 | struct list_head rtx_queue; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 209 | struct list_head join_list; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 210 | struct skb_ext *cached_ext; /* for the next sendmsg */ |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 211 | struct socket *subflow; /* outgoing connect/listener/!mp_capable */ |
Paolo Abeni | 8ab183d | 2020-01-21 16:56:33 -0800 | [diff] [blame] | 212 | struct sock *first; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 213 | struct mptcp_pm_data pm; |
Florian Westphal | a6b118f | 2020-06-30 21:24:45 +0200 | [diff] [blame] | 214 | struct { |
| 215 | u32 space; /* bytes copied in last measurement window */ |
| 216 | u32 copied; /* bytes copied in this measurement window */ |
| 217 | u64 time; /* start time of measurement window */ |
| 218 | u64 rtt_us; /* last maximum rtt of subflows */ |
| 219 | } rcvq_space; |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 220 | }; |
| 221 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 222 | #define mptcp_for_each_subflow(__msk, __subflow) \ |
| 223 | list_for_each_entry(__subflow, &((__msk)->conn_list), node) |
| 224 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 225 | static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) |
| 226 | { |
| 227 | return (struct mptcp_sock *)sk; |
| 228 | } |
| 229 | |
Paolo Abeni | 18b683b | 2020-03-27 14:48:43 -0700 | [diff] [blame] | 230 | static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk) |
| 231 | { |
| 232 | struct mptcp_sock *msk = mptcp_sk(sk); |
| 233 | |
| 234 | if (list_empty(&msk->rtx_queue)) |
| 235 | return NULL; |
| 236 | |
| 237 | return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); |
| 238 | } |
| 239 | |
Florian Westphal | 7948f6c | 2020-03-27 14:48:46 -0700 | [diff] [blame] | 240 | static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk) |
| 241 | { |
| 242 | struct mptcp_sock *msk = mptcp_sk(sk); |
| 243 | |
Geliang Tang | a386bc5 | 2020-06-15 16:34:28 +0800 | [diff] [blame] | 244 | return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list); |
Florian Westphal | 7948f6c | 2020-03-27 14:48:46 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 247 | struct mptcp_subflow_request_sock { |
| 248 | struct tcp_request_sock sk; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 249 | u16 mp_capable : 1, |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 250 | mp_join : 1, |
Paolo Abeni | fca5c82 | 2020-04-20 16:25:06 +0200 | [diff] [blame] | 251 | backup : 1; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 252 | u8 local_id; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 253 | u8 remote_id; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 254 | u64 local_key; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 255 | u64 idsn; |
| 256 | u32 token; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 257 | u32 ssn_offset; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 258 | u64 thmac; |
| 259 | u32 local_nonce; |
| 260 | u32 remote_nonce; |
Paolo Abeni | 8fd4de1 | 2020-06-17 12:08:56 +0200 | [diff] [blame] | 261 | struct mptcp_sock *msk; |
Paolo Abeni | 2c5ebd0 | 2020-06-26 19:30:00 +0200 | [diff] [blame] | 262 | struct hlist_nulls_node token_node; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | static inline struct mptcp_subflow_request_sock * |
| 266 | mptcp_subflow_rsk(const struct request_sock *rsk) |
| 267 | { |
| 268 | return (struct mptcp_subflow_request_sock *)rsk; |
| 269 | } |
| 270 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 271 | /* MPTCP subflow context */ |
| 272 | struct mptcp_subflow_context { |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 273 | struct list_head node;/* conn_list of subflows */ |
| 274 | u64 local_key; |
| 275 | u64 remote_key; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 276 | u64 idsn; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 277 | u64 map_seq; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 278 | u32 snd_isn; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 279 | u32 token; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 280 | u32 rel_write_seq; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 281 | u32 map_subflow_seq; |
| 282 | u32 ssn_offset; |
| 283 | u32 map_data_len; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 284 | u32 request_mptcp : 1, /* send MP_CAPABLE */ |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 285 | request_join : 1, /* send MP_JOIN */ |
| 286 | request_bkup : 1, |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 287 | mp_capable : 1, /* remote is MPTCP capable */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 288 | mp_join : 1, /* remote is JOINing */ |
Paolo Abeni | 0be534f | 2020-03-19 11:06:30 +0100 | [diff] [blame] | 289 | fully_established : 1, /* path validated */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 290 | pm_notified : 1, /* PM hook called for established status */ |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 291 | conn_finished : 1, |
| 292 | map_valid : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 293 | mpc_map : 1, |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 294 | backup : 1, |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 295 | data_avail : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 296 | rx_eof : 1, |
Christoph Paasch | a0c1d0e | 2020-05-14 08:53:03 -0700 | [diff] [blame] | 297 | use_64bit_ack : 1, /* Set when we received a 64-bit DSN */ |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 298 | can_ack : 1; /* only after processing the remote a key */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 299 | u32 remote_nonce; |
| 300 | u64 thmac; |
| 301 | u32 local_nonce; |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 302 | u32 remote_token; |
| 303 | u8 hmac[MPTCPOPT_HMAC_LEN]; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 304 | u8 local_id; |
| 305 | u8 remote_id; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 306 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 307 | struct sock *tcp_sock; /* tcp sk backpointer */ |
| 308 | struct sock *conn; /* parent mptcp_sock */ |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 309 | const struct inet_connection_sock_af_ops *icsk_af_ops; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 310 | void (*tcp_data_ready)(struct sock *sk); |
| 311 | void (*tcp_state_change)(struct sock *sk); |
| 312 | void (*tcp_write_space)(struct sock *sk); |
| 313 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 314 | struct rcu_head rcu; |
| 315 | }; |
| 316 | |
| 317 | static inline struct mptcp_subflow_context * |
| 318 | mptcp_subflow_ctx(const struct sock *sk) |
| 319 | { |
| 320 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 321 | |
| 322 | /* Use RCU on icsk_ulp_data only for sock diag code */ |
| 323 | return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; |
| 324 | } |
| 325 | |
| 326 | static inline struct sock * |
| 327 | mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) |
| 328 | { |
| 329 | return subflow->tcp_sock; |
| 330 | } |
| 331 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 332 | static inline u64 |
| 333 | mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow) |
| 334 | { |
| 335 | return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq - |
| 336 | subflow->ssn_offset - |
| 337 | subflow->map_subflow_seq; |
| 338 | } |
| 339 | |
| 340 | static inline u64 |
| 341 | mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow) |
| 342 | { |
| 343 | return subflow->map_seq + mptcp_subflow_get_map_offset(subflow); |
| 344 | } |
| 345 | |
| 346 | int mptcp_is_enabled(struct net *net); |
Paolo Abeni | b93df08 | 2020-07-23 13:02:32 +0200 | [diff] [blame] | 347 | void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, |
| 348 | struct mptcp_options_received *mp_opt); |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 349 | bool mptcp_subflow_data_available(struct sock *sk); |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 350 | void __init mptcp_subflow_init(void); |
Peter Krystad | ec3edaa | 2020-03-27 14:48:40 -0700 | [diff] [blame] | 351 | |
| 352 | /* called with sk socket lock held */ |
| 353 | int __mptcp_subflow_connect(struct sock *sk, int ifindex, |
| 354 | const struct mptcp_addr_info *loc, |
| 355 | const struct mptcp_addr_info *remote); |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 356 | int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock); |
| 357 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 358 | static inline void mptcp_subflow_tcp_fallback(struct sock *sk, |
| 359 | struct mptcp_subflow_context *ctx) |
| 360 | { |
| 361 | sk->sk_data_ready = ctx->tcp_data_ready; |
| 362 | sk->sk_state_change = ctx->tcp_state_change; |
| 363 | sk->sk_write_space = ctx->tcp_write_space; |
| 364 | |
| 365 | inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops; |
| 366 | } |
| 367 | |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 368 | void __init mptcp_proto_init(void); |
Matthieu Baerts | 784325e | 2020-01-21 16:56:28 -0800 | [diff] [blame] | 369 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 370 | int __init mptcp_proto_v6_init(void); |
Matthieu Baerts | 784325e | 2020-01-21 16:56:28 -0800 | [diff] [blame] | 371 | #endif |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 372 | |
Paolo Abeni | fca5c82 | 2020-04-20 16:25:06 +0200 | [diff] [blame] | 373 | struct sock *mptcp_sk_clone(const struct sock *sk, |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 374 | const struct mptcp_options_received *mp_opt, |
Paolo Abeni | fca5c82 | 2020-04-20 16:25:06 +0200 | [diff] [blame] | 375 | struct request_sock *req); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 376 | void mptcp_get_options(const struct sk_buff *skb, |
Paolo Abeni | cfde141 | 2020-04-30 15:01:52 +0200 | [diff] [blame] | 377 | struct mptcp_options_received *mp_opt); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 378 | |
| 379 | void mptcp_finish_connect(struct sock *sk); |
Paolo Abeni | b93df08 | 2020-07-23 13:02:32 +0200 | [diff] [blame] | 380 | static inline bool mptcp_is_fully_established(struct sock *sk) |
| 381 | { |
| 382 | return inet_sk_state_load(sk) == TCP_ESTABLISHED && |
| 383 | READ_ONCE(mptcp_sk(sk)->fully_established); |
| 384 | } |
Florian Westphal | a6b118f | 2020-06-30 21:24:45 +0200 | [diff] [blame] | 385 | void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk); |
Florian Westphal | 2e52213 | 2020-02-26 10:14:51 +0100 | [diff] [blame] | 386 | void mptcp_data_ready(struct sock *sk, struct sock *ssk); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 387 | bool mptcp_finish_join(struct sock *sk); |
Paolo Abeni | b51f9b8 | 2020-03-27 14:48:44 -0700 | [diff] [blame] | 388 | void mptcp_data_acked(struct sock *sk); |
Florian Westphal | 59832e2 | 2020-04-02 13:44:52 +0200 | [diff] [blame] | 389 | void mptcp_subflow_eof(struct sock *sk); |
Mat Martineau | 3721b9b | 2020-07-28 15:12:03 -0700 | [diff] [blame] | 390 | bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 391 | |
Paolo Abeni | 2c5ebd0 | 2020-06-26 19:30:00 +0200 | [diff] [blame] | 392 | void __init mptcp_token_init(void); |
| 393 | static inline void mptcp_token_init_request(struct request_sock *req) |
| 394 | { |
| 395 | mptcp_subflow_rsk(req)->token_node.pprev = NULL; |
| 396 | } |
| 397 | |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 398 | int mptcp_token_new_request(struct request_sock *req); |
Paolo Abeni | 2c5ebd0 | 2020-06-26 19:30:00 +0200 | [diff] [blame] | 399 | void mptcp_token_destroy_request(struct request_sock *req); |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 400 | int mptcp_token_new_connect(struct sock *sk); |
Paolo Abeni | 2c5ebd0 | 2020-06-26 19:30:00 +0200 | [diff] [blame] | 401 | void mptcp_token_accept(struct mptcp_subflow_request_sock *r, |
| 402 | struct mptcp_sock *msk); |
Florian Westphal | c83a47e | 2020-07-30 21:25:54 +0200 | [diff] [blame^] | 403 | bool mptcp_token_exists(u32 token); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame] | 404 | struct mptcp_sock *mptcp_token_get_sock(u32 token); |
Paolo Abeni | 96d890d | 2020-07-09 15:12:40 +0200 | [diff] [blame] | 405 | struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot, |
| 406 | long *s_num); |
Paolo Abeni | 2c5ebd0 | 2020-06-26 19:30:00 +0200 | [diff] [blame] | 407 | void mptcp_token_destroy(struct mptcp_sock *msk); |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 408 | |
| 409 | void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn); |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 410 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 411 | void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac); |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 412 | |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 413 | void __init mptcp_pm_init(void); |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 414 | void mptcp_pm_data_init(struct mptcp_sock *msk); |
| 415 | void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side); |
| 416 | void mptcp_pm_fully_established(struct mptcp_sock *msk); |
| 417 | bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk); |
| 418 | void mptcp_pm_connection_closed(struct mptcp_sock *msk); |
| 419 | void mptcp_pm_subflow_established(struct mptcp_sock *msk, |
| 420 | struct mptcp_subflow_context *subflow); |
| 421 | void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id); |
| 422 | void mptcp_pm_add_addr_received(struct mptcp_sock *msk, |
| 423 | const struct mptcp_addr_info *addr); |
| 424 | |
| 425 | int mptcp_pm_announce_addr(struct mptcp_sock *msk, |
| 426 | const struct mptcp_addr_info *addr); |
| 427 | int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id); |
| 428 | int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id); |
| 429 | |
| 430 | static inline bool mptcp_pm_should_signal(struct mptcp_sock *msk) |
| 431 | { |
| 432 | return READ_ONCE(msk->pm.addr_signal); |
| 433 | } |
| 434 | |
| 435 | static inline unsigned int mptcp_add_addr_len(int family) |
| 436 | { |
| 437 | if (family == AF_INET) |
| 438 | return TCPOLEN_MPTCP_ADD_ADDR; |
| 439 | return TCPOLEN_MPTCP_ADD_ADDR6; |
| 440 | } |
| 441 | |
| 442 | bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
| 443 | struct mptcp_addr_info *saddr); |
| 444 | int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
| 445 | |
Paolo Abeni | d39dcec | 2020-06-26 19:29:59 +0200 | [diff] [blame] | 446 | void __init mptcp_pm_nl_init(void); |
Paolo Abeni | 01cacb0 | 2020-03-27 14:48:51 -0700 | [diff] [blame] | 447 | void mptcp_pm_nl_data_init(struct mptcp_sock *msk); |
| 448 | void mptcp_pm_nl_fully_established(struct mptcp_sock *msk); |
| 449 | void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk); |
| 450 | void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk); |
| 451 | int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
| 452 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 453 | static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb) |
| 454 | { |
| 455 | return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); |
| 456 | } |
| 457 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 458 | static inline bool before64(__u64 seq1, __u64 seq2) |
| 459 | { |
| 460 | return (__s64)(seq1 - seq2) < 0; |
| 461 | } |
| 462 | |
| 463 | #define after64(seq2, seq1) before64(seq1, seq2) |
| 464 | |
Davide Caratti | 5147dfb | 2020-03-27 14:48:49 -0700 | [diff] [blame] | 465 | void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops); |
| 466 | |
Davide Caratti | e1ff9e8 | 2020-06-29 22:26:20 +0200 | [diff] [blame] | 467 | static inline bool __mptcp_check_fallback(struct mptcp_sock *msk) |
| 468 | { |
| 469 | return test_bit(MPTCP_FALLBACK_DONE, &msk->flags); |
| 470 | } |
| 471 | |
| 472 | static inline bool mptcp_check_fallback(struct sock *sk) |
| 473 | { |
| 474 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 475 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
| 476 | |
| 477 | return __mptcp_check_fallback(msk); |
| 478 | } |
| 479 | |
| 480 | static inline void __mptcp_do_fallback(struct mptcp_sock *msk) |
| 481 | { |
| 482 | if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags)) { |
| 483 | pr_debug("TCP fallback already done (msk=%p)", msk); |
| 484 | return; |
| 485 | } |
| 486 | set_bit(MPTCP_FALLBACK_DONE, &msk->flags); |
| 487 | } |
| 488 | |
| 489 | static inline void mptcp_do_fallback(struct sock *sk) |
| 490 | { |
| 491 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 492 | struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
| 493 | |
| 494 | __mptcp_do_fallback(msk); |
| 495 | } |
| 496 | |
| 497 | #define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=%p)", __func__, a) |
| 498 | |
Davide Caratti | 8fd7380 | 2020-06-29 22:26:21 +0200 | [diff] [blame] | 499 | static inline bool subflow_simultaneous_connect(struct sock *sk) |
| 500 | { |
| 501 | struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 502 | struct sock *parent = subflow->conn; |
| 503 | |
| 504 | return sk->sk_state == TCP_ESTABLISHED && |
| 505 | !mptcp_sk(parent)->pm.server_side && |
| 506 | !subflow->conn_finished; |
| 507 | } |
| 508 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 509 | #endif /* __MPTCP_PROTOCOL_H */ |