[asterisk-bugs] [Asterisk 0018813]: [patch] Session timer refresher incorrect

Asterisk Bug Tracker noreply at bugs.digium.com
Thu Feb 17 09:55:20 CST 2011


A NOTE has been added to this issue. 
====================================================================== 
https://issues.asterisk.org/view.php?id=18813 
====================================================================== 
Reported By:                nohara
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   18813
Category:                   Channels/chan_sip/Interoperability
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     needs license
Asterisk Version:           1.6.2.16.1 
JIRA:                        
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2011-02-15 05:55 CST
Last Modified:              2011-02-17 09:55 CST
====================================================================== 
Summary:                    [patch] Session timer refresher incorrect
Description: 
Asterisk appears to request a refresher role swap relative to the original
refresher roles established in the initial INVITE that set up the
session/dialog, but does not actually perform the refreshes.  


GW -(1)-> Asterisk --> UA

(1)
In the 200 OK that establishes the dialog (the response to the initial
INVITE),
Asterisk sends the SST headers:

    Supported: timer
    Session-Expires: 180;refresher=uac

This establishes the UAC (the GW) as the refresher for this session. 
Asterisk sends a reinvite to the GW by canreinvite with the following
headers:

    Require: timer
    Session-Expires: 180;refresher=uac

This establishes the UAC (Asterisk ) as the refresher for this session. 
Asterisk does not, however, actually send any reinvites.

It looks like issue 18127.
https://issues.asterisk.org/view.php?id=18127

====================================================================== 

---------------------------------------------------------------------- 
 (0132082) nohara (reporter) - 2011-02-17 09:55
 https://issues.asterisk.org/view.php?id=18813#c132082 
---------------------------------------------------------------------- 
I'm sorry. 
I signed the license.
Please check the chan_sip_sample.c.


$ diff -u chan_sip.c chan_sip_sample.c
--- chan_sip.c	2011-02-18 00:47:12.282779200 +0900
+++ chan_sip_sample.c	2011-02-18 00:49:35.178252800 +0900
@@ -1515,6 +1515,7 @@
 	int st_active_peer_ua;                  /*!< Session-Timers on/off in
peer UA */
 	int st_cached_min_se;                   /*!< Session-Timers cached
Min-SE */
 	int st_cached_max_se;                   /*!< Session-Timers cached
Session-Expires */
+	int st_refresher_self;                  /*!< Session-Timers session
refresher is self */
 	enum st_mode st_cached_mode;            /*!< Session-Timers cached M.O.
*/
 	enum st_refresher st_cached_ref;        /*!< Session-Timers cached
refresher */
 	unsigned char quit_flag:1;              /*!< Stop trying to lock; just
quit */
@@ -9731,6 +9732,11 @@
 	*/
 	if (p->stimer && p->stimer->st_active == TRUE &&
p->stimer->st_active_peer_ua == TRUE 
 	    && sipmethod == SIP_INVITE) {
+		if (p->stimer->st_refresher_self == TRUE) {
+			p->stimer->st_ref = SESSION_TIMER_REFRESHER_UAC;
+		} else {
+			p->stimer->st_ref = SESSION_TIMER_REFRESHER_UAS;
+		}
 		char se_hdr[256];
 		snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s",
p->stimer->st_interval, 
 			strefresher2str(p->stimer->st_ref));
@@ -17964,7 +17970,7 @@
 		}
 
 		/* Check for Session-Timers related headers */
-		if (st_get_mode(p) != SESSION_TIMER_MODE_REFUSE && p->outgoing_call ==
TRUE && !reinvite) {
+		if (st_get_mode(p) != SESSION_TIMER_MODE_REFUSE) {
 			p_hdrval = (char*)get_header(req, "Session-Expires");
 			if (!ast_strlen_zero(p_hdrval)) {
 				/* UAS supports Session-Timers */
@@ -17977,19 +17983,28 @@
 				if (tmp_st_ref == SESSION_TIMER_REFRESHER_UAC || 
 					tmp_st_ref == SESSION_TIMER_REFRESHER_UAS) {
 					p->stimer->st_ref = tmp_st_ref;
+					if (tmp_st_ref == SESSION_TIMER_REFRESHER_UAC) {
+						p->stimer->st_refresher_self = TRUE;
+					} else {
+						p->stimer->st_refresher_self = FALSE;
+					}
 				} 
 				if (tmp_st_interval) {
 					p->stimer->st_interval = tmp_st_interval;
 				}
 				p->stimer->st_active = TRUE;
 				p->stimer->st_active_peer_ua = TRUE;
-				start_session_timer(p);
+				if (!reinvite) {
+					start_session_timer(p);
+				}
 			} else {
 				/* UAS doesn't support Session-Timers */
 				if (st_get_mode(p) == SESSION_TIMER_MODE_ORIGINATE) {
 					p->stimer->st_ref = SESSION_TIMER_REFRESHER_UAC;
 					p->stimer->st_active_peer_ua = FALSE;
-					start_session_timer(p);
+					if (!reinvite) {
+						start_session_timer(p);
+					}
 				}
 			}
 		}
@@ -20487,6 +20502,12 @@
 		}
 	}
 
+	if (st_ref == SESSION_TIMER_REFRESHER_UAS) {
+		p->stimer->st_refresher_self = TRUE;
+	} else {
+		p->stimer->st_refresher_self = FALSE;
+	}
+	
 	if (!req->ignore && p)
 		p->lastinvite = seqno;
 
@@ -22884,29 +22905,24 @@
 		goto return_unref;
 	}
 
-	switch (p->stimer->st_ref) {
-	case SESSION_TIMER_REFRESHER_UAC:
-		if (p->outgoing_call == TRUE) {
-	  		sendreinv = TRUE;
-		}
-		break;
-	case SESSION_TIMER_REFRESHER_UAS:
-		if (p->outgoing_call != TRUE) {
-  			sendreinv = TRUE;
-		}
-		break;
-	default:
-		ast_log(LOG_ERROR, "Unknown session refresher %d\n",
p->stimer->st_ref);
-		goto return_unref;
+	if (p->stimer->st_ref != SESSION_TIMER_REFRESHER_UAC &&
+		p->stimer->st_ref != SESSION_TIMER_REFRESHER_UAS) {
+ 		ast_log(LOG_ERROR, "Unknown session refresher %d\n",
p->stimer->st_ref);
+ 		goto return_unref;
+ 	}
+ 
+	if (p->stimer->st_refresher_self == TRUE) {
+		sendreinv = TRUE;
 	}
-
+	
+	res = 1;
 	if (sendreinv == TRUE) {
-		res = 1;
 		transmit_reinvite_with_sdp(p, FALSE, TRUE);
 	} else {
 		p->stimer->st_expirys++;
 		if (p->stimer->st_expirys >= 2) {
 			if (p->stimer->quit_flag) {
+				res = 0;
 				goto return_unref;
 			}
 			ast_log(LOG_WARNING, "Session-Timer expired - %s\n", p->callid);
@@ -22915,6 +22931,7 @@
 				sip_pvt_unlock(p);
 				usleep(1);
 				if (p->stimer && p->stimer->quit_flag) {
+					res = 0;
 					goto return_unref;
 				}
 				sip_pvt_lock(p); 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2011-02-17 09:55 nohara         Note Added: 0132082                          
======================================================================




More information about the asterisk-bugs mailing list