linux_socket.h revision 293588
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: stable/10/sys/compat/linux/linux_socket.h 293588 2016-01-09 17:50:13Z dchagin $ 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_WAITFORONE 0x10000 52#define LINUX_MSG_CMSG_CLOEXEC 0x40000000 53 54/* Socket-level control message types */ 55 56#define LINUX_SCM_RIGHTS 0x01 57#define LINUX_SCM_CREDENTIALS 0x02 58 59struct l_msghdr { 60 l_uintptr_t msg_name; 61 l_int msg_namelen; 62 l_uintptr_t msg_iov; 63 l_size_t msg_iovlen; 64 l_uintptr_t msg_control; 65 l_size_t msg_controllen; 66 l_uint msg_flags; 67}; 68 69struct l_mmsghdr { 70 struct l_msghdr msg_hdr; 71 l_uint msg_len; 72 73}; 74 75struct l_cmsghdr { 76 l_size_t cmsg_len; 77 l_int cmsg_level; 78 l_int cmsg_type; 79}; 80 81/* Ancilliary data object information macros */ 82 83#define LINUX_CMSG_ALIGN(len) roundup2(len, sizeof(l_ulong)) 84#define LINUX_CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + \ 85 LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)))) 86#define LINUX_CMSG_SPACE(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \ 87 LINUX_CMSG_ALIGN(len)) 88#define LINUX_CMSG_LEN(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \ 89 (len)) 90#define LINUX_CMSG_FIRSTHDR(msg) \ 91 ((msg)->msg_controllen >= \ 92 sizeof(struct l_cmsghdr) ? \ 93 (struct l_cmsghdr *) \ 94 PTRIN((msg)->msg_control) : \ 95 (struct l_cmsghdr *)(NULL)) 96#define LINUX_CMSG_NXTHDR(msg, cmsg) \ 97 ((((char *)(cmsg) + \ 98 LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \ 99 sizeof(*(cmsg))) > \ 100 (((char *)PTRIN((msg)->msg_control)) + \ 101 (msg)->msg_controllen)) ? \ 102 (struct l_cmsghdr *) NULL : \ 103 (struct l_cmsghdr *)((char *)(cmsg) + \ 104 LINUX_CMSG_ALIGN((cmsg)->cmsg_len))) 105 106#define CMSG_HDRSZ CMSG_LEN(0) 107#define L_CMSG_HDRSZ LINUX_CMSG_LEN(0) 108 109/* Supported address families */ 110 111#define LINUX_AF_UNSPEC 0 112#define LINUX_AF_UNIX 1 113#define LINUX_AF_INET 2 114#define LINUX_AF_AX25 3 115#define LINUX_AF_IPX 4 116#define LINUX_AF_APPLETALK 5 117#define LINUX_AF_INET6 10 118 119/* Supported socket types */ 120 121#define LINUX_SOCK_STREAM 1 122#define LINUX_SOCK_DGRAM 2 123#define LINUX_SOCK_RAW 3 124#define LINUX_SOCK_RDM 4 125#define LINUX_SOCK_SEQPACKET 5 126 127#define LINUX_SOCK_MAX LINUX_SOCK_SEQPACKET 128 129#define LINUX_SOCK_TYPE_MASK 0xf 130 131/* Flags for socket, socketpair, accept4 */ 132 133#define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC 134#define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK 135 136struct l_ucred { 137 uint32_t pid; 138 uint32_t uid; 139 uint32_t gid; 140}; 141 142#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) 143 144struct linux_sendto_args { 145 int s; 146 l_uintptr_t msg; 147 int len; 148 int flags; 149 l_uintptr_t to; 150 int tolen; 151}; 152 153struct linux_socket_args { 154 int domain; 155 int type; 156 int protocol; 157}; 158 159struct linux_bind_args { 160 int s; 161 l_uintptr_t name; 162 int namelen; 163}; 164 165struct linux_connect_args { 166 int s; 167 l_uintptr_t name; 168 int namelen; 169}; 170 171struct linux_listen_args { 172 int s; 173 int backlog; 174}; 175 176struct linux_accept_args { 177 int s; 178 l_uintptr_t addr; 179 l_uintptr_t namelen; 180}; 181 182struct linux_accept4_args { 183 int s; 184 l_uintptr_t addr; 185 l_uintptr_t namelen; 186 int flags; 187}; 188 189struct linux_getsockname_args { 190 int s; 191 l_uintptr_t addr; 192 l_uintptr_t namelen; 193}; 194 195struct linux_getpeername_args { 196 int s; 197 l_uintptr_t addr; 198 l_uintptr_t namelen; 199}; 200 201struct linux_socketpair_args { 202 int domain; 203 int type; 204 int protocol; 205 l_uintptr_t rsv; 206}; 207 208struct linux_recvfrom_args { 209 int s; 210 l_uintptr_t buf; 211 int len; 212 int flags; 213 l_uintptr_t from; 214 l_uintptr_t fromlen; 215}; 216 217struct linux_sendmsg_args { 218 int s; 219 l_uintptr_t msg; 220 int flags; 221}; 222 223struct linux_recvmsg_args { 224 int s; 225 l_uintptr_t msg; 226 int flags; 227}; 228 229struct linux_shutdown_args { 230 int s; 231 int how; 232}; 233 234struct linux_setsockopt_args { 235 int s; 236 int level; 237 int optname; 238 l_uintptr_t optval; 239 int optlen; 240}; 241 242struct linux_getsockopt_args { 243 int s; 244 int level; 245 int optname; 246 l_uintptr_t optval; 247 l_uintptr_t optlen; 248}; 249 250int linux_socket(struct thread *td, struct linux_socket_args *args); 251int linux_bind(struct thread *td, struct linux_bind_args *args); 252int linux_connect(struct thread *, struct linux_connect_args *); 253int linux_listen(struct thread *td, struct linux_listen_args *args); 254int linux_accept(struct thread *td, struct linux_accept_args *args); 255int linux_accept4(struct thread *td, struct linux_accept4_args *args); 256int linux_getsockname(struct thread *td, struct linux_getsockname_args *args); 257int linux_getpeername(struct thread *td, struct linux_getpeername_args *args); 258int linux_socketpair(struct thread *td, struct linux_socketpair_args *args); 259int linux_sendto(struct thread *td, struct linux_sendto_args *args); 260int linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args); 261int linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args); 262int linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args); 263int linux_shutdown(struct thread *td, struct linux_shutdown_args *args); 264int linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args); 265int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args); 266 267#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ 268 269/* Operations for socketcall */ 270 271#define LINUX_SOCKET 1 272#define LINUX_BIND 2 273#define LINUX_CONNECT 3 274#define LINUX_LISTEN 4 275#define LINUX_ACCEPT 5 276#define LINUX_GETSOCKNAME 6 277#define LINUX_GETPEERNAME 7 278#define LINUX_SOCKETPAIR 8 279#define LINUX_SEND 9 280#define LINUX_RECV 10 281#define LINUX_SENDTO 11 282#define LINUX_RECVFROM 12 283#define LINUX_SHUTDOWN 13 284#define LINUX_SETSOCKOPT 14 285#define LINUX_GETSOCKOPT 15 286#define LINUX_SENDMSG 16 287#define LINUX_RECVMSG 17 288#define LINUX_ACCEPT4 18 289#define LINUX_RECVMMSG 19 290#define LINUX_SENDMMSG 20 291 292/* Socket options */ 293#define LINUX_IP_TOS 1 294#define LINUX_IP_TTL 2 295#define LINUX_IP_HDRINCL 3 296#define LINUX_IP_OPTIONS 4 297 298#define LINUX_IP_MULTICAST_IF 32 299#define LINUX_IP_MULTICAST_TTL 33 300#define LINUX_IP_MULTICAST_LOOP 34 301#define LINUX_IP_ADD_MEMBERSHIP 35 302#define LINUX_IP_DROP_MEMBERSHIP 36 303 304#define LINUX_TCP_NODELAY 1 305#define LINUX_TCP_MAXSEG 2 306#define LINUX_TCP_KEEPIDLE 4 307#define LINUX_TCP_KEEPINTVL 5 308#define LINUX_TCP_KEEPCNT 6 309#define LINUX_TCP_MD5SIG 14 310 311#endif /* _LINUX_SOCKET_H_ */ 312