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 | eda7acd | 2020-01-21 16:56:16 -0800 | [diff] [blame] | 10 | #define MPTCP_SUPPORTED_VERSION 0 |
| 11 | |
| 12 | /* MPTCP option bits */ |
| 13 | #define OPTION_MPTCP_MPC_SYN BIT(0) |
| 14 | #define OPTION_MPTCP_MPC_SYNACK BIT(1) |
| 15 | #define OPTION_MPTCP_MPC_ACK BIT(2) |
| 16 | |
| 17 | /* MPTCP option subtypes */ |
| 18 | #define MPTCPOPT_MP_CAPABLE 0 |
| 19 | #define MPTCPOPT_MP_JOIN 1 |
| 20 | #define MPTCPOPT_DSS 2 |
| 21 | #define MPTCPOPT_ADD_ADDR 3 |
| 22 | #define MPTCPOPT_RM_ADDR 4 |
| 23 | #define MPTCPOPT_MP_PRIO 5 |
| 24 | #define MPTCPOPT_MP_FAIL 6 |
| 25 | #define MPTCPOPT_MP_FASTCLOSE 7 |
| 26 | |
| 27 | /* MPTCP suboption lengths */ |
| 28 | #define TCPOLEN_MPTCP_MPC_SYN 12 |
| 29 | #define TCPOLEN_MPTCP_MPC_SYNACK 12 |
| 30 | #define TCPOLEN_MPTCP_MPC_ACK 20 |
| 31 | |
| 32 | /* MPTCP MP_CAPABLE flags */ |
| 33 | #define MPTCP_VERSION_MASK (0x0F) |
| 34 | #define MPTCP_CAP_CHECKSUM_REQD BIT(7) |
| 35 | #define MPTCP_CAP_EXTENSIBILITY BIT(6) |
| 36 | #define MPTCP_CAP_HMAC_SHA1 BIT(0) |
| 37 | #define MPTCP_CAP_FLAG_MASK (0x3F) |
| 38 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 39 | /* MPTCP connection sock */ |
| 40 | struct mptcp_sock { |
| 41 | /* inet_connection_sock must be the first member */ |
| 42 | struct inet_connection_sock sk; |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 43 | u64 local_key; |
| 44 | u64 remote_key; |
| 45 | struct list_head conn_list; |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 46 | struct socket *subflow; /* outgoing connect/listener/!mp_capable */ |
| 47 | }; |
| 48 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 49 | #define mptcp_for_each_subflow(__msk, __subflow) \ |
| 50 | list_for_each_entry(__subflow, &((__msk)->conn_list), node) |
| 51 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 52 | static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) |
| 53 | { |
| 54 | return (struct mptcp_sock *)sk; |
| 55 | } |
| 56 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 57 | struct mptcp_subflow_request_sock { |
| 58 | struct tcp_request_sock sk; |
| 59 | u8 mp_capable : 1, |
| 60 | mp_join : 1, |
| 61 | backup : 1; |
| 62 | u64 local_key; |
| 63 | u64 remote_key; |
| 64 | }; |
| 65 | |
| 66 | static inline struct mptcp_subflow_request_sock * |
| 67 | mptcp_subflow_rsk(const struct request_sock *rsk) |
| 68 | { |
| 69 | return (struct mptcp_subflow_request_sock *)rsk; |
| 70 | } |
| 71 | |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 72 | /* MPTCP subflow context */ |
| 73 | struct mptcp_subflow_context { |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 74 | struct list_head node;/* conn_list of subflows */ |
| 75 | u64 local_key; |
| 76 | u64 remote_key; |
| 77 | u32 request_mptcp : 1, /* send MP_CAPABLE */ |
| 78 | mp_capable : 1, /* remote is MPTCP capable */ |
| 79 | fourth_ack : 1, /* send initial DSS */ |
| 80 | conn_finished : 1; |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 81 | struct sock *tcp_sock; /* tcp sk backpointer */ |
| 82 | struct sock *conn; /* parent mptcp_sock */ |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 83 | const struct inet_connection_sock_af_ops *icsk_af_ops; |
Peter Krystad | 2303f99 | 2020-01-21 16:56:17 -0800 | [diff] [blame] | 84 | struct rcu_head rcu; |
| 85 | }; |
| 86 | |
| 87 | static inline struct mptcp_subflow_context * |
| 88 | mptcp_subflow_ctx(const struct sock *sk) |
| 89 | { |
| 90 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 91 | |
| 92 | /* Use RCU on icsk_ulp_data only for sock diag code */ |
| 93 | return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data; |
| 94 | } |
| 95 | |
| 96 | static inline struct sock * |
| 97 | mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) |
| 98 | { |
| 99 | return subflow->tcp_sock; |
| 100 | } |
| 101 | |
| 102 | void mptcp_subflow_init(void); |
| 103 | int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock); |
| 104 | |
Peter Krystad | cec37a6 | 2020-01-21 16:56:18 -0800 | [diff] [blame^] | 105 | extern const struct inet_connection_sock_af_ops ipv4_specific; |
| 106 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) |
| 107 | extern const struct inet_connection_sock_af_ops ipv6_specific; |
| 108 | #endif |
| 109 | |
| 110 | void mptcp_get_options(const struct sk_buff *skb, |
| 111 | struct tcp_options_received *opt_rx); |
| 112 | |
| 113 | void mptcp_finish_connect(struct sock *sk); |
| 114 | |
Mat Martineau | f870fa0 | 2020-01-21 16:56:15 -0800 | [diff] [blame] | 115 | #endif /* __MPTCP_PROTOCOL_H */ |