Miniupnpd ver 1.5 (20110309)
[tomato.git] / release / src / router / miniupnpd / genconfig.sh
blobd35009e9954819aceffe29492c8c57e55cc13ed9
1 #! /bin/sh
2 # $Id: genconfig.sh,v 1.41 2011/03/09 15:09:07 nanard Exp $
3 # miniupnp daemon
4 # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
5 # (c) 2006-2011 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 # OpenWRT special case
32 if [ -f ./os.openwrt ]; then
33 OS_NAME=OpenWRT
34 OS_VERSION=$(cat ./os.openwrt)
37 ${RM} ${CONFIGFILE}
39 echo "/* MiniUPnP Project" >> ${CONFIGFILE}
40 echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
41 echo " * (c) 2006-2011 Thomas Bernard" >> ${CONFIGFILE}
42 echo " * generated by $0 on `date` */" >> ${CONFIGFILE}
43 echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
44 echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
45 echo "" >> ${CONFIGFILE}
46 echo "#include <inttypes.h>" >> ${CONFIGFILE}
47 echo "" >> ${CONFIGFILE}
48 echo "#define MINIUPNPD_VERSION \"`cat VERSION`\"" >> ${CONFIGFILE}
49 echo "" >> ${CONFIGFILE}
50 echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
52 # OS Specific stuff
53 case $OS_NAME in
54 OpenBSD)
55 MAJORVER=`echo $OS_VERSION | cut -d. -f1`
56 MINORVER=`echo $OS_VERSION | cut -d. -f2`
57 #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
58 # rtableid was introduced in OpenBSD 4.0
59 if [ $MAJORVER -ge 4 ]; then
60 echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
62 # from the 3.8 version, packets and bytes counters are double : in/out
63 if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
64 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
66 # from the 4.7 version, new pf
67 if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
68 echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
70 echo "#define USE_PF 1" >> ${CONFIGFILE}
71 FW=pf
72 OS_URL=http://www.openbsd.org/
74 FreeBSD)
75 VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
76 if [ $VER -ge 700049 ]; then
77 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
79 # new way to see which one to use PF or IPF.
80 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
81 # source file with handy subroutines like checkyesno
82 . /etc/rc.subr
83 # source config file so we can probe vars
84 . /etc/rc.conf
85 if checkyesno ipfilter_enable; then
86 echo "Using ipf"
87 FW=ipf
88 echo "#define USE_IPF 1" >> ${CONFIGFILE}
89 elif checkyesno pf_enable; then
90 echo "Using pf"
91 FW=pf
92 echo "#define USE_PF 1" >> ${CONFIGFILE}
93 # TODO : Add support for IPFW
94 # echo "#define USE_IPFW 1" >> ${CONFIGFILE}
95 # FW=ipfw
96 else
97 echo "Could not detect usage of ipf or pf. Compiling for pf by default"
98 FW=pf
99 echo "#define USE_PF 1" >> ${CONFIGFILE}
101 OS_URL=http://www.freebsd.org/
103 pfSense)
104 # we need to detect if PFRULE_INOUT_COUNTS macro is needed
105 echo "#define USE_PF 1" >> ${CONFIGFILE}
106 FW=pf
107 OS_URL=http://www.pfsense.com/
109 NetBSD)
110 # source file with handy subroutines like checkyesno
111 . /etc/rc.subr
112 # source config file so we can probe vars
113 . /etc/rc.conf
114 if checkyesno pf; then
115 echo "#define USE_PF 1" >> ${CONFIGFILE}
116 FW=pf
117 elif checkyesno ipfilter; then
118 echo "#define USE_IPF 1" >> ${CONFIGFILE}
119 FW=ipf
120 else
121 echo "Could not detect ipf nor pf, defaulting to pf."
122 echo "#define USE_PF 1" >> ${CONFIGFILE}
123 FW=pf
125 OS_URL=http://www.netbsd.org/
127 DragonFly)
128 # source file with handy subroutines like checkyesno
129 . /etc/rc.subr
130 # source config file so we can probe vars
131 . /etc/rc.conf
132 if checkyesno pf; then
133 echo "#define USE_PF 1" >> ${CONFIGFILE}
134 FW=pf
135 elif checkyesno ipfilter; then
136 echo "#define USE_IPF 1" >> ${CONFIGFILE}
137 FW=ipf
138 else
139 echo "Could not detect ipf nor pf, defaulting to pf."
140 echo "#define USE_PF 1" >> ${CONFIGFILE}
141 FW=pf
143 echo "#define USE_PF 1" >> ${CONFIGFILE}
144 OS_URL=http://www.dragonflybsd.org/
146 SunOS)
147 echo "#define USE_IPF 1" >> ${CONFIGFILE}
148 FW=ipf
149 echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
150 echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
151 OS_URL=http://www.sun.com/solaris/
153 Linux)
154 OS_URL=http://www.kernel.org/
155 KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
156 KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
157 KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
158 KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
159 #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
160 # Debian GNU/Linux special case
161 if [ -f /etc/debian_version ]; then
162 OS_NAME=Debian
163 OS_VERSION=`cat /etc/debian_version`
164 OS_URL=http://www.debian.org/
166 # use lsb_release (Linux Standard Base) when available
167 LSB_RELEASE=`which lsb_release`
168 if [ 0 -eq $? ]; then
169 OS_NAME=`${LSB_RELEASE} -i -s`
170 OS_VERSION=`${LSB_RELEASE} -r -s`
171 case $OS_NAME in
172 Debian)
173 OS_URL=http://www.debian.org/
174 OS_VERSION=`${LSB_RELEASE} -c -s`
176 Ubuntu)
177 OS_URL=http://www.ubuntu.com/
178 OS_VERSION=`${LSB_RELEASE} -c -s`
180 esac
182 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
183 FW=netfilter
185 OpenWRT)
186 OS_URL=http://www.openwrt.org/
187 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
188 FW=netfilter
190 Darwin)
191 echo "#define USE_IPFW 1" >> ${CONFIGFILE}
192 FW=ipfw
193 OS_URL=http://developer.apple.com/macosx
196 echo "Unknown OS : $OS_NAME"
197 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
198 exit 1
200 esac
202 echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
203 echo "Please edit config.h for more compilation options."
205 echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
206 echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
207 echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
208 echo "" >> ${CONFIGFILE}
210 echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
211 echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
212 echo "" >> ${CONFIGFILE}
214 echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
215 echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
216 echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
217 echo "" >> ${CONFIGFILE}
219 echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
220 echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
221 echo "" >> ${CONFIGFILE}
223 echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
224 echo " * filter rules with pf */" >> ${CONFIGFILE}
225 echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
226 echo "" >> ${CONFIGFILE}
228 echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
229 echo " * the getifstats() function */" >> ${CONFIGFILE}
230 echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
231 echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
232 echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
233 echo "" >> ${CONFIGFILE}
235 echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
236 echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
237 echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
238 echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
239 echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
240 echo "" >> ${CONFIGFILE}
242 echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
243 echo " * of BSD daemon() */" >> ${CONFIGFILE}
244 echo "#define USE_DAEMON" >> ${CONFIGFILE}
245 echo "" >> ${CONFIGFILE}
247 echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
248 echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
249 echo "" >> ${CONFIGFILE}
251 echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
252 echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
253 echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
254 echo " * option. */" >> ${CONFIGFILE}
255 echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
256 echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
257 echo "" >> ${CONFIGFILE}
259 echo "/* Experimental UPnP Events support. */" >> ${CONFIGFILE}
260 echo "/*#define ENABLE_EVENTS*/" >> ${CONFIGFILE}
261 echo "" >> ${CONFIGFILE}
263 echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
264 echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
265 echo "" >> ${CONFIGFILE}
267 echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
268 echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
269 echo "" >> ${CONFIGFILE}
271 echo "#endif" >> ${CONFIGFILE}
273 exit 0