Debian Codegraph @

src/modules/tm/README

raw
1 TM Module
2
3 Jiri Kuthan
4
5 FhG FOKUS
6
7 Juha Heinanen
8
9 <[email protected]>
10
11 Daniel-Constantin Mierla
12
13 <[email protected]>
14
15 Copyright © 2003 FhG FOKUS
16
17 Copyright © 2008 Juha Heinanen
18
19 Copyright © 2016 Daniel-Constantin Mierla
20 __________________________________________________________________
21
22 Table of Contents
23
24 1. Admin Guide
25
26 1. Overview
27 2. Serial Forking Based on Q Value
28 3. Parameters
29
30 3.1. fr_timer (integer)
31 3.2. fr_inv_timer (integer)
32 3.3. max_inv_lifetime (integer)
33 3.4. max_noninv_lifetime (integer)
34 3.5. wt_timer (integer)
35 3.6. retr_timer1 (integer)
36 3.7. retr_timer2 (integer)
37 3.8. noisy_ctimer (integer)
38 3.9. restart_fr_on_each_reply (integer)
39 3.10. auto_inv_100 (integer)
40 3.11. auto_inv_100_reason (string)
41 3.12. unix_tx_timeout (integer)
42 3.13. aggregate_challenges (integer)
43 3.14. reparse_invite (integer)
44 3.15. ac_extra_hdrs (string)
45 3.16. blst_503 (integer)
46 3.17. blst_503_def_timeout (integer)
47 3.18. blst_503_min_timeout (integer)
48 3.19. blst_503_max_timeout (integer)
49 3.20. blst_methods_add (unsigned integer)
50 3.21. blst_methods_lookup (unsigned integer)
51 3.22. cancel_b_method (integer)
52 3.23. reparse_on_dns_failover (integer)
53 3.24. on_sl_reply (string)
54 3.25. contacts_avp (string)
55 3.26. contact_flows_avp (string)
56 3.27. fr_timer_avp (string)
57 3.28. fr_inv_timer_avp (string)
58 3.29. unmatched_cancel (integer)
59 3.30. ruri_matching (integer)
60 3.31. via1_matching (integer)
61 3.32. reply_matching (int)
62 3.33. callid_matching (integer)
63 3.34. callid_cseq_matching (int)
64 3.35. pass_provisional_replies (integer)
65 3.36. default_code (integer)
66 3.37. default_reason (string)
67 3.38. disable_6xx_block (integer)
68 3.39. local_ack_mode (integer)
69 3.40. local_ack_branch_mode (integer)
70 3.41. failure_reply_mode (integer)
71 3.42. faked_reply_prio (integer)
72 3.43. local_cancel_reason (boolean)
73 3.44. e2e_cancel_reason (boolean)
74 3.45. e2e_cancel_hop_by_hop (int)
75 3.46. headers_mode (int)
76 3.47. remap_503_500 (boolean)
77 3.48. failure_exec_mode (boolean)
78 3.49. dns_reuse_rcv_socket (boolean)
79 3.50. xavp_contact (string)
80 3.51. event_callback (str)
81 3.52. event_callback_lres_sent (str)
82 3.53. evcb_local_ack_sent (str)
83 3.54. relay_100 (str)
84 3.55. rich_redirect (int)
85 3.56. exec_time_check (int)
86 3.57. reply_relay_mode (int)
87 3.58. enable_uac_fr (int)
88 3.59. failover_reply_codes (string)
89 3.60. reply_408_code (int)
90 3.61. reply_408_reason (str)
91 3.62. delayed_reply (int)
92 3.63. evlreq_mode (int)
93
94 4. Functions
95
96 4.1. t_relay([host, port])
97 4.2. t_relay_to_udp([ip, port])
98 4.3. t_relay_to_tcp([ip, port])
99 4.4. t_relay_to_tls([ip, port])
100 4.5. t_relay_to_sctp([ip, port])
101 4.6. t_on_failure(failure_route)
102 4.7. t_on_branch_failure(branch_failure_route)
103 4.8. t_on_reply(onreply_route)
104 4.9. t_on_branch(branch_route)
105 4.10. t_newtran()
106 4.11. t_reply(code, reason_phrase)
107 4.12. t_reply_error()
108 4.13. t_send_reply(code, reason)
109 4.14. t_lookup_request()
110 4.15. t_retransmit_reply()
111 4.16. t_release()
112 4.17. t_forward_nonack([ip, port])
113 4.18. t_forward_nonack_udp(ip, port)
114 4.19. t_forward_nonack_tcp(ip, port)
115 4.20. t_forward_nonack_tls(ip, port)
116 4.21. t_forward_nonack_sctp(ip, port)
117 4.22. t_set_fr(fr_inv_timeout [, fr_timeout])
118 4.23. t_reset_fr()
119 4.24. t_set_max_lifetime(inv_lifetime, noninv_lifetime)
120 4.25. t_reset_max_lifetime()
121 4.26. t_set_retr(retr_t1_interval, retr_t2_interval)
122 4.27. t_reset_retr()
123 4.28. t_set_auto_inv_100(0|1)
124 4.29. t_branch_timeout()
125 4.30. t_branch_replied()
126 4.31. t_any_timeout()
127 4.32. t_any_replied()
128 4.33. t_grep_status("code")
129 4.34. t_is_canceled()
130 4.35. t_is_expired()
131 4.36. t_relay_cancel()
132 4.37. t_lookup_cancel([1])
133 4.38. t_drop_replies([mode])
134 4.39. t_save_lumps()
135 4.40. t_load_contacts([mode])
136 4.41. t_next_contacts()
137 4.42. t_next_contact_flow()
138 4.43. t_check_status(re)
139 4.44. t_check_trans()
140 4.45. t_set_disable_6xx(0|1)
141 4.46. t_set_disable_failover(0|1)
142 4.47. t_set_disable_internal_reply(0|1)
143 4.48. t_set_no_auto_ack(0|1)
144 4.49. t_replicate([params])
145 4.50. t_relay_to(proxy, flags)
146 4.51. t_relay_to_proxy(proxy [, flags])
147 4.52. t_set_no_e2e_cancel_reason(0|1)
148 4.53. t_is_set(target)
149 4.54. t_use_uac_headers()
150 4.55. t_is_retr_async_reply()
151 4.56. t_uac_send(method, ruri, nexthop, socket, headers,
152 body)
153
154 4.57. t_get_status_code()
155 4.58. t_clean()
156 4.59. t_exists()
157 4.60. t_cell_append_branches(tindex, tlabel)
158 4.61. t_msg_apply_changes()
159
160 5. RPC Commands
161
162 5.1. tm.list
163 5.2. tm.t_uac_start
164 5.3. tm.t_uac_start_hex
165 5.4. tm.t_uac_wait
166 5.5. tm.t_uac_wait_hex
167 5.6. tm.t_uac_wait_block
168 5.7. tm.t_uac_wait_block_hex
169 5.8. tm.t_uac_start_noack
170 5.9. tm.t_uac_start_noack_hex
171 5.10. tm.t_uac_wait_noack
172 5.11. tm.t_uac_wait_noack_hex
173 5.12. tm.t_uac_wait_block_noack
174 5.13. tm.t_uac_wait_block_noack_hex
175 5.14. tm.t_uac_attrs
176 5.15. tm.cancel
177 5.16. tm.hash_stats
178 5.17. tm.reply
179 5.18. tm.reply_callid
180 5.19. tm.retransmit_reply
181 5.20. tm.retransmit_reply_callid
182 5.21. tm.clean
183 5.22. tm.stats
184
185 6. Event Routes
186
187 6.1. event_route[tm:branch-failure:id]
188 6.2. event_route[tm:local-request]
189 6.3. event_route[tm:local-response]
190 6.4. event_route[tm:local-ack-sent]
191
192 7. TM Module API
193
194 7.1. Defines
195 7.2. Functions
196
197 7.2.1. register_tmcb(cb_type, cb_func)
198 7.2.2. load_tm(*import_structure)
199 7.2.3. int t_suspend(struct sip_msg *msg, unsigned int
200 *hash_index, unsigned int *label)
201
202 7.2.4. int t_continue(unsigned int hash_index,
203 unsigned int label, struct action *route)
204
205 7.2.5. int t_cancel_suspend(unsigned int hash_index,
206 unsigned int label)
207
208 8. Known Issues
209
210 List of Examples
211
212 1.1. Set fr_timer parameter
213 1.2. Set fr_inv_timer parameter
214 1.3. Set max_inv_lifetime parameter
215 1.4. Set max_noninv_lifetime parameter
216 1.5. Set wt_timer parameter
217 1.6. Set retr_timer1 parameter
218 1.7. Set retr_timer2 parameter
219 1.8. Set noisy_ctimer parameter
220 1.9. Set restart_fr_on_each_reply parameter
221 1.10. Set auto_inv_100 parameter
222 1.11. Set auto_inv_100_reason parameter
223 1.12. Set unix_tx_timeout parameter
224 1.13. Set aggregate_challenges parameter
225 1.14. Set reparse_invite parameter
226 1.15. Set ac_extra_hdrs parameter
227 1.16. Set blst_503 parameter
228 1.17. Set blst_503_def_timeout parameter
229 1.18. Set blst_503_min_timeout parameter
230 1.19. Set blst_503_max_timeout parameter
231 1.20. Set blst_methods_add parameter
232 1.21. Set blst_methods_lookup parameter
233 1.22. Set cancel_b_method parameter
234 1.23. Set reparse_on_dns_failover parameter
235 1.24. Set on_sl_reply parameter
236 1.25. Set on_sl_reply parameter (KEMI javascript)
237 1.26. Set contacts_avp parameter
238 1.27. Set contact_flows_avp parameter
239 1.28. Set fr_timer_avp parameter
240 1.29. Set fr_inv_timer_avp parameter
241 1.30. Set unmatched_cancel parameter
242 1.31. Set ruri_matching parameter
243 1.32. Set via1_matching parameter
244 1.33. Set reply_matching parameter
245 1.34. Set callid_matching parameter
246 1.35. Set callid_cseq_matching parameter
247 1.36. Set pass_provisional_replies parameter
248 1.37. Set default_code parameter
249 1.38. Set default_reason parameter
250 1.39. Set disable_6xx_block parameter
251 1.40. Set local_ack_mode parameter
252 1.41. Set local_ack_branch_mode parameter
253 1.42. Set failure_reply_mode parameter
254 1.43. Set faked_reply_prio parameter
255 1.44. Set local_cancel_reason parameter
256 1.45. Set e2e_cancel_reason parameter
257 1.46. Set e2e_cancel_hop_by_hop parameter
258 1.47. Set headers_mode parameter
259 1.48. Set remap_503_500 parameter
260 1.49. Set failure_exec_mode parameter
261 1.50. Set dns_reuse_rcv_socket parameter
262 1.51. Set xavp_contact parameter
263 1.52. Set event_callback parameter
264 1.53. Set event_callback_lres_sent parameter
265 1.54. Set evcb_local_ack_sent parameter
266 1.55. Set relay_100 parameter
267 1.56. rich_redirect example
268 1.57. Set exec_time_check parameter
269 1.58. Set reply_relay_mode parameter
270 1.59. enable_uac_fr example
271 1.60. Set the “failover_reply_codes” parameter
272 1.61. reply_408_code example
273 1.62. reply_408_reason example
274 1.63. delayed_reply example
275 1.64. evlreq_mode example
276 1.65. t_relay usage
277 1.66. t_relay_to_udp usage
278 1.67. t_on_failure usage
279 1.68. t_on_branch_failure usage
280 1.69. t_on_reply usage
281 1.70. t_on_branch usage
282 1.71. t_newtran usage
283 1.72. t_reply usage
284 1.73. t_reply_error usage
285 1.74. t_send_reply usage
286 1.75. t_lookup_request usage
287 1.76. t_retransmit_reply usage
288 1.77. t_release usage
289 1.78. t_forward_nonack usage
290 1.79. t_set_fr usage
291 1.80. t_reset_fr usage
292 1.81. t_set_max_lifetime usage
293 1.82. t_reset_max_lifetime usage
294 1.83. t_set_retr usage
295 1.84. t_reset_retr usage
296 1.85. t_set_auto_inv_100 usage
297 1.86. t_branch_timeout usage
298 1.87. t_branch_replied usage
299 1.88. t_any_timeout usage
300 1.89. t_any_replied usage
301 1.90. t_grep_status usage
302 1.91. t_is_canceled usage
303 1.92. t_is_expired usage
304 1.93. t_relay_cancel usage
305 1.94. t_lookup_cancel usage
306 1.95. t_drop_replies() usage
307 1.96. t_save_lumps() usage
308 1.97. t_load_contacts usage
309 1.98. t_next_contacts usage
310 1.99. t_next_contact_flow usage
311 1.100. t_check_status usage
312 1.101. t_check_trans usage
313 1.102. t_set_disable_6xx usage
314 1.103. t_set_disable_failover usage
315 1.104. t_set_disable_internal_reply usage
316 1.105. t_set_no_auto_ack usage
317 1.106. t_replicate usage
318 1.107. t_relay_to usage
319 1.108. t_relay_to_proxy usage
320 1.109. t_set_no_e2e_cancel_reason usage
321 1.110. t_replicate usage
322 1.111. t_use_uac_headers usage
323 1.112. t_is_retr_async_reply usage
324 1.113. t_uac_send usage
325 1.114. t_get_status_code usage
326 1.115. t_clean usage
327 1.116. t_exists usage
328 1.117. t_cell_append_branches usage
329 1.118. t_msg_apply_changes usage
330 1.119. Using “tm.t_uac_attrs”
331 1.120. Using “tm.retransmit_reply”
332 1.121. Using “tm.retransmit_reply_callid”
333 1.122. event_route[tm:branch-failure:id] usage
334 1.123. event_route[tm:local-request] usage
335 1.124. event_route[tm:local-response] usage
336 1.125. event_route[tm:local-ack-sent] usage
337
338 Chapter 1. Admin Guide
339
340 Table of Contents
341
342 1. Overview
343 2. Serial Forking Based on Q Value
344 3. Parameters
345
346 3.1. fr_timer (integer)
347 3.2. fr_inv_timer (integer)
348 3.3. max_inv_lifetime (integer)
349 3.4. max_noninv_lifetime (integer)
350 3.5. wt_timer (integer)
351 3.6. retr_timer1 (integer)
352 3.7. retr_timer2 (integer)
353 3.8. noisy_ctimer (integer)
354 3.9. restart_fr_on_each_reply (integer)
355 3.10. auto_inv_100 (integer)
356 3.11. auto_inv_100_reason (string)
357 3.12. unix_tx_timeout (integer)
358 3.13. aggregate_challenges (integer)
359 3.14. reparse_invite (integer)
360 3.15. ac_extra_hdrs (string)
361 3.16. blst_503 (integer)
362 3.17. blst_503_def_timeout (integer)
363 3.18. blst_503_min_timeout (integer)
364 3.19. blst_503_max_timeout (integer)
365 3.20. blst_methods_add (unsigned integer)
366 3.21. blst_methods_lookup (unsigned integer)
367 3.22. cancel_b_method (integer)
368 3.23. reparse_on_dns_failover (integer)
369 3.24. on_sl_reply (string)
370 3.25. contacts_avp (string)
371 3.26. contact_flows_avp (string)
372 3.27. fr_timer_avp (string)
373 3.28. fr_inv_timer_avp (string)
374 3.29. unmatched_cancel (integer)
375 3.30. ruri_matching (integer)
376 3.31. via1_matching (integer)
377 3.32. reply_matching (int)
378 3.33. callid_matching (integer)
379 3.34. callid_cseq_matching (int)
380 3.35. pass_provisional_replies (integer)
381 3.36. default_code (integer)
382 3.37. default_reason (string)
383 3.38. disable_6xx_block (integer)
384 3.39. local_ack_mode (integer)
385 3.40. local_ack_branch_mode (integer)
386 3.41. failure_reply_mode (integer)
387 3.42. faked_reply_prio (integer)
388 3.43. local_cancel_reason (boolean)
389 3.44. e2e_cancel_reason (boolean)
390 3.45. e2e_cancel_hop_by_hop (int)
391 3.46. headers_mode (int)
392 3.47. remap_503_500 (boolean)
393 3.48. failure_exec_mode (boolean)
394 3.49. dns_reuse_rcv_socket (boolean)
395 3.50. xavp_contact (string)
396 3.51. event_callback (str)
397 3.52. event_callback_lres_sent (str)
398 3.53. evcb_local_ack_sent (str)
399 3.54. relay_100 (str)
400 3.55. rich_redirect (int)
401 3.56. exec_time_check (int)
402 3.57. reply_relay_mode (int)
403 3.58. enable_uac_fr (int)
404 3.59. failover_reply_codes (string)
405 3.60. reply_408_code (int)
406 3.61. reply_408_reason (str)
407 3.62. delayed_reply (int)
408 3.63. evlreq_mode (int)
409
410 4. Functions
411
412 4.1. t_relay([host, port])
413 4.2. t_relay_to_udp([ip, port])
414 4.3. t_relay_to_tcp([ip, port])
415 4.4. t_relay_to_tls([ip, port])
416 4.5. t_relay_to_sctp([ip, port])
417 4.6. t_on_failure(failure_route)
418 4.7. t_on_branch_failure(branch_failure_route)
419 4.8. t_on_reply(onreply_route)
420 4.9. t_on_branch(branch_route)
421 4.10. t_newtran()
422 4.11. t_reply(code, reason_phrase)
423 4.12. t_reply_error()
424 4.13. t_send_reply(code, reason)
425 4.14. t_lookup_request()
426 4.15. t_retransmit_reply()
427 4.16. t_release()
428 4.17. t_forward_nonack([ip, port])
429 4.18. t_forward_nonack_udp(ip, port)
430 4.19. t_forward_nonack_tcp(ip, port)
431 4.20. t_forward_nonack_tls(ip, port)
432 4.21. t_forward_nonack_sctp(ip, port)
433 4.22. t_set_fr(fr_inv_timeout [, fr_timeout])
434 4.23. t_reset_fr()
435 4.24. t_set_max_lifetime(inv_lifetime, noninv_lifetime)
436 4.25. t_reset_max_lifetime()
437 4.26. t_set_retr(retr_t1_interval, retr_t2_interval)
438 4.27. t_reset_retr()
439 4.28. t_set_auto_inv_100(0|1)
440 4.29. t_branch_timeout()
441 4.30. t_branch_replied()
442 4.31. t_any_timeout()
443 4.32. t_any_replied()
444 4.33. t_grep_status("code")
445 4.34. t_is_canceled()
446 4.35. t_is_expired()
447 4.36. t_relay_cancel()
448 4.37. t_lookup_cancel([1])
449 4.38. t_drop_replies([mode])
450 4.39. t_save_lumps()
451 4.40. t_load_contacts([mode])
452 4.41. t_next_contacts()
453 4.42. t_next_contact_flow()
454 4.43. t_check_status(re)
455 4.44. t_check_trans()
456 4.45. t_set_disable_6xx(0|1)
457 4.46. t_set_disable_failover(0|1)
458 4.47. t_set_disable_internal_reply(0|1)
459 4.48. t_set_no_auto_ack(0|1)
460 4.49. t_replicate([params])
461 4.50. t_relay_to(proxy, flags)
462 4.51. t_relay_to_proxy(proxy [, flags])
463 4.52. t_set_no_e2e_cancel_reason(0|1)
464 4.53. t_is_set(target)
465 4.54. t_use_uac_headers()
466 4.55. t_is_retr_async_reply()
467 4.56. t_uac_send(method, ruri, nexthop, socket, headers, body)
468 4.57. t_get_status_code()
469 4.58. t_clean()
470 4.59. t_exists()
471 4.60. t_cell_append_branches(tindex, tlabel)
472 4.61. t_msg_apply_changes()
473
474 5. RPC Commands
475
476 5.1. tm.list
477 5.2. tm.t_uac_start
478 5.3. tm.t_uac_start_hex
479 5.4. tm.t_uac_wait
480 5.5. tm.t_uac_wait_hex
481 5.6. tm.t_uac_wait_block
482 5.7. tm.t_uac_wait_block_hex
483 5.8. tm.t_uac_start_noack
484 5.9. tm.t_uac_start_noack_hex
485 5.10. tm.t_uac_wait_noack
486 5.11. tm.t_uac_wait_noack_hex
487 5.12. tm.t_uac_wait_block_noack
488 5.13. tm.t_uac_wait_block_noack_hex
489 5.14. tm.t_uac_attrs
490 5.15. tm.cancel
491 5.16. tm.hash_stats
492 5.17. tm.reply
493 5.18. tm.reply_callid
494 5.19. tm.retransmit_reply
495 5.20. tm.retransmit_reply_callid
496 5.21. tm.clean
497 5.22. tm.stats
498
499 6. Event Routes
500
501 6.1. event_route[tm:branch-failure:id]
502 6.2. event_route[tm:local-request]
503 6.3. event_route[tm:local-response]
504 6.4. event_route[tm:local-ack-sent]
505
506 7. TM Module API
507
508 7.1. Defines
509 7.2. Functions
510
511 7.2.1. register_tmcb(cb_type, cb_func)
512 7.2.2. load_tm(*import_structure)
513 7.2.3. int t_suspend(struct sip_msg *msg, unsigned int
514 *hash_index, unsigned int *label)
515
516 7.2.4. int t_continue(unsigned int hash_index, unsigned int
517 label, struct action *route)
518
519 7.2.5. int t_cancel_suspend(unsigned int hash_index,
520 unsigned int label)
521
522 8. Known Issues
523
524 1. Overview
525
526 The TM module enables stateful processing of SIP transactions. Stateful
527 logic is costly in terms of memory and CPU. The main use is services
528 that inherently need state. For example, transaction-based accounting
529 (module acc) needs to process transaction state as opposed to
530 individual messages. Any kind of forking must be implemented
531 transaction statefully. By using transaction states you trade CPU
532 caused by retransmission processing for memory. That only makes sense
533 if CPU consumption per request is huge. For example, if you want to
534 avoid costly DNS resolution for every retransmission of a request to an
535 unresolvable destination, use stateful mode. Then, only the initial
536 message burdens server by DNS queries, subsequent retransmissions will
537 be dropped and will not result in more processes blocked by DNS
538 resolution. The price is more memory consumption and higher processing
539 latency.
540
541 From the admin's perspective, these are the major functions : t_relay,
542 t_relay_to_udp and t_relay_to_tcp. All of them set up transaction
543 state, absorb retransmissions from upstream, generate downstream
544 retransmissions and correlate replies to requests. t_relay forwards to
545 current URI (be it original request's URI or a URI changed by some of
546 URI-modifying functions, such as sethost). t_relay_to_udp and
547 t_relay_to_tcp forward to a specific address over UDP or TCP
548 respectively.
549
550 In general, if TM is used, it copies clones of received SIP messages in
551 shared memory. That costs memory and also CPU time (memcpys, lookups,
552 shmem locks, etc.) Note that non-TM functions operate over the received
553 message in private memory, that means that any core operations will
554 have no effect on statefully processed messages after creating the
555 transactional state. For example, calling record_route after t_relay is
556 pretty useless, as the RR is added to privately held message whereas
557 its TM clone is being forwarded.
558
559 The TM module is quite big and uneasy to program --lots of mutexes,
560 shared memory access, malloc and free, timers--you really need to be
561 careful when you do anything. To simplify TM programming, there is the
562 instrument of callbacks. The callback mechanisms allow programmers to
563 register their functions to a specific event. See t_hooks.h for a list
564 of possible events.
565
566 Other things programmers may want to know is UAC--it is a very
567 simplistic code which allows you to generate your own transactions.
568 Particularly useful for things like NOTIFYs or IM gateways. The UAC
569 takes care of all the transaction machinery: retransmissions, FR
570 timeouts, forking, etc. See t_uac prototype in uac.h for more details.
571 If you want to see the transaction result the code can register for a
572 callback.
573
574 Note
575
576 Several Kamailio TM module functions are now implemented in the TMX
577 module. Check it to see if what you are looking for is there.
578
579 2. Serial Forking Based on Q Value
580
581 A single SIP INVITE request may be forked to multiple destinations. We
582 call the set of all such destinations a “destination set”. Individual
583 elements within the destination sets are called branches. The script
584 writer can add URIs to the destination set from the configuration file,
585 or they can be loaded from the user location database. Each registered
586 contact then becomes one branch in the destination set.
587
588 The default behavior of the TM module, if it encounters a SIP message
589 with multiple branches in the destination set, is to forward the SIP
590 message to all the branches in parallel. That means it sends the
591 message to all the branch destinations before it waits for replies from
592 any of them. This is the default behavior if you call t_relay() and
593 similar functions without any other arguments.
594
595 Another approach of handling multiple branches in a destination set is
596 serial forking. When configured to do serial forking, the server takes
597 the first branch out of the destination set, forwards the message to
598 its destination and waits for a reply or timeout. Only after a reply
599 has been received or a timeout occurred, the server takes another
600 destination from the destination set and tries again, until it receives
601 a positive final reply or until all branches from the destination set
602 have been tried.
603
604 Yet another, more sophisticated, way of handling multiple branches is
605 combined serial/parallel forking, where individual branches within the
606 destination set are assigned priorities. The order in which individual
607 branches are tried is then determined by their relative priority within
608 the destination set. Branches can be tried sequentially in the
609 descending priority order and all branches that have the same priority
610 can be tried in parallel. Such combined serial/parallel forking can be
611 achieved in the TM module with the help of functions t_load_contacts()
612 and t_next_contacts().
613
614 Every branch in the destination set is assigned a priority number, also
615 known as the “q value”. The q value is a floating point number in a
616 range 0 to 1.0. The higher the q value number, the more priority is
617 given to the particular branch in the destination set. Branches with q
618 value 1.0 have maximum priority, such branches should always be tried
619 first in serial forking. Branches with q value 0 have the lowest
620 priority and they should by tried after all other branches with higher
621 priority in the destination set.
622
623 As an example, consider the following simple configuration file. When
624 the server receives an INVITE, it creates four branches with usernames
625 A through D and then forwards the request using t_relay():
626 request_route {
627 seturi("sip:[email protected]");
628 append_branch("sip:[email protected]");
629 append_branch("sip:[email protected]");
630 append_branch("sip:[email protected]");
631
632 t_relay();
633 break;
634 }
635
636 With this configuration the server forwards the request to all four
637 branches at once, performing parallel forking as described above. We
638 did not set the q value for individual branches in this example but we
639 can do that by slightly modifying the arguments given to
640 append_branch():
641 request_route {
642 seturi("sip:[email protected]");
643 append_branch("sip:[email protected]", "0.5");
644 append_branch("sip:[email protected]", "0.5");
645 append_branch("sip:[email protected]", "1.0");
646
647 t_relay();
648 break;
649 }
650
651 Here we assigned q value 0.5 to branches B and C and q value 1.0 to
652 branch D. We did not specify any q value for branch A and in that case
653 it is assumed that its q value is the lowest from all branches within
654 the destination set. If you try to run this example again, you will
655 figure out that nothing changed, t_relay() still forward the message to
656 all branches in parallel.
657
658 We now want to implement the combined serial/parallel forking. Branch D
659 should be tried first, because its q value is 1.0. Branches B and C
660 should be tried in parallel, but only after D finishes. Branch A should
661 be tried after B and C finished, because its q value (the default) is
662 the lowest of all. To do that, we need to introduce two new functions
663 into our example and two tm module parameters:
664 modparam("tm", "contacts_avp", "tm_contacts");
665 modparam("tm", "contact_flows_avp", "tm_contact_flows");
666
667 request_route {
668 seturi("sip:[email protected]");
669 append_branch("sip:[email protected]", "0.5");
670 append_branch("sip:[email protected]", "0.5");
671 append_branch("sip:[email protected]", "1.0");
672
673 t_load_contacts();
674
675 t_next_contacts();
676 t_relay();
677 break;
678 }
679
680 First of all, the tm module parameters are mandatory if the two new
681 functions are used. Function t_load_contacts() takes all branches from
682 the destination set, sorts them according to their q values and stores
683 them in the AVP configured in the modparam. The function also clears
684 the destination set, which means that it removes all branches
685 configured before with seturi() and append_branch().
686
687 Function t_next_contacts() takes the AVP created by the previous
688 function and extracts the branches with highest q values from it. In
689 our example it is branch D. That branch is then put back into the
690 destination set and when the script finally reaches t_relay(), the
691 destination set only contains branch D and the request will be
692 forwarded there.
693
694 We achieved the first step of serial forking, but this is not
695 sufficient. Now we also need to forward to other branches with lower
696 priority values when branch D finishes. To do that, we need to extend
697 the configuration file again and introduce a failure_route section:
698 modparam("tm", "contacts_avp", "tm_contacts");
699
700 request_route {
701 seturi("sip:[email protected]");
702 append_branch("sip:[email protected]", "0.5");
703 append_branch("sip:[email protected]", "0.5");
704 append_branch("sip:[email protected]", "1.0");
705
706 t_load_contacts();
707
708 t_next_contacts();
709 t_on_failure("serial");
710 t_relay();
711 break;
712 }
713
714 failure_route["serial"]
715 {
716 if (!t_next_contacts()) {
717 exit;
718 }
719
720 t_on_failure("serial");
721 t_relay();
722 }
723
724 The failure_route section will be executed when branch D finishes. It
725 executes t_next_contacts() again and this time the function retrieves
726 branches B and C from the AVP and adds them to the destination set.
727 Here we need to check the return value of the function, because a
728 negative value indicates that there were no more branches, in that case
729 the failure_route should just terminate and forward the response from
730 branch D upstream.
731
732 If t_next_contact() returns a positive value then we have more new
733 branches to try and we need to set up the failure_route again and call
734 t_relay(). In our example the request will now be forwarded to branches
735 B and C in parallel, because they were both added to the destination
736 set by t_next_contacts() at the same time.
737
738 When branches B and C finish, the failure_route block is executed
739 again, this time t_next_contacts() puts the final branch A into the
740 destination set and t_relay() forwards the request there.
741
742 And that's the whole example, we achieved combined serial/parallel
743 forking based on the q value of individual branches. In real-world
744 configuration files the script writer would need to check the return
745 value of all functions and restart_fr_on_each_reply. The destination
746 set would not be configured directly in the configuration file, but can
747 be retrieved from the user location database. In that case registered
748 contacts will be stored in the destination set as branches and their q
749 values (provided by UAs) will be used.
750
751 3. Parameters
752
753 3.1. fr_timer (integer)
754 3.2. fr_inv_timer (integer)
755 3.3. max_inv_lifetime (integer)
756 3.4. max_noninv_lifetime (integer)
757 3.5. wt_timer (integer)
758 3.6. retr_timer1 (integer)
759 3.7. retr_timer2 (integer)
760 3.8. noisy_ctimer (integer)
761 3.9. restart_fr_on_each_reply (integer)
762 3.10. auto_inv_100 (integer)
763 3.11. auto_inv_100_reason (string)
764 3.12. unix_tx_timeout (integer)
765 3.13. aggregate_challenges (integer)
766 3.14. reparse_invite (integer)
767 3.15. ac_extra_hdrs (string)
768 3.16. blst_503 (integer)
769 3.17. blst_503_def_timeout (integer)
770 3.18. blst_503_min_timeout (integer)
771 3.19. blst_503_max_timeout (integer)
772 3.20. blst_methods_add (unsigned integer)
773 3.21. blst_methods_lookup (unsigned integer)
774 3.22. cancel_b_method (integer)
775 3.23. reparse_on_dns_failover (integer)
776 3.24. on_sl_reply (string)
777 3.25. contacts_avp (string)
778 3.26. contact_flows_avp (string)
779 3.27. fr_timer_avp (string)
780 3.28. fr_inv_timer_avp (string)
781 3.29. unmatched_cancel (integer)
782 3.30. ruri_matching (integer)
783 3.31. via1_matching (integer)
784 3.32. reply_matching (int)
785 3.33. callid_matching (integer)
786 3.34. callid_cseq_matching (int)
787 3.35. pass_provisional_replies (integer)
788 3.36. default_code (integer)
789 3.37. default_reason (string)
790 3.38. disable_6xx_block (integer)
791 3.39. local_ack_mode (integer)
792 3.40. local_ack_branch_mode (integer)
793 3.41. failure_reply_mode (integer)
794 3.42. faked_reply_prio (integer)
795 3.43. local_cancel_reason (boolean)
796 3.44. e2e_cancel_reason (boolean)
797 3.45. e2e_cancel_hop_by_hop (int)
798 3.46. headers_mode (int)
799 3.47. remap_503_500 (boolean)
800 3.48. failure_exec_mode (boolean)
801 3.49. dns_reuse_rcv_socket (boolean)
802 3.50. xavp_contact (string)
803 3.51. event_callback (str)
804 3.52. event_callback_lres_sent (str)
805 3.53. evcb_local_ack_sent (str)
806 3.54. relay_100 (str)
807 3.55. rich_redirect (int)
808 3.56. exec_time_check (int)
809 3.57. reply_relay_mode (int)
810 3.58. enable_uac_fr (int)
811 3.59. failover_reply_codes (string)
812 3.60. reply_408_code (int)
813 3.61. reply_408_reason (str)
814 3.62. delayed_reply (int)
815 3.63. evlreq_mode (int)
816
817 3.1. fr_timer (integer)
818
819 This timer is used for all SIP requests. It hits if no reply for an
820 request INVITE request or other request has been received within (F in
821 milliseconds). If a provisional reply is received for an INVITE (any
822 1xx), then the fr_inv_timer will be used instead. And if no replies (at
823 all) for an INVITE are received before fr_timer hits, the transaction
824 is terminated with a 408 in failure route.
825
826 Default value is 30000 ms (30 seconds).
827
828 See also: t_set_fr(), max_noninv_lifetime.
829
830 Example 1.1. Set fr_timer parameter
831 ...
832 modparam("tm", "fr_timer", 10000)
833 ...
834
835 3.2. fr_inv_timer (integer)
836
837 Timer which hits if no final reply for an INVITE arrives after a
838 provisional message was received (in milliseconds).
839
840 Note: This timer can be restarted when a provisional response is
841 received. For more details see restart_fr_on_each_reply.
842
843 Default value is 120000 ms (120 seconds).
844
845 See also: t_set_fr(), max_inv_lifetime.
846
847 Example 1.2. Set fr_inv_timer parameter
848 ...
849 modparam("tm", "fr_inv_timer", 180000)
850 ...
851
852 3.3. max_inv_lifetime (integer)
853
854 Maximum time an INVITE transaction is allowed to be active (in
855 milliseconds). After this interval has passed from the transaction
856 creation, the transaction will be either moved into the wait state or
857 in the final response retransmission state, irrespective of the
858 transaction fr_inv_timer and fr_timer values.
859
860 An INVITE transaction will be kept in memory for maximum:
861 max_inv_lifetime+fr_timer(from the ACK to the final reply
862 wait)+wt_timer.
863
864 The main difference between this timer and fr_inv_timer is that the
865 fr_inv_timer is per branch, while max_inv_lifetime is per the whole
866 transaction. Even on a per branch basis fr_inv_timer could be
867 restarted. For example, by default if restart_fr_on_each_reply is not
868 cleared, the fr_inv_timer will be restarted for each received
869 provisional reply. Even if restart_fr_on_each_reply is not set the
870 fr_inv_timer will still be restarted for each increasing reply (e.g.
871 180, 181, 182, ...). Another example when a transaction can live
872 substantially more than its fr_inv_timer and where max_inv_lifetime
873 will help is when DNS failover is used (each failed DNS destination can
874 introduce a new branch).
875
876 The default value is 180000 ms (180 seconds - the rfc3261 timer C
877 value).
878
879 See also: max_noninv_lifetime, t_set_max_lifetime() (allows changing
880 max_inv_lifetime on a per transaction basis), t_reset_max_lifetime
881 fr_timer, wt_timer, restart_fr_on_each_reply.
882
883 Example 1.3. Set max_inv_lifetime parameter
884 ...
885 modparam("tm", "max_inv_lifetime", 150000)
886 ...
887
888 3.4. max_noninv_lifetime (integer)
889
890 Maximum time a non-INVITE transaction is allowed to be active (in
891 milliseconds). After this interval has passed from the transaction
892 creation, the transaction will be either moved into the wait state or
893 in the final response retransmission state, irrespective of the
894 transaction fr_timer value. It's the same as max_inv_lifetime, but for
895 non-INVITEs.
896
897 A non-INVITE transaction will be kept in memory for a maximum of:
898 max_noninv_lifetime+wt_timer.
899
900 The main difference between this timer and fr_timer is that the
901 fr_timer is per branch, while max_noninv_lifetime is per the whole
902 transaction. An example when a transaction can live substantially more
903 than its fr_timer and where max_noninv_lifetime will help is when DNS
904 failover is used (each failed DNS SRV destination can introduce a new
905 branch).
906
907 The default value is 32000 ms (32 seconds - the RFC3261 timer F value).
908
909 See also: max_inv_lifetime, t_set_max_lifetime() (allows changing
910 max_noninv_lifetime on a per transaction basis), t_reset_max_lifetime
911 fr_timer, wt_timer.
912
913 Example 1.4. Set max_noninv_lifetime parameter
914 ...
915 modparam("tm", "max_noninv_lifetime", 30000)
916 ...
917
918 3.5. wt_timer (integer)
919
920 Time for which a transaction stays in memory to absorb delayed messages
921 after it completed (in milliseconds); also, when this timer hits,
922 retransmission of local CANCEL requests is stopped (a puristic but
923 complex behavior would be not to enter wait state until local branches
924 are finished by a final reply or FR timer--we simplified).
925
926 Default value is 5000 ms (5 seconds).
927
928 Example 1.5. Set wt_timer parameter
929 ...
930 modparam("tm", "wt_timer", 1000)
931 ...
932
933 3.6. retr_timer1 (integer)
934
935 Initial retransmission period (in milliseconds).
936
937 Default value is 500 milliseconds.
938
939 Example 1.6. Set retr_timer1 parameter
940 ...
941 modparam("tm", "retr_timer1", 1000)
942 ...
943
944 3.7. retr_timer2 (integer)
945
946 Maximum retransmission period (in milliseconds). The retransmission
947 interval starts with retr_timer1 and increases until it reaches this
948 value. After this it stays constant at retr_timer2.
949
950 Default value is 4000 milliseconds.
951
952 Example 1.7. Set retr_timer2 parameter
953 ...
954 modparam("tm", "retr_timer2", 2000)
955 ...
956
957 3.8. noisy_ctimer (integer)
958
959 If set, INVITE transactions that time-out (FR INV timer) will be always
960 replied. If it's not set, the transaction has only one branch and no
961 response was ever received on this branch, it will be silently dropped
962 (no 408 reply will be generated) This behavior is overridden if a
963 request is forked, the transaction has a failure route or callback, or
964 some functionality explicitly turned it on for a transaction (like the
965 ACC module does to avoid unaccounted transactions due to expired
966 timer). Turn this off only if you know the client UACs will timeout and
967 their timeout interval for INVITEs is lower or equal than tm's
968 fr_inv_timer.
969
970 Default value is 1 (on).
971
972 Example 1.8. Set noisy_ctimer parameter
973 ...
974 modparam("tm", "noisy_ctimer", 1)
975 ...
976
977 3.9. restart_fr_on_each_reply (integer)
978
979 If set (default), the fr_inv_timer for an INVITE transaction will be
980 restarted for each provisional reply received (rfc3261 mandated
981 behaviour). If not set, the fr_inv_timer will be restarted only for the
982 first provisional replies and for increasing replies greater or equal
983 180 (e.g. 180, 181, 182, 185, ...).
984
985 Setting it to 0 is especially useful when dealing with bad UAs that
986 continuously retransmit 180s, not allowing the transaction to timeout
987 (and thus making impossible the implementation of certain services,
988 like automatic voicemail after x seconds).
989
990 Default value is 1 (on).
991
992 See also: fr_inv_timer, max_inv_lifetime.
993
994 Example 1.9. Set restart_fr_on_each_reply parameter
995 ...
996 modparam("tm", "restart_fr_on_each_reply", 0)
997 ...
998
999 3.10. auto_inv_100 (integer)
1000
1001 If set (default) tm will automatically send a 100 reply to INVITEs.
1002
1003 Setting it to 0 can be used to enable first running some tests or
1004 pre-processing on the INVITE and only if some conditions are met
1005 manually send a 100 (using t_reply()). Note however that in this case
1006 all the 100s have to be sent "by hand". t_set_auto_inv_100() might help
1007 to selectively turn off this feature only for some specific
1008 transactions.
1009
1010 Default value is 1 (on).
1011
1012 See also: t_set_auto_inv_100() auto_inv_100_reason.
1013
1014 Example 1.10. Set auto_inv_100 parameter
1015 ...
1016 modparam("tm", "auto_inv_100", 0)
1017 ...
1018
1019 3.11. auto_inv_100_reason (string)
1020
1021 Set reason text of the automatically sent 100 to an INVITE.
1022
1023 Default value is "trying -- your call is important to us".
1024
1025 See also: auto_inv_100.
1026
1027 Example 1.11. Set auto_inv_100_reason parameter
1028 ...
1029 modparam("tm", "auto_inv_100_reason", "Trying")
1030 ...
1031
1032 3.12. unix_tx_timeout (integer)
1033
1034 Unix socket transmission timeout, in milliseconds.
1035
1036 If UNIX sockets are used (e.g.: to communicate with sems) and sending a
1037 message on a UNIX socket takes longer than unix_tx_timeout, the send
1038 will fail.
1039
1040 The default value is 500 milliseconds.
1041
1042 Example 1.12. Set unix_tx_timeout parameter
1043 ...
1044 modparam("tm", "unix_tx_timeout", 250)
1045 ...
1046
1047 3.13. aggregate_challenges (integer)
1048
1049 If set (default), the final response is a 401 or a 407 and more than
1050 one branch received a 401 or 407, then all the WWW-Authenticate and
1051 Proxy-Authenticate headers from all the 401 and 407 replies will be
1052 aggregated in a new final response. If only one branch received the
1053 winning 401 or 407 then this reply will be forwarded (no new one will
1054 be built).
1055
1056 If disabled (set to 0) only the first 401, or if no 401 was received
1057 the first 407, will be forwarded (no header aggregation).
1058
1059 Default value is 1 (required by RFC 3261).
1060
1061 Example 1.13. Set aggregate_challenges parameter
1062 ...
1063 modparam("tm", "aggregate_challenges", 0)
1064 ...
1065
1066 3.14. reparse_invite (integer)
1067
1068 If set (default), the CANCEL and negative ACK requests are constructed
1069 from the INVITE message which was sent out instead of building them
1070 from the received request. The disadvantage is that the outgoing INVITE
1071 has to be partially re-parsed, the advantage is that the CANCEL/ACK is
1072 always RFC 3261-compliant, it always contains the same route-set as the
1073 INVITE message. Do not disable the INVITE re-parsing for example in the
1074 following cases:
1075
1076 - The INVITE contains a preloaded route-set, and Kamailio forwards the
1077 message to the next hop according to the "Route" header. The "Route"
1078 header is not removed in the CANCEL without reparse_invite=1.
1079
1080 - Kamailio record-routes, thus an in-dialog INVITE contains a "Route"
1081 header which is removed during loose routing. If the in-dialog INVITE
1082 is rejected, the negative ACK still contains the "Route" header without
1083 reparse_invite=1.
1084
1085 Default value is 1.
1086
1087 Example 1.14. Set reparse_invite parameter
1088 ...
1089 modparam("tm", "reparse_invite", 0)
1090 ...
1091
1092 3.15. ac_extra_hdrs (string)
1093
1094 Header fields prefixed by this parameter value are included in the
1095 CANCEL and negative ACK messages if they were present in the outgoing
1096 INVITE.
1097
1098 Note, that the parameter value effects only those headers which are not
1099 covered by RFC 3261 (which are neither mandatory nor prohibited in
1100 CANCEL and ACK), and the parameter can be used only together with
1101 reparse_invite=1.
1102
1103 Default value is "".
1104
1105 Example 1.15. Set ac_extra_hdrs parameter
1106 ...
1107 modparam("tm", "ac_extra_hdrs", "myfavoriteheaders-")
1108 ...
1109
1110 3.16. blst_503 (integer)
1111
1112 If set and the Kamailio blocklist support is enabled, every 503 reply
1113 source is added to the blocklist. The initial blocklist timeout (or
1114 ttl) depends on the presence of a "Retry-After" header in the reply and
1115 the values of the following tm parameters: blst_503_def_timeout,
1116 blst_503_min_timeout and blst_503_max_timeout.
1117
1118 WARNING:blindly allowing 503 blocklisting could be very easily
1119 exploited for DOS attacks in most network setups.
1120
1121 The default value is 0 (disabled due to the reasons above).
1122
1123 Example 1.16. Set blst_503 parameter
1124 ...
1125 modparam("tm", "blst_503", 1)
1126 ...
1127
1128 3.17. blst_503_def_timeout (integer)
1129
1130 Blocklist interval in seconds for a 503 reply with no "Retry-After"
1131 header. See also blst_503, blst_503_min_timeout and
1132 blst_503_max_timeout.
1133
1134 The default value is 0, which means that if no "Retry-After" header is
1135 present, the 503 reply source will not be blocklisted (RFC 3261
1136 conformant behaviour).
1137
1138 Example 1.17. Set blst_503_def_timeout parameter
1139 ...
1140 modparam("tm", "blst_503_def_timeout", 120)
1141 ...
1142
1143 3.18. blst_503_min_timeout (integer)
1144
1145 Minimum blocklist interval in seconds for a 503 reply with a
1146 "Retry-After" header. It will be used if the "Retry-After" value is
1147 smaller than this value.
1148
1149 See also blst_503, blst_503_def_timeout and blst_503_max_timeout.
1150
1151 The default value is 0
1152
1153 Example 1.18. Set blst_503_min_timeout parameter
1154 ...
1155 modparam("tm", "blst_503_min_timeout", 30)
1156 ...
1157
1158 3.19. blst_503_max_timeout (integer)
1159
1160 Maximum blocklist interval in seconds for a 503 reply with a
1161 "Retry-After header". It will be used if the "Retry-After" value is
1162 greater than this limit.
1163
1164 See also blst_503, blst_503_def_timeout and blst_503_min_timeout.
1165
1166 The default value is 3600
1167
1168 Example 1.19. Set blst_503_max_timeout parameter
1169 ...
1170 modparam("tm", "blst_503_max_timeout", 604800)
1171 ...
1172
1173 3.20. blst_methods_add (unsigned integer)
1174
1175 Bitmap of method types that trigger blocklisting on transaction
1176 timeouts. (This setting has no effect on blocklisting because of send
1177 failures.)
1178
1179 The following values are associated to the request methods: INVITE=1,
1180 CANCEL=2, ACK=4 (not retransmitted, thus, never times-out), BYE=8,
1181 INFO=16, REGISTER=32, SUBSCRIBE=64, NOTIFY=126, OTHER=256 (all the
1182 unknown types). Check parser/msg_parser.h for farther details.
1183
1184 Change the value carefully, because requests that don't get a
1185 provisional response (everything but INVITE) can easily cause the next
1186 hop to be inserted into the blocklist by mistake. For example the next
1187 hop is a proxy, it is alive, but waiting for the response of the UAS,
1188 and has higher fr_timer value.
1189
1190 The default value is 1, only INVITEs trigger blocklisting
1191
1192 Example 1.20. Set blst_methods_add parameter
1193 ...
1194 # INVITEs and REGISTERs trigger blocklisting
1195 modparam("tm", "blst_methods_add", 33)
1196 ...
1197
1198 3.21. blst_methods_lookup (unsigned integer)
1199
1200 Bitmap of method types that are looked-up in the blocklist before being
1201 forwarded statefully. See also blst_methods_add
1202
1203 The default value is 4294967287, every method type except BYE. (We try
1204 to deliver BYEs no matter what)
1205
1206 Example 1.21. Set blst_methods_lookup parameter
1207 ...
1208 # lookup only INVITEs
1209 modparam("tm", "blst_methods_lookup", 1)
1210 ...
1211
1212 3.22. cancel_b_method (integer)
1213
1214 Method used when attempting to CANCEL an unreplied transaction branch
1215 (a branch where no response was received). The possible values are 0,
1216 1, and 2.
1217
1218 - 0 will immediately stop the request (INVITE) retransmission on the
1219 branch and it will behave as if the branch was immediately replied with
1220 a 487 (a fake internal 487 reply). The advantage is the unreplied
1221 branches will be terminated immediately. However it introduces a race
1222 risk with a possible slightly delayed 2xx reply. In this case we could
1223 have an UA receiving a 2xx after a 487. Moreover this risk is greatly
1224 amplified by packet loss (e.g. if an 180 is lost the branch will look
1225 as unreplied and a CANCEL will silently drop the branch, but a 2xx can
1226 still come at a later time). This is the behaviour for SER versions
1227 older than 2.1.
1228
1229 - 1 will keep retransmitting the request on unreplied branches. If a
1230 provisional answer is received a CANCEL will be immediately sent back
1231 (attempting to quickly trigger a 487). This approach is race free and
1232 avoids the 2xx after 487 problem, but it's more resource intensive:
1233 faced with a branch towards and UA that doesn't answer, a CANCEL
1234 attempt will keep the transaction alive for the whole timeout interval
1235 (fr_timer).
1236
1237 - 2 will send and retransmit CANCEL even on unreplied branches,
1238 stopping the request retransmissions. This has the same advantages as 1
1239 and also avoids the extra roundtrip in the case of the provisional
1240 reply, but it's not RFC 3261 conforming (the RFC allows sending CANCELs
1241 only on pending branches).
1242
1243 The default value is 1.
1244
1245 Example 1.22. Set cancel_b_method parameter
1246 ...
1247 modparam("tm", "cancel_b_method", 1)
1248 ...
1249
1250 3.23. reparse_on_dns_failover (integer)
1251
1252 If set to 1, the SIP message after a DNS failover is constructed from
1253 the outgoing message buffer of the failed branch instead of from the
1254 received request.
1255
1256 It must be set if multiple branches are installed, the SIP message is
1257 modified differently in them, and at least one of them can result in
1258 DNS failover. If the parameter is not set the per-branch modifications
1259 are lost after the failover.
1260
1261 Note: If the parameter is set, branch route block and
1262 TMCB_REQUEST_FWDED callback are not called in case of the failover.
1263
1264 Disadvantage: only the via header is replaced in the message buffer, so
1265 the outgoing socket address is not corrected in any other part of the
1266 message. It is dangerous on multihomed hosts: when the new SIP request
1267 after the DNS failover is sent via different interface than the first
1268 request, the message can contain incorrect IP address in the
1269 Record-Route header.
1270
1271 Default value is 1.
1272
1273 Example 1.23. Set reparse_on_dns_failover parameter
1274 ...
1275 modparam("tm", "reparse_on_dns_failover", 0)
1276 ...
1277
1278 3.24. on_sl_reply (string)
1279
1280 Sets reply route block, to which control is passed when a reply is
1281 received that has no associated transaction. The reply is passed to the
1282 core for stateless forwarding after the route block execution unless
1283 drop is executed (or it returns 0).
1284
1285 If KEMI is used, the parameter has to be the KEMI function name, which
1286 receives a string parameter with the event name, respectively
1287 "on_sl_reply".
1288
1289 Example 1.24. Set on_sl_reply parameter
1290 ...
1291 modparam("tm", "on_sl_reply", "stateless_replies")
1292 ...
1293
1294 onreply_route["stateless_replies"] {
1295 # do not allow stateless replies to be forwarded
1296 return 0;
1297 }
1298
1299 Example 1.25. Set on_sl_reply parameter (KEMI javascript)
1300 ...
1301 modparam("tm", "on_sl_reply", "ksr_slreply")
1302 ...
1303 -- event callback function implemented in javascript
1304 function ksr_slreply(evname) {
1305 # the evname is set to "on_sl_reply"
1306 # do not allow stateless replies to be forwarded
1307 KSR.x.drop();
1308 }
1309
1310 3.25. contacts_avp (string)
1311
1312 This is the name of an XAVP that the t_load_contacts() function uses to
1313 store contacts of the destination set and that t_next_contacts()
1314 function uses to restore those contacts.
1315
1316 Default value is "NULL" (t_load_contacts()/t_next_contacts() functions
1317 are disabled).
1318
1319 Example 1.26. Set contacts_avp parameter
1320 ...
1321 modparam("tm", "contacts_avp", "tm_contacts")
1322 ...
1323
1324 3.26. contact_flows_avp (string)
1325
1326 This is the name of an XAVP that the t_next_contacts() function uses to
1327 store contacts (if any) that it skipped, because they contained same
1328 +sip.instance value than some other contact, and that
1329 t_next_contact_flows() function uses to restore those contacts.
1330
1331 Default value is "NULL". This parameter MUST be set if variable
1332 contacts_avp is set.
1333
1334 Example 1.27. Set contact_flows_avp parameter
1335 ...
1336 modparam("tm", "contact_flows_avp", "tm_contact_flows")
1337 ...
1338
1339 3.27. fr_timer_avp (string)
1340
1341 The value of fr_timer timer can be overridden on per-transaction basis.
1342 The administrator can provide a value to be used for a particular
1343 transaction in an AVP. This parameter contains the name of the AVP that
1344 will be checked. If the AVP exists then its value will be used for the
1345 fr_timer timer, effectively overriding the value configured in fr_timer
1346 parameter for the current transaction.
1347
1348 Note
1349
1350 The value of the AVP is expected to be expressed in seconds and not
1351 milliseconds (unlike the rest of the timers).
1352
1353 This parameter is kept for backwards compatibility (hence its value
1354 expressed in seconds instead of milliseconds and its arcane way of
1355 specifying the avps). The recommended replacement is using t_set_fr()
1356 on a per transaction basis.
1357
1358 See also: t_set_fr(), fr_timer.
1359
1360 In Kamailio compatibility mode (defined by #!KAMAILIO, which is
1361 default), the value of the parameter must be the name of an AVP in
1362 pseudo-variable format: $avp(name). In SER compatibility mode (defined
1363 by #!SER) it must be just AVP name.
1364
1365 Example 1.28. Set fr_timer_avp parameter
1366 ...
1367 # default Kamailio compatibility mode
1368 modparam("tm", "fr_timer_avp", "$avp(frtimer)")
1369 # old SER compatibility mode
1370 modparam("tm", "fr_timer_avp", "frtimer")
1371 ...
1372
1373 3.28. fr_inv_timer_avp (string)
1374
1375 The value of fr_inv_timer timer can be overridden on per-transaction
1376 basis. The administrator can provide a value to be used for a
1377 particular transaction in an AVP. This parameter contains the name of
1378 the AVP that will be checked. If the AVP exists, is non-empty and
1379 non-zero then its value will be used for the fr_inv_timer timer,
1380 effectively overriding the value configured in fr_inv_timer parameter
1381 for the current transaction.
1382
1383 Note
1384
1385 The value of the AVP is expected to be expressed in seconds and not
1386 milliseconds (unlike the rest of the timers).
1387
1388 This parameter is kept for backwards compatibility (hence its value
1389 expressed in seconds instead of milliseconds and its arcane way of
1390 specifying the avps). The recommended replacement is using t_set_fr()
1391 on a per transaction basis.
1392
1393 See also: t_set_fr(), fr_inv_timer.
1394
1395 In Kamailio compatibility mode (defined by #!KAMAILIO, which is
1396 default), the value of the parameter must be the name of an AVP in
1397 pseudo-variable format: $avp(name). In SER compatibility mode (defined
1398 by #!SER) it must by just AVP name.
1399
1400 Example 1.29. Set fr_inv_timer_avp parameter
1401 ...
1402 # Kamailio compatibility mode
1403 modparam("tm", "fr_inv_timer_avp", "$avp(my_fr_inv_timer)")
1404 # old SER compatibility mode
1405 modparam("tm", "fr_inv_timer_avp", "my_fr_inv_timer")
1406 ...
1407
1408 3.29. unmatched_cancel (integer)
1409
1410 This parameter selects between forwarding CANCELs that do not match any
1411 transaction statefully (0, default value), statelessly (1) or dropping
1412 them (2). Note that the stateful forwarding has an additional hidden
1413 advantage: the tm module will be able to recognize INVITEs that arrive
1414 after their CANCEL. Note also that this feature could be used to try a
1415 memory exhaustion DOS attack against a proxy that authenticates all
1416 requests, by continuously flooding the victim with CANCELs to random
1417 destinations (since the CANCEL cannot be authenticated, each received
1418 bogus CANCEL will create a new transaction that will live by default
1419 30s).
1420
1421 Default value is 0.
1422
1423 Example 1.30. Set unmatched_cancel parameter
1424 ...
1425 modparam("tm", "unmatched_cancel", 2)
1426 ...
1427
1428 3.30. ruri_matching (integer)
1429
1430 If set the TM module will try to match the request URI when doing SIP
1431 1.0 (pre-RFC 3261) transaction matching (the "Via" header branch
1432 parameter does not contain the 3261 cookie).
1433
1434 The only reason to have it not set is for interoperability with old,
1435 broken implementations.
1436
1437 Default value is 1 (on).
1438
1439 Can be set at runtime, e.g.:
1440 $ kamcmd cfg.set_now_int tm ruri_matching 0
1441
1442 Example 1.31. Set ruri_matching parameter
1443 ...
1444 modparam("tm", "ruri_matching", 1)
1445 ...
1446
1447 3.31. via1_matching (integer)
1448
1449 If set the TM module will try to match the topmost "Via" header when
1450 doing SIP 1.0 (pre-RFC 3261) transaction matching (the "Via" header
1451 branch parameter does not contain the 3261 cookie).
1452
1453 The only reason to have it not set is for interoperability with old,
1454 broken implementations.
1455
1456 Default value is 1 (on).
1457
1458 Can be set at runtime, e.g.:
1459 $ kamcmd cfg.set_now_int tm via1_matching 0
1460
1461 Example 1.32. Set via1_matching parameter
1462 ...
1463 modparam("tm", "via1_matching", 1)
1464 ...
1465
1466 3.32. reply_matching (int)
1467
1468 If set to 1, the tm module will match SIP replies only for active
1469 transactions, skipping when transaction is put on wait or in agony (the
1470 states to destroy the transaction).
1471
1472 Default value is 1 .
1473
1474 Example 1.33. Set reply_matching parameter
1475 ...
1476 modparam("tm", "reply_matching", 0)
1477 ...
1478
1479 3.33. callid_matching (integer)
1480
1481 If set the TM module will try to match the callid when doing
1482 transaction matching.
1483
1484 Turn on if you don't want replies/requests from broken clients who send
1485 a mangled Call-ID to match the transaction. For example when the other
1486 side won't recognise the response anyway because of a changed Call-ID,
1487 this setting will prevent accounting records to be created or
1488 failure_route to be skipped.
1489
1490 Default value is 0 (off).
1491
1492 Can be set at runtime, e.g.:
1493 $ kamcmd cfg.set_now_int tm callid_matching 0
1494
1495 Example 1.34. Set callid_matching parameter
1496 ...
1497 modparam("tm", "callid_matching", 1)
1498 ...
1499
1500 3.34. callid_cseq_matching (int)
1501
1502 If set to something other than 0, will do transaction matching using
1503 callid and cseq header values instead of via branch md5 value. Note
1504 that this behavior is non-RFC conpliant!
1505
1506 Default value is 0.
1507
1508 Example 1.35. Set callid_cseq_matching parameter
1509 ...
1510 modparam("tm", "callid_cseq_matching", 0)
1511 ...
1512
1513 kamctl rpc cfg.set_now_int tm callid_cseq_matching 1
1514
1515 3.35. pass_provisional_replies (integer)
1516
1517 If set, TMCB_LOCAL_RESPONSE_OUT tm registered callbacks will be called
1518 also for provisional replies.
1519
1520 Default value is 0 (off).
1521
1522 Can be set at runtime, e.g.:
1523 $ kamcmd cfg.set_now_int tm pass_provisional_replies 1
1524
1525 Example 1.36. Set pass_provisional_replies parameter
1526 ...
1527 modparam("tm", "pass_provisional_replies", 1)
1528 ...
1529
1530 3.36. default_code (integer)
1531
1532 Default response code sent by t_reply() if it cannot retrieve its
1533 parameters (e.g. inexistent avp). Valid values are between 400 and 699.
1534
1535 Default value is 500.
1536
1537 Can be set at runtime, e.g.:
1538 $ kamcmd cfg.set_now_int tm default_code 505
1539
1540 Example 1.37. Set default_code parameter
1541 ...
1542 modparam("tm", "default_code", 501)
1543 ...
1544
1545 3.37. default_reason (string)
1546
1547 Default SIP reason phrase sent by t_reply() if it cannot retrieve its
1548 parameters (e.g. inexistent avp).
1549
1550 Default value is "Server Internal Error".
1551
1552 Can be set at runtime, e.g.:
1553 $ kamcmd cfg.set_now_string tm default_reason "Unknown error"
1554
1555 Example 1.38. Set default_reason parameter
1556 ...
1557 modparam("tm", "default_reason", "Unknown reason")
1558 ...
1559
1560 3.38. disable_6xx_block (integer)
1561
1562 If set the TM module will treat all the 6xx replies like normal replies
1563 (warning: this would be non-RFC conformant behaviour).
1564
1565 If not set (default) receiving a 6xx will cancel all the running
1566 parallel branches, will stop DNS failover and forking. However serial
1567 forking using append_branch() in the failure_route will still work.
1568
1569 It can be overwritten on a per transaction basis using
1570 t_set_disable_6xx().
1571
1572 Default value is 0 (off, rfc conformant behaviour).
1573
1574 Can be set at runtime, e.g.:
1575 $ kamcmd cfg.set_now_int tm disable_6xx_block 0
1576
1577 See also: t_set_disable_6xx().
1578
1579 Example 1.39. Set disable_6xx_block parameter
1580 ...
1581 modparam("tm", "disable_6xx_block", 1)
1582 ...
1583
1584 3.39. local_ack_mode (integer)
1585
1586 This setting controls where locally generated ACKs for 2xx replies to
1587 local transactions (transactions created via t_uac*() either through
1588 the TM api or via RPC/mi/fifo) are sent.
1589
1590 It has 3 possible values:
1591 * 0 - the ACK destination is choosen according to the RFC: the next
1592 hop is found using the contact and the route set and then DNS
1593 resolution is used on it.
1594 * 1 - the ACK is sent to the same address as the corresponding INVITE
1595 branch.
1596 * 2 - the ACK is sent to the source of the 2xx reply.
1597
1598 Note
1599
1600 Modes 1 and 2 do not follow RFC 3261, but are useful to deal with some
1601 simple UAs behind a NAT (no different routing for the ACK and the
1602 contact contains an address behind the NAT).
1603
1604 The default value is 0 (RFC conformant behaviour).
1605
1606 Can be set at runtime, e.g.:
1607 $ kamcmd cfg.set_now_int tm local_ack_mode 0
1608
1609 Example 1.40. Set local_ack_mode parameter
1610 ...
1611 modparam("tm", "local_ack_mode", 1)
1612 ...
1613
1614 3.40. local_ack_branch_mode (integer)
1615
1616 If set to 1, the Via branch value of the ACK for 200ok of a local
1617 INVITE has a slightly different value than the corresponding local
1618 INVITE. If set to 2, a new Via branch is attempted to be created.
1619
1620 Default 0.
1621
1622 Example 1.41. Set local_ack_branch_mode parameter
1623 ...
1624 modparam("tm", "local_ack_branch_mode", 1)
1625 ...
1626
1627 3.41. failure_reply_mode (integer)
1628
1629 This parameter controls how branches are managed and replies are
1630 selected for failure_route handling: keep all, drop all, drop last
1631 branches in SIP serial forking handling.
1632
1633 To control per transaction see t_drop_replies().
1634
1635 It has 4 possible values:
1636 * 0 - all branches are kept, no matter a new leg of serial forking
1637 has been started. Beware that if the new leg fails, you may get in
1638 failure_route a reply code from a branch of previous serial forking
1639 legs (e.g., if in first leg you got a 3xx, then you handled the
1640 redirection in failure route, sent to a new destination and this
1641 one timeout, you will get again the 3xx). Use t_drop_replies() on
1642 per transaction fashion to control the behavior you want. It is the
1643 default behaviour coming from SER 2.1.x.
1644 * 1 - all branches are discarded by default. You can still overwrite
1645 the behaviour via t_drop_replies()
1646 * 2 - by default only the branches of previous leg of serial forking
1647 are discarded
1648 * 3 - all previous branches are discarded if there is a new serial
1649 forking leg. This is the default behaviour coming from Kamailio
1650 1.5.x. Use this mode if you don't want to handle in a per
1651 transaction fashion with t_drop_replies(). It ensures that you will
1652 get the winning reply from the branches of last serial forking step
1653 (e.g., if in first step you get 3xx, then you forward to a new
1654 destination, you will get in failure_route the reply coming from
1655 that destination or a local timeout).
1656
1657 The default value is 3.
1658
1659 Example 1.42. Set failure_reply_mode parameter
1660 ...
1661 modparam("tm", "failure_reply_mode", 0)
1662 ...
1663
1664 3.42. faked_reply_prio (integer)
1665
1666 It controls how branch selection is done. It allows to give a penalty
1667 to faked replies such as the infamous 408 on branch timeout.
1668
1669 Internally, every reply is assigned a priority between 0 (high prio)
1670 and 32000 (low prio). With this parameter the priority of fake replies
1671 can be adjusted.
1672 * 0 - disabled (default)
1673 * < 0 - priority is increased by given amount.
1674 * > 0 - priority is decreased by given amount. Do not make it higher
1675 than 10000 or faked replies will even loose from 1xx class replies.
1676
1677 The default value is 0.
1678
1679 To let received replies win from a locally generated 408, set this
1680 value to 2000.
1681
1682 Example 1.43. Set faked_reply_prio parameter
1683 ...
1684 modparam("tm", "faked_reply_prio", 2000)
1685 ...
1686
1687 3.43. local_cancel_reason (boolean)
1688
1689 Enables/disables adding reason headers (RFC 3326) for CANCELs generated
1690 due to receiving a final reply. The reason header added will look like:
1691 "Reason: SIP;cause=<final_reply_code>".
1692
1693 Default value is 1 (enabled).
1694
1695 Can be set at runtime, e.g.:
1696 $ kamcmd cfg.set_now_int tm local_cancel_reason 0
1697
1698 See also: e2e_cancel_reason.
1699
1700 Example 1.44. Set local_cancel_reason parameter
1701 ...
1702 modparam("tm", "local_cancel_reason", 0)
1703 ...
1704
1705 3.44. e2e_cancel_reason (boolean)
1706
1707 Enables/disables adding reason headers (RFC 3326) for CANCELs generated
1708 due to a received CANCEL. If enabled the reason headers from received
1709 CANCELs will be copied into the generated hop-by-hop CANCELs.
1710
1711 Default value is 1 (enabled).
1712
1713 Can be changed at runtime, e.g.:
1714 $ kamcmd cfg.set_now_int tm e2e_cancel_reason 0
1715
1716 See also: t_set_no_e2e_cancel_reason() and local_cancel_reason.
1717
1718 Example 1.45. Set e2e_cancel_reason parameter
1719 ...
1720 modparam("tm", "e2e_cancel_reason", 0)
1721 ...
1722
1723 3.45. e2e_cancel_hop_by_hop (int)
1724
1725 Enable/disable sending CANCEL in hop-by-hop mode.
1726
1727 Default value: 1 (hop-by-hop mode).
1728
1729 Example 1.46. Set e2e_cancel_hop_by_hop parameter
1730 ...
1731 modparam("tm", "e2e_cancel_hop_by_hop", 0)
1732 ...
1733
1734 3.46. headers_mode (int)
1735
1736 Control how headers from incoming CANCEL should be propagated to
1737 hop-by-hop generated CANCEL. If bit (flag) 1 is set (value 1),
1738 propagate the headers that are not branch specific (e.g., From, To). If
1739 bit (flag) 2 is set, in case processing ends in stateless forwarding by
1740 tm, forward CANCEL with a single Via header (the one added by
1741 Kamailio).
1742
1743 Default value: 0 (do not propagate).
1744
1745 Example 1.47. Set headers_mode parameter
1746 ...
1747 modparam("tm", "headers_mode", 1)
1748 ...
1749
1750 3.47. remap_503_500 (boolean)
1751
1752 Enables/disables conversion of 503 response code to 500. By default it
1753 is enabled, based on the SIP RFC requirement. This is global setting
1754 for all received replies handled by TM. To do it per transaction basis,
1755 let this option disabled, set a failure route and then do
1756 t_reply("500", "...") inside it.
1757
1758 Default value is 1 (enabled).
1759
1760 Example 1.48. Set remap_503_500 parameter
1761 ...
1762 modparam("tm", "remap_503_500", 0)
1763 ...
1764
1765 3.48. failure_exec_mode (boolean)
1766
1767 Add local failed branches in timer to be considered for failure routing
1768 blocks. If disabled, relay functions will return false in case the
1769 branch could not be forwarded (default behaviour before v4.1.0).
1770
1771 Default value is 0 (disabled).
1772
1773 Example 1.49. Set failure_exec_mode parameter
1774 ...
1775 modparam("tm", "failure_exec_mode", 1)
1776 ...
1777
1778 3.49. dns_reuse_rcv_socket (boolean)
1779
1780 Control reuse of the receive socket for additional branches added by
1781 DNS failover. If set to 1, the receive socket is used for sending out
1782 the new branches, unless the socket is forced explicitely in
1783 configuration file. If set to 0, selected socket is done depending on
1784 value of global parameter "mhomed" (if mhomed=0, then the first listen
1785 socket is used, otherwise the socket is selected based on routing
1786 rules).
1787
1788 Do enable it with caution, it might create troubles on DNS results with
1789 different transport layer. Better let it be disabled and enable
1790 "mhomed".
1791
1792 Default value is 0 (disabled).
1793
1794 Example 1.50. Set dns_reuse_rcv_socket parameter
1795 ...
1796 modparam("tm", "dns_reuse_rcv_socket", 1)
1797 ...
1798
1799 3.50. xavp_contact (string)
1800
1801 The name of XAVP storing the attributes per contact. This must be the
1802 same as the usrloc parameter xavp_contact.
1803
1804 Default value is “NULL”.
1805
1806 Example 1.51. Set xavp_contact parameter
1807 ...
1808 modparam("tm|usrloc", "xavp_contact", "ulattrs")
1809 ...
1810
1811 3.51. event_callback (str)
1812
1813 The name of the function in the kemi configuration file (embedded
1814 scripting language such as Lua, Python, ...) to be executed instead of
1815 event_route[tm:local-request] block. The function receives a string
1816 parameter with the name of the event, respectively "tm:local-request".
1817
1818 Default value is 'empty' (no function is executed for events).
1819
1820 Example 1.52. Set event_callback parameter
1821 ...
1822 modparam("tm", "event_callback", "ksr_tm_event")
1823 ...
1824 -- event callback function implemented in Lua
1825 function ksr_tm_event(evname)
1826 KSR.info("===== tm module triggered event: " .. evname .. "\n");
1827 return 1;
1828 end
1829 ...
1830
1831 3.52. event_callback_lres_sent (str)
1832
1833 The name of the function in the kemi configuration file (embedded
1834 scripting language such as Lua, Python, ...) to be executed instead of
1835 event_route[tm:local-response] block. The function receives a string
1836 parameter with the name of the event, respectively "tm:local-response".
1837
1838 Default value is 'empty' (no function is executed for events).
1839
1840 Example 1.53. Set event_callback_lres_sent parameter
1841 ...
1842 modparam("tm", "event_callback_lres_sent", "ksr_tm_event_response_sent")
1843 ...
1844 -- event callback function implemented in Lua
1845 function ksr_tm_event_response_sent(evname)
1846 KSR.info("===== tm module triggered event: " .. evname .. "\n");
1847 return 1;
1848 end
1849 ...
1850
1851 3.53. evcb_local_ack_sent (str)
1852
1853 The name of the function in the kemi configuration file (embedded
1854 scripting language such as Lua, Python, ...) to be executed instead of
1855 event_route[tm:local-ack-sent] block. The function receives a string
1856 parameter with the name of the event, respectively "tm:local-ack-sent".
1857
1858 Default value is 'empty' (no function is executed for events).
1859
1860 Example 1.54. Set evcb_local_ack_sent parameter
1861 ...
1862 modparam("tm", "evcb_local_ack_sent", "ksr_tm_event_local_ack_sent")
1863 ...
1864 -- event callback function implemented in Lua
1865 function ksr_tm_event_local_ack_sent(evname)
1866 KSR.info("===== tm module triggered event: " .. evname .. "\n");
1867 return 1;
1868 end
1869 ...
1870
1871 3.54. relay_100 (str)
1872
1873 This parameter controls whether or not a SIP 100 response is proxied.
1874 Note that this is not valid behavior when operating in stateful mode
1875 per RFC 3261 Section 21.1.1, and therefore is useful only when
1876 operating as a stateless proxy. When using this feature, it is possible
1877 to control which 100 responses are proxied and which are not by
1878 detecting whether they are part of an existing transaction and setting
1879 up the appropriate logic in onreply_route.
1880
1881 Default value is 0 (disabled).
1882
1883 Example 1.55. Set relay_100 parameter
1884 ...
1885 modparam("tm", "relay_100", 1)
1886 ...
1887
1888 3.55. rich_redirect (int)
1889
1890 When sending a 3xx class reply, include additional branch info to the
1891 contacts such as path vector and branch flags.
1892 * 0 - no extra info is added (default)
1893 * 1 - include branch flags as contact header parameter
1894 * 2 - include path as contact uri Route header
1895
1896 Values may be combined (added).
1897
1898 Example 1.56. rich_redirect example
1899 ...
1900 modparam("tm", "rich_redirect", 3)
1901 ....
1902
1903 3.56. exec_time_check (int)
1904
1905 Duration in milliseconds for executing transaction failure callbacks
1906 and failure_route block after which to do a safety check if transaction
1907 is still active.
1908
1909 Set it to 0 in order to disable this check.
1910
1911 Default value is 5000 (5 seconds).
1912
1913 Example 1.57. Set exec_time_check parameter
1914 ...
1915 modparam("tm", "exec_time_check", 0)
1916 ...
1917
1918 3.57. reply_relay_mode (int)
1919
1920 If set to 1, a received 200 OK response that was suspended is no longer
1921 forwarded in the transactional context if another final response was
1922 forwarded while 200 OK was suspended. Forwarding the 200 OK, even it
1923 was received first, results in overwriting the transaction response
1924 buffer that can impact matching of incoming ACKs.
1925
1926 Set it to 0 in order to disable this behaviour and attempt to forward
1927 suspended 200 OK in the transaction context. This was the behaviour
1928 before the commit 18410da0.
1929
1930 Default value is 1.
1931
1932 Example 1.58. Set reply_relay_mode parameter
1933 ...
1934 modparam("tm", "reply_relay_mode", 0)
1935 ...
1936
1937 3.58. enable_uac_fr (int)
1938
1939 Enable failure route trigger, for uac. This will copy the tm uac into
1940 uas. Thus, failure route can be triggered even for uac messages. The
1941 default is 0 (disabled).
1942
1943 Example 1.59. enable_uac_fr example
1944 ...
1945 modparam("tm", "enable_uac_fr", 1)
1946 ....
1947
1948 3.59. failover_reply_codes (string)
1949
1950 This parameter defines the response codes (only codes >= 300 and class
1951 >= 3), which enable dns failover to continue to try next ips when
1952 previous one fail. It is a list separated by colons, where you may
1953 define either a single code (e.g. "code=408" would accept 408 as an
1954 additional response code) or a class of responses, you want to accept
1955 (e.g. "class=3" would accept everything from 300 to 999 as valid
1956 response). (with default behaviour only 503 code or no response from
1957 previous one will try next ip).
1958
1959 Default value is “”
1960
1961 Example 1.60. Set the “failover_reply_codes” parameter
1962 ...
1963 modparam("tm", "failover_reply_codes", "code=403;code=488;class=5")
1964 ...
1965
1966 3.60. reply_408_code (int)
1967
1968 Status code for internally generated timeout responses.
1969 Default value is “408”.
1970
1971 Example 1.61. reply_408_code example
1972 ...
1973 modparam("tm", "reply_408_code", 410)
1974 ....
1975
1976 3.61. reply_408_reason (str)
1977
1978 Reason phrase for internally generated timeout responses.
1979 Default value is “Request Timeout”.
1980
1981 Example 1.62. reply_408_reason example
1982 ...
1983 modparam("tm", "reply_408_reason", "Gone")
1984 ....
1985
1986 3.62. delayed_reply (int)
1987
1988 If set to 1, the reply generation in case of request
1989 processing/forwarding error is delayed till the config script execution
1990 ends. This allows the script writer to send its own error reply. If set
1991 to 0, the transaction is replied and killed immediately.
1992 Default value is “1”.
1993
1994 Example 1.63. delayed_reply example
1995 ...
1996 modparam("tm", "delayed_reply", 0)
1997 ....
1998
1999 3.63. evlreq_mode (int)
2000
2001 If bit 1 is set (value 1), the event_route[tm:local-request] is also
2002 executed for hop-by-hop CANCEL requests (for received INVITEs, not only
2003 for local generated ones).
2004 Default value is “0”.
2005
2006 Example 1.64. evlreq_mode example
2007 ...
2008 modparam("tm", "evlreq_mode", 1)
2009 ....
2010
2011 4. Functions
2012
2013 4.1. t_relay([host, port])
2014 4.2. t_relay_to_udp([ip, port])
2015 4.3. t_relay_to_tcp([ip, port])
2016 4.4. t_relay_to_tls([ip, port])
2017 4.5. t_relay_to_sctp([ip, port])
2018 4.6. t_on_failure(failure_route)
2019 4.7. t_on_branch_failure(branch_failure_route)
2020 4.8. t_on_reply(onreply_route)
2021 4.9. t_on_branch(branch_route)
2022 4.10. t_newtran()
2023 4.11. t_reply(code, reason_phrase)
2024 4.12. t_reply_error()
2025 4.13. t_send_reply(code, reason)
2026 4.14. t_lookup_request()
2027 4.15. t_retransmit_reply()
2028 4.16. t_release()
2029 4.17. t_forward_nonack([ip, port])
2030 4.18. t_forward_nonack_udp(ip, port)
2031 4.19. t_forward_nonack_tcp(ip, port)
2032 4.20. t_forward_nonack_tls(ip, port)
2033 4.21. t_forward_nonack_sctp(ip, port)
2034 4.22. t_set_fr(fr_inv_timeout [, fr_timeout])
2035 4.23. t_reset_fr()
2036 4.24. t_set_max_lifetime(inv_lifetime, noninv_lifetime)
2037 4.25. t_reset_max_lifetime()
2038 4.26. t_set_retr(retr_t1_interval, retr_t2_interval)
2039 4.27. t_reset_retr()
2040 4.28. t_set_auto_inv_100(0|1)
2041 4.29. t_branch_timeout()
2042 4.30. t_branch_replied()
2043 4.31. t_any_timeout()
2044 4.32. t_any_replied()
2045 4.33. t_grep_status("code")
2046 4.34. t_is_canceled()
2047 4.35. t_is_expired()
2048 4.36. t_relay_cancel()
2049 4.37. t_lookup_cancel([1])
2050 4.38. t_drop_replies([mode])
2051 4.39. t_save_lumps()
2052 4.40. t_load_contacts([mode])
2053 4.41. t_next_contacts()
2054 4.42. t_next_contact_flow()
2055 4.43. t_check_status(re)
2056 4.44. t_check_trans()
2057 4.45. t_set_disable_6xx(0|1)
2058 4.46. t_set_disable_failover(0|1)
2059 4.47. t_set_disable_internal_reply(0|1)
2060 4.48. t_set_no_auto_ack(0|1)
2061 4.49. t_replicate([params])
2062 4.50. t_relay_to(proxy, flags)
2063 4.51. t_relay_to_proxy(proxy [, flags])
2064 4.52. t_set_no_e2e_cancel_reason(0|1)
2065 4.53. t_is_set(target)
2066 4.54. t_use_uac_headers()
2067 4.55. t_is_retr_async_reply()
2068 4.56. t_uac_send(method, ruri, nexthop, socket, headers, body)
2069 4.57. t_get_status_code()
2070 4.58. t_clean()
2071 4.59. t_exists()
2072 4.60. t_cell_append_branches(tindex, tlabel)
2073 4.61. t_msg_apply_changes()
2074
2075 4.1. t_relay([host, port])
2076
2077 Relay a SIP request statefully either to the destination indicated in
2078 the current URI (if called without any parameters) or to the specified
2079 host and port. In the later case (host and port specified) the protocol
2080 used is the same protocol on which the message was received. It creates
2081 the SIP transaction, if none was created before (e.g., with
2082 t_newtran()).
2083
2084 t_relay() is the stateful version for forward() while t_relay(host,
2085 port) is similar to forward(host, port).
2086
2087 In the forward to uri case (t_relay()), if the original URI was
2088 rewritten (by UsrLoc, RR, strip/prefix, etc.) the new URI will be
2089 taken). The destination (including the protocol) is determined from the
2090 uri, using SIP specific DNS resolving if needed (NAPTR, SRV a.s.o
2091 depending also on the dns options).
2092
2093 Returns a negative value on failure -- you may still want to send a
2094 negative reply upstream statelessly not to leave upstream UAC in lurch.
2095
2096 Example 1.65. t_relay usage
2097 ...
2098 if (!t_relay())
2099 {
2100 send_reply_error();
2101 break;
2102 };
2103 ...
2104
2105 4.2. t_relay_to_udp([ip, port])
2106
2107 Relay a message statefully using a fixed protocol either to the
2108 specified fixed destination or to a destination derived from the
2109 message uri (if the host address and port are not specified). These
2110 along with t_relay are the functions most users want to use--all other
2111 are mostly for programming. Programmers interested in writing TM logic
2112 should review how t_relay is implemented in tm.c and how TM callbacks
2113 work.
2114
2115 Meaning of the parameters is as follows:
2116 * ip - IP address where the message should be sent.
2117 * port - Port number.
2118
2119 If no parameters are specified the message is sent to a destination
2120 derived from the message uri (using sip specific DNS lookups), but with
2121 the protocol corresponding to the function name.
2122
2123 Example 1.66. t_relay_to_udp usage
2124 ...
2125 if (src_ip==10.0.0.0/8)
2126 t_relay_to_udp("1.2.3.4", "5060"); # sent to 1.2.3.4:5060 over udp
2127 else
2128 t_relay_to_tcp(); # relay to msg. uri, but over tcp
2129 ...
2130
2131 4.3. t_relay_to_tcp([ip, port])
2132
2133 See function t_relay_to_udp([ip, port]).
2134
2135 4.4. t_relay_to_tls([ip, port])
2136
2137 See function t_relay_to_udp([ip, port]).
2138
2139 4.5. t_relay_to_sctp([ip, port])
2140
2141 See function t_relay_to_udp([ip, port]).
2142
2143 4.6. t_on_failure(failure_route)
2144
2145 Sets failure routing block, to which control is passed after a
2146 transaction completed with a negative result but before sending a final
2147 reply. In the referred block, you can either start a new branch (good
2148 for services such as forward_on_no_reply) or send a final reply on your
2149 own (good for example for message silo, which received a negative reply
2150 from upstream and wants to tell upstream "202 I will take care of it").
2151 Note that the set of commands which are usable within failure_routes is
2152 strictly limited to rewriting URI, initiating new branches, logging,
2153 and sending stateful replies (t_reply). Any other commands may result
2154 in unpredictable behavior and possible server failure. Note that
2155 whenever failure_route is entered, uri is reset to value which it had
2156 on relaying. If it temporarily changed during a reply_route processing,
2157 subsequent reply_route will ignore the changed value and use again the
2158 original one.
2159
2160 Meaning of the parameters is as follows:
2161 * failure_route - Failure route block to be called.
2162
2163 Example 1.67. t_on_failure usage
2164 ...
2165 route {
2166 t_on_failure("1");
2167 t_relay();
2168 }
2169
2170 failure_route[1] {
2171 revert_uri();
2172 setuser("voicemail");
2173 append_branch();
2174 }
2175 ...
2176
2177 See misc/examples/mixed/onr.cfg for a more complex example of
2178 combination of serial with parallel forking.
2179
2180 4.7. t_on_branch_failure(branch_failure_route)
2181
2182 Sets the branch_failure routing block, to which control is passed on
2183 each negative response to a transaction. This route is run before
2184 deciding if the transaction is complete. In the referred block, you can
2185 start a new branch which is required for failover of multiple outbound
2186 flows (RFC 5626). Note that the set of commands which are usable within
2187 a branch_failure route is limited to a subset of the failure_route
2188 commands including logging, rewriting URI and initiating new branches.
2189 Any other commands may generate errors or result in unpredictable
2190 behavior. Note that whenever failure_route is entered, uri is reset to
2191 value which it had on relaying. If it temporarily changed during a
2192 reply_route processing, subsequent reply_route will ignore the changed
2193 value and use again the original one.
2194
2195 Function Parameters:
2196 * branch_failure_route - Name of the branch_failure route block to be
2197 called (it is prefixed internally with 'tm:branch-failure:').
2198
2199 Example 1.68. t_on_branch_failure usage
2200 ...
2201 route {
2202 t_on_branch_failure("myroute");
2203 t_relay();
2204 }
2205
2206 event_route[tm:branch-failure:myroute] {
2207 if (t_check_status("430|403") {
2208 unregister("location", "$tu", "$T_reply_ruid");
2209 }
2210 }
2211 ...
2212
2213 4.8. t_on_reply(onreply_route)
2214
2215 Sets the reply routing block, to which control is passed when a reply
2216 for the current transaction is received. Note that the set of commands
2217 which are usable within onreply_routes is limited.
2218
2219 Meaning of the parameters is as follows:
2220 * onreply_route - Onreply route block to be called.
2221
2222 Example 1.69. t_on_reply usage
2223 ...
2224 loadmodule "/usr/local/lib/ser/modules/nathelper.so"
2225 ...
2226 route {
2227 /* if natted */
2228 t_on_reply("1");
2229 t_relay();
2230 }
2231
2232 onreply_route[1] {
2233 if (status=~ "(183)|2[0-9][0-9]"){
2234 force_rtp_proxy();
2235 search_append('^(Contact|m)[ \t]*:.*sip:[^>[:cntrl:]]*', ';nat=y
2236 es');
2237 }
2238 if (nat_uac_test("1")){
2239 fix_nated_contact();
2240 }
2241 }
2242
2243 4.9. t_on_branch(branch_route)
2244
2245 Sets the branch routing block, to which control is passed after forking
2246 (when a new branch is created). For now branch routes are intended only
2247 for last minute changes of the SIP messages (like adding new headers).
2248 Note that the set of commands which are usable within branch_routes is
2249 very limited. It is not possible to generate a reply.
2250
2251 Meaning of the parameters is as follows:
2252 * branch_route - branch route block to be called.
2253
2254 Example 1.70. t_on_branch usage
2255 ...
2256 route {
2257 t_on_branch("1");
2258 t_relay();
2259 }
2260
2261 branch_route[1] {
2262 if (uri=~"sip:[0-9]+"){
2263 append_hf("P-Warn: numeric uri\r\n");
2264 }
2265 }
2266
2267 4.10. t_newtran()
2268
2269 Creates a new transaction, returns a negative value on error.
2270 Typically, it is used to deploy a UAS.
2271
2272 Note: once the t_newtran() is executed, the new message flag operations
2273 (i.e., setflag() and resetflag()) are not synchronized to the
2274 transaction, being stored only in the private memory SIP message
2275 structure. Use the tmx module function t_flush_flags() to synchronize
2276 the modified message flags to the already created transaction.
2277
2278 Example 1.71. t_newtran usage
2279 ...
2280 if (t_newtran()) {
2281 xlog("the transaction has been created\n");
2282 t_reply("999","hello");
2283 } else {
2284 sl_reply_error();
2285 }
2286 ...
2287
2288 See misc/examples/mixed/uas.cfg for more examples.
2289
2290 4.11. t_reply(code, reason_phrase)
2291
2292 Sends a stateful reply after a transaction has been established. See
2293 t_newtran for usage.
2294
2295 If the code is in the range 300-399 (redirect reply), the current
2296 destination set is appended to the reply as Contact headers. The
2297 destination set contains the request URI (R-URI), if it is modified
2298 compared to the received one, plus the branches added to the request
2299 (e.g., after an append_branch() or lookup("location")). If the R-URI
2300 was changed but it is not desired to be part of the destination set, it
2301 can be reverted using the function revert_uri().
2302
2303 Custom headers to the reply can be added using append_to_reply()
2304 function from textops module.
2305
2306 Meaning of the parameters is as follows:
2307 * code - Reply code number.
2308 * reason_phrase - Reason string.
2309
2310 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
2311 ONREPLY_ROUTE.
2312
2313 Example 1.72. t_reply usage
2314 ...
2315 t_reply("404", "Not found");
2316 ...
2317
2318 4.12. t_reply_error()
2319
2320 Sends a stateful reply based in internal error code, similar to
2321 sl_send_error() from sl module.
2322
2323 This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
2324 ONREPLY_ROUTE.
2325
2326 Example 1.73. t_reply_error usage
2327 ...
2328 t_reply_error();
2329 ...
2330
2331 4.13. t_send_reply(code, reason)
2332
2333 Creates the transaction if it does not exist (executing internally
2334 t_newtran()) and sends a stateful reply (executing internally
2335 t_reply()). If transaction exists, this function does not stop the
2336 execution of config, t_reply() being still executed.
2337
2338 For more, see the docs for t_newtran() and t_reply().
2339
2340 Meaning of the parameters is as follows:
2341 * code - Reply code number.
2342 * reason - Reason string.
2343
2344 Example 1.74. t_send_reply usage
2345 ...
2346 t_send_reply("404", "Not found");
2347 ...
2348
2349 4.14. t_lookup_request()
2350
2351 Checks if a transaction exists. Returns a positive value if so,
2352 negative otherwise. Most likely you will not want to use it, as a
2353 typical application of a look-up is to introduce a new transaction if
2354 none was found. However this is safely (atomically) done using
2355 t_newtran.
2356
2357 Example 1.75. t_lookup_request usage
2358 ...
2359 if (t_lookup_request()) {
2360 ...
2361 };
2362 ...
2363
2364 4.15. t_retransmit_reply()
2365
2366 Retransmits a reply sent previously by UAS transaction.
2367
2368 Example 1.76. t_retransmit_reply usage
2369 ...
2370 t_retransmit_reply();
2371 ...
2372
2373 4.16. t_release()
2374
2375 Remove transaction from memory (it will be first put on a wait timer to
2376 absorb delayed messages).
2377
2378 Example 1.77. t_release usage
2379 ...
2380 t_release();
2381 ...
2382
2383 4.17. t_forward_nonack([ip, port])
2384
2385 Mainly for internal usage -- forward a non-ACK request statefully.
2386 Variants of this functions can enforce a specific transport protocol.
2387
2388 Meaning of the parameters is as follows:
2389 * ip - IP address where the message should be sent.
2390 * port - Port number.
2391
2392 Example 1.78. t_forward_nonack usage
2393 ...
2394 t_forward_nonack("1.2.3.4", "5060");
2395 ...
2396
2397 4.18. t_forward_nonack_udp(ip, port)
2398
2399 See function t_forward_nonack([ip, port]).
2400
2401 4.19. t_forward_nonack_tcp(ip, port)
2402
2403 See function t_forward_nonack([ip, port]).
2404
2405 4.20. t_forward_nonack_tls(ip, port)
2406
2407 See function t_forward_nonack([ip, port]).
2408
2409 4.21. t_forward_nonack_sctp(ip, port)
2410
2411 See function t_forward_nonack([ip, port]).
2412
2413 4.22. t_set_fr(fr_inv_timeout [, fr_timeout])
2414
2415 Sets the fr_inv_timeout and optionally fr_timeout for the current
2416 transaction or for transactions created during the same script
2417 invocation, after calling this function. If the transaction is already
2418 created (e.g called after t_relay() or in an onreply_route) all the
2419 branches will have their final response timeout updated on-the-fly. If
2420 one of the parameters is 0, its value won't be changed.
2421
2422 Meaning of the parameters is as follows:
2423 * fr_inv_timeout - new final response timeout (in milliseconds) for
2424 INVITEs. See also fr_inv_timer.
2425 * fr_timeout - new final response timeout (in milliseconds) for
2426 non-INVITE transaction, or INVITEs which haven't received yet a
2427 provisional response. See also fr_timer.
2428
2429 See also: fr_timer, fr_inv_timer, t_reset_fr().
2430
2431 Example 1.79. t_set_fr usage
2432 ...
2433 route {
2434 t_set_fr(10000); # set only fr invite timeout to 10s
2435 t_on_branch("1");
2436 t_relay();
2437 }
2438
2439 branch_route[1] {
2440 # if we are calling the pstn, extend the invite timeout to 50s
2441 # for all the branches, and set the no-reply-received timeout to 2s
2442 if (uri=~"sip:[0-9]+"){
2443 t_set_fr(50000, 2000);
2444 }
2445 }
2446
2447 4.23. t_reset_fr()
2448
2449 Resets the fr_inv_timer and fr_timer for the current transaction to the
2450 default values (set using the tm module parameters fr_inv_timer and
2451 fr_timer).
2452
2453 It will effectively cancel any previous calls to t_set_fr for the same
2454 transaction.
2455
2456 See also: fr_timer, fr_inv_timer, t_set_fr.
2457
2458 Example 1.80. t_reset_fr usage
2459 ...
2460 route {
2461 ...
2462 t_reset_fr();
2463 ...
2464 }
2465
2466 4.24. t_set_max_lifetime(inv_lifetime, noninv_lifetime)
2467
2468 Sets the maximum lifetime for the current INVITE or non-INVITE
2469 transaction, or for transactions created during the same script
2470 invocation, after calling this function (that's why it takes values for
2471 both INVITE and non-INVITE). If one of the parameters is 0, its value
2472 won't be changed.
2473
2474 It works as a per transaction max_inv_lifetime or max_noninv_lifetime.
2475
2476 Meaning of the parameters is as follows:
2477 * inv_lifetime - maximum INVITE transaction lifetime (in
2478 milliseconds). See also max_inv_lifetime.
2479 * noninv_lifetime - maximum non-INVITE transaction lifetime (in
2480 milliseconds). See also max_noninv_lifetime.
2481
2482 See also: max_inv_lifetime, max_noninv_lifetime, t_reset_max_lifetime.
2483
2484 Example 1.81. t_set_max_lifetime usage
2485 ...
2486 route {
2487 if (src_ip=1.2.3.4)
2488 t_set_max_lifetime(120000, 0); # set only max_inv_lifetime to 120s
2489 else
2490 t_set_max_lifetime(90000, 15000); # set the maximum lifetime to 90s if
2491 # the current transaction is an
2492 # INVITE and to 15s if not
2493 }
2494
2495 4.25. t_reset_max_lifetime()
2496
2497 Resets the maximum lifetime for the current INVITE or non-INVITE
2498 transaction to the default value (set using the tm module parameter
2499 max_inv_lifetime or max_noninv_lifetime).
2500
2501 It will effectively cancel any previous calls to t_set_max_lifetime for
2502 the same transaction.
2503
2504 See also: max_inv_lifetime, max_noninv_lifetime, t_set_max_lifetime.
2505
2506 Example 1.82. t_reset_max_lifetime usage
2507 ...
2508 route {
2509 ...
2510 t_reset_max_lifetime();
2511 ...
2512 }
2513
2514 4.26. t_set_retr(retr_t1_interval, retr_t2_interval)
2515
2516 Sets the retr_t1_interval and retr_t2_interval for the current
2517 transaction or for transactions created during the same script
2518 invocation, after calling this function. If one of the parameters is 0,
2519 its value won't be changed. If the transaction is already created (e.g
2520 called after t_relay() or in an onreply_route) all the existing
2521 branches will have their retransmissions intervals updated on-the-fly:
2522 if the retransmission interval for the branch has not yet reached T2
2523 the interval will be reset to retr_t1_interval, else to
2524 retr_t2_interval. Note that the change will happen after the current
2525 interval expires (after the next retransmission, the next-next
2526 retransmission will take place at retr_t1_interval or
2527 retr_t2_interval). All new branches of the same transaction will start
2528 with the new values. This function will work even if it's called in the
2529 script before a transaction creating function (e.g.: t_set_retr(500,
2530 4000); t_relay()). All new transaction created after this function
2531 call, during the same script invocation will use the new values.
2532
2533 Meaning of the parameters is as follows:
2534 * retr_t1_interval - new T1 retransmission interval (in
2535 milliseconds). See also retr_t1_timeout.
2536 * retr_t2_interval - new T2 (or maximum) retransmission interval (in
2537 milliseconds). See also retr_t2_timeout.
2538
2539 See also: retr_timer1, retr_timer2, t_reset_retr().
2540
2541 Example 1.83. t_set_retr usage
2542 ...
2543 route {
2544 t_set_retr(250, 0); # set only T1 to 250 ms
2545 t_on_branch("1");
2546 t_relay();
2547 }
2548
2549 branch_route[1] {
2550 # if we are calling the a remote pstn, extend T1 and decrease T2
2551 # for all the branches
2552 if (uri=~"sip:[0-9]+"){
2553 t_set_retr(500, 2000);
2554 }
2555 }
2556
2557 4.27. t_reset_retr()
2558
2559 Resets the retr_timer1 and retr_timer2 for the current transaction to
2560 the default values (set using the tm module parameters retr_timer1 and
2561 retr_timer2).
2562
2563 It will effectively cancel any previous calls to t_set_retr for the
2564 same transaction.
2565
2566 See also: retr_timer1, retr_timer2, t_set_retr.
2567
2568 Example 1.84. t_reset_retr usage
2569 ...
2570 route {
2571 ...
2572 t_reset_retr();
2573 ...
2574 }
2575
2576 4.28. t_set_auto_inv_100(0|1)
2577
2578 Switch automatically sending 100 replies to INVITEs on/off on a per
2579 transaction basis. It overrides the auto_inv_100 value for the current
2580 transaction.
2581
2582 See also: auto_inv_100.
2583
2584 Example 1.85. t_set_auto_inv_100 usage
2585 ...
2586 route {
2587 ...
2588 if (src_ip==1.2.3.0/24)
2589 t_set_auto_inv_100(0); # turn off automatic 100 replies
2590 ...
2591 }
2592
2593 4.29. t_branch_timeout()
2594
2595 Returns true if the failure route is executed for a branch that did
2596 timeout. It can be used from FAILURE_ROUTE and BRANCH_FAILURE_ROUTE
2597 event route.
2598
2599 Example 1.86. t_branch_timeout usage
2600 ...
2601 failure_route[0]{
2602 if (t_branch_timeout()){
2603 log("timeout\n");
2604 # ...
2605 }
2606 }
2607
2608 4.30. t_branch_replied()
2609
2610 Returns true if the failure route is executed for a branch that did
2611 receive at least one reply in the past (the "current" reply is not
2612 taken into account). It can be used from failure_route and
2613 branch-failure event route.
2614
2615 Example 1.87. t_branch_replied usage
2616 ...
2617 failure_route[0]{
2618 if (t_branch_timeout()){
2619 if (t_branch_replied())
2620 log("timeout after receiving a reply (no answer?)\n");
2621 else
2622 log("timeout, remote side seems to be down\n");
2623 # ...
2624 }
2625 }
2626
2627 4.31. t_any_timeout()
2628
2629 Returns true if at least one of the current transactions branches did
2630 timeout.
2631
2632 Example 1.88. t_any_timeout usage
2633 ...
2634 failure_route[0]{
2635 if (!t_branch_timeout()){
2636 if (t_any_timeout()){
2637 log("one branch did timeout\n");
2638 sl_send_reply("408", "Timeout");
2639 }
2640 }
2641 }
2642
2643 4.32. t_any_replied()
2644
2645 Returns true if at least one of the current transactions branches did
2646 receive some reply in the past. If called from a failure or onreply
2647 route, the "current" reply is not taken into account.
2648
2649 Example 1.89. t_any_replied usage
2650 ...
2651 onreply_route[0]{
2652 if (!t_any_replied()){
2653 log("first reply received\n");
2654 # ...
2655 }
2656 }
2657
2658 4.33. t_grep_status("code")
2659
2660 Returns true if "code" is the final reply received (or locally
2661 generated) in at least one of the current transactions branches.
2662
2663 Example 1.90. t_grep_status usage
2664 ...
2665 onreply_route[0]{
2666 if (t_grep_status("486")){
2667 /* force a 486 reply, even if this is not the winning branch */
2668 t_reply("486", "Busy");
2669 }
2670 }
2671
2672 4.34. t_is_canceled()
2673
2674 Returns true if the current transaction was canceled.
2675
2676 Example 1.91. t_is_canceled usage
2677 ...
2678 failure_route[0]{
2679 if (t_is_canceled()){
2680 log("transaction canceled\n");
2681 # ...
2682 }
2683 }
2684
2685 4.35. t_is_expired()
2686
2687 Returns true if the current transaction has already expired, i.e. the
2688 max_inv_lifetime/max_noninv_lifetime interval has already elapsed.
2689
2690 Example 1.92. t_is_expired usage
2691 ...
2692 failure_route[0]{
2693 if (t_is_expired()){
2694 log("transaction expired\n");
2695 # There is no point in adding a new branch.
2696 }
2697 }
2698
2699 4.36. t_relay_cancel()
2700
2701 Forwards the CANCEL if the corresponding INVITE transaction exists. The
2702 function is supposed to be used at the very beginning of the script,
2703 because the CANCELs can be caught and the rest of the script can be
2704 bypassed this way. Do not disable reparse_invite module parameter, and
2705 call t_relay_cancel() right after the sanity tests.
2706
2707 Return value is 0 (drop) if the corresponding INVITE was found and the
2708 CANCELs were successfully sent to the pending branches, true if the
2709 INVITE was not found, and false in case of any error.
2710
2711 Example 1.93. t_relay_cancel usage
2712 if (method == CANCEL) {
2713 if (!t_relay_cancel()) { # implicit drop if relaying was successful,
2714 # nothing to do
2715
2716 # corresponding INVITE transaction found but error occurred
2717 sl_reply("500", "Internal Server Error");
2718 drop;
2719 }
2720 # bad luck, corresponding INVITE transaction is missing,
2721 # do the same as for INVITEs
2722 }
2723
2724 4.37. t_lookup_cancel([1])
2725
2726 Returns true if the corresponding INVITE transaction exists for a
2727 CANCEL request. The function can be called at the beginning of the
2728 script to check whether or not the CANCEL can be immediately forwarded
2729 bypassing the rest of the script. Note however that t_relay_cancel
2730 includes t_lookup_cancel as well, therefore it is not needed to
2731 explicitly call this function unless something has to be logged for
2732 example.
2733
2734 If the function parameter (optional) is set to 1, the message flags are
2735 overwritten with the flags of the INVITE. isflagset() can be used to
2736 check the flags of the previously forwarded INVITE in this case.
2737
2738 Example 1.94. t_lookup_cancel usage
2739 if (method == CANCEL) {
2740 if (t_lookup_cancel()) {
2741 log("INVITE transaction exists");
2742 if (!t_relay_cancel()) { # implicit drop if
2743 # relaying was successful,
2744 # nothing to do
2745
2746 # corresponding INVITE transaction found
2747 # but error occurred
2748 sl_reply("500", "Internal Server Error");
2749 drop;
2750 }
2751 }
2752 # bad luck, corresponding INVITE transaction is missing,
2753 # do the same as for INVITEs
2754 }
2755
2756 4.38. t_drop_replies([mode])
2757
2758 Drops all the previously received replies in failure_route block to
2759 make sure that none of them is picked up again.
2760
2761 The parameter 'mode' controls which replies are dropped: 'a' or missing
2762 - all replies are dropped; 'l' - replies received for last set of
2763 branches are dropped; 'n' - no reply is dropped.
2764
2765 Dropping replies works only if a new branch is added to the
2766 transaction, or it is explicitly replied in the script!
2767
2768 Example 1.95. t_drop_replies() usage
2769 ...
2770 failure_route[0]{
2771 if (t_check_status("5[0-9][0-9]")){
2772 # I do not like the 5xx responses,
2773 # so I give another chance to "foobar.com",
2774 # and I drop all the replies to make sure that
2775 # they are not forwarded to the caller.
2776 t_drop_replies();
2777
2778 rewritehostport("foobar.com");
2779 append_branch();
2780 t_relay();
2781 }
2782 }
2783
2784 4.39. t_save_lumps()
2785
2786 Forces the modifications of the processed SIP message to be saved in
2787 shared memory before t_relay() is called. The new branches which are
2788 created in failure_route will contain the same modifications, and any
2789 other modification after t_save_lumps() will be lost.
2790
2791 Note that t_relay() automatically saves the modifications when it is
2792 called the first time, there is no need for t_save_lumps() unless
2793 message changes between t_save_lumps() and t_relay() must not be
2794 propagated to failure_route.
2795
2796 The transaction must be created by t_newtran() before calling
2797 t_save_lumps().
2798
2799 Example 1.96. t_save_lumps() usage
2800 route {
2801 ...
2802 t_newtran();
2803 append_hf("hf1: my first header\r\n");
2804 ...
2805 t_save_lumps();
2806 append_hf("hf2: my second header\r\n");
2807 ...
2808 t_on_failure("1");
2809 t_relay();
2810 }
2811
2812 failure_route[1] {
2813 append_branch();
2814 append_hf("hf3: my third header\r\n");
2815 #
2816 # This branch contains hf1 and hf3, but does
2817 # not contain hf2 header.
2818 # hf2 would be also present here without
2819 # t_save_lumps().
2820 ...
2821 t_relay();
2822 }
2823
2824 4.40. t_load_contacts([mode])
2825
2826 This is the first of the three functions that can be used to implement
2827 serial/parallel forking based on q and +sip.instance values of
2828 individual branches in the destination set.
2829
2830 Function t_load_contacts() removes all branches from the current
2831 destination set and stores them into the XAVP whose name is configured
2832 with the parameter contacts_avp. Note that you have to configure this
2833 parameter before you can use the function, the parameter is set to NULL
2834 by default, which disables the function.
2835
2836 If the destination set contains only one branch, the function does
2837 nothing.
2838
2839 If the current destination set contains more than one branch, the
2840 function sorts them according to the algorithm selected with the 'mode'
2841 parameter and then stores the branches in reverse order into the XAVP.
2842
2843 The q parameter of a branch contains a value from range 0-1.0 and it
2844 expresses relative preference of the branch among all branches in the
2845 destination set. The higher the q value the more preference the user
2846 agent gave to the branch. The parameter 'mode' controls which type of
2847 algorithm kamailio will apply to sort the branches based on the q
2848 values:
2849
2850 - '0' or missing: branches with higher q values will be tried before
2851 branches with lower ones when serial forking takes place Equals q
2852 values will result in a parallel forking.
2853
2854 - '1': branches are ordered using a proportional algorithm that uses to
2855 q value as the weight of the branch. Higher is the q value, higher is
2856 the probability to be tried as first. Equals q values means equals
2857 probability to be tried. Differently from the previous mode there is no
2858 possibility to have parallel forking. Branches with q values equals to
2859 0 or lower are not considered by the ordering algorithm, but just added
2860 at the end of the list as backup option if all other branches fail.
2861 This algorithm can be useful in case of endpoints in ACTIVE-ACTIVE
2862 configuration to load-balance the calls.
2863
2864 After calling t_load_contacts(), function t_next_contacts() and
2865 possibly also t_next_contact_flow() need to be called one or more times
2866 in order to retrieve the branches based on their order.
2867
2868 Function returns 1 if loading of contacts succeeded or there was
2869 nothing to do. In case of an error, function returns -1 (see syslog).
2870
2871 This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
2872
2873 Example 1.97. t_load_contacts usage
2874 ...
2875 if (!t_load_contacts()) {
2876 sl_send_reply("500", "Server Internal Error - Cannot load contacts");
2877 exit;
2878 };
2879 ...
2880
2881 4.41. t_next_contacts()
2882
2883 Function t_next_contacts() is the second of the three functions that
2884 can be used to implement serial/parallel forking based on the q value
2885 of the individual branches in a destination set.
2886
2887 The function adds to request a new destination set that includes the
2888 highest priority contacts in contacts_avp, but only one contact with
2889 the same +sip.instance value is included. Duplicate contacts are added
2890 to contact_flows_avp for later consumption by function
2891 next_contact_flow(). Upon each call, Request URI is rewritten with the
2892 first contact and the remaining contacts (if any) are added as
2893 branches. Then all highest priority contacts are removed from
2894 contacts_avp.
2895
2896 Function does nothing if contact_avp has no values.
2897
2898 Function returns 1 if contacts_avp was not empty and a destination set
2899 was successfully added, returns -2 if contacts_avp was empty and thus
2900 there was nothing to do, and returns -1 in case of an error (see
2901 syslog). Function can be called from REQUEST_ROUTE and FAILURE_ROUTE.
2902
2903 Note that if you use t_load_contacts and t_next_contacts functions then
2904 you should also set the value of restart_fr_on_each_reply parameter to
2905 0. If you do not do that, it can happen that a broken user agent that
2906 retransmits 180 periodically will keep resetting the fr_inv_timer value
2907 and serial forking never happens.
2908
2909 Before calling t_relay(), you can check if the previous call of
2910 next_contacts() consumed all branches by checking if contact_avp and
2911 contact_flows_avp are not anymore set. Based on that test, you can then
2912 use t_set_fr() function to set timers according to your needs.
2913
2914 Example 1.98. t_next_contacts usage
2915 ...
2916 # First call after t_load_contacts() when transaction does not exist yet
2917 # and contacts should be available
2918 if (!t_next_contacts()) {
2919 sl_send_reply("500", "Server Internal Error - Cannot get contacts");
2920 } else {
2921 t_relay();
2922 };
2923 ...
2924 # Following call, when transaction exists and there may or may not be
2925 # contacts left
2926 if (!t_next_contacts()) {
2927 t_reply("408", "Request Timeout");
2928 } else {
2929 t_relay();
2930 };
2931 ...
2932
2933 4.42. t_next_contact_flow()
2934
2935 Function t_next_contact_flow() is the last of the three functions that
2936 can be used to implement serial/parallel forking based on the q value
2937 and instance value of individual branches in a destination set.
2938
2939 Function adds a new branch to the request that includes the first
2940 contact from contact_flows_avp that matches the +sip.instance value of
2941 the flow that has failed. Upon each call, Request URI is rewritten with
2942 the contact. The used contact is removed from contact_flows_avp.
2943
2944 Function does nothing if there are no contact_flows_avp values.
2945
2946 Function returns 1 if contact_flows_avp was not empty and a destination
2947 set was successfully added, returns -2 if contacts_avp was empty and
2948 thus there was nothing to do, and returns -1 in case of an error (see
2949 syslog). This function can be used from a BRANCH_FAILURE_ROUTE event
2950 route.
2951
2952 Example 1.99. t_next_contact_flow usage
2953 ...
2954 event_route[tm:branch-failure:outbound]
2955 {
2956 if (t_next_contact_flow())
2957 {
2958 t_relay();
2959 } else {
2960 xlog("L_INFO", "No more flows\n");
2961 }
2962 ...
2963
2964 4.43. t_check_status(re)
2965
2966 Returns true if the regular expression “re” match the reply code of the
2967 response message as follows:
2968 * in routing block - the code of the last sent reply.
2969 * in on_reply block - the code of the current received reply.
2970 * in on_failure block - the code of the selected negative final
2971 reply.
2972
2973 This function can be used from ANY_ROUTE .
2974
2975 Example 1.100. t_check_status usage
2976 ...
2977 if (t_check_status("(487)|(408)")) {
2978 log("487 or 408 negative reply\n");
2979 }
2980 ...
2981
2982 4.44. t_check_trans()
2983
2984 t_check_trans() can be used to quickly check if a message belongs or is
2985 related to a transaction. It behaves differently for different types of
2986 messages:
2987 * For a SIP Reply it returns true if the reply belongs to an existing
2988 transaction and false otherwise.
2989 * For a CANCEL it behaves exactly as t_lookup_cancel(): returns true
2990 if a corresponding INVITE transaction exists for the CANCEL and
2991 false otherwise.
2992 * For ACKs to negative replies or for ACKs to local transactions it
2993 will terminate the script if the ACK belongs to a transaction (it
2994 would make very little sense to process an ACK to a negative reply
2995 for an existing transaction in some other way then to simply pass
2996 it to tm) or return false if not.
2997 * For end-to-end ACKs (ACKs to 2xx responses for forwarded INVITE
2998 transactions) it will return true if the corresponding INVITE
2999 transaction is found and still active and false if not.
3000
3001 Note
3002 Note that the e2e ACK matching is more of a hint then a certainty.
3003 A delayed e2e ACK might arrive after the transaction wait time
3004 elapses, when the INVITE transaction no longer exists and thus
3005 would not match anything. There are also cases when tm would not
3006 keep all the information needed for e2e ACK matching (since this is
3007 not needed for a stateful proxy and it requires additional memory,
3008 tm will not keep this information unless needed by some other
3009 module or callbacks).
3010 * For other requests (non ACKs and non CANCELs), in case of a
3011 retransmission matching a transaction, it resends the last reply
3012 for that transaction and terminates the config execution.
3013 Otherwise, it returns false (in case of new requests for which no
3014 transaction exists yet).
3015
3016 Note
3017
3018 An important difference from kamailio version is that for an ACK to
3019 negative reply or for a local transaction, the script execution will be
3020 immediately stopped and the message handled by tm, instead of returning
3021 true.
3022
3023 t_check_trans() functionality for requests, except for the e2e ACK
3024 matching, can be replicated in the script using t_lookup_cancel() and
3025 t_lookup_request().
3026
3027 See also: t_lookup_request(), t_lookup_cancel().
3028
3029 Example 1.101. t_check_trans usage
3030 if ( method == "CANCEL" && !t_check_trans())
3031 sl_reply("403", "cancel out of the blue forbidden");
3032 # note: in this example t_check_trans() can be replaced by t_lookup_cancel()
3033
3034 4.45. t_set_disable_6xx(0|1)
3035
3036 Turn off/on 6xx replies special rfc conforming handling on a per
3037 transaction basis. If turned off (t_set_disable_6xx("1")) 6XXs will be
3038 treated like normal replies.
3039
3040 It overrides the disable_6xx_block value for the current transaction.
3041
3042 See also: disable_6xx_block.
3043
3044 Example 1.102. t_set_disable_6xx usage
3045 ...
3046 route {
3047 ...
3048 if (src_ip==1.2.3.4) # bad user agent that sends 603
3049 t_set_disable_6xx(1); # turn off 6xx special handling
3050 ...
3051 }
3052
3053 4.46. t_set_disable_failover(0|1)
3054
3055 Turn off/on dns failover on a per transaction basis.
3056
3057 See also: use_dns_failover.
3058
3059 Example 1.103. t_set_disable_failover usage
3060 ...
3061 route {
3062 ...
3063 if (uri=~"@foo.bar$")
3064 t_set_disable_failover(1); # turn off dns failover
3065 ...
3066 }
3067
3068 4.47. t_set_disable_internal_reply(0|1)
3069
3070 Turn off/on sending internally a SIP reply in case of relay errors.
3071
3072 Example 1.104. t_set_disable_internal_reply usage
3073 ...
3074 t_set_disable_internal_reply(1); # turn off sending internal reply on error
3075 if(!t_relay()) {
3076 send_reply("500", "Server error");
3077 }
3078 ...
3079
3080 4.48. t_set_no_auto_ack(0|1)
3081
3082 Turn off/on generating e2e ACKs automatically for successfully answered
3083 local transactions (uac)
3084
3085 Example 1.105. t_set_no_auto_ack usage
3086 ...
3087 t_set_no_auto_ack(1); # when receiving a 200-299 fr for local transaction (uac),
3088 do not reply automatically
3089 if(!t_relay()) {
3090 send_reply("500", "Server error");
3091 }
3092 ...
3093
3094 4.49. t_replicate([params])
3095
3096 Replicate the SIP request to a specific address. Return values are the
3097 same as for t_relay(). Note that responses to the replicated request
3098 are suppressed and will not show up in any reply_route.
3099
3100 There are several function prototypes:
3101 * t_replicate([uri]),
3102 * t_replicate(host, port),
3103 * t_replicate_udp(host, port)
3104 * t_replicate_tcp(host, port)
3105 * t_replicate_tls(host, port)
3106 * t_replicate_sctp(host, port)
3107 * t_replicate_to(proto, hostport)
3108
3109 Meaning of the parameters is as follows:
3110 * uri - SIP URI where the message should be sent. It can be given via
3111 a script variable. It is optional - when missing, the dst-uri or
3112 r-uri are used as next hop address.
3113 * host - host address where the message should be sent.
3114 * port - port number.
3115 * proto - transport protocol to be used.
3116 * hostport - address in "host:port" format. It can be given via an
3117 AVP.
3118
3119 Example 1.106. t_replicate usage
3120 ...
3121 # sent to 1.2.3.4:5060 over tcp
3122 t_replicate("sip:1.2.3.4:5060;transport=tcp");
3123
3124 # sent to 1.2.3.4:5061 over tls
3125 $var(h) = "1.2.3.4:5061";
3126 t_replicate("sip:$var(h);transport=tls");
3127
3128 # sent to 1.2.3.4:5060 over udp
3129 t_replicate_to_udp("1.2.3.4", "5060");
3130 ...
3131
3132 4.50. t_relay_to(proxy, flags)
3133
3134 Forward the SIP request to a specific address, controlling internal
3135 behavior via flags.
3136
3137 There are several function prototypes:
3138 * t_relay_to(),
3139 * t_relay_to(proxy),
3140 * t_relay_to(flags)
3141 * t_relay_to(proxy, flags)
3142
3143 Meaning of the parameters is as follows:
3144 * proxy - address where the request should be sent. Format is:
3145 "proto:host:port" - any of proto or port can be omitted, along with
3146 the semicolon after or before.
3147 * flags - bitmask integer value to control the internal behavior.
3148 Bits can be:
3149 + 0x01 - do not generate 100 reply.
3150 + 0x02 - do not generate reply on internal error.
3151 + 0x04 - disable dns failover.
3152
3153 Example 1.107. t_relay_to usage
3154 ...
3155 # sent to 1.2.3.4:5060 over tcp
3156 t_relay_to("tcp:1.2.3.4:5060");
3157
3158 # sent to 1.2.3.4 over tls
3159 t_relay_to("tls:1.2.3.4");
3160
3161 # sent to dst URI or R-URI without a 100 reply
3162 t_relay_to("0x01");
3163 ...
3164
3165 4.51. t_relay_to_proxy(proxy [, flags])
3166
3167 Alternative function to relay the SIP request to a specific address,
3168 with the parameter supporting variables inside it.
3169
3170 The format of the proxy parameter is: "proto:host:port" - any of proto
3171 or port can be omitted, along with the semicolon after or before. The
3172 flags parameter is optional, with possible values like for
3173 t_relay_to().
3174
3175 The function can be used in REQUEST_ROUTE and FAILURE_ROUTE.
3176
3177 Example 1.108. t_relay_to_proxy usage
3178 ...
3179 t_relay_to_proxy("udp:$var(addr):5060");
3180 ...
3181
3182 4.52. t_set_no_e2e_cancel_reason(0|1)
3183
3184 Enables/disables reason header (RFC 3326) copying from the triggering
3185 received CANCEL to the generated hop-by-hop CANCEL. 0 enables and 1
3186 disables.
3187
3188 It overrides the e2e_cancel_reason setting (module parameter) for the
3189 current transaction.
3190
3191 Note: the function has to be used when processing the INVITE (not when
3192 processing the CANCEL).
3193
3194 See also: e2e_cancel_reason.
3195
3196 Example 1.109. t_set_no_e2e_cancel_reason usage
3197 ...
3198 route {
3199 ...
3200 if (src_ip!=10.0.0.0/8) # don't trust CANCELs from the outside
3201 t_set_no_e2e_cancel_reason(1); # turn off CANCEL reason header c
3202 opying
3203 ...
3204 }
3205
3206 4.53. t_is_set(target)
3207
3208 Return true if the attribute specified by 'target' is set for
3209 transaction.
3210
3211 The target parameter can be:
3212 * branch_route - the function returns true if a branch route is set
3213 to be executed.
3214 * failure_route - the function returns true if a failure route is set
3215 to be executed.
3216 * onreply_route - the function returns true if an onreply route is
3217 set to be executed.
3218
3219 Example 1.110. t_replicate usage
3220 ...
3221 if(!t_is_set("failure_route"))
3222 LM_DBG("no failure route will be executed for current transaction\n");
3223 ...
3224
3225 4.54. t_use_uac_headers()
3226
3227 Set internal flags to tell tm to use UAC side for building headers for
3228 local generated requests (ACK, CANCEL) - useful when changing From/To
3229 headers using other functions than uac_replace_[from|to]().
3230
3231 It returns true.
3232
3233 Example 1.111. t_use_uac_headers usage
3234 ...
3235 t_use_uac_headers();
3236 ...
3237
3238 4.55. t_is_retr_async_reply()
3239
3240 Check to see if the reply is a retransmitted reply on a transaction
3241 that is currently suspended asynchronously (suspended during reply
3242 processing). Right now the check is only on the transaction, we don't
3243 actually check to see if the reply message is an actual retransmission
3244 of the suspended reply. This is expected as you should not process
3245 another reply until the suspended reply processing has been completed.
3246 The trick here is to make sure you don't suspend for too long or even
3247 worse, indefinitely.
3248
3249 returns true if the transaction is currently reply suspended or false
3250 if not.
3251
3252 Example 1.112. t_is_retr_async_reply usage
3253 ...
3254 if (t_is_retr_async_reply()) {
3255 xlog("L_DBG", "Dropping retransmitted reply which is still currently sus
3256 pended\n");
3257 drop();
3258 }
3259 ...
3260
3261 4.56. t_uac_send(method, ruri, nexthop, socket, headers, body)
3262
3263 Send a UAC request.
3264
3265 It returns true (1) if successful, false (-1) on failure.
3266
3267 The parameters:
3268 * method - SIP method. Add a "." to the end of the method name to
3269 suppress automatic ACK generation (the dot is not transmitted, of
3270 course).
3271 * ruri - request URI.
3272 * nexthop - destination URI (can be empty).
3273 * socket - local send socket (can be empty).
3274 * headers - SIP headers. At least From and To have to be provided. It
3275 can include From/To tags, Call-ID, CSeq. If body is provided, then
3276 Content-Type header must exist.
3277 * body - SIP message body (can be empty).
3278
3279 Example 1.113. t_uac_send usage
3280 ...
3281 t_uac_send("OPTIONS", "sip:[email protected]", "", "",
3282 "From: [email protected];tag=2w3e\r\nTo: [email protected]", "");
3283 ...
3284
3285 4.57. t_get_status_code()
3286
3287 Return the status code for transaction - the most relevant SIP reply
3288 status code, or -1 in case of error or no status code was set.
3289
3290 Example 1.114. t_get_status_code usage
3291 ...
3292 $var(ts) = t_get_status_code();
3293 if($var(ts) == 500) { ... }
3294 ...
3295
3296 4.58. t_clean()
3297
3298 Cleans active but very old transactions. Returns true (1). Can be
3299 called from any route.
3300
3301 Example 1.115. t_clean usage
3302 ...
3303 t_clean();
3304 ...
3305
3306 4.59. t_exists()
3307
3308 Return true if a transaction for the current message exists, without
3309 setting the global references.
3310
3311 Example 1.116. t_exists usage
3312 ...
3313 reply_route {
3314 if (!t_exists()) {
3315 drop();
3316 }
3317 }
3318 ...
3319
3320 4.60. t_cell_append_branches(tindex, tlabel)
3321
3322 Append destination set branches to the transaction identified by
3323 (tindex, tlabel). The parameters can also be variables.
3324
3325 Example 1.117. t_cell_append_branches usage
3326 ...
3327 append_branch("sip:1.2.3.4:5060");
3328 t_cell_append_branches("1234", "$var(tlabel)");
3329 ...
3330
3331 4.61. t_msg_apply_changes()
3332
3333 Apply changes to the SIP request processed in a branch_route block. It
3334 changes the request only for that particular branch, not the
3335 transaction incoming request. It is similar to msg_apply_changes(), but
3336 designed to be used in the context of the branch route, after the
3337 transaction was created.
3338
3339 It is not needed to use this function explicitely, unless the changes
3340 to the SIP request are needed for the next functions in the same
3341 branch_route block, otherwise the operations for adding/removing
3342 headers or changing the body of the request are applied before writing
3343 to the outbound socket.
3344
3345 It requires to set core parameter msg_apply_changes_mode = 1.
3346
3347 Example 1.118. t_msg_apply_changes usage
3348 ...
3349 msg_apply_changes_mode = 1;
3350 ...
3351 branch_route[OUT] {
3352 append_hf("X-Hdr: abc\n");
3353 t_msg_apply_changes();
3354 }
3355 ...
3356
3357 5. RPC Commands
3358
3359 5.1. tm.list
3360 5.2. tm.t_uac_start
3361 5.3. tm.t_uac_start_hex
3362 5.4. tm.t_uac_wait
3363 5.5. tm.t_uac_wait_hex
3364 5.6. tm.t_uac_wait_block
3365 5.7. tm.t_uac_wait_block_hex
3366 5.8. tm.t_uac_start_noack
3367 5.9. tm.t_uac_start_noack_hex
3368 5.10. tm.t_uac_wait_noack
3369 5.11. tm.t_uac_wait_noack_hex
3370 5.12. tm.t_uac_wait_block_noack
3371 5.13. tm.t_uac_wait_block_noack_hex
3372 5.14. tm.t_uac_attrs
3373 5.15. tm.cancel
3374 5.16. tm.hash_stats
3375 5.17. tm.reply
3376 5.18. tm.reply_callid
3377 5.19. tm.retransmit_reply
3378 5.20. tm.retransmit_reply_callid
3379 5.21. tm.clean
3380 5.22. tm.stats
3381
3382 5.1. tm.list
3383
3384 List details of transactions.
3385
3386 Parameters:
3387 * none
3388
3389 5.2. tm.t_uac_start
3390
3391 Generates and sends a local SIP request.
3392
3393 Parameters:
3394 * method - request method
3395 * RURI - request SIP URI
3396 * NEXT HOP - next hop SIP URI (OBP); use “.” if no value.
3397 * socket - local socket to be used for sending the request; use “.”
3398 if no value.
3399 * headers - set of additional headers to be added to the request; at
3400 least “From” and “To” headers must be provided)
3401 * body - (optional, may not be present) request body (if present,
3402 requires the “Content-Type” and “Content-length” headers)
3403
3404 5.3. tm.t_uac_start_hex
3405
3406 Similar to tm.t_uac_start, but with hexa-encoded body. The whitespaces
3407 are ignored when decoding the body.
3408
3409 5.4. tm.t_uac_wait
3410
3411 Similar to tm.t_uac_start, but waits asynchronously for the SIP
3412 response and tries to provide its details via RPC response.
3413
3414 5.5. tm.t_uac_wait_hex
3415
3416 Similar to tm.t_uac_wait, but with hexa-encoded body. The whitespaces
3417 are ignored when decoding the body.
3418
3419 5.6. tm.t_uac_wait_block
3420
3421 Similar to tm.t_uac_start, but blocks waiting for the SIP response and
3422 returns the SIP reply code and reason text via RPC response. It waits
3423 up to 80 seconds, if no reply is received, it returns a RPC fault 500
3424 code. While waiting, the RPC process cannot handle other RPC commands.
3425
3426 5.7. tm.t_uac_wait_block_hex
3427
3428 Similar to tm.t_uac_wait_block, but with hexa-encoded body. The
3429 whitespaces are ignored when decoding the body.
3430
3431 5.8. tm.t_uac_start_noack
3432
3433 Similar to tm.t_uac_start, but do not automatically send ACK for local
3434 INVITE requests.
3435
3436 5.9. tm.t_uac_start_noack_hex
3437
3438 Similar to tm.t_uac_start_noack, but with hexa-encoded body. The
3439 whitespaces are ignored when decoding the body.
3440
3441 5.10. tm.t_uac_wait_noack
3442
3443 Similar to tm.t_uac_wait, but do not automatically send ACK for local
3444 INVITE requests.
3445
3446 5.11. tm.t_uac_wait_noack_hex
3447
3448 Similar to tm.t_uac_wait_noack, but with hexa-encoded body. The
3449 whitespaces are ignored when decoding the body.
3450
3451 5.12. tm.t_uac_wait_block_noack
3452
3453 Similar to tm.t_uac_wait_block, but do not automatically send ACK for
3454 local INVITE requests.
3455
3456 5.13. tm.t_uac_wait_block_noack_hex
3457
3458 Similar to tm.t_uac_wait_block_noack, but with hexa-encoded body. The
3459 whitespaces are ignored when decoding the body.
3460
3461 5.14. tm.t_uac_attrs
3462
3463 Combine the tm.t_uac_* variants, by providing the first parameter with
3464 attributes, then the other parameters are like for tm.t_uac_start.
3465
3466 The attributes are in the format "name1=value1;...;nameX=valueX". The
3467 name of the attribute can be:
3468 * mode - control how the command is done. If not provided or the
3469 value is "start", acts like tm.t_uac_start. The other values can
3470 be: "wait" - act like tm.t_uac_wait; "block" - act like
3471 tm.t_uac_wait_block.
3472 * cbflags - the transaction callback flags. The values can be:
3473 "noack" - to not automatically send ACK for local INVITE requests
3474 * rpflags - RPC parameters flags. The values can be: 1 - the body is
3475 hexa-encoded value.
3476 * fr_timeout - the fr_timeout value for the local transaction.
3477 * fr_inv_timeout - the fr_inv_timeout value for the local
3478 transaction.
3479
3480 Example 1.119. Using “tm.t_uac_attrs”
3481 ...
3482 kamcli rpc tm.t_uac_attrs 'reply=wait;cbflags=noack;rpflags=1' 'INVITE' ...
3483 ...
3484
3485 5.15. tm.cancel
3486
3487 Generates and sends a CANCEL for an existing local SIP request.
3488
3489 Parameters:
3490 * callid - callid of the INVITE request to be cancelled.
3491 * cseq - cseq of the INVITE request to be cancelled.
3492
3493 5.16. tm.hash_stats
3494
3495 Gets information about the load of TM internal hash table.
3496
3497 Parameters:
3498 * none
3499
3500 5.17. tm.reply
3501
3502 Generates and sends a reply for an existing inbound SIP transaction.
3503
3504 Parameters:
3505 * code - reply code
3506 * reason - reason phrase.
3507 * trans_id - transaction identifier (has the hash_entry:label format)
3508 * to_tag - To tag to be added to TO header
3509 * new_headers - extra headers to be appended to the reply; use a dot
3510 (“.”) char only if there are no headers;
3511 * body - (optional, may not be present) reply body (if present,
3512 requires the “Content-Type” and “Content-length” headers)
3513
3514 5.18. tm.reply_callid
3515
3516 Generates and sends a reply for an existing inbound SIP transaction.
3517
3518 Parameters:
3519 * code - reply code
3520 * reason - reason phrase.
3521 * callid - SIP Call-ID header
3522 * cseq - SIP CSeq header
3523 * to_tag - To tag to be added to TO header
3524 * new_headers - extra headers to be appended to the reply; use a dot
3525 (“.”) char only if there are no headers;
3526 * body - (optional, may not be present) reply body (if present,
3527 requires the “Content-Type” and “Content-length” headers)
3528
3529 5.19. tm.retransmit_reply
3530
3531 Retransmit the reply for an existing SIP transaction.
3532
3533 Parameters:
3534 * trans_id - transaction identifier (has the hash_entry:label format)
3535
3536 Example 1.120. Using “tm.retransmit_reply”
3537 ...
3538 kamcli rpc tm.retransmit_reply 1234:5678
3539 ...
3540
3541 5.20. tm.retransmit_reply_callid
3542
3543 Retransmit the reply for an existing SIP transaction.
3544
3545 Parameters:
3546 * callid - SIP Call-ID header
3547 * cseq - SIP CSeq header
3548
3549 Example 1.121. Using “tm.retransmit_reply_callid”
3550 ...
3551 kamcli rpc tm.retransmit_reply_callid "abc-xyz" "10 INVITE"
3552 ...
3553
3554 5.21. tm.clean
3555
3556 Trigger a hard clean of expired transactions.
3557
3558 Parameters:
3559 * none
3560
3561 5.22. tm.stats
3562
3563 Gets information about current and past TM transaction handling.
3564
3565 Parameters:
3566 * none
3567
3568 6. Event Routes
3569
3570 6.1. event_route[tm:branch-failure:id]
3571 6.2. event_route[tm:local-request]
3572 6.3. event_route[tm:local-response]
3573 6.4. event_route[tm:local-ack-sent]
3574
3575 6.1. event_route[tm:branch-failure:id]
3576
3577 Named branch failure routes can be defined to run when a failure
3578 response is received. This allows handling failures on individual
3579 branches, for example, retrying an alternative outbound flow.
3580
3581 The format of the event_route name is "tm:branch-failure:<id>" and is
3582 enabled with the t_on_branch_failure function. This event_route uses
3583 the BRANCH_FAILURE_ROUTE route type.
3584
3585 Example 1.122. event_route[tm:branch-failure:id] usage
3586 ...
3587 request_route {
3588 ...
3589 t_on_branch_failure("myroute");
3590 t_relay();
3591 }
3592
3593 event_route[tm:branch-failure:myroute] {
3594 xlog("L_INFO", "Received $T_reply_code to $rm message\n");
3595 }
3596 ...
3597
3598 6.2. event_route[tm:local-request]
3599
3600 Executed when the tm module generates a request, in other words, the
3601 request originates from Kamailio and a transaction is created for it.
3602 The source of the requests can be tm itself or other modules that use
3603 tm internally (e.g., msilo, uac). The event route is executed if it is
3604 defined in the native Kamailio config file. To execute the equivalent
3605 callback when using KEMI scripting, see the 'event_callback' module
3606 parameter.
3607
3608 The request can still be updated, i.e., changes are possible to R-URI
3609 ($ru), destination URI ($du) or the send socket ($fs).
3610
3611 Example 1.123. event_route[tm:local-request] usage
3612 ...
3613 event_route [tm:local-request] {
3614 xlog("L_INFO", "Routing locally generated $rm to $ru\n");
3615 t_set_fr(10000, 10000);
3616 }
3617 ...
3618
3619 6.3. event_route[tm:local-response]
3620
3621 Executed after the tm module sent a local generated, transaction
3622 stateful response.
3623
3624 Example 1.124. event_route[tm:local-response] usage
3625 ...
3626 event_route[tm:local-response] {
3627 xlog("tm:local-response replied locally\n");
3628 }
3629 ...
3630
3631 6.4. event_route[tm:local-ack-sent]
3632
3633 Executed after the tm module sent the ACK of the 200ok for a local
3634 generated INVITE. It is executed with the received 200ok response.
3635
3636 Example 1.125. event_route[tm:local-ack-sent] usage
3637 ...
3638 event_route[tm:local-ack-sent] {
3639 xlog("ACK for local INVITE was sent\n");
3640 }
3641 ...
3642
3643 7. TM Module API
3644
3645 7.1. Defines
3646 7.2. Functions
3647
3648 7.2.1. register_tmcb(cb_type, cb_func)
3649 7.2.2. load_tm(*import_structure)
3650 7.2.3. int t_suspend(struct sip_msg *msg, unsigned int
3651 *hash_index, unsigned int *label)
3652
3653 7.2.4. int t_continue(unsigned int hash_index, unsigned int label,
3654 struct action *route)
3655
3656 7.2.5. int t_cancel_suspend(unsigned int hash_index, unsigned int
3657 label)
3658
3659 There are applications which would like to generate SIP transactions
3660 without too big involvement in SIP stack, transaction management, etc.
3661 An example of such an application is sending instant messages from a
3662 website. To address needs of such apps, SIP-router accepts requests for
3663 new transactions via the management interface. If you want to enable
3664 this feature, start the management interface server by configuring the
3665 proper modules.
3666
3667 An application can easily launch a new transaction by writing a
3668 transaction request to this interface. The request must follow very
3669 simple format, which for the basic FIFO interface is
3670 :t_uac_from:[<file_name>]\n
3671 <method>\n
3672 <sender's uri>\n
3673 <dst uri>\n
3674 <CR_separated_headers>\n
3675 <body>\n
3676 .\n
3677 \n
3678
3679 (Filename is to where a report will be dumped. ser assumes /tmp as
3680 file's directory.)
3681
3682 Note the request write must be atomic, otherwise it might get
3683 intermixed with writes from other writers. You can easily use it via
3684 Unix command-line tools, see the following example:
3685 [jiri@bat jiri]$ cat > /tmp/ser_fifo
3686 :t_uac_from:xxx
3687 MESSAGE
3688 sip:[email protected]
3689 sip:[email protected]
3690 header:value
3691 foo:bar
3692 bznk:hjhjk
3693 p_header: p_value
3694
3695 body body body
3696 yet body
3697 end of body
3698 .
3699
3700 or cat test/transaction.fifo > /tmp/ser_fifo
3701
3702 7.1. Defines
3703
3704 * ACK_TAG enables stricter matching of acknowledgments including
3705 to-tags. Without it, to-tags are ignored. It is disabled by default
3706 for two reasons:
3707 + It eliminates an unlikely race condition in which
3708 transaction's to-tag is being rewritten by a 200 OK whereas an
3709 ACK is being looked up by to-tag.
3710 + It makes UACs happy who set wrong to-tags.
3711 It should not make a difference, as there may be only one negative
3712 reply sent upstream and 200/ACKs are not matched as they constitute
3713 another transaction. It will make no difference at all when the new
3714 magic cookie matching is enabled anyway.
3715 * CANCEL_TAG similarly enables strict matching of CANCELs including
3716 to-tags--act of mercy to UACs, who screw up the to-tags (however,
3717 it still depends on how forgiving the downstream UAS is). Like with
3718 ACK_TAG, all this complex transactions matching goes with RFC3261's
3719 magic cookie away anyway.
3720
3721 7.2. Functions
3722
3723 7.2.1. register_tmcb(cb_type, cb_func)
3724
3725 For programmatic use only--register a function to be called back on an
3726 event. See t_hooks.h for more details.
3727
3728 Meaning of the parameters is as follows:
3729 * cb_type - Callback type.
3730 * cb_func - Callback function.
3731
3732 7.2.2. load_tm(*import_structure)
3733
3734 For programmatic use only--import exported TM functions. See the acc
3735 module for an example of use.
3736
3737 Meaning of the parameters is as follows:
3738 * import_structure - Pointer to the import structure.
3739
3740 7.2.3. int t_suspend(struct sip_msg *msg, unsigned int *hash_index, unsigned
3741 int *label)
3742
3743 For programmatic use only. This function together with t_continue() can
3744 be used to implement asynchronous actions: t_suspend() saves the
3745 transaction, returns its identifiers, and t_continue() continues the
3746 SIP request/response processing. (The request/response processing does
3747 not continue from the same point in the script, a separate route block
3748 defined by the parameter of t_continue() is executed instead. The reply
3749 lock is held during the route block execution.) FR timer is ticking
3750 while the transaction is suspended, and the transaction's failure route
3751 is executed if t_continue() is not called in time.
3752
3753 Missing: message lumps are saved by t_suspend() and are not updated by
3754 the subsequent t_relay(). This means that the modifications made
3755 between them are lost.
3756
3757 Meaning of the parameters is as follows:
3758 * msg - SIP message pointer.
3759 * hash_index - transaction identifier.
3760 * label - transaction identifier.
3761
3762 Return value: 0 - success, <0 - error.
3763
3764 Usage: Allocate a memory block for storing the transaction identifiers
3765 (hash_index and label), and for storing also any variable related to
3766 the async query. Before calling t_suspend(), register for the following
3767 callbacks, and pass the pointer to the allocated shared memory as a
3768 parameter: TMCB_ON_FAILURE, TMCB_DESTROY, and TMCB_E2ECANCEL_IN (in
3769 case of INVITE transaction). The async operation can be cancelled, if
3770 it is still pending, when TMCB_ON_FAILURE or TMCB_E2ECANCEL_IN is
3771 called. TMCB_DESTROY is suitable to free the shared memory allocated
3772 for the async and SIP transaction identifiers. Once the async query
3773 result is available call t_continue(), see below. The SIP transaction
3774 must exist before calling t_suspend(), and the module function calling
3775 t_suspend() should return 0 to make sure that the script processing
3776 does not continue.
3777
3778 7.2.4. int t_continue(unsigned int hash_index, unsigned int label, struct
3779 action *route)
3780
3781 For programmatic use only. This function is the pair of t_suspend(),
3782 and is supposed to be called when the asynchronous query result is
3783 available. The function executes a route block with the saved SIP
3784 message. It is possible to add more branches to the transaction, or
3785 send a reply from the route block.
3786
3787 Meaning of the parameters is as follows:
3788 * hash_index - transaction identifier.
3789 * label - transaction identifier.
3790 * route - route block to execute.
3791
3792 Return value: 0 - success, <0 - error.
3793
3794 7.2.5. int t_cancel_suspend(unsigned int hash_index, unsigned int label)
3795
3796 For programmatic use only. This function is for revoking t_suspend()
3797 from the same process as it was executed before. t_cancel_suspend() can
3798 be used when something fails after t_suspend() has already been
3799 executed and it turns out that the transaction should not have been
3800 suspended. The function cancels the FR timer of the transaction.
3801
3802 The message lumps are saved by t_suspend() which cannot be restored.
3803
3804 Meaning of the parameters is as follows:
3805 * hash_index - transaction identifier.
3806 * label - transaction identifier.
3807
3808 Return value: 0 - success, <0 - error.
3809
3810 8. Known Issues
3811
3812 * Possibly, performance could be improved by not parsing non-INVITEs,
3813 as they are not replied with 100, and do not result in ACK/CANCELs,
3814 and other things which take parsing. However, we need to rethink
3815 whether we don't need parsed headers later for something else.
3816 Remember, when we now store a request in sh_mem, we can't apply any
3817 pkg_mem operations to it any more. (that might be redesigned too).
3818 * Another performance improvement may be achieved by not parsing CSeq
3819 in replies until reply branch matches branch of an INVITE/CANCEL in
3820 transaction table.
3821 * t_replicate should be done more cleanly--Vias, Routes, etc. should
3822 be removed from a message prior to replicating it (well, does not
3823 matter any longer so much as there is a new replication module).