Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 17f449b | 2010-11-07 11:44:13 +0100 | [diff] [blame] | 2 | * include/common/compat.h |
| 3 | * Operating system compatibility interface. |
| 4 | * |
| 5 | * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu |
| 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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 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 | |
| 25 | /* This is needed on Linux for Netfilter includes */ |
Willy Tarreau | 17f449b | 2010-11-07 11:44:13 +0100 | [diff] [blame] | 26 | #include <sys/param.h> |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 27 | #include <sys/types.h> |
Willy Tarreau | 0e996c6 | 2010-02-26 22:00:19 +0100 | [diff] [blame] | 28 | #include <sys/socket.h> |
Willy Tarreau | 17f449b | 2010-11-07 11:44:13 +0100 | [diff] [blame] | 29 | #include <arpa/inet.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | 177e2b0 | 2008-07-15 00:36:31 +0200 | [diff] [blame] | 31 | #ifndef BITS_PER_INT |
| 32 | #define BITS_PER_INT (8*sizeof(int)) |
| 33 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
| 35 | /* this is for libc5 for example */ |
| 36 | #ifndef TCP_NODELAY |
| 37 | #define TCP_NODELAY 1 |
| 38 | #endif |
| 39 | |
| 40 | #ifndef SHUT_RD |
| 41 | #define SHUT_RD 0 |
| 42 | #endif |
| 43 | |
| 44 | #ifndef SHUT_WR |
| 45 | #define SHUT_WR 1 |
| 46 | #endif |
| 47 | |
Willy Tarreau | d6d0690 | 2009-08-19 11:22:33 +0200 | [diff] [blame] | 48 | /* only Linux defines it */ |
| 49 | #ifndef MSG_NOSIGNAL |
| 50 | #define MSG_NOSIGNAL 0 |
| 51 | #endif |
| 52 | |
Willy Tarreau | c8f24f8 | 2007-11-30 18:38:35 +0100 | [diff] [blame] | 53 | /* AIX does not define MSG_DONTWAIT. We'll define it to zero, and test it |
| 54 | * wherever appropriate. |
| 55 | */ |
| 56 | #ifndef MSG_DONTWAIT |
| 57 | #define MSG_DONTWAIT 0 |
| 58 | #endif |
| 59 | |
Willy Tarreau | 6db06d3 | 2009-08-19 11:14:11 +0200 | [diff] [blame] | 60 | /* Only Linux defines MSG_MORE */ |
| 61 | #ifndef MSG_MORE |
| 62 | #define MSG_MORE 0 |
| 63 | #endif |
| 64 | |
Willy Tarreau | 2b57cb8 | 2013-06-10 19:56:38 +0200 | [diff] [blame] | 65 | /* On Linux 2.4 and above, MSG_TRUNC can be used on TCP sockets to drop any |
| 66 | * pending data. Let's rely on NETFILTER to detect if this is supported. |
| 67 | */ |
| 68 | #ifdef NETFILTER |
| 69 | #define MSG_TRUNC_CLEARS_INPUT |
| 70 | #endif |
| 71 | |
Willy Tarreau | 17f449b | 2010-11-07 11:44:13 +0100 | [diff] [blame] | 72 | /* Maximum path length, OS-dependant */ |
| 73 | #ifndef MAXPATHLEN |
| 74 | #define MAXPATHLEN 128 |
| 75 | #endif |
| 76 | |
Willy Tarreau | bd9a0a7 | 2011-10-23 21:14:29 +0200 | [diff] [blame] | 77 | /* On Linux, allows pipes to be resized */ |
| 78 | #ifndef F_SETPIPE_SZ |
| 79 | #define F_SETPIPE_SZ (1024 + 7) |
| 80 | #endif |
| 81 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 82 | #if defined(TPROXY) && defined(NETFILTER) |
Jeremy Hinegardner | e7dd2f2 | 2008-04-21 07:34:31 +0200 | [diff] [blame] | 83 | #include <linux/types.h> |
| 84 | #include <linux/netfilter_ipv6.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | #include <linux/netfilter_ipv4.h> |
| 86 | #endif |
| 87 | |
Willy Tarreau | 0a45989 | 2008-01-13 17:37:16 +0100 | [diff] [blame] | 88 | /* 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] | 89 | #if defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 0a45989 | 2008-01-13 17:37:16 +0100 | [diff] [blame] | 90 | #if !defined(IP_FREEBIND) |
| 91 | #define IP_FREEBIND 15 |
| 92 | #endif /* !IP_FREEBIND */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 93 | #if !defined(IP_TRANSPARENT) |
| 94 | #define IP_TRANSPARENT 19 |
| 95 | #endif /* !IP_TRANSPARENT */ |
David du Colombier | 65c1796 | 2012-07-13 14:34:59 +0200 | [diff] [blame] | 96 | #if !defined(IPV6_TRANSPARENT) |
| 97 | #define IPV6_TRANSPARENT 75 |
| 98 | #endif /* !IPV6_TRANSPARENT */ |
Willy Tarreau | b1e52e8 | 2008-01-13 14:49:51 +0100 | [diff] [blame] | 99 | #endif /* CONFIG_HAP_LINUX_TPROXY */ |
| 100 | |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 101 | #if defined(IP_FREEBIND) \ |
Pieter Baauw | ff30b66 | 2013-05-08 23:22:39 +0200 | [diff] [blame] | 102 | || defined(IP_BINDANY) \ |
| 103 | || defined(IPV6_BINDANY) \ |
Pieter Baauw | 1eb7592 | 2013-05-08 23:30:23 +0200 | [diff] [blame] | 104 | || defined(SO_BINDANY) \ |
Pieter Baauw | d551fb5 | 2013-05-08 22:49:23 +0200 | [diff] [blame] | 105 | || defined(IP_TRANSPARENT) \ |
| 106 | || defined(IPV6_TRANSPARENT) |
| 107 | #define CONFIG_HAP_TRANSPARENT |
| 108 | #endif |
| 109 | |
Willy Tarreau | 58b2f83 | 2006-11-13 01:22:38 +0100 | [diff] [blame] | 110 | /* We'll try to enable SO_REUSEPORT on Linux 2.4 and 2.6 if not defined. |
| 111 | * There are two families of values depending on the architecture. Those |
| 112 | * are at least valid on Linux 2.4 and 2.6, reason why we'll rely on the |
| 113 | * NETFILTER define. |
| 114 | */ |
| 115 | #if !defined(SO_REUSEPORT) && defined(NETFILTER) |
| 116 | #if (SO_REUSEADDR == 2) |
| 117 | #define SO_REUSEPORT 15 |
| 118 | #elif (SO_REUSEADDR == 0x0004) |
| 119 | #define SO_REUSEPORT 0x0200 |
| 120 | #endif /* SO_REUSEADDR */ |
| 121 | #endif /* SO_REUSEPORT */ |
| 122 | |
Lukas Tribus | 0999f76 | 2013-04-02 16:43:24 +0200 | [diff] [blame] | 123 | /* only Linux defines TCP_FASTOPEN */ |
| 124 | #ifdef USE_TFO |
| 125 | #ifndef TCP_FASTOPEN |
| 126 | #define TCP_FASTOPEN 23 |
| 127 | #endif |
| 128 | #endif |
| 129 | |
Lukas Tribus | 67db8df | 2013-06-23 17:37:13 +0200 | [diff] [blame] | 130 | /* If IPv6 is supported, define IN6_IS_ADDR_V4MAPPED() if missing. */ |
| 131 | #if defined(IPV6_TCLASS) && !defined(IN6_IS_ADDR_V4MAPPED) |
| 132 | #define IN6_IS_ADDR_V4MAPPED(a) \ |
| 133 | ((((const uint32_t *) (a))[0] == 0) \ |
| 134 | && (((const uint32_t *) (a))[1] == 0) \ |
| 135 | && (((const uint32_t *) (a))[2] == htonl (0xffff))) |
| 136 | #endif |
| 137 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 138 | #if defined(__dietlibc__) |
| 139 | #include <strings.h> |
| 140 | #endif |
| 141 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 142 | #endif /* _COMMON_COMPAT_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * Local variables: |
| 146 | * c-indent-level: 8 |
| 147 | * c-basic-offset: 8 |
| 148 | * End: |
| 149 | */ |