[armoring feature] apply the system hardening options.
[platform/upstream/iproute2.git] / configure
1 #! /bin/bash
2 # This is not an autoconf generated configure
3 #
4 INCLUDE=${1:-"$PWD/include"}
5
6 # Make a temp directory in build tree.
7 TMPDIR=$(mktemp -d config.XXXXXX)
8 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
9
10 check_toolchain()
11 {
12     : ${PKG_CONFIG:=pkg-config}
13     : ${AR=ar}
14     : ${CC=gcc}
15     echo "PKG_CONFIG:=${PKG_CONFIG}" >>Config
16     echo "AR:=${AR}" >>Config
17     echo "CC:=${CC}" >>Config
18 }
19
20 check_atm()
21 {
22     cat >$TMPDIR/atmtest.c <<EOF
23 #include <atm.h>
24 int 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 }
29 EOF
30
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
40 }
41
42 check_xt()
43 {
44     #check if we have xtables from iptables >= 1.4.5.
45     cat >$TMPDIR/ipttest.c <<EOF
46 #include <xtables.h>
47 #include <linux/netfilter.h>
48 static 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
57 int main(int argc, char **argv)
58 {
59         xtables_init_all(&test_globals, NFPROTO_IPV4);
60         return 0;
61 }
62 EOF
63
64     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
67         echo "TC_CONFIG_XT:=y" >>Config
68         echo "using xtables"
69     fi
70     rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
71 }
72
73 check_xt_old()
74 {
75     # bail if previous XT checks has already succeded.
76     if grep -q TC_CONFIG_XT Config
77     then
78         return
79     fi
80
81     #check if we dont need our internal header ..
82     cat >$TMPDIR/ipttest.c <<EOF
83 #include <xtables.h>
84 char *lib_dir;
85 unsigned int global_option_offset = 0;
86 const char *program_version = XTABLES_VERSION;
87 const char *program_name = "tc-ipt";
88 struct afinfo afinfo = {
89         .libprefix      = "libxt_",
90 };
91
92 void exit_error(enum exittype status, const char *msg, ...)
93 {
94 }
95
96 int main(int argc, char **argv) {
97
98         return 0;
99 }
100
101 EOF
102
103     $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
104     if [ $? -eq 0 ]
105     then
106         echo "TC_CONFIG_XT_OLD:=y" >>Config
107         echo "using old xtables (no need for xt-internal.h)"
108     fi
109     rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
110 }
111
112 check_xt_old_internal_h()
113 {
114     # bail if previous XT checks has already succeded.
115     if grep -q TC_CONFIG_XT Config
116     then
117         return
118     fi
119
120     #check if we need our own internal.h
121     cat >$TMPDIR/ipttest.c <<EOF
122 #include <xtables.h>
123 #include "xt-internal.h"
124 char *lib_dir;
125 unsigned int global_option_offset = 0;
126 const char *program_version = XTABLES_VERSION;
127 const char *program_name = "tc-ipt";
128 struct afinfo afinfo = {
129         .libprefix      = "libxt_",
130 };
131
132 void exit_error(enum exittype status, const char *msg, ...)
133 {
134 }
135
136 int main(int argc, char **argv) {
137
138         return 0;
139 }
140
141 EOF
142         $CC -I$INCLUDE $IPTC -o $TMPDIR/ipttest $TMPDIR/ipttest.c $IPTL -ldl >/dev/null 2>&1
143
144         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
150 }
151
152 check_ipt()
153 {
154         if ! grep TC_CONFIG_XT Config > /dev/null
155         then
156                 echo "using iptables"
157         fi
158 }
159
160 check_ipt_lib_dir()
161 {
162         IPT_LIB_DIR=$(${PKG_CONFIG} --variable=xtlibdir xtables)
163         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
169         for dir in /lib /usr/lib /usr/local/lib
170         do
171                 for file in $dir/{xtables,iptables}/lib*t_*so ; do
172                         if [ -f $file ]; then
173                                 echo ${file%/*}
174                                 echo "IPT_LIB_DIR:=${file%/*}" >> Config
175                                 return
176                         fi
177                 done
178         done
179         echo "not found!"
180 }
181
182 check_setns()
183 {
184     cat >$TMPDIR/setnstest.c <<EOF
185 #include <sched.h>
186 int main(int argc, char **argv) 
187 {
188         (void)setns(0,0);
189         return 0;
190 }
191 EOF
192     $CC -I$INCLUDE -o $TMPDIR/setnstest $TMPDIR/setnstest.c >/dev/null 2>&1
193     if [ $? -eq 0 ]
194     then
195         echo "IP_CONFIG_SETNS:=y" >>Config
196         echo "yes"
197     else
198         echo "no"
199     fi
200     rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
201 }
202
203 check_ipset()
204 {
205     cat >$TMPDIR/ipsettest.c <<EOF
206 #include <linux/netfilter/ipset/ip_set.h>
207 #ifndef IP_SET_INVALID
208 #define IPSET_DIM_MAX 3
209 typedef unsigned short ip_set_id_t;
210 #endif
211 #include <linux/netfilter/xt_set.h>
212
213 struct xt_set_info info;
214 #if IPSET_PROTOCOL == 6
215 int main(void)
216 {
217         return IPSET_MAXNAMELEN;
218 }
219 #else
220 #error unknown ipset version
221 #endif
222 EOF
223
224     if $CC -I$INCLUDE -o $TMPDIR/ipsettest $TMPDIR/ipsettest.c >/dev/null 2>&1
225     then
226         echo "TC_CONFIG_IPSET:=y" >>Config
227         echo "yes"
228     else
229         echo "no"
230     fi
231     rm -f $TMPDIR/ipsettest.c $TMPDIR/ipsettest
232 }
233
234 echo "# Generated config based on" $INCLUDE >Config
235 check_toolchain
236
237 echo "TC schedulers"
238
239 echo -n " ATM   "
240 check_atm
241
242 echo -n " IPT   "
243 check_xt
244 check_xt_old
245 check_xt_old_internal_h
246 check_ipt
247
248 echo -n " IPSET  "
249 check_ipset
250
251 echo -n "iptables modules directory: "
252 check_ipt_lib_dir
253
254 echo -n "libc has setns: "
255 check_setns