cosmetics
[tomato.git] / release / src / router / openvpn / syshead.h
blob6e81103b295ca4b6c60a17536b23bbbf31dbaebf
1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
8 * Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef SYSHEAD_H
26 #define SYSHEAD_H
29 * Only include if not during configure
31 #ifndef PACKAGE_NAME
32 #ifdef _MSC_VER
33 #include "config-win32.h"
34 #else
35 #include "config.h"
36 #endif
37 #endif
39 /* branch prediction hints */
40 #if defined(__GNUC__)
41 # define likely(x) __builtin_expect((x),1)
42 # define unlikely(x) __builtin_expect((x),0)
43 #else
44 # define likely(x) (x)
45 # define unlikely(x) (x)
46 #endif
48 #if defined(_WIN32) && !defined(WIN32)
49 #define WIN32
50 #endif
52 #ifdef WIN32
53 #include <windows.h>
54 #define sleep(x) Sleep((x)*1000)
55 #define random rand
56 #define srandom srand
57 #endif
59 #ifdef HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
63 #ifdef HAVE_SYS_WAIT_H
64 # include <sys/wait.h>
65 #endif
67 #ifndef WIN32
68 #ifndef WEXITSTATUS
69 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
70 #endif
71 #ifndef WIFEXITED
72 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
73 #endif
74 #endif
76 #ifdef TIME_WITH_SYS_TIME
77 # include <sys/time.h>
78 # include <time.h>
79 #else
80 # ifdef HAVE_SYS_TIME_H
81 # include <sys/time.h>
82 # else
83 # include <time.h>
84 # endif
85 #endif
87 #ifdef HAVE_SYS_SOCKET_H
88 #include <sys/socket.h>
89 #endif
91 #ifdef HAVE_SYS_UN_H
92 #include <sys/un.h>
93 #endif
95 #ifdef HAVE_SYS_IOCTL_H
96 #include <sys/ioctl.h>
97 #endif
99 #ifdef HAVE_SYS_STAT_H
100 #include <sys/stat.h>
101 #endif
103 #ifdef HAVE_FCNTL_H
104 #include <fcntl.h>
105 #endif
107 #ifdef HAVE_SYS_FILE_H
108 #include <sys/file.h>
109 #endif
111 #ifdef HAVE_STDLIB_H
112 #include <stdlib.h>
113 #endif
115 #ifdef HAVE_STDINT_H
116 #include <stdint.h>
117 #endif
119 #ifdef HAVE_STDARG_H
120 #include <stdarg.h>
121 #endif
123 #ifdef HAVE_UNISTD_H
124 #include <unistd.h>
125 #endif
127 #ifdef HAVE_SIGNAL_H
128 #include <signal.h>
129 #endif
131 #ifdef HAVE_STDIO_H
132 #include <stdio.h>
133 #endif
135 #ifdef HAVE_CTYPE_H
136 #include <ctype.h>
137 #endif
139 #ifdef HAVE_ERRNO_H
140 #include <errno.h>
141 #endif
143 #ifdef HAVE_ERR_H
144 #include <err.h>
145 #endif
147 #ifdef HAVE_SYSLOG_H
148 #include <syslog.h>
149 #endif
151 #ifdef HAVE_PWD_H
152 #include <pwd.h>
153 #endif
155 #ifdef HAVE_GRP_H
156 #include <grp.h>
157 #endif
159 #ifdef USE_LIBDL
160 #include <dlfcn.h>
161 #endif
163 #ifdef HAVE_NETDB_H
164 #include <netdb.h>
165 #endif
167 #ifdef HAVE_NETINET_IN_H
168 #include <netinet/in.h>
169 #endif
171 #ifdef HAVE_RESOLV_H
172 #include <resolv.h>
173 #endif
175 #ifdef HAVE_SYS_POLL_H
176 #include <sys/poll.h>
177 #endif
179 #ifdef HAVE_SYS_EPOLL_H
180 #include <sys/epoll.h>
181 #endif
183 #ifdef HAVE_SETCON
184 #include <selinux/selinux.h>
185 #endif
187 #ifdef TARGET_SOLARIS
188 #ifdef HAVE_STRINGS_H
189 #include <strings.h>
190 #endif
191 #else
192 #ifdef HAVE_STRING_H
193 #include <string.h>
194 #endif
195 #endif
197 #ifdef HAVE_ARPA_INET_H
198 #include <arpa/inet.h>
199 #endif
201 #ifdef HAVE_NET_IF_H
202 #include <net/if.h>
203 #endif
205 #ifdef TARGET_LINUX
207 #if defined(HAVE_NETINET_IF_ETHER_H)
208 #include <netinet/if_ether.h>
209 #endif
211 #ifdef HAVE_LINUX_IF_TUN_H
212 #include <linux/if_tun.h>
213 #endif
215 #ifdef HAVE_NETINET_IP_H
216 #include <netinet/ip.h>
217 #endif
219 #ifdef HAVE_LINUX_SOCKIOS_H
220 #include <linux/sockios.h>
221 #endif
223 #ifdef HAVE_LINUX_TYPES_H
224 #include <linux/types.h>
225 #endif
227 #ifdef HAVE_LINUX_ERRQUEUE_H
228 #include <linux/errqueue.h>
229 #endif
231 #ifdef HAVE_NETINET_TCP_H
232 #include <netinet/tcp.h>
233 #endif
235 #endif /* TARGET_LINUX */
237 #ifdef TARGET_SOLARIS
239 #ifdef HAVE_STROPTS_H
240 #include <stropts.h>
241 #undef S_ERROR
242 #endif
244 #ifdef HAVE_NET_IF_TUN_H
245 #include <net/if_tun.h>
246 #endif
248 #ifdef HAVE_SYS_SOCKIO_H
249 #include <sys/sockio.h>
250 #endif
252 #ifdef HAVE_NETINET_IN_SYSTM_H
253 #include <netinet/in_systm.h>
254 #endif
256 #ifdef HAVE_NETINET_IP_H
257 #include <netinet/ip.h>
258 #endif
260 #ifdef HAVE_NETINET_TCP_H
261 #include <netinet/tcp.h>
262 #endif
264 #endif /* TARGET_SOLARIS */
266 #ifdef TARGET_OPENBSD
268 #ifdef HAVE_SYS_UIO_H
269 #include <sys/uio.h>
270 #endif
272 #ifdef HAVE_NETINET_IN_SYSTM_H
273 #include <netinet/in_systm.h>
274 #endif
276 #ifdef HAVE_NETINET_IP_H
277 #include <netinet/ip.h>
278 #endif
280 #ifdef HAVE_NET_IF_TUN_H
281 #include <net/if_tun.h>
282 #endif
284 #endif /* TARGET_OPENBSD */
286 #ifdef TARGET_FREEBSD
288 #ifdef HAVE_SYS_UIO_H
289 #include <sys/uio.h>
290 #endif
292 #ifdef HAVE_NETINET_IN_SYSTM_H
293 #include <netinet/in_systm.h>
294 #endif
296 #ifdef HAVE_NETINET_IP_H
297 #include <netinet/ip.h>
298 #endif
300 #ifdef HAVE_NET_IF_TUN_H
301 #include <net/if_tun.h>
302 #endif
304 #endif /* TARGET_FREEBSD */
306 #ifdef TARGET_NETBSD
308 #ifdef HAVE_NET_IF_TUN_H
309 #include <net/if_tun.h>
310 #endif
312 #ifdef HAVE_NETINET_TCP_H
313 #include <netinet/tcp.h>
314 #endif
316 #endif /* TARGET_NETBSD */
318 #ifdef TARGET_DRAGONFLY
320 #ifdef HAVE_SYS_UIO_H
321 #include <sys/uio.h>
322 #endif
324 #ifdef HAVE_NETINET_IN_SYSTM_H
325 #include <netinet/in_systm.h>
326 #endif
328 #ifdef HAVE_NETINET_IP_H
329 #include <netinet/ip.h>
330 #endif
332 #ifdef HAVE_NET_TUN_IF_TUN_H
333 #include <net/tun/if_tun.h>
334 #endif
336 #endif /* TARGET_DRAGONFLY */
338 #ifdef WIN32
339 #include <iphlpapi.h>
340 #include <wininet.h>
341 #endif
343 #ifdef HAVE_SYS_MMAN_H
344 #ifdef TARGET_DARWIN
345 #define _P1003_1B_VISIBLE
346 #endif /* TARGET_DARWIN */
347 #include <sys/mman.h>
348 #endif
351 * Pedantic mode is meant to accomplish lint-style program checking,
352 * not to build a working executable.
354 #ifdef __STRICT_ANSI__
355 # define PEDANTIC 1
356 # undef HAVE_CPP_VARARG_MACRO_GCC
357 # undef HAVE_CPP_VARARG_MACRO_ISO
358 # undef EMPTY_ARRAY_SIZE
359 # define EMPTY_ARRAY_SIZE 1
360 # undef inline
361 # define inline
362 #else
363 # define PEDANTIC 0
364 #endif
367 * Do we have the capability to support the --passtos option?
369 #if defined(IPPROTO_IP) && defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
370 #define PASSTOS_CAPABILITY 1
371 #else
372 #define PASSTOS_CAPABILITY 0
373 #endif
376 * Do we have the capability to report extended socket errors?
378 #if defined(HAVE_LINUX_TYPES_H) && defined(HAVE_LINUX_ERRQUEUE_H) && defined(HAVE_SOCK_EXTENDED_ERR) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXTHDR) && defined(IP_RECVERR) && defined(MSG_ERRQUEUE) && defined(SOL_IP) && defined(HAVE_IOVEC)
379 #define EXTENDED_SOCKET_ERROR_CAPABILITY 1
380 #else
381 #define EXTENDED_SOCKET_ERROR_CAPABILITY 0
382 #endif
385 * Does this platform support linux-style IP_PKTINFO?
387 #if defined(ENABLE_MULTIHOME) && defined(HAVE_IN_PKTINFO) && defined(IP_PKTINFO) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(HAVE_IOVEC) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXTHDR) && defined(HAVE_RECVMSG) && defined(HAVE_SENDMSG)
388 #define ENABLE_IP_PKTINFO 1
389 #else
390 #define ENABLE_IP_PKTINFO 0
391 #endif
394 * Disable ESEC
396 #if 0
397 #undef EXTENDED_SOCKET_ERROR_CAPABILITY
398 #define EXTENDED_SOCKET_ERROR_CAPABILITY 0
399 #endif
402 * Do we have a syslog capability?
404 #if defined(HAVE_OPENLOG) && defined(HAVE_SYSLOG)
405 #define SYSLOG_CAPABILITY 1
406 #else
407 #define SYSLOG_CAPABILITY 0
408 #endif
411 * Does this OS draw a distinction between binary and ascii files?
413 #ifndef O_BINARY
414 #define O_BINARY 0
415 #endif
418 * Directory separation char
420 #ifdef WIN32
421 #define OS_SPECIFIC_DIRSEP '\\'
422 #else
423 #define OS_SPECIFIC_DIRSEP '/'
424 #endif
427 * Define a boolean value based
428 * on Win32 status.
430 #ifdef WIN32
431 #define WIN32_0_1 1
432 #else
433 #define WIN32_0_1 0
434 #endif
437 * Our socket descriptor type.
439 #ifdef WIN32
440 #define SOCKET_UNDEFINED (INVALID_SOCKET)
441 typedef SOCKET socket_descriptor_t;
442 #else
443 #define SOCKET_UNDEFINED (-1)
444 typedef int socket_descriptor_t;
445 #endif
447 static inline int
448 socket_defined (const socket_descriptor_t sd)
450 return sd != SOCKET_UNDEFINED;
454 * Should statistics counters be 64 bits?
456 #define USE_64_BIT_COUNTERS
459 * Should we enable the use of execve() for calling subprocesses,
460 * instead of system()?
462 #if defined(HAVE_EXECVE) && defined(HAVE_FORK)
463 #define ENABLE_EXECVE
464 #endif
467 * Do we have point-to-multipoint capability?
470 #if defined(ENABLE_CLIENT_SERVER) && defined(USE_CRYPTO) && defined(USE_SSL) && defined(HAVE_GETTIMEOFDAY)
471 #define P2MP 1
472 #else
473 #define P2MP 0
474 #endif
476 #if P2MP && !defined(ENABLE_CLIENT_ONLY)
477 #define P2MP_SERVER 1
478 #else
479 #define P2MP_SERVER 0
480 #endif
483 * HTTPS port sharing capability
485 #if defined(ENABLE_PORT_SHARE) && P2MP_SERVER && defined(SCM_RIGHTS) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(HAVE_IOVEC) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXTHDR) && defined(HAVE_RECVMSG) && defined(HAVE_SENDMSG)
486 #define PORT_SHARE 1
487 #else
488 #define PORT_SHARE 0
489 #endif
492 * Do we have a plug-in capability?
494 #if defined(USE_LIBDL) || defined(USE_LOAD_LIBRARY)
495 #define ENABLE_PLUGIN
496 #endif
499 * Enable deferred authentication?
501 #if defined(CONFIGURE_DEF_AUTH) && P2MP_SERVER && defined(ENABLE_PLUGIN)
502 #define PLUGIN_DEF_AUTH
503 #endif
504 #if defined(CONFIGURE_DEF_AUTH) && P2MP_SERVER && defined(ENABLE_MANAGEMENT)
505 #define MANAGEMENT_DEF_AUTH
506 #endif
507 #if defined(PLUGIN_DEF_AUTH) || defined(MANAGEMENT_DEF_AUTH)
508 #define ENABLE_DEF_AUTH
509 #endif
512 * Enable packet filter?
514 #if defined(CONFIGURE_PF) && P2MP_SERVER && defined(ENABLE_PLUGIN) && defined(HAVE_STAT)
515 #define PLUGIN_PF
516 #endif
517 #if defined(CONFIGURE_PF) && P2MP_SERVER && defined(MANAGEMENT_DEF_AUTH)
518 #define MANAGEMENT_PF
519 #endif
520 #if defined(PLUGIN_PF) || defined(MANAGEMENT_PF)
521 #define ENABLE_PF
522 #endif
525 * Do we support Unix domain sockets?
527 #if defined(PF_UNIX) && !defined(WIN32)
528 #define UNIX_SOCK_SUPPORT 1
529 #else
530 #define UNIX_SOCK_SUPPORT 0
531 #endif
534 * Don't compile the struct buffer_list code unless something needs it
536 #if defined(ENABLE_MANAGEMENT) || defined(ENABLE_PF)
537 #define ENABLE_BUFFER_LIST
538 #endif
541 * Do we have pthread capability?
543 #ifdef USE_PTHREAD
544 #if defined(USE_CRYPTO) && defined(USE_SSL) && P2MP
545 #include <pthread.h>
546 #else
547 #undef USE_PTHREAD
548 #endif
549 #endif
552 * Pthread support is currently experimental (and quite unfinished).
554 #if 1 /* JYFIXME -- if defined, disable pthread */
555 #undef USE_PTHREAD
556 #endif
559 * Should we include OCC (options consistency check) code?
561 #ifndef ENABLE_SMALL
562 #define ENABLE_OCC
563 #endif
566 * Should we include NTLM proxy functionality
568 #if defined(USE_CRYPTO) && defined(ENABLE_HTTP_PROXY)
569 #define NTLM 1
570 #else
571 #define NTLM 0
572 #endif
575 * Should we include code common to all proxy methods?
577 #if defined(ENABLE_HTTP_PROXY) || defined(ENABLE_SOCKS)
578 #define GENERAL_PROXY_SUPPORT
579 #endif
582 * Do we have PKCS11 capability?
584 #if defined(USE_PKCS11) && defined(USE_CRYPTO) && defined(USE_SSL)
585 #define ENABLE_PKCS11
586 #endif
589 * Is poll available on this platform?
591 #if defined(HAVE_POLL) && defined(HAVE_SYS_POLL_H)
592 #define POLL 1
593 #else
594 #define POLL 0
595 #endif
598 * Is epoll available on this platform?
600 #if defined(HAVE_EPOLL_CREATE) && defined(HAVE_SYS_EPOLL_H)
601 #define EPOLL 1
602 #else
603 #define EPOLL 0
604 #endif
606 /* Disable EPOLL */
607 #if 0
608 #undef EPOLL
609 #define EPOLL 0
610 #endif
613 * Should we allow ca/cert/key files to be
614 * included inline, in the configuration file?
616 #define ENABLE_INLINE_FILES 1
619 * Reduce sensitivity to system clock instability
620 * and backtracks.
622 #define TIME_BACKTRACK_PROTECTION 1
625 * Is non-blocking connect() supported?
627 #if defined(HAVE_GETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_ERROR) && defined(EINPROGRESS) && defined(ETIMEDOUT)
628 #define CONNECT_NONBLOCK
629 #endif
632 * Do we have the capability to support the AUTO_USERID feature?
634 #if defined(ENABLE_AUTO_USERID)
635 #define AUTO_USERID 1
636 #else
637 #define AUTO_USERID 0
638 #endif
641 * Support "connection" directive
643 #if ENABLE_INLINE_FILES
644 #define ENABLE_CONNECTION 1
645 #endif
647 #endif