blob: 9cce1f53c6c01e7bf1a15aa349c891734c2be739 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau2dd0d472006-06-29 17:53:05 +02002 include/common/compat.h
Willy Tarreaubaaee002006-06-26 02:48:02 +02003 Operating system compatibility interface.
4
Willy Tarreaub1e52e82008-01-13 14:49:51 +01005 Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
Willy Tarreau2dd0d472006-06-29 17:53:05 +020022#ifndef _COMMON_COMPAT_H
23#define _COMMON_COMPAT_H
Willy Tarreaubaaee002006-06-26 02:48:02 +020024
Willy Tarreau3ff3dc12007-05-07 00:19:57 +020025/*
26 * Gcc before 3.0 needs [0] to declare a variable-size array
27 */
28#if __GNUC__ < 3
29#define VAR_ARRAY 0
30#else
31#define VAR_ARRAY
32#endif
33
Willy Tarreaubaaee002006-06-26 02:48:02 +020034/* This is needed on Linux for Netfilter includes */
35#include <sys/socket.h>
Willy Tarreauc8f24f82007-11-30 18:38:35 +010036#include <sys/types.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020037#include <common/config.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020038
39/* INTBITS
40 * how many bits are needed to code the size of an int on the target platform.
41 * (eg: 32bits -> 5)
42 */
43#define INTBITS 5
44
45/* this is for libc5 for example */
46#ifndef TCP_NODELAY
47#define TCP_NODELAY 1
48#endif
49
50#ifndef SHUT_RD
51#define SHUT_RD 0
52#endif
53
54#ifndef SHUT_WR
55#define SHUT_WR 1
56#endif
57
Willy Tarreauc8f24f82007-11-30 18:38:35 +010058/* AIX does not define MSG_DONTWAIT. We'll define it to zero, and test it
59 * wherever appropriate.
60 */
61#ifndef MSG_DONTWAIT
62#define MSG_DONTWAIT 0
63#endif
64
Willy Tarreaubaaee002006-06-26 02:48:02 +020065#if defined(TPROXY) && defined(NETFILTER)
66#include <linux/netfilter_ipv4.h>
67#endif
68
Willy Tarreau0a459892008-01-13 17:37:16 +010069/* On Linux, IP_TRANSPARENT and/or IP_FREEBIND generally require a kernel patch */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010070#if defined(CONFIG_HAP_LINUX_TPROXY)
Willy Tarreau0a459892008-01-13 17:37:16 +010071#if !defined(IP_FREEBIND)
72#define IP_FREEBIND 15
73#endif /* !IP_FREEBIND */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010074#if !defined(IP_TRANSPARENT)
75#define IP_TRANSPARENT 19
76#endif /* !IP_TRANSPARENT */
77#endif /* CONFIG_HAP_LINUX_TPROXY */
78
Willy Tarreau58b2f832006-11-13 01:22:38 +010079/* We'll try to enable SO_REUSEPORT on Linux 2.4 and 2.6 if not defined.
80 * There are two families of values depending on the architecture. Those
81 * are at least valid on Linux 2.4 and 2.6, reason why we'll rely on the
82 * NETFILTER define.
83 */
84#if !defined(SO_REUSEPORT) && defined(NETFILTER)
85#if (SO_REUSEADDR == 2)
86#define SO_REUSEPORT 15
87#elif (SO_REUSEADDR == 0x0004)
88#define SO_REUSEPORT 0x0200
89#endif /* SO_REUSEADDR */
90#endif /* SO_REUSEPORT */
91
Willy Tarreaubaaee002006-06-26 02:48:02 +020092#if defined(__dietlibc__)
93#include <strings.h>
94#endif
95
Willy Tarreau2dd0d472006-06-29 17:53:05 +020096#endif /* _COMMON_COMPAT_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +020097
98/*
99 * Local variables:
100 * c-indent-level: 8
101 * c-basic-offset: 8
102 * End:
103 */