-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkamailio.cfg
264 lines (217 loc) · 5.36 KB
/
kamailio.cfg
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!KAMAILIO
#
# sample config file for dispatcher module
# - load balancing of VoIP calls with round robin
# - no TPC listening
#
####### Global Parameters #########
##!define WITH_DEBUG
#!ifdef WITH_DEBUG
debug=4
log_stderror=yes
#!else
debug=2
log_stderror=no
#!endif
memdbg=5
memlog=5
fork=yes
children=4
disable_tcp=yes
auto_aliases=no
# ----- docker container with host ip and port advertised.
# listen=udp:0.0.0.0 advertise 192.168.59.30:5060
port=5060
sip_warning=no
####### Modules Section ########
# set paths to location of modules (to sources or installation folders)
#!ifdef WITH_SRCPATH
mpath="modules/"
#!else
mpath="/usr/lib64/kamailio/modules/"
#!endif
loadmodule "mi_fifo.so"
loadmodule "kex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "mi_rpc.so"
loadmodule "dispatcher.so"
# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 0)
# ----- tm params -----
modparam("tm", "fr_timer", 2000)
modparam("tm", "fr_inv_timer", 40000)
# ----- dispatcher params -----
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "ds_ping_interval", 15)
modparam("dispatcher", "ds_probing_threshold", 1)
modparam("dispatcher", "ds_ping_reply_codes", "class=2;class=3;class=4")
####### Routing Logic ########
# main request routing logic
route {
# per request initial checks
route(REQINIT);
# handle requests within SIP dialogs
route(WITHINDLG);
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans())
t_relay();
exit;
}
# handle retransmissions
if(t_precheck_trans()) {
t_check_trans();
exit;
}
t_check_trans();
# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE"))
record_route();
# Directly relay without dispatch
route(PRESENCE);
route(REGISTRAR);
# dispatch destinations
route(DISPATCH);
if ($rU==$null)
{
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
}
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
exit;
}
# Per SIP request initial checks
route[REQINIT] {
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if(!sanity_check("1511", "7"))
{
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
}
# Handle requests within SIP dialogs
route[WITHINDLG] {
if (!has_totag()) return;
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
route(RELAY);
exit;
}
if (is_method("SUBSCRIBE") && uri == myself) {
# in-dialog subscribe requests
route(PRESENCE);
exit;
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK;
# must be ACK after a 487 or e.g. 404 from upstream server
route(RELAY);
}
# ACK without matching transaction ... ignore and discard.
exit;
}
sl_send_reply("404","Not here");
exit;
}
# Handle SIP registrations
route[REGISTRAR] {
if(!is_method("REGISTER"))
return;
if (uri == myself) {
sl_send_reply("404", "No registrar");
exit;
}
route(RELAY);
}
# Presence server route
route[PRESENCE] {
if(!is_method("PUBLISH|SUBSCRIBE"))
return;
if (uri == myself) {
sl_send_reply("404", "No here");
exit;
}
route(RELAY);
exit;
}
# Dispatch requests
route[DISPATCH] {
# Destination types:
# http://kamailio.org/docs/modules/4.2.x/modules/dispatcher.html#dispatcher.f.ds_select_dst
# 4 = round robin
# 9 = weight-based
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "9"))
{
send_reply("404", "No destination");
exit;
}
t_set_fr(0,2000);
t_on_failure("ROUTE_ADVANCE");
route(RELAY);
exit;
}
event_route[dispatcher:dst-down] {
xlog("L_ERR", "Destination down: $rm $ru ($du)\n");
}
event_route[dispatcher:dst-up] {
xlog("L_ERR", "Destination up: $rm $ru\n");
}
failure_route[ROUTE_ADVANCE] {
if (t_is_canceled()) {
exit;
}
xlog("L_NOTICE", "Media server $du failed to answer, selecting other one!\n");
if (t_check_status("503") || (t_branch_timeout() and !t_branch_replied())) {
ds_mark_dst("ip");
# select the new destination
if(ds_next_dst()) {
# again set local timeout for reply
# xlog("L_NOTICE", "Selecting next route upon failure\n");
t_set_fr(0,2000);
t_on_failure("ROUTE_ADVANCE");
route(RELAY);
exit;
} else {
#last available node failed to reply, no other destinations available
send_reply("404", "No destination");
xlog("L_NOTICE","No destination, sent 404\n");
exit;
}
} else {
xlog("L_NOTICE","Unhandled failured route!\n");
}
}