blob: a0764b103a6c2d93e6471a323668c5a4ae37ed56 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau17f449b2010-11-07 11:44:13 +01002 * 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 Tarreaubaaee002006-06-26 02:48:02 +020021
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 */
Willy Tarreau17f449b2010-11-07 11:44:13 +010026#include <sys/param.h>
Willy Tarreauc8f24f82007-11-30 18:38:35 +010027#include <sys/types.h>
Willy Tarreau0e996c62010-02-26 22:00:19 +010028#include <sys/socket.h>
Willy Tarreau17f449b2010-11-07 11:44:13 +010029#include <arpa/inet.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020030#include <common/config.h>
Jeremy Hinegardnere7dd2f22008-04-21 07:34:31 +020031#include <common/standard.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020032
Willy Tarreau177e2b02008-07-15 00:36:31 +020033#ifndef BITS_PER_INT
34#define BITS_PER_INT (8*sizeof(int))
35#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +020036
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 Tarreaud6d06902009-08-19 11:22:33 +020050/* only Linux defines it */
51#ifndef MSG_NOSIGNAL
52#define MSG_NOSIGNAL 0
53#endif
54
Willy Tarreauc8f24f82007-11-30 18:38:35 +010055/* 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 Tarreau6db06d32009-08-19 11:14:11 +020062/* Only Linux defines MSG_MORE */
63#ifndef MSG_MORE
64#define MSG_MORE 0
65#endif
66
Willy Tarreau2b57cb82013-06-10 19:56:38 +020067/* On Linux 2.4 and above, MSG_TRUNC can be used on TCP sockets to drop any
68 * pending data. Let's rely on NETFILTER to detect if this is supported.
69 */
70#ifdef NETFILTER
71#define MSG_TRUNC_CLEARS_INPUT
72#endif
73
Willy Tarreau17f449b2010-11-07 11:44:13 +010074/* Maximum path length, OS-dependant */
75#ifndef MAXPATHLEN
76#define MAXPATHLEN 128
77#endif
78
Willy Tarreaubd9a0a72011-10-23 21:14:29 +020079/* On Linux, allows pipes to be resized */
80#ifndef F_SETPIPE_SZ
81#define F_SETPIPE_SZ (1024 + 7)
82#endif
83
Willy Tarreaubaaee002006-06-26 02:48:02 +020084#if defined(TPROXY) && defined(NETFILTER)
Jeremy Hinegardnere7dd2f22008-04-21 07:34:31 +020085#include <linux/types.h>
86#include <linux/netfilter_ipv6.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020087#include <linux/netfilter_ipv4.h>
88#endif
89
Willy Tarreau0a459892008-01-13 17:37:16 +010090/* On Linux, IP_TRANSPARENT and/or IP_FREEBIND generally require a kernel patch */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010091#if defined(CONFIG_HAP_LINUX_TPROXY)
Willy Tarreau0a459892008-01-13 17:37:16 +010092#if !defined(IP_FREEBIND)
93#define IP_FREEBIND 15
94#endif /* !IP_FREEBIND */
Willy Tarreaub1e52e82008-01-13 14:49:51 +010095#if !defined(IP_TRANSPARENT)
96#define IP_TRANSPARENT 19
97#endif /* !IP_TRANSPARENT */
David du Colombier65c17962012-07-13 14:34:59 +020098#if !defined(IPV6_TRANSPARENT)
99#define IPV6_TRANSPARENT 75
100#endif /* !IPV6_TRANSPARENT */
Willy Tarreaub1e52e82008-01-13 14:49:51 +0100101#endif /* CONFIG_HAP_LINUX_TPROXY */
102
Pieter Baauwd551fb52013-05-08 22:49:23 +0200103#if defined(IP_FREEBIND) \
Pieter Baauwff30b662013-05-08 23:22:39 +0200104 || defined(IP_BINDANY) \
105 || defined(IPV6_BINDANY) \
Pieter Baauw1eb75922013-05-08 23:30:23 +0200106 || defined(SO_BINDANY) \
Pieter Baauwd551fb52013-05-08 22:49:23 +0200107 || defined(IP_TRANSPARENT) \
108 || defined(IPV6_TRANSPARENT)
109#define CONFIG_HAP_TRANSPARENT
110#endif
111
Willy Tarreau58b2f832006-11-13 01:22:38 +0100112/* We'll try to enable SO_REUSEPORT on Linux 2.4 and 2.6 if not defined.
113 * There are two families of values depending on the architecture. Those
114 * are at least valid on Linux 2.4 and 2.6, reason why we'll rely on the
115 * NETFILTER define.
116 */
117#if !defined(SO_REUSEPORT) && defined(NETFILTER)
118#if (SO_REUSEADDR == 2)
119#define SO_REUSEPORT 15
120#elif (SO_REUSEADDR == 0x0004)
121#define SO_REUSEPORT 0x0200
122#endif /* SO_REUSEADDR */
123#endif /* SO_REUSEPORT */
124
Lukas Tribus0999f762013-04-02 16:43:24 +0200125/* only Linux defines TCP_FASTOPEN */
126#ifdef USE_TFO
127#ifndef TCP_FASTOPEN
128#define TCP_FASTOPEN 23
129#endif
130#endif
131
Willy Tarreaubaaee002006-06-26 02:48:02 +0200132#if defined(__dietlibc__)
133#include <strings.h>
134#endif
135
Willy Tarreau2dd0d472006-06-29 17:53:05 +0200136#endif /* _COMMON_COMPAT_H */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200137
138/*
139 * Local variables:
140 * c-indent-level: 8
141 * c-basic-offset: 8
142 * End:
143 */