2 # $Id: genconfig.sh,v 1.61 2012/10/03 21:07:29 nanard Exp $
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
14 --leasefile) LEASEFILE
=1 ;;
16 echo "Usage : $0 [options]"
17 echo " --ipv6 enable IPv6"
18 echo " --igd2 build an IGDv2 instead of an IGDv1"
19 echo " --strict be more strict regarding compliance with UPnP specifications"
20 echo " --leasefile enable lease file"
24 echo "Option not recognized : $argv"
25 echo "use -h option to display help"
33 CONFIGMACRO
="CONFIG_H_INCLUDED"
35 # version reported in XML descriptions
36 #UPNP_VERSION=20070827
37 UPNP_VERSION
=`date +"%Y%m%d"`
39 LOG_MINIUPNPD
="LOG_DAEMON"
41 # detecting the OS name and version
45 # pfSense special case
46 if [ -f /etc
/platform
]; then
47 if [ `cat /etc/platform` = "pfSense" ]; then
49 OS_VERSION
=`cat /etc/version`
53 # OpenWRT special case
54 if [ -f .
/os.openwrt
]; then
56 OS_VERSION
=$
(cat .
/os.openwrt
)
59 # Tomato USB special case
60 if [ -f ..
/shared
/tomato_version
]; then
62 OS_VERSION
="Tomato $(cat ../shared/tomato_version)"
65 # AstLinux special case
66 if [ -f .
/os.astlinux
]; then
68 OS_VERSION
=$
(cat .
/os.astlinux
)
71 # Tomato USB special case
72 if [ -f ..
/shared
/tomato_version
]; then
74 OS_VERSION
="Tomato $(cat ../shared/tomato_version)"
79 echo "/* MiniUPnP Project" >> ${CONFIGFILE}
80 echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
81 echo " * (c) 2006-2012 Thomas Bernard" >> ${CONFIGFILE}
82 echo " * generated by $0 on `date`" >> ${CONFIGFILE}
83 echo " * using command line options $* */" >> ${CONFIGFILE}
84 echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
85 echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
86 echo "" >> ${CONFIGFILE}
87 echo "#include <inttypes.h>" >> ${CONFIGFILE}
88 echo "" >> ${CONFIGFILE}
89 echo "#define MINIUPNPD_VERSION \"`cat VERSION`\"" >> ${CONFIGFILE}
90 echo "" >> ${CONFIGFILE}
91 echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
96 MAJORVER
=`echo $OS_VERSION | cut -d. -f1`
97 MINORVER
=`echo $OS_VERSION | cut -d. -f2`
98 #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
99 # rtableid was introduced in OpenBSD 4.0
100 if [ $MAJORVER -ge 4 ]; then
101 echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
103 # from the 3.8 version, packets and bytes counters are double : in/out
104 if [ \
( $MAJORVER -ge 4 \
) -o \
( $MAJORVER -eq 3 -a $MINORVER -ge 8 \
) ]; then
105 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
107 # from the 4.7 version, new pf
108 if [ \
( $MAJORVER -ge 5 \
) -o \
( $MAJORVER -eq 4 -a $MINORVER -ge 7 \
) ]; then
109 echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
111 # onrdomain was introduced in OpenBSD 5.0
112 if [ $MAJORVER -ge 5 ]; then
113 echo "#define PFRULE_HAS_ONRDOMAIN" >> ${CONFIGFILE}
116 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
117 OS_URL
=http
://www.openbsd.org
/
120 VER
=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
121 if [ $VER -ge 700049 ]; then
122 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
124 # new way to see which one to use PF or IPF.
125 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
126 if [ -f /etc
/rc.subr
] && [ -f /etc
/rc.conf
] ; then
127 # source file with handy subroutines like checkyesno
129 # source config file so we can probe vars
131 if checkyesno ipfilter_enable
; then
134 elif checkyesno pf_enable
; then
137 elif checkyesno firewall_enable
; then
143 echo "Could not detect usage of ipf, pf, ipfw. Compiling for pf by default"
146 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
147 OS_URL
=http
://www.freebsd.org
/
150 # we need to detect if PFRULE_INOUT_COUNTS macro is needed
152 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
153 OS_URL
=http
://www.pfsense.com
/
156 if [ -f /etc
/rc.subr
] && [ -f /etc
/rc.conf
] ; then
157 # source file with handy subroutines like checkyesno
159 # source config file so we can probe vars
161 if checkyesno pf
; then
163 elif checkyesno ipfilter
; then
168 echo "Could not detect ipf nor pf, defaulting to pf."
171 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
172 OS_URL
=http
://www.netbsd.org
/
175 if [ -f /etc
/rc.subr
] && [ -f /etc
/rc.conf
] ; then
176 # source file with handy subroutines like checkyesno
178 # source config file so we can probe vars
180 if checkyesno pf
; then
182 elif checkyesno ipfilter
; then
187 echo "Could not detect ipf nor pf, defaulting to pf."
190 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
191 OS_URL
=http
://www.dragonflybsd.org
/
194 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
196 echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
197 echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
198 # solaris 10 does not define u_int64_t ?
199 # but it does define uint64_t
200 echo "typedef uint64_t u_int64_t;" >> ${CONFIGFILE}
201 OS_URL
=http
://www.sun.com
/solaris
/
204 OS_URL
=http
://www.kernel.org
/
205 KERNVERA
=`echo $OS_VERSION | awk -F. '{print $1}'`
206 KERNVERB
=`echo $OS_VERSION | awk -F. '{print $2}'`
207 KERNVERC
=`echo $OS_VERSION | awk -F. '{print $3}'`
208 KERNVERD
=`echo $OS_VERSION | awk -F. '{print $4}'`
209 #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
210 # Debian GNU/Linux special case
211 if [ -f /etc
/debian_version
]; then
213 OS_VERSION
=`cat /etc/debian_version`
214 OS_URL
=http
://www.debian.org
/
216 # same thing for Gentoo linux
217 if [ -f /etc
/gentoo-release
]; then
219 OS_VERSION
=`cat /etc/gentoo-release`
220 OS_URL
=http
://www.gentoo.org
/
222 # use lsb_release (Linux Standard Base) when available
223 LSB_RELEASE
=`which lsb_release`
224 if [ 0 -eq $?
]; then
225 OS_NAME
=`${LSB_RELEASE} -i -s`
226 OS_VERSION
=`${LSB_RELEASE} -r -s`
229 OS_URL
=http
://www.debian.org
/
230 OS_VERSION
=`${LSB_RELEASE} -c -s`
233 OS_URL
=http
://www.ubuntu.com
/
234 OS_VERSION
=`${LSB_RELEASE} -c -s`
237 OS_URL
=http
://www.gentoo.org
/
241 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
245 OS_URL
=http
://www.openwrt.org
/
246 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
251 OS_URL
=http
://tomatousb.org
/
252 echo "" >> ${CONFIGFILE}
253 echo "#ifdef LINUX26" >> ${CONFIGFILE}
254 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
255 echo "#endif" >> ${CONFIGFILE}
256 echo "#ifdef TCONFIG_IPV6" >> ${CONFIGFILE}
257 echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
258 echo "#endif" >> ${CONFIGFILE}
262 echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
264 OS_URL
=http
://developer.apple.com
/macosx
267 echo "Unknown OS : $OS_NAME"
268 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
275 echo "#define USE_PF 1" >> ${CONFIGFILE}
278 echo "#define USE_IPF 1" >> ${CONFIGFILE}
281 echo "#define USE_IPFW 1" >> ${CONFIGFILE}
284 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
287 echo "Unknown Firewall/packet filtering software [$FW]"
288 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
293 echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
294 echo "Please edit config.h for more compilation options."
296 # define SUPPORT_REMOTEHOST if the FW related code really supports setting
298 if [ \
( "$FW" = "netfilter" \
) -o \
( "$FW" = "pf" \
) -o \
( "$FW" = "ipfw" \
) ] ; then
299 echo "#define SUPPORT_REMOTEHOST" >> ${CONFIGFILE}
302 echo "" >> ${CONFIGFILE}
303 echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
304 echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
305 echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
306 echo "" >> ${CONFIGFILE}
308 echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
309 echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
310 echo "" >> ${CONFIGFILE}
312 echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
313 echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
314 echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
315 echo "" >> ${CONFIGFILE}
317 echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
318 echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
319 echo "" >> ${CONFIGFILE}
321 echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
322 echo " * filter rules with pf */" >> ${CONFIGFILE}
323 echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
324 echo "" >> ${CONFIGFILE}
326 echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
327 echo " * the getifstats() function */" >> ${CONFIGFILE}
328 echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
329 echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
330 echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
331 echo "" >> ${CONFIGFILE}
333 echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
334 echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
335 echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
336 echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
337 echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
338 echo "" >> ${CONFIGFILE}
340 echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
341 echo " * of BSD daemon() */" >> ${CONFIGFILE}
342 echo "#define USE_DAEMON" >> ${CONFIGFILE}
343 echo "" >> ${CONFIGFILE}
345 echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
346 if [ -n "$LEASEFILE" ] ; then
347 echo "#define ENABLE_LEASEFILE" >> ${CONFIGFILE}
349 echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
351 echo "" >> ${CONFIGFILE}
353 echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
354 echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
355 echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
356 echo " * option. */" >> ${CONFIGFILE}
357 echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
358 echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
359 echo "" >> ${CONFIGFILE}
361 echo "/* Enable IP v6 support */" >> ${CONFIGFILE}
362 if [ -n "$IPV6" ]; then
363 echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
365 echo "/*#define ENABLE_IPV6*/" >> ${CONFIGFILE}
367 echo "" >> ${CONFIGFILE}
369 echo "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
370 echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
371 echo " * control points, so enable with care. */" >> ${CONFIGFILE}
372 if [ -n "$IGD2" ]; then
373 echo "#define IGD_V2" >> ${CONFIGFILE}
375 echo "/*#define IGD_V2*/" >> ${CONFIGFILE}
377 echo "" >> ${CONFIGFILE}
379 echo "#ifdef IGD_V2" >> ${CONFIGFILE}
380 echo "/* Enable DeviceProtection service (IGDv2) */" >> ${CONFIGFILE}
381 echo "#define ENABLE_DP_SERVICE" >> ${CONFIGFILE}
382 echo "" >> ${CONFIGFILE}
383 echo "/* Enable WANIPv6FirewallControl service (IGDv2). needs IPv6 */" >> ${CONFIGFILE}
384 echo "#ifdef ENABLE_IPV6" >> ${CONFIGFILE}
385 echo "#define ENABLE_6FC_SERVICE" >> ${CONFIGFILE}
386 echo "#endif /* ENABLE_IPV6 */" >> ${CONFIGFILE}
387 echo "#endif /* IGD_V2 */" >> ${CONFIGFILE}
388 echo "" >> ${CONFIGFILE}
390 echo "/* UPnP Events support. Working well enough to be enabled by default." >> ${CONFIGFILE}
391 echo " * It can be disabled to save a few bytes. */" >> ${CONFIGFILE}
392 echo "#define ENABLE_EVENTS" >> ${CONFIGFILE}
393 echo "" >> ${CONFIGFILE}
395 echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
396 echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
397 echo "" >> ${CONFIGFILE}
399 echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
400 echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
401 echo "" >> ${CONFIGFILE}
403 echo "/* Enable to make MiniUPnPd more strict about UPnP conformance" >> ${CONFIGFILE}
404 echo " * and the messages it receives from control points */" >> ${CONFIGFILE}
405 if [ -n "$STRICT" ] ; then
406 echo "#define UPNP_STRICT" >> ${CONFIGFILE}
408 echo "/*#define UPNP_STRICT*/" >> ${CONFIGFILE}
410 echo "" >> ${CONFIGFILE}
412 echo "/* Add the optional Date: header in all HTTP responses */" >> ${CONFIGFILE}
413 if [ -n "$STRICT" ] ; then
414 echo "#define ENABLE_HTTP_DATE" >> ${CONFIGFILE}
416 echo "/*#define ENABLE_HTTP_DATE*/" >> ${CONFIGFILE}
418 echo "" >> ${CONFIGFILE}
420 echo "/* disable reading and parsing of config file (miniupnpd.conf) */" >> ${CONFIGFILE}
421 echo "/*#define DISABLE_CONFIG_FILE*/" >> ${CONFIGFILE}
422 echo "" >> ${CONFIGFILE}
424 echo "#endif" >> ${CONFIGFILE}