nathelper.cfg 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #
  2. # $Id$
  3. #
  4. # simple quick-start config script including nathelper support
  5. # This default script includes nathelper support. To make it work
  6. # you will also have to install Maxim's RTP proxy. The proxy is enforced
  7. # if one of the parties is behind a NAT.
  8. #
  9. # If you have an endpoing in the public internet which is known to
  10. # support symmetric RTP (Cisco PSTN gateway or voicemail, for example),
  11. # then you don't have to force RTP proxy. If you don't want to enforce
  12. # RTP proxy for some destinations than simply use t_relay() instead of
  13. # route(1)
  14. #
  15. # Sections marked with !! Nathelper contain modifications for nathelper
  16. #
  17. # NOTE !! This config is EXPERIMENTAL !
  18. #
  19. # ----------- global configuration parameters ------------------------
  20. debug=3 # debug level (cmd line: -dddddddddd)
  21. fork=yes
  22. log_stderror=no # (cmd line: -E)
  23. /* Uncomment these lines to enter debugging mode
  24. fork=no
  25. log_stderror=yes
  26. */
  27. check_via=no # (cmd. line: -v)
  28. dns=no # (cmd. line: -r)
  29. rev_dns=no # (cmd. line: -R)
  30. port=5060
  31. children=4
  32. fifo="/tmp/sip-router_fifo"
  33. # ------------------ module loading ----------------------------------
  34. # Uncomment this if you want to use SQL database
  35. #loadmodule "/usr/local/lib/sip-router/modules/mysql.so"
  36. loadmodule "/usr/local/lib/sip-router/modules/sl.so"
  37. loadmodule "/usr/local/lib/sip-router/modules/tm.so"
  38. loadmodule "/usr/local/lib/sip-router/modules/rr.so"
  39. loadmodule "/usr/local/lib/sip-router/modules/maxfwd.so"
  40. loadmodule "/usr/local/lib/sip-router/modules/usrloc.so"
  41. loadmodule "/usr/local/lib/sip-router/modules/registrar.so"
  42. loadmodule "/usr/local/lib/sip-router/modules/textops.so"
  43. # Uncomment this if you want digest authentication
  44. # mysql.so must be loaded !
  45. #loadmodule "/usr/local/lib/sip-router/modules/auth.so"
  46. #loadmodule "/usr/local/lib/sip-router/modules/auth_db.so"
  47. # !! Nathelper
  48. loadmodule "/usr/local/lib/sip-router/modules/nathelper.so"
  49. # ----------------- setting module-specific parameters ---------------
  50. # -- usrloc params --
  51. modparam("usrloc", "db_mode", 0)
  52. # Uncomment this if you want to use SQL database
  53. # for persistent storage and comment the previous line
  54. #modparam("usrloc", "db_mode", 2)
  55. # -- auth params --
  56. # Uncomment if you are using auth module
  57. #
  58. #modparam("auth_db", "calculate_ha1", yes)
  59. #
  60. # If you set "calculate_ha1" parameter to yes (which true in this config),
  61. # uncomment also the following parameter)
  62. #
  63. #modparam("auth_db", "plain_password_column", "password")
  64. # -- rr params --
  65. # add value to ;lr param to make some broken UAs happy
  66. modparam("rr", "enable_full_lr", 1)
  67. # !! Nathelper
  68. modparam("registrar", "nat_flag", 6)
  69. modparam("nathelper", "natping_interval", 30) # Ping interval 30 s
  70. modparam("nathelper", "ping_nated_only", 1) # Ping only clients behind NAT
  71. # ------------------------- request routing logic -------------------
  72. # main routing logic
  73. route{
  74. # initial sanity checks -- messages with
  75. # max_forwards==0, or excessively long requests
  76. if (!mf_process_maxfwd_header("10")) {
  77. sl_send_reply("483","Too Many Hops");
  78. break;
  79. };
  80. if (msg:len >= max_len ) {
  81. sl_send_reply("513", "Message too big");
  82. break;
  83. };
  84. # !! Nathelper
  85. # Special handling for NATed clients; first, NAT test is
  86. # executed: it looks for via!=received and RFC1918 addresses
  87. # in Contact (may fail if line-folding is used); also,
  88. # the received test should, if completed, should check all
  89. # vias for rpesence of received
  90. if (nat_uac_test("3")) {
  91. # Allow RR-ed requests, as these may indicate that
  92. # a NAT-enabled proxy takes care of it; unless it is
  93. # a REGISTER
  94. if (method == "REGISTER" || ! search("^Record-Route:")) {
  95. log("LOG: Someone trying to register from private IP, rewriting\n");
  96. # This will work only for user agents that support symmetric
  97. # communication. We tested quite many of them and majority is
  98. # smart enough to be symmetric. In some phones it takes a configuration
  99. # option. With Cisco 7960, it is called NAT_Enable=Yes, with kphone it is
  100. # called "symmetric media" and "symmetric signalling".
  101. fix_nated_contact(); # Rewrite contact with source IP of signalling
  102. if (method == "INVITE") {
  103. fix_nated_sdp("1"); # Add direction=active to SDP
  104. };
  105. force_rport(); # Add rport parameter to topmost Via
  106. setflag(6); # Mark as NATed
  107. };
  108. };
  109. # we record-route all messages -- to make sure that
  110. # subsequent messages will go through our proxy; that's
  111. # particularly good if upstream and downstream entities
  112. # use different transport protocol
  113. if (!method=="REGISTER") record_route();
  114. # subsequent messages withing a dialog should take the
  115. # path determined by record-routing
  116. if (loose_route()) {
  117. # mark routing logic in request
  118. append_hf("P-hint: rr-enforced\r\n");
  119. route(1);
  120. break;
  121. };
  122. if (!uri==myself) {
  123. # mark routing logic in request
  124. append_hf("P-hint: outbound\r\n");
  125. route(1);
  126. break;
  127. };
  128. # if the request is for other domain use UsrLoc
  129. # (in case, it does not work, use the following command
  130. # with proper names and addresses in it)
  131. if (uri==myself) {
  132. if (method=="REGISTER") {
  133. # Uncomment this if you want to use digest authentication
  134. # if (!www_authorize("iptel.org", "subscriber")) {
  135. # www_challenge("iptel.org", "0");
  136. # break;
  137. # };
  138. save("location");
  139. break;
  140. };
  141. lookup("aliases");
  142. if (!uri==myself) {
  143. append_hf("P-hint: outbound alias\r\n");
  144. route(1);
  145. break;
  146. };
  147. # native SIP destinations are handled using our USRLOC DB
  148. if (!lookup("location")) {
  149. sl_send_reply("404", "Not Found");
  150. break;
  151. };
  152. };
  153. append_hf("P-hint: usrloc applied\r\n");
  154. route(1);
  155. }
  156. route[1]
  157. {
  158. # !! Nathelper
  159. if (uri=~"[@:](192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)" && !search("^Route:")){
  160. sl_send_reply("479", "We don't forward to private IP addresses");
  161. break;
  162. };
  163. # if client or server know to be behind a NAT, enable relay
  164. if (isflagset(6)) {
  165. force_rtp_proxy();
  166. };
  167. # NAT processing of replies; apply to all transactions (for example,
  168. # re-INVITEs from public to private UA are hard to identify as
  169. # NATed at the moment of request processing); look at replies
  170. t_on_reply("1");
  171. # send it out now; use stateful forwarding as it works reliably
  172. # even for UDP2TCP
  173. if (!t_relay()) {
  174. sl_reply_error();
  175. };
  176. }
  177. # !! Nathelper
  178. onreply_route[1] {
  179. # NATed transaction ?
  180. if (isflagset(6) && status =~ "(183)|2[0-9][0-9]") {
  181. fix_nated_contact();
  182. force_rtp_proxy();
  183. # otherwise, is it a transaction behind a NAT and we did not
  184. # know at time of request processing ? (RFC1918 contacts)
  185. } else if (nat_uac_test("1")) {
  186. fix_nated_contact();
  187. };
  188. }