OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / openvpn / syshead.h
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.
7  *
8  *  Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
9  *
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.
13  *
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.
18  *
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
23  */
24
25 #ifndef SYSHEAD_H
26 #define SYSHEAD_H
27
28 /*
29  * Only include if not during configure
30  */
31 #ifndef PACKAGE_NAME
32 #ifdef _MSC_VER
33 #include "config-win32.h"
34 #else
35 #include "config.h"
36 #endif
37 #endif
38
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
47
48 #if defined(_WIN32) && !defined(WIN32)
49 #define WIN32
50 #endif
51
52 #ifdef WIN32
53 #include <windows.h>
54 #define sleep(x) Sleep((x)*1000)
55 #define random rand
56 #define srandom srand
57 #endif
58
59 #ifdef HAVE_SYS_TYPES_H
60 #include <sys/types.h>
61 #endif
62
63 #ifdef HAVE_SYS_WAIT_H
64 # include <sys/wait.h>
65 #endif
66
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
75
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
86
87 #ifdef HAVE_SYS_SOCKET_H
88 #include <sys/socket.h>
89 #endif
90
91 #ifdef HAVE_SYS_UN_H
92 #include <sys/un.h>
93 #endif
94
95 #ifdef HAVE_SYS_IOCTL_H
96 #include <sys/ioctl.h>
97 #endif
98
99 #ifdef HAVE_SYS_STAT_H
100 #include <sys/stat.h>
101 #endif
102
103 #ifdef HAVE_FCNTL_H
104 #include <fcntl.h>
105 #endif
106
107 #ifdef HAVE_SYS_FILE_H
108 #include <sys/file.h>
109 #endif
110
111 #ifdef HAVE_STDLIB_H
112 #include <stdlib.h>
113 #endif
114
115 #ifdef HAVE_STDINT_H
116 #include <stdint.h>
117 #endif
118
119 #ifdef HAVE_STDARG_H
120 #include <stdarg.h>
121 #endif
122
123 #ifdef HAVE_UNISTD_H
124 #include <unistd.h>
125 #endif
126
127 #ifdef HAVE_SIGNAL_H
128 #include <signal.h>
129 #endif
130
131 #ifdef HAVE_STDIO_H
132 #include <stdio.h>
133 #endif
134
135 #ifdef HAVE_CTYPE_H
136 #include <ctype.h>
137 #endif
138
139 #ifdef HAVE_ERRNO_H
140 #include <errno.h>
141 #endif
142
143 #ifdef HAVE_ERR_H
144 #include <err.h>
145 #endif
146
147 #ifdef HAVE_SYSLOG_H
148 #include <syslog.h>
149 #endif
150
151 #ifdef HAVE_PWD_H
152 #include <pwd.h>
153 #endif
154
155 #ifdef HAVE_GRP_H
156 #include <grp.h>
157 #endif
158
159 #ifdef USE_LIBDL
160 #include <dlfcn.h>
161 #endif
162
163 #ifdef HAVE_NETDB_H
164 #include <netdb.h>
165 #endif
166
167 #ifdef HAVE_NETINET_IN_H
168 #include <netinet/in.h>
169 #endif
170
171 #ifdef HAVE_RESOLV_H
172 #include <resolv.h>
173 #endif
174
175 #ifdef HAVE_SYS_POLL_H
176 #include <sys/poll.h>
177 #endif
178
179 #ifdef HAVE_SYS_EPOLL_H
180 #include <sys/epoll.h>
181 #endif
182
183 #ifdef HAVE_SETCON
184 #include <selinux/selinux.h>
185 #endif
186
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
196
197 #ifdef HAVE_ARPA_INET_H
198 #include <arpa/inet.h>
199 #endif
200
201 #ifdef HAVE_NET_IF_H
202 #include <net/if.h>
203 #endif
204
205 #ifdef TARGET_LINUX
206
207 #if defined(HAVE_NETINET_IF_ETHER_H)
208 #include <netinet/if_ether.h>
209 #endif
210
211 #ifdef HAVE_LINUX_IF_TUN_H
212 #include <linux/if_tun.h>
213 #endif
214
215 #ifdef HAVE_NETINET_IP_H
216 #include <netinet/ip.h>
217 #endif
218
219 #ifdef HAVE_LINUX_SOCKIOS_H
220 #include <linux/sockios.h>
221 #endif
222
223 #ifdef HAVE_LINUX_TYPES_H
224 #include <linux/types.h>
225 #endif
226
227 #ifdef HAVE_LINUX_ERRQUEUE_H
228 #include <linux/errqueue.h>
229 #endif
230
231 #ifdef HAVE_NETINET_TCP_H
232 #include <netinet/tcp.h>
233 #endif
234
235 #endif /* TARGET_LINUX */
236
237 #ifdef TARGET_SOLARIS
238
239 #ifdef HAVE_STROPTS_H
240 #include <stropts.h>
241 #undef S_ERROR
242 #endif
243
244 #ifdef HAVE_NET_IF_TUN_H
245 #include <net/if_tun.h>
246 #endif
247
248 #ifdef HAVE_SYS_SOCKIO_H
249 #include <sys/sockio.h>
250 #endif
251
252 #ifdef HAVE_NETINET_IN_SYSTM_H
253 #include <netinet/in_systm.h>
254 #endif
255
256 #ifdef HAVE_NETINET_IP_H
257 #include <netinet/ip.h>
258 #endif
259
260 #ifdef HAVE_NETINET_TCP_H
261 #include <netinet/tcp.h>
262 #endif
263
264 #endif /* TARGET_SOLARIS */
265
266 #ifdef TARGET_OPENBSD
267
268 #ifdef HAVE_SYS_UIO_H
269 #include <sys/uio.h>
270 #endif
271
272 #ifdef HAVE_NETINET_IN_SYSTM_H
273 #include <netinet/in_systm.h>
274 #endif
275
276 #ifdef HAVE_NETINET_IP_H
277 #include <netinet/ip.h>
278 #endif
279
280 #ifdef HAVE_NET_IF_TUN_H
281 #include <net/if_tun.h>
282 #endif
283
284 #endif /* TARGET_OPENBSD */
285
286 #ifdef TARGET_FREEBSD
287
288 #ifdef HAVE_SYS_UIO_H
289 #include <sys/uio.h>
290 #endif
291
292 #ifdef HAVE_NETINET_IN_SYSTM_H
293 #include <netinet/in_systm.h>
294 #endif
295
296 #ifdef HAVE_NETINET_IP_H
297 #include <netinet/ip.h>
298 #endif
299
300 #ifdef HAVE_NET_IF_TUN_H
301 #include <net/if_tun.h>
302 #endif
303
304 #endif /* TARGET_FREEBSD */
305
306 #ifdef TARGET_NETBSD
307
308 #ifdef HAVE_NET_IF_TUN_H
309 #include <net/if_tun.h>
310 #endif
311
312 #ifdef HAVE_NETINET_TCP_H
313 #include <netinet/tcp.h>
314 #endif
315
316 #endif /* TARGET_NETBSD */
317
318 #ifdef TARGET_DRAGONFLY
319
320 #ifdef HAVE_SYS_UIO_H
321 #include <sys/uio.h>
322 #endif
323
324 #ifdef HAVE_NETINET_IN_SYSTM_H
325 #include <netinet/in_systm.h>
326 #endif
327
328 #ifdef HAVE_NETINET_IP_H
329 #include <netinet/ip.h>
330 #endif
331
332 #ifdef HAVE_NET_TUN_IF_TUN_H
333 #include <net/tun/if_tun.h>
334 #endif
335
336 #endif /* TARGET_DRAGONFLY */
337
338 #ifdef WIN32
339 #include <iphlpapi.h>
340 #include <wininet.h>
341 #endif
342
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
349
350 /*
351  * Pedantic mode is meant to accomplish lint-style program checking,
352  * not to build a working executable.
353  */
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
365
366 /*
367  * Do we have the capability to support the --passtos option?
368  */
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
374
375 /*
376  * Do we have the capability to report extended socket errors?
377  */
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
383
384 /*
385  * Does this platform support linux-style IP_PKTINFO?
386  */
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
392
393 /*
394  * Disable ESEC
395  */
396 #if 0
397 #undef EXTENDED_SOCKET_ERROR_CAPABILITY
398 #define EXTENDED_SOCKET_ERROR_CAPABILITY 0
399 #endif
400
401 /*
402  * Do we have a syslog capability?
403  */
404 #if defined(HAVE_OPENLOG) && defined(HAVE_SYSLOG)
405 #define SYSLOG_CAPABILITY 1
406 #else
407 #define SYSLOG_CAPABILITY 0
408 #endif
409
410 /*
411  * Does this OS draw a distinction between binary and ascii files?
412  */
413 #ifndef O_BINARY
414 #define O_BINARY 0
415 #endif
416
417 /*
418  * Directory separation char
419  */
420 #ifdef WIN32
421 #define OS_SPECIFIC_DIRSEP '\\'
422 #else
423 #define OS_SPECIFIC_DIRSEP '/'
424 #endif
425
426 /*
427  * Define a boolean value based
428  * on Win32 status.
429  */
430 #ifdef WIN32
431 #define WIN32_0_1 1
432 #else
433 #define WIN32_0_1 0
434 #endif
435
436 /*
437  * Our socket descriptor type.
438  */
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
446
447 static inline int
448 socket_defined (const socket_descriptor_t sd)
449 {
450   return sd != SOCKET_UNDEFINED;
451 }
452
453 /*
454  * Should statistics counters be 64 bits?
455  */
456 #define USE_64_BIT_COUNTERS
457
458 /*
459  * Should we enable the use of execve() for calling subprocesses,
460  * instead of system()?
461  */
462 #if defined(HAVE_EXECVE) && defined(HAVE_FORK)
463 #define ENABLE_EXECVE
464 #endif
465
466 /*
467  * Do we have point-to-multipoint capability?
468  */
469
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
475
476 #if P2MP && !defined(ENABLE_CLIENT_ONLY)
477 #define P2MP_SERVER 1
478 #else
479 #define P2MP_SERVER 0
480 #endif
481
482 /*
483  * HTTPS port sharing capability
484  */
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
490
491 /*
492  * Do we have a plug-in capability?
493  */
494 #if defined(USE_LIBDL) || defined(USE_LOAD_LIBRARY)
495 #define ENABLE_PLUGIN
496 #endif
497
498 /*
499  * Enable deferred authentication?
500  */
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
510
511 /*
512  * Enable packet filter?
513  */
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
523
524 /*
525  * Do we support Unix domain sockets?
526  */
527 #if defined(PF_UNIX) && !defined(WIN32)
528 #define UNIX_SOCK_SUPPORT 1
529 #else
530 #define UNIX_SOCK_SUPPORT 0
531 #endif
532
533 /*
534  * Don't compile the struct buffer_list code unless something needs it
535  */
536 #if defined(ENABLE_MANAGEMENT) || defined(ENABLE_PF)
537 #define ENABLE_BUFFER_LIST
538 #endif
539
540 /*
541  * Do we have pthread capability?
542  */
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
550
551 /*
552  * Pthread support is currently experimental (and quite unfinished).
553  */
554 #if 1 /* JYFIXME -- if defined, disable pthread */
555 #undef USE_PTHREAD
556 #endif
557
558 /*
559  * Should we include OCC (options consistency check) code?
560  */
561 #ifndef ENABLE_SMALL
562 #define ENABLE_OCC
563 #endif
564
565 /*
566  * Should we include NTLM proxy functionality
567  */
568 #if defined(USE_CRYPTO) && defined(ENABLE_HTTP_PROXY)
569 #define NTLM 1
570 #else
571 #define NTLM 0
572 #endif
573
574 /*
575  * Should we include code common to all proxy methods?
576  */
577 #if defined(ENABLE_HTTP_PROXY) || defined(ENABLE_SOCKS)
578 #define GENERAL_PROXY_SUPPORT
579 #endif
580
581 /*
582  * Do we have PKCS11 capability?
583  */
584 #if defined(USE_PKCS11) && defined(USE_CRYPTO) && defined(USE_SSL)
585 #define ENABLE_PKCS11
586 #endif
587
588 /*
589  * Is poll available on this platform?
590  */
591 #if defined(HAVE_POLL) && defined(HAVE_SYS_POLL_H)
592 #define POLL 1
593 #else
594 #define POLL 0
595 #endif
596
597 /*
598  * Is epoll available on this platform?
599  */
600 #if defined(HAVE_EPOLL_CREATE) && defined(HAVE_SYS_EPOLL_H)
601 #define EPOLL 1
602 #else
603 #define EPOLL 0
604 #endif
605
606 /* Disable EPOLL */
607 #if 0
608 #undef EPOLL
609 #define EPOLL 0
610 #endif
611
612 /*
613  * Should we allow ca/cert/key files to be
614  * included inline, in the configuration file?
615  */
616 #define ENABLE_INLINE_FILES 1
617
618 /*
619  * Reduce sensitivity to system clock instability
620  * and backtracks.
621  */
622 #define TIME_BACKTRACK_PROTECTION 1
623
624 /*
625  * Is non-blocking connect() supported?
626  */
627 #if defined(HAVE_GETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_ERROR) && defined(EINPROGRESS) && defined(ETIMEDOUT)
628 #define CONNECT_NONBLOCK
629 #endif
630
631 /*
632  * Do we have the capability to support the AUTO_USERID feature? 
633  */
634 #if defined(ENABLE_AUTO_USERID)
635 #define AUTO_USERID 1
636 #else
637 #define AUTO_USERID 0
638 #endif
639
640 /*
641  * Support "connection" directive
642  */
643 #if ENABLE_INLINE_FILES
644 #define ENABLE_CONNECTION 1
645 #endif
646
647 #endif