Skip to content

Commit

Permalink
dns: Fallback to A/AAAA lookup when getaddrinfo is used without any D…
Browse files Browse the repository at this point in the history
…NS servers
  • Loading branch information
Wei Li Jiang committed Oct 11, 2024
1 parent 63776ce commit ab59e8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/re_dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ void dnsc_cache_flush(struct dnsc *dnsc);
void dnsc_cache_max(struct dnsc *dnsc, uint32_t max);
void dnsc_getaddrinfo(struct dnsc *dnsc, bool active);
bool dnsc_getaddrinfo_enabled(struct dnsc *dnsc);
bool dnsc_getaddrinfo_only(const struct dnsc *dnsc);


/* DNS System functions */
Expand Down
30 changes: 27 additions & 3 deletions src/dns/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,16 @@ static int query(struct dns_query **qp, struct dnsc *dnsc, uint8_t opcode,
struct dns_query *q = NULL;
struct dnshdr hdr;
int err = 0;
bool use_getaddrinfo = false;
bool srv_available = srvv && srvc && *srvc != 0;

if (!dnsc || !name || !srvv || !srvc || !(*srvc))
if (!dnsc || !name)
return EINVAL;

use_getaddrinfo = dnsc->conf.getaddrinfo &&
(type == DNS_TYPE_A || type == DNS_TYPE_AAAA);

if (!srv_available && !use_getaddrinfo)
return EINVAL;

if (DNS_QTYPE_AXFR == type)
Expand Down Expand Up @@ -1029,8 +1037,7 @@ static int query(struct dns_query **qp, struct dnsc *dnsc, uint8_t opcode,
list_init(q->rrlv[i]);
}

if (dnsc->conf.getaddrinfo &&
(q->type == DNS_TYPE_A || q->type == DNS_TYPE_AAAA)) {
if (use_getaddrinfo) {
err = query_getaddrinfo(q);
if (err)
goto error;
Expand Down Expand Up @@ -1401,3 +1408,20 @@ bool dnsc_getaddrinfo_enabled(struct dnsc *dnsc)

return dnsc->conf.getaddrinfo;
}


/**
* Return if getaddrinfo usage is enabled and exclusive,
* i.e. there are no DNS servers known explicitly
*
* @param dnsc DNS Client
*
* @return true if DNS servers are available, false otherwise
*/
bool dnsc_getaddrinfo_only(const struct dnsc *dnsc)
{
if (!dnsc)
return false;

return dnsc->conf.getaddrinfo && dnsc->srvc == 0;
}
4 changes: 3 additions & 1 deletion src/sip/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ static int sip_request_send(struct sip_request *req, struct sip *sip,
{
struct sa dst;
int err;
bool addr_only = req->tp_selected &&
dnsc_getaddrinfo_only(req->sip->dnsc);

if (!sa_set_str(&dst, req->host,
sip_transp_port(req->tp, route->port))) {
Expand All @@ -737,7 +739,7 @@ static int sip_request_send(struct sip_request *req, struct sip *sip,
return err;
}
}
else if (route->port) {
else if (route->port || addr_only){

req->port = sip_transp_port(req->tp, route->port);
err = addr_lookup(req, req->host);
Expand Down

0 comments on commit ab59e8f

Please sign in to comment.