protocol.h 18.6 KB
Newer Older
M
Mat Martineau 已提交
1 2 3 4 5 6 7 8 9
/* SPDX-License-Identifier: GPL-2.0 */
/* Multipath TCP
 *
 * Copyright (c) 2017 - 2019, Intel Corporation.
 */

#ifndef __MPTCP_PROTOCOL_H
#define __MPTCP_PROTOCOL_H

10 11 12 13
#include <linux/random.h>
#include <net/tcp.h>
#include <net/inet_connection_sock.h>

14
#define MPTCP_SUPPORTED_VERSION	1
P
Peter Krystad 已提交
15 16 17 18 19

/* MPTCP option bits */
#define OPTION_MPTCP_MPC_SYN	BIT(0)
#define OPTION_MPTCP_MPC_SYNACK	BIT(1)
#define OPTION_MPTCP_MPC_ACK	BIT(2)
20 21 22
#define OPTION_MPTCP_MPJ_SYN	BIT(3)
#define OPTION_MPTCP_MPJ_SYNACK	BIT(4)
#define OPTION_MPTCP_MPJ_ACK	BIT(5)
P
Peter Krystad 已提交
23 24 25
#define OPTION_MPTCP_ADD_ADDR	BIT(6)
#define OPTION_MPTCP_ADD_ADDR6	BIT(7)
#define OPTION_MPTCP_RM_ADDR	BIT(8)
P
Peter Krystad 已提交
26 27 28 29 30 31 32 33 34 35 36 37

/* MPTCP option subtypes */
#define MPTCPOPT_MP_CAPABLE	0
#define MPTCPOPT_MP_JOIN	1
#define MPTCPOPT_DSS		2
#define MPTCPOPT_ADD_ADDR	3
#define MPTCPOPT_RM_ADDR	4
#define MPTCPOPT_MP_PRIO	5
#define MPTCPOPT_MP_FAIL	6
#define MPTCPOPT_MP_FASTCLOSE	7

/* MPTCP suboption lengths */
38
#define TCPOLEN_MPTCP_MPC_SYN		4
P
Peter Krystad 已提交
39 40
#define TCPOLEN_MPTCP_MPC_SYNACK	12
#define TCPOLEN_MPTCP_MPC_ACK		20
41
#define TCPOLEN_MPTCP_MPC_ACK_DATA	22
42 43 44
#define TCPOLEN_MPTCP_MPJ_SYN		12
#define TCPOLEN_MPTCP_MPJ_SYNACK	16
#define TCPOLEN_MPTCP_MPJ_ACK		24
45
#define TCPOLEN_MPTCP_DSS_BASE		4
46
#define TCPOLEN_MPTCP_DSS_ACK32		4
47
#define TCPOLEN_MPTCP_DSS_ACK64		8
48
#define TCPOLEN_MPTCP_DSS_MAP32		10
49 50
#define TCPOLEN_MPTCP_DSS_MAP64		14
#define TCPOLEN_MPTCP_DSS_CHECKSUM	2
P
Peter Krystad 已提交
51 52 53 54 55 56 57 58 59 60
#define TCPOLEN_MPTCP_ADD_ADDR		16
#define TCPOLEN_MPTCP_ADD_ADDR_PORT	18
#define TCPOLEN_MPTCP_ADD_ADDR_BASE	8
#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT	10
#define TCPOLEN_MPTCP_ADD_ADDR6		28
#define TCPOLEN_MPTCP_ADD_ADDR6_PORT	30
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	22
#define TCPOLEN_MPTCP_PORT_LEN		2
#define TCPOLEN_MPTCP_RM_ADDR_BASE	4
P
Peter Krystad 已提交
61

62
/* MPTCP MP_JOIN flags */
63 64
#define MPTCPOPT_BACKUP		BIT(0)
#define MPTCPOPT_HMAC_LEN	20
65
#define MPTCPOPT_THMAC_LEN	8
66

P
Peter Krystad 已提交
67 68 69 70
/* MPTCP MP_CAPABLE flags */
#define MPTCP_VERSION_MASK	(0x0F)
#define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
#define MPTCP_CAP_EXTENSIBILITY	BIT(6)
71
#define MPTCP_CAP_HMAC_SHA256	BIT(0)
P
Peter Krystad 已提交
72 73
#define MPTCP_CAP_FLAG_MASK	(0x3F)

74 75 76 77 78 79
/* MPTCP DSS flags */
#define MPTCP_DSS_DATA_FIN	BIT(4)
#define MPTCP_DSS_DSN64		BIT(3)
#define MPTCP_DSS_HAS_MAP	BIT(2)
#define MPTCP_DSS_ACK64		BIT(1)
#define MPTCP_DSS_HAS_ACK	BIT(0)
80 81
#define MPTCP_DSS_FLAG_MASK	(0x1F)

P
Peter Krystad 已提交
82 83 84 85 86
/* MPTCP ADD_ADDR flags */
#define MPTCP_ADDR_ECHO		BIT(0)
#define MPTCP_ADDR_IPVERSION_4	4
#define MPTCP_ADDR_IPVERSION_6	6

87
/* MPTCP socket flags */
88
#define MPTCP_DATA_READY	0
89
#define MPTCP_NOSPACE		1
90
#define MPTCP_WORK_RTX		2
91
#define MPTCP_WORK_EOF		3
92
#define MPTCP_FALLBACK_DONE	4
P
Paolo Abeni 已提交
93
#define MPTCP_WORK_CLOSE_SUBFLOW 5
94

P
Paolo Abeni 已提交
95 96 97 98 99 100 101
static inline bool before64(__u64 seq1, __u64 seq2)
{
	return (__s64)(seq1 - seq2) < 0;
}

#define after64(seq2, seq1)	before64(seq1, seq2)

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
struct mptcp_options_received {
	u64	sndr_key;
	u64	rcvr_key;
	u64	data_ack;
	u64	data_seq;
	u32	subflow_seq;
	u16	data_len;
	u16	mp_capable : 1,
		mp_join : 1,
		dss : 1,
		add_addr : 1,
		rm_addr : 1,
		family : 4,
		echo : 1,
		backup : 1;
	u32	token;
	u32	nonce;
	u64	thmac;
	u8	hmac[20];
	u8	join_id;
	u8	use_map:1,
		dsn64:1,
		data_fin:1,
		use_ack:1,
		ack64:1,
		mpc_map:1,
		__unused:2;
	u8	addr_id;
	u8	rm_id;
	union {
		struct in_addr	addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
		struct in6_addr	addr6;
#endif
	};
	u64	ahmac;
	u16	port;
};

P
Peter Krystad 已提交
141 142 143 144 145 146
static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
{
	return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) |
		     ((nib & 0xF) << 8) | field);
}

147 148 149 150
struct mptcp_addr_info {
	sa_family_t		family;
	__be16			port;
	u8			id;
151 152
	u8			flags;
	int			ifindex;
153 154 155 156 157 158 159 160 161 162
	union {
		struct in_addr addr;
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
		struct in6_addr addr6;
#endif
	};
};

enum mptcp_pm_status {
	MPTCP_PM_ADD_ADDR_RECEIVED,
163
	MPTCP_PM_ADD_ADDR_SEND_ACK,
164
	MPTCP_PM_RM_ADDR_RECEIVED,
165 166 167 168
	MPTCP_PM_ESTABLISHED,
	MPTCP_PM_SUBFLOW_ESTABLISHED,
};

G
Geliang Tang 已提交
169 170 171
enum mptcp_add_addr_status {
	MPTCP_ADD_ADDR_SIGNAL,
	MPTCP_ADD_ADDR_ECHO,
172
	MPTCP_ADD_ADDR_IPV6,
G
Geliang Tang 已提交
173 174
};

175 176 177
struct mptcp_pm_data {
	struct mptcp_addr_info local;
	struct mptcp_addr_info remote;
178
	struct list_head anno_list;
179 180 181

	spinlock_t	lock;		/*protects the whole PM data */

G
Geliang Tang 已提交
182
	u8		add_addr_signal;
183
	bool		rm_addr_signal;
184 185 186 187 188 189 190 191 192 193 194 195 196
	bool		server_side;
	bool		work_pending;
	bool		accept_addr;
	bool		accept_subflow;
	u8		add_addr_signaled;
	u8		add_addr_accepted;
	u8		local_addr_used;
	u8		subflows;
	u8		add_addr_signal_max;
	u8		add_addr_accept_max;
	u8		local_addr_max;
	u8		subflows_max;
	u8		status;
197
	u8		rm_id;
198 199
};

200 201 202
struct mptcp_data_frag {
	struct list_head list;
	u64 data_seq;
203 204 205 206
	u16 data_len;
	u16 offset;
	u16 overhead;
	u16 already_sent;
207 208 209
	struct page *page;
};

M
Mat Martineau 已提交
210 211 212 213
/* MPTCP connection sock */
struct mptcp_sock {
	/* inet_connection_sock must be the first member */
	struct inet_connection_sock sk;
214 215
	u64		local_key;
	u64		remote_key;
216
	u64		write_seq;
P
Paolo Abeni 已提交
217
	u64		snd_nxt;
218
	u64		ack_seq;
219
	u64		rcv_wnd_sent;
220
	u64		rcv_data_fin_seq;
P
Paolo Abeni 已提交
221
	int		wmem_reserved;
222 223
	struct sock	*last_snd;
	int		snd_burst;
224
	int		old_wspace;
225 226
	u64		snd_una;
	u64		wnd_end;
227
	unsigned long	timer_ival;
228
	u32		token;
229
	int		rmem_pending;
230
	int		rmem_released;
231
	unsigned long	flags;
232
	bool		can_ack;
233
	bool		fully_established;
234
	bool		rcv_data_fin;
235
	bool		snd_data_fin_enable;
236
	bool		use_64bit_ack; /* Set when we received a 64-bit DSN */
237
	spinlock_t	join_list_lock;
238
	struct sock	*ack_hint;
P
Paolo Abeni 已提交
239
	struct work_struct work;
240 241
	struct sk_buff  *ooo_last_skb;
	struct rb_root  out_of_order_queue;
242
	struct sk_buff_head receive_queue;
243 244 245
	struct sk_buff_head skb_tx_cache;	/* this is wmem accounted */
	int		tx_pending_data;
	int		size_goal_cache;
246
	struct list_head conn_list;
247
	struct list_head rtx_queue;
248
	struct mptcp_data_frag *first_pending;
249
	struct list_head join_list;
M
Mat Martineau 已提交
250
	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
251
	struct sock	*first;
252
	struct mptcp_pm_data	pm;
253 254 255 256 257 258
	struct {
		u32	space;	/* bytes copied in last measurement window */
		u32	copied; /* bytes copied in this measurement window */
		u64	time;	/* start time of measurement window */
		u64	rtt_us; /* last maximum rtt of subflows */
	} rcvq_space;
M
Mat Martineau 已提交
259 260
};

261 262 263 264 265 266 267 268 269 270 271 272 273
#define mptcp_lock_sock(___sk, cb) do {					\
	struct sock *__sk = (___sk); /* silence macro reuse warning */	\
	might_sleep();							\
	spin_lock_bh(&__sk->sk_lock.slock);				\
	if (__sk->sk_lock.owned)					\
		__lock_sock(__sk);					\
	cb;								\
	__sk->sk_lock.owned = 1;					\
	spin_unlock(&__sk->sk_lock.slock);				\
	mutex_acquire(&__sk->sk_lock.dep_map, 0, 0, _RET_IP_);		\
	local_bh_enable();						\
} while (0)

274 275 276
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
#define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock)

277 278 279
#define mptcp_for_each_subflow(__msk, __subflow)			\
	list_for_each_entry(__subflow, &((__msk)->conn_list), node)

M
Mat Martineau 已提交
280 281 282 283 284
static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
{
	return (struct mptcp_sock *)sk;
}

285 286 287 288 289
static inline int __mptcp_space(const struct sock *sk)
{
	return tcp_space(sk) + READ_ONCE(mptcp_sk(sk)->rmem_pending);
}

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk)
{
	const struct mptcp_sock *msk = mptcp_sk(sk);

	return READ_ONCE(msk->first_pending);
}

static inline struct mptcp_data_frag *mptcp_send_next(struct sock *sk)
{
	struct mptcp_sock *msk = mptcp_sk(sk);
	struct mptcp_data_frag *cur;

	cur = msk->first_pending;
	return list_is_last(&cur->list, &msk->rtx_queue) ? NULL :
						     list_next_entry(cur, list);
}

static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk)
{
	struct mptcp_sock *msk = mptcp_sk(sk);

	if (!msk->first_pending)
		return NULL;

	if (WARN_ON_ONCE(list_empty(&msk->rtx_queue)))
		return NULL;

	return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
}

320 321 322 323
static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk)
{
	struct mptcp_sock *msk = mptcp_sk(sk);

324
	if (!before64(msk->snd_nxt, READ_ONCE(msk->snd_una)))
325 326 327 328 329
		return NULL;

	return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
}

330 331 332 333
static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk)
{
	struct mptcp_sock *msk = mptcp_sk(sk);

334
	return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list);
335 336
}

337 338
struct mptcp_subflow_request_sock {
	struct	tcp_request_sock sk;
339
	u16	mp_capable : 1,
340
		mp_join : 1,
341
		backup : 1;
342
	u8	local_id;
343
	u8	remote_id;
344
	u64	local_key;
345 346
	u64	idsn;
	u32	token;
347
	u32	ssn_offset;
348 349 350
	u64	thmac;
	u32	local_nonce;
	u32	remote_nonce;
351
	struct mptcp_sock	*msk;
P
Paolo Abeni 已提交
352
	struct hlist_nulls_node token_node;
353 354 355 356 357 358 359 360
};

static inline struct mptcp_subflow_request_sock *
mptcp_subflow_rsk(const struct request_sock *rsk)
{
	return (struct mptcp_subflow_request_sock *)rsk;
}

361 362 363 364 365 366
enum mptcp_data_avail {
	MPTCP_SUBFLOW_NODATA,
	MPTCP_SUBFLOW_DATA_AVAIL,
	MPTCP_SUBFLOW_OOO_DATA
};

367 368
/* MPTCP subflow context */
struct mptcp_subflow_context {
369 370 371
	struct	list_head node;/* conn_list of subflows */
	u64	local_key;
	u64	remote_key;
372
	u64	idsn;
373
	u64	map_seq;
374
	u32	snd_isn;
375
	u32	token;
376
	u32	rel_write_seq;
377 378 379
	u32	map_subflow_seq;
	u32	ssn_offset;
	u32	map_data_len;
380
	u32	request_mptcp : 1,  /* send MP_CAPABLE */
381 382
		request_join : 1,   /* send MP_JOIN */
		request_bkup : 1,
383
		mp_capable : 1,	    /* remote is MPTCP capable */
384
		mp_join : 1,	    /* remote is JOINing */
P
Paolo Abeni 已提交
385
		fully_established : 1,	    /* path validated */
386
		pm_notified : 1,    /* PM hook called for established status */
387 388
		conn_finished : 1,
		map_valid : 1,
389
		mpc_map : 1,
390
		backup : 1,
391
		rx_eof : 1,
P
Paolo Abeni 已提交
392 393
		can_ack : 1,        /* only after processing the remote a key */
		disposable : 1;	    /* ctx can be free at ulp release time */
394
	enum mptcp_data_avail data_avail;
395 396 397
	u32	remote_nonce;
	u64	thmac;
	u32	local_nonce;
398 399
	u32	remote_token;
	u8	hmac[MPTCPOPT_HMAC_LEN];
400 401
	u8	local_id;
	u8	remote_id;
402

403 404
	struct	sock *tcp_sock;	    /* tcp sk backpointer */
	struct	sock *conn;	    /* parent mptcp_sock */
405
	const	struct inet_connection_sock_af_ops *icsk_af_ops;
406 407 408 409
	void	(*tcp_data_ready)(struct sock *sk);
	void	(*tcp_state_change)(struct sock *sk);
	void	(*tcp_write_space)(struct sock *sk);

410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
	struct	rcu_head rcu;
};

static inline struct mptcp_subflow_context *
mptcp_subflow_ctx(const struct sock *sk)
{
	struct inet_connection_sock *icsk = inet_csk(sk);

	/* Use RCU on icsk_ulp_data only for sock diag code */
	return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;
}

static inline struct sock *
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
{
	return subflow->tcp_sock;
}

428 429 430 431 432 433 434 435 436 437 438 439 440 441
static inline u64
mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow)
{
	return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq -
		      subflow->ssn_offset -
		      subflow->map_subflow_seq;
}

static inline u64
mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
{
	return subflow->map_seq + mptcp_subflow_get_map_offset(subflow);
}

442 443 444 445 446 447 448 449 450
static inline void mptcp_add_pending_subflow(struct mptcp_sock *msk,
					     struct mptcp_subflow_context *subflow)
{
	sock_hold(mptcp_subflow_tcp_sock(subflow));
	spin_lock_bh(&msk->join_list_lock);
	list_add_tail(&subflow->node, &msk->join_list);
	spin_unlock_bh(&msk->join_list_lock);
}

451
int mptcp_is_enabled(struct net *net);
452
unsigned int mptcp_get_add_addr_timeout(struct net *net);
453 454
void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
				     struct mptcp_options_received *mp_opt);
455
bool mptcp_subflow_data_available(struct sock *sk);
456
void __init mptcp_subflow_init(void);
457 458
void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);
void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
P
Paolo Abeni 已提交
459
		       struct mptcp_subflow_context *subflow);
460
void mptcp_subflow_reset(struct sock *ssk);
461 462

/* called with sk socket lock held */
463
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
464
			    const struct mptcp_addr_info *remote);
465 466
int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);

467 468 469 470 471 472 473 474 475 476
static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
					      struct mptcp_subflow_context *ctx)
{
	sk->sk_data_ready = ctx->tcp_data_ready;
	sk->sk_state_change = ctx->tcp_state_change;
	sk->sk_write_space = ctx->tcp_write_space;

	inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
}

477
void __init mptcp_proto_init(void);
478
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
479
int __init mptcp_proto_v6_init(void);
480
#endif
481

482
struct sock *mptcp_sk_clone(const struct sock *sk,
483
			    const struct mptcp_options_received *mp_opt,
484
			    struct request_sock *req);
485
void mptcp_get_options(const struct sk_buff *skb,
486
		       struct mptcp_options_received *mp_opt);
487 488

void mptcp_finish_connect(struct sock *sk);
489 490 491 492 493
static inline bool mptcp_is_fully_established(struct sock *sk)
{
	return inet_sk_state_load(sk) == TCP_ESTABLISHED &&
	       READ_ONCE(mptcp_sk(sk)->fully_established);
}
494
void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk);
495
void mptcp_data_ready(struct sock *sk, struct sock *ssk);
496
bool mptcp_finish_join(struct sock *sk);
P
Paolo Abeni 已提交
497
bool mptcp_schedule_work(struct sock *sk);
498
void __mptcp_data_acked(struct sock *sk);
499
void mptcp_subflow_eof(struct sock *sk);
500
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit);
501
void __mptcp_flush_join_list(struct mptcp_sock *msk);
P
Paolo Abeni 已提交
502 503 504 505 506 507
static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk)
{
	return READ_ONCE(msk->snd_data_fin_enable) &&
	       READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt);
}

508
void mptcp_destroy_common(struct mptcp_sock *msk);
509

P
Paolo Abeni 已提交
510 511 512 513 514 515
void __init mptcp_token_init(void);
static inline void mptcp_token_init_request(struct request_sock *req)
{
	mptcp_subflow_rsk(req)->token_node.pprev = NULL;
}

516
int mptcp_token_new_request(struct request_sock *req);
P
Paolo Abeni 已提交
517
void mptcp_token_destroy_request(struct request_sock *req);
518
int mptcp_token_new_connect(struct sock *sk);
P
Paolo Abeni 已提交
519 520
void mptcp_token_accept(struct mptcp_subflow_request_sock *r,
			struct mptcp_sock *msk);
521
bool mptcp_token_exists(u32 token);
522
struct mptcp_sock *mptcp_token_get_sock(u32 token);
P
Paolo Abeni 已提交
523 524
struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
					 long *s_num);
P
Paolo Abeni 已提交
525
void mptcp_token_destroy(struct mptcp_sock *msk);
526 527 528

void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);

P
Peter Krystad 已提交
529
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
530

531
void __init mptcp_pm_init(void);
532 533 534 535 536 537 538 539 540 541
void mptcp_pm_data_init(struct mptcp_sock *msk);
void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side);
void mptcp_pm_fully_established(struct mptcp_sock *msk);
bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk);
void mptcp_pm_connection_closed(struct mptcp_sock *msk);
void mptcp_pm_subflow_established(struct mptcp_sock *msk,
				  struct mptcp_subflow_context *subflow);
void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id);
void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
				const struct mptcp_addr_info *addr);
542
void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk);
543
void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id);
544
void mptcp_pm_free_anno_list(struct mptcp_sock *msk);
545 546 547
struct mptcp_pm_add_entry *
mptcp_pm_del_add_timer(struct mptcp_sock *msk,
		       struct mptcp_addr_info *addr);
548 549

int mptcp_pm_announce_addr(struct mptcp_sock *msk,
550 551
			   const struct mptcp_addr_info *addr,
			   bool echo);
552
int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
553
int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
554

555
static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
556
{
G
Geliang Tang 已提交
557 558 559 560 561 562
	return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL);
}

static inline bool mptcp_pm_should_add_signal_echo(struct mptcp_sock *msk)
{
	return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_ECHO);
563 564
}

565 566 567 568 569
static inline bool mptcp_pm_should_add_signal_ipv6(struct mptcp_sock *msk)
{
	return READ_ONCE(msk->pm.add_addr_signal) & BIT(MPTCP_ADD_ADDR_IPV6);
}

570 571 572 573 574
static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
{
	return READ_ONCE(msk->pm.rm_addr_signal);
}

575
static inline unsigned int mptcp_add_addr_len(int family, bool echo)
576 577
{
	if (family == AF_INET)
578 579 580
		return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE
			    : TCPOLEN_MPTCP_ADD_ADDR;
	return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6;
581 582
}

583
bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
584
			      struct mptcp_addr_info *saddr, bool *echo);
585 586
bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
			     u8 *rm_id);
587 588
int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

589
void __init mptcp_pm_nl_init(void);
P
Paolo Abeni 已提交
590 591 592 593
void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk);
594
void mptcp_pm_nl_add_addr_send_ack(struct mptcp_sock *msk);
595
void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk);
596
void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id);
P
Paolo Abeni 已提交
597 598
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

599 600 601 602 603
static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
{
	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
}

604 605
void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops);

606
static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk)
607 608 609 610
{
	return test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
}

611
static inline bool mptcp_check_fallback(const struct sock *sk)
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
{
	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
	struct mptcp_sock *msk = mptcp_sk(subflow->conn);

	return __mptcp_check_fallback(msk);
}

static inline void __mptcp_do_fallback(struct mptcp_sock *msk)
{
	if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags)) {
		pr_debug("TCP fallback already done (msk=%p)", msk);
		return;
	}
	set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
}

static inline void mptcp_do_fallback(struct sock *sk)
{
	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
	struct mptcp_sock *msk = mptcp_sk(subflow->conn);

	__mptcp_do_fallback(msk);
}

#define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=%p)", __func__, a)

638 639 640 641 642 643 644 645 646 647
static inline bool subflow_simultaneous_connect(struct sock *sk)
{
	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
	struct sock *parent = subflow->conn;

	return sk->sk_state == TCP_ESTABLISHED &&
	       !mptcp_sk(parent)->pm.server_side &&
	       !subflow->conn_finished;
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
#ifdef CONFIG_SYN_COOKIES
void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
				       struct sk_buff *skb);
bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
					struct sk_buff *skb);
void __init mptcp_join_cookie_init(void);
#else
static inline void
subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
				  struct sk_buff *skb) {}
static inline bool
mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
				   struct sk_buff *skb)
{
	return false;
}

static inline void mptcp_join_cookie_init(void) {}
#endif

M
Mat Martineau 已提交
668
#endif /* __MPTCP_PROTOCOL_H */