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.
/team/group/dns/include/asterisk/dns_internal.h
Revision 433885 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
	/*! \brief pointer to record-specific data.

    
   
39
	 *

    
   
40
	 * For certain "subclasses" of DNS records, the

    
   
41
	 * location of the raw DNS data will differ from

    
   
42
	 * the generic case. This pointer will reliably

    
   
43
	 * be set to point to the raw DNS data, no matter

    
   
44
	 * where in the structure it may lie.

    
   
45
	 */

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

    
   
50

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

    
   
81
	/*! \brief Buffer for NAPTR-specific data

    
   
82
	 *

    
   
83
	 * This includes the raw NAPTR record, as well as

    
   
84
	 * the area where the flags, service, regexp, and

    
   
85
	 * replacement strings are stored.

    
   
86
	 */

    
   
87
	char data[0];
72
};
88
};
73

    
   
89

   
74
/*! \brief The result of a DNS query */
90
/*! \brief The result of a DNS query */
75
struct ast_dns_result {
91
struct ast_dns_result {
76
	/*! \brief Whether the result is secure */
92
	/*! \brief Whether the result is secure */
[+20] [20] 6 lines
[+20] struct ast_dns_result {
83
	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
99
	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
84
	/*! \brief The canonical name */
100
	/*! \brief The canonical name */
85
	const char *canonical;
101
	const char *canonical;
86
	/*! \brief The raw DNS answer */
102
	/*! \brief The raw DNS answer */
87
	const char *answer;
103
	const char *answer;

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

    
   
105
	size_t answer_size;
88
	/*! \brief Buffer for dynamic data */
106
	/*! \brief Buffer for dynamic data */
89
	char buf[0];
107
	char buf[0];
90
};
108
};
91

    
   
109

   
92
/*! \brief A DNS query */
110
/*! \brief A DNS query */
[+20] [20] 48 lines
[+20] [+] struct ast_sched_context;
141
 * \brief Retrieve the DNS scheduler context
159
 * \brief Retrieve the DNS scheduler context
142
 *
160
 *
143
 * \return scheduler context
161
 * \return scheduler context
144
 */
162
 */
145
struct ast_sched_context *ast_dns_get_sched(void);
163
struct ast_sched_context *ast_dns_get_sched(void);

    
   
164

   

    
   
165
/*!

    
   
166
 * \brief Allocate and parse a DNS NAPTR record

    
   
167
 *

    
   
168
 * \param query The DNS query

    
   
169
 * \param data This specific NAPTR record

    
   
170
 * \param size The size of the NAPTR record

    
   
171
 *

    
   
172
 * \retval non-NULL success

    
   
173
 * \retval NULL failure

    
   
174
 */

    
   
175
struct ast_dns_record *dns_naptr_alloc(struct ast_dns_query *query, const char *data, const size_t size);

    
   
176

   

    
   
177
/*!

    
   
178
 * \brief Sort the NAPTR records on a result

    
   
179
 *

    
   
180
 * \param result The DNS result

    
   
181
 */

    
   
182
void dns_naptr_sort(struct ast_dns_result *result);
/team/group/dns/main/dns_core.c
Revision 433885 New Change
 
/team/group/dns/main/dns_naptr.c
Revision 433885 New Change
 
/team/group/dns/res/res_resolver_unbound.c
Revision 433885 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.