2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2000 Assar Westerlund
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _LINUX_SOCKET_H_
34 #define _LINUX_SOCKET_H_
36 /* msg flags in recvfrom/recvmsg */
38 #define LINUX_MSG_OOB 0x01
39 #define LINUX_MSG_PEEK 0x02
40 #define LINUX_MSG_DONTROUTE 0x04
41 #define LINUX_MSG_CTRUNC 0x08
42 #define LINUX_MSG_PROXY 0x10
43 #define LINUX_MSG_TRUNC 0x20
44 #define LINUX_MSG_DONTWAIT 0x40
45 #define LINUX_MSG_EOR 0x80
46 #define LINUX_MSG_WAITALL 0x100
47 #define LINUX_MSG_FIN 0x200
48 #define LINUX_MSG_SYN 0x400
49 #define LINUX_MSG_CONFIRM 0x800
50 #define LINUX_MSG_RST 0x1000
51 #define LINUX_MSG_ERRQUEUE 0x2000
52 #define LINUX_MSG_NOSIGNAL 0x4000
53 #define LINUX_MSG_WAITFORONE 0x10000
54 #define LINUX_MSG_CMSG_CLOEXEC 0x40000000
56 /* Socket-level control message types */
58 #define LINUX_SCM_RIGHTS 0x01
59 #define LINUX_SCM_CREDENTIALS 0x02
60 #define LINUX_SCM_TIMESTAMP 0x1D
67 l_uintptr_t msg_control;
68 l_size_t msg_controllen;
73 struct l_msghdr msg_hdr;
84 /* Ancillary data object information macros */
86 #define LINUX_CMSG_ALIGN(len) roundup2(len, sizeof(l_ulong))
87 #define LINUX_CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + \
88 LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
89 #define LINUX_CMSG_SPACE(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
90 LINUX_CMSG_ALIGN(len))
91 #define LINUX_CMSG_LEN(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
93 #define LINUX_CMSG_FIRSTHDR(msg) \
94 ((msg)->msg_controllen >= \
95 sizeof(struct l_cmsghdr) ? \
96 (struct l_cmsghdr *) \
97 PTRIN((msg)->msg_control) : \
98 (struct l_cmsghdr *)(NULL))
99 #define LINUX_CMSG_NXTHDR(msg, cmsg) \
100 ((((char *)(cmsg) + \
101 LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
103 (((char *)PTRIN((msg)->msg_control)) + \
104 (msg)->msg_controllen)) ? \
105 (struct l_cmsghdr *) NULL : \
106 (struct l_cmsghdr *)((char *)(cmsg) + \
107 LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
109 #define CMSG_HDRSZ CMSG_LEN(0)
110 #define L_CMSG_HDRSZ LINUX_CMSG_LEN(0)
112 /* Supported socket types */
114 #define LINUX_SOCK_STREAM 1
115 #define LINUX_SOCK_DGRAM 2
116 #define LINUX_SOCK_RAW 3
117 #define LINUX_SOCK_RDM 4
118 #define LINUX_SOCK_SEQPACKET 5
120 #define LINUX_SOCK_MAX LINUX_SOCK_SEQPACKET
122 #define LINUX_SOCK_TYPE_MASK 0xf
124 /* Flags for socket, socketpair, accept4 */
126 #define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC
127 #define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK
135 #if defined(__i386__) || defined(__arm__) || \
136 (defined(__amd64__) && defined(COMPAT_LINUX32))
138 struct linux_accept_args {
144 int linux_accept(struct thread *td, struct linux_accept_args *args);
146 /* Operations for socketcall */
147 #define LINUX_SOCKET 1
149 #define LINUX_CONNECT 3
150 #define LINUX_LISTEN 4
151 #define LINUX_ACCEPT 5
152 #define LINUX_GETSOCKNAME 6
153 #define LINUX_GETPEERNAME 7
154 #define LINUX_SOCKETPAIR 8
156 #define LINUX_RECV 10
157 #define LINUX_SENDTO 11
158 #define LINUX_RECVFROM 12
159 #define LINUX_SHUTDOWN 13
160 #define LINUX_SETSOCKOPT 14
161 #define LINUX_GETSOCKOPT 15
162 #define LINUX_SENDMSG 16
163 #define LINUX_RECVMSG 17
164 #define LINUX_ACCEPT4 18
165 #define LINUX_RECVMMSG 19
166 #define LINUX_SENDMMSG 20
167 #define LINUX_SENDFILE 21
169 #endif /* __i386__ || __arm__ || (__amd64__ && COMPAT_LINUX32) */
172 #define LINUX_SOL_SOCKET 1
174 #define LINUX_SO_DEBUG 1
175 #define LINUX_SO_REUSEADDR 2
176 #define LINUX_SO_TYPE 3
177 #define LINUX_SO_ERROR 4
178 #define LINUX_SO_DONTROUTE 5
179 #define LINUX_SO_BROADCAST 6
180 #define LINUX_SO_SNDBUF 7
181 #define LINUX_SO_RCVBUF 8
182 #define LINUX_SO_KEEPALIVE 9
183 #define LINUX_SO_OOBINLINE 10
184 #define LINUX_SO_NO_CHECK 11
185 #define LINUX_SO_PRIORITY 12
186 #define LINUX_SO_LINGER 13
187 #define LINUX_SO_REUSEPORT 15
188 #ifndef LINUX_SO_PASSCRED /* powerpc differs */
189 #define LINUX_SO_PASSCRED 16
190 #define LINUX_SO_PEERCRED 17
191 #define LINUX_SO_RCVLOWAT 18
192 #define LINUX_SO_SNDLOWAT 19
193 #define LINUX_SO_RCVTIMEO 20
194 #define LINUX_SO_SNDTIMEO 21
196 #define LINUX_SO_TIMESTAMP 29
197 #define LINUX_SO_ACCEPTCONN 30
198 #define LINUX_SO_PEERSEC 31
199 #define LINUX_SO_SNDBUFFORCE 32
200 #define LINUX_SO_RCVBUFFORCE 33
201 #define LINUX_SO_PROTOCOL 38
202 #define LINUX_SO_PEERGROUPS 59
205 #define LINUX_IP_TOS 1
206 #define LINUX_IP_TTL 2
207 #define LINUX_IP_HDRINCL 3
208 #define LINUX_IP_OPTIONS 4
209 #define LINUX_IP_ROUTER_ALERT 5
210 #define LINUX_IP_RECVOPTS 6
211 #define LINUX_IP_RETOPTS 7
212 #define LINUX_IP_PKTINFO 8
213 #define LINUX_IP_PKTOPTIONS 9
214 #define LINUX_IP_MTU_DISCOVER 10
215 #define LINUX_IP_RECVERR 11
216 #define LINUX_IP_RECVTTL 12
217 #define LINUX_IP_RECVTOS 13
218 #define LINUX_IP_MTU 14
219 #define LINUX_IP_FREEBIND 15
220 #define LINUX_IP_IPSEC_POLICY 16
221 #define LINUX_IP_XFRM_POLICY 17
222 #define LINUX_IP_PASSSEC 18
223 #define LINUX_IP_TRANSPARENT 19
225 #define LINUX_IP_MINTTL 21
226 #define LINUX_IP_NODEFRAG 22
227 #define LINUX_IP_CHECKSUM 23
228 #define LINUX_IP_BIND_ADDRESS_NO_PORT 24
229 #define LINUX_IP_RECVFRAGSIZE 25
231 #define LINUX_IP_MULTICAST_IF 32
232 #define LINUX_IP_MULTICAST_TTL 33
233 #define LINUX_IP_MULTICAST_LOOP 34
234 #define LINUX_IP_ADD_MEMBERSHIP 35
235 #define LINUX_IP_DROP_MEMBERSHIP 36
236 #define LINUX_IP_UNBLOCK_SOURCE 37
237 #define LINUX_IP_BLOCK_SOURCE 38
238 #define LINUX_IP_ADD_SOURCE_MEMBERSHIP 39
239 #define LINUX_IP_DROP_SOURCE_MEMBERSHIP 40
240 #define LINUX_IP_MSFILTER 41
242 #define LINUX_MCAST_JOIN_GROUP 42
243 #define LINUX_MCAST_BLOCK_SOURCE 43
244 #define LINUX_MCAST_UNBLOCK_SOURCE 44
245 #define LINUX_MCAST_LEAVE_GROUP 45
246 #define LINUX_MCAST_JOIN_SOURCE_GROUP 46
247 #define LINUX_MCAST_LEAVE_SOURCE_GROUP 47
248 #define LINUX_MCAST_MSFILTER 48
249 #define LINUX_IP_MULTICAST_ALL 49
250 #define LINUX_IP_UNICAST_IF 50
252 #define LINUX_IPV6_ADDRFORM 1
253 #define LINUX_IPV6_2292PKTINFO 2
254 #define LINUX_IPV6_2292HOPOPTS 3
255 #define LINUX_IPV6_2292DSTOPTS 4
256 #define LINUX_IPV6_2292RTHDR 5
257 #define LINUX_IPV6_2292PKTOPTIONS 6
258 #define LINUX_IPV6_CHECKSUM 7
259 #define LINUX_IPV6_2292HOPLIMIT 8
260 #define LINUX_IPV6_NEXTHOP 9
261 #define LINUX_IPV6_AUTHHDR 10
262 #define LINUX_IPV6_FLOWINFO 11
264 #define LINUX_IPV6_UNICAST_HOPS 16
265 #define LINUX_IPV6_MULTICAST_IF 17
266 #define LINUX_IPV6_MULTICAST_HOPS 18
267 #define LINUX_IPV6_MULTICAST_LOOP 19
268 #define LINUX_IPV6_ADD_MEMBERSHIP 20
269 #define LINUX_IPV6_DROP_MEMBERSHIP 21
270 #define LINUX_IPV6_ROUTER_ALERT 22
271 #define LINUX_IPV6_MTU_DISCOVER 23
272 #define LINUX_IPV6_MTU 24
273 #define LINUX_IPV6_RECVERR 25
274 #define LINUX_IPV6_V6ONLY 26
275 #define LINUX_IPV6_JOIN_ANYCAST 27
276 #define LINUX_IPV6_LEAVE_ANYCAST 28
277 #define LINUX_IPV6_MULTICAST_ALL 29
278 #define LINUX_IPV6_ROUTER_ALERT_ISOLATE 30
280 #define LINUX_IPV6_FLOWLABEL_MGR 32
281 #define LINUX_IPV6_FLOWINFO_SEND 33
283 #define LINUX_IPV6_IPSEC_POLICY 34
284 #define LINUX_IPV6_XFRM_POLICY 35
285 #define LINUX_IPV6_HDRINCL 36
287 #define LINUX_IPV6_RECVPKTINFO 49
288 #define LINUX_IPV6_PKTINFO 50
289 #define LINUX_IPV6_RECVHOPLIMIT 51
290 #define LINUX_IPV6_HOPLIMIT 52
291 #define LINUX_IPV6_RECVHOPOPTS 53
292 #define LINUX_IPV6_HOPOPTS 54
293 #define LINUX_IPV6_RTHDRDSTOPTS 55
294 #define LINUX_IPV6_RECVRTHDR 56
295 #define LINUX_IPV6_RTHDR 57
296 #define LINUX_IPV6_RECVDSTOPTS 58
297 #define LINUX_IPV6_DSTOPTS 59
298 #define LINUX_IPV6_RECVPATHMTU 60
299 #define LINUX_IPV6_PATHMTU 61
300 #define LINUX_IPV6_DONTFRAG 62
302 #define LINUX_IPV6_AUTOFLOWLABEL 70
303 #define LINUX_IPV6_ADDR_PREFERENCES 72
304 #define LINUX_IPV6_MINHOPCOUNT 73
305 #define LINUX_IPV6_ORIGDSTADDR 74
306 #define LINUX_IPV6_TRANSPARENT 75
307 #define LINUX_IPV6_UNICAST_IF 76
308 #define LINUX_IPV6_RECVFRAGSIZE 77
309 #define LINUX_IPV6_FREEBIND 78
311 #define LINUX_TCP_NODELAY 1
312 #define LINUX_TCP_MAXSEG 2
313 #define LINUX_TCP_CORK 3
314 #define LINUX_TCP_KEEPIDLE 4
315 #define LINUX_TCP_KEEPINTVL 5
316 #define LINUX_TCP_KEEPCNT 6
317 #define LINUX_TCP_MD5SIG 14
319 #endif /* _LINUX_SOCKET_H_ */