@@ -1698,7 +1698,10 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
1698
1698
1699
1699
lock_sock (ssk );
1700
1700
1701
+ msk -> connect_flags = (msg -> msg_flags & MSG_DONTWAIT ) ? O_NONBLOCK : 0 ;
1702
+ msk -> is_sendmsg = 1 ;
1701
1703
ret = tcp_sendmsg_fastopen (ssk , msg , & copied_syn , len , NULL );
1704
+ msk -> is_sendmsg = 0 ;
1702
1705
copied += copied_syn ;
1703
1706
if (ret == - EINPROGRESS && copied_syn > 0 ) {
1704
1707
/* reflect the new state on the MPTCP socket */
@@ -3507,10 +3510,73 @@ static int mptcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
3507
3510
return put_user (answ , (int __user * )arg );
3508
3511
}
3509
3512
3513
+ static void mptcp_subflow_early_fallback (struct mptcp_sock * msk ,
3514
+ struct mptcp_subflow_context * subflow )
3515
+ {
3516
+ subflow -> request_mptcp = 0 ;
3517
+ __mptcp_do_fallback (msk );
3518
+ }
3519
+
3520
+ static int mptcp_connect (struct sock * sk , struct sockaddr * uaddr , int addr_len )
3521
+ {
3522
+ struct mptcp_subflow_context * subflow ;
3523
+ struct mptcp_sock * msk = mptcp_sk (sk );
3524
+ struct socket * ssock ;
3525
+ int err = - EINVAL ;
3526
+
3527
+ ssock = __mptcp_nmpc_socket (msk );
3528
+ if (!ssock )
3529
+ return - EINVAL ;
3530
+
3531
+ mptcp_token_destroy (msk );
3532
+ inet_sk_state_store (sk , TCP_SYN_SENT );
3533
+ subflow = mptcp_subflow_ctx (ssock -> sk );
3534
+ #ifdef CONFIG_TCP_MD5SIG
3535
+ /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
3536
+ * TCP option space.
3537
+ */
3538
+ if (rcu_access_pointer (tcp_sk (ssock -> sk )-> md5sig_info ))
3539
+ mptcp_subflow_early_fallback (msk , subflow );
3540
+ #endif
3541
+ if (subflow -> request_mptcp && mptcp_token_new_connect (ssock -> sk )) {
3542
+ MPTCP_INC_STATS (sock_net (ssock -> sk ), MPTCP_MIB_TOKENFALLBACKINIT );
3543
+ mptcp_subflow_early_fallback (msk , subflow );
3544
+ }
3545
+ if (likely (!__mptcp_check_fallback (msk )))
3546
+ MPTCP_INC_STATS (sock_net (sk ), MPTCP_MIB_MPCAPABLEACTIVE );
3547
+
3548
+ /* if reaching here via the fastopen/sendmsg path, the caller already
3549
+ * acquired the subflow socket lock, too.
3550
+ */
3551
+ if (msk -> is_sendmsg )
3552
+ err = __inet_stream_connect (ssock , uaddr , addr_len , msk -> connect_flags , 1 );
3553
+ else
3554
+ err = inet_stream_connect (ssock , uaddr , addr_len , msk -> connect_flags );
3555
+ inet_sk (sk )-> defer_connect = inet_sk (ssock -> sk )-> defer_connect ;
3556
+
3557
+ /* on successful connect, the msk state will be moved to established by
3558
+ * subflow_finish_connect()
3559
+ */
3560
+ if (unlikely (err && err != - EINPROGRESS )) {
3561
+ inet_sk_state_store (sk , inet_sk_state_load (ssock -> sk ));
3562
+ return err ;
3563
+ }
3564
+
3565
+ mptcp_copy_inaddrs (sk , ssock -> sk );
3566
+
3567
+ /* unblocking connect, mptcp-level inet_stream_connect will error out
3568
+ * without changing the socket state, update it here.
3569
+ */
3570
+ if (err == - EINPROGRESS )
3571
+ sk -> sk_socket -> state = ssock -> state ;
3572
+ return err ;
3573
+ }
3574
+
3510
3575
static struct proto mptcp_prot = {
3511
3576
.name = "MPTCP" ,
3512
3577
.owner = THIS_MODULE ,
3513
3578
.init = mptcp_init_sock ,
3579
+ .connect = mptcp_connect ,
3514
3580
.disconnect = mptcp_disconnect ,
3515
3581
.close = mptcp_close ,
3516
3582
.accept = mptcp_accept ,
@@ -3562,78 +3628,16 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
3562
3628
return err ;
3563
3629
}
3564
3630
3565
- static void mptcp_subflow_early_fallback (struct mptcp_sock * msk ,
3566
- struct mptcp_subflow_context * subflow )
3567
- {
3568
- subflow -> request_mptcp = 0 ;
3569
- __mptcp_do_fallback (msk );
3570
- }
3571
-
3572
3631
static int mptcp_stream_connect (struct socket * sock , struct sockaddr * uaddr ,
3573
3632
int addr_len , int flags )
3574
3633
{
3575
- struct mptcp_sock * msk = mptcp_sk (sock -> sk );
3576
- struct mptcp_subflow_context * subflow ;
3577
- struct socket * ssock ;
3578
- int err = - EINVAL ;
3634
+ int ret ;
3579
3635
3580
3636
lock_sock (sock -> sk );
3581
- if (uaddr ) {
3582
- if (addr_len < sizeof (uaddr -> sa_family ))
3583
- goto unlock ;
3584
-
3585
- if (uaddr -> sa_family == AF_UNSPEC ) {
3586
- err = mptcp_disconnect (sock -> sk , flags );
3587
- sock -> state = err ? SS_DISCONNECTING : SS_UNCONNECTED ;
3588
- goto unlock ;
3589
- }
3590
- }
3591
-
3592
- if (sock -> state != SS_UNCONNECTED && msk -> subflow ) {
3593
- /* pending connection or invalid state, let existing subflow
3594
- * cope with that
3595
- */
3596
- ssock = msk -> subflow ;
3597
- goto do_connect ;
3598
- }
3599
-
3600
- ssock = __mptcp_nmpc_socket (msk );
3601
- if (!ssock )
3602
- goto unlock ;
3603
-
3604
- mptcp_token_destroy (msk );
3605
- inet_sk_state_store (sock -> sk , TCP_SYN_SENT );
3606
- subflow = mptcp_subflow_ctx (ssock -> sk );
3607
- #ifdef CONFIG_TCP_MD5SIG
3608
- /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
3609
- * TCP option space.
3610
- */
3611
- if (rcu_access_pointer (tcp_sk (ssock -> sk )-> md5sig_info ))
3612
- mptcp_subflow_early_fallback (msk , subflow );
3613
- #endif
3614
- if (subflow -> request_mptcp && mptcp_token_new_connect (ssock -> sk )) {
3615
- MPTCP_INC_STATS (sock_net (ssock -> sk ), MPTCP_MIB_TOKENFALLBACKINIT );
3616
- mptcp_subflow_early_fallback (msk , subflow );
3617
- }
3618
- if (likely (!__mptcp_check_fallback (msk )))
3619
- MPTCP_INC_STATS (sock_net (sock -> sk ), MPTCP_MIB_MPCAPABLEACTIVE );
3620
-
3621
- do_connect :
3622
- err = ssock -> ops -> connect (ssock , uaddr , addr_len , flags );
3623
- inet_sk (sock -> sk )-> defer_connect = inet_sk (ssock -> sk )-> defer_connect ;
3624
- sock -> state = ssock -> state ;
3625
-
3626
- /* on successful connect, the msk state will be moved to established by
3627
- * subflow_finish_connect()
3628
- */
3629
- if (!err || err == - EINPROGRESS )
3630
- mptcp_copy_inaddrs (sock -> sk , ssock -> sk );
3631
- else
3632
- inet_sk_state_store (sock -> sk , inet_sk_state_load (ssock -> sk ));
3633
-
3634
- unlock :
3637
+ mptcp_sk (sock -> sk )-> connect_flags = flags ;
3638
+ ret = __inet_stream_connect (sock , uaddr , addr_len , flags , 0 );
3635
3639
release_sock (sock -> sk );
3636
- return err ;
3640
+ return ret ;
3637
3641
}
3638
3642
3639
3643
static int mptcp_listen (struct socket * sock , int backlog )
0 commit comments