| 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 |
#include <uapi/linux/mptcp.h> |
| 14 |
#include <net/genetlink.h> |
| 15 |
#include <net/rstreason.h> |
| 16 |
|
| 17 |
#define MPTCP_SUPPORTED_VERSION 1 |
| 18 |
|
| 19 |
/* MPTCP option bits */ |
| 20 |
#define OPTION_MPTCP_MPC_SYN BIT(0) |
| 21 |
#define OPTION_MPTCP_MPC_SYNACK BIT(1) |
| 22 |
#define OPTION_MPTCP_MPC_ACK BIT(2) |
| 23 |
#define OPTION_MPTCP_MPJ_SYN BIT(3) |
| 24 |
#define OPTION_MPTCP_MPJ_SYNACK BIT(4) |
| 25 |
#define OPTION_MPTCP_MPJ_ACK BIT(5) |
| 26 |
#define OPTION_MPTCP_ADD_ADDR BIT(6) |
| 27 |
#define OPTION_MPTCP_RM_ADDR BIT(7) |
| 28 |
#define OPTION_MPTCP_FASTCLOSE BIT(8) |
| 29 |
#define OPTION_MPTCP_PRIO BIT(9) |
| 30 |
#define OPTION_MPTCP_RST BIT(10) |
| 31 |
#define OPTION_MPTCP_DSS BIT(11) |
| 32 |
#define OPTION_MPTCP_FAIL BIT(12) |
| 33 |
|
| 34 |
#define OPTION_MPTCP_CSUMREQD BIT(13) |
| 35 |
|
| 36 |
#define OPTIONS_MPTCP_MPC (OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK | \ |
| 37 |
OPTION_MPTCP_MPC_ACK) |
| 38 |
#define OPTIONS_MPTCP_MPJ (OPTION_MPTCP_MPJ_SYN | OPTION_MPTCP_MPJ_SYNACK | \ |
| 39 |
OPTION_MPTCP_MPJ_ACK) |
| 40 |
|
| 41 |
/* MPTCP option subtypes */ |
| 42 |
#define MPTCPOPT_MP_CAPABLE 0 |
| 43 |
#define MPTCPOPT_MP_JOIN 1 |
| 44 |
#define MPTCPOPT_DSS 2 |
| 45 |
#define MPTCPOPT_ADD_ADDR 3 |
| 46 |
#define MPTCPOPT_RM_ADDR 4 |
| 47 |
#define MPTCPOPT_MP_PRIO 5 |
| 48 |
#define MPTCPOPT_MP_FAIL 6 |
| 49 |
#define MPTCPOPT_MP_FASTCLOSE 7 |
| 50 |
#define MPTCPOPT_RST 8 |
| 51 |
|
| 52 |
/* MPTCP suboption lengths */ |
| 53 |
#define TCPOLEN_MPTCP_MPC_SYN 4 |
| 54 |
#define TCPOLEN_MPTCP_MPC_SYNACK 12 |
| 55 |
#define TCPOLEN_MPTCP_MPC_ACK 20 |
| 56 |
#define TCPOLEN_MPTCP_MPC_ACK_DATA 22 |
| 57 |
#define TCPOLEN_MPTCP_MPJ_SYN 12 |
| 58 |
#define TCPOLEN_MPTCP_MPJ_SYNACK 16 |
| 59 |
#define TCPOLEN_MPTCP_MPJ_ACK 24 |
| 60 |
#define TCPOLEN_MPTCP_DSS_BASE 4 |
| 61 |
#define TCPOLEN_MPTCP_DSS_ACK32 4 |
| 62 |
#define TCPOLEN_MPTCP_DSS_ACK64 8 |
| 63 |
#define TCPOLEN_MPTCP_DSS_MAP32 10 |
| 64 |
#define TCPOLEN_MPTCP_DSS_MAP64 14 |
| 65 |
#define TCPOLEN_MPTCP_DSS_CHECKSUM 2 |
| 66 |
#define TCPOLEN_MPTCP_ADD_ADDR 16 |
| 67 |
#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18 |
| 68 |
#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8 |
| 69 |
#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10 |
| 70 |
#define TCPOLEN_MPTCP_ADD_ADDR6 28 |
| 71 |
#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30 |
| 72 |
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20 |
| 73 |
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22 |
| 74 |
#define TCPOLEN_MPTCP_PORT_LEN 2 |
| 75 |
#define TCPOLEN_MPTCP_PORT_ALIGN 2 |
| 76 |
#define TCPOLEN_MPTCP_RM_ADDR_BASE 3 |
| 77 |
#define TCPOLEN_MPTCP_PRIO 3 |
| 78 |
#define TCPOLEN_MPTCP_PRIO_ALIGN 4 |
| 79 |
#define TCPOLEN_MPTCP_FASTCLOSE 12 |
| 80 |
#define TCPOLEN_MPTCP_RST 4 |
| 81 |
#define TCPOLEN_MPTCP_FAIL 12 |
| 82 |
|
| 83 |
#define TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM (TCPOLEN_MPTCP_DSS_CHECKSUM + TCPOLEN_MPTCP_MPC_ACK_DATA) |
| 84 |
|
| 85 |
/* MPTCP MP_JOIN flags */ |
| 86 |
#define MPTCPOPT_BACKUP BIT(0) |
| 87 |
#define MPTCPOPT_THMAC_LEN 8 |
| 88 |
|
| 89 |
/* MPTCP MP_CAPABLE flags */ |
| 90 |
#define MPTCP_VERSION_MASK (0x0F) |
| 91 |
#define MPTCP_CAP_CHECKSUM_REQD BIT(7) |
| 92 |
#define MPTCP_CAP_EXTENSIBILITY BIT(6) |
| 93 |
#define MPTCP_CAP_DENY_JOIN_ID0 BIT(5) |
| 94 |
#define MPTCP_CAP_HMAC_SHA256 BIT(0) |
| 95 |
#define MPTCP_CAP_FLAG_MASK (0x1F) |
| 96 |
|
| 97 |
/* MPTCP DSS flags */ |
| 98 |
#define MPTCP_DSS_DATA_FIN BIT(4) |
| 99 |
#define MPTCP_DSS_DSN64 BIT(3) |
| 100 |
#define MPTCP_DSS_HAS_MAP BIT(2) |
| 101 |
#define MPTCP_DSS_ACK64 BIT(1) |
| 102 |
#define MPTCP_DSS_HAS_ACK BIT(0) |
| 103 |
#define MPTCP_DSS_FLAG_MASK (0x1F) |
| 104 |
|
| 105 |
/* MPTCP ADD_ADDR flags */ |
| 106 |
#define MPTCP_ADDR_ECHO BIT(0) |
| 107 |
|
| 108 |
/* MPTCP MP_PRIO flags */ |
| 109 |
#define MPTCP_PRIO_BKUP BIT(0) |
| 110 |
|
| 111 |
/* MPTCP TCPRST flags */ |
| 112 |
#define MPTCP_RST_TRANSIENT BIT(0) |
| 113 |
|
| 114 |
/* MPTCP socket atomic flags */ |
| 115 |
#define MPTCP_WORK_RTX 1 |
| 116 |
#define MPTCP_FALLBACK_DONE 2 |
| 117 |
#define MPTCP_WORK_CLOSE_SUBFLOW 3 |
| 118 |
|
| 119 |
/* MPTCP socket release cb flags */ |
| 120 |
#define MPTCP_PUSH_PENDING 1 |
| 121 |
#define MPTCP_CLEAN_UNA 2 |
| 122 |
#define MPTCP_ERROR_REPORT 3 |
| 123 |
#define MPTCP_RETRANSMIT 4 |
| 124 |
#define MPTCP_FLUSH_JOIN_LIST 5 |
| 125 |
#define MPTCP_SYNC_STATE 6 |
| 126 |
#define MPTCP_SYNC_SNDBUF 7 |
| 127 |
|
| 128 |
struct mptcp_skb_cb { |
| 129 |
u64 map_seq; |
| 130 |
u64 end_seq; |
| 131 |
u32 offset; |
| 132 |
u8 has_rxtstamp; |
| 133 |
u8 cant_coalesce; |
| 134 |
}; |
| 135 |
|
| 136 |
#define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0])) |
| 137 |
|
| 138 |
static inline bool before64(__u64 seq1, __u64 seq2) |
| 139 |
{ |
| 140 |
return (__s64)(seq1 - seq2) < 0; |
| 141 |
} |
| 142 |
|
| 143 |
#define after64(seq2, seq1) before64(seq1, seq2) |
| 144 |
|
| 145 |
struct mptcp_options_received { |
| 146 |
u64 sndr_key; |
| 147 |
u64 rcvr_key; |
| 148 |
u64 data_ack; |
| 149 |
u64 data_seq; |
| 150 |
u32 subflow_seq; |
| 151 |
u16 data_len; |
| 152 |
__sum16 csum; |
| 153 |
struct_group(status, |
| 154 |
u16 suboptions; |
| 155 |
u16 use_map:1, |
| 156 |
dsn64:1, |
| 157 |
data_fin:1, |
| 158 |
use_ack:1, |
| 159 |
ack64:1, |
| 160 |
mpc_map:1, |
| 161 |
reset_reason:4, |
| 162 |
reset_transient:1, |
| 163 |
echo:1, |
| 164 |
backup:1, |
| 165 |
deny_join_id0:1, |
| 166 |
__unused:2; |
| 167 |
); |
| 168 |
u8 join_id; |
| 169 |
u32 token; |
| 170 |
u32 nonce; |
| 171 |
u64 thmac; |
| 172 |
u8 hmac[MPTCPOPT_HMAC_LEN]; |
| 173 |
struct mptcp_addr_info addr; |
| 174 |
struct mptcp_rm_list rm_list; |
| 175 |
u64 ahmac; |
| 176 |
u64 fail_seq; |
| 177 |
}; |
| 178 |
|
| 179 |
static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field) |
| 180 |
{ |
| 181 |
return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) | |
| 182 |
((nib & 0xF) << 8) | field); |
| 183 |
} |
| 184 |
|
| 185 |
enum mptcp_pm_status { |
| 186 |
MPTCP_PM_ADD_ADDR_RECEIVED, |
| 187 |
MPTCP_PM_ADD_ADDR_SEND_ACK, |
| 188 |
MPTCP_PM_RM_ADDR_RECEIVED, |
| 189 |
MPTCP_PM_ESTABLISHED, |
| 190 |
MPTCP_PM_SUBFLOW_ESTABLISHED, |
| 191 |
MPTCP_PM_ALREADY_ESTABLISHED, /* persistent status, set after ESTABLISHED event */ |
| 192 |
MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is |
| 193 |
* accounted int id_avail_bitmap |
| 194 |
*/ |
| 195 |
}; |
| 196 |
|
| 197 |
enum mptcp_pm_type { |
| 198 |
MPTCP_PM_TYPE_KERNEL = 0, |
| 199 |
MPTCP_PM_TYPE_USERSPACE, |
| 200 |
|
| 201 |
__MPTCP_PM_TYPE_NR, |
| 202 |
__MPTCP_PM_TYPE_MAX = __MPTCP_PM_TYPE_NR - 1, |
| 203 |
}; |
| 204 |
|
| 205 |
/* Status bits below MPTCP_PM_ALREADY_ESTABLISHED need pm worker actions */ |
| 206 |
#define MPTCP_PM_WORK_MASK ((1 << MPTCP_PM_ALREADY_ESTABLISHED) - 1) |
| 207 |
|
| 208 |
enum mptcp_addr_signal_status { |
| 209 |
MPTCP_ADD_ADDR_SIGNAL, |
| 210 |
MPTCP_ADD_ADDR_ECHO, |
| 211 |
MPTCP_RM_ADDR_SIGNAL, |
| 212 |
}; |
| 213 |
|
| 214 |
/* max value of mptcp_addr_info.id */ |
| 215 |
#define MPTCP_PM_MAX_ADDR_ID U8_MAX |
| 216 |
|
| 217 |
struct mptcp_pm_data { |
| 218 |
struct mptcp_addr_info local; |
| 219 |
struct mptcp_addr_info remote; |
| 220 |
struct list_head anno_list; |
| 221 |
struct list_head userspace_pm_local_addr_list; |
| 222 |
|
| 223 |
spinlock_t lock; /*protects the whole PM data */ |
| 224 |
|
| 225 |
struct_group(reset, |
| 226 |
|
| 227 |
u8 addr_signal; |
| 228 |
bool server_side; |
| 229 |
bool work_pending; |
| 230 |
bool accept_addr; |
| 231 |
bool accept_subflow; |
| 232 |
bool remote_deny_join_id0; |
| 233 |
u8 add_addr_signaled; |
| 234 |
u8 add_addr_accepted; |
| 235 |
u8 local_addr_used; |
| 236 |
u8 pm_type; |
| 237 |
u8 extra_subflows; |
| 238 |
u8 status; |
| 239 |
|
| 240 |
); |
| 241 |
|
| 242 |
DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); |
| 243 |
struct mptcp_rm_list rm_list_tx; |
| 244 |
struct mptcp_rm_list rm_list_rx; |
| 245 |
}; |
| 246 |
|
| 247 |
struct mptcp_pm_local { |
| 248 |
struct mptcp_addr_info addr; |
| 249 |
u32 flags; |
| 250 |
int ifindex; |
| 251 |
}; |
| 252 |
|
| 253 |
struct mptcp_pm_addr_entry { |
| 254 |
struct list_head list; |
| 255 |
struct mptcp_addr_info addr; |
| 256 |
u32 flags; |
| 257 |
int ifindex; |
| 258 |
struct socket *lsk; |
| 259 |
}; |
| 260 |
|
| 261 |
struct mptcp_data_frag { |
| 262 |
struct list_head list; |
| 263 |
u64 data_seq; |
| 264 |
u16 data_len; |
| 265 |
u16 offset; |
| 266 |
u16 overhead; |
| 267 |
u16 already_sent; |
| 268 |
struct page *page; |
| 269 |
}; |
| 270 |
|
| 271 |
/* MPTCP connection sock */ |
| 272 |
struct mptcp_sock { |
| 273 |
/* inet_connection_sock must be the first member */ |
| 274 |
struct inet_connection_sock sk; |
| 275 |
u64 local_key; /* protected by the first subflow socket lock |
| 276 |
* lockless access read |
| 277 |
*/ |
| 278 |
u64 remote_key; /* same as above */ |
| 279 |
u64 write_seq; |
| 280 |
u64 bytes_sent; |
| 281 |
u64 snd_nxt; |
| 282 |
u64 bytes_received; |
| 283 |
u64 ack_seq; |
| 284 |
atomic64_t rcv_wnd_sent; |
| 285 |
u64 rcv_data_fin_seq; |
| 286 |
u64 bytes_retrans; |
| 287 |
u64 bytes_consumed; |
| 288 |
int snd_burst; |
| 289 |
int old_wspace; |
| 290 |
u64 recovery_snd_nxt; /* in recovery mode accept up to this seq; |
| 291 |
* recovery related fields are under data_lock |
| 292 |
* protection |
| 293 |
*/ |
| 294 |
u64 bytes_acked; |
| 295 |
u64 snd_una; |
| 296 |
u64 wnd_end; |
| 297 |
u32 last_data_sent; |
| 298 |
u32 last_data_recv; |
| 299 |
u32 last_ack_recv; |
| 300 |
unsigned long timer_ival; |
| 301 |
u32 token; |
| 302 |
unsigned long flags; |
| 303 |
unsigned long cb_flags; |
| 304 |
bool recovery; /* closing subflow write queue reinjected */ |
| 305 |
bool can_ack; |
| 306 |
bool fully_established; |
| 307 |
bool rcv_data_fin; |
| 308 |
bool snd_data_fin_enable; |
| 309 |
bool rcv_fastclose; |
| 310 |
bool use_64bit_ack; /* Set when we received a 64-bit DSN */ |
| 311 |
bool csum_enabled; |
| 312 |
bool allow_infinite_fallback; |
| 313 |
u8 pending_state; /* A subflow asked to set this sk_state, |
| 314 |
* protected by the msk data lock |
| 315 |
*/ |
| 316 |
u8 mpc_endpoint_id; |
| 317 |
u8 recvmsg_inq:1, |
| 318 |
cork:1, |
| 319 |
nodelay:1, |
| 320 |
fastopening:1, |
| 321 |
in_accept_queue:1, |
| 322 |
free_first:1, |
| 323 |
rcvspace_init:1, |
| 324 |
fastclosing:1; |
| 325 |
u32 notsent_lowat; |
| 326 |
int keepalive_cnt; |
| 327 |
int keepalive_idle; |
| 328 |
int keepalive_intvl; |
| 329 |
int maxseg; |
| 330 |
struct work_struct work; |
| 331 |
struct sk_buff *ooo_last_skb; |
| 332 |
struct rb_root out_of_order_queue; |
| 333 |
struct list_head conn_list; |
| 334 |
struct list_head rtx_queue; |
| 335 |
struct mptcp_data_frag *first_pending; |
| 336 |
struct list_head join_list; |
| 337 |
struct sock *first; /* The mptcp ops can safely dereference, using suitable |
| 338 |
* ONCE annotation, the subflow outside the socket |
| 339 |
* lock as such sock is freed after close(). |
| 340 |
*/ |
| 341 |
struct mptcp_pm_data pm; |
| 342 |
struct mptcp_sched_ops *sched; |
| 343 |
struct { |
| 344 |
int space; /* bytes copied in last measurement window */ |
| 345 |
int copied; /* bytes copied in this measurement window */ |
| 346 |
u64 time; /* start time of measurement window */ |
| 347 |
u64 rtt_us; /* last maximum rtt of subflows */ |
| 348 |
} rcvq_space; |
| 349 |
u8 scaling_ratio; |
| 350 |
bool allow_subflows; |
| 351 |
|
| 352 |
u32 subflow_id; |
| 353 |
u32 setsockopt_seq; |
| 354 |
char ca_name[TCP_CA_NAME_MAX]; |
| 355 |
|
| 356 |
spinlock_t fallback_lock; /* protects fallback, |
| 357 |
* allow_infinite_fallback and |
| 358 |
* allow_join |
| 359 |
*/ |
| 360 |
|
| 361 |
struct list_head backlog_list; /* protected by the data lock */ |
| 362 |
u32 backlog_len; |
| 363 |
u32 backlog_unaccounted; |
| 364 |
}; |
| 365 |
|
| 366 |
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock) |
| 367 |
#define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock) |
| 368 |
|
| 369 |
#define mptcp_for_each_subflow(__msk, __subflow) \ |
| 370 |
list_for_each_entry(__subflow, &((__msk)->conn_list), node) |
| 371 |
#define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \ |
| 372 |
list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) |
| 373 |
#define mptcp_next_subflow(__msk, __subflow) \ |
| 374 |
list_next_entry_circular(__subflow, &((__msk)->conn_list), node) |
| 375 |
|
| 376 |
extern struct genl_family mptcp_genl_family; |
| 377 |
|
| 378 |
static inline void msk_owned_by_me(const struct mptcp_sock *msk) |
| 379 |
{ |
| 380 |
sock_owned_by_me((const struct sock *)msk); |
| 381 |
} |
| 382 |
|
| 383 |
#ifdef CONFIG_DEBUG_NET |
| 384 |
/* MPTCP-specific: we might (indirectly) call this helper with the wrong sk */ |
| 385 |
#undef tcp_sk |
| 386 |
#define tcp_sk(ptr) ({ \ |
| 387 |
typeof(ptr) _ptr = (ptr); \ |
| 388 |
WARN_ON(_ptr->sk_protocol != IPPROTO_TCP); \ |
| 389 |
container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk); \ |
| 390 |
}) |
| 391 |
#define mptcp_sk(ptr) ({ \ |
| 392 |
typeof(ptr) _ptr = (ptr); \ |
| 393 |
WARN_ON(_ptr->sk_protocol != IPPROTO_MPTCP); \ |
| 394 |
container_of_const(_ptr, struct mptcp_sock, sk.icsk_inet.sk); \ |
| 395 |
}) |
| 396 |
|
| 397 |
#else /* !CONFIG_DEBUG_NET */ |
| 398 |
#define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_inet.sk) |
| 399 |
#endif |
| 400 |
|
| 401 |
static inline int mptcp_win_from_space(const struct sock *sk, int space) |
| 402 |
{ |
| 403 |
return __tcp_win_from_space(mptcp_sk(sk)->scaling_ratio, space); |
| 404 |
} |
| 405 |
|
| 406 |
static inline int mptcp_space_from_win(const struct sock *sk, int win) |
| 407 |
{ |
| 408 |
return __tcp_space_from_win(mptcp_sk(sk)->scaling_ratio, win); |
| 409 |
} |
| 410 |
|
| 411 |
static inline int __mptcp_space(const struct sock *sk) |
| 412 |
{ |
| 413 |
return mptcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf) - |
| 414 |
READ_ONCE(mptcp_sk(sk)->backlog_len) - |
| 415 |
sk_rmem_alloc_get(sk)); |
| 416 |
} |
| 417 |
|
| 418 |
static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk) |
| 419 |
{ |
| 420 |
const struct mptcp_sock *msk = mptcp_sk(sk); |
| 421 |
|
| 422 |
return msk->first_pending; |
| 423 |
} |
| 424 |
|
| 425 |
static inline struct mptcp_data_frag *mptcp_send_next(struct sock *sk) |
| 426 |
{ |
| 427 |
struct mptcp_sock *msk = mptcp_sk(sk); |
| 428 |
struct mptcp_data_frag *cur; |
| 429 |
|
| 430 |
cur = msk->first_pending; |
| 431 |
return list_is_last(&cur->list, &msk->rtx_queue) ? NULL : |
| 432 |
list_next_entry(cur, list); |
| 433 |
} |
| 434 |
|
| 435 |
static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk) |
| 436 |
{ |
| 437 |
const struct mptcp_sock *msk = mptcp_sk(sk); |
| 438 |
|
| 439 |
if (!msk->first_pending) |
| 440 |
return NULL; |
| 441 |
|
| 442 |
if (WARN_ON_ONCE(list_empty(&msk->rtx_queue))) |
| 443 |
return NULL; |
| 444 |
|
| 445 |
return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list); |
| 446 |
} |
| 447 |
|
| 448 |
static inline struct mptcp_data_frag *mptcp_rtx_head(struct sock *sk) |
| 449 |
{ |
| 450 |
struct mptcp_sock *msk = mptcp_sk(sk); |
| 451 |
|
| 452 |
if (msk->snd_una == msk->snd_nxt) |
| 453 |
return NULL; |
| 454 |
|
| 455 |
return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list); |
| 456 |
} |
| 457 |
|
| 458 |
struct csum_pseudo_header { |
| 459 |
__be64 data_seq; |
| 460 |
__be32 subflow_seq; |
| 461 |
__be16 data_len; |
| 462 |
__sum16 csum; |
| 463 |
}; |
| 464 |
|
| 465 |
struct mptcp_subflow_request_sock { |
| 466 |
struct tcp_request_sock sk; |
| 467 |
u16 mp_capable : 1, |
| 468 |
mp_join : 1, |
| 469 |
backup : 1, |
| 470 |
request_bkup : 1, |
| 471 |
csum_reqd : 1, |
| 472 |
allow_join_id0 : 1; |
| 473 |
u8 local_id; |
| 474 |
u8 remote_id; |
| 475 |
u64 local_key; |
| 476 |
u64 idsn; |
| 477 |
u32 token; |
| 478 |
u32 ssn_offset; |
| 479 |
u64 thmac; |
| 480 |
u32 local_nonce; |
| 481 |
u32 remote_nonce; |
| 482 |
struct mptcp_sock *msk; |
| 483 |
struct hlist_nulls_node token_node; |
| 484 |
}; |
| 485 |
|
| 486 |
static inline struct mptcp_subflow_request_sock * |
| 487 |
mptcp_subflow_rsk(const struct request_sock *rsk) |
| 488 |
{ |
| 489 |
return (struct mptcp_subflow_request_sock *)rsk; |
| 490 |
} |
| 491 |
|
| 492 |
struct mptcp_delegated_action { |
| 493 |
struct napi_struct napi; |
| 494 |
local_lock_t bh_lock; |
| 495 |
struct list_head head; |
| 496 |
}; |
| 497 |
|
| 498 |
DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); |
| 499 |
|
| 500 |
#define MPTCP_DELEGATE_SCHEDULED 0 |
| 501 |
#define MPTCP_DELEGATE_SEND 1 |
| 502 |
#define MPTCP_DELEGATE_ACK 2 |
| 503 |
#define MPTCP_DELEGATE_SNDBUF 3 |
| 504 |
|
| 505 |
#define MPTCP_DELEGATE_ACTIONS_MASK (~BIT(MPTCP_DELEGATE_SCHEDULED)) |
| 506 |
/* MPTCP subflow context */ |
| 507 |
struct mptcp_subflow_context { |
| 508 |
struct list_head node;/* conn_list of subflows */ |
| 509 |
|
| 510 |
struct_group(reset, |
| 511 |
|
| 512 |
unsigned long avg_pacing_rate; /* protected by msk socket lock */ |
| 513 |
u64 local_key; |
| 514 |
u64 remote_key; |
| 515 |
u64 idsn; |
| 516 |
u64 map_seq; |
| 517 |
u64 rcv_wnd_sent; |
| 518 |
u32 snd_isn; |
| 519 |
u32 token; |
| 520 |
u32 rel_write_seq; |
| 521 |
u32 map_subflow_seq; |
| 522 |
u32 ssn_offset; |
| 523 |
u32 map_data_len; |
| 524 |
__wsum map_data_csum; |
| 525 |
u32 map_csum_len; |
| 526 |
u32 request_mptcp : 1, /* send MP_CAPABLE */ |
| 527 |
request_join : 1, /* send MP_JOIN */ |
| 528 |
request_bkup : 1, |
| 529 |
mp_capable : 1, /* remote is MPTCP capable */ |
| 530 |
mp_join : 1, /* remote is JOINing */ |
| 531 |
pm_notified : 1, /* PM hook called for established status */ |
| 532 |
conn_finished : 1, |
| 533 |
map_valid : 1, |
| 534 |
map_csum_reqd : 1, |
| 535 |
map_data_fin : 1, |
| 536 |
mpc_map : 1, |
| 537 |
backup : 1, |
| 538 |
send_mp_prio : 1, |
| 539 |
send_mp_fail : 1, |
| 540 |
send_fastclose : 1, |
| 541 |
send_infinite_map : 1, |
| 542 |
remote_key_valid : 1, /* received the peer key from */ |
| 543 |
disposable : 1, /* ctx can be free at ulp release time */ |
| 544 |
closing : 1, /* must not pass rx data to msk anymore */ |
| 545 |
stale : 1, /* unable to snd/rcv data, do not use for xmit */ |
| 546 |
valid_csum_seen : 1, /* at least one csum validated */ |
| 547 |
is_mptfo : 1, /* subflow is doing TFO */ |
| 548 |
close_event_done : 1, /* has done the post-closed part */ |
| 549 |
mpc_drop : 1, /* the MPC option has been dropped in a rtx */ |
| 550 |
__unused : 8; |
| 551 |
bool data_avail; |
| 552 |
bool scheduled; |
| 553 |
bool pm_listener; /* a listener managed by the kernel PM? */ |
| 554 |
bool fully_established; /* path validated */ |
| 555 |
u32 lent_mem_frag; |
| 556 |
u32 remote_nonce; |
| 557 |
u64 thmac; |
| 558 |
u32 local_nonce; |
| 559 |
u32 remote_token; |
| 560 |
union { |
| 561 |
u8 hmac[MPTCPOPT_HMAC_LEN]; /* MPJ subflow only */ |
| 562 |
u64 iasn; /* initial ack sequence number, MPC subflows only */ |
| 563 |
}; |
| 564 |
s16 local_id; /* if negative not initialized yet */ |
| 565 |
u8 remote_id; |
| 566 |
u8 reset_seen:1; |
| 567 |
u8 reset_transient:1; |
| 568 |
u8 reset_reason:4; |
| 569 |
u8 stale_count; |
| 570 |
|
| 571 |
u32 subflow_id; |
| 572 |
|
| 573 |
long delegated_status; |
| 574 |
unsigned long fail_tout; |
| 575 |
|
| 576 |
); |
| 577 |
|
| 578 |
struct list_head delegated_node; /* link into delegated_action, protected by local BH */ |
| 579 |
|
| 580 |
u32 setsockopt_seq; |
| 581 |
u32 stale_rcv_tstamp; |
| 582 |
int cached_sndbuf; /* sndbuf size when last synced with the msk sndbuf, |
| 583 |
* protected by the msk socket lock |
| 584 |
*/ |
| 585 |
|
| 586 |
struct sock *tcp_sock; /* tcp sk backpointer */ |
| 587 |
struct sock *conn; /* parent mptcp_sock */ |
| 588 |
const struct inet_connection_sock_af_ops *icsk_af_ops; |
| 589 |
void (*tcp_state_change)(struct sock *sk); |
| 590 |
void (*tcp_error_report)(struct sock *sk); |
| 591 |
|
| 592 |
struct rcu_head rcu; |
| 593 |
}; |
| 594 |
|
| 595 |
static inline struct mptcp_subflow_context * |
| 596 |
mptcp_subflow_ctx(const struct sock *sk) |
| 597 |
{ |
| 598 |
const struct inet_connection_sock *icsk = inet_csk(sk); |
| 599 |
|
| 600 |
/* Use RCU on icsk_ulp_data only for sock diag code */ |
| 601 |
return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; |
| 602 |
} |
| 603 |
|
| 604 |
static inline struct sock * |
| 605 |
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) |
| 606 |
{ |
| 607 |
return subflow->tcp_sock; |
| 608 |
} |
| 609 |
|
| 610 |
static inline void |
| 611 |
mptcp_subflow_ctx_reset(struct mptcp_subflow_context *subflow) |
| 612 |
{ |
| 613 |
memset(&subflow->reset, 0, sizeof(subflow->reset)); |
| 614 |
subflow->request_mptcp = 1; |
| 615 |
WRITE_ONCE(subflow->local_id, -1); |
| 616 |
} |
| 617 |
|
| 618 |
/* Convert reset reasons in MPTCP to enum sk_rst_reason type */ |
| 619 |
static inline enum sk_rst_reason |
| 620 |
sk_rst_convert_mptcp_reason(u32 reason) |
| 621 |
{ |
| 622 |
switch (reason) { |
| 623 |
case MPTCP_RST_EUNSPEC: |
| 624 |
return SK_RST_REASON_MPTCP_RST_EUNSPEC; |
| 625 |
case MPTCP_RST_EMPTCP: |
| 626 |
return SK_RST_REASON_MPTCP_RST_EMPTCP; |
| 627 |
case MPTCP_RST_ERESOURCE: |
| 628 |
return SK_RST_REASON_MPTCP_RST_ERESOURCE; |
| 629 |
case MPTCP_RST_EPROHIBIT: |
| 630 |
return SK_RST_REASON_MPTCP_RST_EPROHIBIT; |
| 631 |
case MPTCP_RST_EWQ2BIG: |
| 632 |
return SK_RST_REASON_MPTCP_RST_EWQ2BIG; |
| 633 |
case MPTCP_RST_EBADPERF: |
| 634 |
return SK_RST_REASON_MPTCP_RST_EBADPERF; |
| 635 |
case MPTCP_RST_EMIDDLEBOX: |
| 636 |
return SK_RST_REASON_MPTCP_RST_EMIDDLEBOX; |
| 637 |
default: |
| 638 |
/* It should not happen, or else errors may occur |
| 639 |
* in MPTCP layer |
| 640 |
*/ |
| 641 |
return SK_RST_REASON_ERROR; |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
static inline void |
| 646 |
mptcp_send_active_reset_reason(struct sock *sk) |
| 647 |
{ |
| 648 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 649 |
enum sk_rst_reason reason; |
| 650 |
|
| 651 |
reason = sk_rst_convert_mptcp_reason(subflow->reset_reason); |
| 652 |
tcp_send_active_reset(sk, GFP_ATOMIC, reason); |
| 653 |
} |
| 654 |
|
| 655 |
/* Made the fwd mem carried by the given skb available to the msk, |
| 656 |
* To be paired with a previous mptcp_subflow_lend_fwdmem() before freeing |
| 657 |
* the skb or setting the skb ownership. |
| 658 |
*/ |
| 659 |
static inline void mptcp_borrow_fwdmem(struct sock *sk, struct sk_buff *skb) |
| 660 |
{ |
| 661 |
struct sock *ssk = skb->sk; |
| 662 |
|
| 663 |
/* The subflow just lend the skb fwd memory; if the subflow meanwhile |
| 664 |
* closed, mptcp_close_ssk() already released the ssk rcv memory. |
| 665 |
*/ |
| 666 |
DEBUG_NET_WARN_ON_ONCE(skb->destructor); |
| 667 |
sk_forward_alloc_add(sk, skb->truesize); |
| 668 |
if (!ssk) |
| 669 |
return; |
| 670 |
|
| 671 |
atomic_sub(skb->truesize, &ssk->sk_rmem_alloc); |
| 672 |
skb->sk = NULL; |
| 673 |
} |
| 674 |
|
| 675 |
static inline void |
| 676 |
__mptcp_subflow_lend_fwdmem(struct mptcp_subflow_context *subflow, int size) |
| 677 |
{ |
| 678 |
int frag = (subflow->lent_mem_frag + size) & (PAGE_SIZE - 1); |
| 679 |
|
| 680 |
subflow->lent_mem_frag = frag; |
| 681 |
} |
| 682 |
|
| 683 |
static inline void |
| 684 |
mptcp_subflow_lend_fwdmem(struct mptcp_subflow_context *subflow, |
| 685 |
struct sk_buff *skb) |
| 686 |
{ |
| 687 |
__mptcp_subflow_lend_fwdmem(subflow, skb->truesize); |
| 688 |
skb->destructor = NULL; |
| 689 |
} |
| 690 |
|
| 691 |
static inline u64 |
| 692 |
mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow) |
| 693 |
{ |
| 694 |
return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq - |
| 695 |
subflow->ssn_offset - |
| 696 |
subflow->map_subflow_seq; |
| 697 |
} |
| 698 |
|
| 699 |
static inline u64 |
| 700 |
mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow) |
| 701 |
{ |
| 702 |
return subflow->map_seq + mptcp_subflow_get_map_offset(subflow); |
| 703 |
} |
| 704 |
|
| 705 |
void mptcp_subflow_process_delegated(struct sock *ssk, long actions); |
| 706 |
|
| 707 |
static inline void mptcp_subflow_delegate(struct mptcp_subflow_context *subflow, int action) |
| 708 |
{ |
| 709 |
long old, set_bits = BIT(MPTCP_DELEGATE_SCHEDULED) | BIT(action); |
| 710 |
struct mptcp_delegated_action *delegated; |
| 711 |
bool schedule; |
| 712 |
|
| 713 |
/* the caller held the subflow bh socket lock */ |
| 714 |
lockdep_assert_in_softirq(); |
| 715 |
|
| 716 |
/* The implied barrier pairs with tcp_release_cb_override() |
| 717 |
* mptcp_napi_poll(), and ensures the below list check sees list |
| 718 |
* updates done prior to delegated status bits changes |
| 719 |
*/ |
| 720 |
old = set_mask_bits(&subflow->delegated_status, 0, set_bits); |
| 721 |
if (!(old & BIT(MPTCP_DELEGATE_SCHEDULED))) { |
| 722 |
if (WARN_ON_ONCE(!list_empty(&subflow->delegated_node))) |
| 723 |
return; |
| 724 |
|
| 725 |
local_lock_nested_bh(&mptcp_delegated_actions.bh_lock); |
| 726 |
delegated = this_cpu_ptr(&mptcp_delegated_actions); |
| 727 |
schedule = list_empty(&delegated->head); |
| 728 |
list_add_tail(&subflow->delegated_node, &delegated->head); |
| 729 |
local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock); |
| 730 |
sock_hold(mptcp_subflow_tcp_sock(subflow)); |
| 731 |
if (schedule) |
| 732 |
napi_schedule(&delegated->napi); |
| 733 |
} |
| 734 |
} |
| 735 |
|
| 736 |
static inline struct mptcp_subflow_context * |
| 737 |
mptcp_subflow_delegated_next(struct mptcp_delegated_action *delegated) |
| 738 |
{ |
| 739 |
struct mptcp_subflow_context *ret; |
| 740 |
|
| 741 |
local_lock_nested_bh(&mptcp_delegated_actions.bh_lock); |
| 742 |
if (list_empty(&delegated->head)) { |
| 743 |
local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock); |
| 744 |
return NULL; |
| 745 |
} |
| 746 |
|
| 747 |
ret = list_first_entry(&delegated->head, struct mptcp_subflow_context, delegated_node); |
| 748 |
list_del_init(&ret->delegated_node); |
| 749 |
local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock); |
| 750 |
return ret; |
| 751 |
} |
| 752 |
|
| 753 |
void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp); |
| 754 |
void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk); |
| 755 |
|
| 756 |
int mptcp_is_enabled(const struct net *net); |
| 757 |
unsigned int mptcp_get_add_addr_timeout(const struct net *net); |
| 758 |
int mptcp_is_checksum_enabled(const struct net *net); |
| 759 |
int mptcp_allow_join_id0(const struct net *net); |
| 760 |
unsigned int mptcp_stale_loss_cnt(const struct net *net); |
| 761 |
unsigned int mptcp_close_timeout(const struct sock *sk); |
| 762 |
int mptcp_get_pm_type(const struct net *net); |
| 763 |
const char *mptcp_get_path_manager(const struct net *net); |
| 764 |
const char *mptcp_get_scheduler(const struct net *net); |
| 765 |
|
| 766 |
void mptcp_active_disable(struct sock *sk); |
| 767 |
bool mptcp_active_should_disable(struct sock *ssk); |
| 768 |
void mptcp_active_enable(struct sock *sk); |
| 769 |
|
| 770 |
void mptcp_get_available_schedulers(char *buf, size_t maxlen); |
| 771 |
void __mptcp_subflow_fully_established(struct mptcp_sock *msk, |
| 772 |
struct mptcp_subflow_context *subflow, |
| 773 |
const struct mptcp_options_received *mp_opt); |
| 774 |
bool __mptcp_retransmit_pending_data(struct sock *sk); |
| 775 |
void mptcp_check_and_set_pending(struct sock *sk); |
| 776 |
void __mptcp_push_pending(struct sock *sk, unsigned int flags); |
| 777 |
bool mptcp_subflow_data_available(struct sock *sk); |
| 778 |
void __init mptcp_subflow_init(void); |
| 779 |
void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how); |
| 780 |
void mptcp_close_ssk(struct sock *sk, struct sock *ssk, |
| 781 |
struct mptcp_subflow_context *subflow); |
| 782 |
void __mptcp_subflow_send_ack(struct sock *ssk); |
| 783 |
void mptcp_subflow_reset(struct sock *ssk); |
| 784 |
void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk); |
| 785 |
void mptcp_sock_graft(struct sock *sk, struct socket *parent); |
| 786 |
struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk); |
| 787 |
bool __mptcp_close(struct sock *sk, long timeout); |
| 788 |
void mptcp_cancel_work(struct sock *sk); |
| 789 |
void __mptcp_unaccepted_force_close(struct sock *sk); |
| 790 |
void mptcp_set_state(struct sock *sk, int state); |
| 791 |
|
| 792 |
bool mptcp_addresses_equal(const struct mptcp_addr_info *a, |
| 793 |
const struct mptcp_addr_info *b, bool use_port); |
| 794 |
void mptcp_local_address(const struct sock_common *skc, |
| 795 |
struct mptcp_addr_info *addr); |
| 796 |
void mptcp_remote_address(const struct sock_common *skc, |
| 797 |
struct mptcp_addr_info *addr); |
| 798 |
|
| 799 |
/* called with sk socket lock held */ |
| 800 |
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local, |
| 801 |
const struct mptcp_addr_info *remote); |
| 802 |
int mptcp_subflow_create_socket(struct sock *sk, unsigned short family, |
| 803 |
struct socket **new_sock); |
| 804 |
void mptcp_info2sockaddr(const struct mptcp_addr_info *info, |
| 805 |
struct sockaddr_storage *addr, |
| 806 |
unsigned short family); |
| 807 |
struct mptcp_sched_ops *mptcp_sched_find(const char *name); |
| 808 |
int mptcp_validate_scheduler(struct mptcp_sched_ops *sched); |
| 809 |
int mptcp_register_scheduler(struct mptcp_sched_ops *sched); |
| 810 |
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched); |
| 811 |
void mptcp_sched_init(void); |
| 812 |
int mptcp_init_sched(struct mptcp_sock *msk, |
| 813 |
struct mptcp_sched_ops *sched); |
| 814 |
void mptcp_release_sched(struct mptcp_sock *msk); |
| 815 |
void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, |
| 816 |
bool scheduled); |
| 817 |
struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk); |
| 818 |
struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk); |
| 819 |
int mptcp_sched_get_send(struct mptcp_sock *msk); |
| 820 |
int mptcp_sched_get_retrans(struct mptcp_sock *msk); |
| 821 |
|
| 822 |
static inline u64 mptcp_data_avail(const struct mptcp_sock *msk) |
| 823 |
{ |
| 824 |
return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed); |
| 825 |
} |
| 826 |
|
| 827 |
static inline bool mptcp_epollin_ready(const struct sock *sk) |
| 828 |
{ |
| 829 |
u64 data_avail = mptcp_data_avail(mptcp_sk(sk)); |
| 830 |
|
| 831 |
if (!data_avail) |
| 832 |
return false; |
| 833 |
|
| 834 |
/* mptcp doesn't have to deal with small skbs in the receive queue, |
| 835 |
* as it can always coalesce them |
| 836 |
*/ |
| 837 |
return (data_avail >= sk->sk_rcvlowat) || |
| 838 |
tcp_under_memory_pressure(sk); |
| 839 |
} |
| 840 |
|
| 841 |
int mptcp_set_rcvlowat(struct sock *sk, int val); |
| 842 |
|
| 843 |
static inline bool __tcp_can_send(const struct sock *ssk) |
| 844 |
{ |
| 845 |
/* only send if our side has not closed yet */ |
| 846 |
return ((1 << inet_sk_state_load(ssk)) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)); |
| 847 |
} |
| 848 |
|
| 849 |
static inline bool __mptcp_subflow_active(struct mptcp_subflow_context *subflow) |
| 850 |
{ |
| 851 |
/* can't send if JOIN hasn't completed yet (i.e. is usable for mptcp) */ |
| 852 |
if (subflow->request_join && !READ_ONCE(subflow->fully_established)) |
| 853 |
return false; |
| 854 |
|
| 855 |
return __tcp_can_send(mptcp_subflow_tcp_sock(subflow)); |
| 856 |
} |
| 857 |
|
| 858 |
void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow); |
| 859 |
|
| 860 |
bool mptcp_subflow_active(struct mptcp_subflow_context *subflow); |
| 861 |
|
| 862 |
void mptcp_subflow_drop_ctx(struct sock *ssk); |
| 863 |
|
| 864 |
static inline void mptcp_subflow_tcp_fallback(struct sock *sk, |
| 865 |
struct mptcp_subflow_context *ctx) |
| 866 |
{ |
| 867 |
sk->sk_data_ready = sock_def_readable; |
| 868 |
sk->sk_state_change = ctx->tcp_state_change; |
| 869 |
sk->sk_write_space = sk_stream_write_space; |
| 870 |
sk->sk_error_report = ctx->tcp_error_report; |
| 871 |
|
| 872 |
inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops; |
| 873 |
} |
| 874 |
|
| 875 |
void __init mptcp_proto_init(void); |
| 876 |
#if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 877 |
int __init mptcp_proto_v6_init(void); |
| 878 |
void __init mptcp_subflow_v6_init(void); |
| 879 |
#endif |
| 880 |
|
| 881 |
struct sock *mptcp_sk_clone_init(const struct sock *sk, |
| 882 |
const struct mptcp_options_received *mp_opt, |
| 883 |
struct sock *ssk, |
| 884 |
struct request_sock *req); |
| 885 |
void mptcp_get_options(const struct sk_buff *skb, |
| 886 |
struct mptcp_options_received *mp_opt); |
| 887 |
|
| 888 |
void mptcp_finish_connect(struct sock *sk); |
| 889 |
void __mptcp_sync_state(struct sock *sk, int state); |
| 890 |
void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout); |
| 891 |
|
| 892 |
static inline void mptcp_stop_tout_timer(struct sock *sk) |
| 893 |
{ |
| 894 |
if (!inet_csk(sk)->icsk_mtup.probe_timestamp) |
| 895 |
return; |
| 896 |
|
| 897 |
sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer); |
| 898 |
inet_csk(sk)->icsk_mtup.probe_timestamp = 0; |
| 899 |
} |
| 900 |
|
| 901 |
static inline void mptcp_set_close_tout(struct sock *sk, unsigned long tout) |
| 902 |
{ |
| 903 |
/* avoid 0 timestamp, as that means no close timeout */ |
| 904 |
inet_csk(sk)->icsk_mtup.probe_timestamp = tout ? : 1; |
| 905 |
} |
| 906 |
|
| 907 |
static inline void mptcp_start_tout_timer(struct sock *sk) |
| 908 |
{ |
| 909 |
mptcp_set_close_tout(sk, tcp_jiffies32); |
| 910 |
mptcp_reset_tout_timer(mptcp_sk(sk), 0); |
| 911 |
} |
| 912 |
|
| 913 |
static inline bool mptcp_is_fully_established(struct sock *sk) |
| 914 |
{ |
| 915 |
return inet_sk_state_load(sk) == TCP_ESTABLISHED && |
| 916 |
READ_ONCE(mptcp_sk(sk)->fully_established); |
| 917 |
} |
| 918 |
|
| 919 |
static inline u64 mptcp_stamp(void) |
| 920 |
{ |
| 921 |
return div_u64(tcp_clock_ns(), NSEC_PER_USEC); |
| 922 |
} |
| 923 |
|
| 924 |
void mptcp_data_ready(struct sock *sk, struct sock *ssk); |
| 925 |
bool mptcp_finish_join(struct sock *sk); |
| 926 |
bool mptcp_schedule_work(struct sock *sk); |
| 927 |
int mptcp_setsockopt(struct sock *sk, int level, int optname, |
| 928 |
sockptr_t optval, unsigned int optlen); |
| 929 |
int mptcp_getsockopt(struct sock *sk, int level, int optname, |
| 930 |
char __user *optval, int __user *option); |
| 931 |
|
| 932 |
u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq); |
| 933 |
static inline u64 mptcp_expand_seq(u64 old_seq, u64 cur_seq, bool use_64bit) |
| 934 |
{ |
| 935 |
if (use_64bit) |
| 936 |
return cur_seq; |
| 937 |
|
| 938 |
return __mptcp_expand_seq(old_seq, cur_seq); |
| 939 |
} |
| 940 |
void __mptcp_check_push(struct sock *sk, struct sock *ssk); |
| 941 |
void __mptcp_data_acked(struct sock *sk); |
| 942 |
void __mptcp_error_report(struct sock *sk); |
| 943 |
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit); |
| 944 |
static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk) |
| 945 |
{ |
| 946 |
return READ_ONCE(msk->snd_data_fin_enable) && |
| 947 |
READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt); |
| 948 |
} |
| 949 |
|
| 950 |
static inline u32 mptcp_notsent_lowat(const struct sock *sk) |
| 951 |
{ |
| 952 |
struct net *net = sock_net(sk); |
| 953 |
u32 val; |
| 954 |
|
| 955 |
val = READ_ONCE(mptcp_sk(sk)->notsent_lowat); |
| 956 |
return val ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat); |
| 957 |
} |
| 958 |
|
| 959 |
static inline bool mptcp_stream_memory_free(const struct sock *sk, int wake) |
| 960 |
{ |
| 961 |
const struct mptcp_sock *msk = mptcp_sk(sk); |
| 962 |
u32 notsent_bytes; |
| 963 |
|
| 964 |
notsent_bytes = READ_ONCE(msk->write_seq) - READ_ONCE(msk->snd_nxt); |
| 965 |
return (notsent_bytes << wake) < mptcp_notsent_lowat(sk); |
| 966 |
} |
| 967 |
|
| 968 |
static inline bool __mptcp_stream_is_writeable(const struct sock *sk, int wake) |
| 969 |
{ |
| 970 |
return mptcp_stream_memory_free(sk, wake) && |
| 971 |
__sk_stream_is_writeable(sk, wake); |
| 972 |
} |
| 973 |
|
| 974 |
static inline void mptcp_write_space(struct sock *sk) |
| 975 |
{ |
| 976 |
/* pairs with memory barrier in mptcp_poll */ |
| 977 |
smp_mb(); |
| 978 |
if (mptcp_stream_memory_free(sk, 1)) |
| 979 |
INDIRECT_CALL_1(sk->sk_write_space, sk_stream_write_space, sk); |
| 980 |
} |
| 981 |
|
| 982 |
static inline void __mptcp_sync_sndbuf(struct sock *sk) |
| 983 |
{ |
| 984 |
struct mptcp_subflow_context *subflow; |
| 985 |
int ssk_sndbuf, new_sndbuf; |
| 986 |
|
| 987 |
if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) |
| 988 |
return; |
| 989 |
|
| 990 |
new_sndbuf = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]); |
| 991 |
mptcp_for_each_subflow(mptcp_sk(sk), subflow) { |
| 992 |
ssk_sndbuf = READ_ONCE(mptcp_subflow_tcp_sock(subflow)->sk_sndbuf); |
| 993 |
|
| 994 |
subflow->cached_sndbuf = ssk_sndbuf; |
| 995 |
new_sndbuf += ssk_sndbuf; |
| 996 |
} |
| 997 |
|
| 998 |
/* the msk max wmem limit is <nr_subflows> * tcp wmem[2] */ |
| 999 |
WRITE_ONCE(sk->sk_sndbuf, new_sndbuf); |
| 1000 |
mptcp_write_space(sk); |
| 1001 |
} |
| 1002 |
|
| 1003 |
/* The called held both the msk socket and the subflow socket locks, |
| 1004 |
* possibly under BH |
| 1005 |
*/ |
| 1006 |
static inline void __mptcp_propagate_sndbuf(struct sock *sk, struct sock *ssk) |
| 1007 |
{ |
| 1008 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); |
| 1009 |
|
| 1010 |
if (READ_ONCE(ssk->sk_sndbuf) != subflow->cached_sndbuf) |
| 1011 |
__mptcp_sync_sndbuf(sk); |
| 1012 |
} |
| 1013 |
|
| 1014 |
/* the caller held only the subflow socket lock, either in process or |
| 1015 |
* BH context. Additionally this can be called under the msk data lock, |
| 1016 |
* so we can't acquire such lock here: let the delegate action acquires |
| 1017 |
* the needed locks in suitable order. |
| 1018 |
*/ |
| 1019 |
static inline void mptcp_propagate_sndbuf(struct sock *sk, struct sock *ssk) |
| 1020 |
{ |
| 1021 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); |
| 1022 |
|
| 1023 |
if (likely(READ_ONCE(ssk->sk_sndbuf) == subflow->cached_sndbuf)) |
| 1024 |
return; |
| 1025 |
|
| 1026 |
local_bh_disable(); |
| 1027 |
mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_SNDBUF); |
| 1028 |
local_bh_enable(); |
| 1029 |
} |
| 1030 |
|
| 1031 |
#define MPTCP_TOKEN_MAX_RETRIES 4 |
| 1032 |
|
| 1033 |
void __init mptcp_token_init(void); |
| 1034 |
static inline void mptcp_token_init_request(struct request_sock *req) |
| 1035 |
{ |
| 1036 |
mptcp_subflow_rsk(req)->token_node.pprev = NULL; |
| 1037 |
} |
| 1038 |
|
| 1039 |
int mptcp_token_new_request(struct request_sock *req); |
| 1040 |
void mptcp_token_destroy_request(struct request_sock *req); |
| 1041 |
int mptcp_token_new_connect(struct sock *ssk); |
| 1042 |
void mptcp_token_accept(struct mptcp_subflow_request_sock *r, |
| 1043 |
struct mptcp_sock *msk); |
| 1044 |
bool mptcp_token_exists(u32 token); |
| 1045 |
struct mptcp_sock *mptcp_token_get_sock(struct net *net, u32 token); |
| 1046 |
struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot, |
| 1047 |
long *s_num); |
| 1048 |
void mptcp_token_destroy(struct mptcp_sock *msk); |
| 1049 |
|
| 1050 |
void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn); |
| 1051 |
|
| 1052 |
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac); |
| 1053 |
__sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum); |
| 1054 |
|
| 1055 |
void __init mptcp_pm_init(void); |
| 1056 |
void mptcp_pm_data_init(struct mptcp_sock *msk); |
| 1057 |
void mptcp_pm_data_reset(struct mptcp_sock *msk); |
| 1058 |
void mptcp_pm_destroy(struct mptcp_sock *msk); |
| 1059 |
int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info, |
| 1060 |
struct mptcp_addr_info *addr); |
| 1061 |
int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info, |
| 1062 |
bool require_family, |
| 1063 |
struct mptcp_pm_addr_entry *entry); |
| 1064 |
bool mptcp_pm_addr_families_match(const struct sock *sk, |
| 1065 |
const struct mptcp_addr_info *loc, |
| 1066 |
const struct mptcp_addr_info *rem); |
| 1067 |
void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk); |
| 1068 |
void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side); |
| 1069 |
void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk); |
| 1070 |
bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk); |
| 1071 |
void mptcp_pm_connection_closed(struct mptcp_sock *msk); |
| 1072 |
void mptcp_pm_subflow_established(struct mptcp_sock *msk); |
| 1073 |
bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk); |
| 1074 |
void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, |
| 1075 |
const struct mptcp_subflow_context *subflow); |
| 1076 |
void mptcp_pm_add_addr_received(const struct sock *ssk, |
| 1077 |
const struct mptcp_addr_info *addr); |
| 1078 |
void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, |
| 1079 |
const struct mptcp_addr_info *addr); |
| 1080 |
void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk); |
| 1081 |
void mptcp_pm_send_ack(struct mptcp_sock *msk, |
| 1082 |
struct mptcp_subflow_context *subflow, |
| 1083 |
bool prio, bool backup); |
| 1084 |
void mptcp_pm_addr_send_ack(struct mptcp_sock *msk); |
| 1085 |
void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id); |
| 1086 |
void mptcp_pm_rm_subflow(struct mptcp_sock *msk, |
| 1087 |
const struct mptcp_rm_list *rm_list); |
| 1088 |
void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, |
| 1089 |
const struct mptcp_rm_list *rm_list); |
| 1090 |
void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup); |
| 1091 |
void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq); |
| 1092 |
int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk, |
| 1093 |
struct mptcp_addr_info *addr, |
| 1094 |
struct mptcp_addr_info *rem, |
| 1095 |
u8 bkup); |
| 1096 |
bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, |
| 1097 |
const struct mptcp_addr_info *addr); |
| 1098 |
bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk); |
| 1099 |
struct mptcp_pm_add_entry * |
| 1100 |
mptcp_pm_del_add_timer(struct mptcp_sock *msk, |
| 1101 |
const struct mptcp_addr_info *addr, bool check_id); |
| 1102 |
bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, |
| 1103 |
const struct mptcp_addr_info *saddr); |
| 1104 |
bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, |
| 1105 |
const struct mptcp_addr_info *addr); |
| 1106 |
int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local, |
| 1107 |
struct genl_info *info); |
| 1108 |
int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, |
| 1109 |
struct genl_info *info); |
| 1110 |
int mptcp_pm_announce_addr(struct mptcp_sock *msk, |
| 1111 |
const struct mptcp_addr_info *addr, |
| 1112 |
bool echo); |
| 1113 |
int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); |
| 1114 |
void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, |
| 1115 |
struct mptcp_pm_addr_entry *entry); |
| 1116 |
|
| 1117 |
/* the default path manager, used in mptcp_pm_unregister */ |
| 1118 |
extern struct mptcp_pm_ops mptcp_pm_kernel; |
| 1119 |
|
| 1120 |
struct mptcp_pm_ops *mptcp_pm_find(const char *name); |
| 1121 |
int mptcp_pm_register(struct mptcp_pm_ops *pm_ops); |
| 1122 |
void mptcp_pm_unregister(struct mptcp_pm_ops *pm_ops); |
| 1123 |
int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops); |
| 1124 |
void mptcp_pm_get_available(char *buf, size_t maxlen); |
| 1125 |
|
| 1126 |
void mptcp_userspace_pm_free_local_addr_list(struct mptcp_sock *msk); |
| 1127 |
|
| 1128 |
void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk, |
| 1129 |
const struct sock *ssk, gfp_t gfp); |
| 1130 |
void mptcp_event_addr_announced(const struct sock *ssk, const struct mptcp_addr_info *info); |
| 1131 |
void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id); |
| 1132 |
void mptcp_event_pm_listener(const struct sock *ssk, |
| 1133 |
enum mptcp_event_type event); |
| 1134 |
bool mptcp_userspace_pm_active(const struct mptcp_sock *msk); |
| 1135 |
|
| 1136 |
void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow, |
| 1137 |
struct request_sock *req); |
| 1138 |
int mptcp_pm_genl_fill_addr(struct sk_buff *msg, |
| 1139 |
struct netlink_callback *cb, |
| 1140 |
struct mptcp_pm_addr_entry *entry); |
| 1141 |
|
| 1142 |
static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) |
| 1143 |
{ |
| 1144 |
return READ_ONCE(msk->pm.addr_signal) & |
| 1145 |
(BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO)); |
| 1146 |
} |
| 1147 |
|
| 1148 |
static inline bool mptcp_pm_should_add_signal_addr(struct mptcp_sock *msk) |
| 1149 |
{ |
| 1150 |
return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL); |
| 1151 |
} |
| 1152 |
|
| 1153 |
static inline bool mptcp_pm_should_add_signal_echo(struct mptcp_sock *msk) |
| 1154 |
{ |
| 1155 |
return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_ECHO); |
| 1156 |
} |
| 1157 |
|
| 1158 |
static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk) |
| 1159 |
{ |
| 1160 |
return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL); |
| 1161 |
} |
| 1162 |
|
| 1163 |
static inline bool mptcp_pm_is_userspace(const struct mptcp_sock *msk) |
| 1164 |
{ |
| 1165 |
return READ_ONCE(msk->pm.pm_type) == MPTCP_PM_TYPE_USERSPACE; |
| 1166 |
} |
| 1167 |
|
| 1168 |
static inline bool mptcp_pm_is_kernel(const struct mptcp_sock *msk) |
| 1169 |
{ |
| 1170 |
return READ_ONCE(msk->pm.pm_type) == MPTCP_PM_TYPE_KERNEL; |
| 1171 |
} |
| 1172 |
|
| 1173 |
static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port) |
| 1174 |
{ |
| 1175 |
u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE; |
| 1176 |
|
| 1177 |
if (family == AF_INET6) |
| 1178 |
len = TCPOLEN_MPTCP_ADD_ADDR6_BASE; |
| 1179 |
if (!echo) |
| 1180 |
len += MPTCPOPT_THMAC_LEN; |
| 1181 |
/* account for 2 trailing 'nop' options */ |
| 1182 |
if (port) |
| 1183 |
len += TCPOLEN_MPTCP_PORT_LEN + TCPOLEN_MPTCP_PORT_ALIGN; |
| 1184 |
|
| 1185 |
return len; |
| 1186 |
} |
| 1187 |
|
| 1188 |
static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list) |
| 1189 |
{ |
| 1190 |
if (rm_list->nr == 0 || rm_list->nr > MPTCP_RM_IDS_MAX) |
| 1191 |
return -EINVAL; |
| 1192 |
|
| 1193 |
return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1; |
| 1194 |
} |
| 1195 |
|
| 1196 |
bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, |
| 1197 |
unsigned int opt_size, unsigned int remaining, |
| 1198 |
struct mptcp_addr_info *addr, bool *echo, |
| 1199 |
bool *drop_other_suboptions); |
| 1200 |
bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, |
| 1201 |
struct mptcp_rm_list *rm_list); |
| 1202 |
int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); |
| 1203 |
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, |
| 1204 |
struct mptcp_pm_addr_entry *skc); |
| 1205 |
int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, |
| 1206 |
struct mptcp_pm_addr_entry *skc); |
| 1207 |
bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); |
| 1208 |
bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); |
| 1209 |
bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); |
| 1210 |
int mptcp_pm_nl_dump_addr(struct sk_buff *msg, |
| 1211 |
struct netlink_callback *cb); |
| 1212 |
int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, |
| 1213 |
struct netlink_callback *cb); |
| 1214 |
int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, |
| 1215 |
struct genl_info *info); |
| 1216 |
int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, |
| 1217 |
struct genl_info *info); |
| 1218 |
|
| 1219 |
static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) |
| 1220 |
{ |
| 1221 |
int local_id = READ_ONCE(subflow->local_id); |
| 1222 |
|
| 1223 |
if (local_id < 0) |
| 1224 |
return 0; |
| 1225 |
return local_id; |
| 1226 |
} |
| 1227 |
|
| 1228 |
void __init mptcp_pm_kernel_register(void); |
| 1229 |
void __init mptcp_pm_userspace_register(void); |
| 1230 |
void __init mptcp_pm_nl_init(void); |
| 1231 |
void mptcp_pm_worker(struct mptcp_sock *msk); |
| 1232 |
void __mptcp_pm_kernel_worker(struct mptcp_sock *msk); |
| 1233 |
u8 mptcp_pm_get_endp_signal_max(const struct mptcp_sock *msk); |
| 1234 |
u8 mptcp_pm_get_endp_subflow_max(const struct mptcp_sock *msk); |
| 1235 |
u8 mptcp_pm_get_endp_laminar_max(const struct mptcp_sock *msk); |
| 1236 |
u8 mptcp_pm_get_endp_fullmesh_max(const struct mptcp_sock *msk); |
| 1237 |
u8 mptcp_pm_get_limit_add_addr_accepted(const struct mptcp_sock *msk); |
| 1238 |
u8 mptcp_pm_get_limit_extra_subflows(const struct mptcp_sock *msk); |
| 1239 |
|
| 1240 |
/* called under PM lock */ |
| 1241 |
static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk) |
| 1242 |
{ |
| 1243 |
if (--msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk)) |
| 1244 |
WRITE_ONCE(msk->pm.accept_subflow, true); |
| 1245 |
} |
| 1246 |
|
| 1247 |
static inline void mptcp_pm_close_subflow(struct mptcp_sock *msk) |
| 1248 |
{ |
| 1249 |
spin_lock_bh(&msk->pm.lock); |
| 1250 |
__mptcp_pm_close_subflow(msk); |
| 1251 |
spin_unlock_bh(&msk->pm.lock); |
| 1252 |
} |
| 1253 |
|
| 1254 |
static inline bool mptcp_pm_add_addr_c_flag_case(struct mptcp_sock *msk) |
| 1255 |
{ |
| 1256 |
return READ_ONCE(msk->pm.remote_deny_join_id0) && |
| 1257 |
msk->pm.local_addr_used == 0 && |
| 1258 |
mptcp_pm_get_limit_add_addr_accepted(msk) == 0 && |
| 1259 |
msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk); |
| 1260 |
} |
| 1261 |
|
| 1262 |
void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk); |
| 1263 |
|
| 1264 |
static inline struct mptcp_ext *mptcp_get_ext(const struct sk_buff *skb) |
| 1265 |
{ |
| 1266 |
return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); |
| 1267 |
} |
| 1268 |
|
| 1269 |
void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops); |
| 1270 |
|
| 1271 |
static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk) |
| 1272 |
{ |
| 1273 |
return test_bit(MPTCP_FALLBACK_DONE, &msk->flags); |
| 1274 |
} |
| 1275 |
|
| 1276 |
static inline bool mptcp_check_fallback(const struct sock *sk) |
| 1277 |
{ |
| 1278 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 1279 |
struct mptcp_sock *msk = mptcp_sk(subflow->conn); |
| 1280 |
|
| 1281 |
return __mptcp_check_fallback(msk); |
| 1282 |
} |
| 1283 |
|
| 1284 |
static inline bool __mptcp_has_initial_subflow(const struct mptcp_sock *msk) |
| 1285 |
{ |
| 1286 |
struct sock *ssk = READ_ONCE(msk->first); |
| 1287 |
|
| 1288 |
return ssk && ((1 << inet_sk_state_load(ssk)) & |
| 1289 |
(TCPF_ESTABLISHED | TCPF_SYN_SENT | |
| 1290 |
TCPF_SYN_RECV | TCPF_LISTEN)); |
| 1291 |
} |
| 1292 |
|
| 1293 |
bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib); |
| 1294 |
|
| 1295 |
static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib) |
| 1296 |
{ |
| 1297 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); |
| 1298 |
struct sock *sk = subflow->conn; |
| 1299 |
struct mptcp_sock *msk; |
| 1300 |
|
| 1301 |
msk = mptcp_sk(sk); |
| 1302 |
if (!__mptcp_try_fallback(msk, fb_mib)) |
| 1303 |
return false; |
| 1304 |
if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUTDOWN)) { |
| 1305 |
gfp_t saved_allocation = ssk->sk_allocation; |
| 1306 |
|
| 1307 |
/* we are in a atomic (BH) scope, override ssk default for data |
| 1308 |
* fin allocation |
| 1309 |
*/ |
| 1310 |
ssk->sk_allocation = GFP_ATOMIC; |
| 1311 |
ssk->sk_shutdown |= SEND_SHUTDOWN; |
| 1312 |
tcp_shutdown(ssk, SEND_SHUTDOWN); |
| 1313 |
ssk->sk_allocation = saved_allocation; |
| 1314 |
} |
| 1315 |
return true; |
| 1316 |
} |
| 1317 |
|
| 1318 |
static inline void mptcp_early_fallback(struct mptcp_sock *msk, |
| 1319 |
struct mptcp_subflow_context *subflow, |
| 1320 |
int fb_mib) |
| 1321 |
{ |
| 1322 |
subflow->request_mptcp = 0; |
| 1323 |
WARN_ON_ONCE(!__mptcp_try_fallback(msk, fb_mib)); |
| 1324 |
} |
| 1325 |
|
| 1326 |
static inline bool mptcp_check_infinite_map(struct sk_buff *skb) |
| 1327 |
{ |
| 1328 |
struct mptcp_ext *mpext; |
| 1329 |
|
| 1330 |
mpext = skb ? mptcp_get_ext(skb) : NULL; |
| 1331 |
if (mpext && mpext->infinite_map) |
| 1332 |
return true; |
| 1333 |
|
| 1334 |
return false; |
| 1335 |
} |
| 1336 |
|
| 1337 |
static inline bool is_active_ssk(struct mptcp_subflow_context *subflow) |
| 1338 |
{ |
| 1339 |
return (subflow->request_mptcp || subflow->request_join); |
| 1340 |
} |
| 1341 |
|
| 1342 |
static inline bool subflow_simultaneous_connect(struct sock *sk) |
| 1343 |
{ |
| 1344 |
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); |
| 1345 |
|
| 1346 |
/* Note that the sk state implies !subflow->conn_finished. */ |
| 1347 |
return sk->sk_state == TCP_SYN_RECV && is_active_ssk(subflow); |
| 1348 |
} |
| 1349 |
|
| 1350 |
#ifdef CONFIG_SYN_COOKIES |
| 1351 |
void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req, |
| 1352 |
struct sk_buff *skb); |
| 1353 |
bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req, |
| 1354 |
struct sk_buff *skb); |
| 1355 |
void __init mptcp_join_cookie_init(void); |
| 1356 |
#else |
| 1357 |
static inline void |
| 1358 |
subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req, |
| 1359 |
struct sk_buff *skb) {} |
| 1360 |
static inline bool |
| 1361 |
mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req, |
| 1362 |
struct sk_buff *skb) |
| 1363 |
{ |
| 1364 |
return false; |
| 1365 |
} |
| 1366 |
|
| 1367 |
static inline void mptcp_join_cookie_init(void) {} |
| 1368 |
#endif |
| 1369 |
|
| 1370 |
#endif /* __MPTCP_PROTOCOL_H */ |