1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2021, Red Hat.
7 #define pr_fmt(fmt) "MPTCP: " fmt
9 #include <linux/kernel.h>
10 #include <linux/module.h>
12 #include <net/protocol.h>
14 #include <net/mptcp.h>
17 #define MIN_INFO_OPTLEN_SIZE 16
18 #define MIN_FULL_INFO_OPTLEN_SIZE 40
20 static struct sock
*__mptcp_tcp_fallback(struct mptcp_sock
*msk
)
24 if (likely(!__mptcp_check_fallback(msk
)))
30 static u32
sockopt_seq_reset(const struct sock
*sk
)
34 /* Highbits contain state. Allows to distinguish sockopt_seq
35 * of listener and established:
37 * sockopt(s0) - seq is 1
38 * s1 = accept(s0) - s1 inherits seq 1 if listener sk (s0)
39 * sockopt(s0) - seq increments to 2 on s0
40 * sockopt(s1) // seq increments to 2 on s1 (different option)
41 * new ssk completes join, inherits options from s0 // seq 2
42 * Needs sync from mptcp join logic, but ssk->seq == msk->seq
44 * Set High order bits to sk_state so ssk->seq == msk->seq test
48 return (u32
)sk
->sk_state
<< 24u;
51 static void sockopt_seq_inc(struct mptcp_sock
*msk
)
53 u32 seq
= (msk
->setsockopt_seq
+ 1) & 0x00ffffff;
55 msk
->setsockopt_seq
= sockopt_seq_reset((struct sock
*)msk
) + seq
;
58 static int mptcp_get_int_option(struct mptcp_sock
*msk
, sockptr_t optval
,
59 unsigned int optlen
, int *val
)
61 if (optlen
< sizeof(int))
64 if (copy_from_sockptr(val
, optval
, sizeof(*val
)))
70 static void mptcp_sol_socket_sync_intval(struct mptcp_sock
*msk
, int optname
, int val
)
72 struct mptcp_subflow_context
*subflow
;
73 struct sock
*sk
= (struct sock
*)msk
;
78 mptcp_for_each_subflow(msk
, subflow
) {
79 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
80 bool slow
= lock_sock_fast(ssk
);
84 sock_valbool_flag(ssk
, SOCK_DBG
, !!val
);
87 if (ssk
->sk_prot
->keepalive
)
88 ssk
->sk_prot
->keepalive(ssk
, !!val
);
89 sock_valbool_flag(ssk
, SOCK_KEEPOPEN
, !!val
);
92 WRITE_ONCE(ssk
->sk_priority
, val
);
96 ssk
->sk_userlocks
|= SOCK_SNDBUF_LOCK
;
97 WRITE_ONCE(ssk
->sk_sndbuf
, sk
->sk_sndbuf
);
98 mptcp_subflow_ctx(ssk
)->cached_sndbuf
= sk
->sk_sndbuf
;
102 ssk
->sk_userlocks
|= SOCK_RCVBUF_LOCK
;
103 WRITE_ONCE(ssk
->sk_rcvbuf
, sk
->sk_rcvbuf
);
106 if (READ_ONCE(ssk
->sk_mark
) != sk
->sk_mark
) {
107 WRITE_ONCE(ssk
->sk_mark
, sk
->sk_mark
);
111 case SO_INCOMING_CPU
:
112 WRITE_ONCE(ssk
->sk_incoming_cpu
, val
);
116 subflow
->setsockopt_seq
= msk
->setsockopt_seq
;
117 unlock_sock_fast(ssk
, slow
);
123 static int mptcp_sol_socket_intval(struct mptcp_sock
*msk
, int optname
, int val
)
125 sockptr_t optval
= KERNEL_SOCKPTR(&val
);
126 struct sock
*sk
= (struct sock
*)msk
;
129 ret
= sock_setsockopt(sk
->sk_socket
, SOL_SOCKET
, optname
,
130 optval
, sizeof(val
));
134 mptcp_sol_socket_sync_intval(msk
, optname
, val
);
138 static void mptcp_so_incoming_cpu(struct mptcp_sock
*msk
, int val
)
140 struct sock
*sk
= (struct sock
*)msk
;
142 WRITE_ONCE(sk
->sk_incoming_cpu
, val
);
144 mptcp_sol_socket_sync_intval(msk
, SO_INCOMING_CPU
, val
);
147 static int mptcp_setsockopt_sol_socket_tstamp(struct mptcp_sock
*msk
, int optname
, int val
)
149 sockptr_t optval
= KERNEL_SOCKPTR(&val
);
150 struct mptcp_subflow_context
*subflow
;
151 struct sock
*sk
= (struct sock
*)msk
;
154 ret
= sock_setsockopt(sk
->sk_socket
, SOL_SOCKET
, optname
,
155 optval
, sizeof(val
));
160 mptcp_for_each_subflow(msk
, subflow
) {
161 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
162 bool slow
= lock_sock_fast(ssk
);
164 sock_set_timestamp(sk
, optname
, !!val
);
165 unlock_sock_fast(ssk
, slow
);
172 static int mptcp_setsockopt_sol_socket_int(struct mptcp_sock
*msk
, int optname
,
178 ret
= mptcp_get_int_option(msk
, optval
, optlen
, &val
);
191 return mptcp_sol_socket_intval(msk
, optname
, val
);
192 case SO_INCOMING_CPU
:
193 mptcp_so_incoming_cpu(msk
, val
);
195 case SO_TIMESTAMP_OLD
:
196 case SO_TIMESTAMP_NEW
:
197 case SO_TIMESTAMPNS_OLD
:
198 case SO_TIMESTAMPNS_NEW
:
199 return mptcp_setsockopt_sol_socket_tstamp(msk
, optname
, val
);
205 static int mptcp_setsockopt_sol_socket_timestamping(struct mptcp_sock
*msk
,
210 struct mptcp_subflow_context
*subflow
;
211 struct sock
*sk
= (struct sock
*)msk
;
212 struct so_timestamping timestamping
;
215 if (optlen
== sizeof(timestamping
)) {
216 if (copy_from_sockptr(×tamping
, optval
,
217 sizeof(timestamping
)))
219 } else if (optlen
== sizeof(int)) {
220 memset(×tamping
, 0, sizeof(timestamping
));
222 if (copy_from_sockptr(×tamping
.flags
, optval
, sizeof(int)))
228 ret
= sock_setsockopt(sk
->sk_socket
, SOL_SOCKET
, optname
,
229 KERNEL_SOCKPTR(×tamping
),
230 sizeof(timestamping
));
236 mptcp_for_each_subflow(msk
, subflow
) {
237 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
238 bool slow
= lock_sock_fast(ssk
);
240 sock_set_timestamping(sk
, optname
, timestamping
);
241 unlock_sock_fast(ssk
, slow
);
249 static int mptcp_setsockopt_sol_socket_linger(struct mptcp_sock
*msk
, sockptr_t optval
,
252 struct mptcp_subflow_context
*subflow
;
253 struct sock
*sk
= (struct sock
*)msk
;
258 if (optlen
< sizeof(ling
))
261 if (copy_from_sockptr(&ling
, optval
, sizeof(ling
)))
264 kopt
= KERNEL_SOCKPTR(&ling
);
265 ret
= sock_setsockopt(sk
->sk_socket
, SOL_SOCKET
, SO_LINGER
, kopt
, sizeof(ling
));
270 sockopt_seq_inc(msk
);
271 mptcp_for_each_subflow(msk
, subflow
) {
272 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
273 bool slow
= lock_sock_fast(ssk
);
276 sock_reset_flag(ssk
, SOCK_LINGER
);
278 ssk
->sk_lingertime
= sk
->sk_lingertime
;
279 sock_set_flag(ssk
, SOCK_LINGER
);
282 subflow
->setsockopt_seq
= msk
->setsockopt_seq
;
283 unlock_sock_fast(ssk
, slow
);
290 static int mptcp_setsockopt_sol_socket(struct mptcp_sock
*msk
, int optname
,
291 sockptr_t optval
, unsigned int optlen
)
293 struct sock
*sk
= (struct sock
*)msk
;
300 case SO_BINDTODEVICE
:
301 case SO_BINDTOIFINDEX
:
303 ssk
= __mptcp_nmpc_sk(msk
);
309 ret
= sk_setsockopt(ssk
, SOL_SOCKET
, optname
, optval
, optlen
);
311 if (optname
== SO_REUSEPORT
)
312 sk
->sk_reuseport
= ssk
->sk_reuseport
;
313 else if (optname
== SO_REUSEADDR
)
314 sk
->sk_reuse
= ssk
->sk_reuse
;
315 else if (optname
== SO_BINDTODEVICE
)
316 sk
->sk_bound_dev_if
= ssk
->sk_bound_dev_if
;
317 else if (optname
== SO_BINDTOIFINDEX
)
318 sk
->sk_bound_dev_if
= ssk
->sk_bound_dev_if
;
329 case SO_INCOMING_CPU
:
331 case SO_TIMESTAMP_OLD
:
332 case SO_TIMESTAMP_NEW
:
333 case SO_TIMESTAMPNS_OLD
:
334 case SO_TIMESTAMPNS_NEW
:
335 return mptcp_setsockopt_sol_socket_int(msk
, optname
, optval
,
337 case SO_TIMESTAMPING_OLD
:
338 case SO_TIMESTAMPING_NEW
:
339 return mptcp_setsockopt_sol_socket_timestamping(msk
, optname
,
342 return mptcp_setsockopt_sol_socket_linger(msk
, optval
, optlen
);
344 case SO_RCVTIMEO_OLD
:
345 case SO_RCVTIMEO_NEW
:
346 case SO_SNDTIMEO_OLD
:
347 case SO_SNDTIMEO_NEW
:
349 case SO_PREFER_BUSY_POLL
:
350 case SO_BUSY_POLL_BUDGET
:
351 /* No need to copy: only relevant for msk */
352 return sock_setsockopt(sk
->sk_socket
, SOL_SOCKET
, optname
, optval
, optlen
);
363 case SO_SELECT_ERR_QUEUE
:
367 /* SO_OOBINLINE is not supported, let's avoid the related mess
368 * SO_ATTACH_FILTER, SO_ATTACH_BPF, SO_ATTACH_REUSEPORT_CBPF,
369 * SO_DETACH_REUSEPORT_BPF, SO_DETACH_FILTER, SO_LOCK_FILTER,
370 * we must be careful with subflows
372 * SO_ATTACH_REUSEPORT_EBPF is not supported, at it checks
373 * explicitly the sk_protocol field
375 * SO_PEEK_OFF is unsupported, as it is for plain TCP
376 * SO_MAX_PACING_RATE is unsupported, we must be careful with subflows
377 * SO_CNX_ADVICE is currently unsupported, could possibly be relevant,
378 * but likely needs careful design
380 * SO_ZEROCOPY is currently unsupported, TODO in sndmsg
381 * SO_TXTIME is currently unsupported
387 static int mptcp_setsockopt_v6(struct mptcp_sock
*msk
, int optname
,
388 sockptr_t optval
, unsigned int optlen
)
390 struct sock
*sk
= (struct sock
*)msk
;
391 int ret
= -EOPNOTSUPP
;
396 case IPV6_TRANSPARENT
:
399 ssk
= __mptcp_nmpc_sk(msk
);
405 ret
= tcp_setsockopt(ssk
, SOL_IPV6
, optname
, optval
, optlen
);
411 sockopt_seq_inc(msk
);
415 sk
->sk_ipv6only
= ssk
->sk_ipv6only
;
417 case IPV6_TRANSPARENT
:
418 inet_assign_bit(TRANSPARENT
, sk
,
419 inet_test_bit(TRANSPARENT
, ssk
));
422 inet_assign_bit(FREEBIND
, sk
,
423 inet_test_bit(FREEBIND
, ssk
));
434 static bool mptcp_supported_sockopt(int level
, int optname
)
436 if (level
== SOL_IP
) {
438 /* should work fine */
441 case IP_BIND_ADDRESS_NO_PORT
:
442 case IP_LOCAL_PORT_RANGE
:
444 /* the following are control cmsg related */
451 case IP_RECVORIGDSTADDR
:
453 case IP_RECVFRAGSIZE
:
455 /* common stuff that need some love */
458 case IP_MTU_DISCOVER
:
461 /* possibly less common may deserve some love */
464 /* the following is apparently a no-op for plain TCP */
465 case IP_RECVERR_RFC4884
:
469 /* IP_OPTIONS is not supported, needs subflow care */
470 /* IP_HDRINCL, IP_NODEFRAG are not supported, RAW specific */
471 /* IP_MULTICAST_TTL, IP_MULTICAST_LOOP, IP_UNICAST_IF,
472 * IP_ADD_MEMBERSHIP, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_MEMBERSHIP,
473 * IP_DROP_SOURCE_MEMBERSHIP, IP_BLOCK_SOURCE, IP_UNBLOCK_SOURCE,
474 * MCAST_JOIN_GROUP, MCAST_LEAVE_GROUP MCAST_JOIN_SOURCE_GROUP,
475 * MCAST_LEAVE_SOURCE_GROUP, MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE,
476 * MCAST_MSFILTER, IP_MULTICAST_ALL are not supported, better not deal
479 /* IP_IPSEC_POLICY, IP_XFRM_POLICY are nut supported, unrelated here */
482 if (level
== SOL_IPV6
) {
486 /* the following are control cmsg related */
487 case IPV6_RECVPKTINFO
:
488 case IPV6_2292PKTINFO
:
489 case IPV6_RECVHOPLIMIT
:
490 case IPV6_2292HOPLIMIT
:
493 case IPV6_RECVHOPOPTS
:
494 case IPV6_2292HOPOPTS
:
495 case IPV6_RECVDSTOPTS
:
496 case IPV6_2292DSTOPTS
:
497 case IPV6_RECVTCLASS
:
499 case IPV6_RECVPATHMTU
:
500 case IPV6_RECVORIGDSTADDR
:
501 case IPV6_RECVFRAGSIZE
:
503 /* the following ones need some love but are quite common */
505 case IPV6_TRANSPARENT
:
508 case IPV6_2292PKTOPTIONS
:
509 case IPV6_UNICAST_HOPS
:
510 case IPV6_MTU_DISCOVER
:
513 case IPV6_FLOWINFO_SEND
:
514 case IPV6_FLOWLABEL_MGR
:
515 case IPV6_MINHOPCOUNT
:
517 case IPV6_AUTOFLOWLABEL
:
519 /* the following one is a no-op for plain TCP */
520 case IPV6_RECVERR_RFC4884
:
524 /* IPV6_HOPOPTS, IPV6_RTHDRDSTOPTS, IPV6_RTHDR, IPV6_DSTOPTS are
527 /* IPV6_MULTICAST_HOPS, IPV6_MULTICAST_LOOP, IPV6_UNICAST_IF,
528 * IPV6_MULTICAST_IF, IPV6_ADDRFORM,
529 * IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_JOIN_ANYCAST,
530 * IPV6_LEAVE_ANYCAST, IPV6_MULTICAST_ALL, MCAST_JOIN_GROUP, MCAST_LEAVE_GROUP,
531 * MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP,
532 * MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE, MCAST_MSFILTER
533 * are not supported better not deal with mcast
535 /* IPV6_ROUTER_ALERT, IPV6_ROUTER_ALERT_ISOLATE are not supported, since are evil */
537 /* IPV6_IPSEC_POLICY, IPV6_XFRM_POLICY are not supported */
538 /* IPV6_ADDR_PREFERENCES is not supported, we must be careful with subflows */
541 if (level
== SOL_TCP
) {
543 /* the following are no-op or should work just fine */
544 case TCP_THIN_DUPACK
:
545 case TCP_DEFER_ACCEPT
:
547 /* the following need some love */
550 case TCP_THIN_LINEAR_TIMEOUTS
:
559 case TCP_WINDOW_CLAMP
:
561 case TCP_USER_TIMEOUT
:
563 case TCP_NOTSENT_LOWAT
:
567 case TCP_FASTOPEN_CONNECT
:
568 case TCP_FASTOPEN_KEY
:
569 case TCP_FASTOPEN_NO_COOKIE
:
573 /* TCP_MD5SIG, TCP_MD5SIG_EXT are not supported, MD5 is not compatible with MPTCP */
575 /* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS,
576 * TCP_REPAIR_WINDOW are not supported, better avoid this mess
582 static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock
*msk
, sockptr_t optval
,
585 struct mptcp_subflow_context
*subflow
;
586 struct sock
*sk
= (struct sock
*)msk
;
587 char name
[TCP_CA_NAME_MAX
];
594 ret
= strncpy_from_sockptr(name
, optval
,
595 min_t(long, TCP_CA_NAME_MAX
- 1, optlen
));
601 cap_net_admin
= ns_capable(sock_net(sk
)->user_ns
, CAP_NET_ADMIN
);
605 sockopt_seq_inc(msk
);
606 mptcp_for_each_subflow(msk
, subflow
) {
607 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
611 err
= tcp_set_congestion_control(ssk
, name
, true, cap_net_admin
);
612 if (err
< 0 && ret
== 0)
614 subflow
->setsockopt_seq
= msk
->setsockopt_seq
;
619 strscpy(msk
->ca_name
, name
, sizeof(msk
->ca_name
));
625 static int __mptcp_setsockopt_set_val(struct mptcp_sock
*msk
, int max
,
626 int (*set_val
)(struct sock
*, int),
627 int *msk_val
, int val
)
629 struct mptcp_subflow_context
*subflow
;
632 mptcp_for_each_subflow(msk
, subflow
) {
633 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
637 ret
= set_val(ssk
, val
);
644 sockopt_seq_inc(msk
);
650 static int __mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock
*msk
, int val
)
652 struct mptcp_subflow_context
*subflow
;
653 struct sock
*sk
= (struct sock
*)msk
;
655 sockopt_seq_inc(msk
);
657 mptcp_for_each_subflow(msk
, subflow
) {
658 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
661 __tcp_sock_set_cork(ssk
, !!val
);
665 mptcp_check_and_set_pending(sk
);
670 static int __mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock
*msk
, int val
)
672 struct mptcp_subflow_context
*subflow
;
673 struct sock
*sk
= (struct sock
*)msk
;
675 sockopt_seq_inc(msk
);
676 msk
->nodelay
= !!val
;
677 mptcp_for_each_subflow(msk
, subflow
) {
678 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
681 __tcp_sock_set_nodelay(ssk
, !!val
);
685 mptcp_check_and_set_pending(sk
);
689 static int mptcp_setsockopt_sol_ip_set(struct mptcp_sock
*msk
, int optname
,
690 sockptr_t optval
, unsigned int optlen
)
692 struct sock
*sk
= (struct sock
*)msk
;
696 err
= ip_setsockopt(sk
, SOL_IP
, optname
, optval
, optlen
);
702 ssk
= __mptcp_nmpc_sk(msk
);
710 inet_assign_bit(FREEBIND
, ssk
, inet_test_bit(FREEBIND
, sk
));
713 inet_assign_bit(TRANSPARENT
, ssk
,
714 inet_test_bit(TRANSPARENT
, sk
));
716 case IP_BIND_ADDRESS_NO_PORT
:
717 inet_assign_bit(BIND_ADDRESS_NO_PORT
, ssk
,
718 inet_test_bit(BIND_ADDRESS_NO_PORT
, sk
));
720 case IP_LOCAL_PORT_RANGE
:
721 WRITE_ONCE(inet_sk(ssk
)->local_port_range
,
722 READ_ONCE(inet_sk(sk
)->local_port_range
));
730 sockopt_seq_inc(msk
);
735 static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock
*msk
, int optname
,
736 sockptr_t optval
, unsigned int optlen
)
738 struct mptcp_subflow_context
*subflow
;
739 struct sock
*sk
= (struct sock
*)msk
;
742 err
= ip_setsockopt(sk
, SOL_IP
, optname
, optval
, optlen
);
748 sockopt_seq_inc(msk
);
749 val
= READ_ONCE(inet_sk(sk
)->tos
);
750 mptcp_for_each_subflow(msk
, subflow
) {
751 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
754 slow
= lock_sock_fast(ssk
);
755 __ip_sock_set_tos(ssk
, val
);
756 unlock_sock_fast(ssk
, slow
);
763 static int mptcp_setsockopt_v4(struct mptcp_sock
*msk
, int optname
,
764 sockptr_t optval
, unsigned int optlen
)
769 case IP_BIND_ADDRESS_NO_PORT
:
770 case IP_LOCAL_PORT_RANGE
:
771 return mptcp_setsockopt_sol_ip_set(msk
, optname
, optval
, optlen
);
773 return mptcp_setsockopt_v4_set_tos(msk
, optname
, optval
, optlen
);
779 static int mptcp_setsockopt_first_sf_only(struct mptcp_sock
*msk
, int level
, int optname
,
780 sockptr_t optval
, unsigned int optlen
)
782 struct sock
*sk
= (struct sock
*)msk
;
786 /* Limit to first subflow, before the connection establishment */
788 ssk
= __mptcp_nmpc_sk(msk
);
794 ret
= tcp_setsockopt(ssk
, level
, optname
, optval
, optlen
);
801 static int mptcp_setsockopt_sol_tcp(struct mptcp_sock
*msk
, int optname
,
802 sockptr_t optval
, unsigned int optlen
)
804 struct sock
*sk
= (void *)msk
;
811 return mptcp_setsockopt_sol_tcp_congestion(msk
, optval
, optlen
);
812 case TCP_DEFER_ACCEPT
:
813 /* See tcp.c: TCP_DEFER_ACCEPT does not fail */
814 mptcp_setsockopt_first_sf_only(msk
, SOL_TCP
, optname
, optval
, optlen
);
817 case TCP_FASTOPEN_CONNECT
:
818 case TCP_FASTOPEN_KEY
:
819 case TCP_FASTOPEN_NO_COOKIE
:
820 return mptcp_setsockopt_first_sf_only(msk
, SOL_TCP
, optname
,
824 ret
= mptcp_get_int_option(msk
, optval
, optlen
, &val
);
831 if (val
< 0 || val
> 1)
834 msk
->recvmsg_inq
= !!val
;
836 case TCP_NOTSENT_LOWAT
:
837 WRITE_ONCE(msk
->notsent_lowat
, val
);
838 mptcp_write_space(sk
);
841 ret
= __mptcp_setsockopt_sol_tcp_cork(msk
, val
);
844 ret
= __mptcp_setsockopt_sol_tcp_nodelay(msk
, val
);
847 ret
= __mptcp_setsockopt_set_val(msk
, MAX_TCP_KEEPIDLE
,
848 &tcp_sock_set_keepidle_locked
,
849 &msk
->keepalive_idle
, val
);
852 ret
= __mptcp_setsockopt_set_val(msk
, MAX_TCP_KEEPINTVL
,
853 &tcp_sock_set_keepintvl
,
854 &msk
->keepalive_intvl
, val
);
857 ret
= __mptcp_setsockopt_set_val(msk
, MAX_TCP_KEEPCNT
,
858 &tcp_sock_set_keepcnt
,
870 int mptcp_setsockopt(struct sock
*sk
, int level
, int optname
,
871 sockptr_t optval
, unsigned int optlen
)
873 struct mptcp_sock
*msk
= mptcp_sk(sk
);
876 pr_debug("msk=%p\n", msk
);
878 if (level
== SOL_SOCKET
)
879 return mptcp_setsockopt_sol_socket(msk
, optname
, optval
, optlen
);
881 if (!mptcp_supported_sockopt(level
, optname
))
884 /* @@ the meaning of setsockopt() when the socket is connected and
885 * there are multiple subflows is not yet defined. It is up to the
886 * MPTCP-level socket to configure the subflows until the subflow
887 * is in TCP fallback, when TCP socket options are passed through
888 * to the one remaining subflow.
891 ssk
= __mptcp_tcp_fallback(msk
);
894 return tcp_setsockopt(ssk
, level
, optname
, optval
, optlen
);
897 return mptcp_setsockopt_v4(msk
, optname
, optval
, optlen
);
899 if (level
== SOL_IPV6
)
900 return mptcp_setsockopt_v6(msk
, optname
, optval
, optlen
);
902 if (level
== SOL_TCP
)
903 return mptcp_setsockopt_sol_tcp(msk
, optname
, optval
, optlen
);
908 static int mptcp_getsockopt_first_sf_only(struct mptcp_sock
*msk
, int level
, int optname
,
909 char __user
*optval
, int __user
*optlen
)
911 struct sock
*sk
= (struct sock
*)msk
;
918 ret
= tcp_getsockopt(ssk
, level
, optname
, optval
, optlen
);
922 ssk
= __mptcp_nmpc_sk(msk
);
928 ret
= tcp_getsockopt(ssk
, level
, optname
, optval
, optlen
);
935 void mptcp_diag_fill_info(struct mptcp_sock
*msk
, struct mptcp_info
*info
)
937 struct sock
*sk
= (struct sock
*)msk
;
942 memset(info
, 0, sizeof(*info
));
944 info
->mptcpi_subflows
= READ_ONCE(msk
->pm
.subflows
);
945 info
->mptcpi_add_addr_signal
= READ_ONCE(msk
->pm
.add_addr_signaled
);
946 info
->mptcpi_add_addr_accepted
= READ_ONCE(msk
->pm
.add_addr_accepted
);
947 info
->mptcpi_local_addr_used
= READ_ONCE(msk
->pm
.local_addr_used
);
949 if (inet_sk_state_load(sk
) == TCP_LISTEN
)
952 /* The following limits only make sense for the in-kernel PM */
953 if (mptcp_pm_is_kernel(msk
)) {
954 info
->mptcpi_subflows_max
=
955 mptcp_pm_get_subflows_max(msk
);
956 info
->mptcpi_add_addr_signal_max
=
957 mptcp_pm_get_add_addr_signal_max(msk
);
958 info
->mptcpi_add_addr_accepted_max
=
959 mptcp_pm_get_add_addr_accept_max(msk
);
960 info
->mptcpi_local_addr_max
=
961 mptcp_pm_get_local_addr_max(msk
);
964 if (__mptcp_check_fallback(msk
))
965 flags
|= MPTCP_INFO_FLAG_FALLBACK
;
966 if (READ_ONCE(msk
->can_ack
))
967 flags
|= MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED
;
968 info
->mptcpi_flags
= flags
;
970 slow
= lock_sock_fast(sk
);
971 info
->mptcpi_csum_enabled
= READ_ONCE(msk
->csum_enabled
);
972 info
->mptcpi_token
= msk
->token
;
973 info
->mptcpi_write_seq
= msk
->write_seq
;
974 info
->mptcpi_retransmits
= inet_csk(sk
)->icsk_retransmits
;
975 info
->mptcpi_bytes_sent
= msk
->bytes_sent
;
976 info
->mptcpi_bytes_received
= msk
->bytes_received
;
977 info
->mptcpi_bytes_retrans
= msk
->bytes_retrans
;
978 info
->mptcpi_subflows_total
= info
->mptcpi_subflows
+
979 __mptcp_has_initial_subflow(msk
);
981 info
->mptcpi_last_data_sent
= jiffies_to_msecs(now
- msk
->last_data_sent
);
982 info
->mptcpi_last_data_recv
= jiffies_to_msecs(now
- msk
->last_data_recv
);
983 unlock_sock_fast(sk
, slow
);
986 info
->mptcpi_last_ack_recv
= jiffies_to_msecs(now
- msk
->last_ack_recv
);
987 info
->mptcpi_snd_una
= msk
->snd_una
;
988 info
->mptcpi_rcv_nxt
= msk
->ack_seq
;
989 info
->mptcpi_bytes_acked
= msk
->bytes_acked
;
990 mptcp_data_unlock(sk
);
992 EXPORT_SYMBOL_GPL(mptcp_diag_fill_info
);
994 static int mptcp_getsockopt_info(struct mptcp_sock
*msk
, char __user
*optval
, int __user
*optlen
)
996 struct mptcp_info m_info
;
999 if (get_user(len
, optlen
))
1002 /* When used only to check if a fallback to TCP happened. */
1006 len
= min_t(unsigned int, len
, sizeof(struct mptcp_info
));
1008 mptcp_diag_fill_info(msk
, &m_info
);
1010 if (put_user(len
, optlen
))
1013 if (copy_to_user(optval
, &m_info
, len
))
1019 static int mptcp_put_subflow_data(struct mptcp_subflow_data
*sfd
,
1020 char __user
*optval
,
1024 u32 copylen
= min_t(u32
, sfd
->size_subflow_data
, sizeof(*sfd
));
1027 copied
+= sfd
->size_subflow_data
;
1031 if (put_user(copied
, optlen
))
1034 if (copy_to_user(optval
, sfd
, copylen
))
1040 static int mptcp_get_subflow_data(struct mptcp_subflow_data
*sfd
,
1041 char __user
*optval
,
1046 if (get_user(len
, optlen
))
1049 /* if mptcp_subflow_data size is changed, need to adjust
1050 * this function to deal with programs using old version.
1052 BUILD_BUG_ON(sizeof(*sfd
) != MIN_INFO_OPTLEN_SIZE
);
1054 if (len
< MIN_INFO_OPTLEN_SIZE
)
1057 memset(sfd
, 0, sizeof(*sfd
));
1059 copylen
= min_t(unsigned int, len
, sizeof(*sfd
));
1060 if (copy_from_user(sfd
, optval
, copylen
))
1063 /* size_subflow_data is u32, but len is signed */
1064 if (sfd
->size_subflow_data
> INT_MAX
||
1065 sfd
->size_user
> INT_MAX
)
1068 if (sfd
->size_subflow_data
< MIN_INFO_OPTLEN_SIZE
||
1069 sfd
->size_subflow_data
> len
)
1072 if (sfd
->num_subflows
|| sfd
->size_kernel
)
1075 return len
- sfd
->size_subflow_data
;
1078 static int mptcp_getsockopt_tcpinfo(struct mptcp_sock
*msk
, char __user
*optval
,
1081 struct mptcp_subflow_context
*subflow
;
1082 struct sock
*sk
= (struct sock
*)msk
;
1083 unsigned int sfcount
= 0, copied
= 0;
1084 struct mptcp_subflow_data sfd
;
1085 char __user
*infoptr
;
1088 len
= mptcp_get_subflow_data(&sfd
, optval
, optlen
);
1092 sfd
.size_kernel
= sizeof(struct tcp_info
);
1093 sfd
.size_user
= min_t(unsigned int, sfd
.size_user
,
1094 sizeof(struct tcp_info
));
1096 infoptr
= optval
+ sfd
.size_subflow_data
;
1100 mptcp_for_each_subflow(msk
, subflow
) {
1101 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
1105 if (len
&& len
>= sfd
.size_user
) {
1106 struct tcp_info info
;
1108 tcp_get_info(ssk
, &info
);
1110 if (copy_to_user(infoptr
, &info
, sfd
.size_user
)) {
1115 infoptr
+= sfd
.size_user
;
1116 copied
+= sfd
.size_user
;
1117 len
-= sfd
.size_user
;
1123 sfd
.num_subflows
= sfcount
;
1125 if (mptcp_put_subflow_data(&sfd
, optval
, copied
, optlen
))
1131 static void mptcp_get_sub_addrs(const struct sock
*sk
, struct mptcp_subflow_addrs
*a
)
1133 const struct inet_sock
*inet
= inet_sk(sk
);
1135 memset(a
, 0, sizeof(*a
));
1137 if (sk
->sk_family
== AF_INET
) {
1138 a
->sin_local
.sin_family
= AF_INET
;
1139 a
->sin_local
.sin_port
= inet
->inet_sport
;
1140 a
->sin_local
.sin_addr
.s_addr
= inet
->inet_rcv_saddr
;
1142 if (!a
->sin_local
.sin_addr
.s_addr
)
1143 a
->sin_local
.sin_addr
.s_addr
= inet
->inet_saddr
;
1145 a
->sin_remote
.sin_family
= AF_INET
;
1146 a
->sin_remote
.sin_port
= inet
->inet_dport
;
1147 a
->sin_remote
.sin_addr
.s_addr
= inet
->inet_daddr
;
1148 #if IS_ENABLED(CONFIG_IPV6)
1149 } else if (sk
->sk_family
== AF_INET6
) {
1150 const struct ipv6_pinfo
*np
= inet6_sk(sk
);
1152 if (WARN_ON_ONCE(!np
))
1155 a
->sin6_local
.sin6_family
= AF_INET6
;
1156 a
->sin6_local
.sin6_port
= inet
->inet_sport
;
1158 if (ipv6_addr_any(&sk
->sk_v6_rcv_saddr
))
1159 a
->sin6_local
.sin6_addr
= np
->saddr
;
1161 a
->sin6_local
.sin6_addr
= sk
->sk_v6_rcv_saddr
;
1163 a
->sin6_remote
.sin6_family
= AF_INET6
;
1164 a
->sin6_remote
.sin6_port
= inet
->inet_dport
;
1165 a
->sin6_remote
.sin6_addr
= sk
->sk_v6_daddr
;
1170 static int mptcp_getsockopt_subflow_addrs(struct mptcp_sock
*msk
, char __user
*optval
,
1173 struct mptcp_subflow_context
*subflow
;
1174 struct sock
*sk
= (struct sock
*)msk
;
1175 unsigned int sfcount
= 0, copied
= 0;
1176 struct mptcp_subflow_data sfd
;
1177 char __user
*addrptr
;
1180 len
= mptcp_get_subflow_data(&sfd
, optval
, optlen
);
1184 sfd
.size_kernel
= sizeof(struct mptcp_subflow_addrs
);
1185 sfd
.size_user
= min_t(unsigned int, sfd
.size_user
,
1186 sizeof(struct mptcp_subflow_addrs
));
1188 addrptr
= optval
+ sfd
.size_subflow_data
;
1192 mptcp_for_each_subflow(msk
, subflow
) {
1193 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
1197 if (len
&& len
>= sfd
.size_user
) {
1198 struct mptcp_subflow_addrs a
;
1200 mptcp_get_sub_addrs(ssk
, &a
);
1202 if (copy_to_user(addrptr
, &a
, sfd
.size_user
)) {
1207 addrptr
+= sfd
.size_user
;
1208 copied
+= sfd
.size_user
;
1209 len
-= sfd
.size_user
;
1215 sfd
.num_subflows
= sfcount
;
1217 if (mptcp_put_subflow_data(&sfd
, optval
, copied
, optlen
))
1223 static int mptcp_get_full_info(struct mptcp_full_info
*mfi
,
1224 char __user
*optval
,
1229 BUILD_BUG_ON(offsetof(struct mptcp_full_info
, mptcp_info
) !=
1230 MIN_FULL_INFO_OPTLEN_SIZE
);
1232 if (get_user(len
, optlen
))
1235 if (len
< MIN_FULL_INFO_OPTLEN_SIZE
)
1238 memset(mfi
, 0, sizeof(*mfi
));
1239 if (copy_from_user(mfi
, optval
, MIN_FULL_INFO_OPTLEN_SIZE
))
1242 if (mfi
->size_tcpinfo_kernel
||
1243 mfi
->size_sfinfo_kernel
||
1247 if (mfi
->size_sfinfo_user
> INT_MAX
||
1248 mfi
->size_tcpinfo_user
> INT_MAX
)
1251 return len
- MIN_FULL_INFO_OPTLEN_SIZE
;
1254 static int mptcp_put_full_info(struct mptcp_full_info
*mfi
,
1255 char __user
*optval
,
1259 copylen
+= MIN_FULL_INFO_OPTLEN_SIZE
;
1260 if (put_user(copylen
, optlen
))
1263 if (copy_to_user(optval
, mfi
, copylen
))
1268 static int mptcp_getsockopt_full_info(struct mptcp_sock
*msk
, char __user
*optval
,
1271 unsigned int sfcount
= 0, copylen
= 0;
1272 struct mptcp_subflow_context
*subflow
;
1273 struct sock
*sk
= (struct sock
*)msk
;
1274 void __user
*tcpinfoptr
, *sfinfoptr
;
1275 struct mptcp_full_info mfi
;
1278 len
= mptcp_get_full_info(&mfi
, optval
, optlen
);
1282 /* don't bother filling the mptcp info if there is not enough
1283 * user-space-provided storage
1286 mptcp_diag_fill_info(msk
, &mfi
.mptcp_info
);
1287 copylen
+= min_t(unsigned int, len
, sizeof(struct mptcp_info
));
1290 mfi
.size_tcpinfo_kernel
= sizeof(struct tcp_info
);
1291 mfi
.size_tcpinfo_user
= min_t(unsigned int, mfi
.size_tcpinfo_user
,
1292 sizeof(struct tcp_info
));
1293 sfinfoptr
= u64_to_user_ptr(mfi
.subflow_info
);
1294 mfi
.size_sfinfo_kernel
= sizeof(struct mptcp_subflow_info
);
1295 mfi
.size_sfinfo_user
= min_t(unsigned int, mfi
.size_sfinfo_user
,
1296 sizeof(struct mptcp_subflow_info
));
1297 tcpinfoptr
= u64_to_user_ptr(mfi
.tcp_info
);
1300 mptcp_for_each_subflow(msk
, subflow
) {
1301 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
1302 struct mptcp_subflow_info sfinfo
;
1303 struct tcp_info tcp_info
;
1305 if (sfcount
++ >= mfi
.size_arrays_user
)
1308 /* fetch addr/tcp_info only if the user space buffers
1311 memset(&sfinfo
, 0, sizeof(sfinfo
));
1312 sfinfo
.id
= subflow
->subflow_id
;
1313 if (mfi
.size_sfinfo_user
>
1314 offsetof(struct mptcp_subflow_info
, addrs
))
1315 mptcp_get_sub_addrs(ssk
, &sfinfo
.addrs
);
1316 if (copy_to_user(sfinfoptr
, &sfinfo
, mfi
.size_sfinfo_user
))
1319 if (mfi
.size_tcpinfo_user
) {
1320 tcp_get_info(ssk
, &tcp_info
);
1321 if (copy_to_user(tcpinfoptr
, &tcp_info
,
1322 mfi
.size_tcpinfo_user
))
1326 tcpinfoptr
+= mfi
.size_tcpinfo_user
;
1327 sfinfoptr
+= mfi
.size_sfinfo_user
;
1331 mfi
.num_subflows
= sfcount
;
1332 if (mptcp_put_full_info(&mfi
, optval
, copylen
, optlen
))
1342 static int mptcp_put_int_option(struct mptcp_sock
*msk
, char __user
*optval
,
1343 int __user
*optlen
, int val
)
1347 if (get_user(len
, optlen
))
1352 if (len
< sizeof(int) && len
> 0 && val
>= 0 && val
<= 255) {
1353 unsigned char ucval
= (unsigned char)val
;
1356 if (put_user(len
, optlen
))
1358 if (copy_to_user(optval
, &ucval
, 1))
1361 len
= min_t(unsigned int, len
, sizeof(int));
1362 if (put_user(len
, optlen
))
1364 if (copy_to_user(optval
, &val
, len
))
1371 static int mptcp_getsockopt_sol_tcp(struct mptcp_sock
*msk
, int optname
,
1372 char __user
*optval
, int __user
*optlen
)
1374 struct sock
*sk
= (void *)msk
;
1378 case TCP_CONGESTION
:
1381 case TCP_DEFER_ACCEPT
:
1383 case TCP_FASTOPEN_CONNECT
:
1384 case TCP_FASTOPEN_KEY
:
1385 case TCP_FASTOPEN_NO_COOKIE
:
1386 return mptcp_getsockopt_first_sf_only(msk
, SOL_TCP
, optname
,
1389 return mptcp_put_int_option(msk
, optval
, optlen
, msk
->recvmsg_inq
);
1391 return mptcp_put_int_option(msk
, optval
, optlen
, msk
->cork
);
1393 return mptcp_put_int_option(msk
, optval
, optlen
, msk
->nodelay
);
1395 return mptcp_put_int_option(msk
, optval
, optlen
,
1396 msk
->keepalive_idle
? :
1397 READ_ONCE(sock_net(sk
)->ipv4
.sysctl_tcp_keepalive_time
) / HZ
);
1399 return mptcp_put_int_option(msk
, optval
, optlen
,
1400 msk
->keepalive_intvl
? :
1401 READ_ONCE(sock_net(sk
)->ipv4
.sysctl_tcp_keepalive_intvl
) / HZ
);
1403 return mptcp_put_int_option(msk
, optval
, optlen
,
1404 msk
->keepalive_cnt
? :
1405 READ_ONCE(sock_net(sk
)->ipv4
.sysctl_tcp_keepalive_probes
));
1406 case TCP_NOTSENT_LOWAT
:
1407 return mptcp_put_int_option(msk
, optval
, optlen
, msk
->notsent_lowat
);
1409 return mptcp_put_int_option(msk
, optval
, optlen
, 1);
1414 static int mptcp_getsockopt_v4(struct mptcp_sock
*msk
, int optname
,
1415 char __user
*optval
, int __user
*optlen
)
1417 struct sock
*sk
= (void *)msk
;
1421 return mptcp_put_int_option(msk
, optval
, optlen
, READ_ONCE(inet_sk(sk
)->tos
));
1422 case IP_BIND_ADDRESS_NO_PORT
:
1423 return mptcp_put_int_option(msk
, optval
, optlen
,
1424 inet_test_bit(BIND_ADDRESS_NO_PORT
, sk
));
1425 case IP_LOCAL_PORT_RANGE
:
1426 return mptcp_put_int_option(msk
, optval
, optlen
,
1427 READ_ONCE(inet_sk(sk
)->local_port_range
));
1433 static int mptcp_getsockopt_sol_mptcp(struct mptcp_sock
*msk
, int optname
,
1434 char __user
*optval
, int __user
*optlen
)
1438 return mptcp_getsockopt_info(msk
, optval
, optlen
);
1439 case MPTCP_FULL_INFO
:
1440 return mptcp_getsockopt_full_info(msk
, optval
, optlen
);
1442 return mptcp_getsockopt_tcpinfo(msk
, optval
, optlen
);
1443 case MPTCP_SUBFLOW_ADDRS
:
1444 return mptcp_getsockopt_subflow_addrs(msk
, optval
, optlen
);
1450 int mptcp_getsockopt(struct sock
*sk
, int level
, int optname
,
1451 char __user
*optval
, int __user
*option
)
1453 struct mptcp_sock
*msk
= mptcp_sk(sk
);
1456 pr_debug("msk=%p\n", msk
);
1458 /* @@ the meaning of setsockopt() when the socket is connected and
1459 * there are multiple subflows is not yet defined. It is up to the
1460 * MPTCP-level socket to configure the subflows until the subflow
1461 * is in TCP fallback, when socket options are passed through
1462 * to the one remaining subflow.
1465 ssk
= __mptcp_tcp_fallback(msk
);
1468 return tcp_getsockopt(ssk
, level
, optname
, optval
, option
);
1470 if (level
== SOL_IP
)
1471 return mptcp_getsockopt_v4(msk
, optname
, optval
, option
);
1472 if (level
== SOL_TCP
)
1473 return mptcp_getsockopt_sol_tcp(msk
, optname
, optval
, option
);
1474 if (level
== SOL_MPTCP
)
1475 return mptcp_getsockopt_sol_mptcp(msk
, optname
, optval
, option
);
1479 static void sync_socket_options(struct mptcp_sock
*msk
, struct sock
*ssk
)
1481 static const unsigned int tx_rx_locks
= SOCK_RCVBUF_LOCK
| SOCK_SNDBUF_LOCK
;
1482 struct sock
*sk
= (struct sock
*)msk
;
1484 if (ssk
->sk_prot
->keepalive
) {
1485 if (sock_flag(sk
, SOCK_KEEPOPEN
))
1486 ssk
->sk_prot
->keepalive(ssk
, 1);
1488 ssk
->sk_prot
->keepalive(ssk
, 0);
1491 ssk
->sk_priority
= sk
->sk_priority
;
1492 ssk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
1493 ssk
->sk_incoming_cpu
= sk
->sk_incoming_cpu
;
1494 ssk
->sk_ipv6only
= sk
->sk_ipv6only
;
1495 __ip_sock_set_tos(ssk
, inet_sk(sk
)->tos
);
1497 if (sk
->sk_userlocks
& tx_rx_locks
) {
1498 ssk
->sk_userlocks
|= sk
->sk_userlocks
& tx_rx_locks
;
1499 if (sk
->sk_userlocks
& SOCK_SNDBUF_LOCK
) {
1500 WRITE_ONCE(ssk
->sk_sndbuf
, sk
->sk_sndbuf
);
1501 mptcp_subflow_ctx(ssk
)->cached_sndbuf
= sk
->sk_sndbuf
;
1503 if (sk
->sk_userlocks
& SOCK_RCVBUF_LOCK
)
1504 WRITE_ONCE(ssk
->sk_rcvbuf
, sk
->sk_rcvbuf
);
1507 if (sock_flag(sk
, SOCK_LINGER
)) {
1508 ssk
->sk_lingertime
= sk
->sk_lingertime
;
1509 sock_set_flag(ssk
, SOCK_LINGER
);
1511 sock_reset_flag(ssk
, SOCK_LINGER
);
1514 if (sk
->sk_mark
!= ssk
->sk_mark
) {
1515 ssk
->sk_mark
= sk
->sk_mark
;
1519 sock_valbool_flag(ssk
, SOCK_DBG
, sock_flag(sk
, SOCK_DBG
));
1521 if (inet_csk(sk
)->icsk_ca_ops
!= inet_csk(ssk
)->icsk_ca_ops
)
1522 tcp_set_congestion_control(ssk
, msk
->ca_name
, false, true);
1523 __tcp_sock_set_cork(ssk
, !!msk
->cork
);
1524 __tcp_sock_set_nodelay(ssk
, !!msk
->nodelay
);
1525 tcp_sock_set_keepidle_locked(ssk
, msk
->keepalive_idle
);
1526 tcp_sock_set_keepintvl(ssk
, msk
->keepalive_intvl
);
1527 tcp_sock_set_keepcnt(ssk
, msk
->keepalive_cnt
);
1529 inet_assign_bit(TRANSPARENT
, ssk
, inet_test_bit(TRANSPARENT
, sk
));
1530 inet_assign_bit(FREEBIND
, ssk
, inet_test_bit(FREEBIND
, sk
));
1531 inet_assign_bit(BIND_ADDRESS_NO_PORT
, ssk
, inet_test_bit(BIND_ADDRESS_NO_PORT
, sk
));
1532 WRITE_ONCE(inet_sk(ssk
)->local_port_range
, READ_ONCE(inet_sk(sk
)->local_port_range
));
1535 void mptcp_sockopt_sync_locked(struct mptcp_sock
*msk
, struct sock
*ssk
)
1537 struct mptcp_subflow_context
*subflow
= mptcp_subflow_ctx(ssk
);
1539 msk_owned_by_me(msk
);
1541 ssk
->sk_rcvlowat
= 0;
1543 /* subflows must ignore any latency-related settings: will not affect
1544 * the user-space - only the msk is relevant - but will foul the
1547 tcp_sk(ssk
)->notsent_lowat
= UINT_MAX
;
1549 if (READ_ONCE(subflow
->setsockopt_seq
) != msk
->setsockopt_seq
) {
1550 sync_socket_options(msk
, ssk
);
1552 subflow
->setsockopt_seq
= msk
->setsockopt_seq
;
1556 /* unfortunately this is different enough from the tcp version so
1557 * that we can't factor it out
1559 int mptcp_set_rcvlowat(struct sock
*sk
, int val
)
1561 struct mptcp_subflow_context
*subflow
;
1564 /* bpf can land here with a wrong sk type */
1565 if (sk
->sk_protocol
== IPPROTO_TCP
)
1568 if (sk
->sk_userlocks
& SOCK_RCVBUF_LOCK
)
1569 cap
= sk
->sk_rcvbuf
>> 1;
1571 cap
= READ_ONCE(sock_net(sk
)->ipv4
.sysctl_tcp_rmem
[2]) >> 1;
1572 val
= min(val
, cap
);
1573 WRITE_ONCE(sk
->sk_rcvlowat
, val
? : 1);
1575 /* Check if we need to signal EPOLLIN right now */
1576 if (mptcp_epollin_ready(sk
))
1577 sk
->sk_data_ready(sk
);
1579 if (sk
->sk_userlocks
& SOCK_RCVBUF_LOCK
)
1582 space
= mptcp_space_from_win(sk
, val
);
1583 if (space
<= sk
->sk_rcvbuf
)
1586 /* propagate the rcvbuf changes to all the subflows */
1587 WRITE_ONCE(sk
->sk_rcvbuf
, space
);
1588 mptcp_for_each_subflow(mptcp_sk(sk
), subflow
) {
1589 struct sock
*ssk
= mptcp_subflow_tcp_sock(subflow
);
1592 slow
= lock_sock_fast(ssk
);
1593 WRITE_ONCE(ssk
->sk_rcvbuf
, space
);
1594 WRITE_ONCE(tcp_sk(ssk
)->window_clamp
, val
);
1595 unlock_sock_fast(ssk
, slow
);