preliminary support for 'ss'
Subsystems (3)
Davide Caratti
cover preliminary support for 'ss'
dumping subflow-related information from userspace tools can be useful also in the early stages of developement, for writing functional tests and for debugging purposes.
- patch 1 adds support for ULP-specific information in the output of INET_DIAG_INFO request.
- patch2 is a POC that dumps several members of struct subflow_context.
Davide Caratti (2):
tcp: ulp: add functions to dump ulp-specific information
mptcp: allow dumping subflow context to userspace
include/net/tcp.h | 3 ++ include/uapi/linux/inet_diag.h | 7 ++++ include/uapi/linux/mptcp.h | 21 ++++++++++ net/ipv4/tcp_diag.c | 33 ++++++++++++++- net/mptcp/Makefile | 2 +- net/mptcp/diag.c | 73 ++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 3 ++ net/mptcp/subflow.c | 2 + 8 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 include/uapi/linux/mptcp.h create mode 100644 net/mptcp/diag.c
Signature · 1 line
2.20.1
Davide Caratti
RFC PATCH 1/2 tcp: ulp: add functions to dump ulp-specific information
currently, only getsockopt() can be invoked to know if a ULP is on top of a TCP socket. idiag_get_aux() and idiag_get_aux_size() are currently used only by TCP MD5 extension: extend them to dump ULP-related information to userspace tools like 'ss' when they query the kernel with INET_DIAG_INFO.
--- include/net/tcp.h | 3 +++ include/uapi/linux/inet_diag.h | 2 ++ net/ipv4/tcp_diag.c | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-)
include/net/tcp.h +3 -0
@@ -2100,6 +2100,9 @@ struct tcp_ulp_ops {/* clone ulp */ void (*clone)(const struct request_sock *req,struct sock *newsk,const gfp_t priority); +/* diagnostic */ +int (*get_info)(struct sock *sk,struct sk_buff *skb); +size_t (*get_info_size)(struct sock *sk);char name[TCP_ULP_NAME_MAX ];struct module *owner;
include/uapi/linux/inet_diag.h +2 -0
@@ -153,6 +153,8 @@ enum {INET_DIAG_BBRINFO ,/* request as INET_DIAG_VEGASINFO */ INET_DIAG_CLASS_ID ,/* request as INET_DIAG_TCLASS */ INET_DIAG_MD5SIG , +INET_DIAG_ULPNAME , +INET_DIAG_ULPINFO , __INET_DIAG_MAX, };
net/ipv4/tcp_diag.c +31 -2
@@ -88,10 +88,12 @@ static int tcp_diag_put_md5sig(struct sk_buff *skb,static int tcp_diag_get_aux (struct sock *sk,bool net_admin,struct sk_buff *skb) { +struct inet_connection_sock *icsk =inet_csk (sk); +int err =0 ; +#ifdef CONFIG_TCP_MD5SIG if (net_admin) {struct tcp_md5sig_info *md5sig; -int err =0 ;rcu_read_lock (); md5sig =rcu_dereference (tcp_sk (sk)->md5sig_info);
@@ -102,12 +104,33 @@ static int tcp_diag_get_aux(struct sock *sk, bool net_admin,return err; }#endif +if (net_admin && icsk->icsk_ulp_ops) { +struct nlattr *nest; -return 0 ; + err =nla_put_string (skb,INET_DIAG_ULPNAME , + icsk->icsk_ulp_ops->name); +if (err <0 || !icsk->icsk_ulp_ops->get_info) +return err; + + nest =nla_nest_start_noflag (skb,INET_DIAG_ULPINFO ); +if (!nest) { + err = -EMSGSIZE ; + goto nla_failure; + } + err = icsk->icsk_ulp_ops->get_info (sk, skb); +if (err <0 ) { +nla_failure: +nla_nest_cancel (skb, nest); +return err; + } +nla_nest_end (skb, nest); + } +return err; }static size_t tcp_diag_get_aux_size (struct sock *sk,bool net_admin) { +struct inet_connection_sock *icsk =inet_csk (sk);size_t size =0 ;#ifdef CONFIG_TCP_MD5SIG
@@ -127,6 +150,12 @@ static size_t tcp_diag_get_aux_size(struct sock *sk, bool net_admin) sizeof(struct tcp_diag_md5sig)); }#endif +if (net_admin && icsk->icsk_ulp_ops) { + size +=nla_total_size (TCP_ULP_NAME_MAX ); +if (icsk->icsk_ulp_ops->get_info_size) + size +=nla_total_size (0 ) +/* INET_DIAG_ULPINFO */ + icsk->icsk_ulp_ops->get_info_size (sk); + }return size; }
Signature · 1 line
2.20.1
Davide Caratti
RFC PATCH 2/2 mptcp: allow dumping subflow context to userspace
In reply to Davide Carattiadd ulp-specific diagnostic functions, so that subflow information can be dumped to userspace programs like 'ss'.
---
Notes:
- this is a POC patch where I only dump few members of the subflow, and put them in a nested attribute so that it's possible to read them in a program regardless the value of 'subflow_ulp_ops.name'. Please let me know if we should dump additional information, or if some of those I included don't make sense.
include/uapi/linux/inet_diag.h | 5 +++ include/uapi/linux/mptcp.h | 21 ++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/diag.c | 73 ++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 3 ++ net/mptcp/subflow.c | 2 + 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/mptcp.h create mode 100644 net/mptcp/diag.c
include/uapi/linux/inet_diag.h +5 -0
@@ -204,4 +204,9 @@ union tcp_cc_info {struct tcp_dctcp_info dctcp; struct tcp_bbr_info bbr; }; + +enum { +ULPINFO_MPTCP_SUBFLOW , + __ULPINFO_MAX +};#endif /* _UAPI_INET_DIAG_H_ */
include/uapi/linux/mptcp.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_MPTCP_H +#define _UAPI_MPTCP_H + +#include <linux/types.h> + +#define SUBFLOW_FLAGS_MP_REMOTE BIT(0) +#define SUBFLOW_FLAGS_MP_LOCAL BIT(1) +#define SUBFLOW_FLAGS_DSS_CSUM BIT(2) + +enum { +MPTCP_SUBFLOW_LOCAL_KEY , +MPTCP_SUBFLOW_REMOTE_KEY , +MPTCP_SUBFLOW_FLAGS , +MPTCP_SUBFLOW_PAD , + __MPTCP_SUBFLOW_MAX +}; + +#define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1) + +#endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MPTCP) += mptcp.o -mptcp-y := protocol.o subflow.o options.o token.o crypto.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o diag.o
net/mptcp/diag.c new file +73 -0
73 lines not on this page · raw message
net/mptcp/protocol.h +3 -0
@@ -144,4 +144,7 @@ static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb) return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); } +size_t subflow_get_info_size (struct sock *sk); +int subflow_get_info (struct sock *sk,struct sk_buff *skb); +#endif /* __MPTCP_PROTOCOL_H */
net/mptcp/subflow.c +2 -0
@@ -262,6 +262,8 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = { .init = subflow_ulp_init, .release = subflow_ulp_release, .clone = subflow_ulp_clone, + .get_info = subflow_get_info, + .get_info_size = subflow_get_info_size, };static int subflow_ops_init (struct request_sock_ops *subflow_ops)
Signature · 1 line
2.20.1
Paolo Abeni
Re: [MPTCP] [PATCH RFC mptcp 2/2] mptcp: allow dumping subflow context to userspace
Hi,
Quoted 5 lines · Davide Caratti
- this is a POC patch where I only dump few members of the subflow, and put them in a nested attribute so that it's possible to read them in a program regardless the value of 'subflow_ulp_ops.name'. Please let me know if we should dump additional information, or if some of those I included don't make sense.
I personally think that SSN and mapping related info would be useful and worthy to add.
Paolo
Mat Martineau
Re: [MPTCP] [PATCH RFC mptcp 2/2] mptcp: allow dumping subflow context to userspace
In reply to Davide CarattiQuoted 50 lines · Davide Caratti
add ulp-specific diagnostic functions, so that subflow information can be dumped to userspace programs like 'ss'.
Signed-off-by Davide Caratti <dcaratti(a)redhat.com>---
Notes:
- this is a POC patch where I only dump few members of the subflow, and put them in a nested attribute so that it's possible to read them in a program regardless the value of 'subflow_ulp_ops.name'. Please let me know if we should dump additional information, or if some of those I included don't make sense.include/uapi/linux/inet_diag.h | 5 +++ include/uapi/linux/mptcp.h | 21 ++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/diag.c | 73 ++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 3 ++ net/mptcp/subflow.c | 2 + 6 files changed, 105 insertions(+), 1 deletion(-)create mode 100644
include/uapi/linux/mptcp.h
create mode 100644net/mptcp/diag.cinclude/uapi/linux/inet_diag.h +5
-0@@ -204,4 +204,9 @@ union tcp_cc_info {struct tcp_dctcp_info dctcp; struct tcp_bbr_info bbr; }; + +enum { +ULPINFO_MPTCP_SUBFLOW , + __ULPINFO_MAX +};#endif /* _UAPI_INET_DIAG_H_ */ include/uapi/linux/mptcp.h new file +7
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_MPTCP_H +#define _UAPI_MPTCP_H + +#include <linux/types.h> + +#define SUBFLOW_FLAGS_MP_REMOTE BIT(0)
include/uapi/linux/mptcp.h line 17
Quoted 10 lines
include/uapi/linux/mptcp.h new file +10
-0+#define SUBFLOW_FLAGS_MP_LOCAL BIT(1) +#define SUBFLOW_FLAGS_DSS_CSUM BIT(2) + +enum { +MPTCP_SUBFLOW_LOCAL_KEY , +MPTCP_SUBFLOW_REMOTE_KEY , +MPTCP_SUBFLOW_FLAGS , +MPTCP_SUBFLOW_PAD , + __MPTCP_SUBFLOW_MAX +};
The 32-bit subflow->token is also useful, since that's what would be relevant for future MP_JOIN attempts.
Quoted 43 lines
include/uapi/linux/mptcp.h new file +4
-0+ +#define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1) + +#endif /* _UAPI_MPTCP_H */ net/mptcp/Makefile +0
-0@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0obj-$(CONFIG_MPTCP) += mptcp.o
net/mptcp/Makefile +1
-1-mptcp-y := protocol.o subflow.o options.o token.o crypto.o +mptcp-y := protocol.o subflow.o options.o token.o crypto.o diag.onet/mptcp/diag.c new file +23
-0@@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/module.h> +#include <linux/net.h> +#include <linux/sock_diag.h> +#include <linux/inet_diag.h> +#include <linux/tcp.h> + +#include <net/netlink.h> +#include <net/tcp.h> +#include <net/mptcp.h> + +#include <uapi/linux/mptcp.h> +#include "protocol.h" + +int subflow_get_info (struct sock *sk,struct sk_buff *skb) +{ +struct mptcp_subflow_info *info; +struct subflow_context *subflow =subflow_ctx (sk); +struct nlattr *start =0 ; +u32 flags =0 ; +int ret =0 ; +
net/mptcp/diag.c line 33
Quoted 10 lines
net/mptcp/diag.c new file +10
-0+if (!subflow) + goto end; + + start =nla_nest_start_noflag (skb,ULPINFO_MPTCP_SUBFLOW ); +if (!start) { + ret = -EMSGSIZE ; + goto nla_failure; + } +if (subflow->mp_capable) + flags |=SUBFLOW_FLAGS_MP_REMOTE ;
If mp_capable is true, the socket is using MPTCP. If it's false, it has done a fallback to TCP. For userspace, might be better to name it SUBFLOW_FLAGS_IN_TCP_FALLBACK (or similar) if !mp_capable.
net/mptcp/diag.c line 35
Quoted 2 lines
net/mptcp/diag.c new file +2
-0+if (subflow->request_mptcp) + flags |=SUBFLOW_FLAGS_MP_LOCAL ;
This is only used at connect time and is only false if ULP setup failed, so I don't think it's useful.
net/mptcp/diag.c line 37
Quoted 2 lines
net/mptcp/diag.c new file +2
-0+if (subflow->request_cksum) + flags |=SUBFLOW_FLAGS_DSS_CSUM ;
subflow->use_checksum is the field to check for this flag.
Thanks for the patch, it will be helpful to have more visibility at run time.
Mat
Quoted 69 lines
net/mptcp/diag.c new file +36
-0+ +if (nla_put_be64 (skb,MPTCP_SUBFLOW_LOCAL_KEY , +cpu_to_be64 (subflow->local_key), +MPTCP_SUBFLOW_PAD ) || +nla_put_be64 (skb,MPTCP_SUBFLOW_REMOTE_KEY , +cpu_to_be64 (subflow->remote_key), +MPTCP_SUBFLOW_PAD ) || +nla_put_u32 (skb,MPTCP_SUBFLOW_FLAGS , flags)) { + ret = -EMSGSIZE ; + goto nla_failure; + } +nla_nest_end (skb, start); +end: +return ret; + +nla_failure: +nla_nest_cancel (skb, start); + goto end; +} + +size_t subflow_get_info_size (struct sock *sk) +{ +struct subflow_context *subflow =subflow_ctx (sk); +size_t size =0 ; + +if (!subflow) + goto end; + + size +=nla_total_size (0 ) +/* ULPINFO_MPTCP_SUBFLOW */ +nla_total_size_64bit (8 ) +/* MPTCP_SUBFLOW_LOCAL_KEY */ +nla_total_size_64bit (8 ) +/* MPTCP_SUBFLOW_REMOTE_KEY */ +nla_total_size (4 ) +/* MPTCP_SUBFLOW_FLAGS */ +0 ; +end: +return size; +}net/mptcp/protocol.h +3
-0@@ -144,4 +144,7 @@ static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb) return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP); } +size_t subflow_get_info_size (struct sock *sk); +int subflow_get_info (struct sock *sk,struct sk_buff *skb); +#endif /* __MPTCP_PROTOCOL_H */ net/mptcp/subflow.c +2
-0@@ -262,6 +262,8 @@ static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = { .init = subflow_ulp_init, .release = subflow_ulp_release, .clone = subflow_ulp_clone, + .get_info = subflow_get_info, + .get_info_size = subflow_get_info_size, };static int subflow_ops_init (struct request_sock_ops *subflow_ops)Signature · 6 lines
2.20.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
--
Mat Martineau
Intel
Mat Martineau
Re: [MPTCP] [PATCH RFC mptcp 2/2] mptcp: allow dumping subflow context to userspace
In reply to Paolo AbeniQuoted 12 lines · Paolo Abeni
Hi,
Quoted 5 lines · Davide Caratti
- this is a POC patch where I only dump few members of the subflow, and put them in a nested attribute so that it's possible to read them in a program regardless the value of 'subflow_ulp_ops.name'. Please let me know if we should dump additional information, or if some of those I included don't make sense.
I personally think that SSN and mapping related info would be useful and worthy to add.
As we implement multiple subflows and deal with MPTCP-level out-of-order reassembly, the mapping-related info will likely move in to the MPTCP-level socket. If we expose information about mappings, I think we would register a different inet_diag_handler for the MPTCP socket and report it there.
--
Mat Martineau
Intel
Matthieu Baerts
Re: [MPTCP] [PATCH RFC mptcp 2/2] mptcp: allow dumping subflow context to userspace
In reply to Mat MartineauHi Mat, Davide,
Thank you for the review and the patches!
Quoted 21 lines · Mat Martineau
Quoted 18 lines · Davide Caratti
include/uapi/linux/mptcp.h new file +12
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_MPTCP_H +#define _UAPI_MPTCP_H + +#include <linux/types.h> + +#define SUBFLOW_FLAGS_MP_REMOTE BIT(0) +#define SUBFLOW_FLAGS_MP_LOCAL BIT(1) +#define SUBFLOW_FLAGS_DSS_CSUM BIT(2) + +enum { + MPTCP_SUBFLOW_LOCAL_KEY,
Quoted 8 lines
include/uapi/linux/mptcp.h line 17
Quoted 5 lines
include/uapi/linux/mptcp.h new file +5
-0+ MPTCP_SUBFLOW_REMOTE_KEY, + MPTCP_SUBFLOW_FLAGS, + MPTCP_SUBFLOW_PAD, + __MPTCP_SUBFLOW_MAX +};The 32-bit
subflow->tokenis also useful, since that's what would be relevant for futureMP_JOINattempts.
Just a small note to say that it is not recommended to expose this token to regular users for security reasons. Please see this (famous -- Christoph would remember it :) ) commit from mptcp.org:
https://github.com/multipath-tcp/mptcp/commit/e993b775d8abda232ceecbbed135b40c546f5088
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Mat Martineau
Re: [MPTCP] [PATCH RFC mptcp 2/2] mptcp: allow dumping subflow context to userspace
Quoted 35 lines · Matthieu Baerts
Hi Mat, Davide,
Thank you for the review and the patches!
Quoted 21 lines · Mat Martineau
Quoted 18 lines · Davide Caratti
include/uapi/linux/mptcp.h new file +12
-0@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +#ifndef _UAPI_MPTCP_H +#define _UAPI_MPTCP_H + +#include <linux/types.h> + +#define SUBFLOW_FLAGS_MP_REMOTE BIT(0) +#define SUBFLOW_FLAGS_MP_LOCAL BIT(1) +#define SUBFLOW_FLAGS_DSS_CSUM BIT(2) + +enum { + MPTCP_SUBFLOW_LOCAL_KEY,Quoted 8 lines
include/uapi/linux/mptcp.h line 17
Quoted 5 lines
include/uapi/linux/mptcp.h new file +5
-0+ MPTCP_SUBFLOW_REMOTE_KEY, + MPTCP_SUBFLOW_FLAGS, + MPTCP_SUBFLOW_PAD, + __MPTCP_SUBFLOW_MAX +};The 32-bit
subflow->tokenis also useful, since that's what would be relevant for futureMP_JOINattempts.
Quoted 7 lines
Just a small note to say that it is not recommended to expose this token to regular users for security reasons. Please see this (famous -- Christoph would remember it :) ) commit from mptcp.org:
https://github.com/multipath-tcp/mptcp/commit/e993b775d8abda232ceecbbed135b40c546f5088
Yes! I had seen that Davide's first patch checks for net_admin privileges, but it's best to make sure everyone knows that access to the tokens should have this restriction.
--
Mat Martineau
Intel