Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 2 | include/common/compat.h |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | Operating system compatibility interface. |
| 4 | |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 5 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 6 | |
| 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 Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 22 | #ifndef _COMMON_COMPAT_H |
| 23 | #define _COMMON_COMPAT_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 24 | |
Willy Tarreau | 3ff3dc1 | 2007-05-07 00:19:57 +0200 | [diff] [blame] | 25 | /* |
| 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 Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | /* This is needed on Linux for Netfilter includes */ |
| 35 | #include <sys/socket.h> |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 36 | #include <sys/types.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 37 | #include <common/config.h> |
Jeremy Hinegardner | e7dd2f2 | 2008-04-21 07:34:31 +0200 | [diff] [blame] | 38 | #include <common/standard.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 177e2b0 | 2008-07-15 00:36:31 +0200 | [diff] [blame] | 40 | #ifndef BITS_PER_INT |
| 41 | #define BITS_PER_INT (8*sizeof(int)) |
| 42 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
| 44 | /* this is for libc5 for example */ |
| 45 | #ifndef TCP_NODELAY |
| 46 | #define TCP_NODELAY 1 |
| 47 | #endif |
| 48 | |
| 49 | #ifndef SHUT_RD |
| 50 | #define SHUT_RD 0 |
| 51 | #endif |
| 52 | |
| 53 | #ifndef SHUT_WR |
| 54 | #define SHUT_WR 1 |
| 55 | #endif |
| 56 | |
Willy Tarreau | d6d0690 | 2009-08-19 11:22:33 +0200 | [diff] [blame] | 57 | /* only Linux defines it */ |
| 58 | #ifndef MSG_NOSIGNAL |
| 59 | #define MSG_NOSIGNAL 0 |
| 60 | #endif |
| 61 | |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 62 | /* AIX does not define MSG_DONTWAIT. We'll define it to zero, and test it |
| 63 | * wherever appropriate. |
| 64 | */ |
| 65 | #ifndef MSG_DONTWAIT |
| 66 | #define MSG_DONTWAIT 0 |
| 67 | #endif |
| 68 | |
Willy Tarreau | 6db06d3 | 2009-08-19 11:14:11 +0200 | [diff] [blame] | 69 | /* Only Linux defines MSG_MORE */ |
| 70 | #ifndef MSG_MORE |
| 71 | #define MSG_MORE 0 |
| 72 | #endif |
| 73 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 74 | #if defined(TPROXY) && defined(NETFILTER) |
Jeremy Hinegardner | e7dd2f2 | 2008-04-21 07:34:31 +0200 | [diff] [blame] | 75 | #include <linux/types.h> |
| 76 | #include <linux/netfilter_ipv6.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 77 | #include <linux/netfilter_ipv4.h> |
| 78 | #endif |
| 79 | |
Willy Tarreau | 0a45989 | 2008-01-13 17:37:16 +0100 | [diff] [blame] | 80 | /* On Linux, IP_TRANSPARENT and/or IP_FREEBIND generally require a kernel patch */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 81 | #if defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 0a45989 | 2008-01-13 17:37:16 +0100 | [diff] [blame] | 82 | #if !defined(IP_FREEBIND) |
| 83 | #define IP_FREEBIND 15 |
| 84 | #endif /* !IP_FREEBIND */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 85 | #if !defined(IP_TRANSPARENT) |
| 86 | #define IP_TRANSPARENT 19 |
| 87 | #endif /* !IP_TRANSPARENT */ |
| 88 | #endif /* CONFIG_HAP_LINUX_TPROXY */ |
| 89 | |
Willy Tarreau | 58b2f83 | 2006-11-13 01:22:38 +0100 | [diff] [blame] | 90 | /* We'll try to enable SO_REUSEPORT on Linux 2.4 and 2.6 if not defined. |
| 91 | * There are two families of values depending on the architecture. Those |
| 92 | * are at least valid on Linux 2.4 and 2.6, reason why we'll rely on the |
| 93 | * NETFILTER define. |
| 94 | */ |
| 95 | #if !defined(SO_REUSEPORT) && defined(NETFILTER) |
| 96 | #if (SO_REUSEADDR == 2) |
| 97 | #define SO_REUSEPORT 15 |
| 98 | #elif (SO_REUSEADDR == 0x0004) |
| 99 | #define SO_REUSEPORT 0x0200 |
| 100 | #endif /* SO_REUSEADDR */ |
| 101 | #endif /* SO_REUSEPORT */ |
| 102 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 103 | #if defined(__dietlibc__) |
| 104 | #include <strings.h> |
| 105 | #endif |
| 106 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 107 | #endif /* _COMMON_COMPAT_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Local variables: |
| 111 | * c-indent-level: 8 |
| 112 | * c-basic-offset: 8 |
| 113 | * End: |
| 114 | */ |