Merge "res_pjsip_registrar.c: Update remove_existing AOR contact handling."
authorJenkins2 <jenkins2@gerrit.asterisk.org>
Wed, 11 Oct 2017 11:49:54 +0000 (06:49 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Wed, 11 Oct 2017 11:49:54 +0000 (06:49 -0500)
1  2 
res/res_pjsip.c

diff --combined res/res_pjsip.c
                                                It only limits contacts added through external interaction, such as
                                                registration.
                                                </para>
+                                               <note><para>The <replaceable>rewrite_contact</replaceable> option
+                                               registers the source address as the contact address to help with
+                                               NAT and reusing connection oriented transports such as TCP and
+                                               TLS.  Unfortunately, refreshing a registration may register a
+                                               different contact address and exceed
+                                               <replaceable>max_contacts</replaceable>.  The
+                                               <replaceable>remove_existing</replaceable> option can help by
+                                               removing the soonest to expire contact(s) over
+                                               <replaceable>max_contacts</replaceable> which is likely the
+                                               old <replaceable>rewrite_contact</replaceable> contact source
+                                               address being refreshed.
+                                               </para></note>
                                                <note><para>This should be set to <literal>1</literal> and
                                                <replaceable>remove_existing</replaceable> set to <literal>yes</literal> if you
                                                wish to stick with the older <literal>chan_sip</literal> behaviour.
                                <configOption name="minimum_expiration" default="60">
                                        <synopsis>Minimum keep alive time for an AoR</synopsis>
                                        <description><para>
-                                               Minimum time to keep a peer with an explict expiration. Time in seconds.
+                                               Minimum time to keep a peer with an explicit expiration. Time in seconds.
                                        </para></description>
                                </configOption>
                                <configOption name="remove_existing" default="no">
                                        <synopsis>Determines whether new contacts replace existing ones.</synopsis>
                                        <description><para>
-                                               On receiving a new registration to the AoR should it remove
-                                               the existing contact that was registered against it?
+                                               On receiving a new registration to the AoR should it remove enough
+                                               existing contacts not added or updated by the registration to
+                                               satisfy <replaceable>max_contacts</replaceable>?  Any removed
+                                               contacts will expire the soonest.
                                                </para>
+                                               <note><para>The <replaceable>rewrite_contact</replaceable> option
+                                               registers the source address as the contact address to help with
+                                               NAT and reusing connection oriented transports such as TCP and
+                                               TLS.  Unfortunately, refreshing a registration may register a
+                                               different contact address and exceed
+                                               <replaceable>max_contacts</replaceable>.  The
+                                               <replaceable>remove_existing</replaceable> option can help by
+                                               removing the soonest to expire contact(s) over
+                                               <replaceable>max_contacts</replaceable> which is likely the
+                                               old <replaceable>rewrite_contact</replaceable> contact source
+                                               address being refreshed.
+                                               </para></note>
                                                <note><para>This should be set to <literal>yes</literal> and
                                                <replaceable>max_contacts</replaceable> set to <literal>1</literal> if you
                                                wish to stick with the older <literal>chan_sip</literal> behaviour.
@@@ -2422,20 -2448,25 +2448,20 @@@ static int register_service_noref(void 
        return 0;
  }
  
 -static int register_service(void *data)
 -{
 -      int res;
 -
 -      if (!(res = register_service_noref(data))) {
 -              ast_module_ref(ast_module_info->self);
 -      }
 -
 -      return res;
 -}
 -
  int internal_sip_register_service(pjsip_module *module)
  {
        return ast_sip_push_task_synchronous(NULL, register_service_noref, &module);
  }
  
 -int ast_sip_register_service(pjsip_module *module)
 +int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func)
  {
 -      return ast_sip_push_task_synchronous(NULL, register_service, &module);
 +      int res;
 +
 +      if (!(res = ast_sip_push_task_synchronous(NULL, register_service_noref, &module))) {
 +              __ast_module_ref(ast_module_info->self, file, line, func);
 +      }
 +
 +      return res;
  }
  
  static int unregister_service_noref(void *data)
        return 0;
  }
  
 -static int unregister_service(void *data)
 -{
 -      int res;
 -
 -      if (!(res = unregister_service_noref(data))) {
 -              ast_module_unref(ast_module_info->self);
 -      }
 -
 -      return res;
 -}
 -
  int internal_sip_unregister_service(pjsip_module *module)
  {
        return ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module);
  }
  
 -void ast_sip_unregister_service(pjsip_module *module)
 +void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func)
  {
 -      ast_sip_push_task_synchronous(NULL, unregister_service, &module);
 +      if (!ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module)) {
 +              __ast_module_unref(ast_module_info->self, file, line, func);
 +      }
  }
  
  static struct ast_sip_authenticator *registered_authenticator;
@@@ -3502,7 -3542,7 +3528,7 @@@ int ast_sip_create_request(const char *
  
  AST_RWLIST_HEAD_STATIC(supplements, ast_sip_supplement);
  
 -int ast_sip_register_supplement(struct ast_sip_supplement *supplement)
 +void internal_sip_register_supplement(struct ast_sip_supplement *supplement)
  {
        struct ast_sip_supplement *iter;
        int inserted = 0;
        if (!inserted) {
                AST_RWLIST_INSERT_TAIL(&supplements, supplement, next);
        }
 -      ast_module_ref(ast_module_info->self);
 +}
 +
 +int __ast_sip_register_supplement(struct ast_sip_supplement *supplement,
 +      const char *file, int line, const char *func)
 +{
 +      internal_sip_register_supplement(supplement);
 +      __ast_module_ref(ast_module_info->self, file, line, func);
 +
        return 0;
  }
  
 -void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
 +int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement)
  {
        struct ast_sip_supplement *iter;
        SCOPED_LOCK(lock, &supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
 +      int res = -1;
 +
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&supplements, iter, next) {
                if (supplement == iter) {
                        AST_RWLIST_REMOVE_CURRENT(next);
 -                      ast_module_unref(ast_module_info->self);
 +                      res = 0;
                        break;
                }
        }
        AST_RWLIST_TRAVERSE_SAFE_END;
 +
 +      return res;
 +}
 +
 +void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement,
 +      const char *file, int line, const char *func)
 +{
 +      if (!internal_sip_unregister_supplement(supplement)) {
 +              __ast_module_unref(ast_module_info->self, file, line, func);
 +      }
  }
  
  static int send_in_dialog_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg)