1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Copyright (c) 2017 - 2019, Intel Corporation.
11 #include <linux/skbuff.h>
12 #include <linux/tcp.h>
13 #include <linux/types.h>
17 /* MPTCP sk_buff extension data */
37 struct mptcp_out_options {
38 #if IS_ENABLED(CONFIG_MPTCP)
44 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
45 struct in6_addr addr6;
57 struct mptcp_ext ext_copy;
62 extern struct request_sock_ops mptcp_subflow_request_sock_ops;
64 void mptcp_init(void);
66 static inline bool sk_is_mptcp(const struct sock *sk)
68 return tcp_sk(sk)->is_mptcp;
71 static inline bool rsk_is_mptcp(const struct request_sock *req)
73 return tcp_rsk(req)->is_mptcp;
76 static inline bool rsk_drop_req(const struct request_sock *req)
78 return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
81 void mptcp_space(const struct sock *ssk, int *space, int *full_space);
82 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
83 unsigned int *size, struct mptcp_out_options *opts);
84 bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
85 struct mptcp_out_options *opts);
86 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
87 unsigned int *size, unsigned int remaining,
88 struct mptcp_out_options *opts);
89 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
91 void mptcp_write_options(__be32 *ptr, const struct tcp_sock *tp,
92 struct mptcp_out_options *opts);
94 /* move the skb extension owership, with the assumption that 'to' is
97 static inline void mptcp_skb_ext_move(struct sk_buff *to,
100 if (!skb_ext_exist(from, SKB_EXT_MPTCP))
103 if (WARN_ON_ONCE(to->active_extensions))
106 to->active_extensions = from->active_extensions;
107 to->extensions = from->extensions;
108 from->active_extensions = 0;
111 static inline void mptcp_skb_ext_copy(struct sk_buff *to,
112 struct sk_buff *from)
114 struct mptcp_ext *from_ext;
116 from_ext = skb_ext_find(from, SKB_EXT_MPTCP);
120 from_ext->frozen = 1;
121 skb_ext_copy(to, from);
124 static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
125 const struct mptcp_ext *from_ext)
127 /* MPTCP always clears the ext when adding it to the skb, so
128 * holes do not bother us here
131 (to_ext && from_ext &&
132 !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
135 /* check if skbs can be collapsed.
136 * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
137 * mapping, or if the extension of @to is the same as @from.
138 * Collapsing is not possible if @to lacks an extension, but @from carries one.
140 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
141 const struct sk_buff *from)
143 return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
144 skb_ext_find(from, SKB_EXT_MPTCP));
147 void mptcp_seq_show(struct seq_file *seq);
148 int mptcp_subflow_init_cookie_req(struct request_sock *req,
149 const struct sock *sk_listener,
150 struct sk_buff *skb);
153 static inline void mptcp_init(void)
157 static inline bool sk_is_mptcp(const struct sock *sk)
162 static inline bool rsk_is_mptcp(const struct request_sock *req)
167 static inline bool rsk_drop_req(const struct request_sock *req)
172 static inline void mptcp_parse_option(const struct sk_buff *skb,
173 const unsigned char *ptr, int opsize,
174 struct tcp_options_received *opt_rx)
178 static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
180 struct mptcp_out_options *opts)
185 static inline bool mptcp_synack_options(const struct request_sock *req,
187 struct mptcp_out_options *opts)
192 static inline bool mptcp_established_options(struct sock *sk,
195 unsigned int remaining,
196 struct mptcp_out_options *opts)
201 static inline void mptcp_incoming_options(struct sock *sk,
206 static inline void mptcp_skb_ext_move(struct sk_buff *to,
207 const struct sk_buff *from)
211 static inline void mptcp_skb_ext_copy(struct sk_buff *to,
212 struct sk_buff *from)
216 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
217 const struct sk_buff *from)
222 static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
223 static inline void mptcp_seq_show(struct seq_file *seq) { }
225 static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,
226 const struct sock *sk_listener,
229 return 0; /* TCP fallback */
231 #endif /* CONFIG_MPTCP */
233 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
234 int mptcpv6_init(void);
235 void mptcpv6_handle_mapped(struct sock *sk, bool mapped);
236 #elif IS_ENABLED(CONFIG_IPV6)
237 static inline int mptcpv6_init(void) { return 0; }
238 static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
241 #endif /* __NET_MPTCP_H */