summaryrefslogtreecommitdiffstats
path: root/lib/resolver.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-12-11 12:27:05 +0100
committerDavid Lamparter <equinox@diac24.net>2019-12-11 12:27:05 +0100
commit125dc9525b34089903ccd4402a2e9bf8c6c7f801 (patch)
treef3899d3c1668a4db68955d3c417f30a9332e55e2 /lib/resolver.c
parentbgpd: Allow failed hostname lookup to continue in bmp (diff)
downloadfrr-125dc9525b34089903ccd4402a2e9bf8c6c7f801.tar.xz
frr-125dc9525b34089903ccd4402a2e9bf8c6c7f801.zip
lib/resolver: support/bypass IP literals
libc-ares doesn't do IP literals, so we have to do that before running off to do DNS. Since this isn't BMP specific, move to lib/ so NHRP can benefit too. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/resolver.c')
-rw-r--r--lib/resolver.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/resolver.c b/lib/resolver.c
index fb8aeed92..938ebd414 100644
--- a/lib/resolver.c
+++ b/lib/resolver.c
@@ -180,11 +180,25 @@ static void ares_address_cb(void *arg, int status, int timeouts,
callback(query, 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 *);
+
+ callback = query->callback;
+ query->callback = NULL;
+
+ callback(query, 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 *))
{
+ int ret;
+
if (query->callback != NULL) {
flog_err(
EC_LIB_RESOLVER,
@@ -193,10 +207,26 @@ void resolver_resolve(struct resolver_query *query, int af,
return;
}
+ query->callback = callback;
+ query->literal_cb = NULL;
+
+ ret = str2sockunion(hostname, &query->literal_addr);
+ if (ret == 0) {
+ if (resolver_debug)
+ zlog_debug("[%p] Resolving '%s' (IP literal)",
+ query, hostname);
+
+ /* for consistency with proper name lookup, don't call the
+ * callback immediately; defer to thread loop
+ */
+ thread_add_timer_msec(state.master, resolver_cb_literal,
+ query, 0, &query->literal_cb);
+ return;
+ }
+
if (resolver_debug)
zlog_debug("[%p] Resolving '%s'", query, hostname);
- query->callback = callback;
ares_gethostbyname(state.channel, hostname, af, ares_address_cb, query);
resolver_update_timeouts(&state);
}