blob: 511b343960d80db4d4940f18fd2432266de4f16e [file] [log] [blame]
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00001#! /bin/bash
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -08002# This is not an autoconf generated configure
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00003#
osdl.net!shemminger4b1bbd92004-08-09 16:35:28 +00004INCLUDE=${1:-"$PWD/include"}
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00005
Stephen Hemmingere557d1a2012-02-15 10:03:39 -08006# Make a temp directory in build tree.
7TMPDIR=$(mktemp -d config.XXXXXX)
Mathias Krausec2f7d6c2012-09-01 20:55:29 +02008trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
Stephen Hemmingere557d1a2012-02-15 10:03:39 -08009
Mike Frysinger601f60e2012-12-16 17:09:15 -050010check_toolchain()
11{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080012 : ${PKG_CONFIG:=pkg-config}
13 : ${AR=ar}
14 : ${CC=gcc}
15 echo "AR:=${AR}" >>Config
16 echo "CC:=${CC}" >>Config
Mike Frysinger601f60e2012-12-16 17:09:15 -050017}
18
Andreas Henriksson14743a72010-01-01 23:20:30 +010019check_atm()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000020{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080021 cat >$TMPDIR/atmtest.c <<EOF
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000022#include <atm.h>
23int main(int argc, char **argv) {
24 struct atm_qos qos;
25 (void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
26 return 0;
27}
28EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080029
30 $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
31 if [ $? -eq 0 ]
32 then
33 echo "TC_CONFIG_ATM:=y" >>Config
34 echo yes
35 else
36 echo no
37 fi
38 rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000039}
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050040
Andreas Henriksson14743a72010-01-01 23:20:30 +010041check_xt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000042{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080043 #check if we have xtables from iptables >= 1.4.5.
44 cat >$TMPDIR/ipttest.c <<EOF
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010045#include <xtables.h>
46#include <linux/netfilter.h>
47static struct xtables_globals test_globals = {
48 .option_offset = 0,
49 .program_name = "tc-ipt",
50 .program_version = XTABLES_VERSION,
51 .orig_opts = NULL,
52 .opts = NULL,
53 .exit_err = NULL,
54};
55
56int main(int argc, char **argv)
57{
58 xtables_init_all(&test_globals, NFPROTO_IPV4);
59 return 0;
60}
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010061EOF
62
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080063 if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL \
64 $(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
65 then
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010066 echo "TC_CONFIG_XT:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000067 echo "using xtables"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080068 fi
69 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000070}
71
Andreas Henriksson14743a72010-01-01 23:20:30 +010072check_xt_old()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000073{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080074 # bail if previous XT checks has already succeded.
75 if grep -q TC_CONFIG_XT Config
76 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000077 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080078 fi
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010079
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080080 #check if we dont need our internal header ..
81 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050082#include <xtables.h>
83char *lib_dir;
84unsigned int global_option_offset = 0;
85const char *program_version = XTABLES_VERSION;
86const char *program_name = "tc-ipt";
87struct afinfo afinfo = {
88 .libprefix = "libxt_",
89};
90
91void exit_error(enum exittype status, const char *msg, ...)
92{
93}
94
95int main(int argc, char **argv) {
96
97 return 0;
98}
99
100EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500101
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800102 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
103 if [ $? -eq 0 ]
104 then
Andreas Henriksson80d689d2009-12-02 16:11:21 +0100105 echo "TC_CONFIG_XT_OLD:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000106 echo "using old xtables (no need for xt-internal.h)"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800107 fi
108 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000109}
110
Andreas Henriksson14743a72010-01-01 23:20:30 +0100111check_xt_old_internal_h()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000112{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800113 # bail if previous XT checks has already succeded.
114 if grep -q TC_CONFIG_XT Config
115 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000116 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800117 fi
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500118
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800119 #check if we need our own internal.h
120 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500121#include <xtables.h>
122#include "xt-internal.h"
123char *lib_dir;
124unsigned int global_option_offset = 0;
125const char *program_version = XTABLES_VERSION;
126const char *program_name = "tc-ipt";
127struct afinfo afinfo = {
128 .libprefix = "libxt_",
129};
130
131void exit_error(enum exittype status, const char *msg, ...)
132{
133}
134
135int main(int argc, char **argv) {
136
137 return 0;
138}
139
140EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800141 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500142
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800143 if [ $? -eq 0 ]
144 then
145 echo "using old xtables with xt-internal.h"
146 echo "TC_CONFIG_XT_OLD_H:=y" >>Config
147 fi
148 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000149}
150
Andreas Henriksson14743a72010-01-01 23:20:30 +0100151check_ipt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000152{
153 if ! grep TC_CONFIG_XT Config > /dev/null
154 then
155 echo "using iptables"
156 fi
157}
158
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000159check_ipt_lib_dir()
160{
Mike Frysingere4fc4ad2012-11-08 11:41:17 -0500161 IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
Li Weida7fbb22012-08-20 09:41:47 +0800162 if [ -n "$IPT_LIB_DIR" ]; then
163 echo $IPT_LIB_DIR
164 echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
165 return
166 fi
167
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000168 for dir in /lib /usr/lib /usr/local/lib
169 do
Dan McGee44e743e2011-07-15 08:52:24 +0000170 for file in $dir/{xtables,iptables}/lib*t_*so ; do
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000171 if [ -f $file ]; then
Dan McGee44e743e2011-07-15 08:52:24 +0000172 echo ${file%/*}
173 echo "IPT_LIB_DIR:=${file%/*}" >> Config
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000174 return
175 fi
176 done
177 done
178 echo "not found!"
179}
180
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000181check_setns()
182{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800183 cat >$TMPDIR/setnstest.c <<EOF
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000184#include <sched.h>
185int main(int argc, char **argv)
186{
187 (void)setns(0,0);
188 return 0;
189}
190EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800191 $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
192 if [ $? -eq 0 ]
193 then
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000194 echo "IP_CONFIG_SETNS:=y" >>Config
195 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800196 else
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000197 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800198 fi
199 rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000200}
201
Florian Westphal81944112012-08-09 09:18:50 +0000202check_ipset()
203{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800204 cat >$TMPDIR/ipsettest.c <<EOF
Florian Westphal81944112012-08-09 09:18:50 +0000205#include <linux/netfilter/ipset/ip_set.h>
206#ifndef IP_SET_INVALID
207#define IPSET_DIM_MAX 3
208typedef unsigned short ip_set_id_t;
209#endif
210#include <linux/netfilter/xt_set.h>
211
212struct xt_set_info info;
213#if IPSET_PROTOCOL == 6
214int main(void)
215{
216 return IPSET_MAXNAMELEN;
217}
218#else
219#error unknown ipset version
220#endif
221EOF
222
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800223 if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
224 then
Florian Westphal81944112012-08-09 09:18:50 +0000225 echo "TC_CONFIG_IPSET:=y" >>Config
226 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800227 else
Florian Westphal81944112012-08-09 09:18:50 +0000228 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800229 fi
230 rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
Florian Westphal81944112012-08-09 09:18:50 +0000231}
232
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000233echo "# Generated config based on" $INCLUDE >Config
Jan Engelhardtd29feaa2012-12-18 09:18:45 -0800234echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
Mike Frysinger601f60e2012-12-16 17:09:15 -0500235check_toolchain
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000236
237echo "TC schedulers"
238
239echo -n " ATM "
240check_atm
241
242echo -n " IPT "
243check_xt
244check_xt_old
245check_xt_old_internal_h
246check_ipt
247
Florian Westphal81944112012-08-09 09:18:50 +0000248echo -n " IPSET "
249check_ipset
250
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000251echo -n "iptables modules directory: "
252check_ipt_lib_dir
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000253
254echo -n "libc has setns: "
255check_setns