DNS resolution does not respect local configuration (/etc/hosts, avahi *.local, nsswitch.conf, etc)
afcady opened this issue · comments
There is an issue in baresip
which results from the DNS client code in re
.
re
implements its own asynchronous DNS resolver in src/dns/client.c
. It uses this to resolve all names in SIP addresses.
On systems where the only source of name resolution is DNS, that is alright. But desktop OSes typically support both /etc/hosts
and some form of LAN discovery (such as MDNS, implemented by avahi/bonjour on Linux/Mac OS X). In a correctly functioning SIP client on these platforms, two machines on a LAN that have locally-propagated *.local
MDNS names will be able to make SIP calls to one another using these names.
On Linux, the re
library needs to use getaddrinfo
or getaddrinfo_a
to get the correct behavior.
I looked at src/dns/client.c
to see what would need to be changed to switch to getaddrinfo_a
.
At present the creation of the struct dnsc
in dnscalloc()
is also installing a udp_listen
callback udp_recv_handler
for DNS replies.
Then in query()
either send_udp
or send_tcp
is used to send the DNS request. Here, a third option would be added, when DNS_TYPE_A
or AAAA
, to call getaddrinfo_a
with a callback that is equivalent to what the reply_recv
does, which is ultimately to call the dns_query_h *qh
callback from the struct dns_query
(in query_handler
). This accepts a const struct dnshdr *hdr
which could maybe be NULL
, with only the struct list *ansl
3rd argument containing a value derived from the lookup. I suppose this needs to be called in the same context as the udp_recv_handler
so the callback actually passed to getaddrinfo_a
would only add the response to a list protected by a mutex. Then the part of the loop that runs udp_recv_handler
would be modified to check this list and call the dns_query_h
.
Sound good? Would this be acceptable if I submitted a patch?
due to the current policy, this will not be accepted: