blob: da01c19b6afa37ea500b2cd45711985b18410b8e [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}
Stephen Hemmingerae7b9a02012-12-19 16:01:39 -080015 echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080016 echo "AR:=${AR}" >>Config
17 echo "CC:=${CC}" >>Config
Mike Frysinger601f60e2012-12-16 17:09:15 -050018}
19
Andreas Henriksson14743a72010-01-01 23:20:30 +010020check_atm()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000021{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080022 cat >$TMPDIR/atmtest.c <<EOF
osdl.net!shemmingerc830d772004-07-02 17:47:53 +000023#include <atm.h>
24int main(int argc, char **argv) {
25 struct atm_qos qos;
26 (void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
27 return 0;
28}
29EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080030
31 $CC -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1
32 if [ $? -eq 0 ]
33 then
34 echo "TC_CONFIG_ATM:=y" >>Config
35 echo yes
36 else
37 echo no
38 fi
39 rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000040}
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050041
Andreas Henriksson14743a72010-01-01 23:20:30 +010042check_xt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000043{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080044 #check if we have xtables from iptables >= 1.4.5.
45 cat >$TMPDIR/ipttest.c <<EOF
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010046#include <xtables.h>
47#include <linux/netfilter.h>
48static struct xtables_globals test_globals = {
49 .option_offset = 0,
50 .program_name = "tc-ipt",
51 .program_version = XTABLES_VERSION,
52 .orig_opts = NULL,
53 .opts = NULL,
54 .exit_err = NULL,
55};
56
57int main(int argc, char **argv)
58{
59 xtables_init_all(&test_globals, NFPROTO_IPV4);
60 return 0;
61}
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010062EOF
63
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080064 if $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL \
65 $(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1
66 then
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010067 echo "TC_CONFIG_XT:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000068 echo "using xtables"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080069 fi
70 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000071}
72
Andreas Henriksson14743a72010-01-01 23:20:30 +010073check_xt_old()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000074{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080075 # bail if previous XT checks has already succeded.
76 if grep -q TC_CONFIG_XT Config
77 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +000078 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080079 fi
Andreas Henrikssona36ceb82009-12-02 16:11:50 +010080
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -080081 #check if we dont need our internal header ..
82 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -050083#include <xtables.h>
84char *lib_dir;
85unsigned int global_option_offset = 0;
86const char *program_version = XTABLES_VERSION;
87const char *program_name = "tc-ipt";
88struct afinfo afinfo = {
89 .libprefix = "libxt_",
90};
91
92void exit_error(enum exittype status, const char *msg, ...)
93{
94}
95
96int main(int argc, char **argv) {
97
98 return 0;
99}
100
101EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500102
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800103 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
104 if [ $? -eq 0 ]
105 then
Andreas Henriksson80d689d2009-12-02 16:11:21 +0100106 echo "TC_CONFIG_XT_OLD:=y" >>Config
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000107 echo "using old xtables (no need for xt-internal.h)"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800108 fi
109 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000110}
111
Andreas Henriksson14743a72010-01-01 23:20:30 +0100112check_xt_old_internal_h()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000113{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800114 # bail if previous XT checks has already succeded.
115 if grep -q TC_CONFIG_XT Config
116 then
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000117 return
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800118 fi
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500119
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800120 #check if we need our own internal.h
121 cat >$TMPDIR/ipttest.c <<EOF
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500122#include <xtables.h>
123#include "xt-internal.h"
124char *lib_dir;
125unsigned int global_option_offset = 0;
126const char *program_version = XTABLES_VERSION;
127const char *program_name = "tc-ipt";
128struct afinfo afinfo = {
129 .libprefix = "libxt_",
130};
131
132void exit_error(enum exittype status, const char *msg, ...)
133{
134}
135
136int main(int argc, char **argv) {
137
138 return 0;
139}
140
141EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800142 $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
Jamal Hadi Salim63c7d262009-02-07 08:19:20 -0500143
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800144 if [ $? -eq 0 ]
145 then
146 echo "using old xtables with xt-internal.h"
147 echo "TC_CONFIG_XT_OLD_H:=y" >>Config
148 fi
149 rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000150}
151
Andreas Henriksson14743a72010-01-01 23:20:30 +0100152check_ipt()
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000153{
154 if ! grep TC_CONFIG_XT Config > /dev/null
155 then
156 echo "using iptables"
157 fi
158}
159
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000160check_ipt_lib_dir()
161{
Mike Frysingere4fc4ad2012-11-08 11:41:17 -0500162 IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
Li Weida7fbb22012-08-20 09:41:47 +0800163 if [ -n "$IPT_LIB_DIR" ]; then
164 echo $IPT_LIB_DIR
165 echo "IPT_LIB_DIR:=$IPT_LIB_DIR" >> Config
166 return
167 fi
168
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000169 for dir in /lib /usr/lib /usr/local/lib
170 do
Dan McGee44e743e2011-07-15 08:52:24 +0000171 for file in $dir/{xtables,iptables}/lib*t_*so ; do
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000172 if [ -f $file ]; then
Dan McGee44e743e2011-07-15 08:52:24 +0000173 echo ${file%/*}
174 echo "IPT_LIB_DIR:=${file%/*}" >> Config
Andreas Henriksson12ddfff2010-03-11 10:54:31 +0000175 return
176 fi
177 done
178 done
179 echo "not found!"
180}
181
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000182check_setns()
183{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800184 cat >$TMPDIR/setnstest.c <<EOF
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000185#include <sched.h>
186int main(int argc, char **argv)
187{
188 (void)setns(0,0);
189 return 0;
190}
191EOF
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800192 $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
193 if [ $? -eq 0 ]
194 then
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000195 echo "IP_CONFIG_SETNS:=y" >>Config
196 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800197 else
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000198 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800199 fi
200 rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
Eric W. Biederman2e8a07f2011-07-15 14:26:59 +0000201}
202
Florian Westphal81944112012-08-09 09:18:50 +0000203check_ipset()
204{
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800205 cat >$TMPDIR/ipsettest.c <<EOF
Florian Westphal81944112012-08-09 09:18:50 +0000206#include <linux/netfilter/ipset/ip_set.h>
207#ifndef IP_SET_INVALID
208#define IPSET_DIM_MAX 3
209typedef unsigned short ip_set_id_t;
210#endif
211#include <linux/netfilter/xt_set.h>
212
213struct xt_set_info info;
214#if IPSET_PROTOCOL == 6
215int main(void)
216{
217 return IPSET_MAXNAMELEN;
218}
219#else
220#error unknown ipset version
221#endif
222EOF
223
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800224 if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
225 then
Florian Westphal81944112012-08-09 09:18:50 +0000226 echo "TC_CONFIG_IPSET:=y" >>Config
227 echo "yes"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800228 else
Florian Westphal81944112012-08-09 09:18:50 +0000229 echo "no"
Stephen Hemminger07a6f5e2012-12-18 09:20:13 -0800230 fi
231 rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
Florian Westphal81944112012-08-09 09:18:50 +0000232}
233
Andreas Henrikssonf1a01252009-12-02 05:12:30 +0000234echo "# Generated config based on" $INCLUDE >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