1#! /bin/bash
2# This is not an autconf generated configure
3#
4INCLUDE=${1:-"$PWD/include"}
5
6# Make a temp directory in build tree.
7TMPDIR=$(mktemp -d config.XXXXXX)
8trap 'status=$?; rm -rf $TMPDIRa; exit $status' EXIT HUP INT QUIT TERM
9
10check_atm()
11{
12cat >$TMPDIR/atmtest.c <<EOF
13#include <atm.h>
14int main(int argc, char **argv) {
15	struct atm_qos qos;
16	(void) text2qos("aal5,ubr:sdu=9180,rx:none",&qos,0);
17	return 0;
18}
19EOF
20gcc -I$INCLUDE -o $TMPDIR/atmtest $TMPDIR/atmtest.c -latm >/dev/null 2>&1 
21if [ $? -eq 0 ]
22then
23    echo "TC_CONFIG_ATM:=y" >>Config
24    echo yes
25else
26    echo no
27fi
28rm -f $TMPDIR/atmtest.c $TMPDIR/atmtest
29}
30
31check_xt()
32{
33#check if we have xtables from iptables >= 1.4.5.
34cat >$TMPDIR/ipttest.c <<EOF
35#include <xtables.h>
36#include <linux/netfilter.h>
37static struct xtables_globals test_globals = {
38	.option_offset = 0,
39	.program_name = "tc-ipt",
40	.program_version = XTABLES_VERSION,
41	.orig_opts = NULL,
42	.opts = NULL,
43	.exit_err = NULL,
44};
45
46int main(int argc, char **argv)
47{
48	xtables_init_all(&test_globals, NFPROTO_IPV4);
49	return 0;
50}
51
52EOF
53
54if gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL $(pkg-config xtables --cflags --libs) -ldl >/dev/null 2>&1
55then
56	echo "TC_CONFIG_XT:=y" >>Config
57	echo "using xtables"
58fi
59rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
60}
61
62check_xt_old()
63{
64# bail if previous XT checks has already succeded.
65if grep TC_CONFIG_XT Config > /dev/null
66then
67	return
68fi
69
70#check if we dont need our internal header ..
71cat >$TMPDIR/ipttest.c <<EOF
72#include <xtables.h>
73char *lib_dir;
74unsigned int global_option_offset = 0;
75const char *program_version = XTABLES_VERSION;
76const char *program_name = "tc-ipt";
77struct afinfo afinfo = {
78	.libprefix      = "libxt_",
79};
80
81void exit_error(enum exittype status, const char *msg, ...)
82{
83}
84
85int main(int argc, char **argv) {
86
87	return 0;
88}
89
90EOF
91gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
92
93if [ $? -eq 0 ]
94then
95	echo "TC_CONFIG_XT_OLD:=y" >>Config
96	echo "using old xtables (no need for xt-internal.h)"
97fi
98rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
99}
100
101check_xt_old_internal_h()
102{
103# bail if previous XT checks has already succeded.
104if grep TC_CONFIG_XT Config > /dev/null
105then
106	return
107fi
108
109#check if we need our own internal.h
110cat >$TMPDIR/ipttest.c <<EOF
111#include <xtables.h>
112#include "xt-internal.h"
113char *lib_dir;
114unsigned int global_option_offset = 0;
115const char *program_version = XTABLES_VERSION;
116const char *program_name = "tc-ipt";
117struct afinfo afinfo = {
118	.libprefix      = "libxt_",
119};
120
121void exit_error(enum exittype status, const char *msg, ...)
122{
123}
124
125int main(int argc, char **argv) {
126
127	return 0;
128}
129
130EOF
131gcc -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
132
133if [ $? -eq 0 ]
134then
135	echo "using old xtables with xt-internal.h"
136	echo "TC_CONFIG_XT_OLD_H:=y" >>Config
137fi
138rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
139}
140
141check_ipt()
142{
143	if ! grep TC_CONFIG_XT Config > /dev/null
144	then
145		echo "using iptables"
146	fi
147}
148
149check_ipt_lib_dir()
150{
151	IPT_LIB_DIR=""
152	for dir in /lib /usr/lib /usr/local/lib
153	do
154		for file in $dir/{xtables,iptables}/lib*t_*so ; do
155			if [ -f $file ]; then
156				echo ${file%/*}
157				echo "IPT_LIB_DIR:=${file%/*}" >> Config
158				return
159			fi
160		done
161	done
162	echo "not found!"
163}
164
165check_setns()
166{
167cat >$TMPDIR/setnstest.c <<EOF
168#include <sched.h>
169int main(int argc, char **argv) 
170{
171	(void)setns(0,0);
172	return 0;
173}
174EOF
175gcc -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
176if [ $? -eq 0 ]
177then
178	echo "IP_CONFIG_SETNS:=y" >>Config
179	echo "yes"
180else
181	echo "no"
182fi
183rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
184}
185
186echo "# Generated config based on" $INCLUDE >Config
187
188echo "TC schedulers"
189
190echo -n " ATM	"
191check_atm
192
193echo -n " IPT	"
194check_xt
195check_xt_old
196check_xt_old_internal_h
197check_ipt
198
199echo -n "iptables modules directory: "
200check_ipt_lib_dir
201
202echo -n "libc has setns: "
203check_setns
204