summaryrefslogtreecommitdiff
path: root/net/opensips/files/opensips.cfg.sample
blob: 54483bfce4a7e93a38fdce1037eee06b8581bad2 (plain) (blame)
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
#
# OpenSIPS residential configuration script
#
# This script was originally generated via 
# 'CC=gcc6 gmake menuconfig', from the "Residential" scenario.
# You can enable / disable more features / functionalities by
# re-generating the scenario with different options.
#
# To generate an opensips script in FreeBSD, run the following commands,
# after installing the port / package.
# $ cd /usr/ports/net/opensips
# $ make patch
# $ cd work/opensips-*/
# $ CC=gcc6 gmake menuconfig
# $ ls tmp/
#
# As the FreeBSD port maintainer, I have tailored it a little
# to resemble the (hopefully) sane set of defaults for a residential
# SIP router running on FreeBSD and using PostgreSQL as backend database.
# For other supported databases, it should be as simple as changing all
# the db_url variables throughout this script.
#
# Please refer to the Core CookBook at:
# http://www.opensips.org/Resources/DocsCookbooks
# for an explanation of possible statements, functions and parameters.
#


####### Global Parameters #########

log_level=3
log_stderror=no
log_facility=LOG_LOCAL0

children=4

/* uncomment the following lines to enable debugging */
#debug_mode=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 */
auto_aliases=no


listen=udp:192.168.10.12:5060   # CUSTOMIZE ME
listen=tcp:192.168.10.12:5060   # CUSTOMIZE ME 
listen=tls:192.168.10.12:5061   # CUSTOMIZE ME 
#advertised_address=12.34.56.78   # CUSTOMIZE ME (for running behind a NAT router)
#alias=12.34.56.78   # CUSTOMIZE ME
alias="domain1.net"   # CUSTOMIZE ME
#alias="domain2.com"   # CUSTOMIZE ME

db_default_url="postgres://dbuser:dbpass@dbhostname/dbname"

####### Modules Section ########

#set module path
mpath="/usr/local/lib/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"
/* do not append from tag to the RR (no need for this script) */
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)
  



#### PGSQL module
loadmodule "db_postgres.so"

#### MYSQL module
#loadmodule "db_mysql.so"

#### HTTPD module
#loadmodule "httpd.so"
#modparam("httpd", "port", 8888)

#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode",   2)
modparam("usrloc", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME
#modparam("usrloc", "hash_size", 11)   # increases size of userloc hash table


#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
modparam("registrar", "received_avp", "$avp(received_nh)")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)

#### 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", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME



#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")



#### ALIAS module
loadmodule "alias_db.so"
modparam("alias_db", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME



#### DOMAIN module
loadmodule "domain.so"
modparam("domain", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME
modparam("domain", "db_mode", 1)   # Use caching
modparam("auth_db|usrloc|uri", "use_domain", 1)



#### PRESENCE modules
loadmodule "xcap.so"
loadmodule "presence.so"
loadmodule "presence_xml.so"
modparam("xcap|presence", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME
modparam("presence_xml", "force_active", 1)
modparam("presence", "server_address", "sip:127.0.0.1:5060") # CUSTOMIZE ME
#modparam("presence", "subs_htable_size", 11)   # increases size of presence subs hash table
#modparam("presence", "pres_htable_size", 11)   # increases size of presence pres hash table
#modparam("presence", "max_expires_subscribe", 600)
#modparam("presence", "max_expires_publish", 600)


#### 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", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME



####  NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG")
modparam("nathelper", "sipping_from", "sip:pinger@127.0.0.1") #CUSTOMIZE ME
modparam("nathelper", "received_avp", "$avp(received_nh)")

loadmodule "rtpproxy.so"
modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:12221") # CUSTOMIZE ME (make sure rtpproxy port matches server)


####  DIALPLAN module
loadmodule "dialplan.so"
modparam("dialplan", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME



####  DYNAMMIC ROUTING module
loadmodule "drouting.so"
modparam("drouting", "db_url", "postgres://dbuser:dbpass@dbhostname/dbname") # CUSTOMIZE ME



####  MI_HTTP module
#loadmodule "mi_http.so"


#### UDP module
loadmodule "proto_udp.so"


#### TCP module
loadmodule "proto_tcp.so" 
#modparam("proto_tcp", "tcp_send_timeout", 200)
#modparam("proto_tcp", "tcp_max_msg_chunks", 8)


#### TLS modules
loadmodule "proto_tls.so"
loadmodule "tls_mgm.so"
modparam("tls_mgm","verify_cert", "1")
modparam("tls_mgm","require_cert", "0")
modparam("tls_mgm","tls_method", "TLSv1")
#modparam("tls_mgm","ca_dir", "/usr/local/etc/opensips/tls/user/")
modparam("tls_mgm","certificate", "/usr/local/etc/opensips/tls/user/user-cert.pem")
modparam("tls_mgm","private_key", "/usr/local/etc/opensips/tls/user/user-privkey.pem")
modparam("tls_mgm","ca_list", "/usr/local/etc/opensips/tls/user/user-calist.pem")
#modparam("tls_mgm", "tls_send_timeout", 200)
#modparam("tls_mgm", "tls_handshake_timeout", 119)
#modparam("proto_tls", "tls_max_msg_chunks", 8)
 


####### Routing Logic ########

# main request routing logic

route{
	force_rport();
	if (nat_uac_test("23")) {
		if (is_method("REGISTER")) {
			fix_nated_register();
			setbflag(NAT);
		} else {
			fix_nated_contact();
			setflag(NAT);
		}
	}
 	

	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		exit;
	}

	if (has_totag()) {
		# sequential request withing a dialog should
		# take the path determined by record-routing
		if (loose_route()) {
			
			# 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_method("BYE")) {
				# do accounting even if the transaction fails
				do_accounting("db","failed");
				
			} 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();
			}

			if (check_route_param("nat=yes")) 
				setflag(NAT);

			# route it out to whatever destination was set by loose_route()
			# in $du (destination URI).
			route(relay);
		} else {
			if (is_method("SUBSCRIBE") && $rd == "127.0.0.1:5060") { # CUSTOMIZE ME
				# in-dialog subscribe requests
				route(handle_presence);
				exit;
			}
			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")  || is_from_gw() ) ) {
		
		if (is_from_local())
		{
			
			# authenticate if from local subscriber
			# authenticate all initial non-REGISTER request that pretend to be
			# generated by local subscriber (domain from FROM URI is local)
			if (!proxy_authorize("", "subscriber")) {
				proxy_challenge("", "0");
				exit;
			}
			if (!db_check_from()) {
				sl_send_reply("403","Forbidden auth ID");
				exit;
			}
		
			consume_credentials();
			# caller authenticated
			
		} else {
			# if caller is not local, then called number must be local
			
			if (!is_uri_host_local()) {
				send_reply("403","Rely forbidden");
				exit;
			}
		}

	}

	# 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();

	# account only INVITEs
	if (is_method("INVITE")) {
		
		# create dialog with timeout
		if ( !create_dialog("B") ) {
			send_reply("500","Internal Server Error");
			exit;
		}
		
		do_accounting("db");
		
	}

	
	if (!is_uri_host_local()) {
		append_hf("P-hint: outbound\r\n"); 
		
		# if you have some interdomain connections via TLS
		## CUSTOMIZE IF NEEDED
		##if ($rd=="tls_domain1.net"
		## || $rd=="tls_domain2.net"
		##) {
		##	force_send_socket(tls:127.0.0.1:5061); # CUSTOMIZE
		##}
		
		route(relay);
	}

	# requests for my domain
	
	if( is_method("PUBLISH|SUBSCRIBE"))
			route(handle_presence);

	if (is_method("REGISTER"))
	{
		# authenticate the REGISTER requests
		if (!www_authorize("", "subscriber"))
		{
			www_challenge("", "0");
			exit;
		}
		
		if (!db_check_to()) 
		{
			sl_send_reply("403","Forbidden auth ID");
			exit;
		}

		if ( proto==TCP || proto==TLS || 0 ) setflag(TCP_PERSISTENT);

		if (isflagset(NAT)) {
			setbflag(SIP_PING_FLAG);
		}

		if (!save("location"))
			sl_reply_error();

		exit;
	}

	if ($rU==NULL) {
		# request with no Username in RURI
		sl_send_reply("484","Address Incomplete");
		exit;
	}

	
	# apply DB based aliases
	alias_db_lookup("dbaliases");

	
	# apply transformations from dialplan table
	dp_translate("0","$rU/$rU");

	
	if ($rU=~"^\+[1-9][0-9]+$") {
		
		if (!do_routing("0")) {
			send_reply("500","No PSTN Route found");
			exit;
		}
		
		route(relay);
		exit;
	}
	 

	# do lookup with method filtering
	if (!lookup("location","m")) {
		if (!db_does_uri_exist()) {
			send_reply("420","Bad Extension");
			exit;
		}
		
		# redirect to a different VM system
		$du = "sip:127.0.0.2:5060"; # CUSTOMIZE ME
		route(relay);
		
	} 

	if (isbflagset(NAT)) setflag(NAT);

	# when routing via usrloc, log the missed calls also
	do_accounting("db","missed");
	
	route(relay);
}


route[relay] {
	# for INVITEs enable some additional helper routes
	if (is_method("INVITE")) {
		
		if (isflagset(NAT)) {
			rtpproxy_offer("ro");
		}

		t_on_branch("per_branch_ops");
		t_on_reply("handle_nat");
		t_on_failure("missed_call");
	}

	if (isflagset(NAT)) {
		add_rr_param(";nat=yes");
		}

	if (!t_relay()) {
		send_reply("500","Internal Error");
	};
	exit;
}


# Presence route
route[handle_presence]
{
	if (!t_newtran())
	{
		sl_reply_error();
		exit;
	}

	if(is_method("PUBLISH"))
	{
		handle_publish();
	}
	else
	if( is_method("SUBSCRIBE"))
	{
		handle_subscribe();
	}

	exit;
}


branch_route[per_branch_ops] {
	xlog("new branch at $ru\n");
}


onreply_route[handle_nat] {
	if (nat_uac_test("1"))
		fix_nated_contact();
	if ( isflagset(NAT) )
		rtpproxy_answer("ro");
	xlog("incoming reply\n");
}


failure_route[missed_call] {
	if (t_was_cancelled()) {
		exit;
	}

	# uncomment the following lines if you want to block client 
	# redirect based on 3xx replies.
	##if (t_check_status("3[0-9][0-9]")) {
	##t_reply("404","Not found");
	##	exit;
	##}

	
	# redirect the failed to a different VM system
	if (t_check_status("486|408")) {
		$du = "sip:127.0.0.2:5060"; # CUSTOMIZE ME
		# do not set the missed call flag again
		route(relay);
	}
}



local_route {
	if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
		
		acc_db_request("200 Dialog Timeout", "acc");
		
	}
}