xref: /netbsd-src/sys/compat/linux/common/linux_socket.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: linux_socket.h,v 1.15 2007/07/01 18:45:36 dsl 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _LINUX_SOCKET_H
40 #define _LINUX_SOCKET_H
41 
42 /*
43  * Various Linux socket defines. Everything that is not re-defined here
44  * is the same as in NetBSD.
45  *
46  * COMPAT_43 is assumed, and the osockaddr struct is used (it is what
47  * Linux uses)
48  */
49 
50 /*
51  * Address families. There are fewer of them, and they're numbered
52  * a bit different
53  */
54 
55 #define LINUX_AF_UNSPEC		0
56 #define LINUX_AF_UNIX		1
57 #define LINUX_AF_INET		2
58 #define LINUX_AF_AX25		3
59 #define LINUX_AF_IPX		4
60 #define LINUX_AF_APPLETALK	5
61 #define LINUX_AF_NETROM		6
62 #define LINUX_AF_BRIDGE		7
63 #define LINUX_AF_ATMPVC		8
64 #define LINUX_AF_X25		9
65 #define LINUX_AF_INET6		10
66 #define LINUX_AF_ROSE		11
67 #define LINUX_AF_DECnet		12
68 #define LINUX_AF_NETBEUI	13
69 #define LINUX_AF_SECURITY	14
70 #define LINUX_pseudo_AF_KEY	15
71 #define LINUX_AF_NETLINK	16
72 #define LINUX_AF_PACKET		17
73 #define LINUX_AF_ASH		18
74 #define LINUX_AF_ECONET		19
75 #define	LINUX_AF_ATMSVC		20
76 #define	LINUX_AF_SNA		22
77 #define LINUX_AF_MAX		32
78 
79 /*
80  * Option levels for [gs]etsockopt(2). Only SOL_SOCKET is different,
81  * the rest matches IPPROTO_XXX
82  */
83 
84 /* SOL_SOCKET is machine dependant on Linux */
85 #define LINUX_SOL_IP		0
86 #define LINUX_SOL_TCP		6
87 #define LINUX_SOL_UDP		17
88 /* Unused for now: */
89 #define LINUX_SOL_IPV6		41
90 #define LINUX_SOL_ICMPV6	58
91 #define LINUX_SOL_RAW		255
92 #define LINUX_SOL_IPX		256
93 #define LINUX_SOL_AX25		257
94 #define LINUX_SOL_ATALK		258
95 #define LINUX_SOL_NETROM	259
96 #define LINUX_SOL_ROSE		260
97 #define LINUX_SOL_DECNET	261
98 #define LINUX_SOL_X25		262
99 #define LINUX_SOL_PACKET	263
100 #define LINUX_SOL_ATM		264
101 #define LINUX_SOL_AAL		265
102 
103 /*
104  * Options for [gs]etsockopt(2), socket level are machine dependant.
105  */
106 
107 /*
108  * Options for [gs]etsockopt(2), IP level.
109  */
110 
111 #define LINUX_IP_TOS		1
112 #define LINUX_IP_TTL		2
113 #define	LINUX_IP_MULTICAST_IF	32
114 #define	LINUX_IP_MULTICAST_TTL	33
115 #define	LINUX_IP_MULTICAST_LOOP	34
116 #define	LINUX_IP_ADD_MEMBERSHIP	35
117 #define	LINUX_IP_DROP_MEMBERSHIP 36
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 /*
134  * Message flags (for sendmsg/recvmsg)
135  */
136 #define LINUX_MSG_OOB		0x001
137 #define LINUX_MSG_PEEK		0x002
138 #define LINUX_MSG_DONTROUTE	0x004
139 #define LINUX_MSG_TRYHARD	0x004
140 #define LINUX_MSG_CTRUNC	0x008
141 #define LINUX_MSG_PROBE		0x010	/* Don't send, only probe path */
142 #define LINUX_MSG_TRUNC		0x020
143 #define LINUX_MSG_DONTWAIT	0x040	/* this msg should be nonblocking */
144 #define LINUX_MSG_EOR		0x080	/* data completes record */
145 #define LINUX_MSG_WAITALL	0x100	/* wait for full request or error */
146 #define LINUX_MSG_FIN		0x200
147 #define LINUX_MSG_EOF		LINUX_MSG_FIN
148 #define LINUX_MSG_SYN		0x400
149 #define LINUX_MSG_CONFIRM	0x800	/* Confirm path validity */
150 #define LINUX_MSG_RST		0x1000
151 #define LINUX_MSG_ERRQUEUE	0x2000	/* fetch message from error queue */
152 #define LINUX_MSG_NOSIGNAL	0x4000	/* do not generate SIGPIPE */
153 #define LINUX_MSG_MORE		0x8000	/* Sender will send more */
154 
155 /*
156  * Linux alignment requirement for CMSG struct manipulation.
157  * Linux aligns on (size_t) boundary on all architectures.
158  * Fortunately for linux, linux_cmsghdr is always size_t aligned !
159  * since no padding is added between the header and data.
160  * XXX: this code isn't right for the compat32 code.
161  */
162 struct linux_cmsghdr {
163 	size_t	cmsg_len;	/* NB not socklen_t */
164 	int	cmsg_level;
165 	int	cmsg_type;
166     /*	unsigned char __cmsg_data[0]; */
167 };
168 
169 #define LINUX_CMSG_ALIGN(n)	\
170 	(((n) + sizeof(size_t)-1) & ~(sizeof(size_t)-1))
171 /* Linux either uses this, or  &((cmsg)->__cmsg_data) */
172 #define LINUX_CMSG_DATA(cmsg)	\
173 	((u_char *)((struct linux_cmsghdr *)(cmsg) + 1))
174 #define	LINUX_CMSG_NXTHDR(mhdr, cmsg)	\
175 	((((char *)(cmsg) + LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
176 			    sizeof(*(cmsg))) > \
177 	    (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
178 	    (struct linux_cmsghdr *)NULL : \
179 	    (struct linux_cmsghdr *)((char *)(cmsg) + \
180 	        LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
181 /* This the number of bytes removed from each item (excl. final padding) */
182 #define LINUX_CMSG_ALIGN_DELTA	\
183 	(CMSG_ALIGN(sizeof(struct cmsghdr)) - sizeof(struct linux_cmsghdr))
184 
185 #define LINUX_CMSG_FIRSTHDR(mhdr) \
186 	((mhdr)->msg_controllen >= sizeof(struct linux_cmsghdr) ? \
187 	(struct linux_cmsghdr *)(mhdr)->msg_control : NULL)
188 
189 
190 /*
191  * Machine specific definitions.
192  */
193 #if defined(__i386__)
194 #include <compat/linux/arch/i386/linux_socket.h>
195 #elif defined(__m68k__)
196 #include <compat/linux/arch/m68k/linux_socket.h>
197 #elif defined(__alpha__)
198 #include <compat/linux/arch/alpha/linux_socket.h>
199 #elif defined(__powerpc__)
200 #include <compat/linux/arch/powerpc/linux_socket.h>
201 #elif defined(__mips__)
202 #include <compat/linux/arch/mips/linux_socket.h>
203 #elif defined(__arm__)
204 #include <compat/linux/arch/arm/linux_socket.h>
205 #elif defined(__amd64__)
206 #include <compat/linux/arch/amd64/linux_socket.h>
207 #else
208 #error Undefined linux_socket.h machine type.
209 #endif
210 
211 #endif /* !_LINUX_SOCKET_H */
212