linux_socket.h revision 298829
111695Sache/*-
211695Sache * Copyright (c) 2000 Assar Westerlund
311695Sache * All rights reserved.
411695Sache *
511695Sache * Redistribution and use in source and binary forms, with or without
611695Sache * modification, are permitted provided that the following conditions
711695Sache * are met:
8227753Stheraven * 1. Redistributions of source code must retain the above copyright
9227753Stheraven *    notice, this list of conditions and the following disclaimer
10227753Stheraven *    in this position and unchanged.
11227753Stheraven * 2. Redistributions in binary form must reproduce the above copyright
12227753Stheraven *    notice, this list of conditions and the following disclaimer in the
1311695Sache *    documentation and/or other materials provided with the distribution.
1411695Sache * 3. The name of the author may not be used to endorse or promote products
1511695Sache *    derived from this software without specific prior written permission
1611695Sache *
1711695Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1811695Sache * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1911695Sache * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011695Sache * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2111695Sache * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2211695Sache * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311695Sache * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411695Sache * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511695Sache * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2611695Sache * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711695Sache *
2811695Sache * $FreeBSD: head/sys/compat/linux/linux_socket.h 298829 2016-04-30 00:53:10Z pfg $
2911695Sache */
3011695Sache
3111695Sache#ifndef _LINUX_SOCKET_H_
3211695Sache#define _LINUX_SOCKET_H_
3311695Sache
3411695Sache/* msg flags in recvfrom/recvmsg */
3511695Sache
3611695Sache#define LINUX_MSG_OOB		0x01
3711695Sache#define LINUX_MSG_PEEK		0x02
3892986Sobrien#define LINUX_MSG_DONTROUTE	0x04
3992986Sobrien#define LINUX_MSG_CTRUNC	0x08
4092986Sobrien#define LINUX_MSG_PROXY		0x10
41150065Sstefanf#define LINUX_MSG_TRUNC		0x20
423050Sache#define LINUX_MSG_DONTWAIT	0x40
43132820Stjr#define LINUX_MSG_EOR		0x80
44227753Stheraven#define LINUX_MSG_WAITALL	0x100
45227753Stheraven#define LINUX_MSG_FIN		0x200
463050Sache#define LINUX_MSG_SYN		0x400
473050Sache#define LINUX_MSG_CONFIRM	0x800
48227753Stheraven#define LINUX_MSG_RST		0x1000
493050Sache#define LINUX_MSG_ERRQUEUE	0x2000
50129065Stjr#define LINUX_MSG_NOSIGNAL	0x4000
51227753Stheraven#define LINUX_MSG_WAITFORONE	0x10000
52227753Stheraven#define LINUX_MSG_CMSG_CLOEXEC	0x40000000
53129065Stjr
543050Sache/* Socket-level control message types */
5514811Sache
5614811Sache#define LINUX_SCM_RIGHTS	0x01
5712022Sache#define LINUX_SCM_CREDENTIALS	0x02
58129065Stjr#define LINUX_SCM_TIMESTAMP	0x1D
59130961Stjr
60130961Stjrstruct l_msghdr {
61129065Stjr	l_uintptr_t	msg_name;
62130961Stjr	l_int		msg_namelen;
63130961Stjr	l_uintptr_t	msg_iov;
64130961Stjr	l_size_t	msg_iovlen;
653050Sache	l_uintptr_t	msg_control;
66130961Stjr	l_size_t	msg_controllen;
67130961Stjr	l_uint		msg_flags;
68129065Stjr};
69129065Stjr
703050Sachestruct l_mmsghdr {
713050Sache	struct l_msghdr	msg_hdr;
7261218Sache	l_uint		msg_len;
733050Sache
743050Sache};
75227753Stheraven
76227753Stheravenstruct l_cmsghdr {
77227753Stheraven	l_size_t	cmsg_len;
78227753Stheraven	l_int		cmsg_level;
79227753Stheraven	l_int		cmsg_type;
80227753Stheraven};
81227753Stheraven
82227753Stheraven/* Ancillary data object information macros */
83227753Stheraven
84227753Stheraven#define LINUX_CMSG_ALIGN(len)	roundup2(len, sizeof(l_ulong))
85227753Stheraven#define LINUX_CMSG_DATA(cmsg)	((void *)((char *)(cmsg) + \
86227753Stheraven				    LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
87227753Stheraven#define LINUX_CMSG_SPACE(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
88227753Stheraven				    LINUX_CMSG_ALIGN(len))
89227753Stheraven#define LINUX_CMSG_LEN(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
90				    (len))
91#define LINUX_CMSG_FIRSTHDR(msg) \
92				((msg)->msg_controllen >= \
93				    sizeof(struct l_cmsghdr) ? \
94				    (struct l_cmsghdr *) \
95				        PTRIN((msg)->msg_control) : \
96				    (struct l_cmsghdr *)(NULL))
97#define LINUX_CMSG_NXTHDR(msg, cmsg) \
98				((((char *)(cmsg) + \
99				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
100				    sizeof(*(cmsg))) > \
101				    (((char *)PTRIN((msg)->msg_control)) + \
102				    (msg)->msg_controllen)) ? \
103				    (struct l_cmsghdr *) NULL : \
104				    (struct l_cmsghdr *)((char *)(cmsg) + \
105				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
106
107#define CMSG_HDRSZ		CMSG_LEN(0)
108#define L_CMSG_HDRSZ		LINUX_CMSG_LEN(0)
109
110/* Supported address families */
111
112#define	LINUX_AF_UNSPEC		0
113#define	LINUX_AF_UNIX		1
114#define	LINUX_AF_INET		2
115#define	LINUX_AF_AX25		3
116#define	LINUX_AF_IPX		4
117#define	LINUX_AF_APPLETALK	5
118#define	LINUX_AF_INET6		10
119
120/* Supported socket types */
121
122#define	LINUX_SOCK_STREAM	1
123#define	LINUX_SOCK_DGRAM	2
124#define	LINUX_SOCK_RAW		3
125#define	LINUX_SOCK_RDM		4
126#define	LINUX_SOCK_SEQPACKET	5
127
128#define	LINUX_SOCK_MAX		LINUX_SOCK_SEQPACKET
129
130#define	LINUX_SOCK_TYPE_MASK	0xf
131
132/* Flags for socket, socketpair, accept4 */
133
134#define	LINUX_SOCK_CLOEXEC	LINUX_O_CLOEXEC
135#define	LINUX_SOCK_NONBLOCK	LINUX_O_NONBLOCK
136
137struct l_ucred {
138	uint32_t	pid;
139	uint32_t	uid;
140	uint32_t	gid;
141};
142
143#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
144
145struct linux_sendto_args {
146	int s;
147	l_uintptr_t msg;
148	int len;
149	int flags;
150	l_uintptr_t to;
151	int tolen;
152};
153
154struct linux_socket_args {
155	int domain;
156	int type;
157	int protocol;
158};
159
160struct linux_bind_args {
161	int s;
162	l_uintptr_t name;
163	int namelen;
164};
165
166struct linux_connect_args {
167	int s;
168	l_uintptr_t name;
169	int namelen;
170};
171
172struct linux_listen_args {
173	int s;
174	int backlog;
175};
176
177struct linux_accept_args {
178	int s;
179	l_uintptr_t addr;
180	l_uintptr_t namelen;
181};
182
183struct linux_accept4_args {
184	int s;
185	l_uintptr_t addr;
186	l_uintptr_t namelen;
187	int flags;
188};
189
190struct linux_getsockname_args {
191	int s;
192	l_uintptr_t addr;
193	l_uintptr_t namelen;
194};
195
196struct linux_getpeername_args {
197	int s;
198	l_uintptr_t addr;
199	l_uintptr_t namelen;
200};
201
202struct linux_socketpair_args {
203	int domain;
204	int type;
205	int protocol;
206	l_uintptr_t rsv;
207};
208
209struct linux_recvfrom_args {
210	int s;
211	l_uintptr_t buf;
212	int len;
213	int flags;
214	l_uintptr_t from;
215	l_uintptr_t fromlen;
216};
217
218struct linux_sendmsg_args {
219	int s;
220	l_uintptr_t msg;
221	int flags;
222};
223
224struct linux_recvmsg_args {
225	int s;
226	l_uintptr_t msg;
227	int flags;
228};
229
230struct linux_shutdown_args {
231	int s;
232	int how;
233};
234
235struct linux_setsockopt_args {
236	int s;
237	int level;
238	int optname;
239	l_uintptr_t optval;
240	int optlen;
241};
242
243struct linux_getsockopt_args {
244	int s;
245	int level;
246	int optname;
247	l_uintptr_t optval;
248	l_uintptr_t optlen;
249};
250
251int linux_socket(struct thread *td, struct linux_socket_args *args);
252int linux_bind(struct thread *td, struct linux_bind_args *args);
253int linux_connect(struct thread *, struct linux_connect_args *);
254int linux_listen(struct thread *td, struct linux_listen_args *args);
255int linux_accept(struct thread *td, struct linux_accept_args *args);
256int linux_accept4(struct thread *td, struct linux_accept4_args *args);
257int linux_getsockname(struct thread *td, struct linux_getsockname_args *args);
258int linux_getpeername(struct thread *td, struct linux_getpeername_args *args);
259int linux_socketpair(struct thread *td, struct linux_socketpair_args *args);
260int linux_sendto(struct thread *td, struct linux_sendto_args *args);
261int linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args);
262int linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args);
263int linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args);
264int linux_shutdown(struct thread *td, struct linux_shutdown_args *args);
265int linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args);
266int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args);
267
268#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
269
270/* Operations for socketcall */
271
272#define	LINUX_SOCKET 		1
273#define	LINUX_BIND		2
274#define	LINUX_CONNECT 		3
275#define	LINUX_LISTEN 		4
276#define	LINUX_ACCEPT 		5
277#define	LINUX_GETSOCKNAME	6
278#define	LINUX_GETPEERNAME	7
279#define	LINUX_SOCKETPAIR	8
280#define	LINUX_SEND		9
281#define	LINUX_RECV		10
282#define	LINUX_SENDTO 		11
283#define	LINUX_RECVFROM 		12
284#define	LINUX_SHUTDOWN 		13
285#define	LINUX_SETSOCKOPT	14
286#define	LINUX_GETSOCKOPT	15
287#define	LINUX_SENDMSG		16
288#define	LINUX_RECVMSG		17
289#define	LINUX_ACCEPT4		18
290#define	LINUX_RECVMMSG		19
291#define	LINUX_SENDMMSG		20
292
293/* Socket options */
294#define	LINUX_IP_TOS		1
295#define	LINUX_IP_TTL		2
296#define	LINUX_IP_HDRINCL	3
297#define	LINUX_IP_OPTIONS	4
298
299#define	LINUX_IP_MULTICAST_IF		32
300#define	LINUX_IP_MULTICAST_TTL		33
301#define	LINUX_IP_MULTICAST_LOOP		34
302#define	LINUX_IP_ADD_MEMBERSHIP		35
303#define	LINUX_IP_DROP_MEMBERSHIP	36
304
305#define	LINUX_IPV6_CHECKSUM		7
306#define	LINUX_IPV6_NEXTHOP		9
307#define	LINUX_IPV6_UNICAST_HOPS		16
308#define	LINUX_IPV6_MULTICAST_IF		17
309#define	LINUX_IPV6_MULTICAST_HOPS	18
310#define	LINUX_IPV6_MULTICAST_LOOP	19
311#define	LINUX_IPV6_ADD_MEMBERSHIP	20
312#define	LINUX_IPV6_DROP_MEMBERSHIP	21
313#define	LINUX_IPV6_V6ONLY		26
314
315#define	LINUX_IPV6_RECVPKTINFO		49
316#define	LINUX_IPV6_PKTINFO		50
317#define	LINUX_IPV6_RECVHOPLIMIT		51
318#define	LINUX_IPV6_HOPLIMIT		52
319#define	LINUX_IPV6_RECVHOPOPTS		53
320#define	LINUX_IPV6_HOPOPTS		54
321#define	LINUX_IPV6_RTHDRDSTOPTS		55
322#define	LINUX_IPV6_RECVRTHDR		56
323#define	LINUX_IPV6_RTHDR		57
324#define	LINUX_IPV6_RECVDSTOPTS		58
325#define	LINUX_IPV6_DSTOPTS		59
326#define	LINUX_IPV6_RECVPATHMTU		60
327#define	LINUX_IPV6_PATHMTU		61
328#define	LINUX_IPV6_DONTFRAG		62
329
330#define	LINUX_TCP_NODELAY	1
331#define	LINUX_TCP_MAXSEG	2
332#define	LINUX_TCP_KEEPIDLE	4
333#define	LINUX_TCP_KEEPINTVL	5
334#define	LINUX_TCP_KEEPCNT	6
335#define	LINUX_TCP_MD5SIG	14
336
337#endif /* _LINUX_SOCKET_H_ */
338