Miniupnpd v. 1.5 (20110618)
[tomato.git] / release / src / router / miniupnpd / genconfig.sh
bloba182bc4c7212d12bb4a267bf02a919caead00bcb
1 #! /bin/sh
2 # $Id: genconfig.sh,v 1.49 2011/06/04 16:20:31 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 # Tomato USB special case
38 if [ -f ../shared/tomato_version ]; then
39 OS_NAME=Tomato
40 OS_VERSION="Tomato $(cat ../shared/tomato_version)"
43 ${RM} ${CONFIGFILE}
45 echo "/* MiniUPnP Project" >> ${CONFIGFILE}
46 echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
47 echo " * (c) 2006-2011 Thomas Bernard" >> ${CONFIGFILE}
48 echo " * generated by $0 on `date` */" >> ${CONFIGFILE}
49 echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
50 echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
51 echo "" >> ${CONFIGFILE}
52 echo "#include <inttypes.h>" >> ${CONFIGFILE}
53 echo "" >> ${CONFIGFILE}
54 echo "#define MINIUPNPD_VERSION \"`cat VERSION`\"" >> ${CONFIGFILE}
55 echo "" >> ${CONFIGFILE}
56 echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
58 # OS Specific stuff
59 case $OS_NAME in
60 OpenBSD)
61 MAJORVER=`echo $OS_VERSION | cut -d. -f1`
62 MINORVER=`echo $OS_VERSION | cut -d. -f2`
63 #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
64 # rtableid was introduced in OpenBSD 4.0
65 if [ $MAJORVER -ge 4 ]; then
66 echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
68 # from the 3.8 version, packets and bytes counters are double : in/out
69 if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
70 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
72 # from the 4.7 version, new pf
73 if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
74 echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
76 echo "#define USE_PF 1" >> ${CONFIGFILE}
77 FW=pf
78 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
79 OS_URL=http://www.openbsd.org/
81 FreeBSD)
82 VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
83 if [ $VER -ge 700049 ]; then
84 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
86 # new way to see which one to use PF or IPF.
87 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
88 # source file with handy subroutines like checkyesno
89 . /etc/rc.subr
90 # source config file so we can probe vars
91 . /etc/rc.conf
92 if checkyesno ipfilter_enable; then
93 echo "Using ipf"
94 FW=ipf
95 echo "#define USE_IPF 1" >> ${CONFIGFILE}
96 elif checkyesno pf_enable; then
97 echo "Using pf"
98 FW=pf
99 echo "#define USE_PF 1" >> ${CONFIGFILE}
100 # TODO : Add support for IPFW
101 # echo "#define USE_IPFW 1" >> ${CONFIGFILE}
102 # FW=ipfw
103 else
104 echo "Could not detect usage of ipf or pf. Compiling for pf by default"
105 FW=pf
106 echo "#define USE_PF 1" >> ${CONFIGFILE}
108 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
109 OS_URL=http://www.freebsd.org/
111 pfSense)
112 # we need to detect if PFRULE_INOUT_COUNTS macro is needed
113 echo "#define USE_PF 1" >> ${CONFIGFILE}
114 FW=pf
115 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
116 OS_URL=http://www.pfsense.com/
118 NetBSD)
119 # source file with handy subroutines like checkyesno
120 . /etc/rc.subr
121 # source config file so we can probe vars
122 . /etc/rc.conf
123 if checkyesno pf; then
124 echo "#define USE_PF 1" >> ${CONFIGFILE}
125 FW=pf
126 elif checkyesno ipfilter; then
127 echo "#define USE_IPF 1" >> ${CONFIGFILE}
128 FW=ipf
129 else
130 echo "Could not detect ipf nor pf, defaulting to pf."
131 echo "#define USE_PF 1" >> ${CONFIGFILE}
132 FW=pf
134 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
135 OS_URL=http://www.netbsd.org/
137 DragonFly)
138 # source file with handy subroutines like checkyesno
139 . /etc/rc.subr
140 # source config file so we can probe vars
141 . /etc/rc.conf
142 if checkyesno pf; then
143 echo "#define USE_PF 1" >> ${CONFIGFILE}
144 FW=pf
145 elif checkyesno ipfilter; then
146 echo "#define USE_IPF 1" >> ${CONFIGFILE}
147 FW=ipf
148 else
149 echo "Could not detect ipf nor pf, defaulting to pf."
150 echo "#define USE_PF 1" >> ${CONFIGFILE}
151 FW=pf
153 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
154 OS_URL=http://www.dragonflybsd.org/
156 SunOS)
157 echo "#define USE_IPF 1" >> ${CONFIGFILE}
158 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
159 FW=ipf
160 echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
161 echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
162 OS_URL=http://www.sun.com/solaris/
164 Linux)
165 OS_URL=http://www.kernel.org/
166 KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
167 KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
168 KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
169 KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
170 #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
171 # Debian GNU/Linux special case
172 if [ -f /etc/debian_version ]; then
173 OS_NAME=Debian
174 OS_VERSION=`cat /etc/debian_version`
175 OS_URL=http://www.debian.org/
177 # same thing for Gentoo linux
178 if [ -f /etc/gentoo-release ]; then
179 OS_NAME=Gentoo
180 OS_VERSION=`cat /etc/gentoo-release`
181 OS_URL=http://www.gentoo.org/
183 # use lsb_release (Linux Standard Base) when available
184 LSB_RELEASE=`which lsb_release`
185 if [ 0 -eq $? ]; then
186 OS_NAME=`${LSB_RELEASE} -i -s`
187 OS_VERSION=`${LSB_RELEASE} -r -s`
188 case $OS_NAME in
189 Debian)
190 OS_URL=http://www.debian.org/
191 OS_VERSION=`${LSB_RELEASE} -c -s`
193 Ubuntu)
194 OS_URL=http://www.ubuntu.com/
195 OS_VERSION=`${LSB_RELEASE} -c -s`
197 Gentoo)
198 OS_URL=http://www.gentoo.org/
200 esac
202 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
203 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
204 FW=netfilter
206 OpenWRT)
207 OS_URL=http://www.openwrt.org/
208 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
209 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
210 FW=netfilter
212 Tomato)
213 OS_NAME=UPnP
214 OS_URL=http://tomatousb.org/
215 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
216 echo "" >> ${CONFIGFILE}
217 echo "#include <tomato_config.h>" >> ${CONFIGFILE}
218 echo "" >> ${CONFIGFILE}
219 echo "#ifdef LINUX26" >> ${CONFIGFILE}
220 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
221 echo "#endif" >> ${CONFIGFILE}
222 echo "#ifdef TCONFIG_IPV6" >> ${CONFIGFILE}
223 echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
224 echo "#endif" >> ${CONFIGFILE}
225 FW=netfilter
227 Darwin)
228 echo "#define USE_IPFW 1" >> ${CONFIGFILE}
229 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
230 FW=ipfw
231 OS_URL=http://developer.apple.com/macosx
234 echo "Unknown OS : $OS_NAME"
235 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
236 exit 1
238 esac
240 echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
241 echo "Please edit config.h for more compilation options."
243 # define SUPPORT_REMOTEHOST if the FW related code really supports setting
244 # a RemoteHost
245 if [ "$FW" = "netfilter" ] ; then
246 echo "#define SUPPORT_REMOTEHOST" >> ${CONFIGFILE}
249 echo "" >> ${CONFIGFILE}
250 echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
251 echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
252 echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
253 echo "" >> ${CONFIGFILE}
255 echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
256 echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
257 echo "" >> ${CONFIGFILE}
259 echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
260 echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
261 echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
262 echo "" >> ${CONFIGFILE}
264 echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
265 echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
266 echo "" >> ${CONFIGFILE}
268 echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
269 echo " * filter rules with pf */" >> ${CONFIGFILE}
270 echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
271 echo "" >> ${CONFIGFILE}
273 echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
274 echo " * the getifstats() function */" >> ${CONFIGFILE}
275 echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
276 echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
277 echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
278 echo "" >> ${CONFIGFILE}
280 echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
281 echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
282 echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
283 echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
284 echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
285 echo "" >> ${CONFIGFILE}
287 echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
288 echo " * of BSD daemon() */" >> ${CONFIGFILE}
289 echo "#define USE_DAEMON" >> ${CONFIGFILE}
290 echo "" >> ${CONFIGFILE}
292 echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
293 echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
294 echo "" >> ${CONFIGFILE}
296 echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
297 echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
298 echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
299 echo " * option. */" >> ${CONFIGFILE}
300 echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
301 echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
302 echo "" >> ${CONFIGFILE}
304 echo "/* Enable IP v6 support */" >> ${CONFIGFILE}
305 echo "/*#define ENABLE_IPV6*/" >> ${CONFIGFILE}
306 echo "" >> ${CONFIGFILE}
308 echo "/* Enable the support of IGD v2 specification */" >> ${CONFIGFILE}
309 echo "/*#define IGD_V2*/" >> ${CONFIGFILE}
310 echo "" >> ${CONFIGFILE}
312 echo "#ifdef IGD_V2" >> ${CONFIGFILE}
313 echo "/* Enable DeviceProtection service (IGDv2) */" >> ${CONFIGFILE}
314 echo "#define ENABLE_DP_SERVICE" >> ${CONFIGFILE}
315 echo "" >> ${CONFIGFILE}
316 echo "/* Enable WANIPv6FirewallControl service (IGDv2). needs IPv6 */" >> ${CONFIGFILE}
317 echo "#ifdef ENABLE_IPV6" >> ${CONFIGFILE}
318 echo "#define ENABLE_6FC_SERVICE" >> ${CONFIGFILE}
319 echo "#endif /* ENABLE_IPV6 */" >> ${CONFIGFILE}
320 echo "#endif /* IGD_V2 */" >> ${CONFIGFILE}
321 echo "" >> ${CONFIGFILE}
323 echo "/* UPnP Events support. Working well enough to be enabled by default." >> ${CONFIGFILE}
324 echo " * It can be disabled to save a few bytes. */" >> ${CONFIGFILE}
325 echo "#define ENABLE_EVENTS" >> ${CONFIGFILE}
326 echo "" >> ${CONFIGFILE}
328 echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
329 echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
330 echo "" >> ${CONFIGFILE}
332 echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
333 echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
334 echo "" >> ${CONFIGFILE}
336 echo "/* Enable to make MiniUPnPd more strict about UPnP conformance" >> ${CONFIGFILE}
337 echo " * and the messages it receive from control points */" >> ${CONFIGFILE}
338 echo "/*#define UPNP_STRICT*/" >> ${CONFIGFILE}
339 echo "" >> ${CONFIGFILE}
341 echo "#endif" >> ${CONFIGFILE}
343 exit 0