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 */
33 struct mptcp_out_options {
34 #if IS_ENABLED(CONFIG_MPTCP)
40 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
41 struct in6_addr addr6;
53 struct mptcp_ext ext_copy;
59 void mptcp_init(void);
61 static inline bool sk_is_mptcp(const struct sock *sk)
63 return tcp_sk(sk)->is_mptcp;
66 static inline bool rsk_is_mptcp(const struct request_sock *req)
68 return tcp_rsk(req)->is_mptcp;
71 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
72 unsigned int *size, struct mptcp_out_options *opts);
73 bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
74 struct mptcp_out_options *opts);
75 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
76 unsigned int *size, unsigned int remaining,
77 struct mptcp_out_options *opts);
78 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
79 struct tcp_options_received *opt_rx);
81 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
83 /* move the skb extension owership, with the assumption that 'to' is
86 static inline void mptcp_skb_ext_move(struct sk_buff *to,
89 if (!skb_ext_exist(from, SKB_EXT_MPTCP))
92 if (WARN_ON_ONCE(to->active_extensions))
95 to->active_extensions = from->active_extensions;
96 to->extensions = from->extensions;
97 from->active_extensions = 0;
100 static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
101 const struct mptcp_ext *from_ext)
103 /* MPTCP always clears the ext when adding it to the skb, so
104 * holes do not bother us here
107 (to_ext && from_ext &&
108 !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
111 /* check if skbs can be collapsed.
112 * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
113 * mapping, or if the extension of @to is the same as @from.
114 * Collapsing is not possible if @to lacks an extension, but @from carries one.
116 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
117 const struct sk_buff *from)
119 return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
120 skb_ext_find(from, SKB_EXT_MPTCP));
123 bool mptcp_sk_is_subflow(const struct sock *sk);
125 void mptcp_seq_show(struct seq_file *seq);
128 static inline void mptcp_init(void)
132 static inline bool sk_is_mptcp(const struct sock *sk)
137 static inline bool rsk_is_mptcp(const struct request_sock *req)
142 static inline void mptcp_parse_option(const struct sk_buff *skb,
143 const unsigned char *ptr, int opsize,
144 struct tcp_options_received *opt_rx)
148 static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
150 struct mptcp_out_options *opts)
155 static inline void mptcp_rcv_synsent(struct sock *sk)
159 static inline bool mptcp_synack_options(const struct request_sock *req,
161 struct mptcp_out_options *opts)
166 static inline bool mptcp_established_options(struct sock *sk,
169 unsigned int remaining,
170 struct mptcp_out_options *opts)
175 static inline void mptcp_incoming_options(struct sock *sk,
177 struct tcp_options_received *opt_rx)
181 static inline void mptcp_skb_ext_move(struct sk_buff *to,
182 const struct sk_buff *from)
186 static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
187 const struct sk_buff *from)
192 static inline bool mptcp_sk_is_subflow(const struct sock *sk)
197 static inline void mptcp_seq_show(struct seq_file *seq) { }
198 #endif /* CONFIG_MPTCP */
200 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
201 int mptcpv6_init(void);
202 void mptcpv6_handle_mapped(struct sock *sk, bool mapped);
203 #elif IS_ENABLED(CONFIG_IPV6)
204 static inline int mptcpv6_init(void) { return 0; }
205 static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
208 #endif /* __NET_MPTCP_H */