Skip to contentSkip to conversation

mptcp: Optimize ADD_ADDR fields in mptcp_options_received

PATCH New Peter Krystad 1 participant 1 message Jan 17, 2020

Subsystems (3)
lore
Share & tools
lore

Peter Krystad

author
#0 lore raw

PATCH 1/1 mptcp: Optimize ADD_ADDR fields in mptcp_options_received

Use union to minimize space used in structure.

Allow IPv4 ADD_ADDR to be received in the same header as a MP_CAPABLE. Remove unneeded family field. Ensure that mixed 32 and 64-bit ACKs and sequence numbers can still be received.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h | 34 +++++++++++++++++++++-------------
 net/mptcp/options.c | 18 ++++++++++--------
 2 files changed, 31 insertions(+), 21 deletions(-)
include/linux/tcp.h +21 -13
index ec4dd8c01742..3d9cb3ae7228 100644
@@ -84,19 +84,36 @@ struct mptcp_options_received {
 		struct {
 			u64	sndr_key;
 			u64	rcvr_key;
-			u32	data_ack32;
-			u32	data_seq32;
+			union {
+				struct {
+					u32	data_ack32;
+					u32	data_seq32;
+				};
+				struct {
+					struct in_addr	addr;
+					u8	addr_id;
+				};
+			};
 		};
 		struct {
 			u64	data_ack;
 			u64	data_seq;
 		};
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+		struct {
+			struct in6_addr	addr6;
+			u8	addr6_id;
+		};
+#endif
 	};
 	u32	subflow_seq;
 	u16	data_len;
 	u8	mp_capable : 1,
 		mp_join : 1,
-		dss : 1;
+		dss : 1,
+		add_addr : 1,
+		add_addr6 : 1,
+		rm_addr : 1;
 	u8	use_map:1,
 		dsn64:1,
 		data_fin:1,
@@ -104,16 +121,6 @@ struct mptcp_options_received {
 		ack64:1,
 		mpc_map:1,
 		__unused:2;
-	u8	add_addr : 1,
-		rm_addr : 1,
-		family : 4;
-	u8	addr_id;
-	union {
-		struct	in_addr	addr;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct	in6_addr addr6;
-#endif
-	};
 };
 #endif
 
@@ -150,6 +157,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 	rx_opt->mptcp.mp_capable = 0;
 	rx_opt->mptcp.mp_join = 0;
 	rx_opt->mptcp.add_addr = 0;
+	rx_opt->mptcp.add_addr6 = 0;
 	rx_opt->mptcp.rm_addr = 0;
 	rx_opt->mptcp.dss = 0;
 #endif
net/mptcp/options.c +10 -8
index 819416bd601a..5712dddc9ec5 100644
@@ -21,6 +21,7 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 	u8 subtype = *ptr >> 4;
 	int expected_opsize;
 	u8 version;
+	u8 family;
 	u8 flags;
 
 	switch (subtype) {
@@ -222,21 +223,21 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 		if (opsize != TCPOLEN_MPTCP_ADD_ADDR &&
 		    opsize != TCPOLEN_MPTCP_ADD_ADDR6)
 			break;
-		mp_opt->family = *ptr++ & MPTCP_ADDR_FAMILY_MASK;
-		if (mp_opt->family != MPTCP_ADDR_IPVERSION_4 &&
-		    mp_opt->family != MPTCP_ADDR_IPVERSION_6)
+		family = *ptr++ & MPTCP_ADDR_FAMILY_MASK;
+		if (family != MPTCP_ADDR_IPVERSION_4 &&
+		    family != MPTCP_ADDR_IPVERSION_6)
 			break;
 
-		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4 &&
+		if (family == MPTCP_ADDR_IPVERSION_4 &&
 		    opsize != TCPOLEN_MPTCP_ADD_ADDR)
 			break;
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-		if (mp_opt->family == MPTCP_ADDR_IPVERSION_6 &&
+		if (family == MPTCP_ADDR_IPVERSION_6 &&
 		    opsize != TCPOLEN_MPTCP_ADD_ADDR6)
 			break;
 #endif
-		mp_opt->addr_id = *ptr++;
-		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+		if (family == MPTCP_ADDR_IPVERSION_4) {
+			mp_opt->addr_id = *ptr++;
 			mp_opt->add_addr = 1;
 			memcpy((u8 *)&mp_opt->addr.s_addr, (u8 *)ptr, 4);
 			pr_debug("ADD_ADDR: addr=%x, id=%d",
@@ -244,9 +245,10 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 		}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 		else {
+			mp_opt->addr6_id = *ptr++;
 			mp_opt->add_addr = 1;
 			memcpy(mp_opt->addr6.s6_addr, (u8 *)ptr, 16);
-			pr_debug("ADD_ADDR: addr6=, id=%d", mp_opt->addr_id);
+			pr_debug("ADD_ADDR: addr6=, id=%d", mp_opt->addr6_id);
 		}
 #endif
 		break;
Signature · 1 line
2.17.2