2020-03-27 21:48:49 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
|
|
|
|
#ifndef _UAPI_MPTCP_H
|
|
|
|
#define _UAPI_MPTCP_H
|
|
|
|
|
2022-06-28 01:02:42 +00:00
|
|
|
#ifndef __KERNEL__
|
|
|
|
#include <netinet/in.h> /* for sockaddr_in and sockaddr_in6 */
|
|
|
|
#include <sys/socket.h> /* for struct sockaddr */
|
|
|
|
#endif
|
|
|
|
|
2020-03-27 21:48:49 +00:00
|
|
|
#include <linux/const.h>
|
|
|
|
#include <linux/types.h>
|
2021-09-17 23:33:21 +00:00
|
|
|
#include <linux/in.h> /* for sockaddr_in */
|
|
|
|
#include <linux/in6.h> /* for sockaddr_in6 */
|
|
|
|
#include <linux/socket.h> /* for sockaddr_storage and sa_family */
|
|
|
|
|
2020-03-27 21:48:49 +00:00
|
|
|
#define MPTCP_SUBFLOW_FLAG_MCAP_REM _BITUL(0)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_MCAP_LOC _BITUL(1)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_JOIN_REM _BITUL(2)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_JOIN_LOC _BITUL(3)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_BKUP_REM _BITUL(4)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_BKUP_LOC _BITUL(5)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED _BITUL(6)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_CONNECTED _BITUL(7)
|
|
|
|
#define MPTCP_SUBFLOW_FLAG_MAPVALID _BITUL(8)
|
|
|
|
|
2020-03-27 21:48:51 +00:00
|
|
|
#define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds"
|
2021-02-13 00:00:01 +00:00
|
|
|
#define MPTCP_PM_EV_GRP_NAME "mptcp_pm_events"
|
2020-03-27 21:48:51 +00:00
|
|
|
|
2023-10-23 18:17:09 +00:00
|
|
|
#include <linux/mptcp_pm.h>
|
2020-03-27 21:48:51 +00:00
|
|
|
|
2020-07-09 13:12:41 +00:00
|
|
|
#define MPTCP_INFO_FLAG_FALLBACK _BITUL(0)
|
|
|
|
#define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED _BITUL(1)
|
|
|
|
|
2023-10-23 18:17:09 +00:00
|
|
|
#define MPTCP_PM_ADDR_FLAG_SIGNAL (1 << 0)
|
|
|
|
#define MPTCP_PM_ADDR_FLAG_SUBFLOW (1 << 1)
|
|
|
|
#define MPTCP_PM_ADDR_FLAG_BACKUP (1 << 2)
|
|
|
|
#define MPTCP_PM_ADDR_FLAG_FULLMESH (1 << 3)
|
|
|
|
#define MPTCP_PM_ADDR_FLAG_IMPLICIT (1 << 4)
|
|
|
|
|
2020-07-09 13:12:41 +00:00
|
|
|
struct mptcp_info {
|
|
|
|
__u8 mptcpi_subflows;
|
|
|
|
__u8 mptcpi_add_addr_signal;
|
|
|
|
__u8 mptcpi_add_addr_accepted;
|
|
|
|
__u8 mptcpi_subflows_max;
|
|
|
|
__u8 mptcpi_add_addr_signal_max;
|
|
|
|
__u8 mptcpi_add_addr_accepted_max;
|
|
|
|
__u32 mptcpi_flags;
|
|
|
|
__u32 mptcpi_token;
|
|
|
|
__u64 mptcpi_write_seq;
|
|
|
|
__u64 mptcpi_snd_una;
|
|
|
|
__u64 mptcpi_rcv_nxt;
|
2021-02-13 00:52:02 +00:00
|
|
|
__u8 mptcpi_local_addr_used;
|
|
|
|
__u8 mptcpi_local_addr_max;
|
2021-06-17 23:46:07 +00:00
|
|
|
__u8 mptcpi_csum_enabled;
|
2023-06-20 16:30:15 +00:00
|
|
|
__u32 mptcpi_retransmits;
|
|
|
|
__u64 mptcpi_bytes_retrans;
|
|
|
|
__u64 mptcpi_bytes_sent;
|
|
|
|
__u64 mptcpi_bytes_received;
|
|
|
|
__u64 mptcpi_bytes_acked;
|
2023-11-28 23:18:45 +00:00
|
|
|
__u8 mptcpi_subflows_total;
|
mptcp: add last time fields in mptcp_info
This patch adds "last time" fields last_data_sent, last_data_recv and
last_ack_recv in struct mptcp_sock to record the last time data_sent,
data_recv and ack_recv happened. They all are initialized as
tcp_jiffies32 in __mptcp_init_sock(), and updated as tcp_jiffies32 too
when data is sent in __subflow_push_pending(), data is received in
__mptcp_move_skbs_from_subflow(), and ack is received in ack_update_msk().
Similar to tcpi_last_data_sent, tcpi_last_data_recv and tcpi_last_ack_recv
exposed with TCP, this patch exposes the last time "an action happened" for
MPTCP in mptcp_info, named mptcpi_last_data_sent, mptcpi_last_data_recv and
mptcpi_last_ack_recv, calculated in mptcp_diag_fill_info() as the time
deltas between now and the newly added last time fields in mptcp_sock.
Since msk->last_ack_recv needs to be protected by mptcp_data_lock/unlock,
and lock_sock_fast can sleep and be quite slow, move the entire
mptcp_data_lock/unlock block after the lock/unlock_sock_fast block.
Then mptcpi_last_data_sent and mptcpi_last_data_recv are set in
lock/unlock_sock_fast block, while mptcpi_last_ack_recv is set in
mptcp_data_lock/unlock block, which is protected by a spinlock and
should not block for too long.
Also add three reserved bytes in struct mptcp_info not to have holes in
this structure exposed to userspace.
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/446
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240410-upstream-net-next-20240405-mptcp-last-time-info-v2-1-f95bd6b33e51@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-04-10 09:48:24 +00:00
|
|
|
__u8 reserved[3];
|
|
|
|
__u32 mptcpi_last_data_sent;
|
|
|
|
__u32 mptcpi_last_data_recv;
|
|
|
|
__u32 mptcpi_last_ack_recv;
|
2020-07-09 13:12:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-01 23:19:44 +00:00
|
|
|
/* MPTCP Reset reason codes, rfc8684 */
|
|
|
|
#define MPTCP_RST_EUNSPEC 0
|
|
|
|
#define MPTCP_RST_EMPTCP 1
|
|
|
|
#define MPTCP_RST_ERESOURCE 2
|
|
|
|
#define MPTCP_RST_EPROHIBIT 3
|
|
|
|
#define MPTCP_RST_EWQ2BIG 4
|
|
|
|
#define MPTCP_RST_EBADPERF 5
|
|
|
|
#define MPTCP_RST_EMIDDLEBOX 6
|
|
|
|
|
mptcp: add MPTCP_TCPINFO getsockopt support
Allow users to retrieve TCP_INFO data of all subflows.
Users need to pre-initialize a meta header that has to be
prepended to the data buffer that will be filled with the tcp info data.
The meta header looks like this:
struct mptcp_subflow_data {
__u32 size_subflow_data;/* size of this structure in userspace */
__u32 num_subflows; /* must be 0, set by kernel */
__u32 size_kernel; /* must be 0, set by kernel */
__u32 size_user; /* size of one element in data[] */
} __attribute__((aligned(8)));
size_subflow_data has to be set to 'sizeof(struct mptcp_subflow_data)'.
This allows to extend mptcp_subflow_data structure later on without
breaking backwards compatibility.
If the structure is extended later on, kernel knows where the
userspace-provided meta header ends, even if userspace uses an older
(smaller) version of the structure.
num_subflows must be set to 0. If the getsockopt request succeeds (return
value is 0), it will be updated to contain the number of active subflows
for the given logical connection.
size_kernel must be set to 0. If the getsockopt request is successful,
it will contain the size of the 'struct tcp_info' as known by the kernel.
This is informational only.
size_user must be set to 'sizeof(struct tcp_info)'.
This allows the kernel to only fill in the space reserved/expected by
userspace.
Example:
struct my_tcp_info {
struct mptcp_subflow_data d;
struct tcp_info ti[2];
};
struct my_tcp_info ti;
socklen_t olen;
memset(&ti, 0, sizeof(ti));
ti.d.size_subflow_data = sizeof(struct mptcp_subflow_data);
ti.d.size_user = sizeof(struct tcp_info);
olen = sizeof(ti);
ret = getsockopt(fd, SOL_MPTCP, MPTCP_TCPINFO, &ti, &olen);
if (ret < 0)
die_perror("getsockopt MPTCP_TCPINFO");
mptcp_subflow_data.num_subflows is populated with the number of
subflows that exist on the kernel side for the logical mptcp connection.
This allows userspace to re-try with a larger tcp_info array if the number
of subflows was larger than the available space in the ti[] array.
olen has to be set to the number of bytes that userspace has allocated to
receive the kernel data. It will be updated to contain the real number
bytes that have been copied to by the kernel.
In the above example, if the number if subflows was 1, olen is equal to
'sizeof(struct mptcp_subflow_data) + sizeof(struct tcp_info).
For 2 or more subflows olen is equal to 'sizeof(struct my_tcp_info)'.
If there was more data that could not be copied due to lack of space
in the option buffer, userspace can detect this by checking
mptcp_subflow_data->num_subflows.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-09-17 23:33:20 +00:00
|
|
|
struct mptcp_subflow_data {
|
|
|
|
__u32 size_subflow_data; /* size of this structure in userspace */
|
|
|
|
__u32 num_subflows; /* must be 0, set by kernel */
|
|
|
|
__u32 size_kernel; /* must be 0, set by kernel */
|
|
|
|
__u32 size_user; /* size of one element in data[] */
|
|
|
|
} __attribute__((aligned(8)));
|
|
|
|
|
2021-09-17 23:33:21 +00:00
|
|
|
struct mptcp_subflow_addrs {
|
|
|
|
union {
|
|
|
|
__kernel_sa_family_t sa_family;
|
|
|
|
struct sockaddr sa_local;
|
|
|
|
struct sockaddr_in sin_local;
|
|
|
|
struct sockaddr_in6 sin6_local;
|
|
|
|
struct __kernel_sockaddr_storage ss_local;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
struct sockaddr sa_remote;
|
|
|
|
struct sockaddr_in sin_remote;
|
|
|
|
struct sockaddr_in6 sin6_remote;
|
|
|
|
struct __kernel_sockaddr_storage ss_remote;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-20 16:30:18 +00:00
|
|
|
struct mptcp_subflow_info {
|
|
|
|
__u32 id;
|
|
|
|
struct mptcp_subflow_addrs addrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mptcp_full_info {
|
|
|
|
__u32 size_tcpinfo_kernel; /* must be 0, set by kernel */
|
|
|
|
__u32 size_tcpinfo_user;
|
|
|
|
__u32 size_sfinfo_kernel; /* must be 0, set by kernel */
|
|
|
|
__u32 size_sfinfo_user;
|
|
|
|
__u32 num_subflows; /* must be 0, set by kernel (real subflow count) */
|
|
|
|
__u32 size_arrays_user; /* max subflows that userspace is interested in;
|
|
|
|
* the buffers at subflow_info/tcp_info
|
|
|
|
* are respectively at least:
|
|
|
|
* size_arrays * size_sfinfo_user
|
|
|
|
* size_arrays * size_tcpinfo_user
|
|
|
|
* bytes wide
|
|
|
|
*/
|
|
|
|
__aligned_u64 subflow_info;
|
|
|
|
__aligned_u64 tcp_info;
|
|
|
|
struct mptcp_info mptcp_info;
|
|
|
|
};
|
|
|
|
|
2021-09-17 23:33:19 +00:00
|
|
|
/* MPTCP socket options */
|
mptcp: add MPTCP_TCPINFO getsockopt support
Allow users to retrieve TCP_INFO data of all subflows.
Users need to pre-initialize a meta header that has to be
prepended to the data buffer that will be filled with the tcp info data.
The meta header looks like this:
struct mptcp_subflow_data {
__u32 size_subflow_data;/* size of this structure in userspace */
__u32 num_subflows; /* must be 0, set by kernel */
__u32 size_kernel; /* must be 0, set by kernel */
__u32 size_user; /* size of one element in data[] */
} __attribute__((aligned(8)));
size_subflow_data has to be set to 'sizeof(struct mptcp_subflow_data)'.
This allows to extend mptcp_subflow_data structure later on without
breaking backwards compatibility.
If the structure is extended later on, kernel knows where the
userspace-provided meta header ends, even if userspace uses an older
(smaller) version of the structure.
num_subflows must be set to 0. If the getsockopt request succeeds (return
value is 0), it will be updated to contain the number of active subflows
for the given logical connection.
size_kernel must be set to 0. If the getsockopt request is successful,
it will contain the size of the 'struct tcp_info' as known by the kernel.
This is informational only.
size_user must be set to 'sizeof(struct tcp_info)'.
This allows the kernel to only fill in the space reserved/expected by
userspace.
Example:
struct my_tcp_info {
struct mptcp_subflow_data d;
struct tcp_info ti[2];
};
struct my_tcp_info ti;
socklen_t olen;
memset(&ti, 0, sizeof(ti));
ti.d.size_subflow_data = sizeof(struct mptcp_subflow_data);
ti.d.size_user = sizeof(struct tcp_info);
olen = sizeof(ti);
ret = getsockopt(fd, SOL_MPTCP, MPTCP_TCPINFO, &ti, &olen);
if (ret < 0)
die_perror("getsockopt MPTCP_TCPINFO");
mptcp_subflow_data.num_subflows is populated with the number of
subflows that exist on the kernel side for the logical mptcp connection.
This allows userspace to re-try with a larger tcp_info array if the number
of subflows was larger than the available space in the ti[] array.
olen has to be set to the number of bytes that userspace has allocated to
receive the kernel data. It will be updated to contain the real number
bytes that have been copied to by the kernel.
In the above example, if the number if subflows was 1, olen is equal to
'sizeof(struct mptcp_subflow_data) + sizeof(struct tcp_info).
For 2 or more subflows olen is equal to 'sizeof(struct my_tcp_info)'.
If there was more data that could not be copied due to lack of space
in the option buffer, userspace can detect this by checking
mptcp_subflow_data->num_subflows.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-09-17 23:33:20 +00:00
|
|
|
#define MPTCP_INFO 1
|
|
|
|
#define MPTCP_TCPINFO 2
|
2021-09-17 23:33:21 +00:00
|
|
|
#define MPTCP_SUBFLOW_ADDRS 3
|
2023-06-20 16:30:18 +00:00
|
|
|
#define MPTCP_FULL_INFO 4
|
2021-09-17 23:33:19 +00:00
|
|
|
|
2020-03-27 21:48:49 +00:00
|
|
|
#endif /* _UAPI_MPTCP_H */
|