mptcp: small improvements, fix and clean-ups
Subsystems (3)
Mat Martineau
maintainerv2 cover mptcp: small improvements, fix and clean-ups
This series contain mostly unrelated patches:
- The two first patches can be seen as "fixes". They are part of this series for -next because it looks like the last batch of fixes for v6.9 has already been sent. These fixes are not urgent, so they can wait if an unlikely v6.9-rc8 is published. About the two patches:
- Patch 1 fixes getsockopt(SO_KEEPALIVE) support on MPTCP sockets
- Patch 2 makes sure the full TCP keep-alive feature is supported, not just SO_KEEPALIVE.
- Patch 3 is a small optimisation when getsockopt(MPTCP_INFO) is used without buffer, just to check if MPTCP is still being used: no fallback to TCP.
- Patch 4 adds net.mptcp.available_schedulers sysctl knob to list packet schedulers, similar to net.ipv4.tcp_available_congestion_control.
- Patch 5 and 6 fix CheckPatch warnings: "prefer strscpy over strcpy" and "else is not generally useful after a break or return".
- Patch 7 and 8 remove and add header includes to avoid unused ones, and add missing ones to be self-contained.
v2: Rebased
Gregory Detal (1):
mptcp: add net.mptcp.available_schedulers
Matthieu Baerts (NGI0) (7):
mptcp: SO_KEEPALIVE: fix getsockopt support
mptcp: fix full TCP keep-alive support
mptcp: sockopt: info: stop early if no buffer
mptcp: prefer strscpy over strcpy
mptcp: remove unnecessary else statements
mptcp: move mptcp_pm_gen.h's include
mptcp: include inet_common in mib.h
include/net/mptcp.h | 3 ++ net/mptcp/ctrl.c | 29 ++++++++++++++++-- net/mptcp/mib.h | 2 ++ net/mptcp/pm_netlink.c | 1 + net/mptcp/pm_userspace.c | 1 + net/mptcp/protocol.c | 5 +-- net/mptcp/protocol.h | 6 ++-- net/mptcp/sched.c | 22 ++++++++++++++ net/mptcp/sockopt.c | 66 ++++++++++++++++++++++++++++++++++++++-- net/mptcp/subflow.c | 32 ++++++++++--------- 10 files changed, 143 insertions(+), 24 deletions(-)
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 1/8 mptcp: SO_KEEPALIVE: fix getsockopt support
From: "Matthieu Baerts (NGI0)" <[email protected]>
SO_KEEPALIVE support has to be set on each subflow: on each TCP socket, where sk_prot->keepalive is defined. Technically, nothing has to be done on the MPTCP socket. That's why mptcp_sol_socket_sync_intval() was called instead of mptcp_sol_socket_intval().
Except that when nothing is done on the MPTCP socket, the getsockopt(SO_KEEPALIVE), handled in net/core/sock.c:sk_getsockopt(), will not know if SO_KEEPALIVE has been set on the different subflows or not.
The fix is simple: simply call mptcp_sol_socket_intval() which will end up calling net/core/sock.c:sk_setsockopt() where the SOCK_KEEPOPEN flag will be set, the one used in sk_getsockopt().
So now, getsockopt(SO_KEEPALIVE) on an MPTCP socket will return the same value as the one previously set with setsockopt(SO_KEEPALIVE).
--- net/mptcp/sockopt.c | 2 -- 1 file changed, 2 deletions(-)
net/mptcp/sockopt.c +0 -2
@@ -181,8 +181,6 @@ static int mptcp_setsockopt_sol_socket_int(struct mptcp_sock *msk, int optname,switch (optname) {case SO_KEEPALIVE : -mptcp_sol_socket_sync_intval (msk, optname, val); -return 0 ;case SO_DEBUG :case SO_MARK :case SO_PRIORITY :
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 2/8 mptcp: fix full TCP keep-alive support
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
SO_KEEPALIVE support has been added a while ago, as part of a series "adding SOL_SOCKET" support. To have a full control of this keep-alive feature, it is important to also support TCP_KEEP* socket options at the SOL_TCP level.
Supporting them on the setsockopt() part is easy, it is just a matter of remembering each value in the MPTCP sock structure, and calling tcp_sock_set_keep*() helpers on each subflow. If the value is not modified (0), calling these helpers will not do anything. For the getsockopt() part, the corresponding value from the MPTCP sock structure or the default one is simply returned. All of this is very similar to other TCP_* socket options supported by MPTCP.
It looks important for kernels supporting SO_KEEPALIVE, to also support TCP_KEEP* options as well: some apps seem to (wrongly) consider that if the former is supported, the latter ones will be supported as well. But also, not having this simple and isolated change is preventing MPTCP support in some apps, and libraries like GoLang [1]. This is why this patch is seen as a fix.
--- net/mptcp/protocol.h | 3 +++ net/mptcp/sockopt.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
net/mptcp/protocol.h +3 -0
@@ -312,6 +312,9 @@ struct mptcp_sock { free_first:1 , rcvspace_init:1;u32 notsent_lowat; +int keepalive_cnt; +int keepalive_idle; +int keepalive_intvl;struct work_struct work;struct sk_buff *ooo_last_skb;struct rb_root out_of_order_queue;
net/mptcp/sockopt.c +58 -0
88 lines not on this page · raw message
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 3/8 mptcp: sockopt: info: stop early if no buffer
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Up to recently, it has been recommended to use getsockopt(MPTCP_INFO) to check if a fallback to TCP happened, or if the client requested to use MPTCP.
In this case, the userspace app is only interested by the returned value of the getsocktop() call, and can then give 0 for the option length, and NULL for the buffer address. An easy optimisation is then to stop early, and avoid filling a local buffer -- which now requires two different locks -- if it is not needed.
--- net/mptcp/sockopt.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mptcp/sockopt.c +4 -0
@@ -999,6 +999,10 @@ static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, inif (get_user (len, optlen))return -EFAULT ; +/* When used only to check if a fallback to TCP happened. */ +if (len ==0 ) +return 0 ; + len = min_t(unsigned int, len, sizeof(struct mptcp_info));mptcp_diag_fill_info (msk, &m_info);
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 4/8 mptcp: add net.mptcp.available_schedulers
In reply to Mat MartineauFrom: Gregory Detal <[email protected]>
The sysctl lists the available schedulers that can be set using net.mptcp.scheduler similarly to net.ipv4.tcp_available_congestion_control.
--- include/net/mptcp.h | 3 +++ net/mptcp/ctrl.c | 27 ++++++++++++++++++++++++++- net/mptcp/protocol.h | 1 + net/mptcp/sched.c | 22 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-)
include/net/mptcp.h +3 -0
@@ -97,6 +97,9 @@ struct mptcp_out_options { };#define MPTCP_SCHED_NAME_MAX 16 +#define MPTCP_SCHED_MAX 128 +#define MPTCP_SCHED_BUF_MAX (MPTCP_SCHED_NAME_MAX * MPTCP_SCHED_MAX) +#define MPTCP_SUBFLOWS_MAX 8struct mptcp_sched_data {
net/mptcp/ctrl.c +26 -1
@@ -133,6 +133,24 @@ static int proc_scheduler(struct ctl_table *ctl, int write,return ret; } +static int proc_available_schedulers (struct ctl_table *ctl, +int write,void *buffer, +size_t *lenp,loff_t *ppos) +{ +struct ctl_table tbl = { .maxlen =MPTCP_SCHED_BUF_MAX , }; +int ret; + + tbl.data =kmalloc (tbl.maxlen,GFP_USER ); +if (!tbl.data) +return -ENOMEM ; + +mptcp_get_available_schedulers (tbl.data,MPTCP_SCHED_BUF_MAX ); + ret =proc_dostring (&tbl, write, buffer, lenp, ppos); +kfree (tbl.data); + +return ret; +} +static struct ctl_table mptcp_sysctl_table[] = { { .procname ="enabled" ,
@@ -187,6 +205,12 @@ static struct ctl_table mptcp_sysctl_table[] = { .mode = 0644, .proc_handler = proc_scheduler, }, + { + .procname = "available_schedulers", + .maxlen = MPTCP_SCHED_BUF_MAX, + .mode = 0644, + .proc_handler = proc_available_schedulers, + }, { .procname = "close_timeout", .maxlen = sizeof(unsigned int),
@@ -214,7 +238,8 @@ static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet) table[4 ].data = &pernet->stale_loss_cnt; table[5 ].data = &pernet->pm_type; table[6 ].data = &pernet->scheduler; - table[7 ].data = &pernet->close_timeout; +/* table[7] is for available_schedulers which is read-only info */ + table[8 ].data = &pernet->close_timeout; hdr =register_net_sysctl_sz (net,MPTCP_SYSCTL_PATH , table,ARRAY_SIZE (mptcp_sysctl_table));
net/mptcp/protocol.h +1 -0
@@ -686,6 +686,7 @@ unsigned int mptcp_stale_loss_cnt(const struct net *net);unsigned int mptcp_close_timeout (const struct sock *sk);int mptcp_get_pm_type (const struct net *net);const char *mptcp_get_scheduler (const struct net *net); +void mptcp_get_available_schedulers (char *buf,size_t maxlen);void __mptcp_subflow_fully_established (struct mptcp_sock *msk,struct mptcp_subflow_context *subflow,const struct mptcp_options_received *mp_opt);
net/mptcp/sched.c +22 -0
@@ -51,6 +51,28 @@ struct mptcp_sched_ops *mptcp_sched_find(const char *name)return ret; } +/* Build string with list of available scheduler values. +* Similar to tcp_get_available_congestion_control() +*/ +void mptcp_get_available_schedulers (char *buf,size_t maxlen) +{ +struct mptcp_sched_ops *sched; +size_t offs =0 ; + +rcu_read_lock (); +spin_lock (&mptcp_sched_list_lock); +list_for_each_entry_rcu (sched, &mptcp_sched_list, list) { + offs +=snprintf (buf + offs, maxlen - offs, +"%s%s" , + offs ==0 ?"" :" " , sched->name); + +if (WARN_ON_ONCE (offs >= maxlen)) +break ; + } +spin_unlock (&mptcp_sched_list_lock); +rcu_read_unlock (); +} +int mptcp_register_scheduler (struct mptcp_sched_ops *sched) {if (!sched->get_subflow)
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 5/8 mptcp: prefer strscpy over strcpy
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
strcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. The safe replacement is strscpy() [1].
This is in preparation of a possible future step where all strcpy() uses will be removed in favour of strscpy() [2].
This fixes CheckPatch warnings:
WARNING: Prefer strscpy over strcpy
--- net/mptcp/ctrl.c | 2 +- net/mptcp/protocol.c | 5 +++-- net/mptcp/sockopt.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-)
net/mptcp/ctrl.c +1 -1
@@ -92,7 +92,7 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet) pernet->allow_join_initial_addr_port =1 ; pernet->stale_loss_cnt =4 ; pernet->pm_type =MPTCP_PM_TYPE_KERNEL ; -strcpy (pernet->scheduler,"default" ); +strscpy (pernet->scheduler,"default" ,sizeof (pernet->scheduler)); }#ifdef CONFIG_SYSCTL
net/mptcp/protocol.c +3 -2
@@ -2814,7 +2814,8 @@ static void mptcp_ca_reset(struct sock *sk)struct inet_connection_sock *icsk =inet_csk (sk);tcp_assign_congestion_control (sk); -strcpy (mptcp_sk (sk)->ca_name, icsk->icsk_ca_ops->name); +strscpy (mptcp_sk (sk)->ca_name, icsk->icsk_ca_ops->name, +sizeof (mptcp_sk (sk)->ca_name));/* no need to keep a reference to the ops, the name will suffice */ tcp_cleanup_congestion_control (sk);
@@ -4169,7 +4170,7 @@ int __init mptcp_proto_v6_init(void)int err; mptcp_v6_prot = mptcp_prot; -strcpy (mptcp_v6_prot.name,"MPTCPv6" ); +strscpy (mptcp_v6_prot.name,"MPTCPv6" ,sizeof (mptcp_v6_prot.name)); mptcp_v6_prot.slab =NULL ; mptcp_v6_prot.obj_size =sizeof (struct mptcp6_sock ); mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock , np);
net/mptcp/sockopt.c +1 -1
@@ -616,7 +616,7 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t }if (ret ==0 ) -strcpy (msk->ca_name, name); +strscpy (msk->ca_name, name,sizeof (msk->ca_name));release_sock (sk);return ret;
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 6/8 mptcp: remove unnecessary else statements
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
The 'else' statements are not needed here, because their previous 'if' block ends with a 'return'.
This fixes CheckPatch warnings:
WARNING: else is not generally useful after a break or return
--- net/mptcp/subflow.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
net/mptcp/subflow.c +17 -15
@@ -1119,6 +1119,8 @@ static enum mapping_status get_mapping_status(struct sock *ssk, }if (mpext->data_fin ==1 ) { +u64 data_fin_seq; +if (data_len ==1 ) {bool updated =mptcp_update_rcv_data_fin (msk, mpext->data_seq, mpext->dsn64);
@@ -1131,26 +1133,26 @@ static enum mapping_status get_mapping_status(struct sock *ssk,*/ skb_ext_del (skb,SKB_EXT_MPTCP );return MAPPING_OK ; - }else { -if (updated) -mptcp_schedule_work ((struct sock *)msk); - -return MAPPING_DATA_FIN ; } - }else { -u64 data_fin_seq = mpext->data_seq + data_len -1 ; -/* If mpext->data_seq is a 32-bit value, data_fin_seq -* must also be limited to 32 bits. -*/ -if (!mpext->dsn64) - data_fin_seq &=GENMASK_ULL (31 ,0 ); +if (updated) +mptcp_schedule_work ((struct sock *)msk); -mptcp_update_rcv_data_fin (msk, data_fin_seq, mpext->dsn64); -pr_debug ("DATA_FIN with mapping seq=%llu dsn64=%d" , - data_fin_seq, mpext->dsn64); +return MAPPING_DATA_FIN ; } + data_fin_seq = mpext->data_seq + data_len -1 ; + +/* If mpext->data_seq is a 32-bit value, data_fin_seq must also +* be limited to 32 bits. +*/ +if (!mpext->dsn64) + data_fin_seq &=GENMASK_ULL (31 ,0 ); + +mptcp_update_rcv_data_fin (msk, data_fin_seq, mpext->dsn64); +pr_debug ("DATA_FIN with mapping seq=%llu dsn64=%d" , + data_fin_seq, mpext->dsn64); +/* Adjust for DATA_FIN using 1 byte of sequence space */ data_len--; }
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 7/8 mptcp: move mptcp_pm_gen.h's include
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
Nothing from protocol.h depends on mptcp_pm_gen.h, only code from pm_netlink.c and pm_userspace.c depends on it.
So this include can be moved where it is needed to avoid a "unused includes" warning.
--- net/mptcp/pm_netlink.c | 1 + net/mptcp/pm_userspace.c | 1 + net/mptcp/protocol.h | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +1 -0
@@ -14,6 +14,7 @@#include "protocol.h" #include "mib.h" +#include "mptcp_pm_gen.h" static int pm_nl_pernet_id;
net/mptcp/pm_userspace.c +1 -0
@@ -6,6 +6,7 @@#include "protocol.h" #include "mib.h" +#include "mptcp_pm_gen.h" void mptcp_free_local_addr_list (struct mptcp_sock *msk) {
net/mptcp/protocol.h +0 -2
@@ -14,8 +14,6 @@#include <net/genetlink.h> #include <net/rstreason.h> -#include "mptcp_pm_gen.h" -#define MPTCP_SUPPORTED_VERSION 1/* MPTCP option bits */
Signature · 1 line
2.45.0
Mat Martineau
maintainerPATCH v2 8/8 mptcp: include inet_common in mib.h
In reply to Mat MartineauFrom: "Matthieu Baerts (NGI0)" <[email protected]>
So this file is now self-contained: it can be compiled alone with analytic tools.
--- net/mptcp/mib.h | 2 ++ 1 file changed, 2 insertions(+)
net/mptcp/mib.h +2 -0
@@ -1,5 +1,7 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include <net/inet_common.h> +enum linux_mptcp_mib_field {MPTCP_MIB_NUM =0 ,MPTCP_MIB_MPCAPABLEPASSIVE ,/* Received SYN with MP_CAPABLE */
Signature · 1 line
2.45.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 13 May 2024 18:13:24 -0700 you wrote:
This series contain mostly unrelated patches:
- The two first patches can be seen as "fixes". They are part of this series for -next because it looks like the last batch of fixes for v6.9 has already been sent. These fixes are not urgent, so they can wait if an unlikely v6.9-rc8 is published. About the two patches:
- Patch 1 fixesgetsockopt(SO_KEEPALIVE)support on MPTCP sockets
- Patch 2 makes sure the full TCP keep-alive feature is supported, not justSO_KEEPALIVE.[...]
Here is the summary with links:
- [net-next,v2,1/8] mptcp: SO_KEEPALIVE: fix getsockopt support
https://git.kernel.org/netdev/net-next/c/a65198136eaa - [net-next,v2,2/8] mptcp: fix full TCP keep-alive support https://git.kernel.org/netdev/net-next/c/bd11dc4fb969 - [net-next,v2,3/8] mptcp: sockopt: info: stop early if no buffer https://git.kernel.org/netdev/net-next/c/ce5f6f71b029 - [net-next,v2,4/8] mptcp: add net.mptcp.available_schedulers https://git.kernel.org/netdev/net-next/c/73c900aa3660 - [net-next,v2,5/8] mptcp: prefer strscpy over strcpy https://git.kernel.org/netdev/net-next/c/5eae7a8202f3 - [net-next,v2,6/8] mptcp: remove unnecessary else statements https://git.kernel.org/netdev/net-next/c/00797af95f5e - [net-next,v2,7/8] mptcp: move mptcp_pm_gen.h's include https://git.kernel.org/netdev/net-next/c/76a86686e3f0 - [net-next,v2,8/8] mptcp: include inet_common in mib.h https://git.kernel.org/netdev/net-next/c/7fad5b375611
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html