Annotation of embedaddon/miniupnpd/genconfig.sh, revision 1.1.1.3.2.1
1.1 misho 1: #! /bin/sh
1.1.1.3.2.1! misho 2: # $Id: genconfig.sh,v 1.1.1.3 2013/07/22 00:32:35 misho Exp $
1.1 misho 3: # miniupnp daemon
4: # http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
1.1.1.3 misho 5: # (c) 2006-2012 Thomas Bernard
1.1 misho 6: # This software is subject to the conditions detailed in the
7: # LICENCE file provided within the distribution
8:
1.1.1.3 misho 9: for argv; do
10: case "$argv" in
11: --ipv6) IPV6=1 ;;
12: --igd2) IGD2=1 ;;
13: --strict) STRICT=1 ;;
14: --leasefile) LEASEFILE=1 ;;
15: --help|-h)
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"
21: exit 1
22: ;;
23: *)
24: echo "Option not recognized : $argv"
25: echo "use -h option to display help"
26: exit 1
27: ;;
28: esac
29: done
30:
1.1 misho 31: RM="rm -f"
32: CONFIGFILE="config.h"
1.1.1.3 misho 33: CONFIGMACRO="CONFIG_H_INCLUDED"
1.1 misho 34:
35: # version reported in XML descriptions
36: #UPNP_VERSION=20070827
37: UPNP_VERSION=`date +"%Y%m%d"`
38: # Facility to syslog
39: LOG_MINIUPNPD="LOG_DAEMON"
40:
41: # detecting the OS name and version
42: OS_NAME=`uname -s`
43: OS_VERSION=`uname -r`
44:
45: # pfSense special case
46: if [ -f /etc/platform ]; then
47: if [ `cat /etc/platform` = "pfSense" ]; then
48: OS_NAME=pfSense
49: OS_VERSION=`cat /etc/version`
50: fi
51: fi
52:
1.1.1.2 misho 53: # OpenWRT special case
54: if [ -f ./os.openwrt ]; then
55: OS_NAME=OpenWRT
56: OS_VERSION=$(cat ./os.openwrt)
57: fi
58:
1.1.1.3 misho 59: # AstLinux special case
60: if [ -f ./os.astlinux ]; then
61: OS_NAME=AstLinux
62: OS_VERSION=$(cat ./os.astlinux)
63: fi
64:
65: # Tomato USB special case
66: if [ -f ../shared/tomato_version ]; then
67: OS_NAME=Tomato
68: OS_VERSION="Tomato $(cat ../shared/tomato_version)"
69: fi
70:
1.1 misho 71: ${RM} ${CONFIGFILE}
72:
73: echo "/* MiniUPnP Project" >> ${CONFIGFILE}
74: echo " * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/" >> ${CONFIGFILE}
1.1.1.3 misho 75: echo " * (c) 2006-2012 Thomas Bernard" >> ${CONFIGFILE}
76: echo " * generated by $0 on `date`" >> ${CONFIGFILE}
77: echo " * using command line options $* */" >> ${CONFIGFILE}
1.1 misho 78: echo "#ifndef $CONFIGMACRO" >> ${CONFIGFILE}
79: echo "#define $CONFIGMACRO" >> ${CONFIGFILE}
80: echo "" >> ${CONFIGFILE}
81: echo "#include <inttypes.h>" >> ${CONFIGFILE}
82: echo "" >> ${CONFIGFILE}
1.1.1.2 misho 83: echo "#define MINIUPNPD_VERSION \"`cat VERSION`\"" >> ${CONFIGFILE}
84: echo "" >> ${CONFIGFILE}
1.1 misho 85: echo "#define UPNP_VERSION \"$UPNP_VERSION\"" >> ${CONFIGFILE}
86:
87: # OS Specific stuff
88: case $OS_NAME in
89: OpenBSD)
90: MAJORVER=`echo $OS_VERSION | cut -d. -f1`
91: MINORVER=`echo $OS_VERSION | cut -d. -f2`
92: #echo "OpenBSD majorversion=$MAJORVER minorversion=$MINORVER"
93: # rtableid was introduced in OpenBSD 4.0
94: if [ $MAJORVER -ge 4 ]; then
95: echo "#define PFRULE_HAS_RTABLEID" >> ${CONFIGFILE}
96: fi
97: # from the 3.8 version, packets and bytes counters are double : in/out
98: if [ \( $MAJORVER -ge 4 \) -o \( $MAJORVER -eq 3 -a $MINORVER -ge 8 \) ]; then
99: echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
100: fi
101: # from the 4.7 version, new pf
102: if [ \( $MAJORVER -ge 5 \) -o \( $MAJORVER -eq 4 -a $MINORVER -ge 7 \) ]; then
103: echo "#define PF_NEWSTYLE" >> ${CONFIGFILE}
104: fi
1.1.1.3 misho 105: # onrdomain was introduced in OpenBSD 5.0
106: if [ $MAJORVER -ge 5 ]; then
107: echo "#define PFRULE_HAS_ONRDOMAIN" >> ${CONFIGFILE}
108: fi
1.1 misho 109: FW=pf
1.1.1.2 misho 110: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 111: OS_URL=http://www.openbsd.org/
112: ;;
113: FreeBSD)
114: VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'`
115: if [ $VER -ge 700049 ]; then
116: echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE}
117: fi
118: # new way to see which one to use PF or IPF.
119: # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957
1.1.1.3 misho 120: if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
1.1.1.2 misho 121: # source file with handy subroutines like checkyesno
122: . /etc/rc.subr
123: # source config file so we can probe vars
124: . /etc/rc.conf
125: if checkyesno ipfilter_enable; then
126: echo "Using ipf"
1.1.1.3 misho 127: FW=ipf
1.1.1.2 misho 128: elif checkyesno pf_enable; then
129: echo "Using pf"
130: FW=pf
1.1.1.3 misho 131: elif checkyesno firewall_enable; then
132: echo "Using ifpw"
133: FW=ipfw
1.1.1.2 misho 134: fi
1.1.1.3 misho 135: fi
136: if [ -z $FW ] ; then
137: echo "Could not detect usage of ipf, pf, ipfw. Compiling for pf by default"
1.1 misho 138: FW=pf
139: fi
1.1.1.2 misho 140: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 141: OS_URL=http://www.freebsd.org/
142: ;;
143: pfSense)
144: # we need to detect if PFRULE_INOUT_COUNTS macro is needed
145: FW=pf
1.1.1.2 misho 146: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 147: OS_URL=http://www.pfsense.com/
148: ;;
149: NetBSD)
1.1.1.3 misho 150: if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
151: # source file with handy subroutines like checkyesno
152: . /etc/rc.subr
153: # source config file so we can probe vars
154: . /etc/rc.conf
155: if checkyesno pf; then
156: FW=pf
157: elif checkyesno ipfilter; then
158: FW=ipf
159: fi
160: fi
161: if [ -z $FW ] ; then
1.1 misho 162: echo "Could not detect ipf nor pf, defaulting to pf."
163: FW=pf
164: fi
1.1.1.2 misho 165: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 166: OS_URL=http://www.netbsd.org/
167: ;;
168: DragonFly)
1.1.1.3 misho 169: if [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then
170: # source file with handy subroutines like checkyesno
171: . /etc/rc.subr
172: # source config file so we can probe vars
173: . /etc/rc.conf
174: if checkyesno pf; then
175: FW=pf
176: elif checkyesno ipfilter; then
177: FW=ipf
178: fi
179: fi
180: if [ -z $FW ] ; then
1.1 misho 181: echo "Could not detect ipf nor pf, defaulting to pf."
182: FW=pf
183: fi
1.1.1.2 misho 184: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 185: OS_URL=http://www.dragonflybsd.org/
186: ;;
187: SunOS)
1.1.1.2 misho 188: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 189: FW=ipf
190: echo "#define LOG_PERROR 0" >> ${CONFIGFILE}
191: echo "#define SOLARIS_KSTATS 1" >> ${CONFIGFILE}
1.1.1.3 misho 192: # solaris 10 does not define u_int64_t ?
193: # but it does define uint64_t
194: echo "typedef uint64_t u_int64_t;" >> ${CONFIGFILE}
1.1 misho 195: OS_URL=http://www.sun.com/solaris/
196: ;;
197: Linux)
198: OS_URL=http://www.kernel.org/
199: KERNVERA=`echo $OS_VERSION | awk -F. '{print $1}'`
200: KERNVERB=`echo $OS_VERSION | awk -F. '{print $2}'`
201: KERNVERC=`echo $OS_VERSION | awk -F. '{print $3}'`
202: KERNVERD=`echo $OS_VERSION | awk -F. '{print $4}'`
203: #echo "$KERNVERA.$KERNVERB.$KERNVERC.$KERNVERD"
204: # Debian GNU/Linux special case
205: if [ -f /etc/debian_version ]; then
206: OS_NAME=Debian
207: OS_VERSION=`cat /etc/debian_version`
208: OS_URL=http://www.debian.org/
209: fi
1.1.1.2 misho 210: # same thing for Gentoo linux
211: if [ -f /etc/gentoo-release ]; then
212: OS_NAME=Gentoo
213: OS_VERSION=`cat /etc/gentoo-release`
214: OS_URL=http://www.gentoo.org/
215: fi
1.1 misho 216: # use lsb_release (Linux Standard Base) when available
217: LSB_RELEASE=`which lsb_release`
218: if [ 0 -eq $? ]; then
219: OS_NAME=`${LSB_RELEASE} -i -s`
220: OS_VERSION=`${LSB_RELEASE} -r -s`
221: case $OS_NAME in
222: Debian)
223: OS_URL=http://www.debian.org/
224: OS_VERSION=`${LSB_RELEASE} -c -s`
225: ;;
226: Ubuntu)
227: OS_URL=http://www.ubuntu.com/
228: OS_VERSION=`${LSB_RELEASE} -c -s`
229: ;;
1.1.1.2 misho 230: Gentoo)
231: OS_URL=http://www.gentoo.org/
232: ;;
1.1 misho 233: esac
234: fi
1.1.1.2 misho 235: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
236: FW=netfilter
237: ;;
238: OpenWRT)
239: OS_URL=http://www.openwrt.org/
240: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 241: FW=netfilter
242: ;;
1.1.1.3 misho 243: AstLinux)
244: OS_URL=http://www.astlinux.org/
245: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
246: FW=netfilter
247: ;;
248: Tomato)
249: OS_NAME=UPnP
250: OS_URL=http://tomatousb.org/
251: echo "" >> ${CONFIGFILE}
252: echo "#include <tomato_config.h>" >> ${CONFIGFILE}
253: echo "" >> ${CONFIGFILE}
254: echo "#ifdef LINUX26" >> ${CONFIGFILE}
255: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
256: echo "#endif" >> ${CONFIGFILE}
257: echo "#ifdef TCONFIG_IPV6" >> ${CONFIGFILE}
258: echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
259: echo "#endif" >> ${CONFIGFILE}
260: FW=netfilter
261: ;;
1.1 misho 262: Darwin)
1.1.1.2 misho 263: echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE}
1.1 misho 264: FW=ipfw
265: OS_URL=http://developer.apple.com/macosx
266: ;;
267: *)
268: echo "Unknown OS : $OS_NAME"
269: echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
270: exit 1
271: ;;
272: esac
273:
1.1.1.3 misho 274: case $FW in
275: pf)
276: echo "#define USE_PF 1" >> ${CONFIGFILE}
277: ;;
278: ipf)
279: echo "#define USE_IPF 1" >> ${CONFIGFILE}
280: ;;
281: ipfw)
282: echo "#define USE_IPFW 1" >> ${CONFIGFILE}
283: ;;
284: netfilter)
285: echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
286: ;;
287: *)
288: echo "Unknown Firewall/packet filtering software [$FW]"
289: echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/."
290: exit 1
291: ;;
292: esac
293:
1.1 misho 294: echo "Configuring compilation for [$OS_NAME] [$OS_VERSION] with [$FW] firewall software."
295: echo "Please edit config.h for more compilation options."
296:
1.1.1.2 misho 297: # define SUPPORT_REMOTEHOST if the FW related code really supports setting
298: # a RemoteHost
299: if [ \( "$FW" = "netfilter" \) -o \( "$FW" = "pf" \) -o \( "$FW" = "ipfw" \) ] ; then
300: echo "#define SUPPORT_REMOTEHOST" >> ${CONFIGFILE}
301: fi
302:
303: echo "" >> ${CONFIGFILE}
1.1 misho 304: echo "#define OS_NAME \"$OS_NAME\"" >> ${CONFIGFILE}
305: echo "#define OS_VERSION \"$OS_NAME/$OS_VERSION\"" >> ${CONFIGFILE}
306: echo "#define OS_URL \"${OS_URL}\"" >> ${CONFIGFILE}
307: echo "" >> ${CONFIGFILE}
308:
309: echo "/* syslog facility to be used by miniupnpd */" >> ${CONFIGFILE}
310: echo "#define LOG_MINIUPNPD ${LOG_MINIUPNPD}" >> ${CONFIGFILE}
311: echo "" >> ${CONFIGFILE}
312:
313: echo "/* Uncomment the following line to allow miniupnpd to be" >> ${CONFIGFILE}
314: echo " * controlled by miniupnpdctl */" >> ${CONFIGFILE}
315: echo "/*#define USE_MINIUPNPDCTL*/" >> ${CONFIGFILE}
316: echo "" >> ${CONFIGFILE}
317:
318: echo "/* Comment the following line to disable NAT-PMP operations */" >> ${CONFIGFILE}
319: echo "#define ENABLE_NATPMP" >> ${CONFIGFILE}
320: echo "" >> ${CONFIGFILE}
321:
322: echo "/* Uncomment the following line to enable generation of" >> ${CONFIGFILE}
323: echo " * filter rules with pf */" >> ${CONFIGFILE}
1.1.1.3.2.1! misho 324: echo "#define PF_ENABLE_FILTER_RULES">> ${CONFIGFILE}
1.1 misho 325: echo "" >> ${CONFIGFILE}
326:
327: echo "/* Uncomment the following line to enable caching of results of" >> ${CONFIGFILE}
328: echo " * the getifstats() function */" >> ${CONFIGFILE}
329: echo "/*#define ENABLE_GETIFSTATS_CACHING*/" >> ${CONFIGFILE}
330: echo "/* The cache duration is indicated in seconds */" >> ${CONFIGFILE}
331: echo "#define GETIFSTATS_CACHING_DURATION 2" >> ${CONFIGFILE}
332: echo "" >> ${CONFIGFILE}
333:
334: echo "/* Uncomment the following line to enable multiple external ip support */" >> ${CONFIGFILE}
335: echo "/* note : That is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */" >> ${CONFIGFILE}
336: echo "/* Dynamic external ip adresses are not supported when this option is enabled." >> ${CONFIGFILE}
337: echo " * Also note that you would need to configure your .conf file accordingly. */" >> ${CONFIGFILE}
338: echo "/*#define MULTIPLE_EXTERNAL_IP*/" >> ${CONFIGFILE}
339: echo "" >> ${CONFIGFILE}
340:
341: echo "/* Comment the following line to use home made daemonize() func instead" >> ${CONFIGFILE}
342: echo " * of BSD daemon() */" >> ${CONFIGFILE}
343: echo "#define USE_DAEMON" >> ${CONFIGFILE}
344: echo "" >> ${CONFIGFILE}
345:
346: echo "/* Uncomment the following line to enable lease file support */" >> ${CONFIGFILE}
1.1.1.3 misho 347: if [ -n "$LEASEFILE" ] ; then
348: echo "#define ENABLE_LEASEFILE" >> ${CONFIGFILE}
349: else
350: echo "/*#define ENABLE_LEASEFILE*/" >> ${CONFIGFILE}
351: fi
1.1 misho 352: echo "" >> ${CONFIGFILE}
353:
354: echo "/* Define one or none of the two following macros in order to make some" >> ${CONFIGFILE}
355: echo " * clients happy. It will change the XML Root Description of the IGD." >> ${CONFIGFILE}
356: echo " * Enabling the Layer3Forwarding Service seems to be the more compatible" >> ${CONFIGFILE}
357: echo " * option. */" >> ${CONFIGFILE}
358: echo "/*#define HAS_DUMMY_SERVICE*/" >> ${CONFIGFILE}
359: echo "#define ENABLE_L3F_SERVICE" >> ${CONFIGFILE}
360: echo "" >> ${CONFIGFILE}
361:
1.1.1.2 misho 362: echo "/* Enable IP v6 support */" >> ${CONFIGFILE}
1.1.1.3 misho 363: if [ -n "$IPV6" ]; then
364: echo "#define ENABLE_IPV6" >> ${CONFIGFILE}
365: else
366: echo "/*#define ENABLE_IPV6*/" >> ${CONFIGFILE}
367: fi
1.1.1.2 misho 368: echo "" >> ${CONFIGFILE}
369:
370: echo "/* Enable the support of IGD v2 specification." >> ${CONFIGFILE}
371: echo " * This is not fully tested yet and can cause incompatibilities with some" >> ${CONFIGFILE}
372: echo " * control points, so enable with care. */" >> ${CONFIGFILE}
1.1.1.3 misho 373: if [ -n "$IGD2" ]; then
374: echo "#define IGD_V2" >> ${CONFIGFILE}
375: else
376: echo "/*#define IGD_V2*/" >> ${CONFIGFILE}
377: fi
1.1.1.2 misho 378: echo "" >> ${CONFIGFILE}
379:
380: echo "#ifdef IGD_V2" >> ${CONFIGFILE}
381: echo "/* Enable DeviceProtection service (IGDv2) */" >> ${CONFIGFILE}
382: echo "#define ENABLE_DP_SERVICE" >> ${CONFIGFILE}
383: echo "" >> ${CONFIGFILE}
384: echo "/* Enable WANIPv6FirewallControl service (IGDv2). needs IPv6 */" >> ${CONFIGFILE}
385: echo "#ifdef ENABLE_IPV6" >> ${CONFIGFILE}
386: echo "#define ENABLE_6FC_SERVICE" >> ${CONFIGFILE}
387: echo "#endif /* ENABLE_IPV6 */" >> ${CONFIGFILE}
388: echo "#endif /* IGD_V2 */" >> ${CONFIGFILE}
389: echo "" >> ${CONFIGFILE}
390:
391: echo "/* UPnP Events support. Working well enough to be enabled by default." >> ${CONFIGFILE}
392: echo " * It can be disabled to save a few bytes. */" >> ${CONFIGFILE}
393: echo "#define ENABLE_EVENTS" >> ${CONFIGFILE}
1.1 misho 394: echo "" >> ${CONFIGFILE}
395:
396: echo "/* include interface name in pf and ipf rules */" >> ${CONFIGFILE}
397: echo "#define USE_IFNAME_IN_RULES" >> ${CONFIGFILE}
398: echo "" >> ${CONFIGFILE}
399:
400: echo "/* Experimental NFQUEUE support. */" >> ${CONFIGFILE}
401: echo "/*#define ENABLE_NFQUEUE*/" >> ${CONFIGFILE}
402: echo "" >> ${CONFIGFILE}
403:
1.1.1.2 misho 404: echo "/* Enable to make MiniUPnPd more strict about UPnP conformance" >> ${CONFIGFILE}
405: echo " * and the messages it receives from control points */" >> ${CONFIGFILE}
1.1.1.3 misho 406: if [ -n "$STRICT" ] ; then
407: echo "#define UPNP_STRICT" >> ${CONFIGFILE}
408: else
409: echo "/*#define UPNP_STRICT*/" >> ${CONFIGFILE}
410: fi
411: echo "" >> ${CONFIGFILE}
412:
413: echo "/* Add the optional Date: header in all HTTP responses */" >> ${CONFIGFILE}
414: if [ -n "$STRICT" ] ; then
415: echo "#define ENABLE_HTTP_DATE" >> ${CONFIGFILE}
416: else
417: echo "/*#define ENABLE_HTTP_DATE*/" >> ${CONFIGFILE}
418: fi
419: echo "" >> ${CONFIGFILE}
420:
421: echo "/* disable reading and parsing of config file (miniupnpd.conf) */" >> ${CONFIGFILE}
422: echo "/*#define DISABLE_CONFIG_FILE*/" >> ${CONFIGFILE}
1.1.1.2 misho 423: echo "" >> ${CONFIGFILE}
424:
1.1 misho 425: echo "#endif" >> ${CONFIGFILE}
426:
427: exit 0
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>