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>
15 /* MPTCP sk_buff extension data */
31 struct mptcp_out_options
{
32 #if IS_ENABLED(CONFIG_MPTCP)
36 struct mptcp_ext ext_copy
;
42 void mptcp_init(void);
44 static inline bool sk_is_mptcp(const struct sock
*sk
)
46 return tcp_sk(sk
)->is_mptcp
;
49 static inline bool rsk_is_mptcp(const struct request_sock
*req
)
51 return tcp_rsk(req
)->is_mptcp
;
54 void mptcp_parse_option(const struct sk_buff
*skb
, const unsigned char *ptr
,
55 int opsize
, struct tcp_options_received
*opt_rx
);
56 bool mptcp_syn_options(struct sock
*sk
, const struct sk_buff
*skb
,
57 unsigned int *size
, struct mptcp_out_options
*opts
);
58 void mptcp_rcv_synsent(struct sock
*sk
);
59 bool mptcp_synack_options(const struct request_sock
*req
, unsigned int *size
,
60 struct mptcp_out_options
*opts
);
61 bool mptcp_established_options(struct sock
*sk
, struct sk_buff
*skb
,
62 unsigned int *size
, unsigned int remaining
,
63 struct mptcp_out_options
*opts
);
64 void mptcp_incoming_options(struct sock
*sk
, struct sk_buff
*skb
,
65 struct tcp_options_received
*opt_rx
);
67 void mptcp_write_options(__be32
*ptr
, struct mptcp_out_options
*opts
);
69 /* move the skb extension owership, with the assumption that 'to' is
72 static inline void mptcp_skb_ext_move(struct sk_buff
*to
,
75 if (!skb_ext_exist(from
, SKB_EXT_MPTCP
))
78 if (WARN_ON_ONCE(to
->active_extensions
))
81 to
->active_extensions
= from
->active_extensions
;
82 to
->extensions
= from
->extensions
;
83 from
->active_extensions
= 0;
86 static inline bool mptcp_ext_matches(const struct mptcp_ext
*to_ext
,
87 const struct mptcp_ext
*from_ext
)
89 /* MPTCP always clears the ext when adding it to the skb, so
90 * holes do not bother us here
93 (to_ext
&& from_ext
&&
94 !memcmp(from_ext
, to_ext
, sizeof(struct mptcp_ext
)));
97 /* check if skbs can be collapsed.
98 * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
99 * mapping, or if the extension of @to is the same as @from.
100 * Collapsing is not possible if @to lacks an extension, but @from carries one.
102 static inline bool mptcp_skb_can_collapse(const struct sk_buff
*to
,
103 const struct sk_buff
*from
)
105 return mptcp_ext_matches(skb_ext_find(to
, SKB_EXT_MPTCP
),
106 skb_ext_find(from
, SKB_EXT_MPTCP
));
111 static inline void mptcp_init(void)
115 static inline bool sk_is_mptcp(const struct sock
*sk
)
120 static inline bool rsk_is_mptcp(const struct request_sock
*req
)
125 static inline void mptcp_parse_option(const struct sk_buff
*skb
,
126 const unsigned char *ptr
, int opsize
,
127 struct tcp_options_received
*opt_rx
)
131 static inline bool mptcp_syn_options(struct sock
*sk
, const struct sk_buff
*skb
,
133 struct mptcp_out_options
*opts
)
138 static inline void mptcp_rcv_synsent(struct sock
*sk
)
142 static inline bool mptcp_synack_options(const struct request_sock
*req
,
144 struct mptcp_out_options
*opts
)
149 static inline bool mptcp_established_options(struct sock
*sk
,
152 unsigned int remaining
,
153 struct mptcp_out_options
*opts
)
158 static inline void mptcp_incoming_options(struct sock
*sk
,
160 struct tcp_options_received
*opt_rx
)
164 static inline void mptcp_skb_ext_move(struct sk_buff
*to
,
165 const struct sk_buff
*from
)
169 static inline bool mptcp_skb_can_collapse(const struct sk_buff
*to
,
170 const struct sk_buff
*from
)
175 #endif /* CONFIG_MPTCP */
177 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
178 int mptcpv6_init(void);
179 void mptcpv6_handle_mapped(struct sock
*sk
, bool mapped
);
180 #elif IS_ENABLED(CONFIG_IPV6)
181 static inline int mptcpv6_init(void) { return 0; }
182 static inline void mptcpv6_handle_mapped(struct sock
*sk
, bool mapped
) { }
185 #endif /* __NET_MPTCP_H */