Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: listen on IPv4 and IPv6 socket #27

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/dns/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct dnsc {
struct hash *ht_query;
struct hash *ht_tcpconn;
struct udp_sock *us;
struct udp_sock *us6;
struct sa srvv[SRVC_MAX];
uint32_t srvc;
};
Expand Down Expand Up @@ -578,12 +579,28 @@ static int send_udp(struct dns_query *q)

for (i=0; i<*q->srvc; i++) {

struct udp_sock *us;

srv = &q->srvv[q->ntx++%*q->srvc];

DEBUG_INFO("trying udp server#%u: %J\n", i, srv);

switch (sa_af(srv)) {

case AF_INET:
us = q->dnsc->us;
break;

case AF_INET6:
us = q->dnsc->us6;
break;

default:
continue;
}

q->mb.pos = 0;
err = udp_send(q->dnsc->us, srv, &q->mb);
err = udp_send(us, srv, &q->mb);
if (!err)
break;
}
Expand Down Expand Up @@ -820,6 +837,7 @@ static void dnsc_destructor(void *data)

mem_deref(dnsc->ht_tcpconn);
mem_deref(dnsc->ht_query);
mem_deref(dnsc->us6);
mem_deref(dnsc->us);
}

Expand All @@ -838,6 +856,7 @@ int dnsc_alloc(struct dnsc **dcpp, const struct dnsc_conf *conf,
const struct sa *srvv, uint32_t srvc)
{
struct dnsc *dnsc;
struct sa laddr, laddr6;
int err;

if (!dcpp)
Expand All @@ -856,7 +875,11 @@ int dnsc_alloc(struct dnsc **dcpp, const struct dnsc_conf *conf,
if (err)
goto out;

err = udp_listen(&dnsc->us, NULL, udp_recv_handler, dnsc);
sa_set_str(&laddr, "0.0.0.0", 0);
sa_set_str(&laddr6, "::", 0);

err = udp_listen(&dnsc->us, &laddr, udp_recv_handler, dnsc);
err |= udp_listen(&dnsc->us6, &laddr6, udp_recv_handler, dnsc);
if (err)
goto out;

Expand Down