diff --git a/net/rtpproxy/Makefile b/net/rtpproxy/Makefile index 8c8505b..49b3379 100644 --- a/net/rtpproxy/Makefile +++ b/net/rtpproxy/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=rtpproxy PKG_VERSION:=2.1.0-20170914 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/sippy/rtpproxy.git @@ -64,13 +64,30 @@ TARGET_CFLAGS+=$(TARGET_CPPFLAGS) define Package/rtpproxy/install $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rtpproxy $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rtpproxy $(1)/usr/bin $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/rtpproxy.init $(1)/etc/init.d/rtpproxy $(INSTALL_DIR) $(1)/etc/config $(INSTALL_CONF) ./files/rtpproxy.config $(1)/etc/config/rtpproxy + + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface + $(INSTALL_BIN) ./files/rtpproxy.hotplug $(1)/etc/hotplug.d/iface +endef + +define Package/rtpproxy/postinst +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + echo + echo "o-------------------------------------------------------------------o" + echo "| RTPProxy note |" + echo "o-------------------------------------------------------------------o" + echo "| Edit /etc/config/rtpproxy to change basic init configuration. |" + echo "o-------------------------------------------------------------=^_^=-o" + echo +fi +exit 0 endef define Package/rtpproxy-mod-acct-csv/install diff --git a/net/rtpproxy/files/rtpproxy.config b/net/rtpproxy/files/rtpproxy.config index 7087251..afcf1b2 100644 --- a/net/rtpproxy/files/rtpproxy.config +++ b/net/rtpproxy/files/rtpproxy.config @@ -1,14 +1,23 @@ config rtpproxy global option enabled 0 # 0 - disabled, 1 - enabled -config instance 'site1' - option socket 'udp:127.0.0.1:7723' # socket +config instance 'site1' + option socket 'udp:127.0.0.1:7723' # socket option ipaddr '127.0.0.1' # IPv4 address option ip6addr '2001:0db8:0000:0000:0000:0000:1428:57ab' # IPv6 address option user 'nobody' # userid to run rtpproxy instance from + option log_level 'INFO' # DBUG, INFO, WARN, ERR or CRIT option opts '' # additional options for rtpproxy instance - -config instance 'site2' - option socket 'udp:127.0.0.1:7724' - option ipaddr '192.168.1.1' + +config instance 'site2' + option socket 'udp:127.0.0.1:7724' + option ipaddr 'lan/wan' # Bridge mode. 'lan' and 'wan' will be + option user 'nobody' # translated to IPv4 addresses by init + option log_level 'DBUG' # script. Handy if using dynamic IPs. Can + option opts '' # also be used with single interfaces. + # Translation for both 'ipaddr' and + # 'ip6addr' supported. + +config rtpproxy 'hotplug' + #option interface 'wan' # uncomment to enable hotplug diff --git a/net/rtpproxy/files/rtpproxy.hotplug b/net/rtpproxy/files/rtpproxy.hotplug new file mode 100644 index 0000000..dfa6981 --- /dev/null +++ b/net/rtpproxy/files/rtpproxy.hotplug @@ -0,0 +1,24 @@ +#!/bin/sh + +[ "$ACTION" = ifup ] || exit 0 + +NAME=rtpproxy +COMMAND=/etc/init.d/$NAME +LOGGER="/usr/bin/logger -t hotplug" + +$COMMAND enabled || exit 0 + +. /lib/functions.sh + +config_load $NAME + +config_get_bool enabled global enabled 0 +[ $enabled -eq 0 ] && exit 0 + +config_get hotplug_iface hotplug interface + +[ "$INTERFACE" = "$hotplug_iface" ] && { + $LOGGER "Restarting $NAME due to \"$ACTION\" of \"$INTERFACE\"" + $COMMAND restart +} + diff --git a/net/rtpproxy/files/rtpproxy.init b/net/rtpproxy/files/rtpproxy.init index d1e2b37..f71ec6a 100644 --- a/net/rtpproxy/files/rtpproxy.init +++ b/net/rtpproxy/files/rtpproxy.init @@ -1,17 +1,76 @@ #!/bin/sh /etc/rc.common # Copyright (C) 2014 CESNET, z.s.p.o +# Copyright (C) 2018 OpenWrt.org -START=99 -RTPPROXY_BIN="/usr/bin/rtpproxy" +START=90 -run_instance(){ - local params="$1" +NAME=rtpproxy +COMMAND="/usr/bin/$NAME" - ${RTPPROXY_BIN} $1 - echo "[INFO] rtpproxy instance $2 has started" +USE_PROCD=1 + +#PROCD_DEBUG=1 + +LOGGER="/usr/bin/logger -t $NAME" +LOG_ERR="$LOGGER -p user.err -s" + +run_instance() { + procd_open_instance + procd_set_param command $COMMAND + procd_append_param command \ + $1 \ + -p "/var/run/$NAME-$2.pid" \ + -f + # forward stderr to logd + procd_set_param stderr 1 + procd_close_instance + + $LOGGER instance $2 has started } -check_param(){ +check_ip() { + local tmp_addr + + if [ "$1" = "ipaddr" ]; then + network_get_ipaddr tmp_addr "$2" || tmp_addr="$2" + else + network_get_ipaddr6 tmp_addr "$2" || tmp_addr="$2" + fi + + echo "$tmp_addr" +} + +check_ipaddr() { + local value="$1" + local type="$2" + local param="$3" + local one two + + [ -z "$value" ] && { + $LOG_ERR empty $type entry + exit 1 + } + + # Bail if more than 1 slash. + [ $(echo "$value" | awk -F "/" '{print NF-1}') -gt 1 ] && { + $LOG_ERR init script does not understand $type entry \""$value"\" + exit 1 + } + + IFS="/" read one two << EOF +$value +EOF + + one="$(check_ip "$type" "$one")" + if [ -n "$two" ]; then + two="$(check_ip "$type" "$two")" + rtpproxy_options=$rtpproxy_options" $param $one/$two" + else + rtpproxy_options=$rtpproxy_options" $param $one" + fi +} + +check_param() { local param="$1" local value="$2" local default_value="$3" @@ -25,7 +84,7 @@ check_param(){ fi } -check_special_param(){ +check_special_param() { local param="$1" if [ "$param" != "" ]; then @@ -35,36 +94,40 @@ check_special_param(){ handle_instance() { local site="$1" - local socket opts ipaddr ip6addr rtpproxy_options + local socket opts ipaddr ip6addr rtpproxy_options log_level config_get socket "$site" socket config_get opts "$site" opts config_get ipaddr "$site" ipaddr config_get ip6addr "$site" ip6addr config_get user "$site" user + config_get log_level "$site" log_level check_param "-s" "$socket" - check_param "-l" "$ipaddr" - check_param "-6" "$ip6addr" - check_param "-u" "$user" "nobody" + check_param "-u" "$user" "nobody" + check_param "-d" "$log_level" "DBUG" + check_special_param "$opts" + [ -n "$ipaddr" ] && check_ipaddr "$ipaddr" ipaddr '-l' + [ -n "$ip6addr" ] && check_ipaddr "$ip6addr" ip6addr '-6' + run_instance "$rtpproxy_options" "$site" } -start(){ - config_load rtpproxy - local section="global" +start_service() { + local enabled + + config_load $NAME + config_get_bool enabled global enabled 0 if [ "$enabled" -eq 1 ]; then + . /lib/functions/network.sh config_foreach handle_instance instance else - echo "[WARNING] rtpproxy not yet configured. Edit /etc/config/rtpproxy first." + $LOG_ERR service not enabled + $LOG_ERR edit /etc/config/$NAME fi } -stop() { - killall rtpproxy -} -