Commit | Line | Data |
---|---|---|
3ee17bc7 MM |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Multipath TCP | |
4 | * | |
5 | * Copyright (c) 2017 - 2019, Intel Corporation. | |
6 | */ | |
7 | ||
8 | #ifndef __NET_MPTCP_H | |
9 | #define __NET_MPTCP_H | |
10 | ||
85712484 | 11 | #include <linux/skbuff.h> |
eda7acdd | 12 | #include <linux/tcp.h> |
3ee17bc7 MM |
13 | #include <linux/types.h> |
14 | ||
15 | /* MPTCP sk_buff extension data */ | |
16 | struct mptcp_ext { | |
17 | u64 data_ack; | |
18 | u64 data_seq; | |
19 | u32 subflow_seq; | |
20 | u16 data_len; | |
21 | u8 use_map:1, | |
22 | dsn64:1, | |
23 | data_fin:1, | |
24 | use_ack:1, | |
25 | ack64:1, | |
cc7972ea CP |
26 | mpc_map:1, |
27 | __unused:2; | |
3ee17bc7 MM |
28 | /* one byte hole */ |
29 | }; | |
30 | ||
eda7acdd PK |
31 | struct mptcp_out_options { |
32 | #if IS_ENABLED(CONFIG_MPTCP) | |
33 | u16 suboptions; | |
34 | u64 sndr_key; | |
35 | u64 rcvr_key; | |
3df523ab PK |
36 | union { |
37 | struct in_addr addr; | |
38 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) | |
39 | struct in6_addr addr6; | |
40 | #endif | |
41 | }; | |
42 | u8 addr_id; | |
43 | u64 ahmac; | |
44 | u8 rm_id; | |
6d0060f6 | 45 | struct mptcp_ext ext_copy; |
eda7acdd PK |
46 | #endif |
47 | }; | |
48 | ||
85712484 MM |
49 | #ifdef CONFIG_MPTCP |
50 | ||
f870fa0b MM |
51 | void mptcp_init(void); |
52 | ||
cec37a6e PK |
53 | static inline bool sk_is_mptcp(const struct sock *sk) |
54 | { | |
55 | return tcp_sk(sk)->is_mptcp; | |
56 | } | |
57 | ||
58 | static inline bool rsk_is_mptcp(const struct request_sock *req) | |
59 | { | |
60 | return tcp_rsk(req)->is_mptcp; | |
61 | } | |
62 | ||
cc7972ea CP |
63 | void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr, |
64 | int opsize, struct tcp_options_received *opt_rx); | |
65 | bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, | |
66 | unsigned int *size, struct mptcp_out_options *opts); | |
cec37a6e PK |
67 | void mptcp_rcv_synsent(struct sock *sk); |
68 | bool mptcp_synack_options(const struct request_sock *req, unsigned int *size, | |
69 | struct mptcp_out_options *opts); | |
70 | bool mptcp_established_options(struct sock *sk, struct sk_buff *skb, | |
71 | unsigned int *size, unsigned int remaining, | |
72 | struct mptcp_out_options *opts); | |
648ef4b8 MM |
73 | void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb, |
74 | struct tcp_options_received *opt_rx); | |
cec37a6e | 75 | |
eda7acdd PK |
76 | void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts); |
77 | ||
85712484 MM |
78 | /* move the skb extension owership, with the assumption that 'to' is |
79 | * newly allocated | |
80 | */ | |
81 | static inline void mptcp_skb_ext_move(struct sk_buff *to, | |
82 | struct sk_buff *from) | |
83 | { | |
84 | if (!skb_ext_exist(from, SKB_EXT_MPTCP)) | |
85 | return; | |
86 | ||
87 | if (WARN_ON_ONCE(to->active_extensions)) | |
88 | skb_ext_put(to); | |
89 | ||
90 | to->active_extensions = from->active_extensions; | |
91 | to->extensions = from->extensions; | |
92 | from->active_extensions = 0; | |
93 | } | |
94 | ||
95 | static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext, | |
96 | const struct mptcp_ext *from_ext) | |
97 | { | |
98 | /* MPTCP always clears the ext when adding it to the skb, so | |
99 | * holes do not bother us here | |
100 | */ | |
101 | return !from_ext || | |
102 | (to_ext && from_ext && | |
103 | !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext))); | |
104 | } | |
105 | ||
106 | /* check if skbs can be collapsed. | |
107 | * MPTCP collapse is allowed if neither @to or @from carry an mptcp data | |
108 | * mapping, or if the extension of @to is the same as @from. | |
109 | * Collapsing is not possible if @to lacks an extension, but @from carries one. | |
110 | */ | |
111 | static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, | |
112 | const struct sk_buff *from) | |
113 | { | |
114 | return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP), | |
115 | skb_ext_find(from, SKB_EXT_MPTCP)); | |
116 | } | |
117 | ||
118 | #else | |
119 | ||
f870fa0b MM |
120 | static inline void mptcp_init(void) |
121 | { | |
122 | } | |
123 | ||
cec37a6e PK |
124 | static inline bool sk_is_mptcp(const struct sock *sk) |
125 | { | |
126 | return false; | |
127 | } | |
128 | ||
129 | static inline bool rsk_is_mptcp(const struct request_sock *req) | |
130 | { | |
131 | return false; | |
132 | } | |
133 | ||
cc7972ea CP |
134 | static inline void mptcp_parse_option(const struct sk_buff *skb, |
135 | const unsigned char *ptr, int opsize, | |
eda7acdd PK |
136 | struct tcp_options_received *opt_rx) |
137 | { | |
138 | } | |
139 | ||
cc7972ea CP |
140 | static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, |
141 | unsigned int *size, | |
cec37a6e PK |
142 | struct mptcp_out_options *opts) |
143 | { | |
144 | return false; | |
145 | } | |
146 | ||
147 | static inline void mptcp_rcv_synsent(struct sock *sk) | |
148 | { | |
149 | } | |
150 | ||
151 | static inline bool mptcp_synack_options(const struct request_sock *req, | |
152 | unsigned int *size, | |
153 | struct mptcp_out_options *opts) | |
154 | { | |
155 | return false; | |
156 | } | |
157 | ||
158 | static inline bool mptcp_established_options(struct sock *sk, | |
159 | struct sk_buff *skb, | |
160 | unsigned int *size, | |
161 | unsigned int remaining, | |
162 | struct mptcp_out_options *opts) | |
163 | { | |
164 | return false; | |
165 | } | |
166 | ||
648ef4b8 MM |
167 | static inline void mptcp_incoming_options(struct sock *sk, |
168 | struct sk_buff *skb, | |
169 | struct tcp_options_received *opt_rx) | |
170 | { | |
171 | } | |
172 | ||
85712484 MM |
173 | static inline void mptcp_skb_ext_move(struct sk_buff *to, |
174 | const struct sk_buff *from) | |
175 | { | |
176 | } | |
177 | ||
178 | static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, | |
179 | const struct sk_buff *from) | |
180 | { | |
181 | return true; | |
182 | } | |
183 | ||
184 | #endif /* CONFIG_MPTCP */ | |
f870fa0b MM |
185 | |
186 | #if IS_ENABLED(CONFIG_MPTCP_IPV6) | |
187 | int mptcpv6_init(void); | |
31484d56 | 188 | void mptcpv6_handle_mapped(struct sock *sk, bool mapped); |
f870fa0b | 189 | #elif IS_ENABLED(CONFIG_IPV6) |
31484d56 GU |
190 | static inline int mptcpv6_init(void) { return 0; } |
191 | static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { } | |
f870fa0b MM |
192 | #endif |
193 | ||
3ee17bc7 | 194 | #endif /* __NET_MPTCP_H */ |