opensips.cfg
4.83 KB
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
####### Routing Logic ########
# main request routing logic
route{
if (!mf_process_maxfwd_header("10")) {
send_reply("483","Too Many Hops");
exit;
}
if (is_method("OPTIONS") && is_myself("$rd")) {
sl_send_reply("200","NAT Ping");
exit;
}
t_on_branch("rtpengine");
if (is_method("REGISTER")) {
if (!ds_is_in_list("$si", "", "1")) {
cache_store("local", "ip_$(fu{uri.user})", "$si");
cache_store("local", "port_$(fu{uri.user})", "$sp");
}
}
if (is_method("CANCEL|BYE")) {
cache_remove("local", "ip_$(fu{uri.user})");
cache_remove("local", "port_$(fu{uri.user})");
}
if (!has_totag()) {
record_route();
} else {
if (is_method("CANCEL|BYE")) {
rtpengine_delete();
}
loose_route();
route(send_relay);
}
if (is_method("CANCEL")) {
if (t_check_trans()) route(send_relay);
}
if (is_method("INVITE")) {
route(send_relay);
route(dispatcher_next);
}
if (is_method("REGISTER")) {
if (client_nat_test("3")) {
force_rport();
fix_contact();
}
route(send_relay);
route(dispatcher_next);
}
t_on_failure("DR_failed");
}
route[send_relay] {
if (ds_is_in_list("$si", "", "1")) {
xlog("L_INFO", "$ci|log|originated from internal freeswitch sources");
setflag(26);
} else if (ds_is_in_list("$si", "", "3")) {
xlog("L_INFO", "$ci|log|originated from internal vos sources");
setflag(27);
} else {
xlog("L_INFO", "$ci|log|originated from external sources");
}
t_on_reply("reply");
if (isflagset(26)) {
#to vos
if ($(ru{uri.user}) == "3301xxxxxxxxxxx") {
if (ds_select_dst("3", "0")) {
if (!t_relay()) {
sl_reply_error();
}
}
exit;
}
#to client
if (ds_select_dst("2", "0")) {
if ( (cache_fetch("local", "ip_$(ru{uri.user})", $var(real_ip))) &&
(cache_fetch("local", "port_$(ru{uri.user})", $var(real_port))) ) {
$du = "sip:" + $var(real_ip) + ":" + $var(real_port);
if (!t_relay()) {
sl_reply_error();
}
} else {
send_reply("503","Service Unavailable");
}
exit;
}
} else {
if (ds_select_dst("1", "0")) {
if (!t_relay()) {
sl_reply_error();
}
exit;
}
}
}
branch_route[rtpengine] {
resetbflag(sdp_offer);
if ( ds_is_in_list("$si", "", "1") ) {
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove address-family=IP4 out-iface=pub in-iface=pub";
} else {
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove address-family=IP4 in-iface=priv out-iface=prive";
}
if ( ( (ds_is_in_list("$si", "", "1")) && ($(ru{uri.user}) == "3301xxxxxxxxxxx") ) ||
( ds_is_in_list("$si", "", "3") ) ) {
xlog("=========vos <-> fs pass========\n");
} else {
if ( (is_method("INVITE") || is_method("ACK") || is_method("PRACK")) && has_body("application/sdp") ) {
if( is_method("ACK") || is_method("PRACK") ) {
rtpengine_answer("$var(rtpengine_flags)");
} else {
rtpengine_offer("$var(rtpengine_flags)");
setbflag(sdp_offer);
}
}
}
}
onreply_route["reply"] {
if (ds_is_in_list("$si", "", "1")) {
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove address-family=IP4 out-iface=pub in-iface=pub";
} else {
$var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove address-family=IP4 in-iface=priv out-iface=priv";
}
if ( ( (ds_is_in_list("$si", "", "1")) && ($(ru{uri.user}) == "3301xxxxxxxxxxx") ) ||
( ds_is_in_list("$si", "", "3") ) ) {
xlog("=========vos <-> fs pass========\n");
} else {
# rtp proxying for responses
if ( has_body("application/sdp") ) {
if ( $rs=="183" && !isbflagset(sdp_offer) ) {
rtpengine_offer("$var(rtpengine_flags)");
} else if ( $rs=="200" || $rs=="183" ) {
rtpengine_answer("$var(rtpengine_flags)");
}
}
}
}
route[dispatcher_next] {
if (ds_next_dst()) {
route(send_relay);
} else {
send_reply("503","Service Unavailable");
exit;
}
}
failure_route[DR_failed] {
if (t_was_cancelled()) {
exit;
}
if (t_check_status("[56][0-9][0-9]") || (t_check_status("408") && t_local_replied("all"))) {
route(dispatcher_next);
}
}