]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - include/net/mptcp.h
mptcp: Write MPTCP DSS headers to outgoing data packets
[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
15/* MPTCP sk_buff extension data */
16struct 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,
26 __unused:3;
27 /* one byte hole */
28};
29
eda7acdd
PK
30struct mptcp_out_options {
31#if IS_ENABLED(CONFIG_MPTCP)
32 u16 suboptions;
33 u64 sndr_key;
34 u64 rcvr_key;
6d0060f6 35 struct mptcp_ext ext_copy;
eda7acdd
PK
36#endif
37};
38
85712484
MM
39#ifdef CONFIG_MPTCP
40
f870fa0b
MM
41void mptcp_init(void);
42
cec37a6e
PK
43static inline bool sk_is_mptcp(const struct sock *sk)
44{
45 return tcp_sk(sk)->is_mptcp;
46}
47
48static inline bool rsk_is_mptcp(const struct request_sock *req)
49{
50 return tcp_rsk(req)->is_mptcp;
51}
52
eda7acdd
PK
53void mptcp_parse_option(const unsigned char *ptr, int opsize,
54 struct tcp_options_received *opt_rx);
cec37a6e
PK
55bool mptcp_syn_options(struct sock *sk, unsigned int *size,
56 struct mptcp_out_options *opts);
57void mptcp_rcv_synsent(struct sock *sk);
58bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
59 struct mptcp_out_options *opts);
60bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
61 unsigned int *size, unsigned int remaining,
62 struct mptcp_out_options *opts);
63
eda7acdd
PK
64void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
65
85712484
MM
66/* move the skb extension owership, with the assumption that 'to' is
67 * newly allocated
68 */
69static inline void mptcp_skb_ext_move(struct sk_buff *to,
70 struct sk_buff *from)
71{
72 if (!skb_ext_exist(from, SKB_EXT_MPTCP))
73 return;
74
75 if (WARN_ON_ONCE(to->active_extensions))
76 skb_ext_put(to);
77
78 to->active_extensions = from->active_extensions;
79 to->extensions = from->extensions;
80 from->active_extensions = 0;
81}
82
83static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
84 const struct mptcp_ext *from_ext)
85{
86 /* MPTCP always clears the ext when adding it to the skb, so
87 * holes do not bother us here
88 */
89 return !from_ext ||
90 (to_ext && from_ext &&
91 !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
92}
93
94/* check if skbs can be collapsed.
95 * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
96 * mapping, or if the extension of @to is the same as @from.
97 * Collapsing is not possible if @to lacks an extension, but @from carries one.
98 */
99static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
100 const struct sk_buff *from)
101{
102 return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
103 skb_ext_find(from, SKB_EXT_MPTCP));
104}
105
106#else
107
f870fa0b
MM
108static inline void mptcp_init(void)
109{
110}
111
cec37a6e
PK
112static inline bool sk_is_mptcp(const struct sock *sk)
113{
114 return false;
115}
116
117static inline bool rsk_is_mptcp(const struct request_sock *req)
118{
119 return false;
120}
121
eda7acdd
PK
122static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
123 struct tcp_options_received *opt_rx)
124{
125}
126
cec37a6e
PK
127static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
128 struct mptcp_out_options *opts)
129{
130 return false;
131}
132
133static inline void mptcp_rcv_synsent(struct sock *sk)
134{
135}
136
137static inline bool mptcp_synack_options(const struct request_sock *req,
138 unsigned int *size,
139 struct mptcp_out_options *opts)
140{
141 return false;
142}
143
144static inline bool mptcp_established_options(struct sock *sk,
145 struct sk_buff *skb,
146 unsigned int *size,
147 unsigned int remaining,
148 struct mptcp_out_options *opts)
149{
150 return false;
151}
152
85712484
MM
153static inline void mptcp_skb_ext_move(struct sk_buff *to,
154 const struct sk_buff *from)
155{
156}
157
158static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
159 const struct sk_buff *from)
160{
161 return true;
162}
163
164#endif /* CONFIG_MPTCP */
f870fa0b 165
cec37a6e
PK
166void mptcp_handle_ipv6_mapped(struct sock *sk, bool mapped);
167
f870fa0b
MM
168#if IS_ENABLED(CONFIG_MPTCP_IPV6)
169int mptcpv6_init(void);
170#elif IS_ENABLED(CONFIG_IPV6)
171static inline int mptcpv6_init(void)
172{
173 return 0;
174}
175#endif
176
3ee17bc7 177#endif /* __NET_MPTCP_H */