| 1 |
nathelper Module |
| 2 |
|
| 3 |
Maxim Sobolev |
| 4 |
|
| 5 |
Sippy Software, Inc. |
| 6 |
|
| 7 |
Juha Heinanen |
| 8 |
|
| 9 |
TuTPro, Inc. |
| 10 |
|
| 11 |
Edited by |
| 12 |
|
| 13 |
Maxim Sobolev |
| 14 |
|
| 15 |
Bogdan-Andrei Iancu |
| 16 |
|
| 17 |
Juha Heinanen |
| 18 |
|
| 19 |
Ovidiu Sas |
| 20 |
|
| 21 |
Copyright © 2003-2008 Sippy Software, Inc. |
| 22 |
|
| 23 |
Copyright © 2005 Voice Sistem SRL |
| 24 |
|
| 25 |
Copyright © 2009 TuTPro Inc. |
| 26 |
|
| 27 |
Copyright © 2010 VoIPEmbedded Inc. |
| 28 |
__________________________________________________________________ |
| 29 |
|
| 30 |
Table of Contents |
| 31 |
|
| 32 |
1. Admin Guide |
| 33 |
|
| 34 |
1. Overview |
| 35 |
2. NAT pinging types |
| 36 |
3. Dependencies |
| 37 |
|
| 38 |
3.1. Kamailio Modules |
| 39 |
3.2. External Libraries or Applications |
| 40 |
|
| 41 |
4. Parameters |
| 42 |
|
| 43 |
4.1. force_socket (string) |
| 44 |
4.2. natping_interval (integer) |
| 45 |
4.3. ping_nated_only (integer) |
| 46 |
4.4. natping_processes (integer) |
| 47 |
4.5. natping_socket (string) |
| 48 |
4.6. received_avp (str) |
| 49 |
4.7. sipping_bflag (integer) |
| 50 |
4.8. sipping_from (string) |
| 51 |
4.9. sipping_method (string) |
| 52 |
4.10. natping_disable_bflag (integer) |
| 53 |
4.11. nortpproxy_str (string) |
| 54 |
4.12. keepalive_timeout (int) |
| 55 |
4.13. udpping_from_path (int) |
| 56 |
4.14. ignore_path (int) |
| 57 |
4.15. append_sdp_oldmediaip (int) |
| 58 |
4.16. filter_server_id (int) |
| 59 |
4.17. nat_addr_mode (int) |
| 60 |
4.18. alias_name (string) |
| 61 |
|
| 62 |
5. Functions |
| 63 |
|
| 64 |
5.1. fix_nated_contact() |
| 65 |
5.2. fix_nated_sdp(flags [, ip_address]) |
| 66 |
5.3. add_rcv_param([flag]), |
| 67 |
5.4. fix_nated_register() |
| 68 |
5.5. nat_uac_test(flags) |
| 69 |
5.6. is_rfc1918(ip_address) |
| 70 |
5.7. add_contact_alias([ip_addr, port, proto]) |
| 71 |
5.8. handle_ruri_alias([mode]) |
| 72 |
5.9. set_contact_alias([trim]) |
| 73 |
5.10. set_alias_to_pv(target_avp) |
| 74 |
|
| 75 |
6. Exported Pseudo Variables |
| 76 |
|
| 77 |
6.1. $rr_count |
| 78 |
6.2. $rr_top_count |
| 79 |
|
| 80 |
7. RPC Commands |
| 81 |
|
| 82 |
7.1. nathelper.enable_ping |
| 83 |
|
| 84 |
8. Selects |
| 85 |
|
| 86 |
8.1. @nathelper.rewrite_contact[n] |
| 87 |
|
| 88 |
2. Frequently Asked Questions |
| 89 |
|
| 90 |
List of Examples |
| 91 |
|
| 92 |
1.1. Set force_socket parameter |
| 93 |
1.2. Set natping_interval parameter |
| 94 |
1.3. Set ping_nated_only parameter |
| 95 |
1.4. Set natping_processes parameter |
| 96 |
1.5. Set natping_socket parameter |
| 97 |
1.6. Set received_avp parameter |
| 98 |
1.7. Set sipping_bflag parameter |
| 99 |
1.8. Set sipping_from parameter |
| 100 |
1.9. Set sipping_method parameter |
| 101 |
1.10. Set natping_disable_bflag parameter |
| 102 |
1.11. Set nortpproxy_str parameter |
| 103 |
1.12. Set keepalive_timeout parameter |
| 104 |
1.13. Set udpping_from_path parameter |
| 105 |
1.14. Set ignore_path parameter |
| 106 |
1.15. Set append_sdp_oldmediaip parameter |
| 107 |
1.16. Set filter_server_id parameter |
| 108 |
1.17. Set nat_addr_mode parameter |
| 109 |
1.18. Set alias_name parameter |
| 110 |
1.19. fix_nated_contact usage |
| 111 |
1.20. fix_nated_sdp usage |
| 112 |
1.21. add_rcv_param usage |
| 113 |
1.22. fix_nated_register usage |
| 114 |
1.23. nat_uac_test usage |
| 115 |
1.24. is_rfc1918 usage |
| 116 |
1.25. add_contact_alias usage |
| 117 |
1.26. handle_ruri_alias usage |
| 118 |
1.27. set_contact_alias usage |
| 119 |
1.28. set_alias_to_pv usage |
| 120 |
1.29. $rr_count usage |
| 121 |
1.30. $rr_top_count usage |
| 122 |
1.31. nathelper.enable_ping usage |
| 123 |
1.32. @nathelper.rewrite_contact usage |
| 124 |
|
| 125 |
Chapter 1. Admin Guide |
| 126 |
|
| 127 |
Table of Contents |
| 128 |
|
| 129 |
1. Overview |
| 130 |
2. NAT pinging types |
| 131 |
3. Dependencies |
| 132 |
|
| 133 |
3.1. Kamailio Modules |
| 134 |
3.2. External Libraries or Applications |
| 135 |
|
| 136 |
4. Parameters |
| 137 |
|
| 138 |
4.1. force_socket (string) |
| 139 |
4.2. natping_interval (integer) |
| 140 |
4.3. ping_nated_only (integer) |
| 141 |
4.4. natping_processes (integer) |
| 142 |
4.5. natping_socket (string) |
| 143 |
4.6. received_avp (str) |
| 144 |
4.7. sipping_bflag (integer) |
| 145 |
4.8. sipping_from (string) |
| 146 |
4.9. sipping_method (string) |
| 147 |
4.10. natping_disable_bflag (integer) |
| 148 |
4.11. nortpproxy_str (string) |
| 149 |
4.12. keepalive_timeout (int) |
| 150 |
4.13. udpping_from_path (int) |
| 151 |
4.14. ignore_path (int) |
| 152 |
4.15. append_sdp_oldmediaip (int) |
| 153 |
4.16. filter_server_id (int) |
| 154 |
4.17. nat_addr_mode (int) |
| 155 |
4.18. alias_name (string) |
| 156 |
|
| 157 |
5. Functions |
| 158 |
|
| 159 |
5.1. fix_nated_contact() |
| 160 |
5.2. fix_nated_sdp(flags [, ip_address]) |
| 161 |
5.3. add_rcv_param([flag]), |
| 162 |
5.4. fix_nated_register() |
| 163 |
5.5. nat_uac_test(flags) |
| 164 |
5.6. is_rfc1918(ip_address) |
| 165 |
5.7. add_contact_alias([ip_addr, port, proto]) |
| 166 |
5.8. handle_ruri_alias([mode]) |
| 167 |
5.9. set_contact_alias([trim]) |
| 168 |
5.10. set_alias_to_pv(target_avp) |
| 169 |
|
| 170 |
6. Exported Pseudo Variables |
| 171 |
|
| 172 |
6.1. $rr_count |
| 173 |
6.2. $rr_top_count |
| 174 |
|
| 175 |
7. RPC Commands |
| 176 |
|
| 177 |
7.1. nathelper.enable_ping |
| 178 |
|
| 179 |
8. Selects |
| 180 |
|
| 181 |
8.1. @nathelper.rewrite_contact[n] |
| 182 |
|
| 183 |
1. Overview |
| 184 |
|
| 185 |
This is a module to help with NAT traversal and reuse of TCP |
| 186 |
connections. In particular, it helps symmetric UAs that don't advertise |
| 187 |
they are symmetric and are not able to determine their public address. |
| 188 |
|
| 189 |
The function fix_nated_contact() rewrites the “Contact” header field |
| 190 |
with request's source address:port pair. The function fix_nated_sdp() |
| 191 |
adds the active direction indication to SDP (flag 0x01) and updates the |
| 192 |
source IP address too (flag 0x02). The function fix_nated_register() |
| 193 |
exports the request's source address:port into an AVP to be used during |
| 194 |
save() and should be used for “REGISTER” requests. |
| 195 |
|
| 196 |
Note: fix_nated_contact() changes the “Contact” header, thus it breaks |
| 197 |
the RFC. Although this is not always an issue, it may cause problems |
| 198 |
with strict SIP clients. An alternative is to use add_contact_alias() |
| 199 |
(or set_contact_alias()) that together with the handle_ruri_alias() is |
| 200 |
standards conforming and also supports reuse of TCP/TLS connections. |
| 201 |
|
| 202 |
2. NAT pinging types |
| 203 |
|
| 204 |
Currently, the nathelper module supports two types of NAT pings: |
| 205 |
* UDP packet - 4 bytes (zero filled) UDP packets are sent to the |
| 206 |
contact address. |
| 207 |
+ Advantages: low bandwidth traffic, easy to generate by |
| 208 |
Kamailio; |
| 209 |
+ Disadvantages: unidirectional traffic through NAT (inbound - |
| 210 |
from outside to inside); As many NATs do update the bind |
| 211 |
timeout only on outbound traffic, the bind may expire and get |
| 212 |
closed. |
| 213 |
* SIP request - a stateless SIP request is sent to the UDP contact |
| 214 |
address. |
| 215 |
+ Advantages: bidirectional traffic through NAT, since each PING |
| 216 |
request from Kamailio (inbound traffic) will force the SIP |
| 217 |
client to generate a SIP reply (outbound traffic) - the NAT |
| 218 |
bind will be surely kept open. |
| 219 |
+ Disadvantages: higher bandwidth traffic, more expensive (as |
| 220 |
time) to generate by Kamailio; |
| 221 |
|
| 222 |
3. Dependencies |
| 223 |
|
| 224 |
3.1. Kamailio Modules |
| 225 |
3.2. External Libraries or Applications |
| 226 |
|
| 227 |
3.1. Kamailio Modules |
| 228 |
|
| 229 |
The following modules must be loaded before this module: |
| 230 |
* usrloc module - only if the NATed contacts are to be pinged. |
| 231 |
|
| 232 |
3.2. External Libraries or Applications |
| 233 |
|
| 234 |
The following libraries or applications must be installed before |
| 235 |
running Kamailio with this module loaded: |
| 236 |
* None. |
| 237 |
|
| 238 |
4. Parameters |
| 239 |
|
| 240 |
4.1. force_socket (string) |
| 241 |
4.2. natping_interval (integer) |
| 242 |
4.3. ping_nated_only (integer) |
| 243 |
4.4. natping_processes (integer) |
| 244 |
4.5. natping_socket (string) |
| 245 |
4.6. received_avp (str) |
| 246 |
4.7. sipping_bflag (integer) |
| 247 |
4.8. sipping_from (string) |
| 248 |
4.9. sipping_method (string) |
| 249 |
4.10. natping_disable_bflag (integer) |
| 250 |
4.11. nortpproxy_str (string) |
| 251 |
4.12. keepalive_timeout (int) |
| 252 |
4.13. udpping_from_path (int) |
| 253 |
4.14. ignore_path (int) |
| 254 |
4.15. append_sdp_oldmediaip (int) |
| 255 |
4.16. filter_server_id (int) |
| 256 |
4.17. nat_addr_mode (int) |
| 257 |
4.18. alias_name (string) |
| 258 |
|
| 259 |
4.1. force_socket (string) |
| 260 |
|
| 261 |
Socket to be used when sending NAT pings for UDP communication. If no |
| 262 |
one specified, the OS will choose a socket. |
| 263 |
|
| 264 |
Default value is “NULL”. |
| 265 |
|
| 266 |
Example 1.1. Set force_socket parameter |
| 267 |
... |
| 268 |
modparam("nathelper", "force_socket", "127.0.0.1:5060") |
| 269 |
... |
| 270 |
|
| 271 |
4.2. natping_interval (integer) |
| 272 |
|
| 273 |
Period of time in seconds between sending the NAT pings to all |
| 274 |
currently registered UAs to keep their NAT bindings alive. Value of 0 |
| 275 |
disables this functionality. |
| 276 |
|
| 277 |
Note |
| 278 |
|
| 279 |
Enabling the NAT pinging functionality will force the module to bind |
| 280 |
itself to USRLOC module. |
| 281 |
|
| 282 |
Default value is 0. |
| 283 |
|
| 284 |
Example 1.2. Set natping_interval parameter |
| 285 |
... |
| 286 |
modparam("nathelper", "natping_interval", 10) |
| 287 |
... |
| 288 |
|
| 289 |
4.3. ping_nated_only (integer) |
| 290 |
|
| 291 |
If this parameter is set to 1 then only contacts that have the behind |
| 292 |
NAT “nat_bflag” flag set in user location records get the NAT ping (the |
| 293 |
“nat_bflag” is specified via modparam of usrloc module). By default the |
| 294 |
ping is done with 4-bytes UDP packet. If sipping_bflag is also set, |
| 295 |
then the ping is done with a stateless SIP request (by default: OPTIONS |
| 296 |
request). |
| 297 |
|
| 298 |
If it is 0, then all contacts get a NAT ping, by default being the |
| 299 |
4-bytes UDP packet. If it is 0 and sipping_bflag parameter is set, then |
| 300 |
SIP-request-based pinging is sent to all contacts. |
| 301 |
|
| 302 |
Default value is 0. |
| 303 |
|
| 304 |
Example 1.3. Set ping_nated_only parameter |
| 305 |
... |
| 306 |
modparam("nathelper", "ping_nated_only", 1) |
| 307 |
... |
| 308 |
|
| 309 |
4.4. natping_processes (integer) |
| 310 |
|
| 311 |
How many timer processes should be created by the module for the |
| 312 |
exclusive task of sending the NAT pings. |
| 313 |
|
| 314 |
Default value is 1. |
| 315 |
|
| 316 |
Example 1.4. Set natping_processes parameter |
| 317 |
... |
| 318 |
modparam("nathelper", "natping_processes", 3) |
| 319 |
... |
| 320 |
|
| 321 |
4.5. natping_socket (string) |
| 322 |
|
| 323 |
Spoof the natping's source-ip to this address. Works only for IPv4. |
| 324 |
|
| 325 |
Default value is NULL. |
| 326 |
|
| 327 |
Example 1.5. Set natping_socket parameter |
| 328 |
... |
| 329 |
modparam("nathelper", "natping_socket", "192.168.1.1:5006") |
| 330 |
... |
| 331 |
|
| 332 |
4.6. received_avp (str) |
| 333 |
|
| 334 |
The name of the Attribute-Value-Pair (AVP) used to store the URI |
| 335 |
containing the received IP, port, and protocol. The URI is created by |
| 336 |
fix_nated_register function of nathelper module and the attribute is |
| 337 |
then used by the registrar to store the received parameters. Do not |
| 338 |
forget to change the value of corresponding parameter in registrar |
| 339 |
module if you change the value of this parameter. |
| 340 |
|
| 341 |
Note |
| 342 |
|
| 343 |
You must set this parameter if you use fix_nated_register. In such case |
| 344 |
you must set the parameter with same name in the “registrar” module to |
| 345 |
same value. |
| 346 |
|
| 347 |
Default value is "NULL" (disabled). |
| 348 |
|
| 349 |
Example 1.6. Set received_avp parameter |
| 350 |
... |
| 351 |
modparam("nathelper", "received_avp", "$avp(i:42)") |
| 352 |
... |
| 353 |
|
| 354 |
4.7. sipping_bflag (integer) |
| 355 |
|
| 356 |
Which branch flag should be used by the module to identify NATed |
| 357 |
contacts for which it should perform NAT ping via a SIP request instead |
| 358 |
of dummy UDP packet. |
| 359 |
|
| 360 |
Default value is -1 (disabled). |
| 361 |
|
| 362 |
Example 1.7. Set sipping_bflag parameter |
| 363 |
... |
| 364 |
modparam("nathelper", "sipping_bflag", 7) |
| 365 |
... |
| 366 |
|
| 367 |
4.8. sipping_from (string) |
| 368 |
|
| 369 |
The parameter sets the SIP URI to be used in generating the SIP |
| 370 |
requests for NAT ping purposes. To enable the SIP request pinging |
| 371 |
feature, you have to set this parameter. The SIP request pinging will |
| 372 |
be used only for requests marked so. |
| 373 |
|
| 374 |
Default value is “NULL”. |
| 375 |
|
| 376 |
Example 1.8. Set sipping_from parameter |
| 377 |
... |
| 378 |
modparam("nathelper", "sipping_from", "sip:[email protected]") |
| 379 |
... |
| 380 |
|
| 381 |
4.9. sipping_method (string) |
| 382 |
|
| 383 |
The parameter sets the SIP method to be used in generating the SIP |
| 384 |
requests for NAT ping purposes. |
| 385 |
|
| 386 |
Default value is “OPTIONS”. |
| 387 |
|
| 388 |
Example 1.9. Set sipping_method parameter |
| 389 |
... |
| 390 |
modparam("nathelper", "sipping_method", "INFO") |
| 391 |
... |
| 392 |
|
| 393 |
4.10. natping_disable_bflag (integer) |
| 394 |
|
| 395 |
What branch flag should be used by the module to disable NAT pings on a |
| 396 |
per-registration basis. If the given flag is set for a particular |
| 397 |
registration, then no NAT pings will be sent at all, regardless of any |
| 398 |
other conditions. |
| 399 |
|
| 400 |
Default value is -1 (disabled). |
| 401 |
|
| 402 |
Example 1.10. Set natping_disable_bflag parameter |
| 403 |
... |
| 404 |
modparam("nathelper", "natping_disable_bflag", 8) |
| 405 |
... |
| 406 |
|
| 407 |
4.11. nortpproxy_str (string) |
| 408 |
|
| 409 |
The parameter sets the SDP attribute used by nathelper to mark the |
| 410 |
packet SDP that information have already been mangled. |
| 411 |
|
| 412 |
If empty string, no marker will be added or checked. |
| 413 |
|
| 414 |
Note |
| 415 |
|
| 416 |
The string must be a complete SDP line, including the EOH (\r\n). |
| 417 |
|
| 418 |
Default value is “a=nortpproxy:yes\r\n”. |
| 419 |
|
| 420 |
Example 1.11. Set nortpproxy_str parameter |
| 421 |
... |
| 422 |
modparam("nathelper", "nortpproxy_str", "a=sdpmangled:yes\r\n") |
| 423 |
... |
| 424 |
|
| 425 |
4.12. keepalive_timeout (int) |
| 426 |
|
| 427 |
The parameter sets the interval in seconds after which a natted contact |
| 428 |
is removed from location table if it does not reply to SIP keepalives |
| 429 |
(usually OPTIONS ping requests). |
| 430 |
|
| 431 |
The features is available only for UDP contacts that are stored in |
| 432 |
memory (not working for db only mode for usrloc module). |
| 433 |
|
| 434 |
Keepalives are sent stateless, not using TM module. The value of this |
| 435 |
parameter has to be few times higher than natping_interval. |
| 436 |
|
| 437 |
Default value is “0” (feature disabled). |
| 438 |
|
| 439 |
Example 1.12. Set keepalive_timeout parameter |
| 440 |
... |
| 441 |
modparam("nathelper", "keepalive_timeout", 120) |
| 442 |
... |
| 443 |
|
| 444 |
4.13. udpping_from_path (int) |
| 445 |
|
| 446 |
Enable sending UDP pings (keepalives) using raw socket from Path |
| 447 |
address. |
| 448 |
|
| 449 |
Default value is “0” (feature disabled). |
| 450 |
|
| 451 |
Example 1.13. Set udpping_from_path parameter |
| 452 |
... |
| 453 |
modparam("nathelper", "udpping_from_path", 1) |
| 454 |
... |
| 455 |
|
| 456 |
4.14. ignore_path (int) |
| 457 |
|
| 458 |
Enable ignore of Path header address when sending UDP pings |
| 459 |
(keepalives). |
| 460 |
|
| 461 |
Default value is “0” (feature disabled). UDP pings are sent to Path |
| 462 |
header if header is present. |
| 463 |
|
| 464 |
Example 1.14. Set ignore_path parameter |
| 465 |
... |
| 466 |
modparam("nathelper", "ignore_path", 1) |
| 467 |
... |
| 468 |
|
| 469 |
4.15. append_sdp_oldmediaip (int) |
| 470 |
|
| 471 |
The parameter controls if oldmediaip field should be appended to the |
| 472 |
SDP. |
| 473 |
|
| 474 |
Default value is “1” (feature enabled). |
| 475 |
|
| 476 |
Example 1.15. Set append_sdp_oldmediaip parameter |
| 477 |
... |
| 478 |
modparam("nathelper", "append_sdp_oldmediaip", 1) |
| 479 |
... |
| 480 |
|
| 481 |
4.16. filter_server_id (int) |
| 482 |
|
| 483 |
Filter contacts by “server_id” core parameter. Use this parameter to |
| 484 |
limit pinging. When set to “1”, only proxy instances which send packets |
| 485 |
are those where core server_id matches server_id saved in usrloc. |
| 486 |
Default value is “0” (disabled). |
| 487 |
|
| 488 |
Example 1.16. Set filter_server_id parameter |
| 489 |
... |
| 490 |
modparam("nathelper", "filter_server_id", 1) |
| 491 |
... |
| 492 |
|
| 493 |
4.17. nat_addr_mode (int) |
| 494 |
|
| 495 |
If set to 0, only default private net addresses are checked by |
| 496 |
nat_uac_test(). If set to 1, other reserved net addresses are checked |
| 497 |
by nat_uac_test() as well. |
| 498 |
|
| 499 |
Default private net addresses are: |
| 500 |
* 10.0.0.0/8 |
| 501 |
* 172.16.0.0/12 |
| 502 |
* 192.168.0.0/16 |
| 503 |
* 100.64.0.0/10 - RFC6598 - Carrier Grade NAT |
| 504 |
* 192.0.0.0/29 - RFC7335 - IPv4 Service Continuity Prefix |
| 505 |
|
| 506 |
Reserved net addresses are: |
| 507 |
* 192.0.0.0/24 - RFC7335 - IETF Protocol Assignments |
| 508 |
|
| 509 |
Default value is “1”. |
| 510 |
|
| 511 |
Example 1.17. Set nat_addr_mode parameter |
| 512 |
... |
| 513 |
modparam("nathelper", "nat_addr_mode", 0) |
| 514 |
... |
| 515 |
|
| 516 |
4.18. alias_name (string) |
| 517 |
|
| 518 |
The parameter sets the name of the Contact URI parameter set by |
| 519 |
set_contact_alias() or add_contact_alias() and processed by |
| 520 |
handle_ruri_alias() in R-URI. |
| 521 |
|
| 522 |
Default value is “alias”. |
| 523 |
|
| 524 |
Example 1.18. Set alias_name parameter |
| 525 |
... |
| 526 |
modparam("nathelper", "alias_name", "saddr") |
| 527 |
... |
| 528 |
|
| 529 |
5. Functions |
| 530 |
|
| 531 |
5.1. fix_nated_contact() |
| 532 |
5.2. fix_nated_sdp(flags [, ip_address]) |
| 533 |
5.3. add_rcv_param([flag]), |
| 534 |
5.4. fix_nated_register() |
| 535 |
5.5. nat_uac_test(flags) |
| 536 |
5.6. is_rfc1918(ip_address) |
| 537 |
5.7. add_contact_alias([ip_addr, port, proto]) |
| 538 |
5.8. handle_ruri_alias([mode]) |
| 539 |
5.9. set_contact_alias([trim]) |
| 540 |
5.10. set_alias_to_pv(target_avp) |
| 541 |
|
| 542 |
5.1. fix_nated_contact() |
| 543 |
|
| 544 |
Rewrites the “Contact” header to contain the request's source |
| 545 |
address:port. |
| 546 |
|
| 547 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 548 |
BRANCH_ROUTE. |
| 549 |
|
| 550 |
Example 1.19. fix_nated_contact usage |
| 551 |
... |
| 552 |
if (search("User-Agent: Cisco ATA.*") {fix_nated_contact();}; |
| 553 |
... |
| 554 |
|
| 555 |
5.2. fix_nated_sdp(flags [, ip_address]) |
| 556 |
|
| 557 |
Alters the SDP information in order to facilitate NAT traversal. What |
| 558 |
changes to be performed may be controlled via the “flags” parameter. |
| 559 |
Return value is -1 if error occurred, 1 if ip's were replaced, 2 if no |
| 560 |
ip's were replaced. |
| 561 |
|
| 562 |
Meaning of the parameters is as follows: |
| 563 |
* flags - the value may be a bitwise OR of the following flags: |
| 564 |
+ 0x01 - adds “a=direction:active” SDP line; |
| 565 |
+ 0x02 - rewrite media IP address (c=) with source address of |
| 566 |
the message or the provided IP address. (a=rtcp) param will be |
| 567 |
rewritten if exists. (the provided IP address take precedence |
| 568 |
over the source address). |
| 569 |
+ 0x04 - adds “a=nortpproxy:yes” SDP line; |
| 570 |
+ 0x08 - rewrite IP from origin description (o=) with source |
| 571 |
address of the message or the provided IP address. (a=rtcp) |
| 572 |
param will be rewritten if exists. (the provided IP address |
| 573 |
take precedence over the source address). |
| 574 |
* ip_address - IP to be used for rewriting SDP. If not specified, the |
| 575 |
received signalling IP will be used. The parameter allows |
| 576 |
pseudo-variables usage. NOTE: For the IP to be used, you need to |
| 577 |
use 0x02 or 0x08 flags, otherwise it will have no effect. Must be |
| 578 |
IPv4 address family. |
| 579 |
|
| 580 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 581 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 582 |
|
| 583 |
Example 1.20. fix_nated_sdp usage |
| 584 |
... |
| 585 |
if (search("User-Agent: Cisco ATA.*") {fix_nated_sdp("3");}; |
| 586 |
... |
| 587 |
|
| 588 |
5.3. add_rcv_param([flag]), |
| 589 |
|
| 590 |
Add a received parameter to the “Contact” header fields (available for |
| 591 |
all transports) or to the Contact URI (available only for UDP traffic). |
| 592 |
|
| 593 |
The parameter will contain the URI created from the source IP, port, |
| 594 |
and protocol (if different than UDP) of the packet containing the SIP |
| 595 |
message. The parameter can be then processed by another registrar. This |
| 596 |
is useful, for example, when replicating register messages using |
| 597 |
t_replicate function to another registrar. |
| 598 |
|
| 599 |
Meaning of the parameters is as follows: |
| 600 |
* flag - flags to indicate if the parameter should be added to |
| 601 |
Contact URI or Contact header. If the flag is non-zero, the |
| 602 |
parameter will be added to the Contact URI. If not used or equal to |
| 603 |
zero, the parameter will go to the Contact header. |
| 604 |
|
| 605 |
This function can be used from REQUEST_ROUTE. |
| 606 |
|
| 607 |
Example 1.21. add_rcv_param usage |
| 608 |
... |
| 609 |
add_rcv_param(); # add the parameter to the Contact header |
| 610 |
.... |
| 611 |
add_rcv_param("1"); # add the parameter to the Contact URI |
| 612 |
... |
| 613 |
|
| 614 |
5.4. fix_nated_register() |
| 615 |
|
| 616 |
The function creates a URI consisting of the source IP, port, and |
| 617 |
protocol and stores the URI in an Attribute-Value-Pair. The URI will be |
| 618 |
appended as "received" parameter to Contact in 200 OK and registrar |
| 619 |
will store it in the received column in the location table. |
| 620 |
|
| 621 |
Note: You have to set the “received_avp” parameter of the nathelper |
| 622 |
module and the registrar module (both module parameters must have the |
| 623 |
same value) to use this function. |
| 624 |
|
| 625 |
This function can be used from REQUEST_ROUTE. |
| 626 |
|
| 627 |
Example 1.22. fix_nated_register usage |
| 628 |
... |
| 629 |
fix_nated_register(); |
| 630 |
... |
| 631 |
|
| 632 |
5.5. nat_uac_test(flags) |
| 633 |
|
| 634 |
Tries to guess if client's request originated behind a nat. The |
| 635 |
parameter determines what heuristics is used. |
| 636 |
|
| 637 |
Meaning of the flags is as follows: |
| 638 |
* 1 - The “Contact” header field is searched for occurrence of |
| 639 |
RFC1918 or RFC6598 addresses. |
| 640 |
* 2 - the "received" test is used: address in the “Via” header is |
| 641 |
compared against source IP address of signaling. If the “Via” |
| 642 |
header contains no port, it uses the default SIP port 5060 |
| 643 |
* 4 - The Top Most “Via” is searched for occurrence of RFC1918 or |
| 644 |
RFC6598 addresses |
| 645 |
* 8 - The SDP is searched for occurrence of RFC1918 or RFC6598 |
| 646 |
addresses |
| 647 |
* 16 - Test if the source port is different from the port in the |
| 648 |
“Via” header. If the “Via” header contains no port, it uses the |
| 649 |
default SIP port 5060 |
| 650 |
* 32 - Test if the source IP address of signaling is a RFC1918 or |
| 651 |
RFC6598 address |
| 652 |
* 64 - Test if the source connection of signaling is a WebSocket |
| 653 |
* 128 - Test if the “Contact” header URI port differs from the source |
| 654 |
port of the request (Warning: this is might be legal or even |
| 655 |
intended combination in non NATted scenarios) |
| 656 |
* 256 - Test if the SDP connection address is different from source |
| 657 |
IP address. It will work also with multiple connection address |
| 658 |
lines. |
| 659 |
* 512 - Test if the target addresses are different or over websocket. |
| 660 |
For requests, it compares host and port in R-URI ($rU) and D-URI |
| 661 |
($du). For replies, it compares host and port in 2nd Via with |
| 662 |
received and rport parameters. |
| 663 |
|
| 664 |
All flags can be bitwise combined, the test returns true if any of the |
| 665 |
tests identified a NAT. |
| 666 |
|
| 667 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 668 |
FAILURE_ROUTE, BRANCH_ROUTE. |
| 669 |
|
| 670 |
Example 1.23. nat_uac_test usage |
| 671 |
... |
| 672 |
if(nat_uac_test("19")) { |
| 673 |
rtpproxy_manage("co"); |
| 674 |
} |
| 675 |
... |
| 676 |
|
| 677 |
5.6. is_rfc1918(ip_address) |
| 678 |
|
| 679 |
Determines if the address in the parameter is an rfc1918 or rfc6598 |
| 680 |
address. The parameter allows pseudo-variables usage. |
| 681 |
|
| 682 |
This function can be used from ANY_ROUTE. |
| 683 |
|
| 684 |
Example 1.24. is_rfc1918 usage |
| 685 |
... |
| 686 |
if(is_rfc1918("$rd")) { |
| 687 |
# domain in r-uri is private address |
| 688 |
} |
| 689 |
... |
| 690 |
|
| 691 |
5.7. add_contact_alias([ip_addr, port, proto]) |
| 692 |
|
| 693 |
Adds an “;alias=ip~port~transport” parameter to the contact URI |
| 694 |
containing either received ip, port, and transport protocol or those |
| 695 |
given as parameters. If called without parameters, “;alias” parameter |
| 696 |
is only added if received ip, port, or transport protocol differs from |
| 697 |
that in contact URI. |
| 698 |
|
| 699 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 700 |
BRANCH_ROUTE, and LOCAL_ROUTE. |
| 701 |
|
| 702 |
Example 1.25. add_contact_alias usage |
| 703 |
... |
| 704 |
if (!is_present_hf("Record-Route")) { |
| 705 |
if (!add_contact_alias("$var(src_ip)", "$Rp", "tcp")) { |
| 706 |
xlog("L_ERR", "Error in aliasing contact $ct\n"); |
| 707 |
send_reply("400", "Bad request"); |
| 708 |
exit; |
| 709 |
}; |
| 710 |
}; |
| 711 |
... |
| 712 |
|
| 713 |
5.8. handle_ruri_alias([mode]) |
| 714 |
|
| 715 |
Checks if the Request URI has an “alias” parameter and if so, removes |
| 716 |
it and sets the “$du” based on its value. Note that this means that |
| 717 |
routing of request is based on “;alias” parameter value of the Request |
| 718 |
URI rather than the Request URI itself. If you call handle_ruri_alias() |
| 719 |
on a request, make sure that you screen the alias parameter value of |
| 720 |
Request URI the same way as you would screen the Request URI itself. |
| 721 |
|
| 722 |
The optional parameter mode can be 0 to consume first alias parameter, |
| 723 |
otherwise it consumes the last alias parameter. If the parameter mode |
| 724 |
is not provided, it consumes the first parameter. |
| 725 |
|
| 726 |
Returns 1 if “;alias” parameter was found and “$du” was set and the |
| 727 |
“$ru” rewritten, 2 if the alias parameter was not found and nothing was |
| 728 |
done, or -1 in case of error. |
| 729 |
|
| 730 |
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE, and |
| 731 |
LOCAL_ROUTE. |
| 732 |
|
| 733 |
Example 1.26. handle_ruri_alias usage |
| 734 |
... |
| 735 |
if ($du == "") { |
| 736 |
handle_ruri_alias(); |
| 737 |
switch ($rc) { |
| 738 |
case -1: |
| 739 |
xlog("L_ERR", "Failed to handle alias of R-URI $ru\n"); |
| 740 |
send_reply("400", "Bad request"); |
| 741 |
exit; |
| 742 |
case 1: |
| 743 |
xlog("L_INFO", "Routing in-dialog $rm from $fu to $du\n"); |
| 744 |
break; |
| 745 |
case 2: |
| 746 |
xlog("L_INFO", "Routing in-dialog $rm from $fu to $ru\n"); |
| 747 |
break; |
| 748 |
}; |
| 749 |
}; |
| 750 |
... |
| 751 |
|
| 752 |
5.9. set_contact_alias([trim]) |
| 753 |
|
| 754 |
Adds an “;alias=ip~port~transport” parameter to the contact URI |
| 755 |
containing the received ip, port, and transport protocol. The update of |
| 756 |
contact URI is signaled to a few other modules in the way the |
| 757 |
fix_nated_contact() does it by using the internal flags. The new value |
| 758 |
is not visible to pseudo-variables and it does not change the SIP |
| 759 |
message buffer. |
| 760 |
|
| 761 |
Meaning of parameters: |
| 762 |
* trim - by default, set_contact_alias() will not detect and trim an |
| 763 |
already existing alias parameter. If this optional parameter is set |
| 764 |
to "1", set_contact_alias() will trim the existing alias before |
| 765 |
adding a new one. |
| 766 |
|
| 767 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 768 |
BRANCH_ROUTE, and FAILURE_ROUTE. |
| 769 |
|
| 770 |
Example 1.27. set_contact_alias usage |
| 771 |
... |
| 772 |
if (!is_present_hf("Record-Route")) { |
| 773 |
if (!set_contact_alias()) { |
| 774 |
xlog("L_ERR", "Error in aliasing contact $ct\n"); |
| 775 |
send_reply("400", "Bad request"); |
| 776 |
exit; |
| 777 |
}; |
| 778 |
}; |
| 779 |
... |
| 780 |
|
| 781 |
5.10. set_alias_to_pv(target_avp) |
| 782 |
|
| 783 |
Reads “;alias=ip~port~transport” from Contact header then writes to |
| 784 |
target pseudo-variable as a sip uri. |
| 785 |
|
| 786 |
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, |
| 787 |
BRANCH_ROUTE, and FAILURE_ROUTE. |
| 788 |
|
| 789 |
Example 1.28. set_alias_to_pv usage |
| 790 |
... |
| 791 |
set_alias_to_pv("$avp(aliasuri)"); |
| 792 |
... |
| 793 |
|
| 794 |
6. Exported Pseudo Variables |
| 795 |
|
| 796 |
6.1. $rr_count |
| 797 |
6.2. $rr_top_count |
| 798 |
|
| 799 |
6.1. $rr_count |
| 800 |
|
| 801 |
Number of Record Routes in received SIP request or reply. |
| 802 |
|
| 803 |
Example 1.29. $rr_count usage |
| 804 |
... |
| 805 |
$avp(rr_count) = $rr_count; |
| 806 |
... |
| 807 |
|
| 808 |
6.2. $rr_top_count |
| 809 |
|
| 810 |
If topmost Record Route in received SIP request or reply is a double |
| 811 |
Record Route, value of $rr_top_count is 2. If it a single Record Route, |
| 812 |
value of $rr_top_count is 1. If there is no Record Route(s), value of |
| 813 |
$rr_top_count is 0. |
| 814 |
|
| 815 |
Example 1.30. $rr_top_count usage |
| 816 |
... |
| 817 |
if ($rr_count == $avp(rr_count) + $rr_top_count) { |
| 818 |
route(ADD_CONTACT_ALIAS); |
| 819 |
}; |
| 820 |
... |
| 821 |
|
| 822 |
7. RPC Commands |
| 823 |
|
| 824 |
7.1. nathelper.enable_ping |
| 825 |
|
| 826 |
7.1. nathelper.enable_ping |
| 827 |
|
| 828 |
Enables natping if parameter value different than 0. Disables natping |
| 829 |
if parameter value is 0. |
| 830 |
|
| 831 |
The function takes only one parameter - a number in decimal format. |
| 832 |
|
| 833 |
Example 1.31. nathelper.enable_ping usage |
| 834 |
... |
| 835 |
$ kamctl rpc nathelper.enable_ping 1 |
| 836 |
... |
| 837 |
|
| 838 |
8. Selects |
| 839 |
|
| 840 |
8.1. @nathelper.rewrite_contact[n] |
| 841 |
|
| 842 |
8.1. @nathelper.rewrite_contact[n] |
| 843 |
|
| 844 |
Get n-th Contact value with IP:Port rewritten to source ip:port. N is |
| 845 |
counted from 1. Only IP:port is rewritten, remaining parts are left |
| 846 |
unchanged. Full nameaddr is supported. |
| 847 |
|
| 848 |
Example 1.32. @nathelper.rewrite_contact usage |
| 849 |
... |
| 850 |
$c = @nathelper.rewrite_contact[1]; |
| 851 |
... |
| 852 |
$c2 = @nathelper.rewrite_contact[1].nameaddr.uri; |
| 853 |
|
| 854 |
Chapter 2. Frequently Asked Questions |
| 855 |
|
| 856 |
2.1. What happened with “rtpproxy_disable” parameter? |
| 857 |
2.2. Where can I find more about Kamailio? |
| 858 |
2.3. Where can I post a question about this module? |
| 859 |
2.4. How can I report a bug? |
| 860 |
|
| 861 |
2.1. |
| 862 |
|
| 863 |
What happened with “rtpproxy_disable” parameter? |
| 864 |
|
| 865 |
It was removed as it became obsolete - now “rtpproxy_sock” can take |
| 866 |
empty value to disable the rtpproxy functionality. |
| 867 |
|
| 868 |
2.2. |
| 869 |
|
| 870 |
Where can I find more about Kamailio? |
| 871 |
|
| 872 |
Take a look at https://www.kamailio.org/. |
| 873 |
|
| 874 |
2.3. |
| 875 |
|
| 876 |
Where can I post a question about this module? |
| 877 |
|
| 878 |
First at all check if your question was already answered on one of our |
| 879 |
mailing lists: |
| 880 |
* User Mailing List - |
| 881 |
https://lists.kamailio.org/mailman3/postorius/lists/sr-users.lists. |
| 882 |
kamailio.org/ |
| 883 |
* Developer Mailing List - |
| 884 |
https://lists.kamailio.org/mailman3/postorius/lists/sr-dev.lists.ka |
| 885 |
mailio.org/ |
| 886 |
|
| 887 |
E-mails regarding any stable Kamailio release should be sent to |
| 888 |
<[email protected]> and e-mails regarding development |
| 889 |
versions should be sent to <[email protected]>. |
| 890 |
|
| 891 |
2.4. |
| 892 |
|
| 893 |
How can I report a bug? |
| 894 |
|
| 895 |
Please follow the guidelines provided at: |
| 896 |
https://github.com/kamailio/kamailio/issues. |