operation.xml 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="operation" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>Server Operation</title>
  14. <section id="operationalpractices">
  15. <title>Recommended Operational Practices</title>
  16. <para>
  17. Operation of a SIP server is not always easy task.
  18. Server administrators are challenged by broken or
  19. misconfigured user agents, network and host failures,
  20. hostile attacks and other stress-makers. All such
  21. situations may lead to an operational failure. It is sometimes
  22. very difficult to figure out the root reason of
  23. a failure, particularly in a distributed environment
  24. with many SIP components involved.
  25. In this section,
  26. we share some of our practices and refer to tools
  27. which have proven to
  28. make life of administrators easier
  29. </para>
  30. <qandaset>
  31. <qandaentry>
  32. <question>
  33. <para>
  34. Keeping track of messages is good
  35. </para>
  36. </question>
  37. <answer>
  38. <para>
  39. Frequently, operational errors are discovered or reported
  40. with a delay.
  41. Users frustrated by an error
  42. frequently approach administrators
  43. and scream "even though my SIP requests were absolutely ok
  44. yesterday, they were mistakenly denied by your server".
  45. If administrators do not record all SIP traffic at
  46. their site, they will be no more able to identify
  47. the problem reason.
  48. We thus recommend that site
  49. operators record all messages passing their site and keep them
  50. stored for some period of time.
  51. They may use utilities such as
  52. <application>ngrep
  53. </application> or
  54. <application>tcpdump
  55. </application>.
  56. There is also a utility <application>
  57. scripts/harv_ser.sh</application> in <application>
  58. ser</application> distribution for post-processing
  59. of captured messages. It summarizes messages captured
  60. by reply status and user-agent header field.
  61. </para>
  62. </answer>
  63. </qandaentry>
  64. <qandaentry>
  65. <question>
  66. <para>
  67. Real-time Traffic Watching
  68. </para>
  69. </question>
  70. <answer>
  71. <para>
  72. Looking at SIP messages in real-time may help to gain
  73. understanding of problems. Though there are commercial
  74. tools available, using a simple, text-oriented tool
  75. such as <application>ngrep</application> makes the job very well thanks to SIP's textual nature.
  76. </para>
  77. <example id="usingngrep">
  78. <title>Using <application>ngrep</application>
  79. </title>
  80. <para>In this example, all messages at port 5060
  81. which include the string "bkraegelin" are captured
  82. and displayed</para>
  83. <programlisting>
  84. [jiri@fox s]$ ngrep bkraegelin@ port 5060
  85. interface: eth0 (195.37.77.96/255.255.255.240)
  86. filter: ip and ( port 5060 )
  87. match: bkraegelin@
  88. #
  89. U +0.000000 153.96.14.162:50240 -> 195.37.77.101:5060
  90. REGISTER sip:iptel.org SIP/2.0.
  91. Via: SIP/2.0/UDP 153.96.14.162:5060.
  92. From: sip:[email protected].
  93. To: sip:[email protected].
  94. Call-ID: [email protected].
  95. Date: Thu, 26 Sep 2002 22:03:55 GMT.
  96. CSeq: 101 REGISTER.
  97. Expires: 10.
  98. Content-Length: 0.
  99. .
  100. #
  101. U +0.000406 195.37.77.101:5060 -> 153.96.14.162:5060
  102. SIP/2.0 401 Unauthorized.
  103. Via: SIP/2.0/UDP 153.96.14.162:5060.
  104. From: sip:[email protected].
  105. To: sip:[email protected].
  106. Call-ID: [email protected].
  107. CSeq: 101 REGISTER.
  108. WWW-Authenticate: Digest realm="iptel.org", nonce="3d9385170000000043acbf6ba9c9741790e0c57adee73812", algorithm=MD5.
  109. Server: Sip EXpress router(0.8.8 (i386/linux)).
  110. Content-Length: 0.
  111. Warning: 392 127.0.0.1:5060 "Noisy feedback tells: pid=31604 req_src_ip=153.96.14.162 in_uri=sip:iptel.org out_uri=sip:iptel.org via_cnt==1".
  112. </programlisting>
  113. </example>
  114. </answer>
  115. </qandaentry>
  116. <qandaentry>
  117. <question>
  118. <para>
  119. Tracing Errors in Server Chains
  120. </para>
  121. </question>
  122. <answer>
  123. <para>
  124. A request may pass any number of proxy servers on
  125. its path to its destination. If an error occurs
  126. in the chain, it is difficult for upstream troubleshooters
  127. and/or users complaining to administrators to learn
  128. more about error circumstances.
  129. <application>ser
  130. </application> does its best and displays extensive
  131. diagnostics information in SIP replies. It allows
  132. troubleshooters and/or users who report to troubleshooters
  133. to gain additional knowledge about request processing
  134. status.
  135. This extended debugging information is part of the warning
  136. header field. See <xref linkend="usingngrep"/> for an illustration
  137. of a reply that includes such a warning header field. The header
  138. field contains the following pieces of information:
  139. <itemizedlist>
  140. <listitem>
  141. <para>
  142. Server's IP Address -- good to identify
  143. from which server in a chain the reply
  144. came.
  145. </para>
  146. </listitem>
  147. <listitem>
  148. <para>
  149. Incoming and outgoing URIs -- good to
  150. learn for which URI the reply was
  151. generated, as it may be rewritten
  152. many times in the path. Particularly
  153. useful for debugging of numbering plans.
  154. </para>
  155. </listitem>
  156. <listitem>
  157. <para>
  158. Number of Via header fields in replied
  159. request -- that helps in assessment of
  160. request path length. Upstream clients would
  161. not know otherwise, how far away in terms
  162. of SIP hops their requests were replied.
  163. </para>
  164. </listitem>
  165. <listitem>
  166. <para>
  167. Server's process id. That is useful for
  168. debugging to discover situations when
  169. multiple servers listen at the same
  170. address.
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. IP address of previous SIP hop as seen by
  176. the SIP server.
  177. </para>
  178. </listitem>
  179. </itemizedlist>
  180. </para>
  181. <para>
  182. If server administrator is not comfortable with
  183. disclosing all this information, he can turn them
  184. off using the <varname>sip_warning</varname> configuration
  185. option.
  186. </para>
  187. <para>
  188. A nice utility for debugging server chains is
  189. <application>sipsak</application>,
  190. SIP Swiss Army Knife, traceroute-like tool for SIP
  191. developed at iptel.org. It allows you to send
  192. OPTIONS request with low, increasing Max-Forwards
  193. header-fields and follow how it propagates in
  194. SIP network. See its webpage at
  195. <ulink url="http://sipsak.berlios.de/">
  196. http://sipsak.berlios.de/
  197. </ulink>.
  198. </para>
  199. <example>
  200. <title>Use of SIPSak for Learning SIP Path</title>
  201. <programlisting>
  202. [jiri@bat sipsak]$ ./sipsak -T -s sip:[email protected]
  203. warning: IP extract from warning activated to be more informational
  204. 0: 127.0.0.1 (0.456 ms) SIP/2.0 483 Too Many Hops
  205. 1: ?? (31.657 ms) SIP/2.0 200 OK
  206. without Contact header
  207. </programlisting>
  208. <para>
  209. Note that in this example, the second hop
  210. server does not issue any warning header fields
  211. in replies and it is thus impossible to display
  212. its IP address in <application>
  213. SIPsak</application>'s output.
  214. </para>
  215. </example>
  216. </answer>
  217. </qandaentry>
  218. <qandaentry>
  219. <question>
  220. <para>
  221. Watching Server Health
  222. </para>
  223. </question>
  224. <answer>
  225. <para>
  226. Watching Server's operation status in real-time may
  227. also be a great aid for trouble-shooting.
  228. <application>ser</application> has an excellent
  229. facility, a FIFO server, which allows UNIX
  230. tools to access server's internals. (It is
  231. similar to how Linux tool access Linux kernel
  232. via the proc file system.) The FIFO server
  233. accepts commands via a FIFO (named pipe) and
  234. returns data asked for. Administrators do not
  235. need to learn details of the FIFO communication
  236. and can serve themselves using a front-end
  237. utility <application>serctl</application>.
  238. Of particular interest for
  239. monitoring server's operation are
  240. <application>serctl</application>
  241. commands
  242. <command>ps</command> and
  243. <command>moni</command>.
  244. The former displays running
  245. <application>ser</application>
  246. processes, whereas the latter shows statistics.
  247. </para>
  248. <example>
  249. <title>serctl ps command</title>
  250. <para>
  251. This example shows 10 processes running at a host.
  252. The process 0, "attendant" watches child processes
  253. and terminates all of them if a failure occurs in
  254. any of them. Processes 1-4 listen at local
  255. interface and processes 5-8 listen at Ethernet
  256. interface at port number 5060. Process number
  257. 9 runs FIFO server, and process number 10
  258. processes all server timeouts.
  259. </para>
  260. <programlisting>
  261. [jiri@fox jiri]$ serctl ps
  262. 0 31590 attendant
  263. 1 31592 receiver child=0 sock=0 @ 127.0.0.1::5060
  264. 2 31595 receiver child=1 sock=0 @ 127.0.0.1::5060
  265. 3 31596 receiver child=2 sock=0 @ 127.0.0.1::5060
  266. 4 31597 receiver child=3 sock=0 @ 127.0.0.1::5060
  267. 5 31604 receiver child=0 sock=1 @ 195.37.77.101::5060
  268. 6 31605 receiver child=1 sock=1 @ 195.37.77.101::5060
  269. 7 31606 receiver child=2 sock=1 @ 195.37.77.101::5060
  270. 8 31610 receiver child=3 sock=1 @ 195.37.77.101::5060
  271. 9 31611 fifo server
  272. 10 31627 timer
  273. </programlisting>
  274. </example>
  275. </answer>
  276. </qandaentry>
  277. <qandaentry>
  278. <question>
  279. <para>
  280. Is Server Alive
  281. </para>
  282. </question>
  283. <answer>
  284. <para>
  285. It is essential for solid operation to know
  286. continuously that server is alive. We've been
  287. using two tools for this purpose.
  288. <application>sipsak</application>
  289. does a great job of "pinging" a server, which
  290. may be used for alerting on unresponsive servers.
  291. </para>
  292. <para>
  293. <application>monit</application> is
  294. a server watching utility which alerts when
  295. a server dies.
  296. </para>
  297. </answer>
  298. </qandaentry>
  299. <qandaentry>
  300. <question>
  301. <para>
  302. Dealing with DNS
  303. </para>
  304. </question>
  305. <answer>
  306. <para>
  307. SIP standard leverages DNS. Administrators of
  308. <application>ser</application> should
  309. be aware of impact of DNS on server's operation.
  310. Server's attempt to resolve an unresolvable address
  311. may block a server process in terms of seconds. To be
  312. safer that the server doesn't stop responding
  313. due to being blocked by DNS resolving, we recommend
  314. the following practices:
  315. <itemizedlist>
  316. <listitem>
  317. <para>
  318. Start a sufficient number of children processes.
  319. If one is blocked, the other children will
  320. keep serving.
  321. </para>
  322. </listitem>
  323. <listitem>
  324. <para>
  325. Use DNS caching. For example, in Linux,
  326. there is an <application>
  327. nscd</application> daemon available for
  328. this purpose.
  329. </para>
  330. </listitem>
  331. <listitem>
  332. <para>
  333. Process transactions statefully if memory
  334. allows. That helps to absorb retransmissions
  335. without having to resolve DNS for each of
  336. them.
  337. </para>
  338. </listitem>
  339. </itemizedlist>
  340. </para>
  341. </answer>
  342. </qandaentry>
  343. <qandaentry id="logging">
  344. <question>
  345. <para>
  346. Logging
  347. </para>
  348. </question>
  349. <answer>
  350. <para>
  351. <application>ser</application> by default logs
  352. to <application>syslog</application> facility.
  353. It is very useful to watch log messages for
  354. abnormal behavior. Log messages, subject to
  355. <application>syslog</application> configuration
  356. may be stored at different files, or even at remote
  357. systems. A typical location of the log file is
  358. <filename>/var/log/messages</filename>.
  359. </para>
  360. <note>
  361. <para>
  362. One can also use other <application>syslogd</application>
  363. implementation. <application>metalog</application>
  364. (<ulink url="http://metalog.sourceforge.net/">
  365. http://metalog.sourceforge.net/
  366. </ulink>)
  367. features regular expression matching that enables
  368. to filter and group log messages.
  369. </para>
  370. </note>
  371. <para>
  372. For the purpose of debugging configuration scripts, one may
  373. want to redirect log messages to console not to pollute
  374. syslog files. To do so configure <application>ser</application>
  375. in the following way:
  376. <itemizedlist>
  377. <listitem>
  378. <para>
  379. Attach ser to console by setting <varname>fork=no</varname>.
  380. </para>
  381. </listitem>
  382. <listitem>
  383. <para>
  384. Set explicitly at which address
  385. <application>ser</application>
  386. should be listening, e.g., <varname>listen=192.168.2.16</varname>.
  387. </para>
  388. </listitem>
  389. <listitem>
  390. <para>
  391. Redirect log messages to standard error by setting
  392. <varname>log_stderror=yes</varname>
  393. </para>
  394. </listitem>
  395. <listitem>
  396. <para>
  397. Set appropriately high log level. (Be sure that you redirected logging
  398. to standard output. Flooding system logs with many detailed messages
  399. would make the logs difficult to read and use.) You can set the global
  400. logging threshold value with the option <varname>debug=nr</varname>,
  401. where the higher <varname>nr</varname> the more detailed output.
  402. If you wish to set log level only for some script events, include
  403. the desired log level as the first parameter of the
  404. <command>log</command> action in your script.
  405. The messages will be then printed if <command>log</command>'s
  406. level is lower than the global threshold, i.e., the lower the more
  407. noisy output you get.
  408. <example>
  409. <title>Logging Script</title>
  410. <programlisting>
  411. <xi:include href="../../examples/logging.cfg" parse="text"/>
  412. </programlisting>
  413. <para>
  414. The following SIP message causes then logging output as shown
  415. bellow.
  416. </para>
  417. <programlisting>
  418. REGISTER sip:192.168.2.16 SIP/2.0
  419. Via: SIP/2.0/UDP 192.168.2.33:5060
  420. From: sip:[email protected]
  421. To: sip:[email protected]
  422. Call-ID: [email protected]
  423. Date: Thu, 27 Feb 2003 15:10:52 GMT
  424. CSeq: 101 REGISTER
  425. User-Agent: CSCO/4
  426. Contact: sip:[email protected]:5060
  427. Content-Length: 0
  428. Expires: 600
  429. </programlisting>
  430. <programlisting>
  431. [jiri@cat sip_router]$ ./ser -f examples/logging.cfg
  432. Listening on
  433. 192.168.2.16 [192.168.2.16]::5060
  434. Aliases: cat.iptel.org:5060 cat:5060
  435. WARNING: no fork mode
  436. 0(0) INFO: udp_init: SO_RCVBUF is initially 65535
  437. 0(0) INFO: udp_init: SO_RCVBUF is finally 131070
  438. 0(17379) REGISTER received
  439. 0(17379) request for other domain received
  440. </programlisting>
  441. </example>
  442. </para>
  443. </listitem>
  444. </itemizedlist>
  445. </para>
  446. </answer>
  447. </qandaentry>
  448. <qandaentry>
  449. <question>
  450. <para>
  451. Labeling Outbound Requests
  452. </para>
  453. </question>
  454. <answer>
  455. <para>
  456. Without knowing, which pieces of script code a relayed
  457. request visited, trouble-shooting would be difficult.
  458. Scripts typically apply different processing to
  459. different routes such as to IP phones and PSTN
  460. gateways. We thus recommend to label outgoing
  461. requests with a label describing the type of processing
  462. applied to the request.
  463. </para>
  464. <para>
  465. Attaching "routing-history" hints to relayed
  466. requests is as easy as using the
  467. <command>append_hf</command>
  468. action exported by textops module. The following
  469. example shows how different labels are attached
  470. to requests to which different routing logic
  471. was applied.
  472. <example>
  473. <title>"Routing-history" labels</title>
  474. <programlisting>
  475. # is the request for our domain?
  476. # if so, process it using UsrLoc and label it so.
  477. if (uri=~[@:\.]domain.foo") {
  478. if (!lookup("location")) {
  479. sl_send_reply("404", "Not Found");
  480. break;
  481. };
  482. # user found -- forward to him and label the request
  483. append_hf("P-hint: USRLOC\r\n");
  484. } else {
  485. # it is an outbound request to some other domain --
  486. # indicate it in the routing-history label
  487. append_hf("P-hint: OUTBOUND\r\n");
  488. };
  489. t_relay();
  490. </programlisting>
  491. <para>
  492. This is how such a labeled requests looks
  493. like. The last header field includes
  494. a label indicating the script processed
  495. the request as outbound.
  496. </para>
  497. <programlisting>
  498. #
  499. U 2002/09/26 02:03:09.807288 195.37.77.101:5060 -> 203.122.14.122:5060
  500. SUBSCRIBE sip:[email protected] SIP/2.0.
  501. Max-Forwards: 10.
  502. Via: SIP/2.0/UDP 195.37.77.101;branch=53.b44e9693.0.
  503. Via: SIP/2.0/UDP 203.122.14.115:16819.
  504. From: sip:[email protected];tag=5c7cecb3-cfa2-491d-a0eb-72195d4054c4.
  505. To: sip:[email protected].
  506. Call-ID: [email protected].
  507. CSeq: 2 SUBSCRIBE.
  508. Contact: sip:203.122.14.115:16819.
  509. User-Agent: Windows RTC/1.0.
  510. Proxy-Authorization: Digest username="rajeshacl", realm="iptel.org", algorithm="MD5", uri="sip:[email protected]", nonce="3d924fe900000000fd6227db9e565b73c465225d94b2a938", response="a855233f61d409a791f077cbe184d3e3".
  511. Expires: 1800.
  512. Content-Length: 0.
  513. P-hint: OUTBOUND.
  514. </programlisting>
  515. </example>
  516. </para>
  517. </answer>
  518. </qandaentry>
  519. </qandaset>
  520. </section> <!-- operational practises -->
  521. <section>
  522. <title>HOWTOs</title>
  523. <para>
  524. This section is a "cookbook" for dealing with common tasks, such as
  525. user management or controlling access to PSTN gateways.
  526. </para>
  527. <section>
  528. <title>User Management</title>
  529. <para>
  530. There are two tasks related to management of SIP users:
  531. maintaining user accounts and maintaining user contacts.
  532. Both these jobs can be done using the
  533. <application>serctl</application>
  534. command-line tool. Also, the complimentary web
  535. interface, <application>serweb</application>,
  536. can be used for this purpose as well.
  537. </para>
  538. <para>
  539. If user authentication is turned on, which is a highly
  540. advisable practice, user account must be created before
  541. a user can log in. To create a new user account, call the
  542. <command>serctl add</command> utility
  543. with username, password and email as parameters. It
  544. is important that the environment <varname>SIP_DOMAIN</varname>
  545. is set to your realm and matches realm values used in
  546. your script. The realm value is used for calculation
  547. of credentials stored in subscriber database, which are
  548. bound permanently to this value.
  549. <screen>
  550. [jiri@cat gen_ha1]$ export SIP_DOMAIN=foo.bar
  551. [jiri@cat gen_ha1]$ serctl add newuser secret [email protected]
  552. MySql Password:
  553. new user added
  554. </screen>
  555. </para>
  556. <para><application>serctl</application> can
  557. also change user's password or remove existing accounts
  558. from system permanently.
  559. <screen>
  560. [jiri@cat gen_ha1]$ serctl passwd newuser newpassword
  561. MySql Password:
  562. password change succeeded
  563. [jiri@cat gen_ha1]$ serctl rm newuser
  564. MySql Password:
  565. user removed
  566. </screen>
  567. </para>
  568. <para>
  569. User contacts are typically automatically uploaded by SIP phones
  570. to server during registration process and administrators do not
  571. need to worry about them. However, users
  572. may wish to append permanent contacts to PSTN gateways
  573. or to locations in other administrative domains.
  574. To manipulate the contacts in such cases, use
  575. <application>serctl ul</application>
  576. tool. Note that this is the only correct way
  577. to update contacts -- direct changes to back-end
  578. MySql database do not affect server's memory. Also note,
  579. that if persistence is turned off (usrloc "db_mode"
  580. parameter set to "0"), all contacts are gone on server
  581. reboot. Make sure that persistence is enabled if you
  582. add permanent contacts.
  583. </para>
  584. <para>
  585. To add a new permanent contact for a user, call
  586. <application>serctl ul add &lt;username&gt;
  587. &lt;contact&gt;</application>. To delete
  588. all user's contacts, call
  589. <application>serctl ul rm &lt;username&gt;</application>.
  590. <application>serctl ul show &lt;username&gt;</application>
  591. prints all current user's contacts.
  592. <screen>
  593. [jiri@cat gen_ha1]$ serctl ul add newuser sip:[email protected]
  594. sip:[email protected]
  595. 200 Added to table
  596. ('newuser','sip:[email protected]') to 'location'
  597. [jiri@cat gen_ha1]$ serctl ul show newuser
  598. &lt;sip:[email protected]&gt;;q=1.00;expires=1073741812
  599. [jiri@cat gen_ha1]$ serctl ul rm newuser
  600. 200 user (location, newuser) deleted
  601. [jiri@cat gen_ha1]$ serctl ul show newuser
  602. 404 Username newuser in table location not found
  603. </screen>
  604. </para>
  605. </section> <!-- user management -->
  606. <section>
  607. <title>User Aliases</title>
  608. <para>
  609. Frequently, it is desirable for a user to have multiple
  610. addresses in a domain. For example, a user with username "john.doe" wants to be
  611. reachable at a shorter address "john" or at a numerical address
  612. "12335", so that PSTN callers with digits-only key-pad can reach
  613. him too.
  614. </para>
  615. <para>
  616. With <application>ser</application>, you can maintain
  617. a special user-location table and translate existing aliases to canonical
  618. usernames using the <command>lookup</command>
  619. action from usrloc module. The following script fragment demonstrates
  620. use of <command>lookup</command> for this purpose.
  621. <example>
  622. <title>Configuration of Use of Aliases</title>
  623. <programlisting>
  624. if (!uri==myself) { # request not for our domain...
  625. route(1); # go somewhere else, where outbound requests are processed
  626. break;
  627. };
  628. # the request is for our domain -- process registrations first
  629. if (method=="REGISTER") { route(3); break; };
  630. # look now, if there is an alias in the "aliases" table; don't care
  631. # about return value: whether there is some or not, move ahead then
  632. lookup("aliases");
  633. # there may be aliases which translate to other domain and for which
  634. # local processing is not appropriate; check again, if after the
  635. # alias translation, the request is still for us
  636. if (!uri==myself) { route(1); break; };
  637. # continue with processing for our domain...
  638. ...
  639. </programlisting>
  640. </example>
  641. </para>
  642. <para>
  643. The table with aliases is updated using the
  644. <application>serctl</application>
  645. tool. <application>
  646. serctl alias add &lt;alias&gt; &lt;uri&gt;</application>
  647. adds a new alias,
  648. <application>serctl alias show &lt;user&gt;</application>
  649. prints an existing alias, and
  650. <application>serctl alias rm &lt;user&gt;</application>
  651. removes it.
  652. <screen>
  653. [jiri@cat sip_router]$ serctl alias add 1234 sip:[email protected]
  654. sip:[email protected]
  655. 200 Added to table
  656. ('1234','sip:[email protected]') to 'aliases'
  657. [jiri@cat sip_router]$ serctl alias add john sip:[email protected]
  658. sip:[email protected]
  659. 200 Added to table
  660. ('john','sip:[email protected]') to 'aliases'
  661. [jiri@cat sip_router]$ serctl alias show john
  662. &lt;sip:[email protected]&gt;;q=1.00;expires=1073741811
  663. [jiri@cat sip_router]$ serctl alias rm john
  664. 200 user (aliases, john) deleted
  665. </screen>
  666. </para>
  667. <para>
  668. Note that persistence needs to be turned on in usrloc
  669. module. All changes to aliases will be otherwise lost
  670. on server reboot. To enable persistence, set the
  671. db_mode usrloc parameter to a non-zero value.
  672. <programlisting>
  673. # ....load module ...
  674. loadmodule "modules/usrloc/usrloc.so"
  675. # ... turn on persistence -- all changes to user tables are immediately
  676. # flushed to mysql
  677. modparam("usrloc", "db_mode", 1)
  678. # the SQL address:
  679. modparam("usrloc", "db_url","mysql://ser:secret@dbhost/ser")
  680. </programlisting>
  681. </para>
  682. </section> <!-- user aliases -->
  683. <section id="acl">
  684. <title>Access Control (PSTN Gateway)</title>
  685. <para>
  686. It is sometimes important to exercise some sort of
  687. access control. A typical use case is when
  688. <application>ser</application> is used
  689. to guard a PSTN gateway. If a gateway was not well guarded,
  690. unauthorized users would be able to use it to terminate calls in PSTN,
  691. and cause high charges to its operator.
  692. </para>
  693. <para>
  694. There are few issues you need to understand when
  695. configuring <application>ser</application>
  696. for this purpose. First, if a gateway is built or configured to
  697. accept calls from anywhere, callers may easily bypass your
  698. access control server and communicate with the gateway
  699. directly. You then need to enforce at transport layer
  700. that signaling is only accepted if coming via
  701. <application>ser</application> and
  702. deny SIP packets coming from other hosts and port numbers.
  703. Your network must be configured not to allow forged
  704. IP addresses. Also, you need to turn on record-routing
  705. to assure that all session requests will travel via
  706. <application>ser</application>.
  707. Otherwise, caller's devices would send subsequent SIP requests
  708. directly to your gateway, which would fail because of transport
  709. filtering.
  710. </para>
  711. <para>
  712. Authorization (i.e., the process of determining who may call where)
  713. is facilitated in <application>ser</application>
  714. using <emphasis>group membership</emphasis> concept. Scripts make
  715. decisions on whether a caller is authorized to make a call to
  716. a specific destination based on user's membership in a group.
  717. For example a policy may be set up to allow calls to international
  718. destinations only to users, who are members of an "int" group.
  719. Before user's group membership is checked, his identity
  720. must be verified first. Without cryptographic verification of user's
  721. identity, it would be impossible to assert that a caller really
  722. is who he claims to be.
  723. </para>
  724. <para>
  725. The following script demonstrates, how to configure <application>ser</application>
  726. as an access control server for a PSTN gateway. The script verifies user
  727. identity using digest authentication, checks user's privileges,
  728. and forces all requests to visit the server.
  729. <example>
  730. <title>Script for Gateway Access Control</title>
  731. <programlisting>
  732. <xi:include href="../../examples/pstn.cfg" parse="text"/>
  733. </programlisting>
  734. </example>
  735. </para>
  736. <para>
  737. Use the <application>serctl</application> tool to
  738. maintain group membership.
  739. <application>serctl acl grant &lt;username&gt; &lt;group&gt;</application>
  740. makes a user member of a group,
  741. <application>serctl acl show &lt;username&gt;</application> shows groups
  742. of which a user is member, and
  743. <application>serctl acl revoke &lt;username&gt; [&lt;group&gt;]</application>
  744. revokes user's membership in one or all groups.
  745. <screen>
  746. [jiri@cat sip_router]$ serctl acl grant john int
  747. MySql Password:
  748. +------+-----+---------------------+
  749. | user | grp | last_modified |
  750. +------+-----+---------------------+
  751. | john | int | 2002-12-08 02:09:20 |
  752. +------+-----+---------------------+
  753. </screen>
  754. </para>
  755. </section> <!-- access control -->
  756. <section>
  757. <title>Accounting</title>
  758. <para>
  759. In some scenarios, like termination of calls in PSTN, SIP administrators
  760. may wish to keep track of placed calls. <application>ser</application>
  761. can be configured to report on completed transactions. Reports are sent
  762. by default to <application>syslog</application> facility.
  763. Support for RADIUS and mysql accounting exists as well.
  764. </para>
  765. <para>
  766. Note that <application>ser</application> is no way
  767. call-stateful. It reports on completed transactions, i.e., after
  768. a successful call set up is reported, it drops any call-related
  769. state. When a call is terminated, transactional state for BYE request
  770. is created and forgotten again after the transaction completes.
  771. This is a feature and not a bug -- keeping only transactional
  772. state allows for significantly higher scalability. It is then
  773. up to the accounting application to correlate call initiation
  774. and termination events.
  775. </para>
  776. <para>
  777. To enable call accounting, tm and acc modules need to be loaded,
  778. requests need to be processed statefully and labeled for
  779. accounting. That means, if you want a transaction to be reported,
  780. the initial request must have taken the path
  781. "<command>setflag(X)</command>, <command>t_relay</command>"
  782. in <application>ser</application> script. X must have the
  783. value configured in <varname>acc_flag</varname>
  784. configuration option.
  785. </para>
  786. <para>
  787. Also note, that by default only transactions that initiate
  788. a SIP dialog (typically INVITE) visit a proxy server.
  789. Subsequent transactions are exchanged directly between
  790. end-devices, do not visit proxy server and cannot be
  791. reported. To be able to report on subsequent transactions,
  792. you need to force them visit proxy server by turning
  793. record-routing on.
  794. </para>
  795. <para>
  796. <example>
  797. <title>Configuration with Enabled Accounting</title>
  798. <programlisting>
  799. <xi:include href="../../examples/acc.cfg" parse="text"/>
  800. </programlisting>
  801. </example>
  802. </para>
  803. </section> <!-- accounting -->
  804. <section>
  805. <title>Reliability</title>
  806. <para>
  807. It is essential to guarantee continuous
  808. service operation even under erroneous conditions,
  809. such as host or network failure. The major issue in such
  810. situations is transfer of operation to a backup
  811. infrastructure and making clients use it.
  812. </para>
  813. <para>
  814. The SIP standard's use of DNS SRV records has been
  815. explicitly constructed to handle with server failures.
  816. There may be multiple servers responsible for a domain
  817. and referred to by DNS. If it is impossible to communicate
  818. with a primary server, a client can proceed to another one.
  819. Backup servers may be located in a different geographic
  820. area to minimize risk caused by areal operational
  821. disasters: lack of power, flooding, earthquake, etc.
  822. <note>
  823. <sidebar>
  824. <para>Unless there are redundant DNS
  825. servers, fail-over capability cannot be guaranteed.
  826. </para>
  827. </sidebar>
  828. </note>
  829. Unfortunately, at the moment of writing this documentation
  830. (end of December 2002) only very few SIP products
  831. actually implement the DNS fail-over mechanism. Unless
  832. networks with SIP devices supporting this mechanism are
  833. built, alternative mechanisms must be used to force
  834. clients to use backup servers. Such a mechanism is
  835. disconnecting primary server and replacing it with
  836. a backup server locally.
  837. It unfortunately precludes geographic dispersion and
  838. requires network multihoming to avoid dependency on
  839. single IP access. Another method is to update DNS
  840. when failure of the primary server is detected.
  841. The primary drawback of this method is its latency:
  842. it may take long time until all clients learn to use
  843. the new server.
  844. </para>
  845. <para>
  846. The easier part of the redundancy story is replication of
  847. <application>ser</application>
  848. data. <application>ser</application>
  849. relies on replication capabilities of its back-end database.
  850. This works with one exception: user location database.
  851. User location database is a frequently accessed table,
  852. which is thus cached in server's memory to improve
  853. performance. Back-end replication does not affect
  854. in-memory tables, unless server reboots. To facilitate
  855. replication of user location database,
  856. server's SIP replication feature must be enabled
  857. in parallel with back-end replication.
  858. </para>
  859. <para>
  860. The design idea of replication of user location database
  861. is easy: Replicate any successful REGISTER requests to
  862. a peer server. To assure that digest credentials can
  863. be properly verified, both servers need to use the same
  864. digest generation secret and maintain synchronized time.
  865. A known limitation of this method is it does not replicate
  866. user contacts entered in another way, for example using
  867. web interface through FIFO server.
  868. The following script example shows configuration of
  869. a server that replicates all REGISTERs.
  870. <example>
  871. <title>Script for Replication of User Contacts</title>
  872. <programlisting>
  873. <xi:include href="../../examples/replicate.cfg" parse="text"/>
  874. </programlisting>
  875. </example>
  876. </para>
  877. </section> <!-- reliability -->
  878. <section>
  879. <title>Stateful versus Stateless Forwarding</title>
  880. <para>
  881. <application>ser</application> allows both stateless
  882. and stateful request processing. This memo explains what are pros and cons of
  883. using each method. The rule of thumb is "stateless for scalability,
  884. stateful for services". If you are unsure which you need, stateful
  885. is a safer choice which supports more usage scenarios.
  886. </para>
  887. <para>
  888. Stateless forwarding with the
  889. <command>forward(uri:host, uri:port)</command> action
  890. guarantees high scalability. It withstands high load and
  891. does not run out of memory. A perfect use of stateless forwarding
  892. is load distribution.
  893. </para>
  894. <para>
  895. Stateful forwarding using the <command>t_relay()</command>
  896. action is known to scale worse. It can quickly run out of memory and
  897. consumes more CPU time. Nevertheless, there are scenarios which are
  898. not implementable without stateful processing. In particular:
  899. <itemizedlist>
  900. <listitem>
  901. <para>
  902. <emphasis>Accounting</emphasis> requires stateful processing
  903. to be able to collect transaction status and issue a single
  904. report when a transaction completes.
  905. </para>
  906. </listitem>
  907. <listitem>
  908. <para>
  909. <emphasis>Forking</emphasis> only works with stateful forwarding.
  910. Stateless forwarding only forwards to the default URI out of the
  911. whole destination set.
  912. </para>
  913. </listitem>
  914. <listitem>
  915. <para>
  916. <emphasis>DNS resolution</emphasis>. DNS resolution may be
  917. better served with stateful processing. If a request is forwarded
  918. to a destination whose address takes long time to resolve,
  919. a server process is blocked and unresponsive. Subsequent
  920. request retransmissions from client will cause other processes
  921. to block too if requests are processed statelessly. As a result,
  922. <application>ser</application> will quickly
  923. run out of available processes. With stateful forwarding,
  924. retransmissions are absorbed and do not cause blocking of
  925. another process.
  926. </para>
  927. </listitem>
  928. <listitem>
  929. <para>
  930. <emphasis>Forwarding Services</emphasis>. All sort of services
  931. with the "forward_on_event" logic, which rely on
  932. <command>t_on_failure</command> tm
  933. action must be processed statefully.
  934. </para>
  935. </listitem>
  936. <listitem>
  937. <para>
  938. <emphasis>
  939. Fail-over.
  940. </emphasis>
  941. If you wish to try out another destination, after a primary destination
  942. failed you need to use stateful processing. With stateless processing
  943. you never know with what status a forwarded request completed downstream
  944. because you immediately release all processing information after the
  945. request is sent out.
  946. <note>
  947. <para>
  948. Positive return value of stateless
  949. <command>forward</command> action only indicates that
  950. a request was successfully sent out, and does not gain any knowledge
  951. about whether it was successfully received or replied. Neither does
  952. the return value of
  953. the stateful <command>t_relay</command> action family
  954. gain you this knowledge. However, these actions store transactional
  955. context with which includes original request and allows you to
  956. take an action when a negative reply comes back or a timer strikes.
  957. See <xref linkend="replyprocessingsection"/> for an example script
  958. which launches another
  959. branch if the first try fails.
  960. </para>
  961. </note>
  962. </para>
  963. </listitem>
  964. </itemizedlist>
  965. </para>
  966. </section> <!-- stateful vs. stateless -->
  967. <section>
  968. <title>Serving Multiple Domains</title>
  969. <para>
  970. <application>ser</application> can be configured to
  971. serve multiple domains. To do so, you need to take the following steps:
  972. <orderedlist>
  973. <listitem id="createtable">
  974. <para>
  975. Create separate subscriber and location database table
  976. for each domain served and name them uniquely.
  977. </para>
  978. </listitem>
  979. <listitem>
  980. <para>
  981. Configure your script to distinguish between multiple
  982. served domains. Use regular expressions for domain
  983. matching as described in <xref linkend="redomainmatching"/>.
  984. </para>
  985. </listitem>
  986. <listitem>
  987. <para>
  988. Update table names in usrloc and auth actions to reflect
  989. names you created in <xref linkend="createtable"/>.
  990. </para>
  991. </listitem>
  992. </orderedlist>
  993. </para>
  994. <para>
  995. The latest <application>SER</application> release includes automated
  996. multidomain management which greatly automates maintenance of multiple
  997. domains. Ask our technical support for more help.
  998. </para>
  999. </section> <!-- multiple domains -->
  1000. <section id="missedcalls">
  1001. <title>Reporting Missed Calls</title>
  1002. <para>
  1003. <application>ser</application> can report missed
  1004. calls via <application>syslog</application> facility
  1005. or to mysql. Mysql reporting can be utilized by
  1006. <application>ser</application>'s
  1007. complementary web-interface, <application>serweb</application>.
  1008. (See more in <xref linkend="serweb"/>).
  1009. </para>
  1010. <para>
  1011. Reporting on missed calls is enabled by acc module.
  1012. There are two cases, on which you want to report. The first
  1013. case is when a callee is off-line. The other case is when
  1014. a user is on-line, but call establishment fails. There
  1015. may be many failure reasons (call cancellation, inactive phone,
  1016. busy phone, server timer, etc.), all of them leading to
  1017. a negative (>=300) reply sent to caller. The acc module
  1018. can be configured to issue a missed-call report whenever
  1019. a transaction completes with a negative status. Two following
  1020. script fragment deals with both cases.
  1021. </para>
  1022. <para>
  1023. First, it reports
  1024. on calls missed due to off-line callee status
  1025. using the <command>acc_request</command>
  1026. action. The action is wrapped in transactional
  1027. processing (<command>t_newtran</command>)
  1028. to guarantee that reports are not
  1029. duplicated on receipt of retransmissions.
  1030. </para>
  1031. <para>
  1032. Secondly, transactions to on-line users are marked
  1033. to be reported on failure. That is what the
  1034. <command>setflag(3)</command> action
  1035. is responsible for, along with the configuration option
  1036. "log_missed_flag". This option configures <application>ser</application>
  1037. to report on all transactions, which were marked
  1038. with flag 3.
  1039. <programlisting>
  1040. loadmodule("modules/tm/tm.so");
  1041. loadmodule("modules/acc/acc.so");
  1042. ....
  1043. # if a call is labeled using setflag(3) and is missed, it will
  1044. # be reported
  1045. ...
  1046. modparam("acc", "log_missed_flag", 3 );
  1047. if (!lookup("location")) {
  1048. # call invitations to off-line users are reported using the
  1049. # acc_request action; to avoid duplicate reports on request
  1050. # retransmissions, request is processed statefully (t_newtran,
  1051. # t_reply)
  1052. if ((method=="INVITE" || method=="ACK") &amp;&amp; t_newtran() ) {
  1053. t_reply("404", "Not Found");
  1054. acc_request("404 Not Found");
  1055. break;
  1056. };
  1057. # all other requests to off-line users are simply replied
  1058. # statelessly and no reports are issued
  1059. sl_send_reply("404", "Not Found");
  1060. break;
  1061. } else {
  1062. # user on-line; report on failed transactions; mark the
  1063. # transaction for reporting using the same number as
  1064. # configured above; if the call is really missed, a report
  1065. # will be issued
  1066. setflag(3);
  1067. # forward to user's current destination
  1068. t_relay();
  1069. break;
  1070. };
  1071. </programlisting>
  1072. </para>
  1073. </section> <!-- missed calls -->
  1074. <section>
  1075. <title>NAT Traversal</title>
  1076. <para>
  1077. NATs are worst things that ever happened to SIP. These devices
  1078. are very popular because they help to conserve IP address space
  1079. and save money charged for IP addresses. Unfortunately, they
  1080. translate addresses in a way which is not compatible with SIP.
  1081. SIP advertises receiver addresses in its payload. The advertised
  1082. addresses are invalid out of NATed networks. As a result,
  1083. SIP communication does not work across NATs without extra
  1084. effort.
  1085. </para>
  1086. <para>
  1087. There are few methods that may be deployed to traverse NATs.
  1088. How proper their use is depends on the deployment scenario.
  1089. Unfortunately, all the methods have some limitations and
  1090. there is no straight-forward solution addressing all
  1091. scenarios. Note that none of these methods takes explicit
  1092. support in <application>ser</application>.
  1093. </para>
  1094. <para>
  1095. The first issue is whether SIP users are in control of
  1096. their NATs. If not (NATs are either operated by ISP or
  1097. they are sealed to prevent users setting them up), the
  1098. only method is use of a STUN-enabled phone. STUN is
  1099. a very simple protocol used to fool NAT in such a way,
  1100. they permit SIP sessions. Currently, we are aware of
  1101. one softphone (kphone) and one hardphone (snom) with
  1102. STUN support, other vendors are working on STUN support
  1103. too. Unfortunately, STUN gives no NAT traversal
  1104. guarantee -- there are types of NATs, so called
  1105. symmetric NATs, over which STUN fails to work.
  1106. <note>
  1107. <para>
  1108. There is actually yet another method to address
  1109. SIP-unaware, user-uncontrolled NATs. It is based
  1110. on a proxy server, which relays all signaling and
  1111. media and mangles packets to make them more
  1112. NAT-friendly. The very serious problem with this
  1113. method is it does not scale.
  1114. </para>
  1115. </note>
  1116. </para>
  1117. <para>
  1118. If users are in control of their own NAT, as typically residential
  1119. users are, they can still use STUN. However, they may use other
  1120. alternatives too. One of them is to replace their NAT with
  1121. a SIP-aware NAT. Such NATs have built-in SIP awareness,
  1122. that patches problems caused by address translations. Prices
  1123. of such devices are getting low and there are available
  1124. implementations (Intertex, Cisco/PIX). No special support
  1125. in phones is needed.
  1126. </para>
  1127. <para>
  1128. Other emerging option is UPnP. UPnP is a protocol that allows
  1129. phones to negotiate with NAT boxes. You need UPnP support in
  1130. both, NAT and phones. As UPnP NATs are quite affordable,
  1131. costs are not an obstacle. Currently, we are aware of one
  1132. SIP phone (SNOM) with UPnP support.
  1133. </para>
  1134. <para>
  1135. Geeks not wishing to upgrade their firewall to a SIP-aware or
  1136. UPnP-enabled one may try to configure static address translation.
  1137. That takes phones with configuration ability to use fixed port
  1138. numbers and advertise outside address in signaling. Cisco phones
  1139. have this capability, for example. The NAT devices need to
  1140. be configured to translate outside port ranges to the
  1141. ranges configured in phones.
  1142. </para>
  1143. </section> <!-- NAT traversal -->
  1144. <section>
  1145. <title>Using Only Latest User's Contact for Forwarding
  1146. </title>
  1147. <para>
  1148. In some scenarios, it may be beneficial only to use only one
  1149. registered contact per user. If that is the case, setting
  1150. registrar module's parameter <varname>append_branches</varname>
  1151. to 1 will eliminate forking and forward all requests only
  1152. to a single contact. If there are multiple contacts, a contact
  1153. with highest priority is chosen. This can be changed to
  1154. the "freshest" contact by setting module parameter's
  1155. <varname>desc_time_order</varname> to 1.
  1156. </para>
  1157. </section>
  1158. <section>
  1159. <title>Authentication Policy: Prevention of Unauthorized Domain
  1160. Name Use in From and More</title>
  1161. <para>
  1162. Malicious users can claim a name of domain, to which they do
  1163. not administratively belong, in From header field. This
  1164. behavior cannot be generally prevented. The reason is
  1165. that requests with such a faked header field do not need
  1166. to visit servers of the domain in question. However, if they
  1167. do so, it is desirable to assure that users claiming
  1168. membership in a domain are actually associated with it.
  1169. Otherwise the faked requests would be relayed and appear
  1170. as coming from the domain, which would increase
  1171. credibility of the faked address and decrease credibility of
  1172. the proxy server.
  1173. </para>
  1174. <para>
  1175. Preventing unauthorized domain name use in relayed requests
  1176. is not difficult.
  1177. One needs to authenticate each request with name of the
  1178. served domain in From header field. To do so, one can
  1179. search for such a header field using <command>search</command>
  1180. action (textops module) and force authentication if the
  1181. search succeeds.
  1182. <note>
  1183. <para>
  1184. A straight-forward solution might be to authenticate
  1185. ALL requests. However, that only works in closed
  1186. networks in which all users have an account in the
  1187. server domain. In open networks, it is desirable to permit
  1188. incoming calls from callers from other domains without
  1189. any authentication. For example, a company may wish
  1190. to accept calls from unknown callers who are
  1191. new prospective customers.
  1192. </para>
  1193. </note>
  1194. <programlisting>
  1195. # does the user claim our domain "foo.bar" in From?
  1196. if (search("^(f|From):.*foo.bar")) {
  1197. # if so, verify credential
  1198. if (!proxy_authorize("foo.bar", "subscriber")) {
  1199. # don't proceed if credentials broken; challenge
  1200. proxy_challenge("foo.bar", "0");
  1201. break;
  1202. };
  1203. };
  1204. </programlisting>
  1205. </para>
  1206. <para>
  1207. In general, the authentication policy may be very rich. You may not
  1208. forget each request deserves its own security and you need to
  1209. decide whether it shall be authenticated or not. As mentioned
  1210. above, in closed networks, you may want to authenticate absolutely
  1211. every request. That however prohibits traffic from users from
  1212. other domains. A pseudo-example of a reasonable policy is attached:
  1213. it looks whether a request is registration, it claims to originate
  1214. from our domain in From header field, or is a local request to
  1215. another domain.
  1216. <programlisting>
  1217. # (example provided by Michael Graff on [serusers] mailing list
  1218. if (to me):
  1219. if register
  1220. www_authorize or fail if not a valid register
  1221. done
  1222. if claiming to be "From" one of the domains I accept registrations for
  1223. proxy_authorize
  1224. done
  1225. if not to me (I'm relaying for a local phone to an external address)
  1226. proxy_authorize
  1227. done
  1228. </programlisting>
  1229. </para>
  1230. <para>
  1231. You also may want to apply additional restriction to how
  1232. digest username relates to usernames claimed in From and
  1233. To header fields. For example, the <command>check_to</command>
  1234. action enforces the digest id to be equal to username
  1235. in To header fields. That is good in preventing someone
  1236. with valid credentials to register as someone else
  1237. (e.g., sending a REGISTER with valid credentials of
  1238. "joe" and To belonging to "alice"). Similarly,
  1239. <command>check_from</command> is used
  1240. to enforce username in from to equal to digest id.
  1241. <note>
  1242. <para>
  1243. There may be a need for a more complex relationship
  1244. between From/To username and digest id. For example,
  1245. providers with an established user/password database
  1246. may wish to keep using it, whereas permitting users
  1247. to claim some telephone numbers in From. To address
  1248. such needs generally, there needs to be a 1:N mapping
  1249. between digest id and all usernames that are acceptable
  1250. for it. This is being addressed in a newly contributed
  1251. module "domain", which also addresses more generally
  1252. issues of domain matching for multidomain scenarios.
  1253. </para>
  1254. </note>
  1255. </para>
  1256. <para>
  1257. Other operational aspect affecting the authentication policy
  1258. is guarding PSTN gateways (see <xref linkend="acl"/>). There
  1259. may be destinations that are given away for free whereas
  1260. other destinations may require access control using
  1261. group membership, to which authentication is a prerequisite.
  1262. </para>
  1263. </section> <!-- authentication policy, faked froms -->
  1264. <section>
  1265. <title>Connecting to PBX Voicemail Using a Cisco Gateway</title>
  1266. <para>
  1267. In some networks, administrators may wish to utilize their
  1268. PBX voicemail systems behind PSTN gateways. There is a practical problem
  1269. in many network settings: it is not clear for whom a call to
  1270. voicemail is. If voicemail is identified by a single number,
  1271. which is then put in INVITE's URI, there is no easy way to
  1272. learn for whom a message should be recorded. PBX voicemails
  1273. utilize that PSTN protocols signal the number of originally
  1274. called party. If you wish to make the PBX voicemail work,
  1275. you need to convey the number in SIP and translate it in
  1276. PSTN gateways to its PSTN counterpart.
  1277. </para>
  1278. <para>
  1279. There may be many different ways to achieve this scenario. Here
  1280. we describe the proprietary mechanism Cisco gateways use and how to
  1281. configure <application>ser</application> to
  1282. make the gateways happy. Cisco gateways expect the number
  1283. of originally called party to be located in proprietary
  1284. <varname>CC-Diversion</varname> header field. When a SIP
  1285. INVITE sent via a PSTN gateway to PBX voicemail has number
  1286. of originally called party in the header field, the voicemail
  1287. system knows for whom the incoming message is. That is at least
  1288. true for AS5300/2600 with Cisco IOS 12.2.(2)XB connected to
  1289. Nortel pbxs via PRI. (On the other hand, 12.2.(7b) is known
  1290. not to work in this scenario.)
  1291. </para>
  1292. <para>
  1293. <application>ser</application> needs then to
  1294. be configured to append the <varname>CC-Diversion</varname>
  1295. header field name for INVITEs sent to PBX voicemail.
  1296. The following script shows that: when initial forwarding
  1297. fails (nobody replies, busy is received, etc.), a new branch
  1298. is initiated to the pbx's phone number.
  1299. <command>append_urihf</command> is used to
  1300. append the <varname>CC-Diversion</varname> header field. It
  1301. takes two parameters: prefix, which includes header name,
  1302. and suffix which takes header field separator.
  1303. <command>append_urihf</command> inserts
  1304. original URI between those two.
  1305. <example>
  1306. <title>Forwarding to PBX/Voicemail via Cisco Gateways</title>
  1307. <programlisting>
  1308. <xi:include href="../../examples/ccdiversion.cfg" parse="text"/>
  1309. </programlisting>
  1310. </example>
  1311. </para>
  1312. </section>
  1313. </section> <!-- howtos -->
  1314. <section>
  1315. <title>Troubleshooting</title>
  1316. <para>
  1317. This section gathers practices how to deal with errors
  1318. known to occur frequently. To understand how to watch
  1319. SIP messages, server logs, and in general how to
  1320. troubleshoot, read also <xref linkend="operationalpractices"/>.
  1321. </para>
  1322. <qandaset>
  1323. <qandaentry>
  1324. <question>
  1325. <para>
  1326. SIP requests are replied by <application>ser</application> with
  1327. "483 Too Many Hops" or "513 Message Too Large"
  1328. </para>
  1329. </question>
  1330. <answer>
  1331. <para>
  1332. In both cases, the reason is probably an error in
  1333. request routing script which caused an infinite loop.
  1334. You can easily verify whether this happens by
  1335. watching SIP traffic on loopback interface. A typical
  1336. reason for misrouting is a failure to match local
  1337. domain correctly. If a server fails to recognize
  1338. a request for itself, it will try to forward it
  1339. to current URI in believe it would forward them
  1340. to a foreign domain. Alas, it forwards the request
  1341. to itself again. This continues to happen until
  1342. value of max_forwards header field reaches zero
  1343. or the request grows too big. Solutions is easy:
  1344. make sure that domain matching is correctly
  1345. configured. See <xref linkend="domainmatching"/>
  1346. for more information how to get it right.
  1347. </para>
  1348. </answer>
  1349. </qandaentry>
  1350. <qandaentry id="msmbug">
  1351. <question>
  1352. <para>
  1353. Windows Messenger authentication fails.
  1354. </para>
  1355. </question>
  1356. <answer>
  1357. <para>
  1358. The most likely reason for this problem is a bug
  1359. in Windows Messenger. WM only authenticates if
  1360. server name in request URI equals authentication
  1361. realm. After a challenge is sent by SIP server,
  1362. WM does not resubmit the challenged request at all
  1363. and pops up authentication window again.
  1364. If you want to authenticate WM, you need to
  1365. set up your realm value to equal server name.
  1366. If your server has no name, IP address can be used
  1367. as realm too. The realm value is configured in
  1368. scripts as the first parameter of all
  1369. <command>{www|proxy}_{authorize|challenge}</command>
  1370. actions.
  1371. </para>
  1372. </answer>
  1373. </qandaentry>
  1374. <qandaentry id="mhomed">
  1375. <question>
  1376. <para>
  1377. On a multihomed host, forwarded messages carry other
  1378. interface in Via than used for sending, or messages
  1379. are not sent and an error log is issued "invalid
  1380. sendtoparameters one possible reason is the server
  1381. is bound to localhost".
  1382. </para>
  1383. </question>
  1384. <answer>
  1385. <para>
  1386. Set the configuration option <varname>mhomed</varname>
  1387. to "1". <application>ser</application>
  1388. will then attempt to calculate the correct interface.
  1389. It's not done by default as it degrades performance
  1390. on single-homed hosts or multi-homed hosts that are
  1391. not set-up as routers.
  1392. </para>
  1393. </answer>
  1394. </qandaentry>
  1395. <qandaentry>
  1396. <question>
  1397. <para>
  1398. I receive "ERROR: t_newtran: transaction already in process" in my logs.
  1399. </para>
  1400. </question>
  1401. <answer>
  1402. <para>
  1403. That looks like an erroneous use of tm module in script.
  1404. tm can handle only one transaction per request. If you
  1405. attempt to instantiate a transaction multiple times,
  1406. <application>ser</application> will complain.
  1407. Anytime any of <command>t_newtran</command>,
  1408. <command>t_relay</command> or
  1409. <command>t_relay_to_udp</command> actions is
  1410. encountered, tm attempts to instantiate a transaction.
  1411. Doing so twice fails. Make sure that any of this
  1412. commands is called only once during script execution.
  1413. </para>
  1414. </answer>
  1415. </qandaentry>
  1416. <qandaentry>
  1417. <question>
  1418. <para>
  1419. I try to add an alias but
  1420. <command>serctl</command>
  1421. complains that table does not exist.
  1422. </para>
  1423. </question>
  1424. <answer>
  1425. <para>
  1426. You need to run <application>ser</application>
  1427. and use the command
  1428. <command>lookup("aliases")</command>
  1429. in its routing script. That's because the table
  1430. of aliases is
  1431. stored in cache memory for high speed. The cache
  1432. memory is only set up when the
  1433. <application>ser</application>
  1434. is running and configured to use it. If that is
  1435. not the case,
  1436. <application>serctl</application>
  1437. is not able to manipulate the aliases table.
  1438. </para>
  1439. </answer>
  1440. </qandaentry>
  1441. <qandaentry>
  1442. <question>
  1443. <para>I started <application>ser</application> with
  1444. <varname>children=4</varname> but many more processes
  1445. were started. What is wrong?
  1446. </para>
  1447. </question>
  1448. <answer>
  1449. <para>
  1450. That's ok. The <varname>children</varname> parameter defines
  1451. how many children should process each transport protocol in
  1452. parallel. Typically, the server listens to multiple protocols
  1453. and starts other supporting processes like timer or FIFO
  1454. server too. Call <application>serctl ps</application> to watch
  1455. running processes.
  1456. </para>
  1457. </answer>
  1458. </qandaentry>
  1459. <qandaentry>
  1460. <question>
  1461. <para>
  1462. I decided to use a compiled version of <application>ser</application>
  1463. but it does not start any more.
  1464. </para>
  1465. </question>
  1466. <answer>
  1467. <para>
  1468. You probably kept the same configuration file, which tries to load modules
  1469. from the binary distribution you used previously. Make sure that modules
  1470. paths are valid and point to where you compiled <application>ser</application>.
  1471. Also, watch logs for error messages "ERROR: load_module: could not open
  1472. module".
  1473. </para>
  1474. </answer>
  1475. </qandaentry>
  1476. </qandaset>
  1477. </section> <!-- troubleshooting -->
  1478. </section>