-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkamailio.cfg
1079 lines (931 loc) · 28.5 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
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!KAMAILIO
#######################
# define settings
#######################
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_ACCDB
#!define WITH_DISPATCHER
#!define WITH_GEOIP2
#!define WITH_ANTIFLOOD
#!define WITH_IPAUTH
#!define WITH_EXEC
#!define WITH_BLOCK3XX
#!define WITH_BLOCK401407
# *** 디버그 모드로 실행하려면:
# - WITH_DEBUG로 정의
# - 디버그 수준이 3으로 증가했지만 로그는 여전히 syslog로 전송됨
# - cfgtrace endabled로 로드된 디버거 모듈
#
# *** mysql을 활성화하려면:
# - WITH_MYSQL 정의
#
# *** 인증을 실행하려면:
# - mysql 사용
# - WITH_AUTH 정의
# - 'tftctl' 또는 'tftcli'를 사용하여 사용자 추가
#
# *** IP 인증을 실행하려면:
# - mysql 사용
# - 인증 사용
# - WITH_IPAUTH 정의
# - 그룹 ID가 '1'인 IP 주소를 '주소' 테이블에 추가합니다.
#
# *** 영구 사용자 위치를 실행하려면:
# - mysql 사용
# - WITH_USRLOCDB 정의
#
# *** 존재 서버를 실행하려면:
# - mysql 사용
# - WITH_Presence 정의
# - 존재 처리에서 구성의 수정된 헤더 또는 본문을 사용해야 하는 경우:
# - WITH_MSGREBUILD로 정의
#
# *** nat traversal 실행을 활성화하려면:
# - WITH_NAT 정의
# - NAT SIP 옵션 킵얼라이브 옵션: WITH_NATSIPPING
# - RTP Proxy 설치: http://www.rtpproxy.org
# - RTP 프록시 시작:
# rtppproxy -l _your_public_ip_ -s udp:localhost:7722
#
# *** Nat Traversal에 RTP Proxy 대신 RTPEngine을 사용하려면 다음과 같이 하십시오.
# - RTP 엔진으로 정의
# - RTP 엔진 설치: https://github.com/sipwise/rtpengine
# - RTP 엔진 시동:
# rtp engine --http-ng=127.0.0.1:2223...
#
# *** PSTN 게이트웨이 라우팅을 실행하려면:
# - WITH_PSTN 정의
# - pstn.gw_ip 값을 설정합니다.
# - 경로 확인[regexp 라우팅 조건의 PSTN]
#
# *** 데이터베이스 별칭 검색을 실행하려면:
# - mysql 사용
# - WITH_ALIASDB 정의
#
# *** 단축 다이얼 조회 실행을 활성화하려면:
# - mysql 사용
# - WITH_SPEEDDIAL 정의
#
# *** 다중 도메인 지원을 실행하려면:
# - mysql 사용
# - MULTIDOMAIN으로 정의
#
# *** TLS 지원 실행을 활성화하려면:
# - 필요에 따라 CFGDIR/tls.cfg 조정
# - WITH_TLS 정의
#
# *** JSONRPC over HTTP(S) 지원을 사용하려면 다음을 실행하십시오.
# - WITH_JSONRPC 정의
# - 액세스 정책에 대한 event_route[xhttp:request] 조정
#
# *** 홍수 방지 감지 실행을 활성화하려면:
# - 필요에 따라 pike 및 htable=>ipban 설정을 조정합니다(기본값은 다음과 같습니다).
# 2초 안에 16개 이상의 요청을 차단하고 300초 동안 금지)
# - _Antiflood로 정의
#
# *** 3XX 리디렉션 응답을 차단하려면 다음을 수행합니다.
# - WITH_BLOCK3XX 정의
#
# *** 401 및 407 인증 응답을 차단하려면 다음을 수행합니다.
# - WITH_BLOCK401407 정의
#
# *** 음성 메일 라우팅을 실행하려면:
# - _VOICEMAIL로 정의
# - 음성 메일의 값을 설정합니다.srv_ip
# - 음성 메일의 값을 조정합니다.srv_port
#
# *** 회계 실행을 향상시키려면:
# - mysql 사용
# - WITH_ACCDB 정의
# - 데이터베이스에 다음 열 추가
#!ifdef ACCDB_COMMENT
ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
#!endif
import_file "kamailio-local.cfg"
#!ifdef WITH_DEBUG
#!define DBGLEVEL 3
#!else
#!define DBGLEVEL 2
#!endif
#!ifdef WITH_MYSQL
#!trydef DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
#!endif
#!ifdef WITH_MULTIDOMAIN
#!define MULTIDOMAIN 1
#!else
#!define MULTIDOMAIN 0
#!endif
#!define FLT_ACC 1
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3
#!define FLT_NATS 5
#!define FLB_NATB 6
#!define FLB_NATSIPPING 7
#######################
# variable settings
#######################
debug=DBGLEVEL
log_stderror=no
memdbg=5
memlog=5
log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "
children=8
tcp_connection_lifetime=3605
tcp_max_connections=2048
#!ifdef WITH_JSONRPC
tcp_accept_no_cl=yes
#!endif
#!ifdef WITH_TLS
enable_tls=yes
tls_max_connections=2048
#!endif
enable_sctp=no
#!ifdef WITH_PSTN
pstn.gw_ip = "" desc "PSTN GW Address"
pstn.gw_port = "" desc "PSTN GW Port"
#!endif
#!ifdef WITH_VOICEMAIL
voicemail.srv_ip = "" desc "VoiceMail IP Address"
voicemail.srv_port = "5060" desc "VoiceMail Port"
#!endif
#######################
# load module
#######################
#!ifdef WITH_MYSQL
loadmodule "db_mysql.so"
#!endif
#!ifdef WITH_EXEC
loadmodule "exec.so"
#!endif
#!ifdef WITH_JSONRPC
loadmodule "xhttp.so"
#!endif
loadmodule "jsonrpcs.so"
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "textopsx.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "acc.so"
loadmodule "counters.so"
#!ifdef WITH_AUTH
loadmodule "auth.so"
loadmodule "auth_db.so"
#!ifdef WITH_IPAUTH
loadmodule "permissions.so"
#!endif
#!endif
#!ifdef WITH_ALIASDB
loadmodule "alias_db.so"
#!endif
#!ifdef WITH_SPEEDDIAL
loadmodule "speeddial.so"
#!endif
#!ifdef WITH_MULTIDOMAIN
loadmodule "domain.so"
#!endif
#!ifdef WITH_PRESENCE
loadmodule "presence.so"
loadmodule "presence_xml.so"
#!endif
#!ifdef WITH_NAT
loadmodule "nathelper.so"
#!ifdef WITH_RTPENGINE
loadmodule "rtpengine.so"
#!else
loadmodule "rtpproxy.so"
#!endif
#!endif
#!ifdef WITH_TLS
loadmodule "tls.so"
#!endif
#!ifdef WITH_ANTIFLOOD
loadmodule "htable.so"
loadmodule "pike.so"
#!endif
#!ifdef WITH_DEBUG
loadmodule "debugger.so"
#!endif
#!ifdef WITH_DISPATCHER
loadmodule "dispatcher.so"
#!endif
#!ifdef WITH_DIALPLAN
loadmodule "dialplan.so"
#!endif
#!ifdef WITH_GEOIP2
loadmodule "geoip2.so"
#!endif
#######################
# module param
#######################
# ----- json params -----
modparam("jsonrpcs", "pretty_format", 1)
# modparam("jsonrpcs", "fifo_name", "/run/kamailio/kamailio_rpc.fifo") /* 경로를 RPC fifo 제어 파일로 설정 */
# modparam("jsonrpcs", "dgram_socket", "/run/kamailio/kamailio_rpc.sock") /* 경로를 RPC unix 소켓 제어 파일로 설정 */
#!ifdef WITH_JSONRPC
modparam("jsonrpcs", "transport", 7)
#!endif
# ----- ctl params -----
# modparam("ctl", "binrpc", "unix:/run/kamailio/kamailio_ctl") /* 경로를 RPC unix 소켓 제어 파일로 설정 */
# ----- sanity params -----
modparam("sanity", "autodrop", 0)
# ----- tm params -----
modparam("tm", "failure_reply_mode", 3) # 이전 직렬 포킹 레그에서 분기 자동 정렬
modparam("tm", "fr_timer", 2000) # 기본 재전송 시간 초과: 2초
modparam("tm", "fr_inv_timer", 120000) # 1xx 이후 기본 초대 재전송 시간 초과: 120초
# ----- rr params -----
modparam("rr", "enable_full_lr", 0) # next param을 1로 설정하여 ;lr param에 값을 추가합니다(일부 UA에 도움이 됨).
modparam("rr", "append_fromtag", 0) # 태그에서 RR에 추가하지 않음(이 스크립트는 필요 없음)
# ----- registrar params -----
modparam("registrar", "method_filtering", 1)
# modparam("registrar", "append_branches", 0) /* 위치를 통한 병렬 포킹을 비활성화하려면 다음 줄의 주석을 해제합니다.
# modparam("registrar", "max_contacts", 10) /* AOR당 10개 이상의 접촉이 허용되지 않도록 다음 줄의 주석을 해제합니다 */
modparam("registrar", "max_expires", 3600) /* 등록 만료에 대한 최대값 */
modparam("registrar", "gruu_enabled", 0) /* GRUU를 활성화하려면 1로 설정합니다. */
modparam("registrar", "use_path", 1) /* 경로 처리를 비활성화하려면 0으로 설정합니다. */
modparam("registrar", "path_mode", 0) /* 지원되는 헤더에 나열되지 않은 경우에도 경로 저장 */
# ----- acc params ----- # ACC 모듈은 syslog 및 SQL 과 같은 다양한 백엔드에 트랜잭션 정보를 설명하는 데 사용됩니다
modparam("acc", "early_media", 0)
modparam("acc", "report_ack", 0)
modparam("acc", "report_cancels", 0)
/* 기본적으로 ww는 순차적 요청의 직접을 조정하지 않습니다.
* 이 매개 변수를 활성화하는 경우 "tftp_fromtag"를 활성화해야 합니다.
* "rr" 모듈 */
modparam("acc", "detect_direction", 0)
modparam("acc", "log_flag", FLT_ACC) /* 계정 트리거(실행) */
modparam("acc", "log_missed_flag", FLT_ACCMISSED)
modparam("acc", "log_extra", "src_user=$fU;src_domain=$fd;src_ip=$si;" "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
#!ifdef WITH_ACCDB /* 향상된 DB 계정 */
modparam("acc", "db_flag", FLT_ACC)
modparam("acc", "db_missed_flag", FLT_ACCMISSED)
modparam("acc", "db_url", DBURL)
modparam("acc", "db_extra", "src_user=$fU;src_domain=$fd;src_ip=$si;" "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
#!endif
# ----- usrloc params -----
modparam("usrloc", "timer_interval", 60)
modparam("usrloc", "timer_procs", 1)
modparam("usrloc", "use_domain", MULTIDOMAIN)
#!ifdef WITH_USRLOCDB
modparam("usrloc", "db_url", DBURL)
modparam("usrloc", "db_mode", 2)
#!endif
## auth params
# ----- auth_db params -----
#!ifdef WITH_AUTH
modparam("auth_db", "db_url", DBURL)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db", "load_credentials", "")
modparam("auth_db", "use_domain", MULTIDOMAIN)
# ----- permissions params -----
#!ifdef WITH_IPAUTH
modparam("permissions", "db_url", DBURL)
modparam("permissions", "load_backends", 1)
#!endif
#!endif
# ----- alias_db params -----
#!ifdef WITH_ALIASDB
modparam("alias_db", "db_url", DBURL)
modparam("alias_db", "use_domain", MULTIDOMAIN)
#!endif
# ----- speeddial params -----
#!ifdef WITH_SPEEDDIAL # 이 모듈은 서버의 단축 다이얼 기능을 제공합니다. 사용자는 짧은 숫자(2자리)와 SIP 주소 쌍으로 구성된 레코드를 Kamailio 테이블에 저장할 수 있습니다.
modparam("speeddial", "db_url", DBURL)
modparam("speeddial", "use_domain", MULTIDOMAIN)
#!endif
# ----- domain params -----
#!ifdef WITH_MULTIDOMAIN
modparam("domain", "db_url", DBURL)
modparam("domain", "register_myself", 1)
#!endif
# ----- presence params -----
#!ifdef WITH_PRESENCE # 프레즌스 모듈은 SIP 이벤트 알림의 핵심 기능을 구현합니다. PUBLISH 및 SUBSCRIBE 메시지를 처리하고 일반적이고 이벤트 독립적인 방식으로 NOTIFY 메시지를 생성합니다.
modparam("presence", "db_url", DBURL)
modparam("presence_xml", "db_url", DBURL)
modparam("presence_xml", "force_active", 1)
#!endif
# ----- rtpengine params -----
# ----- nathelper params -----
#!ifdef WITH_NAT
#!ifdef WITH_RTPENGINE
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
#!else
modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
#!endif
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:[email protected]")
modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
modparam("usrloc", "nat_bflag", FLB_NATB)
#!endif
# ----- tls params -----
#!ifdef WITH_TLS
modparam("tls", "config", "/etc/kamailio/tls.cfg")
#!endif
# ----- pike params -----
#!ifdef WITH_ANTIFLOOD # pike 모듈은 들어오는 모든(또는 선택된 것들) 요청의 IP 소스를 추적하고 제한을 초과하는 IP 소스를 차단합니다.
modparam("pike", "sampling_time_unit", 10) # 샘플링(또는 샘플링 정확도)에 사용되는 시간(초)입니다.
modparam("pike", "reqs_density_per_unit", 30) # sampling_time_unit 해당 IP에서 들어오는 모든 요청을 차단하기 전에 허용해야 하는 요청 수 입니다
modparam("pike", "remove_latency", 100) # 해당 IP 주소의 마지막 요청 후 IP 주소가 메모리에 유지되는 기간을 지정합니다
# ----- htable params -----
modparam("htable", "htable", "ipban=>size=8;autoexpire=300;") # ipban 테이블 생성
#!endif
# ----- debugger params -----
#!ifdef WITH_DEBUG
modparam("debugger", "cfgtrace", 1)
modparam("debugger", "log_level_name", "exec")
#!endif
# ----- dispatcher params -----
#!ifdef WITH_DISPATCHER
# modparam("dispatcher", "db_url", DBURL) # 데이터베이스 매개변수에 DBURL 변수 사용
modparam("dispatcher", "list_file", "/etc/kamailio/settings/dispatcher.list")
modparam("dispatcher", "ds_ping_from", GWADDR) # ip/port 수정
modparam("dispatcher", "ds_ping_interval", 10) # 상태를 확인하기 위해 대상을 ping하는 빈도
modparam("dispatcher", "ds_ping_method", "OPTIONS") # SIP 옵션 ping 전송
modparam("dispatcher", "ds_probing_threshold", 1) # 다운을 고려하기 전에 연속적으로 실패한 ping이 몇 개 필요합니까?
modparam("dispatcher", "ds_inactive_threshold", 1) # 그것을 고려하기 전에 연속해서 얼마나 많은 성공적인 핑이 필요합니까?
modparam("dispatcher", "ds_ping_latency_stats", 1) # 대기 시간에 대한 통계 사용
modparam("dispatcher", "ds_probing_mode", 1) # 상태가 알려진 경우(상태의 변화를 감지하기 위해) 게이트웨이를 계속 ping합니다.
modparam("dispatcher", "flags", 2) # retransimission 처리 시 자동 처리
#!endif
# ----- dialplan params -----
#!ifdef WITH_DIALPLAN
modparam("dialplan", "db_url", DBURL); # DBURL 변수의 다이얼플랜 데이터베이스
#!endif
# ----- geoip2 params -----
#!ifdef WITH_GEOIP2
modparam("geoip2", "path", "/etc/kamailio/utils/GeoLite2-City/GeoLite2-City.mmdb");
#!endif
#######################
# routing logic
#######################
request_route {
# search GEOIP
route(GEOIP2);
# per request initial checks
route(REQINIT);
# NAT detection
route(NATDETECT);
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans()) { # 현재 요청이 트랜잭션과 연결되어 있으면 true를 반환합니다.
route(RELAY);
}
exit;
}
# handle retransmissions
if (!is_method("ACK")) {
if(t_precheck_trans()) { # 현재 처리된 메시지가 다른 프로세스에서 처리되고 있는지 확인합니다. 이 기능은 트랜잭션이 생성되기 전에 재전송을 포착하는 데 유용합니다.
t_check_trans();
exit;
}
t_check_trans();
}
# handle requests within SIP dialogs
route(WITHINDLG);
# authentication
route(AUTH);
# record Routing
route(ROUTING);
route(SIPOUT); # 외부 도메인으로 요청 발송
### 내 로컬 도메인에 대한 요청
# PRESENCE 관련 요청 처리
route(PRESENCE);
# 등록을 처리하다
route(REGISTRAR);
if ($rU==$null) {
# RURI에 사용자 이름이 없는 요청
sl_send_reply("484","Address Incomplete");
exit;
}
# PSTN에 목적지를 발송하다
route(PSTN);
# 사용자 위치 서비스
route(LOCATION);
}
route[RELAY] {
# 전달된 요청에 대해 추가 이벤트 경로 사용
# - 직렬 포킹, RTP 릴레이 처리, a.s.o.
if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
}
if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
}
if (is_method("INVITE")) {
if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
}
if (!t_relay()) {
sl_reply_error();
}
exit;
}
route[GEOIP2]{
# GEO IP 로 KOREA IP 찾기
#!ifdef WITH_GEOIP2
if(geoip2_match("$si", "src")){
if($gip2(src=>cc)=="KR" || src_ip==127.0.0.1){
return;
} else {
xlog("Traffic is from IP $si : $gip2(src=>cc) ==> Send 403 Forbidden");
sl_reply("403", "Forbidden");
exit;
}
} else {
xlog("No GeoIP Match for $si");
sl_reply("403", "Forbidden");
exit;
}
#!endif
return;
}
route[ROUTING]{
# Dialog 형성 요청에 대한 레코드 라우팅(라우팅된 경우)
# - 사전 로드된 경로 헤더 제거
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE")) {
record_route();
}
# account only INVITEs
if (is_method("INVITE")) {
setflag(FLT_ACC);
xlog('this is invite groupId really: $avp(s:groupId)');
t_on_failure("DISPATCH_FAILURE");
ds_select_dst($avp(s:groupId), 4); # 발송인에게 무작위로 dispatcher 대상 가져오기
route(RELAY);
exit;
}
return;
}
# SIP 요청별 초기 검사
route[REQINIT] {
set_reply_no_connect(); # 응답을 보내기 위한 연결 없음
# 대칭 신호를 시행하다
# - 요청의 원본 주소로 회신합니다.
force_rport();
#!ifdef WITH_ANTIFLOOD
# 동일한 IP에서 플러드 감지 및 잠시 트래픽 금지
# pstn 게이트웨이와 같은 신뢰할 수 있는 피어 확인을 제외해야 합니다.
# - 로컬 호스트 제외
if(src_ip!=myself) {
if($sht(ipban=>$si)!=$null) {
# ip is already blocked
xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
exit;
}
if (!pike_check_req()) {
xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
$sht(ipban=>$si) = 1;
exit;
}
}
#!endif
if($ua =~ "friendly|scanner|sipcli|sipvicious|VaxSIPUserAgent") {
# 스캐너에 대한 자동 삭제 - 회신하려면 다음 줄 주석 해제
# sl_send_reply("200", "OK");
exit;
}
# hops 10 초과 시 종료
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
# 자기 자신의 OPTIONS -> Keepalive 종료
if(is_method("OPTIONS") && uri==myself && $rU==$null) {
sl_send_reply("200","Keepalive");
exit;
}
# SIP 규격 확인
if(!sanity_check("17895", "7")) {
xlog("Malformed SIP request from $si:$sp\n");
exit;
}
# INVITE
# group Id settingx
# destination server 확인.
#!ifdef WITH_EXEC
if (is_method("INVITE")) {
exec_avp("node /etc/kamailio/settings/search_dispatcher.js $fu", "$avp(s:groupId)");
xlog('invite groupId: $fu');
xlog('invite groupId: $avp(s:groupId)');
if ($avp(s:groupId) == 'false') {
send_reply("404", "Not Found");
exit;
}
}
# OPTIONS
# group Id settingx
# destination server 확인.
if (is_method("OPTIONS")) {
exec_avp("node /etc/kamailio/settings/search_dispatcher.js $fu", "$avp(s:groupId)");
if ($avp(s:groupId) == 'false') {
send_reply("404", "Not Found");
exit;
} else {
sl_send_reply("200", "OK");
exit;
}
}
#!endif
}
# SIP 대화 상자 내에서 요청 처리
route[WITHINDLG] {
if (!has_totag()) return;
# Dialog 가 있는 순차적 요청:
# record-routing 의 기록을 통해 순차적으로 수행
if (loose_route()) {
route(DLGURI); # dialog 요청에 대한 URI 업데이트
if (is_method("BYE")) {
setflag(FLT_ACC); # do accounting ...
setflag(FLT_ACCFAILED); # ...트렌잭션이 실패하더라도
} else if ( is_method("ACK") ) { # ACK가 상태 비저장 상태로 전달됨
route(NATMANAGE); # NAT 트래버설을 위한 RTP 프록시 제어 및 신호 업데이트
} else if ( is_method("NOTIFY") ) {
record_route(); # RFC 6665에 따라 대화 내 NOTIFY를 위한 Record-Route를 추가합니다.
}
route(RELAY);
exit;
}
if (is_method("SUBSCRIBE") && uri == myself) {
route(PRESENCE); # dialog 내 구독 요청
exit;
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# 느슨한 경로는 없지만 상태 그대로의 ACK;
# 487 이후의 ACK여야 합니다.
# 또는 업스트림 서버에서 404
route(RELAY);
exit;
} else {
exit; # 일치하는 트랜잭션이 없는 ACK... 무시하고 버리다
}
}
sl_send_reply("404","Not here");
exit;
}
# SIP 등록 처리
route[REGISTRAR] {
if (!is_method("REGISTER")) return;
if(isflagset(FLT_NATS)) {
setbflag(FLB_NATB);
#!ifdef WITH_NATSIPPING
# SIP NAT ping 수행
setbflag(FLB_NATSIPPING);
#!endif
}
if (!save("location")) {
sl_reply_error();
}
exit;
}
# 사용자 위치 서비스
route[LOCATION] {
#!ifdef WITH_SPEEDDIAL
# 단축 다이얼 검색 - 두 자리 내선 번호
if($rU=~"^[0-9][0-9]$") {
if(sd_lookup("speed_dial")) {
route(SIPOUT); # 외부 도메인으로 요청 발송
}
}
#!endif
#!ifdef WITH_ALIASDB
# DB 기반 별칭으로 검색
if(alias_db_lookup("dbaliases")) {
route(SIPOUT); # 외부 도메인으로 요청 발송
}
#!endif
$avp(oexten) = $rU;
if (!lookup("location")) {
$var(rc) = $rc;
route(TOVOICEMAIL);
t_newtran();
switch ($var(rc)) {
case -1:
case -3:
send_reply("404", "Not Found");
exit;
case -2:
send_reply("405", "Method Not Allowed");
exit;
}
}
# usrloc을 통해 라우팅할 때 부재중 통화도 기록합니다.
if (is_method("INVITE")) {
setflag(FLT_ACCMISSED);
}
route(RELAY);
exit;
}
# PUBLISH, SUBSCRIBEE 처리
route[PRESENCE] {
if(!is_method("PUBLISH|SUBSCRIBE")) return;
if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {
route(TOVOICEMAIL);
sl_send_reply("404", "No voicemail service"); # 음성 메일 서버가 구성되지 않은 경우 여기로 반환됩니다.
exit;
}
#!ifdef WITH_PRESENCE
#!ifdef WITH_MSGREBUILD
msg_apply_changes(); # 요청 헤더 또는 본문이 수정된 경우 변경 사항 적용
#!endif
if (!t_newtran()) {
sl_reply_error();
exit;
}
if(is_method("PUBLISH")) {
handle_publish();
t_release();
} else if(is_method("SUBSCRIBE")) {
handle_subscribe();
t_release();
}
exit;
#!endif
# PRESENCE이 활성화된 경우 이 파트는 실행되지 않습니다.
if (is_method("PUBLISH") || $rU==$null) {
sl_send_reply("404", "Not here");
exit;
}
return;
}
# IP 인증 및 사용자 인증
route[AUTH] {
#!ifdef WITH_AUTH
#!ifdef WITH_IPAUTH
if((!is_method("REGISTER")) && allow_source_address("200")) { # 소스 IP 허용됨
return;
}
#!endif
if (is_method("REGISTER") || from_uri==myself) {
# 요청을 인증하다
if (!auth_check("$fd", "subscriber", "1")) {
auth_challenge("$fd", "0"); # REGISTER 요청에 대해 401 응답을 보내고 다른 유형의 SIP 요청에 대해 407 응답을 보내 인증을 시도합니다.
exit;
}
# 사용자 인증됨 - 인증 헤더 제거
if(!is_method("REGISTER|PUBLISH"))
consume_credentials(); # 이 기능은 서버에서 처리 중인 메시지에서 이전에 승인된 자격 증명 헤더를 제거합니다.
}
# 발신자가 로컬 가입자가 아닌 경우, 발신자가 전화하는지 확인합니다.
# 로컬 목적지, 그렇지 않으면 거부, 여기서 공개 릴레이가 아닙니다.
if (from_uri!=myself && uri!=myself && $Ri!=$sel(cfg_get.junho.gw_ip)) {
xlog("RI: $Ri");
sl_send_reply("403","Not relaying");
exit;
}
#!else
# 인증 사용 안 함 - 외부 네트워크에 전혀 릴레이하지 않음
if(uri!=myself) {
sl_send_reply("403","Not relaying");
exit;
}
#!endif
return;
}
# 발신자 NAT 탐지
route[NATDETECT] {
#!ifdef WITH_NAT
if (nat_uac_test("19")) {
if (is_method("REGISTER")) {
fix_nated_register();
} else {
if(is_first_hop()) {
set_contact_alias();
}
}
setflag(FLT_NATS);
}
#!endif
return;
}
# NAT 트래버설을 위한 RTP 프록시 제어 및 신호 업데이트
route[NATMANAGE] {
#!ifdef WITH_NAT
if (is_request()) {
if(has_totag()) {
if(check_route_param("nat=yes")) {
setbflag(FLB_NATB);
}
}
}
if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return;
#!ifdef WITH_RTPENGINE
if(nat_uac_test("8")) {
rtpengine_manage("SIP-source-address replace-origin replace-session-connection");
} else {
rtpengine_manage("replace-origin replace-session-connection");
}
#!else
if(nat_uac_test("8")) {
rtpproxy_manage("co");
} else {
rtpproxy_manage("cor");
}
#!endif
if (is_request()) {
if (!has_totag()) {
if(t_is_branch_route()) {
add_rr_param(";nat=yes");
}
}
}
if (is_reply()) {
if(isbflagset(FLB_NATB)) {
if(is_first_hop())
set_contact_alias();
}
}
if(isbflagset(FLB_NATB)) {
# NAT 트래버설 관련 대화 상자에 연결 메시지 없음
if (is_request()) {
if(has_totag()) {
set_forward_no_connect();
}
}
}
#!endif
return;
}
# dialog 요청에 대한 URI 업데이트
route[DLGURI] {
#!ifdef WITH_NAT
if(!isdsturiset()) {
handle_ruri_alias();
}
#!endif
return;
}
# 외부 도메인으로 라우팅
route[SIPOUT] {
if (uri==myself || $Ri==$sel(cfg_get.junho.gw_ip)) return;
append_hf("P-Hint: outbound\r\n");
route(RELAY);
exit;
}
# PSTN GW 라우팅
route[PSTN] {
#!ifdef WITH_PSTN
# PSTN GW IP가 정의되어 있는지 확인합니다.
if (strempty($sel(cfg_get.pstn.gw_ip))) {
xlog("SCRIPT: PSTN routing enabled but pstn.gw_ip not defined\n");
return;
}
# '+' 또는 '00'으로 시작하는 PSTN 다이얼 번호로 라우팅
# (국제 형식)
# - PSTN 라우팅에 대한 전화 걸기 규칙과 일치하도록 조건을 업데이트합니다.
if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$")) return;
# only local users allowed to call
if(from_uri!=myself) {
sl_send_reply("403", "Not Allowed");
exit;
}
# pstn 게이트웨이의 대상 번호 정규화
# - 선행 00을 +로 변환합니다.
if (starts_with("$rU", "00")) {
strip(2);
prefix("+");
}
if (strempty($sel(cfg_get.pstn.gw_port))) {
$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
} else {
$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":"
+ $sel(cfg_get.pstn.gw_port);
}
route(RELAY);
exit;
#!endif
return;
}
# JSONRPC over HTTP(S) 라우팅
#!ifdef WITH_JSONRPC
event_route[xhttp:request] {
set_reply_close();
set_reply_no_connect();
if(src_ip!=127.0.0.1) {
xhttp_reply("403", "Forbidden", "text/html",
"<html><body>Not allowed from $si</body></html>");
exit;
}
if ($hu =~ "^/RPC") {
jsonrpc_dispatch();
exit;
}
xhttp_reply("200", "OK", "text/html",
"<html><body>Wrong URL $hu</body></html>");
exit;
}
#!endif
# 음성 메일 서버로 라우팅
route[TOVOICEMAIL] {
#!ifdef WITH_VOICEMAIL
if(!is_method("INVITE|SUBSCRIBE")) return;
# 음성 메일 서버 IP가 정의되었는지 확인합니다.
if (strempty($sel(cfg_get.voicemail.srv_ip))) {
xlog("SCRIPT: VoiceMail routing enabled but IP not defined\n");
return;
}
if(is_method("INVITE")) {
if($avp(oexten)==$null) return;
$ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip)
+ ":" + $sel(cfg_get.voicemail.srv_port);
} else {
if($rU==$null) return;
$ru = "sip:" + $rU + "@" + $sel(cfg_get.voicemail.srv_ip)
+ ":" + $sel(cfg_get.voicemail.srv_port);
}