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