Răsfoiți Sursa

modules/ims_registrar_scscf: new mod_param subscription_expires_range
If set this parameter randomises the subscription expiry
Works exactly the same as usrloc expires_range param

Richard Good 11 ani în urmă
părinte
comite
6eb29ad516

+ 86 - 5
modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml

@@ -67,7 +67,7 @@
       contact parameters, this value will be used for newly created S-CSCF
       contact parameters, this value will be used for newly created S-CSCF
       usrloc records. The parameter contains number of second to expire (for
       usrloc records. The parameter contains number of second to expire (for
       example use 3600 for one hour). If it is set to a lower value than the
       example use 3600 for one hour). If it is set to a lower value than the
-      “min_expires” parameter then it will be ignored. This
+      min_expires parameter then it will be ignored. This
       parameter can be modified via ser config framework. A random value in a
       parameter can be modified via ser config framework. A random value in a
       specific interval can be selected by using the default_expires_range
       specific interval can be selected by using the default_expires_range
       parameter</para>
       parameter</para>
@@ -87,10 +87,10 @@
       <title>default_expires_range (int)</title>
       <title>default_expires_range (int)</title>
 
 
       <para>This parameter specifies that the expiry used for newly created
       <para>This parameter specifies that the expiry used for newly created
-      S-CSCF usrloc records are not fixed(when &ldquo;default_expires&rdquor;
-      applies), but a random value in the interval
-      &ldquo;[default_expires-default_expires_range%,
-      default_expires+default_expires_range%]&rdquor;. The value is between 0
+      S-CSCF usrloc records are not fixed(when default_expires
+      applies), but a random value in the intervalrdq
+      [default_expires-default_expires_range%,
+      default_expires+default_expires_range%]. The value is between 0
       and 100 and represent the maximim percentage from default_expires that
       and 100 and represent the maximim percentage from default_expires that
       will be substracted or added when computing the value. Default in 0,
       will be substracted or added when computing the value. Default in 0,
       meaning default_expires is left unmodified. This parameter can be
       meaning default_expires is left unmodified. This parameter can be
@@ -144,6 +144,87 @@
 ...</programlisting>
 ...</programlisting>
       </example>
       </example>
     </section>
     </section>
+    
+    <section>
+      <title>subscription_default_expires (int)</title>
+
+      <para>If the processed message contains neither Expires HFs nor expires
+      contact parameters, this value will be used for newly created subscriptions.
+      The parameter contains number of second to expire (for example use 3600 for one hour). 
+      If it is set to a lower value than the subscription_min_expires parameter 
+      then it will be ignored. A random value in a specific interval can be selected 
+      by using the subscription_expires_range parameter</para>
+
+      <para><emphasis> Default value is 3600. </emphasis></para>
+
+      <example>
+        <title>Set <varname>subscription_default_expires</varname> parameter</title>
+
+        <programlisting format="linespecific">...
+        modparam("ims_registrar_scscf", "subscription_default_expires", 3600)
+...</programlisting>
+      </example>
+    </section>
+
+    <section>
+      <title>subscription_expires_range (int)</title>
+
+      <para>This parameter specifies that the expiry used for newly created
+      subscriptions are not fixed(when subscription_default_expires
+      applies), but a random value in the interval
+      [subscription_default_expires-subscription_expires_range%,
+      subscription_default_expires+subscription_expires_range%]. 
+      The value is between 0 and 100 and represent the maximim percentage 
+      from subscription_default_expires that will be substracted or added when 
+      computing the value. Default in 0, meaning subscription_default_expires is 
+      left unmodified.</para>
+
+      <para><emphasis> Default value is 0. </emphasis></para>
+
+      <example>
+        <title>Set <varname>subscription_expires_range </varname>parameter</title>
+
+        <programlisting format="linespecific">...
+        modparam("ims_registrar_scscf", "subscription_expires_range", 30) # +- 30% from subscription_expires_range
+...</programlisting>
+      </example>
+    </section>
+
+    <section>
+      <title>subscription_min_expires (int)</title>
+
+      <para>The minimum expires value of a subscription, values lower than this
+      minimum will be automatically set to the minimum. Value 0 disables the
+      checking.</para>
+
+      <para><emphasis> Default value is 10. </emphasis></para>
+
+      <example>
+        <title>Set <varname>subscription_min_expires</varname>parameter</title>
+
+        <programlisting format="linespecific">...
+        modparam("subscription_min_expires", "min_expires", 1800)
+...</programlisting>
+      </example>
+    </section>
+
+    <section>
+      <title>subscription_max_expires (int)</title>
+
+      <para>The maximum expires value of a subscription, values higher than this
+      maximum will be automatically set to the maximum. Value 0 disables the
+      checking.</para>
+
+      <para><emphasis> Default value is 1000000. </emphasis></para>
+
+      <example>
+        <title>Set <varname>subscription_max_expires</varname>parameter</title>
+
+        <programlisting format="linespecific">...
+        modparam("ims_registrar_scscf", "subscription_max_expires", 3600)
+...</programlisting>
+      </example>
+    </section>
 
 
     <section>
     <section>
       <title>user_data_dtd (string)</title>
       <title>user_data_dtd (string)</title>

+ 2 - 0
modules/ims_registrar_scscf/reg_mod.c

@@ -153,6 +153,7 @@ str sock_hdr_name = {0, 0};
 int subscription_default_expires = 3600; /**< the default value for expires if none found*/
 int subscription_default_expires = 3600; /**< the default value for expires if none found*/
 int subscription_min_expires = 10; /**< minimum subscription expiration time 		*/
 int subscription_min_expires = 10; /**< minimum subscription expiration time 		*/
 int subscription_max_expires = 1000000; /**< maximum subscription expiration time 		*/
 int subscription_max_expires = 1000000; /**< maximum subscription expiration time 		*/
+int subscription_expires_range = 0;
 
 
 
 
 extern reg_notification_list *notification_list; /**< list of notifications for reg to be sent			*/
 extern reg_notification_list *notification_list; /**< list of notifications for reg to be sent			*/
@@ -246,6 +247,7 @@ static param_export_t params[] = {
     {"subscription_min_expires", INT_PARAM, &subscription_min_expires},
     {"subscription_min_expires", INT_PARAM, &subscription_min_expires},
     {"subscription_max_expires", INT_PARAM, &subscription_max_expires},
     {"subscription_max_expires", INT_PARAM, &subscription_max_expires},
     {"ue_unsubscribe_on_dereg", INT_PARAM, &ue_unsubscribe_on_dereg},
     {"ue_unsubscribe_on_dereg", INT_PARAM, &ue_unsubscribe_on_dereg},
+    {"subscription_expires_range", INT_PARAM, &subscription_expires_range},
     {"user_data_always", INT_PARAM, &user_data_always},
     {"user_data_always", INT_PARAM, &user_data_always},
 
 
     {0, 0, 0}
     {0, 0, 0}

+ 18 - 0
modules/ims_registrar_scscf/registrar_notify.c

@@ -91,6 +91,22 @@ static str ctype_hdr1 = {"Content-Type: ", 14};
 static str ctype_hdr2 = {"\r\n", 2};
 static str ctype_hdr2 = {"\r\n", 2};
 
 
 extern int ue_unsubscribe_on_dereg;
 extern int ue_unsubscribe_on_dereg;
+extern int subscription_expires_range;
+
+/* \brief
+ * Return randomized expires between expires-range% and expires.
+ * RFC allows only value less or equal to the one provided by UAC.
+ */
+
+static inline int randomize_expires( int expires, int range )
+{
+	/* if no range is given just return expires */
+	if(range == 0) return expires;
+
+	int range_min = expires - (float)range/100 * expires;
+
+	return range_min + (float)(rand()%100)/100 * ( expires - range_min );
+}
 
 
 int notify_init() {
 int notify_init() {
     notification_list = shm_malloc(sizeof (reg_notification_list));
     notification_list = shm_malloc(sizeof (reg_notification_list));
@@ -1055,6 +1071,8 @@ int subscribe_to_reg(struct sip_msg *msg, char *_t, char *str2) {
 
 
         if (expires < subscription_min_expires) expires = subscription_min_expires;
         if (expires < subscription_min_expires) expires = subscription_min_expires;
         if (expires > subscription_max_expires) expires = subscription_max_expires;
         if (expires > subscription_max_expires) expires = subscription_max_expires;
+	
+	expires = randomize_expires(expires, subscription_expires_range);
 
 
         get_act_time();
         get_act_time();
         expires_time = expires + act_time;
         expires_time = expires + act_time;

+ 19 - 0
modules/ims_registrar_scscf/save.c

@@ -86,6 +86,22 @@ extern int store_data_on_dereg; /**< should we store SAR user data on de-registr
 extern int ue_unsubscribe_on_dereg;
 extern int ue_unsubscribe_on_dereg;
 extern int user_data_always;
 extern int user_data_always;
 
 
+
+/* \brief
+ * Return randomized expires between expires-range% and expires.
+ * RFC allows only value less or equal to the one provided by UAC.
+ */
+static inline int randomize_expires( int expires, int range )
+{
+	/* if no range is given just return expires */
+	if(range == 0) return expires;
+
+	int range_min = expires - (float)range/100 * expires;
+
+	return range_min + (float)(rand()%100)/100 * ( expires - range_min );
+}
+
+
 /*! \brief
 /*! \brief
  * Calculate absolute expires value per contact as follows:
  * Calculate absolute expires value per contact as follows:
  * 1) If the contact has expires value, use the value. If it
  * 1) If the contact has expires value, use the value. If it
@@ -124,6 +140,9 @@ static inline int calc_contact_expires(contact_t *c, unsigned int expires_hdr, i
         r = default_registrar_cfg.em_min_expires;
         r = default_registrar_cfg.em_min_expires;
 
 
 end:
 end:
+	    
+    r = randomize_expires(r, default_registrar_cfg.default_expires_range);
+	    
     LM_DBG("Calculated expires for contact is %d\n", r);
     LM_DBG("Calculated expires for contact is %d\n", r);
     return time(NULL) + r;
     return time(NULL) + r;
 }
 }