Skip to contentSkip to conversation

Multipath TCP

RFC PATCH Superseded Mat Martineau 3 participants 65 messages Oct 2, 2019 – Oct 3, 2019

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Multipath TCP

The MPTCP upstreaming community has prepared a net-next RFCv2 patch set for review.

Clone/fetch:
https://github.com/multipath-tcp/mptcp_net-next.git (tag: netdev-rfcv2)

Browse:
https://github.com/multipath-tcp/mptcp_net-next/tree/netdev-rfcv2

With CONFIG_MPTCP=y, a socket created with IPPROTO_MPTCP will attempt to create an MPTCP connection but remains compatible with regular TCP. IPPROTO_TCP socket behavior is unchanged.

This implementation makes use of ULP between the userspace-facing MPTCP socket and the set of in-kernel TCP sockets it controls. ULP has been extended for use with listening sockets. skb_ext is used to carry MPTCP metadata.

The patch set includes self-tests to exercise MPTCP in various connection and routing scenarios.

We have more work planned to reach the initial feature set for merging, notably:

* IPv6

* Comply with MPTCPv1 (RFC6824bis). This patch set supports only MPTCPv0 (RFC 6824 / experimental)

* Proper MPTCP-level connection closing with DATA_FIN

* Couple receive windows across sibling subflow TCP sockets as required by RFC 6824

* Limit subflow ULP visibility to kernel space

* Simple transmit scheduler that respects subflow 'backup' flags

In order to simplify both code review and the development process, we propose splitting the patch set in to smaller chunks. The first patch set for merging would include patches 1 to 31 and basic IPv6 support.

Thank you for your review. You can find us at [email protected] and
https://is.gd/mptcp_upstream

Florian Westphal (7):
mptcp: add mptcp_poll
mptcp: add basic kselftest for mptcp
selftests: mptcp: make tc delays random
selftests: mptcp: extend mptcp_connect tool for ipv6 family
selftests: mptcp: add accept/getpeer checks
selftests: mptcp: add ipv6 connectivity
selftests: mptcp: random ethtool tweaking

Mat Martineau (13):
tcp: Add MPTCP option number
net: Make sock protocol value checks more specific
sock: Make sk_protocol a 16-bit value
tcp: Define IPPROTO_MPTCP
mptcp: Add MPTCP socket stubs
tcp, ulp: Add clone operation to tcp_ulp_ops
mptcp: Add MPTCP to skb extensions
tcp: Prevent coalesce/collapse when skb has MPTCP extensions
tcp: Export low-level TCP functions
mptcp: Write MPTCP DSS headers to outgoing data packets
mptcp: Implement MPTCP receive path
tcp: Check for filled TCP option space before SACK
mptcp: Make MPTCP socket block/wakeup ignore sk_receive_queue

Matthieu Baerts (1):
mptcp: new sysctl to control the activation per NS

Paolo Abeni (11):
tcp: clean ext on tx recycle
mptcp: use sk_page_frag() in sendmsg
mptcp: sendmsg() do spool all the provided data
mptcp: allow collapsing consecutive sendpages on the same substream
mptcp: harmonize locking on all socket operations.
mptcp: update per unacked sequence on pkt reception
mptcp: queue data for mptcp level retransmission
mptcp: introduce MPTCP retransmission timer
mptcp: implement memory accounting for mptcp rtx queue
mptcp: rework mptcp_sendmsg_frag to accept optional dfrag
mptcp: implement and use MPTCP-level retransmission

Peter Krystad (13):
mptcp: Handle MPTCP TCP options
mptcp: Associate MPTCP context with TCP socket
tcp: Expose tcp struct and routine for MPTCP
mptcp: Handle MP_CAPABLE options for outgoing connections
mptcp: Create SUBFLOW socket for incoming connections
mptcp: Add key generation and token tree
mptcp: Add shutdown() socket operation
mptcp: Add setsockopt()/getsockopt() socket operations
mptcp: Add path manager interface
mptcp: Add ADD_ADDR handling
mptcp: Add handling of incoming MP_JOIN requests
mptcp: Add handling of outgoing MP_JOIN requests
mptcp: Implement path manager interface commands

 include/linux/skbuff.h                        |   11 +
 include/linux/tcp.h                           |   51 +
 include/net/mptcp.h                           |  149 ++
 include/net/sock.h                            |    6 +-
 include/net/tcp.h                             |   20 +
 include/trace/events/sock.h                   |    5 +-
 include/uapi/linux/in.h                       |    2 +
 net/Kconfig                                   |    1 +
 net/Makefile                                  |    1 +
 net/ax25/af_ax25.c                            |    2 +-
 net/core/skbuff.c                             |    7 +
 net/decnet/af_decnet.c                        |    2 +-
 net/ipv4/inet_connection_sock.c               |    2 +
 net/ipv4/tcp.c                                |    8 +-
 net/ipv4/tcp_input.c                          |   29 +-
 net/ipv4/tcp_ipv4.c                           |    4 +-
 net/ipv4/tcp_minisocks.c                      |    6 +
 net/ipv4/tcp_output.c                         |   62 +-
 net/ipv4/tcp_ulp.c                            |   12 +
 net/mptcp/Kconfig                             |   11 +
 net/mptcp/Makefile                            |    4 +
 net/mptcp/crypto.c                            |  128 ++
 net/mptcp/ctrl.c                              |  112 ++
 net/mptcp/options.c                           |  753 +++++++++
 net/mptcp/pm.c                                |  181 ++
 net/mptcp/protocol.c                          | 1455 +++++++++++++++++
 net/mptcp/protocol.h                          |  319 ++++
 net/mptcp/subflow.c                           |  537 ++++++
 net/mptcp/token.c                             |  217 +++
 tools/include/uapi/linux/in.h                 |    2 +
 tools/testing/selftests/Makefile              |    1 +
 tools/testing/selftests/net/mptcp/.gitignore  |    2 +
 tools/testing/selftests/net/mptcp/Makefile    |   11 +
 tools/testing/selftests/net/mptcp/config      |    1 +
 .../selftests/net/mptcp/mptcp_connect.c       |  522 ++++++
 .../selftests/net/mptcp/mptcp_connect.sh      |  401 +++++
 36 files changed, 5021 insertions(+), 16 deletions(-)
 create mode 100644 include/net/mptcp.h
 create mode 100644 net/mptcp/Kconfig
 create mode 100644 net/mptcp/Makefile
 create mode 100644 net/mptcp/crypto.c
 create mode 100644 net/mptcp/ctrl.c
 create mode 100644 net/mptcp/options.c
 create mode 100644 net/mptcp/pm.c
 create mode 100644 net/mptcp/protocol.c
 create mode 100644 net/mptcp/protocol.h
 create mode 100644 net/mptcp/subflow.c
 create mode 100644 net/mptcp/token.c
 create mode 100644 tools/testing/selftests/net/mptcp/.gitignore
 create mode 100644 tools/testing/selftests/net/mptcp/Makefile
 create mode 100644 tools/testing/selftests/net/mptcp/config
 create mode 100644 tools/testing/selftests/net/mptcp/mptcp_connect.c
 create mode 100755 tools/testing/selftests/net/mptcp/mptcp_connect.sh
Signature · 1 line
2.23.0
#1 lore raw

RFC PATCH v2 1/45 tcp: Add MPTCP option number

TCP option 30 is allocated for MPTCP by the IANA.

---
 include/net/tcp.h | 1 +
 1 file changed, 1 insertion(+)
include/net/tcp.h +1 -0
index c9a3f9688223..382e245a7909 100644
@@ -182,6 +182,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);
 #define TCPOPT_SACK             5       /* SACK Block */
 #define TCPOPT_TIMESTAMP	8	/* Better RTT estimations/PAWS */
 #define TCPOPT_MD5SIG		19	/* MD5 Signature (RFC2385) */
+#define TCPOPT_MPTCP		30	/* Multipath TCP (RFC6824) */
 #define TCPOPT_FASTOPEN		34	/* Fast open (RFC7413) */
 #define TCPOPT_EXP		254	/* Experimental */
 /* Magic number to be after the option value for sharing TCP
Signature · 1 line
2.23.0
#2 lore raw

RFC PATCH v2 2/45 net: Make sock protocol value checks more specific

In reply to Mat Martineau

SK_PROTOCOL_MAX is only used in two places, for DECNet and AX.25. The limits have more to do with the those protocol definitions than they do with the data type of sk_protocol, so remove SK_PROTOCOL_MAX and use U8_MAX directly.

---
 include/net/sock.h     | 1 -
 net/ax25/af_ax25.c     | 2 +-
 net/decnet/af_decnet.c | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
include/net/sock.h +0 -1
index 2c53f1a1d905..c3fc62bd3e2f 100644
@@ -459,7 +459,6 @@ struct sock {
 				sk_userlocks : 4,
 				sk_protocol  : 8,
 				sk_type      : 16;
-#define SK_PROTOCOL_MAX U8_MAX
 	u16			sk_gso_max_segs;
 	u8			sk_pacing_shift;
 	unsigned long	        sk_lingertime;
net/ax25/af_ax25.c +1 -1
index bb222b882b67..be5772f43816 100644
@@ -808,7 +808,7 @@ static int ax25_create(struct net *net, struct socket *sock, int protocol,
 	struct sock *sk;
 	ax25_cb *ax25;
 
-	if (protocol < 0 || protocol > SK_PROTOCOL_MAX)
+	if (protocol < 0 || protocol > U8_MAX)
 		return -EINVAL;
 
 	if (!net_eq(net, &init_net))
net/decnet/af_decnet.c +1 -1
index 0ea75286abf4..7c0c769a8b26 100644
@@ -670,7 +670,7 @@ static int dn_create(struct net *net, struct socket *sock, int protocol,
 {
 	struct sock *sk;
 
-	if (protocol < 0 || protocol > SK_PROTOCOL_MAX)
+	if (protocol < 0 || protocol > U8_MAX)
 		return -EINVAL;
 
 	if (!net_eq(net, &init_net))
Signature · 1 line
2.23.0
#3 lore raw

RFC PATCH v2 3/45 sock: Make sk_protocol a 16-bit value

In reply to Mat Martineau

Match the 16-bit width of skbuff->protocol. Fills an 8-bit hole so sizeof(struct sock) does not change.

---
 include/net/sock.h          | 4 ++--
 include/trace/events/sock.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/sock.h +2 -2
index c3fc62bd3e2f..ca2071555dde 100644
@@ -457,10 +457,10 @@ struct sock {
 				sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
 				sk_userlocks : 4,
-				sk_protocol  : 8,
+				sk_pacing_shift : 8,
 				sk_type      : 16;
+	u16			sk_protocol;
 	u16			sk_gso_max_segs;
-	u8			sk_pacing_shift;
 	unsigned long	        sk_lingertime;
 	struct proto		*sk_prot_creator;
 	rwlock_t		sk_callback_lock;
include/trace/events/sock.h +1 -1
index a0c4b8a30966..dc749c651318 100644
@@ -147,7 +147,7 @@ TRACE_EVENT(inet_sock_set_state,
 		__field(__u16, sport)
 		__field(__u16, dport)
 		__field(__u16, family)
-		__field(__u8, protocol)
+		__field(__u16, protocol)
 		__array(__u8, saddr, 4)
 		__array(__u8, daddr, 4)
 		__array(__u8, saddr_v6, 16)
Signature · 1 line
2.23.0
#4 lore raw

RFC PATCH v2 4/45 tcp: Define IPPROTO_MPTCP

In reply to Mat Martineau

To open a MPTCP socket with socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP), IPPROTO_MPTCP needs a value that differs from IPPROTO_TCP. The existing IPPROTO numbers mostly map directly to IANA-specified protocol numbers. MPTCP does not have a protocol number allocated because MPTCP packets use the TCP protocol number. Use private number not used OTA.

---
 include/trace/events/sock.h   | 3 ++-
 include/uapi/linux/in.h       | 2 ++
 tools/include/uapi/linux/in.h | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)
include/trace/events/sock.h +2 -1
index dc749c651318..bfbcba315a12 100644
@@ -19,7 +19,8 @@
 #define inet_protocol_names		\
 		EM(IPPROTO_TCP)			\
 		EM(IPPROTO_DCCP)		\
-		EMe(IPPROTO_SCTP)
+		EM(IPPROTO_SCTP)		\
+		EMe(IPPROTO_MPTCP)
 
 #define tcp_state_names			\
 		EM(TCP_ESTABLISHED)		\
include/uapi/linux/in.h +2 -0
index e7ad9d350a28..44df6dc1ff1d 100644
@@ -76,6 +76,8 @@ enum {
 #define IPPROTO_MPLS		IPPROTO_MPLS
   IPPROTO_RAW = 255,		/* Raw IP packets			*/
 #define IPPROTO_RAW		IPPROTO_RAW
+  IPPROTO_MPTCP = 262,		/* Multipath TCP connection 		*/
+#define IPPROTO_MPTCP		IPPROTO_MPTCP
   IPPROTO_MAX
 };
 #endif
tools/include/uapi/linux/in.h +2 -0
index e7ad9d350a28..44df6dc1ff1d 100644
@@ -76,6 +76,8 @@ enum {
 #define IPPROTO_MPLS		IPPROTO_MPLS
   IPPROTO_RAW = 255,		/* Raw IP packets			*/
 #define IPPROTO_RAW		IPPROTO_RAW
+  IPPROTO_MPTCP = 262,		/* Multipath TCP connection 		*/
+#define IPPROTO_MPTCP		IPPROTO_MPTCP
   IPPROTO_MAX
 };
 #endif
Signature · 1 line
2.23.0
#5 lore raw

RFC PATCH v2 5/45 mptcp: Add MPTCP socket stubs

In reply to Mat Martineau

Implements the infrastructure for MPTCP sockets.

MPTCP sockets open one in-kernel TCP socket per subflow. These subflow sockets are only managed by the MPTCP socket that owns them and are not visible from userspace. This commit allows a userspace program to open an MPTCP socket with:

  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);

The resulting socket is simply a wrapper around a single regular TCP socket, without any of the MPTCP protocol implemented over the wire.

---
 include/net/mptcp.h  |  22 +++++++++
 net/Kconfig          |   1 +
 net/Makefile         |   1 +
 net/ipv4/tcp.c       |   2 +
 net/mptcp/Kconfig    |  10 ++++
 net/mptcp/Makefile   |   4 ++
 net/mptcp/protocol.c | 114 +++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h |  22 +++++++++
 8 files changed, 176 insertions(+)
 create mode 100644 include/net/mptcp.h
 create mode 100644 net/mptcp/Kconfig
 create mode 100644 net/mptcp/Makefile
 create mode 100644 net/mptcp/protocol.c
 create mode 100644 net/mptcp/protocol.h
include/net/mptcp.h new file +22 -0
new file mode 100644
index 000000000000..0fe78fddc638
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Multipath TCP
+ *
+ * Copyright (c) 2017 - 2019, Intel Corporation.
+ */
+
+#ifndef __NET_MPTCP_H
+#define __NET_MPTCP_H
+
+#ifdef CONFIG_MPTCP
+
+void mptcp_init(void);
+
+#else
+
+static inline void mptcp_init(void)
+{
+}
+
+#endif /* CONFIG_MPTCP */
+#endif /* __NET_MPTCP_H */
net/Kconfig +1 -0
index 3101bfcbdd7a..4f7e7f3618d0 100644
@@ -91,6 +91,7 @@ if INET
 source "net/ipv4/Kconfig"
 source "net/ipv6/Kconfig"
 source "net/netlabel/Kconfig"
+source "net/mptcp/Kconfig"
 
 endif # if INET
 
net/Makefile +1 -0
index 449fc0b221f8..306d2e8c12c0 100644
@@ -87,3 +87,4 @@ endif
 obj-$(CONFIG_QRTR)		+= qrtr/
 obj-$(CONFIG_NET_NCSI)		+= ncsi/
 obj-$(CONFIG_XDP_SOCKETS)	+= xdp/
+obj-$(CONFIG_MPTCP)		+= mptcp/
net/ipv4/tcp.c +2 -0
index 79c325a07ba5..5893d08cb204 100644
@@ -271,6 +271,7 @@
 #include <net/icmp.h>
 #include <net/inet_common.h>
 #include <net/tcp.h>
+#include <net/mptcp.h>
 #include <net/xfrm.h>
 #include <net/ip.h>
 #include <net/sock.h>
@@ -4006,4 +4007,5 @@ void __init tcp_init(void)
 	tcp_metrics_init();
 	BUG_ON(tcp_register_congestion_control(&tcp_reno) != 0);
 	tcp_tasklet_init();
+	mptcp_init();
 }
net/mptcp/Kconfig new file +10 -0
new file mode 100644
index 000000000000..d87dfdc210cc
@@ -0,0 +1,10 @@
+
+config MPTCP
+	bool "Multipath TCP"
+	depends on INET
+	help
+	  Multipath TCP (MPTCP) connections send and receive data over multiple
+	  subflows in order to utilize multiple network paths. Each subflow
+	  uses the TCP protocol, and TCP options carry header information for
+	  MPTCP.
+
net/mptcp/Makefile new file +4 -0
new file mode 100644
index 000000000000..659129d1fcbf
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MPTCP) += mptcp.o
+
+mptcp-y := protocol.o
net/mptcp/protocol.c new file +114 -0

114 lines not on this page · raw message

net/mptcp/protocol.h new file +22 -0
new file mode 100644
index 000000000000..ee04a01bffd3
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Multipath TCP
+ *
+ * Copyright (c) 2017 - 2019, Intel Corporation.
+ */
+
+#ifndef __MPTCP_PROTOCOL_H
+#define __MPTCP_PROTOCOL_H
+
+/* MPTCP connection sock */
+struct mptcp_sock {
+	/* inet_connection_sock must be the first member */
+	struct inet_connection_sock sk;
+	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
+};
+
+static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
+{
+	return (struct mptcp_sock *)sk;
+}
+
+#endif /* __MPTCP_PROTOCOL_H */
Signature · 1 line
2.23.0
#6 lore raw

RFC PATCH v2 6/45 mptcp: Handle MPTCP TCP options

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Currently only MPTCP v0 is supported so ignore v1 MP_CAPABLE option.

---
 include/linux/tcp.h   |  15 ++++
 include/net/mptcp.h   |  17 +++++
 net/ipv4/tcp_input.c  |   5 ++
 net/ipv4/tcp_output.c |  13 ++++
 net/mptcp/Makefile    |   2 +-
 net/mptcp/options.c   | 159 ++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h  |  27 +++++++
 7 files changed, 237 insertions(+), 1 deletion(-)
 create mode 100644 net/mptcp/options.c
include/linux/tcp.h +15 -0
index 99617e528ea2..18594f40b310 100644
@@ -95,6 +95,17 @@ struct tcp_options_received {
 	u8	num_sacks;	/* Number of SACK blocks		*/
 	u16	user_mss;	/* mss requested by user in ioctl	*/
 	u16	mss_clamp;	/* Maximal mss, negotiated at connection setup */
+#if IS_ENABLED(CONFIG_MPTCP)
+	struct mptcp_options_received {
+		u8      mp_capable : 1,
+			mp_join : 1,
+			dss : 1,
+			version : 4;
+		u8      flags;
+		u64     sndr_key;
+		u64     rcvr_key;
+	} mptcp;
+#endif
 };
 
 static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
@@ -104,6 +115,10 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 #if IS_ENABLED(CONFIG_SMC)
 	rx_opt->smc_ok = 0;
 #endif
+#if IS_ENABLED(CONFIG_MPTCP)
+	rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join = 0;
+	rx_opt->mptcp.dss = 0;
+#endif
 }
 
 /* This is the max number of SACKS that we'll generate and process. It's safe
include/net/mptcp.h +17 -0
index 0fe78fddc638..fc3f9286c667 100644
@@ -8,15 +8,32 @@
 #ifndef __NET_MPTCP_H
 #define __NET_MPTCP_H
 
+struct mptcp_out_options {
+#if IS_ENABLED(CONFIG_MPTCP)
+	u16 suboptions;
+	u64 sndr_key;
+	u64 rcvr_key;
+#endif
+};
+
 #ifdef CONFIG_MPTCP
 
 void mptcp_init(void);
 
+void mptcp_parse_option(const unsigned char *ptr, int opsize,
+			struct tcp_options_received *opt_rx);
+void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
+
 #else
 
 static inline void mptcp_init(void)
 {
 }
 
+static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
+				      struct tcp_options_received *opt_rx)
+{
+}
+
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
net/ipv4/tcp_input.c +5 -0
index 3578357abe30..8e04adff1912 100644
@@ -79,6 +79,7 @@
 #include <trace/events/tcp.h>
 #include <linux/jump_label_ratelimit.h>
 #include <net/busy_poll.h>
+#include <net/mptcp.h>
 
 int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
 
@@ -3918,6 +3919,10 @@ void tcp_parse_options(const struct net *net,
 				 */
 				break;
 #endif
+			case TCPOPT_MPTCP:
+				mptcp_parse_option(ptr, opsize, opt_rx);
+				break;
+
 			case TCPOPT_FASTOPEN:
 				tcp_parse_fastopen_option(
 					opsize - TCPOLEN_FASTOPEN_BASE,
net/ipv4/tcp_output.c +13 -0
index fec6d67bfd14..531929c68822 100644
@@ -38,6 +38,7 @@
 #define pr_fmt(fmt) "TCP: " fmt
 
 #include <net/tcp.h>
+#include <net/mptcp.h>
 
 #include <linux/compiler.h>
 #include <linux/gfp.h>
@@ -411,6 +412,7 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)
 #define OPTION_WSCALE		(1 << 3)
 #define OPTION_FAST_OPEN_COOKIE	(1 << 8)
 #define OPTION_SMC		(1 << 9)
+#define OPTION_MPTCP		(1 << 10)
 
 static void smc_options_write(__be32 *ptr, u16 *options)
 {
@@ -436,8 +438,17 @@ struct tcp_out_options {
 	__u8 *hash_location;	/* temporary pointer, overloaded */
 	__u32 tsval, tsecr;	/* need to include OPTION_TS */
 	struct tcp_fastopen_cookie *fastopen_cookie;	/* Fast open cookie */
+	struct mptcp_out_options mptcp;
 };
 
+static void mptcp_options_write(__be32 *ptr, struct tcp_out_options *opts)
+{
+#if IS_ENABLED(CONFIG_MPTCP)
+	if (unlikely(OPTION_MPTCP & opts->options))
+		mptcp_write_options(ptr, &opts->mptcp);
+#endif
+}
+
 /* Write previously computed TCP options to the packet.
  *
  * Beware: Something in the Internet is very sensitive to the ordering of
@@ -546,6 +557,8 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp,
 	}
 
 	smc_options_write(ptr, &options);
+
+	mptcp_options_write(ptr, opts);
 }
 
 static void smc_set_option(const struct tcp_sock *tp,
net/mptcp/Makefile +1 -1
index 659129d1fcbf..27a846263f08 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o
+mptcp-y := protocol.o options.o
net/mptcp/options.c new file +159 -0

159 lines not on this page · raw message

net/mptcp/protocol.h +27 -0
index ee04a01bffd3..26c48003f689 100644
@@ -7,6 +7,33 @@
 #ifndef __MPTCP_PROTOCOL_H
 #define __MPTCP_PROTOCOL_H
 
+/* MPTCP option bits */
+#define OPTION_MPTCP_MPC_SYN	BIT(0)
+#define OPTION_MPTCP_MPC_SYNACK	BIT(1)
+#define OPTION_MPTCP_MPC_ACK	BIT(2)
+
+/* MPTCP option subtypes */
+#define MPTCPOPT_MP_CAPABLE	0
+#define MPTCPOPT_MP_JOIN	1
+#define MPTCPOPT_DSS		2
+#define MPTCPOPT_ADD_ADDR	3
+#define MPTCPOPT_RM_ADDR	4
+#define MPTCPOPT_MP_PRIO	5
+#define MPTCPOPT_MP_FAIL	6
+#define MPTCPOPT_MP_FASTCLOSE	7
+
+/* MPTCP suboption lengths */
+#define TCPOLEN_MPTCP_MPC_SYN		12
+#define TCPOLEN_MPTCP_MPC_SYNACK	20
+#define TCPOLEN_MPTCP_MPC_ACK		20
+
+/* MPTCP MP_CAPABLE flags */
+#define MPTCP_VERSION_MASK	(0x0F)
+#define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
+#define MPTCP_CAP_EXTENSIBILITY	BIT(6)
+#define MPTCP_CAP_HMAC_SHA1	BIT(0)
+#define MPTCP_CAP_FLAG_MASK	(0x3F)
+
 /* MPTCP connection sock */
 struct mptcp_sock {
 	/* inet_connection_sock must be the first member */
Signature · 1 line
2.23.0
#7 lore raw

Re: [RFC PATCH v2 06/45] mptcp: Handle MPTCP TCP options

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s1-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:

>> include/net/mptcp.h:34:18: warning: 'struct tcp_options_received' declared inside parameter list
              struct tcp_options_received *opt_rx)
                     ^
>> include/net/mptcp.h:34:18: warning: its scope is only this definition or declaration, which is probably not what you want

vim +34 include/net/mptcp.h

32
33 static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,

  > 34					      struct tcp_options_received *opt_rx)
    35	{
    36	}
    37	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw

Re: [RFC PATCH v2 06/45] mptcp: Handle MPTCP TCP options

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u16'

     u16 suboptions;
     ^~~
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64 sndr_key;
     ^~~
   include/net/mptcp.h:15:2: error: unknown type name 'u64'
     u64 rcvr_key;
     ^~~
>> include/net/mptcp.h:24:11: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
       struct tcp_options_received *opt_rx);
              ^~~~~~~~~~~~~~~~~~~~
>> include/net/mptcp.h:25:26: error: unknown type name '__be32'; did you mean '__weak'?
    void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
                             ^~~~~~
                             __weak

vim +25 include/net/mptcp.h

    10	
    11	struct mptcp_out_options {
    12	#if IS_ENABLED(CONFIG_MPTCP)
  > 13		u16 suboptions;
  > 14		u64 sndr_key;
    15		u64 rcvr_key;
    16	#endif
    17	};
    18	
    19	#ifdef CONFIG_MPTCP
    20	
    21	void mptcp_init(void);
    22	
    23	void mptcp_parse_option(const unsigned char *ptr, int opsize,
  > 24				struct tcp_options_received *opt_rx);
  > 25	void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
    26	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#9 lore raw

RFC PATCH v2 7/45 mptcp: Associate MPTCP context with TCP socket

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Use ULP to associate a subflow_context structure with each TCP subflow socket.

---
 include/linux/tcp.h  |   3 ++
 net/mptcp/Makefile   |   2 +-
 net/mptcp/protocol.c |  51 +++++++++++++++++++--
 net/mptcp/protocol.h |  26 +++++++++++
 net/mptcp/subflow.c  | 106 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 184 insertions(+), 4 deletions(-)
 create mode 100644 net/mptcp/subflow.c
include/linux/tcp.h +3 -0
index 18594f40b310..b3311659c39a 100644
@@ -394,6 +394,9 @@ struct tcp_sock {
 	u32	mtu_info; /* We received an ICMP_FRAG_NEEDED / ICMPV6_PKT_TOOBIG
 			   * while socket was owned by user.
 			   */
+#if IS_ENABLED(CONFIG_MPTCP)
+	bool	is_mptcp;
+#endif
 
 #ifdef CONFIG_TCP_MD5SIG
 /* TCP AF-Specific parts; only used by MD5 Signature support so far */
net/mptcp/Makefile +1 -1
index 27a846263f08..e1ee5aade8b0 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o options.o
+mptcp-y := protocol.o subflow.o options.o
net/mptcp/protocol.c +48 -3

77 lines not on this page · raw message

net/mptcp/protocol.h +26 -0
index 26c48003f689..fe6b31bbad1b 100644
@@ -46,4 +46,30 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 	return (struct mptcp_sock *)sk;
 }
 
+/* MPTCP subflow context */
+struct mptcp_subflow_context {
+	u32	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_cksum : 1,
+		request_version : 4;
+	struct  socket *tcp_sock;  /* underlying tcp_sock */
+	struct  sock *conn;        /* parent mptcp_sock */
+};
+
+static inline struct mptcp_subflow_context *
+mptcp_subflow_ctx(const struct sock *sk)
+{
+	struct inet_connection_sock *icsk = inet_csk(sk);
+
+	return (struct mptcp_subflow_context *)icsk->icsk_ulp_data;
+}
+
+static inline struct socket *
+mptcp_subflow_tcp_socket(const struct mptcp_subflow_context *subflow)
+{
+	return subflow->tcp_sock;
+}
+
+void mptcp_subflow_init(void);
+int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
+
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.23.0
#10 lore raw

RFC PATCH v2 8/45 tcp: Expose tcp struct and routine for MPTCP

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

tcp_request_sock_ipv4_ops and tcp_v4_init_sock().

This function is needed for MPTCP subflow initialization.

---
 include/net/tcp.h   | 3 +++
 net/ipv4/tcp_ipv4.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
include/net/tcp.h +3 -0
index 382e245a7909..509b5539d3d1 100644
@@ -445,6 +445,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
 int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
 int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
 int tcp_connect(struct sock *sk);
+int tcp_v4_init_sock(struct sock *sk);
 enum tcp_synack_type {
 	TCP_SYNACK_NORMAL,
 	TCP_SYNACK_FASTOPEN,
@@ -1975,6 +1976,8 @@ struct tcp_request_sock_ops {
 			   enum tcp_synack_type synack_type);
 };
 
+extern const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops;
+
 #ifdef CONFIG_SYN_COOKIES
 static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops,
 					 const struct sock *sk, struct sk_buff *skb,
net/ipv4/tcp_ipv4.c +2 -2
index 2ee45e3755e9..e3f86dd2d2ec 100644
@@ -1371,7 +1371,7 @@ struct request_sock_ops tcp_request_sock_ops __read_mostly = {
 	.syn_ack_timeout =	tcp_syn_ack_timeout,
 };
 
-static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
+const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
 	.mss_clamp	=	TCP_MSS_DEFAULT,
 #ifdef CONFIG_TCP_MD5SIG
 	.req_md5_lookup	=	tcp_v4_md5_lookup,
@@ -2072,7 +2072,7 @@ static const struct tcp_sock_af_ops tcp_sock_ipv4_specific = {
 /* NOTE: A lot of things set to zero explicitly by call to
  *       sk_alloc() so need not be done here.
  */
-static int tcp_v4_init_sock(struct sock *sk)
+int tcp_v4_init_sock(struct sock *sk)
 {
 	struct inet_connection_sock *icsk = inet_csk(sk);
 
Signature · 1 line
2.23.0
#11 lore raw

RFC PATCH v2 9/45 mptcp: Handle MP_CAPABLE options for outgoing connections

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Add hooks to tcp_output.c to add MP_CAPABLE to an outgoing SYN request for a subflow socket and to the final ACK of the three-way handshake.

Use the .sk_rx_dst_set() handler in the subflow proto to capture when the responding SYN-ACK is received and notify the MPTCP connection layer.

---
 include/net/mptcp.h   |  33 +++++++++
 net/ipv4/tcp_input.c  |   3 +
 net/ipv4/tcp_output.c |  27 ++++++++
 net/mptcp/options.c   |  45 ++++++++++++
 net/mptcp/protocol.c  | 158 +++++++++++++++++++++++++++++++++++++-----
 net/mptcp/protocol.h  |  18 ++++-
 net/mptcp/subflow.c   |  25 ++++++-
 7 files changed, 289 insertions(+), 20 deletions(-)
include/net/mptcp.h +33 -0
index fc3f9286c667..e3e248b16016 100644
@@ -20,8 +20,19 @@ struct mptcp_out_options {
 
 void mptcp_init(void);
 
+static inline bool sk_is_mptcp(const struct sock *sk)
+{
+	return tcp_sk(sk)->is_mptcp;
+}
+
 void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			struct tcp_options_received *opt_rx);
+bool mptcp_syn_options(struct sock *sk, unsigned int *size,
+		       struct mptcp_out_options *opts);
+void mptcp_rcv_synsent(struct sock *sk);
+bool mptcp_established_options(struct sock *sk, unsigned int *size,
+			       struct mptcp_out_options *opts);
+
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
 
 #else
@@ -30,10 +41,32 @@ static inline void mptcp_init(void)
 {
 }
 
+static inline bool sk_is_mptcp(const struct sock *sk)
+{
+	return false;
+}
+
 static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
 				      struct tcp_options_received *opt_rx)
 {
 }
 
+static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
+				     struct mptcp_out_options *opts)
+{
+	return false;
+}
+
+static inline void mptcp_rcv_synsent(struct sock *sk)
+{
+}
+
+static inline bool mptcp_established_options(struct sock *sk,
+					     unsigned int *size,
+					     struct mptcp_out_options *opts)
+{
+	return false;
+}
+
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
net/ipv4/tcp_input.c +3 -0
index 8e04adff1912..e28f308006da 100644
@@ -5963,6 +5963,9 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 		tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
 		tcp_initialize_rcv_mss(sk);
 
+		if (sk_is_mptcp(sk))
+			mptcp_rcv_synsent(sk);
+
 		/* Remember, tcp_poll() does not lock socket!
 		 * Change state from SYN-SENT only after copied_seq
 		 * is initialized. */
net/ipv4/tcp_output.c +27 -0
index 531929c68822..2354500c8ebb 100644
@@ -663,6 +663,15 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
 
 	smc_set_option(tp, opts, &remaining);
 
+	if (sk_is_mptcp(sk)) {
+		unsigned int size;
+
+		if (mptcp_syn_options(sk, &size, &opts->mptcp)) {
+			opts->options |= OPTION_MPTCP;
+			remaining -= size;
+		}
+	}
+
 	return MAX_TCP_OPTION_SPACE - remaining;
 }
 
@@ -761,6 +770,24 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		size += TCPOLEN_TSTAMP_ALIGNED;
 	}
 
+	/* MPTCP options have precedence over SACK for the limited TCP
+	 * option space because a MPTCP connection would be forced to
+	 * fall back to regular TCP if a required multipath option is
+	 * missing. SACK still gets a chance to use whatever space is
+	 * left.
+	 */
+	if (sk_is_mptcp(sk)) {
+		unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
+		unsigned int opt_size;
+
+		if (mptcp_established_options(sk, &opt_size, &opts->mptcp)) {
+			if (remaining >= opt_size) {
+				opts->options |= OPTION_MPTCP;
+				size += opt_size;
+			}
+		}
+	}
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
net/mptcp/options.c +45 -0

51 lines not on this page · raw message

net/mptcp/protocol.c +141 -17

214 lines not on this page · raw message

net/mptcp/protocol.h +17 -1
index fe6b31bbad1b..2e000ba7caa4 100644
@@ -38,9 +38,15 @@
 struct mptcp_sock {
 	/* inet_connection_sock must be the first member */
 	struct inet_connection_sock sk;
+	u64		local_key;
+	u64		remote_key;
+	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 };
 
+#define mptcp_for_each_subflow(__msk, __subflow)			\
+	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
+
 static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 {
 	return (struct mptcp_sock *)sk;
@@ -48,9 +54,15 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 
 /* MPTCP subflow context */
 struct mptcp_subflow_context {
+	struct	list_head node;/* conn_list of subflows */
+	u64	local_key;
+	u64	remote_key;
 	u32	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
-		request_version : 4;
+		request_version : 4,
+		mp_capable : 1,	    /* remote is MPTCP capable */
+		fourth_ack : 1,     /* send initial DSS */
+		conn_finished : 1;
 	struct  socket *tcp_sock;  /* underlying tcp_sock */
 	struct  sock *conn;        /* parent mptcp_sock */
 };
@@ -72,4 +84,8 @@ mptcp_subflow_tcp_socket(const struct mptcp_subflow_context *subflow)
 void mptcp_subflow_init(void);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
+extern const struct inet_connection_sock_af_ops ipv4_specific;
+
+void mptcp_finish_connect(struct sock *sk, int mp_capable);
+
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +23 -2
index 5971fb5bfdf2..4690410d9922 100644
@@ -15,6 +15,22 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
+static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
+{
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+
+	inet_sk_rx_dst_set(sk, skb);
+
+	if (subflow->conn && !subflow->conn_finished) {
+		pr_debug("subflow=%p, remote_key=%llu", mptcp_subflow_ctx(sk),
+			 subflow->remote_key);
+		mptcp_finish_connect(subflow->conn, subflow->mp_capable);
+		subflow->conn_finished = 1;
+	}
+}
+
+static struct inet_connection_sock_af_ops subflow_specific;
+
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 {
 	struct mptcp_subflow_context *subflow;
@@ -66,8 +82,9 @@ static struct mptcp_subflow_context *subflow_create_ctx(struct sock *sk,
 
 static int subflow_ulp_init(struct sock *sk)
 {
-	struct tcp_sock *tsk = tcp_sk(sk);
+	struct inet_connection_sock *icsk = inet_csk(sk);
 	struct mptcp_subflow_context *ctx;
+	struct tcp_sock *tp = tcp_sk(sk);
 	int err = 0;
 
 	ctx = subflow_create_ctx(sk, sk->sk_socket);
@@ -78,7 +95,8 @@ static int subflow_ulp_init(struct sock *sk)
 
 	pr_debug("subflow=%p", ctx);
 
-	tsk->is_mptcp = 1;
+	tp->is_mptcp = 1;
+	icsk->icsk_af_ops = &subflow_specific;
 out:
 	return err;
 }
@@ -101,6 +119,9 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = {
 
 void mptcp_subflow_init(void)
 {
+	subflow_specific = ipv4_specific;
+	subflow_specific.sk_rx_dst_set = subflow_finish_connect;
+
 	if (tcp_register_ulp(&subflow_ulp_ops) != 0)
 		panic("MPTCP: failed to register subflows to ULP\n");
 }
Signature · 1 line
2.23.0
#12 lore raw

Re: [RFC PATCH v2 09/45] mptcp: Handle MP_CAPABLE options for outgoing connections

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s1-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:

>> include/net/mptcp.h:44:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^
>> include/net/mptcp.h:44:45: warning: 'struct sock' declared inside parameter list
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^
   include/net/mptcp.h:44:45: warning: its scope is only this definition or declaration, which is probably not what you want
   include/net/mptcp.h: In function 'sk_is_mptcp':
>> include/net/mptcp.h:46:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h:46:9: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:50:18: warning: 'struct tcp_options_received' declared inside parameter list
              struct tcp_options_received *opt_rx)
                     ^
   include/net/mptcp.h:54:15: error: unknown type name 'bool'
    static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                  ^
   include/net/mptcp.h:55:17: warning: 'struct sock' declared inside parameter list
             struct mptcp_out_options *opts)
                    ^
   include/net/mptcp.h: In function 'mptcp_syn_options':
   include/net/mptcp.h:57:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:60:45: warning: 'struct sock' declared inside parameter list
    static inline void mptcp_rcv_synsent(struct sock *sk)
                                                ^
   include/net/mptcp.h:64:15: error: unknown type name 'bool'
    static inline bool mptcp_established_options(struct sock *sk,
                  ^
   include/net/mptcp.h:66:18: warning: 'struct sock' declared inside parameter list
              struct mptcp_out_options *opts)
                     ^
   include/net/mptcp.h: In function 'mptcp_established_options':
   include/net/mptcp.h:68:9: error: 'false' undeclared (first use in this function)
     return false;
            ^

vim +/bool +44 include/net/mptcp.h

    43	
  > 44	static inline bool sk_is_mptcp(const struct sock *sk)
    45	{
  > 46		return false;
    47	}
    48	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#13 lore raw

Re: [RFC PATCH v2 09/45] mptcp: Handle MP_CAPABLE options for outgoing connections

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u16'

     u16 suboptions;
     ^~~
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64 sndr_key;
     ^~~
   include/net/mptcp.h:15:2: error: unknown type name 'u64'
     u64 rcvr_key;
     ^~~
   include/net/mptcp.h:23:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^~~~
>> include/net/mptcp.h:23:45: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^~~~
   include/net/mptcp.h: In function 'sk_is_mptcp':
>> include/net/mptcp.h:25:9: error: implicit declaration of function 'tcp_sk' [-Werror=implicit-function-declaration]
     return tcp_sk(sk)->is_mptcp;
            ^~~~~~
>> include/net/mptcp.h:25:19: error: invalid type argument of '->' (have 'int')
     return tcp_sk(sk)->is_mptcp;
                      ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:29:11: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
       struct tcp_options_received *opt_rx);
              ^~~~~~~~~~~~~~~~~~~~
>> include/net/mptcp.h:30:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:30:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                                  ^~~~
   include/net/mptcp.h:32:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_rcv_synsent(struct sock *sk);
                                  ^~~~
   include/net/mptcp.h:33:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:33:39: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
                                          ^~~~
   include/net/mptcp.h:36:26: error: unknown type name '__be32'; did you mean '__weak'?
    void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
                             ^~~~~~
                             __weak

cc1: some warnings being treated as errors

vim +/tcp_sk +25 include/net/mptcp.h

    10	
    11	struct mptcp_out_options {
    12	#if IS_ENABLED(CONFIG_MPTCP)
    13		u16 suboptions;
  > 14		u64 sndr_key;
    15		u64 rcvr_key;
    16	#endif
    17	};
    18	
    19	#ifdef CONFIG_MPTCP
    20	
    21	void mptcp_init(void);
    22	
  > 23	static inline bool sk_is_mptcp(const struct sock *sk)
    24	{
  > 25		return tcp_sk(sk)->is_mptcp;
    26	}
    27	
    28	void mptcp_parse_option(const unsigned char *ptr, int opsize,
    29				struct tcp_options_received *opt_rx);
  > 30	bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    31			       struct mptcp_out_options *opts);
    32	void mptcp_rcv_synsent(struct sock *sk);
    33	bool mptcp_established_options(struct sock *sk, unsigned int *size,
    34				       struct mptcp_out_options *opts);
    35	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#14 lore raw

RFC PATCH v2 10/45 mptcp: add mptcp_poll

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

Can't use tcp_poll directly:

BUG: KASAN: slab-out-of-bounds in tcp_poll+0x17f/0x540
Read of size 4 at addr ffff88806ac5e50c by task mptcp_connect/2085
Call Trace:
 tcp_poll+0x17f/0x540
 sock_poll+0x152/0x180
---
 net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
net/mptcp/protocol.c +31 -0
index 95c302c59d2e..07508d060b3d 100644
@@ -257,6 +257,36 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
 	return inet_stream_connect(msk->subflow, uaddr, addr_len, flags);
 }
 
+static __poll_t mptcp_poll(struct file *file, struct socket *sock,
+			   struct poll_table_struct *wait)
+{
+	struct mptcp_subflow_context *subflow;
+	const struct mptcp_sock *msk;
+	struct sock *sk = sock->sk;
+	struct socket *ssock;
+	__poll_t ret = 0;
+
+	msk = mptcp_sk(sk);
+	lock_sock(sk);
+	ssock = __mptcp_fallback_get_ref(msk);
+	if (ssock) {
+		release_sock(sk);
+		ret = tcp_poll(file, ssock, wait);
+		sock_put(ssock->sk);
+		return ret;
+	}
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct socket *tcp_sock;
+
+		tcp_sock = mptcp_subflow_tcp_socket(subflow);
+		ret |= tcp_poll(file, tcp_sock, wait);
+	}
+	release_sock(sk);
+
+	return ret;
+}
+
 static struct proto_ops mptcp_stream_ops;
 
 static struct inet_protosw mptcp_protosw = {
@@ -273,6 +303,7 @@ void __init mptcp_init(void)
 	mptcp_stream_ops = inet_stream_ops;
 	mptcp_stream_ops.bind = mptcp_bind;
 	mptcp_stream_ops.connect = mptcp_stream_connect;
+	mptcp_stream_ops.poll = mptcp_poll;
 
 	mptcp_subflow_init();
 
Signature · 1 line
2.23.0
#15 lore raw

RFC PATCH v2 11/45 tcp, ulp: Add clone operation to tcp_ulp_ops

In reply to Mat Martineau

If ULP is used on a listening socket, icsk_ulp_ops and icsk_ulp_data are copied when the listener is cloned. Sometimes the clone is immediately deleted, which will invoke the release op on the clone and likely corrupt the listening socket's icsk_ulp_data.

The clone operation is invoked immediately after the clone is copied and gives the ULP type an opportunity to set up the clone socket and its icsk_ulp_data.

---
 include/net/tcp.h               |  5 +++++
 net/ipv4/inet_connection_sock.c |  2 ++
 net/ipv4/tcp_ulp.c              | 12 ++++++++++++
 3 files changed, 19 insertions(+)
include/net/tcp.h +5 -0
index 509b5539d3d1..907fd214ff1e 100644
@@ -2129,6 +2129,9 @@ struct tcp_ulp_ops {
 	/* diagnostic */
 	int (*get_info)(const struct sock *sk, struct sk_buff *skb);
 	size_t (*get_info_size)(const struct sock *sk);
+	/* clone ulp */
+	void (*clone)(const struct request_sock *req, struct sock *newsk,
+		      const gfp_t priority);
 
 	char		name[TCP_ULP_NAME_MAX];
 	struct module	*owner;
@@ -2139,6 +2142,8 @@ int tcp_set_ulp(struct sock *sk, const char *name);
 void tcp_get_available_ulp(char *buf, size_t len);
 void tcp_cleanup_ulp(struct sock *sk);
 void tcp_update_ulp(struct sock *sk, struct proto *p);
+void tcp_clone_ulp(const struct request_sock *req,
+		   struct sock *newsk, const gfp_t priority);
 
 #define MODULE_ALIAS_TCP_ULP(name)				\
 	__MODULE_INFO(alias, alias_userspace, name);		\
net/ipv4/inet_connection_sock.c +2 -0
index a9183543ca30..64857672e0b5 100644
@@ -810,6 +810,8 @@ struct sock *inet_csk_clone_lock(const struct sock *sk,
 		/* Deinitialize accept_queue to trap illegal accesses. */
 		memset(&newicsk->icsk_accept_queue, 0, sizeof(newicsk->icsk_accept_queue));
 
+		tcp_clone_ulp(req, newsk, priority);
+
 		security_inet_csk_clone(newsk, req);
 	}
 	return newsk;
net/ipv4/tcp_ulp.c +12 -0
index 4849edb62d52..27f949846450 100644
@@ -127,6 +127,18 @@ void tcp_cleanup_ulp(struct sock *sk)
 	icsk->icsk_ulp_ops = NULL;
 }
 
+void tcp_clone_ulp(const struct request_sock *req, struct sock *newsk,
+		   const gfp_t priority)
+{
+	struct inet_connection_sock *icsk = inet_csk(newsk);
+
+	if (!icsk->icsk_ulp_ops)
+		return;
+
+	if (icsk->icsk_ulp_ops->clone)
+		icsk->icsk_ulp_ops->clone(req, newsk, priority);
+}
+
 static int __tcp_set_ulp(struct sock *sk, const struct tcp_ulp_ops *ulp_ops)
 {
 	struct inet_connection_sock *icsk = inet_csk(sk);
Signature · 1 line
2.23.0
#16 lore raw

RFC PATCH v2 12/45 mptcp: Create SUBFLOW socket for incoming connections

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Add subflow_request_sock type that extends tcp_request_sock and add an is_mptcp flag to tcp_request_sock distinguish them.

Override the listen() and accept() methods of the MPTCP socket proto_ops so they may act on the subflow socket.

Override the conn_request() and syn_recv_sock() handlers in the inet_connection_sock to handle incoming MPTCP SYNs and the ACK to the response SYN.

Add handling in tcp_output.c to add MP_CAPABLE to an outgoing SYN-ACK response for a subflow_request_sock.

---
 include/linux/tcp.h   |   3 +
 include/net/mptcp.h   |  19 ++++++
 net/ipv4/tcp_input.c  |   3 +
 net/ipv4/tcp_output.c |  18 ++++++
 net/mptcp/options.c   |  57 ++++++++++++++++-
 net/mptcp/protocol.c  | 138 ++++++++++++++++++++++++++++++++++++++++-
 net/mptcp/protocol.h  |  20 ++++++
 net/mptcp/subflow.c   | 140 ++++++++++++++++++++++++++++++++++++++++--
 8 files changed, 392 insertions(+), 6 deletions(-)
include/linux/tcp.h +3 -0
index b3311659c39a..220883a7a4db 100644
@@ -134,6 +134,9 @@ struct tcp_request_sock {
 	const struct tcp_request_sock_ops *af_specific;
 	u64				snt_synack; /* first SYNACK sent time */
 	bool				tfo_listener;
+#if IS_ENABLED(CONFIG_MPTCP)
+	bool				is_mptcp;
+#endif
 	u32				txhash;
 	u32				rcv_isn;
 	u32				snt_isn;
include/net/mptcp.h +19 -0
index e3e248b16016..1a3ed7734bb4 100644
@@ -25,11 +25,18 @@ static inline bool sk_is_mptcp(const struct sock *sk)
 	return tcp_sk(sk)->is_mptcp;
 }
 
+static inline bool rsk_is_mptcp(const struct request_sock *req)
+{
+	return tcp_rsk(req)->is_mptcp;
+}
+
 void mptcp_parse_option(const unsigned char *ptr, int opsize,
 			struct tcp_options_received *opt_rx);
 bool mptcp_syn_options(struct sock *sk, unsigned int *size,
 		       struct mptcp_out_options *opts);
 void mptcp_rcv_synsent(struct sock *sk);
+bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
+			  struct mptcp_out_options *opts);
 bool mptcp_established_options(struct sock *sk, unsigned int *size,
 			       struct mptcp_out_options *opts);
 
@@ -46,6 +53,11 @@ static inline bool sk_is_mptcp(const struct sock *sk)
 	return false;
 }
 
+static inline bool rsk_is_mptcp(const struct request_sock *req)
+{
+	return false;
+}
+
 static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
 				      struct tcp_options_received *opt_rx)
 {
@@ -61,6 +73,13 @@ static inline void mptcp_rcv_synsent(struct sock *sk)
 {
 }
 
+static inline bool mptcp_synack_options(const struct request_sock *req,
+					unsigned int *size,
+					struct mptcp_out_options *opts)
+{
+	return false;
+}
+
 static inline bool mptcp_established_options(struct sock *sk,
 					     unsigned int *size,
 					     struct mptcp_out_options *opts)
net/ipv4/tcp_input.c +3 -0
index e28f308006da..218df735c822 100644
@@ -6583,6 +6583,9 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 
 	tcp_rsk(req)->af_specific = af_ops;
 	tcp_rsk(req)->ts_off = 0;
+#if IS_ENABLED(CONFIG_MPTCP)
+	tcp_rsk(req)->is_mptcp = 0;
+#endif
 
 	tcp_clear_options(&tmp_opt);
 	tmp_opt.mss_clamp = af_ops->mss_clamp;
net/ipv4/tcp_output.c +18 -0
index 2354500c8ebb..e21e8134559a 100644
@@ -594,6 +594,22 @@ static void smc_set_option_cond(const struct tcp_sock *tp,
 #endif
 }
 
+static void mptcp_set_option_cond(const struct request_sock *req,
+				  struct tcp_out_options *opts,
+				  unsigned int *remaining)
+{
+	if (rsk_is_mptcp(req)) {
+		unsigned int size;
+
+		if (mptcp_synack_options(req, &size, &opts->mptcp)) {
+			if (*remaining >= size) {
+				opts->options |= OPTION_MPTCP;
+				*remaining -= size;
+			}
+		}
+	}
+}
+
 /* Compute TCP options for SYN packets. This is not the final
  * network wire format yet.
  */
@@ -733,6 +749,8 @@ static unsigned int tcp_synack_options(const struct sock *sk,
 		}
 	}
 
+	mptcp_set_option_cond(req, opts, &remaining);
+
 	smc_set_option_cond(tcp_sk(sk), ireq, opts, &remaining);
 
 	return MAX_TCP_OPTION_SPACE - remaining;
net/mptcp/options.c +56 -1

83 lines not on this page · raw message

net/mptcp/protocol.c +137 -1

162 lines not on this page · raw message

net/mptcp/protocol.h +20 -0
index 2e000ba7caa4..d228d1d3c8c3 100644
@@ -52,6 +52,23 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 	return (struct mptcp_sock *)sk;
 }
 
+struct mptcp_subflow_request_sock {
+	struct	tcp_request_sock sk;
+	u8	mp_capable : 1,
+		mp_join : 1,
+		checksum : 1,
+		backup : 1,
+		version : 4;
+	u64	local_key;
+	u64	remote_key;
+};
+
+static inline struct mptcp_subflow_request_sock *
+mptcp_subflow_rsk(const struct request_sock *rsk)
+{
+	return (struct mptcp_subflow_request_sock *)rsk;
+}
+
 /* MPTCP subflow context */
 struct mptcp_subflow_context {
 	struct	list_head node;/* conn_list of subflows */
@@ -86,6 +103,9 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
 
+void mptcp_get_options(const struct sk_buff *skb,
+		       struct tcp_options_received *opt_rx);
+
 void mptcp_finish_connect(struct sock *sk, int mp_capable);
 
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +136 -4

189 lines not on this page · raw message

Signature · 1 line
2.23.0
#17 lore raw

Re: [RFC PATCH v2 12/45] mptcp: Create SUBFLOW socket for incoming connections

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s1-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:51:15: error: unknown type name 'bool'
static inline bool sk_is_mptcp(const struct sock *sk)
^
include/net/mptcp.h:51:45: warning: 'struct sock' declared inside parameter list
static inline bool sk_is_mptcp(const struct sock *sk)
^
include/net/mptcp.h:51:45: warning: its scope is only this definition or declaration, which is probably not what you want include/net/mptcp.h: In function 'sk_is_mptcp':
include/net/mptcp.h:53:9: error: 'false' undeclared (first use in this function)

     return false;
            ^
   include/net/mptcp.h:53:9: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:56:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^
>> include/net/mptcp.h:56:46: warning: 'struct request_sock' declared inside parameter list
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^
   include/net/mptcp.h: In function 'rsk_is_mptcp':
   include/net/mptcp.h:58:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:62:18: warning: 'struct tcp_options_received' declared inside parameter list
              struct tcp_options_received *opt_rx)
                     ^
   include/net/mptcp.h:66:15: error: unknown type name 'bool'
    static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                  ^
   include/net/mptcp.h:67:17: warning: 'struct sock' declared inside parameter list
             struct mptcp_out_options *opts)
                    ^
   include/net/mptcp.h: In function 'mptcp_syn_options':
   include/net/mptcp.h:69:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:72:45: warning: 'struct sock' declared inside parameter list
    static inline void mptcp_rcv_synsent(struct sock *sk)
                                                ^
   include/net/mptcp.h:76:15: error: unknown type name 'bool'
    static inline bool mptcp_synack_options(const struct request_sock *req,
                  ^
   include/net/mptcp.h:78:13: warning: 'struct request_sock' declared inside parameter list
         struct mptcp_out_options *opts)
                ^
   include/net/mptcp.h: In function 'mptcp_synack_options':
   include/net/mptcp.h:80:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:83:15: error: unknown type name 'bool'
    static inline bool mptcp_established_options(struct sock *sk,
                  ^
   include/net/mptcp.h:85:18: warning: 'struct sock' declared inside parameter list
              struct mptcp_out_options *opts)
                     ^
   include/net/mptcp.h: In function 'mptcp_established_options':
   include/net/mptcp.h:87:9: error: 'false' undeclared (first use in this function)
     return false;
            ^

vim +56 include/net/mptcp.h

    50	
    51	static inline bool sk_is_mptcp(const struct sock *sk)
    52	{
  > 53		return false;
    54	}
    55	
  > 56	static inline bool rsk_is_mptcp(const struct request_sock *req)
    57	{
    58		return false;
    59	}
    60	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#18 lore raw

Re: [RFC PATCH v2 12/45] mptcp: Create SUBFLOW socket for incoming connections

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u16'

     u16 suboptions;
     ^~~
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64 sndr_key;
     ^~~
   include/net/mptcp.h:15:2: error: unknown type name 'u64'
     u64 rcvr_key;
     ^~~
   include/net/mptcp.h:23:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^~~~
   include/net/mptcp.h:23:45: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^~~~
   include/net/mptcp.h: In function 'sk_is_mptcp':
   include/net/mptcp.h:25:9: error: implicit declaration of function 'tcp_sk' [-Werror=implicit-function-declaration]
     return tcp_sk(sk)->is_mptcp;
            ^~~~~~
   include/net/mptcp.h:25:19: error: invalid type argument of '->' (have 'int')
     return tcp_sk(sk)->is_mptcp;
                      ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:28:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^~~~
>> include/net/mptcp.h:28:46: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^~~~~~~~~~~~
   include/net/mptcp.h: In function 'rsk_is_mptcp':
>> include/net/mptcp.h:30:9: error: implicit declaration of function 'tcp_rsk' [-Werror=implicit-function-declaration]
     return tcp_rsk(req)->is_mptcp;
            ^~~~~~~
   include/net/mptcp.h:30:21: error: invalid type argument of '->' (have 'int')
     return tcp_rsk(req)->is_mptcp;
                        ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:34:11: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
       struct tcp_options_received *opt_rx);
              ^~~~~~~~~~~~~~~~~~~~
   include/net/mptcp.h:35:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:35:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                                  ^~~~
   include/net/mptcp.h:37:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_rcv_synsent(struct sock *sk);
                                  ^~~~
   include/net/mptcp.h:38:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:38:40: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
                                           ^~~~~~~~~~~~
   include/net/mptcp.h:40:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:40:39: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
                                          ^~~~
   include/net/mptcp.h:43:26: error: unknown type name '__be32'; did you mean '__weak'?
    void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
                             ^~~~~~
                             __weak

cc1: some warnings being treated as errors

vim +/tcp_rsk +30 include/net/mptcp.h

    22	
    23	static inline bool sk_is_mptcp(const struct sock *sk)
    24	{
  > 25		return tcp_sk(sk)->is_mptcp;
    26	}
    27	
  > 28	static inline bool rsk_is_mptcp(const struct request_sock *req)
    29	{
  > 30		return tcp_rsk(req)->is_mptcp;
    31	}
    32	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#19 lore raw

RFC PATCH v2 13/45 mptcp: Add key generation and token tree

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Generate the local keys, IDSN, and token when creating a new socket. Introduce the token tree to track all tokens in use using a radix tree with the MPTCP token itself as the index.

Will be used to obtain the MPTCP parent socket to handle incoming joins.

---
 net/mptcp/Makefile   |   2 +-
 net/mptcp/crypto.c   | 128 ++++++++++++++++++++++++++++
 net/mptcp/protocol.c |  11 +++
 net/mptcp/protocol.h |  32 +++++++
 net/mptcp/subflow.c  |  65 +++++++++++++--
 net/mptcp/token.c    | 195 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 424 insertions(+), 9 deletions(-)
 create mode 100644 net/mptcp/crypto.c
 create mode 100644 net/mptcp/token.c
net/mptcp/Makefile +1 -1
index e1ee5aade8b0..178ae81d8b66 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o
net/mptcp/crypto.c new file +128 -0

128 lines not on this page · raw message

net/mptcp/protocol.c +11 -0
index 5605391fc32a..0a9c447db159 100644
@@ -133,6 +133,7 @@ static void mptcp_close(struct sock *sk, long timeout)
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct socket *ssk = NULL;
 
+	mptcp_token_destroy(msk->token);
 	inet_sk_state_store(sk, TCP_CLOSE);
 
 	lock_sock(sk);
@@ -198,6 +199,10 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		msk->local_key = subflow->local_key;
 		msk->subflow = NULL;
 
+		msk->token = subflow->token;
+
+		mptcp_token_update_accept(new_sock->sk, new_mptcp_sock);
+		msk->subflow = NULL;
 		newsk = new_mptcp_sock;
 		subflow->conn = new_mptcp_sock;
 		list_add(&subflow->node, &msk->conn_list);
@@ -215,6 +220,10 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 	return newsk;
 }
 
+static void mptcp_destroy(struct sock *sk)
+{
+}
+
 static int mptcp_get_port(struct sock *sk, unsigned short snum)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -258,6 +267,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 
 		msk->remote_key = subflow->remote_key;
 		msk->local_key = subflow->local_key;
+		msk->token = subflow->token;
 		list_add(&subflow->node, &msk->conn_list);
 		msk->subflow = NULL;
 		bh_unlock_sock(sk);
@@ -273,6 +283,7 @@ static struct proto mptcp_prot = {
 	.close		= mptcp_close,
 	.accept		= mptcp_accept,
 	.shutdown	= tcp_shutdown,
+	.destroy	= mptcp_destroy,
 	.sendmsg	= mptcp_sendmsg,
 	.recvmsg	= mptcp_recvmsg,
 	.hash		= inet_hash,
net/mptcp/protocol.h +32 -0
index d228d1d3c8c3..dea6d4f32f38 100644
@@ -7,6 +7,10 @@
 #ifndef __MPTCP_PROTOCOL_H
 #define __MPTCP_PROTOCOL_H
 
+#include <linux/random.h>
+#include <linux/tcp.h>
+#include <net/inet_connection_sock.h>
+
 /* MPTCP option bits */
 #define OPTION_MPTCP_MPC_SYN	BIT(0)
 #define OPTION_MPTCP_MPC_SYNACK	BIT(1)
@@ -40,6 +44,7 @@ struct mptcp_sock {
 	struct inet_connection_sock sk;
 	u64		local_key;
 	u64		remote_key;
+	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 };
@@ -61,6 +66,8 @@ struct mptcp_subflow_request_sock {
 		version : 4;
 	u64	local_key;
 	u64	remote_key;
+	u64	idsn;
+	u32	token;
 };
 
 static inline struct mptcp_subflow_request_sock *
@@ -74,6 +81,8 @@ struct mptcp_subflow_context {
 	struct	list_head node;/* conn_list of subflows */
 	u64	local_key;
 	u64	remote_key;
+	u64	idsn;
+	u32	token;
 	u32	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
 		request_version : 4,
@@ -108,4 +117,27 @@ void mptcp_get_options(const struct sk_buff *skb,
 
 void mptcp_finish_connect(struct sock *sk, int mp_capable);
 
+int mptcp_token_new_request(struct request_sock *req);
+void mptcp_token_destroy_request(u32 token);
+int mptcp_token_new_connect(struct sock *sk);
+int mptcp_token_new_accept(u32 token);
+void mptcp_token_update_accept(struct sock *sk, struct sock *conn);
+void mptcp_token_destroy(u32 token);
+
+void mptcp_crypto_key_sha1(u64 key, u32 *token, u64 *idsn);
+static inline void mptcp_crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
+{
+	/* we might consider a faster version that computes the key as a
+	 * hash of some information available in the MPTCP socket. Use
+	 * random data at the moment, as it's probably the safest option
+	 * in case multiple sockets are opened in different namespaces at
+	 * the same time.
+	 */
+	get_random_bytes(key, sizeof(u64));
+	mptcp_crypto_key_sha1(*key, token, idsn);
+}
+
+void mptcp_crypto_hmac_sha1(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
+			    u32 *hash_out);
+
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +57 -8

123 lines not on this page · raw message

net/mptcp/token.c new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
2.23.0
#20 lore raw

Re: [RFC PATCH v2 13/45] mptcp: Add key generation and token tree

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
reproduce:

        # apt-get install sparse
        # sparse version: v0.6.1-rc1-7-g2b96cd8-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag

sparse warnings: (new ones prefixed by >>)

include/linux/sched.h:595:43: sparse: sparse: bad integer constant expression include/linux/sched.h:595:73: sparse: sparse: invalid named zero-width bitfield value' include/linux/sched.h:596:43: sparse: sparse: bad integer constant expression include/linux/sched.h:596:67: sparse: sparse: invalid named zero-width bitfield bucket_id'

>> net/mptcp/token.c:164:17: sparse: sparse: incompatible types in comparison expression (different address spaces):
>> net/mptcp/token.c:164:17: sparse:    void [noderef] <asn:4> *
>> net/mptcp/token.c:164:17: sparse:    int *

vim +164 net/mptcp/token.c

145
146 /**
147 * mptcp_token_update_accept - update token to map to mptcp socket
148 * @conn: the new struct mptcp_sock
149 * @sk: the initial subflow for this mptcp socket
150 *
151 * Called when the first mptcp socket is created on accept to
152 * refresh the dummy mapping (done to reserve the token) with
153 * the mptcp_socket structure that wasn't allocated before.
154 */
155 void mptcp_token_update_accept(struct sock *sk, struct sock *conn)
156 {
157 struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
158 void __rcu **slot;
159
160 spin_lock_bh(&token_tree_lock);
161 slot = radix_tree_lookup_slot(&token_tree, subflow->token);
162 WARN_ON_ONCE(!slot);
163 if (slot) {

 > 164			WARN_ON_ONCE(*slot != &token_used);

165 *slot = conn;
166 }
167 spin_unlock_bh(&token_tree_lock);
168 }
169

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#21 lore raw

RFC PATCH v2 14/45 mptcp: Add shutdown() socket operation

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Call shutdown on all subflows in use on the given socket, or on the fallback socket.

---
 net/mptcp/protocol.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
net/mptcp/protocol.c +32 -0
index 0a9c447db159..dba4d7a4a61a 100644
@@ -431,6 +431,37 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 	return ret;
 }
 
+static int mptcp_shutdown(struct socket *sock, int how)
+{
+	struct mptcp_sock *msk = mptcp_sk(sock->sk);
+	struct mptcp_subflow_context *subflow;
+	struct socket *ssock;
+	int ret = 0;
+
+	pr_debug("sk=%p, how=%d", msk, how);
+
+	lock_sock(sock->sk);
+	ssock = __mptcp_fallback_get_ref(msk);
+	if (ssock) {
+		release_sock(sock->sk);
+		pr_debug("subflow=%p", ssock->sk);
+		ret = kernel_sock_shutdown(ssock, how);
+		sock_put(ssock->sk);
+		return ret;
+	}
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct socket *tcp_socket;
+
+		tcp_socket = mptcp_subflow_tcp_socket(subflow);
+		pr_debug("conn_list->subflow=%p", subflow);
+		ret = kernel_sock_shutdown(tcp_socket, how);
+	}
+	release_sock(sock->sk);
+
+	return ret;
+}
+
 static struct proto_ops mptcp_stream_ops;
 
 static struct inet_protosw mptcp_protosw = {
@@ -451,6 +482,7 @@ void __init mptcp_init(void)
 	mptcp_stream_ops.accept = mptcp_stream_accept;
 	mptcp_stream_ops.getname = mptcp_getname;
 	mptcp_stream_ops.listen = mptcp_listen;
+	mptcp_stream_ops.shutdown = mptcp_shutdown;
 
 	mptcp_subflow_init();
 
Signature · 1 line
2.23.0
#22 lore raw

RFC PATCH v2 15/45 mptcp: Add setsockopt()/getsockopt() socket operations

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

set/getsockopt behaviour with multiple subflows is undefined. Therefore, for now, we return -EOPNOTSUPP unless we're in fallback mode.

---
 net/mptcp/protocol.c | 67 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
net/mptcp/protocol.c +67 -0
index dba4d7a4a61a..41588758f74b 100644
@@ -28,6 +28,17 @@ static struct socket *__mptcp_fallback_get_ref(const struct mptcp_sock *msk)
 	return msk->subflow;
 }
 
+static struct socket *mptcp_fallback_get_ref(const struct mptcp_sock *msk)
+{
+	struct socket *ssock;
+
+	lock_sock((struct sock *)msk);
+	ssock = __mptcp_fallback_get_ref(msk);
+	release_sock((struct sock *)msk);
+
+	return ssock;
+}
+
 static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)
 {
 	struct mptcp_subflow_context *subflow;
@@ -224,6 +235,60 @@ static void mptcp_destroy(struct sock *sk)
 {
 }
 
+static int mptcp_setsockopt(struct sock *sk, int level, int optname,
+			    char __user *uoptval, unsigned int optlen)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	char __kernel *optval;
+	struct socket *ssock;
+	int ret;
+
+	/* will be treated as __user in tcp_setsockopt */
+	optval = (char __kernel __force *)uoptval;
+
+	pr_debug("msk=%p", msk);
+	ssock = mptcp_fallback_get_ref(msk);
+	if (ssock) {
+		pr_debug("subflow=%p", ssock->sk);
+		ret = kernel_setsockopt(ssock, level, optname, optval, optlen);
+		sock_put(ssock->sk);
+		return ret;
+	}
+
+	/* @@ the meaning of setsockopt() when the socket is connected and
+	 * there are multiple subflows is not defined.
+	 */
+	return -EOPNOTSUPP;
+}
+
+static int mptcp_getsockopt(struct sock *sk, int level, int optname,
+			    char __user *uoptval, int __user *uoption)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	char __kernel *optval;
+	int __kernel *option;
+	struct socket *ssock;
+	int ret;
+
+	/* will be treated as __user in tcp_getsockopt */
+	optval = (char __kernel __force *)uoptval;
+	option = (int __kernel __force *)uoption;
+
+	pr_debug("msk=%p", msk);
+	ssock = mptcp_fallback_get_ref(msk);
+	if (ssock) {
+		pr_debug("subflow=%p", ssock->sk);
+		ret = kernel_getsockopt(ssock, level, optname, optval, option);
+		sock_put(ssock->sk);
+		return ret;
+	}
+
+	/* @@ the meaning of getsockopt() when the socket is connected and
+	 * there are multiple subflows is not defined.
+	 */
+	return -EOPNOTSUPP;
+}
+
 static int mptcp_get_port(struct sock *sk, unsigned short snum)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -282,6 +347,8 @@ static struct proto mptcp_prot = {
 	.init		= mptcp_init_sock,
 	.close		= mptcp_close,
 	.accept		= mptcp_accept,
+	.setsockopt	= mptcp_setsockopt,
+	.getsockopt	= mptcp_getsockopt,
 	.shutdown	= tcp_shutdown,
 	.destroy	= mptcp_destroy,
 	.sendmsg	= mptcp_sendmsg,
Signature · 1 line
2.23.0
#23 lore raw

RFC PATCH v2 16/45 tcp: clean ext on tx recycle

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

Otherwise we will find stray/unexpected/old extensions value on next iteration.

On tcp_write_xmit() we can end-up splitting an already queued skb in two parts, via tso_fragment(). The newly created skb can be allocated via the tx cache and the mptcp stack will not be aware of it, so nobody set properly the MPTCP ext.

End result, we transmit the skb using an hold MPTCP DSS map and that confuses the rx side/corrupt the stream. It requires some concurrent conditions, so it's not deterministic.

Resetting the ext on recycle fixes all the current mptcp self tests issues.

Apparently only MPTCP has issues with this kind of stray ext, so an alternative would be add an additional mptcp hook in tso_fragment() or in sk_stream_alloc_skb() to always init the ext.

---
 include/linux/skbuff.h | 8 ++++++++
 include/net/sock.h     | 1 +
 2 files changed, 9 insertions(+)
include/linux/skbuff.h +8 -0
index e7d3b1a513ef..e7a7abd62026 100644
@@ -4099,6 +4099,14 @@ static inline void skb_ext_put(struct sk_buff *skb)
 		__skb_ext_put(skb->extensions);
 }
 
+static inline void skb_ext_clear(struct sk_buff *skb)
+{
+	if (skb->active_extensions) {
+		__skb_ext_put(skb->extensions);
+		skb->active_extensions = 0;
+	}
+}
+
 static inline void __skb_ext_copy(struct sk_buff *dst,
 				  const struct sk_buff *src)
 {
include/net/sock.h +1 -0
index ca2071555dde..b9a085d0bb18 100644
@@ -1470,6 +1470,7 @@ static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
 	sk_mem_uncharge(sk, skb->truesize);
 	if (static_branch_unlikely(&tcp_tx_skb_cache_key) &&
 	    !sk->sk_tx_skb_cache && !skb_cloned(skb)) {
+		skb_ext_clear(skb);
 		skb_zcopy_clear(skb, true);
 		sk->sk_tx_skb_cache = skb;
 		return;
Signature · 1 line
2.23.0
#24 lore raw

Re: [RFC PATCH v2 16/45] tcp: clean ext on tx recycle

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

In file included from include/linux/tcp.h:19:0,

                    from include/linux/ipv6.h:87,
                    from include/net/ipv6.h:12,
                    from include/linux/sunrpc/clnt.h:28,
                    from include/linux/nfs_fs.h:32,
                    from init/do_mounts.c:23:
   include/net/sock.h: In function 'sk_wmem_free_skb':
>> include/net/sock.h:1473:3: error: implicit declaration of function 'skb_ext_clear'; did you mean 'skb_ext_copy'? [-Werror=implicit-function-declaration]
      skb_ext_clear(skb);
      ^~~~~~~~~~~~~
      skb_ext_copy

cc1: some warnings being treated as errors

vim +1473 include/net/sock.h

1464
1465 DECLARE_STATIC_KEY_FALSE(tcp_tx_skb_cache_key);
1466 static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
1467 {
1468 sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1469 sk->sk_wmem_queued -= skb->truesize;
1470 sk_mem_uncharge(sk, skb->truesize);
1471 if (static_branch_unlikely(&tcp_tx_skb_cache_key) &&
1472 !sk->sk_tx_skb_cache && !skb_cloned(skb)) {

> 1473			skb_ext_clear(skb);

1474 skb_zcopy_clear(skb, true);
1475 sk->sk_tx_skb_cache = skb;
1476 return;
1477 }
1478 __kfree_skb(skb);
1479 }
1480

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#25 lore raw

Re: [RFC PATCH v2 16/45] tcp: clean ext on tx recycle

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s0-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

In file included from include/linux/sock_diag.h:8:0,
from kernel//bpf/reuseport_array.c:7:
include/net/sock.h: In function 'sk_wmem_free_skb':

>> include/net/sock.h:1473:3: error: implicit declaration of function 'skb_ext_clear' [-Werror=implicit-function-declaration]
      skb_ext_clear(skb);
      ^

cc1: some warnings being treated as errors

vim +/skb_ext_clear +1473 include/net/sock.h

1464
1465 DECLARE_STATIC_KEY_FALSE(tcp_tx_skb_cache_key);
1466 static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
1467 {
1468 sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
1469 sk->sk_wmem_queued -= skb->truesize;
1470 sk_mem_uncharge(sk, skb->truesize);
1471 if (static_branch_unlikely(&tcp_tx_skb_cache_key) &&
1472 !sk->sk_tx_skb_cache && !skb_cloned(skb)) {

> 1473			skb_ext_clear(skb);

1474 skb_zcopy_clear(skb, true);
1475 sk->sk_tx_skb_cache = skb;
1476 return;
1477 }
1478 __kfree_skb(skb);
1479 }
1480

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#26 lore raw

RFC PATCH v2 17/45 mptcp: Add MPTCP to skb extensions

In reply to Mat Martineau

Add enum value for MPTCP and update config dependencies

---
 include/linux/skbuff.h |  3 +++
 include/net/mptcp.h    | 16 ++++++++++++++++
 net/core/skbuff.c      |  7 +++++++
 net/mptcp/Kconfig      |  1 +
 4 files changed, 27 insertions(+)
include/linux/skbuff.h +3 -0
index e7a7abd62026..5a9b26ff44e9 100644
@@ -4068,6 +4068,9 @@ enum skb_ext_id {
 #endif
 #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
 	TC_SKB_EXT,
+#endif
+#if IS_ENABLED(CONFIG_MPTCP)
+	SKB_EXT_MPTCP,
 #endif
 	SKB_EXT_NUM, /* must be last */
 };
include/net/mptcp.h +16 -0
index 1a3ed7734bb4..6921b7fb6f0d 100644
@@ -8,6 +8,22 @@
 #ifndef __NET_MPTCP_H
 #define __NET_MPTCP_H
 
+/* MPTCP sk_buff extension data */
+struct mptcp_ext {
+	u64		data_ack;
+	u64		data_seq;
+	u32		subflow_seq;
+	u16		data_len;
+	__sum16		checksum;
+	u8		use_map:1,
+			dsn64:1,
+			use_checksum:1,
+			data_fin:1,
+			use_ack:1,
+			ack64:1,
+			__unused:2;
+};
+
 struct mptcp_out_options {
 #if IS_ENABLED(CONFIG_MPTCP)
 	u16 suboptions;
net/core/skbuff.c +7 -0
index 01d65206f4fb..20094629e103 100644
@@ -68,6 +68,7 @@
 #include <net/ip6_checksum.h>
 #include <net/xfrm.h>
 #include <net/mpls.h>
+#include <net/mptcp.h>
 
 #include <linux/uaccess.h>
 #include <trace/events/skb.h>
@@ -4109,6 +4110,9 @@ static const u8 skb_ext_type_len[] = {
 #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
 	[TC_SKB_EXT] = SKB_EXT_CHUNKSIZEOF(struct tc_skb_ext),
 #endif
+#if IS_ENABLED(CONFIG_MPTCP)
+	[SKB_EXT_MPTCP] = SKB_EXT_CHUNKSIZEOF(struct mptcp_ext),
+#endif
 };
 
 static __always_inline unsigned int skb_ext_total_length(void)
@@ -4122,6 +4126,9 @@ static __always_inline unsigned int skb_ext_total_length(void)
 #endif
 #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
 		skb_ext_type_len[TC_SKB_EXT] +
+#endif
+#if IS_ENABLED(CONFIG_MPTCP)
+		skb_ext_type_len[SKB_EXT_MPTCP] +
 #endif
 		0;
 }
net/mptcp/Kconfig +1 -0
index d87dfdc210cc..f21190a4f7e9 100644
@@ -2,6 +2,7 @@
 config MPTCP
 	bool "Multipath TCP"
 	depends on INET
+	select SKB_EXTENSIONS
 	help
 	  Multipath TCP (MPTCP) connections send and receive data over multiple
 	  subflows in order to utilize multiple network paths. Each subflow
Signature · 1 line
2.23.0
#27 lore raw

Re: [RFC PATCH v2 17/45] mptcp: Add MPTCP to skb extensions

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191003]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s1-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

In file included from <command-line>:0:0:

>> include/net/mptcp.h:13:2: error: unknown type name 'u64'
     u64  data_ack;
     ^
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64  data_seq;
     ^
>> include/net/mptcp.h:15:2: error: unknown type name 'u32'
     u32  subflow_seq;
     ^
>> include/net/mptcp.h:16:2: error: unknown type name 'u16'
     u16  data_len;
     ^
>> include/net/mptcp.h:17:2: error: unknown type name '__sum16'
     __sum16  checksum;
     ^
>> include/net/mptcp.h:18:2: error: unknown type name 'u8'
     u8  use_map:1,
     ^
   include/net/mptcp.h:67:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^
   include/net/mptcp.h:67:45: warning: 'struct sock' declared inside parameter list
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^
   include/net/mptcp.h:67:45: warning: its scope is only this definition or declaration, which is probably not what you want
   include/net/mptcp.h: In function 'sk_is_mptcp':
   include/net/mptcp.h:69:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h:69:9: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:72:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^
   include/net/mptcp.h:72:46: warning: 'struct request_sock' declared inside parameter list
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^
   include/net/mptcp.h: In function 'rsk_is_mptcp':
   include/net/mptcp.h:74:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:78:18: warning: 'struct tcp_options_received' declared inside parameter list
              struct tcp_options_received *opt_rx)
                     ^
   include/net/mptcp.h:82:15: error: unknown type name 'bool'
    static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                  ^
   include/net/mptcp.h:83:17: warning: 'struct sock' declared inside parameter list
             struct mptcp_out_options *opts)
                    ^
   include/net/mptcp.h: In function 'mptcp_syn_options':
   include/net/mptcp.h:85:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:88:45: warning: 'struct sock' declared inside parameter list
    static inline void mptcp_rcv_synsent(struct sock *sk)
                                                ^
   include/net/mptcp.h:92:15: error: unknown type name 'bool'
    static inline bool mptcp_synack_options(const struct request_sock *req,
                  ^
   include/net/mptcp.h:94:13: warning: 'struct request_sock' declared inside parameter list
         struct mptcp_out_options *opts)
                ^
   include/net/mptcp.h: In function 'mptcp_synack_options':
   include/net/mptcp.h:96:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:99:15: error: unknown type name 'bool'
    static inline bool mptcp_established_options(struct sock *sk,
                  ^
   include/net/mptcp.h:101:18: warning: 'struct sock' declared inside parameter list
              struct mptcp_out_options *opts)
                     ^
   include/net/mptcp.h: In function 'mptcp_established_options':
   include/net/mptcp.h:103:9: error: 'false' undeclared (first use in this function)
     return false;
            ^

vim +/u64 +13 include/net/mptcp.h

    10	
    11	/* MPTCP sk_buff extension data */
    12	struct mptcp_ext {
  > 13		u64		data_ack;
  > 14		u64		data_seq;
  > 15		u32		subflow_seq;
  > 16		u16		data_len;
  > 17		__sum16		checksum;
  > 18		u8		use_map:1,
    19				dsn64:1,
    20				use_checksum:1,
    21				data_fin:1,
    22				use_ack:1,
    23				ack64:1,
    24				__unused:2;
    25	};
    26	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#28 lore raw

RFC PATCH v2 18/45 tcp: Prevent coalesce/collapse when skb has MPTCP extensions

In reply to Mat Martineau

The MPTCP extension data needs to be preserved as it passes through the TCP stack. Make sure that these skbs are not appended to others during coalesce or collapse, so the data remains associated with the payload of the given skb.

---
 include/net/mptcp.h   | 10 ++++++++++
 include/net/tcp.h     |  8 ++++++++
 net/ipv4/tcp_input.c  | 10 ++++++++--
 net/ipv4/tcp_output.c |  2 +-
 4 files changed, 27 insertions(+), 3 deletions(-)
include/net/mptcp.h +10 -0
index 6921b7fb6f0d..5ec275708036 100644
@@ -56,6 +56,11 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 bool mptcp_established_options(struct sock *sk, unsigned int *size,
 			       struct mptcp_out_options *opts);
 
+static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
+{
+	return skb_ext_exist(skb, SKB_EXT_MPTCP);
+}
+
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
 
 #else
@@ -103,5 +108,10 @@ static inline bool mptcp_established_options(struct sock *sk,
 	return false;
 }
 
+static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
+{
+	return false;
+}
+
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
include/net/tcp.h +8 -0
index 907fd214ff1e..ddc098b33999 100644
@@ -39,6 +39,7 @@
 #include <net/tcp_states.h>
 #include <net/inet_ecn.h>
 #include <net/dst.h>
+#include <net/mptcp.h>
 
 #include <linux/seq_file.h>
 #include <linux/memcontrol.h>
@@ -962,6 +963,13 @@ static inline bool tcp_skb_can_collapse_to(const struct sk_buff *skb)
 	return likely(!TCP_SKB_CB(skb)->eor);
 }
 
+static inline bool tcp_skb_can_collapse(const struct sk_buff *to,
+					const struct sk_buff *from)
+{
+	return likely(tcp_skb_can_collapse_to(to) &&
+		      !mptcp_skb_ext_exist(from));
+}
+
 /* Events passed to congestion control interface */
 enum tcp_ca_event {
 	CA_EVENT_TX_START,	/* first transmit when no packets in flight */
net/ipv4/tcp_input.c +8 -2
index 218df735c822..04267684babf 100644
@@ -1421,7 +1421,7 @@ static struct sk_buff *tcp_shift_skb_data(struct sock *sk, struct sk_buff *skb,
 	if ((TCP_SKB_CB(prev)->sacked & TCPCB_TAGBITS) != TCPCB_SACKED_ACKED)
 		goto fallback;
 
-	if (!tcp_skb_can_collapse_to(prev))
+	if (!tcp_skb_can_collapse(prev, skb))
 		goto fallback;
 
 	in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) &&
@@ -4423,6 +4423,9 @@ static bool tcp_try_coalesce(struct sock *sk,
 	if (TCP_SKB_CB(from)->seq != TCP_SKB_CB(to)->end_seq)
 		return false;
 
+	if (mptcp_skb_ext_exist(from))
+		return false;
+
 #ifdef CONFIG_TLS_DEVICE
 	if (from->decrypted != to->decrypted)
 		return false;
@@ -4931,10 +4934,12 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
 
 		/* The first skb to collapse is:
 		 * - not SYN/FIN and
+		 * - does not include a MPTCP skb extension
 		 * - bloated or contains data before "start" or
 		 *   overlaps to the next one.
 		 */
 		if (!(TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) &&
+		    !mptcp_skb_ext_exist(skb) &&
 		    (tcp_win_from_space(sk, skb->truesize) > skb->len ||
 		     before(TCP_SKB_CB(skb)->seq, start))) {
 			end_of_skbs = false;
@@ -4950,7 +4955,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
 		/* Decided to skip this, advance start seq. */
 		start = TCP_SKB_CB(skb)->end_seq;
 	}
-	if (end_of_skbs ||
+	if (end_of_skbs || mptcp_skb_ext_exist(skb) ||
 	    (TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)))
 		return;
 
@@ -4993,6 +4998,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
 				skb = tcp_collapse_one(sk, skb, list, root);
 				if (!skb ||
 				    skb == tail ||
+				    mptcp_skb_ext_exist(skb) ||
 				    (TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)))
 					goto end;
 #ifdef CONFIG_TLS_DEVICE
net/ipv4/tcp_output.c +1 -1
index e21e8134559a..415b0414d738 100644
@@ -2911,7 +2911,7 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
 		if (!tcp_can_collapse(sk, skb))
 			break;
 
-		if (!tcp_skb_can_collapse_to(to))
+		if (!tcp_skb_can_collapse(to, skb))
 			break;
 
 		space -= skb->len;
Signature · 1 line
2.23.0
#29 lore raw

Re: [RFC PATCH v2 18/45] tcp: Prevent coalesce/collapse when skb has MPTCP extensions

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191003]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u64'

     u64  data_ack;
     ^~~
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64  data_seq;
     ^~~
   include/net/mptcp.h:15:2: error: unknown type name 'u32'
     u32  subflow_seq;
     ^~~
   include/net/mptcp.h:16:2: error: unknown type name 'u16'
     u16  data_len;
     ^~~
   include/net/mptcp.h:17:2: error: unknown type name '__sum16'
     __sum16  checksum;
     ^~~~~~~
   include/net/mptcp.h:18:2: error: unknown type name 'u8'
     u8  use_map:1,
     ^~
   include/net/mptcp.h:29:2: error: unknown type name 'u16'
     u16 suboptions;
     ^~~
   include/net/mptcp.h:30:2: error: unknown type name 'u64'
     u64 sndr_key;
     ^~~
   include/net/mptcp.h:31:2: error: unknown type name 'u64'
     u64 rcvr_key;
     ^~~
   include/net/mptcp.h:39:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^~~~
   include/net/mptcp.h:39:45: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^~~~
   include/net/mptcp.h: In function 'sk_is_mptcp':
   include/net/mptcp.h:41:9: error: implicit declaration of function 'tcp_sk' [-Werror=implicit-function-declaration]
     return tcp_sk(sk)->is_mptcp;
            ^~~~~~
   include/net/mptcp.h:41:19: error: invalid type argument of '->' (have 'int')
     return tcp_sk(sk)->is_mptcp;
                      ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:44:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^~~~
   include/net/mptcp.h:44:46: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^~~~~~~~~~~~
   include/net/mptcp.h: In function 'rsk_is_mptcp':
   include/net/mptcp.h:46:9: error: implicit declaration of function 'tcp_rsk' [-Werror=implicit-function-declaration]
     return tcp_rsk(req)->is_mptcp;
            ^~~~~~~
   include/net/mptcp.h:46:21: error: invalid type argument of '->' (have 'int')
     return tcp_rsk(req)->is_mptcp;
                        ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:50:11: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
       struct tcp_options_received *opt_rx);
              ^~~~~~~~~~~~~~~~~~~~
   include/net/mptcp.h:51:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:51:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                                  ^~~~
   include/net/mptcp.h:53:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_rcv_synsent(struct sock *sk);
                                  ^~~~
   include/net/mptcp.h:54:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:54:40: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
                                           ^~~~~~~~~~~~
   include/net/mptcp.h:56:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:56:39: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_established_options(struct sock *sk, unsigned int *size,
                                          ^~~~
   include/net/mptcp.h:59:15: error: unknown type name 'bool'
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                  ^~~~
>> include/net/mptcp.h:59:53: warning: 'struct sk_buff' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                                                        ^~~~~~~
   include/net/mptcp.h: In function 'mptcp_skb_ext_exist':
>> include/net/mptcp.h:61:9: error: implicit declaration of function 'skb_ext_exist'; did you mean 'mptcp_skb_ext_exist'? [-Werror=implicit-function-declaration]
     return skb_ext_exist(skb, SKB_EXT_MPTCP);
            ^~~~~~~~~~~~~
            mptcp_skb_ext_exist
>> include/net/mptcp.h:61:28: error: 'SKB_EXT_MPTCP' undeclared (first use in this function)
     return skb_ext_exist(skb, SKB_EXT_MPTCP);
                               ^~~~~~~~~~~~~
   include/net/mptcp.h:61:28: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:64:26: error: unknown type name '__be32'; did you mean '__weak'?
    void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
                             ^~~~~~
                             __weak

cc1: some warnings being treated as errors

vim +61 include/net/mptcp.h

    48	
    49	void mptcp_parse_option(const unsigned char *ptr, int opsize,
    50				struct tcp_options_received *opt_rx);
    51	bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    52			       struct mptcp_out_options *opts);
    53	void mptcp_rcv_synsent(struct sock *sk);
    54	bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
    55				  struct mptcp_out_options *opts);
  > 56	bool mptcp_established_options(struct sock *sk, unsigned int *size,
    57				       struct mptcp_out_options *opts);
    58	
  > 59	static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
    60	{
  > 61		return skb_ext_exist(skb, SKB_EXT_MPTCP);
    62	}
    63	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#30 lore raw

Re: [RFC PATCH v2 18/45] tcp: Prevent coalesce/collapse when skb has MPTCP extensions

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191003]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: x86_64-randconfig-s1-201939 (attached as .config)
compiler: gcc-5 (Ubuntu 5.5.0-12ubuntu1) 5.5.0 20171010 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u64'

     u64  data_ack;
     ^
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64  data_seq;
     ^
   include/net/mptcp.h:15:2: error: unknown type name 'u32'
     u32  subflow_seq;
     ^
   include/net/mptcp.h:16:2: error: unknown type name 'u16'
     u16  data_len;
     ^
   include/net/mptcp.h:17:2: error: unknown type name '__sum16'
     __sum16  checksum;
     ^
   include/net/mptcp.h:18:2: error: unknown type name 'u8'
     u8  use_map:1,
     ^
   include/net/mptcp.h:72:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^
   include/net/mptcp.h:72:45: warning: 'struct sock' declared inside parameter list
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^
   include/net/mptcp.h:72:45: warning: its scope is only this definition or declaration, which is probably not what you want
   include/net/mptcp.h: In function 'sk_is_mptcp':
   include/net/mptcp.h:74:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h:74:9: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:77:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^
   include/net/mptcp.h:77:46: warning: 'struct request_sock' declared inside parameter list
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^
   include/net/mptcp.h: In function 'rsk_is_mptcp':
   include/net/mptcp.h:79:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:83:18: warning: 'struct tcp_options_received' declared inside parameter list
              struct tcp_options_received *opt_rx)
                     ^
   include/net/mptcp.h:87:15: error: unknown type name 'bool'
    static inline bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                  ^
   include/net/mptcp.h:88:17: warning: 'struct sock' declared inside parameter list
             struct mptcp_out_options *opts)
                    ^
   include/net/mptcp.h: In function 'mptcp_syn_options':
   include/net/mptcp.h:90:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:93:45: warning: 'struct sock' declared inside parameter list
    static inline void mptcp_rcv_synsent(struct sock *sk)
                                                ^
   include/net/mptcp.h:97:15: error: unknown type name 'bool'
    static inline bool mptcp_synack_options(const struct request_sock *req,
                  ^
   include/net/mptcp.h:99:13: warning: 'struct request_sock' declared inside parameter list
         struct mptcp_out_options *opts)
                ^
   include/net/mptcp.h: In function 'mptcp_synack_options':
   include/net/mptcp.h:101:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:104:15: error: unknown type name 'bool'
    static inline bool mptcp_established_options(struct sock *sk,
                  ^
   include/net/mptcp.h:106:18: warning: 'struct sock' declared inside parameter list
              struct mptcp_out_options *opts)
                     ^
   include/net/mptcp.h: In function 'mptcp_established_options':
   include/net/mptcp.h:108:9: error: 'false' undeclared (first use in this function)
     return false;
            ^
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:111:15: error: unknown type name 'bool'
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                  ^
>> include/net/mptcp.h:111:53: warning: 'struct sk_buff' declared inside parameter list
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                                                        ^
   include/net/mptcp.h: In function 'mptcp_skb_ext_exist':
   include/net/mptcp.h:113:9: error: 'false' undeclared (first use in this function)
     return false;
            ^

vim +111 include/net/mptcp.h

103
104 static inline bool mptcp_established_options(struct sock *sk,
105 unsigned int *size,
106 struct mptcp_out_options *opts)
107 {

 > 108		return false;
   109	}
   110	
 > 111	static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)

112 {
113 return false;
114 }
115

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#31 lore raw

RFC PATCH v2 19/45 tcp: Export low-level TCP functions

In reply to Mat Martineau

MPTCP will make use of tcp_send_mss() and tcp_push() when sending data to specific TCP subflows.

---
 include/net/tcp.h | 3 +++
 net/ipv4/tcp.c    | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)
include/net/tcp.h +3 -0
index ddc098b33999..3994e6b0db27 100644
@@ -330,6 +330,9 @@ int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset,
 			size_t size, int flags);
 ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
 		 size_t size, int flags);
+int tcp_send_mss(struct sock *sk, int *size_goal, int flags);
+void tcp_push(struct sock *sk, int flags, int mss_now, int nonagle,
+	      int size_goal);
 void tcp_release_cb(struct sock *sk);
 void tcp_wfree(struct sk_buff *skb);
 void tcp_write_timer_handler(struct sock *sk);
net/ipv4/tcp.c +3 -3
index 5893d08cb204..5450e91dd82c 100644
@@ -691,8 +691,8 @@ static bool tcp_should_autocork(struct sock *sk, struct sk_buff *skb,
 	       refcount_read(&sk->sk_wmem_alloc) > skb->truesize;
 }
 
-static void tcp_push(struct sock *sk, int flags, int mss_now,
-		     int nonagle, int size_goal)
+void tcp_push(struct sock *sk, int flags, int mss_now,
+	      int nonagle, int size_goal)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct sk_buff *skb;
@@ -926,7 +926,7 @@ static unsigned int tcp_xmit_size_goal(struct sock *sk, u32 mss_now,
 	return max(size_goal, mss_now);
 }
 
-static int tcp_send_mss(struct sock *sk, int *size_goal, int flags)
+int tcp_send_mss(struct sock *sk, int *size_goal, int flags)
 {
 	int mss_now;
 
Signature · 1 line
2.23.0
#32 lore raw

RFC PATCH v2 20/45 mptcp: Write MPTCP DSS headers to outgoing data packets

In reply to Mat Martineau

Per-packet metadata required to write the MPTCP DSS option is written to the skb_ext area. One write to the socket may contain more than one packet of data, in which case the DSS option in the first packet will have a mapping covering all of the data in that write. Packets after the first do not have a DSS option. This is complicated to handle under memory pressure, since the first packet (with the DSS mapping) is pushed to the TCP core before the remaining skbs are allocated.

The current implementation is limited. It will only send up to one page of data. The number of bytes sent is returned so the caller knows which bytes were sent and which were not. More work is required to ensure that it works correctly with full buffers or under memory pressure.

The MPTCP DSS checksum is not yet implemented.

---
 include/net/mptcp.h   |  14 +++-
 net/ipv4/tcp_output.c |  11 ++--
 net/mptcp/options.c   | 146 +++++++++++++++++++++++++++++++++++++++++-
 net/mptcp/protocol.c  | 107 ++++++++++++++++++++++++++++++-
 net/mptcp/protocol.h  |  16 ++++-
 net/mptcp/subflow.c   |   2 +
 6 files changed, 283 insertions(+), 13 deletions(-)
include/net/mptcp.h +13 -1
index 5ec275708036..43fcd4989f37 100644
@@ -8,6 +8,14 @@
 #ifndef __NET_MPTCP_H
 #define __NET_MPTCP_H
 
+/* MPTCP DSS flags */
+
+#define MPTCP_DSS_DATA_FIN	BIT(4)
+#define MPTCP_DSS_DSN64		BIT(3)
+#define MPTCP_DSS_HAS_MAP	BIT(2)
+#define MPTCP_DSS_ACK64		BIT(1)
+#define MPTCP_DSS_HAS_ACK	BIT(0)
+
 /* MPTCP sk_buff extension data */
 struct mptcp_ext {
 	u64		data_ack;
@@ -29,6 +37,7 @@ struct mptcp_out_options {
 	u16 suboptions;
 	u64 sndr_key;
 	u64 rcvr_key;
+	struct mptcp_ext ext_copy;
 #endif
 };
 
@@ -53,7 +62,8 @@ bool mptcp_syn_options(struct sock *sk, unsigned int *size,
 void mptcp_rcv_synsent(struct sock *sk);
 bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 			  struct mptcp_out_options *opts);
-bool mptcp_established_options(struct sock *sk, unsigned int *size,
+bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
+			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts);
 
 static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
@@ -102,7 +112,9 @@ static inline bool mptcp_synack_options(const struct request_sock *req,
 }
 
 static inline bool mptcp_established_options(struct sock *sk,
+					     struct sk_buff *skb,
 					     unsigned int *size,
+					     unsigned int remaining,
 					     struct mptcp_out_options *opts)
 {
 	return false;
net/ipv4/tcp_output.c +5 -6
index 415b0414d738..3de804531231 100644
@@ -796,13 +796,12 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 	 */
 	if (sk_is_mptcp(sk)) {
 		unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
-		unsigned int opt_size;
+		unsigned int opt_size = 0;
 
-		if (mptcp_established_options(sk, &opt_size, &opts->mptcp)) {
-			if (remaining >= opt_size) {
-				opts->options |= OPTION_MPTCP;
-				size += opt_size;
-			}
+		if (mptcp_established_options(sk, skb, &opt_size, remaining,
+					      &opts->mptcp)) {
+			opts->options |= OPTION_MPTCP;
+			size += opt_size;
 		}
 	}
 
net/mptcp/options.c +143 -3

165 lines not on this page · raw message

net/mptcp/protocol.c +105 -2

147 lines not on this page · raw message

net/mptcp/protocol.h +15 -1
index dea6d4f32f38..2b0347612550 100644
@@ -30,6 +30,10 @@
 #define TCPOLEN_MPTCP_MPC_SYN		12
 #define TCPOLEN_MPTCP_MPC_SYNACK	20
 #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_DSS_BASE		4
+#define TCPOLEN_MPTCP_DSS_ACK64		8
+#define TCPOLEN_MPTCP_DSS_MAP64		14
+#define TCPOLEN_MPTCP_DSS_CHECKSUM	2
 
 /* MPTCP MP_CAPABLE flags */
 #define MPTCP_VERSION_MASK	(0x0F)
@@ -44,6 +48,8 @@ struct mptcp_sock {
 	struct inet_connection_sock sk;
 	u64		local_key;
 	u64		remote_key;
+	u64		write_seq;
+	u64		ack_seq;
 	u32		token;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
@@ -83,12 +89,15 @@ struct mptcp_subflow_context {
 	u64	remote_key;
 	u64	idsn;
 	u32	token;
+	u32     rel_write_seq;
 	u32	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
 		request_version : 4,
 		mp_capable : 1,	    /* remote is MPTCP capable */
 		fourth_ack : 1,     /* send initial DSS */
-		conn_finished : 1;
+		conn_finished : 1,
+		use_checksum : 1;
+
 	struct  socket *tcp_sock;  /* underlying tcp_sock */
 	struct  sock *conn;        /* parent mptcp_sock */
 };
@@ -140,4 +149,9 @@ static inline void mptcp_crypto_key_gen_sha1(u64 *key, u32 *token, u64 *idsn)
 void mptcp_crypto_hmac_sha1(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
 			    u32 *hash_out);
 
+static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
+{
+	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
+}
+
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +2 -0
index 43fb1ae51b03..260352af20c9 100644
@@ -224,6 +224,7 @@ static int subflow_ulp_init(struct sock *sk)
 
 	tp->is_mptcp = 1;
 	icsk->icsk_af_ops = &subflow_specific;
+	ctx->use_checksum = 0;
 out:
 	return err;
 }
@@ -252,6 +253,7 @@ static void subflow_ulp_clone(const struct request_sock *req,
 
 	new_ctx->conn = NULL;
 	new_ctx->conn_finished = 1;
+	new_ctx->use_checksum = 0;
 
 	if (subflow_req->mp_capable) {
 		new_ctx->mp_capable = 1;
Signature · 1 line
2.23.0
#33 lore raw

RFC PATCH v2 21/45 mptcp: Implement MPTCP receive path

In reply to Mat Martineau

Parses incoming DSS options and populates outgoing MPTCP ACK fields. MPTCP fields are parsed from the TCP option header and placed in an skb extension, allowing the upper MPTCP layer to access MPTCP options after the skb has gone through the TCP stack.

Outgoing MPTCP ACK values are now populated from an atomic value stored in the connection socket rather than carried in an skb extension. This allows sent packet headers to make use of the most up-to-date sequence number and allows the MPTCP ACK to be populated in TCP ACK packets that have no payload.

---
 include/linux/tcp.h  |  17 ++-
 include/net/mptcp.h  |  16 +--
 net/ipv4/tcp_input.c |   8 +-
 net/mptcp/options.c  | 138 +++++++++++++++++--
 net/mptcp/protocol.c | 318 +++++++++++++++++++++++++++++++++++++++++--
 net/mptcp/protocol.h |  32 ++++-
 net/mptcp/subflow.c  |  36 ++++-
 7 files changed, 523 insertions(+), 42 deletions(-)
include/linux/tcp.h +15 -2
index 220883a7a4db..0f0d6c188f52 100644
@@ -97,13 +97,26 @@ struct tcp_options_received {
 	u16	mss_clamp;	/* Maximal mss, negotiated at connection setup */
 #if IS_ENABLED(CONFIG_MPTCP)
 	struct mptcp_options_received {
+		u64     sndr_key;
+		u64     rcvr_key;
+		u64	data_ack;
+		u64	data_seq;
+		u32	subflow_seq;
+		u16	data_len;
+		__sum16	checksum;
 		u8      mp_capable : 1,
 			mp_join : 1,
 			dss : 1,
 			version : 4;
 		u8      flags;
-		u64     sndr_key;
-		u64     rcvr_key;
+		u8	dss_flags;
+		u8	use_map:1,
+			dsn64:1,
+			use_checksum:1,
+			data_fin:1,
+			use_ack:1,
+			ack64:1,
+			__unused:2;
 	} mptcp;
 #endif
 };
include/net/mptcp.h +8 -8
index 43fcd4989f37..21438bcacb14 100644
@@ -8,14 +8,6 @@
 #ifndef __NET_MPTCP_H
 #define __NET_MPTCP_H
 
-/* MPTCP DSS flags */
-
-#define MPTCP_DSS_DATA_FIN	BIT(4)
-#define MPTCP_DSS_DSN64		BIT(3)
-#define MPTCP_DSS_HAS_MAP	BIT(2)
-#define MPTCP_DSS_ACK64		BIT(1)
-#define MPTCP_DSS_HAS_ACK	BIT(0)
-
 /* MPTCP sk_buff extension data */
 struct mptcp_ext {
 	u64		data_ack;
@@ -65,6 +57,8 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 			       unsigned int *size, unsigned int remaining,
 			       struct mptcp_out_options *opts);
+void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
+			    struct tcp_options_received *opt_rx);
 
 static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 {
@@ -120,6 +114,12 @@ static inline bool mptcp_established_options(struct sock *sk,
 	return false;
 }
 
+static inline void mptcp_incoming_options(struct sock *sk,
+					  struct sk_buff *skb,
+					  struct tcp_options_received *opt_rx)
+{
+}
+
 static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 {
 	return false;
net/ipv4/tcp_input.c +7 -1
index 04267684babf..dac6027a6c2e 100644
@@ -4764,6 +4764,9 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 	bool fragstolen;
 	int eaten;
 
+	if (sk_is_mptcp(sk))
+		mptcp_incoming_options(sk, skb, &tp->rx_opt);
+
 	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
 		__kfree_skb(skb);
 		return;
@@ -6332,8 +6335,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
 	case TCP_CLOSE_WAIT:
 	case TCP_CLOSING:
 	case TCP_LAST_ACK:
-		if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt))
+		if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
+			if (sk_is_mptcp(sk))
+				mptcp_incoming_options(sk, skb, &tp->rx_opt);
 			break;
+		}
 		/* fall through */
 	case TCP_FIN_WAIT1:
 	case TCP_FIN_WAIT2:
net/mptcp/options.c +124 -14

173 lines not on this page · raw message

net/mptcp/protocol.c +308 -10

378 lines not on this page · raw message

net/mptcp/protocol.h +29 -3
index 2b0347612550..7dae12cfcf14 100644
@@ -31,7 +31,9 @@
 #define TCPOLEN_MPTCP_MPC_SYNACK	20
 #define TCPOLEN_MPTCP_MPC_ACK		20
 #define TCPOLEN_MPTCP_DSS_BASE		4
+#define TCPOLEN_MPTCP_DSS_ACK32		4
 #define TCPOLEN_MPTCP_DSS_ACK64		8
+#define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
 
@@ -42,6 +44,14 @@
 #define MPTCP_CAP_HMAC_SHA1	BIT(0)
 #define MPTCP_CAP_FLAG_MASK	(0x3F)
 
+/* MPTCP DSS flags */
+#define MPTCP_DSS_DATA_FIN	BIT(4)
+#define MPTCP_DSS_DSN64		BIT(3)
+#define MPTCP_DSS_HAS_MAP	BIT(2)
+#define MPTCP_DSS_ACK64		BIT(1)
+#define MPTCP_DSS_HAS_ACK	BIT(0)
+#define MPTCP_DSS_FLAG_MASK	(0x1F)
+
 /* MPTCP connection sock */
 struct mptcp_sock {
 	/* inet_connection_sock must be the first member */
@@ -74,6 +84,7 @@ struct mptcp_subflow_request_sock {
 	u64	remote_key;
 	u64	idsn;
 	u32	token;
+	u32	ssn_offset;
 };
 
 static inline struct mptcp_subflow_request_sock *
@@ -88,18 +99,25 @@ struct mptcp_subflow_context {
 	u64	local_key;
 	u64	remote_key;
 	u64	idsn;
+	u64	map_seq;
 	u32	token;
 	u32     rel_write_seq;
-	u32	request_mptcp : 1,  /* send MP_CAPABLE */
+	u32	map_subflow_seq;
+	u32	ssn_offset;
+	u16	map_data_len;
+	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
 		request_version : 4,
 		mp_capable : 1,	    /* remote is MPTCP capable */
 		fourth_ack : 1,     /* send initial DSS */
 		conn_finished : 1,
-		use_checksum : 1;
+		use_checksum : 1,
+		map_valid : 1;
 
 	struct  socket *tcp_sock;  /* underlying tcp_sock */
 	struct  sock *conn;        /* parent mptcp_sock */
+	void	(*tcp_sk_data_ready)(struct sock *sk);
+	struct	rcu_head rcu;
 };
 
 static inline struct mptcp_subflow_context *
@@ -107,7 +125,8 @@ mptcp_subflow_ctx(const struct sock *sk)
 {
 	struct inet_connection_sock *icsk = inet_csk(sk);
 
-	return (struct mptcp_subflow_context *)icsk->icsk_ulp_data;
+	/* Use RCU on icsk_ulp_data only for sock diag code */
+	return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;
 }
 
 static inline struct socket *
@@ -154,4 +173,11 @@ static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
 }
 
+static inline bool before64(__u64 seq1, __u64 seq2)
+{
+	return (__s64)(seq1 - seq2) < 0;
+}
+
+#define after64(seq2, seq1)	before64(seq1, seq2)
+
 #endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +32 -4
index 260352af20c9..1cde27227fd9 100644
@@ -75,6 +75,7 @@ static void subflow_v4_init_req(struct request_sock *req,
 		    listener->request_cksum)
 			subflow_req->checksum = 1;
 		subflow_req->remote_key = rx_opt.mptcp.sndr_key;
+		subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
 	} else {
 		subflow_req->mp_capable = 0;
 	}
@@ -91,6 +92,11 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 			 subflow->remote_key);
 		mptcp_finish_connect(subflow->conn, subflow->mp_capable);
 		subflow->conn_finished = 1;
+
+		if (skb) {
+			pr_debug("synack seq=%u", TCP_SKB_CB(skb)->seq);
+			subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
+		}
 	}
 }
 
@@ -155,6 +161,20 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 
 static struct inet_connection_sock_af_ops subflow_specific;
 
+static void subflow_data_ready(struct sock *sk)
+{
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+	struct sock *parent = subflow->conn;
+
+	pr_debug("sk=%p", sk);
+	subflow->tcp_sk_data_ready(sk);
+
+	if (parent) {
+		pr_debug("parent=%p", parent);
+		parent->sk_data_ready(parent);
+	}
+}
+
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 {
 	struct mptcp_subflow_context *subflow;
@@ -194,10 +214,9 @@ static struct mptcp_subflow_context *subflow_create_ctx(struct sock *sk,
 	struct mptcp_subflow_context *ctx;
 
 	ctx = kzalloc(sizeof(*ctx), priority);
-	icsk->icsk_ulp_data = ctx;
-
 	if (!ctx)
 		return NULL;
+	rcu_assign_pointer(icsk->icsk_ulp_data, ctx);
 
 	pr_debug("subflow=%p", ctx);
 
@@ -224,7 +243,9 @@ static int subflow_ulp_init(struct sock *sk)
 
 	tp->is_mptcp = 1;
 	icsk->icsk_af_ops = &subflow_specific;
+	ctx->tcp_sk_data_ready = sk->sk_data_ready;
 	ctx->use_checksum = 0;
+	sk->sk_data_ready = subflow_data_ready;
 out:
 	return err;
 }
@@ -233,10 +254,13 @@ static void subflow_ulp_release(struct sock *sk)
 {
 	struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(sk);
 
+	if (!ctx)
+		return;
+
 	if (ctx->conn)
 		sock_put(ctx->conn);
 
-	kfree(ctx);
+	kfree_rcu(ctx, rcu);
 }
 
 static void subflow_ulp_clone(const struct request_sock *req,
@@ -244,6 +268,7 @@ static void subflow_ulp_clone(const struct request_sock *req,
 			      const gfp_t priority)
 {
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
+	struct mptcp_subflow_context *old_ctx = mptcp_subflow_ctx(newsk);
 	struct mptcp_subflow_context *new_ctx;
 
 	/* newsk->sk_socket is NULL at this point */
@@ -253,7 +278,8 @@ static void subflow_ulp_clone(const struct request_sock *req,
 
 	new_ctx->conn = NULL;
 	new_ctx->conn_finished = 1;
-	new_ctx->use_checksum = 0;
+	new_ctx->tcp_sk_data_ready = old_ctx->tcp_sk_data_ready;
+	new_ctx->use_checksum = old_ctx->use_checksum;
 
 	if (subflow_req->mp_capable) {
 		new_ctx->mp_capable = 1;
@@ -261,6 +287,8 @@ static void subflow_ulp_clone(const struct request_sock *req,
 		new_ctx->remote_key = subflow_req->remote_key;
 		new_ctx->local_key = subflow_req->local_key;
 		new_ctx->token = subflow_req->token;
+		new_ctx->ssn_offset = subflow_req->ssn_offset;
+		new_ctx->idsn = subflow_req->idsn;
 	}
 }
 
Signature · 1 line
2.23.0
#34 lore raw

Re: [RFC PATCH v2 21/45] mptcp: Implement MPTCP receive path

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:15:0,
from net/mptcp/protocol.c:9:
net/mptcp/protocol.c: In function 'mptcp_recvmsg':
include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]

    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/printk.h:137:10: note: in definition of macro 'no_printk'
      printk(fmt, ##__VA_ARGS__);  \
             ^~~
   include/linux/kern_levels.h:15:20: note: in expansion of macro 'KERN_SOH'
    #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
                       ^~~~~~~~
   include/linux/printk.h:342:12: note: in expansion of macro 'KERN_DEBUG'
     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
               ^~~~~~~~~~
>> net/mptcp/protocol.c:433:4: note: in expansion of macro 'pr_debug'
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
       ^~~~~~~~
   net/mptcp/protocol.c:433:56: note: format string is defined here
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
                                                         ~~^
                                                         %d

vim +/pr_debug +433 net/mptcp/protocol.c

314
315 static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
316 int nonblock, int flags, int *addr_len)
317 {
318 struct mptcp_sock *msk = mptcp_sk(sk);
319 struct mptcp_subflow_context *subflow;
320 struct mptcp_read_arg arg;
321 read_descriptor_t desc;
322 struct socket *ssock;
323 struct tcp_sock *tp;
324 struct sock *ssk;
325 int copied = 0;
326 long timeo;
327
328 lock_sock(sk);
329 ssock = __mptcp_fallback_get_ref(msk);
330 if (ssock) {
331 release_sock(sk);
332 pr_debug("fallback-read subflow=%p",
333 mptcp_subflow_ctx(ssock->sk));
334 copied = sock_recvmsg(ssock, msg, flags);
335 sock_put(ssock->sk);
336 return copied;
337 }
338
339 ssk = mptcp_subflow_get_ref(msk);
340 if (!ssk) {
341 release_sock(sk);
342 return -ENOTCONN;
343 }
344
345 subflow = mptcp_subflow_ctx(ssk);
346 tp = tcp_sk(ssk);
347
348 lock_sock(ssk);
349
350 desc.arg.data = &arg;
351 desc.error = 0;
352
353 timeo = sock_rcvtimeo(sk, nonblock);
354
355 len = min_t(size_t, len, INT_MAX);
356
357 while (copied < len) {
358 enum mapping_status status;
359 u32 map_remaining;
360 int bytes_read;
361 u64 ack_seq;
362 u64 old_ack;
363 u32 ssn;
364
365 status = mptcp_get_mapping(ssk);
366
367 if (status == MAPPING_ADDED) {
368 /* Common case, but nothing to do here */
369 } else if (status == MAPPING_MISSING) {
370 struct sk_buff *skb = skb_peek(&ssk->sk_receive_queue);
371
372 if (!skb->len) {
373 /* the TCP stack deliver 0 len FIN pkt
374 * to the receive queue, that is the only
375 * 0len pkts ever expected here, and we can
376 * admit no mapping only for 0 len pkts
377 */
378 if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN))
379 WARN_ONCE(1, "0len seq %d:%d flags %x",

   380							  TCP_SKB_CB(skb)->seq,
   381							  TCP_SKB_CB(skb)->end_seq,
   382							  TCP_SKB_CB(skb)->tcp_flags);
   383					sk_eat_skb(sk, skb);
   384					continue;
   385				}
   386				if (!subflow->map_valid) {
   387					WARN_ONCE(1, "corrupted stream: missing mapping");
   388					copied = -EBADFD;
   389					break;
   390				}
   391			} else if (status == MAPPING_EMPTY) {
   392				goto wait_for_data;
   393			} else if (status == MAPPING_DATA_FIN) {
   394				/* TODO: Handle according to RFC 6824 */
   395				if (!copied) {
   396					pr_err("Can't read after DATA_FIN");
   397					copied = -ENOTCONN;
   398				}
   399	
   400				break;
   401			}
   402	
   403			ssn = tcp_sk(ssk)->copied_seq - subflow->ssn_offset;
   404			old_ack = msk->ack_seq;
   405	
   406			if (unlikely(before(ssn, subflow->map_subflow_seq))) {
   407				/* Mapping covers data later in the subflow stream,
   408				 * currently unsupported.
   409				 */
   410				warn_bad_map(subflow, ssn);
   411				copied = -EBADFD;
   412				break;
   413			} else if (unlikely(!before(ssn, (subflow->map_subflow_seq +
   414							  subflow->map_data_len)))) {
   415				/* Mapping ends earlier in the subflow stream.
   416				 * Invalid
   417				 */
   418				warn_bad_map(subflow, ssn);
   419				copied = -EBADFD;
   420				break;
   421			}
   422	
   423			ack_seq = get_mapped_dsn(subflow);
   424			map_remaining = subflow->map_data_len - get_map_offset(subflow);
   425	
   426			if (before64(ack_seq, old_ack)) {
   427				/* Mapping covers data already received, discard data
   428				 * in the current mapping
   429				 */
   430				arg.msg = NULL;
   431				desc.count = min_t(size_t, old_ack - ack_seq,
   432						   map_remaining);
 > 433				pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",

434 map_remaining, old_ack - ack_seq, desc.count);
435 } else {
436 arg.msg = msg;
437 desc.count = min_t(size_t, len - copied, map_remaining);
438 }
439
440 /* Read mapped data */
441 bytes_read = tcp_read_sock(ssk, &desc, mptcp_read_actor);
442 if (bytes_read < 0)
443 break;
444
445 /* Refresh current MPTCP sequence number based on subflow seq */
446 ack_seq = get_mapped_dsn(subflow);
447
448 if (before64(old_ack, ack_seq))
449 msk->ack_seq = ack_seq;
450
451 if (!before(tcp_sk(ssk)->copied_seq - subflow->ssn_offset,
452 subflow->map_subflow_seq + subflow->map_data_len)) {
453 subflow->map_valid = 0;
454 pr_debug("Done with mapping: seq=%u data_len=%u",
455 subflow->map_subflow_seq,
456 subflow->map_data_len);
457 }
458
459 if (arg.msg)
460 copied += bytes_read;
461
462 /* The 'wait_for_data' code path can terminate the receive loop
463 * in a number of scenarios: check if more data is pending
464 * before giving up.
465 */
466 if (!skb_queue_empty(&ssk->sk_receive_queue))
467 continue;
468
469 wait_for_data:
470 if (copied)
471 break;
472
473 if (tp->urg_data && tp->urg_seq == tp->copied_seq) {
474 pr_err("Urgent data present, cannot proceed");
475 break;
476 }
477
478 if (ssk->sk_err || ssk->sk_state == TCP_CLOSE ||
479 (ssk->sk_shutdown & RCV_SHUTDOWN) || !timeo ||
480 signal_pending(current)) {
481 pr_debug("nonblock or error");
482 break;
483 }
484
485 /* Handle blocking and retry read if needed.
486 *
487 * Wait on MPTCP sock, the subflow will notify via data ready.
488 */
489
490 pr_debug("block");
491 release_sock(ssk);
492 sk_wait_data(sk, &timeo, NULL);
493 lock_sock(ssk);
494 }
495
496 release_sock(ssk);
497 release_sock(sk);
498
499 sock_put(ssk);
500
501 return copied;
502 }
503

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#35 lore raw

Re: [RFC PATCH v2 21/45] mptcp: Implement MPTCP receive path

In reply to Mat Martineau
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: c6x-allyesconfig (attached as .config)
compiler: c6x-elf-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=c6x

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

net/mptcp/protocol.c: In function 'mptcp_recvmsg':

>> net/mptcp/protocol.c:7:21: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'size_t {aka unsigned int}' [-Wformat=]
    #define pr_fmt(fmt) "MPTCP: " fmt
                        ^
   include/linux/dynamic_debug.h:125:15: note: in expansion of macro 'pr_fmt'
      func(&id, ##__VA_ARGS__);  \
                  ^~~~~~~~~~~
   include/linux/dynamic_debug.h:143:2: note: in expansion of macro '__dynamic_func_call'
     __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:153:2: note: in expansion of macro '_dynamic_func_call'
     _dynamic_func_call(fmt, __dynamic_pr_debug,  \
     ^~~~~~~~~~~~~~~~~~
   include/linux/printk.h:336:2: note: in expansion of macro 'dynamic_pr_debug'
     dynamic_pr_debug(fmt, ##__VA_ARGS__)
     ^~~~~~~~~~~~~~~~
   net/mptcp/protocol.c:433:4: note: in expansion of macro 'pr_debug'
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
       ^~~~~~~~
   net/mptcp/protocol.c:433:56: note: format string is defined here
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
                                                         ~~^
                                                         %d

vim +7 net/mptcp/protocol.c

ed00866b0efe1c Mat Martineau 2019-10-02 @7 #define pr_fmt(fmt) "MPTCP: " fmt ed00866b0efe1c Mat Martineau 2019-10-02 8

:::::: The code at line 7 was first introduced by commit
:::::: ed00866b0efe1c24ccad8988da27578a562fc042 mptcp: Add MPTCP socket stubs

:::::: TO: Mat Martineau <[email protected]> :::::: CC: 0day robot <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#36 lore raw

RFC PATCH v2 22/45 mptcp: use sk_page_frag() in sendmsg

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

This clean-up a bit the send path, and allows better performances.

---
 net/mptcp/protocol.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
net/mptcp/protocol.c +18 -18
index fdcfffce0ec9..da983ea4fb5e 100644
@@ -65,10 +65,11 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	struct socket *ssock;
 	struct sock *ssk;
 	struct mptcp_ext *mpext = NULL;
-	struct page *page = NULL;
+	struct page_frag *pfrag;
 	struct sk_buff *skb;
 	size_t psize;
 	int poffset;
+	long timeo;
 
 	lock_sock(sk);
 	ssock = __mptcp_fallback_get_ref(msk);
@@ -97,32 +98,32 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		goto put_out;
 	}
 
-	/* Initial experiment: new page per send.  Real code will
-	 * maintain list of active pages and DSS mappings, append to the
-	 * end and honor zerocopy
+	lock_sock(ssk);
+	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
+
+	/* use the mptcp page cache so that we can easily move the data
+	 * from one substream to another, but do per subflow memory accounting
 	 */
-	page = alloc_page(GFP_KERNEL);
-	if (!page) {
-		ret = -ENOMEM;
-		goto put_out;
+	pfrag = sk_page_frag(sk);
+	while (!sk_page_frag_refill(ssk, pfrag)) {
+		ret = sk_stream_wait_memory(ssk, &timeo);
+		if (ret)
+			goto put_out;
 	}
 
 	/* Copy to page */
-	poffset = 0;
+	poffset = pfrag->offset;
 	pr_debug("left=%zu", msg_data_left(msg));
-	psize = copy_page_from_iter(page, poffset,
+	psize = copy_page_from_iter(pfrag->page, poffset,
 				    min_t(size_t, msg_data_left(msg),
-					  PAGE_SIZE),
+					  pfrag->size - poffset),
 				    &msg->msg_iter);
 	pr_debug("left=%zu", msg_data_left(msg));
-
 	if (!psize) {
 		ret = -EINVAL;
 		goto put_out;
 	}
 
-	lock_sock(ssk);
-
 	/* Mark the end of the previous write so the beginning of the
 	 * next write (with its own mptcp skb extension data) is not
 	 * collapsed.
@@ -132,8 +133,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		TCP_SKB_CB(skb)->eor = 1;
 
 	mss_now = tcp_send_mss(ssk, &size_goal, msg->msg_flags);
-
-	ret = do_tcp_sendpages(ssk, page, poffset, min_t(int, size_goal, psize),
+	psize = min_t(int, size_goal, psize);
+	ret = do_tcp_sendpages(ssk, pfrag->page, poffset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST);
 	if (ret <= 0)
 		goto put_out;
@@ -159,14 +160,13 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 			 mpext->checksum, mpext->dsn64);
 	} /* TODO: else fallback */
 
+	pfrag->offset += ret;
 	msk->write_seq += ret;
 	mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
 
 	tcp_push(ssk, msg->msg_flags, mss_now, tcp_sk(ssk)->nonagle, size_goal);
 
 put_out:
-	if (page)
-		put_page(page);
 	release_sock(sk);
 	sock_put(ssk);
 	return ret;
Signature · 1 line
2.23.0
#37 lore raw

RFC PATCH v2 23/45 mptcp: sendmsg() do spool all the provided data

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

This makes mptcp sendmsg() behaviour more consistent and improves xmit performances.

---
 net/mptcp/protocol.c | 126 ++++++++++++++++++++++++-------------------
 1 file changed, 71 insertions(+), 55 deletions(-)
net/mptcp/protocol.c +71 -55
index da983ea4fb5e..758369256f9b 100644
@@ -58,71 +58,37 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)
 	return NULL;
 }
 
-static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
+			      struct msghdr *msg, long *timeo)
 {
 	int mss_now = 0, size_goal = 0, ret = 0;
 	struct mptcp_sock *msk = mptcp_sk(sk);
-	struct socket *ssock;
-	struct sock *ssk;
 	struct mptcp_ext *mpext = NULL;
 	struct page_frag *pfrag;
 	struct sk_buff *skb;
 	size_t psize;
-	int poffset;
-	long timeo;
-
-	lock_sock(sk);
-	ssock = __mptcp_fallback_get_ref(msk);
-	if (ssock) {
-		release_sock(sk);
-		pr_debug("fallback passthrough");
-		ret = sock_sendmsg(ssock, msg);
-		sock_put(ssock->sk);
-		return ret;
-	}
-
-	ssk = mptcp_subflow_get_ref(msk);
-	if (!ssk) {
-		release_sock(sk);
-		return -ENOTCONN;
-	}
-
-	if (!msg_data_left(msg)) {
-		pr_debug("empty send");
-		ret = sock_sendmsg(ssk->sk_socket, msg);
-		goto put_out;
-	}
-
-	if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL)) {
-		ret = -ENOTSUPP;
-		goto put_out;
-	}
-
-	lock_sock(ssk);
-	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 
 	/* use the mptcp page cache so that we can easily move the data
 	 * from one substream to another, but do per subflow memory accounting
 	 */
 	pfrag = sk_page_frag(sk);
 	while (!sk_page_frag_refill(ssk, pfrag)) {
-		ret = sk_stream_wait_memory(ssk, &timeo);
+		ret = sk_stream_wait_memory(ssk, timeo);
 		if (ret)
-			goto put_out;
+			return ret;
 	}
 
-	/* Copy to page */
-	poffset = pfrag->offset;
+	/* compute copy limit */
+	mss_now = tcp_send_mss(ssk, &size_goal, msg->msg_flags);
+	psize = min_t(int, pfrag->size - pfrag->offset, size_goal);
+
 	pr_debug("left=%zu", msg_data_left(msg));
-	psize = copy_page_from_iter(pfrag->page, poffset,
-				    min_t(size_t, msg_data_left(msg),
-					  pfrag->size - poffset),
+	psize = copy_page_from_iter(pfrag->page, pfrag->offset,
+				    min_t(size_t, msg_data_left(msg), psize),
 				    &msg->msg_iter);
 	pr_debug("left=%zu", msg_data_left(msg));
-	if (!psize) {
-		ret = -EINVAL;
-		goto put_out;
-	}
+	if (!psize)
+		return -EINVAL;
 
 	/* Mark the end of the previous write so the beginning of the
 	 * next write (with its own mptcp skb extension data) is not
@@ -132,20 +98,15 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	if (skb)
 		TCP_SKB_CB(skb)->eor = 1;
 
-	mss_now = tcp_send_mss(ssk, &size_goal, msg->msg_flags);
-	psize = min_t(int, size_goal, psize);
-	ret = do_tcp_sendpages(ssk, pfrag->page, poffset, psize,
+	ret = do_tcp_sendpages(ssk, pfrag->page, pfrag->offset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST);
 	if (ret <= 0)
-		goto put_out;
-
-	if (skb == tcp_write_queue_tail(ssk))
-		pr_err("no new skb %p/%p", sk, ssk);
+		return ret;
+	if (unlikely(ret < psize))
+		iov_iter_revert(&msg->msg_iter, psize - ret);
 
 	skb = tcp_write_queue_tail(ssk);
-
 	mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
-
 	if (mpext) {
 		memset(mpext, 0, sizeof(*mpext));
 		mpext->data_seq = msk->write_seq;
@@ -165,6 +126,61 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
 
 	tcp_push(ssk, msg->msg_flags, mss_now, tcp_sk(ssk)->nonagle, size_goal);
+	return ret;
+}
+
+static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct socket *ssock;
+	size_t copied = 0;
+	struct sock *ssk;
+	int ret = 0;
+	long timeo;
+
+	lock_sock(sk);
+	ssock = __mptcp_fallback_get_ref(msk);
+	if (ssock) {
+		release_sock(sk);
+		pr_debug("fallback passthrough");
+		ret = sock_sendmsg(ssock, msg);
+		sock_put(ssock->sk);
+		return ret;
+	}
+
+	ssk = mptcp_subflow_get_ref(msk);
+	if (!ssk) {
+		release_sock(sk);
+		return -ENOTCONN;
+	}
+
+	if (!msg_data_left(msg)) {
+		pr_debug("empty send");
+		ret = sock_sendmsg(ssk->sk_socket, msg);
+		goto put_out;
+	}
+
+	pr_debug("conn_list->subflow=%p", ssk);
+
+	if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL)) {
+		ret = -ENOTSUPP;
+		goto put_out;
+	}
+
+	lock_sock(ssk);
+	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
+	while (msg_data_left(msg)) {
+		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo);
+		if (ret < 0)
+			break;
+
+		copied += ret;
+	}
+
+	if (copied > 0)
+		ret = copied;
+
+	release_sock(ssk);
 
 put_out:
 	release_sock(sk);
Signature · 1 line
2.23.0
#38 lore raw

RFC PATCH v2 24/45 mptcp: allow collapsing consecutive sendpages on the same substream

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

If the current sendmsg() lands on the same subflow we used last, we can try to collapse the data.

---
 net/mptcp/protocol.c | 74 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 59 insertions(+), 15 deletions(-)
net/mptcp/protocol.c +59 -15
index 758369256f9b..6b31c0e460d9 100644
@@ -58,11 +58,24 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)
 	return NULL;
 }
 
+static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,
+					     const struct sk_buff *skb,
+					     const struct mptcp_ext *mpext)
+{
+	if (!tcp_skb_can_collapse_to(skb))
+		return false;
+
+	/* can collapse only if MPTCP level sequence is in order */
+	return mpext && mpext->data_seq + mpext->data_len == msk->write_seq;
+}
+
 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
-			      struct msghdr *msg, long *timeo)
+			      struct msghdr *msg, long *timeo, int *pmss_now,
+			      int *ps_goal)
 {
-	int mss_now = 0, size_goal = 0, ret = 0;
+	int mss_now, avail_size, size_goal, ret;
 	struct mptcp_sock *msk = mptcp_sk(sk);
+	bool collapsed, can_collapse = false;
 	struct mptcp_ext *mpext = NULL;
 	struct page_frag *pfrag;
 	struct sk_buff *skb;
@@ -80,8 +93,29 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 
 	/* compute copy limit */
 	mss_now = tcp_send_mss(ssk, &size_goal, msg->msg_flags);
-	psize = min_t(int, pfrag->size - pfrag->offset, size_goal);
+	*pmss_now = mss_now;
+	*ps_goal = size_goal;
+	avail_size = size_goal;
+	skb = tcp_write_queue_tail(ssk);
+	if (skb) {
+		mpext = skb_ext_find(skb, SKB_EXT_MPTCP);
+
+		/* Limit the write to the size available in the
+		 * current skb, if any, so that we create at most a new skb.
+		 * Explicitly tells TCP internals to avoid collapsing on later
+		 * queue management operation, to avoid breaking the ext <->
+		 * SSN association set here
+		 */
+		can_collapse = (size_goal - skb->len > 0) &&
+			      mptcp_skb_can_collapse_to(msk, skb, mpext);
+		if (!can_collapse)
+			TCP_SKB_CB(skb)->eor = 1;
+		else
+			avail_size = size_goal - skb->len;
+	}
+	psize = min_t(size_t, pfrag->size - pfrag->offset, avail_size);
 
+	/* Copy to page */
 	pr_debug("left=%zu", msg_data_left(msg));
 	psize = copy_page_from_iter(pfrag->page, pfrag->offset,
 				    min_t(size_t, msg_data_left(msg), psize),
@@ -90,14 +124,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	if (!psize)
 		return -EINVAL;
 
-	/* Mark the end of the previous write so the beginning of the
-	 * next write (with its own mptcp skb extension data) is not
-	 * collapsed.
+	/* tell the TCP stack to delay the push so that we can safely
+	 * access the skb after the sendpages call
 	 */
-	skb = tcp_write_queue_tail(ssk);
-	if (skb)
-		TCP_SKB_CB(skb)->eor = 1;
-
 	ret = do_tcp_sendpages(ssk, pfrag->page, pfrag->offset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST);
 	if (ret <= 0)
@@ -105,6 +134,14 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	if (unlikely(ret < psize))
 		iov_iter_revert(&msg->msg_iter, psize - ret);
 
+	collapsed = skb == tcp_write_queue_tail(ssk);
+	if (collapsed) {
+		WARN_ON_ONCE(!can_collapse);
+		/* when collapsing mpext always exists */
+		mpext->data_len += ret;
+		goto out;
+	}
+
 	skb = tcp_write_queue_tail(ssk);
 	mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
 	if (mpext) {
@@ -119,23 +156,26 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		pr_debug("data_seq=%llu subflow_seq=%u data_len=%u checksum=%u, dsn64=%d",
 			 mpext->data_seq, mpext->subflow_seq, mpext->data_len,
 			 mpext->checksum, mpext->dsn64);
-	} /* TODO: else fallback */
+	}
+	/* TODO: else fallback; allocation can fail, but we can't easily retire
+	 * skbs from the write_queue, as we need to roll-back TCP status
+	 */
 
+out:
 	pfrag->offset += ret;
 	msk->write_seq += ret;
 	mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
 
-	tcp_push(ssk, msg->msg_flags, mss_now, tcp_sk(ssk)->nonagle, size_goal);
 	return ret;
 }
 
 static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 {
+	int mss_now = 0, size_goal = 0, ret = 0;
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct socket *ssock;
 	size_t copied = 0;
 	struct sock *ssk;
-	int ret = 0;
 	long timeo;
 
 	lock_sock(sk);
@@ -170,15 +210,19 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	lock_sock(ssk);
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 	while (msg_data_left(msg)) {
-		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo);
+		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo, &mss_now,
+					 &size_goal);
 		if (ret < 0)
 			break;
 
 		copied += ret;
 	}
 
-	if (copied > 0)
+	if (copied) {
 		ret = copied;
+		tcp_push(ssk, msg->msg_flags, mss_now, tcp_sk(ssk)->nonagle,
+			 size_goal);
+	}
 
 	release_sock(ssk);
 
Signature · 1 line
2.23.0
#39 lore raw

RFC PATCH v2 25/45 tcp: Check for filled TCP option space before SACK

In reply to Mat Martineau

The SACK code would potentially add four bytes to the expected TCP option size even if all option space was already used.

---
 net/ipv4/tcp_output.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv4/tcp_output.c +3 -0
index 3de804531231..dd9be5169aa3 100644
@@ -805,6 +805,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
 		}
 	}
 
+	if (size + TCPOLEN_SACK_BASE_ALIGNED >= MAX_TCP_OPTION_SPACE)
+		return size;
+
 	eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
 	if (unlikely(eff_sacks)) {
 		const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
Signature · 1 line
2.23.0
#40 lore raw

RFC PATCH v2 26/45 mptcp: Add path manager interface

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Add enough of a path manager interface to allow sending of ADD_ADDR when an incoming MPTCP connection is created. Capable of sending only a single IPv4 ADD_ADDR option. The 'pm_data' element of the connection sock will need to be expanded to handle multiple interfaces and IPv6.

This is a skeleton interface definition for events generated by MPTCP.

---
 include/linux/tcp.h  |   9 ++++
 net/mptcp/Makefile   |   2 +-
 net/mptcp/options.c  |  16 ++++++
 net/mptcp/pm.c       | 124 +++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.c |   6 ++-
 net/mptcp/protocol.h |  48 +++++++++++++++++
 6 files changed, 203 insertions(+), 2 deletions(-)
 create mode 100644 net/mptcp/pm.c
include/linux/tcp.h +9 -0
index 0f0d6c188f52..31e546fe9643 100644
@@ -117,6 +117,15 @@ struct tcp_options_received {
 			use_ack:1,
 			ack64:1,
 			__unused:2;
+		u8	add_addr : 1,
+			family : 4;
+		u8	addr_id;
+		union {
+			struct	in_addr	addr;
+#if IS_ENABLED(CONFIG_IPV6)
+			struct	in6_addr addr6;
+#endif
+		};
 	} mptcp;
 #endif
 };
net/mptcp/Makefile +1 -1
index 178ae81d8b66..7fe7aa64eda0 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o
net/mptcp/options.c +16 -0
index caea320cd2a6..2981c0daa12c 100644
@@ -396,11 +396,23 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			    struct tcp_options_received *opt_rx)
 {
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
 	struct mptcp_options_received *mp_opt;
 	struct mptcp_ext *mpext;
 
 	mp_opt = &opt_rx->mptcp;
 
+	if (msk && mp_opt->add_addr) {
+		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4)
+			pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+#if IS_ENABLED(CONFIG_IPV6)
+		else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6)
+			pm_add_addr6(msk, &mp_opt->addr6, mp_opt->addr_id);
+#endif
+		mp_opt->add_addr = 0;
+	}
+
 	if (!mp_opt->dss)
 		return;
 
@@ -427,6 +439,10 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 	}
 
 	mpext->data_fin = mp_opt->data_fin;
+
+	if (msk)
+		pm_fully_established(msk);
+
 }
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts)
net/mptcp/pm.c new file +124 -0

124 lines not on this page · raw message

net/mptcp/protocol.c +5 -1
index 6b31c0e460d9..932362e6047e 100644
@@ -655,6 +655,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 		mptcp_token_update_accept(new_sock->sk, new_mptcp_sock);
 		msk->subflow = NULL;
 
+		pm_new_connection(msk, 1);
+
 		mptcp_crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
@@ -784,9 +786,10 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->remote_key = subflow->remote_key;
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
-
 		pr_debug("msk=%p, token=%u", msk, msk->token);
 
+		pm_new_connection(msk, 0);
+
 		mptcp_crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
 		ack_seq++;
@@ -1013,6 +1016,7 @@ void __init mptcp_init(void)
 	mptcp_stream_ops.shutdown = mptcp_shutdown;
 
 	mptcp_subflow_init();
+	pm_init();
 
 	if (proto_register(&mptcp_prot, 1) != 0)
 		panic("Failed to register MPTCP proto.\n");
net/mptcp/protocol.h +48 -0

72 lines not on this page · raw message

Signature · 1 line
2.23.0
#41 lore raw

RFC PATCH v2 27/45 mptcp: Add ADD_ADDR handling

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Add handling for sending and receiving the ADD_ADDR, ADD_ADDR6, and RM_ADDR suboptions.

---
 include/linux/tcp.h  |   2 +
 include/net/mptcp.h  |   7 +++
 net/mptcp/options.c  | 115 +++++++++++++++++++++++++++++++++++++++----
 net/mptcp/protocol.h |  16 +++++-
 4 files changed, 130 insertions(+), 10 deletions(-)
include/linux/tcp.h +2 -0
index 31e546fe9643..b3289e69cac1 100644
@@ -118,6 +118,7 @@ struct tcp_options_received {
 			ack64:1,
 			__unused:2;
 		u8	add_addr : 1,
+			rm_addr : 1,
 			family : 4;
 		u8	addr_id;
 		union {
@@ -139,6 +140,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
 #endif
 #if IS_ENABLED(CONFIG_MPTCP)
 	rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join = 0;
+	rx_opt->mptcp.add_addr = rx_opt->mptcp.rm_addr = 0;
 	rx_opt->mptcp.dss = 0;
 #endif
 }
include/net/mptcp.h +7 -0
index 21438bcacb14..f4a9962ea85f 100644
@@ -29,6 +29,13 @@ struct mptcp_out_options {
 	u16 suboptions;
 	u64 sndr_key;
 	u64 rcvr_key;
+	union {
+		struct in_addr addr;
+#if IS_ENABLED(CONFIG_IPV6)
+		struct in6_addr addr6;
+#endif
+	};
+	u8 addr_id;
 	struct mptcp_ext ext_copy;
 #endif
 };
net/mptcp/options.c +106 -9

161 lines not on this page · raw message

net/mptcp/protocol.h +15 -1
index 599c380145e3..fd21ed6c03b7 100644
@@ -8,13 +8,16 @@
 #define __MPTCP_PROTOCOL_H
 
 #include <linux/random.h>
-#include <linux/tcp.h>
+#include <net/tcp.h>
 #include <net/inet_connection_sock.h>
 
 /* MPTCP option bits */
 #define OPTION_MPTCP_MPC_SYN	BIT(0)
 #define OPTION_MPTCP_MPC_SYNACK	BIT(1)
 #define OPTION_MPTCP_MPC_ACK	BIT(2)
+#define OPTION_MPTCP_ADD_ADDR	BIT(6)
+#define OPTION_MPTCP_ADD_ADDR6	BIT(7)
+#define OPTION_MPTCP_RM_ADDR	BIT(8)
 
 /* MPTCP option subtypes */
 #define MPTCPOPT_MP_CAPABLE	0
@@ -36,6 +39,9 @@
 #define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
+#define TCPOLEN_MPTCP_ADD_ADDR		8
+#define TCPOLEN_MPTCP_ADD_ADDR6		20
+#define TCPOLEN_MPTCP_RM_ADDR		4
 
 /* MPTCP MP_CAPABLE flags */
 #define MPTCP_VERSION_MASK	(0x0F)
@@ -53,9 +59,16 @@
 #define MPTCP_DSS_FLAG_MASK	(0x1F)
 
 /* MPTCP ADD_ADDR flags */
+#define MPTCP_ADDR_FAMILY_MASK	(0x0F)
 #define MPTCP_ADDR_IPVERSION_4	4
 #define MPTCP_ADDR_IPVERSION_6	6
 
+static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
+{
+	return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) |
+		     ((nib & 0xF) << 8) | field);
+}
+
 struct mptcp_pm_data {
 	u8	local_valid;
 	u8	local_id;
@@ -96,6 +109,7 @@ struct mptcp_sock {
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
+	u8		addr_signal;
 };
 
 #define mptcp_for_each_subflow(__msk, __subflow)			\
Signature · 1 line
2.23.0
#42 lore raw

Re: [RFC PATCH v2 27/45] mptcp: Add ADD_ADDR handling

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191003]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

In file included from <command-line>:0:0:
include/net/mptcp.h:13:2: error: unknown type name 'u64'

     u64  data_ack;
     ^~~
   include/net/mptcp.h:14:2: error: unknown type name 'u64'
     u64  data_seq;
     ^~~
   include/net/mptcp.h:15:2: error: unknown type name 'u32'
     u32  subflow_seq;
     ^~~
   include/net/mptcp.h:16:2: error: unknown type name 'u16'
     u16  data_len;
     ^~~
   include/net/mptcp.h:17:2: error: unknown type name '__sum16'
     __sum16  checksum;
     ^~~~~~~
   include/net/mptcp.h:18:2: error: unknown type name 'u8'
     u8  use_map:1,
     ^~
   include/net/mptcp.h:29:2: error: unknown type name 'u16'
     u16 suboptions;
     ^~~
   include/net/mptcp.h:30:2: error: unknown type name 'u64'
     u64 sndr_key;
     ^~~
   include/net/mptcp.h:31:2: error: unknown type name 'u64'
     u64 rcvr_key;
     ^~~
>> include/net/mptcp.h:33:18: error: field 'addr' has incomplete type
      struct in_addr addr;
                     ^~~~
>> include/net/mptcp.h:35:19: error: field 'addr6' has incomplete type
      struct in6_addr addr6;
                      ^~~~~
   include/net/mptcp.h:38:2: error: unknown type name 'u8'
     u8 addr_id;
     ^~
   include/net/mptcp.h:47:15: error: unknown type name 'bool'
    static inline bool sk_is_mptcp(const struct sock *sk)
                  ^~~~
   include/net/mptcp.h:47:45: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool sk_is_mptcp(const struct sock *sk)
                                                ^~~~
   include/net/mptcp.h: In function 'sk_is_mptcp':
   include/net/mptcp.h:49:9: error: implicit declaration of function 'tcp_sk' [-Werror=implicit-function-declaration]
     return tcp_sk(sk)->is_mptcp;
            ^~~~~~
   include/net/mptcp.h:49:19: error: invalid type argument of '->' (have 'int')
     return tcp_sk(sk)->is_mptcp;
                      ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:52:15: error: unknown type name 'bool'
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                  ^~~~
   include/net/mptcp.h:52:46: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool rsk_is_mptcp(const struct request_sock *req)
                                                 ^~~~~~~~~~~~
   include/net/mptcp.h: In function 'rsk_is_mptcp':
   include/net/mptcp.h:54:9: error: implicit declaration of function 'tcp_rsk' [-Werror=implicit-function-declaration]
     return tcp_rsk(req)->is_mptcp;
            ^~~~~~~
   include/net/mptcp.h:54:21: error: invalid type argument of '->' (have 'int')
     return tcp_rsk(req)->is_mptcp;
                        ^~
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:58:11: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
       struct tcp_options_received *opt_rx);
              ^~~~~~~~~~~~~~~~~~~~
   include/net/mptcp.h:59:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:59:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_syn_options(struct sock *sk, unsigned int *size,
                                  ^~~~
   include/net/mptcp.h:61:31: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_rcv_synsent(struct sock *sk);
                                  ^~~~
   include/net/mptcp.h:62:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
    ^~~~
    _Bool
   include/net/mptcp.h:62:40: warning: 'struct request_sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
                                           ^~~~~~~~~~~~
   include/net/mptcp.h:64:1: error: unknown type name 'bool'; did you mean '_Bool'?
    bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
    ^~~~
    _Bool
   include/net/mptcp.h:64:56: warning: 'struct sk_buff' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
                                                           ^~~~~~~
   include/net/mptcp.h:64:39: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    bool mptcp_established_options(struct sock *sk, struct sk_buff *skb,
                                          ^~~~
   include/net/mptcp.h:68:15: warning: 'struct tcp_options_received' declared inside parameter list will not be visible outside of this definition or declaration
           struct tcp_options_received *opt_rx);
                  ^~~~~~~~~~~~~~~~~~~~
   include/net/mptcp.h:67:53: warning: 'struct sk_buff' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
                                                        ^~~~~~~
   include/net/mptcp.h:67:36: warning: 'struct sock' declared inside parameter list will not be visible outside of this definition or declaration
    void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
                                       ^~~~
   include/net/mptcp.h:70:15: error: unknown type name 'bool'
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                  ^~~~
   include/net/mptcp.h:70:53: warning: 'struct sk_buff' declared inside parameter list will not be visible outside of this definition or declaration
    static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
                                                        ^~~~~~~
   include/net/mptcp.h: In function 'mptcp_skb_ext_exist':
   include/net/mptcp.h:72:9: error: implicit declaration of function 'skb_ext_exist'; did you mean 'mptcp_skb_ext_exist'? [-Werror=implicit-function-declaration]
     return skb_ext_exist(skb, SKB_EXT_MPTCP);
            ^~~~~~~~~~~~~
            mptcp_skb_ext_exist
   include/net/mptcp.h:72:28: error: 'SKB_EXT_MPTCP' undeclared (first use in this function)
     return skb_ext_exist(skb, SKB_EXT_MPTCP);
                               ^~~~~~~~~~~~~
   include/net/mptcp.h:72:28: note: each undeclared identifier is reported only once for each function it appears in
   include/net/mptcp.h: At top level:
   include/net/mptcp.h:75:26: error: unknown type name '__be32'; did you mean '__weak'?
    void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
                             ^~~~~~
                             __weak

cc1: some warnings being treated as errors

vim +/addr +33 include/net/mptcp.h

    26	
    27	struct mptcp_out_options {
    28	#if IS_ENABLED(CONFIG_MPTCP)
  > 29		u16 suboptions;
  > 30		u64 sndr_key;
    31		u64 rcvr_key;
    32		union {
  > 33			struct in_addr addr;
    34	#if IS_ENABLED(CONFIG_IPV6)
  > 35			struct in6_addr addr6;
    36	#endif
    37		};
    38		u8 addr_id;
    39		struct mptcp_ext ext_copy;
    40	#endif
    41	};
    42	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#43 lore raw

RFC PATCH v2 28/45 mptcp: Add handling of incoming MP_JOIN requests

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Process the MP_JOIN option in a SYN packet with the same flow as MP_CAPABLE but when the third ACK is received add the subflow to the MPTCP socket subflow list instead of adding it to the TCP socket accept queue.

The subflow is added at the end of the subflow list so it will not interfere with the existing subflows operation and no data is expected to be transmitted on it.

---
 include/linux/tcp.h      |   6 +++
 include/net/mptcp.h      |  11 ++++
 net/ipv4/tcp_minisocks.c |   6 +++
 net/mptcp/options.c      |  55 +++++++++++++++++++-
 net/mptcp/protocol.c     |  22 ++++++++
 net/mptcp/protocol.h     |  27 +++++++++-
 net/mptcp/subflow.c      | 105 ++++++++++++++++++++++++++++++++++++++-
 net/mptcp/token.c        |  22 ++++++++
 8 files changed, 249 insertions(+), 5 deletions(-)
include/linux/tcp.h +6 -0
index b3289e69cac1..3b69ab99e666 100644
@@ -107,8 +107,14 @@ struct tcp_options_received {
 		u8      mp_capable : 1,
 			mp_join : 1,
 			dss : 1,
+			backup : 1,
 			version : 4;
 		u8      flags;
+		u8      join_id;
+		u32     token;
+		u32     nonce;
+		u64     thmac;
+		u8      hmac[20];
 		u8	dss_flags;
 		u8	use_map:1,
 			dsn64:1,
include/net/mptcp.h +11 -0
index f4a9962ea85f..bb2dd193c0c5 100644
@@ -36,6 +36,10 @@ struct mptcp_out_options {
 #endif
 	};
 	u8 addr_id;
+	u8 join_id;
+	u8 backup;
+	u32 nonce;
+	u64 thmac;
 	struct mptcp_ext ext_copy;
 #endif
 };
@@ -74,6 +78,8 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 
 void mptcp_write_options(__be32 *ptr, struct mptcp_out_options *opts);
 
+bool mptcp_sk_is_subflow(const struct sock *sk);
+
 #else
 
 static inline void mptcp_init(void)
@@ -132,5 +138,10 @@ static inline bool mptcp_skb_ext_exist(const struct sk_buff *skb)
 	return false;
 }
 
+static inline bool mptcp_sk_is_subflow(const struct sock *sk)
+{
+	return false;
+}
+
 #endif /* CONFIG_MPTCP */
 #endif /* __NET_MPTCP_H */
net/ipv4/tcp_minisocks.c +6 -0
index bb140a5db8c0..c519684d081b 100644
@@ -767,6 +767,12 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 	if (!child)
 		goto listen_overflow;
 
+	if (own_req && sk_is_mptcp(child) && mptcp_sk_is_subflow(child)) {
+		inet_csk_reqsk_queue_drop(sk, req);
+		reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req);
+		return child;
+	}
+
 	sock_rps_save_rxhash(child, skb);
 	tcp_synack_rtt_meas(child, req);
 	*req_stolen = !own_req;
net/mptcp/options.c +54 -1

76 lines not on this page · raw message

net/mptcp/protocol.c +22 -0
index 932362e6047e..32d9963c492d 100644
@@ -805,6 +805,28 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 	inet_sk_state_store(sk, TCP_ESTABLISHED);
 }
 
+void mptcp_finish_join(struct sock *sk)
+{
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
+
+	pr_debug("msk=%p, subflow=%p", msk, subflow);
+
+	local_bh_disable();
+	bh_lock_sock_nested(subflow->conn);
+	list_add_tail(&subflow->node, &msk->conn_list);
+	bh_unlock_sock(subflow->conn);
+	local_bh_enable();
+	inet_sk_state_store(sk, TCP_ESTABLISHED);
+}
+
+bool mptcp_sk_is_subflow(const struct sock *sk)
+{
+	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
+
+	return subflow->mp_join == 1;
+}
+
 static struct proto mptcp_prot = {
 	.name		= "MPTCP",
 	.owner		= THIS_MODULE,
net/mptcp/protocol.h +25 -2
index fd21ed6c03b7..16fe1c766d98 100644
@@ -15,6 +15,9 @@
 #define OPTION_MPTCP_MPC_SYN	BIT(0)
 #define OPTION_MPTCP_MPC_SYNACK	BIT(1)
 #define OPTION_MPTCP_MPC_ACK	BIT(2)
+#define OPTION_MPTCP_MPJ_SYN	BIT(3)
+#define OPTION_MPTCP_MPJ_SYNACK	BIT(4)
+#define OPTION_MPTCP_MPJ_ACK	BIT(5)
 #define OPTION_MPTCP_ADD_ADDR	BIT(6)
 #define OPTION_MPTCP_ADD_ADDR6	BIT(7)
 #define OPTION_MPTCP_RM_ADDR	BIT(8)
@@ -33,6 +36,9 @@
 #define TCPOLEN_MPTCP_MPC_SYN		12
 #define TCPOLEN_MPTCP_MPC_SYNACK	20
 #define TCPOLEN_MPTCP_MPC_ACK		20
+#define TCPOLEN_MPTCP_MPJ_SYN		12
+#define TCPOLEN_MPTCP_MPJ_SYNACK	16
+#define TCPOLEN_MPTCP_MPJ_ACK		24
 #define TCPOLEN_MPTCP_DSS_BASE		4
 #define TCPOLEN_MPTCP_DSS_ACK32		4
 #define TCPOLEN_MPTCP_DSS_ACK64		8
@@ -43,6 +49,9 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6		20
 #define TCPOLEN_MPTCP_RM_ADDR		4
 
+#define MPTCPOPT_BACKUP		BIT(0)
+#define MPTCPOPT_HMAC_LEN	20
+
 /* MPTCP MP_CAPABLE flags */
 #define MPTCP_VERSION_MASK	(0x0F)
 #define MPTCP_CAP_CHECKSUM_REQD	BIT(7)
@@ -128,11 +137,15 @@ struct mptcp_subflow_request_sock {
 		backup : 1,
 		version : 4;
 	u8	local_id;
+	u8	remote_id;
 	u64	local_key;
 	u64	remote_key;
 	u64	idsn;
 	u32	token;
 	u32	ssn_offset;
+	u64	thmac;
+	u32	local_nonce;
+	u32	remote_nonce;
 };
 
 static inline struct mptcp_subflow_request_sock *
@@ -156,14 +169,22 @@ struct mptcp_subflow_context {
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
 		request_cksum : 1,
 		request_version : 4,
-		mp_capable : 1,	    /* remote is MPTCP capable */
+		mp_capable : 1,     /* remote is MPTCP capable */
+		mp_join : 1,        /* remote is JOINing */
 		fourth_ack : 1,     /* send initial DSS */
 		conn_finished : 1,
 		use_checksum : 1,
-		map_valid : 1;
+		map_valid : 1,
+		backup : 1;
+	u32	remote_nonce;
+	u64	thmac;
+	u32	local_nonce;
+	u8	local_id;
+	u8	remote_id;
 
 	struct  socket *tcp_sock;  /* underlying tcp_sock */
 	struct  sock *conn;        /* parent mptcp_sock */
+
 	void	(*tcp_sk_data_ready)(struct sock *sk);
 	struct	rcu_head rcu;
 };
@@ -192,12 +213,14 @@ void mptcp_get_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx);
 
 void mptcp_finish_connect(struct sock *sk, int mp_capable);
+void mptcp_finish_join(struct sock *sk);
 
 int mptcp_token_new_request(struct request_sock *req);
 void mptcp_token_destroy_request(u32 token);
 int mptcp_token_new_connect(struct sock *sk);
 int mptcp_token_new_accept(u32 token);
 void mptcp_token_update_accept(struct sock *sk, struct sock *conn);
+struct mptcp_sock *mptcp_token_get_sock(u32 token);
 void mptcp_token_destroy(u32 token);
 
 void mptcp_crypto_key_sha1(u64 key, u32 *token, u64 *idsn);
net/mptcp/subflow.c +103 -2

158 lines not on this page · raw message

net/mptcp/token.c +22 -0
index 7e579deef6a2..a0d8f6e323b2 100644
@@ -167,6 +167,28 @@ void mptcp_token_update_accept(struct sock *sk, struct sock *conn)
 	spin_unlock_bh(&token_tree_lock);
 }
 
+/**
+ * mptcp_token_get_sock - retrieve mptcp connection sock using its token
+ * @token - token of the mptcp connection to retrieve
+ *
+ * This function returns the mptcp connection structure with the given token.
+ * A reference count on the mptcp socket returned is taken.
+ *
+ * returns NULL if no connection with the given token value exists.
+ */
+struct mptcp_sock *mptcp_token_get_sock(u32 token)
+{
+	struct sock *conn;
+
+	spin_lock_bh(&token_tree_lock);
+	conn = radix_tree_lookup(&token_tree, token);
+	if (conn)
+		sock_hold(conn);
+	spin_unlock_bh(&token_tree_lock);
+
+	return mptcp_sk(conn);
+}
+
 /**
  * mptcp_token_destroy_request - remove mptcp connection/token
  * @token - token of mptcp connection to remove
Signature · 1 line
2.23.0
#44 lore raw

RFC PATCH v2 29/45 mptcp: harmonize locking on all socket operations.

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

The locking schema implied by sendmsg(), recvmsg(), etc. requires acquiring the msk's socket lock before manipulating the msk internal status.

Additionally, we can't acquire the msk->subflow socket lock while holding the msk lock, due to mptcp_finish_connect().

Many socket operations do not enforce the required locking, e.g. we have several patterns alike:

	if (msk->subflow)
		// do something with msk->subflow

or:

	if (!msk->subflow)
		// allocate msk->subflow

all without any lock acquired.

They can race with each other and with mptcp_finish_connect() causing UAF, null ptr dereference and/or memory leaks.

This patch ensures that all mptcp socket operations access and manipulate msk->subflow under the msk socket lock. To avoid breaking the locking assumption introduced by mptcp_finish_connect(), while avoiding UAF issues, we acquire a reference to the msk->subflow, where needed.

---
 net/mptcp/protocol.c | 82 +++++++++++++++++++++++++++++++++-----------
 net/mptcp/subflow.c  |  3 --
 2 files changed, 62 insertions(+), 23 deletions(-)
net/mptcp/protocol.c +62 -20
index 32d9963c492d..8512cf5e0e0f 100644
@@ -178,6 +178,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	struct sock *ssk;
 	long timeo;
 
+	pr_debug("msk=%p", msk);
 	lock_sock(sk);
 	ssock = __mptcp_fallback_get_ref(msk);
 	if (ssock) {
@@ -846,38 +847,72 @@ static struct proto mptcp_prot = {
 	.no_autobind	= 1,
 };
 
+static struct socket *mptcp_socket_create_get(struct mptcp_sock *msk)
+{
+	struct mptcp_subflow_context *subflow;
+	struct sock *sk = (struct sock *)msk;
+	struct socket *ssock;
+	int err;
+
+	lock_sock(sk);
+	ssock = __mptcp_fallback_get_ref(msk);
+	if (ssock)
+		goto release;
+
+	err = mptcp_subflow_create_socket(sk, &ssock);
+	if (err) {
+		ssock = ERR_PTR(err);
+		goto release;
+	}
+
+	msk->subflow = ssock;
+	subflow = mptcp_subflow_ctx(msk->subflow->sk);
+	subflow->request_mptcp = 1; /* @@ if MPTCP enabled */
+	subflow->request_cksum = 0; /* checksum not supported */
+	subflow->request_version = 0; /* only v0 supported */
+
+	sock_hold(ssock->sk);
+
+release:
+	release_sock(sk);
+	return ssock;
+}
+
 static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
 	struct mptcp_sock *msk = mptcp_sk(sock->sk);
+	struct socket *ssock;
 	int err = -ENOTSUPP;
 
 	if (uaddr->sa_family != AF_INET) // @@ allow only IPv4 for now
 		return err;
 
-	if (!msk->subflow) {
-		err = mptcp_subflow_create_socket(sock->sk, &msk->subflow);
-		if (err)
-			return err;
-	}
-	return inet_bind(msk->subflow, uaddr, addr_len);
+	ssock = mptcp_socket_create_get(msk);
+	if (IS_ERR(ssock))
+		return PTR_ERR(ssock);
+
+	err = inet_bind(ssock, uaddr, addr_len);
+	sock_put(ssock->sk);
+	return err;
 }
 
 static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
 				int addr_len, int flags)
 {
 	struct mptcp_sock *msk = mptcp_sk(sock->sk);
+	struct socket *ssock;
 	int err = -ENOTSUPP;
 
 	if (uaddr->sa_family != AF_INET) // @@ allow only IPv4 for now
 		return err;
 
-	if (!msk->subflow) {
-		err = mptcp_subflow_create_socket(sock->sk, &msk->subflow);
-		if (err)
-			return err;
-	}
+	ssock = mptcp_socket_create_get(msk);
+	if (IS_ERR(ssock))
+		return PTR_ERR(ssock);
 
-	return inet_stream_connect(msk->subflow, uaddr, addr_len, flags);
+	err = inet_stream_connect(ssock, uaddr, addr_len, flags);
+	sock_put(ssock->sk);
+	return err;
 }
 
 static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,
@@ -929,29 +964,36 @@ static int mptcp_getname(struct socket *sock, struct sockaddr *uaddr,
 static int mptcp_listen(struct socket *sock, int backlog)
 {
 	struct mptcp_sock *msk = mptcp_sk(sock->sk);
+	struct socket *ssock;
 	int err;
 
 	pr_debug("msk=%p", msk);
 
-	if (!msk->subflow) {
-		err = mptcp_subflow_create_socket(sock->sk, &msk->subflow);
-		if (err)
-			return err;
-	}
-	return inet_listen(msk->subflow, backlog);
+	ssock = mptcp_socket_create_get(msk);
+	if (IS_ERR(ssock))
+		return PTR_ERR(ssock);
+
+	err = inet_listen(ssock, backlog);
+	sock_put(ssock->sk);
+	return err;
 }
 
 static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 			       int flags, bool kern)
 {
 	struct mptcp_sock *msk = mptcp_sk(sock->sk);
+	struct socket *ssock;
+	int err;
 
 	pr_debug("msk=%p", msk);
 
-	if (!msk->subflow)
+	ssock = mptcp_fallback_get_ref(msk);
+	if (!ssock)
 		return -EINVAL;
 
-	return inet_accept(sock, newsock, flags, kern);
+	err = inet_accept(sock, newsock, flags, kern);
+	sock_put(ssock->sk);
+	return err;
 }
 
 static __poll_t mptcp_poll(struct file *file, struct socket *sock,
net/mptcp/subflow.c +0 -3
index 1c3330ab2f30..04f232ff1df0 100644
@@ -293,9 +293,6 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
 	*new_sock = sf;
 	sock_hold(sk);
 	subflow->conn = sk;
-	subflow->request_mptcp = 1; // @@ if MPTCP enabled
-	subflow->request_cksum = 1; // @@ if checksum enabled
-	subflow->request_version = 0;
 
 	return 0;
 }
Signature · 1 line
2.23.0
#45 lore raw

RFC PATCH v2 30/45 mptcp: new sysctl to control the activation per NS

In reply to Mat Martineau

From: Matthieu Baerts <[email protected]>

New MPTCP sockets will return -ENOPROTOOPT if MPTCP support is disabled for the current net namespace.

For security reasons, it is interesting to have a global switch for MPTCP. To start, MPTCP will be disabled by default and only privileged users will be able to modify this. The reason is that because MPTCP is new, it will not be tested and reviewed by many and security issues can then take time to be discovered and fixed.

The value of this new sysctl can be different per namespace. We can then restrict the usage of MPTCP to the selected NS. In case of serious issues with MPTCP, administrators can now easily turn MPTCP off.

---
 net/mptcp/Makefile   |   2 +-
 net/mptcp/ctrl.c     | 112 +++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.c |  25 +++++-----
 net/mptcp/protocol.h |   4 ++
 4 files changed, 129 insertions(+), 14 deletions(-)
 create mode 100644 net/mptcp/ctrl.c
net/mptcp/Makefile +1 -1
index 7fe7aa64eda0..289fdf4339c1 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o ctrl.o
net/mptcp/ctrl.c new file +112 -0

112 lines not on this page · raw message

net/mptcp/protocol.c +12 -13
index 8512cf5e0e0f..fa99337ca773 100644
@@ -562,22 +562,21 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 	return copied;
 }
 
-static int mptcp_init_sock(struct sock *sk)
+static int __mptcp_init_sock(struct sock *sk)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
-	struct net *net = sock_net(sk);
-	struct socket *sf;
-	int err;
-
-	err = sock_create_kern(net, PF_INET, SOCK_STREAM, IPPROTO_TCP, &sf);
-	if (!err) {
-		pr_debug("subflow=%p", sf->sk);
-		msk->subflow = sf;
-	}
 
 	INIT_LIST_HEAD(&msk->conn_list);
 
-	return err;
+	return 0;
+}
+
+static int mptcp_init_sock(struct sock *sk)
+{
+	if (!mptcp_is_enabled(sock_net(sk)))
+		return -ENOPROTOOPT;
+
+	return __mptcp_init_sock(sk);
 }
 
 static void mptcp_close(struct sock *sk, long timeout)
@@ -646,7 +645,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 			return NULL;
 		}
 
-		mptcp_init_sock(new_mptcp_sock);
+		__mptcp_init_sock(new_mptcp_sock);
 
 		msk = mptcp_sk(new_mptcp_sock);
 		msk->remote_key = subflow->remote_key;
@@ -1067,7 +1066,7 @@ static struct inet_protosw mptcp_protosw = {
 	.flags		= INET_PROTOSW_ICSK,
 };
 
-void __init mptcp_init(void)
+void mptcp_proto_init(void)
 {
 	mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;
 	mptcp_stream_ops = inet_stream_ops;
net/mptcp/protocol.h +4 -0
index 16fe1c766d98..394f2477e6f8 100644
@@ -204,11 +204,15 @@ mptcp_subflow_tcp_socket(const struct mptcp_subflow_context *subflow)
 	return subflow->tcp_sock;
 }
 
+int mptcp_is_enabled(struct net *net);
+
 void mptcp_subflow_init(void);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
 
+void mptcp_proto_init(void);
+
 void mptcp_get_options(const struct sk_buff *skb,
 		       struct tcp_options_received *opt_rx);
 
Signature · 1 line
2.23.0
#46 lore raw

RFC PATCH v2 31/45 mptcp: add basic kselftest for mptcp

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

Add mpcp_connect tool:
xmit two files back and forth between two processes. Wrapper script tests that data was transmitted without corruption.

The "-c" command line option for mptcp_connect.sh is there for debugging:

The script will use tcpdump to create one .pcap file per test case, named according to the namespaces, protocols, and connect address in use. For example, the first test case writes the capture to ns1-ns1-MPTCP-MPTCP-10.0.1.1.pcap.

The stderr output from tcpdump is printed after the test completes to show tcpdump's "packets dropped by kernel" information.

Also check that userspace can't create MPTCP sockets when mptcp.enabled sysctl is off.

Will run automatically on "make kselftest".

This patch merged following enhancements:
From Mat Martineau:
* mptcp: selftests: Add capture option
From Matthieu Baerts: Add sysctl test
From Paolo Abeni: Use tc/ethtool to test more skb handling code paths

---
 tools/testing/selftests/Makefile              |   1 +
 tools/testing/selftests/net/mptcp/.gitignore  |   2 +
 tools/testing/selftests/net/mptcp/Makefile    |  11 +
 tools/testing/selftests/net/mptcp/config      |   1 +
 .../selftests/net/mptcp/mptcp_connect.c       | 408 ++++++++++++++++++
 .../selftests/net/mptcp/mptcp_connect.sh      | 295 +++++++++++++
 6 files changed, 718 insertions(+)
 create mode 100644 tools/testing/selftests/net/mptcp/.gitignore
 create mode 100644 tools/testing/selftests/net/mptcp/Makefile
 create mode 100644 tools/testing/selftests/net/mptcp/config
 create mode 100644 tools/testing/selftests/net/mptcp/mptcp_connect.c
 create mode 100755 tools/testing/selftests/net/mptcp/mptcp_connect.sh
tools/testing/selftests/Makefile +1 -0
index c3feccb99ff5..4a404ee1b980 100644
@@ -29,6 +29,7 @@ TARGETS += memory-hotplug
 TARGETS += mount
 TARGETS += mqueue
 TARGETS += net
+TARGETS += net/mptcp
 TARGETS += netfilter
 TARGETS += networking/timestamping
 TARGETS += nsfs
tools/testing/selftests/net/mptcp/.gitignore new file +2 -0
new file mode 100644
index 000000000000..d72f07642738
@@ -0,0 +1,2 @@
+mptcp_connect
+*.pcap
tools/testing/selftests/net/mptcp/Makefile new file +11 -0
new file mode 100644
index 000000000000..0fc5d45055ee
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+
+top_srcdir = ../../../../..
+
+CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
+
+TEST_PROGS := mptcp_connect.sh
+
+TEST_GEN_FILES = mptcp_connect
+
+include ../../lib.mk
tools/testing/selftests/net/mptcp/config new file +1 -0
new file mode 100644
index 000000000000..3bfe60494af8
@@ -0,0 +1 @@
+CONFIG_MPTCP=y
tools/testing/selftests/net/mptcp/mptcp_connect.c new file +408 -0

408 lines not on this page · raw message

tools/testing/selftests/net/mptcp/mptcp_connect.sh new file +295 -0

295 lines not on this page · raw message

Signature · 1 line
2.23.0
#47 lore raw

RFC PATCH v2 32/45 mptcp: Add handling of outgoing MP_JOIN requests

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Subflow creation may be initiated by the path manager when the primary connection is fully established and a remote address has been received via ADD_ADDR.

Create an in-kernel sock and use kernel_connect() to initiate connection. When a valid SYN-ACK is received the new sock is added to the tail of the mptcp sock conn_list where it will not interfere with data flow on the original connection.

Data flow and connection failover not addressed by this commit.

---
 include/net/mptcp.h  |  2 +
 net/mptcp/options.c  | 51 +++++++++++++++++++++--
 net/mptcp/protocol.c |  1 +
 net/mptcp/protocol.h |  9 ++++
 net/mptcp/subflow.c  | 98 +++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 156 insertions(+), 5 deletions(-)
include/net/mptcp.h +2 -0
index bb2dd193c0c5..50cd1b31ebdd 100644
@@ -40,6 +40,8 @@ struct mptcp_out_options {
 	u8 backup;
 	u32 nonce;
 	u64 thmac;
+	u32 token;
+	u8 hmac[20];
 	struct mptcp_ext ext_copy;
 #endif
 };
net/mptcp/options.c +47 -4

105 lines not on this page · raw message

net/mptcp/protocol.c +1 -0
index fa99337ca773..445800eae767 100644
@@ -787,6 +787,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 		msk->local_key = subflow->local_key;
 		msk->token = subflow->token;
 		pr_debug("msk=%p, token=%u", msk, msk->token);
+		msk->dport = ntohs(inet_sk(msk->subflow->sk)->inet_dport);
 
 		pm_new_connection(msk, 0);
 
net/mptcp/protocol.h +9 -0
index 394f2477e6f8..4a1171b75ec6 100644
@@ -49,8 +49,10 @@
 #define TCPOLEN_MPTCP_ADD_ADDR6		20
 #define TCPOLEN_MPTCP_RM_ADDR		4
 
+/* MPTCP MP_JOIN flags */
 #define MPTCPOPT_BACKUP		BIT(0)
 #define MPTCPOPT_HMAC_LEN	20
+#define MPTCPOPT_THMAC_LEN	8
 
 /* MPTCP MP_CAPABLE flags */
 #define MPTCP_VERSION_MASK	(0x0F)
@@ -115,6 +117,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u32		token;
+	u16		dport;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
@@ -167,7 +170,9 @@ struct mptcp_subflow_context {
 	u32	ssn_offset;
 	u16	map_data_len;
 	u16	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_join : 1,   /* send MP_JOIN */
 		request_cksum : 1,
+		request_bkup : 1,
 		request_version : 4,
 		mp_capable : 1,     /* remote is MPTCP capable */
 		mp_join : 1,        /* remote is JOINing */
@@ -179,6 +184,8 @@ struct mptcp_subflow_context {
 	u32	remote_nonce;
 	u64	thmac;
 	u32	local_nonce;
+	u32	remote_token;
+	u8	hmac[MPTCPOPT_HMAC_LEN];
 	u8	local_id;
 	u8	remote_id;
 
@@ -207,6 +214,8 @@ mptcp_subflow_tcp_socket(const struct mptcp_subflow_context *subflow)
 int mptcp_is_enabled(struct net *net);
 
 void mptcp_subflow_init(void);
+int mptcp_subflow_connect(struct sock *sk, struct sockaddr_in *local,
+			  struct sockaddr_in *remote, u8 remote_id);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 extern const struct inet_connection_sock_af_ops ipv4_specific;
net/mptcp/subflow.c +97 -1

128 lines not on this page · raw message

Signature · 1 line
2.23.0
#48 lore raw

RFC PATCH v2 33/45 mptcp: Implement path manager interface commands

In reply to Mat Martineau

From: Peter Krystad <[email protected]>

Use the addr_signal flag to indicate to the subflow layer that a local address may be announced, and call subflow_connect() to initiate a secondary subflow.

---
 net/mptcp/pm.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 3 deletions(-)
net/mptcp/pm.c +60 -3
index 933dd805c9b2..7c7c00f9f7e8 100644
@@ -13,17 +13,74 @@
 int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,
 		     struct in_addr *addr)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_token_get_sock(token);
+	int err = 0;
+
+	if (!msk)
+		return -EINVAL;
+
+	if (msk->pm.local_valid) {
+		err = -EBADR;
+		goto announce_put;
+	}
+
+	pr_debug("msk=%p, local_id=%d, addr=%x", msk, local_id, addr->s_addr);
+	msk->pm.local_valid = 1;
+	msk->pm.local_id = local_id;
+	msk->pm.local_family = family;
+	msk->pm.local_addr.s_addr = addr->s_addr;
+	msk->addr_signal = 1;
+
+announce_put:
+	sock_put((struct sock *)msk);
+	return err;
 }
 
 int pm_remove_addr(u32 token, u8 local_id)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_token_get_sock(token);
+
+	if (!msk)
+		return -EINVAL;
+
+	pr_debug("msk=%p", msk);
+	msk->pm.local_valid = 0;
+
+	sock_put((struct sock *)msk);
+	return 0;
 }
 
 int pm_create_subflow(u32 token, u8 remote_id)
 {
-	return -ENOTSUPP;
+	struct mptcp_sock *msk = mptcp_token_get_sock(token);
+	struct sockaddr_in remote;
+	struct sockaddr_in local;
+	int err;
+
+	if (!msk)
+		return -EINVAL;
+
+	pr_debug("msk=%p", msk);
+
+	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
+		err = -EBADR;
+		goto create_put;
+	}
+
+	local.sin_family = AF_INET;
+	local.sin_port = 0;
+	local.sin_addr.s_addr = htonl(INADDR_ANY);
+
+	remote.sin_family = msk->pm.remote_family;
+	remote.sin_port = htons(msk->dport);
+	remote.sin_addr.s_addr = msk->pm.remote_addr.s_addr;
+
+	err = mptcp_subflow_connect((struct sock *)msk, &local, &remote,
+				    remote_id);
+
+create_put:
+	sock_put((struct sock *)msk);
+	return err;
 }
 
 int pm_remove_subflow(u32 token, u8 remote_id)
Signature · 1 line
2.23.0
#49 lore raw

RFC PATCH v2 34/45 mptcp: Make MPTCP socket block/wakeup ignore sk_receive_queue

In reply to Mat Martineau

The MPTCP-level socket doesn't use sk_receive_queue, so it was possible for mptcp_recvmsg() to remain blocked when there was data ready for it to read. When the MPTCP socket is waiting for additional data and it releases the subflow socket lock, the subflow may have incoming packets ready to process and it sometimes called subflow_data_ready() before the MPTCP socket called sk_wait_data().

This change adds a new function for the MPTCP socket to use when waiting for a data ready signal. Atomic bitops with memory barriers are used to set, test, and clear a MPTCP socket flag that indicates waiting subflow data. This flag replaces the sk_receive_queue checks used by other socket types.

---
 net/mptcp/protocol.c | 31 ++++++++++++++++++++++++++++++-
 net/mptcp/protocol.h |  4 ++++
 net/mptcp/subflow.c  |  5 +++++
 3 files changed, 39 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +30 -1
index 445800eae767..c8ee20963887 100644
@@ -367,6 +367,31 @@ static enum mapping_status mptcp_get_mapping(struct sock *ssk)
 	return ret;
 }
 
+static void mptcp_wait_data(struct sock *sk, long *timeo)
+{
+	DEFINE_WAIT_FUNC(wait, woken_wake_function);
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	int data_ready;
+
+	add_wait_queue(sk_sleep(sk), &wait);
+	sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk);
+
+	release_sock(sk);
+
+	smp_mb__before_atomic();
+	data_ready = test_and_clear_bit(MPTCP_DATA_READY, &msk->flags);
+	smp_mb__after_atomic();
+
+	if (!data_ready)
+		*timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, *timeo);
+
+	sched_annotate_sleep();
+	lock_sock(sk);
+
+	sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk);
+	remove_wait_queue(sk_sleep(sk), &wait);
+}
+
 static void warn_bad_map(struct mptcp_subflow_context *subflow, u32 ssn)
 {
 	WARN_ONCE(1, "Bad mapping: ssn=%d map_seq=%d map_data_len=%d",
@@ -423,6 +448,10 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 		u64 old_ack;
 		u32 ssn;
 
+		smp_mb__before_atomic();
+		clear_bit(MPTCP_DATA_READY, &msk->flags);
+		smp_mb__after_atomic();
+
 		status = mptcp_get_mapping(ssk);
 
 		if (status == MAPPING_ADDED) {
@@ -550,7 +579,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 
 		pr_debug("block");
 		release_sock(ssk);
-		sk_wait_data(sk, &timeo, NULL);
+		mptcp_wait_data(sk, &timeo);
 		lock_sock(ssk);
 	}
 
net/mptcp/protocol.h +4 -0
index 4a1171b75ec6..56df4f46f313 100644
@@ -74,6 +74,9 @@
 #define MPTCP_ADDR_IPVERSION_4	4
 #define MPTCP_ADDR_IPVERSION_6	6
 
+/* MPTCP socket flags */
+#define MPTCP_DATA_READY	BIT(0)
+
 static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
 {
 	return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) |
@@ -117,6 +120,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	u32		token;
+	unsigned long	flags;
 	u16		dport;
 	struct list_head conn_list;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
net/mptcp/subflow.c +5 -0
index 257e52d9595e..7a94049587cc 100644
@@ -311,6 +311,11 @@ static void subflow_data_ready(struct sock *sk)
 
 	if (parent) {
 		pr_debug("parent=%p", parent);
+
+		smp_mb__before_atomic();
+		set_bit(MPTCP_DATA_READY, &mptcp_sk(parent)->flags);
+		smp_mb__after_atomic();
+
 		parent->sk_data_ready(parent);
 	}
 }
Signature · 1 line
2.23.0
#50 lore raw

RFC PATCH v2 35/45 mptcp: update per unacked sequence on pkt reception

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

So that we keep per unacked sequence number consistent; since we update per msk data, use an atomic64 cmpxcgh() to protect against concurrent updates from multiple subflows.

Initialize the snd_una at connect()/accept() time.

---
 net/mptcp/options.c  | 45 ++++++++++++++++++++++++++++++++++++++------
 net/mptcp/protocol.c |  2 ++
 net/mptcp/protocol.h |  1 +
 3 files changed, 42 insertions(+), 6 deletions(-)
net/mptcp/options.c +39 -6
index ce298ecc64f5..2427fff98091 100644
@@ -540,6 +540,39 @@ bool mptcp_synack_options(const struct request_sock *req, unsigned int *size,
 	return false;
 }
 
+static u64 expand_ack(u64 old_ack, u64 cur_ack, bool use_64bit)
+{
+	u32 old_ack32, cur_ack32;
+
+	if (use_64bit)
+		return cur_ack;
+
+	old_ack32 = (u32)old_ack;
+	cur_ack32 = (u32)cur_ack;
+	cur_ack = (old_ack & GENMASK_ULL(63, 32)) + cur_ack32;
+	if (unlikely(before(cur_ack32, old_ack32)))
+		return cur_ack + (1LL << 32);
+	return cur_ack;
+}
+
+void update_una(struct mptcp_sock *msk, struct mptcp_options_received *mp_opt)
+{
+	u64 new_snd_una, snd_una, old_snd_una = atomic64_read(&msk->snd_una);
+
+	/* avoid ack expansion on update conflict, to reduce the risk of
+	 * wrongly expanding to a future ack sequence number, which is way
+	 * more dangerous than missing an ack
+	 */
+	new_snd_una = expand_ack(old_snd_una, mp_opt->data_ack, mp_opt->ack64);
+	while (after64(new_snd_una, old_snd_una)) {
+		snd_una = old_snd_una;
+		old_snd_una = atomic64_cmpxchg(&msk->snd_una, snd_una,
+					       new_snd_una);
+		if (old_snd_una == snd_una)
+			break;
+	}
+}
+
 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			    struct tcp_options_received *opt_rx)
 {
@@ -563,6 +596,12 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 	if (!mp_opt->dss)
 		return;
 
+	/* we can't wait for recvmsg() to update the ack_seq, otherwise
+	 * monodirectional flows will stuck
+	 */
+	if (msk && mp_opt->use_ack)
+		update_una(msk, mp_opt);
+
 	mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
 	if (!mpext)
 		return;
@@ -579,12 +618,6 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 		mpext->use_checksum = mp_opt->use_checksum;
 	}
 
-	if (mp_opt->use_ack) {
-		mpext->data_ack = mp_opt->data_ack;
-		mpext->use_ack = 1;
-		mpext->ack64 = mp_opt->ack64;
-	}
-
 	mpext->data_fin = mp_opt->data_fin;
 
 	if (msk)
net/mptcp/protocol.c +2 -0
index c8ee20963887..2c64435aedd8 100644
@@ -688,6 +688,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 
 		mptcp_crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
+		atomic64_set(&msk->snd_una, msk->write_seq);
 		ack_seq++;
 		msk->ack_seq = ack_seq;
 		subflow->map_seq = ack_seq;
@@ -822,6 +823,7 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)
 
 		mptcp_crypto_key_sha1(msk->remote_key, NULL, &ack_seq);
 		msk->write_seq = subflow->idsn + 1;
+		atomic64_set(&msk->snd_una, msk->write_seq);
 		ack_seq++;
 		msk->ack_seq = ack_seq;
 		subflow->map_seq = ack_seq;
net/mptcp/protocol.h +1 -0
index 56df4f46f313..45646e38aa4c 100644
@@ -119,6 +119,7 @@ struct mptcp_sock {
 	u64		remote_key;
 	u64		write_seq;
 	u64		ack_seq;
+	atomic64_t	snd_una;
 	u32		token;
 	unsigned long	flags;
 	u16		dport;
Signature · 1 line
2.23.0
#51 lore raw

RFC PATCH v2 36/45 mptcp: queue data for mptcp level retransmission

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

keep the send page fragment on an MPTCP level retransmission queue. the queue entries are allocated inside the page frag allocator, acquiring an additional reference to the page for each list entry.

Also switch to a custom page frag refill function, to ensure that the current page fragment can always host an MPTCP rtx queue entry.

The MPTCP rtx queue is flushed at disconnect() and close() time

Note that now we need to call __mptcp_init_sock() regarless of mptcp enable status, as the destructor will try to walk the rtx_queue.

---
 net/mptcp/protocol.c | 131 ++++++++++++++++++++++++++++++++++++++++---
 net/mptcp/protocol.h |  20 +++++++
 2 files changed, 143 insertions(+), 8 deletions(-)
net/mptcp/protocol.c +123 -8
index 2c64435aedd8..c2e89e8cbc0e 100644
@@ -69,14 +69,74 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,
 	return mpext && mpext->data_seq + mpext->data_len == msk->write_seq;
 }
 
+static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
+					      const struct page_frag *pfrag,
+					      const struct mptcp_data_frag *df)
+{
+	return df && pfrag->page == df->page &&
+		df->data_seq + df->data_len == msk->write_seq;
+}
+
+static void dfrag_clear(struct mptcp_data_frag *dfrag)
+{
+	list_del(&dfrag->list);
+	put_page(dfrag->page);
+}
+
+static void mptcp_clean_una(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_data_frag *dtmp, *dfrag;
+	u64 snd_una = atomic64_read(&msk->snd_una);
+
+	list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list) {
+		if (after64(dfrag->data_seq + dfrag->data_len, snd_una))
+			break;
+
+		dfrag_clear(dfrag);
+	}
+}
+
+/* ensure we get enough memory for the frag hdr, beyond some minimal amount of
+ * data
+ */
+bool mptcp_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
+{
+	if (likely(skb_page_frag_refill(32U + sizeof(struct mptcp_data_frag),
+					pfrag, sk->sk_allocation)))
+		return true;
+
+	sk->sk_prot->enter_memory_pressure(sk);
+	sk_stream_moderate_sndbuf(sk);
+	return false;
+}
+
+static inline struct mptcp_data_frag *
+mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
+		      int orig_offset)
+{
+	int offset = ALIGN(orig_offset, sizeof(long));
+	struct mptcp_data_frag *dfrag;
+
+	dfrag = (struct mptcp_data_frag *)(page_to_virt(pfrag->page) + offset);
+	dfrag->data_len = 0;
+	dfrag->data_seq = msk->write_seq;
+	dfrag->overhead = offset - orig_offset + sizeof(struct mptcp_data_frag);
+	dfrag->offset = offset + sizeof(struct mptcp_data_frag);
+	dfrag->page = pfrag->page;
+
+	return dfrag;
+}
+
 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 			      struct msghdr *msg, long *timeo, int *pmss_now,
 			      int *ps_goal)
 {
-	int mss_now, avail_size, size_goal, ret;
+	int mss_now, avail_size, size_goal, offset, ret, frag_truesize = 0;
+	bool dfrag_collapsed, collapsed, can_collapse = false;
 	struct mptcp_sock *msk = mptcp_sk(sk);
-	bool collapsed, can_collapse = false;
 	struct mptcp_ext *mpext = NULL;
+	struct mptcp_data_frag *dfrag;
 	struct page_frag *pfrag;
 	struct sk_buff *skb;
 	size_t psize;
@@ -85,10 +145,15 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	 * from one substream to another, but do per subflow memory accounting
 	 */
 	pfrag = sk_page_frag(sk);
-	while (!sk_page_frag_refill(ssk, pfrag)) {
+	while (!mptcp_page_frag_refill(ssk, pfrag)) {
 		ret = sk_stream_wait_memory(ssk, timeo);
 		if (ret)
 			return ret;
+
+		/* id sk_stream_wait_memory() sleeps snd_una can change
+		 * significantly, refresh the rtx queue
+		 */
+		mptcp_clean_una(sk);
 	}
 
 	/* compute copy limit */
@@ -113,11 +178,23 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		else
 			avail_size = size_goal - skb->len;
 	}
-	psize = min_t(size_t, pfrag->size - pfrag->offset, avail_size);
+
+	/* reuse tail pfrag, if possible, or carve a new one from the page
+	 * allocator
+	 */
+	dfrag = mptcp_rtx_tail(sk);
+	offset = pfrag->offset;
+	dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
+	if (!dfrag_collapsed) {
+		dfrag = mptcp_carve_data_frag(msk, pfrag, offset);
+		offset = dfrag->offset;
+		frag_truesize = dfrag->overhead;
+	}
+	psize = min_t(size_t, pfrag->size - offset, avail_size);
 
 	/* Copy to page */
 	pr_debug("left=%zu", msg_data_left(msg));
-	psize = copy_page_from_iter(pfrag->page, pfrag->offset,
+	psize = copy_page_from_iter(pfrag->page, offset,
 				    min_t(size_t, msg_data_left(msg), psize),
 				    &msg->msg_iter);
 	pr_debug("left=%zu", msg_data_left(msg));
@@ -127,13 +204,24 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	/* tell the TCP stack to delay the push so that we can safely
 	 * access the skb after the sendpages call
 	 */
-	ret = do_tcp_sendpages(ssk, pfrag->page, pfrag->offset, psize,
+	ret = do_tcp_sendpages(ssk, pfrag->page, offset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST);
 	if (ret <= 0)
 		return ret;
+
+	frag_truesize += ret;
 	if (unlikely(ret < psize))
 		iov_iter_revert(&msg->msg_iter, psize - ret);
 
+	/* send successful, keep track of sent data for mptcp-level
+	 * retransmission
+	 */
+	dfrag->data_len += ret;
+	if (!dfrag_collapsed) {
+		get_page(dfrag->page);
+		list_add_tail(&dfrag->list, &msk->rtx_queue);
+	}
+
 	collapsed = skb == tcp_write_queue_tail(ssk);
 	if (collapsed) {
 		WARN_ON_ONCE(!can_collapse);
@@ -162,7 +250,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	 */
 
 out:
-	pfrag->offset += ret;
+	pfrag->offset += frag_truesize;
 	msk->write_seq += ret;
 	mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
 
@@ -209,6 +297,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	}
 
 	lock_sock(ssk);
+	mptcp_clean_una(sk);
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 	while (msg_data_left(msg)) {
 		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo, &mss_now,
@@ -596,16 +685,31 @@ static int __mptcp_init_sock(struct sock *sk)
 	struct mptcp_sock *msk = mptcp_sk(sk);
 
 	INIT_LIST_HEAD(&msk->conn_list);
+	INIT_LIST_HEAD(&msk->rtx_queue);
 
 	return 0;
 }
 
 static int mptcp_init_sock(struct sock *sk)
 {
+	int ret = __mptcp_init_sock(sk);
+
+	if (ret)
+		return ret;
+
 	if (!mptcp_is_enabled(sock_net(sk)))
 		return -ENOPROTOOPT;
 
-	return __mptcp_init_sock(sk);
+	return 0;
+}
+
+static void __mptcp_clear_xmit(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_data_frag *dtmp, *dfrag;
+
+	list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list)
+		dfrag_clear(dfrag);
 }
 
 static void mptcp_close(struct sock *sk, long timeout)
@@ -634,10 +738,20 @@ static void mptcp_close(struct sock *sk, long timeout)
 		sock_release(mptcp_subflow_tcp_socket(subflow));
 	}
 
+	__mptcp_clear_xmit(sk);
 	release_sock(sk);
+
 	sk_common_release(sk);
 }
 
+static int mptcp_disconnect(struct sock *sk, int flags)
+{
+	lock_sock(sk);
+	__mptcp_clear_xmit(sk);
+	release_sock(sk);
+	return tcp_disconnect(sk, flags);
+}
+
 static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 				 bool kern)
 {
@@ -863,6 +977,7 @@ static struct proto mptcp_prot = {
 	.name		= "MPTCP",
 	.owner		= THIS_MODULE,
 	.init		= mptcp_init_sock,
+	.disconnect	= mptcp_disconnect,
 	.close		= mptcp_close,
 	.accept		= mptcp_accept,
 	.setsockopt	= mptcp_setsockopt,
net/mptcp/protocol.h +20 -0
index 45646e38aa4c..e09db0f85bfc 100644
@@ -111,6 +111,15 @@ struct mptcp_pm_data {
 	u32	token;
 };
 
+struct mptcp_data_frag {
+	struct list_head list;
+	u64 data_seq;
+	int data_len;
+	int offset;
+	int overhead;
+	struct page *page;
+};
+
 /* MPTCP connection sock */
 struct mptcp_sock {
 	/* inet_connection_sock must be the first member */
@@ -124,6 +133,7 @@ struct mptcp_sock {
 	unsigned long	flags;
 	u16		dport;
 	struct list_head conn_list;
+	struct list_head rtx_queue;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct mptcp_pm_data	pm;
 	u8		addr_signal;
@@ -137,6 +147,16 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
 	return (struct mptcp_sock *)sk;
 }
 
+static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
+	if (list_empty(&msk->rtx_queue))
+		return NULL;
+
+	return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
+}
+
 struct mptcp_subflow_request_sock {
 	struct	tcp_request_sock sk;
 	u8	mp_capable : 1,
Signature · 1 line
2.23.0
#52 lore raw

RFC PATCH v2 37/45 mptcp: introduce MPTCP retransmission timer

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

The timer will be used to schedule retransmission. It's frequency is based on the current subflow RTO estimation and is reset on every una_seq update

The timer is clearer for good by __mptcp_clear_xmit()

Also clean MPTCP rtx queue before each transmission

---
 net/mptcp/options.c  |  4 +-
 net/mptcp/protocol.c | 99 ++++++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h |  2 +
 3 files changed, 104 insertions(+), 1 deletion(-)
net/mptcp/options.c +3 -1
index 2427fff98091..5e575999e281 100644
@@ -568,8 +568,10 @@ void update_una(struct mptcp_sock *msk, struct mptcp_options_received *mp_opt)
 		snd_una = old_snd_una;
 		old_snd_una = atomic64_cmpxchg(&msk->snd_una, snd_una,
 					       new_snd_una);
-		if (old_snd_una == snd_una)
+		if (old_snd_una == snd_una) {
+			mptcp_reset_timer((struct sock *)msk);
 			break;
+		}
 	}
 }
 
net/mptcp/protocol.c +99 -0

145 lines not on this page · raw message

net/mptcp/protocol.h +2 -0
index e09db0f85bfc..ef35d0aa8eb7 100644
@@ -129,6 +129,7 @@ struct mptcp_sock {
 	u64		write_seq;
 	u64		ack_seq;
 	atomic64_t	snd_una;
+	unsigned long	timer_ival;
 	u32		token;
 	unsigned long	flags;
 	u16		dport;
@@ -252,6 +253,7 @@ void mptcp_get_options(const struct sk_buff *skb,
 
 void mptcp_finish_connect(struct sock *sk, int mp_capable);
 void mptcp_finish_join(struct sock *sk);
+void mptcp_reset_timer(struct sock *sk);
 
 int mptcp_token_new_request(struct request_sock *req);
 void mptcp_token_destroy_request(u32 token);
Signature · 1 line
2.23.0
#53 lore raw

RFC PATCH v2 38/45 mptcp: implement memory accounting for mptcp rtx queue

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

Charge the data on the rtx queue to the master MPTCP socket, too. Such memory in uncharged when the data is acked/dequeued.

Also account mptcp sockets inuse via a protocol specific pcpu counter.

---
 net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +26 -3
index 1f7a090ed25c..8319ee807481 100644
@@ -19,6 +19,8 @@
 #include <net/mptcp.h>
 #include "protocol.h"
 
+static struct percpu_counter mptcp_sockets_allocated;
+
 static void mptcp_set_timeout(const struct sock *sk, const struct sock *ssk)
 {
 	unsigned long tout = ssk && inet_csk(ssk)->icsk_pending ?
@@ -112,9 +114,10 @@ static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
 		df->data_seq + df->data_len == msk->write_seq;
 }
 
-static void dfrag_clear(struct mptcp_data_frag *dfrag)
+static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
 {
 	list_del(&dfrag->list);
+	sk_mem_uncharge(sk, dfrag->data_len + dfrag->overhead);
 	put_page(dfrag->page);
 }
 
@@ -128,8 +131,9 @@ static void mptcp_clean_una(struct sock *sk)
 		if (after64(dfrag->data_seq + dfrag->data_len, snd_una))
 			break;
 
-		dfrag_clear(dfrag);
+		dfrag_clear(sk, dfrag);
 	}
+	sk_mem_reclaim_partial(sk);
 }
 
 /* ensure we get enough memory for the frag hdr, beyond some minimal amount of
@@ -236,6 +240,9 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	if (!psize)
 		return -EINVAL;
 
+	if (!sk_wmem_schedule(sk, psize + dfrag->overhead))
+		return -ENOMEM;
+
 	/* tell the TCP stack to delay the push so that we can safely
 	 * access the skb after the sendpages call
 	 */
@@ -257,6 +264,11 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		list_add_tail(&dfrag->list, &msk->rtx_queue);
 	}
 
+	/* charge data on mptcp rtx queue to the master socket
+	 * Note: we charge such data both to sk and ssk
+	 */
+	sk->sk_forward_alloc -= frag_truesize;
+
 	collapsed = skb == tcp_write_queue_tail(ssk);
 	if (collapsed) {
 		WARN_ON_ONCE(!can_collapse);
@@ -769,6 +781,8 @@ static int mptcp_init_sock(struct sock *sk)
 	if (ret)
 		return ret;
 
+	sk_sockets_allocated_inc(sk);
+
 	if (!mptcp_is_enabled(sock_net(sk)))
 		return -ENOPROTOOPT;
 
@@ -783,7 +797,7 @@ static void __mptcp_clear_xmit(struct sock *sk)
 	sk_stop_timer(sk, &msk->sk.icsk_retransmit_timer);
 
 	list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list)
-		dfrag_clear(dfrag);
+		dfrag_clear(sk, dfrag);
 }
 
 static void mptcp_close(struct sock *sk, long timeout)
@@ -902,6 +916,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
 
 static void mptcp_destroy(struct sock *sk)
 {
+	sk_sockets_allocated_dec(sk);
 }
 
 static int mptcp_setsockopt(struct sock *sk, int level, int optname,
@@ -1088,6 +1103,11 @@ static struct proto mptcp_prot = {
 	.hash		= inet_hash,
 	.unhash		= inet_unhash,
 	.get_port	= mptcp_get_port,
+	.sockets_allocated	= &mptcp_sockets_allocated,
+	.memory_allocated	= &tcp_memory_allocated,
+	.memory_pressure	= &tcp_memory_pressure,
+	.sysctl_wmem_offset	= offsetof(struct net, ipv4.sysctl_tcp_wmem),
+	.sysctl_mem	= sysctl_tcp_mem,
 	.obj_size	= sizeof(struct mptcp_sock),
 	.no_autobind	= 1,
 };
@@ -1324,6 +1344,9 @@ void mptcp_proto_init(void)
 	mptcp_stream_ops.listen = mptcp_listen;
 	mptcp_stream_ops.shutdown = mptcp_shutdown;
 
+	if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
+		panic("Failed to allocate MPTCP pcpu counter\n");
+
 	mptcp_subflow_init();
 	pm_init();
 
Signature · 1 line
2.23.0
#54 lore raw

RFC PATCH v2 39/45 mptcp: rework mptcp_sendmsg_frag to accept optional dfrag

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

This will simplify mptcp-level retransmission implementation in the next patch. If dfrag is provided by the caller, skip kernel space memory allocation and use data and metadata provided by the dfrag itself.

---
 net/mptcp/protocol.c | 133 +++++++++++++++++++++++++------------------
 1 file changed, 78 insertions(+), 55 deletions(-)
net/mptcp/protocol.c +78 -55
index 8319ee807481..6366dfd65aa8 100644
@@ -95,7 +95,7 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)
 	return NULL;
 }
 
-static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,
+static inline bool mptcp_skb_can_collapse_to(u64 write_seq,
 					     const struct sk_buff *skb,
 					     const struct mptcp_ext *mpext)
 {
@@ -103,7 +103,7 @@ static inline bool mptcp_skb_can_collapse_to(const struct mptcp_sock *msk,
 		return false;
 
 	/* can collapse only if MPTCP level sequence is in order */
-	return mpext && mpext->data_seq + mpext->data_len == msk->write_seq;
+	return mpext && mpext->data_seq + mpext->data_len == write_seq;
 }
 
 static inline bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
@@ -168,31 +168,44 @@ mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
 }
 
 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
-			      struct msghdr *msg, long *timeo, int *pmss_now,
+			      struct msghdr *msg, struct mptcp_data_frag *dfrag,
+			      long *timeo, int *pmss_now,
 			      int *ps_goal)
 {
 	int mss_now, avail_size, size_goal, offset, ret, frag_truesize = 0;
 	bool dfrag_collapsed, collapsed, can_collapse = false;
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct mptcp_ext *mpext = NULL;
-	struct mptcp_data_frag *dfrag;
+	bool retransmission = !!dfrag;
 	struct page_frag *pfrag;
 	struct sk_buff *skb;
+	struct page *page;
+	u64 *write_seq;
 	size_t psize;
+	int *poffset;
 
 	/* use the mptcp page cache so that we can easily move the data
 	 * from one substream to another, but do per subflow memory accounting
+	 * Note: pfrag is used only !retransmission, but the compiler if
+	 * fooled into a warning if we don't init here
 	 */
 	pfrag = sk_page_frag(sk);
-	while (!mptcp_page_frag_refill(ssk, pfrag)) {
-		ret = sk_stream_wait_memory(ssk, timeo);
-		if (ret)
-			return ret;
-
-		/* id sk_stream_wait_memory() sleeps snd_una can change
-		 * significantly, refresh the rtx queue
-		 */
-		mptcp_clean_una(sk);
+	if (!retransmission) {
+		while (!mptcp_page_frag_refill(ssk, pfrag)) {
+			ret = sk_stream_wait_memory(ssk, timeo);
+			if (ret)
+				return ret;
+
+			/* id sk_stream_wait_memory() sleeps snd_una can change
+			 * significantly, refresh the rtx queue
+			 */
+			mptcp_clean_una(sk);
+		}
+		write_seq = &msk->write_seq;
+		page = pfrag->page;
+	} else {
+		write_seq = &dfrag->data_seq;
+		page = dfrag->page;
 	}
 
 	/* compute copy limit */
@@ -211,63 +224,73 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		 * SSN association set here
 		 */
 		can_collapse = (size_goal - skb->len > 0) &&
-			      mptcp_skb_can_collapse_to(msk, skb, mpext);
+			      mptcp_skb_can_collapse_to(*write_seq, skb, mpext);
 		if (!can_collapse)
 			TCP_SKB_CB(skb)->eor = 1;
 		else
 			avail_size = size_goal - skb->len;
 	}
 
-	/* reuse tail pfrag, if possible, or carve a new one from the page
-	 * allocator
-	 */
-	dfrag = mptcp_rtx_tail(sk);
-	offset = pfrag->offset;
-	dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
-	if (!dfrag_collapsed) {
-		dfrag = mptcp_carve_data_frag(msk, pfrag, offset);
+	if (!retransmission) {
+		/* reuse tail pfrag, if possible, or carve a new one from the
+		 * page allocator
+		 */
+		dfrag = mptcp_rtx_tail(sk);
+		offset = pfrag->offset;
+		dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
+		if (!dfrag_collapsed) {
+			dfrag = mptcp_carve_data_frag(msk, pfrag, offset);
+			offset = dfrag->offset;
+			frag_truesize = dfrag->overhead;
+		}
+		poffset = &pfrag->offset;
+		psize = min_t(size_t, pfrag->size - offset, avail_size);
+
+		/* Copy to page */
+		pr_debug("left=%zu", msg_data_left(msg));
+		psize = copy_page_from_iter(pfrag->page, offset,
+					    min_t(size_t, msg_data_left(msg),
+						  psize),
+					    &msg->msg_iter);
+		pr_debug("left=%zu", msg_data_left(msg));
+		if (!psize)
+			return -EINVAL;
+
+		if (!sk_wmem_schedule(sk, psize + dfrag->overhead))
+			return -ENOMEM;
+	} else {
 		offset = dfrag->offset;
-		frag_truesize = dfrag->overhead;
+		poffset = &dfrag->offset;
+		psize = min_t(size_t, dfrag->data_len, avail_size);
 	}
-	psize = min_t(size_t, pfrag->size - offset, avail_size);
-
-	/* Copy to page */
-	pr_debug("left=%zu", msg_data_left(msg));
-	psize = copy_page_from_iter(pfrag->page, offset,
-				    min_t(size_t, msg_data_left(msg), psize),
-				    &msg->msg_iter);
-	pr_debug("left=%zu", msg_data_left(msg));
-	if (!psize)
-		return -EINVAL;
-
-	if (!sk_wmem_schedule(sk, psize + dfrag->overhead))
-		return -ENOMEM;
 
 	/* tell the TCP stack to delay the push so that we can safely
 	 * access the skb after the sendpages call
 	 */
-	ret = do_tcp_sendpages(ssk, pfrag->page, offset, psize,
+	ret = do_tcp_sendpages(ssk, page, offset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST);
 	if (ret <= 0)
 		return ret;
 
 	frag_truesize += ret;
-	if (unlikely(ret < psize))
-		iov_iter_revert(&msg->msg_iter, psize - ret);
+	if (!retransmission) {
+		if (unlikely(ret < psize))
+			iov_iter_revert(&msg->msg_iter, psize - ret);
 
-	/* send successful, keep track of sent data for mptcp-level
-	 * retransmission
-	 */
-	dfrag->data_len += ret;
-	if (!dfrag_collapsed) {
-		get_page(dfrag->page);
-		list_add_tail(&dfrag->list, &msk->rtx_queue);
-	}
+		/* send successful, keep track of sent data for mptcp-level
+		 * retransmission
+		 */
+		dfrag->data_len += ret;
+		if (!dfrag_collapsed) {
+			get_page(dfrag->page);
+			list_add_tail(&dfrag->list, &msk->rtx_queue);
+		}
 
-	/* charge data on mptcp rtx queue to the master socket
-	 * Note: we charge such data both to sk and ssk
-	 */
-	sk->sk_forward_alloc -= frag_truesize;
+		/* charge data on mptcp rtx queue to the master socket
+		 * Note: we charge such data both to sk and ssk
+		 */
+		sk->sk_forward_alloc -= frag_truesize;
+	}
 
 	collapsed = skb == tcp_write_queue_tail(ssk);
 	if (collapsed) {
@@ -281,7 +304,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
 	if (mpext) {
 		memset(mpext, 0, sizeof(*mpext));
-		mpext->data_seq = msk->write_seq;
+		mpext->data_seq = *write_seq;
 		mpext->subflow_seq = mptcp_subflow_ctx(ssk)->rel_write_seq;
 		mpext->data_len = ret;
 		mpext->checksum = 0xbeef;
@@ -297,8 +320,8 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	 */
 
 out:
-	pfrag->offset += frag_truesize;
-	msk->write_seq += ret;
+	*poffset += frag_truesize;
+	*write_seq += ret;
 	mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
 
 	return ret;
@@ -347,7 +370,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	mptcp_clean_una(sk);
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 	while (msg_data_left(msg)) {
-		ret = mptcp_sendmsg_frag(sk, ssk, msg, &timeo, &mss_now,
+		ret = mptcp_sendmsg_frag(sk, ssk, msg, NULL, &timeo, &mss_now,
 					 &size_goal);
 		if (ret < 0)
 			break;
Signature · 1 line
2.23.0
#55 lore raw

Re: [RFC PATCH v2 39/45] mptcp: rework mptcp_sendmsg_frag to accept optional dfrag

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Mat,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on net/master]
[cannot apply to v5.4-rc1 next-20191002]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mat-Martineau/Multipath-TCP/20191003-074736
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

net//mptcp/protocol.c: In function 'mptcp_sendmsg_frag':

>> net//mptcp/protocol.c:246:11: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
      poffset = &pfrag->offset;
              ^
   In file included from include/linux/kernel.h:15:0,
                    from net//mptcp/protocol.c:9:
   net//mptcp/protocol.c: In function 'mptcp_recvmsg':
   include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
    #define KERN_SOH "\001"  /* ASCII Start Of Header */
                     ^
   include/linux/printk.h:137:10: note: in definition of macro 'no_printk'
      printk(fmt, ##__VA_ARGS__);  \
             ^~~
   include/linux/kern_levels.h:15:20: note: in expansion of macro 'KERN_SOH'
    #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
                       ^~~~~~~~
   include/linux/printk.h:342:12: note: in expansion of macro 'KERN_DEBUG'
     no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
               ^~~~~~~~~~
   net//mptcp/protocol.c:687:4: note: in expansion of macro 'pr_debug'
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
       ^~~~~~~~
   net//mptcp/protocol.c:687:56: note: format string is defined here
       pr_debug("Dup data, map len=%d acked=%lld dropped=%ld",
                                                         ~~^
                                                         %d

cc1: some warnings being treated as errors

vim +246 net//mptcp/protocol.c

169
170 static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,

   171				      struct msghdr *msg, struct mptcp_data_frag *dfrag,
   172				      long *timeo, int *pmss_now,
   173				      int *ps_goal)
   174	{
   175		int mss_now, avail_size, size_goal, offset, ret, frag_truesize = 0;
   176		bool dfrag_collapsed, collapsed, can_collapse = false;
   177		struct mptcp_sock *msk = mptcp_sk(sk);
   178		struct mptcp_ext *mpext = NULL;
   179		bool retransmission = !!dfrag;
   180		struct page_frag *pfrag;
   181		struct sk_buff *skb;
   182		struct page *page;
   183		u64 *write_seq;
   184		size_t psize;
   185		int *poffset;
   186	
   187		/* use the mptcp page cache so that we can easily move the data
   188		 * from one substream to another, but do per subflow memory accounting
   189		 * Note: pfrag is used only !retransmission, but the compiler if
   190		 * fooled into a warning if we don't init here
   191		 */
   192		pfrag = sk_page_frag(sk);
   193		if (!retransmission) {
   194			while (!mptcp_page_frag_refill(ssk, pfrag)) {
   195				ret = sk_stream_wait_memory(ssk, timeo);
   196				if (ret)
   197					return ret;
   198	
   199				/* id sk_stream_wait_memory() sleeps snd_una can change
   200				 * significantly, refresh the rtx queue
   201				 */
   202				mptcp_clean_una(sk);
   203			}
   204			write_seq = &msk->write_seq;
   205			page = pfrag->page;
   206		} else {
   207			write_seq = &dfrag->data_seq;
   208			page = dfrag->page;
   209		}
   210	
   211		/* compute copy limit */
   212		mss_now = tcp_send_mss(ssk, &size_goal, msg->msg_flags);
   213		*pmss_now = mss_now;
   214		*ps_goal = size_goal;
   215		avail_size = size_goal;
   216		skb = tcp_write_queue_tail(ssk);
   217		if (skb) {
   218			mpext = skb_ext_find(skb, SKB_EXT_MPTCP);
   219	
   220			/* Limit the write to the size available in the
   221			 * current skb, if any, so that we create at most a new skb.
   222			 * Explicitly tells TCP internals to avoid collapsing on later
   223			 * queue management operation, to avoid breaking the ext <->
   224			 * SSN association set here
   225			 */
   226			can_collapse = (size_goal - skb->len > 0) &&
   227				      mptcp_skb_can_collapse_to(*write_seq, skb, mpext);
   228			if (!can_collapse)
   229				TCP_SKB_CB(skb)->eor = 1;
   230			else
   231				avail_size = size_goal - skb->len;
   232		}
   233	
   234		if (!retransmission) {
   235			/* reuse tail pfrag, if possible, or carve a new one from the
   236			 * page allocator
   237			 */
   238			dfrag = mptcp_rtx_tail(sk);
   239			offset = pfrag->offset;
   240			dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
   241			if (!dfrag_collapsed) {
   242				dfrag = mptcp_carve_data_frag(msk, pfrag, offset);
   243				offset = dfrag->offset;
   244				frag_truesize = dfrag->overhead;
   245			}
 > 246			poffset = &pfrag->offset;

247 psize = min_t(size_t, pfrag->size - offset, avail_size);
248
249 /* Copy to page */
250 pr_debug("left=%zu", msg_data_left(msg));
251 psize = copy_page_from_iter(pfrag->page, offset,
252 min_t(size_t, msg_data_left(msg),
253 psize),
254 &msg->msg_iter);
255 pr_debug("left=%zu", msg_data_left(msg));
256 if (!psize)
257 return -EINVAL;
258
259 if (!sk_wmem_schedule(sk, psize + dfrag->overhead))
260 return -ENOMEM;
261 } else {
262 offset = dfrag->offset;
263 poffset = &dfrag->offset;
264 psize = min_t(size_t, dfrag->data_len, avail_size);
265 }
266
267 /* tell the TCP stack to delay the push so that we can safely
268 * access the skb after the sendpages call
269 */
270 ret = do_tcp_sendpages(ssk, page, offset, psize,
271 msg->msg_flags | MSG_SENDPAGE_NOTLAST);
272 if (ret <= 0)
273 return ret;
274
275 frag_truesize += ret;
276 if (!retransmission) {
277 if (unlikely(ret < psize))
278 iov_iter_revert(&msg->msg_iter, psize - ret);
279
280 /* send successful, keep track of sent data for mptcp-level
281 * retransmission
282 */
283 dfrag->data_len += ret;
284 if (!dfrag_collapsed) {
285 get_page(dfrag->page);
286 list_add_tail(&dfrag->list, &msk->rtx_queue);
287 }
288
289 /* charge data on mptcp rtx queue to the master socket
290 * Note: we charge such data both to sk and ssk
291 */
292 sk->sk_forward_alloc -= frag_truesize;
293 }
294
295 collapsed = skb == tcp_write_queue_tail(ssk);
296 if (collapsed) {
297 WARN_ON_ONCE(!can_collapse);
298 /* when collapsing mpext always exists */
299 mpext->data_len += ret;
300 goto out;
301 }
302
303 skb = tcp_write_queue_tail(ssk);
304 mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
305 if (mpext) {
306 memset(mpext, 0, sizeof(*mpext));
307 mpext->data_seq = *write_seq;
308 mpext->subflow_seq = mptcp_subflow_ctx(ssk)->rel_write_seq;
309 mpext->data_len = ret;
310 mpext->checksum = 0xbeef;
311 mpext->use_map = 1;
312 mpext->dsn64 = 1;
313
314 pr_debug("data_seq=%llu subflow_seq=%u data_len=%u checksum=%u, dsn64=%d",
315 mpext->data_seq, mpext->subflow_seq, mpext->data_len,
316 mpext->checksum, mpext->dsn64);
317 }
318 /* TODO: else fallback; allocation can fail, but we can't easily retire
319 * skbs from the write_queue, as we need to roll-back TCP status
320 */
321
322 out:
323 *poffset += frag_truesize;
324 *write_seq += ret;
325 mptcp_subflow_ctx(ssk)->rel_write_seq += ret;
326
327 return ret;
328 }
329

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#56 lore raw

RFC PATCH v2 40/45 mptcp: implement and use MPTCP-level retransmission

In reply to Mat Martineau

From: Paolo Abeni <[email protected]>

On timeout event, schedule a work queue to do the retransmission. Retransmission code resemple closely sendmsg() implementation and re-uses mptcp_sendmsg_frag, providing a dummy msghdr - for flags' sake - and peeking the relevant dfrag from the rtx head.

---
 net/mptcp/protocol.c | 81 ++++++++++++++++++++++++++++++++++++++++++--
 net/mptcp/protocol.h | 11 ++++++
 2 files changed, 89 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +78 -3
index 6366dfd65aa8..b54fecf528b9 100644
@@ -759,10 +759,12 @@ static void mptcp_retransmit_handler(struct sock *sk)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 
-	if (atomic64_read(&msk->snd_una) == msk->write_seq)
+	if (atomic64_read(&msk->snd_una) == msk->write_seq) {
 		mptcp_stop_timer(sk);
-	else
-		mptcp_reset_timer(sk);
+	} else {
+		if (schedule_work(&msk->rtx_work))
+			sock_hold(sk);
+	}
 }
 
 static void mptcp_retransmit_timer(struct timer_list *t)
@@ -784,6 +786,66 @@ static void mptcp_retransmit_timer(struct timer_list *t)
 	sock_put(sk);
 }
 
+static void mptcp_retransmit(struct work_struct *work)
+{
+	int orig_len, orig_offset, ret, mss_now = 0, size_goal = 0;
+	struct mptcp_data_frag *dfrag;
+	struct sock *ssk, *sk;
+	struct mptcp_sock *msk;
+	u64 orig_write_seq;
+	size_t copied = 0;
+	struct msghdr msg;
+	long timeo = 0;
+
+	msk = container_of(work, struct mptcp_sock, rtx_work);
+	sk = &msk->sk.icsk_inet.sk;
+
+	lock_sock(sk);
+	mptcp_clean_una(sk);
+	dfrag = mptcp_rtx_head(sk);
+	if (!dfrag)
+		goto unlock;
+
+	ssk = mptcp_subflow_get_ref(msk);
+	if (!ssk)
+		goto reset_unlock;
+
+	lock_sock(ssk);
+
+	msg.msg_flags = MSG_DONTWAIT;
+	orig_len = dfrag->data_len;
+	orig_offset = dfrag->offset;
+	orig_write_seq = dfrag->data_seq;
+	while (dfrag->data_len > 0) {
+		ret = mptcp_sendmsg_frag(sk, ssk, &msg, dfrag, &timeo, &mss_now,
+					 &size_goal);
+		if (ret < 0)
+			break;
+
+		copied += ret;
+		dfrag->data_len -= ret;
+	}
+	if (copied)
+		tcp_push(ssk, msg.msg_flags, mss_now, tcp_sk(ssk)->nonagle,
+			 size_goal);
+
+	dfrag->data_seq = orig_write_seq;
+	dfrag->offset = orig_offset;
+	dfrag->data_len = orig_len;
+
+	mptcp_set_timeout(sk, ssk);
+	release_sock(ssk);
+	sock_put(ssk);
+
+reset_unlock:
+	if (!mptcp_timer_pending(sk))
+		mptcp_reset_timer(sk);
+
+unlock:
+	release_sock(sk);
+	sock_put(sk);
+}
+
 static int __mptcp_init_sock(struct sock *sk)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
@@ -791,6 +853,8 @@ static int __mptcp_init_sock(struct sock *sk)
 	INIT_LIST_HEAD(&msk->conn_list);
 	INIT_LIST_HEAD(&msk->rtx_queue);
 
+	INIT_WORK(&msk->rtx_work, mptcp_retransmit);
+
 	/* re-use the csk retrans timer for MPTCP-level retrans */
 	timer_setup(&msk->sk.icsk_retransmit_timer, mptcp_retransmit_timer, 0);
 
@@ -823,6 +887,14 @@ static void __mptcp_clear_xmit(struct sock *sk)
 		dfrag_clear(sk, dfrag);
 }
 
+static void mptcp_cancel_rtx_work(struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
+	if (cancel_work_sync(&msk->rtx_work))
+		sock_put(sk);
+}
+
 static void mptcp_close(struct sock *sk, long timeout)
 {
 	struct mptcp_subflow_context *subflow, *tmp;
@@ -852,6 +924,8 @@ static void mptcp_close(struct sock *sk, long timeout)
 	__mptcp_clear_xmit(sk);
 	release_sock(sk);
 
+	mptcp_cancel_rtx_work(sk);
+
 	sk_common_release(sk);
 }
 
@@ -860,6 +934,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
 	lock_sock(sk);
 	__mptcp_clear_xmit(sk);
 	release_sock(sk);
+	mptcp_cancel_rtx_work(sk);
 	return tcp_disconnect(sk, flags);
 }
 
net/mptcp/protocol.h +11 -0
index ef35d0aa8eb7..0c6bc8617cf4 100644
@@ -133,6 +133,7 @@ struct mptcp_sock {
 	u32		token;
 	unsigned long	flags;
 	u16		dport;
+	struct work_struct rtx_work;
 	struct list_head conn_list;
 	struct list_head rtx_queue;
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
@@ -158,6 +159,16 @@ static inline struct mptcp_data_frag *mptcp_rtx_tail(const struct sock *sk)
 	return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
 }
 
+static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
+	if (list_empty(&msk->rtx_queue))
+		return NULL;
+
+	return list_first_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
+}
+
 struct mptcp_subflow_request_sock {
 	struct	tcp_request_sock sk;
 	u8	mp_capable : 1,
Signature · 1 line
2.23.0
#57 lore raw

RFC PATCH v2 41/45 selftests: mptcp: make tc delays random

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

test with less predictable setups:
tc qdisc delay is now random, same for reordering and loss. Main motivation is to cover more scenarious without a large increase in test-time.

---
 .../selftests/net/mptcp/mptcp_connect.sh      | 28 +++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +26 -2
index d029bdc5946d..fb9bf9f4fc8b 100755
@@ -277,8 +277,32 @@ for sender in 1 2 3 4;do
 	do_ping ns4 ns$sender 10.0.3.1
 done
 
-tc -net ns2 qdisc add dev ns2eth3 root netem loss random 1
-tc -net ns3 qdisc add dev ns3eth4 root netem delay 10ms reorder 25% 50% gap 5
+loss=$((RANDOM%101))
+if [ $loss -eq 100 ] ;then
+	loss=1%
+	tc -net ns2 qdisc add dev ns2eth3 root netem loss random $loss
+elif [ $loss -ge 10 ]; then
+	loss=0.$loss%
+	tc -net ns2 qdisc add dev ns2eth3 root netem loss random $loss
+elif [ $loss -ge 1 ]; then
+	loss=0.0$loss%
+	tc -net ns2 qdisc add dev ns2eth3 root netem loss random $loss
+fi
+
+delay=$((RANDOM%1200))
+reorder1=$((RANDOM%25))
+reorder2=$((RANDOM%50))
+gap=$((RANDOM%100))
+if [ $gap -gt 0 ]; then
+	gap="gap $gap"
+else
+	gap=""
+fi
+
+if [ $reorder1 -gt 0 ] && [ $reorder2 -gt 0 ]; then
+  tc -net ns3 qdisc add dev ns3eth4 root netem delay ${delay}ms reorder ${reorder1}% ${reorder2}% $gap
+fi
+echo "INFO: Using loss of $loss, delay $delay ms, reorder: $reorder1, $reorder2 $gap on ns3eth4"
 
 for sender in 1 2 3 4;do
 	run_tests ns1 ns$sender 10.0.1.1
Signature · 1 line
2.23.0
#58 lore raw

RFC PATCH v2 42/45 selftests: mptcp: extend mptcp_connect tool for ipv6 family

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

At this time socket() will fail when requesting an ipv6 mptcp socket. This is ok for now, as the test script won't request ipv6 tests yet.

Tested with a tcp <-> tcp connection.

---
 .../testing/selftests/net/mptcp/mptcp_connect.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +12 -5
index cac71f0ac8f8..32a1630b7fa3 100644
@@ -32,11 +32,11 @@ static int  poll_timeout;
 static const char *cfg_host;
 static const char *cfg_port	= "12000";
 static int cfg_sock_proto	= IPPROTO_MPTCP;
-
+static int pf = AF_INET;
 
 static void die_usage(void)
 {
-	fprintf(stderr, "Usage: mptcp_connect [-s MPTCP|TCP] [-p port] "
+	fprintf(stderr, "Usage: mptcp_connect [ -6 ] [-s MPTCP|TCP] [-p port] "
 		"[ -l ] [ -t timeout ] connect_address\n");
 	exit(1);
 }
@@ -74,12 +74,13 @@ static int sock_listen_mptcp(const char * const listenaddr,
 		.ai_flags = AI_PASSIVE | AI_NUMERICHOST
 	};
 
-	hints.ai_family = AF_INET;
+	hints.ai_family = pf;
 
 	struct addrinfo *a, *addr;
 	int one = 1;
 
 	xgetaddrinfo(listenaddr, port, &hints, &addr);
+	hints.ai_family = pf;
 
 	for (a = addr; a; a = a->ai_next) {
 		sock = socket(a->ai_family, a->ai_socktype, cfg_sock_proto);
@@ -124,7 +125,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
 	struct addrinfo *a, *addr;
 	int sock = -1;
 
-	hints.ai_family = AF_INET;
+	hints.ai_family = pf;
 
 	xgetaddrinfo(remoteaddr, port, &hints, &addr);
 	for (a = addr; a; a = a->ai_next) {
@@ -362,7 +363,7 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "lp:s:ht:")) != -1) {
+	while ((c = getopt(argc, argv, "6lp:s:ht:")) != -1) {
 		switch (c) {
 		case 'l':
 			listen_mode = true;
@@ -376,6 +377,9 @@ static void parse_opts(int argc, char **argv)
 		case 'h':
 			die_usage();
 			break;
+		case '6':
+			pf = AF_INET6;
+			break;
 		case 't':
 			poll_timeout = atoi(optarg) * 1000;
 			if (poll_timeout <= 0)
@@ -387,6 +391,9 @@ static void parse_opts(int argc, char **argv)
 	if (optind + 1 != argc)
 		die_usage();
 	cfg_host = argv[optind];
+
+	if (strchr(cfg_host, ':'))
+		pf = AF_INET6;
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.23.0
#59 lore raw

RFC PATCH v2 43/45 selftests: mptcp: add accept/getpeer checks

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

Check that the result coming from accept matches that of getpeername. For initiator side, check getpeername matches address passed to connect().

At this time, kernel returns the address of the first subflow in the list. Right now, we do not yet implement fate-sharing, i.e. if the original subflow goes away, the result of getpeername would change.

There are different ways to fix that. One would be to copy the quadruple from the first subflow socket to the mptcp socket.

If we do that, this test should catch a possible bug (such as accidental reversal of saddr/daddr).

---
 .../selftests/net/mptcp/mptcp_connect.c       | 107 ++++++++++++++++++
 1 file changed, 107 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.c +107 -0
index 32a1630b7fa3..8df2b1b24695 100644
@@ -49,6 +49,21 @@ static const char *getxinfo_strerr(int err)
 	return gai_strerror(err);
 }
 
+static void xgetnameinfo(const struct sockaddr *addr, socklen_t addrlen,
+			 char *host, socklen_t hostlen,
+			 char *serv, socklen_t servlen)
+{
+	int flags = NI_NUMERICHOST | NI_NUMERICSERV;
+	int err = getnameinfo(addr, addrlen, host, hostlen, serv, servlen, flags);
+
+	if (err) {
+		const char *errstr = getxinfo_strerr(err);
+
+		fprintf(stderr, "Fatal: getnameinfo: %s\n", errstr);
+		exit(1);
+	}
+}
+
 static void xgetaddrinfo(const char *node, const char *service,
 			 const struct addrinfo *hints,
 			 struct addrinfo **res)
@@ -285,6 +300,94 @@ static int copyfd_io(int infd, int peerfd, int outfd)
 	return 0;
 }
 
+static void check_sockaddr(int pf, struct sockaddr_storage *ss,
+			   socklen_t salen)
+{
+	char addr[INET6_ADDRSTRLEN];
+	char serv[INET6_ADDRSTRLEN];
+	struct sockaddr_in6 *sin6;
+	struct sockaddr_in *sin;
+	int wanted_size = 0;
+
+	switch (pf) {
+	case AF_INET:
+		wanted_size = sizeof(*sin);
+		sin = (void *)ss;
+		if (!sin->sin_port)
+			fprintf(stderr, "accept: something wrong: ip connection from port 0");
+		break;
+	case AF_INET6:
+		wanted_size = sizeof(*sin6);
+		sin6 = (void *)ss;
+		if (!sin6->sin6_port)
+			fprintf(stderr, "accept: something wrong: ipv6 connection from port 0");
+		break;
+	default:
+		fprintf(stderr, "accept: Unknown pf %d, salen %u\n", pf, salen);
+		return;
+	}
+
+	if (salen != wanted_size)
+		fprintf(stderr, "accept: size mismatch, got %d expected %d\n",
+				(int)salen, wanted_size);
+
+	if (ss->ss_family != pf)
+		fprintf(stderr, "accept: pf mismatch, expect %d, ss_family is %d\n",
+				(int)ss->ss_family, pf);
+}
+
+static void check_getpeername(int fd, struct sockaddr_storage *ss, socklen_t salen)
+{
+	struct sockaddr_storage peerss;
+	socklen_t peersalen = sizeof(peerss);
+
+	if (getpeername(fd, (struct sockaddr *)&peerss, &peersalen)) {
+		perror("getpeername");
+		return;
+	}
+
+	if (peersalen != salen) {
+		fprintf(stderr, "%s: %d vs %d\n", __func__, peersalen, salen);
+		return;
+	}
+
+	if (memcmp(ss, &peerss, peersalen)) {
+		char a[INET6_ADDRSTRLEN];
+		char b[INET6_ADDRSTRLEN];
+		char c[INET6_ADDRSTRLEN];
+		char d[INET6_ADDRSTRLEN];
+
+		xgetnameinfo((struct sockaddr *)ss, salen,
+			     a, sizeof(a), b, sizeof(b));
+
+		xgetnameinfo((struct sockaddr *)&peerss, peersalen,
+			     c, sizeof(c), d, sizeof(d));
+
+		fprintf(stderr, "%s: memcmp failure: accept %s vs peername %s, %s vs %s salen %d vs %d\n",
+			__func__, a, c, b, d, peersalen, salen);
+	}
+}
+
+static void check_getpeername_connect(int fd)
+{
+	struct sockaddr_storage ss;
+	socklen_t salen = sizeof(ss);
+	char a[INET6_ADDRSTRLEN];
+	char b[INET6_ADDRSTRLEN];
+
+	if (!getpeername(fd, (struct sockaddr *)&ss, &salen)) {
+		perror("getpeername");
+		return;
+	}
+
+	xgetnameinfo((struct sockaddr *)&ss, salen,
+		     a, sizeof(a), b, sizeof(b));
+
+	if (strcmp(cfg_host, a) || strcmp(cfg_port, b))
+		fprintf(stderr, "%s: %s vs %s, %s vs %s\n", __func__,
+			cfg_host, a, cfg_port, b);
+}
+
 int main_loop_s(int listensock)
 {
 	struct sockaddr_storage ss;
@@ -308,6 +411,9 @@ int main_loop_s(int listensock)
 	salen = sizeof(ss);
 	remotesock = accept(listensock, (struct sockaddr *)&ss, &salen);
 	if (remotesock >= 0) {
+		check_sockaddr(pf, &ss, salen);
+		check_getpeername(remotesock, &ss, salen);
+
 		copyfd_io(0, remotesock, 1);
 		return 0;
 	}
@@ -342,6 +448,7 @@ int main_loop(void)
 	if (fd < 0)
 		return 2;
 
+	check_getpeername_connect(fd);
 	return copyfd_io(0, fd, 1);
 }
 
Signature · 1 line
2.23.0
#60 lore raw

RFC PATCH v2 44/45 selftests: mptcp: add ipv6 connectivity

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

prepare for ipv6 mptcp tests.
Once someone starts to implement mptcp v6 support, just set ipv6=true in the script and the selftest will attempt to connect via ipv6.

---
 .../selftests/net/mptcp/mptcp_connect.sh      | 77 ++++++++++++++++---
 1 file changed, 66 insertions(+), 11 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +66 -11
index fb9bf9f4fc8b..615691434a34 100755
@@ -9,6 +9,7 @@ cout=""
 ksft_skip=4
 capture=0
 timeout=30
+ipv6=false
 
 TEST_COUNT=0
 
@@ -58,29 +59,48 @@ ip link add ns2eth3 netns ns2 type veth peer name ns3eth2 netns ns3
 ip link add ns3eth4 netns ns3 type veth peer name ns4eth3 netns ns4
 
 ip -net ns1 addr add 10.0.1.1/24 dev ns1eth2
+if $ipv6 ; then
+	ip -net ns1 addr add dead:beef:1::1/64 dev ns1eth2
+	if [ $? -ne 0 ] ;then
+		echo "SKIP: Can't add ipv6 address, skip ipv6 tests" 1>&2
+		ipv6=false
+	fi
+fi
+
 ip -net ns1 link set ns1eth2 up
 ip -net ns1 route add default via 10.0.1.2
+$ipv6 && ip -net ns1 route add default via dead:beef:1::2
 
 ip -net ns2 addr add 10.0.1.2/24 dev ns2eth1
+$ipv6 && ip -net ns2 addr add dead:beef:1::2/64 dev ns2eth1
 ip -net ns2 link set ns2eth1 up
 
 ip -net ns2 addr add 10.0.2.1/24 dev ns2eth3
+$ipv6 && ip -net ns2 addr add dead:beef:2::1/64 dev ns2eth3
 ip -net ns2 link set ns2eth3 up
 ip -net ns2 route add default via 10.0.2.2
+$ipv6 && ip -net ns2 route add default via dead:beef:2::2
 ip netns exec ns2 sysctl -q net.ipv4.ip_forward=1
+$ipv6 && ip netns exec ns2 sysctl -q net.ipv6.conf.all.forwarding=1
 
 ip -net ns3 addr add 10.0.2.2/24 dev ns3eth2
+$ipv6 && ip -net ns3 addr add dead:beef:2::2/64 dev ns3eth2
 ip -net ns3 link set ns3eth2 up
 
 ip -net ns3 addr add 10.0.3.2/24 dev ns3eth4
+$ipv6 && ip -net ns3 addr add dead:beef:3::2/64 dev ns3eth4
 ip -net ns3 link set ns3eth4 up
 ip -net ns3 route add default via 10.0.2.1
+$ipv6 && ip -net ns3 route add default via dead:beef:2::1
 ip netns exec ns3 ethtool -K ns3eth2 tso off 2>/dev/null
 ip netns exec ns3 sysctl -q net.ipv4.ip_forward=1
+$ipv6 && ip netns exec ns3 sysctl -q net.ipv6.conf.all.forwarding=1
 
 ip -net ns4 addr add 10.0.3.1/24 dev ns4eth3
+$ipv6 && ip -net ns4 addr add dead:beef:3::1/64 dev ns4eth3
 ip -net ns4 link set ns4eth3 up
 ip -net ns4 route add default via 10.0.3.2
+$ipv6 && ip -net ns4 route add default via dead:beef:3::2
 
 print_file_err()
 {
@@ -138,7 +158,11 @@ do_ping()
 	if [ $? -ne 0 ] ; then
 		echo "$listener_ns -> $connect_addr connectivity [ FAIL ]" 1>&2
 		ret=1
+
+		return 1
 	fi
+
+	return 0
 }
 
 do_transfer()
@@ -148,6 +172,7 @@ do_transfer()
 	cl_proto="$3"
 	srv_proto="$4"
 	connect_addr="$5"
+	local_addr="$6"
 
 	port=$((10000+$TEST_COUNT))
 	TEST_COUNT=$((TEST_COUNT+1))
@@ -173,7 +198,7 @@ do_transfer()
 	    sleep 1
 	fi
 
-	ip netns exec ${listener_ns} ./mptcp_connect -t $timeout -l -p $port -s ${srv_proto} 0.0.0.0 < "$sin" > "$sout" &
+	ip netns exec ${listener_ns} ./mptcp_connect -t $timeout -l -p $port -s ${srv_proto} $local_addr < "$sin" > "$sout" &
 	spid=$!
 
 	sleep 1
@@ -241,23 +266,26 @@ run_tests()
 	listener_ns="$1"
 	connector_ns="$2"
 	connect_addr="$3"
+	local_addr="$4"
 	lret=0
 
 	for proto in MPTCP TCP;do
-		do_transfer ${listener_ns} ${connector_ns} MPTCP "$proto" ${connect_addr}
+		do_transfer ${listener_ns} ${connector_ns} MPTCP "$proto" ${connect_addr} ${local_addr}
 		lret=$?
 		if [ $lret -ne 0 ]; then
 			ret=$lret
-			return
+			return 1
 		fi
 	done
 
-	do_transfer ${listener_ns} ${connector_ns} TCP MPTCP ${connect_addr}
+	do_transfer ${listener_ns} ${connector_ns} TCP MPTCP ${connect_addr} ${local_addr}
 	lret=$?
 	if [ $lret -ne 0 ]; then
 		ret=$lret
-		return
+		return 1
 	fi
+
+	return 0
 }
 
 make_file "$cin" "client"
@@ -265,16 +293,31 @@ make_file "$sin" "server"
 
 check_mptcp_disabled
 
+# Allow DAD to finish
+$ipv6 && sleep 2
+
 for sender in 1 2 3 4;do
 	do_ping ns1 ns$sender 10.0.1.1
+	if $ipv6;then
+		do_ping ns1 ns$sender dead:beef:1::1
+		if [ $? -ne 0 ]; then
+			echo "SKIP: IPv6 tests" 2>&1
+			ipv6=false
+		fi
+	fi
 
 	do_ping ns2 ns$sender 10.0.1.2
+	$ipv6 && do_ping ns2 ns$sender dead:beef:1::2
 	do_ping ns2 ns$sender 10.0.2.1
+	$ipv6 && do_ping ns2 ns$sender dead:beef:2::1
 
 	do_ping ns3 ns$sender 10.0.2.2
+	$ipv6 && do_ping ns3 ns$sender dead:beef:2::2
 	do_ping ns3 ns$sender 10.0.3.2
+	$ipv6 && do_ping ns3 ns$sender dead:beef:3::2
 
 	do_ping ns4 ns$sender 10.0.3.1
+	$ipv6 && do_ping ns4 ns$sender dead:beef:3::1
 done
 
 loss=$((RANDOM%101))
@@ -305,15 +348,27 @@ fi
 echo "INFO: Using loss of $loss, delay $delay ms, reorder: $reorder1, $reorder2 $gap on ns3eth4"
 
 for sender in 1 2 3 4;do
-	run_tests ns1 ns$sender 10.0.1.1
+	run_tests ns1 ns$sender 10.0.1.1 0.0.0.0
+	if $ipv6;then
+		run_tests ns1 ns$sender dead:beef:1::1 ::
+		if [ $? -ne 0 ] ;then
+			echo "SKIP: IPv6 tests" 2>&1
+			ipv6=false
+		fi
+	fi
 
-	run_tests ns2 ns$sender 10.0.1.2
-	run_tests ns2 ns$sender 10.0.2.1
+	run_tests ns2 ns$sender 10.0.1.2 0.0.0.0
+	$ipv6 && run_tests ns2 ns$sender dead:beef:1::2 ::
+	run_tests ns2 ns$sender 10.0.2.1 0.0.0.0
+	$ipv6 && run_tests ns2 ns$sender dead:beef:2::1 ::
 
-	run_tests ns3 ns$sender 10.0.2.2
-	run_tests ns3 ns$sender 10.0.3.2
+	run_tests ns3 ns$sender 10.0.2.2 0.0.0.0
+	$ipv6 && run_tests ns3 ns$sender dead:beef:2::2 ::
+	run_tests ns3 ns$sender 10.0.3.2 0.0.0.0
+	$ipv6 && run_tests ns3 ns$sender dead:beef:3::2 ::
 
-	run_tests ns4 ns$sender 10.0.3.1
+	run_tests ns4 ns$sender 10.0.3.1 0.0.0.0
+	$ipv6 && run_tests ns4 ns$sender dead:beef:3::1 ::
 done
 
 exit $ret
Signature · 1 line
2.23.0
#61 lore raw

RFC PATCH v2 45/45 selftests: mptcp: random ethtool tweaking

In reply to Mat Martineau

From: Florian Westphal <[email protected]>

Instead of unconditionally disabling TSO in ns3, turn off any of gso/tso/gro in ns3 and/or ns4.

This gets us various combinations of GRO/GSO/TSO without a large impact on test time.

---
 .../selftests/net/mptcp/mptcp_connect.sh      | 29 ++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +28 -1
index 615691434a34..40cce8d1772e 100755
@@ -92,7 +92,6 @@ $ipv6 && ip -net ns3 addr add dead:beef:3::2/64 dev ns3eth4
 ip -net ns3 link set ns3eth4 up
 ip -net ns3 route add default via 10.0.2.1
 $ipv6 && ip -net ns3 route add default via dead:beef:2::1
-ip netns exec ns3 ethtool -K ns3eth2 tso off 2>/dev/null
 ip netns exec ns3 sysctl -q net.ipv4.ip_forward=1
 $ipv6 && ip netns exec ns3 sysctl -q net.ipv6.conf.all.forwarding=1
 
@@ -102,6 +101,34 @@ ip -net ns4 link set ns4eth3 up
 ip -net ns4 route add default via 10.0.3.2
 $ipv6 && ip -net ns4 route add default via dead:beef:3::2
 
+set_ethtool_flags() {
+	ns=$1
+	dev=$2
+
+	r=$RANDOM
+
+	pick1=$((r & 1))
+	r=$((r>>1))
+	pick2=$((r & 1))
+	r=$((r>>1))
+	pick3=$((r & 1))
+
+	comma=""
+	flags=""
+	[ $pick1 -ne 0 ] && flags="tso"
+	[ $pick1 -ne 0 ] && comma=","
+	[ $pick2 -ne 0 ] && flags=${flags}${comma}"gso"
+	[ $pick3 -ne 0 ] && flags=${flags}${comma}"gro"
+
+	[ -z $flags ] && return
+
+	ip netns exec $ns ethtool -K $dev $flags off 2>/dev/null
+	[ $? -eq 0 ] && echo "INFO: set $ns dev $dev: ethtool -K $flags off"
+}
+
+set_ethtool_flags ns3 ns3eth2
+set_ethtool_flags ns4 ns4eth3
+
 print_file_err()
 {
 	ls -l "$1" 1>&2
Signature · 1 line
2.23.0
#62 lore raw
In reply to Mat Martineau
Quoted 8 lines · Mat Martineau

The MPTCP upstreaming community has prepared a net-next RFCv2 patch set for review.

Clone/fetch:
https://github.com/multipath-tcp/mptcp_net-next.git (tag: netdev-rfcv2)

Browse:
https://github.com/multipath-tcp/mptcp_net-next/tree/netdev-rfcv2

Huge apologies everyone: while the branches referenced above are correct, the email patch series I just posted was not generated from the correct git commits.

Please disregard, I will send v3 shortly.

--
Mat Martineau
Intel

maintainer
#63 lore raw
In reply to Mat Martineau

From: Mat Martineau <[email protected]>
Date: Wed, 2 Oct 2019 16:36:10 -0700

Quoted 2 lines

The MPTCP upstreaming community has prepared a net-next RFCv2 patch set for review.

Nobody is going to read 45 patches and properly review them.

And I do mean nobody.

Please make smaller, more reasonable (like 12-20 MAX), patch sets to start building up the MPTCP infrastructure.

This is for your sake as well as everyone else's.

#64 lore raw
Quoted 6 lines · David Miller

From: Mat Martineau <[email protected]>
Date: Wed, 2 Oct 2019 16:36:10 -0700

Quoted 2 lines

The MPTCP upstreaming community has prepared a net-next RFCv2 patch set for review.

Quoted 8 lines

Nobody is going to read 45 patches and properly review them.

And I do mean nobody.

Please make smaller, more reasonable (like 12-20 MAX), patch sets to start building up the MPTCP infrastructure.

This is for your sake as well as everyone else's.

Thanks David.

We were proposing a shorter series for our later non-RFC posting, but will do some further squashing and partitioning to fit in the under 12-20 range for all future MPTCP patch sets posted on netdev.

And for my sake as well as everyone elses, I'll skip resending the correction to this series since it's only slightly shorter.

--
Mat Martineau
Intel