]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/compat/linux/linux_socket.h
MFC r347203:
[FreeBSD/FreeBSD.git] / sys / compat / linux / linux_socket.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2000 Assar Westerlund
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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
18  *
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.
29  *
30  * $FreeBSD$
31  */
32
33 #ifndef _LINUX_SOCKET_H_
34 #define _LINUX_SOCKET_H_
35
36 /* msg flags in recvfrom/recvmsg */
37
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
55
56 /* Socket-level control message types */
57
58 #define LINUX_SCM_RIGHTS        0x01
59 #define LINUX_SCM_CREDENTIALS   0x02
60 #define LINUX_SCM_TIMESTAMP     0x1D
61
62 struct l_msghdr {
63         l_uintptr_t     msg_name;
64         l_int           msg_namelen;
65         l_uintptr_t     msg_iov;
66         l_size_t        msg_iovlen;
67         l_uintptr_t     msg_control;
68         l_size_t        msg_controllen;
69         l_uint          msg_flags;
70 };
71
72 struct l_mmsghdr {
73         struct l_msghdr msg_hdr;
74         l_uint          msg_len;
75
76 };
77
78 struct l_cmsghdr {
79         l_size_t        cmsg_len;
80         l_int           cmsg_level;
81         l_int           cmsg_type;
82 };
83
84 /* Ancillary data object information macros */
85
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)) + \
92                                     (len))
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) + \
102                                     sizeof(*(cmsg))) > \
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)))
108
109 #define CMSG_HDRSZ              CMSG_LEN(0)
110 #define L_CMSG_HDRSZ            LINUX_CMSG_LEN(0)
111
112 /* Supported address families */
113
114 #define LINUX_AF_UNSPEC         0
115 #define LINUX_AF_UNIX           1
116 #define LINUX_AF_INET           2
117 #define LINUX_AF_AX25           3
118 #define LINUX_AF_IPX            4
119 #define LINUX_AF_APPLETALK      5
120 #define LINUX_AF_INET6          10
121
122 /* Supported socket types */
123
124 #define LINUX_SOCK_STREAM       1
125 #define LINUX_SOCK_DGRAM        2
126 #define LINUX_SOCK_RAW          3
127 #define LINUX_SOCK_RDM          4
128 #define LINUX_SOCK_SEQPACKET    5
129
130 #define LINUX_SOCK_MAX          LINUX_SOCK_SEQPACKET
131
132 #define LINUX_SOCK_TYPE_MASK    0xf
133
134 /* Flags for socket, socketpair, accept4 */
135
136 #define LINUX_SOCK_CLOEXEC      LINUX_O_CLOEXEC
137 #define LINUX_SOCK_NONBLOCK     LINUX_O_NONBLOCK
138
139 struct l_ucred {
140         uint32_t        pid;
141         uint32_t        uid;
142         uint32_t        gid;
143 };
144
145 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
146 struct linux_accept_args {
147         register_t s;
148         register_t addr;
149         register_t namelen;
150 };
151
152 int linux_accept(struct thread *td, struct linux_accept_args *args);
153
154 /* Operations for socketcall */
155 #define LINUX_SOCKET            1
156 #define LINUX_BIND              2
157 #define LINUX_CONNECT           3
158 #define LINUX_LISTEN            4
159 #define LINUX_ACCEPT            5
160 #define LINUX_GETSOCKNAME       6
161 #define LINUX_GETPEERNAME       7
162 #define LINUX_SOCKETPAIR        8
163 #define LINUX_SEND              9
164 #define LINUX_RECV              10
165 #define LINUX_SENDTO            11
166 #define LINUX_RECVFROM          12
167 #define LINUX_SHUTDOWN          13
168 #define LINUX_SETSOCKOPT        14
169 #define LINUX_GETSOCKOPT        15
170 #define LINUX_SENDMSG           16
171 #define LINUX_RECVMSG           17
172 #define LINUX_ACCEPT4           18
173 #define LINUX_RECVMMSG          19
174 #define LINUX_SENDMMSG          20
175 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
176
177 /* Socket defines */
178 #define LINUX_SOL_SOCKET        1
179 #define LINUX_SOL_IP            0
180 #define LINUX_SOL_TCP           6
181 #define LINUX_SOL_UDP           17
182 #define LINUX_SOL_IPV6          41
183 #define LINUX_SOL_IPX           256
184 #define LINUX_SOL_AX25          257
185
186 #define LINUX_SO_DEBUG          1
187 #define LINUX_SO_REUSEADDR      2
188 #define LINUX_SO_TYPE           3
189 #define LINUX_SO_ERROR          4
190 #define LINUX_SO_DONTROUTE      5
191 #define LINUX_SO_BROADCAST      6
192 #define LINUX_SO_SNDBUF         7
193 #define LINUX_SO_RCVBUF         8
194 #define LINUX_SO_KEEPALIVE      9
195 #define LINUX_SO_OOBINLINE      10
196 #define LINUX_SO_NO_CHECK       11
197 #define LINUX_SO_PRIORITY       12
198 #define LINUX_SO_LINGER         13
199 #ifndef LINUX_SO_PASSCRED       /* powerpc differs */
200 #define LINUX_SO_PASSCRED       16
201 #define LINUX_SO_PEERCRED       17
202 #define LINUX_SO_RCVLOWAT       18
203 #define LINUX_SO_SNDLOWAT       19
204 #define LINUX_SO_RCVTIMEO       20
205 #define LINUX_SO_SNDTIMEO       21
206 #endif
207 #define LINUX_SO_TIMESTAMP      29
208 #define LINUX_SO_ACCEPTCONN     30
209
210 /* Socket options */
211 #define LINUX_IP_TOS            1
212 #define LINUX_IP_TTL            2
213 #define LINUX_IP_HDRINCL        3
214 #define LINUX_IP_OPTIONS        4
215
216 #define LINUX_IP_MULTICAST_IF           32
217 #define LINUX_IP_MULTICAST_TTL          33
218 #define LINUX_IP_MULTICAST_LOOP         34
219 #define LINUX_IP_ADD_MEMBERSHIP         35
220 #define LINUX_IP_DROP_MEMBERSHIP        36
221
222 #define LINUX_IPV6_CHECKSUM             7
223 #define LINUX_IPV6_NEXTHOP              9
224 #define LINUX_IPV6_UNICAST_HOPS         16
225 #define LINUX_IPV6_MULTICAST_IF         17
226 #define LINUX_IPV6_MULTICAST_HOPS       18
227 #define LINUX_IPV6_MULTICAST_LOOP       19
228 #define LINUX_IPV6_ADD_MEMBERSHIP       20
229 #define LINUX_IPV6_DROP_MEMBERSHIP      21
230 #define LINUX_IPV6_V6ONLY               26
231
232 #define LINUX_IPV6_RECVPKTINFO          49
233 #define LINUX_IPV6_PKTINFO              50
234 #define LINUX_IPV6_RECVHOPLIMIT         51
235 #define LINUX_IPV6_HOPLIMIT             52
236 #define LINUX_IPV6_RECVHOPOPTS          53
237 #define LINUX_IPV6_HOPOPTS              54
238 #define LINUX_IPV6_RTHDRDSTOPTS         55
239 #define LINUX_IPV6_RECVRTHDR            56
240 #define LINUX_IPV6_RTHDR                57
241 #define LINUX_IPV6_RECVDSTOPTS          58
242 #define LINUX_IPV6_DSTOPTS              59
243 #define LINUX_IPV6_RECVPATHMTU          60
244 #define LINUX_IPV6_PATHMTU              61
245 #define LINUX_IPV6_DONTFRAG             62
246
247 #define LINUX_TCP_NODELAY       1
248 #define LINUX_TCP_MAXSEG        2
249 #define LINUX_TCP_KEEPIDLE      4
250 #define LINUX_TCP_KEEPINTVL     5
251 #define LINUX_TCP_KEEPCNT       6
252 #define LINUX_TCP_MD5SIG        14
253
254 #endif /* _LINUX_SOCKET_H_ */