Browse Source

on_sl_reply module parameter is introduced:
It defines the route block that is called if a reply with no associated
transaction is received.
Closes SER-330

Miklos Tirpak 17 years ago
parent
commit
6d05820c8c
4 changed files with 59 additions and 4 deletions
  1. 24 1
      modules/tm/doc/params.xml
  2. 17 2
      modules/tm/t_reply.c
  3. 2 0
      modules/tm/t_reply.h
  4. 16 1
      modules/tm/tm.c

+ 24 - 1
modules/tm/doc/params.xml

@@ -511,7 +511,30 @@ modparam("tm", "cancel_b_method", 1)
 modparam("tm", "reparse_on_dns_failover", 0)
 ...
 	    </programlisting>
-       </example>
+	</example>
+    </section>
+
+    <section id="on_sl_reply">
+	<title><varname>on_sl_reply</varname> (string)</title>
+	<para>
+		Sets reply route block, to which control is passed when a
+		reply is received that has no associated transaction.
+		The reply is passed to the core for stateless forwarding after
+		the route block execution unless it returns 0.
+	</para>
+	<example>
+	    <title>Set <varname>on_sl_reply</varname> parameter</title>
+	    <programlisting>
+...
+modparam("tm", "on_sl_reply", "stateless_replies")
+...
+
+onreply_route["stateless_replies"] {
+	# do not allow stateless replies to be forwarded
+	return 0;
+}
+	    </programlisting>
+	</example>
     </section>
 
 </section>

+ 17 - 2
modules/tm/t_reply.c

@@ -147,6 +147,8 @@ char *tm_tag_suffix;
 static int goto_on_negative=0;
 /* where to go on receipt of reply */
 static int goto_on_reply=0;
+/* where to go on receipt of reply without transaction context */
+int goto_on_sl_reply=0;
 
 
 /* responses priority (used by t_pick_branch)
@@ -1712,10 +1714,11 @@ int reply_received( struct sip_msg  *p_msg )
 
 	/* make sure we know the associated transaction ... */
 	if (t_check( p_msg  , &branch )==-1)
-		return 1;
+		goto trans_not_found;
 	/*... if there is none, tell the core router to fwd statelessly */
 	t=get_t();
-	if ( (t==0)||(t==T_UNDEFINED)) return 1;
+	if ( (t==0)||(t==T_UNDEFINED))
+		goto trans_not_found;
 
 	cancel_bitmap=0;
 	msg_status=p_msg->REPLY_STATUS;
@@ -1960,6 +1963,18 @@ done:
 	   simply do nothing; that will make the other party to
 	   retransmit; hopefuly, we'll then be better off */
 	return 0;
+
+trans_not_found:
+	/* transaction context was not found */
+	if (goto_on_sl_reply) {
+		/* the script writer has a chance to decide whether to
+		forward the reply or not */
+		init_run_actions_ctx(&ra_ctx);
+		return run_actions(&ra_ctx, onreply_rt.rlist[goto_on_sl_reply], p_msg);
+	} else {
+		/* let the core forward the reply */
+		return 1;
+	}
 }
 
 

+ 2 - 0
modules/tm/t_reply.h

@@ -56,6 +56,8 @@ enum rps {
 extern char tm_tags[TOTAG_VALUE_LEN];
 extern char *tm_tag_suffix;
 
+extern int goto_on_sl_reply;
+
 enum route_mode { MODE_REQUEST=1, MODE_ONREPLY, MODE_ONFAILURE };
 extern enum route_mode rmode;
 

+ 16 - 1
modules/tm/tm.c

@@ -135,7 +135,7 @@ static int fixup_on_failure(void** param, int param_no);
 static int fixup_on_reply(void** param, int param_no);
 static int fixup_on_branch(void** param, int param_no);
 static int fixup_t_reply(void** param, int param_no);
-
+static int fixup_on_sl_reply(modparam_t type, void* val);
 
 /* init functions */
 static int mod_init(void);
@@ -387,6 +387,7 @@ static param_export_t params[]={
 	{"blst_methods_lookup", PARAM_INT, &default_tm_cfg.tm_blst_methods_lookup},
 	{"cancel_b_method",     PARAM_INT, &default_tm_cfg.cancel_b_flags},
 	{"reparse_on_dns_failover", PARAM_INT, &default_tm_cfg.reparse_on_dns_failover},
+	{"on_sl_reply",         PARAM_STRING|PARAM_USE_FUNC, fixup_on_sl_reply   },
 	{0,0,0}
 };
 
@@ -471,6 +472,20 @@ static int fixup_on_branch(void** param, int param_no)
 	return 0;
 }
 
+static int fixup_on_sl_reply(modparam_t type, void* val)
+{
+	if ((type & PARAM_STRING) == 0) {
+		LOG(L_ERR, "ERROR: tm: fixup_on_sl_reply: not a string parameter\n");
+		return -1;
+	}
+
+	if (fixup_routes("on_sl_reply", &onreply_rt, &val))
+		return -1;
+
+	goto_on_sl_reply = (int)(long)val;
+	return 0;
+}
+
 
 
 /* (char *hostname, char *port_nr) ==> (struct proxy_l *, -)  */