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