2020-01-22 08:56:15 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Multipath TCP
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 - 2019, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MPTCP_PROTOCOL_H
|
|
|
|
#define __MPTCP_PROTOCOL_H
|
|
|
|
|
2020-01-22 08:56:20 +08:00
|
|
|
#include <linux/random.h>
|
|
|
|
#include <net/tcp.h>
|
|
|
|
#include <net/inet_connection_sock.h>
|
|
|
|
|
2020-01-22 08:56:31 +08:00
|
|
|
#define MPTCP_SUPPORTED_VERSION 1
|
2020-01-22 08:56:16 +08:00
|
|
|
|
|
|
|
/* MPTCP option bits */
|
|
|
|
#define OPTION_MPTCP_MPC_SYN BIT(0)
|
|
|
|
#define OPTION_MPTCP_MPC_SYNACK BIT(1)
|
|
|
|
#define OPTION_MPTCP_MPC_ACK BIT(2)
|
2020-03-28 05:48:39 +08:00
|
|
|
#define OPTION_MPTCP_MPJ_SYN BIT(3)
|
|
|
|
#define OPTION_MPTCP_MPJ_SYNACK BIT(4)
|
|
|
|
#define OPTION_MPTCP_MPJ_ACK BIT(5)
|
2020-03-28 05:48:37 +08:00
|
|
|
#define OPTION_MPTCP_ADD_ADDR BIT(6)
|
|
|
|
#define OPTION_MPTCP_ADD_ADDR6 BIT(7)
|
|
|
|
#define OPTION_MPTCP_RM_ADDR BIT(8)
|
2020-01-22 08:56:16 +08:00
|
|
|
|
|
|
|
/* 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 */
|
2020-01-22 08:56:31 +08:00
|
|
|
#define TCPOLEN_MPTCP_MPC_SYN 4
|
2020-01-22 08:56:16 +08:00
|
|
|
#define TCPOLEN_MPTCP_MPC_SYNACK 12
|
|
|
|
#define TCPOLEN_MPTCP_MPC_ACK 20
|
2020-01-22 08:56:31 +08:00
|
|
|
#define TCPOLEN_MPTCP_MPC_ACK_DATA 22
|
2020-03-28 05:48:39 +08:00
|
|
|
#define TCPOLEN_MPTCP_MPJ_SYN 12
|
|
|
|
#define TCPOLEN_MPTCP_MPJ_SYNACK 16
|
|
|
|
#define TCPOLEN_MPTCP_MPJ_ACK 24
|
2020-01-22 08:56:23 +08:00
|
|
|
#define TCPOLEN_MPTCP_DSS_BASE 4
|
2020-01-22 08:56:24 +08:00
|
|
|
#define TCPOLEN_MPTCP_DSS_ACK32 4
|
2020-01-22 08:56:23 +08:00
|
|
|
#define TCPOLEN_MPTCP_DSS_ACK64 8
|
2020-01-22 08:56:24 +08:00
|
|
|
#define TCPOLEN_MPTCP_DSS_MAP32 10
|
2020-01-22 08:56:23 +08:00
|
|
|
#define TCPOLEN_MPTCP_DSS_MAP64 14
|
|
|
|
#define TCPOLEN_MPTCP_DSS_CHECKSUM 2
|
2020-03-28 05:48:37 +08:00
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR 16
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR_PORT 18
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR_BASE 8
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR6 28
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20
|
|
|
|
#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22
|
|
|
|
#define TCPOLEN_MPTCP_PORT_LEN 2
|
|
|
|
#define TCPOLEN_MPTCP_RM_ADDR_BASE 4
|
2020-01-22 08:56:16 +08:00
|
|
|
|
2020-03-28 05:48:40 +08:00
|
|
|
/* MPTCP MP_JOIN flags */
|
2020-03-28 05:48:39 +08:00
|
|
|
#define MPTCPOPT_BACKUP BIT(0)
|
|
|
|
#define MPTCPOPT_HMAC_LEN 20
|
2020-03-28 05:48:40 +08:00
|
|
|
#define MPTCPOPT_THMAC_LEN 8
|
2020-03-28 05:48:39 +08:00
|
|
|
|
2020-01-22 08:56:16 +08:00
|
|
|
/* MPTCP MP_CAPABLE flags */
|
|
|
|
#define MPTCP_VERSION_MASK (0x0F)
|
|
|
|
#define MPTCP_CAP_CHECKSUM_REQD BIT(7)
|
|
|
|
#define MPTCP_CAP_EXTENSIBILITY BIT(6)
|
2020-01-22 08:56:30 +08:00
|
|
|
#define MPTCP_CAP_HMAC_SHA256 BIT(0)
|
2020-01-22 08:56:16 +08:00
|
|
|
#define MPTCP_CAP_FLAG_MASK (0x3F)
|
|
|
|
|
2020-01-22 08:56:23 +08:00
|
|
|
/* 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)
|
2020-01-22 08:56:24 +08:00
|
|
|
#define MPTCP_DSS_FLAG_MASK (0x1F)
|
|
|
|
|
2020-03-28 05:48:37 +08:00
|
|
|
/* MPTCP ADD_ADDR flags */
|
|
|
|
#define MPTCP_ADDR_ECHO BIT(0)
|
|
|
|
#define MPTCP_ADDR_IPVERSION_4 4
|
|
|
|
#define MPTCP_ADDR_IPVERSION_6 6
|
|
|
|
|
2020-01-22 08:56:24 +08:00
|
|
|
/* MPTCP socket flags */
|
2020-02-17 23:54:38 +08:00
|
|
|
#define MPTCP_DATA_READY 0
|
|
|
|
#define MPTCP_SEND_SPACE 1
|
2020-03-28 05:48:48 +08:00
|
|
|
#define MPTCP_WORK_RTX 2
|
2020-04-02 19:44:52 +08:00
|
|
|
#define MPTCP_WORK_EOF 3
|
2020-06-30 04:26:20 +08:00
|
|
|
#define MPTCP_FALLBACK_DONE 4
|
2020-10-10 01:00:01 +08:00
|
|
|
#define MPTCP_WORK_CLOSE_SUBFLOW 5
|
2020-01-22 08:56:23 +08:00
|
|
|
|
mptcp: move option parsing into mptcp_incoming_options()
The mptcp_options_received structure carries several per
packet flags (mp_capable, mp_join, etc.). Such fields must
be cleared on each packet, even on dropped ones or packet
not carrying any MPTCP options, but the current mptcp
code clears them only on TCP option reset.
On several races/corner cases we end-up with stray bits in
incoming options, leading to WARN_ON splats. e.g.:
[ 171.164906] Bad mapping: ssn=32714 map_seq=1 map_data_len=32713
[ 171.165006] WARNING: CPU: 1 PID: 5026 at net/mptcp/subflow.c:533 warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.167632] Modules linked in: ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel geneve ip6_udp_tunnel udp_tunnel macsec macvtap tap ipvlan macvlan 8021q garp mrp xfrm_interface veth netdevsim nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun binfmt_misc intel_rapl_msr intel_rapl_common rfkill kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel joydev virtio_balloon pcspkr i2c_piix4 sunrpc ip_tables xfs libcrc32c crc32c_intel serio_raw virtio_console ata_generic virtio_blk virtio_net net_failover failover ata_piix libata
[ 171.199464] CPU: 1 PID: 5026 Comm: repro Not tainted 5.7.0-rc1.mptcp_f227fdf5d388+ #95
[ 171.200886] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-2.fc30 04/01/2014
[ 171.202546] RIP: 0010:warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.206537] Code: c1 ea 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 04 84 d2 75 1d 8b 55 3c 44 89 e6 48 c7 c7 20 51 13 95 e8 37 8b 22 fe <0f> 0b 48 83 c4 08 5b 5d 41 5c c3 89 4c 24 04 e8 db d6 94 fe 8b 4c
[ 171.220473] RSP: 0018:ffffc90000150560 EFLAGS: 00010282
[ 171.221639] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 171.223108] RDX: 0000000000000000 RSI: 0000000000000008 RDI: fffff5200002a09e
[ 171.224388] RBP: ffff8880aa6e3c00 R08: 0000000000000001 R09: fffffbfff2ec9955
[ 171.225706] R10: ffffffff9764caa7 R11: fffffbfff2ec9954 R12: 0000000000007fca
[ 171.227211] R13: ffff8881066f4a7f R14: ffff8880aa6e3c00 R15: 0000000000000020
[ 171.228460] FS: 00007f8623719740(0000) GS:ffff88810be00000(0000) knlGS:0000000000000000
[ 171.230065] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 171.231303] CR2: 00007ffdab190a50 CR3: 00000001038ea006 CR4: 0000000000160ee0
[ 171.232586] Call Trace:
[ 171.233109] <IRQ>
[ 171.233531] get_mapping_status (linux-mptcp/net/mptcp/subflow.c:691)
[ 171.234371] mptcp_subflow_data_available (linux-mptcp/net/mptcp/subflow.c:736 linux-mptcp/net/mptcp/subflow.c:832)
[ 171.238181] subflow_state_change (linux-mptcp/net/mptcp/subflow.c:1085 (discriminator 1))
[ 171.239066] tcp_fin (linux-mptcp/net/ipv4/tcp_input.c:4217)
[ 171.240123] tcp_data_queue (linux-mptcp/./include/linux/compiler.h:199 linux-mptcp/net/ipv4/tcp_input.c:4822)
[ 171.245083] tcp_rcv_established (linux-mptcp/./include/linux/skbuff.h:1785 linux-mptcp/./include/net/tcp.h:1774 linux-mptcp/./include/net/tcp.h:1847 linux-mptcp/net/ipv4/tcp_input.c:5238 linux-mptcp/net/ipv4/tcp_input.c:5730)
[ 171.254089] tcp_v4_rcv (linux-mptcp/./include/linux/spinlock.h:393 linux-mptcp/net/ipv4/tcp_ipv4.c:2009)
[ 171.258969] ip_protocol_deliver_rcu (linux-mptcp/net/ipv4/ip_input.c:204 (discriminator 1))
[ 171.260214] ip_local_deliver_finish (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/ipv4/ip_input.c:232)
[ 171.261389] ip_local_deliver (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:252)
[ 171.265884] ip_rcv (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:539)
[ 171.273666] process_backlog (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/core/dev.c:6135)
[ 171.275328] net_rx_action (linux-mptcp/net/core/dev.c:6572 linux-mptcp/net/core/dev.c:6640)
[ 171.280472] __do_softirq (linux-mptcp/./arch/x86/include/asm/jump_label.h:25 linux-mptcp/./include/linux/jump_label.h:200 linux-mptcp/./include/trace/events/irq.h:142 linux-mptcp/kernel/softirq.c:293)
[ 171.281379] do_softirq_own_stack (linux-mptcp/arch/x86/entry/entry_64.S:1083)
[ 171.282358] </IRQ>
We could address the issue clearing explicitly the relevant fields
in several places - tcp_parse_option, tcp_fast_parse_options,
possibly others.
Instead we move the MPTCP option parsing into the already existing
mptcp ingress hook, so that we need to clear the fields in a single
place.
This allows us dropping an MPTCP hook from the TCP code and
removing the quite large mptcp_options_received from the tcp_sock
struct. On the flip side, the MPTCP sockets will traverse the
option space twice (in tcp_parse_option() and in
mptcp_incoming_options(). That looks acceptable: we already
do that for syn and 3rd ack packets, plain TCP socket will
benefit from it, and even MPTCP sockets will experience better
code locality, reducing the jumps between TCP and MPTCP code.
v1 -> v2:
- rebased on current '-net' tree
Fixes: 648ef4b88673 ("mptcp: Implement MPTCP receive path")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-04-30 21:01:52 +08:00
|
|
|
struct mptcp_options_received {
|
|
|
|
u64 sndr_key;
|
|
|
|
u64 rcvr_key;
|
|
|
|
u64 data_ack;
|
|
|
|
u64 data_seq;
|
|
|
|
u32 subflow_seq;
|
|
|
|
u16 data_len;
|
|
|
|
u16 mp_capable : 1,
|
|
|
|
mp_join : 1,
|
|
|
|
dss : 1,
|
|
|
|
add_addr : 1,
|
|
|
|
rm_addr : 1,
|
|
|
|
family : 4,
|
|
|
|
echo : 1,
|
|
|
|
backup : 1;
|
|
|
|
u32 token;
|
|
|
|
u32 nonce;
|
|
|
|
u64 thmac;
|
|
|
|
u8 hmac[20];
|
|
|
|
u8 join_id;
|
|
|
|
u8 use_map:1,
|
|
|
|
dsn64:1,
|
|
|
|
data_fin:1,
|
|
|
|
use_ack:1,
|
|
|
|
ack64:1,
|
|
|
|
mpc_map:1,
|
|
|
|
__unused:2;
|
|
|
|
u8 addr_id;
|
|
|
|
u8 rm_id;
|
|
|
|
union {
|
|
|
|
struct in_addr addr;
|
|
|
|
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
|
|
|
struct in6_addr addr6;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
u64 ahmac;
|
|
|
|
u16 port;
|
|
|
|
};
|
|
|
|
|
2020-03-28 05:48:37 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-28 05:48:38 +08:00
|
|
|
struct mptcp_addr_info {
|
|
|
|
sa_family_t family;
|
|
|
|
__be16 port;
|
|
|
|
u8 id;
|
2020-09-14 16:01:15 +08:00
|
|
|
u8 flags;
|
|
|
|
int ifindex;
|
2020-03-28 05:48:38 +08:00
|
|
|
union {
|
|
|
|
struct in_addr addr;
|
|
|
|
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
|
|
|
struct in6_addr addr6;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
enum mptcp_pm_status {
|
|
|
|
MPTCP_PM_ADD_ADDR_RECEIVED,
|
2020-09-24 08:29:49 +08:00
|
|
|
MPTCP_PM_RM_ADDR_RECEIVED,
|
2020-03-28 05:48:38 +08:00
|
|
|
MPTCP_PM_ESTABLISHED,
|
|
|
|
MPTCP_PM_SUBFLOW_ESTABLISHED,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mptcp_pm_data {
|
|
|
|
struct mptcp_addr_info local;
|
|
|
|
struct mptcp_addr_info remote;
|
2020-09-24 08:29:54 +08:00
|
|
|
struct list_head anno_list;
|
2020-03-28 05:48:38 +08:00
|
|
|
|
|
|
|
spinlock_t lock; /*protects the whole PM data */
|
|
|
|
|
2020-09-24 08:29:47 +08:00
|
|
|
bool add_addr_signal;
|
2020-09-24 08:29:48 +08:00
|
|
|
bool rm_addr_signal;
|
2020-03-28 05:48:38 +08:00
|
|
|
bool server_side;
|
|
|
|
bool work_pending;
|
|
|
|
bool accept_addr;
|
|
|
|
bool accept_subflow;
|
2020-09-24 08:29:50 +08:00
|
|
|
bool add_addr_echo;
|
2020-03-28 05:48:38 +08:00
|
|
|
u8 add_addr_signaled;
|
|
|
|
u8 add_addr_accepted;
|
|
|
|
u8 local_addr_used;
|
|
|
|
u8 subflows;
|
|
|
|
u8 add_addr_signal_max;
|
|
|
|
u8 add_addr_accept_max;
|
|
|
|
u8 local_addr_max;
|
|
|
|
u8 subflows_max;
|
|
|
|
u8 status;
|
2020-09-24 08:29:48 +08:00
|
|
|
u8 rm_id;
|
2020-03-28 05:48:38 +08:00
|
|
|
};
|
|
|
|
|
2020-03-28 05:48:43 +08:00
|
|
|
struct mptcp_data_frag {
|
|
|
|
struct list_head list;
|
|
|
|
u64 data_seq;
|
|
|
|
int data_len;
|
|
|
|
int offset;
|
|
|
|
int overhead;
|
|
|
|
struct page *page;
|
|
|
|
};
|
|
|
|
|
2020-01-22 08:56:15 +08:00
|
|
|
/* MPTCP connection sock */
|
|
|
|
struct mptcp_sock {
|
|
|
|
/* inet_connection_sock must be the first member */
|
|
|
|
struct inet_connection_sock sk;
|
2020-01-22 08:56:18 +08:00
|
|
|
u64 local_key;
|
|
|
|
u64 remote_key;
|
2020-01-22 08:56:23 +08:00
|
|
|
u64 write_seq;
|
|
|
|
u64 ack_seq;
|
2020-07-29 06:12:03 +08:00
|
|
|
u64 rcv_data_fin_seq;
|
2020-09-14 16:01:17 +08:00
|
|
|
struct sock *last_snd;
|
|
|
|
int snd_burst;
|
2020-03-28 05:48:42 +08:00
|
|
|
atomic64_t snd_una;
|
2020-03-28 05:48:44 +08:00
|
|
|
unsigned long timer_ival;
|
2020-01-22 08:56:20 +08:00
|
|
|
u32 token;
|
2020-01-22 08:56:24 +08:00
|
|
|
unsigned long flags;
|
2020-01-22 08:56:32 +08:00
|
|
|
bool can_ack;
|
2020-07-23 19:02:32 +08:00
|
|
|
bool fully_established;
|
2020-07-29 06:12:03 +08:00
|
|
|
bool rcv_data_fin;
|
2020-07-29 06:12:02 +08:00
|
|
|
bool snd_data_fin_enable;
|
2020-10-07 00:26:17 +08:00
|
|
|
bool use_64bit_ack; /* Set when we received a 64-bit DSN */
|
2020-03-28 05:48:40 +08:00
|
|
|
spinlock_t join_list_lock;
|
2020-02-26 17:14:47 +08:00
|
|
|
struct work_struct work;
|
2020-09-14 16:01:12 +08:00
|
|
|
struct sk_buff *ooo_last_skb;
|
|
|
|
struct rb_root out_of_order_queue;
|
2020-01-22 08:56:18 +08:00
|
|
|
struct list_head conn_list;
|
2020-03-28 05:48:43 +08:00
|
|
|
struct list_head rtx_queue;
|
2020-03-28 05:48:40 +08:00
|
|
|
struct list_head join_list;
|
2020-01-22 08:56:23 +08:00
|
|
|
struct skb_ext *cached_ext; /* for the next sendmsg */
|
2020-01-22 08:56:15 +08:00
|
|
|
struct socket *subflow; /* outgoing connect/listener/!mp_capable */
|
mptcp: cope with later TCP fallback
With MPTCP v1, passive connections can fallback to TCP after the
subflow becomes established:
syn + MP_CAPABLE ->
<- syn, ack + MP_CAPABLE
ack, seq = 3 ->
// OoO packet is accepted because in-sequence
// passive socket is created, is in ESTABLISHED
// status and tentatively as MP_CAPABLE
ack, seq = 2 ->
// no MP_CAPABLE opt, subflow should fallback to TCP
We can't use the 'subflow' socket fallback, as we don't have
it available for passive connection.
Instead, when the fallback is detected, replace the mptcp
socket with the underlying TCP subflow. Beyond covering
the above scenario, it makes a TCP fallback socket as efficient
as plain TCP ones.
Co-developed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Christoph Paasch <cpaasch@apple.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-01-22 08:56:33 +08:00
|
|
|
struct sock *first;
|
2020-03-28 05:48:38 +08:00
|
|
|
struct mptcp_pm_data pm;
|
2020-07-01 03:24:45 +08:00
|
|
|
struct {
|
|
|
|
u32 space; /* bytes copied in last measurement window */
|
|
|
|
u32 copied; /* bytes copied in this measurement window */
|
|
|
|
u64 time; /* start time of measurement window */
|
|
|
|
u64 rtt_us; /* last maximum rtt of subflows */
|
|
|
|
} rcvq_space;
|
2020-01-22 08:56:15 +08:00
|
|
|
};
|
|
|
|
|
2020-01-22 08:56:18 +08:00
|
|
|
#define mptcp_for_each_subflow(__msk, __subflow) \
|
|
|
|
list_for_each_entry(__subflow, &((__msk)->conn_list), node)
|
|
|
|
|
2020-01-22 08:56:15 +08:00
|
|
|
static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct mptcp_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2020-03-28 05:48:43 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-28 05:48:46 +08:00
|
|
|
static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk)
|
|
|
|
{
|
|
|
|
struct mptcp_sock *msk = mptcp_sk(sk);
|
|
|
|
|
2020-06-15 16:34:28 +08:00
|
|
|
return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list);
|
2020-03-28 05:48:46 +08:00
|
|
|
}
|
|
|
|
|
2020-01-22 08:56:18 +08:00
|
|
|
struct mptcp_subflow_request_sock {
|
|
|
|
struct tcp_request_sock sk;
|
2020-01-22 08:56:32 +08:00
|
|
|
u16 mp_capable : 1,
|
2020-01-22 08:56:18 +08:00
|
|
|
mp_join : 1,
|
2020-04-20 22:25:06 +08:00
|
|
|
backup : 1;
|
2020-03-28 05:48:38 +08:00
|
|
|
u8 local_id;
|
2020-03-28 05:48:39 +08:00
|
|
|
u8 remote_id;
|
2020-01-22 08:56:18 +08:00
|
|
|
u64 local_key;
|
2020-01-22 08:56:20 +08:00
|
|
|
u64 idsn;
|
|
|
|
u32 token;
|
2020-01-22 08:56:24 +08:00
|
|
|
u32 ssn_offset;
|
2020-03-28 05:48:39 +08:00
|
|
|
u64 thmac;
|
|
|
|
u32 local_nonce;
|
|
|
|
u32 remote_nonce;
|
2020-06-17 18:08:56 +08:00
|
|
|
struct mptcp_sock *msk;
|
2020-06-27 01:30:00 +08:00
|
|
|
struct hlist_nulls_node token_node;
|
2020-01-22 08:56:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct mptcp_subflow_request_sock *
|
|
|
|
mptcp_subflow_rsk(const struct request_sock *rsk)
|
|
|
|
{
|
|
|
|
return (struct mptcp_subflow_request_sock *)rsk;
|
|
|
|
}
|
|
|
|
|
2020-09-14 16:01:09 +08:00
|
|
|
enum mptcp_data_avail {
|
|
|
|
MPTCP_SUBFLOW_NODATA,
|
|
|
|
MPTCP_SUBFLOW_DATA_AVAIL,
|
|
|
|
MPTCP_SUBFLOW_OOO_DATA
|
|
|
|
};
|
|
|
|
|
2020-01-22 08:56:17 +08:00
|
|
|
/* MPTCP subflow context */
|
|
|
|
struct mptcp_subflow_context {
|
2020-01-22 08:56:18 +08:00
|
|
|
struct list_head node;/* conn_list of subflows */
|
|
|
|
u64 local_key;
|
|
|
|
u64 remote_key;
|
2020-01-22 08:56:20 +08:00
|
|
|
u64 idsn;
|
2020-01-22 08:56:24 +08:00
|
|
|
u64 map_seq;
|
2020-01-22 08:56:31 +08:00
|
|
|
u32 snd_isn;
|
2020-01-22 08:56:20 +08:00
|
|
|
u32 token;
|
2020-01-22 08:56:23 +08:00
|
|
|
u32 rel_write_seq;
|
2020-01-22 08:56:24 +08:00
|
|
|
u32 map_subflow_seq;
|
|
|
|
u32 ssn_offset;
|
|
|
|
u32 map_data_len;
|
2020-01-22 08:56:18 +08:00
|
|
|
u32 request_mptcp : 1, /* send MP_CAPABLE */
|
2020-03-28 05:48:40 +08:00
|
|
|
request_join : 1, /* send MP_JOIN */
|
|
|
|
request_bkup : 1,
|
2020-01-22 08:56:18 +08:00
|
|
|
mp_capable : 1, /* remote is MPTCP capable */
|
2020-03-28 05:48:39 +08:00
|
|
|
mp_join : 1, /* remote is JOINing */
|
2020-03-19 18:06:30 +08:00
|
|
|
fully_established : 1, /* path validated */
|
2020-03-28 05:48:39 +08:00
|
|
|
pm_notified : 1, /* PM hook called for established status */
|
2020-01-22 08:56:24 +08:00
|
|
|
conn_finished : 1,
|
|
|
|
map_valid : 1,
|
2020-01-22 08:56:32 +08:00
|
|
|
mpc_map : 1,
|
2020-03-28 05:48:39 +08:00
|
|
|
backup : 1,
|
2020-01-22 08:56:32 +08:00
|
|
|
rx_eof : 1,
|
|
|
|
can_ack : 1; /* only after processing the remote a key */
|
2020-09-14 16:01:09 +08:00
|
|
|
enum mptcp_data_avail data_avail;
|
2020-03-28 05:48:39 +08:00
|
|
|
u32 remote_nonce;
|
|
|
|
u64 thmac;
|
|
|
|
u32 local_nonce;
|
2020-03-28 05:48:40 +08:00
|
|
|
u32 remote_token;
|
|
|
|
u8 hmac[MPTCPOPT_HMAC_LEN];
|
2020-03-28 05:48:39 +08:00
|
|
|
u8 local_id;
|
|
|
|
u8 remote_id;
|
2020-01-22 08:56:24 +08:00
|
|
|
|
2020-01-22 08:56:17 +08:00
|
|
|
struct sock *tcp_sock; /* tcp sk backpointer */
|
|
|
|
struct sock *conn; /* parent mptcp_sock */
|
2020-01-22 08:56:18 +08:00
|
|
|
const struct inet_connection_sock_af_ops *icsk_af_ops;
|
2020-01-22 08:56:24 +08:00
|
|
|
void (*tcp_data_ready)(struct sock *sk);
|
|
|
|
void (*tcp_state_change)(struct sock *sk);
|
|
|
|
void (*tcp_write_space)(struct sock *sk);
|
|
|
|
|
2020-01-22 08:56:17 +08:00
|
|
|
struct rcu_head rcu;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct mptcp_subflow_context *
|
|
|
|
mptcp_subflow_ctx(const struct sock *sk)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
/* Use RCU on icsk_ulp_data only for sock diag code */
|
|
|
|
return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct sock *
|
|
|
|
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
|
|
|
|
{
|
|
|
|
return subflow->tcp_sock;
|
|
|
|
}
|
|
|
|
|
2020-01-22 08:56:24 +08:00
|
|
|
static inline u64
|
|
|
|
mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow)
|
|
|
|
{
|
|
|
|
return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq -
|
|
|
|
subflow->ssn_offset -
|
|
|
|
subflow->map_subflow_seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64
|
|
|
|
mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
|
|
|
|
{
|
|
|
|
return subflow->map_seq + mptcp_subflow_get_map_offset(subflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mptcp_is_enabled(struct net *net);
|
2020-07-23 19:02:32 +08:00
|
|
|
void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
|
|
|
|
struct mptcp_options_received *mp_opt);
|
2020-01-22 08:56:24 +08:00
|
|
|
bool mptcp_subflow_data_available(struct sock *sk);
|
2020-06-27 01:29:59 +08:00
|
|
|
void __init mptcp_subflow_init(void);
|
2020-09-24 08:29:49 +08:00
|
|
|
void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);
|
|
|
|
void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
|
|
|
|
struct mptcp_subflow_context *subflow,
|
|
|
|
long timeout);
|
2020-10-10 01:00:00 +08:00
|
|
|
void mptcp_subflow_reset(struct sock *ssk);
|
2020-03-28 05:48:40 +08:00
|
|
|
|
|
|
|
/* called with sk socket lock held */
|
2020-09-14 16:01:15 +08:00
|
|
|
int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
|
2020-03-28 05:48:40 +08:00
|
|
|
const struct mptcp_addr_info *remote);
|
2020-01-22 08:56:17 +08:00
|
|
|
int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
|
|
|
|
|
2020-01-22 08:56:24 +08:00
|
|
|
static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
|
|
|
|
struct mptcp_subflow_context *ctx)
|
|
|
|
{
|
|
|
|
sk->sk_data_ready = ctx->tcp_data_ready;
|
|
|
|
sk->sk_state_change = ctx->tcp_state_change;
|
|
|
|
sk->sk_write_space = ctx->tcp_write_space;
|
|
|
|
|
|
|
|
inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
|
|
|
|
}
|
|
|
|
|
2020-06-27 01:29:59 +08:00
|
|
|
void __init mptcp_proto_init(void);
|
2020-01-22 08:56:28 +08:00
|
|
|
#if IS_ENABLED(CONFIG_MPTCP_IPV6)
|
2020-06-27 01:29:59 +08:00
|
|
|
int __init mptcp_proto_v6_init(void);
|
2020-01-22 08:56:28 +08:00
|
|
|
#endif
|
2020-01-22 08:56:24 +08:00
|
|
|
|
2020-04-20 22:25:06 +08:00
|
|
|
struct sock *mptcp_sk_clone(const struct sock *sk,
|
mptcp: move option parsing into mptcp_incoming_options()
The mptcp_options_received structure carries several per
packet flags (mp_capable, mp_join, etc.). Such fields must
be cleared on each packet, even on dropped ones or packet
not carrying any MPTCP options, but the current mptcp
code clears them only on TCP option reset.
On several races/corner cases we end-up with stray bits in
incoming options, leading to WARN_ON splats. e.g.:
[ 171.164906] Bad mapping: ssn=32714 map_seq=1 map_data_len=32713
[ 171.165006] WARNING: CPU: 1 PID: 5026 at net/mptcp/subflow.c:533 warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.167632] Modules linked in: ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel geneve ip6_udp_tunnel udp_tunnel macsec macvtap tap ipvlan macvlan 8021q garp mrp xfrm_interface veth netdevsim nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun binfmt_misc intel_rapl_msr intel_rapl_common rfkill kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel joydev virtio_balloon pcspkr i2c_piix4 sunrpc ip_tables xfs libcrc32c crc32c_intel serio_raw virtio_console ata_generic virtio_blk virtio_net net_failover failover ata_piix libata
[ 171.199464] CPU: 1 PID: 5026 Comm: repro Not tainted 5.7.0-rc1.mptcp_f227fdf5d388+ #95
[ 171.200886] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-2.fc30 04/01/2014
[ 171.202546] RIP: 0010:warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.206537] Code: c1 ea 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 04 84 d2 75 1d 8b 55 3c 44 89 e6 48 c7 c7 20 51 13 95 e8 37 8b 22 fe <0f> 0b 48 83 c4 08 5b 5d 41 5c c3 89 4c 24 04 e8 db d6 94 fe 8b 4c
[ 171.220473] RSP: 0018:ffffc90000150560 EFLAGS: 00010282
[ 171.221639] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 171.223108] RDX: 0000000000000000 RSI: 0000000000000008 RDI: fffff5200002a09e
[ 171.224388] RBP: ffff8880aa6e3c00 R08: 0000000000000001 R09: fffffbfff2ec9955
[ 171.225706] R10: ffffffff9764caa7 R11: fffffbfff2ec9954 R12: 0000000000007fca
[ 171.227211] R13: ffff8881066f4a7f R14: ffff8880aa6e3c00 R15: 0000000000000020
[ 171.228460] FS: 00007f8623719740(0000) GS:ffff88810be00000(0000) knlGS:0000000000000000
[ 171.230065] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 171.231303] CR2: 00007ffdab190a50 CR3: 00000001038ea006 CR4: 0000000000160ee0
[ 171.232586] Call Trace:
[ 171.233109] <IRQ>
[ 171.233531] get_mapping_status (linux-mptcp/net/mptcp/subflow.c:691)
[ 171.234371] mptcp_subflow_data_available (linux-mptcp/net/mptcp/subflow.c:736 linux-mptcp/net/mptcp/subflow.c:832)
[ 171.238181] subflow_state_change (linux-mptcp/net/mptcp/subflow.c:1085 (discriminator 1))
[ 171.239066] tcp_fin (linux-mptcp/net/ipv4/tcp_input.c:4217)
[ 171.240123] tcp_data_queue (linux-mptcp/./include/linux/compiler.h:199 linux-mptcp/net/ipv4/tcp_input.c:4822)
[ 171.245083] tcp_rcv_established (linux-mptcp/./include/linux/skbuff.h:1785 linux-mptcp/./include/net/tcp.h:1774 linux-mptcp/./include/net/tcp.h:1847 linux-mptcp/net/ipv4/tcp_input.c:5238 linux-mptcp/net/ipv4/tcp_input.c:5730)
[ 171.254089] tcp_v4_rcv (linux-mptcp/./include/linux/spinlock.h:393 linux-mptcp/net/ipv4/tcp_ipv4.c:2009)
[ 171.258969] ip_protocol_deliver_rcu (linux-mptcp/net/ipv4/ip_input.c:204 (discriminator 1))
[ 171.260214] ip_local_deliver_finish (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/ipv4/ip_input.c:232)
[ 171.261389] ip_local_deliver (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:252)
[ 171.265884] ip_rcv (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:539)
[ 171.273666] process_backlog (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/core/dev.c:6135)
[ 171.275328] net_rx_action (linux-mptcp/net/core/dev.c:6572 linux-mptcp/net/core/dev.c:6640)
[ 171.280472] __do_softirq (linux-mptcp/./arch/x86/include/asm/jump_label.h:25 linux-mptcp/./include/linux/jump_label.h:200 linux-mptcp/./include/trace/events/irq.h:142 linux-mptcp/kernel/softirq.c:293)
[ 171.281379] do_softirq_own_stack (linux-mptcp/arch/x86/entry/entry_64.S:1083)
[ 171.282358] </IRQ>
We could address the issue clearing explicitly the relevant fields
in several places - tcp_parse_option, tcp_fast_parse_options,
possibly others.
Instead we move the MPTCP option parsing into the already existing
mptcp ingress hook, so that we need to clear the fields in a single
place.
This allows us dropping an MPTCP hook from the TCP code and
removing the quite large mptcp_options_received from the tcp_sock
struct. On the flip side, the MPTCP sockets will traverse the
option space twice (in tcp_parse_option() and in
mptcp_incoming_options(). That looks acceptable: we already
do that for syn and 3rd ack packets, plain TCP socket will
benefit from it, and even MPTCP sockets will experience better
code locality, reducing the jumps between TCP and MPTCP code.
v1 -> v2:
- rebased on current '-net' tree
Fixes: 648ef4b88673 ("mptcp: Implement MPTCP receive path")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-04-30 21:01:52 +08:00
|
|
|
const struct mptcp_options_received *mp_opt,
|
2020-04-20 22:25:06 +08:00
|
|
|
struct request_sock *req);
|
2020-01-22 08:56:18 +08:00
|
|
|
void mptcp_get_options(const struct sk_buff *skb,
|
mptcp: move option parsing into mptcp_incoming_options()
The mptcp_options_received structure carries several per
packet flags (mp_capable, mp_join, etc.). Such fields must
be cleared on each packet, even on dropped ones or packet
not carrying any MPTCP options, but the current mptcp
code clears them only on TCP option reset.
On several races/corner cases we end-up with stray bits in
incoming options, leading to WARN_ON splats. e.g.:
[ 171.164906] Bad mapping: ssn=32714 map_seq=1 map_data_len=32713
[ 171.165006] WARNING: CPU: 1 PID: 5026 at net/mptcp/subflow.c:533 warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.167632] Modules linked in: ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel geneve ip6_udp_tunnel udp_tunnel macsec macvtap tap ipvlan macvlan 8021q garp mrp xfrm_interface veth netdevsim nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun binfmt_misc intel_rapl_msr intel_rapl_common rfkill kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul ghash_clmulni_intel joydev virtio_balloon pcspkr i2c_piix4 sunrpc ip_tables xfs libcrc32c crc32c_intel serio_raw virtio_console ata_generic virtio_blk virtio_net net_failover failover ata_piix libata
[ 171.199464] CPU: 1 PID: 5026 Comm: repro Not tainted 5.7.0-rc1.mptcp_f227fdf5d388+ #95
[ 171.200886] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-2.fc30 04/01/2014
[ 171.202546] RIP: 0010:warn_bad_map (linux-mptcp/net/mptcp/subflow.c:533 linux-mptcp/net/mptcp/subflow.c:531)
[ 171.206537] Code: c1 ea 03 0f b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 04 84 d2 75 1d 8b 55 3c 44 89 e6 48 c7 c7 20 51 13 95 e8 37 8b 22 fe <0f> 0b 48 83 c4 08 5b 5d 41 5c c3 89 4c 24 04 e8 db d6 94 fe 8b 4c
[ 171.220473] RSP: 0018:ffffc90000150560 EFLAGS: 00010282
[ 171.221639] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 171.223108] RDX: 0000000000000000 RSI: 0000000000000008 RDI: fffff5200002a09e
[ 171.224388] RBP: ffff8880aa6e3c00 R08: 0000000000000001 R09: fffffbfff2ec9955
[ 171.225706] R10: ffffffff9764caa7 R11: fffffbfff2ec9954 R12: 0000000000007fca
[ 171.227211] R13: ffff8881066f4a7f R14: ffff8880aa6e3c00 R15: 0000000000000020
[ 171.228460] FS: 00007f8623719740(0000) GS:ffff88810be00000(0000) knlGS:0000000000000000
[ 171.230065] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 171.231303] CR2: 00007ffdab190a50 CR3: 00000001038ea006 CR4: 0000000000160ee0
[ 171.232586] Call Trace:
[ 171.233109] <IRQ>
[ 171.233531] get_mapping_status (linux-mptcp/net/mptcp/subflow.c:691)
[ 171.234371] mptcp_subflow_data_available (linux-mptcp/net/mptcp/subflow.c:736 linux-mptcp/net/mptcp/subflow.c:832)
[ 171.238181] subflow_state_change (linux-mptcp/net/mptcp/subflow.c:1085 (discriminator 1))
[ 171.239066] tcp_fin (linux-mptcp/net/ipv4/tcp_input.c:4217)
[ 171.240123] tcp_data_queue (linux-mptcp/./include/linux/compiler.h:199 linux-mptcp/net/ipv4/tcp_input.c:4822)
[ 171.245083] tcp_rcv_established (linux-mptcp/./include/linux/skbuff.h:1785 linux-mptcp/./include/net/tcp.h:1774 linux-mptcp/./include/net/tcp.h:1847 linux-mptcp/net/ipv4/tcp_input.c:5238 linux-mptcp/net/ipv4/tcp_input.c:5730)
[ 171.254089] tcp_v4_rcv (linux-mptcp/./include/linux/spinlock.h:393 linux-mptcp/net/ipv4/tcp_ipv4.c:2009)
[ 171.258969] ip_protocol_deliver_rcu (linux-mptcp/net/ipv4/ip_input.c:204 (discriminator 1))
[ 171.260214] ip_local_deliver_finish (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/ipv4/ip_input.c:232)
[ 171.261389] ip_local_deliver (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:252)
[ 171.265884] ip_rcv (linux-mptcp/./include/linux/netfilter.h:307 linux-mptcp/./include/linux/netfilter.h:301 linux-mptcp/net/ipv4/ip_input.c:539)
[ 171.273666] process_backlog (linux-mptcp/./include/linux/rcupdate.h:651 linux-mptcp/net/core/dev.c:6135)
[ 171.275328] net_rx_action (linux-mptcp/net/core/dev.c:6572 linux-mptcp/net/core/dev.c:6640)
[ 171.280472] __do_softirq (linux-mptcp/./arch/x86/include/asm/jump_label.h:25 linux-mptcp/./include/linux/jump_label.h:200 linux-mptcp/./include/trace/events/irq.h:142 linux-mptcp/kernel/softirq.c:293)
[ 171.281379] do_softirq_own_stack (linux-mptcp/arch/x86/entry/entry_64.S:1083)
[ 171.282358] </IRQ>
We could address the issue clearing explicitly the relevant fields
in several places - tcp_parse_option, tcp_fast_parse_options,
possibly others.
Instead we move the MPTCP option parsing into the already existing
mptcp ingress hook, so that we need to clear the fields in a single
place.
This allows us dropping an MPTCP hook from the TCP code and
removing the quite large mptcp_options_received from the tcp_sock
struct. On the flip side, the MPTCP sockets will traverse the
option space twice (in tcp_parse_option() and in
mptcp_incoming_options(). That looks acceptable: we already
do that for syn and 3rd ack packets, plain TCP socket will
benefit from it, and even MPTCP sockets will experience better
code locality, reducing the jumps between TCP and MPTCP code.
v1 -> v2:
- rebased on current '-net' tree
Fixes: 648ef4b88673 ("mptcp: Implement MPTCP receive path")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-04-30 21:01:52 +08:00
|
|
|
struct mptcp_options_received *mp_opt);
|
2020-01-22 08:56:18 +08:00
|
|
|
|
|
|
|
void mptcp_finish_connect(struct sock *sk);
|
2020-07-23 19:02:32 +08:00
|
|
|
static inline bool mptcp_is_fully_established(struct sock *sk)
|
|
|
|
{
|
|
|
|
return inet_sk_state_load(sk) == TCP_ESTABLISHED &&
|
|
|
|
READ_ONCE(mptcp_sk(sk)->fully_established);
|
|
|
|
}
|
2020-07-01 03:24:45 +08:00
|
|
|
void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk);
|
2020-02-26 17:14:51 +08:00
|
|
|
void mptcp_data_ready(struct sock *sk, struct sock *ssk);
|
2020-03-28 05:48:39 +08:00
|
|
|
bool mptcp_finish_join(struct sock *sk);
|
2020-03-28 05:48:44 +08:00
|
|
|
void mptcp_data_acked(struct sock *sk);
|
2020-04-02 19:44:52 +08:00
|
|
|
void mptcp_subflow_eof(struct sock *sk);
|
2020-09-30 06:08:20 +08:00
|
|
|
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit);
|
2020-09-24 08:29:57 +08:00
|
|
|
void mptcp_destroy_common(struct mptcp_sock *msk);
|
2020-01-22 08:56:18 +08:00
|
|
|
|
2020-06-27 01:30:00 +08:00
|
|
|
void __init mptcp_token_init(void);
|
|
|
|
static inline void mptcp_token_init_request(struct request_sock *req)
|
|
|
|
{
|
|
|
|
mptcp_subflow_rsk(req)->token_node.pprev = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-22 08:56:20 +08:00
|
|
|
int mptcp_token_new_request(struct request_sock *req);
|
2020-06-27 01:30:00 +08:00
|
|
|
void mptcp_token_destroy_request(struct request_sock *req);
|
2020-01-22 08:56:20 +08:00
|
|
|
int mptcp_token_new_connect(struct sock *sk);
|
2020-06-27 01:30:00 +08:00
|
|
|
void mptcp_token_accept(struct mptcp_subflow_request_sock *r,
|
|
|
|
struct mptcp_sock *msk);
|
2020-07-31 03:25:54 +08:00
|
|
|
bool mptcp_token_exists(u32 token);
|
2020-03-28 05:48:39 +08:00
|
|
|
struct mptcp_sock *mptcp_token_get_sock(u32 token);
|
2020-07-09 21:12:40 +08:00
|
|
|
struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
|
|
|
|
long *s_num);
|
2020-06-27 01:30:00 +08:00
|
|
|
void mptcp_token_destroy(struct mptcp_sock *msk);
|
2020-01-22 08:56:20 +08:00
|
|
|
|
|
|
|
void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
|
|
|
|
|
2020-03-28 05:48:37 +08:00
|
|
|
void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
|
2020-01-22 08:56:20 +08:00
|
|
|
|
2020-06-27 01:29:59 +08:00
|
|
|
void __init mptcp_pm_init(void);
|
2020-03-28 05:48:38 +08:00
|
|
|
void mptcp_pm_data_init(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side);
|
|
|
|
void mptcp_pm_fully_established(struct mptcp_sock *msk);
|
|
|
|
bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_connection_closed(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_subflow_established(struct mptcp_sock *msk,
|
|
|
|
struct mptcp_subflow_context *subflow);
|
|
|
|
void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id);
|
|
|
|
void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
|
|
|
|
const struct mptcp_addr_info *addr);
|
2020-09-24 08:29:49 +08:00
|
|
|
void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id);
|
2020-09-24 08:29:54 +08:00
|
|
|
void mptcp_pm_free_anno_list(struct mptcp_sock *msk);
|
2020-09-24 08:30:02 +08:00
|
|
|
struct mptcp_pm_add_entry *
|
|
|
|
mptcp_pm_del_add_timer(struct mptcp_sock *msk,
|
|
|
|
struct mptcp_addr_info *addr);
|
2020-03-28 05:48:38 +08:00
|
|
|
|
|
|
|
int mptcp_pm_announce_addr(struct mptcp_sock *msk,
|
2020-09-24 08:29:50 +08:00
|
|
|
const struct mptcp_addr_info *addr,
|
|
|
|
bool echo);
|
2020-03-28 05:48:38 +08:00
|
|
|
int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
|
2020-09-24 08:29:55 +08:00
|
|
|
int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
|
2020-03-28 05:48:38 +08:00
|
|
|
|
2020-09-24 08:29:47 +08:00
|
|
|
static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
|
2020-03-28 05:48:38 +08:00
|
|
|
{
|
2020-09-24 08:29:47 +08:00
|
|
|
return READ_ONCE(msk->pm.add_addr_signal);
|
2020-03-28 05:48:38 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 08:29:48 +08:00
|
|
|
static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
|
|
|
|
{
|
|
|
|
return READ_ONCE(msk->pm.rm_addr_signal);
|
|
|
|
}
|
|
|
|
|
2020-10-03 23:36:56 +08:00
|
|
|
static inline unsigned int mptcp_add_addr_len(int family, bool echo)
|
2020-03-28 05:48:38 +08:00
|
|
|
{
|
|
|
|
if (family == AF_INET)
|
2020-10-03 23:36:56 +08:00
|
|
|
return echo ? TCPOLEN_MPTCP_ADD_ADDR_BASE
|
|
|
|
: TCPOLEN_MPTCP_ADD_ADDR;
|
|
|
|
return echo ? TCPOLEN_MPTCP_ADD_ADDR6_BASE : TCPOLEN_MPTCP_ADD_ADDR6;
|
2020-03-28 05:48:38 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 08:29:47 +08:00
|
|
|
bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
|
2020-09-24 08:29:50 +08:00
|
|
|
struct mptcp_addr_info *saddr, bool *echo);
|
2020-09-24 08:29:48 +08:00
|
|
|
bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
|
|
|
|
u8 *rm_id);
|
2020-03-28 05:48:38 +08:00
|
|
|
int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
|
|
|
|
|
2020-06-27 01:29:59 +08:00
|
|
|
void __init mptcp_pm_nl_init(void);
|
2020-03-28 05:48:51 +08:00
|
|
|
void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
|
|
|
|
void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk);
|
2020-09-24 08:29:49 +08:00
|
|
|
void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk);
|
2020-09-24 08:29:55 +08:00
|
|
|
void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id);
|
2020-03-28 05:48:51 +08:00
|
|
|
int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
|
|
|
|
|
2020-01-22 08:56:23 +08:00
|
|
|
static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
|
|
|
|
}
|
|
|
|
|
2020-01-22 08:56:24 +08:00
|
|
|
static inline bool before64(__u64 seq1, __u64 seq2)
|
|
|
|
{
|
|
|
|
return (__s64)(seq1 - seq2) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define after64(seq2, seq1) before64(seq1, seq2)
|
|
|
|
|
2020-03-28 05:48:49 +08:00
|
|
|
void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops);
|
|
|
|
|
2020-09-14 16:01:17 +08:00
|
|
|
static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk)
|
2020-06-30 04:26:20 +08:00
|
|
|
{
|
|
|
|
return test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
|
|
|
|
}
|
|
|
|
|
2020-09-14 16:01:17 +08:00
|
|
|
static inline bool mptcp_check_fallback(const struct sock *sk)
|
2020-06-30 04:26:20 +08:00
|
|
|
{
|
|
|
|
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
|
|
|
|
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
|
|
|
|
|
|
|
|
return __mptcp_check_fallback(msk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __mptcp_do_fallback(struct mptcp_sock *msk)
|
|
|
|
{
|
|
|
|
if (test_bit(MPTCP_FALLBACK_DONE, &msk->flags)) {
|
|
|
|
pr_debug("TCP fallback already done (msk=%p)", msk);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mptcp_do_fallback(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
|
|
|
|
struct mptcp_sock *msk = mptcp_sk(subflow->conn);
|
|
|
|
|
|
|
|
__mptcp_do_fallback(msk);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define pr_fallback(a) pr_debug("%s:fallback to TCP (msk=%p)", __func__, a)
|
|
|
|
|
mptcp: fallback in case of simultaneous connect
when a MPTCP client tries to connect to itself, tcp_finish_connect() is
never reached. Because of this, depending on the socket current state,
multiple faulty behaviours can be observed:
1) a WARN_ON() in subflow_data_ready() is hit
WARNING: CPU: 2 PID: 882 at net/mptcp/subflow.c:911 subflow_data_ready+0x18b/0x230
[...]
CPU: 2 PID: 882 Comm: gh35 Not tainted 5.7.0+ #187
[...]
RIP: 0010:subflow_data_ready+0x18b/0x230
[...]
Call Trace:
tcp_data_queue+0xd2f/0x4250
tcp_rcv_state_process+0xb1c/0x49d3
tcp_v4_do_rcv+0x2bc/0x790
__release_sock+0x153/0x2d0
release_sock+0x4f/0x170
mptcp_shutdown+0x167/0x4e0
__sys_shutdown+0xe6/0x180
__x64_sys_shutdown+0x50/0x70
do_syscall_64+0x9a/0x370
entry_SYSCALL_64_after_hwframe+0x44/0xa9
2) client is stuck forever in mptcp_sendmsg() because the socket is not
TCP_ESTABLISHED
crash> bt 4847
PID: 4847 TASK: ffff88814b2fb100 CPU: 1 COMMAND: "gh35"
#0 [ffff8881376ff680] __schedule at ffffffff97248da4
#1 [ffff8881376ff778] schedule at ffffffff9724a34f
#2 [ffff8881376ff7a0] schedule_timeout at ffffffff97252ba0
#3 [ffff8881376ff8a8] wait_woken at ffffffff958ab4ba
#4 [ffff8881376ff940] sk_stream_wait_connect at ffffffff96c2d859
#5 [ffff8881376ffa28] mptcp_sendmsg at ffffffff97207fca
#6 [ffff8881376ffbc0] sock_sendmsg at ffffffff96be1b5b
#7 [ffff8881376ffbe8] sock_write_iter at ffffffff96be1daa
#8 [ffff8881376ffce8] new_sync_write at ffffffff95e5cb52
#9 [ffff8881376ffe50] vfs_write at ffffffff95e6547f
#10 [ffff8881376ffe90] ksys_write at ffffffff95e65d26
#11 [ffff8881376fff28] do_syscall_64 at ffffffff956088ba
#12 [ffff8881376fff50] entry_SYSCALL_64_after_hwframe at ffffffff9740008c
RIP: 00007f126f6956ed RSP: 00007ffc2a320278 RFLAGS: 00000217
RAX: ffffffffffffffda RBX: 0000000020000044 RCX: 00007f126f6956ed
RDX: 0000000000000004 RSI: 00000000004007b8 RDI: 0000000000000003
RBP: 00007ffc2a3202a0 R8: 0000000000400720 R9: 0000000000400720
R10: 0000000000400720 R11: 0000000000000217 R12: 00000000004004b0
R13: 00007ffc2a320380 R14: 0000000000000000 R15: 0000000000000000
ORIG_RAX: 0000000000000001 CS: 0033 SS: 002b
3) tcpdump captures show that DSS is exchanged even when MP_CAPABLE handshake
didn't complete.
$ tcpdump -tnnr bad.pcap
IP 127.0.0.1.20000 > 127.0.0.1.20000: Flags [S], seq 3208913911, win 65483, options [mss 65495,sackOK,TS val 3291706876 ecr 3291694721,nop,wscale 7,mptcp capable v1], length 0
IP 127.0.0.1.20000 > 127.0.0.1.20000: Flags [S.], seq 3208913911, ack 3208913912, win 65483, options [mss 65495,sackOK,TS val 3291706876 ecr 3291706876,nop,wscale 7,mptcp capable v1], length 0
IP 127.0.0.1.20000 > 127.0.0.1.20000: Flags [.], ack 1, win 512, options [nop,nop,TS val 3291706876 ecr 3291706876], length 0
IP 127.0.0.1.20000 > 127.0.0.1.20000: Flags [F.], seq 1, ack 1, win 512, options [nop,nop,TS val 3291707876 ecr 3291706876,mptcp dss fin seq 0 subseq 0 len 1,nop,nop], length 0
IP 127.0.0.1.20000 > 127.0.0.1.20000: Flags [.], ack 2, win 512, options [nop,nop,TS val 3291707876 ecr 3291707876], length 0
force a fallback to TCP in these cases, and adjust the main socket
state to avoid hanging in mptcp_sendmsg().
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/35
Reported-by: Christoph Paasch <cpaasch@apple.com>
Suggested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Reviewed-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-06-30 04:26:21 +08:00
|
|
|
static inline bool subflow_simultaneous_connect(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
|
|
|
|
struct sock *parent = subflow->conn;
|
|
|
|
|
|
|
|
return sk->sk_state == TCP_ESTABLISHED &&
|
|
|
|
!mptcp_sk(parent)->pm.server_side &&
|
|
|
|
!subflow->conn_finished;
|
|
|
|
}
|
|
|
|
|
2020-07-31 03:25:56 +08:00
|
|
|
#ifdef CONFIG_SYN_COOKIES
|
|
|
|
void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
|
|
|
|
struct sk_buff *skb);
|
|
|
|
bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
|
|
|
|
struct sk_buff *skb);
|
|
|
|
void __init mptcp_join_cookie_init(void);
|
|
|
|
#else
|
|
|
|
static inline void
|
|
|
|
subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
|
|
|
|
struct sk_buff *skb) {}
|
|
|
|
static inline bool
|
|
|
|
mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mptcp_join_cookie_init(void) {}
|
|
|
|
#endif
|
|
|
|
|
2020-01-22 08:56:15 +08:00
|
|
|
#endif /* __MPTCP_PROTOCOL_H */
|