From: florian Date: Sat, 23 Jan 2021 16:28:12 +0000 (+0000) Subject: Move resolv_conf string generation for ASR to function; makes X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fe412bb2388536fa392d8150ba1abdff533f686a;p=openbsd Move resolv_conf string generation for ASR to function; makes upcomming DNS64 diff simpler. --- diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c index b4ae3fd0abf..ef753454b2d 100644 --- a/sbin/unwind/resolver.c +++ b/sbin/unwind/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.132 2021/01/23 16:27:24 florian Exp $ */ +/* $OpenBSD: resolver.c,v 1.133 2021/01/23 16:28:12 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -195,6 +195,7 @@ int running_query_cnt(void); int *resolvers_to_restart(struct uw_conf *, struct uw_conf *); const char *query_imsg2str(struct query_imsg *); +char *gen_resolv_conf(void); struct uw_conf *resolver_conf; static struct imsgev *iev_frontend; @@ -1172,10 +1173,9 @@ create_resolver(enum uw_resolver_type type) { struct uw_resolver *res; struct trust_anchor *ta; - struct uw_forwarder *uw_forwarder; size_t i; int err; - char *resolv_conf = NULL, *tmp = NULL; + char *resolv_conf; if ((res = calloc(1, sizeof(*res))) == NULL) { log_warn("%s", __func__); @@ -1193,18 +1193,11 @@ create_resolver(enum uw_resolver_type type) free(res); return (NULL); } - TAILQ_FOREACH(uw_forwarder, &autoconf_forwarder_list, entry) { - tmp = resolv_conf; - if (asprintf(&resolv_conf, "%snameserver %s\n", tmp == - NULL ? "" : tmp, uw_forwarder->ip) == -1) { - free(tmp); - free(res); - log_warnx("could not create asr context"); - return (NULL); - } - free(tmp); + if ((resolv_conf = gen_resolv_conf()) == NULL) { + free(res); + log_warnx("could not create asr context"); + return (NULL); } - if ((res->asr_ctx = asr_resolver_from_string(resolv_conf)) == NULL) { free(res); @@ -2146,3 +2139,21 @@ query_imsg2str(struct query_imsg *query_imsg) qtype_buf); return buf; } + +char * +gen_resolv_conf() +{ + struct uw_forwarder *uw_forwarder; + char *resolv_conf = NULL, *tmp = NULL; + + TAILQ_FOREACH(uw_forwarder, &autoconf_forwarder_list, entry) { + tmp = resolv_conf; + if (asprintf(&resolv_conf, "%snameserver %s\n", tmp == + NULL ? "" : tmp, uw_forwarder->ip) == -1) { + free(tmp); + return (NULL); + } + free(tmp); + } + return resolv_conf; +}