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