Tomato 1.25
[tomato.git] / release / src / router / miniupnpd / genconfig.sh
blob668aaf39660c2703e8377efc3b853b1a3a858a37
1 #! /bin/sh
2 # $Id: genconfig.sh,v 1.29 2008/10/01 11:19:38 nanard Exp $
3 # miniupnp daemon
4 # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
5 # (c) 2006-2008 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-2008 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 "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
42 # OS Specific stuff
43 case $OS_NAME in
44 OpenBSD)
45 MAJORVER=`echo $OS_VERSION | cut -d. -f1`
46 MINORVER=`echo $OS_VERSION | cut -d. -f2`
47 #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
48 # rtableid was introduced in OpenBSD 4.0
49 if [ $MAJORVER -ge 4 ]; then
50 echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
52 # from the 3.8 version, packets and bytes counters are double : in/out
53 if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
54 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
56 echo "#define USE_PF 1" >> ${CONFIGFILE}
57 FW=pf
58 OS_URL=http://www.openbsd.org/
60 FreeBSD)
61 VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
62 if [ $VER -ge 700049 ]; then
63 echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
65 #if [ -f /usr/include/net/pfvar.h ] ; then
66 # echo "#define USE_PF 1" >> ${CONFIGFILE}
67 #else
68 # echo "#define USE_IPF 1" >> ${CONFIGFILE}
69 #fi
70 # new way to see which one to use PF or IPF.
71 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
72 # source file with handy subroutines like checkyesno
73 . /etc/rc.subr
74 # source config file so we can probe vars
75 . /etc/rc.conf
76 if checkyesno ipfilter_enable; then
77 echo "Using ipf"
78 FW=ipf
79 echo "#define USE_IPF 1" >> ${CONFIGFILE}
80 elif checkyesno pf_enable; then
81 echo "Using pf"
82 FW=pf
83 echo "#define USE_PF 1" >> ${CONFIGFILE}
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 OS_URL=http://www.netbsd.org/
99 if [ -f /usr/include/net/pfvar.h ] ; then
100 echo "#define USE_PF 1" >> ${CONFIGFILE}
101 FW=pf
102 else
103 echo "#define USE_IPF 1" >> ${CONFIGFILE}
104 FW=ipf
107 SunOS)
108 echo "#define USE_IPF 1" >> ${CONFIGFILE}
109 FW=ipf
110 echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
111 echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
112 echo "typedef uint64_t u_int64_t;" >> ${CONFIGFILE}
113 echo "typedef uint32_t u_int32_t;" >> ${CONFIGFILE}
114 echo "typedef uint16_t u_int16_t;" >> ${CONFIGFILE}
115 echo "typedef uint8_t u_int8_t;" >> ${CONFIGFILE}
116 OS_URL=http://www.sun.com/solaris/
118 Linux)
119 OS_URL=http://www.kernel.org/
120 KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
121 KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
122 KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
123 KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
124 #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
125 # Debian GNU/Linux special case
126 if [ -f /etc/debian_version ]; then
127 OS_NAME=Debian
128 OS_VERSION=`cat /etc/debian_version`
129 OS_URL=http://www.debian.org/
131 # use lsb_release (Linux Standard Base) when available
132 LSB_RELEASE=`which lsb_release`
133 if [ 0 -eq $? ]; then
134 OS_NAME=`${LSB_RELEASE} -i -s`
135 OS_VERSION=`${LSB_RELEASE} -r -s`
136 case $OS_NAME in
137 Debian)
138 OS_URL=http://www.debian.org/
139 OS_VERSION=`${LSB_RELEASE} -c -s`
141 Ubuntu)
142 OS_URL=http://www.ubuntu.com/
143 OS_VERSION=`${LSB_RELEASE} -c -s`
145 esac
147 echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
148 FW=netfilter
151 echo "Unknown OS : $OS_NAME"
152 echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
153 exit 1
155 esac
157 echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
158 echo "Please edit config.h for more compilation options."
160 echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
161 echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
162 echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
163 echo "" >> ${CONFIGFILE}
165 echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
166 echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
167 echo "" >> ${CONFIGFILE}
169 echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
170 echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
171 echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
172 echo "" >> ${CONFIGFILE}
174 echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
175 echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
176 echo "" >> ${CONFIGFILE}
178 echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
179 echo " * filter rules with pf */" >> ${CONFIGFILE}
180 echo "/*#define PF_ENABLE_FILTER_RULES*/">> ${CONFIGFILE}
181 echo "" >> ${CONFIGFILE}
183 echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
184 echo " * the getifstats() function */" >> ${CONFIGFILE}
185 echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
186 echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
187 echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
188 echo "" >> ${CONFIGFILE}
190 echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
191 echo "/* note : Thas is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
192 echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
193 echo "" >> ${CONFIGFILE}
195 echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
196 echo " * of BSD daemon() */" >> ${CONFIGFILE}
197 echo "#define USE_DAEMON" >> ${CONFIGFILE}
198 echo "" >> ${CONFIGFILE}
200 echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
201 echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
202 echo "" >> ${CONFIGFILE}
204 echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
205 echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
206 echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
207 echo " * option. */" >> ${CONFIGFILE}
208 echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
209 echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
210 echo "" >> ${CONFIGFILE}
212 echo "/* Experimental UPnP Events support. */" >> ${CONFIGFILE}
213 echo "/*#define ENABLE_EVENTS*/" >> ${CONFIGFILE}
214 echo "" >> ${CONFIGFILE}
216 echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
217 echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
218 echo "" >> ${CONFIGFILE}
220 echo "#endif" >> ${CONFIGFILE}
222 exit 0