MPTCP architecture proposal for discussion
Subsystems (3)
Mat Martineau
v2 cover MPTCP architecture proposal for discussion
Hello everyone,
Peter and I have been working on this patch set to show how how MPTCP can fit in to the Linux networking stack using these design ideas:
* Applications opt-in to MPTCP using IPPROTO_MPTCP, regular TCP sockets are still the default. A socket created with socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP) will attempt to form a MPTCP connection. IPPROTO_MPTCP == 99 as a placeholder.
* Subflows exist within the kernel as separate sockets, owned by a MPTCP connection-level socket that is visible to userspace.
* Adds an optional area to struct sk_buff to store MPTCP metadata without increasing the size of normal sk_buffs.
* Adds the CONFIG_MPTCP option to Kconfig.
The following patches can form an MPTCP connection with the multipath-tcp.org kernel (tested with v0.94), and send DSS mappings that are accepted for the initial data packet. It is an early implementation, and I don't represent it as being upstreamable as-is or being everyone's idea of what an eventual upstream implementation will necessarily look like. It has significant limitations:
* Only one subflow is supported, no joins, and only ipv4.
* Does not support DSS checksums. Checksums must be disabled on the remote stack (for multipath-tcp.org, 'sudo sysctl -w net.mptcp.mptcp_checksum=0')
* Lots of debug statements (although they use dynamic debug and are disabled by default) and TODOs.
* It's only been tested sending small amounts of data, and will reject system calls attempting to write more data than can fit in one mapping.
Hopefully there are are some interesting concepts to discuss, and this code helps us assess how workable the above design principles are. Thanks in advance for your feedback on the benefits or drawbacks of this code, how it might be improved, or how other approaches might compare.
The patch set applies to net-next (as of commit 75d4e704fa8d on 2018-06-05). I have also pushed it to:
https://git.kernel.org/pub/scm/linux/kernel/git/martineau/linux.git
(mptcp-proposal branch)
v2 changes: Added receive path implementation (last two patches). Reworked TCP option writing. Miscellaneous bug fixes including header dependency cleanup.
Mat Martineau (8):
tcp: Add MPTCP option number
tcp: Define IPPROTO_MPTCP
skbuff: Add shared control buffer
tcp: Export low-level TCP functions
mptcp: More efficient byte order handling
mptcp: Write MPTCP DSS headers to outgoing data packets
mptcp: Disable TCP coalesce/collapse for MPTCP subflows
mptcp: Implement MPTCP receive path
Peter Krystad (11):
mptcp: Add MPTCP socket stubs
mptcp: Handle MPTCP TCP options
tcp: Add IPPROTO_SUBFLOW
tcp: expose tcp routines and structs for MPTCP
mptcp: Create SUBFLOW socket for outgoing connections
mptcp: Create SUBFLOW socket for incoming connections
mptcp: Add key generation and token tree
mptcp: Add getname() socket operation
mptcp: Add shutdown() socket operation
mptcp: Implement setsockopt()/getsockopt()
mptcp: Rework handling of the MPTCP sub-options
include/linux/skbuff.h | 24 +- include/linux/tcp.h | 26 ++ include/net/inet_common.h | 3 + include/net/mptcp.h | 188 ++++++++ include/net/tcp.h | 8 + include/uapi/linux/in.h | 4 + net/Kconfig | 1 + net/Makefile | 1 + net/core/skbuff.c | 53 ++- net/ipv4/af_inet.c | 2 +- net/ipv4/tcp.c | 12 +- net/ipv4/tcp_input.c | 26 +- net/ipv4/tcp_ipv4.c | 4 +- net/ipv4/tcp_output.c | 235 +++++++++- net/mptcp/Kconfig | 10 + net/mptcp/Makefile | 3 + net/mptcp/crypto.c | 209 +++++++++ net/mptcp/options.c | 230 ++++++++++ net/mptcp/protocol.c | 904 ++++++++++++++++++++++++++++++++++++++ net/mptcp/subflow.c | 374 ++++++++++++++++ net/mptcp/token.c | 222 ++++++++++ 21 files changed, 2501 insertions(+), 38 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/options.c create mode 100644 net/mptcp/protocol.c create mode 100644 net/mptcp/subflow.c create mode 100644 net/mptcp/token.c
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 1/19 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
@@ -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.17.1
Mat Martineau
RFC PATCH v2 2/19 tcp: Define IPPROTO_MPTCP
In reply to Mat MartineauTo 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/uapi/linux/in.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/in.h +2 -0
@@ -64,6 +64,8 @@ enum {#define IPPROTO_BEETPH IPPROTO_BEETPH IPPROTO_ENCAP = 98, /* Encapsulation Header */#define IPPROTO_ENCAP IPPROTO_ENCAP + IPPROTO_MPTCP = 99, /* Multipath TCP connection */ +#define IPPROTO_MPTCP IPPROTO_MPTCP IPPROTO_PIM = 103, /* Protocol Independent Multicast */#define IPPROTO_PIM IPPROTO_PIM IPPROTO_COMP = 108, /* Compression Header Protocol */
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 3/19 mptcp: Add MPTCP socket stubs
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
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 | 33 +++++++++++ net/Kconfig | 1 + net/Makefile | 1 + net/mptcp/Kconfig | 10 ++++ net/mptcp/Makefile | 3 + net/mptcp/protocol.c | 138 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 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
include/net/mptcp.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Multipath TCP +* +* Copyright (c) 2017, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#ifndef __NET_MPTCP_H +#define __NET_MPTCP_H + +#include <linux/tcp.h> + +/* MPTCP connection sock */ +struct mptcp_sock { +/* inet_connection_sock must be the first member */ +struct inet_connection_sock sk; +struct socket *subflow; +}; + +static inline struct mptcp_sock *mptcp_sk (const struct sock *sk) +{ +return (struct mptcp_sock *)sk; +} + +#endif /* __NET_MPTCP_H */
net/Kconfig +1 -0
@@ -89,6 +89,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
@@ -91,3 +91,4 @@ endif obj-$(CONFIG_QRTR) += qrtr/ obj-$(CONFIG_NET_NCSI) += ncsi/ obj-$(CONFIG_XDP_SOCKETS) += xdp/ +obj-$(CONFIG_MPTCP) += mptcp/
net/mptcp/Kconfig new file +10 -0
@@ -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 +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_MPTCP) += mptcp.o + +mptcp-y := protocol.o
net/mptcp/protocol.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 4/19 mptcp: Handle MPTCP TCP options
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
--- include/linux/tcp.h | 14 ++++ include/net/mptcp.h | 49 ++++++++++++ include/net/tcp.h | 2 + net/ipv4/tcp_input.c | 15 ++++ net/ipv4/tcp_output.c | 72 +++++++++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/options.c | 176 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/options.c
include/linux/tcp.h +14 -0
@@ -104,6 +104,16 @@ 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 */ +struct { +u8 mp_capable :1 , + mp_join :1 , + dss :1 , + version :4 ; +u8 flags; +u64 sndr_key; +u64 rcvr_key; + } mptcp; + };static inline void tcp_clear_options (struct tcp_options_received *rx_opt)
@@ -113,6 +123,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)#if IS_ENABLED (CONFIG_SMC ) rx_opt->smc_ok =0 ;#endif + rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join = rx_opt->mptcp.dss =0 ; }/* This is the max number of SACKS that we'll generate and process. It's safe
@@ -137,6 +148,7 @@ struct tcp_request_sock {* FastOpen it's the seq# * after data-in-SYN. */ +bool is_mptcp; };static inline struct tcp_request_sock *tcp_rsk (const struct request_sock *req)
@@ -387,6 +399,8 @@ struct tcp_sock {*/ struct request_sock *fastopen_rsk;u32 *saved_syn; + +bool is_mptcp; };enum tsq_enum {
include/net/mptcp.h +49 -0
59 lines not on this page · raw message
include/net/tcp.h +2 -0
@@ -214,6 +214,8 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);#define TCPOLEN_MD5SIG_ALIGNED 20#define TCPOLEN_MSS_ALIGNED 4#define TCPOLEN_EXP_SMC_BASE_ALIGNED 8 +#define TCPOLEN_MPTCP_MPC_SYN 12 +#define TCPOLEN_MPTCP_MPC_SYNACK 20/* Flags in tp->nonagle */ #define TCP_NAGLE_OFF 1/* Nagle's algo is disabled */
net/ipv4/tcp_input.c +15 -0
@@ -78,6 +78,7 @@#include <linux/errqueue.h> #include <trace/events/tcp.h> #include <linux/static_key.h> +#include <net/mptcp.h> int sysctl_tcp_max_orphans__read_mostly =NR_FILE ;
@@ -3842,6 +3843,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,
@@ -5763,6 +5768,15 @@ 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); +// @@ could use a callout here +if (tp->is_mptcp) { +struct subflow_sock *subflow =subflow_sk (sk); +if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) { + subflow->mp_capable =1 ; + subflow->remote_key = tp->rx_opt.mptcp.sndr_key; + } + } +/* Remember, tcp_poll() does not lock socket! * Change state from SYN-SENT only after copied_seq * is initialized. */
@@ -6339,6 +6353,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,tcp_rsk (req)->af_specific = af_ops;tcp_rsk (req)->ts_off =0 ; +tcp_rsk (req)->is_mptcp =0 ;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;
net/ipv4/tcp_output.c +72 -0
114 lines not on this page · raw message
net/mptcp/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o +mptcp-y := protocol.o options.o
net/mptcp/options.c new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
2.17.1
Christoph Paasch
Re: [MPTCP] [RFC PATCH v2 04/19] mptcp: Handle MPTCP TCP options
Quoted 21 lines · Mat Martineau
From: Peter Krystad <peter.krystad(a)intel.com>
Signed-off-by Peter Krystad <peter.krystad(a)intel.com>--- include/linux/tcp.h | 14 ++++ include/net/mptcp.h | 49 ++++++++++++ include/net/tcp.h | 2 + net/ipv4/tcp_input.c | 15 ++++ net/ipv4/tcp_output.c | 72 +++++++++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/options.c | 176 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/options.cinclude/linux/tcp.h +0
-0@@ -104,6 +104,16 @@ struct tcp_options_received {u8 num_sacks;/* Number of SACK blocks */ u16 user_mss;/* mss requested by user in ioctl */
include/linux/tcp.h struct tcp_options_received { · line 115
Quoted 10 lines
include/linux/tcp.h +9
-0u16 mss_clamp;/* Maximal mss, negotiated at connection setup */ +struct { +u8 mp_capable :1 , + mp_join :1 , + dss :1 , + version :4 ; +u8 flags; +u64 sndr_key; +u64 rcvr_key; + } mptcp;
Indentation looks wrong here.
Nit-picking ;-) (because I have a bigger comment further down below)
Quoted 266 lines
include/linux/tcp.h +5
-0+ };static inline void tcp_clear_options (struct tcp_options_received *rx_opt)@@ -113,6 +123,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)#if IS_ENABLED (CONFIG_SMC ) rx_opt->smc_ok =0 ;#endif + rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join = rx_opt->mptcp.dss =0 ; }/* This is the max number of SACKS that we'll generate and process. It's safe @@ -137,6 +148,7 @@ struct tcp_request_sock {* FastOpen it's the seq# * after data-in-SYN. */ +bool is_mptcp; };static inline struct tcp_request_sock *tcp_rsk (const struct request_sock *req)@@ -387,6 +399,8 @@ struct tcp_sock {*/ struct request_sock *fastopen_rsk;u32 *saved_syn; + +bool is_mptcp; };enum tsq_enum {include/net/mptcp.h +49
-0@@ -18,6 +18,23 @@#include <linux/tcp.h> +/* MPTCP option subtypes */ + +#define MPTCPOPT_MP_CAPABLE 0 +#define MPTCPOPT_MP_JOIN 1 +#define MPTCPOPT_DSS 2 +#define MPTCPOPT_ADD_ADDR 3 +#define MPTCPOPT_REMOVE_ADDR 4 +#define MPTCPOPT_MP_PRIO 5 +#define MPTCPOPT_MP_FAIL 6 +#define MPTCPOPT_MP_FASTCLOSE 7 + +/* MPTCP handshake flags */ + +#define MPTCP_CAP_CHECKSUM_REQD (1 << 7) +#define MPTCP_CAP_EXTENSIBILITY (1 << 6) +#define MPTCP_CAP_HMAC_SHA1 (1 << 0) +/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */ @@ -30,4 +47,36 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)return (struct mptcp_sock *)sk; } +#ifdef CONFIG_MPTCP + +void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx); +unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key); +unsigned int mptcp_synack_options (struct request_sock *req, +u64 *local_key,u64 *remote_key); + +void mptcp_get_options (const struct sk_buff *skb, +struct tcp_options_received *options); + +#else + +static inline void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx) +{ +} + +static inline unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key) +{ +return 0 ; +} +static inline unsigned int mptcp_synack_options (struct request_sock *sk, +u64 *local_key, +u64 *remote_key) +{ +return 0 ; +} + + + +#endif /* CONFIG_MPTCP */ #endif /* __NET_MPTCP_H */ include/net/tcp.h +2
-0@@ -214,6 +214,8 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);#define TCPOLEN_MD5SIG_ALIGNED 20#define TCPOLEN_MSS_ALIGNED 4#define TCPOLEN_EXP_SMC_BASE_ALIGNED 8 +#define TCPOLEN_MPTCP_MPC_SYN 12 +#define TCPOLEN_MPTCP_MPC_SYNACK 20/* Flags in tp->nonagle */ #define TCP_NAGLE_OFF 1/* Nagle's algo is disabled */ net/ipv4/tcp_input.c +15
-0@@ -78,6 +78,7 @@#include <linux/errqueue.h> #include <trace/events/tcp.h> #include <linux/static_key.h> +#include <net/mptcp.h> int sysctl_tcp_max_orphans__read_mostly =NR_FILE ;@@ -3842,6 +3843,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,@@ -5763,6 +5768,15 @@ 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); +// @@ could use a callout here +if (tp->is_mptcp) { +struct subflow_sock *subflow =subflow_sk (sk); +if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) { + subflow->mp_capable =1 ; + subflow->remote_key = tp->rx_opt.mptcp.sndr_key; + } + } +/* Remember, tcp_poll() does not lock socket! * Change state from SYN-SENT only after copied_seq * is initialized. */ @@ -6339,6 +6353,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,tcp_rsk (req)->af_specific = af_ops;tcp_rsk (req)->ts_off =0 ; +tcp_rsk (req)->is_mptcp =0 ;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;net/ipv4/tcp_output.c +62
-0@@ -37,6 +37,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,8 @@ 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) +#define OPTION_MPTCP_ACK (1 << 11)static void smc_options_write (__be32 *ptr,u16 *options) {@@ -436,6 +439,8 @@ 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 */ +u64 sndr_key; +u64 rcvr_key; };/* Write previously computed TCP options to the packet. @@ -546,6 +551,29 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp, }smc_options_write (ptr, &options); + +if (OPTION_MPTCP & options) { +u8 *p = (u8 *)ptr; + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ =12 ;// length + *p++ =0 ;// subtype=MP_CAPABLE | version=0 + *p++ =0x1 ;// flags=HMAC-SHA1 +memcpy (p, &opts->sndr_key,8 ); +pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); + } + +if (OPTION_MPTCP_ACK & options) { +u8 *p = (u8 *)ptr; + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ =20 ;// length + *p++ =0 ;// subtype=MP_CAPABLE | version=0 + *p++ =0x1 ;// flags=HMAC-SHA1 +memcpy (p, &opts->sndr_key,8 ); +pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); + p +=8 ; +memcpy (p, &opts->rcvr_key,8 ); +pr_debug ("tcp_options_write: opts->rcvr_key=%llu" , opts->rcvr_key); + } } static void smc_set_option(const struct tcp_sock *tp,@@ -649,6 +677,15 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,smc_set_option (tp, opts, &remaining); +if (tp->is_mptcp) { +u64 local_key; +if (mptcp_syn_options (sk, &local_key)) { + opts->options |=OPTION_MPTCP ; + opts->sndr_key = local_key; + remaining -=TCPOLEN_MPTCP_MPC_SYN ; + } + } +return MAX_TCP_OPTION_SPACE - remaining; }@@ -709,6 +746,18 @@ static unsigned int tcp_synack_options(const struct sock *sk, remaining -= need; } } +if (tcp_rsk (req)->is_mptcp) { +u64 local_key; +u64 remote_key; +if (mptcp_synack_options (req, &local_key, &remote_key)) { +if (remaining >=TCPOLEN_MPTCP_MPC_SYNACK ) { + opts->options |=OPTION_MPTCP_ACK ; + opts->sndr_key = local_key; + opts->rcvr_key = remote_key; + remaining -=TCPOLEN_MPTCP_MPC_SYNACK ; + } + } + }smc_set_option_cond (tcp_sk (sk), ireq, opts, &remaining);@@ -757,6 +806,29 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb opts->num_sack_blocks *TCPOLEN_SACK_PERBLOCK ; } +if (tp->is_mptcp) { +struct subflow_sock *subflow =subflow_sk (sk); +pr_debug ("tcp_established_options: subflow=%p" , subflow); +if (subflow->mp_capable) { +const unsigned int remaining =MAX_TCP_OPTION_SPACE - size; +pr_debug ("tcp_established_options: remaining=%d" , remaining); +if (!subflow->fourth_ack) { +pr_debug ("tcp_established_options: OPTION_MPTCP_ACK" ); +if (remaining >=20 ) { + opts->options |=OPTION_MPTCP_ACK ; + opts->sndr_key = subflow->local_key; + opts->rcvr_key = subflow->remote_key; + size +=20 ;
net/ipv4/tcp_output.c static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb · line 831
Quoted 10 lines
net/ipv4/tcp_output.c +10
-0+ } + subflow->fourth_ack =1 ; +// @@ also this is where first DSS goes in? + } +else { +pr_debug ("tcp_established_options: OPTION_MPTCP_DSS" ); +// @@ send DSS based on remaining + } + } + }
You would need to have this code before the SACK-code. Because otherwise SACK might fill up the available space and you will end up not writing the DSS-option.
This also implies that you need to check whether at all there is space for a SACK-block.
Christoph
Quoted 201 lines
net/ipv4/tcp_output.c +0
-0return size; }net/mptcp/Makefile +1
-1@@ -1,3 +1,3 @@ obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o +mptcp-y := protocol.o options.onet/mptcp/options.c new file +176
-0@@ -0,0 +1,176 @@ +/* +* Multipath TCP +* +* Copyright (c) 2017, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#include <linux/kernel.h> +#include <net/tcp.h> +#include <net/mptcp.h> + +void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx) +{ +u8 subtype; +u64 *p; + + opsize -=2 ; + subtype = *ptr++; + +/* MPTCPOPT_MP_CAPABLE +* 0: 4MSB=subtype, 4LSB=version +* 1: Handshake flags +* 2-9: Sender key +* 10-17: Receiver key (optional) +*/ +switch (subtype &0xF0 ) { +case 0x00 : +pr_debug ("MP_CAPABLE" ); +pr_debug ("flags=%02x" , *ptr); + opt_rx->mptcp.mp_capable =1 ; + opt_rx->mptcp.version = subtype &0x0F ; + opt_rx->mptcp.flags = *ptr++; + p = (u64 *)ptr; +pr_debug ("sndr_key=%llu" , *p); + opt_rx->mptcp.sndr_key = *p++; +if (opsize >10 ) { +pr_debug ("rcvr_key=%llu" , *p); + opt_rx->mptcp.rcvr_key = *p++; + } +break ; + +/* MPTCPOPT_MP_JOIN +* +* Initial SYN +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID +* 2-5: Receiver token +* 6-9: Sender random number +* +* SYN/ACK response +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID +* 2-9: Sender truncated HMAC +* 10-13: Sender random number +* +* Third ACK +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-21: Sender HMAC +*/ + +/* MPTCPOPT_DSS +* 0: 4MSB=subtype, 0000 +* 1: 3MSB=0, F=Data FIN, m=DSN length, M=has DSN/SSN/DLL/checksum, +* a=DACK length, A=has DACK +* 0, 4, or 8 bytes of DACK (depending on A/a) +* 0, 4, or 8 bytes of DSN (depending on M/m) +* 0 or 4 bytes of SSN (depending on M) +* 0 or 2 bytes of DLL (depending on M) +* 0 or 2 bytes of checksum (depending on M) +*/ +case 0x20 : +pr_debug ("DSS" ); + opt_rx->mptcp.dss =1 ; +break ; + +/* MPTCPOPT_ADD_ADDR +* 0: 4MSB=subtype, 4LSB=IP version (4 or 6) +* 1: Address ID +* 4 or 16 bytes of address (depending on ip version) +* 0 or 2 bytes of port (depending on length) +*/ + +/* MPTCPOPT_REMOVE_ADDR +* 0: 4MSB=subtype, 0000 +* 1: Address ID +* Additional bytes: More address IDs (depending on length) +*/ + +/* MPTCPOPT_MP_PRIO +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID (optional, current addr implied if not present) +*/ + +/* MPTCPOPT_MP_FAIL +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-9: DSN +*/ + +/* MPTCPOPT_MP_FASTCLOSE +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-9: Receiver key +*/ +default : +break ; + } +} + +void mptcp_get_options (const struct sk_buff *skb, +struct tcp_options_received *opt_rx) +{ +const unsigned char *ptr; +const struct tcphdr *th =tcp_hdr (skb); +int length = (th->doff *4 ) -sizeof (struct tcphdr ); + + ptr = (const unsigned char *)(th +1 ); + +while (length >0 ) { +int opcode = *ptr++; +int opsize; + +switch (opcode) { +case TCPOPT_EOL : +return ; +case TCPOPT_NOP :/* Ref: RFC 793 section 3.1 */ + length--; +continue ; +default : + opsize = *ptr++; +if (opsize <2 )/* "silly options" */ +return ; +if (opsize > length) +return ;/* don't parse partial options */ +if (opcode ==TCPOPT_MPTCP ) +mptcp_parse_option (ptr, opsize, opt_rx); + ptr += opsize -2 ; + length -= opsize; + } + } +} + +unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key) +{ +struct subflow_sock *subflow =subflow_sk (sk); + +if (subflow->request_mptcp) { +pr_debug ("local_key=%llu" , subflow->local_key); + *local_key = subflow->local_key; + } +return subflow->request_mptcp; +} + +unsigned int mptcp_synack_options (struct request_sock *req,u64 *local_key, +u64 *remote_key) +{ +struct subflow_request_sock *subflow_req =subflow_rsk (req); + +if (subflow_req->mp_capable) { + *local_key = subflow_req->local_key; + *remote_key = subflow_req->remote_key; +pr_debug ("local_key=%llu" , *local_key); +pr_debug ("remote_key=%llu" , *remote_key); + } +return subflow_req->mp_capable; +}Signature · 6 lines
2.17.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
Krystad
Re: [MPTCP] [RFC PATCH v2 04/19] mptcp: Handle MPTCP TCP options
Hi Christoph -
Quoted 318 lines · Christoph Paasch
Quoted 21 lines · Mat Martineau
From: Peter Krystad <peter.krystad(a)intel.com>
Signed-off-by Peter Krystad <peter.krystad(a)intel.com>--- include/linux/tcp.h | 14 ++++ include/net/mptcp.h | 49 ++++++++++++ include/net/tcp.h | 2 + net/ipv4/tcp_input.c | 15 ++++ net/ipv4/tcp_output.c | 72 +++++++++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/options.c | 176 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/options.cinclude/linux/tcp.h +0
-0@@ -104,6 +104,16 @@ struct tcp_options_received {u8 num_sacks;/* Number of SACK blocks */ u16 user_mss;/* mss requested by user in ioctl */ include/linux/tcp.h struct tcp_options_received { · line 115
Quoted 10 lines
include/linux/tcp.h +9
-0u16 mss_clamp;/* Maximal mss, negotiated at connection setup */ +struct { +u8 mp_capable :1 , + mp_join :1 , + dss :1 , + version :4 ; +u8 flags; +u64 sndr_key; +u64 rcvr_key; + } mptcp;Indentation looks wrong here.
Nit-picking ;-) (because I have a bigger comment further down below)
Quoted 266 lines
include/linux/tcp.h +5
-0+ };static inline void tcp_clear_options (struct tcp_options_received *rx_opt)@@ -113,6 +123,7 @@ static inline void tcp_clear_options(struct tcp_options_received *rx_opt)#if IS_ENABLED (CONFIG_SMC ) rx_opt->smc_ok =0 ;#endif + rx_opt->mptcp.mp_capable = rx_opt->mptcp.mp_join = rx_opt->mptcp.dss =0 ; }/* This is the max number of SACKS that we'll generate and process. It's safe @@ -137,6 +148,7 @@ struct tcp_request_sock {* FastOpen it's the seq# * after data-in-SYN. */ +bool is_mptcp; };static inline struct tcp_request_sock *tcp_rsk (const struct request_sock *req)@@ -387,6 +399,8 @@ struct tcp_sock {*/ struct request_sock *fastopen_rsk;u32 *saved_syn; + +bool is_mptcp; };enum tsq_enum {include/net/mptcp.h +49
-0@@ -18,6 +18,23 @@#include <linux/tcp.h> +/* MPTCP option subtypes */ + +#define MPTCPOPT_MP_CAPABLE 0 +#define MPTCPOPT_MP_JOIN 1 +#define MPTCPOPT_DSS 2 +#define MPTCPOPT_ADD_ADDR 3 +#define MPTCPOPT_REMOVE_ADDR 4 +#define MPTCPOPT_MP_PRIO 5 +#define MPTCPOPT_MP_FAIL 6 +#define MPTCPOPT_MP_FASTCLOSE 7 + +/* MPTCP handshake flags */ + +#define MPTCP_CAP_CHECKSUM_REQD (1 << 7) +#define MPTCP_CAP_EXTENSIBILITY (1 << 6) +#define MPTCP_CAP_HMAC_SHA1 (1 << 0) +/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */ @@ -30,4 +47,36 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)return (struct mptcp_sock *)sk; } +#ifdef CONFIG_MPTCP + +void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx); +unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key); +unsigned int mptcp_synack_options (struct request_sock *req, +u64 *local_key,u64 *remote_key); + +void mptcp_get_options (const struct sk_buff *skb, +struct tcp_options_received *options); + +#else + +static inline void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx) +{ +} + +static inline unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key) +{ +return 0 ; +} +static inline unsigned int mptcp_synack_options (struct request_sock *sk, +u64 *local_key, +u64 *remote_key) +{ +return 0 ; +} + + + +#endif /* CONFIG_MPTCP */ #endif /* __NET_MPTCP_H */ include/net/tcp.h +2
-0@@ -214,6 +214,8 @@ void tcp_time_wait(struct sock *sk, int state, int timeo);#define TCPOLEN_MD5SIG_ALIGNED 20#define TCPOLEN_MSS_ALIGNED 4#define TCPOLEN_EXP_SMC_BASE_ALIGNED 8 +#define TCPOLEN_MPTCP_MPC_SYN 12 +#define TCPOLEN_MPTCP_MPC_SYNACK 20/* Flags in tp->nonagle */ #define TCP_NAGLE_OFF 1/* Nagle's algo is disabled */ net/ipv4/tcp_input.c +15
-0@@ -78,6 +78,7 @@#include <linux/errqueue.h> #include <trace/events/tcp.h> #include <linux/static_key.h> +#include <net/mptcp.h> int sysctl_tcp_max_orphans__read_mostly =NR_FILE ;@@ -3842,6 +3843,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,@@ -5763,6 +5768,15 @@ 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); +// @@ could use a callout here +if (tp->is_mptcp) { +struct subflow_sock *subflow =subflow_sk (sk); +if (subflow->request_mptcp && tp->rx_opt.mptcp.mp_capable) { + subflow->mp_capable =1 ; + subflow->remote_key = tp->rx_opt.mptcp.sndr_key; + } + } +/* Remember, tcp_poll() does not lock socket! * Change state from SYN-SENT only after copied_seq * is initialized. */ @@ -6339,6 +6353,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,tcp_rsk (req)->af_specific = af_ops;tcp_rsk (req)->ts_off =0 ; +tcp_rsk (req)->is_mptcp =0 ;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;net/ipv4/tcp_output.c +62
-0@@ -37,6 +37,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,8 @@ 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) +#define OPTION_MPTCP_ACK (1 << 11)static void smc_options_write (__be32 *ptr,u16 *options) {@@ -436,6 +439,8 @@ 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 */ +u64 sndr_key; +u64 rcvr_key; };/* Write previously computed TCP options to the packet. @@ -546,6 +551,29 @@ static void tcp_options_write(__be32 *ptr, struct tcp_sock *tp, }smc_options_write (ptr, &options); + +if (OPTION_MPTCP & options) { +u8 *p = (u8 *)ptr; + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ =12 ;// length + *p++ =0 ;// subtype=MP_CAPABLE | version=0 + *p++ =0x1 ;// flags=HMAC-SHA1 +memcpy (p, &opts->sndr_key,8 ); +pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); + } + +if (OPTION_MPTCP_ACK & options) { +u8 *p = (u8 *)ptr; + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ =20 ;// length + *p++ =0 ;// subtype=MP_CAPABLE | version=0 + *p++ =0x1 ;// flags=HMAC-SHA1 +memcpy (p, &opts->sndr_key,8 ); +pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); + p +=8 ; +memcpy (p, &opts->rcvr_key,8 ); +pr_debug ("tcp_options_write: opts->rcvr_key=%llu" , opts->rcvr_key); + } } static void smc_set_option(const struct tcp_sock *tp,@@ -649,6 +677,15 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,smc_set_option (tp, opts, &remaining); +if (tp->is_mptcp) { +u64 local_key; +if (mptcp_syn_options (sk, &local_key)) { + opts->options |=OPTION_MPTCP ; + opts->sndr_key = local_key; + remaining -=TCPOLEN_MPTCP_MPC_SYN ; + } + } +return MAX_TCP_OPTION_SPACE - remaining; }@@ -709,6 +746,18 @@ static unsigned int tcp_synack_options(const struct sock *sk, remaining -= need; } } +if (tcp_rsk (req)->is_mptcp) { +u64 local_key; +u64 remote_key; +if (mptcp_synack_options (req, &local_key, &remote_key)) { +if (remaining >=TCPOLEN_MPTCP_MPC_SYNACK ) { + opts->options |=OPTION_MPTCP_ACK ; + opts->sndr_key = local_key; + opts->rcvr_key = remote_key; + remaining -=TCPOLEN_MPTCP_MPC_SYNACK ; + } + } + }smc_set_option_cond (tcp_sk (sk), ireq, opts, &remaining);@@ -757,6 +806,29 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb opts->num_sack_blocks *TCPOLEN_SACK_PERBLOCK ; } +if (tp->is_mptcp) { +struct subflow_sock *subflow =subflow_sk (sk); +pr_debug ("tcp_established_options: subflow=%p" , subflow); +if (subflow->mp_capable) { +const unsigned int remaining =MAX_TCP_OPTION_SPACE - size; +pr_debug ("tcp_established_options: remaining=%d" , remaining); +if (!subflow->fourth_ack) { +pr_debug ("tcp_established_options: OPTION_MPTCP_ACK" ); +if (remaining >=20 ) { + opts->options |=OPTION_MPTCP_ACK ; + opts->sndr_key = subflow->local_key; + opts->rcvr_key = subflow->remote_key; + size +=20 ;net/ipv4/tcp_output.c static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb · line 831
Quoted 10 lines
net/ipv4/tcp_output.c +10
-0+ } + subflow->fourth_ack =1 ; +// @@ also this is where first DSS goes in? + } +else { +pr_debug ("tcp_established_options: OPTION_MPTCP_DSS" ); +// @@ send DSS based on remaining + } + } + }You would need to have this code before the SACK-code. Because otherwise SACK might fill up the available space and you will end up not writing the DSS-option.
Quoted 3 lines
This also implies that you need to check whether at all there is space for a SACK-block.
This is addressed in patch 16 of this set. I'll clean up the indenting.
Peter.
Quoted 208 lines
Christoph
Quoted 201 lines
net/ipv4/tcp_output.c +0
-0return size; }net/mptcp/Makefile +1
-1@@ -1,3 +1,3 @@ obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o +mptcp-y := protocol.o options.onet/mptcp/options.c new file +176
-0@@ -0,0 +1,176 @@ +/* +* Multipath TCP +* +* Copyright (c) 2017, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#include <linux/kernel.h> +#include <net/tcp.h> +#include <net/mptcp.h> + +void mptcp_parse_option (const unsigned char *ptr,int opsize, +struct tcp_options_received *opt_rx) +{ +u8 subtype; +u64 *p; + + opsize -=2 ; + subtype = *ptr++; + +/* MPTCPOPT_MP_CAPABLE +* 0: 4MSB=subtype, 4LSB=version +* 1: Handshake flags +* 2-9: Sender key +* 10-17: Receiver key (optional) +*/ +switch (subtype &0xF0 ) { +case 0x00 : +pr_debug ("MP_CAPABLE" ); +pr_debug ("flags=%02x" , *ptr); + opt_rx->mptcp.mp_capable =1 ; + opt_rx->mptcp.version = subtype &0x0F ; + opt_rx->mptcp.flags = *ptr++; + p = (u64 *)ptr; +pr_debug ("sndr_key=%llu" , *p); + opt_rx->mptcp.sndr_key = *p++; +if (opsize >10 ) { +pr_debug ("rcvr_key=%llu" , *p); + opt_rx->mptcp.rcvr_key = *p++; + } +break ; + +/* MPTCPOPT_MP_JOIN +* +* Initial SYN +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID +* 2-5: Receiver token +* 6-9: Sender random number +* +* SYN/ACK response +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID +* 2-9: Sender truncated HMAC +* 10-13: Sender random number +* +* Third ACK +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-21: Sender HMAC +*/ + +/* MPTCPOPT_DSS +* 0: 4MSB=subtype, 0000 +* 1: 3MSB=0, F=Data FIN, m=DSN length, M=has DSN/SSN/DLL/checksum, +* a=DACK length, A=has DACK +* 0, 4, or 8 bytes of DACK (depending on A/a) +* 0, 4, or 8 bytes of DSN (depending on M/m) +* 0 or 4 bytes of SSN (depending on M) +* 0 or 2 bytes of DLL (depending on M) +* 0 or 2 bytes of checksum (depending on M) +*/ +case 0x20 : +pr_debug ("DSS" ); + opt_rx->mptcp.dss =1 ; +break ; + +/* MPTCPOPT_ADD_ADDR +* 0: 4MSB=subtype, 4LSB=IP version (4 or 6) +* 1: Address ID +* 4 or 16 bytes of address (depending on ip version) +* 0 or 2 bytes of port (depending on length) +*/ + +/* MPTCPOPT_REMOVE_ADDR +* 0: 4MSB=subtype, 0000 +* 1: Address ID +* Additional bytes: More address IDs (depending on length) +*/ + +/* MPTCPOPT_MP_PRIO +* 0: 4MSB=subtype, 000, 1LSB=Backup +* 1: Address ID (optional, current addr implied if not present) +*/ + +/* MPTCPOPT_MP_FAIL +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-9: DSN +*/ + +/* MPTCPOPT_MP_FASTCLOSE +* 0: 4MSB=subtype, 0000 +* 1: 0 (Reserved) +* 2-9: Receiver key +*/ +default : +break ; + } +} + +void mptcp_get_options (const struct sk_buff *skb, +struct tcp_options_received *opt_rx) +{ +const unsigned char *ptr; +const struct tcphdr *th =tcp_hdr (skb); +int length = (th->doff *4 ) -sizeof (struct tcphdr ); + + ptr = (const unsigned char *)(th +1 ); + +while (length >0 ) { +int opcode = *ptr++; +int opsize; + +switch (opcode) { +case TCPOPT_EOL : +return ; +case TCPOPT_NOP :/* Ref: RFC 793 section 3.1 */ + length--; +continue ; +default : + opsize = *ptr++; +if (opsize <2 )/* "silly options" */ +return ; +if (opsize > length) +return ;/* don't parse partial options */ +if (opcode ==TCPOPT_MPTCP ) +mptcp_parse_option (ptr, opsize, opt_rx); + ptr += opsize -2 ; + length -= opsize; + } + } +} + +unsigned int mptcp_syn_options (struct sock *sk,u64 *local_key) +{ +struct subflow_sock *subflow =subflow_sk (sk); + +if (subflow->request_mptcp) { +pr_debug ("local_key=%llu" , subflow->local_key); + *local_key = subflow->local_key; + } +return subflow->request_mptcp; +} + +unsigned int mptcp_synack_options (struct request_sock *req,u64 *local_key, +u64 *remote_key) +{ +struct subflow_request_sock *subflow_req =subflow_rsk (req); + +if (subflow_req->mp_capable) { + *local_key = subflow_req->local_key; + *remote_key = subflow_req->remote_key; +pr_debug ("local_key=%llu" , *local_key); +pr_debug ("remote_key=%llu" , *remote_key); + } +return subflow_req->mp_capable; +}Signature · 6 lines
2.17.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
Mat Martineau
RFC PATCH v2 5/19 tcp: Add IPPROTO_SUBFLOW
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
IANA protocol numbers fit in a single byte, however the protocol field of struct inet_protosw is an unsigned short so defining IPPROTO_SUBFLOW as a 16-bit value greater than 0xFF with the same LSB as IPPROTO_TCP is convenient for registering a unique protocol with inet_register_protosw() that still transmits packets with IPPROTO_TCP as the protocol number.
--- include/uapi/linux/in.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/in.h +2 -0
@@ -78,6 +78,8 @@ enum {#define IPPROTO_MPLS IPPROTO_MPLS IPPROTO_RAW = 255, /* Raw IP packets */#define IPPROTO_RAW IPPROTO_RAW + IPPROTO_SUBFLOW = 262, /* Multipath TCP (IPPROTO_TCP | 0x100) */ +#define IPPROTO_SUBFLOW IPPROTO_SUBFLOWIPPROTO_MAX };#endif
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 6/19 tcp: expose tcp routines and structs for MPTCP
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
tcp_v4_init_sock(), inet_compat_ioctl()tcp_request_sock_ipv4_ops
This function is needed for MPTCP subflow initialization.
--- include/net/inet_common.h | 3 +++ include/net/mptcp.h | 2 ++ include/net/tcp.h | 1 + net/ipv4/af_inet.c | 2 +- net/ipv4/tcp_ipv4.c | 4 ++-- 5 files changed, 9 insertions(+), 3 deletions(-)
include/net/inet_common.h +3 -0
@@ -37,6 +37,9 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,int inet_getname (struct socket *sock,struct sockaddr *uaddr,int peer);int inet_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg); +#ifdef CONFIG_COMPAT +int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg); +#endif int inet_ctl_sock_create (struct sock **sk,unsigned short family,unsigned short type,unsigned char protocol,struct net *net);
include/net/mptcp.h +2 -0
@@ -58,6 +58,8 @@ unsigned int mptcp_synack_options(struct request_sock *req,void mptcp_get_options (const struct sk_buff *skb,struct tcp_options_received *options); +extern const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops; +#else static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
include/net/tcp.h +1 -0
@@ -434,6 +434,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 ,
net/ipv4/af_inet.c +1 -1
@@ -965,7 +965,7 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)EXPORT_SYMBOL (inet_ioctl);#ifdef CONFIG_COMPAT -static int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) +int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) {struct sock *sk = sock->sk;int err = -ENOIOCTLCMD ;
net/ipv4/tcp_ipv4.c +2 -2
@@ -1343,7 +1343,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,
@@ -1932,7 +1932,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.17.1
Mat Martineau
RFC PATCH v2 7/19 mptcp: Create SUBFLOW socket for outgoing connections
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
Override the bind() and connect() methods of the MPTCP socket so they may act on the subflow socket and use the .sk_rx_dst_set() handler in the subflow proto to capture when the responding SYN-ACK is received.
--- include/net/mptcp.h | 46 ++++++++++- net/mptcp/Makefile | 2 +- net/mptcp/protocol.c | 151 +++++++++++++++++++++++++++++++--- net/mptcp/subflow.c | 192 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 376 insertions(+), 15 deletions(-) create mode 100644 net/mptcp/subflow.c
include/net/mptcp.h +45 -1
@@ -39,7 +39,10 @@struct mptcp_sock {/* inet_connection_sock must be the first member */ struct inet_connection_sock sk; -struct socket *subflow; +u64 local_key; +u64 remote_key; +struct socket *connection_list;/* @@ needs to be a list */ +struct socket *subflow;/* outgoing connect, listener or !mp_capable */ };static inline struct mptcp_sock *mptcp_sk (const struct sock *sk)
@@ -47,6 +50,42 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)return (struct mptcp_sock *)sk; } +/* MPTCP subflow sock structure */ +struct subflow_sock { +/* tcp_sock must be the first member */ +struct tcp_sock sk; +u64 local_key; +u64 remote_key; +bool request_mptcp;// send MP_CAPABLE +bool checksum; +bool version; +bool mp_capable;// remote is MPTCP capable +bool fourth_ack;// send initial DSS +struct sock *conn;// parent mptcp_sock +}; + +static inline struct subflow_sock *subflow_sk (const struct sock *sk) +{ +return (struct subflow_sock *)sk; +} + +struct 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 subflow_request_sock *subflow_rsk (const struct request_sock *rsk) +{ +return (struct subflow_request_sock *)rsk; +} +#ifdef CONFIG_MPTCP void mptcp_parse_option(const unsigned char *ptr, int opsize,
@@ -55,6 +94,11 @@ unsigned int mptcp_syn_options(struct sock *sk, u64 *local_key);unsigned int mptcp_synack_options (struct request_sock *req,u64 *local_key,u64 *remote_key); +void mptcp_finish_connect (struct sock *sk,int mp_capable); + +int mptcp_subflow_init (void ); +void mptcp_subflow_exit (void ); +void mptcp_get_options (const struct sk_buff *skb,struct tcp_options_received *options);
net/mptcp/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o options.o +mptcp-y := protocol.o subflow.o options.o
net/mptcp/protocol.c +138 -13
228 lines not on this page · raw message
net/mptcp/subflow.c new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 8/19 mptcp: Create SUBFLOW socket for incoming connections
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
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.
--- net/mptcp/protocol.c | 52 ++++++++++++++++++- net/mptcp/subflow.c | 115 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 162 insertions(+), 5 deletions(-)
net/mptcp/protocol.c +50 -2
@@ -118,6 +118,44 @@ static void mptcp_close(struct sock *sk, long timeout) } } +static struct sock *mptcp_accept (struct sock *sk,int flags,int *err, +bool kern) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *listener = msk->subflow; +struct socket *new_sock; +struct socket *mp; +struct subflow_sock *subflow; + +pr_debug ("msk=%p, listener=%p" , msk, listener->sk); + *err =kernel_accept (listener, &new_sock, flags); +if (*err <0 ) +return NULL ; + + subflow =subflow_sk (new_sock->sk); +pr_debug ("new_sock=%p" , subflow); + + *err =sock_create (PF_INET ,SOCK_STREAM ,IPPROTO_MPTCP , &mp); +if (*err <0 ) { +kernel_sock_shutdown (new_sock,SHUT_RDWR ); +sock_release (new_sock); +return NULL ; + } + + msk =mptcp_sk (mp->sk); +pr_debug ("msk=%p" , msk); + +if (subflow->mp_capable) { + msk->remote_key = subflow->remote_key; + msk->local_key = subflow->local_key; + msk->connection_list = new_sock; + }else { + msk->subflow = new_sock; + } + +return mp->sk; +} +static int mptcp_get_port (struct sock *sk,unsigned short snum) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -167,12 +205,22 @@ int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,return err; } +int mptcp_listen (struct socket *sock,int backlog) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct socket *subflow = msk->subflow; + +pr_debug ("msk=%p, subflow=%p" , msk, subflow->sk); + +return inet_listen (subflow, backlog); +} +static struct proto mptcp_prot = { .name ="MPTCP" , .owner =THIS_MODULE , .init = mptcp_init_sock, .close = mptcp_close, - .accept = inet_csk_accept, + .accept = mptcp_accept, .connect = mptcp_connect, .shutdown = tcp_shutdown, .sendmsg = mptcp_sendmsg,
@@ -195,7 +243,7 @@ const struct proto_ops mptcp_stream_ops = { .getname = inet_getname, .poll = tcp_poll, .ioctl = inet_ioctl, - .listen = inet_listen, + .listen = mptcp_listen, .shutdown = inet_shutdown, .setsockopt = sock_common_setsockopt, .getsockopt = sock_common_getsockopt,
net/mptcp/subflow.c +112 -3
151 lines not on this page · raw message
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 9/19 mptcp: Add key generation and token tree
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
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.
--- include/net/mptcp.h | 25 +++++ net/mptcp/Makefile | 2 +- net/mptcp/crypto.c | 213 +++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 21 +++- net/mptcp/subflow.c | 31 +++++- net/mptcp/token.c | 221 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 509 insertions(+), 4 deletions(-) create mode 100644 net/mptcp/crypto.c create mode 100644 net/mptcp/token.c
include/net/mptcp.h +25 -0
@@ -41,6 +41,7 @@ struct mptcp_sock {struct inet_connection_sock sk;u64 local_key;u64 remote_key; +u32 token;struct socket *connection_list;/* @@ needs to be a list */ struct socket *subflow;/* outgoing connect, listener or !mp_capable */ };
@@ -56,6 +57,7 @@ struct subflow_sock {struct tcp_sock sk;u64 local_key;u64 remote_key; +u32 token;bool request_mptcp;// send MP_CAPABLE bool checksum;bool version;
@@ -78,6 +80,7 @@ struct subflow_request_sock { version :4 ;u64 local_key;u64 remote_key; +u32 token; }; static inline
@@ -104,6 +107,28 @@ void mptcp_get_options(const struct sk_buff *skb,extern const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops; +void token_init (void ); +void token_new_request (struct request_sock *req,const struct sk_buff *skb); +void token_destroy_request (u32 token); +void token_new_connect (struct sock *sk); +void token_new_accept (struct sock *sk); +void token_destroy (u32 token); + +void crypto_init (void ); +u32 crypto_v4_get_nonce (__be32 saddr,__be32 daddr, +__be16 sport,__be16 dport); +u64 crypto_v4_get_key (__be32 saddr,__be32 daddr, +__be16 sport,__be16 dport); +u64 crypto_v6_get_key (const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 sport,__be16 dport); +u32 crypto_v6_get_nonce (const struct in6_addr *saddr, +const struct in6_addr *daddr, +__be16 sport,__be16 dport); +void crypto_key_sha1 (u64 key,u32 *token,u64 *idsn); +void crypto_hmac_sha1 (const u8 *key_1,const u8 *key_2,u32 *hash_out, +int arg_num, ...); +#else static inline void mptcp_parse_option(const unsigned char *ptr, int opsize,
net/mptcp/Makefile +1 -1
@@ -1,3 +1,3 @@ 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 +213 -0
213 lines not on this page · raw message
net/mptcp/protocol.c +19 -2
@@ -38,6 +38,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *saddr, int len)if (!err) { msk->remote_key = subflow->remote_key; msk->local_key = subflow->local_key; + msk->token = subflow->token; +pr_debug ("token=%u" , subflow->token); msk->connection_list = msk->subflow; msk->subflow =NULL ; }
@@ -91,13 +93,11 @@ static int mptcp_init_sock(struct sock *sk)struct subflow_sock *subflow =subflow_sk (sf->sk);pr_debug ("subflow=%p" , subflow); - msk->local_key =1234567887654321 ;// @@ fixed for now msk->subflow = sf; subflow->conn = sk; subflow->request_mptcp =1 ;// @@ if MPTCP enabled subflow->checksum =1 ;// @@ if checksum enabled subflow->version =0 ; - subflow->local_key = msk->local_key; }return err;
@@ -148,6 +148,8 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,if (subflow->mp_capable) { msk->remote_key = subflow->remote_key; msk->local_key = subflow->local_key; + msk->token = subflow->token; +pr_debug ("token=%u" , msk->token); msk->connection_list = new_sock; }else { msk->subflow = new_sock;
@@ -156,6 +158,15 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,return mp->sk; } +static void mptcp_destroy (struct sock *sk) +{ +struct mptcp_sock *msk =mptcp_sk (sk); + +pr_debug ("msk=%p, subflow=%p" , sk, msk->subflow->sk); + +token_destroy (msk->token); +} +static int mptcp_get_port (struct sock *sk,unsigned short snum) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -186,6 +197,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable)if (mp_capable) { msk->remote_key = subflow->remote_key; msk->local_key = subflow->local_key; + msk->token = subflow->token; +pr_debug ("token=%u" , msk->token); msk->connection_list = msk->subflow; msk->subflow =NULL ; }
@@ -223,6 +236,7 @@ static struct proto mptcp_prot = { .accept = mptcp_accept, .connect = mptcp_connect, .shutdown = tcp_shutdown, + .destroy = mptcp_destroy, .sendmsg = mptcp_sendmsg, .recvmsg = mptcp_recvmsg, .hash = inet_hash,
@@ -275,6 +289,9 @@ static int __init mptcp_init(void) mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo; +token_init (); +crypto_init (); + err =mptcp_subflow_init ();if (err) goto subflow_failed;
net/mptcp/subflow.c +30 -1
@@ -53,6 +53,29 @@ static int subflow_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,return tcp_recvmsg (sk, msg, len, nonblock, flags, addr_len); } +static int subflow_rebuild_header (struct sock *sk) +{ +struct subflow_sock *subflow =subflow_sk (sk); + +if (subflow->request_mptcp && !subflow->token) { +pr_debug ("subflow=%p" , sk); +token_new_connect (sk); + } + +return inet_sk_rebuild_header (sk); +} + +static void subflow_req_destructor (struct request_sock *req) +{ +struct subflow_request_sock *subflow_req =subflow_rsk (req); + +pr_debug ("subflow_req=%p" , subflow_req); + +if (subflow_req->mp_capable) +token_destroy_request (subflow_req->token); + tcp_request_sock_ops.destructor (req); +} +static void subflow_v4_init_req (struct request_sock *req,const struct sock *sk_listener,struct sk_buff *skb)
@@ -82,6 +105,8 @@ static void subflow_v4_init_req(struct request_sock *req, listener->checksum) subflow_req->checksum =1 ; subflow_req->remote_key = rx_opt.mptcp.sndr_key; +pr_debug ("remote_key=%llu" , subflow_req->remote_key); +token_new_request (req, skb); }else { subflow_req->mp_capable =0 ; }
@@ -147,6 +172,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, subflow->fourth_ack =1 ; subflow->remote_key = subflow_req->remote_key; subflow->local_key = subflow_req->local_key; + subflow->token = subflow_req->token; +pr_debug ("token=%u" , subflow->token); +token_new_accept (child); }else { subflow->mp_capable =0 ; }
@@ -158,7 +186,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,const struct inet_connection_sock_af_ops subflow_specific = { .queue_xmit = ip_queue_xmit, .send_check = tcp_v4_send_check, - .rebuild_header = inet_sk_rebuild_header, + .rebuild_header = subflow_rebuild_header, .sk_rx_dst_set = subflow_finish_connect, .conn_request = subflow_conn_request, .syn_recv_sock = subflow_syn_recv_sock,
@@ -273,6 +301,7 @@ int mptcp_subflow_init(void) subflow_request_sock_ops = tcp_request_sock_ops; subflow_request_sock_ops.obj_size =sizeof (struct subflow_request_sock ), + subflow_request_sock_ops.destructor = subflow_req_destructor; subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops; subflow_request_sock_ipv4_ops.init_req = subflow_v4_init_req;
net/mptcp/token.c new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 10/19 mptcp: Add getname() socket operation
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
--- net/mptcp/protocol.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +17 -1
@@ -218,6 +218,22 @@ int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,return err; } +int mptcp_getname (struct socket *sock,struct sockaddr *uaddr,int peer) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +struct socket *subflow; +int err = -EPERM ; + +if (msk->connection_list) + subflow = msk->connection_list; +else + subflow = msk->subflow; + + err =inet_getname (subflow, uaddr, peer); + +return err; +} +int mptcp_listen (struct socket *sock,int backlog) {struct mptcp_sock *msk =mptcp_sk (sock->sk);
@@ -254,7 +270,7 @@ const struct proto_ops mptcp_stream_ops = { .connect = mptcp_stream_connect, .socketpair = sock_no_socketpair, .accept = inet_accept, - .getname = inet_getname, + .getname = mptcp_getname, .poll = tcp_poll, .ioctl = inet_ioctl, .listen = mptcp_listen,
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 11/19 mptcp: Add shutdown() socket operation
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
--- net/mptcp/protocol.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +21 -1
@@ -244,6 +244,26 @@ int mptcp_listen(struct socket *sock, int backlog)return inet_listen (subflow, backlog); } +int mptcp_stream_shutdown (struct socket *sock,int how) +{ +struct mptcp_sock *msk =mptcp_sk (sock->sk); +int ret =0 ; + +pr_debug ("sk=%p, how=%d" , msk, how); + +if (msk->subflow) { +pr_debug ("subflow=%p" , msk->subflow->sk); + ret =kernel_sock_shutdown (msk->subflow, how); + } +if (msk->connection_list) { +pr_debug ("conn_list->subflow=%p" , msk->connection_list->sk); + ret =kernel_sock_shutdown (msk->connection_list, how); + } +inet_shutdown (sock, how); + +return ret; +} +static struct proto mptcp_prot = { .name ="MPTCP" , .owner =THIS_MODULE ,
@@ -274,7 +294,7 @@ const struct proto_ops mptcp_stream_ops = { .poll = tcp_poll, .ioctl = inet_ioctl, .listen = mptcp_listen, - .shutdown = inet_shutdown, + .shutdown = mptcp_stream_shutdown, .setsockopt = sock_common_setsockopt, .getsockopt = sock_common_getsockopt, .sendmsg = inet_sendmsg,
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 12/19 mptcp: Implement setsockopt()/getsockopt()
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
--- net/mptcp/protocol.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/subflow.c | 22 ++++++++++++++++++++ 2 files changed, 70 insertions(+)
net/mptcp/protocol.c +48 -0
@@ -167,6 +167,52 @@ static void mptcp_destroy(struct sock *sk)token_destroy (msk->token); } +static int mptcp_setsockopt (struct sock *sk,int level,int optname, +char __user *uoptval,unsigned int optlen) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *subflow; +char __kernel *optval; + +pr_debug ("msk=%p" , msk); +if (msk->connection_list) { + subflow = msk->connection_list; +pr_debug ("conn_list->subflow=%p" , subflow->sk); + }else { + subflow = msk->subflow; +pr_debug ("subflow=%p" , subflow->sk); + } + +/* will be treated as __user in subflow_setsockopt */ + optval = (char __kernel __force *) uoptval; + +return kernel_setsockopt (subflow, level, optname, optval, optlen); +} + +static int mptcp_getsockopt (struct sock *sk,int level,int optname, +char __user *uoptval,int __user *uoption) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +struct socket *subflow; +char __kernel *optval; +int __kernel *option; + +pr_debug ("msk=%p" , msk); +if (msk->connection_list) { + subflow = msk->connection_list; +pr_debug ("conn_list->subflow=%p" , subflow->sk); + }else { + subflow = msk->subflow; +pr_debug ("subflow=%p" , subflow->sk); + } + +/* will be treated as __user in subflow_getsockopt */ + optval = (char __kernel __force *) uoptval; + option = (int __kernel __force *) uoption; + +return kernel_getsockopt (subflow, level, optname, optval, option); +} +static int mptcp_get_port (struct sock *sk,unsigned short snum) {struct mptcp_sock *msk =mptcp_sk (sk);
@@ -273,6 +319,8 @@ static struct proto mptcp_prot = { .connect = mptcp_connect, .shutdown = tcp_shutdown, .destroy = mptcp_destroy, + .setsockopt = mptcp_setsockopt, + .getsockopt = mptcp_getsockopt, .sendmsg = mptcp_sendmsg, .recvmsg = mptcp_recvmsg, .hash = inet_hash,
net/mptcp/subflow.c +22 -0
@@ -249,6 +249,26 @@ static void subflow_destroy(struct sock *sk)tcp_v4_destroy_sock (sk); } +static int subflow_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,unsigned int optlen) +{ +struct subflow_sock *subflow =subflow_sk (sk); + +pr_debug ("subflow=%p" , subflow); + +return tcp_setsockopt (sk, level, optname, optval, optlen); +} + +static int subflow_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *option) +{ +struct subflow_sock *subflow =subflow_sk (sk); + +pr_debug ("subflow=%p" , subflow); + +return tcp_getsockopt (sk, level, optname, optval, option); +} +static struct proto subflow_prot = { .name ="SUBFLOW" , .owner =THIS_MODULE ,
@@ -260,6 +280,8 @@ static struct proto subflow_prot = { .init = subflow_init_sock, .destroy = subflow_destroy, .shutdown = tcp_shutdown, + .setsockopt = subflow_setsockopt, + .getsockopt = subflow_getsockopt, .keepalive = tcp_set_keepalive, .recvmsg = subflow_recvmsg, .sendmsg = subflow_sendmsg,
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 13/19 skbuff: Add shared control buffer
In reply to Mat MartineauThe sk_buff control buffer is of limited size, and cannot be enlarged without significant impact on systemwide memory use. However, additional per-packet state is needed for some protocols, like Multipath TCP.
An optional shared control buffer placed after the normal struct skb_shared_info can accomodate the necessary state without imposing extra memory usage or code changes on normal struct sk_buff users. __alloc_skb will now place a skb_shared_info_ext structure at skb->end when given the SKB_ALLOC_SHINFO_EXT flag. Most users of struct sk_buff continue to use the skb_shinfo() macro to access shared info. skb_shinfo(skb)->is_ext is set if the extended structure is available, and cleared if it is not.
pskb_expand_head will preserve the shared control buffer if it is present.
--- include/linux/skbuff.h | 24 ++++++++++++++++++- net/core/skbuff.c | 53 ++++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 13 deletions(-)
include/linux/skbuff.h +23 -1
@@ -491,7 +491,8 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb,* the end of the header data, ie. at skb->end. */ struct skb_shared_info { -__u8 __unused; +__u8 is_ext:1 , + __unused:7 ;__u8 meta_len;__u8 nr_frags;__u8 tx_flags;
@@ -531,6 +532,24 @@ struct skb_shared_info {#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) +/* This is an extended version of skb_shared_info, also invariant across +* clones and living at the end of the header data. +*/ +struct skb_shared_info_ext { +/* skb_shared_info must be the first member */ +struct skb_shared_info shinfo; + +/* This is the shared control buffer. It is similar to sk_buff's +* control buffer, but is shared across clones. It must not be +* modified when multiple sk_buffs are referencing this structure. +*/ +char shcb[48 ]; +}; + +#define SKB_SHINFO_EXT_OVERHEAD \ + (SKB_DATA_ALIGN(sizeof(struct skb_shared_info_ext)) - \ + SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) +enum {SKB_FCLONE_UNAVAILABLE ,/* skb has no fclone (from head_cache) */ SKB_FCLONE_ORIG ,/* orig skb (from fclone_cache) */
@@ -858,6 +877,7 @@ struct sk_buff {#define SKB_ALLOC_FCLONE 0x01#define SKB_ALLOC_RX 0x02#define SKB_ALLOC_NAPI 0x04 +#define SKB_ALLOC_SHINFO_EXT 0x08/* Returns true if the skb was allocated from PFMEMALLOC reserves */ static inline bool skb_pfmemalloc (const struct sk_buff *skb)
@@ -1280,6 +1300,8 @@ static inline unsigned int skb_end_offset(const struct sk_buff *skb)/* Internal */ #define skb_shinfo (SKB ) ((struct skb_shared_info *)(skb_end_pointer(SKB))) +#define skb_shinfo_ext (SKB ) \ + ((struct skb_shared_info_ext *)(skb_end_pointer(SKB)))static inline struct skb_shared_hwtstamps *skb_hwtstamps (struct sk_buff *skb) {
net/core/skbuff.c +41 -12
113 lines not on this page · raw message
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 14/19 tcp: Export low-level TCP functions
In reply to Mat Martineau--- include/net/tcp.h | 4 ++++ net/ipv4/tcp.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-)
include/net/tcp.h +4 -0
@@ -331,6 +331,10 @@ 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_skb_entail (struct sock *sk,struct sk_buff *skb); +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 +6 -6
@@ -657,7 +657,7 @@ static inline bool forced_push(const struct tcp_sock *tp)return after (tp->write_seq, tp->pushed_seq + (tp->max_window >>1 )); } -static void skb_entail (struct sock *sk,struct sk_buff *skb) +void tcp_skb_entail (struct sock *sk,struct sk_buff *skb) {struct tcp_sock *tp =tcp_sk (sk);struct tcp_skb_cb *tcb =TCP_SKB_CB (skb);
@@ -701,8 +701,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;
@@ -925,7 +925,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;
@@ -980,7 +980,7 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,if (!skb) goto wait_for_memory; -skb_entail (sk, skb); +tcp_skb_entail (sk, skb); copy = size_goal; }
@@ -1295,7 +1295,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) process_backlog = true; skb->ip_summed =CHECKSUM_PARTIAL ; -skb_entail (sk, skb); +tcp_skb_entail (sk, skb); copy = size_goal;/* All packets are restored as if they have
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 15/19 mptcp: More efficient byte order handling
In reply to Mat Martineaucrypto_key_sha1() was reordering bytes in words that were discarded, and the initial data sequence number (IDSN) was returned in a way that required additional byte swapping. Now only the token is returned with its bytes swapped, and the IDSN is returned in host order so it is ready for comparison and addition.
--- net/mptcp/crypto.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/mptcp/crypto.c +2 -6
@@ -106,7 +106,6 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn)u32 workspace[SHA_WORKSPACE_WORDS ];u32 mptcp_hashed_key[SHA_DIGEST_WORDS ];u8 input[64 ]; -int i;memset (workspace,0 ,sizeof (workspace));
@@ -121,13 +120,10 @@ void crypto_key_sha1(u64 key, u32 *token, u64 *idsn)sha_init (mptcp_hashed_key);sha_transform (mptcp_hashed_key, input, workspace); -for (i =0 ; i <5 ; i++) - mptcp_hashed_key[i] =cpu_to_be32 (mptcp_hashed_key[i]); -if (token) - *token = mptcp_hashed_key[0 ]; + *token =htonl (mptcp_hashed_key[0 ]);if (idsn) - *idsn = *((u64 *)&mptcp_hashed_key[3 ]); + *idsn = ((u64 )mptcp_hashed_key[3 ] <<32 ) + mptcp_hashed_key[4 ]; } void crypto_hmac_sha1(const u8 *key_1, const u8 *key_2, u32 *hash_out,
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 16/19 mptcp: Write MPTCP DSS headers to outgoing data packets
In reply to Mat MartineauPer-packet metadata required to write the MPTCP DSS option is written to the skb shared control buffer. 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. If a non-blocking write only succeeds in sending part of the data, the mapping that was in the first packet will cover data that was not sent and is not buffered within the kernel. There's no guarantee that the socket user will write the same (or any) data when the socket becomes writable again.
The MPTCP DSS checksum is not yet implemented.
--- include/net/mptcp.h | 30 ++++- net/ipv4/tcp_output.c | 144 ++++++++++++++++++--- net/mptcp/protocol.c | 285 ++++++++++++++++++++++++++++++++++++++++-- net/mptcp/token.c | 13 +- 4 files changed, 432 insertions(+), 40 deletions(-)
include/net/mptcp.h +28 -2
@@ -41,6 +41,8 @@ struct mptcp_sock {struct inet_connection_sock sk;u64 local_key;u64 remote_key; +u64 write_seq; +u64 ack_seq;u32 token;struct socket *connection_list;/* @@ needs to be a list */ struct socket *subflow;/* outgoing connect, listener or !mp_capable */
@@ -51,13 +53,36 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)return (struct mptcp_sock *)sk; } +/* MPTCP sk_buff extended control buffer */ +struct mptcp_skb_ext_cb { +u64 data_ack; +u64 data_seq; +u32 subflow_seq; +u16 data_level_len; +__sum16 checksum; +u8 use_ack:1 , + ack64:1 , + use_map:1 , + dsn64:1 , + use_checksum:1 , + data_fin:1 , + __unused:2 ; +}; + +static inline struct mptcp_skb_ext_cb *mptcp_skb_ecb (struct sk_buff *skb) +{ +return (struct mptcp_skb_ext_cb *)skb_shinfo_ext (skb)->shcb; +} +/* MPTCP subflow sock structure */ struct subflow_sock {/* tcp_sock must be the first member */ struct tcp_sock sk;u64 local_key; -u64 remote_key;u32 token; +u64 idsn; +u64 remote_key; +u32 rel_write_seq;bool request_mptcp;// send MP_CAPABLE bool checksum;bool version;
@@ -79,8 +104,9 @@ struct subflow_request_sock { backup :1 , version : 4;u64 local_key; -u64 remote_key;u32 token; +u64 idsn; +u64 remote_key; }; static inline
net/ipv4/tcp_output.c +124 -20
199 lines not on this page · raw message
net/mptcp/protocol.c +273 -12
319 lines not on this page · raw message
net/mptcp/token.c +7 -6
@@ -81,10 +81,11 @@ static void new_req_token(struct request_sock *req, ireq->ir_rmt_port);#endif } -pr_debug ("local_key=%llu:%llx" , local_key, local_key); subflow_req->local_key = local_key; -crypto_key_sha1 (subflow_req->local_key, &subflow_req->token,NULL ); -pr_debug ("token=%u" , subflow_req->token); +crypto_key_sha1 (subflow_req->local_key, &subflow_req->token, + &subflow_req->idsn); +pr_debug ("local_key=%llu, token=%u, idsn=%llu" , subflow_req->local_key, + subflow_req->token, subflow_req->idsn); }static void new_token (const struct sock *sk)
@@ -105,9 +106,9 @@ static void new_token(const struct sock *sk) isk->inet_dport);#endif } -pr_debug ("local_key=%llu:%llx" , subflow->local_key, subflow->local_key); -crypto_key_sha1 (subflow->local_key, &subflow->token,NULL ); -pr_debug ("token=%u" , subflow->token); +crypto_key_sha1 (subflow->local_key, &subflow->token, &subflow->idsn); +pr_debug ("local_key=%llu, token=%u, idsn=%llu" , subflow->local_key, + subflow->token, subflow->idsn); }static int insert_req_token (u32 token)
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 17/19 mptcp: Rework handling of the MPTCP sub-options
In reply to Mat MartineauFrom: Peter Krystad <peter.krystad(a)intel.com>
--- net/ipv4/tcp_output.c | 230 +++++++++++++++++++++++------------------- 1 file changed, 124 insertions(+), 106 deletions(-)
net/ipv4/tcp_output.c +124 -106
@@ -413,9 +413,116 @@ static inline bool tcp_urg_mode(const struct tcp_sock *tp)#define OPTION_FAST_OPEN_COOKIE (1 << 8)#define OPTION_SMC (1 << 9)#define OPTION_MPTCP (1 << 10) -#define OPTION_MPTCP_ACK (1 << 11) -#define OPTION_MPTCP_DSS_MAP (1 << 12) -#define OPTION_MPTCP_DSS_ACK (1 << 13) + +/* MPTCP option subtypes */ +#define OPTION_MPTCP_MPC_SYN (1 << 0) +#define OPTION_MPTCP_MPC_SYNACK (1 << 1) +#define OPTION_MPTCP_MPC_ACK (1 << 2) +#define OPTION_MPTCP_DSS_ACK (1 << 7) +#define OPTION_MPTCP_DSS_MAP (1 << 8) + +struct tcp_out_options { +u16 options;/* bit field of OPTION_* */ +u16 mss;/* 0 to disable */ +u8 ws;/* window scale, 0 to disable */ +u8 num_sack_blocks;/* number of SACK blocks to include */ +u8 hash_size;/* bytes in hash_location */ +__u8 *hash_location;/* temporary pointer, overloaded */ +__u32 tsval, tsecr;/* need to include OPTION_TS */ +struct tcp_fastopen_cookie *fastopen_cookie;/* Fast open cookie */ +u16 suboptions;/* MPTCP sub-options */ +u64 sndr_key; +u64 rcvr_key; +}; + +static void mptcp_options_write (__be32 *ptr,struct sk_buff *skb,struct tcp_out_options *opts) +{ +if (!(OPTION_MPTCP & opts->options)) +return ; + +if ((OPTION_MPTCP_MPC_SYN | +OPTION_MPTCP_MPC_SYNACK | +OPTION_MPTCP_MPC_ACK ) & opts->suboptions) { +u8 len; +u8 *p = (u8 *)ptr; + +if (OPTION_MPTCP_MPC_SYN & opts->suboptions) + len =TCPOLEN_MPTCP_MPC_SYN ; +else + len =TCPOLEN_MPTCP_MPC_SYNACK ; + + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ = len;// length + *p++ =0 ;// subtype=MP_CAPABLE | version=0 + *p++ =0x1 ;// flags=HMAC-SHA1 +memcpy (p, &opts->sndr_key,8 ); +if (OPTION_MPTCP_MPC_SYNACK & opts->suboptions) { + p +=8 ; +memcpy (p, &opts->rcvr_key,8 ); + } + } + +if ((OPTION_MPTCP_DSS_MAP | +OPTION_MPTCP_DSS_ACK ) & opts->suboptions) { +struct mptcp_skb_ext_cb *ecb =mptcp_skb_ecb (skb); +bool write_ack = (OPTION_MPTCP_DSS_ACK & opts->suboptions) && ecb->use_ack; +bool write_map = (OPTION_MPTCP_DSS_MAP & opts->suboptions) && ecb->use_map; +u8 flags =0 ; +u8 len =4 ; +u8 *p = (u8 *)ptr; + +BUG_ON (!skb_shinfo (skb)->is_ext); +BUG_ON (!write_ack && !write_map); + +if (write_ack) { + len +=8 ; + flags =0x03 ; + } + +if (write_map) { + len +=14 ; + +if (ecb->use_checksum) + len +=2 ; + +/* Use only 64-bit mapping flags for now, add +* support for optional 32-bit mappings later. +*/ + flags |=0x0c ; +if (ecb->data_fin) + flags |=0x10 ; + } + + *p++ =0x1e ;// TCP option: Multipath TCP + *p++ = len;// length + *p++ =0x20 ;// subtype=DSS + *p++ = flags; + +if (write_ack) { + *(__be64 *)p =cpu_to_be64 (ecb->data_ack); + p +=8 ; + } + +if (write_map) { + *(__be64 *)p =cpu_to_be64 (ecb->data_seq); + p +=8 ; + + *(__be32 *)p =htonl (ecb->subflow_seq); + p +=4 ; + + *(__be16 *)p =htons (ecb->data_level_len); + p +=2 ; + +if (ecb->use_checksum) { + *(__be16 *)p =htons (ecb->checksum); + p +=2 ; + }else { + *p++ =TCPOPT_NOP ; + *p++ =TCPOPT_NOP ; + } + } + } +}static void smc_options_write (__be32 *ptr,u16 *options) {
@@ -432,19 +539,6 @@ static void smc_options_write(__be32 *ptr, u16 *options)#endif } -struct tcp_out_options { -u16 options;/* bit field of OPTION_* */ -u16 mss;/* 0 to disable */ -u8 ws;/* window scale, 0 to disable */ -u8 num_sack_blocks;/* number of SACK blocks to include */ -u8 hash_size;/* bytes in hash_location */ -__u8 *hash_location;/* temporary pointer, overloaded */ -__u32 tsval, tsecr;/* need to include OPTION_TS */ -struct tcp_fastopen_cookie *fastopen_cookie;/* Fast open cookie */ -u64 sndr_key; -u64 rcvr_key; -}; -/* Write previously computed TCP options to the packet. * * Beware: Something in the Internet is very sensitive to the ordering of
@@ -554,88 +648,7 @@ static void tcp_options_write(__be32 *ptr, struct sk_buff *skb,smc_options_write (ptr, &options); -if (OPTION_MPTCP & options) { -u8 *p = (u8 *)ptr; - *p++ =0x1e ;// TCP option: Multipath TCP - *p++ =12 ;// length - *p++ =0 ;// subtype=MP_CAPABLE | version=0 - *p++ =0x1 ;// flags=HMAC-SHA1 -memcpy (p, &opts->sndr_key,8 ); -pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); - } - -if (OPTION_MPTCP_ACK & options) { -u8 *p = (u8 *)ptr; - *p++ =0x1e ;// TCP option: Multipath TCP - *p++ =20 ;// length - *p++ =0 ;// subtype=MP_CAPABLE | version=0 - *p++ =0x1 ;// flags=HMAC-SHA1 -memcpy (p, &opts->sndr_key,8 ); -pr_debug ("tcp_options_write: opts->sndr_key=%llu" , opts->sndr_key); - p +=8 ; -memcpy (p, &opts->rcvr_key,8 ); -pr_debug ("tcp_options_write: opts->rcvr_key=%llu" , opts->rcvr_key); - } - -if ((OPTION_MPTCP_DSS_MAP |OPTION_MPTCP_DSS_ACK ) & options) { -struct mptcp_skb_ext_cb *ecb =mptcp_skb_ecb (skb); -bool write_ack = (OPTION_MPTCP_DSS_ACK & options) && ecb->use_ack; -bool write_map = (OPTION_MPTCP_DSS_MAP & options) && ecb->use_map; -u8 flags =0 ; -u8 len =4 ; -u8 *p = (u8 *)ptr; - -BUG_ON (!skb_shinfo (skb)->is_ext); -BUG_ON (!write_ack && !write_map); - -if (write_ack) { - len +=8 ; - flags =0x03 ; - } - -if (write_map) { - len +=14 ; - -if (ecb->use_checksum) - len +=2 ; - -/* Use only 64-bit mapping flags for now, add -* support for optional 32-bit mappings later. -*/ - flags |=0x0c ; -if (ecb->data_fin) - flags |=0x10 ; - } - - *p++ =0x1e ;// TCP option: Multipath TCP - *p++ = len;// length - *p++ =0x20 ;// subtype=DSS - *p++ = flags; - -if (write_ack) { - *(__be64 *)p =cpu_to_be64 (ecb->data_ack); - p +=8 ; - } - -if (write_map) { - *(__be64 *)p =cpu_to_be64 (ecb->data_seq); - p +=8 ; - - *(__be32 *)p =htonl (ecb->subflow_seq); - p +=4 ; - - *(__be16 *)p =htons (ecb->data_level_len); - p +=2 ; - -if (ecb->use_checksum) { - *(__be16 *)p =htons (ecb->checksum); - p +=2 ; - }else { - *p++ =TCPOPT_NOP ; - *p++ =TCPOPT_NOP ; - } - } - } +mptcp_options_write (ptr, skb, opts); } static void smc_set_option(const struct tcp_sock *tp,
@@ -743,6 +756,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,u64 local_key;if (mptcp_syn_options (sk, &local_key)) { opts->options |=OPTION_MPTCP ; + opts->suboptions |=OPTION_MPTCP_MPC_SYN ; opts->sndr_key = local_key; remaining -=TCPOLEN_MPTCP_MPC_SYN ; }
@@ -813,7 +827,8 @@ static unsigned int tcp_synack_options(const struct sock *sk,u64 remote_key;if (mptcp_synack_options (req, &local_key, &remote_key)) {if (remaining >=TCPOLEN_MPTCP_MPC_SYNACK ) { - opts->options |=OPTION_MPTCP_ACK ; + opts->options |=OPTION_MPTCP ; + opts->suboptions |=OPTION_MPTCP_MPC_SYNACK ; opts->sndr_key = local_key; opts->rcvr_key = remote_key; remaining -=TCPOLEN_MPTCP_MPC_SYNACK ;
@@ -859,14 +874,17 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skbif (tp->is_mptcp) {struct subflow_sock *subflow =subflow_sk (sk); +pr_debug ("tcp_established_options: subflow=%p" , subflow); + opts->suboptions =0 ;if (subflow->mp_capable) {unsigned int remaining =MAX_TCP_OPTION_SPACE - size;pr_debug ("tcp_established_options: remaining=%d" , remaining);if (!subflow->fourth_ack) { -pr_debug ("tcp_established_options: OPTION_MPTCP_ACK" ); +pr_debug ("tcp_established_options: OPTION_MPTCP_MPC_ACK" );if (remaining >=20 ) { - opts->options |=OPTION_MPTCP_ACK ; + opts->options |=OPTION_MPTCP ; + opts->suboptions |=OPTION_MPTCP_MPC_ACK ; opts->sndr_key = subflow->local_key; opts->rcvr_key = subflow->remote_key; size +=20 ;
@@ -876,7 +894,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb }else if (skb &&skb_shinfo (skb)->is_ext) {struct mptcp_skb_ext_cb *ecb;unsigned int dss_size =0 ; -u16 options =0 ; +u16 suboptions =0 ; ecb =mptcp_skb_ecb (skb);
@@ -889,7 +907,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skbif (map_size <= remaining) { remaining -= map_size; dss_size = map_size; - options =OPTION_MPTCP_DSS_MAP ; + suboptions =OPTION_MPTCP_DSS_MAP ; }else {WARN (1 ,"MPTCP: Map dropped" ); }
@@ -906,7 +924,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skbif (ack_size <= remaining) { dss_size += ack_size; - options |=OPTION_MPTCP_DSS_ACK ; + suboptions |=OPTION_MPTCP_DSS_ACK ; }else {WARN (1 ,"MPTCP: Ack dropped" ); }
@@ -914,8 +932,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skbif (dss_size) { size +=ALIGN (dss_size,4 ); - opts->options |= options; -pr_debug ("dss_size=%u size=%u" , dss_size, size); + opts->options |=OPTION_MPTCP ; + opts->suboptions = suboptions; } } }
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 18/19 mptcp: Disable TCP coalesce/collapse for MPTCP subflows
In reply to Mat MartineauAs a temporary measure, make sure packets are passed to the upper layers unmodified so the TCP options are preserved.
--- net/ipv4/tcp_input.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +10 -1
@@ -4335,6 +4335,9 @@ static bool tcp_try_coalesce(struct sock *sk,if (TCP_SKB_CB (from)->seq !=TCP_SKB_CB (to)->end_seq)return false; +if (tcp_sk (sk)->is_mptcp) +return false; +if (!skb_try_coalesce (to, from, fragstolen, &delta))return false;
@@ -4838,11 +4841,17 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,break ; } +if (tcp_sk (sk)->is_mptcp) { + end_of_skbs = false; +break ; + } +/* Decided to skip this, advance start seq. */ start =TCP_SKB_CB (skb)->end_seq; }if (end_of_skbs || - (TCP_SKB_CB (skb)->tcp_flags & (TCPHDR_SYN |TCPHDR_FIN ))) + (TCP_SKB_CB (skb)->tcp_flags & (TCPHDR_SYN |TCPHDR_FIN )) || +tcp_sk (sk)->is_mptcp)return ;__skb_queue_head_init (&tmp);
Signature · 1 line
2.17.1
Mat Martineau
RFC PATCH v2 19/19 mptcp: Implement MPTCP receive path
In reply to Mat MartineauParses incoming DSS options and populates outgoing MPTCP ACK fields. Incoming packets are read from the recieve buffer with tcp_read_sock() to allow access to skb fields and packet headers, and to only copy the data payload when it's the correct placement in the data stream.
MPTCP ACK values are now populated from an atomic value stored in the connection socket rather than carried in the extended control block, which makes use of the most up-to-date sequence number and allows the MPTCP ACK to be populated on TCP ACK packets that have no payload.
--- include/linux/tcp.h | 12 ++ include/net/mptcp.h | 37 ++++-- net/ipv4/tcp_output.c | 81 +++++++----- net/mptcp/options.c | 58 ++++++++- net/mptcp/protocol.c | 291 +++++++++++++++++++++++++++++++++++++----- net/mptcp/subflow.c | 26 +++- 6 files changed, 422 insertions(+), 83 deletions(-)
include/linux/tcp.h +12 -0
@@ -112,6 +112,18 @@ struct tcp_options_received {u8 flags;u64 sndr_key;u64 rcvr_key; +u64 ack; +u64 seq; +u32 subflow_seq; +u16 dll; +u16 checksum; + u8 use_ack:1, + ack64:1, + use_map:1, + dsn64:1, + use_checksum:1, + data_fin:1, + __unused:2; } mptcp; };
include/net/mptcp.h +23 -14
@@ -38,14 +38,14 @@/* MPTCP connection sock */ struct mptcp_sock {/* inet_connection_sock must be the first member */ -struct inet_connection_sock sk; -u64 local_key; -u64 remote_key; -u64 write_seq; -u64 ack_seq; -u32 token; -struct socket *connection_list;/* @@ needs to be a list */ -struct socket *subflow;/* outgoing connect, listener or !mp_capable */ +struct inet_connection_sock sk; +u64 local_key; +u64 remote_key; +u64 write_seq; +atomic64_t ack_seq; +u32 token; +struct socket *connection_list;/* @@ needs to be a list */ +struct socket *subflow;/* outgoing connect, listener or !mp_capable */ };static inline struct mptcp_sock *mptcp_sk (const struct sock *sk)
@@ -55,18 +55,15 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)/* MPTCP sk_buff extended control buffer */ struct mptcp_skb_ext_cb { -u64 data_ack;u64 data_seq;u32 subflow_seq; -u16 data_level_len; +u16 dll;__sum16 checksum; -u8 use_ack:1 , - ack64:1 , - use_map:1 , +u8 use_map:1 , dsn64:1 , use_checksum:1 , data_fin:1 , - __unused:2 ; + __unused:4 ; };static inline struct mptcp_skb_ext_cb *mptcp_skb_ecb (struct sk_buff *skb)
@@ -79,16 +76,22 @@ struct subflow_sock {/* tcp_sock must be the first member */ struct tcp_sock sk;u64 local_key; +u64 map_seq; +u32 map_subflow_seq;u32 token;u64 idsn;u64 remote_key;u32 rel_write_seq; +u32 ssn_offset; +u16 map_dll;bool request_mptcp;// send MP_CAPABLE bool checksum;bool version;bool mp_capable;// remote is MPTCP capable bool fourth_ack;// send initial DSS +bool conn_finished;struct sock *conn;// parent mptcp_sock +void (*tcp_sk_data_ready)(struct sock *sk); };static inline struct subflow_sock *subflow_sk (const struct sock *sk)
@@ -96,6 +99,11 @@ static inline struct subflow_sock *subflow_sk(const struct sock *sk)return (struct subflow_sock *)sk; } +static inline struct subflow_sock *subflow_tp (const struct tcp_sock *tp) +{ +return (struct subflow_sock *)tp; +} +struct subflow_request_sock {struct tcp_request_sock sk; u8 mp_capable : 1,
@@ -107,6 +115,7 @@ struct subflow_request_sock {u32 token;u64 idsn;u64 remote_key; +u32 ssn_offset; }; static inline
net/ipv4/tcp_output.c +46 -35
156 lines not on this page · raw message
net/mptcp/options.c +56 -2
83 lines not on this page · raw message
net/mptcp/protocol.c +261 -30
379 lines not on this page · raw message
net/mptcp/subflow.c +24 -2
@@ -107,6 +107,8 @@ static void subflow_v4_init_req(struct request_sock *req, subflow_req->remote_key = rx_opt.mptcp.sndr_key;pr_debug ("remote_key=%llu" , subflow_req->remote_key);token_new_request (req, skb); +pr_debug ("syn seq=%u" ,TCP_SKB_CB (skb)->seq); + subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq; }else { subflow_req->mp_capable =0 ; }
@@ -120,10 +122,15 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)pr_debug ("subflow=%p" , subflow); -if (subflow->conn) { +if (!subflow->conn_finished) {pr_debug ("remote_key=%llu" , subflow->remote_key);mptcp_finish_connect (subflow->conn, subflow->mp_capable); - subflow->conn =NULL ; + subflow->conn_finished =1 ; + +if (skb) { +pr_debug ("synack seq=%u" ,TCP_SKB_CB (skb)->seq); + subflow->ssn_offset =TCP_SKB_CB (skb)->seq; + } } }
@@ -172,7 +179,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, subflow->fourth_ack =1 ; subflow->remote_key = subflow_req->remote_key; subflow->local_key = subflow_req->local_key; + subflow->ssn_offset = subflow_req->ssn_offset; subflow->token = subflow_req->token; + subflow->idsn = subflow_req->idsn;pr_debug ("token=%u" , subflow->token);token_new_accept (child); }else {
@@ -202,6 +211,17 @@ const struct inet_connection_sock_af_ops subflow_specific = { .mtu_reduced = tcp_v4_mtu_reduced, }; +static void subflow_data_ready (struct sock *sk) +{ +struct subflow_sock *subflow =subflow_sk (sk); +struct sock *parent = subflow->conn; + + subflow->tcp_sk_data_ready (sk); + +if (parent) + parent->sk_data_ready (parent); +} +static int subflow_init_sock (struct sock *sk) {struct subflow_sock *subflow =subflow_sk (sk);
@@ -215,6 +235,8 @@ static int subflow_init_sock(struct sock *sk)if (!err) {// @@ AND mptcp is enabled tsk->is_mptcp =1 ; icsk->icsk_af_ops = &subflow_specific; + subflow->tcp_sk_data_ready = sk->sk_data_ready; + sk->sk_data_ready = subflow_data_ready; }return err;
Signature · 1 line
2.17.1