summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2021-12-01 07:12:33 +0100
committerGitHub <noreply@github.com>2021-12-01 07:12:33 +0100
commite2144103f81c5bd46f734bc94e1dbc0aebb66f6e (patch)
treeb7a657150a5c54a2a196476047bb90d3d5ec5c41
parentMerge pull request #9610 from iqras23/best_path (diff)
parentlib: resolver per vrf support (diff)
downloadfrr-e2144103f81c5bd46f734bc94e1dbc0aebb66f6e.tar.xz
frr-e2144103f81c5bd46f734bc94e1dbc0aebb66f6e.zip
Merge pull request #9878 from pguibert6WIND/resolver_vrf
lib: resolver per vrf support
-rw-r--r--bgpd/bgp_bmp.c8
-rw-r--r--lib/resolver.c14
-rw-r--r--lib/resolver.h8
-rw-r--r--nhrpd/nhrp_nhs.c4
-rw-r--r--tests/lib/test_resolver.c2
5 files changed, 27 insertions, 9 deletions
diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c
index 9f27399f5..746f067ae 100644
--- a/bgpd/bgp_bmp.c
+++ b/bgpd/bgp_bmp.c
@@ -1833,6 +1833,7 @@ static int bmp_active_thread(struct thread *t)
socklen_t slen;
int status, ret;
char buf[SU_ADDRSTRLEN];
+ vrf_id_t vrf_id;
/* all 3 end up here, though only timer or read+write are active
* at a time */
@@ -1843,7 +1844,12 @@ static int bmp_active_thread(struct thread *t)
ba->last_err = NULL;
if (ba->socket == -1) {
- resolver_resolve(&ba->resq, AF_UNSPEC, ba->hostname,
+ /* get vrf_id */
+ if (!ba->targets || !ba->targets->bgp)
+ vrf_id = VRF_DEFAULT;
+ else
+ vrf_id = ba->targets->bgp->vrf_id;
+ resolver_resolve(&ba->resq, AF_UNSPEC, vrf_id, ba->hostname,
bmp_active_resolved);
return 0;
}
diff --git a/lib/resolver.c b/lib/resolver.c
index e3dba5f8a..29138bbc8 100644
--- a/lib/resolver.c
+++ b/lib/resolver.c
@@ -21,6 +21,7 @@
#include "resolver.h"
#include "command.h"
#include "xref.h"
+#include "vrf.h"
XREF_SETUP();
@@ -244,7 +245,7 @@ static int resolver_cb_literal(struct thread *t)
return 0;
}
-void resolver_resolve(struct resolver_query *query, int af,
+void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
const char *hostname,
void (*callback)(struct resolver_query *, const char *,
int, union sockunion *))
@@ -279,7 +280,18 @@ void resolver_resolve(struct resolver_query *query, int af,
if (resolver_debug)
zlog_debug("[%p] Resolving '%s'", query, hostname);
+ ret = vrf_switch_to_netns(vrf_id);
+ if (ret < 0) {
+ flog_err_sys(EC_LIB_SOCKET, "%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+ return;
+ }
ares_gethostbyname(state.channel, hostname, af, ares_address_cb, query);
+ ret = vrf_switchback_to_initial();
+ if (ret < 0)
+ flog_err_sys(EC_LIB_SOCKET,
+ "%s: Can't switchback from VRF %u (%s)", __func__,
+ vrf_id, safe_strerror(errno));
resolver_update_timeouts(&state);
}
diff --git a/lib/resolver.h b/lib/resolver.h
index 5f922dcb5..988449693 100644
--- a/lib/resolver.h
+++ b/lib/resolver.h
@@ -27,10 +27,10 @@ struct resolver_query {
};
void resolver_init(struct thread_master *tm);
-void resolver_resolve(struct resolver_query *query, int af,
- const char *hostname, void (*cb)(struct resolver_query *,
- const char *, int,
- union sockunion *));
+void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
+ const char *hostname,
+ void (*cb)(struct resolver_query *, const char *, int,
+ union sockunion *));
#ifdef __cplusplus
}
diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c
index 597c125e1..3733910a6 100644
--- a/nhrpd/nhrp_nhs.c
+++ b/nhrpd/nhrp_nhs.c
@@ -324,8 +324,8 @@ static int nhrp_nhs_resolve(struct thread *t)
{
struct nhrp_nhs *nhs = THREAD_ARG(t);
- resolver_resolve(&nhs->dns_resolve, AF_INET, nhs->nbma_fqdn,
- nhrp_nhs_resolve_cb);
+ resolver_resolve(&nhs->dns_resolve, AF_INET, VRF_DEFAULT,
+ nhs->nbma_fqdn, nhrp_nhs_resolve_cb);
return 0;
}
diff --git a/tests/lib/test_resolver.c b/tests/lib/test_resolver.c
index 0b3dccc82..6a582ccea 100644
--- a/tests/lib/test_resolver.c
+++ b/tests/lib/test_resolver.c
@@ -63,7 +63,7 @@ DEFUN (test_resolve,
"DNS resolver\n"
"Name to resolve\n")
{
- resolver_resolve(&query, AF_UNSPEC, argv[1]->arg, resolver_result);
+ resolver_resolve(&query, AF_UNSPEC, 0, argv[1]->arg, resolver_result);
return CMD_SUCCESS;
}