[asterisk-commits] mmichelson: trunk r370386 - in /trunk: ./ channels/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 23 16:11:00 CDT 2012


Author: mmichelson
Date: Mon Jul 23 16:10:54 2012
New Revision: 370386

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=370386
Log:
Add separate configuration options for subscription and registration minexpiry and maxexpiry.

This offers more fine-grained control over how long subscriptions last without negatively
affecting the expiration range for registrations.

Uploaded by:
	Guenther Kelleter(license #6372)

Review: https://reviewboard.asterisk.org/r/2051


Modified:
    trunk/CHANGES
    trunk/channels/chan_sip.c
    trunk/configs/sip.conf.sample

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=370386&r1=370385&r2=370386
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Mon Jul 23 16:10:54 2012
@@ -311,6 +311,14 @@
 
  * Add support for WebSocket transport. This can be configured using 'ws' or 'wss'
    as the transport.
+ * Add options subminexpiry and submaxexpiry to set limits of subscription
+   timer independently from registration timer settings. The setting of the
+   registration timer limits still is done by options minexpiry, maxexpiry
+   and defaultexpiry. For backwards compatibility the setting of minexpiry
+   and maxexpiry also is used to configure the subscription timer limits if
+   subminexpiry and submaxexpiry are not set in sip.conf.
+ * Set registration timer limits to default values when reloading sip
+   configuration and values are not set by configuration.
 
  * When a MESSAGE request is received, the address the request was received from
    is now saved in the SIP_RECVADDR variable.

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=370386&r1=370385&r2=370386
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Mon Jul 23 16:10:54 2012
@@ -585,6 +585,8 @@
 static int min_expiry = DEFAULT_MIN_EXPIRY;        /*!< Minimum accepted registration time */
 static int max_expiry = DEFAULT_MAX_EXPIRY;        /*!< Maximum accepted registration time */
 static int default_expiry = DEFAULT_DEFAULT_EXPIRY;
+static int min_subexpiry = DEFAULT_MIN_EXPIRY;     /*!< Minimum accepted subscription time */
+static int max_subexpiry = DEFAULT_MAX_EXPIRY;     /*!< Maximum accepted subscription time */
 static int mwi_expiry = DEFAULT_MWI_EXPIRY;
 
 static int unauth_sessions = 0;
@@ -11546,12 +11548,12 @@
 }
 
 /*! \brief Append Min-Expires header, content length before transmitting response */
-static int transmit_response_with_minexpires(struct sip_pvt *p, const char *msg, const struct sip_request *req)
+static int transmit_response_with_minexpires(struct sip_pvt *p, const char *msg, const struct sip_request *req, int minexpires)
 {
 	struct sip_request resp;
 	char tmp[32];
 
-	snprintf(tmp, sizeof(tmp), "%d", min_expiry);
+	snprintf(tmp, sizeof(tmp), "%d", minexpires);
 	respprep(&resp, p, msg, req);
 	add_header(&resp, "Min-Expires", tmp);
 	return send_response(p, &resp, XMIT_UNRELIABLE, 0);
@@ -19678,6 +19680,8 @@
 	ast_cli(a->fd, "  Reg. min duration       %d secs\n", min_expiry);
 	ast_cli(a->fd, "  Reg. max duration:      %d secs\n", max_expiry);
 	ast_cli(a->fd, "  Reg. default duration:  %d secs\n", default_expiry);
+	ast_cli(a->fd, "  Sub. min duration       %d secs\n", min_subexpiry);
+	ast_cli(a->fd, "  Sub. max duration:      %d secs\n", max_subexpiry);
 	ast_cli(a->fd, "  Outbound reg. timeout:  %d secs\n", global_reg_timeout);
 	ast_cli(a->fd, "  Outbound reg. attempts: %d\n", global_regattempts_max);
 	ast_cli(a->fd, "  Notify ringing state:   %s\n", AST_CLI_YESNO(sip_cfg.notifyringing));
@@ -26330,7 +26334,7 @@
 	if (expires_int > max_expiry) {
 		expires_int = max_expiry;
 	} else if (expires_int < min_expiry && expires_int > 0) {
-		transmit_response_with_minexpires(p, "423 Interval too small", req);
+		transmit_response_with_minexpires(p, "423 Interval too small", req, min_expiry);
 		pvt_set_needdestroy(p, "Expires is less that the min expires allowed.");
 		return 0;
 	}
@@ -26762,13 +26766,13 @@
 		p->expiry = atoi(sip_get_header(req, "Expires"));
 
 		/* check if the requested expiry-time is within the approved limits from sip.conf */
-		if (p->expiry > max_expiry) {
-			p->expiry = max_expiry;
-		} else if (p->expiry < min_expiry && p->expiry > 0) {
-			transmit_response_with_minexpires(p, "423 Interval too small", req);
+		if (p->expiry > max_subexpiry) {
+			p->expiry = max_subexpiry;
+		} else if (p->expiry < min_subexpiry && p->expiry > 0) {
+			transmit_response_with_minexpires(p, "423 Interval too small", req, min_subexpiry);
 			ast_log(LOG_WARNING, "Received subscription for extension \"%s\" context \"%s\" "
-				"with Expire header less that 'minexpire' limit. Received \"Expire: %d\" min is %d\n",
-				p->exten, p->context, p->expiry, min_expiry);
+				"with Expire header less than 'subminexpire' limit. Received \"Expire: %d\" min is %d\n",
+				p->exten, p->context, p->expiry, min_subexpiry);
 			pvt_set_needdestroy(p, "Expires is less that the min expires allowed.");
 			if (authpeer) {
 				sip_unref_peer(authpeer, "sip_unref_peer, from handle_request_subscribe (authpeer 6)");
@@ -30108,6 +30112,7 @@
 	time_t run_start, run_end;
 	int bindport = 0;
 	int acl_change_subscription_needed = 0;
+	int min_subexpiry_set = 0, max_subexpiry_set = 0;
 
 	run_start = time(0);
 	ast_unload_realtime("sipregs");
@@ -30324,6 +30329,9 @@
 	authlimit = DEFAULT_AUTHLIMIT;
 	authtimeout = DEFAULT_AUTHTIMEOUT;
 	global_store_sip_cause = DEFAULT_STORE_SIP_CAUSE;
+	min_expiry = DEFAULT_MIN_EXPIRY;
+	max_expiry = DEFAULT_MAX_EXPIRY;
+	default_expiry = DEFAULT_DEFAULT_EXPIRY;
 
 	sip_cfg.matchexternaddrlocally = DEFAULT_MATCHEXTERNADDRLOCALLY;
 
@@ -30595,6 +30603,18 @@
 			if (default_expiry < 1) {
 				default_expiry = DEFAULT_DEFAULT_EXPIRY;
 			}
+		} else if (!strcasecmp(v->name, "submaxexpirey") || !strcasecmp(v->name, "submaxexpiry")) {
+			max_subexpiry = atoi(v->value);
+			if (max_subexpiry < 1) {
+				max_subexpiry = DEFAULT_MAX_EXPIRY;
+			}
+			max_subexpiry_set = 1;
+		} else if (!strcasecmp(v->name, "subminexpirey") || !strcasecmp(v->name, "subminexpiry")) {
+			min_subexpiry = atoi(v->value);
+			if (min_subexpiry < 1) {
+				min_subexpiry = DEFAULT_MIN_EXPIRY;
+			}
+			min_subexpiry_set = 1;
 		} else if (!strcasecmp(v->name, "mwiexpiry") || !strcasecmp(v->name, "mwiexpirey")) {
 			mwi_expiry = atoi(v->value);
 			if (mwi_expiry < 1) {
@@ -30864,6 +30884,14 @@
 		} else if (!strcasecmp(v->name, "parkinglot")) {
 			ast_copy_string(default_parkinglot, v->value, sizeof(default_parkinglot));
 		}
+	}
+
+	/* For backwards compatibility the corresponding registration timer value is used if subscription timer value isn't set by configuration */
+	if (!min_subexpiry_set) {
+		min_subexpiry = min_expiry;
+	}
+	if (!max_subexpiry_set) {
+		max_subexpiry = max_expiry;
 	}
 
 	if (reason != CHANNEL_MODULE_LOAD) {

Modified: trunk/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/sip.conf.sample?view=diff&rev=370386&r1=370385&r2=370386
==============================================================================
--- trunk/configs/sip.conf.sample (original)
+++ trunk/configs/sip.conf.sample Mon Jul 23 16:10:54 2012
@@ -258,10 +258,11 @@
 ;cos_video=4                    ; Sets 802.1p priority for RTP video packets.
 ;cos_text=3                     ; Sets 802.1p priority for RTP text packets.
 
-;maxexpiry=3600                 ; Maximum allowed time of incoming registrations
-                                ; and subscriptions (seconds)
-;minexpiry=60                   ; Minimum length of registrations/subscriptions (default 60)
+;maxexpiry=3600                 ; Maximum allowed time of incoming registrations (seconds)
+;minexpiry=60                   ; Minimum length of registrations (default 60)
 ;defaultexpiry=120              ; Default length of incoming/outgoing registration
+;submaxexpiry=3600              ; Maximum allowed time of incoming subscriptions (seconds), default: maxexpiry
+;subminexpiry=60                ; Minimum length of subscriptions, default: minexpiry
 ;mwiexpiry=3600                 ; Expiry time for outgoing MWI subscriptions
 ;maxforwards=70			; Setting for the SIP Max-Forwards: header (loop prevention)
 				; Default value is 70




More information about the asterisk-commits mailing list