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