blob: 0bfedf9d748707b1563f48de8d4916c3db535d20 [file] [log] [blame]
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00001#! /bin/bash
2# This is not an autconf generated configure
3#
osdl.net!shemminger4b1bbd92004-08-09 16:35:28 +00004INCLUDE=${1:-"$PWD/include"}
Mike Frysingere4fc4ad2012-11-08 11:41:17 -05005: ${PKG_CONFIG:=pkg-config}
6echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +00007
Stephen Hemmingere557d1a2012-02-15 10:03:39 -08008# Make a temp directory in build tree.
9TMPDIR=$(mktemp -d config.XXXXXX)
Mathias Krausec2f7d6c2012-09-01 20:55:29 +020010trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080011
Andreas Henriksson14743a72010-01-01 23:20:30 +010012check_atm()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000013{
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080014cat >$TMPDIR/atmtest.c <<EOF
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000015#include <atm.h>
16int main(int argc, char **argv) {
17 struct atm_qos qos;
18 (void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
19 return 0;
20}
21EOF
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080022gcc -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000023if [ $? -eq 0 ]
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +000024then
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000025 echo "TC_CONFIG_ATM:=y" >>Config
osdl.net!shemmingerb9cb1c92004-07-30 22:27:50 +000026 echo yes
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +000027else
osdl.net!shemmingerb9cb1c92004-07-30 22:27:50 +000028 echo no
osdl.net!shemminger449bf1f2004-06-25 21:14:22 +000029fi
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080030rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000031}
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050032
Andreas Henriksson14743a72010-01-01 23:20:30 +010033check_xt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000034{
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010035#check if we have xtables from iptables >= 1.4.5.
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080036cat >$TMPDIR/ipttest.c <<EOF
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010037#include <xtables.h>
38#include <linux/netfilter.h>
39static struct xtables_globals test_globals = {
40 .option_offset = 0,
41 .program_name = "tc-ipt",
42 .program_version = XTABLES_VERSION,
43 .orig_opts = NULL,
44 .opts = NULL,
45 .exit_err = NULL,
46};
47
48int main(int argc, char **argv)
49{
50 xtables_init_all(&test_globals, NFPROTO_IPV4);
51 return 0;
52}
53
54EOF
55
Mike Frysingere4fc4ad2012-11-08 11:41:17 -050056if gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL $(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010057then
58 echo "TC_CONFIG_XT:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000059 echo "using xtables"
60fi
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080061rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000062}
63
Andreas Henriksson14743a72010-01-01 23:20:30 +010064check_xt_old()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000065{
66# bail if previous XT checks has already succeded.
67if grep TC_CONFIG_XT Config > /dev/null
68then
69 return
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010070fi
71
Gilles Espinasse4f69c632011-07-10 05:45:37 +000072#check if we dont need our internal header ..
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080073cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050074#include <xtables.h>
75char *lib_dir;
76unsigned int global_option_offset = 0;
77const char *program_version = XTABLES_VERSION;
78const char *program_name = "tc-ipt";
79struct afinfo afinfo = {
80 .libprefix = "libxt_",
81};
82
83void exit_error(enum exittype status, const char *msg, ...)
84{
85}
86
87int main(int argc, char **argv) {
88
89 return 0;
90}
91
92EOF
Stephen Hemmingere557d1a2012-02-15 10:03:39 -080093gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050094
95if [ $? -eq 0 ]
96then
Andreas Henriksson80d689d2009-12-02 16:11:21 +010097 echo "TC_CONFIG_XT_OLD:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000098 echo "using old xtables (no need for xt-internal.h)"
99fi
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800100rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000101}
102
Andreas Henriksson14743a72010-01-01 23:20:30 +0100103check_xt_old_internal_h()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000104{
105# bail if previous XT checks has already succeded.
106if grep TC_CONFIG_XT Config > /dev/null
107then
108 return
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500109fi
110
111#check if we need our own internal.h
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800112cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500113#include <xtables.h>
114#include "xt-internal.h"
115char *lib_dir;
116unsigned int global_option_offset = 0;
117const char *program_version = XTABLES_VERSION;
118const char *program_name = "tc-ipt";
119struct afinfo afinfo = {
120 .libprefix = "libxt_",
121};
122
123void exit_error(enum exittype status, const char *msg, ...)
124{
125}
126
127int main(int argc, char **argv) {
128
129 return 0;
130}
131
132EOF
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800133gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500134
135if [ $? -eq 0 ]
136then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000137 echo "using old xtables with xt-internal.h"
Andreas Henriksson80d689d2009-12-02 16:11:21 +0100138 echo "TC_CONFIG_XT_OLD_H:=y" >>Config
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500139fi
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800140rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000141}
142
Andreas Henriksson14743a72010-01-01 23:20:30 +0100143check_ipt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000144{
145 if ! grep TC_CONFIG_XT Config > /dev/null
146 then
147 echo "using iptables"
148 fi
149}
150
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000151check_ipt_lib_dir()
152{
Mike Frysingere4fc4ad2012-11-08 11:41:17 -0500153 IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
Li Weida7fbb22012-08-20 09:41:47 +0800154 if [ -n "$IPT_LIB_DIR" ]; then
155 echo $IPT_LIB_DIR
156 echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
157 return
158 fi
159
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000160 for dir in /lib /usr/lib /usr/local/lib
161 do
Dan McGee44e743e2011-07-15 08:52:24 +0000162 for file in $dir/{xtables,iptables}/lib*t_*so ; do
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000163 if [ -f $file ]; then
Dan McGee44e743e2011-07-15 08:52:24 +0000164 echo ${file%/*}
165 echo "IPT_LIB_DIR:=${file%/*}" >> Config
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000166 return
167 fi
168 done
169 done
170 echo "not found!"
171}
172
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000173check_setns()
174{
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800175cat >$TMPDIR/setnstest.c <<EOF
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000176#include <sched.h>
177int main(int argc, char **argv)
178{
179 (void)setns(0,0);
180 return 0;
181}
182EOF
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800183gcc -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000184if [ $? -eq 0 ]
185then
186 echo "IP_CONFIG_SETNS:=y" >>Config
187 echo "yes"
188else
189 echo "no"
190fi
Stephen Hemmingere557d1a2012-02-15 10:03:39 -0800191rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000192}
193
Florian Westphal81944112012-08-09 09:18:50 +0000194check_ipset()
195{
196cat >$TMPDIR/ipsettest.c <<EOF
197#include <linux/netfilter/ipset/ip_set.h>
198#ifndef IP_SET_INVALID
199#define IPSET_DIM_MAX 3
200typedef unsigned short ip_set_id_t;
201#endif
202#include <linux/netfilter/xt_set.h>
203
204struct xt_set_info info;
205#if IPSET_PROTOCOL == 6
206int main(void)
207{
208 return IPSET_MAXNAMELEN;
209}
210#else
211#error unknown ipset version
212#endif
213EOF
214
215if gcc -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
216then
217 echo "TC_CONFIG_IPSET:=y" >>Config
218 echo "yes"
219else
220 echo "no"
221fi
222rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
223}
224
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000225echo "# Generated config based on" $INCLUDE >Config
226
227echo "TC schedulers"
228
229echo -n " ATM "
230check_atm
231
232echo -n " IPT "
233check_xt
234check_xt_old
235check_xt_old_internal_h
236check_ipt
237
Florian Westphal81944112012-08-09 09:18:50 +0000238echo -n " IPSET "
239check_ipset
240
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000241echo -n "iptables modules directory: "
242check_ipt_lib_dir
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000243
244echo -n "libc has setns: "
245check_setns