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 };
127 
128 /*
129  * MPTCP_EVENT_CREATED: token, family, saddr4 | saddr6, daddr4 | daddr6,
130  *                      sport, dport
131  * A new MPTCP connection has been created. It is the good time to allocate
132  * memory and send ADD_ADDR if needed. Depending on the traffic-patterns
133  * it can take a long time until the MPTCP_EVENT_ESTABLISHED is sent.
134  *
135  * MPTCP_EVENT_ESTABLISHED: token, family, saddr4 | saddr6, daddr4 | daddr6,
136  *			    sport, dport
137  * A MPTCP connection is established (can start new subflows).
138  *
139  * MPTCP_EVENT_CLOSED: token
140  * A MPTCP connection has stopped.
141  *
142  * MPTCP_EVENT_ANNOUNCED: token, rem_id, family, daddr4 | daddr6 [, dport]
143  * A new address has been announced by the peer.
144  *
145  * MPTCP_EVENT_REMOVED: token, rem_id
146  * An address has been lost by the peer.
147  *
148  * MPTCP_EVENT_SUB_ESTABLISHED: token, family, loc_id, rem_id,
149  *                              saddr4 | saddr6, daddr4 | daddr6, sport,
150  *                              dport, backup, if_idx [, error]
151  * A new subflow has been established. 'error' should not be set.
152  *
153  * MPTCP_EVENT_SUB_CLOSED: token, family, loc_id, rem_id, saddr4 | saddr6,
154  *                         daddr4 | daddr6, sport, dport, backup, if_idx
155  *                         [, error]
156  * A subflow has been closed. An error (copy of sk_err) could be set if an
157  * error has been detected for this subflow.
158  *
159  * MPTCP_EVENT_SUB_PRIORITY: token, family, loc_id, rem_id, saddr4 | saddr6,
160  *                           daddr4 | daddr6, sport, dport, backup, if_idx
161  *                           [, error]
162  * The priority of a subflow has changed. 'error' should not be set.
163  */
164 enum mptcp_event_type {
165 	MPTCP_EVENT_UNSPEC = 0,
166 	MPTCP_EVENT_CREATED = 1,
167 	MPTCP_EVENT_ESTABLISHED = 2,
168 	MPTCP_EVENT_CLOSED = 3,
169 
170 	MPTCP_EVENT_ANNOUNCED = 6,
171 	MPTCP_EVENT_REMOVED = 7,
172 
173 	MPTCP_EVENT_SUB_ESTABLISHED = 10,
174 	MPTCP_EVENT_SUB_CLOSED = 11,
175 
176 	MPTCP_EVENT_SUB_PRIORITY = 13,
177 };
178 
179 enum mptcp_event_attr {
180 	MPTCP_ATTR_UNSPEC = 0,
181 
182 	MPTCP_ATTR_TOKEN,	/* u32 */
183 	MPTCP_ATTR_FAMILY,	/* u16 */
184 	MPTCP_ATTR_LOC_ID,	/* u8 */
185 	MPTCP_ATTR_REM_ID,	/* u8 */
186 	MPTCP_ATTR_SADDR4,	/* be32 */
187 	MPTCP_ATTR_SADDR6,	/* struct in6_addr */
188 	MPTCP_ATTR_DADDR4,	/* be32 */
189 	MPTCP_ATTR_DADDR6,	/* struct in6_addr */
190 	MPTCP_ATTR_SPORT,	/* be16 */
191 	MPTCP_ATTR_DPORT,	/* be16 */
192 	MPTCP_ATTR_BACKUP,	/* u8 */
193 	MPTCP_ATTR_ERROR,	/* u8 */
194 	MPTCP_ATTR_FLAGS,	/* u16 */
195 	MPTCP_ATTR_TIMEOUT,	/* u32 */
196 	MPTCP_ATTR_IF_IDX,	/* s32 */
197 	MPTCP_ATTR_RESET_REASON,/* u32 */
198 	MPTCP_ATTR_RESET_FLAGS, /* u32 */
199 	MPTCP_ATTR_SERVER_SIDE,	/* u8 */
200 
201 	__MPTCP_ATTR_AFTER_LAST
202 };
203 
204 #define MPTCP_ATTR_MAX (__MPTCP_ATTR_AFTER_LAST - 1)
205 
206 /* MPTCP Reset reason codes, rfc8684 */
207 #define MPTCP_RST_EUNSPEC	0
208 #define MPTCP_RST_EMPTCP	1
209 #define MPTCP_RST_ERESOURCE	2
210 #define MPTCP_RST_EPROHIBIT	3
211 #define MPTCP_RST_EWQ2BIG	4
212 #define MPTCP_RST_EBADPERF	5
213 #define MPTCP_RST_EMIDDLEBOX	6
214 
215 struct mptcp_subflow_data {
216 	__u32		size_subflow_data;		/* size of this structure in userspace */
217 	__u32		num_subflows;			/* must be 0, set by kernel */
218 	__u32		size_kernel;			/* must be 0, set by kernel */
219 	__u32		size_user;			/* size of one element in data[] */
220 } __attribute__((aligned(8)));
221 
222 struct mptcp_subflow_addrs {
223 	union {
224 		__kernel_sa_family_t sa_family;
225 		struct sockaddr sa_local;
226 		struct sockaddr_in sin_local;
227 		struct sockaddr_in6 sin6_local;
228 		struct __kernel_sockaddr_storage ss_local;
229 	};
230 	union {
231 		struct sockaddr sa_remote;
232 		struct sockaddr_in sin_remote;
233 		struct sockaddr_in6 sin6_remote;
234 		struct __kernel_sockaddr_storage ss_remote;
235 	};
236 };
237 
238 /* MPTCP socket options */
239 #define MPTCP_INFO		1
240 #define MPTCP_TCPINFO		2
241 #define MPTCP_SUBFLOW_ADDRS	3
242 
243 #endif /* _UAPI_MPTCP_H */
244