Tomato 1.28
[tomato.git] / release / src / router / miniupnpd / genconfig.sh
blobd14edcece2fad364fd23e9494a39131d95f0abb8
1 #! /bin/sh
2 # $Id: genconfig.sh,v 1.34 2009/09/04 16:14:05 nanard Exp $
3 # miniupnp daemon
4 # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
5 # (c) 2006-2009 Thomas Bernard
6 # This software is subject to the conditions detailed in the
7 # LICENCE file provided within the distribution
9 RM="rm -f"
10 CONFIGFILE="config.h"
11 CONFIGMACRO="__CONFIG_H__"
13 # version reported in XML descriptions
14 #UPNP_VERSION=20070827
15 UPNP_VERSION=`date +"%Y%m%d"`
16 # Facility to syslog
17 LOG_MINIUPNPD="LOG_DAEMON"
19 # detecting the OS name and version
20 OS_NAME=`uname -s`
21 OS_VERSION=`uname -r`
23 # pfSense special case
24 if [ -f /etc/platform ]; then
25 if [ `cat /etc/platform` = "pfSense" ]; then
26 OS_NAME=pfSense
27 OS_VERSION=`cat /etc/version`
31 ${RM} ${CONFIGFILE}
33 echo "/* MiniUPnP Project" >> ${CONFIGFILE}
34 echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
35 echo " * (c) 2006-2009 Thomas Bernard" >> ${CONFIGFILE}
36 echo " * generated by $0 on `date` */" >> ${CONFIGFILE}
37 echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
38 echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
39 echo "" >> ${CONFIGFILE}
40 echo "#include <inttypes.h>" >> ${CONFIGFILE}
41 echo "" >> ${CONFIGFILE}
42 echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
44 # OS Specific stuff
45 case $OS_NAME in
46 OpenBSD)
47 MAJORVER=`echo $OS_VERSION | cut -d. -f1`
48 MINORVER=`echo $OS_VERSION | cut -d. -f2`
49 #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
50 # rtableid was introduced in OpenBSD 4.0
51 if [ $MAJORVER -ge 4 ]; then
52 echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
54 # from the 3.8 version, packets and bytes counters are double : in/out
55 if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
56 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
58 echo "#define USE_PF 1" >> ${CONFIGFILE}
59 FW=pf
60 OS_URL=http://www.openbsd.org/
62 FreeBSD)
63 VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
64 if [ $VER -ge 700049 ]; then
65 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
67 # new way to see which one to use PF or IPF.
68 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
69 # source file with handy subroutines like checkyesno
70 . /etc/rc.subr
71 # source config file so we can probe vars
72 . /etc/rc.conf
73 if checkyesno ipfilter_enable; then
74 echo "Using ipf"
75 FW=ipf
76 echo "#define USE_IPF 1" >> ${CONFIGFILE}
77 elif checkyesno pf_enable; then
78 echo "Using pf"
79 FW=pf
80 echo "#define USE_PF 1" >> ${CONFIGFILE}
81 # TODO : Add support for IPFW
82 # echo "#define USE_IPFW 1" >> ${CONFIGFILE}
83 # FW=ipfw
84 else
85 echo "Could not detect usage of ipf or pf. Compiling for pf by default"
86 FW=pf
87 echo "#define USE_PF 1" >> ${CONFIGFILE}
89 OS_URL=http://www.freebsd.org/
91 pfSense)
92 # we need to detect if PFRULE_INOUT_COUNTS macro is needed
93 echo "#define USE_PF 1" >> ${CONFIGFILE}
94 FW=pf
95 OS_URL=http://www.pfsense.com/
97 NetBSD)
98 # source file with handy subroutines like checkyesno
99 . /etc/rc.subr
100 # source config file so we can probe vars
101 . /etc/rc.conf
102 if checkyesno pf; then
103 echo "#define USE_PF 1" >> ${CONFIGFILE}
104 FW=pf
105 elif checkyesno ipfilter; then
106 echo "#define USE_IPF 1" >> ${CONFIGFILE}
107 FW=ipf
108 else
109 echo "Could not detect ipf nor pf, defaulting to pf."
110 echo "#define USE_PF 1" >> ${CONFIGFILE}
111 FW=pf
113 OS_URL=http://www.netbsd.org/
115 DragonFly)
116 echo "#define USE_PF 1" >> ${CONFIGFILE}
117 OS_URL=http://www.dragonflybsd.org/
118 FW=pf
120 SunOS)
121 echo "#define USE_IPF 1" >> ${CONFIGFILE}
122 FW=ipf
123 echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
124 echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
125 OS_URL=http://www.sun.com/solaris/
127 Linux)
128 OS_URL=http://www.kernel.org/
129 KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
130 KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
131 KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
132 KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
133 #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
134 # Debian GNU/Linux special case
135 if [ -f /etc/debian_version ]; then
136 OS_NAME=Debian
137 OS_VERSION=`cat /etc/debian_version`
138 OS_URL=http://www.debian.org/
140 # use lsb_release (Linux Standard Base) when available
141 LSB_RELEASE=`which lsb_release`
142 if [ 0 -eq $? ]; then
143 OS_NAME=`${LSB_RELEASE} -i -s`
144 OS_VERSION=`${LSB_RELEASE} -r -s`
145 case $OS_NAME in
146 Debian)
147 OS_URL=http://www.debian.org/
148 OS_VERSION=`${LSB_RELEASE} -c -s`
150 Ubuntu)
151 OS_URL=http://www.ubuntu.com/
152 OS_VERSION=`${LSB_RELEASE} -c -s`
154 esac
156 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
157 FW=netfilter
159 Darwin)
160 echo "#define USE_IPFW 1" >> ${CONFIGFILE}
161 FW=ipfw
162 OS_URL=http://developer.apple.com/macosx
165 echo "Unknown OS : $OS_NAME"
166 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
167 exit 1
169 esac
171 echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
172 echo "Please edit config.h for more compilation options."
174 echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
175 echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
176 echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
177 echo "" >> ${CONFIGFILE}
179 echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
180 echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
181 echo "" >> ${CONFIGFILE}
183 echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
184 echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
185 echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
186 echo "" >> ${CONFIGFILE}
188 echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
189 echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
190 echo "" >> ${CONFIGFILE}
192 echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
193 echo " * filter rules with pf */" >> ${CONFIGFILE}
194 echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
195 echo "" >> ${CONFIGFILE}
197 echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
198 echo " * the getifstats() function */" >> ${CONFIGFILE}
199 echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
200 echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
201 echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
202 echo "" >> ${CONFIGFILE}
204 echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
205 echo "/* note : Thas is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
206 echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
207 echo "" >> ${CONFIGFILE}
209 echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
210 echo " * of BSD daemon() */" >> ${CONFIGFILE}
211 echo "#define USE_DAEMON" >> ${CONFIGFILE}
212 echo "" >> ${CONFIGFILE}
214 echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
215 echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
216 echo "" >> ${CONFIGFILE}
218 echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
219 echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
220 echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
221 echo " * option. */" >> ${CONFIGFILE}
222 echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
223 echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
224 echo "" >> ${CONFIGFILE}
226 echo "/* Experimental UPnP Events support. */" >> ${CONFIGFILE}
227 echo "/*#define ENABLE_EVENTS*/" >> ${CONFIGFILE}
228 echo "" >> ${CONFIGFILE}
230 echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
231 echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
232 echo "" >> ${CONFIGFILE}
234 echo "#endif" >> ${CONFIGFILE}
236 exit 0