1 /*- 2 * Copyright (c) 2000 Assar Westerlund 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #ifndef _LINUX_SOCKET_H_ 32 #define _LINUX_SOCKET_H_ 33 34 /* msg flags in recvfrom/recvmsg */ 35 36 #define LINUX_MSG_OOB 0x01 37 #define LINUX_MSG_PEEK 0x02 38 #define LINUX_MSG_DONTROUTE 0x04 39 #define LINUX_MSG_CTRUNC 0x08 40 #define LINUX_MSG_PROXY 0x10 41 #define LINUX_MSG_TRUNC 0x20 42 #define LINUX_MSG_DONTWAIT 0x40 43 #define LINUX_MSG_EOR 0x80 44 #define LINUX_MSG_WAITALL 0x100 45 #define LINUX_MSG_FIN 0x200 46 #define LINUX_MSG_SYN 0x400 47 #define LINUX_MSG_CONFIRM 0x800 48 #define LINUX_MSG_RST 0x1000 49 #define LINUX_MSG_ERRQUEUE 0x2000 50 #define LINUX_MSG_NOSIGNAL 0x4000 51 #define LINUX_MSG_CMSG_CLOEXEC 0x40000000 52 53 /* Socket-level control message types */ 54 55 #define LINUX_SCM_RIGHTS 0x01 56 #define LINUX_SCM_CREDENTIALS 0x02 57 58 struct l_msghdr { 59 l_uintptr_t msg_name; 60 l_int msg_namelen; 61 l_uintptr_t msg_iov; 62 l_size_t msg_iovlen; 63 l_uintptr_t msg_control; 64 l_size_t msg_controllen; 65 l_uint msg_flags; 66 }; 67 68 struct l_cmsghdr { 69 l_size_t cmsg_len; 70 l_int cmsg_level; 71 l_int cmsg_type; 72 }; 73 74 /* Ancilliary data object information macros */ 75 76 #define LINUX_CMSG_ALIGN(len) roundup2(len, sizeof(l_ulong)) 77 #define LINUX_CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + \ 78 LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)))) 79 #define LINUX_CMSG_SPACE(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \ 80 LINUX_CMSG_ALIGN(len)) 81 #define LINUX_CMSG_LEN(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \ 82 (len)) 83 #define LINUX_CMSG_FIRSTHDR(msg) \ 84 ((msg)->msg_controllen >= \ 85 sizeof(struct l_cmsghdr) ? \ 86 (struct l_cmsghdr *) \ 87 PTRIN((msg)->msg_control) : \ 88 (struct l_cmsghdr *)(NULL)) 89 #define LINUX_CMSG_NXTHDR(msg, cmsg) \ 90 ((((char *)(cmsg) + \ 91 LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \ 92 sizeof(*(cmsg))) > \ 93 (((char *)PTRIN((msg)->msg_control)) + \ 94 (msg)->msg_controllen)) ? \ 95 (struct l_cmsghdr *) NULL : \ 96 (struct l_cmsghdr *)((char *)(cmsg) + \ 97 LINUX_CMSG_ALIGN((cmsg)->cmsg_len))) 98 99 #define CMSG_HDRSZ CMSG_LEN(0) 100 #define L_CMSG_HDRSZ LINUX_CMSG_LEN(0) 101 102 /* Supported address families */ 103 104 #define LINUX_AF_UNSPEC 0 105 #define LINUX_AF_UNIX 1 106 #define LINUX_AF_INET 2 107 #define LINUX_AF_AX25 3 108 #define LINUX_AF_IPX 4 109 #define LINUX_AF_APPLETALK 5 110 #define LINUX_AF_INET6 10 111 112 /* Supported socket types */ 113 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 119 120 #define LINUX_SOCK_MAX LINUX_SOCK_SEQPACKET 121 122 #define LINUX_SOCK_TYPE_MASK 0xf 123 124 /* Flags for socket, socketpair, accept4 */ 125 126 #define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC 127 #define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK 128 129 struct l_ucred { 130 uint32_t pid; 131 uint32_t uid; 132 uint32_t gid; 133 }; 134 135 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 136 137 struct linux_sendto_args { 138 int s; 139 l_uintptr_t msg; 140 int len; 141 int flags; 142 l_uintptr_t to; 143 int tolen; 144 }; 145 146 struct linux_socket_args { 147 int domain; 148 int type; 149 int protocol; 150 }; 151 152 struct linux_bind_args { 153 int s; 154 l_uintptr_t name; 155 int namelen; 156 }; 157 158 struct linux_connect_args { 159 int s; 160 l_uintptr_t name; 161 int namelen; 162 }; 163 164 struct linux_listen_args { 165 int s; 166 int backlog; 167 }; 168 169 struct linux_accept_args { 170 int s; 171 l_uintptr_t addr; 172 l_uintptr_t namelen; 173 }; 174 175 struct linux_accept4_args { 176 int s; 177 l_uintptr_t addr; 178 l_uintptr_t namelen; 179 int flags; 180 }; 181 182 struct linux_getsockname_args { 183 int s; 184 l_uintptr_t addr; 185 l_uintptr_t namelen; 186 }; 187 188 struct linux_getpeername_args { 189 int s; 190 l_uintptr_t addr; 191 l_uintptr_t namelen; 192 }; 193 194 struct linux_socketpair_args { 195 int domain; 196 int type; 197 int protocol; 198 l_uintptr_t rsv; 199 }; 200 201 struct linux_recvfrom_args { 202 int s; 203 l_uintptr_t buf; 204 int len; 205 int flags; 206 l_uintptr_t from; 207 l_uintptr_t fromlen; 208 }; 209 210 struct linux_sendmsg_args { 211 int s; 212 l_uintptr_t msg; 213 int flags; 214 }; 215 216 struct linux_recvmsg_args { 217 int s; 218 l_uintptr_t msg; 219 int flags; 220 }; 221 222 struct linux_shutdown_args { 223 int s; 224 int how; 225 }; 226 227 struct linux_setsockopt_args { 228 int s; 229 int level; 230 int optname; 231 l_uintptr_t optval; 232 int optlen; 233 }; 234 235 struct linux_getsockopt_args { 236 int s; 237 int level; 238 int optname; 239 l_uintptr_t optval; 240 l_uintptr_t optlen; 241 }; 242 243 int linux_socket(struct thread *td, struct linux_socket_args *args); 244 int linux_bind(struct thread *td, struct linux_bind_args *args); 245 int linux_connect(struct thread *, struct linux_connect_args *); 246 int linux_listen(struct thread *td, struct linux_listen_args *args); 247 int linux_accept(struct thread *td, struct linux_accept_args *args); 248 int linux_accept4(struct thread *td, struct linux_accept4_args *args); 249 int linux_getsockname(struct thread *td, struct linux_getsockname_args *args); 250 int linux_getpeername(struct thread *td, struct linux_getpeername_args *args); 251 int linux_socketpair(struct thread *td, struct linux_socketpair_args *args); 252 int linux_sendto(struct thread *td, struct linux_sendto_args *args); 253 int linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args); 254 int linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args); 255 int linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args); 256 int linux_shutdown(struct thread *td, struct linux_shutdown_args *args); 257 int linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args); 258 int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args); 259 260 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 261 262 /* Operations for socketcall */ 263 264 #define LINUX_SOCKET 1 265 #define LINUX_BIND 2 266 #define LINUX_CONNECT 3 267 #define LINUX_LISTEN 4 268 #define LINUX_ACCEPT 5 269 #define LINUX_GETSOCKNAME 6 270 #define LINUX_GETPEERNAME 7 271 #define LINUX_SOCKETPAIR 8 272 #define LINUX_SEND 9 273 #define LINUX_RECV 10 274 #define LINUX_SENDTO 11 275 #define LINUX_RECVFROM 12 276 #define LINUX_SHUTDOWN 13 277 #define LINUX_SETSOCKOPT 14 278 #define LINUX_GETSOCKOPT 15 279 #define LINUX_SENDMSG 16 280 #define LINUX_RECVMSG 17 281 #define LINUX_ACCEPT4 18 282 283 /* Socket options */ 284 #define LINUX_IP_TOS 1 285 #define LINUX_IP_TTL 2 286 #define LINUX_IP_HDRINCL 3 287 #define LINUX_IP_OPTIONS 4 288 289 #define LINUX_IP_MULTICAST_IF 32 290 #define LINUX_IP_MULTICAST_TTL 33 291 #define LINUX_IP_MULTICAST_LOOP 34 292 #define LINUX_IP_ADD_MEMBERSHIP 35 293 #define LINUX_IP_DROP_MEMBERSHIP 36 294 295 #define LINUX_TCP_NODELAY 1 296 #define LINUX_TCP_MAXSEG 2 297 #define LINUX_TCP_KEEPIDLE 4 298 #define LINUX_TCP_KEEPINTVL 5 299 #define LINUX_TCP_KEEPCNT 6 300 #define LINUX_TCP_MD5SIG 14 301 302 #endif /* _LINUX_SOCKET_H_ */ 303