From 047fe367dd764f4ddedcc617724da4359bea6f26 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Wed, 18 May 2022 09:55:52 +0200 Subject: [PATCH] miniupnpd: improve configure script for cross builds --- miniupnpd/Changelog.txt | 5 +- miniupnpd/configure | 178 +++++++++++++++++++++++++--------------- 2 files changed, 116 insertions(+), 67 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 6426606..647f5fc 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,4 +1,7 @@ -$Id: Changelog.txt,v 1.487 2022/02/19 22:45:06 nanard Exp $ +$Id: Changelog.txt,v 1.488 2022/05/18 07:50:46 nanard Exp $ + +2022/05/18: + improve configure script for cross builds 2022/02/19: prefer non-reserved over reserved addresses in getifaddr() diff --git a/miniupnpd/configure b/miniupnpd/configure index 4513e8d..b2dd583 100755 --- a/miniupnpd/configure +++ b/miniupnpd/configure @@ -1,5 +1,5 @@ #! /bin/sh -# $Id: configure,v 1.119 2022/02/19 21:44:50 nanard Exp $ +# $Id: configure,v 1.120 2022/05/18 07:50:48 nanard Exp $ # vim: tabstop=4 shiftwidth=4 noexpandtab # # miniupnp daemon @@ -17,6 +17,7 @@ UPNP_VERSION_MINOR=1 # IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER, # PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT, # PKG_CONFIG, NO_BACKGROUND_NO_PIDFILE, DYNAMIC_OS_VERSION +# OS_NAME, OS_VERSION, OS_MACHINE, V6SOCKETS_ARE_V6ONLY if [ -z "$DYNAMIC_OS_VERSION" ] ; then DYNAMIC_OS_VERSION=1 @@ -48,8 +49,16 @@ case "$argv" in --iptablespath=*) IPTABLESPATH=$(echo $argv | cut -d= -f2) ;; --getifaddrs) GETIFADDRS=1 ;; + --v6sockets-v6only) V6SOCKETS_ARE_V6ONLY=1 ;; + --host-os=*) + OS_NAME=$(echo $argv | cut -d= -f2) ;; + --host-os-version=*) + OS_VERSION=$(echo $argv | cut -d= -f2) ;; + --host-machine=*) + OS_MACHINE=$(echo $argv | cut -d= -f2) ;; --help|-h) echo "Usage : $0 [options]" + echo " --help this help" echo " --ipv6 enable IPv6" echo " --igd2 build an IGDv2 instead of an IGDv1" echo " --strict be more strict regarding compliance with UPnP specifications" @@ -64,6 +73,10 @@ case "$argv" in echo " --iptablespath=/path/to/iptables use a specific version of iptables" echo " --disable-fork Do not go to background and do not write pid file" echo " --getifaddrs Force use getifaddrs() to obtain interface addresses" + echo " --v6sockets-v6only v6 sockets don't do v4, ie sysctl net.inet6.ip6.v6only=1" + echo " --host-os= For cross build. result of uname -s on the host machine" + echo " --host-os-version=x.x For cross build. result of uname -r on the host machine" + echo " --host-machine= For cross build. result of uname -m on the host machine" exit 1 ;; *) @@ -93,12 +106,14 @@ fi # Facility to syslog LOG_MINIUPNPD="LOG_DAEMON" +# Makefile to use +MAKEFILE= + +if [ -z "$OS_NAME" ] ; then # detecting the OS name and version OS_NAME=`uname -s` OS_VERSION=`uname -r` OS_MACHINE=`uname -m` -# Makefile to use -MAKEFILE= # pfSense special case if [ -f /etc/platform ]; then @@ -133,11 +148,20 @@ if [ -f ./os.openembedded ]; then OS_VERSION=$(cat ./os.openembedded) fi +else +CROSSBUILD=1 +if [ -z "$OS_VERSION" ] || [ -z "$OS_MACHINE" ] ; then + echo "OS_NAME set to \"$OS_NAME\"." + echo "Please also set OS_VERSION/--host-os-version and OS_MACHINE/--host-machine" + exit 1 +fi +fi + ${RM} ${CONFIGFILE} echo "/* MiniUPnP Project" >> ${CONFIGFILE} echo " * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/" >> ${CONFIGFILE} -echo " * (c) 2006-2021 Thomas Bernard" >> ${CONFIGFILE} +echo " * (c) 2006-2022 Thomas Bernard" >> ${CONFIGFILE} echo " * generated by $0 on `date`" >> ${CONFIGFILE} echo " * `uname -a`" >> ${CONFIGFILE} if [ -z "$*" ] ; then @@ -215,22 +239,31 @@ case $OS_NAME in OS_URL=http://www.openbsd.org/ # net.inet6.ip6.v6only has been removed in recent OpenBSD versions # Default to 1 in that case - if sysctl net.inet6.ip6 | grep net.inet6.ip6.v6only ; then - V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` - else - V6SOCKETS_ARE_V6ONLY=1 + if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then + if sysctl net.inet6.ip6 | grep net.inet6.ip6.v6only ; then + V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` + else + V6SOCKETS_ARE_V6ONLY=1 + fi fi ;; FreeBSD | GNU/kFreeBSD) MAKEFILE=Makefile.bsd - VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'` - if [ $VER -ge 700049 ]; then - echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE} + if [ "$CROSSBUILD" != "1" ] ; then + VER=`grep '#define __FreeBSD_version' /usr/include/sys/param.h | awk '{print $3}'` + if [ $VER -ge 700049 ]; then + echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE} + fi + else + VER=`echo $OS_VERSION | cut -d. -f1` + if [ $VER -ge 7 ]; then + echo "#define PFRULE_INOUT_COUNTS" >> ${CONFIGFILE} + fi fi HAVE_IP_MREQN=1 # new way to see which one to use PF or IPF. # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=957 - if [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/defaults/rc.conf ] ; then + if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/defaults/rc.conf ] ; then # source file with handy subroutines like checkyesno . /etc/rc.subr # source config file so we can probe vars @@ -259,7 +292,9 @@ case $OS_NAME in fi echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE} OS_URL=http://www.freebsd.org/ - V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` + if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then + V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` + fi ;; pfSense) MAKEFILE=Makefile.bsd @@ -267,11 +302,13 @@ case $OS_NAME in FW=pf echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE} OS_URL=http://www.pfsense.com/ - V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` + if [ "$CROSSBUILD" != "1" ] && [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then + V6SOCKETS_ARE_V6ONLY=`sysctl -n net.inet6.ip6.v6only` + fi ;; NetBSD) MAKEFILE=Makefile.bsd - if [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then + if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then # source file with handy subroutines like checkyesno . /etc/rc.subr # source config file so we can probe vars @@ -291,7 +328,7 @@ case $OS_NAME in ;; DragonFly) MAKEFILE=Makefile.bsd - if [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then + if [ "$CROSSBUILD" != "1" ] && [ -z $FW ] && [ -f /etc/rc.subr ] && [ -f /etc/rc.conf ] ; then # source file with handy subroutines like checkyesno . /etc/rc.subr # source config file so we can probe vars @@ -337,58 +374,64 @@ case $OS_NAME in if [ \( $KERNVERA -ge 3 \) -o \( $KERNVERA -eq 2 -a $KERNVERB -ge 4 \) ]; then HAVE_IP_MREQN=1 fi - # Debian GNU/Linux special case - if [ -f /etc/debian_version ]; then - OS_NAME=Debian - OS_VERSION=`cat /etc/debian_version` - OS_URL=http://www.debian.org/ - fi - # same thing for Gentoo linux - if [ -f /etc/gentoo-release ]; then - OS_NAME=Gentoo - OS_VERSION=`cat /etc/gentoo-release` - OS_URL=http://www.gentoo.org/ - fi - # ClearOS special case - if [ -f /etc/clearos-release ]; then - OS_NAME=ClearOS - OS_VERSION=`grep ^base_version /etc/product | awk '{ print $3 }'` - OS_URL=https://www.clearos.com/ - fi - # use lsb_release (Linux Standard Base) when available - LSB_RELEASE=`command -v lsb_release` - if [ 0 -eq $? ]; then - OS_NAME=`${LSB_RELEASE} -i -s` - OS_VERSION=`${LSB_RELEASE} -r -s` - case $OS_NAME in - Debian) - OS_URL=http://www.debian.org/ - OS_VERSION=`${LSB_RELEASE} -c -s` - ;; - Ubuntu) - OS_URL=http://www.ubuntu.com/ - OS_VERSION=`${LSB_RELEASE} -c -s` - ;; - Gentoo) - OS_URL=http://www.gentoo.org/ - ;; - arch) - OS_URL=http://www.archlinux.org/ - OS_VERSION=`uname -r` - ;; - esac - fi - echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE} - if [ -z ${FW} ]; then - # test the current environment to determine which to use - # Would be better to check for actual presence of nftable rules, but that requires root privileges - if [ -x "$(command -v nft)" ]; then - FW=nftables - else - FW=iptables + if [ "$CROSSBUILD" != "1" ] ; then + # Debian GNU/Linux special case + if [ -f /etc/debian_version ]; then + OS_NAME=Debian + OS_VERSION=`cat /etc/debian_version` + OS_URL=http://www.debian.org/ + fi + # same thing for Gentoo linux + if [ -f /etc/gentoo-release ]; then + OS_NAME=Gentoo + OS_VERSION=`cat /etc/gentoo-release` + OS_URL=http://www.gentoo.org/ + fi + # ClearOS special case + if [ -f /etc/clearos-release ]; then + OS_NAME=ClearOS + OS_VERSION=`grep ^base_version /etc/product | awk '{ print $3 }'` + OS_URL=https://www.clearos.com/ + fi + # use lsb_release (Linux Standard Base) when available + LSB_RELEASE=`command -v lsb_release` + if [ 0 -eq $? ]; then + OS_NAME=`${LSB_RELEASE} -i -s` + OS_VERSION=`${LSB_RELEASE} -r -s` + case $OS_NAME in + Debian) + OS_URL=http://www.debian.org/ + OS_VERSION=`${LSB_RELEASE} -c -s` + ;; + Ubuntu) + OS_URL=http://www.ubuntu.com/ + OS_VERSION=`${LSB_RELEASE} -c -s` + ;; + Gentoo) + OS_URL=http://www.gentoo.org/ + ;; + arch) + OS_URL=http://www.archlinux.org/ + OS_VERSION=`uname -r` + ;; + esac + fi + fi + echo "#define USE_IFACEWATCHER 1" >> ${CONFIGFILE} + if [ "$CROSSBUILD" != "1" ] ; then + if [ -z ${FW} ]; then + # test the current environment to determine which to use + # Would be better to check for actual presence of nftable rules, but that requires root privileges + if [ -x "$(command -v nft)" ]; then + FW=nftables + else + FW=iptables + fi + fi + if [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then + V6SOCKETS_ARE_V6ONLY=`$(find /sbin /bin /usr/sbin /usr/bin -name sysctl) -n net.ipv6.bindv6only` fi fi - V6SOCKETS_ARE_V6ONLY=`$(find /sbin /bin /usr/sbin /usr/bin -name sysctl) -n net.ipv6.bindv6only` ;; OpenWrt) OS_URL=http://www.openwrt.org/ @@ -436,6 +479,9 @@ case $OS_NAME in ;; *) echo "Unknown OS : $OS_NAME" + echo "Supported OS_NAME / --host-os values : " + # find all the cases in this "case $OS_NAME in" statement : + awk '/# OS Specific stuff/{if(b>0){b=0}else{b=NR}} (b>0&&NR>b){print}' "$0" | grep '^ [^\(]*)$' | grep -v '*)' | tr ')|' " \n" | tr -d '\t ' | sort | tr "\n" " " ; echo "" echo "Please contact the author at http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/." exit 1 ;;