From 0b092cbe2b5eed5dd6f9140ee35860ac32bdd577 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 20:16:54 +0100 Subject: [PATCH 1/5] rtpproxy: add hotplug script Install hotplug script along with rtpproxy. It will only be used if enabled by the user (via uci config file). Signed-off-by: Sebastian Kemper --- net/rtpproxy/Makefile | 5 ++++- net/rtpproxy/files/rtpproxy.config | 3 +++ net/rtpproxy/files/rtpproxy.hotplug | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 net/rtpproxy/files/rtpproxy.hotplug diff --git a/net/rtpproxy/Makefile b/net/rtpproxy/Makefile index 8c8505b..87ecab8 100644 --- a/net/rtpproxy/Makefile +++ b/net/rtpproxy/Makefile @@ -64,13 +64,16 @@ 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-mod-acct-csv/install diff --git a/net/rtpproxy/files/rtpproxy.config b/net/rtpproxy/files/rtpproxy.config index 7087251..2350c11 100644 --- a/net/rtpproxy/files/rtpproxy.config +++ b/net/rtpproxy/files/rtpproxy.config @@ -12,3 +12,6 @@ config instance 'site2' option socket 'udp:127.0.0.1:7724' option ipaddr '192.168.1.1' +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 +} + From 325bbe9bbb96025862b8f31e16ad623cf96d8c90 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 20:21:06 +0100 Subject: [PATCH 2/5] rtpproxy: add a note about the uci file Echoes a message upon installation and points the user to /etc/config/rtpproxy. Signed-off-by: Sebastian Kemper --- net/rtpproxy/Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/rtpproxy/Makefile b/net/rtpproxy/Makefile index 87ecab8..fdebd1d 100644 --- a/net/rtpproxy/Makefile +++ b/net/rtpproxy/Makefile @@ -76,6 +76,20 @@ define Package/rtpproxy/install $(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 $(INSTALL_DIR) $(1)/usr/lib/rtpproxy $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/rtpproxy/rtpp_acct_csv.so \ From a3767c5f00544054ebde80071e217d041e04a7df Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 20:34:28 +0100 Subject: [PATCH 3/5] rtpproxy: convert init to procd Update rtpproxy init script to use procd. Also increases the start priority to 90 (like the hotplug script) to make sure rtpproxy is started before kamailio. Fixes some whitespace issues along the way, too. Signed-off-by: Sebastian Kemper --- net/rtpproxy/files/rtpproxy.init | 51 +++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/net/rtpproxy/files/rtpproxy.init b/net/rtpproxy/files/rtpproxy.init index d1e2b37..32c2940 100644 --- a/net/rtpproxy/files/rtpproxy.init +++ b/net/rtpproxy/files/rtpproxy.init @@ -1,17 +1,34 @@ #!/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_param() { local param="$1" local value="$2" local default_value="$3" @@ -25,7 +42,7 @@ check_param(){ fi } -check_special_param(){ +check_special_param() { local param="$1" if [ "$param" != "" ]; then @@ -46,25 +63,25 @@ handle_instance() { check_param "-s" "$socket" check_param "-l" "$ipaddr" check_param "-6" "$ip6addr" - check_param "-u" "$user" "nobody" + check_param "-u" "$user" "nobody" + check_special_param "$opts" 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 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 -} - From 76b09155bc682bb9fd279aa27efa78fa61730684 Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 20:43:25 +0100 Subject: [PATCH 4/5] rtpproxy: add uci log switch Add log_level option to uci config. Paired with the comment it makes setting the log level easier when no man page is around. Signed-off-by: Sebastian Kemper --- net/rtpproxy/files/rtpproxy.config | 2 ++ net/rtpproxy/files/rtpproxy.init | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/net/rtpproxy/files/rtpproxy.config b/net/rtpproxy/files/rtpproxy.config index 2350c11..760a3c3 100644 --- a/net/rtpproxy/files/rtpproxy.config +++ b/net/rtpproxy/files/rtpproxy.config @@ -6,11 +6,13 @@ config instance 'site1' 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' + option log_level 'DBUG' config rtpproxy 'hotplug' #option interface 'wan' # uncomment to enable hotplug diff --git a/net/rtpproxy/files/rtpproxy.init b/net/rtpproxy/files/rtpproxy.init index 32c2940..ac93721 100644 --- a/net/rtpproxy/files/rtpproxy.init +++ b/net/rtpproxy/files/rtpproxy.init @@ -52,18 +52,20 @@ 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 "-d" "$log_level" "DBUG" check_special_param "$opts" From 3da92d2359d2ef79a996542bc5f02598a4557e1e Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Mon, 5 Nov 2018 20:59:29 +0100 Subject: [PATCH 5/5] rtpproxy: add iface translation to init rtpproxy expects IPs as parameters. Lots of OpenWrt devices use connections where the IP is dynamically assigned. This commit adds shell functions to convert an iface like 'wan' to an IP address before adding the parameter to the rtpproxy command line. Explanation is provided in /etc/config/rtpproxy. Some whitespace issues were also fixed. Signed-off-by: Sebastian Kemper --- net/rtpproxy/Makefile | 2 +- net/rtpproxy/files/rtpproxy.config | 18 ++++++----- net/rtpproxy/files/rtpproxy.init | 48 ++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/net/rtpproxy/Makefile b/net/rtpproxy/Makefile index fdebd1d..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 diff --git a/net/rtpproxy/files/rtpproxy.config b/net/rtpproxy/files/rtpproxy.config index 760a3c3..afcf1b2 100644 --- a/net/rtpproxy/files/rtpproxy.config +++ b/net/rtpproxy/files/rtpproxy.config @@ -1,18 +1,22 @@ 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' - option log_level 'DBUG' + +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.init b/net/rtpproxy/files/rtpproxy.init index ac93721..f71ec6a 100644 --- a/net/rtpproxy/files/rtpproxy.init +++ b/net/rtpproxy/files/rtpproxy.init @@ -28,6 +28,48 @@ run_instance() { $LOGGER instance $2 has started } +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" @@ -62,13 +104,14 @@ handle_instance() { 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 "-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" } @@ -80,6 +123,7 @@ start_service() { config_get_bool enabled global enabled 0 if [ "$enabled" -eq 1 ]; then + . /lib/functions/network.sh config_foreach handle_instance instance else $LOG_ERR service not enabled