瀏覽代碼

tm: new config parameter - remap_503_500

- option to disable remapping of 503 response code to 500
Daniel-Constantin Mierla 13 年之前
父節點
當前提交
ca57c86315
共有 4 個文件被更改,包括 83 次插入39 次删除
  1. 54 38
      modules/tm/README
  2. 22 0
      modules/tm/doc/params.xml
  3. 4 1
      modules/tm/t_reply.c
  4. 3 0
      modules/tm/tm.c

+ 54 - 38
modules/tm/README

@@ -58,6 +58,7 @@ Juha Heinanen
         1.4.38. faked_reply_prio (integer)
         1.4.38. faked_reply_prio (integer)
         1.4.39. local_cancel_reason (boolean)
         1.4.39. local_cancel_reason (boolean)
         1.4.40. e2e_cancel_reason (boolean)
         1.4.40. e2e_cancel_reason (boolean)
+        1.4.41. remap_503_500 (boolean)
 
 
    1.5. Functions
    1.5. Functions
 
 
@@ -1188,6 +1189,21 @@ modparam("tm", "local_cancel_reason", 0)
 modparam("tm", "e2e_cancel_reason", 0)
 modparam("tm", "e2e_cancel_reason", 0)
 ...
 ...
 
 
+1.4.41. remap_503_500 (boolean)
+
+   Enables/disables conversion of 503 response code to 500. By default it
+   is enabled, based on the SIP RFC requirement. This is global setting
+   for all received replies handled by TM. To do it per transaction basis,
+   let this option disabled, set a failure route and then do
+   t_reply("500", "...") inside it.
+
+   Default value is 1 (enabled).
+
+   Example 41. Set remap_503_500 parameter
+...
+modparam("tm", "remap_503_500", 0)
+...
+
 1.5. Functions
 1.5. Functions
 
 
 1.5.1. t_relay([host, port])
 1.5.1. t_relay([host, port])
@@ -1209,7 +1225,7 @@ modparam("tm", "e2e_cancel_reason", 0)
    Returns a negative value on failure -- you may still want to send a
    Returns a negative value on failure -- you may still want to send a
    negative reply upstream statelessly not to leave upstream UAC in lurch.
    negative reply upstream statelessly not to leave upstream UAC in lurch.
 
 
-   Example 41. t_relay usage
+   Example 42. t_relay usage
 ...
 ...
 if (!t_relay())
 if (!t_relay())
 {
 {
@@ -1236,7 +1252,7 @@ if (!t_relay())
    derived from the message uri (using sip sepcific DNS lookups), but with
    derived from the message uri (using sip sepcific DNS lookups), but with
    the protocol corresponding to the function name.
    the protocol corresponding to the function name.
 
 
-   Example 42. t_relay_to_udp usage
+   Example 43. t_relay_to_udp usage
 ...
 ...
 if (src_ip==10.0.0.0/8)
 if (src_ip==10.0.0.0/8)
         t_relay_to_udp("1.2.3.4", "5060"); # sent to 1.2.3.4:5060 over udp
         t_relay_to_udp("1.2.3.4", "5060"); # sent to 1.2.3.4:5060 over udp
@@ -1276,7 +1292,7 @@ else
    Meaning of the parameters is as follows:
    Meaning of the parameters is as follows:
      * failure_route - Failure route block to be called.
      * failure_route - Failure route block to be called.
 
 
-   Example 43. t_on_failure usage
+   Example 44. t_on_failure usage
 ...
 ...
 route {
 route {
     t_on_failure("1");
     t_on_failure("1");
@@ -1302,7 +1318,7 @@ failure_route[1] {
    Meaning of the parameters is as follows:
    Meaning of the parameters is as follows:
      * onreply_route - Onreply route block to be called.
      * onreply_route - Onreply route block to be called.
 
 
-   Example 44. t_on_reply usage
+   Example 45. t_on_reply usage
 ...
 ...
 loadmodule "/usr/local/lib/ser/modules/nathelper.so"
 loadmodule "/usr/local/lib/ser/modules/nathelper.so"
 ...
 ...
@@ -1334,7 +1350,7 @@ es');
    Meaning of the parameters is as follows:
    Meaning of the parameters is as follows:
      * branch_route - branch route block to be called.
      * branch_route - branch route block to be called.
 
 
-   Example 45. t_on_branch usage
+   Example 46. t_on_branch usage
 ...
 ...
 route {
 route {
         t_on_branch("1");
         t_on_branch("1");
@@ -1353,7 +1369,7 @@ branch_route[1] {
    the only way a script can add a new transaction in an atomic way.
    the only way a script can add a new transaction in an atomic way.
    Typically, it is used to deploy a UAS.
    Typically, it is used to deploy a UAS.
 
 
-   Example 46. t_newtran usage
+   Example 47. t_newtran usage
 ...
 ...
 if (t_newtran()) {
 if (t_newtran()) {
     log("UAS logic");
     log("UAS logic");
@@ -1372,7 +1388,7 @@ if (t_newtran()) {
      * code - Reply code number.
      * code - Reply code number.
      * reason_phrase - Reason string.
      * reason_phrase - Reason string.
 
 
-   Example 47. t_reply usage
+   Example 48. t_reply usage
 ...
 ...
 t_reply("404", "Not found");
 t_reply("404", "Not found");
 ...
 ...
@@ -1385,7 +1401,7 @@ t_reply("404", "Not found");
    none was found. However this is safely (atomically) done using
    none was found. However this is safely (atomically) done using
    t_newtran.
    t_newtran.
 
 
-   Example 48. t_lookup_request usage
+   Example 49. t_lookup_request usage
 ...
 ...
 if (t_lookup_request()) {
 if (t_lookup_request()) {
     ...
     ...
@@ -1396,7 +1412,7 @@ if (t_lookup_request()) {
 
 
    Retransmits a reply sent previously by UAS transaction.
    Retransmits a reply sent previously by UAS transaction.
 
 
-   Example 49. t_retransmit_reply usage
+   Example 50. t_retransmit_reply usage
 ...
 ...
 t_retransmit_reply();
 t_retransmit_reply();
 ...
 ...
@@ -1406,7 +1422,7 @@ t_retransmit_reply();
    Remove transaction from memory (it will be first put on a wait timer to
    Remove transaction from memory (it will be first put on a wait timer to
    absorb delayed messages).
    absorb delayed messages).
 
 
-   Example 50. t_release usage
+   Example 51. t_release usage
 ...
 ...
 t_release();
 t_release();
 ...
 ...
@@ -1420,7 +1436,7 @@ t_release();
      * ip - IP address where the message should be sent.
      * ip - IP address where the message should be sent.
      * port - Port number.
      * port - Port number.
 
 
-   Example 51. t_forward_nonack usage
+   Example 52. t_forward_nonack usage
 ...
 ...
 t_forward_nonack("1.2.3.4", "5060");
 t_forward_nonack("1.2.3.4", "5060");
 ...
 ...
@@ -1459,7 +1475,7 @@ t_forward_nonack("1.2.3.4", "5060");
 
 
    See also: fr_timer, fr_inv_timer, t_reset_fr().
    See also: fr_timer, fr_inv_timer, t_reset_fr().
 
 
-   Example 52. t_set_fr usage
+   Example 53. t_set_fr usage
 ...
 ...
 route {
 route {
         t_set_fr(10000); # set only fr invite timeout to 10s
         t_set_fr(10000); # set only fr invite timeout to 10s
@@ -1486,7 +1502,7 @@ branch_route[1] {
 
 
    See also: fr_timer, fr_inv_timer, t_set_fr.
    See also: fr_timer, fr_inv_timer, t_set_fr.
 
 
-   Example 53. t_reset_fr usage
+   Example 54. t_reset_fr usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -1512,7 +1528,7 @@ route {
 
 
    See also: max_inv_lifetime, max_noninv_lifetime, t_reset_max_lifetime.
    See also: max_inv_lifetime, max_noninv_lifetime, t_reset_max_lifetime.
 
 
-   Example 54. t_set_max_lifetime usage
+   Example 55. t_set_max_lifetime usage
 ...
 ...
 route {
 route {
     if (src_ip=1.2.3.4)
     if (src_ip=1.2.3.4)
@@ -1534,7 +1550,7 @@ route {
 
 
    See also: max_inv_lifetime, max_noninv_lifetime, t_set_max_lifetime.
    See also: max_inv_lifetime, max_noninv_lifetime, t_set_max_lifetime.
 
 
-   Example 55. t_reset_max_lifetime usage
+   Example 56. t_reset_max_lifetime usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -1572,7 +1588,7 @@ route {
 
 
    See also: retr_timer1, retr_timer2, t_reset_retr().
    See also: retr_timer1, retr_timer2, t_reset_retr().
 
 
-   Example 56. t_set_retr usage
+   Example 57. t_set_retr usage
 ...
 ...
 route {
 route {
         t_set_retr(250, 0); # set only T1 to 250 ms
         t_set_retr(250, 0); # set only T1 to 250 ms
@@ -1599,7 +1615,7 @@ branch_route[1] {
 
 
    See also: retr_timer1, retr_timer2, t_set_retr.
    See also: retr_timer1, retr_timer2, t_set_retr.
 
 
-   Example 57. t_reset_retr usage
+   Example 58. t_reset_retr usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -1615,7 +1631,7 @@ route {
 
 
    See also: auto_inv_100.
    See also: auto_inv_100.
 
 
-   Example 58. t_set_auto_inv_100 usage
+   Example 59. t_set_auto_inv_100 usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -1629,7 +1645,7 @@ route {
    Returns true if the failure route is executed for a branch that did
    Returns true if the failure route is executed for a branch that did
    timeout. It can be used only from the failure_route.
    timeout. It can be used only from the failure_route.
 
 
-   Example 59. t_branch_timeout usage
+   Example 60. t_branch_timeout usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (t_branch_timeout()){
         if (t_branch_timeout()){
@@ -1644,7 +1660,7 @@ failure_route[0]{
    receive at least one reply in the past (the "current" reply is not
    receive at least one reply in the past (the "current" reply is not
    taken into account). It can be used only from the failure_route.
    taken into account). It can be used only from the failure_route.
 
 
-   Example 60. t_branch_replied usage
+   Example 61. t_branch_replied usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (t_branch_timeout()){
         if (t_branch_timeout()){
@@ -1661,7 +1677,7 @@ failure_route[0]{
    Returns true if at least one of the current transactions branches did
    Returns true if at least one of the current transactions branches did
    timeout.
    timeout.
 
 
-   Example 61. t_any_timeout usage
+   Example 62. t_any_timeout usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (!t_branch_timeout()){
         if (!t_branch_timeout()){
@@ -1678,7 +1694,7 @@ failure_route[0]{
    receive some reply in the past. If called from a failure or onreply
    receive some reply in the past. If called from a failure or onreply
    route, the "current" reply is not taken into account.
    route, the "current" reply is not taken into account.
 
 
-   Example 62. t_any_replied usage
+   Example 63. t_any_replied usage
 ...
 ...
 onreply_route[0]{
 onreply_route[0]{
         if (!t_any_replied()){
         if (!t_any_replied()){
@@ -1692,7 +1708,7 @@ onreply_route[0]{
    Returns true if "code" is the final reply received (or locally
    Returns true if "code" is the final reply received (or locally
    generated) in at least one of the current transactions branches.
    generated) in at least one of the current transactions branches.
 
 
-   Example 63. t_grep_status usage
+   Example 64. t_grep_status usage
 ...
 ...
 onreply_route[0]{
 onreply_route[0]{
         if (t_grep_status("486")){
         if (t_grep_status("486")){
@@ -1705,7 +1721,7 @@ onreply_route[0]{
 
 
    Returns true if the current transaction was canceled.
    Returns true if the current transaction was canceled.
 
 
-   Example 64. t_is_canceled usage
+   Example 65. t_is_canceled usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (t_is_canceled()){
         if (t_is_canceled()){
@@ -1719,7 +1735,7 @@ failure_route[0]{
    Returns true if the current transaction has already been expired, i.e.
    Returns true if the current transaction has already been expired, i.e.
    the max_inv_lifetime/max_noninv_lifetime interval has already elapsed.
    the max_inv_lifetime/max_noninv_lifetime interval has already elapsed.
 
 
-   Example 65. t_is_expired usage
+   Example 66. t_is_expired usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (t_is_expired()){
         if (t_is_expired()){
@@ -1740,7 +1756,7 @@ failure_route[0]{
    CANCELs were successfully sent to the pending branches, true if the
    CANCELs were successfully sent to the pending branches, true if the
    INVITE was not found, and false in case of any error.
    INVITE was not found, and false in case of any error.
 
 
-   Example 66. t_relay_cancel usage
+   Example 67. t_relay_cancel usage
 if (method == CANCEL) {
 if (method == CANCEL) {
         if (!t_relay_cancel()) {  # implicit drop if relaying was successful,
         if (!t_relay_cancel()) {  # implicit drop if relaying was successful,
                                   # nothing to do
                                   # nothing to do
@@ -1767,7 +1783,7 @@ if (method == CANCEL) {
    overwritten with the flags of the INVITE. isflagset() can be used to
    overwritten with the flags of the INVITE. isflagset() can be used to
    check the flags of the previously forwarded INVITE in this case.
    check the flags of the previously forwarded INVITE in this case.
 
 
-   Example 67. t_lookup_cancel usage
+   Example 68. t_lookup_cancel usage
 if (method == CANCEL) {
 if (method == CANCEL) {
         if (t_lookup_cancel()) {
         if (t_lookup_cancel()) {
                 log("INVITE transaction exists");
                 log("INVITE transaction exists");
@@ -1797,7 +1813,7 @@ if (method == CANCEL) {
    Dropping replies works only if a new branch is added to the
    Dropping replies works only if a new branch is added to the
    transaction, or it is explicitly replied in the script!
    transaction, or it is explicitly replied in the script!
 
 
-   Example 68. t_drop_replies() usage
+   Example 69. t_drop_replies() usage
 ...
 ...
 failure_route[0]{
 failure_route[0]{
         if (t_check_status("5[0-9][0-9]")){
         if (t_check_status("5[0-9][0-9]")){
@@ -1828,7 +1844,7 @@ failure_route[0]{
    The transaction must be created by t_newtran() before calling
    The transaction must be created by t_newtran() before calling
    t_save_lumps().
    t_save_lumps().
 
 
-   Example 69. t_save_lumps() usage
+   Example 70. t_save_lumps() usage
 route {
 route {
         ...
         ...
         t_newtran();
         t_newtran();
@@ -1898,7 +1914,7 @@ failure_route[1] {
 
 
    This function can be used from REQUEST_ROUTE.
    This function can be used from REQUEST_ROUTE.
 
 
-   Example 70. t_load_contacts usage
+   Example 71. t_load_contacts usage
 ...
 ...
 if (!t_load_contacts()) {
 if (!t_load_contacts()) {
         sl_send_reply("500", "Server Internal Error - Cannot load contacts");
         sl_send_reply("500", "Server Internal Error - Cannot load contacts");
@@ -1939,7 +1955,7 @@ if (!t_load_contacts()) {
    anymore set. Based on that test, you can then use t_set_fr() function
    anymore set. Based on that test, you can then use t_set_fr() function
    to set timers according to your needs.
    to set timers according to your needs.
 
 
-   Example 71. t_next_contacts usage
+   Example 72. t_next_contacts usage
 ...
 ...
 # First call after t_load_contacts() when transaction does not exist yet
 # First call after t_load_contacts() when transaction does not exist yet
 # and contacts should be available
 # and contacts should be available
@@ -2003,7 +2019,7 @@ Note
 
 
    See also: t_lookup_request(), t_lookup_cancel().
    See also: t_lookup_request(), t_lookup_cancel().
 
 
-   Example 72. t_check_trans usage
+   Example 73. t_check_trans usage
 if ( method == "CANCEL" && !t_check_trans())
 if ( method == "CANCEL" && !t_check_trans())
         sl_reply("403", "cancel out of the blue forbidden");
         sl_reply("403", "cancel out of the blue forbidden");
 # note: in this example t_check_trans() can be replaced by t_lookup_cancel()
 # note: in this example t_check_trans() can be replaced by t_lookup_cancel()
@@ -2018,7 +2034,7 @@ if ( method == "CANCEL" && !t_check_trans())
 
 
    See also: disable_6xx_block.
    See also: disable_6xx_block.
 
 
-   Example 73. t_set_disable_6xx usage
+   Example 74. t_set_disable_6xx usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -2033,7 +2049,7 @@ route {
 
 
    See also: use_dns_failover.
    See also: use_dns_failover.
 
 
-   Example 74. t_set_disable_failover usage
+   Example 75. t_set_disable_failover usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -2064,7 +2080,7 @@ route {
      * hostport - address in "host:port" format. It can be given via an
      * hostport - address in "host:port" format. It can be given via an
        AVP.
        AVP.
 
 
-   Example 75. t_replicate usage
+   Example 76. t_replicate usage
 ...
 ...
 # sent to 1.2.3.4:5060 over tcp
 # sent to 1.2.3.4:5060 over tcp
 t_replicate("sip:1.2.3.4:5060;transport=tcp");
 t_replicate("sip:1.2.3.4:5060;transport=tcp");
@@ -2099,7 +2115,7 @@ t_replicate_to_udp("1.2.3.4", "5060");
             effect anymore).
             effect anymore).
           + 0x04 - disable dns failover.
           + 0x04 - disable dns failover.
 
 
-   Example 76. t_replicate usage
+   Example 77. t_replicate usage
 ...
 ...
 # sent to 1.2.3.4:5060 over tcp
 # sent to 1.2.3.4:5060 over tcp
 t_relay_to("tcp:1.2.3.4:5060");
 t_relay_to("tcp:1.2.3.4:5060");
@@ -2122,7 +2138,7 @@ t_relay_to("0x01");
 
 
    See also: e2e_cancel_reason.
    See also: e2e_cancel_reason.
 
 
-   Example 77. t_set_no_e2e_cancel_reason usage
+   Example 78. t_set_no_e2e_cancel_reason usage
 ...
 ...
 route {
 route {
 ...
 ...
@@ -2145,7 +2161,7 @@ opying
      * onreply_route - the function returns true if an onreply route is
      * onreply_route - the function returns true if an onreply route is
        set to be executed.
        set to be executed.
 
 
-   Example 78. t_replicate usage
+   Example 79. t_replicate usage
 ...
 ...
 if(!t_is_set("failure_route"))
 if(!t_is_set("failure_route"))
     LM_DBG("no failure route will be executed for current transaction\n");
     LM_DBG("no failure route will be executed for current transaction\n");

+ 22 - 0
modules/tm/doc/params.xml

@@ -1265,6 +1265,28 @@ modparam("tm", "local_cancel_reason", 0)
 			<programlisting>
 			<programlisting>
 ...
 ...
 modparam("tm", "e2e_cancel_reason", 0)
 modparam("tm", "e2e_cancel_reason", 0)
+...
+			</programlisting>
+		</example>
+	</section>
+
+	<section id="remap_503_500">
+		<title><varname>remap_503_500</varname> (boolean)</title>
+		<para>
+			Enables/disables conversion of 503 response code to 500. By default
+			it is enabled, based on the SIP RFC requirement. This is global
+			setting for all received replies handled by TM. To do it per
+			transaction basis, let this option disabled, set a failure route
+			and then do t_reply("500", "...") inside it.
+		</para>
+		<para>
+			Default value is 1 (enabled).
+		</para>
+		<example>
+			<title>Set <varname>remap_503_500</varname> parameter</title>
+			<programlisting>
+...
+modparam("tm", "remap_503_500", 0)
 ...
 ...
 			</programlisting>
 			</programlisting>
 		</example>
 		</example>

+ 4 - 1
modules/tm/t_reply.c

@@ -177,6 +177,9 @@ static int goto_on_reply=0;
 /* where to go on receipt of reply without transaction context */
 /* where to go on receipt of reply without transaction context */
 int goto_on_sl_reply=0;
 int goto_on_sl_reply=0;
 
 
+/* remap 503 response code to 500 */
+extern int tm_remap_503_500;
+
 /* how to deal with winning branch reply selection in failure_route
 /* how to deal with winning branch reply selection in failure_route
  * can be overwritten per transaction with t_drop_replies(...)
  * can be overwritten per transaction with t_drop_replies(...)
  * Values:
  * Values:
@@ -1759,7 +1762,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
 			}
 			}
 		} else {
 		} else {
 			relayed_code=relayed_msg->REPLY_STATUS;
 			relayed_code=relayed_msg->REPLY_STATUS;
-			if (relayed_code==503){
+			if (relayed_code==503 && tm_remap_503_500){
 				/* replace a final 503 with a 500:
 				/* replace a final 503 with a 500:
 				 * generate a "FAKE" reply and a new to_tag (for easier
 				 * generate a "FAKE" reply and a new to_tag (for easier
 				 *  debugging)*/
 				 *  debugging)*/

+ 3 - 0
modules/tm/tm.c

@@ -308,6 +308,8 @@ static char *fr_timer_param = 0 /*FR_TIMER_AVP*/;
 static char *fr_inv_timer_param = 0 /*FR_INV_TIMER_AVP*/;
 static char *fr_inv_timer_param = 0 /*FR_INV_TIMER_AVP*/;
 static char *contacts_avp_param = 0;
 static char *contacts_avp_param = 0;
 
 
+int tm_remap_503_500 = 1;
+
 static rpc_export_t tm_rpc[];
 static rpc_export_t tm_rpc[];
 
 
 static int fixup_t_check_status(void** param, int param_no);
 static int fixup_t_check_status(void** param, int param_no);
@@ -522,6 +524,7 @@ static param_export_t params[]={
 	{"local_ack_mode",      PARAM_INT, &default_tm_cfg.local_ack_mode        },
 	{"local_ack_mode",      PARAM_INT, &default_tm_cfg.local_ack_mode        },
 	{"failure_reply_mode",  PARAM_INT, &failure_reply_mode                   },
 	{"failure_reply_mode",  PARAM_INT, &failure_reply_mode                   },
 	{"faked_reply_prio",    PARAM_INT, &faked_reply_prio                     },
 	{"faked_reply_prio",    PARAM_INT, &faked_reply_prio                     },
+	{"remap_503_500",       PARAM_INT, &tm_remap_503_500                     },
 #ifdef CANCEL_REASON_SUPPORT
 #ifdef CANCEL_REASON_SUPPORT
 	{"local_cancel_reason", PARAM_INT, &default_tm_cfg.local_cancel_reason   },
 	{"local_cancel_reason", PARAM_INT, &default_tm_cfg.local_cancel_reason   },
 	{"e2e_cancel_reason",   PARAM_INT, &default_tm_cfg.e2e_cancel_reason     },
 	{"e2e_cancel_reason",   PARAM_INT, &default_tm_cfg.e2e_cancel_reason     },