xref: /openbmc/linux/include/uapi/linux/mptcp.h (revision 49243207)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 #ifndef _UAPI_MPTCP_H
3 #define _UAPI_MPTCP_H
4 
5 #ifndef __KERNEL__
6 #include <netinet/in.h>		/* for sockaddr_in and sockaddr_in6	*/
7 #include <sys/socket.h>		/* for struct sockaddr			*/
8 #endif
9 
10 #include <linux/const.h>
11 #include <linux/types.h>
12 #include <linux/in.h>		/* for sockaddr_in			*/
13 #include <linux/in6.h>		/* for sockaddr_in6			*/
14 #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
15 
16 #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
17 #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
18 #define MPTCP_SUBFLOW_FLAG_JOIN_REM		_BITUL(2)
19 #define MPTCP_SUBFLOW_FLAG_JOIN_LOC		_BITUL(3)
20 #define MPTCP_SUBFLOW_FLAG_BKUP_REM		_BITUL(4)
21 #define MPTCP_SUBFLOW_FLAG_BKUP_LOC		_BITUL(5)
22 #define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED	_BITUL(6)
23 #define MPTCP_SUBFLOW_FLAG_CONNECTED		_BITUL(7)
24 #define MPTCP_SUBFLOW_FLAG_MAPVALID		_BITUL(8)
25 
26 enum {
27 	MPTCP_SUBFLOW_ATTR_UNSPEC,
28 	MPTCP_SUBFLOW_ATTR_TOKEN_REM,
29 	MPTCP_SUBFLOW_ATTR_TOKEN_LOC,
30 	MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
31 	MPTCP_SUBFLOW_ATTR_MAP_SEQ,
32 	MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
33 	MPTCP_SUBFLOW_ATTR_SSN_OFFSET,
34 	MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
35 	MPTCP_SUBFLOW_ATTR_FLAGS,
36 	MPTCP_SUBFLOW_ATTR_ID_REM,
37 	MPTCP_SUBFLOW_ATTR_ID_LOC,
38 	MPTCP_SUBFLOW_ATTR_PAD,
39 	__MPTCP_SUBFLOW_ATTR_MAX
40 };
41 
42 #define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1)
43 
44 /* netlink interface */
45 #define MPTCP_PM_NAME		"mptcp_pm"
46 #define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
47 #define MPTCP_PM_EV_GRP_NAME	"mptcp_pm_events"
48 #define MPTCP_PM_VER		0x1
49 
50 /*
51  * ATTR types defined for MPTCP
52  */
53 enum {
54 	MPTCP_PM_ATTR_UNSPEC,
55 
56 	MPTCP_PM_ATTR_ADDR,				/* nested address */
57 	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
58 	MPTCP_PM_ATTR_SUBFLOWS,				/* u32 */
59 	MPTCP_PM_ATTR_TOKEN,				/* u32 */
60 	MPTCP_PM_ATTR_LOC_ID,				/* u8 */
61 	MPTCP_PM_ATTR_ADDR_REMOTE,			/* nested address */
62 
63 	__MPTCP_PM_ATTR_MAX
64 };
65 
66 #define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
67 
68 enum {
69 	MPTCP_PM_ADDR_ATTR_UNSPEC,
70 
71 	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
72 	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
73 	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
74 	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
75 	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */
76 	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
77 	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
78 
79 	__MPTCP_PM_ADDR_ATTR_MAX
80 };
81 
82 #define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
83 
84 #define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
85 #define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
86 #define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)
87 #define MPTCP_PM_ADDR_FLAG_FULLMESH			(1 << 3)
88 #define MPTCP_PM_ADDR_FLAG_IMPLICIT			(1 << 4)
89 
90 enum {
91 	MPTCP_PM_CMD_UNSPEC,
92 
93 	MPTCP_PM_CMD_ADD_ADDR,
94 	MPTCP_PM_CMD_DEL_ADDR,
95 	MPTCP_PM_CMD_GET_ADDR,
96 	MPTCP_PM_CMD_FLUSH_ADDRS,
97 	MPTCP_PM_CMD_SET_LIMITS,
98 	MPTCP_PM_CMD_GET_LIMITS,
99 	MPTCP_PM_CMD_SET_FLAGS,
100 	MPTCP_PM_CMD_ANNOUNCE,
101 	MPTCP_PM_CMD_REMOVE,
102 	MPTCP_PM_CMD_SUBFLOW_CREATE,
103 	MPTCP_PM_CMD_SUBFLOW_DESTROY,
104 
105 	__MPTCP_PM_CMD_AFTER_LAST
106 };
107 
108 #define MPTCP_INFO_FLAG_FALLBACK		_BITUL(0)
109 #define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED	_BITUL(1)
110 
111 struct mptcp_info {
112 	__u8	mptcpi_subflows;
113 	__u8	mptcpi_add_addr_signal;
114 	__u8	mptcpi_add_addr_accepted;
115 	__u8	mptcpi_subflows_max;
116 	__u8	mptcpi_add_addr_signal_max;
117 	__u8	mptcpi_add_addr_accepted_max;
118 	__u32	mptcpi_flags;
119 	__u32	mptcpi_token;
120 	__u64	mptcpi_write_seq;
121 	__u64	mptcpi_snd_una;
122 	__u64	mptcpi_rcv_nxt;
123 	__u8	mptcpi_local_addr_used;
124 	__u8	mptcpi_local_addr_max;
125 	__u8	mptcpi_csum_enabled;
126 	__u32	mptcpi_retransmits;
127 	__u64	mptcpi_bytes_retrans;
128 	__u64	mptcpi_bytes_sent;
129 	__u64	mptcpi_bytes_received;
130 	__u64	mptcpi_bytes_acked;
131 };
132 
133 /*
134  * MPTCP_EVENT_CREATED: token, family, saddr4 | saddr6, daddr4 | daddr6,
135  *                      sport, dport
136  * A new MPTCP connection has been created. It is the good time to allocate
137  * memory and send ADD_ADDR if needed. Depending on the traffic-patterns
138  * it can take a long time until the MPTCP_EVENT_ESTABLISHED is sent.
139  *
140  * MPTCP_EVENT_ESTABLISHED: token, family, saddr4 | saddr6, daddr4 | daddr6,
141  *			    sport, dport
142  * A MPTCP connection is established (can start new subflows).
143  *
144  * MPTCP_EVENT_CLOSED: token
145  * A MPTCP connection has stopped.
146  *
147  * MPTCP_EVENT_ANNOUNCED: token, rem_id, family, daddr4 | daddr6 [, dport]
148  * A new address has been announced by the peer.
149  *
150  * MPTCP_EVENT_REMOVED: token, rem_id
151  * An address has been lost by the peer.
152  *
153  * MPTCP_EVENT_SUB_ESTABLISHED: token, family, loc_id, rem_id,
154  *                              saddr4 | saddr6, daddr4 | daddr6, sport,
155  *                              dport, backup, if_idx [, error]
156  * A new subflow has been established. 'error' should not be set.
157  *
158  * MPTCP_EVENT_SUB_CLOSED: token, family, loc_id, rem_id, saddr4 | saddr6,
159  *                         daddr4 | daddr6, sport, dport, backup, if_idx
160  *                         [, error]
161  * A subflow has been closed. An error (copy of sk_err) could be set if an
162  * error has been detected for this subflow.
163  *
164  * MPTCP_EVENT_SUB_PRIORITY: token, family, loc_id, rem_id, saddr4 | saddr6,
165  *                           daddr4 | daddr6, sport, dport, backup, if_idx
166  *                           [, error]
167  * The priority of a subflow has changed. 'error' should not be set.
168  *
169  * MPTCP_EVENT_LISTENER_CREATED: family, sport, saddr4 | saddr6
170  * A new PM listener is created.
171  *
172  * MPTCP_EVENT_LISTENER_CLOSED: family, sport, saddr4 | saddr6
173  * A PM listener is closed.
174  */
175 enum mptcp_event_type {
176 	MPTCP_EVENT_UNSPEC = 0,
177 	MPTCP_EVENT_CREATED = 1,
178 	MPTCP_EVENT_ESTABLISHED = 2,
179 	MPTCP_EVENT_CLOSED = 3,
180 
181 	MPTCP_EVENT_ANNOUNCED = 6,
182 	MPTCP_EVENT_REMOVED = 7,
183 
184 	MPTCP_EVENT_SUB_ESTABLISHED = 10,
185 	MPTCP_EVENT_SUB_CLOSED = 11,
186 
187 	MPTCP_EVENT_SUB_PRIORITY = 13,
188 
189 	MPTCP_EVENT_LISTENER_CREATED = 15,
190 	MPTCP_EVENT_LISTENER_CLOSED = 16,
191 };
192 
193 enum mptcp_event_attr {
194 	MPTCP_ATTR_UNSPEC = 0,
195 
196 	MPTCP_ATTR_TOKEN,	/* u32 */
197 	MPTCP_ATTR_FAMILY,	/* u16 */
198 	MPTCP_ATTR_LOC_ID,	/* u8 */
199 	MPTCP_ATTR_REM_ID,	/* u8 */
200 	MPTCP_ATTR_SADDR4,	/* be32 */
201 	MPTCP_ATTR_SADDR6,	/* struct in6_addr */
202 	MPTCP_ATTR_DADDR4,	/* be32 */
203 	MPTCP_ATTR_DADDR6,	/* struct in6_addr */
204 	MPTCP_ATTR_SPORT,	/* be16 */
205 	MPTCP_ATTR_DPORT,	/* be16 */
206 	MPTCP_ATTR_BACKUP,	/* u8 */
207 	MPTCP_ATTR_ERROR,	/* u8 */
208 	MPTCP_ATTR_FLAGS,	/* u16 */
209 	MPTCP_ATTR_TIMEOUT,	/* u32 */
210 	MPTCP_ATTR_IF_IDX,	/* s32 */
211 	MPTCP_ATTR_RESET_REASON,/* u32 */
212 	MPTCP_ATTR_RESET_FLAGS, /* u32 */
213 	MPTCP_ATTR_SERVER_SIDE,	/* u8 */
214 
215 	__MPTCP_ATTR_AFTER_LAST
216 };
217 
218 #define MPTCP_ATTR_MAX (__MPTCP_ATTR_AFTER_LAST - 1)
219 
220 /* MPTCP Reset reason codes, rfc8684 */
221 #define MPTCP_RST_EUNSPEC	0
222 #define MPTCP_RST_EMPTCP	1
223 #define MPTCP_RST_ERESOURCE	2
224 #define MPTCP_RST_EPROHIBIT	3
225 #define MPTCP_RST_EWQ2BIG	4
226 #define MPTCP_RST_EBADPERF	5
227 #define MPTCP_RST_EMIDDLEBOX	6
228 
229 struct mptcp_subflow_data {
230 	__u32		size_subflow_data;		/* size of this structure in userspace */
231 	__u32		num_subflows;			/* must be 0, set by kernel */
232 	__u32		size_kernel;			/* must be 0, set by kernel */
233 	__u32		size_user;			/* size of one element in data[] */
234 } __attribute__((aligned(8)));
235 
236 struct mptcp_subflow_addrs {
237 	union {
238 		__kernel_sa_family_t sa_family;
239 		struct sockaddr sa_local;
240 		struct sockaddr_in sin_local;
241 		struct sockaddr_in6 sin6_local;
242 		struct __kernel_sockaddr_storage ss_local;
243 	};
244 	union {
245 		struct sockaddr sa_remote;
246 		struct sockaddr_in sin_remote;
247 		struct sockaddr_in6 sin6_remote;
248 		struct __kernel_sockaddr_storage ss_remote;
249 	};
250 };
251 
252 struct mptcp_subflow_info {
253 	__u32				id;
254 	struct mptcp_subflow_addrs	addrs;
255 };
256 
257 struct mptcp_full_info {
258 	__u32		size_tcpinfo_kernel;	/* must be 0, set by kernel */
259 	__u32		size_tcpinfo_user;
260 	__u32		size_sfinfo_kernel;	/* must be 0, set by kernel */
261 	__u32		size_sfinfo_user;
262 	__u32		num_subflows;		/* must be 0, set by kernel (real subflow count) */
263 	__u32		size_arrays_user;	/* max subflows that userspace is interested in;
264 						 * the buffers at subflow_info/tcp_info
265 						 * are respectively at least:
266 						 *  size_arrays * size_sfinfo_user
267 						 *  size_arrays * size_tcpinfo_user
268 						 * bytes wide
269 						 */
270 	__aligned_u64		subflow_info;
271 	__aligned_u64		tcp_info;
272 	struct mptcp_info	mptcp_info;
273 };
274 
275 /* MPTCP socket options */
276 #define MPTCP_INFO		1
277 #define MPTCP_TCPINFO		2
278 #define MPTCP_SUBFLOW_ADDRS	3
279 #define MPTCP_FULL_INFO		4
280 
281 #endif /* _UAPI_MPTCP_H */
282