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 | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 62 | #define MPTCPOPT_BACKUP BIT(0) |
| 63 | #define MPTCPOPT_HMAC_LEN 20 |
| 64 | |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 65 | /* MPTCP MP_CAPABLE flags */ |
| 66 | #define MPTCP_VERSION_MASK (0x0F) |
| 67 | #define MPTCP_CAP_CHECKSUM_REQD BIT(7) |
| 68 | #define MPTCP_CAP_EXTENSIBILITY BIT(6) |
Paolo Abeni | 65492c5 | 2020-01-21 16:56:30 -0800 | [diff] [blame] | 69 | #define MPTCP_CAP_HMAC_SHA256 BIT(0) |
Peter Krystad | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 70 | #define MPTCP_CAP_FLAG_MASK (0x3F) |
| 71 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 72 | /* MPTCP DSS flags */ |
| 73 | #define MPTCP_DSS_DATA_FIN BIT(4) |
| 74 | #define MPTCP_DSS_DSN64 BIT(3) |
| 75 | #define MPTCP_DSS_HAS_MAP BIT(2) |
| 76 | #define MPTCP_DSS_ACK64 BIT(1) |
| 77 | #define MPTCP_DSS_HAS_ACK BIT(0) |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 78 | #define MPTCP_DSS_FLAG_MASK (0x1F) |
| 79 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 80 | /* MPTCP ADD_ADDR flags */ |
| 81 | #define MPTCP_ADDR_ECHO BIT(0) |
| 82 | #define MPTCP_ADDR_HMAC_LEN 20 |
| 83 | #define MPTCP_ADDR_IPVERSION_4 4 |
| 84 | #define MPTCP_ADDR_IPVERSION_6 6 |
| 85 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 86 | /* MPTCP socket flags */ |
Florian Westphal | d99bfed | 2020-02-17 16:54:38 +0100 | [diff] [blame] | 87 | #define MPTCP_DATA_READY 0 |
| 88 | #define MPTCP_SEND_SPACE 1 |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 89 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 90 | static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) |
| 91 | { |
| 92 | return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) | |
| 93 | ((nib & 0xF) << 8) | field); |
| 94 | } |
| 95 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 96 | #define MPTCP_PM_MAX_ADDR 4 |
| 97 | |
| 98 | struct mptcp_addr_info { |
| 99 | sa_family_t family; |
| 100 | __be16 port; |
| 101 | u8 id; |
| 102 | union { |
| 103 | struct in_addr addr; |
| 104 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 105 | struct in6_addr addr6; |
| 106 | #endif |
| 107 | }; |
| 108 | }; |
| 109 | |
| 110 | enum mptcp_pm_status { |
| 111 | MPTCP_PM_ADD_ADDR_RECEIVED, |
| 112 | MPTCP_PM_ESTABLISHED, |
| 113 | MPTCP_PM_SUBFLOW_ESTABLISHED, |
| 114 | }; |
| 115 | |
| 116 | struct mptcp_pm_data { |
| 117 | struct mptcp_addr_info local; |
| 118 | struct mptcp_addr_info remote; |
| 119 | |
| 120 | spinlock_t lock; /*protects the whole PM data */ |
| 121 | |
| 122 | bool addr_signal; |
| 123 | bool server_side; |
| 124 | bool work_pending; |
| 125 | bool accept_addr; |
| 126 | bool accept_subflow; |
| 127 | u8 add_addr_signaled; |
| 128 | u8 add_addr_accepted; |
| 129 | u8 local_addr_used; |
| 130 | u8 subflows; |
| 131 | u8 add_addr_signal_max; |
| 132 | u8 add_addr_accept_max; |
| 133 | u8 local_addr_max; |
| 134 | u8 subflows_max; |
| 135 | u8 status; |
| 136 | |
| 137 | struct work_struct work; |
| 138 | }; |
| 139 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 140 | /* MPTCP connection sock */ |
| 141 | struct mptcp_sock { |
| 142 | /* inet_connection_sock must be the first member */ |
| 143 | struct inet_connection_sock sk; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 144 | u64 local_key; |
| 145 | u64 remote_key; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 146 | u64 write_seq; |
| 147 | u64 ack_seq; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 148 | u32 token; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 149 | unsigned long flags; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 150 | bool can_ack; |
Paolo Abeni | 8099201 | 2020-02-26 10:14:47 +0100 | [diff] [blame] | 151 | struct work_struct work; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 152 | struct list_head conn_list; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 153 | struct skb_ext *cached_ext; /* for the next sendmsg */ |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 154 | struct socket *subflow; /* outgoing connect/listener/!mp_capable */ |
Paolo Abeni | 8ab183d | 2020-01-21 16:56:33 -0800 | [diff] [blame] | 155 | struct sock *first; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 156 | struct mptcp_pm_data pm; |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 159 | #define mptcp_for_each_subflow(__msk, __subflow) \ |
| 160 | list_for_each_entry(__subflow, &((__msk)->conn_list), node) |
| 161 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 162 | static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) |
| 163 | { |
| 164 | return (struct mptcp_sock *)sk; |
| 165 | } |
| 166 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 167 | struct mptcp_subflow_request_sock { |
| 168 | struct tcp_request_sock sk; |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 169 | u16 mp_capable : 1, |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 170 | mp_join : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 171 | backup : 1, |
| 172 | remote_key_valid : 1; |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 173 | u8 local_id; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 174 | u8 remote_id; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 175 | u64 local_key; |
| 176 | u64 remote_key; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 177 | u64 idsn; |
| 178 | u32 token; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 179 | u32 ssn_offset; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 180 | u64 thmac; |
| 181 | u32 local_nonce; |
| 182 | u32 remote_nonce; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | static inline struct mptcp_subflow_request_sock * |
| 186 | mptcp_subflow_rsk(const struct request_sock *rsk) |
| 187 | { |
| 188 | return (struct mptcp_subflow_request_sock *)rsk; |
| 189 | } |
| 190 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 191 | /* MPTCP subflow context */ |
| 192 | struct mptcp_subflow_context { |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 193 | struct list_head node;/* conn_list of subflows */ |
| 194 | u64 local_key; |
| 195 | u64 remote_key; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 196 | u64 idsn; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 197 | u64 map_seq; |
Christoph Paasch | cc7972e | 2020-01-21 16:56:31 -0800 | [diff] [blame] | 198 | u32 snd_isn; |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 199 | u32 token; |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 200 | u32 rel_write_seq; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 201 | u32 map_subflow_seq; |
| 202 | u32 ssn_offset; |
| 203 | u32 map_data_len; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 204 | u32 request_mptcp : 1, /* send MP_CAPABLE */ |
| 205 | mp_capable : 1, /* remote is MPTCP capable */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 206 | mp_join : 1, /* remote is JOINing */ |
Paolo Abeni | 0be534f | 2020-03-19 11:06:30 +0100 | [diff] [blame] | 207 | fully_established : 1, /* path validated */ |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 208 | pm_notified : 1, /* PM hook called for established status */ |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 209 | conn_finished : 1, |
| 210 | map_valid : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 211 | mpc_map : 1, |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 212 | backup : 1, |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 213 | data_avail : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 214 | rx_eof : 1, |
Mat Martineau | 76c42a2 | 2020-02-28 15:47:40 -0800 | [diff] [blame] | 215 | data_fin_tx_enable : 1, |
Christoph Paasch | d22f498 | 2020-01-21 16:56:32 -0800 | [diff] [blame] | 216 | can_ack : 1; /* only after processing the remote a key */ |
Mat Martineau | 76c42a2 | 2020-02-28 15:47:40 -0800 | [diff] [blame] | 217 | u64 data_fin_tx_seq; |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 218 | u32 remote_nonce; |
| 219 | u64 thmac; |
| 220 | u32 local_nonce; |
| 221 | u8 local_id; |
| 222 | u8 remote_id; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 223 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 224 | struct sock *tcp_sock; /* tcp sk backpointer */ |
| 225 | struct sock *conn; /* parent mptcp_sock */ |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 226 | const struct inet_connection_sock_af_ops *icsk_af_ops; |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 227 | void (*tcp_data_ready)(struct sock *sk); |
| 228 | void (*tcp_state_change)(struct sock *sk); |
| 229 | void (*tcp_write_space)(struct sock *sk); |
| 230 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 231 | struct rcu_head rcu; |
| 232 | }; |
| 233 | |
| 234 | static inline struct mptcp_subflow_context * |
| 235 | mptcp_subflow_ctx(const struct sock *sk) |
| 236 | { |
| 237 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 238 | |
| 239 | /* Use RCU on icsk_ulp_data only for sock diag code */ |
| 240 | return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; |
| 241 | } |
| 242 | |
| 243 | static inline struct sock * |
| 244 | mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) |
| 245 | { |
| 246 | return subflow->tcp_sock; |
| 247 | } |
| 248 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 249 | static inline u64 |
| 250 | mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow) |
| 251 | { |
| 252 | return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq - |
| 253 | subflow->ssn_offset - |
| 254 | subflow->map_subflow_seq; |
| 255 | } |
| 256 | |
| 257 | static inline u64 |
| 258 | mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow) |
| 259 | { |
| 260 | return subflow->map_seq + mptcp_subflow_get_map_offset(subflow); |
| 261 | } |
| 262 | |
| 263 | int mptcp_is_enabled(struct net *net); |
| 264 | bool mptcp_subflow_data_available(struct sock *sk); |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 265 | void mptcp_subflow_init(void); |
| 266 | int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock); |
| 267 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 268 | static inline void mptcp_subflow_tcp_fallback(struct sock *sk, |
| 269 | struct mptcp_subflow_context *ctx) |
| 270 | { |
| 271 | sk->sk_data_ready = ctx->tcp_data_ready; |
| 272 | sk->sk_state_change = ctx->tcp_state_change; |
| 273 | sk->sk_write_space = ctx->tcp_write_space; |
| 274 | |
| 275 | inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops; |
| 276 | } |
| 277 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 278 | extern const struct inet_connection_sock_af_ops ipv4_specific; |
| 279 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 280 | extern const struct inet_connection_sock_af_ops ipv6_specific; |
| 281 | #endif |
| 282 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 283 | void mptcp_proto_init(void); |
Matthieu Baerts | 784325e | 2020-01-21 16:56:28 -0800 | [diff] [blame] | 284 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 285 | int mptcp_proto_v6_init(void); |
| 286 | #endif |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 287 | |
Paolo Abeni | 58b0991 | 2020-03-13 16:52:41 +0100 | [diff] [blame] | 288 | struct sock *mptcp_sk_clone(const struct sock *sk, struct request_sock *req); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 289 | void mptcp_get_options(const struct sk_buff *skb, |
| 290 | struct tcp_options_received *opt_rx); |
| 291 | |
| 292 | void mptcp_finish_connect(struct sock *sk); |
Florian Westphal | 2e52213 | 2020-02-26 10:14:51 +0100 | [diff] [blame] | 293 | void mptcp_data_ready(struct sock *sk, struct sock *ssk); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 294 | bool mptcp_finish_join(struct sock *sk); |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame] | 295 | |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 296 | int mptcp_token_new_request(struct request_sock *req); |
| 297 | void mptcp_token_destroy_request(u32 token); |
| 298 | int mptcp_token_new_connect(struct sock *sk); |
Paolo Abeni | 58b0991 | 2020-03-13 16:52:41 +0100 | [diff] [blame] | 299 | int mptcp_token_new_accept(u32 token, struct sock *conn); |
Peter Krystad | f296234 | 2020-03-27 14:48:39 -0700 | [diff] [blame^] | 300 | struct mptcp_sock *mptcp_token_get_sock(u32 token); |
Peter Krystad | 79c0949 | 2020-01-21 16:56:20 -0800 | [diff] [blame] | 301 | void mptcp_token_destroy(u32 token); |
| 302 | |
| 303 | void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn); |
| 304 | static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn) |
| 305 | { |
| 306 | /* we might consider a faster version that computes the key as a |
| 307 | * hash of some information available in the MPTCP socket. Use |
| 308 | * random data at the moment, as it's probably the safest option |
| 309 | * in case multiple sockets are opened in different namespaces at |
| 310 | * the same time. |
| 311 | */ |
| 312 | get_random_bytes(key, sizeof(u64)); |
| 313 | mptcp_crypto_key_sha(*key, token, idsn); |
| 314 | } |
| 315 | |
Peter Krystad | 3df523a | 2020-03-27 14:48:37 -0700 | [diff] [blame] | 316 | 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] | 317 | |
Peter Krystad | 1b1c7a0 | 2020-03-27 14:48:38 -0700 | [diff] [blame] | 318 | void mptcp_pm_init(void); |
| 319 | void mptcp_pm_data_init(struct mptcp_sock *msk); |
| 320 | void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side); |
| 321 | void mptcp_pm_fully_established(struct mptcp_sock *msk); |
| 322 | bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk); |
| 323 | void mptcp_pm_connection_closed(struct mptcp_sock *msk); |
| 324 | void mptcp_pm_subflow_established(struct mptcp_sock *msk, |
| 325 | struct mptcp_subflow_context *subflow); |
| 326 | void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id); |
| 327 | void mptcp_pm_add_addr_received(struct mptcp_sock *msk, |
| 328 | const struct mptcp_addr_info *addr); |
| 329 | |
| 330 | int mptcp_pm_announce_addr(struct mptcp_sock *msk, |
| 331 | const struct mptcp_addr_info *addr); |
| 332 | int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id); |
| 333 | int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id); |
| 334 | |
| 335 | static inline bool mptcp_pm_should_signal(struct mptcp_sock *msk) |
| 336 | { |
| 337 | return READ_ONCE(msk->pm.addr_signal); |
| 338 | } |
| 339 | |
| 340 | static inline unsigned int mptcp_add_addr_len(int family) |
| 341 | { |
| 342 | if (family == AF_INET) |
| 343 | return TCPOLEN_MPTCP_ADD_ADDR; |
| 344 | return TCPOLEN_MPTCP_ADD_ADDR6; |
| 345 | } |
| 346 | |
| 347 | bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
| 348 | struct mptcp_addr_info *saddr); |
| 349 | int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
| 350 | |
Mat Martineau | 6d0060f | 2020-01-21 16:56:23 -0800 | [diff] [blame] | 351 | static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb) |
| 352 | { |
| 353 | return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); |
| 354 | } |
| 355 | |
Mat Martineau | 648ef4b | 2020-01-21 16:56:24 -0800 | [diff] [blame] | 356 | static inline bool before64(__u64 seq1, __u64 seq2) |
| 357 | { |
| 358 | return (__s64)(seq1 - seq2) < 0; |
| 359 | } |
| 360 | |
| 361 | #define after64(seq2, seq1) before64(seq1, seq2) |
| 362 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 363 | #endif /* __MPTCP_PROTOCOL_H */ |