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 4ad82a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 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_has_srv(const struct dnsc *dnsc);


/* DNS System functions */
Expand Down
22 changes: 21 additions & 1 deletion src/dns/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,16 @@ static int query(struct dns_query **qp, struct dnsc *dnsc, uint8_t opcode,
struct dnshdr hdr;
int err = 0;

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

if ((!srvv || !srvc || !(*srvc)) &&
(!dnsc->conf.getaddrinfo ||
(type != DNS_TYPE_A && type != DNS_TYPE_AAAA))) {

return EINVAL;
}

if (DNS_QTYPE_AXFR == type)
proto = IPPROTO_TCP;

Expand Down Expand Up @@ -1401,3 +1408,16 @@ bool dnsc_getaddrinfo_enabled(struct dnsc *dnsc)

return dnsc->conf.getaddrinfo;
}


/**
* Return whether any DNS servers are available
*
* @param dnsc DNS Client
*
* @return true if DNS servers are available, false otherwise
*/
bool dnsc_has_srv(const struct dnsc *dnsc)
{
return dnsc->srvc != 0;
}
5 changes: 4 additions & 1 deletion src/sip/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,10 @@ static int sip_request_send(struct sip_request *req, struct sip *sip,
return err;
}
}
else if (route->port) {
else if (route->port ||
(req->tp_selected &&
!dnsc_has_srv(req->sip->dnsc) &&
dnsc_getaddrinfo_enabled(req->sip->dnsc))) {

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

0 comments on commit 4ad82a3

Please sign in to comment.