sip-router-oob.cfg 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  1. #
  2. # $Id$
  3. #
  4. #
  5. # Applicability of this Configuration File
  6. # ----------------------------------------
  7. #
  8. # This is default SER script as used for example at the iptel.org
  9. # SIP service; it can deal with NATs, terminate calls to a PSTN
  10. # gateway, and it implements a couple of basic signaling features
  11. # (few types of call forwarding). In this scenario you may have
  12. # multiple SIP proxies sharing one database for accessing provisioned
  13. # data, which are maintained for example using serweb. The proxy
  14. # servers also share write-access to user location database (and
  15. # keeps a full cache of all usrloc entries synchronized using
  16. # multicast).
  17. #
  18. # If you look for a simpler version with a lot less dependencies
  19. # please refer to the sip-router-basic.cfg file in your SER distribution.
  20. #
  21. # If you look for documentation, try http://sip-router.org/wiki/.
  22. # The right mailing lists for questions about this file is
  23. # <[email protected]>.
  24. #
  25. # Requirements:
  26. # ---------------
  27. # running DB, running RTP proxy, one public IP address
  28. # for SIP service, one private IP address for administrative purposes;
  29. # optional: IP address of a PSTN gateway
  30. #
  31. # HOWTOs:
  32. # ---------
  33. # To get this config running you need to execute the following commands
  34. # with the new serctl (the capital word are just place holders):
  35. #
  36. # $ ser_ctl domain add DOMAINNAME
  37. # $ ser_ctl user add USERNAME@DOMAINNAME -p PASSWORD
  38. #
  39. # (ser_ctl can be obtained from
  40. # http://ftp.iptel.org/pub/serctl/daily-snapshots/ )
  41. #
  42. # If you want to have P-Asserted-ID header for your user
  43. #
  44. # $ ser_attr add uid=UID asserted_id="PID"
  45. #
  46. # If you want to have (PSTN) gateway support:
  47. #
  48. # $ ser_db add attr_types name=gw_ip rich_type=string raw_type=2 \
  49. # description="The gateway IP for the default ser.cfg" default_flags=33
  50. # $ ser_attr add global gw_ip=GATEWAY-IP
  51. #
  52. # Alternatively, you can simple uncomment the relevant line in this file
  53. # right at the beginning of the main route.
  54. #
  55. # You can also use serweb to set all the values above
  56. # (http://ftp.iptel.org/pub/serweb/daily-snapshots/ or
  57. # http://developer.berlios.de/projects/serweb).
  58. #
  59. # Users with permission to call PSTN using this script must have
  60. # the $gw_acl attribute set properly, and shall have $asserted_id
  61. # set to indicate their caller-id for calls to PSTN. For inbound
  62. # calls from PSTN, additional aliases may be also set.
  63. #
  64. # Warning:
  65. # -----------
  66. # If this file is installed on Debian from package 'ser-oob' then some
  67. # options in this configuration file may be set by post-installation
  68. # script, according to values entered by user at installation time in
  69. # debconf configuration. These values are then applied automatically to
  70. # this file each time the 'ser-oob' package is upgraded or reconfigured by
  71. # calling 'dpkg-reconfigure sip-router-oob'.
  72. #
  73. # The parts of this configuration file that may be altered by debconf are
  74. # enclosed between '#DEBCONF-something-START' and '#DEBCONF-something-END'
  75. # comment marks. Please do not remove them.
  76. #
  77. #
  78. # TODO (Future possible improvements):
  79. # ---------------------------------------
  80. # * protocol tuning
  81. # - AVP-based diversion for call-forwarding (as opposed to specialized
  82. # module)
  83. # - add Date header in 200s to REGISTERs (to be packaged with NTP!)
  84. # * more security:
  85. # - pike/rate-limit
  86. # - identity
  87. # - TLS
  88. # - permissions
  89. # - Re-name all internal headers so that they start with a common prefix,
  90. # such as P-SER and then wipe all such headers from requests received
  91. # from untrusted sources, such as the user agents or foreign proxy
  92. # servers
  93. # * refined DB use (e.g., flatstore for acc)
  94. # * miscellanous:
  95. # - dialog module for monitoring purposes
  96. # - more extensive logging using xlog (controlled by gflags/gAVPs)
  97. # * leveraging 2.1 features:
  98. # - removal of private IP address (it takes a multicast-specific
  99. # command which will allow OS to determine source IP address)
  100. # - timer route:
  101. # * don't use exec (it takes domain.reload as script command)
  102. # * compare last-stored timestamp with current timestamp (it takes
  103. # assignment of gAVPs)
  104. # * check multicast REGISTERs for their TTL (this is a simple and
  105. # effective security check to prevent remote multicast messages
  106. # to damage our traffic)
  107. # - numerous fine-tuning parameters which are only available in 2.1
  108. # (mlock_pages, dns_try_naptr, etc.)
  109. # - better support for preloaded routes with domain name
  110. #
  111. # Security considerations:
  112. # ------------------------
  113. # The script has been tested against security leaks, but it comes
  114. # under terms of GPL "as is" without any warranties; better check
  115. # yourself that:
  116. # - IP based authentication of PSTN gateway and multicast REGISTERs
  117. # is compliant to your network setup and security policy.
  118. # - Multiple gateway IPs can't be provisioned as security checks
  119. # are applied only to one.
  120. #
  121. # Licensing
  122. # ----------
  123. # Copyright (C) 2005-2008 iptelorg GmbH
  124. # This file is part of SER, a free SIP server. It is available under the
  125. # terms of the GNU General Public License.
  126. # Numerous folks have contributed to this file, including but not limited
  127. # to Andrei, Jan, Jiri, Michal, Miklos, Nils.
  128. #
  129. #
  130. # .... that's it, enough of yadiyada, here the real config begins!
  131. # ----------- Global Defines / Extra Features -------------------------------
  132. # (can be enabled either by uncommenting the corresponding #!define
  133. # statement or by starting with -A WITH_<FEATURE_NAME>, e.g.
  134. # ser -A WITH_TLS -f /etc/ser/ser-oob.cfg )
  135. # enable TLS
  136. ##!define WITH_TLS
  137. #enable xmlrpc support
  138. ##!define WITH_XMLRPC
  139. # xmlrpc allowed only if it comes on TLS from a client with a valid cert
  140. ##!define XMLRPC_TLS_ONLY
  141. # xmlrpc allowed subnets (if defined XMLRPC requests with source ip matching
  142. # this network addresses will be allowed, if no XMLRPC_ALLOWED_SUBNETx is
  143. # defined only requests coming from localhost will be allowed).
  144. # E.g.: ser -A XMLRPC_ALLOW_NET1=192.168.1.0/24 -f ser-oob.cfg
  145. ##!define XMLRPC_ALLOW_NET1 192.168.0.0/16
  146. ##!define XMLRPC_ALLOW_NET2 10.0.0.0/255.0.0.0
  147. ##!define XMLRPC_ALLOW_NET3 172.16.0.0/12
  148. # started from compile directory (not installed)
  149. ##!define LOCAL_TEST_RUN
  150. # ----------- Global Configuration Parameters -------------------------------
  151. #debug=3 # debug level (cmd line: -ddd)
  152. #memdbg=10 # memory debug log level
  153. #memlog=10 # memory statistics log level
  154. #log_facility=LOG_LOCAL0 # the facility used for logging (see syslog(3))
  155. #DEBCONF-SERVERID-START
  156. server_id=0
  157. #DEBCONF-SERVERID-END
  158. # Uncomment these lines to enter debugging mode or start SER with
  159. # sip-router -ED
  160. #
  161. #fork=no
  162. #log_stderror=yes
  163. check_via=no # (cmd. line: -v)
  164. dns=no # (cmd. line: -r)
  165. rev_dns=no # (cmd. line: -R)
  166. #port=5060
  167. #children=4
  168. #user=sip-router
  169. #group=sip-router
  170. #disable_core=yes # disables core dumping
  171. #open_files_limit=20480 # sets the open file descriptors limit
  172. #mhomed=yes # usefull for multihomed hosts, small performance
  173. # penalty
  174. disable_tcp=no # be conservative about enabling TCP -- it can
  175. # degrade performance a lot
  176. #tcp_accept_aliases=yes # accepts the tcp alias via option
  177. phone2tel=no # ignore user=phone in request-URIs -- otherwise
  178. # these URIs would be interpreted as equivalent
  179. # to TEL URIs, and their lookup would fail in URI
  180. # database
  181. reply_to_via=no
  182. sip_warning=yes
  183. # public IP address
  184. #DEBCONF-LISTEN-START
  185. listen=127.0.0.1
  186. #DEBCONF-LISTEN-END
  187. # sip.mcast.net for REGISTER replication
  188. #DEBCONF-LISTEN_REPL-START
  189. listen=udp:224.0.1.75
  190. #DEBCONF-LISTEN_REPL-END
  191. # administrative interface -- needed for example for multicast source
  192. # or XML-RPC
  193. #DEBCONF-LISTEN_ADMIN-START
  194. listen=udp:127.0.0.1
  195. #DEBCONF-LISTEN_ADMIN-END
  196. #listen=tls:127.0.0.1:5061
  197. mlock_pages=yes
  198. shm_force_alloc=yes
  199. real_time=7
  200. # ------------------- DNS Parameters ----------------------------------------
  201. # (see doc/dns.txt for more details)
  202. #
  203. # minimum timeouts
  204. dns_retr_time=1
  205. dns_retr_no=1
  206. dns_servers_no=1
  207. dns_use_search_list=no
  208. dns_try_ipv6=no
  209. # dns cache & failover
  210. use_dns_cache=on
  211. use_dns_failover=on
  212. # dns_cache_flags=0
  213. dns_cache_negative_ttl=300
  214. dns_cache_min_ttl=60
  215. dns_cache_max_ttl=86400 # 1 day
  216. dns_cache_mem=2048 # 2 MB
  217. dns_cache_gc_interval=60 # garbage collection every minute
  218. # ser 2.1 specific options
  219. dns_try_naptr=yes
  220. dns_srv_lb=yes # srv based load balancing
  221. dns_udp_pref=3 # prefer udp (when resolving naptr record)
  222. dns_tcp_pref=2 # if no udp available accept tcp (for naptr)
  223. dns_sctp_pref=2 # same preference as tcp
  224. #!ifdef WITH_TLS
  225. dns_tls_pref=1 # low preference (heavy resource use)
  226. #!else
  227. dns_tls_pref=-1 # ignore / don't accept tls (for naptr)
  228. #!endif
  229. # dns_cache_delete_nonexpired=no
  230. # ------------------- Blacklist Parameters ----------------------------------
  231. # (see doc/dst_blacklist.txt for more details)
  232. #
  233. use_dst_blacklist=on
  234. dst_blacklist_mem=1024 # 1 MB
  235. dst_blacklist_expire=300 # blacklist default time
  236. dst_blacklist_gc_interval=150 # 2.5 min
  237. # for sip-router 2.1 to the above add tm blst_503* parameters and/or use the
  238. # blst module (see NEWS)
  239. # ------------------- TCP Parameters ----------------------------------------
  240. # (see NEWS for more details)
  241. tcp_connection_lifetime=3600
  242. #tcp_max_connections=10240 # default is 2048
  243. tcp_connect_timeout=1
  244. tcp_async=yes
  245. # ------------------- TLS Parameters ----------------------------------------
  246. #!ifdef WITH_TLS
  247. # Enable TLS hooks so that the TLS module can be used
  248. tls_enable=yes
  249. #!endif
  250. # -------------------- Custom Parameters ------------------------------------
  251. # These parameters can be modified runtime via RPC interface,
  252. # read the documentation of cfg_rpc module.
  253. # Session Timer parameters, RFC 4028
  254. #
  255. # Default session interval used by the proxy if the UAC does not support
  256. # session timer. Set it to "0" to disable session timer proxy support.
  257. #
  258. session_timer.default = "1800" desc "default session interval (in s)"
  259. #
  260. # Minimum session interval accepted by the proxy, it must not be less
  261. # than 90 seconds.
  262. #
  263. session_timer.min_se = "90" desc "minimum session interval (in s)"
  264. # RTP Proxy options
  265. #
  266. # Whether to enable or disable the rtp proxy. Possible values are:
  267. # "0" -- always disable
  268. # "1" -- always enable regardless of whether UAC or UAS is behind NAT
  269. # "detect" -- detect whether the UAC or the UAS is behind NAT,
  270. # and enable the rtp proxy when necessary
  271. #
  272. #DEBCONF-RTP_ENABLE-START
  273. rtp_proxy.enabled = "detect" desc "indicates whether the RTP Proxy is enabled or not (0/1/detect)"
  274. #DEBCONF-RTP_ENABLE-END
  275. # ------------------ Module Loading -----------------------------------------
  276. #!ifdef LOCAL_TEST_RUN
  277. loadpath "modules:modules_s"
  278. #!else
  279. loadpath "/usr/lib/sip-router/modules:/usr/lib/sip-router/modules_s"
  280. #!endif
  281. # load a SQL database for authentication, domains, user AVPs etc.
  282. loadmodule "db_mysql"
  283. #loadmodule "postgres"
  284. loadmodule "tm"
  285. loadmodule "sl"
  286. loadmodule "rr"
  287. loadmodule "maxfwd"
  288. loadmodule "usrloc"
  289. loadmodule "registrar"
  290. loadmodule "xlog"
  291. loadmodule "textops"
  292. loadmodule "ctl"
  293. loadmodule "auth"
  294. loadmodule "auth_db"
  295. loadmodule "gflags"
  296. loadmodule "domain"
  297. loadmodule "uri_db"
  298. loadmodule "avp"
  299. loadmodule "avp_db"
  300. loadmodule "acc_db"
  301. #!ifdef WITH_XMLRPC
  302. loadmodule "xmlrpc"
  303. #!endif
  304. loadmodule "options"
  305. loadmodule "sanity"
  306. loadmodule "nathelper"
  307. loadmodule "uri"
  308. loadmodule "speeddial"
  309. loadmodule "timer"
  310. loadmodule "db_ops"
  311. loadmodule "exec"
  312. loadmodule "cfg_rpc"
  313. loadmodule "eval"
  314. loadmodule "enum"
  315. #!ifdef WITH_TLS
  316. loadmodule "tls"
  317. #!endif
  318. # ----------------- Declaration of Script Flags -----------------------------
  319. flags
  320. FLAG_ACC : 1, # the request will be recorded by ACC
  321. FLAG_FAILUREROUTE : 2, # we are operating from the failure route
  322. FLAG_NAT : 3, # the UAC is behind a NAT
  323. FLAG_REPL_ENABLED : 4, # REGISTER replication is enabled if set
  324. FLAG_TOTAG : 5, # request has a To tag
  325. FLAG_PSTN_ALLOWED : 6, # the user is allowed to use the PSTN
  326. FLAG_DONT_RM_CRED : 7, # do not remove the credentials
  327. FLAG_AUTH_OK : 8, # authentication succeeded
  328. FLAG_SERWEB_RSVD1 : 9, # bit reserved for use with serweb
  329. FLAG_SERWEB_RSVD2 : 10, # bit reserved for use with serweb
  330. FLAG_SESSIONTIMER : 11, # indicates that the UAC supports Session Timer
  331. FLAG_RR_DONE : 12, # the request got already one RR header
  332. FLAG_RTP_PROXY : 13, # the RTP proxy is turned on
  333. FLAG_NAT_REG : 14, # the UAC behind NAT, stored in location record
  334. FLAG_INIT_DLG : 15, # init INVITE dialog
  335. FLAG_REVERSE_DIR : 16, # set if request goes callee -> caller direction, requires rr.append_fromtag=1
  336. FLAG_ACC_MISSED : 17, # the missed call will be recorded by ACC
  337. FLAG_USRLOC_FWD : 18, # usrloc based forward
  338. FLAG_NEXT_ROUTE : 19; # there is a route remaining
  339. avpflags
  340. dialog_cookie; # attribute will be stored in Route headers
  341. # ----------------- Module-specific Parameters ------------------------------
  342. # path to the database
  343. #
  344. #DEBCONF-DBURL-START
  345. modparam("speeddial|auth_db|usrloc|domain|uri_db|gflags|avp_db|db_ops",
  346. "db_url", "mysql://ser:heslo@localhost/ser")
  347. #DEBCONF-DBURL-END
  348. # specify the path to your database for accounting
  349. #DEBCONF-DBURLACC-START
  350. modparam("acc_db", "db_url", "mysql://ser:heslo@localhost/ser")
  351. #DEBCONF-DBURLACC-END
  352. # -- usrloc --
  353. # Database access mode: 0 -- memory cached, 1 -- write through,
  354. # 2 -- delayed write. 1 is generally safer than 2. 2 can help
  355. # to survive peaks in load. However, it creates delayed peaks that can
  356. # impair request-processing latency later (usrloc would have to be
  357. # re-redesigned more lock-free to avoid it).
  358. #DEBCONF-DBMODE-START
  359. modparam("usrloc", "db_mode", 1)
  360. #DEBCONF-DBMODE-END
  361. # Don't delete expired records from database on a per-contact basis -- that
  362. # results in bulky DB operations and can lead to synchronization issues
  363. # in server farm when for a time a server doesn't obtain re-reregistrations
  364. modparam("usrloc","db_skip_delete",1)
  365. # -- registrar --
  366. # Maximum expires time. Forces users to re-register every 10 min.
  367. modparam("registrar", "max_expires", 600)
  368. # Minimum expires time. Even if they try, clients cannot register
  369. # for a shorter time than this.
  370. modparam("registrar", "min_expires", 240)
  371. # Identify natted contacts using a flag.
  372. modparam("registrar", "load_nat_flag", "FLAG_NAT_REG")
  373. modparam("registrar", "save_nat_flag", "FLAG_NAT_REG")
  374. # Maximum number of contacts.
  375. modparam("registrar", "max_contacts", 10)
  376. # -- auth --
  377. #modparam("auth_db", "calculate_ha1", yes)
  378. #modparam("auth_db", "password_column", "password")
  379. # Minimize replay-attack window.
  380. modparam("auth", "nonce_expire", 10)
  381. # Enable/disable extra authentication checks using the following modparams.
  382. # The values are: 1 -- Request-URI, 2 -- Call-ID, 4 -- From tag,
  383. # 8 -- source IP. The options are disabled by default.
  384. # For REGISTER requests we hash the Request-URI, Call-ID, and source IP of the
  385. # request into the nonce string. This ensures that the generated credentials
  386. # cannot be used with another registrar, user agent with another source IP
  387. # address or Call-ID. Note that user agents that change Call-ID with every
  388. # REGISTER message will not be able to register if you enable this.
  389. #modparam("auth", "auth_checks_register", 11)
  390. # For dialog-establishing requests (such as the original INVITE, OPTIONS, etc)
  391. # we hash the Request-URI and source IP. Hashing Call-ID and From tags takes
  392. # some extra precaution, because these checks could render some UA unusable.
  393. #modparam("auth", "auth_checks_no_dlg", 9)
  394. # For mid-dialog requests, such as re-INVITE, we can hash source IP and
  395. # Request-URI just like in the previous case. In addition to that we can hash
  396. # Call-ID and From tag because these are fixed within a dialog and are
  397. # guaranteed not to change. This settings effectively restrict the usage of
  398. # generated credentials to a single user agent within a single dialog.
  399. #modparam("auth", "auth_checks_in_dlg", 15)
  400. # Deal with clients who can't do qop properly
  401. modparam("auth", "qop", "")
  402. #DEBCONF-AUTHSECRET-START
  403. modparam("auth", "secret", "aqwedrftredswqwddcft")
  404. #DEBCONF-AUTHSECRET-END
  405. # -- rr --
  406. # Add value to lr param to make some broken UAs happy.
  407. modparam("rr", "enable_full_lr", 1)
  408. # Limit the length of the AVP cookie to necessary attributes only
  409. modparam("rr", "cookie_filter", "(account|rproxy|stimer|dialog_id)")
  410. # You probably do not want that someone can simply read and change
  411. # the AVP cookie in your Routes, thus should really change this
  412. # secret value below
  413. modparam("rr", "cookie_secret", "sgsatewgdbsnmpoiewh")
  414. # The ftag Route parameter may be used to easily determine if a BYE
  415. # is coming from caller or callee, but we prefer shorter messages
  416. # Enable when FLAG_REVERSE_DIR is to be used
  417. modparam("rr", "append_fromtag", 0)
  418. # -- gflags --
  419. # Load global attributes.
  420. modparam("gflags", "load_global_attrs", 1)
  421. # -- domain --
  422. # Load domain attributes.
  423. modparam("domain", "load_domain_attrs", 1)
  424. # -- ctl --
  425. # By default, ctl listens on unixs:/tmp/sip-router_ctl if no other address is
  426. # specified in modparams; this is also the default for sercmd.
  427. modparam("ctl", "binrpc", "unixs:/tmp/ser_ctl")
  428. # Listen on the "standard" fifo for backward compatibility.
  429. modparam("ctl", "fifo", "fifo:/tmp/ser_fifo")
  430. # Listen on tcp on localhost.
  431. modparam("ctl", "binrpc", "tcp:127.0.0.1:2046")
  432. # -- acc_db --
  433. # Failed transactions (those with negative responses) should be logged, too.
  434. modparam("acc_db", "failed_transactions", 1)
  435. # If you don't want to have accounting entries written into the database,
  436. # comment the next line out.
  437. modparam("acc_db", "log_flag", "FLAG_ACC")
  438. # seems "log_flag" and "log_flag_missed" cannot share the same flag!
  439. modparam("acc_db", "log_missed_flag", "FLAG_ACC_MISSED")
  440. # if you would like to customize your CDRs, do it here....
  441. #modparam("acc_db", "attrs",
  442. # "$f.sop_billing_category,$f.isPrepaidCustomer,$f.sop_cf_orig_uid")
  443. # -- tm --
  444. # Do not restart the resend timer with each reply. (See INBOUND route
  445. # below.)
  446. modparam("tm", "restart_fr_on_each_reply", 0)
  447. # -- xmlrpc --
  448. #!ifdef WITH_XMLRPC
  449. # Use a sub-route. This is a lot safer then relying on the request method
  450. # to distinguish HTTP from SIP
  451. modparam("xmlrpc", "route", "XMLRPC");
  452. #!endif
  453. # -- nathelper --
  454. # RTP Proxy address
  455. #DEBCONF-RTTPPROXY-START
  456. modparam("nathelper", "rtpproxy_sock", "udp:127.0.0.1:22222")
  457. #DEBCONF-RTTPPROXY-END
  458. # TCP keepalives as simple as CRLF
  459. modparam("nathelper", "natping_crlf", 0)
  460. # How often to send a NAT ping. Set this to 0 to turn NAT ping off.
  461. #DEBCONF-NATPING_INTERVAL-START
  462. modparam("nathelper", "natping_interval", 15)
  463. #DEBCONF-NATPING_INTERVAL-END
  464. # Only ping contacts that have the NAT flag set.
  465. modparam("nathelper", "ping_nated_only", 1)
  466. # Send an OPTIONS SIP request as NAT ping. If this is not set, a simple
  467. # 4-byte ping is used.
  468. modparam("nathelper", "natping_method", "OPTIONS")
  469. # Temporary statefull natping test (only in future versions)
  470. #modparam("nathelper", "natping_stateful", 1)
  471. # -- exec --
  472. modparam("exec", "time_to_kill", 200);
  473. modparam("exec", "setvars", 0);
  474. # -- timer --
  475. # Register route ON_1MIN_TIMER to be called every minute.
  476. modparam("timer", "declare_timer",
  477. "ON_1MIN_TIMER=ON_1MIN_TIMER,60000,slow,enable");
  478. #!ifdef WITH_TLS
  479. # -- tls --
  480. #!ifdef LOCAL_TEST_RUN
  481. modparam("tls", "config", "./modules/tls/tls.cfg");
  482. #!else
  483. modparam("tls", "config", "tls.cfg");
  484. #!endif
  485. #!endif
  486. # -- db_ops --
  487. modparam("db_ops", "declare_handle", "reload")
  488. modparam("db_ops", "declare_handle", "gattr_reload")
  489. # ------------------------- Request Routing Logic --------------------------
  490. # Main request route.
  491. #
  492. # Each request starts here.
  493. #
  494. route
  495. {
  496. # if you have a PSTN gateway just un-comment the follwoing line and
  497. # specify the IP address of it to route calls to it.
  498. #$gw_ip = "1.2.3.4"
  499. # Alternatively (even better), set it as global persistent parameter
  500. # using serweb or ser_attrs). If using a PSTN GW, per-subscriber
  501. # options must ($gw_acl) or may (asserted_id) be set to enable calls
  502. # to PSTN. If email-like URIs are used, having a URI alias for
  503. # processing incoming PSTN-to-ip requests may be useful, too.
  504. # Important: the script is assuming one global pstn-gw for all
  505. # domains! Failure to allow gw_ip to be a domain-specic attribute
  506. # would result in security gaps (onsend_route checks only for one
  507. # gateway).
  508. # First, do some initial sanity checks.
  509. route(INIT);
  510. # Bypass the rest of the script for CANCELs if possible.
  511. route(CATCH_CANCEL);
  512. # Check if the request is routed via Route header.
  513. route(PROCESS_ROUTES);
  514. # Look up domain IDs
  515. route(DOMAIN);
  516. # Answer OPTIONS requests to our system.
  517. route(OPTIONS_REPLY);
  518. # Enforce domain policy.
  519. route(DOMAIN_POLICY);
  520. # Handle REGISTER requests.
  521. route(REGISTRAR);
  522. # From here on we want to know who is calling.
  523. route(AUTHENTICATION);
  524. # We are finished with all the precaution work -- let's
  525. # try to locate the callee. The first route that matches
  526. # "wins" and relays the request. If none matches, SER will
  527. # send a 404.
  528. # Check if we should be outbound proxy for a local user.
  529. route(OUTBOUND);
  530. # Redirect in case user dialed a speed dial entry.
  531. route(SPEEDDIAL);
  532. # Place various site-specific routes here.
  533. route(SITE_SPECIFIC);
  534. # Check if the request is for a local user.
  535. route(INBOUND);
  536. # There is SIP user for the called address. Before trying PSTN,
  537. # you may have to convert the adress, for instance by using
  538. # ENUM.
  539. #route(ENUM);
  540. # Last resort: if none of the previous route has found
  541. # the recepient, try PSTN.
  542. route(PSTN);
  543. # nothing matched
  544. sl_reply("404", "No route matched");
  545. }
  546. # Forward a request to the destination set.
  547. #
  548. route[FORWARD]
  549. {
  550. # If this is called from the failure route we need to add a new
  551. # branch.
  552. if (isflagset(FLAG_FAILUREROUTE)) {
  553. if (!append_branch()) {
  554. t_reply("500", "Too many branches");
  555. drop;
  556. }
  557. }
  558. # If this is an initial INVITE (without a To-tag) we might try
  559. # another target (call forwarding or voicemail) after receiving
  560. # an error.
  561. if (isflagset(FLAG_INIT_DLG)) {
  562. t_on_failure("FAILURE_ROUTE");
  563. }
  564. # Always use the reply route to check for NATed UAS.
  565. t_on_reply("REPLY_ROUTE");
  566. # Remove credentials to keep requests shorter
  567. if (isflagset(FLAG_AUTH_OK) && !isflagset(FLAG_DONT_RM_CRED) ) {
  568. consume_credentials();
  569. }
  570. # Activate the RTP proxy as the second last step because it modifies the
  571. # body but also sets an dialog AVP cookie.
  572. route(RTPPROXY);
  573. # Insert a Record-Route header into all requests.
  574. # This has to be done as one of the last steps to include all the
  575. # RR cookies which might have been created during the script run.
  576. route(RECORD_ROUTE);
  577. # Send it out now.
  578. if (!t_relay()) {
  579. if (isflagset(FLAG_FAILUREROUTE)) {
  580. # XXX This should be replaced with
  581. # t_reply_error() similar to sl_reply_error()
  582. # in order to return the proper failure code.
  583. # Only, there is no such function yet.
  584. t_reply("500", "Request cannot be forwarded");
  585. }
  586. else {
  587. sl_reply_error();
  588. }
  589. }
  590. drop;
  591. }
  592. # Perform initial checks on an incoming request.
  593. #
  594. # Rejects the request if it fails any of the checks.
  595. #
  596. route[INIT]
  597. {
  598. # Messages with a Max-Forwards header of zero.
  599. if (!mf_process_maxfwd_header("10")) {
  600. sl_reply("483","Too Many Hops");
  601. drop;
  602. }
  603. # Set flag for use in the onsend route (because it does not
  604. # allow to use "select" statements)
  605. if (@to.tag != "") {
  606. setflag(FLAG_TOTAG);
  607. }
  608. # Check if the UAC is NATed and fix the message accordingly
  609. route(UAC_NAT_DETECTION);
  610. # Activate accounting for all initial INVITEs. In-dialog requests
  611. # are accounted by a RR cookie (see below).
  612. # It should work also when the call has been already forked at a previous router
  613. if (method == "INVITE" && !isflagset(FLAG_TOTAG)) {
  614. $dialog_id = @sys.unique; # make unique dialogid
  615. setflag(FLAG_ACC);
  616. setflag(FLAG_ACC_MISSED);
  617. setflag(FLAG_INIT_DLG);
  618. } else if (isflagset(FLAG_TOTAG) && @hf_value.route[0].params.ftag != @from.tag) {
  619. setflag(FLAG_REVERSE_DIR); # callee -> caller
  620. }
  621. # if needed then we MUST put after force_rport() which is located in NAT_DETECTION!!!
  622. # also must be called after FLAG_ACC is set !!!
  623. # Check t_reply() vs. sl_reply() usage in script
  624. #if (!t_newtran()) {
  625. # sl_reply("500", "Internal tm error");
  626. # drop;
  627. #}
  628. # Set flag and use it instead of the attribute.
  629. if ($replicate==1) {
  630. setflag(FLAG_REPL_ENABLED);
  631. }
  632. }
  633. # Reply OPTIONS requests sent to the proxy itself.
  634. #
  635. route[OPTIONS_REPLY]
  636. {
  637. # OPTIONS requests without a username in the Request-URI but one
  638. # of our domains or IPs are addressed to the proxy itself and
  639. # can be answered statelessly.
  640. if (method == "OPTIONS" && strempty(@ruri.user) &&
  641. (uri == myself || $t.did != ""))
  642. {
  643. options_reply();
  644. drop;
  645. }
  646. }
  647. # Check if the sender of the request is behind a NAT device. If so,
  648. # fix the request so that other devices can talk to the sender nonetheless.
  649. #
  650. route[UAC_NAT_DETECTION]
  651. {
  652. # Lots of UAs do not include the rport parameter in there Via
  653. # header, so we put it there regardless.
  654. force_rport();
  655. # If a reliable transport was used store the connection internally
  656. # so that SERs core can re-use the connection later.
  657. if (proto==TCP || proto == TLS)
  658. {
  659. force_tcp_alias();
  660. }
  661. # Check if the request contains hints for a NATed UAC. Also, try to
  662. # rewrite contacts using maddr. Using maddr is a really dubious
  663. # technique and we better replace such with transport address.
  664. # Downside: it fails for clients fronted by another server, in
  665. # which case a valid contact we dislike because of maddr will be
  666. # substituted inapproprietely (e.g., WM from other domains will
  667. # fail). If you are worried about that, remove tests for maddr and
  668. # recompile SER using HONOR_MADDR. Also note that rewriting
  669. # contacts may possibly lead to client denying subseqent requests
  670. # to them because they don't recognized fixed contacts as their
  671. # own. Should you encounter such a case, a possible solution
  672. # would be to store the original information as a contact parameter
  673. # and restore it on its way back.
  674. # In case of UDP we test for
  675. # - private IPs in Contact
  676. # - mismatch of transport IP and IP in Via
  677. # - mismatch of transport port and port in Via
  678. # in all other cases we skip the port test, because lots of clients
  679. # do not correctly advertise their emphemeral port number in their Via
  680. # header in case of reliable transports (although they are not behind
  681. # a NAT).
  682. # Warning: if you are dealing with SIP implementations which are
  683. # running on public IP and do as-symmertic signaling for whatever
  684. # reason the following check will make their signaling symmetric.
  685. # If you need to support as-symmertic signaling reduce the following
  686. # nat_uac_test for UDP to "3" or even "1".
  687. if ((proto == UDP && nat_uac_test("19")) ||
  688. (nat_uac_test("3")) ||
  689. (@hf_value["contact"] != "" && @contact.uri.params.maddr != ""))
  690. {
  691. setflag(FLAG_NAT);
  692. if (method == "REGISTER") {
  693. # Prepare the Contact so that the registrar module
  694. # saves the source address and port as well.
  695. fix_nated_register();
  696. }
  697. else {
  698. # Overwrite the Contact to allow proper in-dialog
  699. # routing.
  700. # but do not override if there is already a proxy in the path, we'll route by record-route,
  701. # RURI responsibility takes to previous proxy
  702. # TODO: shouldn't we rather limit to methods which are dialog aware (INVITE, UPDATE, SUBSCRIBE, ..)
  703. if (strempty(@hf_value.record_route) || (@hf_value["contact"]!="" && @contact.uri.params.maddr!="")) {
  704. fix_nated_contact();
  705. }
  706. }
  707. }
  708. }
  709. # Check if the receiver of the request is behind a NAT device. If so,
  710. # fix the Contact header to allow proper routing of in-dialog requests.
  711. route[UAS_NAT_DETECTION]
  712. {
  713. # Fix the Contact in the reply if it contains a private IP to
  714. # allow proper routing of in-dialog messages.
  715. # Do the same if the contact is maddred.
  716. # But skip 3XX responses, because we do not know the right IP for that,
  717. # even if they contain private IPs.
  718. if (status=~"(3[0-9][0-9])") {
  719. break;
  720. }
  721. # prevent contact overwriting when a proxy between ser and UAS.
  722. # We get it from record-route but it's rather difficult or
  723. # do it only for UAS which is registered in usrloc database and has no
  724. # proxy on path.
  725. # Note: destination forced by $fwd_always_target is not NAT detected and contact left untouched!
  726. if (isflagset(FLAG_INIT_DLG) && !isflagset(FLAG_USRLOC_FWD)) {
  727. break;
  728. }
  729. # for in-dialog requests we get it easily because it provides loose_route()
  730. if (!isflagset(FLAG_INIT_DLG) && isflagset(FLAG_NEXT_ROUTE)) {
  731. break;
  732. }
  733. # Prevent that we over-write the Contact with the IP of our proxy when
  734. # the reply loops through ourself.
  735. if (src_ip == myself) {
  736. break;
  737. }
  738. # In this case we check only if the Contact URI contains a private
  739. # IP, because the Via header contains only informations from the UAC.
  740. # Additionally we check if the port in the Contact URI differs from
  741. # the port of the transport to catch UAS or ALG which put the public
  742. # IP address into the Contact header, but "forget" about the port.
  743. # Warning: if you are dealing with SIP implementations which are
  744. # running on public IP and do as-symmertic signaling for whatever
  745. # reason the following check will make their signaling symmetric.
  746. # If you need to support as-symmertic signaling reduce the following
  747. # nat_uac_test for UDP to just "1".
  748. if ( (proto == UDP && nat_uac_test("33")) ||
  749. (nat_uac_test("1") ||
  750. (@hf_value["contact"] != "" && @contact.uri.params.maddr != "")))
  751. {
  752. # TODO: check if no proxy between UAS&myself
  753. fix_nated_contact();
  754. }
  755. }
  756. # Activates RTP proxy if necessary.
  757. #
  758. route[RTPPROXY]
  759. {
  760. if (@cfg_get.rtp_proxy.enabled == "0") {
  761. # RTP Proxy is disabled
  762. break;
  763. } else if (@cfg_get.rtp_proxy.enabled == "detect") {
  764. if (!isflagset(FLAG_NAT)) {
  765. # If no NAT is involved we don't have to do here anything.
  766. break;
  767. }
  768. } else if (@cfg_get.rtp_proxy.enabled != "1") {
  769. # This is not a valid setting
  770. xlog("L_ERR", "Unknown option for rtp_proxy.enabled: %@cfg_get.rtp_proxy.enabled\n");
  771. break;
  772. } # else rtp proxy is permanently enabled
  773. # If the message terminates a dialog for which the RTP proxy
  774. # was turned on, turn it off again.
  775. if ((method == "BYE" && isflagset(FLAG_RTP_PROXY)) ||
  776. (method == "CANCEL")) {
  777. unforce_rtp_proxy();
  778. append_hf("P-RTP-Proxy: Off\r\n");
  779. break;
  780. }
  781. # Turn the RTP proxy on for INVITEs and UPDATEs, if they
  782. # have a body
  783. if (((method=="INVITE" || method == "UPDATE") && @msg.body != "")
  784. && !isflagset(FLAG_RTP_PROXY))
  785. {
  786. force_rtp_proxy('r');
  787. append_hf("P-RTP-Proxy: On\r\n");
  788. setflag(FLAG_RTP_PROXY);
  789. $rproxy = 1;
  790. setavpflag($rproxy, "dialog_cookie");
  791. }
  792. }
  793. # Handling of Route headers
  794. #
  795. route[PROCESS_ROUTES]
  796. {
  797. # subsequent messages withing a dialog should take the
  798. # path determined by the Route headers.
  799. if (loose_route()) {
  800. if (!defined $dialog_id) {
  801. $dialog_id = $t.dialog_id; # there is only 1 dialog_id
  802. }
  803. if (@rr.next_route != "") {
  804. setflag("FLAG_NEXT_ROUTE");
  805. }
  806. xlog("L_DEBUG", "\n%mb\n\ndialogid -/from/to=%$dialog_id/%$f.dialog_id/%$t.dialog_id");
  807. if (method == "INVITE" || method == "UPDATE" || method == "ACK" || method == "BYE") {
  808. if (!defined $dialog_id) {
  809. sl_reply("400", "Missing cookie");
  810. drop;
  811. }
  812. }
  813. # Mark routing logic in request.
  814. append_hf("P-hint: rr-enforced\r\n");
  815. # If the Route contained the accounting AVP cookie we
  816. # set the accounting flag for the acc_db module.
  817. # This is more for demonstration purpose as this could
  818. # also be solved without RR cookies.
  819. # Note: this means all in-dialog request will show up in
  820. # the accounting tables, so prepare your accounting software
  821. # for this.
  822. if ($account == "yes") {
  823. setflag(FLAG_ACC);
  824. setflag(FLAG_ACC_MISSED);
  825. }
  826. # Restore the RTP proxy flag if present
  827. if ($rproxy == "1") {
  828. setflag(FLAG_RTP_PROXY);
  829. }
  830. # Restore Session Timer flag and headers.
  831. if ( defined $stimer && ($stimer != "0")) {
  832. route(SESSION_TIMER);
  833. }
  834. # Some broken devices overide the dialog route set with the
  835. # Record-Route headers from each in-dialog request. So, we
  836. # better add Record-Route headers again. If we call
  837. # record_route() after loose_route(), the AVP cookies are
  838. # restored automatically. Additionally, there is a scenario
  839. # where Record-Route headers are necessary if an initial
  840. # SUBSCRIBE is forked.
  841. #
  842. # Note that here we forward before authentication checks
  843. # are executed. Generally, we only authenticate
  844. # out-of-dialog requests. Some in-dialog requests can't be
  845. # authenticated at all, see the call-forwarding example in
  846. # route[DOMAIN].
  847. route(RECORD_ROUTE);
  848. route(FORWARD);
  849. }
  850. }
  851. # Add a Record-Route header
  852. #
  853. route[RECORD_ROUTE]
  854. {
  855. if (!isflagset(FLAG_RR_DONE) && method != "REGISTER") {
  856. # We record-route all messages to make sure that
  857. # subsequent messages will go through our proxy. This is
  858. # particularly good if upstream and downstream entities
  859. # use different transport protocols.
  860. # If the ACC flag is set, store this in a Record-Route
  861. # AVP cookie. This is more for demonstration purposes.
  862. if (isflagset(FLAG_ACC)) {
  863. $account = "yes";
  864. setavpflag($account, "dialog_cookie");
  865. }
  866. setavpflag("$f.dialog_id", "dialog_cookie");
  867. # Insert the RR header.
  868. record_route();
  869. # This flag allows to call this route several times
  870. # without inserting several RR headers.
  871. setflag(FLAG_RR_DONE);
  872. }
  873. }
  874. # Look up the domains of the caller and the callee.
  875. #
  876. route[DOMAIN]
  877. {
  878. # Check whether the caller is from a local domain.
  879. lookup_domain("$fd", "@from.uri.host");
  880. # Check whether the callee is at a local domain
  881. lookup_domain("$td", "@ruri.host");
  882. }
  883. # Check domain usage policies and reject illegal requests.
  884. #
  885. route[DOMAIN_POLICY]
  886. {
  887. # If we don't know the domain of the caller nor the domain of the
  888. # callee, somone tries to use our proxy as a relay. However, we
  889. # can only apply this check out-of-dialog requests without a To
  890. # tag. In some cases such as call-forwarding, subsequent requests
  891. # may not include served domain neither as origination nor
  892. # destination (a@A calls b@B who forwards to c@C. A BYE by c@C is
  893. # then From b@B and To a@A. There is no mentioning of c@C despite
  894. # legitimate behaviour of c@C).
  895. if (!isflagset(FLAG_TOTAG) && strempty($t.did) && strempty($f.did)) {
  896. sl_reply("403", "Relaying Forbidden");
  897. drop;
  898. }
  899. }
  900. # The Registrar
  901. #
  902. route[REGISTRAR]
  903. {
  904. # Process only REGISTERs here.
  905. if (method != "REGISTER") {
  906. break;
  907. }
  908. # If this is a replica (sent to the multicast address), trust it to
  909. # be secure and store it in usrloc
  910. if (dst_ip==224.0.1.75) {
  911. if (!isflagset(FLAG_REPL_ENABLED)) {
  912. # Multicast replication administratively disabled.
  913. # Ignore.
  914. drop;
  915. }
  916. # Read marker from master
  917. if (search("^Repl-Marker: nated")) {
  918. setflag(FLAG_NAT);
  919. }
  920. # If the replicating server added its own server id to the
  921. # request, obtain the value and store it in an attribute.
  922. # This is used by registrar.
  923. $server_id = @msg.header["SER-Server-ID"];
  924. # Assume URI in form of UID@mydomain and store contacts
  925. # under this UID. Note that this only works if local policy
  926. # causes UIDs to have form compliant to RFC3261 URI
  927. # usernames.
  928. if (@ruri.user!="")
  929. $tu.uid = @ruri.user;
  930. if (isflagset(FLAG_NAT)) {
  931. setflag(FLAG_NAT_REG);
  932. }
  933. if (!save_mem_nr("location")) {
  934. log(1, "Error while saving replicated REGISTER.\n");
  935. }
  936. drop;
  937. }
  938. else {
  939. # This is a REGISTER request received from the UA. Remove
  940. # our internal header fields if they are present. The may
  941. # have been added maliciously.
  942. remove_hf("SER-Server-ID");
  943. remove_hf("Repl-Marker");
  944. }
  945. # Check if the REGISTER if for one of our local domains.
  946. if (strempty($t.did)) {
  947. sl_reply("403", "Register Forwarding Forbidden");
  948. drop;
  949. }
  950. # The REGISTER target is in the To header, so reload the domain.
  951. if (!lookup_domain("$td", "@to.uri.host")) {
  952. sl_reply("404", "Unknown Domain");
  953. drop;
  954. }
  955. # Useful for clients that ignore expires in 200 (OK). This is an
  956. # attempt to keep them sticking to our value of 600.
  957. append_to_reply("Expires: 600\r\n");
  958. append_to_reply("Min-Expires: 240\r\n");
  959. # We want only authenticated users to be registered.
  960. if (!www_authenticate("$fd.digest_realm", "credentials")) {
  961. if ($? == -2) {
  962. sl_reply("500", "Internal Server Error");
  963. }
  964. else if ($? == -3) {
  965. sl_reply("400", "Bad Request");
  966. }
  967. else {
  968. if ($digest_challenge != "") {
  969. append_to_reply("%$digest_challenge");
  970. }
  971. sl_reply("401", "Unauthorized");
  972. }
  973. drop;
  974. }
  975. # Check if the authenticated user is the same as the target user.
  976. if (!lookup_user("$tu.uid", "@to.uri")) {
  977. sl_reply("404", "Unknown user in To");
  978. drop;
  979. }
  980. # the authentication ID does not match the ID in the To header
  981. if ($f.uid != $t.uid) {
  982. sl_reply("403", "Authentication and To-Header mismatch");
  983. drop;
  984. }
  985. # Check if the authenticated user is the same as the request
  986. # originator. You may uncomment it if you care, which URI is in
  987. # the From header.
  988. #if (!lookup_user("$fr.uid", "@from.uri")) {
  989. # sl_reply("404", "Unknown user in From");
  990. # drop;
  991. #}
  992. #if ($fu.uid != $fr.uid) {
  993. # sl_reply("403", "Authentication and From-Header mismatch");
  994. # drop;
  995. #}
  996. if (isflagset(FLAG_NAT)) {
  997. setflag(FLAG_NAT_REG);
  998. }
  999. # Everything is fine. Store the binding.
  1000. if (!save_contacts("location")) {
  1001. sl_reply("400", "Invalid REGISTER Request");
  1002. drop;
  1003. }
  1004. # do not delete the following 3 lines, they are used by debconf
  1005. #DEBCONF-REPLICATION1-START
  1006. #
  1007. #DEBCONF-REPLICATION1-END
  1008. if (isflagset(FLAG_REPL_ENABLED)) {
  1009. if (isflagset(FLAG_NAT)) {
  1010. append_hf("Repl-Marker: nated\r\n");
  1011. }
  1012. # Append this server's unique ID to the request
  1013. append_hf_value("SER-Server-ID", "%@sys.server_id");
  1014. # We are multicasting a successful REGISTER to all proxies
  1015. # on the multicast network to replicate the contact
  1016. # addresses to all of them. In case they share the same IP
  1017. # address (VIP) it is important to set the sending IP
  1018. # address to an unshared one (in the future a special mcast
  1019. # module may use unbound sockets for sending and leave
  1020. # the source IP address decision up to kernel routing
  1021. # tables).
  1022. #DEBCONF-REPL_SEND_ADDR-START
  1023. force_send_socket(udp:127.0.0.1);
  1024. #DEBCONF-REPL_SEND_ADDR-END
  1025. # Put the UID in the Request-URI so that it doesn't have to
  1026. # be looked up in the database by all multicast receivers.
  1027. attr2uri("$tu.uid","user");
  1028. forward_udp(224.0.1.75,5060);
  1029. }
  1030. #DEBCONF-REPLICATION2-START
  1031. #
  1032. #DEBCONF-REPLICATION2-END
  1033. drop;
  1034. }
  1035. # Authentication of request originators claiming to belong to one of our
  1036. # domains.
  1037. #
  1038. route[AUTHENTICATION]
  1039. {
  1040. # CANCELs and ACKs cannot be challenged.
  1041. if (method=="CANCEL" || method=="ACK") {
  1042. break;
  1043. }
  1044. # Requests from non-local to local domains should be permitted.
  1045. # Remove this if you want a walled garden.
  1046. if (strempty($f.did)) {
  1047. break;
  1048. }
  1049. # Gateways are usually not able to authenticate for their requests.
  1050. # You have to trust them base on some other information such as the
  1051. # source IP address.
  1052. # WARNING: If at all this is only safe in a local network!
  1053. if (src_ip == $gw_ip) {
  1054. break;
  1055. }
  1056. if (!proxy_authenticate("$fd.digest_realm", "credentials")) {
  1057. if ($? == -2) {
  1058. sl_reply("500", "Internal Server Error");
  1059. }
  1060. else if ($? == -3) {
  1061. sl_reply("400", "Bad Request");
  1062. }
  1063. else {
  1064. if (defined $digest_challenge && $digest_challenge != "") {
  1065. append_to_reply("%$digest_challenge");
  1066. }
  1067. sl_reply("407", "Proxy Authentication Required");
  1068. }
  1069. drop;
  1070. }
  1071. # Check if the UID derived from authentication matches that from
  1072. # the From header.
  1073. if (!lookup_user("$fr.uid", "@from.uri")) {
  1074. sl_reply("403", "Fake Identity");
  1075. drop;
  1076. }
  1077. if ($fu.uid != $fr.uid) {
  1078. sl_reply("403", "Fake Identity");
  1079. drop;
  1080. }
  1081. setflag(FLAG_AUTH_OK);
  1082. # Load the user attributes of the caller.
  1083. load_attrs("$fu", "$f.uid");
  1084. }
  1085. # Process request targeted to non-local domains.
  1086. #
  1087. route[OUTBOUND]
  1088. {
  1089. # If a local user calls to a foreign domain we play outbound
  1090. # proxy for them.
  1091. # Comment this out if you want a walled garden.
  1092. if ($f.did != "" && strempty($t.did)) {
  1093. append_hf("P-hint: outbound\r\n");
  1094. route(FORWARD);
  1095. }
  1096. }
  1097. # Process speeddial addresses.
  1098. #
  1099. route[SPEEDDIAL]
  1100. {
  1101. # If the caller is local and uses two digits only, we redirect the
  1102. # UA to the real target.
  1103. if ($fd.did != "" && uri =~ "sip:[0-9][0-9]@") {
  1104. if (sd_lookup("speed_dial")) {
  1105. sl_reply("302", "Speed Dial Redirect");
  1106. }
  1107. else {
  1108. sl_reply("404", "Speed Dial Not Found");
  1109. }
  1110. drop;
  1111. }
  1112. }
  1113. # Process requests targeted to a local user.
  1114. #
  1115. route[INBOUND]
  1116. {
  1117. # lets see if know the callee
  1118. if (!lookup_user("$tu.uid", "@ruri")) {
  1119. break;
  1120. }
  1121. # Load the attributes of the callee.
  1122. load_attrs("$tu", "$t.uid");
  1123. # You can check if the called URI is in fact an alias like this.
  1124. #if (! $tu.uri_canonical) {
  1125. # # If the alias URI has different attributes, you can load
  1126. # # them into the URI track like this.
  1127. # load_attrs("$tr", "@ruri");
  1128. #}
  1129. # Check for call forwarding of the callee.
  1130. # Note: The forwarding target has to be full routable URI
  1131. # in this example.
  1132. if (defined $tu.fwd_always_target && $tu.fwd_always_target != "") {
  1133. attr2uri("$tu.fwd_always_target");
  1134. # If we are forwarding to ourselves, don't remove
  1135. # credentials. Otherwise the request would be challenged
  1136. # again.
  1137. # Note: This doesn't apply to failure_route which may
  1138. # still be problematic -- credentials are already
  1139. # removed when we forward. Consider using a 3xx.
  1140. lookup_domain("$td", "@ruri.host");
  1141. if (defined $t.did && $t.did != "") {
  1142. setflag(FLAG_DONT_RM_CRED);
  1143. }
  1144. route(FORWARD);
  1145. }
  1146. # Native SIP destinations are handled using the usrloc database.
  1147. if (lookup_contacts("location")) {
  1148. append_hf("P-hint: usrloc applied\r\n");
  1149. # destination is behind NAT
  1150. if (isflagset(FLAG_NAT_REG)) {
  1151. setflag(FLAG_NAT); /* client was behind NAT when made registration */
  1152. }
  1153. # We set the tm module timers according to the prefences
  1154. # of the callee (avoid too long ringing of his phones).
  1155. # Note1: Timer values have to be in ms now!
  1156. # Note2: This makes even more sense if you switch to a
  1157. # voicemail from the FAILURE_ROUTE below.
  1158. if ($t.fr_inv_timer) {
  1159. if ($t.fr_timer) {
  1160. t_set_fr("$t.fr_inv_timer", "$t.fr_timer");
  1161. }
  1162. else {
  1163. t_set_fr("$t.fr_inv_timer");
  1164. }
  1165. }
  1166. # This enables session timer support as long as one side
  1167. # supports it. If you want to have session timmer support
  1168. # only for calls from your PSTN gateway but not between pure
  1169. # VoIP calls you can remove the comment marks from the if
  1170. # clause in the next line and closing bracket below.
  1171. # WARNING: If at all you should trust IP addresses only in
  1172. # your local network!
  1173. #if (src_ip == $gw_ip) {
  1174. route(SESSION_TIMER);
  1175. #}
  1176. route(FORWARD);
  1177. }
  1178. else {
  1179. sl_reply("480", "Temporarily unavailable");
  1180. drop;
  1181. }
  1182. }
  1183. # Process calls for PSTN.
  1184. #
  1185. route[PSTN]
  1186. {
  1187. # Check some conditions first:
  1188. # PSTN is available for our own users only.
  1189. if (strempty($f.did)) {
  1190. break;
  1191. }
  1192. # If the attribute $gw_ip isn't set, there is no PSTN service
  1193. # active.
  1194. if (!defined $gw_ip) {
  1195. break;
  1196. }
  1197. # And finally, the username of the Request-URI must look like
  1198. # a phone number.
  1199. if (!uri =~ "^sips?:\+?[0-9]{3,18}@") {
  1200. break;
  1201. }
  1202. # You may have to convert the number in the Request-URI into a
  1203. # format that is accepted by your gateway here.
  1204. # Check permissions of the caller for initial INVITEs.
  1205. if (isflagset(FLAG_INIT_DLG)) {
  1206. if ($f.gw_acl != "1") {
  1207. sl_reply("403", "PSTN Not Permitted");
  1208. drop;
  1209. }
  1210. }
  1211. # If the attribute $asserted_id is set, we add its contents as a
  1212. # Remote-Party-ID header.
  1213. # Depending on your gateway, you may have to add a
  1214. # P-Asserted-Identity header here instead.
  1215. if (defined $asserted_id) {
  1216. xlset_attr("$rpidheader",
  1217. "<sip:%$asserted_id@%@ruri.host>;screen=yes");
  1218. replace_attr_hf("Remote-Party-ID", "$rpidheader");
  1219. }
  1220. # Enable Session Timer support with the gateway.
  1221. route(SESSION_TIMER);
  1222. # Replace the domain part of the Request-URI with the value from
  1223. # the attribute and send it out.
  1224. attr2uri("$gw_ip", "domain");
  1225. # Set the PSTN_ALLOWED flag. This will be checked on the
  1226. # onsend_route.
  1227. setflag(FLAG_PSTN_ALLOWED);
  1228. route(FORWARD);
  1229. }
  1230. # Try to process CANCEL requests quickly.
  1231. #
  1232. route[CATCH_CANCEL]
  1233. {
  1234. if (method == CANCEL) {
  1235. # t_relay_cancel() will stop processing if a matching
  1236. # INVITE was found.
  1237. xlog("L_DEBUG", "catching cancel dialogid=%$dialog_id\n");
  1238. if (!t_relay_cancel()) {
  1239. # An INVITE was found but some error occurred.
  1240. sl_reply("500", "Internal Server Error");
  1241. drop;
  1242. }
  1243. # Bad luck, no corresponding INVITE was found, we have to
  1244. # continue with the script.
  1245. }
  1246. }
  1247. # Site specific policy.
  1248. #
  1249. route[SITE_SPECIFIC]
  1250. {
  1251. # This is only relevant for requests for one of our domains.
  1252. if (strempty($t.did)) {
  1253. break;
  1254. }
  1255. # Do site specific routing such as peering.
  1256. # For example:
  1257. if (uri=~"^sip:000777") {
  1258. rewritehostport("sems01.iptel.org:5074");
  1259. route(FORWARD);
  1260. }
  1261. }
  1262. # Process Session-Timer.
  1263. #
  1264. route[SESSION_TIMER]
  1265. {
  1266. # We are only interested in session establishment or session
  1267. # refreshing.
  1268. #
  1269. if (method != "INVITE" && method != "UPDATE") {
  1270. break;
  1271. }
  1272. # Let's check if the Session-Expires header is already present.
  1273. if (@hf_value.session_expires != "") {
  1274. # Compare the Session-Expires header value with the
  1275. # configured Min-SE.
  1276. eval_push("x:%@hf_value.session_expires.uri");
  1277. eval_oper("(int)", -1);
  1278. eval_push("x:%@cfg_get.session_timer.min_se");
  1279. eval_oper("(int)", -1);
  1280. eval_oper(">=", -2);
  1281. # Let's check for the Suported header.
  1282. if (hf_value_exists("Supported", "timer")) {
  1283. # The UAC supports Session-Timer, so we
  1284. # only need to take a look at the values
  1285. if (@eval.pop[-1] == "0") {
  1286. # Session interval is lower than the
  1287. # configured Min-SE
  1288. append_to_reply("Min-SE: %@cfg_get.session_timer.min_se\r\n");
  1289. sl_reply("422", "Session Interval Too Small");
  1290. drop;
  1291. }
  1292. # We store the session expires value for the reply
  1293. # route and mark the attribute for inserting as
  1294. # Record-Route cookie.
  1295. $stimer = @hf_value.session_expires.uri;
  1296. setavpflag($stimer, "dialog_cookie");
  1297. # Set the session timer flag that indicates the
  1298. # UAC supports the extension.
  1299. setflag(FLAG_SESSIONTIMER);
  1300. }
  1301. else {
  1302. # Session epxires was already inserted by some other
  1303. # proxy
  1304. if (@eval.pop[-1] == "0") {
  1305. # Session interval is lower than the
  1306. # configured Min-SE. There is no point in
  1307. # sending 422 response, because the UAC
  1308. # does not support the extension, the values
  1309. # can be corrected instead.
  1310. assign_hf_value("Session-Expires",
  1311. "%@cfg_get.session_timer.min_se");
  1312. remove_hf_value("Min-SE");
  1313. append_hf_value("Min-SE",
  1314. "%@cfg_get.session_timer.min_se");
  1315. }
  1316. }
  1317. }
  1318. else {
  1319. # No Session Timer is requested yet, neither by UAC nor by
  1320. # proxy
  1321. if (@cfg_get.session_timer.default != "0") {
  1322. # Add a Session Expires header to see if the UAS
  1323. # supports Session Timer. We do not insert a
  1324. # Required header because then the call might fail.
  1325. append_hf_value("Session-Expires",
  1326. "%@cfg_get.session_timer.default");
  1327. if (@cfg_get.session_timer.min_se != "90") {
  1328. append_hf_value("Min-SE",
  1329. "%@cfg_get.session_timer.min_se");
  1330. }
  1331. # Mark the attribute to be inserted as a
  1332. # Record-Route cookie
  1333. $stimer = @cfg_get.session_timer.default;
  1334. setavpflag($stimer, "dialog_cookie");
  1335. }
  1336. }
  1337. }
  1338. # Route which checks and performs ENUM queries
  1339. # #
  1340. route[ENUM]
  1341. {
  1342. # perform ENUM query only if the RURI contains an E.164
  1343. # number as uer part
  1344. if (uri =~ "sip:\+[0-9]?@") {
  1345. # if the ENUM query was successful send it right
  1346. # away of to the new target, otherwise do nothing
  1347. if (enum_query()) {
  1348. route(FORWARD);
  1349. }
  1350. }
  1351. }
  1352. # Failure route for initial INVITEs.
  1353. #
  1354. failure_route[FAILURE_ROUTE]
  1355. {
  1356. if (isflagset(FLAG_INIT_DLG)) {
  1357. # Mark that we are operating from a failure route.
  1358. setflag(FLAG_FAILUREROUTE);
  1359. if (t_check_status("486|600")) {
  1360. # If we received a busy and a busy target is set, forward
  1361. # it there.
  1362. # Note: Again, the forwarding target has to be a routeable
  1363. # URI. We redirect using 3xx to avoid possible issues with
  1364. # credentials (if we consumed them, they may be missing in
  1365. # a loop, if we don't consume them, messages are bigger and
  1366. # more vulnerable)
  1367. if ($tu.fwd_busy_target != "") {
  1368. attr2uri("$tu.fwd_busy_target");
  1369. #attr_destination("$tu.fwd_busy_target");
  1370. #route(FORWARD);
  1371. t_reply("302", "Redirect On Busy");
  1372. }
  1373. # Alternatively, you could forward the request to
  1374. # SEMS/voicemail here
  1375. }
  1376. else if (t_check_status("408|480")) {
  1377. # If we received no answer and the noanswer target is set,
  1378. # forward it there.
  1379. # Note: See above.
  1380. if ($tu.fwd_noanswer_target != "") {
  1381. attr2uri("$tu.fwd_noanswer_target");
  1382. #attr_destination("$tu.fwd_noanswer_target");
  1383. #route(FORWARD);
  1384. t_reply("302", "Redirect On No Answer");
  1385. }
  1386. }
  1387. } # if (isflagset...
  1388. }
  1389. # Onreply route that fixes NAT in responses.
  1390. #
  1391. onreply_route[REPLY_ROUTE]
  1392. {
  1393. # Check and fix the Contact in the reply to
  1394. # allow proper routing of in-dialog messages.
  1395. route(UAS_NAT_DETECTION);
  1396. # If RTP proxy was activated and this is a 18x or 2xx reply with a
  1397. # body, inform RTP proxy.
  1398. if (isflagset(FLAG_RTP_PROXY)
  1399. && status=~"(18[03])|(2[0-9][0-9])"
  1400. && @msg.body != "")
  1401. {
  1402. force_rtp_proxy('r');
  1403. }
  1404. # Let's check for session timer support.
  1405. if (isflagset(FLAG_SESSIONTIMER) && status =~ "2[0-9][0-9]") {
  1406. # The UAC wanted to have a session timer.
  1407. if (strempty(@hf_value.session_expires)) {
  1408. # But the UAS does not support it, so we will try
  1409. # to convince the UAC to do it.
  1410. append_hf_value("Session-Expires",
  1411. "%$stimer;refresher=uac");
  1412. if (!hf_value_exists("Require", "timer")) {
  1413. include_hf_value("Require", "timer");
  1414. }
  1415. }
  1416. }
  1417. }
  1418. # Do some final checks before a request is sent out.
  1419. onsend_route
  1420. {
  1421. # Bypass check: Eliminate requests to the PSTN gateway if they have
  1422. # not passed ACL checks and are not marked with FLAG_PSTN_ALLOWED
  1423. # but are dialog-initiating requests (no to-tag, no CANCEL, no ACK).
  1424. # This helps to stop policy bypasses (gateway IP uploaded as a
  1425. # forked contact, or a call-forwarding destination, or a DNS name,
  1426. # or a preloaded route, or something else possibly)
  1427. if (defined $g.gw_ip && to_ip==$g.gw_ip && !isflagset(FLAG_PSTN_ALLOWED)
  1428. && !isflagset(FLAG_TOTAG)
  1429. && method != "ACK" && method != "CANCEL")
  1430. {
  1431. log(1, "ALERT: non authorized packet for PSTN, dropping...\n%mb\n");
  1432. # You can't use advanced features from onsend_route.
  1433. # xlog("L_ALERT", "non authorized packet for PSTN, dropping...\n%mb\n");
  1434. drop;
  1435. }
  1436. # RFC 1918 relay protection: Useful if SER is attached to an
  1437. # administrative network using private IP address space and you
  1438. # wish to prevent UACs from relaying their packets there.
  1439. #
  1440. # You will have to comment this out, if you are regularly serving
  1441. # an RFC 1918 address space.
  1442. if (to_ip==10.0.0.0/8 || to_ip==172.16.0.0/12
  1443. || to_ip==192.168.0.0/16)
  1444. {
  1445. log(1, "ALERT: Packet targeted to an RFC1918 address dropped\n");
  1446. drop;
  1447. }
  1448. }
  1449. # Run every minute by the timer module.
  1450. #
  1451. route[ON_1MIN_TIMER] {
  1452. # Cleanup expired location records
  1453. # MySQL version:
  1454. db_query("delete from location where expires<utc_timestamp()");
  1455. # PostgreSQL version:
  1456. #db_query("delete from location where expires<now()");
  1457. # Reload domains if domain table has been changed recently.
  1458. # Note: because global attributes are read-only and we can't
  1459. # easily remember the "last" status, we check for changed
  1460. # timestamp in 2 minute time-interval.
  1461. # MySQL version:
  1462. db_query("select value from global_attrs where name='domain_data_version' and type=0 and cast(value as unsigned int) between unix_timestamp(now())-120 and unix_timestamp(now())", "reload");
  1463. # PostgreSQL version:
  1464. #db_query("select value from global_attrs where name='domain_data_version' and type=0 and cast(value as integer) between date_part('epoch', now() - interval '120 seconds') and date_part('epoch', now())", "reload");
  1465. if (@db.fetch.reload.count=="1") {
  1466. # Domain reload only available as fifo command.
  1467. exec_msg("sercmd domain.reload");
  1468. }
  1469. db_close("reload");
  1470. # Reload global attributes (they are cached in memory) if the contents of
  1471. # the global_attrs table has been changed recently.
  1472. db_query("select value from global_attrs where name='gattr_timestamp' and type=0 and cast(value as unsigned int) between unix_timestamp(now())-120 and unix_timestamp(now())", "gattr_reload");
  1473. if (@db.fetch.gattr_reload.count=="1") {
  1474. exec_msg("sercmd global.reload");
  1475. }
  1476. db_close("gattr_reload");
  1477. }
  1478. #!ifdef WITH_XMLRPC
  1479. # handle xmlrpcs
  1480. route[XMLRPC]{
  1481. # accept xmlrpc requests only from localhost
  1482. if (src_ip!=127.0.0.1
  1483. #!ifdef XMLRPC_ALLOW_NET1
  1484. && src_ip != XMLRPC_ALLOW_NET1
  1485. #!endif
  1486. #!ifdef XMLRPC_ALLOW_NET2
  1487. && src_ip != XMLRPC_ALLOW_NET2
  1488. #!endif
  1489. #!ifdef XMLRPC_ALLOW_NET3
  1490. && src_ip != XMLRPC_ALLOW_NET3
  1491. #!endif
  1492. ) {
  1493. xmlrpc_reply("400", "xmlrpc not allowed from this address");
  1494. return;
  1495. }
  1496. if (method!="POST" && method!="GET") {
  1497. xmlrpc_reply("400", "unsupported HTTP method");
  1498. return;
  1499. }
  1500. if (msg:len >= 8192) {
  1501. xmlrpc_reply("513", "request too big");
  1502. return;
  1503. }
  1504. #!ifdef XMLRPC_TLS_ONLY
  1505. # allow xmlrpc only on TLS and only if the client certificate is valid
  1506. if (proto!=TLS){
  1507. xmlrpc_reply("400", "xmlrpc allowed only over TLS");
  1508. return;
  1509. }
  1510. if (@tls.peer.verified!=""){
  1511. xmlrpc_reply("400", "Unauthorized");
  1512. return;
  1513. }
  1514. #!endif
  1515. # close connection only for xmlrpclib user agents (there is a bug in
  1516. # xmlrpclib: it waits for EOF before interpreting the response).
  1517. if (search("^User-Agent:.*xmlrpclib"))
  1518. set_reply_close();
  1519. set_reply_no_connect(); # optional
  1520. dispatch_rpc();
  1521. }