PageRenderTime 25ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src/router/miniupnpd/genconfig.sh

https://github.com/ReliefLabs/EasyTomato
Shell | 426 lines | 351 code | 36 blank | 39 comment | 36 complexity | bd21f5928b52c93541a81ddb9bf27d08 MD5 | raw file
  1. #! /bin/sh
  2. # $Id: genconfig.sh,v 1.61 2012/10/03 21:07:29 nanard Exp $
  3. # miniupnp daemon
  4. # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
  5. # (c) 2006-2012 Thomas Bernard
  6. # This software is subject to the conditions detailed in the
  7. # LICENCE file provided within the distribution
  8. for argv; do
  9. case "$argv" in
  10. --ipv6) IPV6=1 ;;
  11. --igd2) IGD2=1 ;;
  12. --strict) STRICT=1 ;;
  13. --leasefile) LEASEFILE=1 ;;
  14. --help|-h)
  15. echo "Usage : $0 [options]"
  16. echo " --ipv6 enable IPv6"
  17. echo " --igd2 build an IGDv2 instead of an IGDv1"
  18. echo " --strict be more strict regarding compliance with UPnP specifications"
  19. echo " --leasefile enable lease file"
  20. exit 1
  21. ;;
  22. *)
  23. echo "Option not recognized : $argv"
  24. echo "use -h option to display help"
  25. exit 1
  26. ;;
  27. esac
  28. done
  29. RM="rm -f"
  30. CONFIGFILE="config.h"
  31. CONFIGMACRO="CONFIG_H_INCLUDED"
  32. # version reported in XML descriptions
  33. #UPNP_VERSION=20070827
  34. UPNP_VERSION=`date +"%Y%m%d"`
  35. # Facility to syslog
  36. LOG_MINIUPNPD="LOG_DAEMON"
  37. # detecting the OS name and version
  38. OS_NAME=`uname -s`
  39. OS_VERSION=`uname -r`
  40. # pfSense special case
  41. if [ -f /etc/platform ]; then
  42. if [ `cat /etc/platform` = "pfSense" ]; then
  43. OS_NAME=pfSense
  44. OS_VERSION=`cat /etc/version`
  45. fi
  46. fi
  47. # OpenWRT special case
  48. if [ -f ./os.openwrt ]; then
  49. OS_NAME=OpenWRT
  50. OS_VERSION=$(cat ./os.openwrt)
  51. fi
  52. # Tomato USB special case
  53. if [ -f ../shared/tomato_version ]; then
  54. OS_NAME=Tomato
  55. OS_VERSION="Tomato $(cat ../shared/tomato_version)"
  56. fi
  57. # AstLinux special case
  58. if [ -f ./os.astlinux ]; then
  59. OS_NAME=AstLinux
  60. OS_VERSION=$(cat ./os.astlinux)
  61. fi
  62. # Tomato USB special case
  63. if [ -f ../shared/tomato_version ]; then
  64. OS_NAME=Tomato
  65. OS_VERSION="Tomato $(cat ../shared/tomato_version)"
  66. fi
  67. ${RM} ${CONFIGFILE}
  68. echo "/* MiniUPnP Project" >> ${CONFIGFILE}
  69. echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
  70. echo " * (c) 2006-2012 Thomas Bernard" >> ${CONFIGFILE}
  71. echo " * generated by $0 on `date`" >> ${CONFIGFILE}
  72. echo " * using command line options $* */" >> ${CONFIGFILE}
  73. echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
  74. echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
  75. echo "" >> ${CONFIGFILE}
  76. echo "#include <inttypes.h>" >> ${CONFIGFILE}
  77. echo "" >> ${CONFIGFILE}
  78. echo "#define MINIUPNPD_VERSION \"`cat VERSION`\"" >> ${CONFIGFILE}
  79. echo "" >> ${CONFIGFILE}
  80. echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
  81. # OS Specific stuff
  82. case $OS_NAME in
  83. OpenBSD)
  84. MAJORVER=`echo $OS_VERSION | cut -d. -f1`
  85. MINORVER=`echo $OS_VERSION | cut -d. -f2`
  86. #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
  87. # rtableid was introduced in OpenBSD 4.0
  88. if [ $MAJORVER -ge 4 ]; then
  89. echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
  90. fi
  91. # from the 3.8 version, packets and bytes counters are double : in/out
  92. if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
  93. echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
  94. fi
  95. # from the 4.7 version, new pf
  96. if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
  97. echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
  98. fi
  99. # onrdomain was introduced in OpenBSD 5.0
  100. if [ $MAJORVER -ge 5 ]; then
  101. echo "#define PFRULE_HAS_ONRDOMAIN" >> ${CONFIGFILE}
  102. fi
  103. FW=pf
  104. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  105. OS_URL=http://www.openbsd.org/
  106. ;;
  107. FreeBSD)
  108. VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
  109. if [ $VER -ge 700049 ]; then
  110. echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
  111. fi
  112. # new way to see which one to use PF or IPF.
  113. # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
  114. if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
  115. # source file with handy subroutines like checkyesno
  116. . /etc/rc.subr
  117. # source config file so we can probe vars
  118. . /etc/rc.conf
  119. if checkyesno ipfilter_enable; then
  120. echo "Using ipf"
  121. FW=ipf
  122. elif checkyesno pf_enable; then
  123. echo "Using pf"
  124. FW=pf
  125. elif checkyesno firewall_enable; then
  126. echo "Using ifpw"
  127. FW=ipfw
  128. fi
  129. fi
  130. if [ -z $FW ] ; then
  131. echo "Could not detect usage of ipf, pf, ipfw. Compiling for pf by default"
  132. FW=pf
  133. fi
  134. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  135. OS_URL=http://www.freebsd.org/
  136. ;;
  137. pfSense)
  138. # we need to detect if PFRULE_INOUT_COUNTS macro is needed
  139. FW=pf
  140. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  141. OS_URL=http://www.pfsense.com/
  142. ;;
  143. NetBSD)
  144. if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
  145. # source file with handy subroutines like checkyesno
  146. . /etc/rc.subr
  147. # source config file so we can probe vars
  148. . /etc/rc.conf
  149. if checkyesno pf; then
  150. FW=pf
  151. elif checkyesno ipfilter; then
  152. FW=ipf
  153. fi
  154. fi
  155. if [ -z $FW ] ; then
  156. echo "Could not detect ipf nor pf, defaulting to pf."
  157. FW=pf
  158. fi
  159. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  160. OS_URL=http://www.netbsd.org/
  161. ;;
  162. DragonFly)
  163. if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
  164. # source file with handy subroutines like checkyesno
  165. . /etc/rc.subr
  166. # source config file so we can probe vars
  167. . /etc/rc.conf
  168. if checkyesno pf; then
  169. FW=pf
  170. elif checkyesno ipfilter; then
  171. FW=ipf
  172. fi
  173. fi
  174. if [ -z $FW ] ; then
  175. echo "Could not detect ipf nor pf, defaulting to pf."
  176. FW=pf
  177. fi
  178. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  179. OS_URL=http://www.dragonflybsd.org/
  180. ;;
  181. SunOS)
  182. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  183. FW=ipf
  184. echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
  185. echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
  186. # solaris 10 does not define u_int64_t ?
  187. # but it does define uint64_t
  188. echo "typedef uint64_t u_int64_t;" >> ${CONFIGFILE}
  189. OS_URL=http://www.sun.com/solaris/
  190. ;;
  191. Linux)
  192. OS_URL=http://www.kernel.org/
  193. KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
  194. KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
  195. KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
  196. KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
  197. #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
  198. # Debian GNU/Linux special case
  199. if [ -f /etc/debian_version ]; then
  200. OS_NAME=Debian
  201. OS_VERSION=`cat /etc/debian_version`
  202. OS_URL=http://www.debian.org/
  203. fi
  204. # same thing for Gentoo linux
  205. if [ -f /etc/gentoo-release ]; then
  206. OS_NAME=Gentoo
  207. OS_VERSION=`cat /etc/gentoo-release`
  208. OS_URL=http://www.gentoo.org/
  209. fi
  210. # use lsb_release (Linux Standard Base) when available
  211. LSB_RELEASE=`which lsb_release`
  212. if [ 0 -eq $? ]; then
  213. OS_NAME=`${LSB_RELEASE} -i -s`
  214. OS_VERSION=`${LSB_RELEASE} -r -s`
  215. case $OS_NAME in
  216. Debian)
  217. OS_URL=http://www.debian.org/
  218. OS_VERSION=`${LSB_RELEASE} -c -s`
  219. ;;
  220. Ubuntu)
  221. OS_URL=http://www.ubuntu.com/
  222. OS_VERSION=`${LSB_RELEASE} -c -s`
  223. ;;
  224. Gentoo)
  225. OS_URL=http://www.gentoo.org/
  226. ;;
  227. esac
  228. fi
  229. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  230. FW=netfilter
  231. ;;
  232. OpenWRT)
  233. OS_URL=http://www.openwrt.org/
  234. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  235. FW=netfilter
  236. ;;
  237. Tomato)
  238. OS_NAME=UPnP
  239. OS_URL=http://tomatousb.org/
  240. echo "" >> ${CONFIGFILE}
  241. echo "#ifdef LINUX26" >> ${CONFIGFILE}
  242. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  243. echo "#endif" >> ${CONFIGFILE}
  244. echo "#ifdef TCONFIG_IPV6" >> ${CONFIGFILE}
  245. echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
  246. echo "#endif" >> ${CONFIGFILE}
  247. FW=netfilter
  248. ;;
  249. Darwin)
  250. echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
  251. FW=ipfw
  252. OS_URL=http://developer.apple.com/macosx
  253. ;;
  254. *)
  255. echo "Unknown OS : $OS_NAME"
  256. echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
  257. exit 1
  258. ;;
  259. esac
  260. case $FW in
  261. pf)
  262. echo "#define USE_PF 1" >> ${CONFIGFILE}
  263. ;;
  264. ipf)
  265. echo "#define USE_IPF 1" >> ${CONFIGFILE}
  266. ;;
  267. ipfw)
  268. echo "#define USE_IPFW 1" >> ${CONFIGFILE}
  269. ;;
  270. netfilter)
  271. echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
  272. ;;
  273. *)
  274. echo "Unknown Firewall/packet filtering software [$FW]"
  275. echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
  276. exit 1
  277. ;;
  278. esac
  279. echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
  280. echo "Please edit config.h for more compilation options."
  281. # define SUPPORT_REMOTEHOST if the FW related code really supports setting
  282. # a RemoteHost
  283. if [ \( "$FW" = "netfilter" \) -o \( "$FW" = "pf" \) -o \( "$FW" = "ipfw" \) ] ; then
  284. echo "#define SUPPORT_REMOTEHOST" >> ${CONFIGFILE}
  285. fi
  286. echo "" >> ${CONFIGFILE}
  287. echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
  288. echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
  289. echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
  290. echo "" >> ${CONFIGFILE}
  291. echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
  292. echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
  293. echo "" >> ${CONFIGFILE}
  294. echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
  295. echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
  296. echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
  297. echo "" >> ${CONFIGFILE}
  298. echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
  299. echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
  300. echo "" >> ${CONFIGFILE}
  301. echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
  302. echo " * filter rules with pf */" >> ${CONFIGFILE}
  303. echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
  304. echo "" >> ${CONFIGFILE}
  305. echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
  306. echo " * the getifstats() function */" >> ${CONFIGFILE}
  307. echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
  308. echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
  309. echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
  310. echo "" >> ${CONFIGFILE}
  311. echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
  312. echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
  313. echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
  314. echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
  315. echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
  316. echo "" >> ${CONFIGFILE}
  317. echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
  318. echo " * of BSD daemon() */" >> ${CONFIGFILE}
  319. echo "#define USE_DAEMON" >> ${CONFIGFILE}
  320. echo "" >> ${CONFIGFILE}
  321. echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
  322. if [ -n "$LEASEFILE" ] ; then
  323. echo "#define ENABLE_LEASEFILE" >> ${CONFIGFILE}
  324. else
  325. echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
  326. fi
  327. echo "" >> ${CONFIGFILE}
  328. echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
  329. echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
  330. echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
  331. echo " * option. */" >> ${CONFIGFILE}
  332. echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
  333. echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
  334. echo "" >> ${CONFIGFILE}
  335. echo "/* Enable IP v6 support */" >> ${CONFIGFILE}
  336. if [ -n "$IPV6" ]; then
  337. echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
  338. else
  339. echo "/*#define ENABLE_IPV6*/" >> ${CONFIGFILE}
  340. fi
  341. echo "" >> ${CONFIGFILE}
  342. echo "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
  343. echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
  344. echo " * control points, so enable with care. */" >> ${CONFIGFILE}
  345. if [ -n "$IGD2" ]; then
  346. echo "#define IGD_V2" >> ${CONFIGFILE}
  347. else
  348. echo "/*#define IGD_V2*/" >> ${CONFIGFILE}
  349. fi
  350. echo "" >> ${CONFIGFILE}
  351. echo "#ifdef IGD_V2" >> ${CONFIGFILE}
  352. echo "/* Enable DeviceProtection service (IGDv2) */" >> ${CONFIGFILE}
  353. echo "#define ENABLE_DP_SERVICE" >> ${CONFIGFILE}
  354. echo "" >> ${CONFIGFILE}
  355. echo "/* Enable WANIPv6FirewallControl service (IGDv2). needs IPv6 */" >> ${CONFIGFILE}
  356. echo "#ifdef ENABLE_IPV6" >> ${CONFIGFILE}
  357. echo "#define ENABLE_6FC_SERVICE" >> ${CONFIGFILE}
  358. echo "#endif /* ENABLE_IPV6 */" >> ${CONFIGFILE}
  359. echo "#endif /* IGD_V2 */" >> ${CONFIGFILE}
  360. echo "" >> ${CONFIGFILE}
  361. echo "/* UPnP Events support. Working well enough to be enabled by default." >> ${CONFIGFILE}
  362. echo " * It can be disabled to save a few bytes. */" >> ${CONFIGFILE}
  363. echo "#define ENABLE_EVENTS" >> ${CONFIGFILE}
  364. echo "" >> ${CONFIGFILE}
  365. echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
  366. echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
  367. echo "" >> ${CONFIGFILE}
  368. echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
  369. echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
  370. echo "" >> ${CONFIGFILE}
  371. echo "/* Enable to make MiniUPnPd more strict about UPnP conformance" >> ${CONFIGFILE}
  372. echo " * and the messages it receives from control points */" >> ${CONFIGFILE}
  373. if [ -n "$STRICT" ] ; then
  374. echo "#define UPNP_STRICT" >> ${CONFIGFILE}
  375. else
  376. echo "/*#define UPNP_STRICT*/" >> ${CONFIGFILE}
  377. fi
  378. echo "" >> ${CONFIGFILE}
  379. echo "/* Add the optional Date: header in all HTTP responses */" >> ${CONFIGFILE}
  380. if [ -n "$STRICT" ] ; then
  381. echo "#define ENABLE_HTTP_DATE" >> ${CONFIGFILE}
  382. else
  383. echo "/*#define ENABLE_HTTP_DATE*/" >> ${CONFIGFILE}
  384. fi
  385. echo "" >> ${CONFIGFILE}
  386. echo "/* disable reading and parsing of config file (miniupnpd.conf) */" >> ${CONFIGFILE}
  387. echo "/*#define DISABLE_CONFIG_FILE*/" >> ${CONFIGFILE}
  388. echo "" >> ${CONFIGFILE}
  389. echo "#endif" >> ${CONFIGFILE}
  390. exit 0