1/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2#ifndef _MPTCP_H
3#define _MPTCP_H
4
5#include <netinet/in.h> /* for sockaddr_in and sockaddr_in6 */
6#include <sys/socket.h> /* for struct sockaddr */
7
8#include <linux/const.h>
9#include <linux/types.h>
10#include <linux/in.h> /* for sockaddr_in */
11#include <linux/in6.h> /* for sockaddr_in6 */
12#include <linux/socket.h> /* for sockaddr_storage and sa_family */
13
14#define MPTCP_SUBFLOW_FLAG_MCAP_REM _BITUL(0)
15#define MPTCP_SUBFLOW_FLAG_MCAP_LOC _BITUL(1)
16#define MPTCP_SUBFLOW_FLAG_JOIN_REM _BITUL(2)
17#define MPTCP_SUBFLOW_FLAG_JOIN_LOC _BITUL(3)
18#define MPTCP_SUBFLOW_FLAG_BKUP_REM _BITUL(4)
19#define MPTCP_SUBFLOW_FLAG_BKUP_LOC _BITUL(5)
20#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED _BITUL(6)
21#define MPTCP_SUBFLOW_FLAG_CONNECTED _BITUL(7)
22#define MPTCP_SUBFLOW_FLAG_MAPVALID _BITUL(8)
23
24#define MPTCP_PM_CMD_GRP_NAME "mptcp_pm_cmds"
25#define MPTCP_PM_EV_GRP_NAME "mptcp_pm_events"
26
27#include <linux/mptcp_pm.h>
28
29#define MPTCP_INFO_FLAG_FALLBACK _BITUL(0)
30#define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED _BITUL(1)
31
32#define MPTCP_PM_EV_FLAG_DENY_JOIN_ID0 _BITUL(0)
33#define MPTCP_PM_EV_FLAG_SERVER_SIDE _BITUL(1)
34
35#define MPTCP_PM_ADDR_FLAG_SIGNAL _BITUL(0)
36#define MPTCP_PM_ADDR_FLAG_SUBFLOW _BITUL(1)
37#define MPTCP_PM_ADDR_FLAG_BACKUP _BITUL(2)
38#define MPTCP_PM_ADDR_FLAG_FULLMESH _BITUL(3)
39#define MPTCP_PM_ADDR_FLAG_IMPLICIT _BITUL(4)
40#define MPTCP_PM_ADDR_FLAG_LAMINAR _BITUL(5)
41#define MPTCP_PM_ADDR_FLAGS_MASK GENMASK(5, 0)
42
43struct mptcp_info {
44 __u8 mptcpi_subflows;
45 #define mptcpi_extra_subflows mptcpi_subflows
46 __u8 mptcpi_add_addr_signal;
47 __u8 mptcpi_add_addr_accepted;
48 __u8 mptcpi_subflows_max;
49 #define mptcpi_limit_extra_subflows mptcpi_subflows_max
50 __u8 mptcpi_add_addr_signal_max;
51 #define mptcpi_endp_signal_max mptcpi_add_addr_signal_max
52 __u8 mptcpi_add_addr_accepted_max;
53 #define mptcpi_limit_add_addr_accepted mptcpi_add_addr_accepted_max
54 /* 16-bit hole that can no longer be filled */
55 __u32 mptcpi_flags;
56 __u32 mptcpi_token;
57 __u64 mptcpi_write_seq;
58 __u64 mptcpi_snd_una;
59 __u64 mptcpi_rcv_nxt;
60 __u8 mptcpi_local_addr_used;
61 __u8 mptcpi_local_addr_max;
62 #define mptcpi_endp_subflow_max mptcpi_local_addr_max
63 __u8 mptcpi_csum_enabled;
64 /* 8-bit hole that can no longer be filled */
65 __u32 mptcpi_retransmits;
66 __u64 mptcpi_bytes_retrans;
67 __u64 mptcpi_bytes_sent;
68 __u64 mptcpi_bytes_received;
69 __u64 mptcpi_bytes_acked;
70 __u8 mptcpi_subflows_total;
71 __u8 mptcpi_endp_laminar_max;
72 __u8 mptcpi_endp_fullmesh_max;
73 __u8 reserved;
74 __u32 mptcpi_last_data_sent;
75 __u32 mptcpi_last_data_recv;
76 __u32 mptcpi_last_ack_recv;
77};
78
79/* MPTCP Reset reason codes, rfc8684 */
80#define MPTCP_RST_EUNSPEC 0
81#define MPTCP_RST_EMPTCP 1
82#define MPTCP_RST_ERESOURCE 2
83#define MPTCP_RST_EPROHIBIT 3
84#define MPTCP_RST_EWQ2BIG 4
85#define MPTCP_RST_EBADPERF 5
86#define MPTCP_RST_EMIDDLEBOX 6
87
88struct mptcp_subflow_data {
89 __u32 size_subflow_data; /* size of this structure in userspace */
90 __u32 num_subflows; /* must be 0, set by kernel */
91 __u32 size_kernel; /* must be 0, set by kernel */
92 __u32 size_user; /* size of one element in data[] */
93} __attribute__((aligned(8)));
94
95struct mptcp_subflow_addrs {
96 union {
97 __kernel_sa_family_t sa_family;
98 struct sockaddr sa_local;
99 struct sockaddr_in sin_local;
100 struct sockaddr_in6 sin6_local;
101 struct __kernel_sockaddr_storage ss_local;
102 };
103 union {
104 struct sockaddr sa_remote;
105 struct sockaddr_in sin_remote;
106 struct sockaddr_in6 sin6_remote;
107 struct __kernel_sockaddr_storage ss_remote;
108 };
109};
110
111struct mptcp_subflow_info {
112 __u32 id;
113 struct mptcp_subflow_addrs addrs;
114};
115
116struct mptcp_full_info {
117 __u32 size_tcpinfo_kernel; /* must be 0, set by kernel */
118 __u32 size_tcpinfo_user;
119 __u32 size_sfinfo_kernel; /* must be 0, set by kernel */
120 __u32 size_sfinfo_user;
121 __u32 num_subflows; /* must be 0, set by kernel (real subflow count) */
122 __u32 size_arrays_user; /* max subflows that userspace is interested in;
123 * the buffers at subflow_info/tcp_info
124 * are respectively at least:
125 * size_arrays * size_sfinfo_user
126 * size_arrays * size_tcpinfo_user
127 * bytes wide
128 */
129 __aligned_u64 subflow_info;
130 __aligned_u64 tcp_info;
131 struct mptcp_info mptcp_info;
132};
133
134/* MPTCP socket options */
135#define MPTCP_INFO 1
136#define MPTCP_TCPINFO 2
137#define MPTCP_SUBFLOW_ADDRS 3
138#define MPTCP_FULL_INFO 4
139
140#endif /* _MPTCP_H */