forked from Binan/rtpengine-systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtpengine-start
executable file
·123 lines (101 loc) · 5.06 KB
/
rtpengine-start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /bin/sh
# $1 contains the path to the configuration file. It is passed in the systemd unit file
# When calling the rtpengine command
# It should be /etc/default/rtpengine-conf
DEFAULTS=$1
# Load startup options if available
if [ -f $DEFAULTS ]; then
. $DEFAULTS || true
fi
if [ "$RUN_RTPENGINE" != "yes" ]; then
echo "rtpengine not yet configured. Edit $DEFAULTS first."
exit 0
fi
# Gradually fill the options of the command rtpengine which starts the RTPEngine daemon
# The variables used are sourced from the configuration file rtpengine-conf
OPTIONS=""
if [ ! -z "$INTERFACES" ]; then
for interface in $INTERFACES; do
OPTIONS="$OPTIONS --interface=$interface"
done
fi
if [ ! -z "$TABLE" ]; then
echo "TABLE=$TABLE" > /etc/default/rtpengine-table
fi
[ -z "$LISTEN_TCP" ] || OPTIONS="$OPTIONS --listen-tcp=$LISTEN_TCP"
[ -z "$LISTEN_UDP" ] || OPTIONS="$OPTIONS --listen-udp=$LISTEN_UDP"
[ -z "$LISTEN_NG" ] || OPTIONS="$OPTIONS --listen-ng=$LISTEN_NG"
[ -z "$LISTEN_CLI" ] || OPTIONS="$OPTIONS --listen-cli=$LISTEN_CLI"
[ -z "$TIMEOUT" ] || OPTIONS="$OPTIONS --timeout=$TIMEOUT"
[ -z "$SILENT_TIMEOUT" ] || OPTIONS="$OPTIONS --silent-timeout=$SILENT_TIMEOUT"
[ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE"
[ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS"
[ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN"
[ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX"
[ -z "$REDIS" ] || OPTIONS="$OPTIONS --redis=$REDIS"
[ -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis-db=$REDIS_DB"
[ -z "$REDIS_READ" ] || OPTIONS="$OPTIONS --redis-read=$REDIS_READ"
[ -z "$REDIS_READ_DB" ] || OPTIONS="$OPTIONS --redis-read-db=$REDIS_READ_DB"
[ -z "$REDIS_WRITE" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE"
[ -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write-db=$REDIS_WRITE_DB"
[ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"
[ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"
OPTIONS="$OPTIONS --table=$TABLE"
[ -z "$LOG_LEVEL" ] || OPTIONS="$OPTIONS --log-level=$LOG_LEVEL"
[ -z "$LOG_FACILITY" ] || OPTIONS="$OPTIONS --log-facility=$LOG_FACILITY"
[ -z "$LOG_FACILITY_CDR" ] || OPTIONS="$OPTIONS --log-facility-cdr=$LOG_FACILITY_CDR"
[ -z "$LOG_FACILITY_RTCP" ] || OPTIONS="$OPTIONS --log-facility-rtcp=$LOG_FACILITY_RTCP"
[ -z "$NUM_THREADS" ] || OPTIONS="$OPTIONS --num-threads=$NUM_THREADS"
[ -z "$DELETE_DELAY" ] || OPTIONS="$OPTIONS --delete-delay=$DELETE_DELAY"
[ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE"
[ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL"
[ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX"
[ -z "$MAX_SESSIONS" ] || OPTIONS="$OPTIONS --max-sessions=$MAX_SESSIONS"
[ -z "$HOMER" ] || OPTIONS="$OPTIONS --homer=$HOMER"
[ -z "$HOMER_PROTOCOL" ] || OPTIONS="$OPTIONS --homer-protocol=$HOMER_PROTOCOL"
[ -z "$HOMER_ID" ] || OPTIONS="$OPTIONS --homer-id=$HOMER_ID"
if test "$FORK" = "no" ; then
OPTIONS="$OPTIONS --foreground"
fi
modprobe xt_RTPENGINE
if [ -e /proc/rtpengine/control ]; then
echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null
fi
# Freshly add the iptables rules to forward the udp packets to the iptables-extension "RTPEngine":
# Remember iptables table = chains, rules stored in the chains
# -N (create a new chain with the name rtpengine)
iptables -N rtpengine 2> /dev/null
# -D: Delete the rule for the target "rtpengine" if exists. -j (target): chain name or extension name
# from the table "filter" (the default -without the option '-t')
#iptables -D INPUT -j rtpengine 2> /dev/null
RULE_NUMBER=$(iptables -L INPUT --line-numbers | awk '/udp dpts:[0-9]+:[0-9]+ \/\* rtpengine in-kernel packet forwarding \*\// {print $1}')
if [ ! -z $RULE_NUMBER ]
then
iptables -D INPUT $RULE_NUMBER
fi
RULE_NUMBER=$(iptables -L INPUT --line-numbers | awk '/udp dpts:[0-9]+:[0-9]+ \/\* RTP PORT RANGE \*\// {print $1}')
if [ ! -z $RULE_NUMBER ]
then
iptables -D INPUT $RULE_NUMBER
fi
# Add the rule again so the packets will go to rtpengine chain after the (filter-INPUT) hook point.
#iptables -I INPUT -j rtpengine
if [ -z $PORT_MIN ] || [ -z $PORT_MAX ]
then
iptables -A INPUT -p udp --dport 50000:55000 -j rtpengine -m comment --comment "rtpengine in-kernel packet forwarding"
iptables -A INPUT -p udp --dport 50000:55000 -j ACCEPT -m comment --comment "RTP PORT RANGE"
else
iptables -A INPUT -p udp --dport $PORT_MIN:$PORT_MAX -j rtpengine -m comment --comment "rtpengine in-kernel packet forwarding"
iptables -A INPUT -p udp --dport $PORT_MIN:$PORT_MAX -j ACCEPT -m comment --comment "RTP PORT RANGE"
fi
# Delete and Insert a rule in the rtpengine chain to forward the UDP traffic
iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
# The same for IPv6
#ip6tables -N rtpengine 2> /dev/null
#ip6tables -D INPUT -j rtpengine 2> /dev/null
#ip6tables -I INPUT -j rtpengine
#ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
#ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
rtpengine $OPTIONS
exit 0