2020-01-22 03:56:15 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Multipath TCP
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 - 2019, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MPTCP_PROTOCOL_H
|
|
|
|
#define __MPTCP_PROTOCOL_H
|
|
|
|
|
2020-01-22 03:56:20 +03:00
|
|
|
#include <linux/random.h>
|
|
|
|
#include <net/tcp.h>
|
|
|
|
#include <net/inet_connection_sock.h>
|
|
|
|
|
2020-01-22 03:56:16 +03:00
|
|
|
#define MPTCP_SUPPORTED_VERSION 0
|
|
|
|
|
|
|
|
/* MPTCP option bits */
|
|
|
|
#define OPTION_MPTCP_MPC_SYN BIT(0)
|
|
|
|
#define OPTION_MPTCP_MPC_SYNACK BIT(1)
|
|
|
|
#define OPTION_MPTCP_MPC_ACK BIT(2)
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
#define TCPOLEN_MPTCP_MPC_SYN 12
|
|
|
|
#define TCPOLEN_MPTCP_MPC_SYNACK 12
|
|
|
|
#define TCPOLEN_MPTCP_MPC_ACK 20
|
|
|
|
|
|
|
|
/* MPTCP MP_CAPABLE flags */
|
|
|
|
#define MPTCP_VERSION_MASK (0x0F)
|
|
|
|
#define MPTCP_CAP_CHECKSUM_REQD BIT(7)
|
|
|
|
#define MPTCP_CAP_EXTENSIBILITY BIT(6)
|
|
|
|
#define MPTCP_CAP_HMAC_SHA1 BIT(0)
|
|
|
|
#define MPTCP_CAP_FLAG_MASK (0x3F)
|
|
|
|
|
2020-01-22 03:56:15 +03:00
|
|
|
/* MPTCP connection sock */
|
|
|
|
struct mptcp_sock {
|
|
|
|
/* inet_connection_sock must be the first member */
|
|
|
|
struct inet_connection_sock sk;
|
2020-01-22 03:56:18 +03:00
|
|
|
u64 local_key;
|
|
|
|
u64 remote_key;
|
2020-01-22 03:56:20 +03:00
|
|
|
u32 token;
|
2020-01-22 03:56:18 +03:00
|
|
|
struct list_head conn_list;
|
2020-01-22 03:56:15 +03:00
|
|
|
struct socket *subflow; /* outgoing connect/listener/!mp_capable */
|
|
|
|
};
|
|
|
|
|
2020-01-22 03:56:18 +03:00
|
|
|
#define mptcp_for_each_subflow(__msk, __subflow) \
|
|
|
|
list_for_each_entry(__subflow, &((__msk)->conn_list), node)
|
|
|
|
|
2020-01-22 03:56:15 +03:00
|
|
|
static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct mptcp_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2020-01-22 03:56:18 +03:00
|
|
|
struct mptcp_subflow_request_sock {
|
|
|
|
struct tcp_request_sock sk;
|
|
|
|
u8 mp_capable : 1,
|
|
|
|
mp_join : 1,
|
|
|
|
backup : 1;
|
|
|
|
u64 local_key;
|
|
|
|
u64 remote_key;
|
2020-01-22 03:56:20 +03:00
|
|
|
u64 idsn;
|
|
|
|
u32 token;
|
2020-01-22 03:56:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct mptcp_subflow_request_sock *
|
|
|
|
mptcp_subflow_rsk(const struct request_sock *rsk)
|
|
|
|
{
|
|
|
|
return (struct mptcp_subflow_request_sock *)rsk;
|
|
|
|
}
|
|
|
|
|
2020-01-22 03:56:17 +03:00
|
|
|
/* MPTCP subflow context */
|
|
|
|
struct mptcp_subflow_context {
|
2020-01-22 03:56:18 +03:00
|
|
|
struct list_head node;/* conn_list of subflows */
|
|
|
|
u64 local_key;
|
|
|
|
u64 remote_key;
|
2020-01-22 03:56:20 +03:00
|
|
|
u64 idsn;
|
|
|
|
u32 token;
|
2020-01-22 03:56:18 +03:00
|
|
|
u32 request_mptcp : 1, /* send MP_CAPABLE */
|
|
|
|
mp_capable : 1, /* remote is MPTCP capable */
|
|
|
|
fourth_ack : 1, /* send initial DSS */
|
|
|
|
conn_finished : 1;
|
2020-01-22 03:56:17 +03:00
|
|
|
struct sock *tcp_sock; /* tcp sk backpointer */
|
|
|
|
struct sock *conn; /* parent mptcp_sock */
|
2020-01-22 03:56:18 +03:00
|
|
|
const struct inet_connection_sock_af_ops *icsk_af_ops;
|
2020-01-22 03:56:17 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mptcp_subflow_init(void);
|
|
|
|
int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
|
|
|
|
|
2020-01-22 03:56:18 +03:00
|
|
|
extern const struct inet_connection_sock_af_ops ipv4_specific;
|
|
|
|
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
|
|
|
extern const struct inet_connection_sock_af_ops ipv6_specific;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void mptcp_get_options(const struct sk_buff *skb,
|
|
|
|
struct tcp_options_received *opt_rx);
|
|
|
|
|
|
|
|
void mptcp_finish_connect(struct sock *sk);
|
|
|
|
|
2020-01-22 03:56:20 +03:00
|
|
|
int mptcp_token_new_request(struct request_sock *req);
|
|
|
|
void mptcp_token_destroy_request(u32 token);
|
|
|
|
int mptcp_token_new_connect(struct sock *sk);
|
|
|
|
int mptcp_token_new_accept(u32 token);
|
|
|
|
void mptcp_token_update_accept(struct sock *sk, struct sock *conn);
|
|
|
|
void mptcp_token_destroy(u32 token);
|
|
|
|
|
|
|
|
void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
|
|
|
|
static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
|
|
|
|
{
|
|
|
|
/* we might consider a faster version that computes the key as a
|
|
|
|
* hash of some information available in the MPTCP socket. Use
|
|
|
|
* random data at the moment, as it's probably the safest option
|
|
|
|
* in case multiple sockets are opened in different namespaces at
|
|
|
|
* the same time.
|
|
|
|
*/
|
|
|
|
get_random_bytes(key, sizeof(u64));
|
|
|
|
mptcp_crypto_key_sha(*key, token, idsn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
|
|
|
|
u32 *hash_out);
|
|
|
|
|
2020-01-22 03:56:15 +03:00
|
|
|
#endif /* __MPTCP_PROTOCOL_H */
|