-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopensips.cfg
333 lines (266 loc) · 8.79 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
#
# 2015-12-1 15:08:56 PKT Hamid R. Hashmi $
#
# SIP Load Balancer
# Please chnage following IPs before deploying
# Publicly Accessible IP => 8.8.8.8 // EIP for SIP
# localIP => 192.168.26.180
# advertised_port => 5060
# Regex for local Subnet => '^192.168.26.[0-2][0-9][0-9]'
#
# Vim Editor:
#
# :%s/8.8.8.8/NEW_PUBLIC_IP/g
# :%s/advertised_port=5060/advertised_port=NEW_PUBLIC_SIP_PORT/g
# :%s/192.168.26.180:5060/NEW_PRIVATE_IP0:NEW_PRIVATE_PORT0/g
# :%s/192.168.26.180/NEW_PRIVATE_IP0/g
# Change Regex Manualy
# :%s/mysql:\/\/opensips:opensips@localhost\/opensips/mysql:\/\/DB_USER:DB_PASSWORD@NEW_DB_IP\/DB_NAME/g
# :%s/LOG_LOCAL0/LOG_LOCAL6/g
#
# 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
/* uncomment the following lines to enable debugging */
#debug=6
#fork=no
#log_stderror=yes
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
############## AWS ###########
auto_aliases=no
listen=udp:192.168.26.180:5060
advertised_address="8.8.8.8"
advertised_port=5060
alias="8.8.8.8"
#port=8000
log_name="SIPLB"
##################################
#disable_tcp=yes
####### Modules Section ########
#set module path
mpath="/usr/local//lib/opensips/modules/"
#### Protocl UDP
loadmodule "proto_udp.so"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 10)
modparam("tm", "fr_inv_timeout", 60)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 1)
#### 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)
#### MYSQL module
loadmodule "db_mysql.so"
#### AVPOPS module
loadmodule "avpops.so"
#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "failed_transaction_flag", "ACC_FAILED")
/* account triggers (flags) */
modparam("acc", "log_flag", "ACC_DO")
modparam("acc", "log_missed_flag", "ACC_MISSED")
#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600) # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
"mysql://opensips:opensips@localhost/opensips")
modparam("dialog", "rr_param", "siplb")
#### DISPATCHER
loadmodule "dispatcher.so"
modparam("dispatcher", "db_url", "mysql://opensips:opensips@localhost/opensips")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_from", "sip:siplb@192.168.26.180:5060")
modparam("dispatcher", "ds_ping_interval", 5)
modparam("dispatcher", "ds_probing_threshhold", 6)
modparam("dispatcher", "ds_probing_mode", 1)
##### Path #####
loadmodule "path.so"
modparam("path", "use_received", 1)
##### Domain #####
loadmodule "domain.so"
modparam("domain", "db_url", "mysql://opensips:opensips@localhost/opensips")
modparam("domain", "db_mode", 1) # Use caching
####### Routing Logic ########
# main request routing logic
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if ( $(fU{s.len}) < 8 && $(fU{s.len}) < 13 ) {
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: user number length not supported. Not a Comoyo user \n");
exit;
}
if (is_method("OPTIONS")) {
if($si =~ '192.168.26.[0-9]*' ) {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Receive request $rm from local server [$si] \n");
sl_send_reply("200","ACK");
exit;
} else {
xlog("L_ERROR", "[$pr:$fU@$si:$sp]: Receive request $rm from unknown destination [$si] \n");
exit;
}
}
if (is_method("PUBLISH")) {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: request $rm not allowed received from $si \n");
sl_send_reply("405","Method not allowed");
exit;
}
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Receive request $rm from $si \n");
if (has_totag() ) {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Request $rm from $si has totag \n");
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: Removing route from method $rm \n");
# validate the sequential request against dialog
if ( $DLG_status!=NULL && !validate_dialog() ) {
xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
## exit;
}
if (is_direction("upstream")) {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: UAS to UAC - Upstream \n");
} else {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: UAC to UAS - Downstream \n");
}
if (is_method("BYE")) {
# setflag(ACC_DO); # do accounting ...
# setflag(ACC_FAILED); # ... even if the transaction fails
} else 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") ) {
remove_hf("Proxy-Authorization");
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Method ACK with Request URI: $ru and CONTACT: '$ct' \n");
t_relay();
} else {
xlog("L_ERROR", "[$pr:$fU@$si:$sp]: Method ACK Discarded \n");
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
} else {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Request $rm from $si has NO to_tag \n");
if (is_method("INVITE") && $si =~ '192.168.26.[0-9]*' ) {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: INVITE from Local server \n");
remove_hf("Route");
record_route();
route(RELAY);
};
}
#### INITIAL REQUESTS
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: SIP Method is $rm with Request-URI $ru \n");
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
# record routing
record_route();
add_rr_param(";EdgeProxy=true");
# 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;
}
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Dispatching request $rm \n");
if (is_method("REGISTER")) {
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: Adding Path to Method $rm \n");
set_advertised_address("192.168.26.180");
if (!add_path_received()) {
sl_send_reply("503", "Internal Path Error");
};
}
ds_select_dst("1", "0");
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Dispatched to $du \n");
t_on_failure("GW_FAILOVER");
t_on_reply("GW_FAILOVER");
route(RELAY);
}
route[RELAY] {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: Relaying to $rd:$rp \n");
if (!t_relay()) {
xlog("L_ERROR", "[$pr:$fU@$si:$sp]: ERROR in Relaying \n");
sl_reply_error();
};
exit;
}
onreply_route[GW_FAILOVER] {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: On reply Route $rs:$rr \n");
}
failure_route[GW_FAILOVER] {
xlog("L_INFO", "[$pr:$fU@$si:$sp]: In Failure Route $rs:$rr \n");
if (t_was_cancelled()) {
exit;
}
# failure detection with redirect to next available trunk
if (t_check_status("(408)|([56][0-9][0-9])")) {
xlog("Failed trunk $rd/$du detected \n");
send_reply("408","Request Timeout");
}
}
local_route {
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: In LOCAL Route sending $rm to $rd \n");
if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
xlog("L_NOTICE", "[$pr:$fU@$si:$sp]: In LOCAL Route sending $rs:$rr for Method $rm \n");
acc_log_request("200 Dialog Timeout");
}
}