]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
ecabab03 DL |
2 | /* |
3 | * FRR c-ares integration test | |
4 | * Copyright (C) 2021 David Lamparter for NetDEF, Inc. | |
ecabab03 DL |
5 | */ |
6 | ||
7 | /* this test is not run automatically since tests MUST NOT rely on any outside | |
8 | * state. DNS is most definitely "outside state". A testbed may not have any | |
9 | * internet connectivity at all. It may not have working DNS. Or worst of | |
10 | * all, whatever name we use to test may have a temporary failure entirely | |
11 | * beyond our control. | |
12 | * | |
13 | * The only way this test could be run in a testbed is with an all-local DNS | |
14 | * setup, which considering the resolver code is rarely touched is not worth | |
15 | * the time at all. Instead, after touching the resolver code, manually run | |
16 | * this test and throw some names at it. | |
17 | */ | |
18 | ||
19 | #include <zebra.h> | |
20 | ||
21 | #include "vty.h" | |
22 | #include "command.h" | |
23 | #include "resolver.h" | |
24 | #include "log.h" | |
25 | #include "sockunion.h" | |
26 | ||
27 | #include "tests/lib/cli/common_cli.h" | |
28 | ||
29 | extern struct thread_master *master; | |
30 | ||
31 | static void resolver_result(struct resolver_query *resq, const char *errstr, | |
32 | int numaddrs, union sockunion *addr) | |
33 | { | |
34 | int i; | |
35 | ||
36 | if (numaddrs <= 0) { | |
37 | zlog_warn("hostname resolution failed: %s", errstr); | |
38 | return; | |
39 | } | |
40 | ||
41 | for (i = 0; i < numaddrs; i++) | |
42 | zlog_info("resolver result: %pSU", &addr[i]); | |
43 | } | |
44 | ||
45 | struct resolver_query query; | |
46 | ||
47 | DEFUN (test_resolve, | |
48 | test_resolve_cmd, | |
49 | "resolve WORD", | |
50 | "DNS resolver\n" | |
51 | "Name to resolve\n") | |
52 | { | |
c742573b | 53 | resolver_resolve(&query, AF_UNSPEC, 0, argv[1]->arg, resolver_result); |
ecabab03 DL |
54 | return CMD_SUCCESS; |
55 | } | |
56 | ||
57 | __attribute__((_CONSTRUCTOR(2000))) | |
58 | static void test_setup(void) | |
59 | { | |
60 | test_log_prio = LOG_DEBUG; | |
61 | } | |
62 | ||
63 | void test_init(int argc, char **argv) | |
64 | { | |
65 | resolver_init(master); | |
66 | ||
67 | install_element(VIEW_NODE, &test_resolve_cmd); | |
68 | } |