[asterisk-commits] file: branch file/pjsip-dns r410665 - in /team/file/pjsip-dns: configs/ res/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 17 08:10:38 CDT 2014


Author: file
Date: Mon Mar 17 08:10:31 2014
New Revision: 410665

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410665
Log:
Remove "nameservers" configuration option.

Modified:
    team/file/pjsip-dns/configs/pjsip.conf.sample
    team/file/pjsip-dns/res/res_pjsip.c
    team/file/pjsip-dns/res/res_pjsip/config_global.c
    team/file/pjsip-dns/res/res_pjsip/config_system.c
    team/file/pjsip-dns/res/res_pjsip/include/res_pjsip_private.h
    team/file/pjsip-dns/res/res_pjsip/pjsip_configuration.c

Modified: team/file/pjsip-dns/configs/pjsip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/configs/pjsip.conf.sample?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/configs/pjsip.conf.sample (original)
+++ team/file/pjsip-dns/configs/pjsip.conf.sample Mon Mar 17 08:10:31 2014
@@ -688,12 +688,6 @@
                                                         ; int")
 ;debug=no ; Enable/Disable SIP debug logging.  Valid options include yes|no
           ; or a host address (default: "no")
-;nameservers=auto ; The nameservers to use for DNS resolution. Valid options
-                  ; include disabled, auto, or a comma separated list of
-                  ; addresses. If auto is used the system nameservers will be
-                  ; automatically used. If a comma separated list is provided
-                  ; the order of addresses specifies the preference.
-                  ; (default: "auto")
 
 
 ; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl

Modified: team/file/pjsip-dns/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/res/res_pjsip.c?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/res/res_pjsip.c (original)
+++ team/file/pjsip-dns/res/res_pjsip.c Mon Mar 17 08:10:31 2014
@@ -1092,15 +1092,6 @@
 				<configOption name="debug" default="no">
 					<synopsis>Enable/Disable SIP debug logging.  Valid options include yes|no or
                                         a host address</synopsis>
-				</configOption>
-				<configOption name="nameservers" default="auto">
-					<synopsis>Set nameservers to use for DNS resolution.</synopsis>
-					<description><para>
-						The nameservers can be specified by order of preference using ',' as a separator.
-						To have the nameservers configured on the system automatically used you can specify
-						the special value of "auto". To disable DNS support and resort to using the system
-						for resolution you can specify the special value of "disabled".
-					</para></description>
 				</configOption>
 			</configObject>
 		</configFile>
@@ -2314,6 +2305,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	ast_sip_initialize_dns();
+
 	pjsip_tsx_layer_init_module(ast_pjsip_endpoint);
 	pjsip_ua_init_module(ast_pjsip_endpoint, NULL);
 
@@ -2404,6 +2397,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 	ast_res_pjsip_init_options_handling(1);
+	ast_sip_initialize_dns();
 	return 0;
 }
 

Modified: team/file/pjsip-dns/res/res_pjsip/config_global.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/res/res_pjsip/config_global.c?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/res/res_pjsip/config_global.c (original)
+++ team/file/pjsip-dns/res/res_pjsip/config_global.c Mon Mar 17 08:10:31 2014
@@ -25,7 +25,6 @@
 #include "include/res_pjsip_private.h"
 #include "asterisk/sorcery.h"
 #include "asterisk/ast_version.h"
-#include "asterisk/dns.h"
 
 #define DEFAULT_MAX_FORWARDS 70
 #define DEFAULT_USERAGENT_PREFIX "Asterisk PBX"
@@ -41,8 +40,6 @@
 		AST_STRING_FIELD(default_outbound_endpoint);
 		/*! Debug logging yes|no|host */
 		AST_STRING_FIELD(debug);
-		/*! Nameservers for DNS */
-		AST_STRING_FIELD(nameservers);
 	);
 	/* Value to put in Max-Forwards header */
 	unsigned int max_forwards;
@@ -139,138 +136,7 @@
 			OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
 	ast_sorcery_object_field_register(sorcery, "global", "debug", "no",
 			OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, debug));
-	ast_sorcery_object_field_register(sorcery, "global", "nameservers", DEFAULT_NAMESERVERS,
-			OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, nameservers));
 
 	return 0;
 }
 
-
-/*! \brief Helper function which gets the system nameservers adds them to the nameservers array */
-static int system_add_system_nameservers(pj_pool_t *pool, pj_str_t *nameservers, unsigned int *count)
-{
-	struct ao2_container *discovered_nameservers;
-	struct ao2_iterator it_nameservers;
-	char *nameserver;
-
-	discovered_nameservers = ast_dns_get_nameservers();
-	if (!discovered_nameservers) {
-		ast_log(LOG_ERROR, "Could not retrieve local system nameservers\n");
-		return -1;
-	}
-
-	if (!ao2_container_count(discovered_nameservers)) {
-		ast_log(LOG_ERROR, "There are no local system nameservers configured\n");
-		ao2_ref(discovered_nameservers, -1);
-		return -1;
-	}
-
-	it_nameservers = ao2_iterator_init(discovered_nameservers, 0);
-	while ((nameserver = ao2_iterator_next(&it_nameservers))) {
-		pj_strdup2(pool, &nameservers[(*count)++], nameserver);
-		ao2_ref(nameserver, -1);
-
-		if (*count == (PJ_DNS_RESOLVER_MAX_NS - 1)) {
-			break;
-		}
-	}
-	ao2_iterator_destroy(&it_nameservers);
-
-	ao2_ref(discovered_nameservers, -1);
-
-	return 0;
-}
-
-static int system_create_resolver_and_set_nameservers(void *data)
-{
-	struct global_config *cfg = get_global_cfg();
-	pj_status_t status;
-	pj_pool_t *pool = NULL;
-	pj_dns_resolver *resolver;
-	pj_str_t nameservers[PJ_DNS_RESOLVER_MAX_NS];
-	unsigned int count = 0;
-	char *nameserver, *remaining;
-
-	if (cfg) {
-		remaining = ast_strdupa(cfg->nameservers);
-	} else {
-		remaining = ast_strdupa(DEFAULT_NAMESERVERS);
-	}
-
-	ao2_cleanup(cfg);
-
-	/* If DNS support has been disabled don't even bother doing anything, just resort to the
-	 * system way of doing lookups
-	 */
-	if (!strcmp(remaining, "disabled")) {
-		return 0;
-	}
-
-	if (!pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint())) {
-		status = pjsip_endpt_create_resolver(ast_sip_get_pjsip_endpoint(), &resolver);
-		if (status != PJ_SUCCESS) {
-			ast_log(LOG_ERROR, "Could not create DNS resolver(%d)\n", status);
-			return -1;
-		}
-	}
-
-	while ((nameserver = strsep(&remaining, ","))) {
-		nameserver = ast_strip(nameserver);
-
-		if (!strcmp(nameserver, "auto")) {
-			if (!pool) {
-				pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Automatic Nameserver Discovery", 256, 256);
-			}
-			if (!pool) {
-				ast_log(LOG_ERROR, "Could not create memory pool for automatic nameserver discovery\n");
-				return -1;
-			} else if (system_add_system_nameservers(pool, nameservers, &count)) {
-				/* A log message will have already been output by system_add_resolv_conf_nameservers */
-				pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
-				return -1;
-			}
-		} else {
-			pj_strset2(&nameservers[count++], nameserver);
-		}
-
-		/* If we have reached the max number of nameservers we can specify bail early */
-		if (count == (PJ_DNS_RESOLVER_MAX_NS - 1)) {
-			break;
-		}
-	}
-
-	if (!count) {
-		ast_log(LOG_ERROR, "No nameservers specified for DNS resolver, resorting to system resolution\n");
-		if (pool) {
-			pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
-		}
-		return 0;
-	}
-
-	status = pj_dns_resolver_set_ns(resolver, count, nameservers, NULL);
-
-	/* Since we no longer need the nameservers we can drop the memory pool they may be allocated from */
-	if (pool) {
-		pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
-	}
-
-	if (status != PJ_SUCCESS) {
-		ast_log(LOG_ERROR, "Could not set nameservers on DNS resolver in PJSIP(%d)\n", status);
-		return -1;
-	}
-
-	if (!pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint())) {
-		status = pjsip_endpt_set_resolver(ast_sip_get_pjsip_endpoint(), resolver);
-		if (status != PJ_SUCCESS) {
-			ast_log(LOG_ERROR, "Could not set DNS resolver in PJSIP(%d)\n", status);
-			return -1;
-		}
-	}
-
-	return 0;
-}
-
-int ast_sip_initialize_dns(void)
-{
-	return ast_sip_push_task_synchronous(NULL, system_create_resolver_and_set_nameservers, NULL);
-}

Modified: team/file/pjsip-dns/res/res_pjsip/config_system.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/res/res_pjsip/config_system.c?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/res/res_pjsip/config_system.c (original)
+++ team/file/pjsip-dns/res/res_pjsip/config_system.c Mon Mar 17 08:10:31 2014
@@ -25,6 +25,7 @@
 #include "asterisk/sorcery.h"
 #include "include/res_pjsip_private.h"
 #include "asterisk/threadpool.h"
+#include "asterisk/dns.h"
 
 #define TIMER_T1_MIN 100
 #define DEFAULT_TIMER_T1 500
@@ -174,3 +175,70 @@
 	ast_sorcery_unref(system_sorcery);
 }
 
+static int system_create_resolver_and_set_nameservers(void *data)
+{
+	struct ao2_container *discovered_nameservers;
+	struct ao2_iterator it_nameservers;
+	char *nameserver;
+	pj_status_t status;
+	pj_dns_resolver *resolver;
+	pj_str_t nameservers[PJ_DNS_RESOLVER_MAX_NS];
+	unsigned int count = 0;
+
+	discovered_nameservers = ast_dns_get_nameservers();
+	if (!discovered_nameservers) {
+		ast_log(LOG_ERROR, "Could not retrieve local system nameservers, resorting to system resolution\n");
+		return 0;
+	}
+
+	if (!ao2_container_count(discovered_nameservers)) {
+		ast_log(LOG_ERROR, "There are no local system nameservers configured, resorting to system resolution\n");
+		ao2_ref(discovered_nameservers, -1);
+		return -1;
+	}
+
+	if (!(resolver = pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint()))) {
+		status = pjsip_endpt_create_resolver(ast_sip_get_pjsip_endpoint(), &resolver);
+		if (status != PJ_SUCCESS) {
+			ast_log(LOG_ERROR, "Could not create DNS resolver(%d), resorting to system resolution\n", status);
+			return 0;
+		}
+	}
+
+	it_nameservers = ao2_iterator_init(discovered_nameservers, 0);
+	while ((nameserver = ao2_iterator_next(&it_nameservers))) {
+		pj_strset2(&nameservers[count++], nameserver);
+		ao2_ref(nameserver, -1);
+
+		if (count == (PJ_DNS_RESOLVER_MAX_NS - 1)) {
+			break;
+		}
+	}
+	ao2_iterator_destroy(&it_nameservers);
+
+	status = pj_dns_resolver_set_ns(resolver, count, nameservers, NULL);
+
+	/* Since we no longer need the nameservers we can drop the list of them */
+	ao2_ref(discovered_nameservers, -1);
+
+	if (status != PJ_SUCCESS) {
+		ast_log(LOG_ERROR, "Could not set nameservers on DNS resolver in PJSIP(%d), resorting to system resolution\n",
+			status);
+		return 0;
+	}
+
+	if (!pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint())) {
+		status = pjsip_endpt_set_resolver(ast_sip_get_pjsip_endpoint(), resolver);
+		if (status != PJ_SUCCESS) {
+			ast_log(LOG_ERROR, "Could not set DNS resolver in PJSIP(%d), resorting to system resolution\n", status);
+			return 0;
+		}
+	}
+
+	return 0;
+}
+
+void ast_sip_initialize_dns(void)
+{
+	ast_sip_push_task_synchronous(NULL, system_create_resolver_and_set_nameservers, NULL);
+}

Modified: team/file/pjsip-dns/res/res_pjsip/include/res_pjsip_private.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/res/res_pjsip/include/res_pjsip_private.h?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/res/res_pjsip/include/res_pjsip_private.h (original)
+++ team/file/pjsip-dns/res/res_pjsip/include/res_pjsip_private.h Mon Mar 17 08:10:31 2014
@@ -74,11 +74,8 @@
 
 /*!
  * \brief Initialize nameserver configuration
- *
- * \retval 0 Success
- * \retval non-zero Failure
  */
-int ast_sip_initialize_dns(void);
+void ast_sip_initialize_dns(void);
 
 /*!
  * \brief Initialize global configuration

Modified: team/file/pjsip-dns/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-dns/res/res_pjsip/pjsip_configuration.c?view=diff&rev=410665&r1=410664&r2=410665
==============================================================================
--- team/file/pjsip-dns/res/res_pjsip/pjsip_configuration.c (original)
+++ team/file/pjsip-dns/res/res_pjsip/pjsip_configuration.c Mon Mar 17 08:10:31 2014
@@ -1760,13 +1760,6 @@
 		return -1;
 	}
 
-	if (ast_sip_initialize_dns()) {
-		ast_log(LOG_ERROR, "Failed to initialize DNS support\n");
-		ast_sorcery_unref(sip_sorcery);
-		sip_sorcery = NULL;
-		return -1;
-	}
-
 	channel_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL);
 	if (!channel_formatter) {
 		ast_log(LOG_ERROR, "Unable to allocate memory for channel_formatter\n");




More information about the asterisk-commits mailing list