1 /* Test the RES_NOAAAA resolver option with a large response.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
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>
30 /* Used to keep track of the number of queries. */
31 static volatile unsigned int queries
;
33 /* If true, add a large TXT record at the start of the answer section. */
34 static volatile bool stuff_txt
;
37 response (const struct resolv_response_context
*ctx
,
38 struct resolv_response_builder
*b
,
39 const char *qname
, uint16_t qclass
, uint16_t qtype
)
41 /* If not using TCP, just force its use. */
44 struct resolv_response_flags flags
= {.tc
= true};
45 resolv_response_init (b
, flags
);
46 resolv_response_add_question (b
, qname
, qclass
, qtype
);
50 /* The test needs to send four queries, the first three are used to
51 grow the NSS buffer via the ERANGE handshake. */
53 TEST_VERIFY (queries
<= 4);
55 /* AAAA queries are supposed to be disabled. */
56 TEST_COMPARE (qtype
, T_A
);
57 TEST_COMPARE (qclass
, C_IN
);
58 TEST_COMPARE_STRING (qname
, "example.com");
60 struct resolv_response_flags flags
= {};
61 resolv_response_init (b
, flags
);
62 resolv_response_add_question (b
, qname
, qclass
, qtype
);
64 resolv_response_section (b
, ns_s_an
);
68 resolv_response_open_record (b
, qname
, qclass
, T_TXT
, 60);
70 for (int i
= 0; i
<= 15000; ++i
)
71 resolv_response_add_data (b
, &zero
, sizeof (zero
));
72 resolv_response_close_record (b
);
75 for (int i
= 0; i
< 200; ++i
)
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
);
87 struct resolv_test
*obj
= resolv_test_start
88 ((struct resolv_redirect_config
)
90 .response_callback
= response
93 _res
.options
|= RES_NOAAAA
;
95 for (int do_stuff_txt
= 0; do_stuff_txt
< 2; ++do_stuff_txt
)
98 stuff_txt
= do_stuff_txt
;
100 struct addrinfo
*ai
= NULL
;
102 ret
= getaddrinfo ("example.com", "80",
105 .ai_family
= AF_UNSPEC
,
106 .ai_socktype
= SOCK_STREAM
,
109 char *expected_result
;
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
;
119 check_addrinfo ("example.com", ai
, ret
, expected_result
);
121 free (expected_result
);
125 resolv_test_end (obj
);
129 #include <support/test-driver.c>