History log of /openbsd-current/lib/libc/asr/asr.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.68 20-Jan-2022 naddy

remove unused variable from all copies of _asr_strdname()

... including those inlined into print_dname(). This also fixes
-Wunused-but-set-variable warnings warnings in smtpd and smtpctl.
The code was imported with asr and then copied around.

ok deraadt@ guenther@


# 1.67 22-Nov-2021 jca

Implement rfc6840 (AD flag processing) if using trusted name servers

libc can't do DNSSEC validation but it can ask a "security-aware"
resolver to do so. Let's send queries with the AD flag set when
appropriate, and let applications look at the AD flag in responses in
a safe way, ie clear the AD flag if the resolvers aren't trusted.
By default we only trust resolvers if resolv.conf(5) only lists name
servers on localhost - the obvious candidates being unwind(8) and
unbound(8). For non-localhost resolvers, an admin who trusts *all the
name servers* listed in resolv.conf(5) *and the network path leading to
them* can annotate this with "options trust-ad".

AD flag processing gives ssh -o VerifyHostkeyDNS=Yes a chance to fetch
SSHFP records in a secure manner, and tightens the situation for other
applications, eg those using RES_USE_DNSSEC for DANE. It should be
noted that postfix currently assumes trusted name servers by default and
forces RES_TRUSTAD if available.

RES_TRUSTAD and "options trust-ad" were first introduced in glibc by
Florian Weimer. Florian Obser (florian@) contributed various
improvements, fixed a bug and added automatic trust for name servers on
localhost.

ok florian@ phessler@


# 1.66 05-Nov-2021 kn

Zap unused variables

OK martijn


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.65 06-Jan-2021 otto

Fix two issues related to thread private data in asr.
- setting up asr in single thread mode and then starting threads using asr
would lead to multiple threads sharing the same resolver.
- destruction of a thread that has been using asr would leak data.
Problem originally reported by Alexey Sokolov and Uli Schlachter.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.64 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.67 22-Nov-2021 jca

Implement rfc6840 (AD flag processing) if using trusted name servers

libc can't do DNSSEC validation but it can ask a "security-aware"
resolver to do so. Let's send queries with the AD flag set when
appropriate, and let applications look at the AD flag in responses in
a safe way, ie clear the AD flag if the resolvers aren't trusted.
By default we only trust resolvers if resolv.conf(5) only lists name
servers on localhost - the obvious candidates being unwind(8) and
unbound(8). For non-localhost resolvers, an admin who trusts *all the
name servers* listed in resolv.conf(5) *and the network path leading to
them* can annotate this with "options trust-ad".

AD flag processing gives ssh -o VerifyHostkeyDNS=Yes a chance to fetch
SSHFP records in a secure manner, and tightens the situation for other
applications, eg those using RES_USE_DNSSEC for DANE. It should be
noted that postfix currently assumes trusted name servers by default and
forces RES_TRUSTAD if available.

RES_TRUSTAD and "options trust-ad" were first introduced in glibc by
Florian Weimer. Florian Obser (florian@) contributed various
improvements, fixed a bug and added automatic trust for name servers on
localhost.

ok florian@ phessler@


# 1.66 05-Nov-2021 kn

Zap unused variables

OK martijn


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.65 06-Jan-2021 otto

Fix two issues related to thread private data in asr.
- setting up asr in single thread mode and then starting threads using asr
would lead to multiple threads sharing the same resolver.
- destruction of a thread that has been using asr would leak data.
Problem originally reported by Alexey Sokolov and Uli Schlachter.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.64 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.66 05-Nov-2021 kn

Zap unused variables

OK martijn


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.65 06-Jan-2021 otto

Fix two issues related to thread private data in asr.
- setting up asr in single thread mode and then starting threads using asr
would lead to multiple threads sharing the same resolver.
- destruction of a thread that has been using asr would leak data.
Problem originally reported by Alexey Sokolov and Uli Schlachter.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.64 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.65 06-Jan-2021 otto

Fix two issues related to thread private data in asr.
- setting up asr in single thread mode and then starting threads using asr
would lead to multiple threads sharing the same resolver.
- destruction of a thread that has been using asr would leak data.
Problem originally reported by Alexey Sokolov and Uli Schlachter.
ok kettenis@


Revision tags: OPENBSD_6_8_BASE
# 1.64 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.64 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.63 07-Jun-2020 deraadt

In the libc resolver function asr_run(), clear the result buffer everytime,
because there are callers who were inspecting unrelated fields.
discussion with eric, otto, solution from semarie
this is errata 6.6/031_asr and 6.7/009_asr


Revision tags: OPENBSD_6_7_BASE
# 1.62 24-Oct-2019 otto

branches: 1.62.4;
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

branches: 1.61.4;
More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.62 24-Oct-2019 otto

Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent
and we want to ride the minor shlib bump.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.61 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.61 22-Oct-2018 krw

More "explicitely" -> "explicitly" in various comments.

ok guenther@ tb@ deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.60 28-Apr-2018 schwarze

To allow us to get rid of /etc/networks, make getnetby*(3)
wrappers around gethostby*_async(3). If you had anything of
importance in /etc/networks, specify it in /etc/hosts instead.
Feedback and OK eric@, OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.59 13-Mar-2018 jca

Fix comments

ok eric@ a while ago


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


# 1.58 06-Feb-2018 eric

make sure that all error paths are correctly handled in asr_run_sync()
and that the result is always properly set when the functions returns.
fix issues spotted by claudio@.

ok claudio@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 27-Feb-2017 jca

Put a common flags field in the query struct, rather than in some
elements of the union.

This field is for internal asr flags. The flags in "struct rrset" and
"struct ni" are different kinds of flags.

ok eric@


# 1.56 23-Feb-2017 eric

Put a common subq pointer in the query struct, rather than one in each
element of the union.

ok gilles@ millert@ krw@


# 1.55 18-Feb-2017 jca

Add EDNS0 support.

EDNS allows for various DNS extensions, among which UDP DNS packets size
bigger than 512 bytes. The default is still to not advertize anything.

ok eric@


Revision tags: OPENBSD_6_0_BASE
# 1.54 18-Jun-2016 reyk

Remove duplicated line.

OK eric@


# 1.53 27-May-2016 sthen

typo fixes; Anthony Coulter


# 1.52 26-May-2016 jmatthew

Calculate elapsed time in poll() and subtract that from the remaining time
when restarting poll() after receiving a signal.

The ruby runtime send signals to threads periodically, so without accounting
for elapsed time, the timeout would never expire if we didn't get a response
from a nameserver.

ok deraadt@ eric@


Revision tags: OPENBSD_5_9_BASE
# 1.51 24-Feb-2016 eric

Avoid a possible double-free if the "search" keyword is used multiple times.

ok jca@ gilles@


# 1.50 16-Dec-2015 deraadt

Remove support for HOSTALIASES from the resolver. This "open and parse
any file indicated by an environment variable" feature inside the
resolver is incompatible with what pledge "dns" is trying to be. It is
a misguided "feature" added way back in history which almost noone uses,
but everyone has to assume the risk from.
ok eric florian kettenis


# 1.49 23-Nov-2015 deraadt

Remove support for "lookup yp" in /etc/resolv.conf. This historical
wart is incompatible with pledge, because suddenly a "dns" operation
needs "getpw" access to ypbind/ypserv, etc. file + dns access is
enough for everyone, sorry if you were using that old SunOS 4.x style
mechanism, but it is now gone.
ok semarie millert florian


# 1.48 28-Oct-2015 eric

We are always using _PATH_RESCONF, so no need to remember the path on
the resolver.

ok millert@ deraadt@


# 1.47 28-Oct-2015 deraadt

Remove support for [addr]:port syntax from the "nameserver" line.
This extension never made it to other systems. (pledge is also happy
with this. The idea of DNS @ any port collides with pledge encouraring
differentiation between DNS and non-DNS sockets)
ok phessler jung sthen kettenis


# 1.46 07-Oct-2015 deraadt

getaddrinfo_async() shouldn't unconditionally intialize the resolver
via _asr_use_resolver(). If the hint specifies for AI_NUMERICHOST,
create a transient lookup context which won't try to open /etc/reslov.conf
ok eric guenther


# 1.45 03-Oct-2015 deraadt

Initially eric developers asr as a side-load style library for async DNS.
When it was integrated as the main resolver, a bunch of strange initialization
code remained. Start whittling away at this, piece by piece, to make it
more clear.
ok eric


# 1.44 03-Oct-2015 eric

missing asr* -> _asr* symbol rename for building with debug code

ok jca@


# 1.43 20-Sep-2015 eric

remove bogus includes of err.h


# 1.42 20-Sep-2015 eric

use _PATH_RESCONF directly


# 1.41 14-Sep-2015 guenther

Wrap <asr.h> so internal calls go direct and all the symbols are weak


# 1.40 09-Sep-2015 deraadt

Hide all unnecessary asr / resolver related API with _ prefixes.
direction & ok guenther


# 1.39 02-Sep-2015 deraadt

use _PATH_RESCONF


Revision tags: OPENBSD_5_8_BASE
# 1.38 04-Jun-2015 eric

make sure to check for resolv.conf update the first time the resolver
is used after pid has changed.

ok deraadt@


# 1.37 29-May-2015 eric

fix a possible off-by-one when reading /etc/hosts if it doesn't end
with a newline.

ok jca@


# 1.36 26-May-2015 eric

simply use _PATH_HOSTS where appropriate


Revision tags: OPENBSD_5_7_BASE
# 1.35 16-Jan-2015 deraadt

Move to the <limits.h> universe.
review by millert, binary checking process with doug, concept with guenther


# 1.34 15-Sep-2014 guenther

When fopen()ing internal to libc (the API doesn't support the use
of the resulting FILE *), then pass fopen() the 'e' mode letter to
mark it close-on-exec.

ok miod@


Revision tags: OPENBSD_5_6_BASE
# 1.33 26-Mar-2014 eric

Make the asr API public. Install asr.h to /usr/include.h and manpages.
Include tweaks suggested by mpi@

ok deraadt@


# 1.32 25-Mar-2014 eric

Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.

discussed with and ok deraadt@ guenther@


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.31 12-Jul-2013 eric

Make some symbols static and prefix all visible symbols with asr_
to prevent collisions with third-party programs.

suggested by sthen@, ok theo@


# 1.30 01-Jun-2013 eric

Move search domain iteration code in res_search_async.c where it belongs.


# 1.29 01-Jun-2013 eric

Make hostaliases work for gethostbyname() and getaddrinfo() when
looking into /etc/hosts. Remove the alias check from the search
domain iteration. Instead, take a shortcut to res_query_async_ctx() in
res_search_async_ctx().


# 1.28 01-Jun-2013 eric

Update asr_hostaliases() to make all necessary checks in the function.
Explicitely check for issetguid() before calling getenv(). Also make
asr_hostalias() callable from other parts of asr too.


# 1.27 01-Jun-2013 eric

iterating over the ns list only matters for res_send_async.c, so move
things around.


# 1.26 27-May-2013 eric

Add minimal support for _res setup and update.

Change res_init() to initialize the _res structure on first call, and
udpate the global async context if changes were made by the user. All
resolver functions now call res_init() internally.

fixes issue spotted by otto@


# 1.25 30-Apr-2013 eric

Do not take external buffers for storing DNS responses in the internal
async API. That is actually useless and it makes the code more
complicated. The required buffers are always allocated when needed.


# 1.24 17-Apr-2013 otto

check return value of strdup(), fix mem leak in error path and take
into account that asr_use_resolver() can return NULL; ok tedu@ eric@


# 1.23 17-Apr-2013 deraadt

give a timespec a name that is easier to verify


# 1.22 11-Apr-2013 otto

Proper access of _THREAD_PRIVATE storage. Avoids a mem leak and reinit
of resolver context for each resolver call for single threaded
programs. With and ok tedu@ ok eric@


# 1.21 01-Apr-2013 eric

If more than one lookup line is found in resolv.conf, the latest one
takes precedence. Simplify code while there.

suggested by deraadt@


# 1.20 01-Apr-2013 eric

properly check for domain name truncation at various places and fail
if that happens.

prodded by deraadt@


# 1.19 01-Apr-2013 deraadt

space cleanup; ok eric


# 1.18 31-Mar-2013 eric

Principle of least astonishment: implement nameserver retry/backoff as
in the former resolver.


# 1.17 30-Mar-2013 eric

Do not assume local nameserver if resolv.conf doesn't exist, just use
/etc/hosts.

discussed with deraadt@


# 1.16 30-Mar-2013 otto

don't ever skip reload the very first time; detective work by rpe@; ok eric@


# 1.15 27-Mar-2013 eric

Only use the search domains for DNS lookups, as the current resolver does.
Better not diverge too much in behavior at this point.
Typo fix and doc update while there.


Revision tags: OPENBSD_5_3_BASE
# 1.14 24-Nov-2012 eric

knf


# 1.13 09-Sep-2012 eric

tweak options


# 1.12 09-Sep-2012 eric

allow to disable some features at build time


# 1.11 09-Sep-2012 eric

cleanup asr_debug.c


# 1.10 09-Sep-2012 eric

use proper macros for debug traces.


# 1.9 07-Sep-2012 eric

return value has no use; make it void.
fix comment.


# 1.8 06-Sep-2012 eric

config parsing is done in one pass now. no need to use callback anymore.


# 1.7 06-Sep-2012 eric

add a strsplit() helper to factorize code a bit.


# 1.6 05-Sep-2012 eric

Get rid of the hostaddr_async subquery and merge its behaviour
directly into getaddrinfo_async_run. Simplifies everything by
a great deal.


# 1.5 05-Sep-2012 eric

Make hostaddr_async() return a linked list of struct addrinfo. First
round of a getaddrinfo_async() simplification. The goal is to make YP
support easier to add, and eventually remove the whole hostaddr_async
subquery.


# 1.4 18-Aug-2012 eric

ensure that async_run() and async_run_sync() always preserve errno.


Revision tags: OPENBSD_5_2_BASE
# 1.3 15-Apr-2012 eric

Create a new resolver for each thread. It will be done differently
eventually, but it's enough for now to make the blocking API fully
thread-safe without locking.


# 1.2 14-Apr-2012 eric

only define DEBUG internally


# 1.1 14-Apr-2012 eric

Import asr, an experimental async resolver implementation.
The idea is to eventually replace the existing resolver with
something better. Time to start working on it in tree.

ok deraadt@