Asterisk - The Open Source Telephony Project
18.5.0
|
DNS NAPTR Record Support. More...
#include "asterisk.h"
#include <arpa/nameser.h>
#include <netinet/in.h>
#include <resolv.h>
#include <regex.h>
#include "asterisk/dns_core.h"
#include "asterisk/dns_naptr.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dns_internal.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Macros | |
#define | PAST_END_OF_RECORD ptr >= end_of_record |
Enumerations | |
enum | flags_result { FLAGS_TERMINAL, FLAGS_EMPTY, FLAGS_UNKNOWN, FLAGS_INVALID } |
Result of analyzing NAPTR flags on a record. More... | |
Functions | |
const char * | ast_dns_naptr_get_flags (const struct ast_dns_record *record) |
Get the flags from a NAPTR record. More... | |
unsigned short | ast_dns_naptr_get_order (const struct ast_dns_record *record) |
Get the order from a NAPTR record. More... | |
unsigned short | ast_dns_naptr_get_preference (const struct ast_dns_record *record) |
Get the preference from a NAPTR record. More... | |
const char * | ast_dns_naptr_get_regexp (const struct ast_dns_record *record) |
Get the regular expression from a NAPTR record. More... | |
const char * | ast_dns_naptr_get_replacement (const struct ast_dns_record *record) |
Get the replacement value from a NAPTR record. More... | |
const char * | ast_dns_naptr_get_service (const struct ast_dns_record *record) |
Get the service from a NAPTR record. More... | |
static int | compare_order (const void *record1, const void *record2) |
static int | compare_preference (const void *record1, const void *record2) |
struct ast_dns_record * | dns_naptr_alloc (struct ast_dns_query *query, const char *data, const size_t size) |
Allocate and parse a DNS NAPTR record. More... | |
void | dns_naptr_sort (struct ast_dns_result *result) |
Sort the NAPTR records on a result. More... | |
static enum flags_result | interpret_flags (const char *flags, uint8_t flags_size) |
Analyze and interpret NAPTR flags as per RFC 3404. More... | |
static int | regexp_flags_invalid (const char *flags, const char *end) |
Determine if flags in the regexp are invalid. More... | |
static int | regexp_invalid (const char *regexp, uint8_t regexp_size) |
Determine if the regexp in a NAPTR record is invalid. More... | |
static int | regexp_pattern_invalid (const char *pattern, const char *end) |
Determine if the pattern in a regexp is invalid. More... | |
static int | regexp_repl_invalid (const char *repl, const char *end, char delim) |
Determine if the replacement in the regexp is invalid. More... | |
static int | services_invalid (const char *services, uint8_t services_size) |
Analyze NAPTR services for validity as defined by RFC 3404. More... | |
DNS NAPTR Record Support.
Definition in file dns_naptr.c.
#define PAST_END_OF_RECORD ptr >= end_of_record |
Definition at line 378 of file dns_naptr.c.
Referenced by dns_naptr_alloc().
enum flags_result |
Result of analyzing NAPTR flags on a record.
Definition at line 46 of file dns_naptr.c.
const char* ast_dns_naptr_get_flags | ( | const struct ast_dns_record * | record | ) |
Get the flags from a NAPTR record.
record | The DNS record |
Definition at line 600 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::flags.
Referenced by AST_TEST_DEFINE(), and sip_resolve_handle_naptr().
unsigned short ast_dns_naptr_get_order | ( | const struct ast_dns_record * | record | ) |
Get the order from a NAPTR record.
record | The DNS record |
Definition at line 632 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::order.
Referenced by AST_TEST_DEFINE(), and sip_resolve_callback().
unsigned short ast_dns_naptr_get_preference | ( | const struct ast_dns_record * | record | ) |
Get the preference from a NAPTR record.
record | The DNS record |
Definition at line 640 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::preference.
Referenced by AST_TEST_DEFINE().
const char* ast_dns_naptr_get_regexp | ( | const struct ast_dns_record * | record | ) |
Get the regular expression from a NAPTR record.
record | The DNS record |
Definition at line 616 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::regexp.
Referenced by AST_TEST_DEFINE().
const char* ast_dns_naptr_get_replacement | ( | const struct ast_dns_record * | record | ) |
Get the replacement value from a NAPTR record.
record | The DNS record |
Definition at line 624 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::replacement.
Referenced by AST_TEST_DEFINE(), and sip_resolve_handle_naptr().
const char* ast_dns_naptr_get_service | ( | const struct ast_dns_record * | record | ) |
Get the service from a NAPTR record.
record | The DNS record |
Definition at line 608 of file dns_naptr.c.
References ast_assert, ast_dns_record_get_rr_type(), and ast_dns_naptr_record::service.
Referenced by AST_TEST_DEFINE(), and sip_resolve_handle_naptr().
|
static |
|
static |
struct ast_dns_record* dns_naptr_alloc | ( | struct ast_dns_query * | query, |
const char * | data, | ||
const size_t | size | ||
) |
Allocate and parse a DNS NAPTR record.
query | The DNS query |
data | This specific NAPTR record |
size | The size of the NAPTR record |
non-NULL | success |
NULL | failure |
Definition at line 380 of file dns_naptr.c.
References ast_dns_result::answer, ast_dns_result::answer_size, ast_assert, ast_calloc, ast_log, ast_dns_naptr_record::data, ast_dns_record::data_ptr, dns_find_record(), dns_parse_short(), dns_parse_string(), errno, ast_dns_naptr_record::flags, FLAGS_INVALID, ast_dns_naptr_record::generic, interpret_flags(), LOG_ERROR, NULL, order, ast_dns_naptr_record::order, PAST_END_OF_RECORD, ast_dns_naptr_record::preference, ast_dns_naptr_record::regexp, regexp_invalid(), ast_dns_naptr_record::replacement, ast_dns_query::result, ast_dns_naptr_record::service, and services_invalid().
void dns_naptr_sort | ( | struct ast_dns_result * | result | ) |
Sort the NAPTR records on a result.
result | The DNS result |
Definition at line 551 of file dns_naptr.c.
References ast_alloca, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, compare_order(), compare_preference(), order, ast_dns_naptr_record::order, records, and ast_dns_result::records.
|
static |
Analyze and interpret NAPTR flags as per RFC 3404.
flags | The flags string from a NAPTR record The size of the flags string in bytes |
Definition at line 66 of file dns_naptr.c.
References FLAGS_EMPTY, FLAGS_INVALID, FLAGS_TERMINAL, and FLAGS_UNKNOWN.
Referenced by dns_naptr_alloc().
|
static |
Determine if flags in the regexp are invalid.
A NAPTR regexp is structured like so /pattern/repl/FLAGS
This ensures that the flags on the regexp are valid. Regexp flags can either be zero or one character long. If the flags are one character long, that character must be "i" to indicate the regex evaluation is case-insensitive.
flags | The regexp flags from the NAPTR record |
end | A pointer to the end of the flags string |
0 | Flags are valid |
-1 | Flags are invalid |
Definition at line 189 of file dns_naptr.c.
Referenced by regexp_invalid().
|
static |
Determine if the regexp in a NAPTR record is invalid.
The goal of this function is to divide the regexp into its constituent parts and then let validation subroutines determine if each part is valid. If all parts are valid, then the entire regexp is valid.
regexp | The regexp from the NAPTR record |
regexp_size | The size of the regexp string |
0 | regexp is valid |
non-zero | regexp is invalid |
Definition at line 309 of file dns_naptr.c.
References regexp_flags_invalid(), regexp_pattern_invalid(), and regexp_repl_invalid().
Referenced by dns_naptr_alloc().
|
static |
Determine if the pattern in a regexp is invalid.
A NAPTR regexp is structured like so /PATTERN/repl/flags
This ensures that the pattern on the regexp is valid. The pattern is passed to a regex compiler to determine its validity.
pattern | The pattern from the NAPTR record |
end | A pointer to the end of the pattern |
0 | Pattern is valid |
non-zero | Pattern is invalid |
Definition at line 275 of file dns_naptr.c.
Referenced by regexp_invalid().
|
static |
Determine if the replacement in the regexp is invalid.
A NAPTR regexp is structured like so /pattern/REPL/flags
This ensures that the replacement on the regexp is valid. The regexp replacement is free to use any character it wants, plus backreferences and an escaped regexp delimiter.
This function does not attempt to ensure that the backreferences refer to valid portions of the regexp's regex pattern.
repl | The regexp replacement string |
end | Pointer to the end of the replacement string |
delim | The delimiter character for the regexp |
0 | Replacement is valid |
-1 | Replacement is invalid |
Definition at line 228 of file dns_naptr.c.
References ast_assert.
Referenced by regexp_invalid().
|
static |
Analyze NAPTR services for validity as defined by RFC 3404.
services | The services string parsed from a NAPTR record |
services_size | The size of the services string |
0 | Services are valid |
-1 | Services are invalid |
Definition at line 130 of file dns_naptr.c.
Referenced by dns_naptr_alloc().