Skip to content

Commit e10a923

Browse files
pemensiksimonkelley
authored andcommitted
Move repeated test pattern to server_test_type
Use static function to test similar checks in multiple places.
1 parent 51f7bc9 commit e10a923

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/forward.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ static void server_send_log(struct server *server, int fd,
284284
}
285285
#endif
286286

287+
static int server_test_type(const struct server *server,
288+
const char *domain, int type, int extratype)
289+
{
290+
return (type == (server->flags & (SERV_TYPE | extratype)) &&
291+
(type != SERV_HAS_DOMAIN || hostname_isequal(domain, server->domain)) &&
292+
!(server->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)));
293+
}
294+
287295
static int forward_query(int udpfd, union mysockaddr *udpaddr,
288296
union all_addr *dst_addr, unsigned int dst_iface,
289297
struct dns_header *header, size_t plen, time_t now,
@@ -538,9 +546,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
538546
domain may be NULL, in which case server->domain
539547
must be NULL also. */
540548

541-
if (type == (start->flags & SERV_TYPE) &&
542-
(type != SERV_HAS_DOMAIN || hostname_isequal(domain, start->domain)) &&
543-
!(start->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)) &&
549+
if (server_test_type(start, domain, type, 0) &&
544550
((fd = allocate_rfd(&forward->rfds, start)) != -1))
545551
{
546552

@@ -1076,9 +1082,7 @@ void reply_query(int fd, time_t now)
10761082

10771083
while (1)
10781084
{
1079-
if (type == (start->flags & (SERV_TYPE | SERV_DO_DNSSEC)) &&
1080-
((type & SERV_TYPE) != SERV_HAS_DOMAIN || hostname_isequal(domain, start->domain)) &&
1081-
!(start->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)))
1085+
if (server_test_type(start, domain, type, 0))
10821086
{
10831087
new_server = start;
10841088
if (server == start)
@@ -1662,9 +1666,7 @@ static int tcp_key_recurse(time_t now, int status, struct dns_header *header, si
16621666
}
16631667
}
16641668

1665-
if (type != (server->flags & (SERV_TYPE | SERV_DO_DNSSEC)) ||
1666-
(type == SERV_HAS_DOMAIN && !hostname_isequal(domain, server->domain)) ||
1667-
(server->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)))
1669+
if (!server_test_type(server, domain, type, SERV_DO_DNSSEC))
16681670
continue;
16691671

16701672
retry:
@@ -1976,9 +1978,7 @@ unsigned char *tcp_request(int confd, time_t now,
19761978
}
19771979

19781980
/* server for wrong domain */
1979-
if (type != (last_server->flags & SERV_TYPE) ||
1980-
(type == SERV_HAS_DOMAIN && !hostname_isequal(domain, last_server->domain)) ||
1981-
(last_server->flags & (SERV_LITERAL_ADDRESS | SERV_LOOP)))
1981+
if (!server_test_type(last_server, domain, type, 0))
19821982
continue;
19831983

19841984
retry:

0 commit comments

Comments
 (0)