[svn-commits] mmichelson: branch group/dns r433150 - in /team/group/dns: include/asterisk/ ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 19 10:16:15 CDT 2015


Author: mmichelson
Date: Thu Mar 19 10:16:09 2015
New Revision: 433150

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433150
Log:
Add full DNS answer to DNS result structure.

Having this allows for encoded domain-names to be expanded.

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


Modified:
    team/group/dns/include/asterisk/dns_core.h
    team/group/dns/include/asterisk/dns_internal.h
    team/group/dns/include/asterisk/dns_resolver.h
    team/group/dns/main/dns_core.c
    team/group/dns/res/res_resolver_unbound.c
    team/group/dns/tests/test_dns.c
    team/group/dns/tests/test_dns_recurring.c

Modified: team/group/dns/include/asterisk/dns_core.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_core.h?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/include/asterisk/dns_core.h (original)
+++ team/group/dns/include/asterisk/dns_core.h Thu Mar 19 10:16:09 2015
@@ -131,6 +131,14 @@
  */
 const struct ast_dns_record *ast_dns_result_get_records(const struct ast_dns_result *result);
 
+/*!
+ * \brief Get the raw DNS answer from a DNS result
+ *
+ * \param result The DNS result
+ *
+ * \return The DNS result
+ */
+const char *ast_dns_result_get_answer(const struct ast_dns_result *result);
 
 /*!
  * \brief Retrieve the lowest TTL from a result

Modified: team/group/dns/include/asterisk/dns_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_internal.h?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/include/asterisk/dns_internal.h (original)
+++ team/group/dns/include/asterisk/dns_internal.h Thu Mar 19 10:16:09 2015
@@ -82,7 +82,11 @@
 	/*! \brief Records returned */
 	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
 	/*! \brief The canonical name */
-	char canonical[0];
+	const char *canonical;
+	/*! \brief The raw DNS answer */
+	const char *answer;
+	/*! \brief Buffer for dynamic data */
+	char buf[0];
 };
 
 /*! \brief A DNS query */
@@ -138,4 +142,4 @@
  *
  * \return scheduler context
  */
-struct ast_sched_context *ast_dns_get_sched(void);
+struct ast_sched_context *ast_dns_get_sched(void);

Modified: team/group/dns/include/asterisk/dns_resolver.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_resolver.h?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/include/asterisk/dns_resolver.h (original)
+++ team/group/dns/include/asterisk/dns_resolver.h Thu Mar 19 10:16:09 2015
@@ -87,12 +87,14 @@
  * \param bogus Whether the result is bogus or not
  * \param rcode Optional response code
  * \param canonical The canonical name
+ * \param answer The raw DNS answer
+ * \param answer_size The size of the raw DNS answer
  *
  * \retval 0 success
  * \retval -1 failure
  */
 int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus,
-	unsigned int rcode, const char *canonical);
+	unsigned int rcode, const char *canonical, const char *answer, size_t answer_size);
 
 /*!
  * \brief Add a DNS record to the result of a DNS query

Modified: team/group/dns/main/dns_core.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_core.c?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Thu Mar 19 10:16:09 2015
@@ -104,6 +104,11 @@
 	return AST_LIST_FIRST(&result->records);
 }
 
+const char *ast_dns_result_get_answer(const struct ast_dns_result *result)
+{
+	return result->answer;
+}
+
 int ast_dns_result_get_lowest_ttl(const struct ast_dns_result *result)
 {
 	int ttl = 0;
@@ -361,8 +366,10 @@
 }
 
 int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int secure, unsigned int bogus,
-	unsigned int rcode, const char *canonical)
-{
+	unsigned int rcode, const char *canonical, const char *answer, size_t answer_size)
+{
+	char *buf_ptr;
+
 	if (secure && bogus) {
 		ast_debug(2, "Query '%p': Could not set result information, it can not be both secure and bogus\n",
 			query);
@@ -375,9 +382,15 @@
 		return -1;
 	}
 
+	if (ast_strlen_zero(answer) || answer_size == 0) {
+		ast_debug(2, "Query '%p': Could not set result information since no DNS answer was provided\n",
+			query);
+		return -1;
+	}
+
 	ast_dns_result_free(query->result);
 
-	query->result = ast_calloc(1, sizeof(*query->result) + strlen(canonical) + 1);
+	query->result = ast_calloc(1, sizeof(*query->result) + strlen(canonical) + 1 + answer_size);
 	if (!query->result) {
 		return -1;
 	}
@@ -385,7 +398,14 @@
 	query->result->secure = secure;
 	query->result->bogus = bogus;
 	query->result->rcode = rcode;
-	strcpy(query->result->canonical, canonical); /* SAFE */
+
+	buf_ptr = query->result->buf;
+	strcpy(buf_ptr, canonical); /* SAFE */
+	query->result->canonical = buf_ptr;
+
+	buf_ptr += strlen(canonical) + 1;
+	memcpy(buf_ptr, answer, answer_size); /* SAFE */
+	query->result->answer = buf_ptr;
 
 	return 0;
 }

Modified: team/group/dns/res/res_resolver_unbound.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/res/res_resolver_unbound.c?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/res/res_resolver_unbound.c (original)
+++ team/group/dns/res/res_resolver_unbound.c Thu Mar 19 10:16:09 2015
@@ -255,7 +255,7 @@
 	struct ast_dns_query *query = data;
 
 	if (!ast_dns_resolver_set_result(query, ub_result->secure, ub_result->bogus, ub_result->rcode,
-		S_OR(ub_result->canonname, ast_dns_query_get_name(query)))) {
+		S_OR(ub_result->canonname, ast_dns_query_get_name(query)), ub_result->answer_packet, ub_result->answer_len)) {
 		int i;
 		char *data;
 

Modified: team/group/dns/tests/test_dns.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/tests/test_dns.c?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/tests/test_dns.c (original)
+++ team/group/dns/tests/test_dns.c Thu Mar 19 10:16:09 2015
@@ -264,7 +264,8 @@
 
 static int test_results(struct ast_test *test, const struct ast_dns_query *query,
 		unsigned int expected_secure, unsigned int expected_bogus,
-		unsigned int expected_rcode, const char *expected_canonical)
+		unsigned int expected_rcode, const char *expected_canonical,
+		const char *expected_answer, size_t answer_size)
 {
 	struct ast_dns_result *result;
 
@@ -277,13 +278,21 @@
 	if (ast_dns_result_get_secure(result) != expected_secure ||
 			ast_dns_result_get_bogus(result) != expected_bogus ||
 			ast_dns_result_get_rcode(result) != expected_rcode ||
-			strcmp(ast_dns_result_get_canonical(result), expected_canonical)) {
+			strcmp(ast_dns_result_get_canonical(result), expected_canonical) ||
+			memcmp(ast_dns_result_get_answer(result), expected_answer, answer_size)) {
 		ast_test_status_update(test, "Unexpected values in result from query\n");
 		return -1;
 	}
 
 	return 0;
 }
+
+/* When setting a DNS result, we have to provide the raw DNS answer. This
+ * is not happening. Sorry. Instead, we provide a dummy string and call it
+ * a day
+ */
+#define DNS_ANSWER "Grumble Grumble"
+#define DNS_ANSWER_SIZE strlen(DNS_ANSWER)
 
 AST_TEST_DEFINE(resolver_set_result)
 {
@@ -295,10 +304,10 @@
 		unsigned int bogus;
 		unsigned int rcode;
 	} results[] = {
-		{ 0, 0, ns_r_noerror },
-		{ 0, 1, ns_r_noerror },
-		{ 1, 0, ns_r_noerror },
-		{ 0, 0, ns_r_nxdomain },
+		{ 0, 0, ns_r_noerror, },
+		{ 0, 1, ns_r_noerror, },
+		{ 1, 0, ns_r_noerror, },
+		{ 0, 0, ns_r_nxdomain, },
 	};
 	int i;
 	enum ast_test_result_state res = AST_TEST_PASS;
@@ -325,13 +334,13 @@
 
 	for (i = 0; i < ARRAY_LEN(results); ++i) {
 		if (ast_dns_resolver_set_result(&some_query, results[i].secure, results[i].bogus,
-				results[i].rcode, "asterisk.org")) {
+				results[i].rcode, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE)) {
 			ast_test_status_update(test, "Unable to add DNS result to query\n");
 			res = AST_TEST_FAIL;
 		}
 
 		if (test_results(test, &some_query, results[i].secure, results[i].bogus,
-				results[i].rcode, "asterisk.org")) {
+				results[i].rcode, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE)) {
 			res = AST_TEST_FAIL;
 		}
 	}
@@ -356,7 +365,9 @@
 		info->description =
 			"This test performs the following:\n"
 			"\t* Attempt to add a DNS result that is both bogus and secure\n"
-			"\t* Attempt to add a DNS result that has no canonical name\n";
+			"\t* Attempt to add a DNS result that has no canonical name\n"
+			"\t* Attempt to add a DNS result that has no answer\n"
+			"\t* Attempt to add a DNS result with a zero answer size\n";
 		return AST_TEST_NOT_RUN;
 	case TEST_EXECUTE:
 		break;
@@ -364,15 +375,33 @@
 
 	memset(&some_query, 0, sizeof(some_query));
 
-	if (!ast_dns_resolver_set_result(&some_query, 1, 1, ns_r_noerror, "asterisk.org")) {
+	if (!ast_dns_resolver_set_result(&some_query, 1, 1, ns_r_noerror, "asterisk.org",
+				DNS_ANSWER, DNS_ANSWER_SIZE)) {
 		ast_test_status_update(test, "Successfully added a result that was both secure and bogus\n");
 		result = ast_dns_query_get_result(&some_query);
 		ast_dns_result_free(result);
 		return AST_TEST_FAIL;
 	}
 
-	if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL)) {
+	if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
+				DNS_ANSWER, DNS_ANSWER_SIZE)) {
 		ast_test_status_update(test, "Successfully added result with no canonical name\n");
+		result = ast_dns_query_get_result(&some_query);
+		ast_dns_result_free(result);
+		return AST_TEST_FAIL;
+	}
+
+	if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
+				NULL, DNS_ANSWER_SIZE)) {
+		ast_test_status_update(test, "Successfully added result with no answer\n");
+		result = ast_dns_query_get_result(&some_query);
+		ast_dns_result_free(result);
+		return AST_TEST_FAIL;
+	}
+
+	if (!ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, NULL,
+				DNS_ANSWER, 0)) {
+		ast_test_status_update(test, "Successfully added result with answer size of zero\n");
 		result = ast_dns_query_get_result(&some_query);
 		ast_dns_result_free(result);
 		return AST_TEST_FAIL;
@@ -453,7 +482,8 @@
 
 	memset(&some_query, 0, sizeof(some_query));
 
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org")) {
+	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org",
+				DNS_ANSWER, DNS_ANSWER_SIZE)) {
 		ast_test_status_update(test, "Unable to set result for DNS query\n");
 		return AST_TEST_FAIL;
 	}
@@ -571,7 +601,8 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org")) {
+	if (ast_dns_resolver_set_result(&some_query, 0, 0, ns_r_noerror, "asterisk.org",
+				DNS_ANSWER, DNS_ANSWER_SIZE)) {
 		ast_test_status_update(test, "Unable to set result for DNS query\n");
 		return AST_TEST_FAIL;
 	}
@@ -680,7 +711,7 @@
 		return NULL;
 	}
 
-	ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org");
+	ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE);
 
 	inet_pton(AF_INET, V4, v4_buf);
 	ast_dns_resolver_add_record(query, ns_t_a, ns_c_in, 12345, v4_buf, V4_BUFSIZE);

Modified: team/group/dns/tests/test_dns_recurring.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/tests/test_dns_recurring.c?view=diff&rev=433150&r1=433149&r2=433150
==============================================================================
--- team/group/dns/tests/test_dns_recurring.c (original)
+++ team/group/dns/tests/test_dns_recurring.c Thu Mar 19 10:16:09 2015
@@ -77,6 +77,9 @@
 	return rdata;
 }
 
+#define DNS_ANSWER "Yes sirree"
+#define DNS_ANSWER_SIZE strlen(DNS_ANSWER)
+
 /*!
  * \brief Thread that performs asynchronous resolution.
  *
@@ -126,7 +129,7 @@
 	/* When the query isn't canceled, we set the TTL of the results based on what
 	 * we've been told to set it to
 	 */
-	ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org");
+	ast_dns_resolver_set_result(query, 0, 0, ns_r_noerror, "asterisk.org", DNS_ANSWER, DNS_ANSWER_SIZE);
 
 	inet_pton(AF_INET, ADDR1, addr1_buf);
 	ast_dns_resolver_add_record(query, ns_t_a, ns_c_in, rdata->ttl1, addr1_buf, ADDR1_BUFSIZE);




More information about the svn-commits mailing list