| 1 | /* $NetBSD: linux_socket.h,v 1.22 2014/01/27 19:19:15 njoly Exp $ */ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * This code is derived from software contributed to The NetBSD Foundation |
| 8 | * by Frank van der Linden and Eric Haszlakiewicz. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | * POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #ifndef _LINUX_SOCKET_H |
| 33 | #define _LINUX_SOCKET_H |
| 34 | |
| 35 | /* |
| 36 | * Various Linux socket defines. Everything that is not re-defined here |
| 37 | * is the same as in NetBSD. |
| 38 | * |
| 39 | * COMPAT_43 is assumed, and the osockaddr struct is used (it is what |
| 40 | * Linux uses) |
| 41 | */ |
| 42 | |
| 43 | /* |
| 44 | * Address families. There are fewer of them, and they're numbered |
| 45 | * a bit different |
| 46 | */ |
| 47 | |
| 48 | #define LINUX_AF_UNSPEC 0 |
| 49 | #define LINUX_AF_UNIX 1 |
| 50 | #define LINUX_AF_INET 2 |
| 51 | #define LINUX_AF_AX25 3 |
| 52 | #define LINUX_AF_IPX 4 |
| 53 | #define LINUX_AF_APPLETALK 5 |
| 54 | #define LINUX_AF_NETROM 6 |
| 55 | #define LINUX_AF_BRIDGE 7 |
| 56 | #define LINUX_AF_ATMPVC 8 |
| 57 | #define LINUX_AF_X25 9 |
| 58 | #define LINUX_AF_INET6 10 |
| 59 | #define LINUX_AF_ROSE 11 |
| 60 | #define LINUX_AF_DECnet 12 |
| 61 | #define LINUX_AF_NETBEUI 13 |
| 62 | #define LINUX_AF_SECURITY 14 |
| 63 | #define LINUX_pseudo_AF_KEY 15 |
| 64 | #define LINUX_AF_NETLINK 16 |
| 65 | #define LINUX_AF_PACKET 17 |
| 66 | #define LINUX_AF_ASH 18 |
| 67 | #define LINUX_AF_ECONET 19 |
| 68 | #define LINUX_AF_ATMSVC 20 |
| 69 | #define LINUX_AF_SNA 22 |
| 70 | #define LINUX_AF_MAX 32 |
| 71 | |
| 72 | /* |
| 73 | * Option levels for [gs]etsockopt(2). Only SOL_SOCKET is different, |
| 74 | * the rest matches IPPROTO_XXX |
| 75 | */ |
| 76 | |
| 77 | /* SOL_SOCKET is machine dependent on Linux */ |
| 78 | #define LINUX_SOL_IP 0 |
| 79 | #define LINUX_SOL_TCP 6 |
| 80 | #define LINUX_SOL_UDP 17 |
| 81 | #define LINUX_SOL_IPV6 41 |
| 82 | /* Unused for now: */ |
| 83 | #define LINUX_SOL_ICMPV6 58 |
| 84 | #define LINUX_SOL_RAW 255 |
| 85 | #define LINUX_SOL_IPX 256 |
| 86 | #define LINUX_SOL_AX25 257 |
| 87 | #define LINUX_SOL_ATALK 258 |
| 88 | #define LINUX_SOL_NETROM 259 |
| 89 | #define LINUX_SOL_ROSE 260 |
| 90 | #define LINUX_SOL_DECNET 261 |
| 91 | #define LINUX_SOL_X25 262 |
| 92 | #define LINUX_SOL_PACKET 263 |
| 93 | #define LINUX_SOL_ATM 264 |
| 94 | #define LINUX_SOL_AAL 265 |
| 95 | |
| 96 | /* |
| 97 | * Options for [gs]etsockopt(2), socket level are machine dependent. |
| 98 | */ |
| 99 | |
| 100 | /* |
| 101 | * Options for [gs]etsockopt(2), IP level. |
| 102 | */ |
| 103 | |
| 104 | #define LINUX_IP_TOS 1 |
| 105 | #define LINUX_IP_TTL 2 |
| 106 | #define LINUX_IP_HDRINCL 3 |
| 107 | #define LINUX_IP_MULTICAST_IF 32 |
| 108 | #define LINUX_IP_MULTICAST_TTL 33 |
| 109 | #define LINUX_IP_MULTICAST_LOOP 34 |
| 110 | #define LINUX_IP_ADD_MEMBERSHIP 35 |
| 111 | #define LINUX_IP_DROP_MEMBERSHIP 36 |
| 112 | |
| 113 | /* |
| 114 | * Options for [gs]etsockopt(2), IPV6 level. |
| 115 | */ |
| 116 | |
| 117 | #define LINUX_IPV6_V6ONLY 26 |
| 118 | |
| 119 | /* |
| 120 | * Options for [gs]etsockopt(2), TCP level. |
| 121 | */ |
| 122 | |
| 123 | #define LINUX_TCP_NODELAY 1 |
| 124 | #define LINUX_TCP_MAXSEG 2 |
| 125 | |
| 126 | /* "Socket"-level control message types: */ |
| 127 | #define LINUX_SCM_RIGHTS 1 /* same as SCM_RIGHTS */ |
| 128 | #define LINUX_SCM_CREDENTIALS 2 /* accepts ucred rather than sockcred */ |
| 129 | #define LINUX_SCM_CONNECT 3 /* not supported in NetBSD */ |
| 130 | #define LINUX_SCM_TIMESTAMP LINUX_SO_TIMESTAMP |
| 131 | /* not actually implemented in Linux 2.5.15? */ |
| 132 | |
| 133 | struct linux_msghdr { |
| 134 | void *msg_name; |
| 135 | int msg_namelen; |
| 136 | struct iovec *msg_iov; |
| 137 | size_t msg_iovlen; |
| 138 | void *msg_control; |
| 139 | size_t msg_controllen; |
| 140 | unsigned int msg_flags; |
| 141 | }; |
| 142 | |
| 143 | /* |
| 144 | * Message flags (for sendmsg/recvmsg) |
| 145 | */ |
| 146 | #define LINUX_MSG_OOB 0x001 |
| 147 | #define LINUX_MSG_PEEK 0x002 |
| 148 | #define LINUX_MSG_DONTROUTE 0x004 |
| 149 | #define LINUX_MSG_TRYHARD 0x004 |
| 150 | #define LINUX_MSG_CTRUNC 0x008 |
| 151 | #define LINUX_MSG_PROBE 0x010 /* Don't send, only probe path */ |
| 152 | #define LINUX_MSG_TRUNC 0x020 |
| 153 | #define LINUX_MSG_DONTWAIT 0x040 /* this msg should be nonblocking */ |
| 154 | #define LINUX_MSG_EOR 0x080 /* data completes record */ |
| 155 | #define LINUX_MSG_WAITALL 0x100 /* wait for full request or error */ |
| 156 | #define LINUX_MSG_FIN 0x200 |
| 157 | #define LINUX_MSG_EOF LINUX_MSG_FIN |
| 158 | #define LINUX_MSG_SYN 0x400 |
| 159 | #define LINUX_MSG_CONFIRM 0x800 /* Confirm path validity */ |
| 160 | #define LINUX_MSG_RST 0x1000 |
| 161 | #define LINUX_MSG_ERRQUEUE 0x2000 /* fetch message from error queue */ |
| 162 | #define LINUX_MSG_NOSIGNAL 0x4000 /* do not generate SIGPIPE */ |
| 163 | #define LINUX_MSG_MORE 0x8000 /* Sender will send more */ |
| 164 | |
| 165 | /* |
| 166 | * Linux alignment requirement for CMSG struct manipulation. |
| 167 | * Linux aligns on (size_t) boundary on all architectures. |
| 168 | * Fortunately for linux, linux_cmsghdr is always size_t aligned ! |
| 169 | * since no padding is added between the header and data. |
| 170 | * XXX: this code isn't right for the compat32 code. |
| 171 | */ |
| 172 | struct linux_cmsghdr { |
| 173 | size_t cmsg_len; /* NB not socklen_t */ |
| 174 | int cmsg_level; |
| 175 | int cmsg_type; |
| 176 | /* unsigned char __cmsg_data[0]; */ |
| 177 | }; |
| 178 | |
| 179 | #define LINUX_CMSG_ALIGN(n) \ |
| 180 | (((n) + sizeof(size_t)-1) & ~(sizeof(size_t)-1)) |
| 181 | /* Linux either uses this, or &((cmsg)->__cmsg_data) */ |
| 182 | #define LINUX_CMSG_DATA(cmsg) \ |
| 183 | ((u_char *)((struct linux_cmsghdr *)(cmsg) + 1)) |
| 184 | #define LINUX_CMSG_NXTHDR(mhdr, cmsg) \ |
| 185 | ((((char *)(cmsg) + LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \ |
| 186 | sizeof(*(cmsg))) > \ |
| 187 | (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \ |
| 188 | (struct linux_cmsghdr *)NULL : \ |
| 189 | (struct linux_cmsghdr *)((char *)(cmsg) + \ |
| 190 | LINUX_CMSG_ALIGN((cmsg)->cmsg_len))) |
| 191 | /* This the number of bytes removed from each item (excl. final padding) */ |
| 192 | #define LINUX_CMSG_ALIGN_DELTA \ |
| 193 | (CMSG_ALIGN(sizeof(struct cmsghdr)) - sizeof(struct linux_cmsghdr)) |
| 194 | |
| 195 | #define LINUX_CMSG_FIRSTHDR(mhdr) \ |
| 196 | ((mhdr)->msg_controllen >= sizeof(struct linux_cmsghdr) ? \ |
| 197 | (struct linux_cmsghdr *)(mhdr)->msg_control : NULL) |
| 198 | |
| 199 | #define LINUX_CMSG_SPACE(l) \ |
| 200 | (sizeof(struct linux_cmsghdr) + LINUX_CMSG_ALIGN(l)) |
| 201 | #define LINUX_CMSG_LEN(l) \ |
| 202 | (sizeof(struct linux_cmsghdr) + (l)) |
| 203 | |
| 204 | /* |
| 205 | * Machine specific definitions. |
| 206 | */ |
| 207 | #if defined(__i386__) |
| 208 | #include <compat/linux/arch/i386/linux_socket.h> |
| 209 | #elif defined(__m68k__) |
| 210 | #include <compat/linux/arch/m68k/linux_socket.h> |
| 211 | #elif defined(__alpha__) |
| 212 | #include <compat/linux/arch/alpha/linux_socket.h> |
| 213 | #elif defined(__powerpc__) |
| 214 | #include <compat/linux/arch/powerpc/linux_socket.h> |
| 215 | #elif defined(__mips__) |
| 216 | #include <compat/linux/arch/mips/linux_socket.h> |
| 217 | #elif defined(__arm__) |
| 218 | #include <compat/linux/arch/arm/linux_socket.h> |
| 219 | #elif defined(__amd64__) |
| 220 | #include <compat/linux/arch/amd64/linux_socket.h> |
| 221 | #else |
| 222 | #error Undefined linux_socket.h machine type. |
| 223 | #endif |
| 224 | |
| 225 | /* |
| 226 | * Flags for socket(). |
| 227 | * These are provided in the "type" parameter. |
| 228 | */ |
| 229 | |
| 230 | #define LINUX_SOCK_TYPE_MASK 0xf |
| 231 | #define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC |
| 232 | #ifndef LINUX_SOCK_NONBLOCK |
| 233 | #define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK |
| 234 | #endif |
| 235 | |
| 236 | #endif /* !_LINUX_SOCKET_H */ |
| 237 | |