blob: 3c939ce61f6ad8b709b04a9e6d76d0ab70dd83aa [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
25/* This is needed on Linux for Netfilter includes */
26#include <sys/socket.h>
Willy Tarreauc8f24f82007-11-30 18:38:35 +010027#include <sys/types.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020028#include <common/config.h>
Jeremy Hinegardnere7dd2f22008-04-21 07:34:31 +020029#include <common/standard.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030
Willy Tarreau177e2b02008-07-15 00:36:31 +020031#ifndef BITS_PER_INT
32#define BITS_PER_INT (8*sizeof(int))
33#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +020034
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 Tarreaud6d06902009-08-19 11:22:33 +020048/* only Linux defines it */
49#ifndef MSG_NOSIGNAL
50#define MSG_NOSIGNAL 0
51#endif
52
Willy Tarreauc8f24f82007-11-30 18:38:35 +010053/* 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 Tarreau6db06d32009-08-19 11:14:11 +020060/* Only Linux defines MSG_MORE */
61#ifndef MSG_MORE
62#define MSG_MORE 0
63#endif
64
Willy Tarreaubaaee002006-06-26 02:48:02 +020065#if defined(TPROXY) && defined(NETFILTER)
Jeremy Hinegardnere7dd2f22008-04-21 07:34:31 +020066#include <linux/types.h>
67#include <linux/netfilter_ipv6.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020068#include <linux/netfilter_ipv4.h>
69#endif
70
Willy Tarreau0a459892008-01-13 17:37:16 +010071/* On Linux, IP_TRANSPARENT and/or IP_FREEBIND generally require a kernel patch */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010072#if defined(CONFIG_HAP_LINUX_TPROXY)
Willy Tarreau0a459892008-01-13 17:37:16 +010073#if !defined(IP_FREEBIND)
74#define IP_FREEBIND 15
75#endif /* !IP_FREEBIND */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010076#if !defined(IP_TRANSPARENT)
77#define IP_TRANSPARENT 19
78#endif /* !IP_TRANSPARENT */
79#endif /* CONFIG_HAP_LINUX_TPROXY */
80
Willy Tarreau58b2f832006-11-13 01:22:38 +010081/* We'll try to enable SO_REUSEPORT on Linux 2.4 and 2.6 if not defined.
82 * There are two families of values depending on the architecture. Those
83 * are at least valid on Linux 2.4 and 2.6, reason why we'll rely on the
84 * NETFILTER define.
85 */
86#if !defined(SO_REUSEPORT) && defined(NETFILTER)
87#if (SO_REUSEADDR == 2)
88#define SO_REUSEPORT 15
89#elif (SO_REUSEADDR == 0x0004)
90#define SO_REUSEPORT 0x0200
91#endif /* SO_REUSEADDR */
92#endif /* SO_REUSEPORT */
93
Willy Tarreaubaaee002006-06-26 02:48:02 +020094#if defined(__dietlibc__)
95#include <strings.h>
96#endif
97
Willy Tarreau2dd0d472006-06-29 17:53:05 +020098#endif /* _COMMON_COMPAT_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +020099
100/*
101 * Local variables:
102 * c-indent-level: 8
103 * c-basic-offset: 8
104 * End:
105 */