Asterisk - The Open Source Telephony Project
18.5.0
|
#include "asterisk.h"
#include "asterisk/dns_core.h"
#include "asterisk/dns_test.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Functions | |
int | ast_dns_test_generate_result (struct ast_dns_query *query, void *records, size_t num_records, size_t record_size, record_fn generate, char *buffer) |
Generate a full DNS response for the given DNS records. More... | |
int | ast_dns_test_write_domain (const char *string, char *buf) |
Write a DNS domain to a buffer. More... | |
int | ast_dns_test_write_string (const struct ast_dns_test_string *string, char *buf) |
Write a DNS string to a buffer. More... | |
static int | generate_dns_answer (int ttl, char *buf) |
Generate a DNS answer and write it to a buffer. More... | |
static int | generate_dns_header (unsigned short num_records, char *buf) |
Generate a DNS header and write it to a buffer. More... | |
static int | generate_dns_question (char *buf) |
Generate a DNS question and write it to a buffer. More... | |
Variables | |
const char | DNS_HEADER [] |
const char | DNS_QUESTION [] |
const char | NAPTR_ANSWER [] |
int ast_dns_test_generate_result | ( | struct ast_dns_query * | query, |
void * | records, | ||
size_t | num_records, | ||
size_t | record_size, | ||
record_fn | generate, | ||
char * | buffer | ||
) |
Generate a full DNS response for the given DNS records.
This function takes care of generating the DNS header, question, and answer sections of a DNS response. In order to place test-specific record data into the DNS answers, a callback is provided as a parameter to this function so that the necessary records can be encoded properly by the tests.
There is no buffer size passed to this function. Tests are expected to use a buffer that is sufficiently large for their tests.
query | The DNS query that is being processed |
records | An array of test-specific representations of DNS records |
num_records | The number of elements in the records array |
record_size | The size of each element in the records array |
generate | The test-specific encoder for DNS records |
buffer | The buffer into which to write the DNS response |
Definition at line 222 of file dns_test.c.
References ast_dns_test_write_domain(), ast_dns_test_write_string(), buf, generate_dns_answer(), generate_dns_header(), generate_dns_question(), and records.
Referenced by naptr_thread(), and srv_thread().
int ast_dns_test_write_domain | ( | const char * | string, |
char * | buf | ||
) |
Write a DNS domain to a buffer.
A DNS domain consists of a series of labels separated by dots. Each of these labels gets written as a DNS string. A DNS domain ends with a NULL label, which is essentially a zero-length DNS string.
There is no buffer size passed to this function since we provide the data ourselves and have sized the buffer to be way larger than necessary for the tests.
string | The DNS domain to write |
buf | The buffer to write the domain into |
Definition at line 196 of file dns_test.c.
References ast_dns_test_write_string(), ast_strdupa, ast_strlen_zero, buf, copy(), ast_dns_test_string::len, strsep(), and ast_dns_test_string::val.
Referenced by ast_dns_test_generate_result(), generate_naptr_record(), and generate_srv_record().
int ast_dns_test_write_string | ( | const struct ast_dns_test_string * | string, |
char * | buf | ||
) |
Write a DNS string to a buffer.
This writes the DNS string to the buffer and returns the total number of bytes written to the buffer.
There is no buffer size passed to this function since we provide the data ourselves and have sized the buffer to be way larger than necessary for the tests.
string | The string to write |
buf | The buffer to write the string into |
Definition at line 162 of file dns_test.c.
References len(), and ast_dns_test_string::val.
Referenced by ast_dns_test_generate_result(), ast_dns_test_write_domain(), and generate_naptr_record().
|
static |
Generate a DNS answer and write it to a buffer.
The DNS answer is the third (and in our case final) part of a DNS response. The DNS answer generated here is only partial. The record-specific data is generated by a separate function. DNS answers in our tests may have variable TTLs, but the rest is hard-coded.
There is no buffer size passed to this function since we provide the data ourselves and have sized the buffer to be way larger than necessary for the tests.
buf | The buffer to write the answer into |
The | number of bytes written to the buffer |
Definition at line 135 of file dns_test.c.
References ARRAY_LEN, and NAPTR_ANSWER.
Referenced by ast_dns_test_generate_result().
|
static |
Generate a DNS header and write it to a buffer.
The DNS header is the first part of a DNS request or response. In our case, the only part of the header that a test can affect is the number of answers. The rest of the DNS header is based on hard-coded values.
There is no buffer size passed to this function since we provide the data ourselves and have sized the buffer to be way larger than necessary for the tests.
num_records | The number of DNS records in this DNS response |
buf | The buffer to write the header into |
The | number of bytes written to the buffer |
Definition at line 64 of file dns_test.c.
References ARRAY_LEN, and DNS_HEADER.
Referenced by ast_dns_test_generate_result().
|
static |
Generate a DNS question and write it to a buffer.
The DNS question is the second part of a DNS request or response. All DNS questions in this file are for the same domain and thus the DNS question is a hard-coded value.
There is no buffer size passed to this function since we provide the data ourselves and have sized the buffer to be way larger than necessary for the tests.
buf | The buffer to write the question into |
The | number of bytes written to the buffer |
Definition at line 102 of file dns_test.c.
References ARRAY_LEN, and DNS_QUESTION.
Referenced by ast_dns_test_generate_result().
const char DNS_HEADER[] |
Definition at line 32 of file dns_test.c.
Referenced by generate_dns_header().
const char DNS_QUESTION[] |
Definition at line 75 of file dns_test.c.
Referenced by generate_dns_question().
const char NAPTR_ANSWER[] |
Definition at line 108 of file dns_test.c.
Referenced by generate_dns_answer().