linux_socket.h revision 283487
170178Sassar/*-
270178Sassar * Copyright (c) 2000 Assar Westerlund
370178Sassar * All rights reserved.
470178Sassar *
570178Sassar * Redistribution and use in source and binary forms, with or without
670178Sassar * modification, are permitted provided that the following conditions
770178Sassar * are met:
870178Sassar * 1. Redistributions of source code must retain the above copyright
970178Sassar *    notice, this list of conditions and the following disclaimer
1070178Sassar *    in this position and unchanged.
1170178Sassar * 2. Redistributions in binary form must reproduce the above copyright
1270178Sassar *    notice, this list of conditions and the following disclaimer in the
1370178Sassar *    documentation and/or other materials provided with the distribution.
1470178Sassar * 3. The name of the author may not be used to endorse or promote products
1597748Sschweikh *    derived from this software without specific prior written permission
1670178Sassar *
1770178Sassar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1870178Sassar * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1970178Sassar * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2070178Sassar * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2170178Sassar * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2270178Sassar * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2370178Sassar * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2470178Sassar * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2570178Sassar * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2670178Sassar * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2770178Sassar *
2870178Sassar * $FreeBSD: head/sys/compat/linux/linux_socket.h 283487 2015-05-24 18:03:14Z dchagin $
2970178Sassar */
3070178Sassar
3170178Sassar#ifndef _LINUX_SOCKET_H_
3270178Sassar#define _LINUX_SOCKET_H_
3370178Sassar
3470178Sassar/* msg flags in recvfrom/recvmsg */
3570178Sassar
3670178Sassar#define LINUX_MSG_OOB		0x01
3770178Sassar#define LINUX_MSG_PEEK		0x02
3870178Sassar#define LINUX_MSG_DONTROUTE	0x04
3970178Sassar#define LINUX_MSG_CTRUNC	0x08
4070178Sassar#define LINUX_MSG_PROXY		0x10
4170178Sassar#define LINUX_MSG_TRUNC		0x20
4270178Sassar#define LINUX_MSG_DONTWAIT	0x40
4370178Sassar#define LINUX_MSG_EOR		0x80
4470178Sassar#define LINUX_MSG_WAITALL	0x100
4570178Sassar#define LINUX_MSG_FIN		0x200
4670178Sassar#define LINUX_MSG_SYN		0x400
4770178Sassar#define LINUX_MSG_CONFIRM	0x800
4870178Sassar#define LINUX_MSG_RST		0x1000
4970178Sassar#define LINUX_MSG_ERRQUEUE	0x2000
5070178Sassar#define LINUX_MSG_NOSIGNAL	0x4000
51192284Sdchagin#define LINUX_MSG_CMSG_CLOEXEC	0x40000000
5270178Sassar
53185442Skib/* Socket-level control message types */
54185442Skib
55185442Skib#define LINUX_SCM_RIGHTS	0x01
56220031Savg#define LINUX_SCM_CREDENTIALS   0x02
57185442Skib
58283487Sdchaginstruct l_msghdr {
59283487Sdchagin	l_uintptr_t	msg_name;
60283487Sdchagin	l_int		msg_namelen;
61283487Sdchagin	l_uintptr_t	msg_iov;
62283487Sdchagin	l_size_t	msg_iovlen;
63283487Sdchagin	l_uintptr_t	msg_control;
64283487Sdchagin	l_size_t	msg_controllen;
65283487Sdchagin	l_uint		msg_flags;
66283487Sdchagin};
67283487Sdchagin
68283487Sdchaginstruct l_cmsghdr {
69283487Sdchagin	l_size_t	cmsg_len;
70283487Sdchagin	l_int		cmsg_level;
71283487Sdchagin	l_int		cmsg_type;
72283487Sdchagin};
73283487Sdchagin
74185442Skib/* Ancilliary data object information macros */
75185442Skib
76185442Skib#define LINUX_CMSG_ALIGN(len)	roundup2(len, sizeof(l_ulong))
77185442Skib#define LINUX_CMSG_DATA(cmsg)	((void *)((char *)(cmsg) + \
78185442Skib				    LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
79185442Skib#define LINUX_CMSG_SPACE(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
80185442Skib				    LINUX_CMSG_ALIGN(len))
81185442Skib#define LINUX_CMSG_LEN(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
82185442Skib				    (len))
83185442Skib#define LINUX_CMSG_FIRSTHDR(msg) \
84185442Skib				((msg)->msg_controllen >= \
85185442Skib				    sizeof(struct l_cmsghdr) ? \
86220031Savg				    (struct l_cmsghdr *) \
87220031Savg				        PTRIN((msg)->msg_control) : \
88185442Skib				    (struct l_cmsghdr *)(NULL))
89185442Skib#define LINUX_CMSG_NXTHDR(msg, cmsg) \
90185442Skib				((((char *)(cmsg) + \
91185442Skib				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
92185442Skib				    sizeof(*(cmsg))) > \
93220031Savg				    (((char *)PTRIN((msg)->msg_control)) + \
94185442Skib				    (msg)->msg_controllen)) ? \
95185442Skib				    (struct l_cmsghdr *) NULL : \
96185442Skib				    (struct l_cmsghdr *)((char *)(cmsg) + \
97185442Skib				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
98185442Skib
99185442Skib#define CMSG_HDRSZ		CMSG_LEN(0)
100185442Skib#define L_CMSG_HDRSZ		LINUX_CMSG_LEN(0)
101185442Skib
102191876Sdchagin/* Supported address families */
103191876Sdchagin
104191876Sdchagin#define	LINUX_AF_UNSPEC		0
105191876Sdchagin#define	LINUX_AF_UNIX		1
106191876Sdchagin#define	LINUX_AF_INET		2
107191876Sdchagin#define	LINUX_AF_AX25		3
108191876Sdchagin#define	LINUX_AF_IPX		4
109191876Sdchagin#define	LINUX_AF_APPLETALK	5
110191876Sdchagin#define	LINUX_AF_INET6		10
111191876Sdchagin
112192205Sdchagin/* Supported socket types */
113192205Sdchagin
114192205Sdchagin#define	LINUX_SOCK_STREAM	1
115192205Sdchagin#define	LINUX_SOCK_DGRAM	2
116192205Sdchagin#define	LINUX_SOCK_RAW		3
117192205Sdchagin#define	LINUX_SOCK_RDM		4
118192205Sdchagin#define	LINUX_SOCK_SEQPACKET	5
119192205Sdchagin
120192205Sdchagin#define	LINUX_SOCK_MAX		LINUX_SOCK_SEQPACKET
121192205Sdchagin
122192206Sdchagin#define	LINUX_SOCK_TYPE_MASK	0xf
123192206Sdchagin
124192206Sdchagin/* Flags for socket, socketpair, accept4 */
125192206Sdchagin
126192206Sdchagin#define	LINUX_SOCK_CLOEXEC	LINUX_O_CLOEXEC
127192206Sdchagin#define	LINUX_SOCK_NONBLOCK	LINUX_O_NONBLOCK
128192206Sdchagin
129192203Sdchaginstruct l_ucred {
130192203Sdchagin	uint32_t	pid;
131192203Sdchagin	uint32_t	uid;
132192203Sdchagin	uint32_t	gid;
133192203Sdchagin};
134192203Sdchagin
135283413Sdchagin#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
136283413Sdchagin
137283413Sdchaginstruct linux_sendto_args {
138283413Sdchagin	int s;
139283413Sdchagin	l_uintptr_t msg;
140283413Sdchagin	int len;
141283413Sdchagin	int flags;
142283413Sdchagin	l_uintptr_t to;
143283413Sdchagin	int tolen;
144283413Sdchagin};
145283413Sdchagin
146283413Sdchaginstruct linux_socket_args {
147283413Sdchagin	int domain;
148283413Sdchagin	int type;
149283413Sdchagin	int protocol;
150283413Sdchagin};
151283413Sdchagin
152283413Sdchaginstruct linux_bind_args {
153283413Sdchagin	int s;
154283413Sdchagin	l_uintptr_t name;
155283413Sdchagin	int namelen;
156283413Sdchagin};
157283413Sdchagin
158283413Sdchaginstruct linux_connect_args {
159283413Sdchagin	int s;
160283413Sdchagin	l_uintptr_t name;
161283413Sdchagin	int namelen;
162283413Sdchagin};
163283413Sdchagin
164283413Sdchaginstruct linux_listen_args {
165283413Sdchagin	int s;
166283413Sdchagin	int backlog;
167283413Sdchagin};
168283413Sdchagin
169283413Sdchaginstruct linux_accept_args {
170283413Sdchagin	int s;
171283413Sdchagin	l_uintptr_t addr;
172283413Sdchagin	l_uintptr_t namelen;
173283413Sdchagin};
174283413Sdchagin
175283413Sdchaginstruct linux_accept4_args {
176283413Sdchagin	int s;
177283413Sdchagin	l_uintptr_t addr;
178283413Sdchagin	l_uintptr_t namelen;
179283413Sdchagin	int flags;
180283413Sdchagin};
181283413Sdchagin
182283413Sdchaginstruct linux_getsockname_args {
183283413Sdchagin	int s;
184283413Sdchagin	l_uintptr_t addr;
185283413Sdchagin	l_uintptr_t namelen;
186283413Sdchagin};
187283413Sdchagin
188283413Sdchaginstruct linux_getpeername_args {
189283413Sdchagin	int s;
190283413Sdchagin	l_uintptr_t addr;
191283413Sdchagin	l_uintptr_t namelen;
192283413Sdchagin};
193283413Sdchagin
194283413Sdchaginstruct linux_socketpair_args {
195283413Sdchagin	int domain;
196283413Sdchagin	int type;
197283413Sdchagin	int protocol;
198283413Sdchagin	l_uintptr_t rsv;
199283413Sdchagin};
200283413Sdchagin
201283413Sdchaginstruct linux_recvfrom_args {
202283413Sdchagin	int s;
203283413Sdchagin	l_uintptr_t buf;
204283413Sdchagin	int len;
205283413Sdchagin	int flags;
206283413Sdchagin	l_uintptr_t from;
207283413Sdchagin	l_uintptr_t fromlen;
208283413Sdchagin};
209283413Sdchagin
210283413Sdchaginstruct linux_sendmsg_args {
211283413Sdchagin	int s;
212283413Sdchagin	l_uintptr_t msg;
213283413Sdchagin	int flags;
214283413Sdchagin};
215283413Sdchagin
216283413Sdchaginstruct linux_recvmsg_args {
217283413Sdchagin	int s;
218283413Sdchagin	l_uintptr_t msg;
219283413Sdchagin	int flags;
220283413Sdchagin};
221283413Sdchagin
222283413Sdchaginstruct linux_shutdown_args {
223283413Sdchagin	int s;
224283413Sdchagin	int how;
225283413Sdchagin};
226283413Sdchagin
227283413Sdchaginstruct linux_setsockopt_args {
228283413Sdchagin	int s;
229283413Sdchagin	int level;
230283413Sdchagin	int optname;
231283413Sdchagin	l_uintptr_t optval;
232283413Sdchagin	int optlen;
233283413Sdchagin};
234283413Sdchagin
235283413Sdchaginstruct linux_getsockopt_args {
236283413Sdchagin	int s;
237283413Sdchagin	int level;
238283413Sdchagin	int optname;
239283413Sdchagin	l_uintptr_t optval;
240283413Sdchagin	l_uintptr_t optlen;
241283413Sdchagin};
242283413Sdchagin
243283413Sdchaginint linux_socket(struct thread *td, struct linux_socket_args *args);
244283413Sdchaginint linux_bind(struct thread *td, struct linux_bind_args *args);
245283413Sdchaginint linux_connect(struct thread *, struct linux_connect_args *);
246283413Sdchaginint linux_listen(struct thread *td, struct linux_listen_args *args);
247283413Sdchaginint linux_accept(struct thread *td, struct linux_accept_args *args);
248283413Sdchaginint linux_accept4(struct thread *td, struct linux_accept4_args *args);
249283413Sdchaginint linux_getsockname(struct thread *td, struct linux_getsockname_args *args);
250283413Sdchaginint linux_getpeername(struct thread *td, struct linux_getpeername_args *args);
251283413Sdchaginint linux_socketpair(struct thread *td, struct linux_socketpair_args *args);
252283413Sdchaginint linux_sendto(struct thread *td, struct linux_sendto_args *args);
253283413Sdchaginint linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args);
254283413Sdchaginint linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args);
255283413Sdchaginint linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args);
256283413Sdchaginint linux_shutdown(struct thread *td, struct linux_shutdown_args *args);
257283413Sdchaginint linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args);
258283413Sdchaginint linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args);
259283413Sdchagin
260283413Sdchagin#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
261283413Sdchagin
262246085Sjhb/* Operations for socketcall */
263246085Sjhb
264246085Sjhb#define	LINUX_SOCKET 		1
265246085Sjhb#define	LINUX_BIND		2
266246085Sjhb#define	LINUX_CONNECT 		3
267246085Sjhb#define	LINUX_LISTEN 		4
268246085Sjhb#define	LINUX_ACCEPT 		5
269246085Sjhb#define	LINUX_GETSOCKNAME	6
270246085Sjhb#define	LINUX_GETPEERNAME	7
271246085Sjhb#define	LINUX_SOCKETPAIR	8
272246085Sjhb#define	LINUX_SEND		9
273246085Sjhb#define	LINUX_RECV		10
274246085Sjhb#define	LINUX_SENDTO 		11
275246085Sjhb#define	LINUX_RECVFROM 		12
276246085Sjhb#define	LINUX_SHUTDOWN 		13
277246085Sjhb#define	LINUX_SETSOCKOPT	14
278246085Sjhb#define	LINUX_GETSOCKOPT	15
279246085Sjhb#define	LINUX_SENDMSG		16
280246085Sjhb#define	LINUX_RECVMSG		17
281246085Sjhb#define	LINUX_ACCEPT4		18
282246085Sjhb
283246085Sjhb/* Socket options */
284246085Sjhb#define	LINUX_IP_TOS		1
285246085Sjhb#define	LINUX_IP_TTL		2
286246085Sjhb#define	LINUX_IP_HDRINCL	3
287246085Sjhb#define	LINUX_IP_OPTIONS	4
288246085Sjhb
289246085Sjhb#define	LINUX_IP_MULTICAST_IF		32
290246085Sjhb#define	LINUX_IP_MULTICAST_TTL		33
291246085Sjhb#define	LINUX_IP_MULTICAST_LOOP		34
292246085Sjhb#define	LINUX_IP_ADD_MEMBERSHIP		35
293246085Sjhb#define	LINUX_IP_DROP_MEMBERSHIP	36
294246085Sjhb
295246085Sjhb#define	LINUX_TCP_NODELAY	1
296246085Sjhb#define	LINUX_TCP_MAXSEG	2
297246085Sjhb#define	LINUX_TCP_KEEPIDLE	4
298246085Sjhb#define	LINUX_TCP_KEEPINTVL	5
299246085Sjhb#define	LINUX_TCP_KEEPCNT	6
300246085Sjhb#define	LINUX_TCP_MD5SIG	14
301246085Sjhb
30270178Sassar#endif /* _LINUX_SOCKET_H_ */
303