xref: /freebsd/sys/compat/linux/linux_socket.h (revision bbf392d5eff073919385ecab501fdf9277d2ef68)
140dbba57SAssar Westerlund /*-
240dbba57SAssar Westerlund  * Copyright (c) 2000 Assar Westerlund
340dbba57SAssar Westerlund  * All rights reserved.
440dbba57SAssar Westerlund  *
540dbba57SAssar Westerlund  * Redistribution and use in source and binary forms, with or without
640dbba57SAssar Westerlund  * modification, are permitted provided that the following conditions
740dbba57SAssar Westerlund  * are met:
840dbba57SAssar Westerlund  * 1. Redistributions of source code must retain the above copyright
940dbba57SAssar Westerlund  *    notice, this list of conditions and the following disclaimer
1040dbba57SAssar Westerlund  *    in this position and unchanged.
1140dbba57SAssar Westerlund  * 2. Redistributions in binary form must reproduce the above copyright
1240dbba57SAssar Westerlund  *    notice, this list of conditions and the following disclaimer in the
1340dbba57SAssar Westerlund  *    documentation and/or other materials provided with the distribution.
1440dbba57SAssar Westerlund  * 3. The name of the author may not be used to endorse or promote products
1521dc7d4fSJens Schweikhardt  *    derived from this software without specific prior written permission
1640dbba57SAssar Westerlund  *
1740dbba57SAssar Westerlund  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1840dbba57SAssar Westerlund  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1940dbba57SAssar Westerlund  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2040dbba57SAssar Westerlund  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2140dbba57SAssar Westerlund  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2240dbba57SAssar Westerlund  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2340dbba57SAssar Westerlund  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2440dbba57SAssar Westerlund  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2540dbba57SAssar Westerlund  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2640dbba57SAssar Westerlund  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2740dbba57SAssar Westerlund  *
2840dbba57SAssar Westerlund  * $FreeBSD$
2940dbba57SAssar Westerlund  */
3040dbba57SAssar Westerlund 
3140dbba57SAssar Westerlund #ifndef _LINUX_SOCKET_H_
3240dbba57SAssar Westerlund #define _LINUX_SOCKET_H_
3340dbba57SAssar Westerlund 
3440dbba57SAssar Westerlund /* msg flags in recvfrom/recvmsg */
3540dbba57SAssar Westerlund 
3640dbba57SAssar Westerlund #define LINUX_MSG_OOB		0x01
3740dbba57SAssar Westerlund #define LINUX_MSG_PEEK		0x02
3840dbba57SAssar Westerlund #define LINUX_MSG_DONTROUTE	0x04
3940dbba57SAssar Westerlund #define LINUX_MSG_CTRUNC	0x08
4040dbba57SAssar Westerlund #define LINUX_MSG_PROXY		0x10
4140dbba57SAssar Westerlund #define LINUX_MSG_TRUNC		0x20
4240dbba57SAssar Westerlund #define LINUX_MSG_DONTWAIT	0x40
4340dbba57SAssar Westerlund #define LINUX_MSG_EOR		0x80
4440dbba57SAssar Westerlund #define LINUX_MSG_WAITALL	0x100
4540dbba57SAssar Westerlund #define LINUX_MSG_FIN		0x200
4640dbba57SAssar Westerlund #define LINUX_MSG_SYN		0x400
4740dbba57SAssar Westerlund #define LINUX_MSG_CONFIRM	0x800
4840dbba57SAssar Westerlund #define LINUX_MSG_RST		0x1000
4940dbba57SAssar Westerlund #define LINUX_MSG_ERRQUEUE	0x2000
5040dbba57SAssar Westerlund #define LINUX_MSG_NOSIGNAL	0x4000
51e1ff74c0SDmitry Chagin #define LINUX_MSG_WAITFORONE	0x10000
523a72bf04SDmitry Chagin #define LINUX_MSG_CMSG_CLOEXEC	0x40000000
5340dbba57SAssar Westerlund 
5474f5d680SKonstantin Belousov /* Socket-level control message types */
5574f5d680SKonstantin Belousov 
5674f5d680SKonstantin Belousov #define LINUX_SCM_RIGHTS	0x01
57605da56bSAndriy Gapon #define LINUX_SCM_CREDENTIALS	0x02
58*bbf392d5SDmitry Chagin #define LINUX_SCM_TIMESTAMP	0x1D
5974f5d680SKonstantin Belousov 
60b7aaa9fdSDmitry Chagin struct l_msghdr {
61b7aaa9fdSDmitry Chagin 	l_uintptr_t	msg_name;
62b7aaa9fdSDmitry Chagin 	l_int		msg_namelen;
63b7aaa9fdSDmitry Chagin 	l_uintptr_t	msg_iov;
64b7aaa9fdSDmitry Chagin 	l_size_t	msg_iovlen;
65b7aaa9fdSDmitry Chagin 	l_uintptr_t	msg_control;
66b7aaa9fdSDmitry Chagin 	l_size_t	msg_controllen;
67b7aaa9fdSDmitry Chagin 	l_uint		msg_flags;
68b7aaa9fdSDmitry Chagin };
69b7aaa9fdSDmitry Chagin 
70e1ff74c0SDmitry Chagin struct l_mmsghdr {
71e1ff74c0SDmitry Chagin 	struct l_msghdr	msg_hdr;
72e1ff74c0SDmitry Chagin 	l_uint		msg_len;
73e1ff74c0SDmitry Chagin 
74e1ff74c0SDmitry Chagin };
75e1ff74c0SDmitry Chagin 
76b7aaa9fdSDmitry Chagin struct l_cmsghdr {
77b7aaa9fdSDmitry Chagin 	l_size_t	cmsg_len;
78b7aaa9fdSDmitry Chagin 	l_int		cmsg_level;
79b7aaa9fdSDmitry Chagin 	l_int		cmsg_type;
80b7aaa9fdSDmitry Chagin };
81b7aaa9fdSDmitry Chagin 
8274f5d680SKonstantin Belousov /* Ancilliary data object information macros */
8374f5d680SKonstantin Belousov 
8474f5d680SKonstantin Belousov #define LINUX_CMSG_ALIGN(len)	roundup2(len, sizeof(l_ulong))
8574f5d680SKonstantin Belousov #define LINUX_CMSG_DATA(cmsg)	((void *)((char *)(cmsg) + \
8674f5d680SKonstantin Belousov 				    LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
8774f5d680SKonstantin Belousov #define LINUX_CMSG_SPACE(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
8874f5d680SKonstantin Belousov 				    LINUX_CMSG_ALIGN(len))
8974f5d680SKonstantin Belousov #define LINUX_CMSG_LEN(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
9074f5d680SKonstantin Belousov 				    (len))
9174f5d680SKonstantin Belousov #define LINUX_CMSG_FIRSTHDR(msg) \
9274f5d680SKonstantin Belousov 				((msg)->msg_controllen >= \
9374f5d680SKonstantin Belousov 				    sizeof(struct l_cmsghdr) ? \
94605da56bSAndriy Gapon 				    (struct l_cmsghdr *) \
95605da56bSAndriy Gapon 				        PTRIN((msg)->msg_control) : \
9674f5d680SKonstantin Belousov 				    (struct l_cmsghdr *)(NULL))
9774f5d680SKonstantin Belousov #define LINUX_CMSG_NXTHDR(msg, cmsg) \
9874f5d680SKonstantin Belousov 				((((char *)(cmsg) + \
9974f5d680SKonstantin Belousov 				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
10074f5d680SKonstantin Belousov 				    sizeof(*(cmsg))) > \
101605da56bSAndriy Gapon 				    (((char *)PTRIN((msg)->msg_control)) + \
10274f5d680SKonstantin Belousov 				    (msg)->msg_controllen)) ? \
10374f5d680SKonstantin Belousov 				    (struct l_cmsghdr *) NULL : \
10474f5d680SKonstantin Belousov 				    (struct l_cmsghdr *)((char *)(cmsg) + \
10574f5d680SKonstantin Belousov 				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
10674f5d680SKonstantin Belousov 
10774f5d680SKonstantin Belousov #define CMSG_HDRSZ		CMSG_LEN(0)
10874f5d680SKonstantin Belousov #define L_CMSG_HDRSZ		LINUX_CMSG_LEN(0)
10974f5d680SKonstantin Belousov 
11013f20d7eSDmitry Chagin /* Supported address families */
11113f20d7eSDmitry Chagin 
11213f20d7eSDmitry Chagin #define	LINUX_AF_UNSPEC		0
11313f20d7eSDmitry Chagin #define	LINUX_AF_UNIX		1
11413f20d7eSDmitry Chagin #define	LINUX_AF_INET		2
11513f20d7eSDmitry Chagin #define	LINUX_AF_AX25		3
11613f20d7eSDmitry Chagin #define	LINUX_AF_IPX		4
11713f20d7eSDmitry Chagin #define	LINUX_AF_APPLETALK	5
11813f20d7eSDmitry Chagin #define	LINUX_AF_INET6		10
11913f20d7eSDmitry Chagin 
120eeb63e51SDmitry Chagin /* Supported socket types */
121eeb63e51SDmitry Chagin 
122eeb63e51SDmitry Chagin #define	LINUX_SOCK_STREAM	1
123eeb63e51SDmitry Chagin #define	LINUX_SOCK_DGRAM	2
124eeb63e51SDmitry Chagin #define	LINUX_SOCK_RAW		3
125eeb63e51SDmitry Chagin #define	LINUX_SOCK_RDM		4
126eeb63e51SDmitry Chagin #define	LINUX_SOCK_SEQPACKET	5
127eeb63e51SDmitry Chagin 
128eeb63e51SDmitry Chagin #define	LINUX_SOCK_MAX		LINUX_SOCK_SEQPACKET
129eeb63e51SDmitry Chagin 
1303933bde2SDmitry Chagin #define	LINUX_SOCK_TYPE_MASK	0xf
1313933bde2SDmitry Chagin 
1323933bde2SDmitry Chagin /* Flags for socket, socketpair, accept4 */
1333933bde2SDmitry Chagin 
1343933bde2SDmitry Chagin #define	LINUX_SOCK_CLOEXEC	LINUX_O_CLOEXEC
1353933bde2SDmitry Chagin #define	LINUX_SOCK_NONBLOCK	LINUX_O_NONBLOCK
1363933bde2SDmitry Chagin 
137d4dd69c4SDmitry Chagin struct l_ucred {
138d4dd69c4SDmitry Chagin 	uint32_t	pid;
139d4dd69c4SDmitry Chagin 	uint32_t	uid;
140d4dd69c4SDmitry Chagin 	uint32_t	gid;
141d4dd69c4SDmitry Chagin };
142d4dd69c4SDmitry Chagin 
143a12b9b3dSDmitry Chagin #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
144a12b9b3dSDmitry Chagin 
145a12b9b3dSDmitry Chagin struct linux_sendto_args {
146a12b9b3dSDmitry Chagin 	int s;
147a12b9b3dSDmitry Chagin 	l_uintptr_t msg;
148a12b9b3dSDmitry Chagin 	int len;
149a12b9b3dSDmitry Chagin 	int flags;
150a12b9b3dSDmitry Chagin 	l_uintptr_t to;
151a12b9b3dSDmitry Chagin 	int tolen;
152a12b9b3dSDmitry Chagin };
153a12b9b3dSDmitry Chagin 
154a12b9b3dSDmitry Chagin struct linux_socket_args {
155a12b9b3dSDmitry Chagin 	int domain;
156a12b9b3dSDmitry Chagin 	int type;
157a12b9b3dSDmitry Chagin 	int protocol;
158a12b9b3dSDmitry Chagin };
159a12b9b3dSDmitry Chagin 
160a12b9b3dSDmitry Chagin struct linux_bind_args {
161a12b9b3dSDmitry Chagin 	int s;
162a12b9b3dSDmitry Chagin 	l_uintptr_t name;
163a12b9b3dSDmitry Chagin 	int namelen;
164a12b9b3dSDmitry Chagin };
165a12b9b3dSDmitry Chagin 
166a12b9b3dSDmitry Chagin struct linux_connect_args {
167a12b9b3dSDmitry Chagin 	int s;
168a12b9b3dSDmitry Chagin 	l_uintptr_t name;
169a12b9b3dSDmitry Chagin 	int namelen;
170a12b9b3dSDmitry Chagin };
171a12b9b3dSDmitry Chagin 
172a12b9b3dSDmitry Chagin struct linux_listen_args {
173a12b9b3dSDmitry Chagin 	int s;
174a12b9b3dSDmitry Chagin 	int backlog;
175a12b9b3dSDmitry Chagin };
176a12b9b3dSDmitry Chagin 
177a12b9b3dSDmitry Chagin struct linux_accept_args {
178a12b9b3dSDmitry Chagin 	int s;
179a12b9b3dSDmitry Chagin 	l_uintptr_t addr;
180a12b9b3dSDmitry Chagin 	l_uintptr_t namelen;
181a12b9b3dSDmitry Chagin };
182a12b9b3dSDmitry Chagin 
183a12b9b3dSDmitry Chagin struct linux_accept4_args {
184a12b9b3dSDmitry Chagin 	int s;
185a12b9b3dSDmitry Chagin 	l_uintptr_t addr;
186a12b9b3dSDmitry Chagin 	l_uintptr_t namelen;
187a12b9b3dSDmitry Chagin 	int flags;
188a12b9b3dSDmitry Chagin };
189a12b9b3dSDmitry Chagin 
190a12b9b3dSDmitry Chagin struct linux_getsockname_args {
191a12b9b3dSDmitry Chagin 	int s;
192a12b9b3dSDmitry Chagin 	l_uintptr_t addr;
193a12b9b3dSDmitry Chagin 	l_uintptr_t namelen;
194a12b9b3dSDmitry Chagin };
195a12b9b3dSDmitry Chagin 
196a12b9b3dSDmitry Chagin struct linux_getpeername_args {
197a12b9b3dSDmitry Chagin 	int s;
198a12b9b3dSDmitry Chagin 	l_uintptr_t addr;
199a12b9b3dSDmitry Chagin 	l_uintptr_t namelen;
200a12b9b3dSDmitry Chagin };
201a12b9b3dSDmitry Chagin 
202a12b9b3dSDmitry Chagin struct linux_socketpair_args {
203a12b9b3dSDmitry Chagin 	int domain;
204a12b9b3dSDmitry Chagin 	int type;
205a12b9b3dSDmitry Chagin 	int protocol;
206a12b9b3dSDmitry Chagin 	l_uintptr_t rsv;
207a12b9b3dSDmitry Chagin };
208a12b9b3dSDmitry Chagin 
209a12b9b3dSDmitry Chagin struct linux_recvfrom_args {
210a12b9b3dSDmitry Chagin 	int s;
211a12b9b3dSDmitry Chagin 	l_uintptr_t buf;
212a12b9b3dSDmitry Chagin 	int len;
213a12b9b3dSDmitry Chagin 	int flags;
214a12b9b3dSDmitry Chagin 	l_uintptr_t from;
215a12b9b3dSDmitry Chagin 	l_uintptr_t fromlen;
216a12b9b3dSDmitry Chagin };
217a12b9b3dSDmitry Chagin 
218a12b9b3dSDmitry Chagin struct linux_sendmsg_args {
219a12b9b3dSDmitry Chagin 	int s;
220a12b9b3dSDmitry Chagin 	l_uintptr_t msg;
221a12b9b3dSDmitry Chagin 	int flags;
222a12b9b3dSDmitry Chagin };
223a12b9b3dSDmitry Chagin 
224a12b9b3dSDmitry Chagin struct linux_recvmsg_args {
225a12b9b3dSDmitry Chagin 	int s;
226a12b9b3dSDmitry Chagin 	l_uintptr_t msg;
227a12b9b3dSDmitry Chagin 	int flags;
228a12b9b3dSDmitry Chagin };
229a12b9b3dSDmitry Chagin 
230a12b9b3dSDmitry Chagin struct linux_shutdown_args {
231a12b9b3dSDmitry Chagin 	int s;
232a12b9b3dSDmitry Chagin 	int how;
233a12b9b3dSDmitry Chagin };
234a12b9b3dSDmitry Chagin 
235a12b9b3dSDmitry Chagin struct linux_setsockopt_args {
236a12b9b3dSDmitry Chagin 	int s;
237a12b9b3dSDmitry Chagin 	int level;
238a12b9b3dSDmitry Chagin 	int optname;
239a12b9b3dSDmitry Chagin 	l_uintptr_t optval;
240a12b9b3dSDmitry Chagin 	int optlen;
241a12b9b3dSDmitry Chagin };
242a12b9b3dSDmitry Chagin 
243a12b9b3dSDmitry Chagin struct linux_getsockopt_args {
244a12b9b3dSDmitry Chagin 	int s;
245a12b9b3dSDmitry Chagin 	int level;
246a12b9b3dSDmitry Chagin 	int optname;
247a12b9b3dSDmitry Chagin 	l_uintptr_t optval;
248a12b9b3dSDmitry Chagin 	l_uintptr_t optlen;
249a12b9b3dSDmitry Chagin };
250a12b9b3dSDmitry Chagin 
251a12b9b3dSDmitry Chagin int linux_socket(struct thread *td, struct linux_socket_args *args);
252a12b9b3dSDmitry Chagin int linux_bind(struct thread *td, struct linux_bind_args *args);
253a12b9b3dSDmitry Chagin int linux_connect(struct thread *, struct linux_connect_args *);
254a12b9b3dSDmitry Chagin int linux_listen(struct thread *td, struct linux_listen_args *args);
255a12b9b3dSDmitry Chagin int linux_accept(struct thread *td, struct linux_accept_args *args);
256a12b9b3dSDmitry Chagin int linux_accept4(struct thread *td, struct linux_accept4_args *args);
257a12b9b3dSDmitry Chagin int linux_getsockname(struct thread *td, struct linux_getsockname_args *args);
258a12b9b3dSDmitry Chagin int linux_getpeername(struct thread *td, struct linux_getpeername_args *args);
259a12b9b3dSDmitry Chagin int linux_socketpair(struct thread *td, struct linux_socketpair_args *args);
260a12b9b3dSDmitry Chagin int linux_sendto(struct thread *td, struct linux_sendto_args *args);
261a12b9b3dSDmitry Chagin int linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args);
262a12b9b3dSDmitry Chagin int linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args);
263a12b9b3dSDmitry Chagin int linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args);
264a12b9b3dSDmitry Chagin int linux_shutdown(struct thread *td, struct linux_shutdown_args *args);
265a12b9b3dSDmitry Chagin int linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args);
266a12b9b3dSDmitry Chagin int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args);
267a12b9b3dSDmitry Chagin 
268a12b9b3dSDmitry Chagin #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
269a12b9b3dSDmitry Chagin 
270d825ce0aSJohn Baldwin /* Operations for socketcall */
271d825ce0aSJohn Baldwin 
272d825ce0aSJohn Baldwin #define	LINUX_SOCKET 		1
273d825ce0aSJohn Baldwin #define	LINUX_BIND		2
274d825ce0aSJohn Baldwin #define	LINUX_CONNECT 		3
275d825ce0aSJohn Baldwin #define	LINUX_LISTEN 		4
276d825ce0aSJohn Baldwin #define	LINUX_ACCEPT 		5
277d825ce0aSJohn Baldwin #define	LINUX_GETSOCKNAME	6
278d825ce0aSJohn Baldwin #define	LINUX_GETPEERNAME	7
279d825ce0aSJohn Baldwin #define	LINUX_SOCKETPAIR	8
280d825ce0aSJohn Baldwin #define	LINUX_SEND		9
281d825ce0aSJohn Baldwin #define	LINUX_RECV		10
282d825ce0aSJohn Baldwin #define	LINUX_SENDTO 		11
283d825ce0aSJohn Baldwin #define	LINUX_RECVFROM 		12
284d825ce0aSJohn Baldwin #define	LINUX_SHUTDOWN 		13
285d825ce0aSJohn Baldwin #define	LINUX_SETSOCKOPT	14
286d825ce0aSJohn Baldwin #define	LINUX_GETSOCKOPT	15
287d825ce0aSJohn Baldwin #define	LINUX_SENDMSG		16
288d825ce0aSJohn Baldwin #define	LINUX_RECVMSG		17
289d825ce0aSJohn Baldwin #define	LINUX_ACCEPT4		18
290e1ff74c0SDmitry Chagin #define	LINUX_RECVMMSG		19
291e1ff74c0SDmitry Chagin #define	LINUX_SENDMMSG		20
292d825ce0aSJohn Baldwin 
293d825ce0aSJohn Baldwin /* Socket options */
294d825ce0aSJohn Baldwin #define	LINUX_IP_TOS		1
295d825ce0aSJohn Baldwin #define	LINUX_IP_TTL		2
296d825ce0aSJohn Baldwin #define	LINUX_IP_HDRINCL	3
297d825ce0aSJohn Baldwin #define	LINUX_IP_OPTIONS	4
298d825ce0aSJohn Baldwin 
299d825ce0aSJohn Baldwin #define	LINUX_IP_MULTICAST_IF		32
300d825ce0aSJohn Baldwin #define	LINUX_IP_MULTICAST_TTL		33
301d825ce0aSJohn Baldwin #define	LINUX_IP_MULTICAST_LOOP		34
302d825ce0aSJohn Baldwin #define	LINUX_IP_ADD_MEMBERSHIP		35
303d825ce0aSJohn Baldwin #define	LINUX_IP_DROP_MEMBERSHIP	36
304d825ce0aSJohn Baldwin 
305d825ce0aSJohn Baldwin #define	LINUX_TCP_NODELAY	1
306d825ce0aSJohn Baldwin #define	LINUX_TCP_MAXSEG	2
307d825ce0aSJohn Baldwin #define	LINUX_TCP_KEEPIDLE	4
308d825ce0aSJohn Baldwin #define	LINUX_TCP_KEEPINTVL	5
309d825ce0aSJohn Baldwin #define	LINUX_TCP_KEEPCNT	6
310d825ce0aSJohn Baldwin #define	LINUX_TCP_MD5SIG	14
311d825ce0aSJohn Baldwin 
31240dbba57SAssar Westerlund #endif /* _LINUX_SOCKET_H_ */
313