conf: Handle addresses passed via --dns just like the ones from resolv.conf

...that is, call add_dns4() and add_dns6() instead of simply adding
those to the list of servers we advertise.

Most importantly, this will set the 'dns_host' field for the matching
IP version, so that, as mentioned in the man page, servers passed via
--dns are used for DNS mapping as well, if used in combination with
--dns-forward.

Reported-by: Paul Holzinger <pholzing@redhat.com>
Link: https://bugs.passt.top/show_bug.cgi?id=82
Fixes: 89678c5157 ("conf, udp: Introduce basic DNS forwarding")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Tested-by: Paul Holzinger <pholzing@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2024-03-12 01:51:56 +01:00
parent b299942bbd
commit 43881636c2

12
conf.c
View file

@ -1164,11 +1164,11 @@ void conf(struct ctx *c, int argc, char **argv)
}; };
char userns[PATH_MAX] = { 0 }, netns[PATH_MAX] = { 0 }; char userns[PATH_MAX] = { 0 }, netns[PATH_MAX] = { 0 };
bool copy_addrs_opt = false, copy_routes_opt = false; bool copy_addrs_opt = false, copy_routes_opt = false;
struct in6_addr *dns6 = c->ip6.dns, dns6_tmp;
struct in_addr *dns4 = c->ip4.dns, dns4_tmp;
enum fwd_ports_mode fwd_default = FWD_NONE; enum fwd_ports_mode fwd_default = FWD_NONE;
bool v4_only = false, v6_only = false; bool v4_only = false, v6_only = false;
struct in6_addr *dns6 = c->ip6.dns;
struct fqdn *dnss = c->dns_search; struct fqdn *dnss = c->dns_search;
struct in_addr *dns4 = c->ip4.dns;
unsigned int ifi4 = 0, ifi6 = 0; unsigned int ifi4 = 0, ifi6 = 0;
const char *logfile = NULL; const char *logfile = NULL;
const char *optstring; const char *optstring;
@ -1554,14 +1554,14 @@ void conf(struct ctx *c, int argc, char **argv)
die("Conflicting DNS options"); die("Conflicting DNS options");
if (dns4 - &c->ip4.dns[0] < ARRAY_SIZE(c->ip4.dns) && if (dns4 - &c->ip4.dns[0] < ARRAY_SIZE(c->ip4.dns) &&
inet_pton(AF_INET, optarg, dns4)) { inet_pton(AF_INET, optarg, &dns4_tmp)) {
dns4++; add_dns4(c, &dns4_tmp, &dns4);
break; break;
} }
if (dns6 - &c->ip6.dns[0] < ARRAY_SIZE(c->ip6.dns) && if (dns6 - &c->ip6.dns[0] < ARRAY_SIZE(c->ip6.dns) &&
inet_pton(AF_INET6, optarg, dns6)) { inet_pton(AF_INET6, optarg, &dns6_tmp)) {
dns6++; add_dns6(c, &dns6_tmp, &dns6);
break; break;
} }