Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Multipath TCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2017 - 2019, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #ifndef __NET_MPTCP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define __NET_MPTCP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) struct seq_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* MPTCP sk_buff extension data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct mptcp_ext {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		u64	data_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		u32	data_ack32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u64		data_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u32		subflow_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	u16		data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	u8		use_map:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			dsn64:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 			data_fin:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			use_ack:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			ack64:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			mpc_map:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			__unused:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* one byte hole */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct mptcp_out_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #if IS_ENABLED(CONFIG_MPTCP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u16 suboptions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u64 sndr_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u64 rcvr_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		struct in_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		struct in6_addr addr6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 addr_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	u64 ahmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u8 rm_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u8 join_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u8 backup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	u32 nonce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u64 thmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	u32 token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u8 hmac[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct mptcp_ext ext_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #ifdef CONFIG_MPTCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) extern struct request_sock_ops mptcp_subflow_request_sock_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) void mptcp_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static inline bool sk_is_mptcp(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return tcp_sk(sk)->is_mptcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static inline bool rsk_is_mptcp(const struct request_sock *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return tcp_rsk(req)->is_mptcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static inline bool rsk_drop_req(const struct request_sock *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) void mptcp_space(const struct sock *ssk, int *space, int *full_space);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		       unsigned int *size, struct mptcp_out_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			  struct mptcp_out_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			       unsigned int *size, unsigned int remaining,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			       struct mptcp_out_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /* move the skb extension owership, with the assumption that 'to' is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * newly allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static inline void mptcp_skb_ext_move(struct sk_buff *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				      struct sk_buff *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (!skb_ext_exist(from, SKB_EXT_MPTCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (WARN_ON_ONCE(to->active_extensions))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		skb_ext_put(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	to->active_extensions = from->active_extensions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	to->extensions = from->extensions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	from->active_extensions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static inline bool mptcp_ext_matches(const struct mptcp_ext *to_ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				     const struct mptcp_ext *from_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* MPTCP always clears the ext when adding it to the skb, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * holes do not bother us here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return !from_ext ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	       (to_ext && from_ext &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	        !memcmp(from_ext, to_ext, sizeof(struct mptcp_ext)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* check if skbs can be collapsed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * MPTCP collapse is allowed if neither @to or @from carry an mptcp data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * mapping, or if the extension of @to is the same as @from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * Collapsing is not possible if @to lacks an extension, but @from carries one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					  const struct sk_buff *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return mptcp_ext_matches(skb_ext_find(to, SKB_EXT_MPTCP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				 skb_ext_find(from, SKB_EXT_MPTCP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void mptcp_seq_show(struct seq_file *seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) int mptcp_subflow_init_cookie_req(struct request_sock *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				  const struct sock *sk_listener,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				  struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline void mptcp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static inline bool sk_is_mptcp(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline bool rsk_is_mptcp(const struct request_sock *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static inline bool rsk_drop_req(const struct request_sock *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline void mptcp_parse_option(const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				      const unsigned char *ptr, int opsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				      struct tcp_options_received *opt_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				     unsigned int *size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				     struct mptcp_out_options *opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline bool mptcp_synack_options(const struct request_sock *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					unsigned int *size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					struct mptcp_out_options *opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static inline bool mptcp_established_options(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					     struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					     unsigned int *size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 					     unsigned int remaining,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					     struct mptcp_out_options *opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static inline void mptcp_incoming_options(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static inline void mptcp_skb_ext_move(struct sk_buff *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				      const struct sk_buff *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 					  const struct sk_buff *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline void mptcp_seq_show(struct seq_file *seq) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static inline int mptcp_subflow_init_cookie_req(struct request_sock *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 						const struct sock *sk_listener,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	return 0; /* TCP fallback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif /* CONFIG_MPTCP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #if IS_ENABLED(CONFIG_MPTCP_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int mptcpv6_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) void mptcpv6_handle_mapped(struct sock *sk, bool mapped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #elif IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static inline int mptcpv6_init(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif /* __NET_MPTCP_H */