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 <sebastian_ml@gmx.net>
This commit is contained in:
parent
76b09155bc
commit
3da92d2359
3 changed files with 58 additions and 10 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
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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
|
||||||
|
@ -10,9 +10,13 @@ config instance 'site1'
|
||||||
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 log_level 'DBUG'
|
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'
|
config rtpproxy 'hotplug'
|
||||||
#option interface 'wan' # uncomment to enable hotplug
|
#option interface 'wan' # uncomment to enable hotplug
|
||||||
|
|
|
@ -28,6 +28,48 @@ run_instance() {
|
||||||
$LOGGER instance $2 has started
|
$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() {
|
check_param() {
|
||||||
local param="$1"
|
local param="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
|
@ -62,13 +104,14 @@ handle_instance() {
|
||||||
config_get log_level "$site" log_level
|
config_get log_level "$site" log_level
|
||||||
|
|
||||||
check_param "-s" "$socket"
|
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_param "-d" "$log_level" "DBUG"
|
||||||
|
|
||||||
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +123,7 @@ start_service() {
|
||||||
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
|
||||||
$LOG_ERR service not enabled
|
$LOG_ERR service not enabled
|
||||||
|
|
Loading…
Reference in a new issue