mirror of
https://git.proxmox.com/git/mirror_frr
synced 2026-01-06 18:10:20 +00:00
lib,nhrpd,bgpd/bmp: pass resolver failure details
To keep the calling code agnostic of the DNS resolver libary used, pass a strerror-style string instead of a status code that would need extra handling. Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
parent
9e89da8c55
commit
3286ca0750
@ -1662,14 +1662,16 @@ static void bmp_active_connect(struct bmp_active *ba)
|
||||
bmp_active_setup(ba);
|
||||
}
|
||||
|
||||
static void bmp_active_resolved(struct resolver_query *resq, int numaddrs,
|
||||
union sockunion *addr)
|
||||
static void bmp_active_resolved(struct resolver_query *resq, const char *errstr,
|
||||
int numaddrs, union sockunion *addr)
|
||||
{
|
||||
struct bmp_active *ba = container_of(resq, struct bmp_active, resq);
|
||||
unsigned i;
|
||||
|
||||
if (numaddrs <= 0) {
|
||||
zlog_warn("bmp[%s]: hostname resolution failed", ba->hostname);
|
||||
zlog_warn("bmp[%s]: hostname resolution failed: %s",
|
||||
ba->hostname, errstr);
|
||||
ba->last_err = errstr;
|
||||
ba->curretry += ba->curretry / 2;
|
||||
ba->addrpos = 0;
|
||||
ba->addrtotal = 0;
|
||||
@ -1701,6 +1703,8 @@ static int bmp_active_thread(struct thread *t)
|
||||
THREAD_OFF(ba->t_read);
|
||||
THREAD_OFF(ba->t_write);
|
||||
|
||||
ba->last_err = NULL;
|
||||
|
||||
if (ba->socket == -1) {
|
||||
resolver_resolve(&ba->resq, AF_UNSPEC, ba->hostname,
|
||||
bmp_active_resolved);
|
||||
@ -1713,8 +1717,9 @@ static int bmp_active_thread(struct thread *t)
|
||||
|
||||
sockunion2str(&ba->addrs[ba->addrpos], buf, sizeof(buf));
|
||||
if (ret < 0 || status != 0) {
|
||||
zlog_warn("bmp[%s]: failed to connect to %s:%d",
|
||||
ba->hostname, buf, ba->port);
|
||||
ba->last_err = strerror(status);
|
||||
zlog_warn("bmp[%s]: failed to connect to %s:%d: %s",
|
||||
ba->hostname, buf, ba->port, ba->last_err);
|
||||
goto out_next;
|
||||
}
|
||||
|
||||
|
||||
@ -182,6 +182,7 @@ struct bmp_active {
|
||||
unsigned addrpos, addrtotal;
|
||||
union sockunion addrs[8];
|
||||
int socket;
|
||||
const char *last_err;
|
||||
struct thread *t_timer, *t_read, *t_write;
|
||||
};
|
||||
|
||||
|
||||
@ -145,7 +145,8 @@ static void ares_address_cb(void *arg, int status, int timeouts,
|
||||
{
|
||||
struct resolver_query *query = (struct resolver_query *)arg;
|
||||
union sockunion addr[16];
|
||||
void (*callback)(struct resolver_query *, int, union sockunion *);
|
||||
void (*callback)(struct resolver_query *, const char *, int,
|
||||
union sockunion *);
|
||||
size_t i;
|
||||
|
||||
callback = query->callback;
|
||||
@ -153,9 +154,10 @@ static void ares_address_cb(void *arg, int status, int timeouts,
|
||||
|
||||
if (status != ARES_SUCCESS) {
|
||||
if (resolver_debug)
|
||||
zlog_debug("[%p] Resolving failed", query);
|
||||
zlog_debug("[%p] Resolving failed (%s)",
|
||||
query, ares_strerror(status));
|
||||
|
||||
callback(query, -1, NULL);
|
||||
callback(query, ares_strerror(status), -1, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -177,25 +179,26 @@ static void ares_address_cb(void *arg, int status, int timeouts,
|
||||
if (resolver_debug)
|
||||
zlog_debug("[%p] Resolved with %d results", query, (int)i);
|
||||
|
||||
callback(query, i, &addr[0]);
|
||||
callback(query, NULL, i, &addr[0]);
|
||||
}
|
||||
|
||||
static int resolver_cb_literal(struct thread *t)
|
||||
{
|
||||
struct resolver_query *query = THREAD_ARG(t);
|
||||
void (*callback)(struct resolver_query *, int, union sockunion *);
|
||||
void (*callback)(struct resolver_query *, const char *, int,
|
||||
union sockunion *);
|
||||
|
||||
callback = query->callback;
|
||||
query->callback = NULL;
|
||||
|
||||
callback(query, 1, &query->literal_addr);
|
||||
callback(query, ARES_SUCCESS, 1, &query->literal_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void resolver_resolve(struct resolver_query *query, int af,
|
||||
const char *hostname,
|
||||
void (*callback)(struct resolver_query *, int,
|
||||
union sockunion *))
|
||||
void (*callback)(struct resolver_query *, const char *,
|
||||
int, union sockunion *))
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
@ -14,7 +14,8 @@
|
||||
#include "sockunion.h"
|
||||
|
||||
struct resolver_query {
|
||||
void (*callback)(struct resolver_query *, int n, union sockunion *);
|
||||
void (*callback)(struct resolver_query *, const char *errstr, int n,
|
||||
union sockunion *);
|
||||
|
||||
/* used to immediate provide the result if IP literal is passed in */
|
||||
union sockunion literal_addr;
|
||||
@ -24,6 +25,7 @@ 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 *,
|
||||
int, union sockunion *));
|
||||
const char *, int,
|
||||
union sockunion *));
|
||||
|
||||
#endif /* _FRR_RESOLVER_H */
|
||||
|
||||
@ -238,8 +238,8 @@ nhrp_reg_by_nbma(struct nhrp_nhs *nhs, const union sockunion *nbma_addr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void nhrp_nhs_resolve_cb(struct resolver_query *q, int n,
|
||||
union sockunion *addrs)
|
||||
static void nhrp_nhs_resolve_cb(struct resolver_query *q, const char *errstr,
|
||||
int n, union sockunion *addrs)
|
||||
{
|
||||
struct nhrp_nhs *nhs = container_of(q, struct nhrp_nhs, dns_resolve);
|
||||
struct nhrp_interface *nifp = nhs->ifp->info;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user