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
Diff Revision 2 Diff Revision 3
[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
	 */
38
	char *data_ptr;
46
	char *data_ptr;
39
	/*! \brief The raw DNS record */
47
	/*! \brief The raw DNS record */
40
	char data[0];
48
	char data[0];
41
};
49
};
42

    
   
50

   
[+20] [20] 25 lines
[+20] [+] struct ast_dns_naptr_record {
68
	const char *replacement;
76
	const char *replacement;
69
	/*! \brief The order for the NAPTR record */
77
	/*! \brief The order for the NAPTR record */
70
	unsigned short order;
78
	unsigned short order;
71
	/*! \brief The preference of the NAPTR record */
79
	/*! \brief The preference of the NAPTR record */
72
	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
	 */
73
	char data[0];
87
	char data[0];
74
};
88
};
75

    
   
89

   
76
/*! \brief The result of a DNS query */
90
/*! \brief The result of a DNS query */
77
struct ast_dns_result {
91
struct ast_dns_result {
[+20] [20] 78 lines
[+20] [+] struct ast_sched_context *ast_dns_get_sched(void);
156
 * \param size The size of the NAPTR record
170
 * \param size The size of the NAPTR record
157
 *
171
 *
158
 * \retval non-NULL success
172
 * \retval non-NULL success
159
 * \retval NULL failure
173
 * \retval NULL failure
160
 */
174
 */
161
struct ast_dns_record *ast_dns_naptr_alloc(struct ast_dns_query *query, const char *data, const size_t size);
175
struct ast_dns_record *dns_naptr_alloc(struct ast_dns_query *query, const char *data, const size_t size);
162

    
   
176

   
163
/*!
177
/*!
164
 * \brief Sort the NAPTR records on a result
178
 * \brief Sort the NAPTR records on a result
165
 *
179
 *
166
 * \param result The DNS result
180
 * \param result The DNS result
167
 */
181
 */
168
void ast_dns_naptr_sort(struct ast_dns_result *result);
182
void dns_naptr_sort(struct ast_dns_result *result);
/team/group/dns/main/dns_core.c
Diff Revision 2 Diff Revision 3
 
/team/group/dns/main/dns_naptr.c
Diff Revision 2 Diff Revision 3
 
/team/group/dns/res/res_resolver_unbound.c
Diff Revision 2 Diff Revision 3
 
/team/group/dns/tests/test_dns_naptr.c
Diff Revision 2 Diff Revision 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...

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.