-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathopensips.cfg
342 lines (281 loc) · 8.98 KB
/
opensips.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#
# OpenSIPS residential configuration script
# by OpenSIPS Solutions <[email protected]>
#
# Please refer to the Core CookBook at:
# http://www.opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#
####### Global Parameters #########
debug=3
log_stderror=no
log_facility=LOG_LOCAL0
fork=yes
children=4
auto_aliases=no
listen=udp:118.69.135.152:5060 # TODO: update with your local IP and port
listen=ws:118.69.135.152:7080 # TODO: update with your local IP and port
####### Modules Section ########
# set module path
mpath="/usr/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
modparam("rr", "append_fromtag", 0)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
#modparam("usrloc", "db_mode", 0)
#### Using with Database mode --> all register sip device will be store in `location` Table
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "max_contacts", 2)
#### RTPengine protocol
#loadmodule "rtpengine.so"
#modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.0:60000")
#### AVPOPS Module
#### The Module can be used in sip trace module
#### Using it by Adding SIP user should be traced:
#### opensipsctl avp add [email protected] traceuser 1 1 --> result
#### +------+----------+----------------+-----------+------+-------+
#### | uuid | username | domain | attribute | type | value |
#### +------+----------+----------------+-----------+------+-------+
#### | | 1001 | 118.69.135.152 | traceuser | 1 | 1 |
#### +------+----------+----------------+-----------+------+-------+
#### the `attribute` should be the same with siptrace module
#### modparam("siptrace", "traced_user_avp", "$avp(traceuser)")
#### https://voipmagazine.wordpress.com/2014/11/13/attribute-value-pair-variables-avps-in-opensips/
loadmodule "avpops.so"
modparam("avpops", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
#### Nathelper protocol
loadmodule "nathelper.so"
modparam("registrar|nathelper", "received_avp", "$avp(received)")
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "sipping_bflag", "NAT")
modparam("nathelper", "sipping_from", "sip:[email protected]")
#### UDP protocol
loadmodule "proto_udp.so"
#### WebSocket protocol
loadmodule "proto_ws.so"
#### Database loading
loadmodule "db_mysql.so"
#### Authentication and Authorization
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
modparam("auth_db", "calculate_ha1", 0)
modparam("auth_db", "use_domain", 0)
#modparam("auth_db", "load_credentials", "")
#### Sip Trace module
loadmodule "siptrace.so"
modparam("siptrace", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
modparam("siptrace", "trace_on", 1)
modparam("siptrace", "enable_ack_trace", 1)
modparam("siptrace", "trace_flag", "TRACE_FLAG")
modparam("siptrace", "traced_user_avp", "$avp(traceuser)")
modparam("siptrace", "trace_local_ip", "118.69.135.152")
#### how to calc google adsense
#### http://vitalk.vn/threads/cha-de-flappy-bird-nguyen-ha-dong-da-nop-1-4-ty-dong-tien-thue-nhung-van-con-thieu-nhieu.2223633/?page_thread=1
#### https://voipmagazine.wordpress.com/2014/12/13/linux-tuning-for-sip-routers-part-1-interrupts-and-irq-tuning/
####### Routing Logic ########
# main request routing logic
route{
#### for sip trace working properly
#### the flag should be set
#### the example is used by loading $avp(traceuser) from database
#### load $fu from Database if true run the rest of if's body
if(avp_db_load("$fu/username","$avp(traceuser)")) {
$avp(traceuser)=$fu;
setflag(TRACE_FLAG);
sip_trace();
xlog("L_INFO", "User $fu being traced");
}
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if (has_totag()) {
# sequential requests within a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("INVITE")) {
# even if in most of the cases is useless, do RR for
# re-INVITEs alos, as some buggy clients do change route set
# during the dialog.
record_route();
}
# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(relay);
} else {
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
t_check_trans();
if (!is_method("REGISTER")) {
if (from_uri!=myself) {
# if caller is not local, then called number must be local
if (!uri==myself) {
send_reply("403","Rely forbidden");
exit;
}
}
if (!proxy_authorize("", "subscriber")) {
proxy_challenge("", "0");
exit;
}
if (!db_check_from()) {
sl_send_reply("403","Forbidden auth ID");
exit;
}
consume_credentials();
}
# preloaded route checking
if (loose_route()) {
xlog("L_ERR", "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}
# record routing
if (!is_method("REGISTER|MESSAGE"))
record_route();
if (!uri==myself) {
append_hf("P-hint: outbound\r\n");
route(relay);
}
# requests for my domain
if (is_method("PUBLISH|SUBSCRIBE")) {
sl_send_reply("503", "Service Unavailable");
exit;
}
# check if the clients are using WebSockets
if (proto == WS)
setflag(SRC_WS);
# consider the client is behind NAT - always fix the contact
#fix_nated_contact();
if (is_method("REGISTER")) {
if (nat_uac_test("19")) {
xlog("L_ERR", "Attempt to test client NAT [received_avp]");
setbflag(NAT);
}
if (!www_authorize("", "subscriber"))
{
www_challenge("", "0");
exit;
}
# indicate that the client supports DTLS
# so we know when he is called
if (isflagset(SRC_WS))
setbflag(DST_WS);
fix_nated_register();
if (!save("location"))
sl_reply_error();
exit;
}
if ($rU==NULL) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
# do lookup with method filtering
#if (!lookup("location","m")) {
# t_newtran();
# t_reply("404", "Not Found");
# exit;
#}
if (!lookup("location","m")) {
switch ($retcode) {
case -1:
case -3:
t_newtran();
t_reply("404", "Not Found");
exit;
case -2:
sl_send_reply("405", "Method Not Allowed");
exit;
}
}
route(relay);
}
route[relay] {
# for INVITEs enable some additional helper routes
if (is_method("INVITE")) {
t_on_branch("handle_nat");
t_on_reply("handle_nat");
} #else if (is_method("BYE|CANCEL")) {
# rtpengine_delete();
#}
if (!t_relay()) {
send_reply("500","Internal Error");
};
exit;
}
branch_route[handle_nat] {
if (!is_method("INVITE") || !has_body("application/sdp"))
return;
#if (isflagset(SRC_WS) && isbflagset(DST_WS))
# $var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
#else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
# $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
#else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
# $var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
#else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
# $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
#rtpengine_offer("$var(rtpengine_flags)");
}
onreply_route[handle_nat] {
fix_nated_contact();
if (!has_body("application/sdp"))
return;
#if (isflagset(SRC_WS) && isbflagset(DST_WS))
#$var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
#else if (isflagset(SRC_WS) && !isbflagset(DST_WS))
#$var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
#else if (!isflagset(SRC_WS) && isbflagset(DST_WS))
#$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
#else if (!isflagset(SRC_WS) && !isbflagset(DST_WS))
# $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
#rtpengine_answer("$var(rtpengine_flags)");
}