Review Board 1.7.16


DNS: Add NAPTR support and tests

Review Request #4542 - Created March 27, 2015 and submitted

Mark Michelson
/team/group/dns/
Reviewers
asterisk-dev
Asterisk
This adds NAPTR support for DNS in Asterisk.

The main parts of this are the functions for allocating a DNS NAPTR record when a resolver wishes to add a NAPTR record, the sorting algorithm for sorting DNS NAPTR records, and the tests that use a mock DNS resolver.

NOTE: There is likely to be some overlap here in this review and Josh's SRV review (/r/4528). Our stance on this is that we will factor out the duplicated code once both SRV and NAPTR have been merged into the main DNS branch. The factoring out of common functions will be placed in its own review.
All previous DNS tests continue to pass, and all new tests added in this review pass as well.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

1 2 3
1 2 3

  1. /team/group/dns/include/asterisk/dns_internal.h: Loading...
  2. /team/group/dns/main/dns_core.c: Loading...
  3. /team/group/dns/main/dns_naptr.c: Loading...
  4. /team/group/dns/res/res_resolver_unbound.c: Loading...
  5. /team/group/dns/tests/test_dns_naptr.c: Loading...
/team/group/dns/include/asterisk/dns_internal.h
Revision 433573 New Change
[20] 32 lines
[+20] [+] struct ast_dns_record {
33
	int ttl;
33
	int ttl;
34
	/*! \brief The size of the raw DNS record */
34
	/*! \brief The size of the raw DNS record */
35
	size_t data_len;
35
	size_t data_len;
36
	/*! \brief Linked list information */
36
	/*! \brief Linked list information */
37
	AST_LIST_ENTRY(ast_dns_record) list;
37
	AST_LIST_ENTRY(ast_dns_record) list;

    
   
38
	char *data_ptr;
38
	/*! \brief The raw DNS record */
39
	/*! \brief The raw DNS record */
39
	char data[0];
40
	char data[0];
40
};
41
};
41

    
   
42

   
42
/*! \brief An SRV record */
43
/*! \brief An SRV record */
[+20] [20] 24 lines
[+20] [+] struct ast_dns_naptr_record {
67
	const char *replacement;
68
	const char *replacement;
68
	/*! \brief The order for the NAPTR record */
69
	/*! \brief The order for the NAPTR record */
69
	unsigned short order;
70
	unsigned short order;
70
	/*! \brief The preference of the NAPTR record */
71
	/*! \brief The preference of the NAPTR record */
71
	unsigned short preference;
72
	unsigned short preference;

    
   
73
	char data[0];
72
};
74
};
73

    
   
75

   
74
/*! \brief The result of a DNS query */
76
/*! \brief The result of a DNS query */
75
struct ast_dns_result {
77
struct ast_dns_result {
76
	/*! \brief Whether the result is secure */
78
	/*! \brief Whether the result is secure */
[+20] [20] 6 lines
[+20] struct ast_dns_result {
83
	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
85
	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
84
	/*! \brief The canonical name */
86
	/*! \brief The canonical name */
85
	const char *canonical;
87
	const char *canonical;
86
	/*! \brief The raw DNS answer */
88
	/*! \brief The raw DNS answer */
87
	const char *answer;
89
	const char *answer;

    
   
90
	/*! \brief The size of the raw DNS answer */

    
   
91
	size_t answer_size;
88
	/*! \brief Buffer for dynamic data */
92
	/*! \brief Buffer for dynamic data */
89
	char buf[0];
93
	char buf[0];
90
};
94
};
91

    
   
95

   
92
/*! \brief A DNS query */
96
/*! \brief A DNS query */
[+20] [20] 48 lines
[+20] [+] struct ast_sched_context;
141
 * \brief Retrieve the DNS scheduler context
145
 * \brief Retrieve the DNS scheduler context
142
 *
146
 *
143
 * \return scheduler context
147
 * \return scheduler context
144
 */
148
 */
145
struct ast_sched_context *ast_dns_get_sched(void);
149
struct ast_sched_context *ast_dns_get_sched(void);

    
   
150

   

    
   
151
/*!

    
   
152
 * \brief Allocate and parse a DNS NAPTR record

    
   
153
 *

    
   
154
 * \param query The DNS query

    
   
155
 * \param data This specific NAPTR record

    
   
156
 * \param size The size of the NAPTR record

    
   
157
 *

    
   
158
 * \retval non-NULL success

    
   
159
 * \retval NULL failure

    
   
160
 */

    
   
161
struct ast_dns_record *ast_dns_naptr_alloc(struct ast_dns_query *query, const char *data, const size_t size);

    
   
162

   

    
   
163
/*!

    
   
164
 * \brief Sort the NAPTR records on a result

    
   
165
 *

    
   
166
 * \param result The DNS result

    
   
167
 */

    
   
168
void ast_dns_naptr_sort(struct ast_dns_result *result);
/team/group/dns/main/dns_core.c
Revision 433573 New Change
 
/team/group/dns/main/dns_naptr.c
Revision 433573 New Change
 
/team/group/dns/res/res_resolver_unbound.c
Revision 433573 New Change
 
/team/group/dns/tests/test_dns_naptr.c
New File
 
  1. /team/group/dns/include/asterisk/dns_internal.h: Loading...
  2. /team/group/dns/main/dns_core.c: Loading...
  3. /team/group/dns/main/dns_naptr.c: Loading...
  4. /team/group/dns/res/res_resolver_unbound.c: Loading...
  5. /team/group/dns/tests/test_dns_naptr.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.