| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <errno.h> |
| 20 |
#include <netdb.h> |
| 21 |
#include <resolv.h> |
| 22 |
#include <stdbool.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <support/check.h> |
| 25 |
#include <support/check_nss.h> |
| 26 |
#include <support/resolv_test.h> |
| 27 |
#include <support/support.h> |
| 28 |
#include <support/xmemstream.h> |
| 29 |
|
| 30 |
|
| 31 |
static volatile unsigned int queries; |
| 32 |
|
| 33 |
|
| 34 |
static volatile bool stuff_txt; |
| 35 |
|
| 36 |
static void |
| 37 |
response (const struct resolv_response_context *ctx, |
| 38 |
struct resolv_response_builder *b, |
| 39 |
const char *qname, uint16_t qclass, uint16_t qtype) |
| 40 |
{ |
| 41 |
|
| 42 |
if (!ctx->tcp) |
| 43 |
{ |
| 44 |
struct resolv_response_flags flags = {.tc = true}; |
| 45 |
resolv_response_init (b, flags); |
| 46 |
resolv_response_add_question (b, qname, qclass, qtype); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
++queries; |
| 53 |
TEST_VERIFY (queries <= 4); |
| 54 |
|
| 55 |
|
| 56 |
TEST_COMPARE (qtype, T_A); |
| 57 |
TEST_COMPARE (qclass, C_IN); |
| 58 |
TEST_COMPARE_STRING (qname, "example.com"); |
| 59 |
|
| 60 |
struct resolv_response_flags flags = {}; |
| 61 |
resolv_response_init (b, flags); |
| 62 |
resolv_response_add_question (b, qname, qclass, qtype); |
| 63 |
|
| 64 |
resolv_response_section (b, ns_s_an); |
| 65 |
|
| 66 |
if (stuff_txt) |
| 67 |
{ |
| 68 |
resolv_response_open_record (b, qname, qclass, T_TXT, 60); |
| 69 |
int zero = 0; |
| 70 |
for (int i = 0; i <= 15000; ++i) |
| 71 |
resolv_response_add_data (b, &zero, sizeof (zero)); |
| 72 |
resolv_response_close_record (b); |
| 73 |
} |
| 74 |
|
| 75 |
for (int i = 0; i < 200; ++i) |
| 76 |
{ |
| 77 |
resolv_response_open_record (b, qname, qclass, qtype, 60); |
| 78 |
char ipv4[4] = {192, 0, 2, i + 1}; |
| 79 |
resolv_response_add_data (b, &ipv4, sizeof (ipv4)); |
| 80 |
resolv_response_close_record (b); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
static int |
| 85 |
do_test (void) |
| 86 |
{ |
| 87 |
struct resolv_test *obj = resolv_test_start |
| 88 |
((struct resolv_redirect_config) |
| 89 |
{ |
| 90 |
.response_callback = response |
| 91 |
}); |
| 92 |
|
| 93 |
_res.options |= RES_NOAAAA; |
| 94 |
|
| 95 |
for (int do_stuff_txt = 0; do_stuff_txt < 2; ++do_stuff_txt) |
| 96 |
{ |
| 97 |
queries = 0; |
| 98 |
stuff_txt = do_stuff_txt; |
| 99 |
|
| 100 |
struct addrinfo *ai = NULL; |
| 101 |
int ret; |
| 102 |
ret = getaddrinfo ("example.com", "80", |
| 103 |
&(struct addrinfo) |
| 104 |
{ |
| 105 |
.ai_family = AF_UNSPEC, |
| 106 |
.ai_socktype = SOCK_STREAM, |
| 107 |
}, &ai); |
| 108 |
|
| 109 |
char *expected_result; |
| 110 |
{ |
| 111 |
struct xmemstream mem; |
| 112 |
xopen_memstream (&mem); |
| 113 |
for (int i = 0; i < 200; ++i) |
| 114 |
fprintf (mem.out, "address: STREAM/TCP 192.0.2.%d 80\n", i + 1); |
| 115 |
xfclose_memstream (&mem); |
| 116 |
expected_result = mem.buffer; |
| 117 |
} |
| 118 |
|
| 119 |
check_addrinfo ("example.com", ai, ret, expected_result); |
| 120 |
|
| 121 |
free (expected_result); |
| 122 |
freeaddrinfo (ai); |
| 123 |
} |
| 124 |
|
| 125 |
resolv_test_end (obj); |
| 126 |
return 0; |
| 127 |
} |
| 128 |
|
| 129 |
#include <support/test-driver.c> |