Merge pull request #385 from micmac1/rtpp
rtpproxy: update to procd and some brushing up
This commit is contained in:
commit
4395598a75
4 changed files with 141 additions and 28 deletions
|
@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=rtpproxy
|
PKG_NAME:=rtpproxy
|
||||||
PKG_VERSION:=2.1.0-20170914
|
PKG_VERSION:=2.1.0-20170914
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
|
|
||||||
PKG_SOURCE_PROTO:=git
|
PKG_SOURCE_PROTO:=git
|
||||||
PKG_SOURCE_URL:=https://github.com/sippy/rtpproxy.git
|
PKG_SOURCE_URL:=https://github.com/sippy/rtpproxy.git
|
||||||
|
@ -64,13 +64,30 @@ TARGET_CFLAGS+=$(TARGET_CPPFLAGS)
|
||||||
|
|
||||||
define Package/rtpproxy/install
|
define Package/rtpproxy/install
|
||||||
$(INSTALL_DIR) $(1)/usr/bin
|
$(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_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/rtpproxy.init $(1)/etc/init.d/rtpproxy
|
$(INSTALL_BIN) ./files/rtpproxy.init $(1)/etc/init.d/rtpproxy
|
||||||
|
|
||||||
$(INSTALL_DIR) $(1)/etc/config
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
$(INSTALL_CONF) ./files/rtpproxy.config $(1)/etc/config/rtpproxy
|
$(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
|
endef
|
||||||
|
|
||||||
define Package/rtpproxy-mod-acct-csv/install
|
define Package/rtpproxy-mod-acct-csv/install
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
config rtpproxy global
|
config rtpproxy global
|
||||||
option enabled 0 # 0 - disabled, 1 - enabled
|
option enabled 0 # 0 - disabled, 1 - enabled
|
||||||
|
|
||||||
config instance 'site1'
|
config instance 'site1'
|
||||||
option socket 'udp:127.0.0.1:7723' # socket
|
option socket 'udp:127.0.0.1:7723' # socket
|
||||||
option ipaddr '127.0.0.1' # IPv4 address
|
option ipaddr '127.0.0.1' # IPv4 address
|
||||||
option ip6addr '2001:0db8:0000:0000:0000:0000:1428:57ab' # IPv6 address
|
option ip6addr '2001:0db8:0000:0000:0000:0000:1428:57ab' # IPv6 address
|
||||||
option user 'nobody' # userid to run rtpproxy instance from
|
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
|
option opts '' # additional options for rtpproxy instance
|
||||||
|
|
||||||
config instance 'site2'
|
config instance 'site2'
|
||||||
option socket 'udp:127.0.0.1:7724'
|
option socket 'udp:127.0.0.1:7724'
|
||||||
option ipaddr '192.168.1.1'
|
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
|
||||||
|
|
||||||
|
|
24
net/rtpproxy/files/rtpproxy.hotplug
Normal file
24
net/rtpproxy/files/rtpproxy.hotplug
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
@ -1,17 +1,76 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# Copyright (C) 2014 CESNET, z.s.p.o
|
# Copyright (C) 2014 CESNET, z.s.p.o
|
||||||
|
# Copyright (C) 2018 OpenWrt.org
|
||||||
|
|
||||||
START=99
|
START=90
|
||||||
RTPPROXY_BIN="/usr/bin/rtpproxy"
|
|
||||||
|
|
||||||
run_instance(){
|
NAME=rtpproxy
|
||||||
local params="$1"
|
COMMAND="/usr/bin/$NAME"
|
||||||
|
|
||||||
${RTPPROXY_BIN} $1
|
USE_PROCD=1
|
||||||
echo "[INFO] rtpproxy instance $2 has started"
|
|
||||||
|
#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 param="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
local default_value="$3"
|
local default_value="$3"
|
||||||
|
@ -25,7 +84,7 @@ check_param(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_special_param(){
|
check_special_param() {
|
||||||
local param="$1"
|
local param="$1"
|
||||||
|
|
||||||
if [ "$param" != "" ]; then
|
if [ "$param" != "" ]; then
|
||||||
|
@ -35,36 +94,40 @@ check_special_param(){
|
||||||
|
|
||||||
handle_instance() {
|
handle_instance() {
|
||||||
local site="$1"
|
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 socket "$site" socket
|
||||||
config_get opts "$site" opts
|
config_get opts "$site" opts
|
||||||
config_get ipaddr "$site" ipaddr
|
config_get ipaddr "$site" ipaddr
|
||||||
config_get ip6addr "$site" ip6addr
|
config_get ip6addr "$site" ip6addr
|
||||||
config_get user "$site" user
|
config_get user "$site" user
|
||||||
|
config_get log_level "$site" log_level
|
||||||
|
|
||||||
check_param "-s" "$socket"
|
check_param "-s" "$socket"
|
||||||
check_param "-l" "$ipaddr"
|
check_param "-u" "$user" "nobody"
|
||||||
check_param "-6" "$ip6addr"
|
check_param "-d" "$log_level" "DBUG"
|
||||||
check_param "-u" "$user" "nobody"
|
|
||||||
check_special_param "$opts"
|
check_special_param "$opts"
|
||||||
|
|
||||||
|
[ -n "$ipaddr" ] && check_ipaddr "$ipaddr" ipaddr '-l'
|
||||||
|
[ -n "$ip6addr" ] && check_ipaddr "$ip6addr" ip6addr '-6'
|
||||||
|
|
||||||
run_instance "$rtpproxy_options" "$site"
|
run_instance "$rtpproxy_options" "$site"
|
||||||
}
|
}
|
||||||
|
|
||||||
start(){
|
start_service() {
|
||||||
config_load rtpproxy
|
local enabled
|
||||||
local section="global"
|
|
||||||
|
config_load $NAME
|
||||||
|
|
||||||
config_get_bool enabled global enabled 0
|
config_get_bool enabled global enabled 0
|
||||||
|
|
||||||
if [ "$enabled" -eq 1 ]; then
|
if [ "$enabled" -eq 1 ]; then
|
||||||
|
. /lib/functions/network.sh
|
||||||
config_foreach handle_instance instance
|
config_foreach handle_instance instance
|
||||||
else
|
else
|
||||||
echo "[WARNING] rtpproxy not yet configured. Edit /etc/config/rtpproxy first."
|
$LOG_ERR service not enabled
|
||||||
|
$LOG_ERR edit /etc/config/$NAME
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
|
||||||
killall rtpproxy
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue