Hi Davide, Paolo,
On 27/09/2019 22:51, Davide Caratti wrote:
add ulp-specific diagnostic functions, so that subflow information
can be
dumped to userspace programs like 'ss'.
Thank you for the patch and the review!
I am applying this patch and I will continue doing it but I have 2
questions here below. If they are relevant, this can be fixed in a
follow-up patch.
Signed-off-by: Davide Caratti <dcaratti(a)redhat.com>
---
Notes:
changes since RFC:
- dump all subflow-related infos except keys
include/uapi/linux/inet_diag.h | 1 +
include/uapi/linux/mptcp.h | 34 ++++++++++++
net/mptcp/Makefile | 2 +-
net/mptcp/diag.c | 95 ++++++++++++++++++++++++++++++++++
net/mptcp/protocol.h | 3 ++
net/mptcp/subflow.c | 2 +
6 files changed, 136 insertions(+), 1 deletion(-)
create mode 100644 include/uapi/linux/mptcp.h
create mode 100644 net/mptcp/diag.c
diff --git a/include/uapi/linux/inet_diag.h b/include/uapi/linux/inet_diag.h
index a1ff345b3f33..13d16b887512 100644
--- a/include/uapi/linux/inet_diag.h
+++ b/include/uapi/linux/inet_diag.h
@@ -163,6 +163,7 @@ enum {
INET_ULP_INFO_UNSPEC,
INET_ULP_INFO_NAME,
INET_ULP_INFO_TLS,
+ INET_ULP_INFO_MPTCP,
__INET_ULP_INFO_MAX,
};
#define INET_ULP_INFO_MAX (__INET_ULP_INFO_MAX - 1)
diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
new file mode 100644
index 000000000000..2856b89cc36e
--- /dev/null
+++ b/include/uapi/linux/mptcp.h
@@ -0,0 +1,34 @@
+/* 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_MCAP_REM BIT(0)
+#define SUBFLOW_FLAGS_MCAP_LOC BIT(1)
+#define SUBFLOW_FLAGS_JOIN_REM BIT(2)
+#define SUBFLOW_FLAGS_JOIN_LOC BIT(3)
+#define SUBFLOW_FLAGS_BKUP_REM BIT(4)
+#define SUBFLOW_FLAGS_BKUP_LOC BIT(5)
+#define SUBFLOW_FLAGS_4THACK BIT(6)
+#define SUBFLOW_FLAGS_CONNECTED BIT(7)
+#define SUBFLOW_FLAGS_MAPVALID BIT(8)
Should we not prefix all of these with MPTCP_?
+
+enum {
+ MPTCP_SUBFLOW_UNSPEC,
+ MPTCP_SUBFLOW_TOKEN_REM,
+ MPTCP_SUBFLOW_TOKEN_LOC,
+ MPTCP_SUBFLOW_RELWRITE_SEQ,
+ MPTCP_SUBFLOW_MAP_SEQ,
+ MPTCP_SUBFLOW_MAP_SFSEQ,
+ MPTCP_SUBFLOW_SSN_OFFSET,
+ MPTCP_SUBFLOW_MAP_DATALEN,
+ MPTCP_SUBFLOW_FLAGS,
+ MPTCP_SUBFLOW_ID_REM,
+ MPTCP_SUBFLOW_ID_LOC,
+ MPTCP_SUBFLOW_PAD,
+ __MPTCP_SUBFLOW_MAX
+};
+
+#define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1)
+#endif /* _UAPI_MPTCP_H */
diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile
index 289fdf4339c1..6b556e2995ec 100644
--- a/net/mptcp/Makefile
+++ b/net/mptcp/Makefile
@@ -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 pm.o ctrl.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o pm.o ctrl.o diag.o
diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c
new file mode 100644
index 000000000000..a42c96619faa
--- /dev/null
+++ b/net/mptcp/diag.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+/* MPTCP socket monitoring support
+ *
+ * Copyright (c) 2019 Red Hat
+ *
+ * Author: Davide Caratti <dcaratti(a)redhat.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/net.h>
+#include <linux/inet_diag.h>
+#include <net/netlink.h>
+#include <uapi/linux/mptcp.h>
+#include "protocol.h"
+
+int subflow_get_info(const struct sock *sk, struct sk_buff *skb)
+{
+ struct subflow_context *sf;
+ struct nlattr *start;
+ u32 flags = 0;
+ int err;
+
+ start = nla_nest_start_noflag(skb, INET_ULP_INFO_MPTCP);
+ if (!start)
+ return -EMSGSIZE;
+
+ rcu_read_lock();
+ sf = rcu_dereference(inet_csk(sk)->icsk_ulp_data);
+ if (!sf) {
+ err = 0;
+ goto nla_failure;
+ }
+
+ if (sf->mp_capable)
+ flags |= SUBFLOW_FLAGS_MCAP_REM;
+ if (sf->request_mptcp)
+ flags |= SUBFLOW_FLAGS_MCAP_LOC;
+ if (sf->mp_join)
+ flags |= SUBFLOW_FLAGS_JOIN_REM;
+ if (sf->request_join)
+ flags |= SUBFLOW_FLAGS_JOIN_LOC;
+ if (sf->backup)
+ flags |= SUBFLOW_FLAGS_BKUP_REM;
+ if (sf->request_bkup)
+ flags |= SUBFLOW_FLAGS_BKUP_LOC;
+ if (sf->fourth_ack)
+ flags |= SUBFLOW_FLAGS_4THACK;
+ if (sf->conn_finished)
+ flags |= SUBFLOW_FLAGS_CONNECTED;
+ if (sf->map_valid)
+ flags |= SUBFLOW_FLAGS_MAPVALID;
+
+ if (nla_put_u32(skb, MPTCP_SUBFLOW_TOKEN_REM, sf->remote_token) ||
+ nla_put_u32(skb, MPTCP_SUBFLOW_TOKEN_LOC, sf->token) ||
+ nla_put_u32(skb, MPTCP_SUBFLOW_RELWRITE_SEQ, sf->rel_write_seq) ||
+ nla_put_u64_64bit(skb, MPTCP_SUBFLOW_MAP_SEQ, sf->map_seq,
+ MPTCP_SUBFLOW_PAD) ||
+ nla_put_u32(skb, MPTCP_SUBFLOW_MAP_SFSEQ, sf->map_subflow_seq) ||
+ nla_put_u32(skb, MPTCP_SUBFLOW_SSN_OFFSET, sf->ssn_offset) ||
+ nla_put_u16(skb, MPTCP_SUBFLOW_MAP_DATALEN, sf->map_data_len) ||
+ nla_put_u32(skb, MPTCP_SUBFLOW_FLAGS, flags) ||
+ nla_put_u8(skb, MPTCP_SUBFLOW_ID_REM, sf->remote_id) ||
+ nla_put_u8(skb, MPTCP_SUBFLOW_ID_LOC, sf->local_id)) {
+ err = -EMSGSIZE;
+ goto nla_failure;
+ }
+
+ rcu_read_unlock();
+ nla_nest_end(skb, start);
+ return 0;
+
+nla_failure:
+ rcu_read_unlock();
+ nla_nest_cancel(skb, start);
+ return err;
+}
+
+size_t subflow_get_info_size(const struct sock *sk)
+{
+ size_t size = 0;
+
+ size += nla_total_size(0) + /* INET_ULP_INFO_MPTCP */
+ nla_total_size(4) + /* MPTCP_SUBFLOW_TOKEN_REM */
+ nla_total_size(4) + /* MPTCP_SUBFLOW_TOKEN_LOC */
+ nla_total_size(4) + /* MPTCP_SUBFLOW_RELWRITE_SEQ */
+ nla_total_size_64bit(8) + /* MPTCP_SUBFLOW_MAP_SEQ */
+ nla_total_size(4) + /* MPTCP_SUBFLOW_MAP_SFSEQ */
+ nla_total_size(2) + /* MPTCP_SUBFLOW_SSN_OFFSET */
+ nla_total_size(2) + /* MPTCP_SUBFLOW_MAP_DATALEN */
+ nla_total_size(4) + /* MPTCP_SUBFLOW_FLAGS */
+ nla_total_size(1) + /* MPTCP_SUBFLOW_ID_REM */
+ nla_total_size(1) + /* MPTCP_SUBFLOW_ID_LOC */
+ 0;
+ return size;
+}
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index f3f293c82058..f38639cc35b4 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -314,4 +314,7 @@ static inline bool before64(__u64 seq1, __u64 seq2)
#define after64(seq2, seq1) before64(seq1, seq2)
+size_t subflow_get_info_size(const struct sock *sk);
+int subflow_get_info(const struct sock *sk, struct sk_buff *skb);
Should we prefix them as well? If yes only with "mptcp_" or
"mptcp_diag_"? (as linked to diag.c, not subflow.c)
Cheers,
Matt
--
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