Merge branch 'develop' into features/valchain_without_lookups

This commit is contained in:
Willem Toorop 2017-08-30 15:15:43 +02:00
commit 2572c8f17b
210 changed files with 20995 additions and 3848 deletions

10
.gitignore vendored
View File

@ -39,6 +39,7 @@ src/test/check_getdns_ev
src/test/scratchpad
src/test/scratchpad.c
src/tools/getdns_query
src/stubby
doc/*.3
src/getdns/getdns.h
*.log
@ -54,6 +55,13 @@ m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
src/config.h.in
build/
getdns.pc
getdns_ext_event.pc
/src/test/tpkg/result.*
/src/test/tpkg/.done-*
/src/test/tpkg/.tpkg.var.master
/src/test/tpkg/scan-build-reports/
/src/test/tpkg/install/
/src/test/tpkg/build/
/src/test/tpkg/build-stub-only/
/src/test/tpkg/build-event-loops/

4
.gitmodules vendored
View File

@ -2,3 +2,7 @@
path = src/jsmn
url = https://github.com/getdnsapi/jsmn.git
branch = getdns
[submodule "stubby"]
path = stubby
url = https://github.com/getdnsapi/stubby.git
branch = develop

View File

@ -13,6 +13,7 @@ addons:
- libev-dev
- valgrind
- clang
- wget
script:
- mkdir tests
- cd tests

100
ChangeLog
View File

@ -1,3 +1,101 @@
* 2017-0?-??: Version 1.1.3
* No annotations with the output of getdns_query anymore,
unless -V option is given to increase verbosity
Thanks Ollivier Robert
* getdns_query will now exit with failure status if replies are BOGUS
* Bugfix: dnssec_return_validation_chain now also works when fallback
to full recursion was needed with dnssec_roadblock_avoidance
* More clear build instructions from Paul Hoffman. Thanks.
* Bugfix #320.1: Eliminate multiple closing of file descriptors
Thanks Neil Cook
* Bugfix #320.2: Array bounds bug in upstream_select
Thanks Neil Cook
* Bugfix #318: getdnsapi/getdns/README.md links to nonexistent wiki
pages. Thanks James Raftery
* Bugfix #322: MacOS 10.10 (Yosemite) provides TCP fastopen interface
but does not have it implemented. Thanks Joel Purra
* Compile without Stubby by default. Stubby now has a git repository
of its own. The new Stubby repository is added as a submodule.
Stubby will still be build alongside getdns with the --with-stubby
configure option.
* 2017-07-03: Version 1.1.2
* Bugfix for parallel make install
* Bugfix to trigger event callbacks on socket errors
* A getdns_context_set_logfunc() function with which one may
register a callback log function for certain library subsystems
at certain levels. Currently this can only be used for
upstream stastistics subsystem.
* 2017-06-15: Version 1.1.1
* Bugfix #306 hanging/segfaulting on certain (IPv6) upstream failures
* Spelling fix s/receive/receive. Thanks Andreas Schulze.
* Added stubby-setdns-macos.sh script to support Homebrew formula
* Include stubby.conf in the districution tarball
* Bugfix #286 reschedule reused listening addresses
* Bugfix #166 Allow parallel builds and unit-tests
* NSAP-PTR, EID and NIMLOC, TALINK, AVC support
* Bugfix of TA RR type
* OPENPGPKEY and SMIMEA support
* Bugfix TAG rdata type presentation format for CAA RR type
* Bugfix Zero sized gateways with IPSECKEY gateway_type 0
* Guidance for integration with systemd
* Also check for memory leaks with advances server capabilities.
* Bugfix convert IP string to IP dict with getdns_str2dict() directly.
* 2017-04-13: Version 1.1.0
* bugfix: Check size of tls_auth_name.
* Improvements that came from Visual Studio static analysis
* Fix to compile with libressl. Thanks phicoh.
* Spelling fixes. Thanks Andreas Schulze.
* bugfix: Reschedule request timeout when getting the DNSSEC chain.
* getdns_context_unset_edns_maximum_udp_payload_size() to reset
to default IPv4/IPv6 dependent edns max udp payload size.
* Implement sensible default edns0 padding policy. Thanks DKG.
* Keep connections open with sync requests too.
* Fix of event loops so they do not give up with naked timers with
windows. Thanks Christian Huitema.
* Include peer certificate with DNS-over-TLS in combination with
the return_call_reporting extension.
* More fine grained control over TLS upstream retry and back off
behaviour with getdns_context_set_tls_backoff_time() and
getdns_context_set_tls_connection_retries().
* New round robin over the available upstreams feaure.
Enable with getdns_context_set_round_robin_upstreams()
* Bugfix: Queue requests when no sockets available for outgoing queries.
* Obey the outstanding query limit with STUB resolution mode too.
* Updated stubby config file
* Draft MDNS client implementation by Christian Huitema.
Enable with --enable-draft-mdns-support to configure
* bugfix: Let synchronous queries use fds > MAX_FDSETSIZE;
By moving default eventloop from select to poll
Thanks Neil Cook
* bugfix: authentication failure for self signed cert + only pinset
* bugfix: issue with session re-use making authentication appear to fail
* 2017-01-13: Version 1.0.0
* edns0_cookies extension enabled by default (per RFC7873)
* dnssec_roadblock_avoidance enabled by default (per RFC8027)
* bugfix: DSA support with OpenSSL 1.1.0
* Initialize OpenSSL just once in a thread safe way
* Thread safety with arc4random function
* Improvements that came from Visual Studio static analysis
Thanks Christian Huitema
* Conventional RFC3986 IPv6 [address]:port parsing from getdns_query
* bugfix: OpenSSL 1.1.0 style crypto locking
Thanks volkommenheit
* configure tells *which* dependency is missing
* bugfix: Exclude terminating '\0' from bindata's returned by
getdns_get_suffix(). Thanks Jim Hague
* Better README.md. Thanks Andrew Sullivan
* 2016-10-19: Version 1.1.0-a2
* Improved TLS connection management
* OpenSSL 1.1 support
* Stubby, Server version of getdns_query that by default listens
on 127.0.0.1 and ::1 and reads config from /etc/stubby.conf
and $HOME/.stubby.conf
* 2016-07-14: Version 1.1.0a1
* Conversion functions from text strings to getdns native types:
getdns_str2dict(), getdns_str2list(), getdns_str2bindata() and
@ -127,7 +225,7 @@
'-1' to append suffix only to single label after failure
'-M' to append suffix only to multi label name after failure
'-N' to never append a suffix
'-Z <suffixes>' to set suffixes with the given comma separed list
'-Z <suffixes>' to set suffixes with the given comma separated list
* Better help text for getdns_query (printed with the '-h' option)
* Setting the +specify_class extension with getdns_query
* Return NOT_IMPLEMENTED for not implemented namespaces, and the

View File

@ -44,7 +44,7 @@ libdir = @libdir@
srcdir = @srcdir@
INSTALL = @INSTALL@
all : default @GETDNS_QUERY@
all : default @GETDNS_QUERY@
everything: default
cd src/test && $(MAKE)
@ -52,7 +52,10 @@ everything: default
default:
cd src && $(MAKE) $@
install: all getdns.pc getdns_ext_event.pc @INSTALL_GETDNS_QUERY@
install-lib:
cd src && $(MAKE) install
install: getdns.pc getdns_ext_event.pc install-lib @INSTALL_GETDNS_QUERY@
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)
$(INSTALL) -m 644 $(srcdir)/AUTHORS $(DESTDIR)$(docdir)
$(INSTALL) -m 644 $(srcdir)/ChangeLog $(DESTDIR)$(docdir)
@ -66,9 +69,7 @@ install: all getdns.pc getdns_ext_event.pc @INSTALL_GETDNS_QUERY@
$(INSTALL) -m 644 getdns_ext_event.pc $(DESTDIR)$(libdir)/pkgconfig
$(INSTALL) -m 755 -d $(DESTDIR)$(docdir)/spec
$(INSTALL) -m 644 $(srcdir)/spec/index.html $(DESTDIR)$(docdir)/spec
$(INSTALL) -m 644 $(srcdir)/spec/getdns*tgz $(DESTDIR)$(docdir)/spec || true
cd src && $(MAKE) $@
cd doc && $(MAKE) $@
cd doc && $(MAKE) install
@echo "***"
@echo "*** !!! IMPORTANT !!!! libgetdns needs a DNSSEC trust anchor!"
@echo "***"
@ -98,23 +99,32 @@ doc: FORCE
example:
cd spec/example && $(MAKE) $@
test:
test: default
cd src/test && $(MAKE) $@
getdns_query: default
cd src/tools && $(MAKE) $@
stubby:
cd src && $(MAKE) $@
getdns_query:
cd src && $(MAKE) $@
scratchpad:
cd src && $(MAKE) $@
scratchpad: default
cd src/test && $(MAKE) $@
pad: scratchpad
src/test/scratchpad || ./libtool exec gdb src/test/scratchpad
install-getdns_query:
cd src/tools && $(MAKE) install
install-getdns_query: install-lib
cd src/tools && $(MAKE) $@
uninstall-getdns_query:
cd src/tools && $(MAKE) uninstall
cd src/tools && $(MAKE) $@
install-stubby:
cd src && $(MAKE) $@
uninstall-stubby:
cd src && $(MAKE) $@
clean:
cd src && $(MAKE) $@
@ -141,18 +151,22 @@ distclean:
rm -f m4/ltoptions.m4
rm -f m4/ltsugar.m4
rm -f m4/ltversion.m4
rm -f $(distdir).tar.gz $(distdir).tar.gz.sha1
rm -f $(distdir).tar.gz $(distdir).tar.gz.sha256
rm -f $(distdir).tar.gz.md5 $(distdir).tar.gz.asc
megaclean:
cd $(srcdir) && rm -fr * .dir-locals.el .gitignore .indent.pro .travis.yml && git reset --hard
cd $(srcdir) && rm -fr * .dir-locals.el .gitignore .indent.pro .travis.yml && git reset --hard && git submodule update --init
autoclean: megaclean
libtoolize -ci
autoreconf -fi
dist: $(distdir).tar.gz
pub: $(distdir).tar.gz.sha1 $(distdir).tar.gz.md5 $(distdir).tar.gz.asc
pub: $(distdir).tar.gz.sha256 $(distdir).tar.gz.md5 $(distdir).tar.gz.asc
$(distdir).tar.gz.sha1: $(distdir).tar.gz
openssl sha1 $(distdir).tar.gz >$@
$(distdir).tar.gz.sha256: $(distdir).tar.gz
openssl sha256 $(distdir).tar.gz >$@
$(distdir).tar.gz.md5: $(distdir).tar.gz
openssl md5 $(distdir).tar.gz >$@
@ -178,7 +192,6 @@ $(distdir):
mkdir -p $(distdir)/src
mkdir -p $(distdir)/src/getdns
mkdir -p $(distdir)/src/test
mkdir -p $(distdir)/src/test/jsmn
mkdir -p $(distdir)/src/extension
mkdir -p $(distdir)/src/compat
mkdir -p $(distdir)/src/util
@ -188,6 +201,8 @@ $(distdir):
mkdir -p $(distdir)/doc
mkdir -p $(distdir)/spec
mkdir -p $(distdir)/spec/example
mkdir -p $(distdir)/stubby
mkdir -p $(distdir)/stubby/src
cp $(srcdir)/configure.ac $(distdir)
cp $(srcdir)/configure $(distdir)
cp $(srcdir)/AUTHORS $(distdir)
@ -219,16 +234,22 @@ $(distdir):
cp $(srcdir)/src/test/*.good $(distdir)/src/test
cp $(srcdir)/src/compat/*.[ch] $(distdir)/src/compat
cp $(srcdir)/src/util/*.[ch] $(distdir)/src/util
cp -r $(srcdir)/src/util/orig-headers $(distdir)/src/util
cp -r $(srcdir)/src/util/auxiliary $(distdir)/src/util
cp $(srcdir)/src/gldns/*.[ch] $(distdir)/src/gldns
cp $(srcdir)/doc/Makefile.in $(distdir)/doc
cp $(srcdir)/doc/*.in $(distdir)/doc
cp $(srcdir)/doc/manpgaltnames $(distdir)/doc
cp $(srcdir)/spec/*.html $(distdir)/spec
cp $(srcdir)/spec/*.tgz $(distdir)/spec || true
cp $(srcdir)/spec/example/Makefile.in $(distdir)/spec/example
cp $(srcdir)/spec/example/*.[ch] $(distdir)/spec/example
cp $(srcdir)/src/tools/Makefile.in $(distdir)/src/tools
cp $(srcdir)/src/tools/*.[ch] $(distdir)/src/tools
cp $(srcdir)/stubby/stubby.conf.example $(distdir)/stubby
cp $(srcdir)/stubby/stubby-setdns-macos.sh $(distdir)/stubby
cp $(srcdir)/stubby/src/stubby.c $(distdir)/stubby/src
cp $(srcdir)/stubby/COPYING $(distdir)/stubby
cp $(srcdir)/stubby/README.md $(distdir)/stubby
cp $(srcdir)/src/jsmn/*.[ch] $(distdir)/src/jsmn
cp $(srcdir)/src/jsmn/LICENSE $(distdir)/src/jsmn
cp $(srcdir)/src/jsmn/README.md $(distdir)/src/jsmn

275
README.md
View File

@ -5,23 +5,45 @@ getdns
* GitHub: <https://github.com/getdnsapi/getdns>
getdns is an implementation of a modern asynchronous DNS API specification
originally edited by Paul Hoffman. It is intended to make all types of DNS
information easily available to application developers and non-DNS experts.
The project home page at [getdnsapi.net](https://getdnsapi.net) provides
documentation, binary downloads and news regarding the getdns API
implementation. This implementation is licensed under the New BSD License
(BSD-new).
getdns is an implementation of a modern asynchronous DNS API; the specification was originally edited by Paul Hoffman. It is intended to make all types of DNS information easily available to application developers and non-DNS experts.
This file captures the goals and direction of the project and the current state
of the implementation.
## Why you might want getdns
If you are just getting started with the library take a look at the section
below that describes building and handling external dependencies for the
library. Once it is built you should take a look at src/examples to see how
the library is used.
Traditional access to DNS data from applications has several limitations:
## Download
* APIs require applications to have considerable sophistication about DNS data and data types
* Some kinds of data about the response (notably, the resource record set time to live) is not exposed via any API, so applications need to process raw protocol responses to get such data
* APIs are often blocking, meaning asynchronous access is not possible without some work
* Sophisticated uses of the DNS (things like IDNA and DNSSEC validation) require considerable application work, possibly by application developers with little experience with the vagaries of DNS.
getdns also provides an experimental DNS Privacy enabled client called 'stubby' - see below for more details.
## Motivation for providing the API
The developers are of the opinion that DNSSEC offers a unique global infrastructure for establishing and enhancing cryptographic trust relations. With the development of this API we intend to offer application developers a modern and flexible interface that enables end-to-end trust in the DNS architecture, and which will inspire application developers to implement innovative security solutions in their applications.
### API Documentation
Note that this implementation offers additional functionality to supplement that in the [official getdns API](https://getdnsapi.net/documentation/spec/). Some additions are convenient utility functions but other functionality is experimental prior to be being recommended for inclusion in the official API. The [Doxygen documentation](https://getdnsapi.net/doxygen/modules.html) provides the details of the full API for this implementation.
## License
This implementation is licensed under the New BSD License (BSD-new).
Obtaining and getting started with getdns
=========================================
The project home page at [getdnsapi.net](https://getdnsapi.net) provides documentation, binary downloads, and news regarding the getdns API implementation. This README file captures the goals and direction of the project and the current state of the implementation.
If you are just getting started with the library take a look at the section below that describes building and handling external dependencies for the library.
### Examples
Once it is built you should take a look at src/examples to see how the library is used.
# Download
Download the sources from our [github repo](https://github.com/getdnsapi/getdns)
or from [getdnsapi.net](https://getdnsapi.net) and verify the download using
@ -29,129 +51,79 @@ the checksums (SHA1 or MD5) or using gpg to verify the signature. Our keys are
available from the [pgp keyservers](https://keyserver.pgp.com)
* willem@nlnetlabs.nl, key id E5F8F8212F77A498
* gwiley@verisign.com, key id 9DC3D572A6B73532
## Mailing lists
# Releases
We have a [getdns users list](https://getdnsapi.net/mailman/listinfo/spec) for this implementation.
The [getdns-api mailing list](https://getdnsapi.net/mailman/listinfo/spec)
is a good place to engage in discussions regarding the design of the API.
## Motivation for providing the API
The developers are of the opinion that DNSSEC offers a unique global
infrastructure for establishing and enhancing cryptographic trust relations.
With the development of this API we intend to offer application developers a
modern and flexible way that enables end-to-end trust in the DNS architecture
and will inspire application developers towards innovative security solutions
in their applications.
## Goals
The goals of this implementation of the getdns API are:
* Provide an open source implementation, in C, of the formally described getdns API by getdns API team at <https://getdnsapi.net/spec.html>
* Initial support for FreeBSD, OSX, Linux (CentOS/RHEL, Ubuntu) via functional "configure" script
* Initial support for Windows 8.1
* Initial support to include the Android platform
* Include examples and tests as part of the build
* Document code using doxygen
* Leverage github as much as possible for project coordination
* Coding style/standards follow the BSD coding style <ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/share/misc/style>
Non-goals (things we will not be doing at least initially) include:
* implementation of the traditional DNS related routines (gethostbyname, etc.)
## Official and Additional API
Note that this implementation offers additional functionality to supplement that
in the official getdns API. Some additions are convenient utility functions but other functionality
is experimental prior to be being recommended for inclusion in the official API.
The 'Modules' page in the doxygen documentation provides a guide to both the
official API and the additional functionality.
## Language Bindings
In parallel, the team is actively developing bindings for various languages.
For more information, visit the
[wiki](https://github.com/getdnsapi/getdns/wiki/Language-Bindings).
Releases
========
Release numbering follows the [Semantic Versioning](http://semver.org/)
approach. The code is currently under active development.
The following requirements were met as conditions for the present release:
* code compiles cleanly on at least the primary target platforms: OSX, RHEL/CentOS Linux, FreeBSD
* examples must compile and run clean
* clearly document supported/unsupported elements of the API
* examples must compile and run cleanly
* there must be clear documentation of supported and unsupported elements of the API
# Building and External Dependencies
Tickets/Bug Reports
===================
Tickets and bug reports should be reported via the [GitHub issues list](https://github.com/getdnsapi/getdns/issues).
If you are installing from packages, you have to install the library and also the library-devel (or -dev) for your package management system to get the the necessary compile time files.
Additionally, we have a mailing list at users@getdns.net.
Building/External Dependencies
==============================
External dependencies are linked outside the getdns API build tree (we rely on configure to find them). We would like to keep the dependency tree short.
Please refer to section for building on Windows for separate dependency and build instructions.
External dependencies are linked outside the getdns API build tree (we rely on configure to find them). We would like to keep the dependency tree short. Please refer to section for building on Windows for separate dependency and build instructions for that platform.
* [libunbound from NLnet Labs](https://unbound.net/) version 1.4.16 or later.
* [libidn from the FSF](https://www.gnu.org/software/libidn/) version 1.
* [libidn from the FSF](https://www.gnu.org/software/libidn/) version 1. (Note that the libidn version means the conversions between A-labels and U-labels may permit conversion of formally invalid labels under IDNA2008.)
* [libssl and libcrypto from the OpenSSL Project](https://www.openssl.org/) version 0.9.7 or later. (Note: version 1.0.1 or later is required for TLS support, version 1.0.2 or later is required for TLS hostname authentication)
* Doxygen is used to generate documentation, while this is not technically necessary for the build it makes things a lot more pleasant.
* Doxygen is used to generate documentation; while this is not technically necessary for the build it makes things a lot more pleasant.
You have to install the library and also the library-devel (or -dev) for your
package management system to install the compile time files. If you checked
out our git you need to copy the libtool helper scripts and rebuild configure
with:
For example, to build on a recent version of Ubuntu, you would need the following packages:
# libtoolize -ci (use glibtoolize for OS X, libtool is installed as glibtool to avoid name conflict on OS X)
# autoreconf -fi
# apt install build-essential libunbound-dev libidn11-dev libssl-dev libtool m4 autoconf
If you are building from git, you need to do the following before building:
If you want to make use of the configuration files that utilise a JSON-like format, you must do
# git submodule update --init
before building.
# libtoolize -ci # (use glibtoolize for OS X, libtool is installed as glibtool to avoid name conflict on OS X)
# autoreconf -fi
If you want to use the getdns_query command line wrapper script for testing or to enable getdns as a daemon then you must build it using
# make getdns_query
As well as building the getdns library 2 other tools are installed by default by the above process:
## Minimal dependencies
* getdns_query: a command line test script wrapper for getdns
* stubby: an experimental DNS Privacy enabled client
* getdns can be configured for stub resolution mode only with the `--enable-stub-only` option to configure. This removed the dependency on `libunbound`.
Note: If you only want to build stubby, then use the `--with-stubby` option when running 'configure'.
## Minimizing dependencies
* getdns can be configured for stub resolution mode only with the `--enable-stub-only` option to configure. This removes the dependency on `libunbound`.
* Currently getdns only offers two helper functions to deal with IDN: `getdns_convert_ulabel_to_alabel` and `getdns_convert_alabel_to_ulabel`. If you do not need these functions, getdns can be configured to compile without them with the `--without-libidn` option to configure.
* When both `--enable-stub-only` and `--without-libidn` options are used, getdns has only one dependency left, which is OpenSSL.
## Extensions / Event loop dependencies
## Extensions and Event loop dependencies
The implementation works with a variety of event loops, each built as a separate shared library. See [the wiki](https://github.com/getdnsapi/getdns/wiki/Asynchronous-Support#wiki-included-event-loop-integrations) for more details.
The implementation works with a variety of event loops, each built as a separate shared library. See [this Doxygen page](https://getdnsapi.net/doxygen/group__eventloops.html) and [this man page](https://getdnsapi.net/documentation/manpages/#ASYNCHRONOUS USE) for more details.
* [libevent](http://libevent.org). Note: the examples *require* this and should work with either libevent 1.x or 2.x. 2.x is preferred.
* [libuv](https://github.com/joyent/libuv)
* [libev](http://software.schmorp.de/pkg/libev.html)
NOTE: The current Windows implementation does not support the above.
## Stubby
* Stubby is an experimental implementation of a DNS Privacy enabled stub resolver than encrypts DNS queries using TLS. It is currently suitable for advanced/technical users - all feedback is welcome!
* Details on how to use Stubby can be found in the [Stubby Reference Guide](https://getdnsapi.net/blog/dns-privacy-daemon-stubby).
* Also see [dnsprivacy.org](https://dnsprivacy.org) for more information on DNS Privacy.
## Regression Tests
A suite of regression tests are included with the library, if you make changes or just
want to sanity check things on your system take a look at src/test. You will need
to install [libcheck](https://libcheck.github.io/check/). The check library is also available from
many of the package repositories for the more popular operating systems.
to install [libcheck](https://libcheck.github.io/check/). The check library is also available from many of the package repositories for the more popular operating systems.
NOTE: The current Windows implementation does not support the above.
The regression tests do not work with --enable-stub-only.
## DNSSEC
## DNSSEC dependencies
For the library to be DNSSEC capable, it needs to know the root trust anchor.
The library will try to load the root trust anchor from
@ -167,34 +139,66 @@ execute the following steps as root:
# mkdir -p /etc/unbound
# unbound-anchor -a /etc/unbound/getdns-root.key
# Unsupported Features
Support
=======
## Mailing lists
We have a [getdns users list](https://getdnsapi.net/mailman/listinfo/users) for this implementation.
The [getdns-api mailing list](https://getdnsapi.net/mailman/listinfo/spec) is a good place to engage in discussions regarding the design of the API.
## Tickets and Bug Reports
Tickets and bug reports should be reported via the [GitHub issues list](https://github.com/getdnsapi/getdns/issues).
Features of this release
========================
## Goals
The goals of this implementation of the getdns API are:
* Provide an open source implementation, in C, of the formally described getdns API by getdns API team at <https://getdnsapi.net/spec.html>
* Support FreeBSD, OSX, Linux (CentOS/RHEL, Ubuntu) via functional "configure" script
* Support Windows 8.1
* Include examples and tests as part of the build
* Document code using doxygen
* Leverage github as much as possible for project coordination
* Follow the BSD coding style/standards <ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/share/misc/style>
Non-goals (things we will not be doing at least initially) include:
* implementation of the traditional DNS related routines (gethostbyname, etc.)
## Language Bindings
In parallel, the team is actively developing bindings for various languages.
For more information, visit this
[webpage](https://getdnsapi.net/bindings/).
## Unsupported getDNS Features
The following API calls are documented in getDNS but *not supported* by the implementation at this time:
* Disabling following of `CNAME`s with `getdns_context_set_follow_redirects()`
* Detecting changes to resolv.conf and hosts
* MDNS, NIS and NetBIOS namespaces (only DNS and LOCALFILES are supported)
## Non-uniform implementation
### Minor omissions
The following minor implementation omissions are noted:
Recursive mode does not support:
* TLS as a transport
* Non-zero connection idle timeouts or query pipelining
* Anything other than query_type and resolution_type in the return_call_reporting extension
Stub mode does not support:
* Non zero idle timeouts for synchronous calls
* Limit on number of outstanding queries
# Known Issues
There are a few known issues which we have summarized below - the most recent
and helpful list is being maintained in the git issues list in the repository.
Other known issues are being managed in the git repository issue list.
* When doing a synchronous lookup with a context that has outstanding asynchronous lookups, the callbacks for the asynchronous lookups might get called as a side effect of the synchronous lookup.
* None
# Supported Platforms
@ -203,9 +207,9 @@ The primary platforms targeted are Linux and FreeBSD, other platform are support
* RHEL/CentOS 6.4
* OSX 10.8
* Ubuntu 14.04
* Microsoft Windows 8.1 (initial support for DNSSEC but no TLS provided for version 0.5.1)
* Microsoft Windows 8.1
We intend to add Android and other platforms to the releases as we have time to port it.
We intend to add Android and other platforms to future releases as we have time to port it.
## Platform Specific Build Reports
@ -218,11 +222,11 @@ If you're using [FreeBSD](https://www.freebsd.org/), you may install getdns via
If you are using FreeBSD 10 getdns can be intalled via 'pkg install getdns'.
### CentOS/RHEL 6.5
### CentOS and RHEL 6.5
We rely on the most excellent package manager fpm to build the linux packages which
We rely on the most excellent package manager fpm to build the linux packages, which
means that the packaging platform requires ruby 2.1.0. There are other ways to
build the packages, this is simplythe one we chose to use.
build the packages; this is simply the one we chose to use.
# cat /etc/redhat-release
CentOS release 6.5 (Final)
@ -258,50 +262,48 @@ build the packages, this is simplythe one we chose to use.
create dmg
A self-compiled version of OpenSSL or the version installed via Homebrew is required.
Note: If using a self-compiled version manual configuration of certificates into /usr/local/etc/openssl/certs is required for TLS authentication to work.
Note: If using a self-compiled version, manual configuration of certificates into /usr/local/etc/openssl/certs is required for TLS authentication to work.
#### Homebrew
If you're using [Homebrew](http://brew.sh/), you may run `brew install getdns`. By default, this will only build the core library without any 3rd party event loop support.
To install the [event loop integration libraries](https://github.com/getdnsapi/getdns/wiki/Asynchronous-Support) that enable support for libevent, libuv, and libev, run: `brew install getdns --with-libevent --with-libuv --with-libev`. All switches are optional.
To install the [event loop integration libraries](https://getdnsapi.net/doxygen/group__eventloops.html) that enable support for libevent, libuv, and libev, run: `brew install getdns --with-libevent --with-libuv --with-libev`. All switches are optional.
Note that in order to compile the examples, the `--with-libevent` switch is required.
As of the 0.2.0 release, when installing via Homebrew, the trust anchor is expected to be located at `$(brew --prefix)/etc/getdns-root.key`. Additionally, the OpenSSL library installed by Homebrew is linked against. Note that the Homebrew OpenSSL installation clones the Keychain certificates to the default OpenSSL location so TLS certificate authentication should work out of the box.
### Microsoft Windows 8.1
This section has some Windows specific build instructions.
Build tested using the following:
The build has been tested using the following:
32 bit only Mingw: [Mingw(3.21.0) and Msys 1.0](http://www.mingw.org/) on Windows 8.1
32 bit build on a 64 bit Mingw [Download latest from: http://mingw-w64.org/doku.php/download/mingw-builds and http://msys2.github.io/]. IMPORTANT: Install tested ONLY on the "x86_64" for 64-bit installer of msys2.
Dependencies:
#### Dependencies
The following dependencies are
openssl-1.0.2e
libidn
* openssl-1.0.2j
* libidn
Instructions to build openssl-1.0.2e:
Instructions to build openssl-1.0.2j:
Open the mingw32_shell.bat from msys2 in order to build:
If necessary, install the following using pacman:
pacman -S pkg-config libtool automake
pacman -S autoconf automake-wrapper
tar -xvf openssl-1.0.2e.tar
cd openssl-1.0.2e/
./Configure --prefix=${LOCALDESTDIR} --openssldir=${LOCALDESTDIR}/etc/ssl --libdir=lib shared zlib-dynamic mingw
make
make install
pacman -S pkg-config libtool automake
pacman -S autoconf automake-wrapper
tar -xvf openssl-1.0.2j.tar
cd openssl-1.0.2j/
./Configure --prefix=${LOCALDESTDIR} --openssldir=${LOCALDESTDIR}/etc/ssl --libdir=lib shared zlib-dynamic mingw
make
make install
To configure:
./configure --enable-stub-only --with-trust-anchor="c:\\\MinGW\\\msys\\\1.0\\\etc\\\unbound\\\getdns-root.key" --with-ssl=<location of openssl from above> --with-getdns_query
The trust anchor is also installed by unbound on c:\program Files (X86)\unbound\root.key and can be referenced from there
The trust anchor is also installed by unbound on `c:\program Files (X86)\unbound\root.key` and can be referenced from there
or anywhere else that the user chooses to configure it.
After configuring, do a `make` and `make install` to build getdns for Windows.
@ -315,6 +317,7 @@ To configure:
Contributors
============
* Claus Assman
* Theogene Bucuti
* Andrew Cathrow, Verisign Labs
* Neil Cook
@ -322,26 +325,38 @@ Contributors
* Craig Despeaux, Verisign, Inc.
* John Dickinson, Sinodun
* Sara Dickinson, Sinodun
* Robert Edmonds
* Angelique Finan, Verisign, Inc.
* Simson Garfinkel
* Daniel Kahn Gillmor
* Neel Goyal, Verisign, Inc.
* Bryan Graham, Verisign, Inc.
* Robert Groenenberg
* Jim Hague, Sinodun
* Paul Hoffman
* Scott Hollenbeck, Verising, Inc.
* Christian Huitema
* Shumon Huque, Verisign Labs
* Jelte Janssen
* Guillem Jover
* Shane Kerr
* Anthony Kirby
* Olaf Kolkman, NLnet Labs
* Sanjay Mahurpawar, Verisign, Inc.
* Allison Mankin, Verisign, Inc. - Verisign Labs.
* Sai Mogali, Verisign, Inc.
* Linus Nordberg
* Benno Overeinder, NLnet Labs
* Joel Purra
* Tom Pusateri
* Prithvi Ranganath, Verisign, Inc.
* Hoda Rohani, NLnet Labs
* Rushi Shah, Verisign, Inc.
* Vinay Soni, Verisign, Inc.
* Melinda Shore, No Mountain Software LLC
* Bob Steagall, Verisign, Inc.
* Andrew Sullivan
* Ondřej Surý
* Willem Toorop, NLnet Labs
* Gowri Visweswaran, Verisign Labs
* Wouter Wijngaards, NLnet Labs

View File

@ -36,8 +36,12 @@ sinclude(./m4/acx_getaddrinfo.m4)
sinclude(./m4/ax_check_compile_flag.m4)
sinclude(./m4/pkg.m4)
AC_INIT([getdns], [1.1.0], [users@getdnsapi.net], [], [https://getdnsapi.net])
AC_SUBST(RELEASE_CANDIDATE, [a1])
AC_INIT([getdns], [1.1.3], [users@getdnsapi.net], [], [https://getdnsapi.net])
# Dont forget to put a dash in front of the release candidate!!!
# That is how it is done with semantic versioning!
#
AC_SUBST(RELEASE_CANDIDATE, [-rc1])
# Set current date from system if not set
AC_ARG_WITH([current-date],
@ -47,7 +51,7 @@ AC_ARG_WITH([current-date],
[CURRENT_DATE="`date -u +%Y-%m-%dT%H:%M:%SZ`"])
AC_SUBST(GETDNS_VERSION, ["AC_PACKAGE_VERSION$RELEASE_CANDIDATE"])
AC_SUBST(GETDNS_NUMERIC_VERSION, [0x0100A100])
AC_SUBST(GETDNS_NUMERIC_VERSION, [0x010102c1])
AC_SUBST(API_VERSION, ["December 2015"])
AC_SUBST(API_NUMERIC_VERSION, [0x07df0c00])
GETDNS_COMPILATION_COMMENT="AC_PACKAGE_NAME $GETDNS_VERSION configured on $CURRENT_DATE for the $API_VERSION version of the API"
@ -77,10 +81,13 @@ GETDNS_COMPILATION_COMMENT="AC_PACKAGE_NAME $GETDNS_VERSION configured on $CURRE
# getdns-0.5.0 had libversion 4:0:3
# getdns-0.5.1 had libversion 4:1:3 (but should have been getdns-0.6.0)
# getdns-0.9.0 had libversion 5:0:4
# getdns-1.0.0 will have libversion 5:1:4
# getdns-1.1.0 will have libversion 6:0:5
# getdns-1.0.0 had libversion 5:1:4
# getdns-1.1.0 had libversion 6:0:0
# getdns-1.1.1 had libversion 6:1:0
# getdns-1.1.2 has libversion 7:0:1
# getdns-1.1.3 will have libversion 7:1:1
#
GETDNS_LIBVERSION=6:0:5
GETDNS_LIBVERSION=7:1:1
AC_SUBST(GETDNS_COMPILATION_COMMENT)
AC_SUBST(GETDNS_LIBVERSION)
@ -96,9 +103,17 @@ AC_PROG_CPP
AC_CANONICAL_HOST
CFLAGS="$CFLAGS"
WPEDANTICFLAG=""
WNOERRORFLAG=""
AC_PROG_CC_C99
AX_CHECK_COMPILE_FLAG([-xc99],[CFLAGS="$CFLAGS -xc99"],[],[])
AX_CHECK_COMPILE_FLAG([-Wall],[CFLAGS="$CFLAGS -Wall"],[],[])
AX_CHECK_COMPILE_FLAG([-Wextra],[CFLAGS="$CFLAGS -Wextra"],[],[])
AX_CHECK_COMPILE_FLAG([-Wpedantic],[WPEDANTICFLAG="-Wpedantic"],[],[])
AX_CHECK_COMPILE_FLAG([-Wno-error=unused-parameter],[WNOERRORFLAG="-Wno-error=unused-parameter"],[],[])
AX_CHECK_COMPILE_FLAG([-Wno-unused-parameter],[WNOERRORFLAG="$WNOERRORFLAG -Wno-unused-parameter"],[],[])
AC_SUBST(WPEDANTICFLAG)
AC_SUBST(WNOERRORFLAG)
case "$host_os" in
linux* ) CFLAGS="$CFLAGS -D_BSD_SOURCE -D_DEFAULT_SOURCE"
@ -141,22 +156,32 @@ fi
])
ACX_ARG_RPATH
AC_ARG_ENABLE(debug-req, AC_HELP_STRING([--enable-debug-req], [Enable request debugging]))
AC_ARG_ENABLE(debug-sched, AC_HELP_STRING([--enable-debug-sched], [Enable scheduling debugging messages]))
AC_ARG_ENABLE(debug-stub, AC_HELP_STRING([--enable-debug-stub], [Enable stub debugging messages]))
AC_ARG_ENABLE(debug-daemon, AC_HELP_STRING([--enable-debug-daemon], [Enable daemon debugging messages]))
AC_ARG_ENABLE(debug-sec, AC_HELP_STRING([--enable-debug-sec], [Enable dnssec debugging messages]))
AC_ARG_ENABLE(debug-server, AC_HELP_STRING([--enable-debug-server], [Enable server debugging messages]))
AC_ARG_ENABLE(all-debugging, AC_HELP_STRING([--enable-all-debugging], [Enable scheduling, stub and dnssec debugging]))
AC_ARG_ENABLE(all-debugging, AC_HELP_STRING([--enable-all-debugging], [Enable all debugging messages]))
case "$enable_all_debugging" in
yes)
enable_debug_req=yes
enable_debug_sched=yes
enable_debug_stub=yes
enable_debug_daemon=yes
enable_debug_sec=yes
enable_debug_server=yes
;;
no|*)
;;
esac
case "$enable_debug_req" in
yes)
AC_DEFINE_UNQUOTED([REQ_DEBUG], [1], [Define this to enable printing of request debugging messages.])
;;
no|*)
;;
esac
case "$enable_debug_sched" in
yes)
AC_DEFINE_UNQUOTED([SCHED_DEBUG], [1], [Define this to enable printing of scheduling debugging messages.])
@ -171,6 +196,13 @@ case "$enable_debug_stub" in
no|*)
;;
esac
case "$enable_debug_daemon" in
yes)
AC_DEFINE_UNQUOTED([DAEMON_DEBUG], [1], [Define this to enable printing of daemon debugging messages.])
;;
no|*)
;;
esac
case "$enable_debug_sec" in
yes)
AC_DEFINE_UNQUOTED([SEC_DEBUG], [1], [Define this to enable printing of dnssec debugging messages.])
@ -198,6 +230,30 @@ case "$enable_debug_keep_connections_open" in
;;
esac
DEFAULT_EVENTLOOP=select_eventloop
AC_CHECK_HEADERS([sys/poll.h poll.h sys/resource.h],,, [AC_INCLUDES_DEFAULT])
AC_ARG_ENABLE(poll-eventloop, AC_HELP_STRING([--disable-poll-eventloop], [Disable default eventloop based on poll (default=enabled if available)]))
case "$enable_poll_eventloop" in
no)
;;
yes|*)
AC_MSG_CHECKING(for poll)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#else
#include <poll.h>
#endif
], [int rc; rc = poll((struct pollfd *)(0), 0, 0);])], [
AC_MSG_RESULT(yes)
AC_DEFINE_UNQUOTED([USE_POLL_DEFAULT_EVENTLOOP], [1], [Define this to enable a default eventloop based on poll().])
DEFAULT_EVENTLOOP=poll_eventloop
],[AC_MSG_RESULT(no)])
;;
esac
AC_SUBST(DEFAULT_EVENTLOOP)
AC_ARG_ENABLE(tcp-fastopen, AC_HELP_STRING([--disable-tcp-fastopen], Disable TCP Fast Open (default=enabled if available)),
enable_tcp_fastopen="$enableval", enable_tcp_fastopen=yes)
if test "x$enable_tcp_fastopen" = xno; then
@ -246,7 +302,8 @@ else
fi
AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS([OPENSSL_config EVP_md5 EVP_sha1 EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512 FIPS_mode ENGINE_load_cryptodev EVP_PKEY_keygen ECDSA_SIG_get0 EVP_MD_CTX_new EVP_PKEY_base_id HMAC_CTX_new HMAC_CTX_free TLS_client_method])
AC_CHECK_HEADERS([openssl/bn.h openssl/rsa.h openssl/dsa.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS([OPENSSL_config EVP_md5 EVP_sha1 EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512 FIPS_mode ENGINE_load_cryptodev EVP_PKEY_keygen ECDSA_SIG_get0 EVP_MD_CTX_new EVP_PKEY_base_id HMAC_CTX_new HMAC_CTX_free TLS_client_method DSA_SIG_set0 EVP_dss1 EVP_DigestVerify SSL_CTX_set_min_proto_version])
AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free,SSL_CTX_set_ecdh_auto], [], [], [
AC_INCLUDES_DEFAULT
#ifdef HAVE_OPENSSL_ERR_H
@ -270,6 +327,15 @@ AC_INCLUDES_DEFAULT
fi
AC_ARG_ENABLE(sha1, AC_HELP_STRING([--disable-sha1], [Disable SHA1 RRSIG support, does not disable nsec3 support]))
case "$enable_sha1" in
no)
;;
yes|*)
AC_DEFINE([USE_SHA1], [1], [Define this to enable SHA1 support.])
;;
esac
AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
case "$enable_sha2" in
no)
@ -433,39 +499,57 @@ case "$enable_dsa" in
;;
*) dnl default
# detect if DSA is supported, and turn it off if not.
AC_CHECK_FUNC(EVP_dss1, [
AC_CHECK_FUNC(DSA_SIG_new, [
AC_DEFINE_UNQUOTED([USE_DSA], [1], [Define this to enable DSA support.])
], [if test "x$enable_dsa" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support DSA and you used --enable-dsa.])
fi ])
;;
esac
AC_ARG_ENABLE(draft-dnssec-roadblock-avoidance, AC_HELP_STRING([--enable-draft-dnssec-roadblock-avoidance], [Enable experimental dnssec roadblock avoidance]))
AC_ARG_ENABLE(draft-edns-cookies, AC_HELP_STRING([--enable-draft-edns-cookies], [Enable experimental edns cookies]))
AC_ARG_ENABLE(all-drafts, AC_HELP_STRING([--enable-all-drafts], [Enable cookies and roadblock avoidance]))
AC_ARG_ENABLE(ed25519, AC_HELP_STRING([--disable-ed25519], [Disable ED25519 support]))
use_ed25519="no"
case "$enable_ed25519" in
no)
;;
*)
if test $USE_NSS = "no" -a $USE_NETTLE = "no"; then
AC_CHECK_DECLS([NID_ED25519], [
AC_DEFINE_UNQUOTED([USE_ED25519], [1], [Define this to enable ED25519 support.])
use_ed25519="yes"
], [ if test "x$enable_ed25519" = "xyes"; then AC_MSG_ERROR([OpenSSL does not support ED25519 and you used --enable-ed25519.])
fi ], [AC_INCLUDES_DEFAULT
#include <openssl/evp.h>
])
fi
;;
esac
AC_ARG_ENABLE(all-drafts, AC_HELP_STRING([--enable-all-drafts], [Enables the draft mdns client support]))
case "$enable_all_drafts" in
yes)
enable_draft_dnssec_roadblock_avoidance=yes
enable_draft_edns_cookies=yes
AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
;;
no|*)
;;
esac
case "$enable_draft_dnssec_roadblock_avoidance" in
yes)
AC_DEFINE_UNQUOTED([DNSSEC_ROADBLOCK_AVOIDANCE], [1], [Define this to enable the experimental draft dnssec roadblock avoidance.])
AC_ARG_ENABLE(dnssec-roadblock-avoidance, AC_HELP_STRING([--disable-dnssec-roadblock-avoidance], [Disable dnssec roadblock avoidance]))
case "$enable_dnssec_roadblock_avoidance" in
no)
;;
no|*)
yes|*)
AC_DEFINE_UNQUOTED([DNSSEC_ROADBLOCK_AVOIDANCE], [1], [Define this to enable the experimental dnssec roadblock avoidance.])
;;
esac
case "$enable_draft_edns_cookies" in
yes)
AC_ARG_ENABLE(edns-cookies, AC_HELP_STRING([--disable-edns-cookies], [Disable edns cookies]))
case "$enable_edns_cookies" in
no)
;;
yes|*)
if test "x_$HAVE_SSL" != "x_yes"; then
AC_MSG_ERROR([edns cookies need openssl libcrypto which is not available, please rerun without --enable-draft-edns-cookies])
AC_MSG_ERROR([edns cookies need openssl libcrypto which is not available, please rerun with --disable-edns-cookies])
fi
AC_DEFINE_UNQUOTED([EDNS_COOKIES], [1], [Define this to enable the experimental draft edns cookies.])
;;
no|*)
AC_DEFINE_UNQUOTED([EDNS_COOKIES], [1], [Define this to enable the experimental edns cookies.])
;;
esac
AC_DEFINE_UNQUOTED([EDNS_COOKIE_OPCODE], [10], [The edns cookie option code.])
@ -474,6 +558,15 @@ AC_DEFINE_UNQUOTED([EDNS_COOKIE_ROLLOVER_TIME], [(24 * 60 * 60)], [How often the
AC_DEFINE_UNQUOTED([MAXIMUM_UPSTREAM_OPTION_SPACE], [3000], [limit for dynamically-generated DNS options])
AC_DEFINE_UNQUOTED([EDNS_PADDING_OPCODE], [12], [The edns padding option code.])
AC_ARG_ENABLE(draft-mdns-support, AC_HELP_STRING([--enable-draft-mdns-support], [Enable draft mdns client support]))
case "$enable_draft_mdns_support" in
yes)
AC_DEFINE_UNQUOTED([HAVE_MDNS_SUPPORT], [1], [Define this to enable the draft mdns client support.])
;;
no|*)
;;
esac
my_with_libunbound=1
AC_ARG_ENABLE(stub-only, AC_HELP_STRING([--enable-stub-only], [Restricts resolution modes to STUB (which will be the default mode). Removes the libunbound dependency.]))
case "$enable_stub_only" in
@ -553,10 +646,16 @@ fi
# Checks for libraries.
found_all_libs=1
MISSING_DEPS=""
MISSING_SEP=""
if test $my_with_libidn = 1
then
AC_MSG_NOTICE([Checking for dependency libidn])
AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [found_all_libs=0])
AC_CHECK_LIB([idn], [idna_to_ascii_8z], [], [
MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn"
MISSING_SEP=", "
found_all_libs=0
])
fi
AC_ARG_ENABLE(unbound-event-api, AC_HELP_STRING([--disable-unbound-event-api], [Disable usage of libunbounds event API]))
@ -585,12 +684,16 @@ then
])
fi
AC_CHECK_FUNCS([ub_ctx_set_stub])
], [found_all_libs=0])
], [
MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libunbound"
MISSING_SEP=", "
found_all_libs=0
])
fi
if test $found_all_libs = 0
then
AC_MSG_ERROR([One more dependencies is missing])
AC_MSG_ERROR([Missing dependencies: $MISSING_DEPS])
fi
AC_PATH_PROG([DOXYGEN], [doxygen])
@ -607,7 +710,7 @@ AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
AC_CHECK_TYPE([u_char])
AC_CHECK_TYPES([u_char])
AC_CHECK_FUNCS([fcntl])
# check ioctlsocket
@ -692,7 +795,7 @@ AS_IF([test x_$withval = x_no],
[AC_MSG_ERROR([event2/event.h and event.h missing, try without libevent])]
[have_libevent=0],
[AC_INCLUDES_DEFAULT]
[#if HAVE_U_CHAR == 0
[#ifndef HAVE_U_CHAR
typedef unsigned char u_char;
#endif])],
[AC_INCLUDES_DEFAULT])],
@ -903,6 +1006,26 @@ else
INSTALL_GETDNS_QUERY="install-getdns_query"
UNINSTALL_GETDNS_QUERY="uninstall-getdns_query"
fi
AC_SUBST(GETDNS_QUERY)
AC_SUBST(INSTALL_GETDNS_QUERY)
AC_SUBST(UNINSTALL_GETDNS_QUERY)
AC_ARG_WITH(stubby, AS_HELP_STRING([--with-stubby],
[Compile and install stubby, the (stub) resolver daemon]),
[], [withval="no"])
if test x_$withval = x_yes; then
STUBBY="stubby"
INSTALL_STUBBY="install-stubby"
UNINSTALL_STUBBY="uninstall-stubby"
else
STUBBY=""
INSTALL_STUBBY=""
UNINSTALL_STUBBY=""
fi
AC_SUBST(STUBBY)
AC_SUBST(INSTALL_STUBBY)
AC_SUBST(UNINSTALL_STUBBY)
AC_ARG_WITH(fd-setsize, AS_HELP_STRING([--with-fd-setsize=size],
[Set maximum file descriptor number that can be used by select]),
[], [withval="no"])
@ -915,22 +1038,33 @@ case "$withval" in
;;
esac
AC_SUBST(GETDNS_QUERY)
AC_SUBST(INSTALL_GETDNS_QUERY)
AC_SUBST(UNINSTALL_GETDNS_QUERY)
AC_CONFIG_FILES([Makefile src/Makefile src/version.c src/getdns/getdns.h src/getdns/getdns_extra.h spec/example/Makefile src/test/Makefile src/tools/Makefile doc/Makefile getdns.pc getdns_ext_event.pc])
if [ test -n "$DOXYGEN" ]
then AC_CONFIG_FILES([src/Doxyfile])
fi
#---- check for pthreads library
AC_SEARCH_LIBS([pthread_mutex_init],[pthread], [
AC_DEFINE([HAVE_PTHREAD], [1], [Have pthreads library])
LIBS="-lpthread $LIBS"
], [AC_MSG_WARN([pthreads not available])])
AC_MSG_CHECKING([whether the C compiler (${CC-cc}) supports the __func__ variable])
AC_LANG_PUSH(C)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[char*s=__func__;]],[[]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE___FUNC__, [1], [Whether the C compiler support the __func__ variable])],
[AC_MSG_RESULT([no])])
AC_LANG_POP(C)
dnl -----
dnl ----- Start of "Things needed for gldns" section
dnl -----
dnl ---------------------------------------------------------------------------
AC_CHECK_HEADERS([stdarg.h stdint.h netinet/in.h arpa/inet.h netdb.h sys/socket.h time.h sys/time.h sys/select.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([stdarg.h stdint.h netinet/in.h arpa/inet.h netdb.h sys/socket.h time.h sys/time.h sys/select.h endian.h],,, [AC_INCLUDES_DEFAULT])
dnl Check the printf-format attribute (if any)
dnl result in HAVE_ATTR_FORMAT.
@ -1022,8 +1156,6 @@ if test "$ac_cv_func_arc4random" = "no"; then
])
fi
AC_DEFINE(USE_MINI_EVENT, 1, [Needed for sync stub resolver functions])
AC_TYPE_SIGNAL
case `uname` in
@ -1037,21 +1169,32 @@ esac
AC_SUBST(C99COMPATFLAGS)
AC_DEFINE_UNQUOTED([MAX_CNAME_REFERRALS], [100], [The maximum number of cname referrals.])
AC_DEFINE_UNQUOTED([DRAFT_RRTYPES], [1], [Define this to enable all rrtypes in gldns.])
AH_BOTTOM([
#ifdef GETDNS_ON_WINDOWS
/* On windows it is allowed to increase the FD_SETSIZE
* (and nescessary to make our custom eventloop work)
* See: https://support.microsoft.com/en-us/kb/111855
*/
#ifndef FD_SETSIZE
#define FD_SETSIZE 1024
#ifdef HAVE___FUNC__
#define __FUNC__ __func__
#else
#define __FUNC__ __FUNCTION__
#endif
#define PRIsz "%Iu"
#ifdef GETDNS_ON_WINDOWS
/* On windows it is allowed to increase the FD_SETSIZE
* (and nescessary to make our custom eventloop work)
* See: https://support.microsoft.com/en-us/kb/111855
*/
# ifndef FD_SETSIZE
# define FD_SETSIZE 1024
# endif
# define PRIsz "%Iu"
/* Windows wants us to use _strdup instead of strdup */
# ifndef strdup
# define strdup _strdup
# endif
#else
#define PRIsz "%zu"
# define PRIsz "%zu"
#endif
#include <stdint.h>
@ -1088,8 +1231,6 @@ AH_BOTTOM([
#define FD_SET_T
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -1144,6 +1285,12 @@ int inet_pton(int af, const char* src, void* dst);
const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#endif
#ifdef USE_WINSOCK
static inline int _gldns_custom_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ int r = vsnprintf(str, size, format, ap); return r == -1 ? _vscprintf(format, ap) : r; }
# define vsnprintf _gldns_custom_vsnprintf
#endif
#ifdef __cplusplus
}
#endif

View File

@ -77,6 +77,7 @@ uninstall:
clean:
for x in $(MANPAGES3); do rm -f $$($(srcdir)/manpgaltnames $$x); done
rm -f tagfile
rm -rf $(DOCDIRS) $(MANPAGES3)
distclean : clean

View File

@ -33,7 +33,7 @@
-- get ip address(es) for a name
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- cancel an outstanding asyn getdns request
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -39,7 +39,7 @@
.ad n
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>
@ -141,7 +141,7 @@ in use might have a requirements on this issue. You may need to provide one or
two functions to allow it to function properly. For example before you call
getdns_context_create() you may need to use
the openssl functions CRYPTO_set_id_callback and CRYPTO_set_locking_callback to set up
asyncronous operation (the application calls these functions once for initialisation).
asynchronous operation (the application calls these functions once for initialisation).
Openssl 1.0.0 or later uses the CRYPTO_THREADID_set_callback function.
.HP 3

View File

@ -45,7 +45,7 @@
.ad n
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- get informed on getdns context updates
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -34,7 +34,7 @@
-- convert dname between presentation- and wire-format
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -38,7 +38,7 @@
.ad n
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -38,7 +38,7 @@
-- get value by name from a getdns dict
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -36,7 +36,7 @@
-- set a value by name in a getdns dict
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- convert an getdns ip address to string
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -33,7 +33,7 @@
-- do a getdns DNS lookup
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -33,7 +33,7 @@
-- get hostname by address
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -38,7 +38,7 @@
.ad n
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -38,7 +38,7 @@
-- get a value by index from a getdns list
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -36,7 +36,7 @@
-- set a value by index from a getdns list
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- return a string representation of a getdns dict
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- return the getdns list of default root trust anchors
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -33,7 +33,7 @@
-- getdns lookup of a service
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@
-- DNSSEC validate a given getdns record
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
#include <getdns.h>

View File

@ -32,7 +32,7 @@ libgetdns
-- an implementation of a modern asynchronous DNS API by and for application developers
.SH LIBRARY
DNS Resolver library (libgetdns, -lgetdns)
DNS Resolver library (libgetdns, \-lgetdns)
.SH SYNOPSIS
.B libgetdns
@ -230,7 +230,7 @@ Set to GETDNS_EXTENSION_TRUE to include the DNSSEC status for each DNS record in
.HP 3
"dnssec_return_only_secure" (int)
Set to GETDNS_EXTENSION_TRUE to cause only records that the API can validate as secure withe DNSSEC to be returned in the
Set to GETDNS_EXTENSION_TRUE to cause only records that the API can validate as secure with DNSSEC to be returned in the
.I replies_tree
and
.I replies_full lists

View File

@ -13,10 +13,10 @@ Recursive Resolver Cache
Caching is arguably an important feature for most recursive resolvers.
In this case we are not intending a replacement for the fully
functional recursive resolvers already available (BIND, Unbound, etc.)
so we shoudl limit a cache implementation to behaviors important to
so we should limit a cache implementation to behaviors important to
proper operation of a recursive resolver.
DNSSEC validation can potentially triggers more queries than a simple
DNSSEC validation can potentially trigger more queries than a simple
request for a A RR so I think it makes sense to cache root and TLD
data. Once we have gone that far it isn't much of a reach to cache
at each layer in the hierarchy (depth will not increase the coding

View File

@ -1,168 +1,93 @@
High level release procedure that we follow to make a formal release for the
getdns API project. This is a recipe - if you have a better way to do it then
update this document and share it with us.
High level release procedure for formal release for the getdns API project.
- code freeze
confirm with core team that all commits are in, from this point forward
only bug fixes should be committed to the release branch, once the release
is cut nothing should be committed to the release branch (make a new release)
1) Git branching for a release
-- Confirm with core team (preferably via email) that all commits to be included
in the release are in the develop branch. Development for the next release can
continue on develop.
-- Create a release branch. We use the pattern "release/v1.0.0-b3" for naming
release branches. This branch is used for testing
and bug fixing while preparing the release (which can take several days
if there are un-foreseen issues). Note that from this point forward _only_
bug fixes for this release should be committed to the release branch.
-- Once the release is published there should be no further commits on that
release branch.
- create a release branch
in git repository named for the release, e.g. "v0.1.2"
we do this because folks may want to continue to work in the master branch
and be free to commit changes without injuring the release process. Since
building and testing binaries for a release takes a few days we don't want to
force changes to queue up.
2) Prepare the release
-- Clone the upstream to a _new_ local directory. (Do NOT re-use and
existing working copy as this can lead to issues).
One might argue that a release can be cut more quickly, however there are
inevitably little tweaks that need to be made that get uncovered as a result
of the binary builds - these tweaks need to be included in the souces for
this release so building the source tarball can't be done until all of the
binaries have been built and tested.
# git clone -b v1.0.0-b3 https://github.com/getdnsapi/getdns.git getdns-1.0.0-b3
- clone repo release branch to a clean local repo
this should be a brand spanking new directory - don't try to shortcut it and
use a working directory with lots of cruft - crap will find its way into the
release and embarass you:
-- Update several files to reflect release number/date
./README.md
./ChangeLog
./configure.ac
- Check and change the values for:
- AC_INIT
- RELEASE_CANDIDATE
- GETDNS_NUMERIC_VERSION
- API_VERSION and API_NUMERUC_VERSION
- read the section "Library version" and update GETDNS_LIBVERSION carefully!
# git clone -b v0.1.2 https://github.com/getdnsapi/getdns.git getdns-0.1.2
# autoreconf -fi
- update files to reflect release number/date
./README.md
./ChangeLog
./configure.ac (AC_INIT)
./src/Makefile.in (-version-info, follow libtool guidelines)
Commit these changes to the release branch
# make clean
# autoreconf
# git commit -a -m "release number and date updates"
# git push
commit these changes to the release branch
3) Test
The unit and tpkg tests should be run on all the supported platforms. They must all
be able to fulfil all requirements. So they must have libidn, libev, libuv, libevent,
latest libunbound, latest openssl (at least 1.0.2) latest clang compiler
(for static analysis), latest valgrind. The tests can be run using:
# git commit -a -m "release number and date updates"
# git push
# ${GETDNS_SRCDIR}/src/test/tpkg/run-all.sh
- prepare to build binaries for each target platform
you need to remove libs and headers that might be lingering from previous builds
to avoid accidentally including the wrong headers or linking the wrong libs
and evaluating the results.
- create clean local repo
- build source distribution tar
4) Build and sign source distribution tarball
# rm -fr *
# git reset --hard
# git submodule update --init
# autoreconf -fi
# libtoolize -ci
# ./configure
# make dist
# openssl sha1 getdns-0.1.2.tar.gz > getdns-0.1.2.tar.gz.sha1
# openssl md5 getdns-0.1.2.tar.gz > getdns-0.1.2.tar.gz.md5
# gpg --armor --detach-sig --default-key gwiley@verisign.com getdns-0.1.2.tar.gz
# make pub
- test the resulting tar by building it and running the regression tests
The resulting tarball must be built, installed and tested on all the supported
platforms. Be sure to use a user that was NOT used for the build, this will uncover
any issues related to absolute paths in the build
- build CentOS binary
# tar -xzvf getdns-0.1.2.tar.gz
# cd getdns-0.1.2
# ./configure --with-libevent --prefix=$HOME/build
# make
# make install
# cd ~/build
- fix the libdir path in the *.la files to point to /usr/local/lib
- fix the dependency_libs entry in the *.la files to point to /usr/local/lib
# fpm -x "*.la" -a native -s dir --rpm-sign -t rpm -n getdns -v 0.1.2 -d "unbound" -d "ldns" -d "libevent" -d "libidn" --prefix /usr/local --vendor "Verisign Inc., NLnet Labs" --license "BSD New" --url "http://www.getdnsapi.net" --description "Modern asynchronous API to the DNS" .
- make sure your signing key is in the keyring on the build machine
- contents of ~/.rpmmacros
%_signature gpg
%_gpg_path /root/.gnupg
%_gpg_name A6B73532
%_gpgbin /usr/bin/gpg
5) Fix any problems
-- If a build breaks or an install fails then commit fixes to the release branch.
Then re-run steps 3 and 4 for all supported platforms using the new code.
- name the rpm and checksum files something like this:
getdns-0.1.3-1.CentOS_6_5.x86_64.rpm
getdns-0.1.3-1.CentOS_6_5.x86_64.rpm.sha1
getdns-0.1.3-1.CentOS_6_5.x86_64.rpm.md5
- check the signature
- install
- test
6) Merge branch changes back into master/develop
-- If this is a production release - then the release branch must be merged into master
Sign the merge tag if possible.
-- Now the release is ready, all the relevant commits on the release branch
should also be merged back into develop.
- build OSX binary disk image
7) Create the tarball
# make clean
# make pub
This generates getdns-1.0.0-b3.tar.gz + checksums + signatures.
- build code (no additional libraries, note that regression tests will not build)
if you are building a simple binary tar then something like this works
# ./configure --prefix=/Users/gwiley/getdnsox/export
# make
# make install
# tar -C /Users/gwiley/getdnsosx/export -cvf getdns-0.1.2.tar *
8) Upload source tarball and checksums and signatures to the getdnsapi.net site
- build code (with libevent)
# ./configure --with-libevent2
# scp getdns-1.0.0-b3.tar.gz* getdnsapi.net:/usr/local/www/apache24/data/dist
- run regression tests and verify that alls well
9) Create and push signed tags to github
if you have do do anything even mildly interesting to get the build or install to
work then we either have to add it to the README.md or, preferably, fix it
and update the branch
# git -s v1.0.0-b3
# git push --tags
Be careful about tool sets loaded on your build hosts. You may have 'solved'
problems while you are working that mask issues with the build for more typical
users - this is why we want to build on hosts that are representative of
our users.
10) Update getdnsapi.net web site
- Create an entry the the 'Checksum' page using the content of ChangeLog
- Create a new 'News' entry
- install on each target platform
- make sure and use a user that was NOT used for the build, this will uncover
any silliness related to absolute paths in the build
- if a build breaks or an install fails then commit fixes to the relase branch
- rebuild EVERY binary using the changed release branch
- merge branch changes back into master
- once all binaries are built and tested clean, create source tar ball
and the actual package for each platform
you may need to run this as root to permit the chown
# make clean
# make dist
generates getdns-0.1.2.tar.gz
- sign each binary/source tar using one or more developers keys
- make sure that the keys you use to sign the release are also up to date
on the getdnsapi.net site
- generate checksums for each binary/source tar
- upload source and binaries to the getdnsapi.net site
- create a release in the github repository
- from the main repo choose 'releases'
- choose 'Draft a new release'
- use tag v0.x.y to match the branch being released
- for a release name use v0.x.y
- for description cut/paste the ChangeLog entry
- check the 'pre-release' checkbox (unless this is a production release)
- update getdnsapi.net web site
- push binaries to getdnsapi.net
/usr/local/www/apache24/data/dist
- news entry for the release
/usr/local/www/apache24/data/news.html
- download links and checksums
/usr/local/www/apache24/data/frontpage.html
- rebuild website
# ./build.sh
- announce message to
getdns mailing list
stub-resolvers mailing list
Verisign internal via the matrix
- update the
11) Announce the release to the lists (make sure to sign the emails)
users@getdnsapi.net, spec@getdnsapi.net and maintainers@nlnetlabs.nl
List of Build Targets
---------------------
The naming conventions for each of these build products are specific to the
platform they target. The result is that the naming seems a little inconsistent,
however I felt that it is best to follow naming standards for the platform rather
than try to impose a project specific standard across platforms.
- source tar: getdns-0.1.2.tar.gz
- OSX binary package: getdns-0.1.2-OSX_10_8.dmg
- RHEL/CentOS: getdns-0.1.0-1.CentOS_6_5.x86_64.rpm
- Debian/Ubuntu:

View File

@ -875,7 +875,7 @@ names:</p>
<li><code>query_name</code> (a bindata) is the name that was sent</li>
<li><code>query_type</code> (an int) is the type that was queried for</li>
<li><code>query_to</code> (a bindata) is the address to which the query was sent</li>
<li><code>run_time</code> (a bindata) is the difference between the time the successful
<li><code>run_time/ms</code> (a bindata) is the difference between the time the successful
query started and ended in milliseconds, represented
as a uint32_t (this does not include time taken for connection set up
or transport fallback)</li>

File diff suppressed because it is too large Load Diff

View File

@ -35,20 +35,29 @@ libversion = @GETDNS_LIBVERSION@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libdir = @libdir@
includedir = @includedir@
sysconfdir = @sysconfdir@
localstatedir = @localstatedir@
runstatedir = @runstatedir@
stubbyconfdir = $(sysconfdir)/stubby
have_libevent = @have_libevent@
have_libuv = @have_libuv@
have_libev = @have_libev@
# datarootdir is here to please some checkers
datarootdir=@datarootdir@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
srcdir = @srcdir@
stubbysrcdir = $(srcdir)/../stubby
LIBTOOL = ../libtool
CC=@CC@
CFLAGS=-I$(srcdir) -I. @CFLAGS@ @CPPFLAGS@
CFLAGS=-I$(srcdir) -I. -I$(srcdir)/util/auxiliary @CFLAGS@ @CPPFLAGS@ $(XTRA_CFLAGS)
WPEDANTICFLAG=@WPEDANTICFLAG@
WNOERRORFLAG=@WNOERRORFLAG@
LDFLAGS=@LDFLAGS@ @LIBS@
EXTENSION_LIBEVENT_LIB=@EXTENSION_LIBEVENT_LIB@
@ -63,103 +72,136 @@ EXTENSION_LIBUV_LDFLAGS=@EXTENSION_LIBUV_LDFLAGS@
C99COMPATFLAGS=@C99COMPATFLAGS@
DEFAULT_EVENTLOOP_OBJ=@DEFAULT_EVENTLOOP@.lo
GETDNS_OBJ=const-info.lo convert.lo dict.lo dnssec.lo general.lo \
list.lo request-internal.lo pubkey-pinning.lo rr-dict.lo \
rr-iter.lo server.lo stub.lo sync.lo ub_loop.lo util-internal.lo
rr-iter.lo server.lo stub.lo sync.lo ub_loop.lo util-internal.lo \
mdns.lo
GLDNS_OBJ=keyraw.lo gbuffer.lo wire2str.lo parse.lo parseutil.lo rrdef.lo \
str2wire.lo
PROGRAMS=@STUBBY@
LIBOBJDIR=
LIBOBJS=@LIBOBJS@
COMPAT_OBJ=$(LIBOBJS:.o=.lo)
UTIL_OBJ=rbtree.lo val_secalgo.lo
UTIL_OBJ=rbtree.lo val_secalgo.lo lruhash.lo lookup3.lo locks.lo
JSMN_OBJ=jsmn.lo
EXTENSION_OBJ=default_eventloop.lo libevent.lo libev.lo
EXTENSION_OBJ=$(DEFAULT_EVENTLOOP_OBJ) libevent.lo libev.lo
NON_C99_OBJS=context.lo libuv.lo
.SUFFIXES: .c .o .a .lo .h
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $< -o $@
.c.lo:
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $< -o $@
default: all
all: libgetdns.la $(EXTENSION_LIBEVENT_LIB) $(EXTENSION_LIBUV_LIB) $(EXTENSION_LIBEV_LIB)
all: libgetdns.la $(EXTENSION_LIBEVENT_LIB) $(EXTENSION_LIBUV_LIB) $(EXTENSION_LIBEV_LIB) $(PROGRAMS)
$(GETDNS_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $(srcdir)/$(@:.lo=.c) -o $@
$(GLDNS_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/gldns/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $(srcdir)/gldns/$(@:.lo=.c) -o $@
$(COMPAT_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/compat/$(@:.lo=.c) -o $@
$(UTIL_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/util/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WNOERRORFLAG) -c $(srcdir)/util/$(@:.lo=.c) -o $@
$(JSMN_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -DJSMN_GETDNS -c $(srcdir)/jsmn/$(@:.lo=.c) -o $@
$(EXTENSION_OBJ):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/extension/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $(srcdir)/extension/$(@:.lo=.c) -o $@
context.lo:
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(C99COMPATFLAGS) -c $(srcdir)/context.c -o context.lo
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) $(C99COMPATFLAGS) -c $(srcdir)/context.c -o context.lo
libuv.lo:
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(C99COMPATFLAGS) -c $(srcdir)/extension/libuv.c -o libuv.lo
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) $(C99COMPATFLAGS) -c $(srcdir)/extension/libuv.c -o libuv.lo
install: libgetdns.la
install-headers: getdns/getdns.h getdns/getdns_extra.h
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/getdns
$(INSTALL) -m 644 getdns/getdns.h $(DESTDIR)$(includedir)/getdns/getdns.h
$(INSTALL) -m 644 getdns/getdns_extra.h $(DESTDIR)$(includedir)/getdns/getdns_extra.h
if test $(have_libevent) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libevent.h $(DESTDIR)$(includedir)/getdns/ ; fi
if test $(have_libuv) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libuv.h $(DESTDIR)$(includedir)/getdns/ ; fi
if test $(have_libev) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libev.h $(DESTDIR)$(includedir)/getdns/ ; fi
uninstall-headers:
rm -rf $(DESTDIR)$(includedir)/getdns
install-libs: libgetdns.la
$(INSTALL) -m 755 -d $(DESTDIR)$(libdir)
$(LIBTOOL) --mode=install cp libgetdns.la $(DESTDIR)$(libdir)
if test $(have_libevent) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libevent.h $(DESTDIR)$(includedir)/getdns/ ; $(LIBTOOL) --mode=install cp $(EXTENSION_LIBEVENT_LIB) $(DESTDIR)$(libdir) ; fi
if test $(have_libuv) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libuv.h $(DESTDIR)$(includedir)/getdns/ ; $(LIBTOOL) --mode=install cp $(EXTENSION_LIBUV_LIB) $(DESTDIR)$(libdir) ; fi
if test $(have_libev) = 1 ; then $(INSTALL) -m 644 $(srcdir)/getdns/getdns_ext_libev.h $(DESTDIR)$(includedir)/getdns/ ; $(LIBTOOL) --mode=install cp $(EXTENSION_LIBEV_LIB) $(DESTDIR)$(libdir) ; fi
if test $(have_libevent) = 1 ; then $(LIBTOOL) --mode=install cp $(EXTENSION_LIBEVENT_LIB) $(DESTDIR)$(libdir) ; fi
if test $(have_libuv) = 1 ; then $(LIBTOOL) --mode=install cp $(EXTENSION_LIBUV_LIB) $(DESTDIR)$(libdir) ; fi
if test $(have_libev) = 1 ; then $(LIBTOOL) --mode=install cp $(EXTENSION_LIBEV_LIB) $(DESTDIR)$(libdir) ; fi
$(LIBTOOL) --mode=finish $(DESTDIR)$(libdir)
uninstall:
rm -rf $(DESTDIR)$(includedir)/getdns
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/libgetdns.la
uninstall-libs:
if test $(have_libevent) = 1; then $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(EXTENSION_LIBEVENT_LIB) ; fi
if test $(have_libuv) = 1; then $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(EXTENSION_LIBUV_LIB) ; fi
if test $(have_libev) = 1; then $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$(EXTENSION_LIBEV_LIB) ; fi
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/libgetdns.la
install: install-libs install-headers @INSTALL_STUBBY@
uninstall: @UNINSTALL_STUBBY@ uninstall-headers uninstall-libs
libgetdns_ext_event.la: libgetdns.la libevent.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ libevent.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libevent.symbols
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ libevent.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libevent.symbols
libgetdns_ext_uv.la: libgetdns.la libuv.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ libuv.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libuv.symbols
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ libuv.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libuv.symbols
libgetdns_ext_ev.la: libgetdns.la libev.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ libev.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libev.symbols
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ libev.lo libgetdns.la $(LDFLAGS) $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/extension/libev.symbols
libgetdns.la: $(GETDNS_OBJ) version.lo context.lo default_eventloop.lo $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ)
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ $(GETDNS_OBJ) version.lo context.lo default_eventloop.lo $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/libgetdns.symbols
libgetdns.la: $(GETDNS_OBJ) version.lo context.lo $(DEFAULT_EVENTLOOP_OBJ) $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ $(GETDNS_OBJ) version.lo context.lo $(DEFAULT_EVENTLOOP_OBJ) $(GLDNS_OBJ) $(COMPAT_OBJ) $(UTIL_OBJ) $(JSMN_OBJ) $(LDFLAGS) -rpath $(libdir) -version-info $(libversion) -no-undefined -export-symbols $(srcdir)/libgetdns.symbols
test: all
test: default
cd test && $(MAKE) $@
getdns_query: all
getdns_query: default
cd tools && $(MAKE) $@
scratchpad: all
stubby.lo: $(stubbysrcdir)/src/stubby.c
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -DSTUBBYCONFDIR=\"$(sysconfdir)/stubby\" -DRUNSTATEDIR=\"$(runstatedir)\" -c $< -o $@
stubby: stubby.lo libgetdns.la
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ stubby.lo $(LDFLAGS) libgetdns.la
install-stubby: stubby $(stubbysrcdir)/stubby.conf.example $(stubbysrcdir)/stubby-setdns-macos.sh
$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
$(LIBTOOL) --mode=install cp stubby $(DESTDIR)$(bindir)
$(INSTALL) -m 755 -d $(DESTDIR)$(sbindir)
$(INSTALL) -m 755 $(stubbysrcdir)/stubby-setdns-macos.sh $(DESTDIR)$(sbindir)
$(INSTALL) -m 755 -d $(DESTDIR)$(stubbyconfdir)
test -f $(DESTDIR)$(stubbyconfdir)/stubby.conf || \
$(INSTALL_DATA) $(stubbysrcdir)/stubby.conf.example $(DESTDIR)$(stubbyconfdir)/stubby.conf
uninstall-stubby:
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(bindir)/stubby
rm -f $(DESTDIR)$(sbindir)/stubby-setdns-macos.sh
scratchpad: default
cd test && $(MAKE) $@
pad: scratchpad
@ -184,13 +226,14 @@ Makefile: $(srcdir)/Makefile.in ../config.status
depend:
(cd $(srcdir) ; awk 'BEGIN{P=1}{if(P)print}/^# Dependencies/{P=0}' Makefile.in > Makefile.in.new )
(blddir=`pwd`; cd $(srcdir) ; gcc -MM -I. -I"$$blddir" *.c gldns/*.c compat/*.c util/*.c jsmn/*.c extension/*.c| \
(blddir=`pwd`; cd $(srcdir) ; gcc -MM -I. -I"$$blddir" -Iutil/auxiliary *.c gldns/*.c compat/*.c util/*.c jsmn/*.c extension/*.c| \
sed -e "s? $$blddir/? ?g" \
-e 's?gldns/?$$(srcdir)/gldns/?g' \
-e 's?compat/?$$(srcdir)/compat/?g' \
-e 's?util/?$$(srcdir)/util/?g' \
-e 's?jsmn/?$$(srcdir)/jsmn/?g' \
-e 's?extension/?$$(srcdir)/extension/?g' \
-e 's? gldns/? $$(srcdir)/gldns/?g' \
-e 's? compat/? $$(srcdir)/compat/?g' \
-e 's? util/auxiliary/util/? $$(srcdir)/util/auxiliary/util/?g' \
-e 's? util/? $$(srcdir)/util/?g' \
-e 's? jsmn/? $$(srcdir)/jsmn/?g' \
-e 's? extension/? $$(srcdir)/extension/?g' \
-e 's? \([a-z_-]*\)\.\([ch]\)? $$(srcdir)/\1.\2?g' \
-e 's? \$$(srcdir)/config\.h? config.h?g' \
-e 's? \$$(srcdir)/getdns/getdns_extra\.h? getdns/getdns_extra.h?g' \
@ -217,16 +260,22 @@ context.lo context.o: $(srcdir)/context.c \
$(srcdir)/debug.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/context.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/list.h $(srcdir)/dict.h \
$(srcdir)/pubkey-pinning.h
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/list.h \
$(srcdir)/dict.h $(srcdir)/pubkey-pinning.h
convert.lo convert.o: $(srcdir)/convert.c \
config.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h \
$(srcdir)/util/orig-headers/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h \
$(srcdir)/util/lruhash.h $(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h \
$(srcdir)/util/orig-headers/locks.h $(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/wire2str.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/parseutil.h $(srcdir)/const-info.h $(srcdir)/dict.h \
$(srcdir)/list.h $(srcdir)/jsmn/jsmn.h $(srcdir)/convert.h
@ -235,62 +284,98 @@ dict.lo dict.o: $(srcdir)/dict.c \
$(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/const-info.h $(srcdir)/gldns/wire2str.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/const-info.h $(srcdir)/gldns/wire2str.h \
$(srcdir)/gldns/parseutil.h
dnssec.lo dnssec.o: $(srcdir)/dnssec.c \
config.h \
$(srcdir)/debug.h \
getdns/getdns.h \
$(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/parseutil.h $(srcdir)/general.h $(srcdir)/dict.h \
$(srcdir)/list.h $(srcdir)/util/val_secalgo.h
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/gldns/keyraw.h $(srcdir)/gldns/parseutil.h \
$(srcdir)/general.h $(srcdir)/dict.h $(srcdir)/list.h $(srcdir)/util/val_secalgo.h \
$(srcdir)/util/orig-headers/val_secalgo.h
general.lo general.o: $(srcdir)/general.c \
config.h \
$(srcdir)/general.h \
getdns/getdns.h \
$(srcdir)/types-internal.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/gldns/wire2str.h $(srcdir)/context.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \
$(srcdir)/dict.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/ub_loop.h $(srcdir)/debug.h \
$(srcdir)/gldns/wire2str.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h $(srcdir)/dict.h \
$(srcdir)/mdns.h
list.lo list.o: $(srcdir)/list.c $(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util-internal.h \
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/util-internal.h \
config.h \
$(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h \
$(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/list.h $(srcdir)/dict.h
$(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/list.h $(srcdir)/dict.h
mdns.lo mdns.o: $(srcdir)/mdns.c \
config.h \
$(srcdir)/debug.h $(srcdir)/context.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/general.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h \
$(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/mdns.h \
$(srcdir)/util/auxiliary/util/fptr_wlist.h $(srcdir)/util/lookup3.h \
$(srcdir)/util/orig-headers/lookup3.h
pubkey-pinning.lo pubkey-pinning.o: $(srcdir)/pubkey-pinning.c \
config.h \
$(srcdir)/debug.h \
getdns/getdns.h \
$(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/server.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h
request-internal.lo request-internal.o: $(srcdir)/request-internal.c \
config.h \
$(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/util-internal.h $(srcdir)/context.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h \
$(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/dict.h \
$(srcdir)/convert.h
$(srcdir)/convert.h $(srcdir)/general.h
rr-dict.lo rr-dict.o: $(srcdir)/rr-dict.c $(srcdir)/rr-dict.h \
config.h \
getdns/getdns.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/util-internal.h $(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dict.h
rr-iter.lo rr-iter.o: $(srcdir)/rr-iter.c $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
config.h \
getdns/getdns.h \
@ -299,40 +384,52 @@ server.lo server.o: $(srcdir)/server.c \
config.h \
getdns/getdns_extra.h \
getdns/getdns.h \
$(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h
$(srcdir)/context.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h
stub.lo stub.o: $(srcdir)/stub.c \
config.h \
$(srcdir)/debug.h $(srcdir)/stub.h \
getdns/getdns.h \
$(srcdir)/types-internal.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/rrdef.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h $(srcdir)/server.h \
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/wire2str.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/server.h \
$(srcdir)/util/lruhash.h $(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h \
$(srcdir)/util/orig-headers/locks.h $(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h \
$(srcdir)/util-internal.h $(srcdir)/general.h $(srcdir)/pubkey-pinning.h
sync.lo sync.o: $(srcdir)/sync.c \
getdns/getdns.h \
config.h \
$(srcdir)/context.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/general.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h \
$(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h \
$(srcdir)/extension/default_eventloop.h $(srcdir)/extension/poll_eventloop.h \
$(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/general.h $(srcdir)/util-internal.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h $(srcdir)/stub.h \
$(srcdir)/gldns/wire2str.h
ub_loop.lo ub_loop.o: $(srcdir)/ub_loop.c $(srcdir)/ub_loop.h \
config.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/debug.h
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/debug.h
util-internal.lo util-internal.o: $(srcdir)/util-internal.c \
config.h \
getdns/getdns.h \
$(srcdir)/dict.h $(srcdir)/util/rbtree.h $(srcdir)/types-internal.h \
$(srcdir)/dict.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/types-internal.h \
getdns/getdns_extra.h \
$(srcdir)/list.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h $(srcdir)/ub_loop.h \
$(srcdir)/debug.h $(srcdir)/server.h $(srcdir)/rr-iter.h $(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h \
$(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h $(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h
$(srcdir)/list.h $(srcdir)/util-internal.h $(srcdir)/context.h $(srcdir)/extension/default_eventloop.h \
$(srcdir)/extension/poll_eventloop.h $(srcdir)/types-internal.h $(srcdir)/ub_loop.h $(srcdir)/debug.h $(srcdir)/server.h \
$(srcdir)/util/lruhash.h $(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h \
$(srcdir)/util/orig-headers/locks.h $(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/rr-iter.h \
$(srcdir)/rr-dict.h $(srcdir)/gldns/gbuffer.h $(srcdir)/gldns/pkthdr.h $(srcdir)/gldns/str2wire.h $(srcdir)/gldns/rrdef.h \
$(srcdir)/dnssec.h $(srcdir)/gldns/rrdef.h
gbuffer.lo gbuffer.o: $(srcdir)/gldns/gbuffer.c \
config.h \
$(srcdir)/gldns/gbuffer.h
@ -372,6 +469,8 @@ getentropy_osx.lo getentropy_osx.o: $(srcdir)/compat/getentropy_osx.c \
getentropy_solaris.lo getentropy_solaris.o: $(srcdir)/compat/getentropy_solaris.c \
config.h
getentropy_win.lo getentropy_win.o: $(srcdir)/compat/getentropy_win.c
gettimeofday.lo gettimeofday.o: $(srcdir)/compat/gettimeofday.c \
config.h
inet_ntop.lo inet_ntop.o: $(srcdir)/compat/inet_ntop.c \
config.h
inet_pton.lo inet_pton.o: $(srcdir)/compat/inet_pton.c \
@ -380,35 +479,59 @@ sha512.lo sha512.o: $(srcdir)/compat/sha512.c \
config.h
strlcpy.lo strlcpy.o: $(srcdir)/compat/strlcpy.c \
config.h
locks.lo locks.o: $(srcdir)/util/locks.c \
config.h \
$(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h $(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h
lookup3.lo lookup3.o: $(srcdir)/util/lookup3.c \
config.h \
$(srcdir)/util/auxiliary/util/storage/lookup3.h $(srcdir)/util/lookup3.h \
$(srcdir)/util/orig-headers/lookup3.h
lruhash.lo lruhash.o: $(srcdir)/util/lruhash.c \
config.h \
$(srcdir)/util/auxiliary/util/storage/lruhash.h $(srcdir)/util/lruhash.h \
$(srcdir)/util/orig-headers/lruhash.h $(srcdir)/util/locks.h $(srcdir)/util/orig-headers/locks.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util/auxiliary/util/fptr_wlist.h
rbtree.lo rbtree.o: $(srcdir)/util/rbtree.c \
config.h \
$(srcdir)/util/log.h $(srcdir)/debug.h $(srcdir)/util/fptr_wlist.h $(srcdir)/util/rbtree.h
$(srcdir)/util/auxiliary/log.h $(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h \
$(srcdir)/util/auxiliary/fptr_wlist.h $(srcdir)/util/auxiliary/util/fptr_wlist.h \
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h
val_secalgo.lo val_secalgo.o: $(srcdir)/util/val_secalgo.c \
config.h \
$(srcdir)/util/val_secalgo.h $(srcdir)/util/log.h $(srcdir)/debug.h $(srcdir)/gldns/rrdef.h $(srcdir)/gldns/keyraw.h \
$(srcdir)/gldns/gbuffer.h
$(srcdir)/util/auxiliary/util/data/packed_rrset.h \
$(srcdir)/util/auxiliary/validator/val_secalgo.h $(srcdir)/util/val_secalgo.h \
$(srcdir)/util/orig-headers/val_secalgo.h $(srcdir)/util/auxiliary/validator/val_nsec3.h \
$(srcdir)/util/auxiliary/util/log.h $(srcdir)/debug.h $(srcdir)/util/auxiliary/sldns/rrdef.h \
$(srcdir)/gldns/rrdef.h $(srcdir)/util/auxiliary/sldns/keyraw.h $(srcdir)/gldns/keyraw.h \
$(srcdir)/util/auxiliary/sldns/sbuffer.h $(srcdir)/gldns/gbuffer.h
jsmn.lo jsmn.o: $(srcdir)/jsmn/jsmn.c $(srcdir)/jsmn/jsmn.h
default_eventloop.lo default_eventloop.o: $(srcdir)/extension/default_eventloop.c \
$(srcdir)/extension/default_eventloop.h \
config.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/debug.h
libev.lo libev.o: $(srcdir)/extension/libev.c \
config.h \
$(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libev.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/getdns/getdns_ext_libev.h
libevent.lo libevent.o: $(srcdir)/extension/libevent.c \
config.h \
$(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libevent.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/getdns/getdns_ext_libevent.h
libuv.lo libuv.o: $(srcdir)/extension/libuv.c \
config.h \
$(srcdir)/debug.h $(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/getdns/getdns_ext_libuv.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/getdns/getdns_ext_libuv.h
poll_eventloop.lo poll_eventloop.o: $(srcdir)/extension/poll_eventloop.c \
config.h \
$(srcdir)/extension/poll_eventloop.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/debug.h
select_eventloop.lo select_eventloop.o: $(srcdir)/extension/select_eventloop.c \
config.h \
$(srcdir)/extension/select_eventloop.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/debug.h $(srcdir)/types-internal.h $(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h

View File

@ -34,6 +34,79 @@
#include "config.h"
#define LOCKRET(func) func
#ifdef HAVE_PTHREAD
#include "pthread.h"
static pthread_mutex_t arc_lock = PTHREAD_MUTEX_INITIALIZER;
void _ARC4_LOCK(void)
{
pthread_mutex_lock(&arc_lock);
}
void _ARC4_UNLOCK(void)
{
pthread_mutex_unlock(&arc_lock);
}
#elif defined(GETDNS_ON_WINDOWS)
/*
* There is no explicit arc4random_init call, and thus
* the critical section must be allocated on the first call to
* ARC4_LOCK(). The interlocked test is used to verify that
* the critical section will be allocated only once.
*
* The work around is for the main program to call arc4random()
* at the beginning of execution, before spinning new threads.
*
* There is also no explicit arc4random_close call, and thus
* the critical section is never deleted. It will remain allocated
* as long as the program runs.
*/
static CRITICAL_SECTION arc_critical_section;
static volatile long arc_critical_section_initialized = 0;
void _ARC4_LOCK(void)
{
long r = InterlockedCompareExchange(&arc_critical_section_initialized, 1, 0);
if (r != 2)
{
if (r == 0)
{
InitializeCriticalSection(&arc_critical_section);
arc_critical_section_initialized = 2;
}
else if (r == 1)
{
/*
* If the critical section is initialized, the first test
* will return the value 2.
*
* If several threads try to initialize the arc4random
* state "at the same time", the first one will find
* the "initialized" variable at 0, the other ones at 1.
*
* Since this is a fairly rare event, we resolve it with a
* simple active wait loop.
*/
while (arc_critical_section_initialized != 2)
{
Sleep(1);
}
}
}
EnterCriticalSection(&arc_critical_section);
}
void _ARC4_UNLOCK(void)
{
LeaveCriticalSection(&arc_critical_section);
}
#else
/* XXX - add non pthread specific lock routines here */
void _ARC4_LOCK(void)
{
}
@ -41,4 +114,4 @@ void _ARC4_LOCK(void)
void _ARC4_UNLOCK(void)
{
}
#endif

View File

@ -38,6 +38,9 @@
#ifndef GETDNS_ON_WINDOWS
#include <sys/mman.h>
#endif
#if defined(GETDNS_ON_WINDOWS) && !defined(MAP_INHERIT_ZERO)
#define explicit_bzero(rnd, rnd_size) memset(rnd, 0, rnd_size)
#endif
#define KEYSTREAM_ONLY
#include "chacha_private.h"
@ -114,6 +117,9 @@ _rs_stir(void)
#ifdef SIGKILL
raise(SIGKILL);
#else
#ifdef GETDNS_ON_WINDOWS
DebugBreak();
#endif
exit(9); /* windows */
#endif
}
@ -125,6 +131,9 @@ _rs_stir(void)
explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */
/* invalidate rs_buf */
#ifdef GETDNS_ON_WINDOWS
_Analysis_assume_(rs != NULL);
#endif
rs->rs_have = 0;
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
@ -136,7 +145,15 @@ _rs_stir_if_needed(size_t len)
{
#ifndef MAP_INHERIT_ZERO
static pid_t _rs_pid = 0;
#ifdef GETDNS_ON_WINDOWS
/*
* TODO: if compiling for the Windows Runtime, use GetCurrentProcessId(),
* but this requires linking with kernel32.lib
*/
pid_t pid = _getpid();
#else
pid_t pid = getpid();
#endif
/* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */
if (_rs_pid == 0 || _rs_pid != pid) {
@ -147,6 +164,9 @@ _rs_stir_if_needed(size_t len)
#endif
if (!rs || rs->rs_count <= len)
_rs_stir();
#ifdef GETDNS_ON_WINDOWS
_Analysis_assume_(rs != NULL);
#endif
if (rs->rs_count <= len)
rs->rs_count = 0;
else

View File

@ -39,7 +39,7 @@ arc4random_uniform(uint32_t upper_bound)
return 0;
/* 2**32 % x == (2**32 - x) % x */
min = -upper_bound % upper_bound;
min = ((uint32_t)(-(int32_t)upper_bound)) % upper_bound;
/*
* This could theoretically loop forever but each retry has

73
src/compat/gettimeofday.c Normal file
View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2016 Christian Huitema <huitema@huitema.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Numerous places in the code make reference to the Unix/Linux
* "gettimeofday()" function, which is not available in the standard
* windows libraries. This code provides a compatible implementation.
*/
#include "config.h"
#ifdef GETDNS_ON_WINDOWS
int gettimeofday(struct timeval* tv, struct timezone* tz)
{
FILETIME ft;
uint64_t now = 0;
/*
* The GetSystemTimeAsFileTime API returns the number
* of 100-nanosecond intervals since January 1, 1601 (UTC),
* in FILETIME format.
*/
GetSystemTimeAsFileTime(&ft);
/*
* Convert to plain 64 bit format, without making
* assumptions about the FILETIME structure alignment.
*/
now |= ft.dwHighDateTime;
now <<= 32;
now |= ft.dwLowDateTime;
/*
* Convert units from 100ns to 1us
*/
now /= 10;
/*
* Account for microseconds elapsed between 1601 and 1970.
*/
now -= 11644473600000000ULL;
if (tv != NULL)
{
uint64_t sec = now / 1000000;
uint64_t usec = now % 1000000;
tv->tv_sec = (long)sec;
tv->tv_usec = (long)usec;
}
if (tz != NULL)
{
/*
* TODO: implement a timezone retrieval function.
* Not urgent, since the GetDNS code always set this parameter to NULL.
*/
return -1;
}
return 0;
}
#endif /* GETDNS_ON_WINDOWS */

View File

@ -9,90 +9,101 @@
static struct const_info consts_info[] = {
{ -1, NULL, "/* <unknown getdns value> */" },
{ 0, "GETDNS_RETURN_GOOD", GETDNS_RETURN_GOOD_TEXT },
{ 1, "GETDNS_RETURN_GENERIC_ERROR", GETDNS_RETURN_GENERIC_ERROR_TEXT },
{ 300, "GETDNS_RETURN_BAD_DOMAIN_NAME", GETDNS_RETURN_BAD_DOMAIN_NAME_TEXT },
{ 301, "GETDNS_RETURN_BAD_CONTEXT", GETDNS_RETURN_BAD_CONTEXT_TEXT },
{ 302, "GETDNS_RETURN_CONTEXT_UPDATE_FAIL", GETDNS_RETURN_CONTEXT_UPDATE_FAIL_TEXT },
{ 303, "GETDNS_RETURN_UNKNOWN_TRANSACTION", GETDNS_RETURN_UNKNOWN_TRANSACTION_TEXT },
{ 304, "GETDNS_RETURN_NO_SUCH_LIST_ITEM", GETDNS_RETURN_NO_SUCH_LIST_ITEM_TEXT },
{ 305, "GETDNS_RETURN_NO_SUCH_DICT_NAME", GETDNS_RETURN_NO_SUCH_DICT_NAME_TEXT },
{ 306, "GETDNS_RETURN_WRONG_TYPE_REQUESTED", GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT },
{ 307, "GETDNS_RETURN_NO_SUCH_EXTENSION", GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT },
{ 308, "GETDNS_RETURN_EXTENSION_MISFORMAT", GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT },
{ 309, "GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED", GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT },
{ 310, "GETDNS_RETURN_MEMORY_ERROR", GETDNS_RETURN_MEMORY_ERROR_TEXT },
{ 311, "GETDNS_RETURN_INVALID_PARAMETER", GETDNS_RETURN_INVALID_PARAMETER_TEXT },
{ 312, "GETDNS_RETURN_NOT_IMPLEMENTED", GETDNS_RETURN_NOT_IMPLEMENTED_TEXT },
{ 399, "GETDNS_RETURN_NEED_MORE_SPACE", GETDNS_RETURN_NEED_MORE_SPACE_TEXT },
{ 400, "GETDNS_DNSSEC_SECURE", GETDNS_DNSSEC_SECURE_TEXT },
{ 401, "GETDNS_DNSSEC_BOGUS", GETDNS_DNSSEC_BOGUS_TEXT },
{ 402, "GETDNS_DNSSEC_INDETERMINATE", GETDNS_DNSSEC_INDETERMINATE_TEXT },
{ 403, "GETDNS_DNSSEC_INSECURE", GETDNS_DNSSEC_INSECURE_TEXT },
{ 404, "GETDNS_DNSSEC_NOT_PERFORMED", GETDNS_DNSSEC_NOT_PERFORMED_TEXT },
{ 500, "GETDNS_NAMESPACE_DNS", GETDNS_NAMESPACE_DNS_TEXT },
{ 501, "GETDNS_NAMESPACE_LOCALNAMES", GETDNS_NAMESPACE_LOCALNAMES_TEXT },
{ 502, "GETDNS_NAMESPACE_NETBIOS", GETDNS_NAMESPACE_NETBIOS_TEXT },
{ 503, "GETDNS_NAMESPACE_MDNS", GETDNS_NAMESPACE_MDNS_TEXT },
{ 504, "GETDNS_NAMESPACE_NIS", GETDNS_NAMESPACE_NIS_TEXT },
{ 520, "GETDNS_RESOLUTION_STUB", GETDNS_RESOLUTION_STUB_TEXT },
{ 521, "GETDNS_RESOLUTION_RECURSING", GETDNS_RESOLUTION_RECURSING_TEXT },
{ 530, "GETDNS_REDIRECTS_FOLLOW", GETDNS_REDIRECTS_FOLLOW_TEXT },
{ 531, "GETDNS_REDIRECTS_DO_NOT_FOLLOW", GETDNS_REDIRECTS_DO_NOT_FOLLOW_TEXT },
{ 540, "GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP", GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP_TEXT },
{ 541, "GETDNS_TRANSPORT_UDP_ONLY", GETDNS_TRANSPORT_UDP_ONLY_TEXT },
{ 542, "GETDNS_TRANSPORT_TCP_ONLY", GETDNS_TRANSPORT_TCP_ONLY_TEXT },
{ 543, "GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN_TEXT },
{ 544, "GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN_TEXT },
{ 545, "GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN_TEXT },
{ 550, "GETDNS_APPEND_NAME_ALWAYS", GETDNS_APPEND_NAME_ALWAYS_TEXT },
{ 551, "GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE", GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE_TEXT },
{ 552, "GETDNS_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE", GETDNS_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE_TEXT },
{ 553, "GETDNS_APPEND_NAME_NEVER", GETDNS_APPEND_NAME_NEVER_TEXT },
{ 554, "GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST", GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST_TEXT },
{ 600, "GETDNS_CONTEXT_CODE_NAMESPACES", GETDNS_CONTEXT_CODE_NAMESPACES_TEXT },
{ 601, "GETDNS_CONTEXT_CODE_RESOLUTION_TYPE", GETDNS_CONTEXT_CODE_RESOLUTION_TYPE_TEXT },
{ 602, "GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS", GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS_TEXT },
{ 603, "GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS", GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS_TEXT },
{ 604, "GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS", GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS_TEXT },
{ 605, "GETDNS_CONTEXT_CODE_DNS_TRANSPORT", GETDNS_CONTEXT_CODE_DNS_TRANSPORT_TEXT },
{ 606, "GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES", GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES_TEXT },
{ 607, "GETDNS_CONTEXT_CODE_APPEND_NAME", GETDNS_CONTEXT_CODE_APPEND_NAME_TEXT },
{ 608, "GETDNS_CONTEXT_CODE_SUFFIX", GETDNS_CONTEXT_CODE_SUFFIX_TEXT },
{ 609, "GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS", GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS_TEXT },
{ 610, "GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE", GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE_TEXT },
{ 611, "GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE", GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE_TEXT },
{ 612, "GETDNS_CONTEXT_CODE_EDNS_VERSION", GETDNS_CONTEXT_CODE_EDNS_VERSION_TEXT },
{ 613, "GETDNS_CONTEXT_CODE_EDNS_DO_BIT", GETDNS_CONTEXT_CODE_EDNS_DO_BIT_TEXT },
{ 614, "GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW", GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW_TEXT },
{ 615, "GETDNS_CONTEXT_CODE_MEMORY_FUNCTIONS", GETDNS_CONTEXT_CODE_MEMORY_FUNCTIONS_TEXT },
{ 616, "GETDNS_CONTEXT_CODE_TIMEOUT", GETDNS_CONTEXT_CODE_TIMEOUT_TEXT },
{ 617, "GETDNS_CONTEXT_CODE_IDLE_TIMEOUT", GETDNS_CONTEXT_CODE_IDLE_TIMEOUT_TEXT },
{ 618, "GETDNS_CONTEXT_CODE_TLS_AUTHENTICATION", GETDNS_CONTEXT_CODE_TLS_AUTHENTICATION_TEXT },
{ 619, "GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE", GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE_TEXT },
{ 620, "GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE", GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE_TEXT },
{ 621, "GETDNS_CONTEXT_CODE_PUBKEY_PINSET", GETDNS_CONTEXT_CODE_PUBKEY_PINSET_TEXT },
{ 700, "GETDNS_CALLBACK_COMPLETE", GETDNS_CALLBACK_COMPLETE_TEXT },
{ 701, "GETDNS_CALLBACK_CANCEL", GETDNS_CALLBACK_CANCEL_TEXT },
{ 702, "GETDNS_CALLBACK_TIMEOUT", GETDNS_CALLBACK_TIMEOUT_TEXT },
{ 703, "GETDNS_CALLBACK_ERROR", GETDNS_CALLBACK_ERROR_TEXT },
{ 800, "GETDNS_NAMETYPE_DNS", GETDNS_NAMETYPE_DNS_TEXT },
{ 801, "GETDNS_NAMETYPE_WINS", GETDNS_NAMETYPE_WINS_TEXT },
{ 900, "GETDNS_RESPSTATUS_GOOD", GETDNS_RESPSTATUS_GOOD_TEXT },
{ 901, "GETDNS_RESPSTATUS_NO_NAME", GETDNS_RESPSTATUS_NO_NAME_TEXT },
{ 902, "GETDNS_RESPSTATUS_ALL_TIMEOUT", GETDNS_RESPSTATUS_ALL_TIMEOUT_TEXT },
{ 903, "GETDNS_RESPSTATUS_NO_SECURE_ANSWERS", GETDNS_RESPSTATUS_NO_SECURE_ANSWERS_TEXT },
{ 904, "GETDNS_RESPSTATUS_ALL_BOGUS_ANSWERS", GETDNS_RESPSTATUS_ALL_BOGUS_ANSWERS_TEXT },
{ 1000, "GETDNS_EXTENSION_TRUE", GETDNS_EXTENSION_TRUE_TEXT },
{ 1001, "GETDNS_EXTENSION_FALSE", GETDNS_EXTENSION_FALSE_TEXT },
{ 1100, "GETDNS_BAD_DNS_CNAME_IN_TARGET", GETDNS_BAD_DNS_CNAME_IN_TARGET_TEXT },
{ 1101, "GETDNS_BAD_DNS_ALL_NUMERIC_LABEL", GETDNS_BAD_DNS_ALL_NUMERIC_LABEL_TEXT },
{ 1102, "GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE", GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE_TEXT },
{ 1200, "GETDNS_TRANSPORT_UDP", GETDNS_TRANSPORT_UDP_TEXT },
{ 1201, "GETDNS_TRANSPORT_TCP", GETDNS_TRANSPORT_TCP_TEXT },
{ 1202, "GETDNS_TRANSPORT_TLS", GETDNS_TRANSPORT_TLS_TEXT },
{ 1300, "GETDNS_AUTHENTICATION_NONE", GETDNS_AUTHENTICATION_NONE_TEXT },
{ 1301, "GETDNS_AUTHENTICATION_REQUIRED", GETDNS_AUTHENTICATION_REQUIRED_TEXT },
{ 0, "GETDNS_RETURN_GOOD", GETDNS_RETURN_GOOD_TEXT },
{ 1, "GETDNS_RETURN_GENERIC_ERROR", GETDNS_RETURN_GENERIC_ERROR_TEXT },
{ 2, "GETDNS_LOG_CRIT", GETDNS_LOG_CRIT_TEXT },
{ 3, "GETDNS_LOG_ERR", GETDNS_LOG_ERR_TEXT },
{ 4, "GETDNS_LOG_WARNING", GETDNS_LOG_WARNING_TEXT },
{ 5, "GETDNS_LOG_NOTICE", GETDNS_LOG_NOTICE_TEXT },
{ 6, "GETDNS_LOG_INFO", GETDNS_LOG_INFO_TEXT },
{ 7, "GETDNS_LOG_DEBUG", GETDNS_LOG_DEBUG_TEXT },
{ 300, "GETDNS_RETURN_BAD_DOMAIN_NAME", GETDNS_RETURN_BAD_DOMAIN_NAME_TEXT },
{ 301, "GETDNS_RETURN_BAD_CONTEXT", GETDNS_RETURN_BAD_CONTEXT_TEXT },
{ 302, "GETDNS_RETURN_CONTEXT_UPDATE_FAIL", GETDNS_RETURN_CONTEXT_UPDATE_FAIL_TEXT },
{ 303, "GETDNS_RETURN_UNKNOWN_TRANSACTION", GETDNS_RETURN_UNKNOWN_TRANSACTION_TEXT },
{ 304, "GETDNS_RETURN_NO_SUCH_LIST_ITEM", GETDNS_RETURN_NO_SUCH_LIST_ITEM_TEXT },
{ 305, "GETDNS_RETURN_NO_SUCH_DICT_NAME", GETDNS_RETURN_NO_SUCH_DICT_NAME_TEXT },
{ 306, "GETDNS_RETURN_WRONG_TYPE_REQUESTED", GETDNS_RETURN_WRONG_TYPE_REQUESTED_TEXT },
{ 307, "GETDNS_RETURN_NO_SUCH_EXTENSION", GETDNS_RETURN_NO_SUCH_EXTENSION_TEXT },
{ 308, "GETDNS_RETURN_EXTENSION_MISFORMAT", GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT },
{ 309, "GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED", GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED_TEXT },
{ 310, "GETDNS_RETURN_MEMORY_ERROR", GETDNS_RETURN_MEMORY_ERROR_TEXT },
{ 311, "GETDNS_RETURN_INVALID_PARAMETER", GETDNS_RETURN_INVALID_PARAMETER_TEXT },
{ 312, "GETDNS_RETURN_NOT_IMPLEMENTED", GETDNS_RETURN_NOT_IMPLEMENTED_TEXT },
{ 398, "GETDNS_RETURN_NO_UPSTREAM_AVAILABLE", GETDNS_RETURN_NO_UPSTREAM_AVAILABLE_TEXT },
{ 399, "GETDNS_RETURN_NEED_MORE_SPACE", GETDNS_RETURN_NEED_MORE_SPACE_TEXT },
{ 400, "GETDNS_DNSSEC_SECURE", GETDNS_DNSSEC_SECURE_TEXT },
{ 401, "GETDNS_DNSSEC_BOGUS", GETDNS_DNSSEC_BOGUS_TEXT },
{ 402, "GETDNS_DNSSEC_INDETERMINATE", GETDNS_DNSSEC_INDETERMINATE_TEXT },
{ 403, "GETDNS_DNSSEC_INSECURE", GETDNS_DNSSEC_INSECURE_TEXT },
{ 404, "GETDNS_DNSSEC_NOT_PERFORMED", GETDNS_DNSSEC_NOT_PERFORMED_TEXT },
{ 500, "GETDNS_NAMESPACE_DNS", GETDNS_NAMESPACE_DNS_TEXT },
{ 501, "GETDNS_NAMESPACE_LOCALNAMES", GETDNS_NAMESPACE_LOCALNAMES_TEXT },
{ 502, "GETDNS_NAMESPACE_NETBIOS", GETDNS_NAMESPACE_NETBIOS_TEXT },
{ 503, "GETDNS_NAMESPACE_MDNS", GETDNS_NAMESPACE_MDNS_TEXT },
{ 504, "GETDNS_NAMESPACE_NIS", GETDNS_NAMESPACE_NIS_TEXT },
{ 520, "GETDNS_RESOLUTION_STUB", GETDNS_RESOLUTION_STUB_TEXT },
{ 521, "GETDNS_RESOLUTION_RECURSING", GETDNS_RESOLUTION_RECURSING_TEXT },
{ 530, "GETDNS_REDIRECTS_FOLLOW", GETDNS_REDIRECTS_FOLLOW_TEXT },
{ 531, "GETDNS_REDIRECTS_DO_NOT_FOLLOW", GETDNS_REDIRECTS_DO_NOT_FOLLOW_TEXT },
{ 540, "GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP", GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP_TEXT },
{ 541, "GETDNS_TRANSPORT_UDP_ONLY", GETDNS_TRANSPORT_UDP_ONLY_TEXT },
{ 542, "GETDNS_TRANSPORT_TCP_ONLY", GETDNS_TRANSPORT_TCP_ONLY_TEXT },
{ 543, "GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN_TEXT },
{ 544, "GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN_TEXT },
{ 545, "GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN", GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN_TEXT },
{ 550, "GETDNS_APPEND_NAME_ALWAYS", GETDNS_APPEND_NAME_ALWAYS_TEXT },
{ 551, "GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE", GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE_TEXT },
{ 552, "GETDNS_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE", GETDNS_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE_TEXT },
{ 553, "GETDNS_APPEND_NAME_NEVER", GETDNS_APPEND_NAME_NEVER_TEXT },
{ 554, "GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST", GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST_TEXT },
{ 600, "GETDNS_CONTEXT_CODE_NAMESPACES", GETDNS_CONTEXT_CODE_NAMESPACES_TEXT },
{ 601, "GETDNS_CONTEXT_CODE_RESOLUTION_TYPE", GETDNS_CONTEXT_CODE_RESOLUTION_TYPE_TEXT },
{ 602, "GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS", GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS_TEXT },
{ 603, "GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS", GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS_TEXT },
{ 604, "GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS", GETDNS_CONTEXT_CODE_DNS_ROOT_SERVERS_TEXT },
{ 605, "GETDNS_CONTEXT_CODE_DNS_TRANSPORT", GETDNS_CONTEXT_CODE_DNS_TRANSPORT_TEXT },
{ 606, "GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES", GETDNS_CONTEXT_CODE_LIMIT_OUTSTANDING_QUERIES_TEXT },
{ 607, "GETDNS_CONTEXT_CODE_APPEND_NAME", GETDNS_CONTEXT_CODE_APPEND_NAME_TEXT },
{ 608, "GETDNS_CONTEXT_CODE_SUFFIX", GETDNS_CONTEXT_CODE_SUFFIX_TEXT },
{ 609, "GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS", GETDNS_CONTEXT_CODE_DNSSEC_TRUST_ANCHORS_TEXT },
{ 610, "GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE", GETDNS_CONTEXT_CODE_EDNS_MAXIMUM_UDP_PAYLOAD_SIZE_TEXT },
{ 611, "GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE", GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE_TEXT },
{ 612, "GETDNS_CONTEXT_CODE_EDNS_VERSION", GETDNS_CONTEXT_CODE_EDNS_VERSION_TEXT },
{ 613, "GETDNS_CONTEXT_CODE_EDNS_DO_BIT", GETDNS_CONTEXT_CODE_EDNS_DO_BIT_TEXT },
{ 614, "GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW", GETDNS_CONTEXT_CODE_DNSSEC_ALLOWED_SKEW_TEXT },
{ 615, "GETDNS_CONTEXT_CODE_MEMORY_FUNCTIONS", GETDNS_CONTEXT_CODE_MEMORY_FUNCTIONS_TEXT },
{ 616, "GETDNS_CONTEXT_CODE_TIMEOUT", GETDNS_CONTEXT_CODE_TIMEOUT_TEXT },
{ 617, "GETDNS_CONTEXT_CODE_IDLE_TIMEOUT", GETDNS_CONTEXT_CODE_IDLE_TIMEOUT_TEXT },
{ 618, "GETDNS_CONTEXT_CODE_TLS_AUTHENTICATION", GETDNS_CONTEXT_CODE_TLS_AUTHENTICATION_TEXT },
{ 619, "GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE", GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE_TEXT },
{ 620, "GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE", GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE_TEXT },
{ 621, "GETDNS_CONTEXT_CODE_PUBKEY_PINSET", GETDNS_CONTEXT_CODE_PUBKEY_PINSET_TEXT },
{ 622, "GETDNS_CONTEXT_CODE_ROUND_ROBIN_UPSTREAMS", GETDNS_CONTEXT_CODE_ROUND_ROBIN_UPSTREAMS_TEXT },
{ 623, "GETDNS_CONTEXT_CODE_TLS_BACKOFF_TIME", GETDNS_CONTEXT_CODE_TLS_BACKOFF_TIME_TEXT },
{ 624, "GETDNS_CONTEXT_CODE_TLS_CONNECTION_RETRIES", GETDNS_CONTEXT_CODE_TLS_CONNECTION_RETRIES_TEXT },
{ 700, "GETDNS_CALLBACK_COMPLETE", GETDNS_CALLBACK_COMPLETE_TEXT },
{ 701, "GETDNS_CALLBACK_CANCEL", GETDNS_CALLBACK_CANCEL_TEXT },
{ 702, "GETDNS_CALLBACK_TIMEOUT", GETDNS_CALLBACK_TIMEOUT_TEXT },
{ 703, "GETDNS_CALLBACK_ERROR", GETDNS_CALLBACK_ERROR_TEXT },
{ 800, "GETDNS_NAMETYPE_DNS", GETDNS_NAMETYPE_DNS_TEXT },
{ 801, "GETDNS_NAMETYPE_WINS", GETDNS_NAMETYPE_WINS_TEXT },
{ 900, "GETDNS_RESPSTATUS_GOOD", GETDNS_RESPSTATUS_GOOD_TEXT },
{ 901, "GETDNS_RESPSTATUS_NO_NAME", GETDNS_RESPSTATUS_NO_NAME_TEXT },
{ 902, "GETDNS_RESPSTATUS_ALL_TIMEOUT", GETDNS_RESPSTATUS_ALL_TIMEOUT_TEXT },
{ 903, "GETDNS_RESPSTATUS_NO_SECURE_ANSWERS", GETDNS_RESPSTATUS_NO_SECURE_ANSWERS_TEXT },
{ 904, "GETDNS_RESPSTATUS_ALL_BOGUS_ANSWERS", GETDNS_RESPSTATUS_ALL_BOGUS_ANSWERS_TEXT },
{ 1000, "GETDNS_EXTENSION_TRUE", GETDNS_EXTENSION_TRUE_TEXT },
{ 1001, "GETDNS_EXTENSION_FALSE", GETDNS_EXTENSION_FALSE_TEXT },
{ 1100, "GETDNS_BAD_DNS_CNAME_IN_TARGET", GETDNS_BAD_DNS_CNAME_IN_TARGET_TEXT },
{ 1101, "GETDNS_BAD_DNS_ALL_NUMERIC_LABEL", GETDNS_BAD_DNS_ALL_NUMERIC_LABEL_TEXT },
{ 1102, "GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE", GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE_TEXT },
{ 1200, "GETDNS_TRANSPORT_UDP", GETDNS_TRANSPORT_UDP_TEXT },
{ 1201, "GETDNS_TRANSPORT_TCP", GETDNS_TRANSPORT_TCP_TEXT },
{ 1202, "GETDNS_TRANSPORT_TLS", GETDNS_TRANSPORT_TLS_TEXT },
{ 1300, "GETDNS_AUTHENTICATION_NONE", GETDNS_AUTHENTICATION_NONE_TEXT },
{ 1301, "GETDNS_AUTHENTICATION_REQUIRED", GETDNS_AUTHENTICATION_REQUIRED_TEXT },
{ 4096, "GETDNS_LOG_UPSTREAM_STATS", GETDNS_LOG_UPSTREAM_STATS_TEXT },
};
static int const_info_cmp(const void *a, const void *b)
@ -156,9 +167,12 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_CONTEXT_CODE_NAMESPACES", 600 },
{ "GETDNS_CONTEXT_CODE_PUBKEY_PINSET", 621 },
{ "GETDNS_CONTEXT_CODE_RESOLUTION_TYPE", 601 },
{ "GETDNS_CONTEXT_CODE_ROUND_ROBIN_UPSTREAMS", 622 },
{ "GETDNS_CONTEXT_CODE_SUFFIX", 608 },
{ "GETDNS_CONTEXT_CODE_TIMEOUT", 616 },
{ "GETDNS_CONTEXT_CODE_TLS_AUTHENTICATION", 618 },
{ "GETDNS_CONTEXT_CODE_TLS_BACKOFF_TIME", 623 },
{ "GETDNS_CONTEXT_CODE_TLS_CONNECTION_RETRIES", 624 },
{ "GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE", 620 },
{ "GETDNS_CONTEXT_CODE_UPSTREAM_RECURSIVE_SERVERS", 603 },
{ "GETDNS_DNSSEC_BOGUS", 401 },
@ -168,6 +182,15 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_DNSSEC_SECURE", 400 },
{ "GETDNS_EXTENSION_FALSE", 1001 },
{ "GETDNS_EXTENSION_TRUE", 1000 },
{ "GETDNS_LOG_ALERT", 1 },
{ "GETDNS_LOG_CRIT", 2 },
{ "GETDNS_LOG_DEBUG", 7 },
{ "GETDNS_LOG_EMERG", 0 },
{ "GETDNS_LOG_ERR", 3 },
{ "GETDNS_LOG_INFO", 6 },
{ "GETDNS_LOG_NOTICE", 5 },
{ "GETDNS_LOG_UPSTREAM_STATS", 4096 },
{ "GETDNS_LOG_WARNING", 4 },
{ "GETDNS_NAMESPACE_DNS", 500 },
{ "GETDNS_NAMESPACE_LOCALNAMES", 501 },
{ "GETDNS_NAMESPACE_MDNS", 503 },
@ -188,6 +211,7 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_RCODE_BADTIME", 18 },
{ "GETDNS_RCODE_BADTRUNC", 22 },
{ "GETDNS_RCODE_BADVERS", 16 },
{ "GETDNS_RCODE_COOKIE", 23 },
{ "GETDNS_RCODE_FORMERR", 1 },
{ "GETDNS_RCODE_NOERROR", 0 },
{ "GETDNS_RCODE_NOTAUTH", 9 },
@ -222,6 +246,7 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_RETURN_NO_SUCH_DICT_NAME", 305 },
{ "GETDNS_RETURN_NO_SUCH_EXTENSION", 307 },
{ "GETDNS_RETURN_NO_SUCH_LIST_ITEM", 304 },
{ "GETDNS_RETURN_NO_UPSTREAM_AVAILABLE", 398 },
{ "GETDNS_RETURN_UNKNOWN_TRANSACTION", 303 },
{ "GETDNS_RETURN_WRONG_TYPE_REQUESTED", 306 },
{ "GETDNS_RRCLASS_ANY", 255 },
@ -235,6 +260,7 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_RRTYPE_ANY", 255 },
{ "GETDNS_RRTYPE_APL", 42 },
{ "GETDNS_RRTYPE_ATMA", 34 },
{ "GETDNS_RRTYPE_AVC", 258 },
{ "GETDNS_RRTYPE_AXFR", 252 },
{ "GETDNS_RRTYPE_CAA", 257 },
{ "GETDNS_RRTYPE_CDNSKEY", 60 },
@ -274,6 +300,7 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_RRTYPE_NINFO", 56 },
{ "GETDNS_RRTYPE_NS", 2 },
{ "GETDNS_RRTYPE_NSAP", 22 },
{ "GETDNS_RRTYPE_NSAP_PTR", 23 },
{ "GETDNS_RRTYPE_NSEC", 47 },
{ "GETDNS_RRTYPE_NULL", 10 },
{ "GETDNS_RRTYPE_NXT", 30 },
@ -287,6 +314,7 @@ static struct const_name_info consts_name_info[] = {
{ "GETDNS_RRTYPE_RT", 21 },
{ "GETDNS_RRTYPE_SIG", 24 },
{ "GETDNS_RRTYPE_SINK", 40 },
{ "GETDNS_RRTYPE_SMIMEA", 53 },
{ "GETDNS_RRTYPE_SOA", 6 },
{ "GETDNS_RRTYPE_SPF", 99 },
{ "GETDNS_RRTYPE_SRV", 33 },

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,9 @@
#include "util/rbtree.h"
#include "ub_loop.h"
#include "server.h"
#ifdef HAVE_MDNS_SUPPORT
#include "util/lruhash.h"
#endif
struct getdns_dns_req;
struct ub_ctx;
@ -124,10 +127,36 @@ typedef struct getdns_upstream {
socklen_t addr_len;
struct sockaddr_storage addr;
char addr_str[INET6_ADDRSTRLEN];
/* How is this upstream doing over UDP? */
int to_retry;
int back_off;
/**
* How is this upstream doing over UDP?
*
* to_retry = 1, back_off = 1, in context.c:upstream_init()
*
* When querying over UDP, first a upstream is selected which to_retry
* value > 0 in stub.c:upstream_select().
*
* Every time a udp request times out, to_retry is decreased, and if
* it reaches 0, it is set to minus back_off in
* stub.c:stub_next_upstream().
*
* to_retry will become > 0 again. because each time an upstream is
* selected for a UDP query in stub.c:upstream_select(), all to_retry
* counters <= 0 are incremented.
*
* On continuous failure, the stubs are less likely to be reselected,
* because each time to_retry is set to minus back_off, in
* stub.c:stub_next_upstream(), the back_off value is doubled.
*
* Finally, if all upstreams are failing, the upstreams with the
* smallest back_off value will be selected, and the back_off value
* decremented by one.
*/
int to_retry; /* (initialized to 1) */
int back_off; /* (initialized to 1) */
size_t udp_responses;
size_t udp_timeouts;
/* For stateful upstreams, need to share the connection and track the
activity on the connection */
@ -140,14 +169,18 @@ typedef struct getdns_upstream {
size_t conn_completed;
size_t conn_shutdowns;
size_t conn_setup_failed;
time_t conn_retry_time;
size_t conn_backoffs;
size_t total_responses;
size_t total_timeouts;
getdns_auth_state_t past_tls_auth_state;
getdns_auth_state_t best_tls_auth_state;
getdns_auth_state_t last_tls_auth_state;
/* These are per connection. */
getdns_conn_state_t conn_state;
size_t queries_sent;
size_t responses_received;
size_t responses_timeouts;
size_t keepalive_shutdown;
uint64_t keepalive_timeout;
/* Management of outstanding requests on stateful transports */
@ -203,11 +236,22 @@ typedef struct getdns_upstream {
} getdns_upstream;
typedef struct getdns_log_config {
getdns_logfunc_type func;
void *userarg;
uint64_t system;
getdns_loglevel_type level;
} getdns_log_config;
typedef struct getdns_upstreams {
struct mem_funcs mf;
size_t referenced;
size_t count;
size_t current_udp;
size_t current_stateful;
uint16_t tls_backoff_time;
uint16_t tls_connection_retries;
getdns_log_config log;
getdns_upstream upstreams[];
} getdns_upstreams;
@ -215,7 +259,7 @@ struct getdns_context {
/* Context values */
getdns_resolution_t resolution_type;
getdns_namespace_t *namespaces;
int namespace_count;
size_t namespace_count;
uint64_t timeout;
uint64_t idle_timeout;
getdns_redirects_t follow_redirects;
@ -239,6 +283,9 @@ struct getdns_context {
uint32_t dnssec_allowed_skew;
getdns_tls_authentication_t tls_auth; /* What user requested for TLS*/
getdns_tls_authentication_t tls_auth_min; /* Derived minimum auth allowed*/
uint8_t round_robin_upstreams;
uint16_t tls_backoff_time;
uint16_t tls_connection_retries;
getdns_transport_list_t *dns_transports;
size_t dns_transport_count;
@ -255,6 +302,8 @@ struct getdns_context {
getdns_update_callback2 update_callback2;
void *update_userarg;
getdns_log_config log;
int processing;
int destroying;
@ -282,6 +331,14 @@ struct getdns_context {
*/
_getdns_rbtree_t outbound_requests;
/* network requests
*/
size_t netreqs_in_flight;
_getdns_rbtree_t pending_netreqs;
getdns_network_req *first_pending_netreq;
getdns_eventloop_event pending_timeout_event;
struct listen_set *server;
/* Event loop extension. */
@ -300,19 +357,19 @@ struct getdns_context {
/* request extension defaults */
getdns_dict *header;
getdns_dict *add_opt_parameters;
int add_warning_for_bad_dns : 1;
int dnssec_return_all_statuses : 1;
int dnssec_return_full_validation_chain : 1;
int dnssec_return_only_secure : 1;
int dnssec_return_status : 1;
int dnssec_return_validation_chain : 1;
unsigned add_warning_for_bad_dns : 1;
unsigned dnssec_return_all_statuses : 1;
unsigned dnssec_return_full_validation_chain : 1;
unsigned dnssec_return_only_secure : 1;
unsigned dnssec_return_status : 1;
unsigned dnssec_return_validation_chain : 1;
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
int dnssec_roadblock_avoidance : 1;
unsigned dnssec_roadblock_avoidance : 1;
#endif
int edns_cookies : 1;
int return_api_information : 1; /* Not used */
int return_both_v4_and_v6 : 1;
int return_call_reporting : 1;
unsigned edns_cookies : 1;
unsigned return_api_information : 1; /* Not used */
unsigned return_both_v4_and_v6 : 1;
unsigned return_call_reporting : 1;
uint16_t specify_class;
/*
@ -327,8 +384,32 @@ struct getdns_context {
/* We need to run WSAStartup() to be able to use getaddrinfo() */
WSADATA wsaData;
#endif
/* MDNS */
#ifdef HAVE_MDNS_SUPPORT
/*
* If supporting MDNS, context may be instantiated either in basic mode
* or in full mode. If working in extended mode, two multicast sockets are
* left open, for IPv4 and IPv6. Data can be received on either socket.
* The context also keeps a list of open queries, characterized by a
* name and an RR type, and a list of received answers, characterized
* by name, RR type and data value.
*/
int mdns_extended_support; /* 0 = no support, 1 = supported, 2 = initialization needed */
int mdns_connection_nb; /* typically 0 or 2 for IPv4 and IPv6 */
struct mdns_network_connection * mdns_connection;
struct lruhash * mdns_cache;
#endif /* HAVE_MDNS_SUPPORT */
}; /* getdns_context */
void _getdns_upstream_log(getdns_upstream *upstream, uint64_t system,
getdns_loglevel_type level, const char *fmt, ...);
void _getdns_context_log(getdns_context *context, uint64_t system,
getdns_loglevel_type level, const char *fmt, ...);
/** internal functions **/
/**
* Sets up the unbound contexts with stub or recursive behavior
@ -340,19 +421,33 @@ struct getdns_context {
getdns_return_t _getdns_context_prepare_for_resolution(struct getdns_context *context,
int usenamespaces);
/* track an outbound request */
getdns_return_t _getdns_context_track_outbound_request(struct getdns_dns_req
*req);
/* clear the outbound request from being tracked - does not cancel it */
getdns_return_t _getdns_context_clear_outbound_request(struct getdns_dns_req
*req);
/* Register a getdns_dns_req with context.
* - Without pluggable unbound event API,
* ub_fd() is scheduled when this was the first request.
*/
void _getdns_context_track_outbound_request(getdns_dns_req *dnsreq);
getdns_return_t _getdns_context_request_timed_out(struct getdns_dns_req
*req);
/* Deregister getdns_dns_req from the context.
* - Without pluggable unbound event API,
* ub_fd() is scheduled when this was the first request.
* - Potential timeout events will be cleared.
* - All associated getdns_dns_reqs (to get the validation chain)
* will be canceled.
*/
void _getdns_context_clear_outbound_request(getdns_dns_req *dnsreq);
/* cancel callback internal - flag to indicate if req should be freed and callback fired */
getdns_return_t _getdns_context_cancel_request(struct getdns_context *context,
getdns_transaction_t transaction_id, int fire_callback);
/* Cancels and frees a getdns_dns_req (without calling user callbacks)
* - Deregisters getdns_dns_req with _getdns_context_clear_outbound_request()
* - Cancels associated getdns_network_reqs
* (by calling ub_cancel() or _getdns_cancel_stub_request())
* - Frees the getdns_dns_req
*/
void _getdns_context_cancel_request(getdns_dns_req *dnsreq);
/* Calls user callback (with GETDNS_CALLBACK_TIMEOUT + response dict), then
* cancels and frees the getdns_dns_req with _getdns_context_cancel_request()
*/
void _getdns_context_request_timed_out(getdns_dns_req *dnsreq);
char *_getdns_strdup(const struct mem_funcs *mfs, const char *str);

View File

@ -57,9 +57,6 @@
#include "convert.h"
#include "debug.h"
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
getdns_return_t
getdns_convert_dns_name_to_fqdn(
const getdns_bindata *dns_name_wire_fmt, char **fqdn_as_string)
@ -154,6 +151,7 @@ getdns_convert_ulabel_to_alabel(const char *ulabel)
free(prepped2);
return buf;
#else
(void)ulabel;
return NULL;
#endif
}
@ -183,6 +181,7 @@ getdns_convert_alabel_to_ulabel(const char *alabel)
}
return buf;
#else
(void)alabel;
return NULL;
#endif
}
@ -289,7 +288,7 @@ getdns_rr_dict2wire_scan(
return GETDNS_RETURN_INVALID_PARAMETER;
gldns_buffer_init_frm_data(&gbuf, *wire, *wire_sz);
gldns_buffer_init_vfixed_frm_data(&gbuf, *wire, *wire_sz);
if ((r = _getdns_rr_dict2wire(rr_dict, &gbuf)))
return r;
@ -439,7 +438,7 @@ getdns_rr_dict2str_scan(
if (!rr_dict || !str || !*str || !str_len)
return GETDNS_RETURN_INVALID_PARAMETER;
gldns_buffer_init_frm_data(&gbuf, buf, sizeof(buf_spc));
gldns_buffer_init_vfixed_frm_data(&gbuf, buf, sizeof(buf_spc));
r = _getdns_rr_dict2wire(rr_dict, &gbuf);
if (gldns_buffer_position(&gbuf) > sizeof(buf_spc)) {
if (!(buf = GETDNS_XMALLOC(
@ -830,7 +829,6 @@ _getdns_reply_dict2wire(
}
}
remove_dnssec = !getdns_dict_get_int(reply, "/header/do", &n) && n == 0;
DEBUG_SERVER("remove_dnssec: %d\n", remove_dnssec);
if (!getdns_dict_get_list(reply, "answer", &section)) {
for ( n = 0, i = 0
@ -953,7 +951,7 @@ getdns_msg_dict2wire_scan(
if (!msg_dict || !wire || !wire_sz || (!*wire && *wire_sz))
return GETDNS_RETURN_INVALID_PARAMETER;
gldns_buffer_init_frm_data(&gbuf, *wire, *wire_sz);
gldns_buffer_init_vfixed_frm_data(&gbuf, *wire, *wire_sz);
if ((r = _getdns_msg_dict2wire_buf(msg_dict, &gbuf)))
return r;
@ -1029,7 +1027,7 @@ getdns_msg_dict2str_scan(
if (!msg_dict || !str || !*str || !str_len)
return GETDNS_RETURN_INVALID_PARAMETER;
gldns_buffer_init_frm_data(&gbuf, buf, sizeof(buf_spc));
gldns_buffer_init_vfixed_frm_data(&gbuf, buf, sizeof(buf_spc));
r = _getdns_msg_dict2wire_buf(msg_dict, &gbuf);
if (gldns_buffer_position(&gbuf) > sizeof(buf_spc)) {
if (!(buf = GETDNS_XMALLOC(
@ -1066,7 +1064,7 @@ getdns_msg_dict2str_scan(
}
static getdns_dict *
_getdns_ipaddr_dict_mf(struct mem_funcs *mf, char *ipstr)
_getdns_ipaddr_dict_mf(struct mem_funcs *mf, const char *ipstr)
{
getdns_dict *r = _getdns_dict_create_with_mf(mf);
char *s = strchr(ipstr, '%'), *scope_id_str = "";
@ -1187,7 +1185,7 @@ static int _jsmn_get_ipdict(struct mem_funcs *mf, const char *js, jsmntok_t *t,
char value_str[3072];
int size = t->end - t->start;
if (size <= 0 || size >= sizeof(value_str))
if (size <= 0 || size >= (int)sizeof(value_str))
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1197,21 +1195,81 @@ static int _jsmn_get_ipdict(struct mem_funcs *mf, const char *js, jsmntok_t *t,
return *value != NULL;
}
static int _jsmn_get_base64_data(struct mem_funcs *mf, const char *js, jsmntok_t *t,
getdns_bindata **value)
{
int e, i;
int size = t->end - t->start;
char value_str_buf[1025];
char *value_str;
size_t target_buf_size;
assert(size >= 4);
if (size % 4 != 0)
return 0;
e = t->end;
if (js[e - 1] == '=') e -= 1;
if (js[e - 1] == '=') e -= 1;
for (i = t->start; i < e; i++)
if (!((js[i] >= '0' && js[i] <= '9')
||(js[i] >= 'a' && js[i] <= 'z')
||(js[i] >= 'A' && js[i] <= 'Z')
|| js[i] == '+' || js[i] == '/'))
return 0;
target_buf_size = gldns_b64_pton_calculate_size(size);
if (!(*value = GETDNS_MALLOC(*mf, getdns_bindata)))
return 0;
else if (!((*value)->data = GETDNS_XMALLOC(
*mf, uint8_t, target_buf_size))) {
GETDNS_FREE(*mf, *value);
return 0;
}
if ((size_t)size >= sizeof(value_str_buf))
value_str = GETDNS_XMALLOC(*mf, char, size + 1);
else value_str = value_str_buf;
if (value_str) {
(void) memcpy(value_str, js + t->start, size);
value_str[size] = '\0';
e = gldns_b64_pton(value_str, (*value)->data, target_buf_size);
if (value_str != value_str_buf)
GETDNS_FREE(*mf, value_str);
if (e > 0) {
(*value)->size = e;
return 1;
}
}
GETDNS_FREE(*mf, (*value)->data);
GETDNS_FREE(*mf, *value);
return 0;
}
static int _jsmn_get_data(struct mem_funcs *mf, const char *js, jsmntok_t *t,
getdns_bindata **value)
{
size_t i, j;
int i;
size_t j;
uint8_t h, l;
if ((t->end - t->start) < 4 || (t->end - t->start) % 2 == 1 ||
js[t->start] != '0' || js[t->start + 1] != 'x')
if ((t->end - t->start) < 4 || (t->end - t->start) % 2 == 1)
return 0;
if (js[t->start] != '0' || js[t->start + 1] != 'x')
return _jsmn_get_base64_data(mf, js, t, value);
for (i = t->start + 2; i < t->end; i++)
if (!((js[i] >= '0' && js[i] <= '9')
||(js[i] >= 'a' && js[i] <= 'f')
||(js[i] >= 'A' && js[i] <= 'F')))
return 0;
return _jsmn_get_base64_data(mf, js, t, value);
if (!(*value = GETDNS_MALLOC(*mf, getdns_bindata)))
return 0;
@ -1241,8 +1299,9 @@ static int _jsmn_get_dname(struct mem_funcs *mf, const char *js, jsmntok_t *t,
{
char value_str[1025];
int size = t->end - t->start;
(void)mf; /* TODO: Fix to use mf */
if (size <= 0 || size >= sizeof(value_str) || js[t->end - 1] != '.')
if (size <= 0 || size >= (int)sizeof(value_str) || js[t->end - 1] != '.')
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1258,7 +1317,7 @@ static int _jsmn_get_ipv4(struct mem_funcs *mf, const char *js, jsmntok_t *t,
int size = t->end - t->start;
uint8_t buf[4];
if (size <= 0 || size >= sizeof(value_str))
if (size <= 0 || size >= (int)sizeof(value_str))
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1288,7 +1347,7 @@ static int _jsmn_get_ipv6(struct mem_funcs *mf, const char *js, jsmntok_t *t,
int size = t->end - t->start;
uint8_t buf[16];
if (size <= 0 || size >= sizeof(value_str))
if (size <= 0 || size >= (int)sizeof(value_str))
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1311,14 +1370,13 @@ static int _jsmn_get_ipv6(struct mem_funcs *mf, const char *js, jsmntok_t *t,
return 0;
}
static int _jsmn_get_int(struct mem_funcs *mf, const char *js, jsmntok_t *t,
uint32_t *value)
static int _jsmn_get_int(const char *js, jsmntok_t *t, uint32_t *value)
{
char value_str[11];
int size = t->end - t->start;
char *endptr;
if (size <= 0 || size >= sizeof(value_str))
if (size <= 0 || size >= (int)sizeof(value_str))
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1328,13 +1386,12 @@ static int _jsmn_get_int(struct mem_funcs *mf, const char *js, jsmntok_t *t,
return *value_str != '\0' && *endptr == '\0';
}
static int _jsmn_get_const(struct mem_funcs *mf, const char *js, jsmntok_t *t,
uint32_t *value)
static int _jsmn_get_const(const char *js, jsmntok_t *t, uint32_t *value)
{
char value_str[80];
int size = t->end - t->start;
if (size <= 0 || size >= sizeof(value_str))
if (size <= 0 || size >= (int)sizeof(value_str))
return 0;
(void) memcpy(value_str, js + t->start, size);
@ -1368,7 +1425,8 @@ static int _jsmn_get_item(struct mem_funcs *mf, const char *js, jsmntok_t *t,
static int _jsmn_get_dict(struct mem_funcs *mf, const char *js, jsmntok_t *t,
size_t count, getdns_dict *dict, getdns_return_t *r)
{
size_t i, j = 1;
int i;
size_t j = 1;
char key_spc[1024], *key = NULL;
getdns_item child_item;
@ -1388,7 +1446,7 @@ static int _jsmn_get_dict(struct mem_funcs *mf, const char *js, jsmntok_t *t,
*r = GETDNS_RETURN_GENERIC_ERROR; /* range error */
break;
}
if (t[j].end - t[j].start < sizeof(key_spc))
if (t[j].end - t[j].start < (int)sizeof(key_spc))
key = key_spc;
else if (!(key = GETDNS_XMALLOC(
@ -1446,7 +1504,8 @@ static int _jsmn_get_dict(struct mem_funcs *mf, const char *js, jsmntok_t *t,
static int _jsmn_get_list(struct mem_funcs *mf, const char *js, jsmntok_t *t,
size_t count, getdns_list *list, getdns_return_t *r)
{
size_t i, j = 1, index = 0;
int i;
size_t j = 1, index = 0;
getdns_item child_item;
if (t->size <= 0)
@ -1525,8 +1584,8 @@ static int _jsmn_get_item(struct mem_funcs *mf, const char *js, jsmntok_t *t,
*r = GETDNS_RETURN_GENERIC_ERROR;
break;
} else if (_jsmn_get_int(mf, js, t, &item->data.n)
|| _jsmn_get_const(mf, js, t, &item->data.n)) {
} else if (_jsmn_get_int(js, t, &item->data.n)
|| _jsmn_get_const(js, t, &item->data.n)) {
item->dtype = t_int;
}
@ -1607,6 +1666,31 @@ getdns_str2dict(const char *str, getdns_dict **dict)
getdns_item item;
getdns_return_t r;
if (!str || !dict)
return GETDNS_RETURN_INVALID_PARAMETER;
while (*str && isspace(*str))
str++;
if (*str != '{') {
char value_buf[3072], *value_str = value_buf;
if (strlen(str) > sizeof(value_str) - 1)
value_str = strdup(str);
else
(void)strncpy(value_buf, str, sizeof(value_buf));
getdns_dict *dict_r = _getdns_ipaddr_dict_mf(
&_getdns_plain_mem_funcs, value_str);
if (value_str != value_buf)
free(value_str);
if (dict_r) {
*dict = dict_r;
return GETDNS_RETURN_GOOD;
}
}
if ((r = _getdns_str2item_mf(&_getdns_plain_mem_funcs, str, &item)))
return r;
@ -1664,6 +1748,9 @@ getdns_str2list(const char *str, getdns_list **list)
getdns_item item;
getdns_return_t r;
if (!str || !list)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_str2item_mf(&_getdns_plain_mem_funcs, str, &item)))
return r;
@ -1681,6 +1768,9 @@ getdns_str2bindata(const char *str, getdns_bindata **bindata)
getdns_item item;
getdns_return_t r;
if (!str || !bindata)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_str2item_mf(&_getdns_plain_mem_funcs, str, &item)))
return r;
@ -1698,6 +1788,9 @@ getdns_str2int(const char *str, uint32_t *value)
getdns_item item;
getdns_return_t r;
if (!str || !value)
return GETDNS_RETURN_INVALID_PARAMETER;
if ((r = _getdns_str2item_mf(&_getdns_plain_mem_funcs, str, &item)))
return r;

View File

@ -36,7 +36,6 @@
#define DEBUG_H
#include "config.h"
#define STUB_DEBUG_ENTRY "=> ENTRY: "
#define STUB_DEBUG_SETUP "--- SETUP: "
#define STUB_DEBUG_SETUP_TLS "--- SETUP(TLS): "
@ -46,6 +45,21 @@
#define STUB_DEBUG_WRITE "------- WRITE: "
#define STUB_DEBUG_CLEANUP "--- CLEANUP: "
#ifdef GETDNS_ON_WINDOWS
#define DEBUG_ON(...) do { \
struct timeval tv; \
struct tm tm; \
char buf[10]; \
time_t tsec; \
\
gettimeofday(&tv, NULL); \
tsec = (time_t) tv.tv_sec; \
gmtime_s(&tm, (const time_t *) &tsec); \
strftime(buf, 10, "%H:%M:%S", &tm); \
fprintf(stderr, "[%s.%.6d] ", buf, (int)tv.tv_usec); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
#else
#define DEBUG_ON(...) do { \
struct timeval tv; \
struct tm tm; \
@ -57,6 +71,7 @@
fprintf(stderr, "[%s.%.6d] ", buf, (int)tv.tv_usec); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
#endif
#define DEBUG_NL(...) do { \
struct timeval tv; \
@ -74,6 +89,31 @@
#define DEBUG_OFF(...) do {} while (0)
#if defined(REQ_DEBUG) && REQ_DEBUG
#include <time.h>
#define DEBUG_REQ(...) DEBUG_ON(__VA_ARGS__)
#include "gldns/wire2str.h"
#include "rr-dict.h"
#include "types-internal.h"
static inline void debug_req(const char *msg, getdns_network_req *netreq)
{
char str[1024];
struct timeval tv;
uint64_t t;
(void) gettimeofday(&tv, NULL);
t = tv.tv_sec * 1000 + tv.tv_usec / 1000;
t = t >= netreq->owner->expires ? 0 : netreq->owner->expires - t;
(void) gldns_wire2str_dname_buf(netreq->owner->name,
netreq->owner->name_len, str, sizeof(str));
DEBUG_REQ("NETREQ %s %4"PRIu64" %s %s\n", msg, t,
str, _getdns_rr_type_name(netreq->request_type));
}
#else
#define DEBUG_REQ(...) DEBUG_OFF(__VA_ARGS__)
#define debug_req(...) DEBUG_OFF(__VA_ARGS__)
#endif
#if defined(SCHED_DEBUG) && SCHED_DEBUG
#include <time.h>
#define DEBUG_SCHED(...) DEBUG_ON(__VA_ARGS__)
@ -88,6 +128,13 @@
#define DEBUG_STUB(...) DEBUG_OFF(__VA_ARGS__)
#endif
#if defined(DAEMON_DEBUG) && DAEMON_DEBUG
#include <time.h>
#define DEBUG_DAEMON(...) DEBUG_ON(__VA_ARGS__)
#else
#define DEBUG_DAEMON(...) DEBUG_OFF(__VA_ARGS__)
#endif
#if defined(SEC_DEBUG) && SEC_DEBUG
#include <time.h>
#define DEBUG_SEC(...) DEBUG_ON(__VA_ARGS__)
@ -102,5 +149,28 @@
#define DEBUG_SERVER(...) DEBUG_OFF(__VA_ARGS__)
#endif
#define MDNS_DEBUG_ENTRY "-> MDNS ENTRY: "
#define MDNS_DEBUG_READ "-- MDNS READ: "
#define MDNS_DEBUG_MREAD "-- MDNS MREAD: "
#define MDNS_DEBUG_WRITE "-- MDNS WRITE: "
#define MDNS_DEBUG_CLEANUP "-- MDNS CLEANUP:"
#if defined(MDNS_DEBUG) && MDNS_DEBUG
#include <time.h>
#define DEBUG_MDNS(...) DEBUG_ON(__VA_ARGS__)
#else
#define DEBUG_MDNS(...) DEBUG_OFF(__VA_ARGS__)
#endif
#if (defined(REQ_DEBUG) && REQ_DEBUG) || \
(defined(SCHED_DEBUG) && SCHED_DEBUG) || \
(defined(STUB_DEBUG) && STUB_DEBUG) || \
(defined(DAEMON_DEBUG) && DAEMON_DEBUG) || \
(defined(SEC_DEBUG) && SEC_DEBUG) || \
(defined(SERVER_DEBUG) && SERVER_DEBUG) || \
(defined(MDNS_DEBUG) && MDNS_DEBUG)
#define DEBUGGING 1
#endif
#endif
/* debug.h */

View File

@ -51,10 +51,11 @@
#include "const-info.h"
#include "gldns/gbuffer.h"
#include "gldns/wire2str.h"
#include "gldns/parseutil.h"
static char *_json_ptr_first(const struct mem_funcs *mf,
const char *jptr, char *first, size_t first_sz)
const char *jptr, char *first, ssize_t first_sz)
{
const char *next_ref, *k;
char *j;
@ -65,7 +66,7 @@ static char *_json_ptr_first(const struct mem_funcs *mf,
if (!(next_ref = strchr(jptr, '/')))
next_ref = strchr(jptr, '\0');
if (next_ref - jptr + 1 > first_sz || !first)
if ((ssize_t)(next_ref - jptr + 1) > first_sz || !first)
first = GETDNS_XMALLOC(*mf, char, next_ref - jptr + 1);
for (j = first, k = jptr; k < next_ref; j++, k++)
@ -731,18 +732,44 @@ _getdns_bindata_is_dname(getdns_bindata *bindata)
bindata->data[bindata->size - 1] == 0;
}
static int
getdns_pp_base64(gldns_buffer *buf, getdns_bindata *bindata)
{
size_t p = gldns_buffer_position(buf);
size_t base64str_sz;
char *target;
size_t avail;
if (gldns_buffer_printf(buf, " <bindata of ") < 0)
return -1;
base64str_sz = gldns_b64_ntop_calculate_size(bindata->size);
target = (char *)gldns_buffer_current(buf);
avail = gldns_buffer_remaining(buf);
if (avail >= base64str_sz)
gldns_buffer_skip(buf, gldns_b64_ntop(
bindata->data, bindata->size,
target, base64str_sz));
else
gldns_buffer_skip(buf, base64str_sz);
if (gldns_buffer_printf(buf, ">") < 0)
return -1;
return gldns_buffer_position(buf) - p;
}
/*---------------------------------------- getdns_pp_bindata */
/**
* private function to pretty print bindata to a gldns_buffer
* @param buf buffer to write to
* @param indent number of spaces to append after newline
* @param bindata the bindata to print
* @return on success the number of written characters
* if an output error is encountered, a negative value
*/
static int
getdns_pp_bindata(gldns_buffer *buf, size_t indent,
getdns_bindata *bindata, int rdata_raw, int json)
getdns_pp_bindata(gldns_buffer *buf, getdns_bindata *bindata,
int rdata_raw, int json)
{
size_t i, p = gldns_buffer_position(buf);
uint8_t *dptr;
@ -887,7 +914,7 @@ getdns_pp_list(gldns_buffer *buf, size_t indent, const getdns_list *list,
GETDNS_RETURN_GOOD)
return -1;
if (getdns_pp_bindata(
buf, indent, bindata_item, 0, json) < 0)
buf, bindata_item, 0, json) < 0)
return -1;
break;
@ -1095,8 +1122,18 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent,
)) < 0)
return -1;
} else if (!json &&
(strcmp(item->node.key, "pin-sha256") == 0 ||
strcmp(item->node.key, "value") == 0) &&
item->i.data.bindata->size > 0 &&
item->i.data.bindata->size % 4 == 0) {
if (getdns_pp_base64(buf,
item->i.data.bindata) < 0)
return -1;
} else if (getdns_pp_bindata(
buf, indent, item->i.data.bindata,
buf, item->i.data.bindata,
(strcmp(item->node.key, "rdata_raw") == 0),
json) < 0)
return -1;
@ -1187,9 +1224,9 @@ getdns_pretty_snprint_dict(char *str, size_t size, const getdns_dict *dict)
if (!dict) return -1;
gldns_buffer_init_frm_data(&buf, str, size);
gldns_buffer_init_vfixed_frm_data(&buf, str, size);
return getdns_pp_dict(&buf, 0, dict, 0) < 0
? -1 : gldns_buffer_position(&buf);
? -1 : (int)gldns_buffer_position(&buf);
}
char *
@ -1221,9 +1258,9 @@ getdns_pretty_snprint_list(char *str, size_t size, const getdns_list *list)
if (!list) return -1;
gldns_buffer_init_frm_data(&buf, str, size);
gldns_buffer_init_vfixed_frm_data(&buf, str, size);
return getdns_pp_list(&buf, 0, list, 0, 0) < 0
? -1 : gldns_buffer_position(&buf);
? -1 : (int)gldns_buffer_position(&buf);
}
char *
@ -1256,9 +1293,9 @@ getdns_snprint_json_dict(
if (!dict) return -1;
gldns_buffer_init_frm_data(&buf, str, size);
gldns_buffer_init_vfixed_frm_data(&buf, str, size);
return getdns_pp_dict(&buf, 0, dict, pretty ? 1 : 2) < 0
? -1 : gldns_buffer_position(&buf);
? -1 : (int)gldns_buffer_position(&buf);
}
char *
@ -1291,9 +1328,9 @@ getdns_snprint_json_list(
if (!list) return -1;
gldns_buffer_init_frm_data(&buf, str, size);
gldns_buffer_init_vfixed_frm_data(&buf, str, size);
return getdns_pp_list(&buf, 0, list, 0, pretty ? 1 : 2) < 0
? -1 : gldns_buffer_position(&buf);
? -1 : (int)gldns_buffer_position(&buf);
}
/* dict.c */

View File

@ -256,7 +256,7 @@ static uint8_t *_dname_label_copy(uint8_t *dst, const uint8_t *src, size_t dst_l
{
uint8_t *r = dst, i;
if (!src || *src + 1 > dst_len)
if (!src || (size_t)*src + 1 > dst_len)
return NULL;
for (i = (*dst++ = *src++); i ; i--)
@ -528,7 +528,7 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf,
chain_head *head;
const uint8_t *labels[128], **last_label, **label;
size_t max_labels; /* max labels in common */
ssize_t max_labels; /* max labels in common */
chain_head *max_head;
chain_node *max_node;
@ -550,16 +550,31 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf,
/* Also, try to prevent adding double rrsets */
if ( rrset->rr_class == head->rrset.rr_class
&& rrset->rr_type == head->rrset.rr_type
&& rrset->pkt == head->rrset.pkt
&& rrset->pkt_len == head->rrset.pkt_len
&& _dname_equal(rrset->name, head->rrset.name))
return NULL;
&& _dname_equal(rrset->name, head->rrset.name)) {
if (rrset->pkt == head->rrset.pkt &&
rrset->pkt_len == head->rrset.pkt_len)
return NULL;
else {
/* Anticipate resubmissions due to
* roadblock avoidance */
head->rrset.pkt = rrset->pkt;
head->rrset.pkt_len = rrset->pkt_len;
return head;
}
}
if ( rrset->rr_class == head->rrset.rr_class
&& rrset->rr_type == head->rrset.rr_type
&& rrset->pkt != head->rrset.pkt
&& _dname_equal(rrset->name, head->rrset.name)) {
return NULL;
}
for (label = labels; label < last_label; label++) {
if (! _dname_is_parent(*label, head->rrset.name))
break;
}
if (label - labels > max_labels) {
if ((ssize_t)(label - labels) > max_labels) {
max_labels = label - labels;
max_head = head;
}
@ -616,6 +631,11 @@ static chain_head *add_rrset2val_chain(struct mem_funcs *mf,
head->node_count = node_count;
if (!node_count) {
/* When this head has no nodes of itself, it must have found
* another head which has nodes for its labels (i.e. max_head)
*/
assert(max_head != NULL);
head->parent = max_head->parent;
return head;
}
@ -857,6 +877,7 @@ static getdns_dict *CD_extension(getdns_dns_req *dnsreq)
? dnssec_ok_checking_disabled_roadblock_avoidance
: dnssec_ok_checking_disabled_avoid_roadblocks;
#else
(void)dnsreq;
return dnssec_ok_checking_disabled;
#endif
}
@ -1038,13 +1059,13 @@ static void val_chain_node_cb(getdns_dns_req *dnsreq)
_getdns_rrsig_iter *rrsig, rrsig_spc;
size_t n_signers;
_getdns_context_clear_outbound_request(dnsreq);
switch (netreq->request_type) {
case GETDNS_RRTYPE_DS : node->ds.pkt = netreq->response;
node->ds.pkt_len = netreq->response_len;
break;
case GETDNS_RRTYPE_DNSKEY: node->dnskey.pkt = netreq->response;
node->dnskey.pkt_len = netreq->response_len;
/* fallthrough */
default : check_chain_complete(node->chains);
return;
}
@ -1088,7 +1109,9 @@ static void val_chain_node_soa_cb(getdns_dns_req *dnsreq)
_getdns_rrset_iter i_spc, *i;
_getdns_rrset *rrset;
_getdns_context_clear_outbound_request(dnsreq);
/* A SOA query is always scheduled with a node as the user argument.
*/
assert(node != NULL);
for ( i = _getdns_rrset_iter_init(&i_spc, netreq->response
, netreq->response_len
@ -1097,10 +1120,8 @@ static void val_chain_node_soa_cb(getdns_dns_req *dnsreq)
; i = _getdns_rrset_iter_next(i)) {
rrset = _getdns_rrset_iter_value(i);
if (rrset->rr_type == GETDNS_RRTYPE_SOA)
break;
}
if (i) {
if (rrset->rr_type != GETDNS_RRTYPE_SOA)
continue;
while (node &&
! _dname_equal(node->ds.name, rrset->name))
@ -1112,11 +1133,14 @@ static void val_chain_node_soa_cb(getdns_dns_req *dnsreq)
} else {
/* SOA for a different name */
node = (chain_node *)dnsreq->user_pointer;
node->lock++;
val_chain_sched_soa_node(node->parent);
if (node->parent) {
node->lock++;
val_chain_sched_soa_node(node->parent);
}
}
} else if (node->parent) {
break;
}
if (!i && node->parent) {
node->lock++;
val_chain_sched_soa_node(node->parent);
}
@ -1314,7 +1338,7 @@ static int _rr_iter_rdata_cmp(const void *a, const void *b)
* When the rrset was a wildcard expansion (rrsig labels < labels owner name),
* nc_name will be set to the next closer (within rrset->name).
*/
#define VAL_RRSET_SPC_SZ 1024
#define VAL_RRSET_SPC_SZ 256
static int _getdns_verify_rrsig(struct mem_funcs *mf,
_getdns_rrset *rrset, _getdns_rrsig_iter *rrsig, _getdns_rrtype_iter *key, const uint8_t **nc_name)
{
@ -1626,7 +1650,7 @@ static int nsec3_iteration_count_high(_getdns_rrtype_iter *dnskey, _getdns_rrset
return gldns_read_uint16(rr->rr_i.rr_type + 12) > 150;
}
static int check_dates(int32_t now, int32_t skew, int32_t exp, int32_t inc)
static int check_dates(time_t now, int32_t skew, int32_t exp, int32_t inc)
{
return (exp - inc > 0) && (inc - now < skew) && (now - exp < skew);
}
@ -1871,7 +1895,7 @@ static int ds_authenticates_keys(struct mem_funcs *mf,
max_supported_digest = ds->rr_i.rr_type[13];
max_supported_result = 0;
if (digest_len != ds->rr_i.nxt - ds->rr_i.rr_type-14
if ((int)digest_len != ds->rr_i.nxt - ds->rr_i.rr_type-14
|| memcmp(digest, ds->rr_i.rr_type+14, digest_len) != 0) {
if (digest != digest_spc)
GETDNS_FREE(*mf, digest);
@ -2408,6 +2432,7 @@ static int key_proves_nonexistance(
* ========================+
* First find the closest encloser.
*/
if (*rrset->name)
for ( nc_name = rrset->name, ce_name = rrset->name + *rrset->name + 1
; *ce_name ; nc_name = ce_name, ce_name += *ce_name + 1) {
@ -2670,6 +2695,7 @@ static int chain_head_validate(struct mem_funcs *mf, time_t now, uint32_t skew,
if (_getdns_rrset_has_rrs(&ds_ta)) {
switch (chain_head_validate_with_ta(mf,now,skew,head,&ds_ta)) {
case GETDNS_DNSSEC_SECURE : s = GETDNS_DNSSEC_SECURE;
/* fallthrough */
case GETDNS_DNSSEC_INSECURE: if (s != GETDNS_DNSSEC_SECURE)
s = GETDNS_DNSSEC_INSECURE;
break;
@ -2687,6 +2713,7 @@ static int chain_head_validate(struct mem_funcs *mf, time_t now, uint32_t skew,
* evaluated by processing each head in turn. The worst outcome per network request
* is the dnssec status for that network request.
*/
#ifdef STUB_NATIVE_DNSSEC
static void chain_set_netreq_dnssec_status(chain_head *chain, _getdns_rrset_iter *tas)
{
chain_head *head;
@ -2723,6 +2750,7 @@ static void chain_set_netreq_dnssec_status(chain_head *chain, _getdns_rrset_iter
}
}
}
#endif
/* The DNSSEC status of all heads for a chain structure is evaluated by
* processing each head in turn. The worst outcome is the dnssec status for
@ -3087,18 +3115,50 @@ static void check_chain_complete(chain_head *chain)
&& !dnsreq->avoid_dnssec_roadblocks
&& dnsreq->netreqs[0]->dnssec_status == GETDNS_DNSSEC_BOGUS) {
int r = GETDNS_RETURN_GOOD;
getdns_network_req **netreq_p, *netreq;
uint64_t now_ms = 0;
dnsreq->avoid_dnssec_roadblocks = 1;
dnsreq->chain->lock += 1;
for ( netreq_p = dnsreq->netreqs
; !r && (netreq = *netreq_p)
; (netreq = *netreq_p)
; netreq_p++) {
netreq->state = NET_REQ_NOT_SENT;
_getdns_netreq_change_state(netreq, NET_REQ_NOT_SENT);
netreq->dnssec_status =
GETDNS_DNSSEC_INDETERMINATE;
netreq->owner = dnsreq;
r = _getdns_submit_netreq(netreq);
(void) _getdns_submit_netreq(netreq, &now_ms);
}
if (!dnsreq->dnssec_return_validation_chain)
return;
for ( head = chain; head ; head = next ) {
next = head->next;
for ( node_count = head->node_count
, node = head->parent
; node_count
; node_count--, node = node->parent ) {
if (node->dnskey_req) {
_getdns_netreq_change_state(
node->dnskey_req,
NET_REQ_NOT_SENT);
node->dnskey_req->owner->
avoid_dnssec_roadblocks = 1;
(void) _getdns_submit_netreq(
node->dnskey_req, &now_ms);
}
if (node->ds_req) {
_getdns_netreq_change_state(
node->ds_req, NET_REQ_NOT_SENT);
node->ds_req->owner->
avoid_dnssec_roadblocks = 1;
(void) _getdns_submit_netreq(
node->ds_req, &now_ms);
}
}
}
return;
}
@ -3121,17 +3181,89 @@ static void check_chain_complete(chain_head *chain)
_getdns_call_user_callback(dnsreq, response_dict);
}
void _getdns_validation_chain_timeout(getdns_dns_req *dnsreq)
{
chain_head *head = dnsreq->chain, *next;
chain_node *node;
size_t node_count;
while (head) {
next = head->next;
for ( node_count = head->node_count, node = head->parent
; node_count
; node_count--, node = node->parent ) {
if (!_getdns_netreq_finished(node->dnskey_req)) {
_getdns_context_cancel_request(
node->dnskey_req->owner);
node->dnskey_req = NULL;
}
if (!_getdns_netreq_finished(node->ds_req)) {
_getdns_context_cancel_request(
node->ds_req->owner);
node->ds_req = NULL;
}
if (!_getdns_netreq_finished(node->soa_req)) {
_getdns_context_cancel_request(
node->soa_req->owner);
node->soa_req = NULL;
}
}
head = next;
}
dnsreq->request_timed_out = 1;
check_chain_complete(dnsreq->chain);
}
void _getdns_cancel_validation_chain(getdns_dns_req *dnsreq)
{
chain_head *head = dnsreq->chain, *next;
chain_node *node;
size_t node_count;
dnsreq->chain = NULL;
while (head) {
next = head->next;
for ( node_count = head->node_count, node = head->parent
; node_count
; node_count--, node = node->parent ) {
if (node->dnskey_req)
_getdns_context_cancel_request(
node->dnskey_req->owner);
if (node->ds_req)
_getdns_context_cancel_request(
node->ds_req->owner);
if (node->soa_req)
_getdns_context_cancel_request(
node->soa_req->owner);
}
GETDNS_FREE(head->my_mf, head);
head = next;
}
}
void _getdns_get_validation_chain(getdns_dns_req *dnsreq)
{
getdns_network_req *netreq, **netreq_p;
chain_head *chain = NULL, *chain_p;
if (dnsreq->validating)
if (dnsreq->avoid_dnssec_roadblocks) {
chain = dnsreq->chain;
} else if (dnsreq->validating)
return;
dnsreq->validating = 1;
for (netreq_p = dnsreq->netreqs; (netreq = *netreq_p) ; netreq_p++) {
if (dnsreq->avoid_dnssec_roadblocks && chain->lock == 0)
; /* pass */
else for (netreq_p = dnsreq->netreqs; (netreq = *netreq_p) ; netreq_p++) {
if (! netreq->response
|| netreq->response_len < GLDNS_HEADER_SIZE
|| ( GLDNS_RCODE_WIRE(netreq->response)
@ -3158,6 +3290,10 @@ void _getdns_get_validation_chain(getdns_dns_req *dnsreq)
for (chain_p = chain; chain_p; chain_p = chain_p->next) {
if (chain_p->lock) chain_p->lock--;
}
dnsreq->chain = chain;
if (dnsreq->avoid_dnssec_roadblocks && chain->lock)
chain->lock -= 1;
check_chain_complete(chain);
} else {
dnsreq->validating = 0;

View File

@ -46,6 +46,8 @@
/* Do some additional requests to fetch the complete validation chain */
void _getdns_get_validation_chain(getdns_dns_req *dns_req);
void _getdns_cancel_validation_chain(getdns_dns_req *dns_req);
void _getdns_validation_chain_timeout(getdns_dns_req *dns_req);
uint16_t _getdns_parse_ta_file(time_t *ta_mtime, gldns_buffer *gbuf);

View File

@ -1,6 +1,6 @@
/*
* \file default_eventloop.h
* @brief Build in default eventloop extension that uses select.
* @brief Build in default eventloop extension that uses either poll or select.
*
*/
/*
@ -32,28 +32,13 @@
#ifndef DEFAULT_EVENTLOOP_H_
#define DEFAULT_EVENTLOOP_H_
#include "config.h"
#include "getdns/getdns.h"
#include "getdns/getdns_extra.h"
/* No more than select's capability queries can be outstanding,
* The number of outstanding timeouts should be less or equal then
* the number of outstanding queries, so MAX_TIMEOUTS equal to
* FD_SETSIZE should be safe.
*/
#define MAX_TIMEOUTS FD_SETSIZE
/* Eventloop based on select */
typedef struct _getdns_default_eventloop {
getdns_eventloop loop;
getdns_eventloop_event *fd_events[FD_SETSIZE];
uint64_t fd_timeout_times[FD_SETSIZE];
getdns_eventloop_event *timeout_events[MAX_TIMEOUTS];
uint64_t timeout_times[MAX_TIMEOUTS];
} _getdns_default_eventloop;
void
_getdns_default_eventloop_init(_getdns_default_eventloop *loop);
#ifdef USE_POLL_DEFAULT_EVENTLOOP
#include "extension/poll_eventloop.h"
#define _getdns_default_eventloop _getdns_poll_eventloop
#define _getdns_default_eventloop_init _getdns_poll_eventloop_init
#else
#include "extension/select_eventloop.h"
#define _getdns_default_eventloop _getdns_select_eventloop
#define _getdns_default_eventloop_init _getdns_select_eventloop_init
#endif
#endif

View File

@ -97,6 +97,7 @@ static void
getdns_libev_read_cb(struct ev_loop *l, struct ev_io *io, int revents)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)io->data;
(void)l; (void)revents;
assert(el_ev->read_cb);
el_ev->read_cb(el_ev->userarg);
}
@ -105,14 +106,16 @@ static void
getdns_libev_write_cb(struct ev_loop *l, struct ev_io *io, int revents)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)io->data;
(void)l; (void)revents;
assert(el_ev->write_cb);
el_ev->write_cb(el_ev->userarg);
}
static void
getdns_libev_timeout_cb(struct ev_loop *l, struct ev_timer *timer, int revent)
getdns_libev_timeout_cb(struct ev_loop *l, struct ev_timer *timer, int revents)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)timer->data;
(void)l; (void)revents;
assert(el_ev->timeout_cb);
el_ev->timeout_cb(el_ev->userarg);
}

View File

@ -95,6 +95,7 @@ static getdns_return_t
getdns_libevent_clear(getdns_eventloop *loop, getdns_eventloop_event *el_ev)
{
struct event *my_ev = (struct event *)el_ev->ev;
(void)loop;
assert(my_ev);
@ -110,6 +111,7 @@ static void
getdns_libevent_callback(evutil_socket_t fd, short bits, void *arg)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)arg;
(void)fd;
if (bits & EV_READ) {
assert(el_ev->read_cb);

View File

@ -104,6 +104,7 @@ getdns_libuv_clear(getdns_eventloop *loop, getdns_eventloop_event *el_ev)
poll_timer *my_ev = (poll_timer *)el_ev->ev;
uv_poll_t *my_poll;
uv_timer_t *my_timer;
(void)loop;
assert(my_ev);
@ -141,6 +142,7 @@ static void
getdns_libuv_read_cb(uv_poll_t *poll, int status, int events)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)poll->data;
(void)status; (void)events;
assert(el_ev->read_cb);
DEBUG_UV("enter libuv_read_cb(el_ev = %p, el_ev->ev = %p)\n"
, el_ev, el_ev->ev);
@ -153,6 +155,7 @@ static void
getdns_libuv_write_cb(uv_poll_t *poll, int status, int events)
{
getdns_eventloop_event *el_ev = (getdns_eventloop_event *)poll->data;
(void)status; (void)events;
assert(el_ev->write_cb);
DEBUG_UV("enter libuv_write_cb(el_ev = %p, el_ev->ev = %p)\n"
, el_ev, el_ev->ev);

View File

@ -0,0 +1,551 @@
/*
* Copyright (c) 2013, NLNet Labs, Verisign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#else
#ifndef USE_WINSOCK
#include <poll.h>
#endif
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#include "extension/poll_eventloop.h"
#include "debug.h"
enum { init_fd_events_capacity = 64
, init_to_events_capacity = 64 };
static void *get_to_event(_getdns_poll_eventloop *loop,
getdns_eventloop_event *event, uint64_t timeout_time)
{
if (loop->to_events_free == loop->to_events_capacity) {
if (loop->to_events_free) {
_getdns_poll_event *to_events = GETDNS_XREALLOC(
loop->mf, loop->to_events, _getdns_poll_event,
loop->to_events_free * 2);
if (!to_events)
return NULL;
(void) memset(&to_events[loop->to_events_free],
0, sizeof(_getdns_poll_event)
* loop->to_events_free);
loop->to_events_capacity = loop->to_events_free * 2;
loop->to_events = to_events;
} else {
if (!(loop->to_events = GETDNS_XMALLOC(loop->mf,
_getdns_poll_event, init_to_events_capacity)))
return NULL;
(void) memset(loop->to_events, 0,
sizeof(_getdns_poll_event)
* init_to_events_capacity);
loop->to_events_capacity = init_to_events_capacity;
}
}
loop->to_events[loop->to_events_free].event = event;
loop->to_events[loop->to_events_free].timeout_time = timeout_time;
loop->to_events_n_used++;
return (void *) (intptr_t) (++loop->to_events_free);
}
static void *get_fd_event(_getdns_poll_eventloop *loop, int fd,
getdns_eventloop_event *event, uint64_t timeout_time)
{
size_t i;
if (loop->fd_events_free == loop->fd_events_capacity) {
if (loop->fd_events_free) {
_getdns_poll_event *fd_events = GETDNS_XREALLOC(
loop->mf, loop->fd_events, _getdns_poll_event,
loop->fd_events_free * 2);
struct pollfd *pfds = GETDNS_XREALLOC(
loop->mf, loop->pfds, struct pollfd,
loop->fd_events_free * 2);
if (!fd_events || !pfds) {
if (fd_events)
GETDNS_FREE(loop->mf, fd_events);
if (pfds)
GETDNS_FREE(loop->mf, pfds);
return NULL;
}
(void) memset(&fd_events[loop->fd_events_free],
0, sizeof(_getdns_poll_event)
* loop->fd_events_free);
for ( i = loop->fd_events_free
; i < loop->fd_events_free * 2
; i++) {
pfds[i].fd = -1;
pfds[i].events = 0;
pfds[i].revents = 0;
}
loop->fd_events_capacity = loop->fd_events_free * 2;
loop->fd_events = fd_events;
loop->pfds = pfds;
} else {
if (!(loop->fd_events = GETDNS_XMALLOC(loop->mf,
_getdns_poll_event, init_fd_events_capacity)) ||
!(loop->pfds = GETDNS_XMALLOC(loop->mf,
struct pollfd, init_fd_events_capacity))) {
GETDNS_NULL_FREE(loop->mf, loop->fd_events);
return NULL;
}
(void) memset(loop->fd_events, 0,
sizeof(_getdns_poll_event)
* init_fd_events_capacity);
for (i = 0; i < init_fd_events_capacity; i++) {
loop->pfds[i].fd = -1;
loop->pfds[i].events = 0;
loop->pfds[i].revents = 0;
}
loop->fd_events_capacity = init_fd_events_capacity;
}
}
loop->pfds[loop->fd_events_free].fd = fd;
loop->pfds[loop->fd_events_free].events = 0;
if (event->read_cb)
loop->pfds[loop->fd_events_free].events |= POLLIN;
if (event->write_cb)
loop->pfds[loop->fd_events_free].events |= POLLOUT;
loop->fd_events[loop->fd_events_free].event = event;
loop->fd_events[loop->fd_events_free].timeout_time = timeout_time;
loop->fd_events_n_used++;
return (void *) (intptr_t) (++loop->fd_events_free);
}
static uint64_t get_now_plus(uint64_t amount)
{
struct timeval tv;
uint64_t now;
if (gettimeofday(&tv, NULL)) {
perror("gettimeofday() failed");
exit(EXIT_FAILURE);
}
now = tv.tv_sec * 1000000 + tv.tv_usec;
return (now + amount * 1000) >= now
? now + amount * 1000 : TIMEOUT_FOREVER;
}
static getdns_return_t
poll_eventloop_schedule(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *event)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p)\n"
, __FUNC__, (void *)loop, fd, timeout, (void *)event);
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
if (fd >= 0 && !(event->read_cb || event->write_cb)) {
DEBUG_SCHED("WARNING: fd event without "
"read or write cb!\n");
fd = -1;
}
if (fd >= 0) {
if (!(event->ev = get_fd_event(
poll_loop, fd, event, get_now_plus(timeout)))) {
DEBUG_SCHED("ERROR: scheduled read/write slots!\n");
return GETDNS_RETURN_GENERIC_ERROR;
}
DEBUG_SCHED( "scheduled read/write at for %d at %p\n"
, fd, (void *)event->ev);
return GETDNS_RETURN_GOOD;
}
if (!event->timeout_cb) {
DEBUG_SCHED("ERROR: fd < 0 without timeout_cb!\n");
return GETDNS_RETURN_GENERIC_ERROR;
}
if (event->read_cb) {
DEBUG_SCHED("ERROR: timeout event with read_cb! Clearing.\n");
event->read_cb = NULL;
}
if (event->write_cb) {
DEBUG_SCHED("ERROR: timeout event with write_cb! Clearing.\n");
event->write_cb = NULL;
}
if (!(event->ev = get_to_event(poll_loop, event, get_now_plus(timeout)))) {
DEBUG_SCHED("ERROR: Out of timeout slots!\n");
return GETDNS_RETURN_GENERIC_ERROR;
}
DEBUG_SCHED("scheduled timeout at slot %p\n", (void *)event->ev);
return GETDNS_RETURN_GOOD;
}
static getdns_return_t
poll_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNC__, (void *)loop, (void *)event);
if (!event->ev)
return GETDNS_RETURN_GOOD;
else if (event->timeout_cb && !event->read_cb && !event->write_cb) {
size_t i = ((size_t) (intptr_t) event->ev) - 1;
/* This may happen with full recursive synchronous requests
* with the unbound pluggable event API, because the default
* poll_eventloop is temporarily replaced by a poll_eventloop
* used only in synchronous calls. When the synchronous request
* had an answer, the poll_eventloop for the synchronous is
* cleaned, however it could still have outstanding events.
*/
if (i >= poll_loop->to_events_capacity ||
poll_loop->to_events[i].event != event) {
event->ev = NULL;
DEBUG_SCHED( "ERROR: Event mismatch %p\n", (void *)event->ev);
return GETDNS_RETURN_GENERIC_ERROR;
}
poll_loop->to_events[i].event = NULL;
if (--poll_loop->to_events_n_used == 0) {
poll_loop->to_events_free = 0;
}
DEBUG_SCHED( "cleared timeout at slot %p\n", (void *)event->ev);
} else {
size_t i = ((size_t) (intptr_t) event->ev) - 1;
/* This may happen with full recursive synchronous requests
* with the unbound pluggable event API, because the default
* poll_eventloop is temporarily replaced by a poll_eventloop
* used only in synchronous calls. When the synchronous request
* had an answer, the poll_eventloop for the synchronous is
* cleaned, however it could still have outstanding events.
*/
if (i >= poll_loop->fd_events_capacity ||
poll_loop->fd_events[i].event != event) {
event->ev = NULL;
DEBUG_SCHED( "ERROR: Event mismatch %p\n", (void *)event->ev);
return GETDNS_RETURN_GENERIC_ERROR;
}
poll_loop->fd_events[i].event = NULL;
if (--poll_loop->fd_events_n_used == 0) {
poll_loop->fd_events_free = 0;
}
DEBUG_SCHED( "cleared read/write for %d at slot %p\n"
, poll_loop->pfds[i].fd, (void *)event->ev);
poll_loop->pfds[i].fd = -1; /* Not necessary, but to be sure */
}
event->ev = NULL;
return GETDNS_RETURN_GOOD;
}
static void
poll_eventloop_cleanup(getdns_eventloop *loop)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
struct mem_funcs *mf = &poll_loop->mf;
GETDNS_NULL_FREE(*mf, poll_loop->pfds);
if (poll_loop->fd_events) {
GETDNS_FREE(*mf, poll_loop->fd_events);
poll_loop->fd_events = NULL;
poll_loop->fd_events_capacity = 0;
poll_loop->fd_events_free = 0;
poll_loop->fd_events_n_used = 0;
}
if (poll_loop->to_events) {
GETDNS_FREE(*mf, poll_loop->to_events);
poll_loop->to_events = NULL;
poll_loop->to_events_capacity = 0;
poll_loop->to_events_free = 0;
poll_loop->to_events_n_used = 0;
}
}
static void
poll_read_cb(int fd, getdns_eventloop_event *event)
{
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->read_cb(event->userarg);
}
static void
poll_write_cb(int fd, getdns_eventloop_event *event)
{
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->write_cb(event->userarg);
}
static void
poll_timeout_cb(getdns_eventloop_event *event)
{
DEBUG_SCHED( "%s(event: %p)\n", __FUNC__, (void *)event);
event->timeout_cb(event->userarg);
}
static void
poll_eventloop_run_once(getdns_eventloop *loop, int blocking)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
uint64_t now, timeout = TIMEOUT_FOREVER;
size_t i = 0, j;
int poll_timeout = 0;
if (!loop)
return;
now = get_now_plus(0);
for (i = 0, j = 0; i < poll_loop->to_events_free; i++, j++) {
while (poll_loop->to_events[i].event == NULL) {
if (++i == poll_loop->to_events_free) {
poll_loop->to_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->to_events_free)
break;
poll_loop->to_events[j] = poll_loop->to_events[i];
poll_loop->to_events[i].event = NULL;
poll_loop->to_events[j].event->ev =
(void *) (intptr_t) (j + 1);
}
if (poll_loop->to_events[j].timeout_time < now)
poll_timeout_cb(poll_loop->to_events[j].event);
}
for (i = 0, j = 0; i < poll_loop->to_events_free; i++, j++) {
while (poll_loop->to_events[i].event == NULL) {
if (++i == poll_loop->to_events_free) {
poll_loop->to_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->to_events_free)
break;
poll_loop->to_events[j] = poll_loop->to_events[i];
poll_loop->to_events[i].event = NULL;
poll_loop->to_events[j].event->ev =
(void *) (intptr_t) (j + 1);
}
if (poll_loop->to_events[j].timeout_time < timeout)
timeout = poll_loop->to_events[j].timeout_time;
}
if ((timeout == TIMEOUT_FOREVER) && (poll_loop->fd_events_free == 0))
return;
for (i = 0, j = 0; i < poll_loop->fd_events_free; i++, j++) {
while (poll_loop->fd_events[i].event == NULL) {
if (++i == poll_loop->fd_events_free) {
poll_loop->fd_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->fd_events_free)
break;
poll_loop->fd_events[j] = poll_loop->fd_events[i];
poll_loop->fd_events[i].event = NULL;
poll_loop->fd_events[j].event->ev =
(void *) (intptr_t) (j + 1);
poll_loop->pfds[j] = poll_loop->pfds[i];
poll_loop->pfds[i].fd = -1;
}
if (poll_loop->fd_events[j].timeout_time < timeout)
timeout = poll_loop->fd_events[j].timeout_time;
}
if (timeout == TIMEOUT_FOREVER) {
poll_timeout = -1;
} else if (! blocking || now > timeout) {
poll_timeout = 0;
} else {
/* turn microseconds into milliseconds */
poll_timeout = (timeout - now) / 1000;
}
DEBUG_SCHED( "poll(fd_free: %d, fd_used: %d, to_free: %d, to_used: %d, timeout: %d)\n"
, (int)poll_loop->fd_events_free, (int)poll_loop->fd_events_n_used
, (int)poll_loop->to_events_free, (int)poll_loop->to_events_n_used
, poll_timeout
);
#ifdef USE_WINSOCK
if (poll_loop->fd_events_free == 0)
{
Sleep(poll_timeout);
} else
if (WSAPoll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
#else
if (poll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
#endif
perror("poll() failed");
exit(EXIT_FAILURE);
}
now = get_now_plus(0);
for (i = 0, j = 0; i < poll_loop->fd_events_free; i++, j++) {
while (poll_loop->fd_events[i].event == NULL) {
if (++i == poll_loop->fd_events_free) {
poll_loop->fd_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->fd_events_free)
break;
poll_loop->fd_events[j] = poll_loop->fd_events[i];
poll_loop->fd_events[i].event = NULL;
poll_loop->fd_events[j].event->ev =
(void *) (intptr_t) (j + 1);
poll_loop->pfds[j] = poll_loop->pfds[i];
poll_loop->pfds[i].fd = -1;
}
if (poll_loop->fd_events[j].event->write_cb &&
poll_loop->pfds[j].revents & (POLLOUT|POLLERR|POLLHUP|POLLNVAL))
poll_write_cb( poll_loop->pfds[j].fd
, poll_loop->fd_events[j].event);
if (poll_loop->fd_events[j].event &&
poll_loop->fd_events[j].event->read_cb &&
poll_loop->pfds[j].revents & (POLLIN|POLLERR|POLLHUP|POLLNVAL))
poll_read_cb( poll_loop->pfds[j].fd
, poll_loop->fd_events[j].event);
}
for (i = 0, j = 0; i < poll_loop->fd_events_free; i++, j++) {
while (poll_loop->fd_events[i].event == NULL) {
if (++i == poll_loop->fd_events_free) {
poll_loop->fd_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->fd_events_free)
break;
poll_loop->fd_events[j] = poll_loop->fd_events[i];
poll_loop->fd_events[i].event = NULL;
poll_loop->fd_events[j].event->ev =
(void *) (intptr_t) (j + 1);
poll_loop->pfds[j] = poll_loop->pfds[i];
poll_loop->pfds[i].fd = -1;
}
if (poll_loop->fd_events[j].timeout_time < now)
poll_timeout_cb(poll_loop->fd_events[j].event);
}
for (i = 0, j = 0; i < poll_loop->to_events_free; i++, j++) {
while (poll_loop->to_events[i].event == NULL) {
if (++i == poll_loop->to_events_free) {
poll_loop->to_events_free = j;
break;
}
}
if (j < i) {
if (j >= poll_loop->to_events_free)
break;
poll_loop->to_events[j] = poll_loop->to_events[i];
poll_loop->to_events[i].event = NULL;
poll_loop->to_events[j].event->ev =
(void *) (intptr_t) (j + 1);
}
if (poll_loop->to_events[j].timeout_time < now)
poll_timeout_cb(poll_loop->to_events[j].event);
}
}
static void
poll_eventloop_run(getdns_eventloop *loop)
{
_getdns_poll_eventloop *poll_loop = (_getdns_poll_eventloop *)loop;
if (!loop)
return;
/* keep going until all the events are cleared */
while (poll_loop->fd_events_n_used || poll_loop->to_events_n_used) {
poll_eventloop_run_once(loop, 1);
}
}
void
_getdns_poll_eventloop_init(struct mem_funcs *mf, _getdns_poll_eventloop *loop)
{
static getdns_eventloop_vmt poll_eventloop_vmt = {
poll_eventloop_cleanup,
poll_eventloop_schedule,
poll_eventloop_clear,
poll_eventloop_run,
poll_eventloop_run_once
};
loop->loop.vmt = &poll_eventloop_vmt;
loop->mf = *mf;
loop->to_events_capacity = init_to_events_capacity;
if ((loop->to_events = GETDNS_XMALLOC(
*mf, _getdns_poll_event, init_to_events_capacity)))
(void) memset(loop->to_events, 0,
sizeof(_getdns_poll_event) * init_to_events_capacity);
else
loop->to_events_capacity = 0;
loop->to_events_free = 0;
loop->to_events_n_used = 0;
loop->fd_events_capacity = init_fd_events_capacity;
if ((loop->fd_events = GETDNS_XMALLOC(
*mf, _getdns_poll_event, init_fd_events_capacity)) &&
(loop->pfds = GETDNS_XMALLOC(
*mf, struct pollfd, init_fd_events_capacity))) {
size_t i;
(void) memset(loop->fd_events, 0,
sizeof(_getdns_poll_event) * init_fd_events_capacity);
for (i = 0; i < init_fd_events_capacity; i++) {
loop->pfds[i].fd = -1;
loop->pfds[i].events = 0;
loop->pfds[i].revents = 0;
}
} else {
loop->fd_events_capacity = 0;
if (loop->fd_events) {
GETDNS_FREE(*mf, loop->fd_events);
loop->fd_events = NULL;
}
}
loop->fd_events_free = 0;
loop->fd_events_n_used = 0;
}

View File

@ -0,0 +1,66 @@
/*
* \file poll_eventloop.h
* @brief Build in default eventloop extension that uses select.
*
*/
/*
* Copyright (c) 2013, NLNet Labs, Verisign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef POLL_EVENTLOOP_H_
#define POLL_EVENTLOOP_H_
#include "config.h"
#include "getdns/getdns.h"
#include "getdns/getdns_extra.h"
#include "types-internal.h"
/* Eventloop based on poll */
typedef struct _getdns_poll_event {
getdns_eventloop_event *event;
uint64_t timeout_time;
} _getdns_poll_event;
typedef struct _getdns_poll_eventloop {
getdns_eventloop loop;
struct mem_funcs mf;
struct pollfd *pfds;
size_t fd_events_capacity;
_getdns_poll_event *fd_events;
size_t fd_events_free;
size_t fd_events_n_used;
size_t to_events_capacity;
_getdns_poll_event *to_events;
size_t to_events_free;
size_t to_events_n_used;
} _getdns_poll_eventloop;
void
_getdns_poll_eventloop_init(struct mem_funcs *mf, _getdns_poll_eventloop *loop);
#endif

View File

@ -25,32 +25,36 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "extension/default_eventloop.h"
#include "config.h"
#include "extension/select_eventloop.h"
#include "debug.h"
#include "types-internal.h"
static uint64_t get_now_plus(uint64_t amount)
{
struct timeval tv;
uint64_t now;
if (gettimeofday(&tv, NULL)) {
perror("gettimeofday() failed");
exit(EXIT_FAILURE);
}
now = tv.tv_sec * 1000000 + tv.tv_usec;
return (now + amount * 1000) >= now ? now + amount * 1000 : -1;
return (now + amount * 1000) >= now
? now + amount * 1000 : TIMEOUT_FOREVER;
}
static getdns_return_t
default_eventloop_schedule(getdns_eventloop *loop,
select_eventloop_schedule(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *event)
{
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop;
_getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
size_t i;
DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p, FD_SETSIZE: %d)\n"
, __FUNCTION__, loop, fd, timeout, event, FD_SETSIZE);
, __FUNC__, (void *)loop, fd, timeout, (void *)event, FD_SETSIZE);
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
@ -67,22 +71,21 @@ default_eventloop_schedule(getdns_eventloop *loop,
}
if (fd >= 0) {
#if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->fd_events[fd]) {
if (default_loop->fd_events[fd] == event) {
if (select_loop->fd_events[fd]) {
if (select_loop->fd_events[fd] == event) {
DEBUG_SCHED("WARNING: Event %p not cleared "
"before being rescheduled!\n"
, default_loop->fd_events[fd]);
, (void *)select_loop->fd_events[fd]);
} else {
DEBUG_SCHED("ERROR: A different event is "
"already present at fd slot: %p!\n"
, default_loop->fd_events[fd]);
, (void *)select_loop->fd_events[fd]);
}
}
#endif
default_loop->fd_events[fd] = event;
default_loop->fd_timeout_times[fd] = get_now_plus(timeout);
event->ev = (void *) (intptr_t) fd + 1;
select_loop->fd_events[fd] = event;
select_loop->fd_timeout_times[fd] = get_now_plus(timeout);
event->ev = (void *)(intptr_t)(fd + 1);
DEBUG_SCHED( "scheduled read/write at %d\n", fd);
return GETDNS_RETURN_GOOD;
}
@ -99,11 +102,10 @@ default_eventloop_schedule(getdns_eventloop *loop,
event->write_cb = NULL;
}
for (i = 0; i < MAX_TIMEOUTS; i++) {
if (default_loop->timeout_events[i] == NULL) {
default_loop->timeout_events[i] = event;
default_loop->timeout_times[i] = get_now_plus(timeout);
event->ev = (void *) (intptr_t) i + 1;
if (select_loop->timeout_events[i] == NULL) {
select_loop->timeout_events[i] = event;
select_loop->timeout_times[i] = get_now_plus(timeout);
event->ev = (void *)(intptr_t)(i + 1);
DEBUG_SCHED( "scheduled timeout at %d\n", (int)i);
return GETDNS_RETURN_GOOD;
}
@ -113,75 +115,85 @@ default_eventloop_schedule(getdns_eventloop *loop,
}
static getdns_return_t
default_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
select_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event)
{
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop;
_getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
ssize_t i;
if (!loop || !event)
return GETDNS_RETURN_INVALID_PARAMETER;
DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNCTION__, loop, event);
DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNC__, (void *)loop, (void *)event);
i = (intptr_t)event->ev - 1;
if (i < 0 || i > FD_SETSIZE) {
if (i < 0 || i >= FD_SETSIZE) {
return GETDNS_RETURN_GENERIC_ERROR;
}
if (event->timeout_cb && !event->read_cb && !event->write_cb) {
#if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->timeout_events[i] != event)
if (select_loop->timeout_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at "
"timeout slot: %p!\n"
, default_loop->timeout_events[i]);
, (void *)select_loop->timeout_events[i]);
#endif
default_loop->timeout_events[i] = NULL;
select_loop->timeout_events[i] = NULL;
} else {
#if defined(SCHED_DEBUG) && SCHED_DEBUG
if (default_loop->fd_events[i] != event)
if (select_loop->fd_events[i] != event)
DEBUG_SCHED( "ERROR: Different/wrong event present at "
"fd slot: %p!\n"
, default_loop->fd_events[i]);
, (void *)select_loop->fd_events[i]);
#endif
default_loop->fd_events[i] = NULL;
select_loop->fd_events[i] = NULL;
}
event->ev = NULL;
return GETDNS_RETURN_GOOD;
}
static void
default_eventloop_cleanup(getdns_eventloop *loop)
select_eventloop_cleanup(getdns_eventloop *loop)
{
(void)loop;
}
static void
default_read_cb(int fd, getdns_eventloop_event *event)
select_read_cb(int fd, getdns_eventloop_event *event)
{
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event);
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->read_cb(event->userarg);
}
static void
default_write_cb(int fd, getdns_eventloop_event *event)
select_write_cb(int fd, getdns_eventloop_event *event)
{
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event);
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->write_cb(event->userarg);
}
static void
default_timeout_cb(int fd, getdns_eventloop_event *event)
select_timeout_cb(int fd, getdns_eventloop_event *event)
{
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event);
#if !defined(SCHED_DEBUG) || !SCHED_DEBUG
(void)fd;
#endif
DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNC__, fd, (void *)event);
event->timeout_cb(event->userarg);
}
static void
default_eventloop_run_once(getdns_eventloop *loop, int blocking)
select_eventloop_run_once(getdns_eventloop *loop, int blocking)
{
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop;
_getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
fd_set readfds, writefds;
int fd, max_fd = -1;
uint64_t now, timeout = (uint64_t)-1;
uint64_t now, timeout = TIMEOUT_FOREVER;
size_t i;
struct timeval tv;
@ -193,69 +205,79 @@ default_eventloop_run_once(getdns_eventloop *loop, int blocking)
now = get_now_plus(0);
for (i = 0; i < MAX_TIMEOUTS; i++) {
if (!default_loop->timeout_events[i])
if (!select_loop->timeout_events[i])
continue;
if (now > default_loop->timeout_times[i])
default_timeout_cb(-1, default_loop->timeout_events[i]);
else if (default_loop->timeout_times[i] < timeout)
timeout = default_loop->timeout_times[i];
if (now > select_loop->timeout_times[i])
select_timeout_cb(-1, select_loop->timeout_events[i]);
else if (select_loop->timeout_times[i] < timeout)
timeout = select_loop->timeout_times[i];
}
for (fd = 0; fd < FD_SETSIZE; fd++) {
if (!default_loop->fd_events[fd])
for (fd = 0; fd < (int)FD_SETSIZE; fd++) {
if (!select_loop->fd_events[fd])
continue;
if (default_loop->fd_events[fd]->read_cb)
if (select_loop->fd_events[fd]->read_cb)
FD_SET(fd, &readfds);
if (default_loop->fd_events[fd]->write_cb)
if (select_loop->fd_events[fd]->write_cb)
FD_SET(fd, &writefds);
if (fd > max_fd)
max_fd = fd;
if (default_loop->fd_timeout_times[fd] < timeout)
timeout = default_loop->fd_timeout_times[fd];
if (select_loop->fd_timeout_times[fd] < timeout)
timeout = select_loop->fd_timeout_times[fd];
}
if (max_fd == -1 && timeout == (uint64_t)-1)
if (max_fd == -1 && timeout == TIMEOUT_FOREVER)
return;
if (! blocking || now > timeout) {
tv.tv_sec = 0;
tv.tv_usec = 0;
} else {
tv.tv_sec = (timeout - now) / 1000000;
tv.tv_usec = (timeout - now) % 1000000;
tv.tv_sec = (long)((timeout - now) / 1000000);
tv.tv_usec = (long)((timeout - now) % 1000000);
}
#ifdef USE_WINSOCK
if (max_fd == -1)
{
if (timeout != TIMEOUT_FOREVER)
{
uint32_t timeout_ms = (tv.tv_usec / 1000) + (tv.tv_sec * 1000);
Sleep(timeout_ms);
}
} else
#endif
if (select(max_fd + 1, &readfds, &writefds, NULL,
(timeout == ((uint64_t)-1) ? NULL : &tv)) < 0) {
(timeout == TIMEOUT_FOREVER ? NULL : &tv)) < 0) {
perror("select() failed");
exit(EXIT_FAILURE);
}
now = get_now_plus(0);
for (fd = 0; fd < FD_SETSIZE; fd++) {
if (default_loop->fd_events[fd] &&
default_loop->fd_events[fd]->read_cb &&
for (fd = 0; fd < (int)FD_SETSIZE; fd++) {
if (select_loop->fd_events[fd] &&
select_loop->fd_events[fd]->read_cb &&
FD_ISSET(fd, &readfds))
default_read_cb(fd, default_loop->fd_events[fd]);
select_read_cb(fd, select_loop->fd_events[fd]);
if (default_loop->fd_events[fd] &&
default_loop->fd_events[fd]->write_cb &&
if (select_loop->fd_events[fd] &&
select_loop->fd_events[fd]->write_cb &&
FD_ISSET(fd, &writefds))
default_write_cb(fd, default_loop->fd_events[fd]);
select_write_cb(fd, select_loop->fd_events[fd]);
if (default_loop->fd_events[fd] &&
default_loop->fd_events[fd]->timeout_cb &&
now > default_loop->fd_timeout_times[fd])
default_timeout_cb(fd, default_loop->fd_events[fd]);
if (select_loop->fd_events[fd] &&
select_loop->fd_events[fd]->timeout_cb &&
now > select_loop->fd_timeout_times[fd])
select_timeout_cb(fd, select_loop->fd_events[fd]);
i = fd;
if (default_loop->timeout_events[i] &&
default_loop->timeout_events[i]->timeout_cb &&
now > default_loop->timeout_times[i])
default_timeout_cb(-1, default_loop->timeout_events[i]);
if (select_loop->timeout_events[i] &&
select_loop->timeout_events[i]->timeout_cb &&
now > select_loop->timeout_times[i])
select_timeout_cb(-1, select_loop->timeout_events[i]);
}
}
static void
default_eventloop_run(getdns_eventloop *loop)
select_eventloop_run(getdns_eventloop *loop)
{
_getdns_default_eventloop *default_loop = (_getdns_default_eventloop *)loop;
_getdns_select_eventloop *select_loop = (_getdns_select_eventloop *)loop;
size_t i;
if (!loop)
@ -263,8 +285,8 @@ default_eventloop_run(getdns_eventloop *loop)
i = 0;
while (i < MAX_TIMEOUTS) {
if (default_loop->fd_events[i] || default_loop->timeout_events[i]) {
default_eventloop_run_once(loop, 1);
if (select_loop->fd_events[i] || select_loop->timeout_events[i]) {
select_eventloop_run_once(loop, 1);
i = 0;
} else {
i++;
@ -273,16 +295,16 @@ default_eventloop_run(getdns_eventloop *loop)
}
void
_getdns_default_eventloop_init(_getdns_default_eventloop *loop)
_getdns_select_eventloop_init(struct mem_funcs *mf, _getdns_select_eventloop *loop)
{
static getdns_eventloop_vmt default_eventloop_vmt = {
default_eventloop_cleanup,
default_eventloop_schedule,
default_eventloop_clear,
default_eventloop_run,
default_eventloop_run_once
static getdns_eventloop_vmt select_eventloop_vmt = {
select_eventloop_cleanup,
select_eventloop_schedule,
select_eventloop_clear,
select_eventloop_run,
select_eventloop_run_once
};
(void) memset(loop, 0, sizeof(_getdns_default_eventloop));
loop->loop.vmt = &default_eventloop_vmt;
(void) mf;
(void) memset(loop, 0, sizeof(_getdns_select_eventloop));
loop->loop.vmt = &select_eventloop_vmt;
}

View File

@ -0,0 +1,58 @@
/*
* \file select_eventloop.h
* @brief Build in default eventloop extension that uses select.
*
*/
/*
* Copyright (c) 2013, NLNet Labs, Verisign, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SELECT_EVENTLOOP_H_
#define SELECT_EVENTLOOP_H_
#include "config.h"
#include "getdns/getdns.h"
#include "getdns/getdns_extra.h"
/* No more than select's capability queries can be outstanding,
* The number of outstanding timeouts should be less or equal then
* the number of outstanding queries, so MAX_TIMEOUTS equal to
* FD_SETSIZE should be safe.
*/
#define MAX_TIMEOUTS FD_SETSIZE
/* Eventloop based on select */
typedef struct _getdns_select_eventloop {
getdns_eventloop loop;
getdns_eventloop_event *fd_events[FD_SETSIZE];
uint64_t fd_timeout_times[FD_SETSIZE];
getdns_eventloop_event *timeout_events[MAX_TIMEOUTS];
uint64_t timeout_times[MAX_TIMEOUTS];
} _getdns_select_eventloop;
void
_getdns_select_eventloop_init(struct mem_funcs *mf, _getdns_select_eventloop *loop);
#endif

View File

@ -52,32 +52,26 @@
#include "dnssec.h"
#include "stub.h"
#include "dict.h"
#include "mdns.h"
#include "debug.h"
/* cancel, cleanup and send timeout to callback */
static void
ub_resolve_timeout(void *arg)
void _getdns_call_user_callback(getdns_dns_req *dnsreq, getdns_dict *response)
{
getdns_dns_req *dns_req = (getdns_dns_req *) arg;
(void) _getdns_context_request_timed_out(dns_req);
}
_getdns_context_clear_outbound_request(dnsreq);
void _getdns_call_user_callback(getdns_dns_req *dns_req,
struct getdns_dict *response)
{
struct getdns_context *context = dns_req->context;
getdns_transaction_t trans_id = dns_req->trans_id;
getdns_callback_t cb = dns_req->user_callback;
void *user_arg = dns_req->user_pointer;
/* clean up */
_getdns_context_clear_outbound_request(dns_req);
_getdns_dns_req_free(dns_req);
context->processing = 1;
cb(context,
(response ? GETDNS_CALLBACK_COMPLETE : GETDNS_CALLBACK_ERROR),
response, user_arg, trans_id);
context->processing = 0;
#if defined(REQ_DEBUG) && REQ_DEBUG
debug_req(__FUNC__, *dnsreq->netreqs);
#endif
if (dnsreq->user_callback) {
dnsreq->context->processing = 1;
dnsreq->user_callback(dnsreq->context,
( ! response ? GETDNS_CALLBACK_ERROR
: dnsreq->request_timed_out ? GETDNS_CALLBACK_TIMEOUT
: GETDNS_CALLBACK_COMPLETE ),
response, dnsreq->user_pointer, dnsreq->trans_id);
dnsreq->context->processing = 0;
}
_getdns_dns_req_free(dnsreq);
}
static int
@ -101,17 +95,28 @@ void
_getdns_check_dns_req_complete(getdns_dns_req *dns_req)
{
getdns_network_req **netreq_p, *netreq;
int results_found = 0, r;
int results_found = 0, timed_out = 1, r;
uint64_t now_ms = 0;
for (netreq_p = dns_req->netreqs; (netreq = *netreq_p); netreq_p++)
if (!_getdns_netreq_finished(netreq))
return;
else if (netreq->response_len > 0)
results_found = 1;
else {
if (netreq->state != NET_REQ_TIMED_OUT)
timed_out = 0;
if (netreq->response_len > 0)
results_found = 1;
}
if (timed_out) {
_getdns_context_request_timed_out(dns_req);
return;
}
/* Do we have to check more suffixes on nxdomain/nodata?
*/
if (dns_req->suffix_appended && /* Something was appended */
if (dns_req->is_dns_request &&
dns_req->suffix_appended && /* Something was appended */
dns_req->suffix_len > 1 && /* Next suffix available */
no_answer(dns_req)) {
/* Remove suffix from name */
@ -137,16 +142,17 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
; (netreq = *netreq_p)
; netreq_p++ ) {
_getdns_netreq_reinit(netreq);
if ((r = _getdns_submit_netreq(netreq))) {
if ((r = _getdns_submit_netreq(netreq, &now_ms))) {
if (r == DNS_REQ_FINISHED)
return;
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
}
}
_getdns_check_dns_req_complete(dns_req);
return;
}
} else if (
dns_req->is_dns_request &&
( dns_req->append_name ==
GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE ||
dns_req->append_name ==
@ -175,21 +181,32 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
; (netreq = *netreq_p)
; netreq_p++ ) {
_getdns_netreq_reinit(netreq);
if ((r = _getdns_submit_netreq(netreq))) {
if ((r = _getdns_submit_netreq(netreq, &now_ms))) {
if (r == DNS_REQ_FINISHED)
return;
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
}
}
_getdns_check_dns_req_complete(dns_req);
return;
}
}
#if defined(REQ_DEBUG) && REQ_DEBUG
if (dns_req->internal_cb)
debug_req("CB Internal", *dns_req->netreqs);
else if (results_found)
debug_req("CB Complete", *dns_req->netreqs);
else
debug_req("CB Error ", *dns_req->netreqs);
#endif
if (dns_req->internal_cb) {
_getdns_context_clear_outbound_request(dns_req);
dns_req->internal_cb(dns_req);
else if (! results_found)
} else if (! results_found)
_getdns_call_user_callback(dns_req, NULL);
else if (dns_req->dnssec_return_validation_chain
else if (
dns_req->is_dns_request &&
(dns_req->dnssec_return_validation_chain
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
|| ( dns_req->dnssec_roadblock_avoidance
&& !dns_req->avoid_dnssec_roadblocks)
@ -197,14 +214,29 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
#ifdef STUB_NATIVE_DNSSEC
|| (dns_req->context->resolution_type == GETDNS_RESOLUTION_STUB
&& !dns_req->avoid_dnssec_roadblocks
&& (dns_req->dnssec_return_status ||
dns_req->dnssec_return_only_secure ||
dns_req->dnssec_return_all_statuses
))
#endif
)
)) {
/* Reschedule timeout for this DNS request
*/
if (dns_req->timeout.timeout_cb && dns_req->timeout.ev)
GETDNS_CLEAR_EVENT(dns_req->loop, &dns_req->timeout);
GETDNS_SCHEDULE_EVENT(dns_req->loop, -1,
_getdns_ms_until_expiry2(dns_req->expires, &now_ms),
getdns_eventloop_event_init(&dns_req->timeout, dns_req,
NULL, NULL, (getdns_eventloop_callback)
_getdns_validation_chain_timeout));
#if defined(REQ_DEBUG) && REQ_DEBUG
debug_req("getting validation chain for ", *dns_req->netreqs);
#endif
_getdns_get_validation_chain(dns_req);
else
} else
_getdns_call_user_callback(
dns_req, _getdns_create_getdns_response(dns_req));
}
@ -218,7 +250,7 @@ ub_resolve_event_callback(void* arg, int rcode, void *pkt, int pkt_len,
getdns_network_req *netreq = (getdns_network_req *) arg;
getdns_dns_req *dns_req = netreq->owner;
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_FINISHED);
/* parse */
if (getdns_apply_network_result(
netreq, rcode, pkt, pkt_len, sec, why_bogus)) {
@ -236,7 +268,7 @@ ub_resolve_callback(void* arg, int err, struct ub_result* ub_res)
getdns_network_req *netreq = (getdns_network_req *) arg;
getdns_dns_req *dns_req = netreq->owner;
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_FINISHED);
if (err != 0) {
_getdns_call_user_callback(dns_req, NULL);
return;
@ -257,28 +289,131 @@ ub_resolve_callback(void* arg, int err, struct ub_result* ub_res)
#endif
void _getdns_check_expired_pending_netreqs(
getdns_context *context, uint64_t *now_ms)
{
getdns_network_req *first;
assert(context);
while (context->pending_netreqs.count) {
first = (getdns_network_req *)
_getdns_rbtree_first(&context->pending_netreqs);
if (_getdns_ms_until_expiry2(first->owner->expires, now_ms) > 0)
break;
(void) _getdns_rbtree_delete(&context->pending_netreqs, first);
_getdns_netreq_change_state(first, NET_REQ_TIMED_OUT);
_getdns_check_dns_req_complete(first->owner);
}
first = context->pending_netreqs.count ? (getdns_network_req *)
_getdns_rbtree_first(&context->pending_netreqs) : NULL;
if (first == context->first_pending_netreq ||
(first && context->first_pending_netreq &&
first->owner->expires == context->first_pending_netreq->owner->expires))
return; /* Nothing changed */
if (context->first_pending_netreq)
GETDNS_CLEAR_EVENT( context->extension
, &context->pending_timeout_event);
if ((context->first_pending_netreq = first))
GETDNS_SCHEDULE_EVENT( context->extension, -1,
_getdns_ms_until_expiry2(first->owner->expires, now_ms),
&context->pending_timeout_event);
}
void
_getdns_netreq_change_state(
getdns_network_req *netreq, network_req_state new_state)
{
getdns_context *context;
uint64_t now_ms;
getdns_network_req *prev;
if (!netreq)
return;
if (!netreq->owner->is_dns_request) {
netreq->state = new_state;
return;
}
context = netreq->owner->context;
if (netreq->state != NET_REQ_IN_FLIGHT) {
if (new_state == NET_REQ_IN_FLIGHT)
context->netreqs_in_flight += 1;
netreq->state = new_state;
return;
}
if (new_state == NET_REQ_IN_FLIGHT) /* No change */
return;
netreq->state = new_state;
context->netreqs_in_flight -= 1;
now_ms = 0;
prev = NULL;
while (context->pending_netreqs.count > 0 &&
( context->limit_outstanding_queries > context->netreqs_in_flight
|| context->limit_outstanding_queries == 0 )) {
getdns_network_req *first = (getdns_network_req *)
_getdns_rbtree_first(&context->pending_netreqs);
/* To prevent loops due to _getdns_submit_netreq re-inserting
* because of errno == EMFILE
*/
if (first == prev)
break;
else
prev = first;
(void) _getdns_rbtree_delete(&context->pending_netreqs, first);
(void) _getdns_submit_netreq(first, &now_ms);
}
}
int
_getdns_submit_netreq(getdns_network_req *netreq)
_getdns_submit_netreq(getdns_network_req *netreq, uint64_t *now_ms)
{
getdns_return_t r;
getdns_dns_req *dns_req = netreq->owner;
getdns_context *context = dns_req->context;
char name[1024];
int dnsreq_freed = 0;
#ifdef HAVE_LIBUNBOUND
int ub_resolve_r;
#endif
if (context->limit_outstanding_queries > 0 &&
context->netreqs_in_flight >= context->limit_outstanding_queries) {
netreq->node.key = netreq;
if (_getdns_rbtree_insert(
&context->pending_netreqs, &netreq->node)) {
_getdns_check_expired_pending_netreqs(context, now_ms);
return GETDNS_RETURN_GOOD;
}
}
_getdns_netreq_change_state(netreq, NET_REQ_IN_FLIGHT);
debug_req("Submitting ", netreq);
#ifdef STUB_NATIVE_DNSSEC
# ifdef DNSSEC_ROADBLOCK_AVOIDANCE
if ((dns_req->context->resolution_type == GETDNS_RESOLUTION_RECURSING
if ((context->resolution_type == GETDNS_RESOLUTION_RECURSING
&& !dns_req->dnssec_roadblock_avoidance)
|| dns_req->avoid_dnssec_roadblocks) {
# else
if ( dns_req->context->resolution_type == GETDNS_RESOLUTION_RECURSING) {
if ( context->resolution_type == GETDNS_RESOLUTION_RECURSING) {
# endif
#else
if ( dns_req->context->resolution_type == GETDNS_RESOLUTION_RECURSING
if ( context->resolution_type == GETDNS_RESOLUTION_RECURSING
|| dns_req->dnssec_return_status
|| dns_req->dnssec_return_only_secure
|| dns_req->dnssec_return_all_statuses
@ -289,10 +424,13 @@ _getdns_submit_netreq(getdns_network_req *netreq)
dns_req->timeout.userarg = dns_req;
dns_req->timeout.read_cb = NULL;
dns_req->timeout.write_cb = NULL;
dns_req->timeout.timeout_cb = ub_resolve_timeout;
dns_req->timeout.timeout_cb =
(getdns_eventloop_callback)
_getdns_context_request_timed_out;
dns_req->timeout.ev = NULL;
if ((r = dns_req->loop->vmt->schedule(dns_req->loop, -1,
dns_req->context->timeout, &dns_req->timeout)))
_getdns_ms_until_expiry2(dns_req->expires, now_ms),
&dns_req->timeout)))
return r;
}
(void) gldns_wire2str_dname_buf(dns_req->name,
@ -301,15 +439,15 @@ _getdns_submit_netreq(getdns_network_req *netreq)
#ifdef HAVE_LIBUNBOUND
dns_req->freed = &dnsreq_freed;
#ifdef HAVE_UNBOUND_EVENT_API
if (_getdns_ub_loop_enabled(&dns_req->context->ub_loop))
ub_resolve_r = ub_resolve_event(dns_req->context->unbound_ctx,
name, netreq->request_type, netreq->owner->request_class,
if (_getdns_ub_loop_enabled(&context->ub_loop))
ub_resolve_r = ub_resolve_event(context->unbound_ctx,
name, netreq->request_type, dns_req->request_class,
netreq, ub_resolve_event_callback, &(netreq->unbound_id)) ?
GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD;
else
#endif
ub_resolve_r = ub_resolve_async(dns_req->context->unbound_ctx,
name, netreq->request_type, netreq->owner->request_class,
ub_resolve_r = ub_resolve_async(context->unbound_ctx,
name, netreq->request_type, dns_req->request_class,
netreq, ub_resolve_callback, &(netreq->unbound_id)) ?
GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD;
if (dnsreq_freed)
@ -322,7 +460,7 @@ _getdns_submit_netreq(getdns_network_req *netreq)
}
/* Submit with stub resolver */
dns_req->freed = &dnsreq_freed;
r = _getdns_submit_stub_request(netreq);
r = _getdns_submit_stub_request(netreq, now_ms);
if (dnsreq_freed)
return DNS_REQ_FINISHED;
dns_req->freed = NULL;
@ -421,6 +559,7 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
getdns_dns_req *req;
getdns_dict *localnames_response;
size_t i;
uint64_t now_ms = 0;
if (!context || !name || (!callbackfn && !internal_cb))
return GETDNS_RETURN_INVALID_PARAMETER;
@ -438,7 +577,7 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
/* create the request */
if (!(req = _getdns_dns_req_new(
context, loop, name, request_type, extensions)))
context, loop, name, request_type, extensions, &now_ms)))
return GETDNS_RETURN_MEMORY_ERROR;
req->user_pointer = userarg;
@ -456,13 +595,13 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
for ( netreq_p = req->netreqs
; !r && (netreq = *netreq_p)
; netreq_p++) {
if ((r = _getdns_submit_netreq(netreq))) {
if ((r = _getdns_submit_netreq(netreq, &now_ms))) {
if (r == DNS_REQ_FINISHED) {
if (return_netreq_p)
*return_netreq_p = NULL;
return GETDNS_RETURN_GOOD;
}
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
}
}
@ -471,11 +610,34 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
if (!(r = _getdns_context_local_namespace_resolve(
req, &localnames_response))) {
req->is_dns_request = 0;
_getdns_call_user_callback
( req, localnames_response);
break;
}
#ifdef HAVE_MDNS_SUPPORT
} else if (context->namespaces[i] == GETDNS_NAMESPACE_MDNS) {
/* Check whether the name belongs in the MDNS space */
if (!(r = _getdns_mdns_namespace_check(req)))
{
req->is_dns_request = 0;
// Submit the query to the MDNS transport.
for (netreq_p = req->netreqs
; !r && (netreq = *netreq_p)
; netreq_p++) {
if ((r = _getdns_submit_mdns_request(netreq))) {
if (r == DNS_REQ_FINISHED) {
if (return_netreq_p)
*return_netreq_p = NULL;
return GETDNS_RETURN_GOOD;
}
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
}
}
/* Stop processing more namespaces, since there was a match */
break;
}
#endif /* HAVE_MDNS_SUPPORT */
} else if (context->namespaces[i] == GETDNS_NAMESPACE_DNS) {
/* TODO: We will get a good return code here even if
@ -486,13 +648,13 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
for ( netreq_p = req->netreqs
; !r && (netreq = *netreq_p)
; netreq_p++) {
if ((r = _getdns_submit_netreq(netreq))) {
if ((r = _getdns_submit_netreq(netreq, &now_ms))) {
if (r == DNS_REQ_FINISHED) {
if (return_netreq_p)
*return_netreq_p = NULL;
return GETDNS_RETURN_GOOD;
}
netreq->state = NET_REQ_FINISHED;
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
}
}
break;

View File

@ -45,8 +45,20 @@
#define DNS_REQ_FINISHED -1
void _getdns_call_user_callback(getdns_dns_req *, getdns_dict *);
/* Change state of the netreq req.
* - Increments context->netreqs_in_flight
* when state changes from NOT_SENT to IN_FLIGHT
* - Decrements context->netreqs_in_flight
* when state changes from IN_FLIGHT to FINISHED, TIMED_OUT or ERRORED
* - Resubmits NOT_SENT netreqs from context->pending_netreqs,
* when # pending_netreqs < limit_outstanding_queries
*/
void _getdns_netreq_change_state(
getdns_network_req *netreq, network_req_state new_state);
void _getdns_check_dns_req_complete(getdns_dns_req *dns_req);
int _getdns_submit_netreq(getdns_network_req *netreq);
int _getdns_submit_netreq(getdns_network_req *netreq, uint64_t *now_ms);
getdns_return_t

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,21 @@ struct ev_loop;
/**
* \ingroup eventloops
*/
/* For libevent, which we are using for these examples */
/**
* Associate the libev ev_loop with the context, so that all
* asynchronous requests will schedule Input/Output with it.
* Synchronous requests will still use a default eventloop based on `poll()`.
* Applications need to @code #include <getdns/getdns_ext_libev.h> @endcode
* and link with libgetdns_ext_ev to use this function.
* getdns needs to have been configured with --with-libev for this
* extension to be available.
* @param context The context to configure
* @param ev_loop The libev event loop to associate with this context.
* @return GETDNS_RETURN_GOOD when successful
* @return GETDNS_RETURN_BAD_CONTEXT when context is NULL
* @return GETDNS_RETURN_INVALID_PARAMETER when ev_loop is NULL
* @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated
*/
getdns_return_t
getdns_extension_set_libev_loop(struct getdns_context *context,
struct ev_loop *ev_loop);

View File

@ -47,7 +47,21 @@ struct event_base;
/**
* \ingroup eventloops
*/
/* For libevent, which we are using for these examples */
/**
* Associate the libevent event_base with the context, so that all
* asynchronous requests will schedule Input/Output with it.
* Synchronous requests will still use a default eventloop based on `poll()`.
* Applications need to @code #include <getdns/getdns_ext_libevent.h> @endcode
* and link with libgetdns_ext_event to use this function.
* getdns needs to have been configured with --with-libevent for this
* extension to be available.
* @param context The context to configure
* @param this_event_base The libevent event base to associate with this context.
* @return GETDNS_RETURN_GOOD when successful
* @return GETDNS_RETURN_BAD_CONTEXT when context is NULL
* @return GETDNS_RETURN_INVALID_PARAMETER when this_event_base is NULL
* @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated
*/
getdns_return_t
getdns_extension_set_libevent_base(struct getdns_context *context,
struct event_base *this_event_base);

View File

@ -47,7 +47,21 @@ struct uv_loop_s;
/**
* \ingroup eventloops
*/
/* For libevent, which we are using for these examples */
/**
* Associate the libuv uv_loop with the context, so that all
* asynchronous requests will schedule Input/Output with it.
* Synchronous requests will still use a default eventloop based on `poll()`.
* Applications need to @code #include <getdns/getdns_ext_libuv.h> @endcode
* and link with libgetdns_ext_uv to use this function.
* getdns needs to have been configured with --with-libuv for this
* extension to be available.
* @param context The context to configure
* @param uv_loop The libuv event loop to associate with this context.
* @return GETDNS_RETURN_GOOD when successful
* @return GETDNS_RETURN_BAD_CONTEXT when context is NULL
* @return GETDNS_RETURN_INVALID_PARAMETER when uv_loop is NULL
* @return GETDNS_RETURN_MEMORY_ERROR when memory could not be allocated
*/
getdns_return_t
getdns_extension_set_libuv_loop(struct getdns_context *context,
struct uv_loop_s *uv_loop);

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,7 @@ gldns_buffer_new(size_t capacity)
buffer->_position = 0;
buffer->_limit = buffer->_capacity = capacity;
buffer->_fixed = 0;
buffer->_vfixed = 0;
buffer->_status_err = 0;
gldns_buffer_invariant(buffer);
@ -48,6 +49,9 @@ gldns_buffer_new_frm_data(gldns_buffer *buffer, void *data, size_t size)
buffer->_position = 0;
buffer->_limit = buffer->_capacity = size;
buffer->_fixed = 0;
buffer->_vfixed = 0;
if (!buffer->_fixed && buffer->_data)
free(buffer->_data);
buffer->_data = malloc(size);
if(!buffer->_data) {
buffer->_status_err = 1;
@ -66,6 +70,17 @@ gldns_buffer_init_frm_data(gldns_buffer *buffer, void *data, size_t size)
buffer->_data = data;
buffer->_capacity = buffer->_limit = size;
buffer->_fixed = 1;
buffer->_vfixed = 0;
}
void
gldns_buffer_init_vfixed_frm_data(gldns_buffer *buffer, void *data, size_t size)
{
memset(buffer, 0, sizeof(*buffer));
buffer->_data = data;
buffer->_capacity = buffer->_limit = size;
buffer->_fixed = 1;
buffer->_vfixed = 1;
}
int
@ -120,20 +135,19 @@ gldns_buffer_printf(gldns_buffer *buffer, const char *format, ...)
remaining = gldns_buffer_remaining(buffer);
va_start(args, format);
written = _gldns_vsnprintf((char*)gldns_buffer_current(buffer),
remaining, format, args);
written = vsnprintf((char *) gldns_buffer_current(buffer), remaining,
format, args);
va_end(args);
if (written == -1) {
buffer->_status_err = 1;
return -1;
} else if (!buffer->_fixed && (size_t) written >= remaining) {
} else if (!buffer->_vfixed && (size_t) written >= remaining) {
if (!gldns_buffer_reserve(buffer, (size_t) written + 1)) {
buffer->_status_err = 1;
return -1;
}
va_start(args, format);
written = _gldns_vsnprintf(
(char *) gldns_buffer_current(buffer),
written = vsnprintf((char *) gldns_buffer_current(buffer),
gldns_buffer_remaining(buffer), format, args);
va_end(args);
if (written == -1) {

View File

@ -27,21 +27,6 @@ extern "C" {
# endif
#endif
#ifndef USE_WINSOCK
#define _gldns_vsnprintf vsnprintf
#else
/* Unlike Linux and BSD, vsnprintf on Windows returns -1 on overflow.
* Here it is redefined to always return the amount printed
* if enough space had been available.
*/
INLINE int
_gldns_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
int r = vsnprintf(str, size, format, ap);
return r == -1 ? _vscprintf(format, ap) : r;
}
#endif
/*
* Copy data allowing for unaligned accesses in network byte order
* (big endian).
@ -145,6 +130,17 @@ struct gldns_buffer
/** If the buffer is fixed it cannot be resized */
unsigned _fixed : 1;
/** If the buffer is vfixed, no more than capacity bytes willl be
* written to _data, however the _position counter will be updated
* with the amount that would have been written in consecutive
* writes. This allows for a modus operandi in which a sequence is
* written on a fixed capacity buffer (perhaps with _data on stack).
* When everything could be written, then the _data is immediately
* usable, if not, then a buffer could be allocated sized precisely
* to fit the data for a second attempt.
*/
unsigned _vfixed : 1;
/** The current state of the buffer. If writing to the buffer fails
* for any reason, this value is changed. This way, you can perform
* multiple writes in sequence and check for success afterwards. */
@ -162,9 +158,9 @@ INLINE void
gldns_buffer_invariant(gldns_buffer *buffer)
{
assert(buffer != NULL);
assert(buffer->_position <= buffer->_limit || buffer->_fixed);
assert(buffer->_position <= buffer->_limit || buffer->_vfixed);
assert(buffer->_limit <= buffer->_capacity);
assert(buffer->_data != NULL || (buffer->_capacity == 0 && buffer->_fixed));
assert(buffer->_data != NULL || (buffer->_vfixed && buffer->_capacity == 0));
}
#endif
@ -196,6 +192,19 @@ void gldns_buffer_new_frm_data(gldns_buffer *buffer, void *data, size_t size);
*/
void gldns_buffer_init_frm_data(gldns_buffer *buffer, void *data, size_t size);
/**
* Setup a buffer with the data pointed to. No data copied, no memory allocs.
* The buffer is "virtually" fixed. Writes beyond size (the capacity) will
* only update position, but no data will be written beyond capacity. This
* allows to determine how big the buffer should have been to contain all the
* written data, by looking at the position with gldns_buffer_position(),
* similarly to the return value of POSIX's snprintf.
* \param[in] buffer pointer to the buffer to put the data in
* \param[in] data the data to encapsulate in the buffer
* \param[in] size the size of the data
*/
void gldns_buffer_init_vfixed_frm_data(gldns_buffer *buffer, void *data, size_t size);
/**
* clears the buffer and make it ready for writing. The buffer's limit
* is set to the capacity and the position is set to 0.
@ -259,7 +268,7 @@ gldns_buffer_position(gldns_buffer *buffer)
INLINE void
gldns_buffer_set_position(gldns_buffer *buffer, size_t mark)
{
assert(mark <= buffer->_limit || buffer->_fixed);
assert(mark <= buffer->_limit || buffer->_vfixed);
buffer->_position = mark;
}
@ -273,7 +282,7 @@ gldns_buffer_set_position(gldns_buffer *buffer, size_t mark)
INLINE void
gldns_buffer_skip(gldns_buffer *buffer, ssize_t count)
{
assert(buffer->_position + count <= buffer->_limit || buffer->_fixed);
assert(buffer->_position + count <= buffer->_limit || buffer->_vfixed);
buffer->_position += count;
}
@ -345,7 +354,7 @@ int gldns_buffer_reserve(gldns_buffer *buffer, size_t amount);
INLINE uint8_t *
gldns_buffer_at(const gldns_buffer *buffer, size_t at)
{
assert(at <= buffer->_limit || buffer->_fixed);
assert(at <= buffer->_limit || buffer->_vfixed);
return buffer->_data + at;
}
@ -395,6 +404,7 @@ INLINE size_t
gldns_buffer_remaining_at(gldns_buffer *buffer, size_t at)
{
gldns_buffer_invariant(buffer);
assert(at <= buffer->_limit || buffer->_vfixed);
return at < buffer->_limit ? buffer->_limit - at : 0;
}
@ -447,7 +457,7 @@ gldns_buffer_available(gldns_buffer *buffer, size_t count)
INLINE void
gldns_buffer_write_at(gldns_buffer *buffer, size_t at, const void *data, size_t count)
{
if (!buffer->_fixed)
if (!buffer->_vfixed)
assert(gldns_buffer_available_at(buffer, at, count));
else if (gldns_buffer_remaining_at(buffer, at) == 0)
return;
@ -459,6 +469,30 @@ gldns_buffer_write_at(gldns_buffer *buffer, size_t at, const void *data, size_t
memcpy(buffer->_data + at, data, count);
}
/**
* set the given byte to the buffer at the specified position
* \param[in] buffer the buffer
* \param[in] at the position (in number of bytes) to write the data at
* \param[in] c the byte to set to the buffer
* \param[in] count the number of bytes of bytes to write
*/
INLINE void
gldns_buffer_set_at(gldns_buffer *buffer, size_t at, int c, size_t count)
{
if (!buffer->_vfixed)
assert(gldns_buffer_available_at(buffer, at, count));
else if (gldns_buffer_remaining_at(buffer, at) == 0)
return;
else if (count > gldns_buffer_remaining_at(buffer, at)) {
memset(buffer->_data + at, c,
gldns_buffer_remaining_at(buffer, at));
return;
}
memset(buffer->_data + at, c, count);
}
/**
* writes count bytes of data to the current position of the buffer
* \param[in] buffer the buffer
@ -504,7 +538,7 @@ gldns_buffer_write_string(gldns_buffer *buffer, const char *str)
INLINE void
gldns_buffer_write_u8_at(gldns_buffer *buffer, size_t at, uint8_t data)
{
if (buffer->_fixed && at + sizeof(data) > buffer->_limit) return;
if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
buffer->_data[at] = data;
}
@ -530,7 +564,7 @@ gldns_buffer_write_u8(gldns_buffer *buffer, uint8_t data)
INLINE void
gldns_buffer_write_u16_at(gldns_buffer *buffer, size_t at, uint16_t data)
{
if (buffer->_fixed && at + sizeof(data) > buffer->_limit) return;
if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
gldns_write_uint16(buffer->_data + at, data);
}
@ -556,7 +590,7 @@ gldns_buffer_write_u16(gldns_buffer *buffer, uint16_t data)
INLINE void
gldns_buffer_write_u32_at(gldns_buffer *buffer, size_t at, uint32_t data)
{
if (buffer->_fixed && at + sizeof(data) > buffer->_limit) return;
if (buffer->_vfixed && at + sizeof(data) > buffer->_limit) return;
assert(gldns_buffer_available_at(buffer, at, sizeof(data)));
gldns_write_uint32(buffer->_data + at, data);
}
@ -570,7 +604,7 @@ gldns_buffer_write_u32_at(gldns_buffer *buffer, size_t at, uint32_t data)
INLINE void
gldns_buffer_write_u48_at(gldns_buffer *buffer, size_t at, uint64_t data)
{
if (buffer->_fixed && at + 6 > buffer->_limit) return;
if (buffer->_vfixed && at + 6 > buffer->_limit) return;
assert(gldns_buffer_available_at(buffer, at, 6));
gldns_write_uint48(buffer->_data + at, data);
}

View File

@ -23,6 +23,15 @@
#ifdef HAVE_OPENSSL_ENGINE_H
# include <openssl/engine.h>
#endif
#ifdef HAVE_OPENSSL_BN_H
#include <openssl/bn.h>
#endif
#ifdef HAVE_OPENSSL_RSA_H
#include <openssl/rsa.h>
#endif
#ifdef HAVE_OPENSSL_DSA_H
#include <openssl/dsa.h>
#endif
#endif /* HAVE_SSL */
size_t
@ -215,6 +224,7 @@ gldns_key_buf2dsa_raw(unsigned char* key, size_t len)
BN_free(Y);
return NULL;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
#ifndef S_SPLINT_S
dsa->p = P;
dsa->q = Q;
@ -222,6 +232,25 @@ gldns_key_buf2dsa_raw(unsigned char* key, size_t len)
dsa->pub_key = Y;
#endif /* splint */
#else /* OPENSSL_VERSION_NUMBER */
if (!DSA_set0_pqg(dsa, P, Q, G)) {
/* QPG not yet attached, need to free */
BN_free(Q);
BN_free(P);
BN_free(G);
DSA_free(dsa);
BN_free(Y);
return NULL;
}
if (!DSA_set0_key(dsa, Y, NULL)) {
/* QPG attached, cleaned up by DSA_fre() */
DSA_free(dsa);
BN_free(Y);
return NULL;
}
#endif
return dsa;
}
@ -273,11 +302,21 @@ gldns_key_buf2rsa_raw(unsigned char* key, size_t len)
BN_free(modulus);
return NULL;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
#ifndef S_SPLINT_S
rsa->n = modulus;
rsa->e = exponent;
#endif /* splint */
#else /* OPENSSL_VERSION_NUMBER */
if (!RSA_set0_key(rsa, modulus, exponent, NULL)) {
BN_free(exponent);
BN_free(modulus);
RSA_free(rsa);
return NULL;
}
#endif
return rsa;
}
@ -349,6 +388,27 @@ gldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo)
}
#endif /* USE_ECDSA */
#ifdef USE_ED25519
EVP_PKEY*
gldns_ed255192pkey_raw(const unsigned char* key, size_t keylen)
{
/* ASN1 for ED25519 is 302a300506032b6570032100 <32byteskey> */
uint8_t pre[] = {0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
0x70, 0x03, 0x21, 0x00};
int pre_len = 12;
uint8_t buf[256];
EVP_PKEY *evp_key;
/* pp gets modified by d2i() */
const unsigned char* pp = (unsigned char*)buf;
if(keylen != 32 || keylen + pre_len > sizeof(buf))
return NULL; /* wrong length */
memmove(buf, pre, pre_len);
memmove(buf+pre_len, key, keylen);
evp_key = d2i_PUBKEY(NULL, &pp, (int)(pre_len+keylen));
return evp_key;
}
#endif /* USE_ED25519 */
int
gldns_digest_evp(unsigned char* data, unsigned int len, unsigned char* dest,
const EVP_MD* md)

View File

@ -92,6 +92,15 @@ EVP_PKEY* gldns_ecdsa2pkey_raw(unsigned char* key, size_t keylen, uint8_t algo);
*/
RSA *gldns_key_buf2rsa_raw(unsigned char* key, size_t len);
/**
* Converts a holding buffer with key material to EVP PKEY in openssl.
* Only available if ldns was compiled with ED25519.
* \param[in] key the uncompressed wireformat of the key.
* \param[in] len length of key data
* \return the key or NULL on error.
*/
EVP_PKEY* gldns_ed255192pkey_raw(const unsigned char* key, size_t len);
/**
* Utility function to calculate hash using generic EVP_MD pointer.
* \param[in] data the data to hash.

View File

@ -120,6 +120,10 @@ gldns_fget_token_l(FILE *f, char *token, const char *delim, size_t limit, int *l
if (line_nr) {
*line_nr = *line_nr + 1;
}
if (limit > 0 && (i >= limit || (size_t)(t-token) >= limit)) {
*t = '\0';
return -1;
}
*t++ = ' ';
prev_c = c;
continue;

View File

@ -402,10 +402,12 @@ gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz,
/* ........ ........ ....4444 4....... ........ */
c = src[3] >> 7 ;
/* fallthrough */
case 3: dst[4] = b32[(src[2] & 0x0f) << 1 | c];
/* ........ .......3 3333.... ........ ........ */
c = src[2] >> 4 ;
/* fallthrough */
case 2: dst[3] = b32[(src[1] & 0x01) << 4 | c];
/* ........ ..22222. ........ ........ ........ */
@ -413,6 +415,7 @@ gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz,
/* .....111 11...... ........ ........ ........ */
c = src[1] >> 6 ;
/* fallthrough */
case 1: dst[1] = b32[(src[0] & 0x07) << 2 | c];
/* 00000... ........ ........ ........ ........ */
@ -423,9 +426,12 @@ gldns_b32_ntop_base(const uint8_t* src, size_t src_sz, char* dst, size_t dst_sz,
switch (src_sz) {
case 1: dst[2] = '=';
dst[3] = '=';
/* fallthrough */
case 2: dst[4] = '=';
/* fallthrough */
case 3: dst[5] = '=';
dst[6] = '=';
/* fallthrough */
case 4: dst[7] = '=';
}
}
@ -537,15 +543,18 @@ gldns_b32_pton_base(const char* src, size_t src_sz, uint8_t* dst, size_t dst_sz,
/* ........ ........ ........ .55555.. ........ */
/* ........ ........ ....4444 4....... ........ */
dst[3] = buf[4] << 7 | buf[5] << 2 | buf[6] >> 3;
/* fallthrough */
case 5: /* ........ ........ ....4444 4....... ........ */
/* ........ .......3 3333.... ........ ........ */
dst[2] = buf[3] << 4 | buf[4] >> 1;
/* fallthrough */
case 4: /* ........ .......3 3333.... ........ ........ */
/* ........ ..22222. ........ ........ ........ */
/* .....111 11...... ........ ........ ........ */
dst[1] = buf[1] << 6 | buf[2] << 1 | buf[3] >> 4;
/* fallthrough */
case 2: /* .....111 11...... ........ ........ ........ */
/* 00000... ........ ........ ........ ........ */

View File

@ -175,7 +175,7 @@ static const gldns_rdf_type type_tkey_wireformat[] = {
GLDNS_RDF_TYPE_TIME,
GLDNS_RDF_TYPE_TIME,
GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_TSIGERROR,
GLDNS_RDF_TYPE_INT16_DATA,
GLDNS_RDF_TYPE_INT16_DATA,
};
@ -185,7 +185,7 @@ static const gldns_rdf_type type_tsig_wireformat[] = {
GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_INT16_DATA,
GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_INT16,
GLDNS_RDF_TYPE_TSIGERROR,
GLDNS_RDF_TYPE_INT16_DATA
};
static const gldns_rdf_type type_tlsa_wireformat[] = {
@ -341,8 +341,12 @@ static gldns_rr_descriptor rdata_field_descriptors[] = {
{GLDNS_RR_TYPE_NSEC3PARAM, "NSEC3PARAM", 4, 4, type_nsec3param_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
/* 52 */
{GLDNS_RR_TYPE_TLSA, "TLSA", 4, 4, type_tlsa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
/*53 */
#ifdef DRAFT_RRTYPES
{GLDNS_RR_TYPE_SMIMEA, "SMIMEA", 4, 4, type_tlsa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
#else
{GLDNS_RR_TYPE_NULL, "TYPE53", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
#endif
{GLDNS_RR_TYPE_NULL, "TYPE54", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
/* 55
* Hip ends with 0 or more Rendezvous Servers represented as dname's.
@ -600,6 +604,12 @@ static gldns_rr_descriptor rdata_field_descriptors[] = {
{GLDNS_RR_TYPE_URI, "URI", 3, 3, type_uri_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
/* 257 */
{GLDNS_RR_TYPE_CAA, "CAA", 3, 3, type_caa_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
#ifdef DRAFT_RRTYPES
/* 258 */
{GLDNS_RR_TYPE_AVC, "AVC", 1, 0, NULL, GLDNS_RDF_TYPE_STR, GLDNS_RR_NO_COMPRESS, 0 },
#else
{GLDNS_RR_TYPE_NULL, "TYPE258", 1, 1, type_0_wireformat, GLDNS_RDF_TYPE_NONE, GLDNS_RR_NO_COMPRESS, 0 },
#endif
/* split in array, no longer contiguous */

View File

@ -38,7 +38,7 @@ extern "C" {
#define GLDNS_KEY_REVOKE_KEY 0x0080 /* used to revoke KSK, rfc 5011 */
/* The first fields are contiguous and can be referenced instantly */
#define GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON 258
#define GLDNS_RDATA_FIELD_DESCRIPTORS_COMMON 259
/** lookuptable for rr classes */
extern struct gldns_struct_lookup_table* gldns_rr_classes;
@ -195,7 +195,7 @@ enum gldns_enum_rr_type
GLDNS_RR_TYPE_TALINK = 58,
GLDNS_RR_TYPE_CDS = 59, /** RFC 7344 */
GLDNS_RR_TYPE_CDNSKEY = 60, /** RFC 7344 */
GLDNS_RR_TYPE_OPENPGPKEY = 61, /* draft-ietf-dane-openpgpkey */
GLDNS_RR_TYPE_OPENPGPKEY = 61, /* RFC 7929 */
GLDNS_RR_TYPE_CSYNC = 62, /* RFC 7477 */
GLDNS_RR_TYPE_SPF = 99, /* RFC 4408 */
@ -226,6 +226,7 @@ enum gldns_enum_rr_type
GLDNS_RR_TYPE_ANY = 255,
GLDNS_RR_TYPE_URI = 256, /* RFC 7553 */
GLDNS_RR_TYPE_CAA = 257, /* RFC 6844 */
GLDNS_RR_TYPE_AVC = 258,
/** DNSSEC Trust Authorities */
GLDNS_RR_TYPE_TA = 32768,
@ -350,6 +351,9 @@ enum gldns_enum_rdf_type
*/
GLDNS_RDF_TYPE_LONG_STR,
/** TSIG extended 16bit error value */
GLDNS_RDF_TYPE_TSIGERROR,
/* Aliases */
GLDNS_RDF_TYPE_BITMAP = GLDNS_RDF_TYPE_NSEC
};
@ -372,6 +376,8 @@ enum gldns_enum_algorithm
GLDNS_ECC_GOST = 12, /* RFC 5933 */
GLDNS_ECDSAP256SHA256 = 13, /* RFC 6605 */
GLDNS_ECDSAP384SHA384 = 14, /* RFC 6605 */
GLDNS_ED25519 = 15, /* RFC 8080 */
GLDNS_ED448 = 16, /* RFC 8080 */
GLDNS_INDIRECT = 252,
GLDNS_PRIVATEDNS = 253,
GLDNS_PRIVATEOID = 254
@ -420,7 +426,7 @@ enum gldns_enum_edns_option
GLDNS_EDNS_DAU = 5, /* RFC6975 */
GLDNS_EDNS_DHU = 6, /* RFC6975 */
GLDNS_EDNS_N3U = 7, /* RFC6975 */
GLDNS_EDNS_CLIENT_SUBNET = 8, /* draft-vandergaast-edns-client-subnet */
GLDNS_EDNS_CLIENT_SUBNET = 8, /* RFC7871 */
GLDNS_EDNS_KEEPALIVE = 11, /* draft-ietf-dnsop-edns-tcp-keepalive*/
GLDNS_EDNS_PADDING = 12 /* RFC7830 */
};
@ -428,6 +434,15 @@ typedef enum gldns_enum_edns_option gldns_edns_option;
#define GLDNS_EDNS_MASK_DO_BIT 0x8000
/** TSIG and TKEY extended rcodes (16bit), 0-15 are the normal rcodes. */
#define GLDNS_TSIG_ERROR_NOERROR 0
#define GLDNS_TSIG_ERROR_BADSIG 16
#define GLDNS_TSIG_ERROR_BADKEY 17
#define GLDNS_TSIG_ERROR_BADTIME 18
#define GLDNS_TSIG_ERROR_BADMODE 19
#define GLDNS_TSIG_ERROR_BADNAME 20
#define GLDNS_TSIG_ERROR_BADALG 21
/**
* Contains all information about resource record types.
*

View File

@ -328,7 +328,7 @@ rrinternal_write_typeclassttl(gldns_buffer* strbuf, uint8_t* rr, size_t len,
/** find delimiters for type */
static const char*
rrinternal_get_delims(gldns_rdf_type rdftype, uint16_t r_cnt, uint16_t r_max)
rrinternal_get_delims(gldns_rdf_type rdftype, size_t r_cnt, size_t r_max)
{
switch(rdftype) {
case GLDNS_RDF_TYPE_B64 :
@ -463,7 +463,7 @@ rrinternal_parse_unknown(gldns_buffer* strbuf, char* token, size_t token_len,
static int
rrinternal_parse_rdf(gldns_buffer* strbuf, char* token, size_t token_len,
uint8_t* rr, size_t rr_len, size_t* rr_cur_len, gldns_rdf_type rdftype,
uint16_t rr_type, uint16_t r_cnt, uint16_t r_max, size_t dname_len,
uint16_t rr_type, size_t r_cnt, size_t r_max, size_t dname_len,
uint8_t* origin, size_t origin_len)
{
size_t len;
@ -613,7 +613,7 @@ rrinternal_parse_rdata(gldns_buffer* strbuf, char* token, size_t token_len,
uint8_t* origin, size_t origin_len)
{
const gldns_rr_descriptor *desc = gldns_rr_descript((uint16_t)rr_type);
uint16_t r_cnt, r_min, r_max;
size_t r_cnt, r_min, r_max;
size_t rr_cur_len = dname_len + 10, pre_data_pos, token_strlen;
int was_unknown_rr_format = 0, parens = 0, status, quoted;
const char* delimiters;
@ -664,6 +664,14 @@ rrinternal_parse_rdata(gldns_buffer* strbuf, char* token, size_t token_len,
&pre_data_pos, delimiters,
rdftype, &token_strlen))
break;
} else if(rdftype == GLDNS_RDF_TYPE_INT16_DATA &&
strcmp(token, "0")!=0) {
/* affix len and b64 fields */
if(!gldns_affix_token(strbuf, token,
&token_len, &quoted, &parens,
&pre_data_pos, delimiters,
rdftype, &token_strlen))
break;
}
/* normal RR */
@ -693,7 +701,7 @@ rrinternal_parse_rdata(gldns_buffer* strbuf, char* token, size_t token_len,
gldns_buffer_position(strbuf));
}
/* write rdata length */
gldns_write_uint16(rr+dname_len+8, rr_cur_len-dname_len-10);
gldns_write_uint16(rr+dname_len+8, (uint16_t)(rr_cur_len-dname_len-10));
*rr_len = rr_cur_len;
return GLDNS_WIREPARSE_ERR_OK;
}
@ -861,6 +869,8 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
/* we can have the situation, where we've read ok, but still got
* no bytes to play with, in this case size is 0 */
if(size == 0) {
if(*len > 0)
rr[0] = 0;
*len = 0;
*dname_len = 0;
return GLDNS_WIREPARSE_ERR_OK;
@ -868,6 +878,7 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
if(strncmp(line, "$ORIGIN", 7) == 0 && isspace((unsigned char)line[7])) {
int s;
strlcpy((char*)rr, line, *len);
*len = 0;
*dname_len = 0;
if(!parse_state) return GLDNS_WIREPARSE_ERR_OK;
@ -878,12 +889,19 @@ int gldns_fp2wire_rr_buf(FILE* in, uint8_t* rr, size_t* len, size_t* dname_len,
return s;
} else if(strncmp(line, "$TTL", 4) == 0 && isspace((unsigned char)line[4])) {
const char* end = NULL;
strlcpy((char*)rr, line, *len);
*len = 0;
*dname_len = 0;
if(!parse_state) return GLDNS_WIREPARSE_ERR_OK;
parse_state->default_ttl = gldns_str2period(
gldns_strip_ws(line+5), &end);
} else if (strncmp(line, "$INCLUDE", 8) == 0) {
strlcpy((char*)rr, line, *len);
*len = 0;
*dname_len = 0;
return GLDNS_WIREPARSE_ERR_INCLUDE;
} else if (strncmp(line, "$", 1) == 0) {
strlcpy((char*)rr, line, *len);
*len = 0;
*dname_len = 0;
return GLDNS_WIREPARSE_ERR_INCLUDE;
@ -940,6 +958,8 @@ int gldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
return gldns_str2wire_time_buf(str, rd, len);
case GLDNS_RDF_TYPE_PERIOD:
return gldns_str2wire_period_buf(str, rd, len);
case GLDNS_RDF_TYPE_TSIGTIME:
return gldns_str2wire_tsigtime_buf(str, rd, len);
case GLDNS_RDF_TYPE_LOC:
return gldns_str2wire_loc_buf(str, rd, len);
case GLDNS_RDF_TYPE_WKS:
@ -964,6 +984,8 @@ int gldns_str2wire_rdf_buf(const char* str, uint8_t* rd, size_t* len,
return gldns_str2wire_tag_buf(str, rd, len);
case GLDNS_RDF_TYPE_LONG_STR:
return gldns_str2wire_long_str_buf(str, rd, len);
case GLDNS_RDF_TYPE_TSIGERROR:
return gldns_str2wire_tsigerror_buf(str, rd, len);
case GLDNS_RDF_TYPE_HIP:
return gldns_str2wire_hip_buf(str, rd, len);
case GLDNS_RDF_TYPE_INT16_DATA:
@ -1168,6 +1190,10 @@ int gldns_str2wire_b64_buf(const char* str, uint8_t* rd, size_t* len)
{
size_t sz = gldns_b64_pton_calculate_size(strlen(str));
int n;
if(strcmp(str, "0") == 0) {
*len = 0;
return GLDNS_WIREPARSE_ERR_OK;
}
if(*len < sz)
return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
n = gldns_b64_pton(str, rd, *len);
@ -1201,6 +1227,10 @@ int gldns_str2wire_hex_buf(const char* str, uint8_t* rd, size_t* len)
s++;
continue;
}
if(dlen == 0 && *s == '0' && *(s+1) == 0) {
*len = 0;
return GLDNS_WIREPARSE_ERR_OK;
}
if(!isxdigit((unsigned char)*s))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_HEX, s-str);
if(*len < dlen/2 + 1)
@ -1341,6 +1371,21 @@ int gldns_str2wire_alg_buf(const char* str, uint8_t* rd, size_t* len)
return GLDNS_WIREPARSE_ERR_OK;
}
int gldns_str2wire_tsigerror_buf(const char* str, uint8_t* rd, size_t* len)
{
gldns_lookup_table *lt = gldns_lookup_by_name(gldns_tsig_errors, str);
if(*len < 2)
return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
if(lt) {
gldns_write_uint16(rd, (uint16_t)lt->id);
*len = 2;
} else {
/* try as-is (a number) */
return gldns_str2wire_int16_buf(str, rd, len);
}
return GLDNS_WIREPARSE_ERR_OK;
}
int gldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len)
{
/* convert a time YYYYDDMMHHMMSS to wireformat */
@ -1369,7 +1414,7 @@ int gldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len)
if (tm.tm_sec < 0 || tm.tm_sec > 59)
return GLDNS_WIREPARSE_ERR_SYNTAX_TIME;
gldns_write_uint32(rd, gldns_mktime_from_utc(&tm));
gldns_write_uint32(rd, (uint32_t)gldns_mktime_from_utc(&tm));
} else {
/* handle it as 32 bits timestamp */
char *end;
@ -1383,6 +1428,24 @@ int gldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len)
return GLDNS_WIREPARSE_ERR_OK;
}
int gldns_str2wire_tsigtime_buf(const char* str, uint8_t* rd, size_t* len)
{
char* end;
uint64_t t = (uint64_t)strtol((char*)str, &end, 10);
uint16_t high;
uint32_t low;
if(*end != 0)
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_TIME, end-str);
if(*len < 6)
return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
high = (uint16_t)(t>>32);
low = (uint32_t)(t);
gldns_write_uint16(rd, high);
gldns_write_uint32(rd+2, low);
*len = 6;
return GLDNS_WIREPARSE_ERR_OK;
}
int gldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len)
{
const char* end;
@ -1932,7 +1995,7 @@ int gldns_str2wire_tag_buf(const char* str, uint8_t* rd, size_t* len)
if(!isalnum((unsigned char)*ptr))
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_TAG, ptr-str);
}
rd[0] = slen;
rd[0] = (uint8_t)slen;
memmove(rd+1, str, slen);
*len = slen+1;
return GLDNS_WIREPARSE_ERR_OK;
@ -2000,7 +2063,7 @@ int gldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len)
return RET_ERR_SHIFT(e, s-(char*)str);
if(pklen > 65535)
return RET_ERR(GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW, s-(char*)str+65535);
gldns_write_uint16(rd+2, pklen);
gldns_write_uint16(rd+2, (uint16_t)pklen);
*len = 4 + hitlen + pklen;
return GLDNS_WIREPARSE_ERR_OK;
@ -2008,16 +2071,29 @@ int gldns_str2wire_hip_buf(const char* str, uint8_t* rd, size_t* len)
int gldns_str2wire_int16_data_buf(const char* str, uint8_t* rd, size_t* len)
{
size_t sz = gldns_b64_pton_calculate_size(strlen(str));
char* s;
int n;
if(*len < sz+2)
n = strtol(str, &s, 10);
if(*len < ((size_t)n)+2)
return GLDNS_WIREPARSE_ERR_BUFFER_TOO_SMALL;
if(sz > 65535)
if(n > 65535)
return GLDNS_WIREPARSE_ERR_LABEL_OVERFLOW;
n = gldns_b64_pton(str, rd+2, (*len)-2);
if(n == 0) {
gldns_write_uint16(rd, 0);
*len = 2;
return GLDNS_WIREPARSE_ERR_OK;
}
if(*s != ' ')
return RET_ERR(GLDNS_WIREPARSE_ERR_SYNTAX_INT, s-(char*)str);
s++;
while(*s == ' ')
s++;
n = gldns_b64_pton(s, rd+2, (*len)-2);
if(n < 0)
return GLDNS_WIREPARSE_ERR_SYNTAX_B64;
gldns_write_uint16(rd, (uint16_t)n);
*len = (size_t)n;
*len = ((size_t)n)+2;
return GLDNS_WIREPARSE_ERR_OK;
}

View File

@ -237,6 +237,8 @@ struct gldns_file_parse_state {
* @param rr: this is malloced by the user and the result is stored here,
* if an RR is read. If no RR is read this is signalled with the
* return len set to 0 (for ORIGIN, TTL directives).
* The read line is available in the rr_buf (zero terminated), for
* $DIRECTIVE style elements.
* @param len: on input, the length of the rr buffer. on output the rr len.
* Buffer size of 64k should be enough.
* @param dname_len: returns the length of the dname initial part of the rr.
@ -417,6 +419,24 @@ int gldns_str2wire_time_buf(const char* str, uint8_t* rd, size_t* len);
*/
int gldns_str2wire_period_buf(const char* str, uint8_t* rd, size_t* len);
/**
* Convert rdf of type GLDNS_RDF_TYPE_TSIGTIME from string to wireformat.
* @param str: the text to convert for this rdata element.
* @param rd: rdata buffer for the wireformat.
* @param len: length of rd buffer on input, used length on output.
* @return 0 on success, error on failure.
*/
int gldns_str2wire_tsigtime_buf(const char* str, uint8_t* rd, size_t* len);
/**
* Convert rdf of type GLDNS_RDF_TYPE_TSIGERROR from string to wireformat.
* @param str: the text to convert for this rdata element.
* @param rd: rdata buffer for the wireformat.
* @param len: length of rd buffer on input, used length on output.
* @return 0 on success, error on failure.
*/
int gldns_str2wire_tsigerror_buf(const char* str, uint8_t* rd, size_t* len);
/**
* Convert rdf of type GLDNS_RDF_TYPE_LOC from string to wireformat.
* @param str: the text to convert for this rdata element.

View File

@ -47,6 +47,8 @@ static gldns_lookup_table gldns_algorithms_data[] = {
{ GLDNS_ECC_GOST, "ECC-GOST"},
{ GLDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
{ GLDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
{ GLDNS_ED25519, "ED25519"},
{ GLDNS_ED448, "ED448"},
{ GLDNS_INDIRECT, "INDIRECT" },
{ GLDNS_PRIVATEDNS, "PRIVATEDNS" },
{ GLDNS_PRIVATEOID, "PRIVATEOID" },
@ -171,6 +173,28 @@ static gldns_lookup_table gldns_edns_options_data[] = {
};
gldns_lookup_table* gldns_edns_options = gldns_edns_options_data;
static gldns_lookup_table gldns_tsig_errors_data[] = {
{ GLDNS_TSIG_ERROR_NOERROR, "NOERROR" },
{ GLDNS_RCODE_FORMERR, "FORMERR" },
{ GLDNS_RCODE_SERVFAIL, "SERVFAIL" },
{ GLDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
{ GLDNS_RCODE_NOTIMPL, "NOTIMPL" },
{ GLDNS_RCODE_REFUSED, "REFUSED" },
{ GLDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
{ GLDNS_RCODE_YXRRSET, "YXRRSET" },
{ GLDNS_RCODE_NXRRSET, "NXRRSET" },
{ GLDNS_RCODE_NOTAUTH, "NOTAUTH" },
{ GLDNS_RCODE_NOTZONE, "NOTZONE" },
{ GLDNS_TSIG_ERROR_BADSIG, "BADSIG" },
{ GLDNS_TSIG_ERROR_BADKEY, "BADKEY" },
{ GLDNS_TSIG_ERROR_BADTIME, "BADTIME" },
{ GLDNS_TSIG_ERROR_BADMODE, "BADMODE" },
{ GLDNS_TSIG_ERROR_BADNAME, "BADNAME" },
{ GLDNS_TSIG_ERROR_BADALG, "BADALG" },
{ 0, NULL }
};
gldns_lookup_table* gldns_tsig_errors = gldns_tsig_errors_data;
char* gldns_wire2str_pkt(uint8_t* data, size_t len)
{
size_t slen = (size_t)gldns_wire2str_pkt_buf(data, len, NULL, 0);
@ -271,6 +295,12 @@ int gldns_wire2str_rcode_buf(int rcode, char* s, size_t slen)
return gldns_wire2str_rcode_print(&s, &slen, rcode);
}
int gldns_wire2str_opcode_buf(int opcode, char* s, size_t slen)
{
/* use arguments as temporary variables */
return gldns_wire2str_opcode_print(&s, &slen, opcode);
}
int gldns_wire2str_dname_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
{
/* use arguments as temporary variables */
@ -279,7 +309,7 @@ int gldns_wire2str_dname_buf(uint8_t* d, size_t dlen, char* s, size_t slen)
int gldns_str_vprint(char** str, size_t* slen, const char* format, va_list args)
{
int w = _gldns_vsnprintf(*str, *slen, format, args);
int w = vsnprintf(*str, *slen, format, args);
if(w < 0) {
/* error in printout */
return 0;
@ -668,7 +698,7 @@ int gldns_wire2str_rdata_scan(uint8_t** d, size_t* dlen, char** s,
uint8_t* origd = *d;
char* origs = *s;
size_t origdlen = *dlen, origslen = *slen;
uint16_t r_cnt, r_max;
size_t r_cnt, r_max;
gldns_rdf_type rdftype;
int w = 0, n;
@ -789,8 +819,9 @@ int gldns_wire2str_dname_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen,
}
/* spool label characters, end with '.' */
if(in_buf && *dlen < labellen) labellen = *dlen;
else if(!in_buf && pos+labellen > pkt+pktlen)
if(in_buf && *dlen < (size_t)labellen)
labellen = (uint8_t)*dlen;
else if(!in_buf && pos+(size_t)labellen > pkt+pktlen)
labellen = (uint8_t)(pkt + pktlen - pos);
for(i=0; i<(unsigned)labellen; i++) {
w += dname_char_print(s, slen, *pos++);
@ -967,6 +998,8 @@ int gldns_wire2str_rdf_scan(uint8_t** d, size_t* dlen, char** s, size_t* slen,
return gldns_wire2str_tag_scan(d, dlen, s, slen);
case GLDNS_RDF_TYPE_LONG_STR:
return gldns_wire2str_long_str_scan(d, dlen, s, slen);
case GLDNS_RDF_TYPE_TSIGERROR:
return gldns_wire2str_tsigerror_scan(d, dlen, s, slen);
}
/* unknown rdf type */
return -1;
@ -1187,11 +1220,17 @@ static int gldns_wire2str_b64_scan_num(uint8_t** d, size_t* dl, char** s,
int gldns_wire2str_b64_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
{
if(*dl == 0) {
return gldns_str_print(s, sl, "0");
}
return gldns_wire2str_b64_scan_num(d, dl, s, sl, *dl);
}
int gldns_wire2str_hex_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
{
if(*dl == 0) {
return gldns_str_print(s, sl, "0");
}
return print_remainder_hex("", d, dl, s, sl);
}
@ -1565,6 +1604,7 @@ int gldns_wire2str_hip_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
int gldns_wire2str_int16_data_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
{
int w;
uint16_t n;
if(*dl < 2)
return -1;
@ -1573,7 +1613,12 @@ int gldns_wire2str_int16_data_scan(uint8_t** d, size_t* dl, char** s, size_t* sl
return -1;
(*d)+=2;
(*dl)-=2;
return gldns_wire2str_b64_scan_num(d, dl, s, sl, n);
if(n == 0) {
return gldns_str_print(s, sl, "0");
}
w = gldns_str_print(s, sl, "%u ", (unsigned)n);
w += gldns_wire2str_b64_scan_num(d, dl, s, sl, n);
return w;
}
int gldns_wire2str_nsec3_next_owner_scan(uint8_t** d, size_t* dl, char** s,
@ -1630,10 +1675,10 @@ int gldns_wire2str_tag_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
if(*dl < 1+n)
return -1;
for(i=0; i<n; i++)
if(!isalnum((unsigned char)(*d)[i]))
if(!isalnum((unsigned char)(*d)[i+1]))
return -1;
for(i=0; i<n; i++)
w += gldns_str_print(s, sl, "%c", (char)(*d)[i]);
w += gldns_str_print(s, sl, "%c", (char)(*d)[i+1]);
(*d)+=n+1;
(*dl)-=(n+1);
return w;
@ -1652,6 +1697,21 @@ int gldns_wire2str_long_str_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
return w;
}
int gldns_wire2str_tsigerror_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
{
gldns_lookup_table *lt;
int data, w;
if(*dl < 2) return -1;
data = (int)gldns_read_uint16(*d);
lt = gldns_lookup_by_id(gldns_tsig_errors, data);
if(lt && lt->name)
w = gldns_str_print(s, sl, "%s", lt->name);
else w = gldns_str_print(s, sl, "%d", data);
(*dl)-=2;
(*d)+=2;
return w;
}
int gldns_wire2str_edns_llq_print(char** s, size_t* sl, uint8_t* data,
size_t len)
{
@ -1983,10 +2043,10 @@ int gldns_wire2str_edns_scan(uint8_t** data, size_t* data_len, char** str,
w += gldns_str_print(str, str_len, " ; udp: %u", (unsigned)udpsize);
if(rdatalen) {
if(*data_len < rdatalen) {
if((size_t)*data_len < rdatalen) {
w += gldns_str_print(str, str_len,
" ; Error EDNS rdata too short; ");
rdatalen = *data_len;
rdatalen = (uint16_t)*data_len;
}
w += print_edns_opts(str, str_len, *data, rdatalen);
(*data) += rdatalen;

View File

@ -38,6 +38,8 @@ extern struct gldns_struct_lookup_table* gldns_edns_flags;
extern struct gldns_struct_lookup_table* gldns_edns_options;
/** error string from wireparse */
extern struct gldns_struct_lookup_table* gldns_wireparse_errors;
/** tsig errors are the rcodes with extra (higher) values */
extern struct gldns_struct_lookup_table* gldns_tsig_errors;
/**
* Convert wireformat packet to a string representation
@ -118,7 +120,7 @@ int gldns_str_print(char** str, size_t* slen, const char* format, ...)
* @param str_len: the size of the string buffer. If more is needed, it'll
* silently truncate the output to fit in the buffer.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_pkt_buf(uint8_t* data, size_t data_len, char* str,
size_t str_len);
@ -351,7 +353,7 @@ int gldns_wire2str_edns_option_code_print(char** str, size_t* str_len,
* @param str_len: the size of the string buffer. If more is needed, it'll
* silently truncate the output to fit in the buffer.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_rr_buf(uint8_t* rr, size_t rr_len, char* str,
size_t str_len);
@ -369,7 +371,7 @@ int gldns_wire2str_rr_buf(uint8_t* rr, size_t rr_len, char* str,
* @param str_len: the size of the string buffer. If more is needed, it'll
* silently truncate the output to fit in the buffer.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_rr_unknown_buf(uint8_t* rr, size_t rr_len, char* str,
size_t str_len);
@ -389,7 +391,7 @@ int gldns_wire2str_rr_unknown_buf(uint8_t* rr, size_t rr_len, char* str,
* @param str_len: the size of the string buffer. If more is needed, it'll
* silently truncate the output to fit in the buffer.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_rr_comment_buf(uint8_t* rr, size_t rr_len, size_t dname_len,
char* str, size_t str_len);
@ -406,7 +408,7 @@ int gldns_wire2str_rr_comment_buf(uint8_t* rr, size_t rr_len, size_t dname_len,
* silently truncate the output to fit in the buffer.
* @param rrtype: rr type of the data
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str,
size_t str_len, uint16_t rrtype);
@ -417,7 +419,7 @@ int gldns_wire2str_rdata_buf(uint8_t* rdata, size_t rdata_len, char* str,
* @param str: the string to write to.
* @param len: length of str.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_type_buf(uint16_t rrtype, char* str, size_t len);
@ -427,7 +429,7 @@ int gldns_wire2str_type_buf(uint16_t rrtype, char* str, size_t len);
* @param str: the string to write to.
* @param len: length of str.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_class_buf(uint16_t rrclass, char* str, size_t len);
@ -437,10 +439,21 @@ int gldns_wire2str_class_buf(uint16_t rrclass, char* str, size_t len);
* @param str: the string to write to.
* @param len: length of str.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_rcode_buf(int rcode, char* str, size_t len);
/**
* Convert host format opcode to a string. 'QUERY', 'NOTIFY', 'UPDATE'.
* With user buffer.
* @param opcode: opcode as integer in host order
* @param str: the string to write to.
* @param len: length of str.
* @return the number of characters for this element, excluding zerobyte.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_opcode_buf(int opcode, char* str, size_t len);
/**
* Convert wire dname to a string, "example.com.". With user buffer.
* @param dname: the dname in uncompressed wireformat.
@ -448,7 +461,7 @@ int gldns_wire2str_rcode_buf(int rcode, char* str, size_t len);
* @param str: the string to write to.
* @param len: length of string.
* @return the number of characters for this element, excluding zerobyte.
* Is larger than str_len if output was truncated.
* Is larger or equal than str_len if output was truncated.
*/
int gldns_wire2str_dname_buf(uint8_t* dname, size_t dname_len, char* str,
size_t len);
@ -796,6 +809,19 @@ int gldns_wire2str_hip_scan(uint8_t** data, size_t* data_len, char** str,
int gldns_wire2str_int16_data_scan(uint8_t** data, size_t* data_len, char** str,
size_t* str_len);
/**
* Scan wireformat tsigerror field to string, with user buffers.
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).
* @param data: wireformat data.
* @param data_len: length of data buffer.
* @param str: string buffer.
* @param str_len: length of string buffer.
* @return number of characters (except null) needed to print.
* Can return -1 on failure.
*/
int gldns_wire2str_tsigerror_scan(uint8_t** data, size_t* data_len, char** str,
size_t* str_len);
/**
* Scan wireformat nsec3_next_owner field to string, with user buffers.
* It shifts the arguments to move along (see gldns_wire2str_pkt_scan).

@ -1 +1 @@
Subproject commit 49024a6e11739c866bce0e9f3617278b98906ad0
Subproject commit c831c3869f56a571a79a3cbf58e0a366e588e256

View File

@ -26,9 +26,12 @@ getdns_context_get_limit_outstanding_queries
getdns_context_get_namespaces
getdns_context_get_num_pending_requests
getdns_context_get_resolution_type
getdns_context_get_round_robin_upstreams
getdns_context_get_suffix
getdns_context_get_timeout
getdns_context_get_tls_authentication
getdns_context_get_tls_backoff_time
getdns_context_get_tls_connection_retries
getdns_context_get_tls_query_padding_blocksize
getdns_context_get_update_callback
getdns_context_get_upstream_recursive_servers
@ -52,17 +55,22 @@ getdns_context_set_follow_redirects
getdns_context_set_idle_timeout
getdns_context_set_limit_outstanding_queries
getdns_context_set_listen_addresses
getdns_context_set_logfunc
getdns_context_set_memory_functions
getdns_context_set_namespaces
getdns_context_set_resolution_type
getdns_context_set_return_dnssec_status
getdns_context_set_round_robin_upstreams
getdns_context_set_suffix
getdns_context_set_timeout
getdns_context_set_tls_authentication
getdns_context_set_tls_backoff_time
getdns_context_set_tls_connection_retries
getdns_context_set_tls_query_padding_blocksize
getdns_context_set_update_callback
getdns_context_set_upstream_recursive_servers
getdns_context_set_use_threads
getdns_context_unset_edns_maximum_udp_payload_size
getdns_convert_alabel_to_ulabel
getdns_convert_dns_name_to_fqdn
getdns_convert_fqdn_to_dns_name

View File

@ -312,7 +312,7 @@ getdns_return_t
_getdns_list_copy(const struct getdns_list * srclist,
struct getdns_list ** dstlist)
{
int i;
size_t i;
getdns_return_t retval;
if (!dstlist)
@ -353,6 +353,9 @@ _getdns_list_copy(const struct getdns_list * srclist,
retval = _getdns_list_append_dict(*dstlist,
srclist->items[i].data.dict);
break;
default:
retval = GETDNS_RETURN_WRONG_TYPE_REQUESTED;
break;
}
if (retval != GETDNS_RETURN_GOOD) {
getdns_list_destroy(*dstlist);

2161
src/mdns.c Normal file

File diff suppressed because it is too large Load Diff

121
src/mdns.h Normal file
View File

@ -0,0 +1,121 @@
/*
* Functions for MDNS resolving.
*/
/*
* Copyright (c) 2016 Christian Huitema <huitema@huitema.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef MDNS_H
#define MDNS_H
#ifdef HAVE_MDNS_SUPPORT
#include "getdns/getdns.h"
#include "types-internal.h"
#include "util/lruhash.h"
#include "config.h"
#ifndef USE_WINSOCK
#define SOCKADDR_STORAGE struct sockaddr_storage
#endif
getdns_return_t
_getdns_submit_mdns_request(getdns_network_req *netreq);
getdns_return_t
_getdns_mdns_namespace_check(getdns_dns_req *dnsreq);
/*
* data structure for continuous queries
*/
typedef struct getdns_mdns_known_record
{
/* For storage in context->mdns_known_records_by_value */
_getdns_rbnode_t node;
uint64_t insertion_microsec;
uint16_t record_type;
uint16_t record_class;
uint32_t ttl;
int name_len;
int record_data_len;
uint8_t* name;
uint8_t * record_data;
} getdns_mdns_known_record;
/*
* Each entry in the hash table is keyed by type, class and name.
* The key structure also contains the LRU hash entry structure.
* The data part contains:
* - 64 bit time stamp
* - 32 bit word describing the record size
* - 32 bit word describing teh allocated memory size
* - valid DNS response, including 1 query and N answers, 0 AUTH, 0 AD.
* For economy, the names of all answers are encoded using header compression, pointing
* to the name in the query, i.e. offset 12 from beginning of message.
* For stability, the names included in the data part of records are not compressed.
*/
typedef struct getdns_mdns_cached_key_header
{
/* embedded entry, for LRU hash */
struct lruhash_entry entry;
/* identification */
uint16_t record_type;
uint16_t record_class;
int name_len;
/* the octets following this structure contain the name */
} getdns_mdns_cached_key_header;
typedef struct getdns_mdns_cached_record_header
{
uint64_t insertion_microsec;
uint32_t content_len;
uint32_t allocated_length;
/* list of user queries */
getdns_network_req *netreq_first;
} getdns_mdns_cached_record_header;
typedef struct getdns_mdns_continuous_query
{
/* For storage in context->mdns_continuous_queries_by_name_rrtype */
_getdns_rbnode_t node;
uint8_t name[256]; /* binary representation of name being queried */
int name_len;
uint16_t request_class;
uint16_t request_type;
/* list of user queries */
getdns_network_req *netreq_first;
/* todo: do we need an expiration date, or a timer? */
/* todo: do we need an update mark for showing last results? */
} getdns_mdns_continuous_query;
typedef struct mdns_network_connection
{
struct getdns_context* context;
int fd;
int addr_mcast_len;
SOCKADDR_STORAGE addr_mcast;
getdns_eventloop_event event;
uint8_t response[1500];
} mdns_network_connection;
void _getdns_mdns_context_init(struct getdns_context *context);
void _getdns_mdns_context_destroy(struct getdns_context *context);
#endif /* HAVE_MDNS_SUPPORT */
#endif /* MDNS_H */

View File

@ -14,7 +14,7 @@ cat > const-info.c << END_OF_HEAD
static struct const_info consts_info[] = {
{ -1, NULL, "/* <unknown getdns value> */" },
END_OF_HEAD
gawk '/^[ ]+GETDNS_[A-Z_]+[ ]+=[ ]+[0-9]+/{ key = sprintf("%4d", $3); consts[key] = $1; }/^#define GETDNS_[A-Z_]+[ ]+[0-9]+/ && !/^#define GETDNS_RRTYPE/ && !/^#define GETDNS_RRCLASS/ && !/^#define GETDNS_OPCODE/ && !/^#define GETDNS_RCODE/ && !/_TEXT/{ key = sprintf("%4d", $3); consts[key] = $2; }/^#define GETDNS_[A-Z_]+[ ]+\(\(getdns_(return|append_name)_t) [0-9]+ \)/{ key = sprintf("%4d", $4); consts[key] = $2; }END{ n = asorti(consts, const_vals); for ( i = 1; i <= n; i++) { val = const_vals[i]; name = consts[val]; print "\t{ "val", \""name"\", "name"_TEXT },"}}' getdns/getdns.h.in getdns/getdns_extra.h.in | sed 's/,,/,/g' >> const-info.c
gawk '/^[ ]+GETDNS_[A-Z_]+[ ]+=[ ]+[0-9]+/{ key = sprintf("%7d", $3); consts[key] = $1; }/^#define GETDNS_[A-Z_]+[ ]+[0-9]+/ && !/^#define GETDNS_RRTYPE/ && !/^#define GETDNS_RRCLASS/ && !/^#define GETDNS_OPCODE/ && !/^#define GETDNS_RCODE/ && !/_TEXT/{ key = sprintf("%7d", $3); consts[key] = $2; }/^#define GETDNS_[A-Z_]+[ ]+\(\(getdns_(return|append_name)_t) [0-9]+ \)/{ key = sprintf("%7d", $4); consts[key] = $2; }END{ n = asorti(consts, const_vals); for ( i = 1; i <= n; i++) { val = const_vals[i]; name = consts[val]; print "\t{ "val", \""name"\", "name"_TEXT },"}}' getdns/getdns_extra.h.in getdns/getdns.h.in | sed 's/,,/,/g' >> const-info.c
cat >> const-info.c << END_OF_TAIL
};

View File

@ -3,7 +3,7 @@
write_symbols() {
OUTPUT=$1
shift
grep 'getdns_[0-9a-zA-Z_]*(' $* | grep -v '^#' | grep -v 'INLINE' \
grep 'getdns_[0-9a-zA-Z_]*(' $* | grep -v '^#' | grep -v 'INLINE' | grep -v 'getdns_extra\.h\.in: \* if' \
| sed -e 's/(.*$//g' -e 's/^.*getdns_/getdns_/g' | LC_ALL=C sort | uniq > $OUTPUT
}

View File

@ -56,6 +56,10 @@
#include "context.h"
#include "util-internal.h"
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
#define X509_STORE_CTX_get0_untrusted(store) store->untrusted
#endif
/* we only support sha256 at the moment. adding support for another
digest is more complex than just adding another entry here. in
particular, you'll probably need a match for a particular cert
@ -93,7 +97,7 @@ getdns_dict* getdns_pubkey_pin_create_from_string(
const char* str)
{
BIO *bio = NULL;
int i;
size_t i;
uint8_t buf[SHA256_DIGEST_LENGTH];
char inbuf[B64_ENCODED_SHA256_LENGTH + 1];
getdns_bindata value = { .size = SHA256_DIGEST_LENGTH, .data = buf };
@ -310,15 +314,27 @@ _getdns_get_pubkey_pinset_list(getdns_context *ctx,
see doc/HOWTO/proxy_certificates.txt as an example
*/
static int
_get_ssl_getdns_upstream_idx()
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
_get_ssl_getdns_upstream_idx(void)
#else
_get_ssl_getdns_upstream_idx(X509_STORE *store)
#endif
{
static volatile int idx = -1;
if (idx < 0) {
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
#else
X509_STORE_lock(store);
#endif
if (idx < 0)
idx = SSL_get_ex_new_index(0, "associated getdns upstream",
NULL,NULL,NULL);
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
#else
X509_STORE_unlock(store);
#endif
}
return idx;
}
@ -326,7 +342,11 @@ _get_ssl_getdns_upstream_idx()
getdns_upstream*
_getdns_upstream_from_x509_store(X509_STORE_CTX *store)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
int uidx = _get_ssl_getdns_upstream_idx();
#else
int uidx = _get_ssl_getdns_upstream_idx(X509_STORE_CTX_get0_store(store));
#endif
int sslidx = SSL_get_ex_data_X509_STORE_CTX_idx();
const SSL *ssl;
@ -344,7 +364,11 @@ getdns_return_t
_getdns_associate_upstream_with_SSL(SSL *ssl,
getdns_upstream *upstream)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
int uidx = _get_ssl_getdns_upstream_idx();
#else
int uidx = _get_ssl_getdns_upstream_idx(SSL_CTX_get_cert_store(SSL_get_SSL_CTX(ssl)));
#endif
if (SSL_set_ex_data(ssl, uidx, upstream))
return GETDNS_RETURN_GOOD;
else
@ -358,10 +382,10 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
X509_STORE_CTX *store)
{
getdns_return_t ret = GETDNS_RETURN_GENERIC_ERROR;
X509 *x;
X509 *x, *prev = NULL;
int i, len;
unsigned char raw[4096];
unsigned char *next = raw;
unsigned char *next;
unsigned char buf[sizeof(pinset->pin)];
const sha256_pin_t *p;
@ -383,33 +407,45 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
/* TODO: how do we handle raw public keys? */
for (i = 0; i < sk_X509_num(store->untrusted); i++) {
if (i > 0) {
/* TODO: how do we ensure that the certificates in
* each stage appropriately sign the previous one?
* for now, to be safe, we only examine the end-entity
* cert: */
return GETDNS_RETURN_GENERIC_ERROR;
}
for (i = 0; i < sk_X509_num(X509_STORE_CTX_get0_untrusted(store)); i++, prev = x) {
x = sk_X509_value(store->untrusted, i);
x = sk_X509_value(X509_STORE_CTX_get0_untrusted(store), i);
#if defined(STUB_DEBUG) && STUB_DEBUG
DEBUG_STUB("%s %-35s: Name of cert: %d ",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i);
STUB_DEBUG_SETUP_TLS, __FUNC__, i);
X509_NAME_print_ex_fp(stderr, X509_get_subject_name(x), 1, XN_FLAG_ONELINE);
fprintf(stderr, "\n");
#endif
if (i > 0) {
/* we ensure that "prev" is signed by "x" */
EVP_PKEY *pkey = X509_get_pubkey(x);
int verified;
if (!pkey) {
DEBUG_STUB("%s %-35s: Could not get pubkey from cert %d (%p)\n",
STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)x);
return GETDNS_RETURN_GENERIC_ERROR;
}
verified = X509_verify(prev, pkey);
EVP_PKEY_free(pkey);
if (!verified) {
DEBUG_STUB("%s %-35s: cert %d (%p) was not signed by cert %d\n",
STUB_DEBUG_SETUP_TLS, __FUNC__, i-1, (void*)prev, i);
return GETDNS_RETURN_GENERIC_ERROR;
}
}
/* digest the cert with sha256 */
len = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), NULL);
if (len > sizeof(raw)) {
if (len > (int)sizeof(raw)) {
DEBUG_STUB("%s %-35s: Pubkey %d is larger than "PRIsz" octets\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, sizeof(raw));
STUB_DEBUG_SETUP_TLS, __FUNC__, i, sizeof(raw));
continue;
}
next = raw;
i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x), &next);
if (next - raw != len) {
DEBUG_STUB("%s %-35s: Pubkey %d claimed it needed %d octets, really needed "PRIsz"\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, len, next - raw);
STUB_DEBUG_SETUP_TLS, __FUNC__, i, len, next - raw);
continue;
}
SHA256(raw, len, buf);
@ -418,11 +454,11 @@ _getdns_verify_pinset_match(const sha256_pin_t *pinset,
for (p = pinset; p; p = p->next)
if (0 == memcmp(buf, p->pin, sizeof(p->pin))) {
DEBUG_STUB("%s %-35s: Pubkey %d matched pin %p ("PRIsz")\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, p, sizeof(p->pin));
STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)p, sizeof(p->pin));
return GETDNS_RETURN_GOOD;
} else
DEBUG_STUB("%s %-35s: Pubkey %d did not match pin %p\n",
STUB_DEBUG_SETUP_TLS, __FUNCTION__, i, p);
STUB_DEBUG_SETUP_TLS, __FUNC__, i, (void*)p);
}
return ret;

View File

@ -43,6 +43,7 @@
#include "dict.h"
#include "debug.h"
#include "convert.h"
#include "general.h"
/* MAXIMUM_TSIG_SPACE = TSIG name (dname) : 256
* TSIG type (uint16_t) : 2
@ -65,20 +66,20 @@
getdns_dict dnssec_ok_checking_disabled_spc = {
{ RBTREE_NULL, 0, (int (*)(const void *, const void *)) strcmp },
{ 0 }
{ NULL, {{ NULL, NULL, NULL }}}
};
getdns_dict *dnssec_ok_checking_disabled = &dnssec_ok_checking_disabled_spc;
getdns_dict dnssec_ok_checking_disabled_roadblock_avoidance_spc = {
{ RBTREE_NULL, 0, (int (*)(const void *, const void *)) strcmp },
{ 0 }
{ NULL, {{ NULL, NULL, NULL }}}
};
getdns_dict *dnssec_ok_checking_disabled_roadblock_avoidance
= &dnssec_ok_checking_disabled_roadblock_avoidance_spc;
getdns_dict dnssec_ok_checking_disabled_avoid_roadblocks_spc = {
{ RBTREE_NULL, 0, (int (*)(const void *, const void *)) strcmp },
{ 0 }
{ NULL, {{ NULL, NULL, NULL }}}
};
getdns_dict *dnssec_ok_checking_disabled_avoid_roadblocks
= &dnssec_ok_checking_disabled_avoid_roadblocks_spc;
@ -109,6 +110,9 @@ network_req_cleanup(getdns_network_req *net_req)
if (net_req->response && (net_req->response < net_req->wire_data ||
net_req->response > net_req->wire_data+ net_req->wire_data_sz))
GETDNS_FREE(net_req->owner->my_mf, net_req->response);
if (net_req->debug_tls_peer_cert.size &&
net_req->debug_tls_peer_cert.data)
OPENSSL_free(net_req->debug_tls_peer_cert.data);
}
static uint8_t *
@ -118,10 +122,9 @@ netreq_reset(getdns_network_req *net_req)
/* variables that need to be reset on reinit
*/
net_req->unbound_id = -1;
net_req->state = NET_REQ_NOT_SENT;
_getdns_netreq_change_state(net_req, NET_REQ_NOT_SENT);
net_req->dnssec_status = GETDNS_DNSSEC_INDETERMINATE;
net_req->tsig_status = GETDNS_DNSSEC_INDETERMINATE;
net_req->query_id = 0;
net_req->response_len = 0;
/* Some fields to record info for return_call_reporting */
net_req->debug_start_time = 0;
@ -181,8 +184,14 @@ network_req_init(getdns_network_req *net_req, getdns_dns_req *owner,
net_req->write_queue_tail = NULL;
/* Some fields to record info for return_call_reporting */
net_req->debug_tls_auth_status = GETDNS_AUTH_NONE;
net_req->debug_tls_peer_cert.size = 0;
net_req->debug_tls_peer_cert.data = NULL;
net_req->debug_udp = 0;
/* Scheduling, touch only via _getdns_netreq_change_state!
*/
net_req->state = NET_REQ_NOT_SENT;
if (max_query_sz == 0) {
net_req->query = NULL;
net_req->opt = NULL;
@ -262,10 +271,10 @@ _getdns_network_req_clear_upstream_options(getdns_network_req * req)
{
size_t pktlen;
if (req->opt) {
gldns_write_uint16(req->opt + 9, req->base_query_option_sz);
gldns_write_uint16(req->opt + 9, (uint16_t) req->base_query_option_sz);
req->response = req->opt + 11 + req->base_query_option_sz;
pktlen = req->response - req->query;
gldns_write_uint16(req->query - 2, pktlen);
gldns_write_uint16(req->query - 2, (uint16_t) pktlen);
}
}
@ -383,7 +392,7 @@ _getdns_network_req_add_tsig(getdns_network_req *req)
#endif
tsig_info = _getdns_get_tsig_info(upstream->tsig_alg);
gldns_buffer_init_frm_data(&gbuf, req->response, MAXIMUM_TSIG_SPACE);
gldns_buffer_init_vfixed_frm_data(&gbuf, req->response, MAXIMUM_TSIG_SPACE);
gldns_buffer_write(&gbuf,
upstream->tsig_dname, upstream->tsig_dname_len); /* Name */
gldns_buffer_write_u16(&gbuf, GETDNS_RRCLASS_ANY); /* Class */
@ -428,7 +437,7 @@ _getdns_network_req_add_tsig(getdns_network_req *req)
gldns_buffer_write_u16(&gbuf, GETDNS_RRCLASS_ANY); /* Class */
gldns_buffer_write_u32(&gbuf, 0); /* TTL */
gldns_buffer_write_u16(&gbuf,
tsig_info->dname_len + 10 + md_len + 6); /* RdLen */
(uint16_t)(tsig_info->dname_len + 10 + md_len + 6)); /* RdLen */
gldns_buffer_write(&gbuf,
tsig_info->dname, tsig_info->dname_len); /* Algorithm Name */
gldns_buffer_write_u48(&gbuf, time(NULL)); /* Time Signed */
@ -474,7 +483,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_CTX ctx_space;
#endif
DEBUG_STUB("%s %-35s: Validate TSIG\n", STUB_DEBUG_TSIG, __FUNCTION__);
DEBUG_STUB("%s %-35s: Validate TSIG\n", STUB_DEBUG_TSIG, __FUNC__);
for ( rr = _getdns_rr_iter_init(&rr_spc, req->query,
(req->response - req->query))
; rr
@ -491,7 +500,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (request_mac_len != rdf->nxt - rdf->pos - 2)
return;
DEBUG_STUB("%s %-35s: Request MAC found length %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(request_mac_len));
STUB_DEBUG_TSIG, __FUNC__, (int)(request_mac_len));
request_mac = rdf->pos + 2;
@ -548,7 +557,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
if (response_mac_len != rdf->nxt - rdf->pos - 2)
return;
DEBUG_STUB("%s %-35s: Response MAC found length: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(response_mac_len));
STUB_DEBUG_TSIG, __FUNC__, (int)(response_mac_len));
response_mac = rdf->pos + 2;
if (!(rdf = _getdns_rdf_iter_next(rdf)) ||
@ -565,7 +574,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
return;
gldns_buffer_write_u16(&gbuf, 0); /* Other len */
other_len = gldns_read_uint16(rdf->pos);
other_len = (uint8_t) gldns_read_uint16(rdf->pos);
if (other_len != rdf->nxt - rdf->pos - 2)
return;
if (other_len)
@ -573,7 +582,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
/* TSIG found */
DEBUG_STUB("%s %-35s: TSIG found, original ID: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)original_id);
STUB_DEBUG_TSIG, __FUNC__, (int)original_id);
gldns_write_uint16(req->response + 10,
gldns_read_uint16(req->response + 10) - 1);
@ -614,7 +623,7 @@ _getdns_network_validate_tsig(getdns_network_req *req)
HMAC_Final(ctx, result_mac, &result_mac_len);
DEBUG_STUB("%s %-35s: Result MAC length: %d\n",
STUB_DEBUG_TSIG, __FUNCTION__, (int)(result_mac_len));
STUB_DEBUG_TSIG, __FUNC__, (int)(result_mac_len));
if (result_mac_len == response_mac_len &&
memcmp(result_mac, response_mac, result_mac_len) == 0)
req->tsig_status = GETDNS_DNSSEC_SECURE;
@ -644,7 +653,7 @@ _getdns_dns_req_free(getdns_dns_req * req)
network_req_cleanup(*net_req);
/* clear timeout event */
if (req->timeout.timeout_cb) {
if (req->loop && req->loop->vmt && req->timeout.timeout_cb) {
req->loop->vmt->clear(req->loop, &req->timeout);
req->timeout.timeout_cb = NULL;
}
@ -658,7 +667,8 @@ static const uint8_t no_suffixes[] = { 1, 0 };
/* create a new dns req to be submitted */
getdns_dns_req *
_getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
const char *name, uint16_t request_type, getdns_dict *extensions)
const char *name, uint16_t request_type, getdns_dict *extensions,
uint64_t *now_ms)
{
int dnssec_return_status = is_extension_set(
extensions, "dnssec_return_status",
@ -755,17 +765,26 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
edns_do_bit = context->edns_do_bit;
if (have_add_opt_parameters) {
if (!getdns_dict_get_int(add_opt_parameters,
if (getdns_dict_get_int(add_opt_parameters,
"maximum_udp_payload_size",
&get_edns_maximum_udp_payload_size))
&get_edns_maximum_udp_payload_size)) {
if (!getdns_dict_get_int(
add_opt_parameters, "udp_payload_size",
&get_edns_maximum_udp_payload_size))
edns_maximum_udp_payload_size =
get_edns_maximum_udp_payload_size;
} else
edns_maximum_udp_payload_size =
get_edns_maximum_udp_payload_size;
(void) getdns_dict_get_int(add_opt_parameters,
"extended_rcode", &edns_extended_rcode);
(void) getdns_dict_get_int(add_opt_parameters,
"version", &edns_version);
(void) getdns_dict_get_int(add_opt_parameters,
"do_bit", &edns_do_bit);
if (getdns_dict_get_int(add_opt_parameters,
"do_bit", &edns_do_bit))
(void) getdns_dict_get_int(
add_opt_parameters, "do", &edns_do_bit);
}
}
if (have_add_opt_parameters && getdns_dict_get_list(
@ -887,9 +906,7 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
}
result->context = context;
result->loop = loop;
result->canceled = 0;
result->trans_id = (((uint64_t)arc4random()) << 32) |
((uint64_t)arc4random());
result->trans_id = (uint64_t) (intptr_t) result;
result->dnssec_return_status = dnssec_return_status;
result->dnssec_return_only_secure = dnssec_return_only_secure;
result->dnssec_return_all_statuses = dnssec_return_all_statuses;
@ -925,12 +942,15 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
result->finished_next = NULL;
result->freed = NULL;
result->validating = 0;
result->is_dns_request = 1;
result->request_timed_out = 0;
result->chain = NULL;
network_req_init(result->netreqs[0], result,
request_type, dnssec_extension_set, with_opt,
edns_maximum_udp_payload_size,
edns_extended_rcode, edns_version, edns_do_bit,
opt_options_size, noptions, options,
(uint16_t) opt_options_size, noptions, options,
netreq_sz - sizeof(getdns_network_req), max_query_sz,
extensions);
@ -941,9 +961,14 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
dnssec_extension_set, with_opt,
edns_maximum_udp_payload_size,
edns_extended_rcode, edns_version, edns_do_bit,
opt_options_size, noptions, options,
(uint16_t) opt_options_size, noptions, options,
netreq_sz - sizeof(getdns_network_req), max_query_sz,
extensions);
if (*now_ms == 0 && (*now_ms = _getdns_get_now_ms()) == 0)
result->expires = 0;
else
result->expires = *now_ms + context->timeout;
return result;
}

View File

@ -47,6 +47,7 @@
static const uint8_t *
apl_n_rdf_end(const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf)
{
(void)pkt;
return rdf < pkt_end ? rdf + 1 : NULL;
}
static getdns_return_t
@ -55,11 +56,6 @@ apl_n_wire2dict(getdns_dict *dict, const uint8_t *rdf)
return getdns_dict_set_int(dict, "n", (*rdf >> 7));
}
static getdns_return_t
apl_n_wire2list(getdns_list *list, const uint8_t *rdf)
{
return _getdns_list_append_int(list, (*rdf >> 7));
}
static getdns_return_t
apl_n_2wire(uint32_t value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
(void)rdata; /* unused parameter */
@ -84,22 +80,10 @@ apl_n_dict2wire(const getdns_dict *dict,
else
return apl_n_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
apl_n_list2wire(const getdns_list *list, size_t i,
uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
uint32_t value;
if ((r = getdns_list_get_int(list, i, &value)))
return r;
else
return apl_n_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special apl_n = {
apl_n_rdf_end,
apl_n_wire2dict, apl_n_wire2list,
apl_n_dict2wire, apl_n_list2wire
apl_n_wire2dict, NULL,
apl_n_dict2wire, NULL
};
static const uint8_t *
@ -107,6 +91,7 @@ apl_afdpart_rdf_end(
const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf)
{
const uint8_t *end = rdf + (rdf[-1] & 0x7F);
(void)(pkt);
return end <= pkt_end ? end : NULL;
}
static getdns_return_t
@ -116,11 +101,6 @@ apl_afdpart_wire2dict(getdns_dict *dict, const uint8_t *rdf)
dict, "afdpart", (rdf[-1] & 0x7F), rdf);
}
static getdns_return_t
apl_afdpart_wire2list(getdns_list *list, const uint8_t *rdf)
{
return _getdns_list_append_const_bindata(list, (rdf[-1] & 0x7F), rdf);
}
static getdns_return_t
apl_afdpart_2wire(
const getdns_bindata *value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
@ -154,22 +134,10 @@ apl_afdpart_dict2wire(
else
return apl_afdpart_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
apl_afdpart_list2wire(const getdns_list *list,
size_t i, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
getdns_bindata *value;
if ((r = getdns_list_get_bindata(list, i, &value)))
return r;
else
return apl_afdpart_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special apl_afdpart = {
apl_afdpart_rdf_end,
apl_afdpart_wire2dict, apl_afdpart_wire2list,
apl_afdpart_dict2wire, apl_afdpart_list2wire
apl_afdpart_wire2dict, NULL,
apl_afdpart_dict2wire, NULL
};
static const uint8_t *
@ -244,30 +212,12 @@ ipseckey_gateway_wire2dict(getdns_dict *dict, const uint8_t *rdf)
return _getdns_dict_set_const_bindata(dict, "gateway", size, data);
}
static getdns_return_t
ipseckey_gateway_wire2list(getdns_list *list, const uint8_t *rdf)
{
size_t size;
const uint8_t *data;
if (ipseckey_gateway_equip_const_bindata(rdf, &size, &data))
return GETDNS_RETURN_GENERIC_ERROR;
else if (!size)
return GETDNS_RETURN_GOOD;
else
return _getdns_list_append_const_bindata(list, size, data);
}
static getdns_return_t
ipseckey_gateway_2wire(
const getdns_bindata *value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
if (rdf - 2 < rdata)
return GETDNS_RETURN_GENERIC_ERROR;
assert(rdf - 2 >= rdata && rdf[-2] > 0);
switch (rdf[-2]) {
case 0: if (value && value->size > 0)
return GETDNS_RETURN_INVALID_PARAMETER;
break;
case 1: if (!value || value->size != 4)
return GETDNS_RETURN_INVALID_PARAMETER;
if (*rdf_len < 4) {
@ -308,33 +258,29 @@ ipseckey_gateway_dict2wire(
getdns_return_t r;
getdns_bindata *value;
if ((r = getdns_dict_get_bindata(dict, "gateway", &value)))
return r;
else
return ipseckey_gateway_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
ipseckey_gateway_list2wire(const getdns_list *list,
size_t i, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
getdns_bindata *value;
if (rdf - 2 < rdata)
return GETDNS_RETURN_GENERIC_ERROR;
if ((r = getdns_list_get_bindata(list, i, &value)))
else if (rdf[-2] == 0) {
*rdf_len = 0;
return GETDNS_RETURN_GOOD;
}
else if ((r = getdns_dict_get_bindata(dict, "gateway", &value)))
return r;
else
return ipseckey_gateway_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special ipseckey_gateway = {
ipseckey_gateway_rdf_end,
ipseckey_gateway_wire2dict, ipseckey_gateway_wire2list,
ipseckey_gateway_dict2wire, ipseckey_gateway_list2wire
ipseckey_gateway_wire2dict, NULL,
ipseckey_gateway_dict2wire, NULL
};
static const uint8_t *
hip_pk_algorithm_rdf_end(
const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf)
{
(void)(pkt);
return rdf + 4 > pkt_end ? NULL
: rdf + 4 + *rdf + gldns_read_uint16(rdf + 2) > pkt_end ? NULL
: rdf + 1;
@ -345,11 +291,6 @@ hip_pk_algorithm_wire2dict(getdns_dict *dict, const uint8_t *rdf)
return getdns_dict_set_int(dict, "pk_algorithm", rdf[1]);
}
static getdns_return_t
hip_pk_algorithm_wire2list(getdns_list *list, const uint8_t *rdf)
{
return _getdns_list_append_int(list, rdf[1]);
}
static getdns_return_t
hip_pk_algorithm_2wire(uint32_t value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
if (rdata != rdf)
@ -376,27 +317,16 @@ hip_pk_algorithm_dict2wire(
else
return hip_pk_algorithm_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
hip_pk_algorithm_list2wire(const getdns_list *list,
size_t i, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
uint32_t value;
if ((r = getdns_list_get_int(list, i, &value)))
return r;
else
return hip_pk_algorithm_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special hip_pk_algorithm = {
hip_pk_algorithm_rdf_end,
hip_pk_algorithm_wire2dict, hip_pk_algorithm_wire2list,
hip_pk_algorithm_dict2wire, hip_pk_algorithm_list2wire
hip_pk_algorithm_wire2dict, NULL,
hip_pk_algorithm_dict2wire, NULL
};
static const uint8_t *
hip_hit_rdf_end(const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf)
{
(void)(pkt);
return rdf + 3 > pkt_end ? NULL
: rdf + 3 + rdf[-1] + gldns_read_uint16(rdf + 1) > pkt_end ? NULL
: rdf + 1;
@ -407,11 +337,6 @@ hip_hit_wire2dict(getdns_dict *dict, const uint8_t *rdf)
return _getdns_dict_set_const_bindata(dict, "hit", rdf[-1], rdf + 3);
}
static getdns_return_t
hip_hit_wire2list(getdns_list *list, const uint8_t *rdf)
{
return _getdns_list_append_const_bindata(list, rdf[-1], rdf + 3);
}
static getdns_return_t
hip_hit_2wire(
const getdns_bindata *value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
@ -429,7 +354,7 @@ hip_hit_2wire(
return GETDNS_RETURN_NEED_MORE_SPACE;
}
*rdf_len = value->size;
rdata[0] = value->size;
rdata[0] = (uint8_t) value->size;
(void)memcpy(rdf, value->data, value->size);
return GETDNS_RETURN_GOOD;
}
@ -445,28 +370,17 @@ hip_hit_dict2wire(
else
return hip_hit_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
hip_hit_list2wire(const getdns_list *list,
size_t i, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
getdns_bindata *value;
if ((r = getdns_list_get_bindata(list, i, &value)))
return r;
else
return hip_hit_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special hip_hit = {
hip_hit_rdf_end,
hip_hit_wire2dict, hip_hit_wire2list,
hip_hit_dict2wire, hip_hit_list2wire
hip_hit_wire2dict, NULL,
hip_hit_dict2wire, NULL
};
static const uint8_t *
hip_public_key_rdf_end(
const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf)
{
(void)(pkt);
return rdf + 2 > pkt_end ? NULL
: rdf + 2 + rdf[-2] + gldns_read_uint16(rdf) > pkt_end ? NULL
: rdf + 2 + rdf[-2] + gldns_read_uint16(rdf);
@ -478,12 +392,6 @@ hip_public_key_wire2dict(getdns_dict *dict, const uint8_t *rdf)
dict, "public_key", gldns_read_uint16(rdf), rdf + 2 + rdf[-2]);
}
static getdns_return_t
hip_public_key_wire2list(getdns_list *list, const uint8_t *rdf)
{
return _getdns_list_append_const_bindata(
list, gldns_read_uint16(rdf), rdf + 2 + rdf[-2]);
}
static getdns_return_t
hip_public_key_2wire(
const getdns_bindata *value, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
@ -501,7 +409,7 @@ hip_public_key_2wire(
return GETDNS_RETURN_NEED_MORE_SPACE;
}
*rdf_len = value->size;
gldns_write_uint16(rdata + 2, value->size);
gldns_write_uint16(rdata + 2, (uint16_t) value->size);
(void)memcpy(rdf, value->data, value->size);
return GETDNS_RETURN_GOOD;
}
@ -517,242 +425,241 @@ hip_public_key_dict2wire(
else
return hip_public_key_2wire(value, rdata, rdf, rdf_len);
}
static getdns_return_t
hip_public_key_list2wire(
const getdns_list *list, size_t i, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len)
{
getdns_return_t r;
getdns_bindata *value;
if ((r = getdns_list_get_bindata(list, i, &value)))
return r;
else
return hip_public_key_2wire(value, rdata, rdf, rdf_len);
}
static _getdns_rdf_special hip_public_key = {
hip_public_key_rdf_end,
hip_public_key_wire2dict, hip_public_key_wire2list,
hip_public_key_dict2wire, hip_public_key_list2wire
hip_public_key_wire2dict, NULL,
hip_public_key_dict2wire, NULL
};
static _getdns_rdata_def a_rdata[] = {
{ "ipv4_address" , GETDNS_RDF_A }};
{ "ipv4_address" , GETDNS_RDF_A , NULL }};
static _getdns_rdata_def ns_rdata[] = {
{ "nsdname" , GETDNS_RDF_N_C }};
{ "nsdname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def md_rdata[] = {
{ "madname" , GETDNS_RDF_N_C }};
{ "madname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def cname_rdata[] = {
{ "cname" , GETDNS_RDF_N_C }};
{ "cname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def soa_rdata[] = {
{ "mname" , GETDNS_RDF_N_C },
{ "rname" , GETDNS_RDF_N_C },
{ "serial" , GETDNS_RDF_I4 },
{ "refresh" , GETDNS_RDF_I4 },
{ "retry" , GETDNS_RDF_I4 },
{ "expire" , GETDNS_RDF_I4 },
{ "minimum" , GETDNS_RDF_I4 }};
{ "mname" , GETDNS_RDF_N_C , NULL },
{ "rname" , GETDNS_RDF_N_C , NULL },
{ "serial" , GETDNS_RDF_I4 , NULL },
{ "refresh" , GETDNS_RDF_I4 , NULL },
{ "retry" , GETDNS_RDF_I4 , NULL },
{ "expire" , GETDNS_RDF_I4 , NULL },
{ "minimum" , GETDNS_RDF_I4 , NULL }};
static _getdns_rdata_def mg_rdata[] = {
{ "mgmname" , GETDNS_RDF_N_C }};
{ "mgmname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def mr_rdata[] = {
{ "newname" , GETDNS_RDF_N_C }};
{ "newname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def null_rdata[] = {
{ "anything" , GETDNS_RDF_X }};
{ "anything" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def wks_rdata[] = {
{ "address" , GETDNS_RDF_A },
{ "protocol" , GETDNS_RDF_I1 },
{ "bitmap" , GETDNS_RDF_X }};
{ "address" , GETDNS_RDF_A , NULL },
{ "protocol" , GETDNS_RDF_I1 , NULL },
{ "bitmap" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def ptr_rdata[] = {
{ "ptrdname" , GETDNS_RDF_N_C }};
{ "ptrdname" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def hinfo_rdata[] = {
{ "cpu" , GETDNS_RDF_S },
{ "os" , GETDNS_RDF_S }};
{ "cpu" , GETDNS_RDF_S , NULL },
{ "os" , GETDNS_RDF_S , NULL }};
static _getdns_rdata_def minfo_rdata[] = {
{ "rmailbx" , GETDNS_RDF_N_C },
{ "emailbx" , GETDNS_RDF_N_C }};
{ "rmailbx" , GETDNS_RDF_N_C , NULL },
{ "emailbx" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def mx_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "exchange" , GETDNS_RDF_N_C }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "exchange" , GETDNS_RDF_N_C , NULL }};
static _getdns_rdata_def txt_rdata[] = {
{ "txt_strings" , GETDNS_RDF_S_M }};
{ "txt_strings" , GETDNS_RDF_S_M , NULL }};
static _getdns_rdata_def rp_rdata[] = {
{ "mbox_dname" , GETDNS_RDF_N },
{ "txt_dname" , GETDNS_RDF_N }};
{ "mbox_dname" , GETDNS_RDF_N , NULL },
{ "txt_dname" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def afsdb_rdata[] = {
{ "subtype" , GETDNS_RDF_I2 },
{ "hostname" , GETDNS_RDF_N }};
{ "subtype" , GETDNS_RDF_I2 , NULL },
{ "hostname" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def x25_rdata[] = {
{ "psdn_address" , GETDNS_RDF_S }};
{ "psdn_address" , GETDNS_RDF_S , NULL }};
static _getdns_rdata_def isdn_rdata[] = {
{ "isdn_address" , GETDNS_RDF_S },
{ "sa" , GETDNS_RDF_S }};
{ "isdn_address" , GETDNS_RDF_S , NULL },
{ "sa" , GETDNS_RDF_S , NULL }};
static _getdns_rdata_def rt_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "intermediate_host" , GETDNS_RDF_N }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "intermediate_host" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def nsap_rdata[] = {
{ "nsap" , GETDNS_RDF_X }};
{ "nsap" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def nsap_ptr_rdata[] = {
{ "owner" , GETDNS_RDF_S , NULL }};
static _getdns_rdata_def sig_rdata[] = {
{ "sig_obsolete" , GETDNS_RDF_X }};
{ "sig_obsolete" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def key_rdata[] = {
{ "key_obsolete" , GETDNS_RDF_X }};
{ "key_obsolete" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def px_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "map822" , GETDNS_RDF_N },
{ "mapx400" , GETDNS_RDF_N }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "map822" , GETDNS_RDF_N , NULL },
{ "mapx400" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def gpos_rdata[] = {
{ "longitude" , GETDNS_RDF_S },
{ "latitude" , GETDNS_RDF_S },
{ "altitude" , GETDNS_RDF_S }};
{ "longitude" , GETDNS_RDF_S , NULL },
{ "latitude" , GETDNS_RDF_S , NULL },
{ "altitude" , GETDNS_RDF_S , NULL }};
static _getdns_rdata_def aaaa_rdata[] = {
{ "ipv6_address" , GETDNS_RDF_AAAA }};
{ "ipv6_address" , GETDNS_RDF_AAAA , NULL }};
static _getdns_rdata_def loc_rdata[] = {
{ "loc_obsolete" , GETDNS_RDF_X }};
{ "loc_obsolete" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def nxt_rdata[] = {
{ "nxt_obsolete" , GETDNS_RDF_X }};
{ "nxt_obsolete" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def eid_rdata[] = {
{ "endpoint_identifier" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def nimloc_rdata[] = {
{ "nimrod_locator" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def srv_rdata[] = {
{ "priority" , GETDNS_RDF_I2 },
{ "weight" , GETDNS_RDF_I2 },
{ "port" , GETDNS_RDF_I2 },
{ "target" , GETDNS_RDF_N }};
{ "priority" , GETDNS_RDF_I2 , NULL },
{ "weight" , GETDNS_RDF_I2 , NULL },
{ "port" , GETDNS_RDF_I2 , NULL },
{ "target" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def atma_rdata[] = {
{ "format" , GETDNS_RDF_X }};
{ "format" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def naptr_rdata[] = {
{ "order" , GETDNS_RDF_I2 },
{ "preference" , GETDNS_RDF_I2 },
{ "flags" , GETDNS_RDF_S },
{ "service" , GETDNS_RDF_S },
{ "regexp" , GETDNS_RDF_S },
{ "replacement" , GETDNS_RDF_N }};
{ "order" , GETDNS_RDF_I2 , NULL },
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "flags" , GETDNS_RDF_S , NULL },
{ "service" , GETDNS_RDF_S , NULL },
{ "regexp" , GETDNS_RDF_S , NULL },
{ "replacement" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def kx_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "exchanger" , GETDNS_RDF_N }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "exchanger" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def cert_rdata[] = {
{ "type" , GETDNS_RDF_I2 },
{ "key_tag" , GETDNS_RDF_I2 },
{ "algorithm" , GETDNS_RDF_I1 },
{ "certificate_or_crl" , GETDNS_RDF_B }};
{ "type" , GETDNS_RDF_I2 , NULL },
{ "key_tag" , GETDNS_RDF_I2 , NULL },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "certificate_or_crl" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def a6_rdata[] = {
{ "a6_obsolete" , GETDNS_RDF_X }};
{ "a6_obsolete" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def dname_rdata[] = {
{ "target" , GETDNS_RDF_N }};
{ "target" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def opt_rdata[] = {
{ "options" , GETDNS_RDF_R },
{ "option_code" , GETDNS_RDF_I2 },
{ "option_data" , GETDNS_RDF_X_S }};
{ "options" , GETDNS_RDF_R , NULL },
{ "option_code" , GETDNS_RDF_I2 , NULL },
{ "option_data" , GETDNS_RDF_X_S , NULL }};
static _getdns_rdata_def apl_rdata[] = {
{ "apitems" , GETDNS_RDF_R },
{ "address_family" , GETDNS_RDF_I2 },
{ "prefix" , GETDNS_RDF_I1 },
{ "apitems" , GETDNS_RDF_R , NULL },
{ "address_family" , GETDNS_RDF_I2 , NULL },
{ "prefix" , GETDNS_RDF_I1 , NULL },
{ "n" , GETDNS_RDF_SPECIAL, &apl_n },
{ "afdpart" , GETDNS_RDF_SPECIAL, &apl_afdpart }};
static _getdns_rdata_def ds_rdata[] = {
{ "key_tag" , GETDNS_RDF_I2 },
{ "algorithm" , GETDNS_RDF_I1 },
{ "digest_type" , GETDNS_RDF_I1 },
{ "digest" , GETDNS_RDF_X }};
{ "key_tag" , GETDNS_RDF_I2 , NULL },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "digest_type" , GETDNS_RDF_I1 , NULL },
{ "digest" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def sshfp_rdata[] = {
{ "algorithm" , GETDNS_RDF_I1 },
{ "fp_type" , GETDNS_RDF_I1 },
{ "fingerprint" , GETDNS_RDF_X }};
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "fp_type" , GETDNS_RDF_I1 , NULL },
{ "fingerprint" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def ipseckey_rdata[] = {
{ "algorithm" , GETDNS_RDF_I1 },
{ "gateway_type" , GETDNS_RDF_I1 },
{ "precedence" , GETDNS_RDF_I1 },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "gateway_type" , GETDNS_RDF_I1 , NULL },
{ "precedence" , GETDNS_RDF_I1 , NULL },
{ "gateway" , GETDNS_RDF_SPECIAL, &ipseckey_gateway },
{ "public_key" , GETDNS_RDF_B }};
{ "public_key" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def rrsig_rdata[] = {
{ "type_covered" , GETDNS_RDF_I2 },
{ "algorithm" , GETDNS_RDF_I1 },
{ "labels" , GETDNS_RDF_I1 },
{ "original_ttl" , GETDNS_RDF_I4 },
{ "signature_expiration" , GETDNS_RDF_T },
{ "signature_inception" , GETDNS_RDF_T },
{ "key_tag" , GETDNS_RDF_I2 },
{ "signers_name" , GETDNS_RDF_N },
{ "signature" , GETDNS_RDF_B }};
{ "type_covered" , GETDNS_RDF_I2 , NULL },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "labels" , GETDNS_RDF_I1 , NULL },
{ "original_ttl" , GETDNS_RDF_I4 , NULL },
{ "signature_expiration" , GETDNS_RDF_T , NULL },
{ "signature_inception" , GETDNS_RDF_T , NULL },
{ "key_tag" , GETDNS_RDF_I2 , NULL },
{ "signers_name" , GETDNS_RDF_N , NULL },
{ "signature" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def nsec_rdata[] = {
{ "next_domain_name" , GETDNS_RDF_N },
{ "type_bit_maps" , GETDNS_RDF_X }};
{ "next_domain_name" , GETDNS_RDF_N , NULL },
{ "type_bit_maps" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def dnskey_rdata[] = {
{ "flags" , GETDNS_RDF_I2 },
{ "protocol" , GETDNS_RDF_I1 },
{ "algorithm" , GETDNS_RDF_I1 },
{ "public_key" , GETDNS_RDF_B }};
{ "flags" , GETDNS_RDF_I2 , NULL },
{ "protocol" , GETDNS_RDF_I1 , NULL },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "public_key" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def dhcid_rdata[] = {
{ "dhcid_opaque" , GETDNS_RDF_B }};
{ "dhcid_opaque" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def nsec3_rdata[] = {
{ "hash_algorithm" , GETDNS_RDF_I1 },
{ "flags" , GETDNS_RDF_I1 },
{ "iterations" , GETDNS_RDF_I2 },
{ "salt" , GETDNS_RDF_X_C },
{ "next_hashed_owner_name" , GETDNS_RDF_B32_C},
{ "type_bit_maps" , GETDNS_RDF_X }};
{ "hash_algorithm" , GETDNS_RDF_I1 , NULL },
{ "flags" , GETDNS_RDF_I1 , NULL },
{ "iterations" , GETDNS_RDF_I2 , NULL },
{ "salt" , GETDNS_RDF_X_C , NULL },
{ "next_hashed_owner_name" , GETDNS_RDF_B32_C , NULL },
{ "type_bit_maps" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def nsec3param_rdata[] = {
{ "hash_algorithm" , GETDNS_RDF_I1 },
{ "flags" , GETDNS_RDF_I1 },
{ "iterations" , GETDNS_RDF_I2 },
{ "salt" , GETDNS_RDF_X_C }};
{ "hash_algorithm" , GETDNS_RDF_I1 , NULL },
{ "flags" , GETDNS_RDF_I1 , NULL },
{ "iterations" , GETDNS_RDF_I2 , NULL },
{ "salt" , GETDNS_RDF_X_C , NULL }};
static _getdns_rdata_def tlsa_rdata[] = {
{ "certificate_usage" , GETDNS_RDF_I1 },
{ "selector" , GETDNS_RDF_I1 },
{ "matching_type" , GETDNS_RDF_I1 },
{ "certificate_association_data", GETDNS_RDF_X }};
{ "certificate_usage" , GETDNS_RDF_I1 , NULL },
{ "selector" , GETDNS_RDF_I1 , NULL },
{ "matching_type" , GETDNS_RDF_I1 , NULL },
{ "certificate_association_data", GETDNS_RDF_X , NULL }};
static _getdns_rdata_def hip_rdata[] = {
{ "pk_algorithm" , GETDNS_RDF_SPECIAL, &hip_pk_algorithm },
{ "hit" , GETDNS_RDF_SPECIAL, &hip_hit },
{ "public_key" , GETDNS_RDF_SPECIAL, &hip_public_key },
{ "rendezvous_servers" , GETDNS_RDF_N_M }};
{ "rendezvous_servers" , GETDNS_RDF_N_M , NULL }};
static _getdns_rdata_def talink_rdata[] = {
{ "previous" , GETDNS_RDF_N , NULL },
{ "next" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def openpgpkey_rdata[] = {
{ "transferable_public_key" , GETDNS_RDF_B , NULL }};
static _getdns_rdata_def csync_rdata[] = {
{ "serial" , GETDNS_RDF_I4 },
{ "flags" , GETDNS_RDF_I2 },
{ "type_bit_maps" , GETDNS_RDF_X }};
{ "serial" , GETDNS_RDF_I4 , NULL },
{ "flags" , GETDNS_RDF_I2 , NULL },
{ "type_bit_maps" , GETDNS_RDF_X , NULL }};
static _getdns_rdata_def spf_rdata[] = {
{ "text" , GETDNS_RDF_S_M }};
{ "text" , GETDNS_RDF_S_M , NULL }};
static _getdns_rdata_def nid_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "node_id" , GETDNS_RDF_AA }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "node_id" , GETDNS_RDF_AA , NULL }};
static _getdns_rdata_def l32_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "locator32" , GETDNS_RDF_A }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "locator32" , GETDNS_RDF_A , NULL }};
static _getdns_rdata_def l64_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "locator64" , GETDNS_RDF_AA }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "locator64" , GETDNS_RDF_AA , NULL }};
static _getdns_rdata_def lp_rdata[] = {
{ "preference" , GETDNS_RDF_I2 },
{ "fqdn" , GETDNS_RDF_N }};
{ "preference" , GETDNS_RDF_I2 , NULL },
{ "fqdn" , GETDNS_RDF_N , NULL }};
static _getdns_rdata_def eui48_rdata[] = {
{ "eui48_address" , GETDNS_RDF_X6 }};
{ "eui48_address" , GETDNS_RDF_X6 , NULL }};
static _getdns_rdata_def eui64_rdata[] = {
{ "eui64_address" , GETDNS_RDF_X8 }};
{ "eui64_address" , GETDNS_RDF_X8 , NULL }};
static _getdns_rdata_def tkey_rdata[] = {
{ "algorithm" , GETDNS_RDF_N },
{ "inception" , GETDNS_RDF_T },
{ "expiration" , GETDNS_RDF_T },
{ "mode" , GETDNS_RDF_I2 },
{ "error" , GETDNS_RDF_I2 },
{ "key_data" , GETDNS_RDF_X_S },
{ "other_data" , GETDNS_RDF_X_S }};
{ "algorithm" , GETDNS_RDF_N , NULL },
{ "inception" , GETDNS_RDF_T , NULL },
{ "expiration" , GETDNS_RDF_T , NULL },
{ "mode" , GETDNS_RDF_I2 , NULL },
{ "error" , GETDNS_RDF_I2 , NULL },
{ "key_data" , GETDNS_RDF_X_S , NULL },
{ "other_data" , GETDNS_RDF_X_S , NULL }};
static _getdns_rdata_def tsig_rdata[] = {
{ "algorithm" , GETDNS_RDF_N },
{ "time_signed" , GETDNS_RDF_T6 },
{ "fudge" , GETDNS_RDF_I2 },
{ "mac" , GETDNS_RDF_X_S },
{ "original_id" , GETDNS_RDF_I2 },
{ "error" , GETDNS_RDF_I2 },
{ "other_data" , GETDNS_RDF_X_S }};
{ "algorithm" , GETDNS_RDF_N , NULL },
{ "time_signed" , GETDNS_RDF_T6 , NULL },
{ "fudge" , GETDNS_RDF_I2 , NULL },
{ "mac" , GETDNS_RDF_X_S , NULL },
{ "original_id" , GETDNS_RDF_I2 , NULL },
{ "error" , GETDNS_RDF_I2 , NULL },
{ "other_data" , GETDNS_RDF_X_S , NULL }};
static _getdns_rdata_def uri_rdata[] = {
{ "priority" , GETDNS_RDF_I2 },
{ "weight" , GETDNS_RDF_I2 },
{ "target" , GETDNS_RDF_S_L }};
{ "priority" , GETDNS_RDF_I2 , NULL },
{ "weight" , GETDNS_RDF_I2 , NULL },
{ "target" , GETDNS_RDF_S_L , NULL }};
static _getdns_rdata_def caa_rdata[] = {
{ "flags" , GETDNS_RDF_I1 },
{ "tag" , GETDNS_RDF_S },
{ "value" , GETDNS_RDF_S_L }};
{ "flags" , GETDNS_RDF_I1 , NULL },
{ "tag" , GETDNS_RDF_S , NULL },
{ "value" , GETDNS_RDF_S_L , NULL }};
static _getdns_rdata_def dlv_rdata[] = {
{ "key_tag" , GETDNS_RDF_I2 },
{ "algorithm" , GETDNS_RDF_I1 },
{ "digest_type" , GETDNS_RDF_I1 },
{ "digest" , GETDNS_RDF_X }};
{ "key_tag" , GETDNS_RDF_I2 , NULL },
{ "algorithm" , GETDNS_RDF_I1 , NULL },
{ "digest_type" , GETDNS_RDF_I1 , NULL },
{ "digest" , GETDNS_RDF_X , NULL }};
static _getdns_rr_def _getdns_rr_defs[] = {
{ NULL, NULL, 0 },
@ -777,17 +684,17 @@ static _getdns_rr_def _getdns_rr_defs[] = {
{ "X25", x25_rdata, ALEN( x25_rdata) },
{ "ISDN", isdn_rdata, ALEN( isdn_rdata) },
{ "RT", rt_rdata, ALEN( rt_rdata) },
{ "NSAP", nsap_rdata, ALEN( nsap_rdata) }, /* - 22 */
{ NULL, NULL, 0 },
{ "SIG", sig_rdata, ALEN( sig_rdata) }, /* 24 - */
{ "NSAP", nsap_rdata, ALEN( nsap_rdata) },
{ "NSAP_PTR", nsap_ptr_rdata, ALEN( nsap_ptr_rdata) },
{ "SIG", sig_rdata, ALEN( sig_rdata) },
{ "KEY", key_rdata, ALEN( key_rdata) },
{ "PX", px_rdata, ALEN( px_rdata) },
{ "GPOS", gpos_rdata, ALEN( gpos_rdata) },
{ "AAAA", aaaa_rdata, ALEN( aaaa_rdata) },
{ "LOC", loc_rdata, ALEN( loc_rdata) },
{ "NXT", nxt_rdata, ALEN( nxt_rdata) },
{ "EID", UNKNOWN_RDATA, 0 },
{ "NIMLOC", UNKNOWN_RDATA, 0 },
{ "EID", eid_rdata, ALEN( eid_rdata) },
{ "NIMLOC", nimloc_rdata, ALEN( nimloc_rdata) },
{ "SRV", srv_rdata, ALEN( srv_rdata) },
{ "ATMA", atma_rdata, ALEN( atma_rdata) },
{ "NAPTR", naptr_rdata, ALEN( naptr_rdata) },
@ -807,16 +714,16 @@ static _getdns_rr_def _getdns_rr_defs[] = {
{ "DHCID", dhcid_rdata, ALEN( dhcid_rdata) },
{ "NSEC3", nsec3_rdata, ALEN( nsec3_rdata) },
{ "NSEC3PARAM", nsec3param_rdata, ALEN(nsec3param_rdata) },
{ "TLSA", tlsa_rdata, ALEN( tlsa_rdata) }, /* - 52 */
{ NULL, NULL, 0 },
{ "TLSA", tlsa_rdata, ALEN( tlsa_rdata) },
{ "SMIMEA", tlsa_rdata, ALEN( tlsa_rdata) }, /* - 53 */
{ NULL, NULL, 0 },
{ "HIP", hip_rdata, ALEN( hip_rdata) }, /* 55 - */
{ "NINFO", UNKNOWN_RDATA, 0 },
{ "RKEY", UNKNOWN_RDATA, 0 },
{ "TALINK", UNKNOWN_RDATA, 0 },
{ "TALINK", talink_rdata, ALEN( talink_rdata) },
{ "CDS", ds_rdata, ALEN( ds_rdata) },
{ "CDNSKEY", dnskey_rdata, ALEN( dnskey_rdata) },
{ "OPENPGPKEY", UNKNOWN_RDATA, 0 }, /* 61 - */
{ "OPENPGPKEY", openpgpkey_rdata, ALEN(openpgpkey_rdata) }, /* 61 - */
{ "CSYNC", csync_rdata, ALEN( csync_rdata) }, /* - 62 */
{ NULL, NULL, 0 },
{ NULL, NULL, 0 },
@ -1012,20 +919,21 @@ static _getdns_rr_def _getdns_rr_defs[] = {
{ "MAILA", UNKNOWN_RDATA, 0 }, /* - 254 */
{ NULL, NULL, 0 },
{ "URI", uri_rdata, ALEN( uri_rdata) }, /* 256 - */
{ "CAA", caa_rdata, ALEN( caa_rdata) }, /* - 257 */
{ "TA", UNKNOWN_RDATA, 0 }, /* 32768 */
{ "CAA", caa_rdata, ALEN( caa_rdata) },
{ "AVC", txt_rdata, ALEN( txt_rdata) }, /* - 258 */
{ "TA", ds_rdata, ALEN( ds_rdata) }, /* 32768 */
{ "DLV", dlv_rdata, ALEN( dlv_rdata) } /* 32769 */
};
const _getdns_rr_def *
_getdns_rr_def_lookup(uint16_t rr_type)
{
if (rr_type <= 257)
if (rr_type <= 258)
return &_getdns_rr_defs[rr_type];
else if (rr_type == 32768)
return &_getdns_rr_defs[258];
else if (rr_type == 32769)
return &_getdns_rr_defs[259];
else if (rr_type == 32769)
return &_getdns_rr_defs[260];
return _getdns_rr_defs;
}
@ -1115,7 +1023,12 @@ write_rdata_field(gldns_buffer *buf, uint8_t *rdata_start,
return GETDNS_RETURN_GENERIC_ERROR;
} else if (!(rd_def->type & GETDNS_RDF_REPEAT)) {
/*
* Non repetitive special rdatafield,
* We must have a dict2wire function
*/
assert(rd_def->special->dict2wire);
rdf_len = gldns_buffer_remaining(buf);
r = rd_def->special->dict2wire(rdata, rdata_start,
gldns_buffer_current(buf), &rdf_len);
@ -1125,12 +1038,21 @@ write_rdata_field(gldns_buffer *buf, uint8_t *rdata_start,
if (r)
return r;
/* We do not have repetitive special rdata fields (yet)
*
* LCOV_EXCL_START
*/
} else if ((r = getdns_dict_get_list(rdata, rd_def->name, &list))) {
return r == GETDNS_RETURN_NO_SUCH_DICT_NAME
? GETDNS_RETURN_GOOD : r;
} else for ( i = 0; r == GETDNS_RETURN_GOOD; i++ ) {
/*
* A repetitive special rdata field must have the list2wire
* function.
*/
assert(rd_def->special->list2wire);
rdf_len = gldns_buffer_remaining(buf);
r = rd_def->special->list2wire(list, i, rdata_start,
@ -1139,6 +1061,7 @@ write_rdata_field(gldns_buffer *buf, uint8_t *rdata_start,
r == GETDNS_RETURN_NEED_MORE_SPACE)
gldns_buffer_skip(buf, rdf_len);
}
/* LCOV_EXCL_STOP */
return r != GETDNS_RETURN_NO_SUCH_LIST_ITEM ? r : GETDNS_RETURN_GOOD;
}

View File

@ -138,7 +138,7 @@ typedef struct _getdns_rdata_def {
typedef struct _getdns_rr_def {
const char *name;
const _getdns_rdata_def *rdata;
int n_rdata_fields;
size_t n_rdata_fields;
} _getdns_rr_def;
const _getdns_rr_def *_getdns_rr_def_lookup(uint16_t rr_type);

View File

@ -75,8 +75,8 @@ find_rrtype(_getdns_rr_iter *i)
/* Past the last RR in the pkt */
if (i->pkt &&
GLDNS_QDCOUNT(i->pkt) + GLDNS_ANCOUNT(i->pkt) +
GLDNS_NSCOUNT(i->pkt) + GLDNS_ARCOUNT(i->pkt) <= i->n)
(size_t)GLDNS_QDCOUNT(i->pkt) + GLDNS_ANCOUNT(i->pkt) +
GLDNS_NSCOUNT(i->pkt) + GLDNS_ARCOUNT(i->pkt) <= i->n)
goto done;
for (pos = i->pos; pos + 4 < i->pkt_end; pos += *pos + 1)
@ -101,7 +101,7 @@ done:
}
_getdns_rr_iter *
_getdns_rr_iter_init(_getdns_rr_iter *i, const uint8_t *pkt, size_t pkt_len)
_getdns_rr_iter_init(_getdns_rr_iter *i, const uint8_t *pkt, const size_t pkt_len)
{
assert(i);
@ -119,7 +119,7 @@ _getdns_rr_iter_init(_getdns_rr_iter *i, const uint8_t *pkt, size_t pkt_len)
_getdns_rr_iter *
_getdns_single_rr_iter_init(
_getdns_rr_iter *i, const uint8_t *wire, size_t wire_len)
_getdns_rr_iter *i, const uint8_t *wire, const size_t wire_len)
{
assert(i);
@ -518,8 +518,16 @@ rdf_iter_find_nxt(_getdns_rdf_iter *i)
/* Empty rdata fields are only allowed in case of non-repeating
* remaining data. So only the GETDNS_RDF_BINDATA bit is set.
*
* There is one exception, the IPSECKEY has an empty special rdata
* field "gateway" when another rdata field, "gateway_type" is 0.
* In general, the special wire2dict or list functions should
* handle this case themselves, so allow for 0 sized RDF_SPECIAL
* typed rdata fields too.
*/
(i->nxt > i->pos || (i->rdd_pos->type == GETDNS_RDF_BINDATA)))
( i->nxt > i->pos
|| i->rdd_pos->type == GETDNS_RDF_BINDATA
|| i->rdd_pos->type == GETDNS_RDF_SPECIAL))
return i;
done:
i->pos = NULL;

View File

@ -76,7 +76,7 @@ _getdns_rr_iter *_getdns_single_rr_iter_init(_getdns_rr_iter *i,
const uint8_t *wire, const size_t wire_len);
static inline _getdns_rr_iter *_getdns_rr_iter_rewind(_getdns_rr_iter *i)
{ return _getdns_rr_iter_init(i, i->pkt, i->pkt_end - i->pkt); }
{ return i ? _getdns_rr_iter_init(i, i->pkt, i->pkt_end - i->pkt) : NULL; }
_getdns_rr_iter *_getdns_rr_iter_next(_getdns_rr_iter *i);
@ -86,19 +86,19 @@ const uint8_t *_getdns_owner_if_or_as_decompressed(
static inline _getdns_section
_getdns_rr_iter_section(_getdns_rr_iter *i)
{
return !i->pkt ? (i->nxt - i->rr_type == 4 ? SECTION_QUESTION
: SECTION_ANSWER )
: i->n < GLDNS_QDCOUNT(i->pkt) ? SECTION_QUESTION
: i->n < GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt) ? SECTION_ANSWER
: i->n < GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt)
+ GLDNS_NSCOUNT(i->pkt) ? SECTION_AUTHORITY
: i->n < GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt)
+ GLDNS_NSCOUNT(i->pkt)
+ GLDNS_ARCOUNT(i->pkt) ? SECTION_ADDITIONAL
: SECTION_ANY;
return ! i->pkt ? (i->nxt - i->rr_type == 4 ? SECTION_QUESTION
: SECTION_ANSWER )
: i->n < (size_t)GLDNS_QDCOUNT(i->pkt) ? SECTION_QUESTION
: i->n < (size_t)GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt) ? SECTION_ANSWER
: i->n < (size_t)GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt)
+ GLDNS_NSCOUNT(i->pkt) ? SECTION_AUTHORITY
: i->n < (size_t)GLDNS_QDCOUNT(i->pkt)
+ GLDNS_ANCOUNT(i->pkt)
+ GLDNS_NSCOUNT(i->pkt)
+ GLDNS_ARCOUNT(i->pkt) ? SECTION_ADDITIONAL
: SECTION_ANY;
}
/* Utility functions to read rr_type and rr_class from a rr iterator */
@ -181,7 +181,7 @@ static inline _getdns_rrset *_getdns_rrset_iter_value(_getdns_rrset_iter *i)
{ return i && i->rr_i.pos ? &i->rrset : NULL; }
static inline _getdns_rrset_iter *_getdns_rrset_iter_rewind(_getdns_rrset_iter *i)
{ return _getdns_rrset_iter_init(i, i->rrset.pkt, i->rrset.pkt_len, i->rrset.sections); }
{ return i ? _getdns_rrset_iter_init(i, i->rrset.pkt, i->rrset.pkt_len, i->rrset.sections) : NULL; }
typedef struct _getdns_rdf_iter {
const uint8_t *pkt;

View File

@ -26,7 +26,14 @@
*/
#include "config.h"
#ifndef USE_WINSOCK
#include <netdb.h>
#else
#include <winsock2.h>
#include <iphlpapi.h>
#endif
#include "getdns/getdns_extra.h"
#include "context.h"
#include "types-internal.h"
@ -65,6 +72,7 @@ struct listener {
*/
struct listen_set {
getdns_context *context;
void *userarg;
getdns_request_handler_t handler;
_getdns_rbtree_t connections_set;
@ -100,9 +108,9 @@ typedef struct tcp_connection {
getdns_eventloop_event event;
uint8_t *read_buf;
size_t read_buf_len;
ssize_t read_buf_len;
uint8_t *read_pos;
size_t to_read;
ssize_t to_read;
tcp_to_write *to_write;
size_t to_answer;
@ -127,7 +135,11 @@ static void tcp_connection_destroy(tcp_connection *conn)
loop->vmt->clear(loop, &conn->event);
if (conn->fd >= 0)
#ifdef USE_WINSOCK
(void) closesocket(conn->fd);
#else
(void) close(conn->fd);
#endif
GETDNS_FREE(*mf, conn->read_buf);
for (cur = conn->to_write; cur; cur = next) {
@ -177,8 +189,8 @@ static void tcp_write_cb(void *userarg)
}
to_write = conn->to_write;
if (conn->fd == -1 ||
(written = write(conn->fd, &to_write->write_buf[to_write->written],
to_write->write_buf_len - to_write->written)) == -1) {
(written = send(conn->fd, &to_write->write_buf[to_write->written],
to_write->write_buf_len - to_write->written, 0)) == -1) {
/* IO error, close connection */
conn->event.read_cb = conn->event.write_cb =
@ -231,7 +243,7 @@ _getdns_cancel_reply(getdns_context *context, connection *conn)
getdns_return_t
getdns_reply(
getdns_context *context, getdns_transaction_t request_id, getdns_dict *reply)
getdns_context *context, getdns_dict *reply, getdns_transaction_t request_id)
{
/* TODO: Check request_id at context->outbound_requests */
connection *conn = (connection *)(intptr_t)request_id;
@ -268,11 +280,15 @@ getdns_reply(
else if (conn->l->transport == GETDNS_TRANSPORT_UDP) {
listener *l = conn->l;
if (conn->l->fd >= 0 && sendto(conn->l->fd, buf, len, 0,
if (conn->l->fd >= 0 && sendto(conn->l->fd, (void *)buf, len, 0,
(struct sockaddr *)&conn->remote_in, conn->addrlen) == -1) {
/* IO error, cleanup this listener */
loop->vmt->clear(loop, &conn->l->event);
#ifdef USE_WINSOCK
closesocket(conn->l->fd);
#else
close(conn->l->fd);
#endif
conn->l->fd = -1;
}
/* Unlink this connection */
@ -351,7 +367,7 @@ static void tcp_read_cb(void *userarg)
(void) loop->vmt->schedule(loop, conn->fd,
DOWNSTREAM_IDLE_TIMEOUT, &conn->event);
if ((bytes_read = read(conn->fd, conn->read_pos, conn->to_read)) == -1) {
if ((bytes_read = recv(conn->fd, conn->read_pos, conn->to_read, 0)) < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
return; /* Come back to do the read later */
@ -400,9 +416,14 @@ static void tcp_read_cb(void *userarg)
else {
conn->to_answer++;
/* TODO: wish list item:
* (void) getdns_dict_set_int64(
* request_dict, "request_id", intptr_t)conn);
*/
/* Call request handler */
conn->super.l->set->handler(
conn->super.l->set->context, request_dict, (intptr_t)conn);
conn->super.l->set->context, GETDNS_CALLBACK_COMPLETE,
request_dict, conn->super.l->set->userarg, (intptr_t)conn);
conn->read_pos = conn->read_buf;
conn->to_read = 2;
@ -460,7 +481,11 @@ static void tcp_accept_cb(void *userarg)
&conn->super.remote_in, &conn->super.addrlen)) == -1) {
/* IO error, cleanup this listener */
loop->vmt->clear(loop, &l->event);
#ifdef USE_WINSOCK
closesocket(l->fd);
#else
close(l->fd);
#endif
l->fd = -1;
GETDNS_FREE(*mf, conn);
return;
@ -526,11 +551,15 @@ static void udp_read_cb(void *userarg)
conn->l = l;
conn->addrlen = sizeof(conn->remote_in);
if ((len = recvfrom(l->fd, buf, sizeof(buf), 0,
if ((len = recvfrom(l->fd, (void *)buf, sizeof(buf), 0,
(struct sockaddr *)&conn->remote_in, &conn->addrlen)) == -1) {
/* IO error, cleanup this listener. */
loop->vmt->clear(loop, &l->event);
#ifdef USE_WINSOCK
closesocket(l->fd);
#else
close(l->fd);
#endif
l->fd = -1;
#if 0 && defined(SERVER_DEBUG) && SERVER_DEBUG
@ -618,8 +647,14 @@ static void udp_read_cb(void *userarg)
conn->prev_next = &l->connections;
l->connections = conn;
/* TODO: wish list item:
* (void) getdns_dict_set_int64(
* request_dict, "request_id", (intptr_t)conn);
*/
/* Call request handler */
l->set->handler(l->set->context, request_dict, (intptr_t)conn);
l->set->handler(l->set->context, GETDNS_CALLBACK_COMPLETE,
request_dict, l->set->userarg, (intptr_t)conn);
return;
}
GETDNS_FREE(*mf, conn);
@ -636,7 +671,7 @@ static void free_listen_set_when_done(listen_set *set)
if (!(mf = &set->context->mf))
return;
DEBUG_SERVER("To free listen set: %p\n", set);
DEBUG_SERVER("To free listen set: %p\n", (void *)set);
for (i = 0; i < set->count; i++) {
listener *l = &set->items[i];
@ -647,7 +682,7 @@ static void free_listen_set_when_done(listen_set *set)
return;
}
GETDNS_FREE(*mf, set);
DEBUG_SERVER("Listen set: %p freed\n", set);
DEBUG_SERVER("Listen set: %p freed\n", (void *)set);
}
static void remove_listeners(listen_set *set)
@ -673,7 +708,11 @@ static void remove_listeners(listen_set *set)
continue;
loop->vmt->clear(loop, &l->event);
#ifdef USE_WINSOCK
closesocket(l->fd);
#else
close(l->fd);
#endif
l->fd = -1;
if (l->transport != GETDNS_TRANSPORT_TCP)
@ -692,7 +731,11 @@ static void remove_listeners(listen_set *set)
static getdns_return_t add_listeners(listen_set *set)
{
#ifdef USE_WINSOCK
static const char enable = 1;
#else
static const int enable = 1;
#endif
struct mem_funcs *mf;
getdns_eventloop *loop;
@ -726,9 +769,9 @@ static getdns_return_t add_listeners(listen_set *set)
break;
if (setsockopt(l->fd, SOL_SOCKET, SO_REUSEADDR,
&enable, sizeof(int)) < 0)
&enable, sizeof(int)) < 0) {
; /* Ignore */
}
if (bind(l->fd, (struct sockaddr *)&l->addr,
l->addr_len) == -1)
/* IO error */
@ -765,9 +808,9 @@ ptr_cmp(const void *a, const void *b)
return a == b ? 0 : (a < b ? -1 : 1);
}
getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
getdns_request_handler_t request_handler,
const getdns_list *listen_addresses)
getdns_return_t getdns_context_set_listen_addresses(
getdns_context *context, const getdns_list *listen_addresses,
void *userarg, getdns_request_handler_t request_handler)
{
static const getdns_transport_list_t listen_transports[]
= { GETDNS_TRANSPORT_UDP, GETDNS_TRANSPORT_TCP };
@ -786,10 +829,9 @@ getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
size_t i;
struct addrinfo hints;
DEBUG_SERVER("getdns_context_set_listen_addresses(%p, %p, %p)\n",
context, request_handler,
DEBUG_SERVER("getdns_context_set_listen_addresses(%p, <func>, %p)\n",
(void *)context, (void *)listen_addresses);
listen_addresses);
if (!(mf = &context->mf))
return GETDNS_RETURN_GENERIC_ERROR;
@ -826,10 +868,11 @@ getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
_getdns_rbtree_init(&new_set->connections_set, ptr_cmp);
DEBUG_SERVER("New listen set: %p, current_set: %p\n",
new_set, current_set);
(void *)new_set, (void *)current_set);
new_set->context = context;
new_set->handler = request_handler;
new_set->userarg = userarg;
new_set->count = new_set_count * n_transports;
(void) memset(new_set->items, 0,
sizeof(listener) * new_set_count * n_transports);
@ -952,15 +995,16 @@ getdns_return_t getdns_context_set_listen_addresses(getdns_context *context,
connection *conn;
loop->vmt->clear(loop, &l->to_replace->event);
(void) memset(&l->to_replace->event, 0,
sizeof(getdns_eventloop_event));
l->fd = l->to_replace->fd;
l->event = l->to_replace->event;
l->event.userarg = l;
l->connections = l->to_replace->connections;
for (conn = l->connections; conn; conn = conn->next)
conn->l = l;
(void) memset(&l->to_replace->event, 0,
sizeof(getdns_eventloop_event));
l->to_replace->connections = NULL;
l->to_replace->fd = -1;

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,8 @@
#include "getdns/getdns.h"
#include "types-internal.h"
getdns_return_t _getdns_submit_stub_request(getdns_network_req *netreq);
getdns_return_t _getdns_submit_stub_request(
getdns_network_req *netreq, uint64_t *now_ms);
void _getdns_cancel_stub_request(getdns_network_req *netreq);

View File

@ -123,18 +123,22 @@ getdns_sync_data_cleanup(getdns_sync_data *data)
* synchronous request.
*/
GETDNS_CLEAR_EVENT(upstream->loop, &upstream->event);
(*upstream->event.timeout_cb)(upstream->event.userarg);
/* This should have cleared the event */
assert(!upstream->event.read_cb &&
!upstream->event.write_cb &&
!upstream->event.timeout_cb);
if (upstream->conn_state != GETDNS_CONN_OPEN ||
upstream->keepalive_timeout == 0)
(*upstream->event.timeout_cb)(upstream->event.userarg);
}
upstream->loop = data->context->extension;
upstream->is_sync_loop = 0;
if (upstream->event.read_cb || upstream->event.write_cb)
GETDNS_SCHEDULE_EVENT(upstream->loop, upstream->fd,
TIMEOUT_FOREVER, &upstream->event);
else if (upstream->event.timeout_cb &&
upstream->conn_state == GETDNS_CONN_OPEN &&
upstream->keepalive_timeout != 0) {
GETDNS_SCHEDULE_EVENT(upstream->loop, upstream->fd,
upstream->keepalive_timeout, &upstream->event);
}
}
}
@ -151,6 +155,7 @@ getdns_sync_cb(getdns_context *context, getdns_callback_type_t callback_type,
getdns_dict *response, void *userarg, getdns_transaction_t transaction_id)
{
getdns_sync_data *data = (getdns_sync_data *)userarg;
(void)context; (void)callback_type; (void)transaction_id;
assert(data);

View File

@ -57,7 +57,8 @@ CHECK_EVENT_PROG=@CHECK_EVENT_PROG@
CHECK_EV_PROG=@CHECK_EV_PROG@
CC=@CC@
CFLAGS=-I$(srcdir)/.. -I$(srcdir) -I.. $(cflags) @CFLAGS@ @CPPFLAGS@
CFLAGS=-I$(srcdir)/.. -I$(srcdir) -I.. $(cflags) @CFLAGS@ @CPPFLAGS@ $(XTRA_CFLAGS)
WPEDANTICFLAG=@WPEDANTICFLAG@
LDFLAGS=-L.. @LDFLAGS@
LDLIBS=../libgetdns.la @LIBS@
CHECK_LIBS=@CHECK_LIBS@
@ -79,53 +80,53 @@ PROGRAMS=tests_dict tests_list tests_namespaces tests_stub_async tests_stub_sync
.SUFFIXES: .c .o .a .lo .h
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $< -o $@
.c.lo:
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $< -o $@
default: all
all: $(PROGRAMS)
$(ALL_OBJS):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $(srcdir)/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -c $(srcdir)/$(@:.lo=.c) -o $@
$(NON_C99_OBJS):
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -c $(srcdir)/$(@:.lo=.c) -o $@
$(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(WPEDANTICFLAG) -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -c $(srcdir)/$(@:.lo=.c) -o $@
tests_dict: tests_dict.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_dict.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ tests_dict.lo testmessages.lo
tests_list: tests_list.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_list.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ tests_list.lo testmessages.lo
tests_namespaces: tests_namespaces.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_namespaces.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ tests_namespaces.lo
tests_stub_async: tests_stub_async.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_async.lo testmessages.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_async.lo testmessages.lo
tests_stub_sync: tests_stub_sync.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ tests_stub_sync.lo
check_getdns_common: check_getdns_common.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns_common.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) -o $@ check_getdns_common.lo
check_getdns: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(LDFLAGS) $(LDLIBS) $(CHECK_LIBS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_selectloop.lo
check_getdns_event: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo ../libgetdns_ext_event.la
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_event.la $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libevent.lo $(LDFLAGS) $(LDLIBS) $(CHECK_LIBS) ../libgetdns_ext_event.la $(EXTENSION_LIBEVENT_LDFLAGS) $(EXTENSION_LIBEVENT_EXT_LIBS)
check_getdns_uv: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo ../libgetdns_ext_uv.la
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_uv.la $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libuv.lo $(LDFLAGS) $(LDLIBS) $(CHECK_LIBS) ../libgetdns_ext_uv.la $(EXTENSION_LIBUV_LDFLAGS) $(EXTENSION_LIBUV_EXT_LIBS)
check_getdns_ev: check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo ../libgetdns_ext_ev.la
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo $(LDFLAGS) $(LDLIBS) $(CHECK_CFLAGS) $(CHECK_LIBS) ../libgetdns_ext_ev.la $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ check_getdns.lo check_getdns_common.lo check_getdns_context_set_timeout.lo check_getdns_transport.lo check_getdns_libev.lo $(LDFLAGS) $(LDLIBS) $(CHECK_LIBS) ../libgetdns_ext_ev.la $(EXTENSION_LIBEV_LDFLAGS) $(EXTENSION_LIBEV_EXT_LIBS)
scratchpad: scratchpad.lo
$(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ scratchpad.lo $(LDFLAGS) $(LDLIBS)
$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ scratchpad.lo $(LDFLAGS) $(LDLIBS)
scratchpad.lo: scratchpad.c
@ -147,13 +148,28 @@ nolibcheck:
@echo "***"
@false
test: $(NOLIBCHECK) all
(cd $(srcdir)/../.. && find . -type f -executable -and \( -name "*.[ch]" -or -name "*.html" -or -name "*.in" -or -name "*.good" -or -name "*.ac" \) | awk 'BEGIN{e=0}{print("ERROR! Executable bit found on", $$0);e=1}END{exit(e)}')
test_noeventloop: $(NOLIBCHECK) all
rm -f $(CHECK_GETDNS).failed
GETDNS_TEST_PORT=43210 CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_GETDNS).log" ./$(CHECK_GETDNS) || echo "$(CHECK_GETDNS) failed" >> $(CHECK_GETDNS).failed
test_libevent: $(NOLIBCHECK) all
rm -f $(CHECK_EVENT_PROG).failed
if test $(have_libevent) = 1 ; then GETDNS_TEST_PORT=44321 CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_EVENT_PROG).log" ./$(CHECK_EVENT_PROG) || echo "$(CHECK_EVENT_PROG) failed" >> $(CHECK_EVENT_PROG).failed; fi
test_libev: $(NOLIBCHECK) all
rm -f $(CHECK_EV_PROG).failed
if test $(have_libev) = 1 ; then GETDNS_TEST_PORT=45432 CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_EV_PROG).log" ./$(CHECK_EV_PROG) || echo "$(CHECK_EV_PROG) failed" >> $(CHECK_EV_PROG).failed; fi
test_libuv: $(NOLIBCHECK) all
rm -f $(CHECK_UV_PROG).failed
if test $(have_libev) = 1 ; then GETDNS_TEST_PORT=46543 CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_UV_PROG).log" ./$(CHECK_UV_PROG) || echo "$(CHECK_UV_PROG) failed" >> $(CHECK_UV_PROG).failed; fi
test: test_noeventloop test_libevent test_libev test_libuv
rm -f fails
CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_GETDNS).log" ./$(CHECK_GETDNS) || echo "$(CHECK_GETDNS) failed" >> fails
if test $(have_libevent) = 1 ; then CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_EVENT_PROG).log" ./$(CHECK_EVENT_PROG) || echo "$(CHECK_EVENT_PROG) failed" >> fails; fi
if test $(have_libev) = 1 ; then CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_EV_PROG).log" ./$(CHECK_EV_PROG) || echo "$(CHECK_EV_PROG) failed" >> fails; fi
if test $(have_libuv) = 1 ; then CK_TIMEOUT_MULTIPLIER=2 CK_LOG_FILE_NAME="$(CHECK_UV_PROG).log" ./$(CHECK_UV_PROG) || echo "$(CHECK_UV_PROG) failed" >> fails; fi
if test -f $(CHECK_GETDNS).failed ; then cat $(CHECK_GETDNS).failed >> fails ; fi
if test -f $(CHECK_EVENT_PROG).failed ; then cat $(CHECK_EVENT_PROG).failed >> fails ; fi
if test -f $(CHECK_EV_PROG).failed ; then cat $(CHECK_EV_PROG).failed >> fails ; fi
if test -f $(CHECK_UV_PROG).failed ; then cat $(CHECK_UV_PROG).failed >> fails ; fi
test ! -e fails
@echo "All tests OK"

View File

@ -30,7 +30,14 @@
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#include <check.h>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include "getdns/getdns.h"
#include "check_getdns_common.h"
#include "check_getdns_address.h"
@ -75,7 +82,7 @@
int
main (int argc, char** argv)
main ()
{
int number_failed;
SRunner *sr ;

View File

@ -149,6 +149,7 @@
* rcode = 0
*/
void verify_getdns_address_6(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_address_6 };
struct getdns_context *context = NULL; \
void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0;
@ -157,7 +158,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_address(context, "google.com", NULL,
verify_getdns_address_6, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_address()");
RUN_EVENT_LOOP;
@ -183,6 +184,7 @@
* ancount = 1 (number of records in ANSWER section)
*/
void verify_getdns_address_7(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_address_7 };
struct getdns_context *context = NULL; \
void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0;
@ -191,7 +193,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_address(context, "localhost", NULL,
verify_getdns_address_7, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_address()");
RUN_EVENT_LOOP;
@ -213,6 +215,7 @@
* rcode = 3 (NXDOMAIN)
*/
void verify_getdns_address_8(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_address_8 };
struct getdns_context *context = NULL; \
void* eventloop = NULL; \
getdns_transaction_t transaction_id = 0;
@ -221,8 +224,8 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_address(context, "hostnamedoesntexist", NULL,
verify_getdns_address_8, &transaction_id, callbackfn),
ASSERT_RC(getdns_address(context, "hostnamedoesntexist.", NULL,
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_address()");
RUN_EVENT_LOOP;

View File

@ -55,6 +55,7 @@
* expect: GETDNS_RETURN_UNKNOWN_TRANSACTION
*/
void verify_getdns_cancel_callback(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_cancel_callback };
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
@ -65,7 +66,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_general(context, "google.com", GETDNS_RRTYPE_A, NULL,
verify_getdns_cancel_callback, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_general()");
RUN_EVENT_LOOP;
@ -86,6 +87,7 @@
* expect: GETDNS_RETURN_UNKNOWN_TRANSACTION
*/
void verify_getdns_cancel_callback(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_cancel_callback };
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
@ -96,7 +98,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_general(context, "google.com", GETDNS_RRTYPE_A, NULL,
verify_getdns_cancel_callback, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_general()");
RUN_EVENT_LOOP;
@ -133,7 +135,8 @@
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {};
getdns_transaction_t transaction_id_array[10]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
int odd = 0;
int even = 0;
@ -212,7 +215,8 @@
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {};
getdns_transaction_t transaction_id_array[10]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
int odd = 0;
int even = 0;
@ -295,7 +299,8 @@
struct getdns_bindata address_data = { 4, (void *)"\x08\x08\x08\x08" };
struct getdns_dict *address = NULL;
getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {};
getdns_transaction_t transaction_id_array[10]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
int odd = 0;
int even = 0;
@ -381,7 +386,8 @@
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
getdns_transaction_t transaction_id_array[10] = {};
getdns_transaction_t transaction_id_array[10]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
int odd = 0;
int even = 0;
@ -451,6 +457,8 @@
void *userarg,
getdns_transaction_t transaction_id)
{
(void)context; (void)response; (void)userarg;
callback_called++;
if(callback_type == GETDNS_CALLBACK_CANCEL)
@ -483,6 +491,7 @@
*/
void verify_getdns_cancel_callback(struct extracted_response *ex_response)
{
(void)ex_response;
/*
* increment callback_called global to prove callback was called.
*/

View File

@ -29,7 +29,14 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
#include <check.h>
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#include "getdns/getdns.h"
#include "config.h"
#include "check_getdns_common.h"
@ -320,6 +327,7 @@ void destroy_callbackfn(struct getdns_context *context,
void *userarg,
getdns_transaction_t transaction_id) {
int* flag = (int*)userarg;
(void)callback_type; (void)transaction_id;
*flag = 1;
getdns_dict_destroy(response);
getdns_context_destroy(context);
@ -338,7 +346,8 @@ void callbackfn(struct getdns_context *context,
getdns_transaction_t transaction_id)
{
typedef void (*fn_ptr)(struct extracted_response *ex_response);
fn_ptr fn = userarg;
fn_ptr fn = ((fn_cont *)userarg)->fn;
(void)context; (void)transaction_id;
/*
* If userarg is NULL, either a negative test case
@ -378,7 +387,7 @@ void callbackfn(struct getdns_context *context,
void update_callbackfn(struct getdns_context *context,
getdns_context_code_t changed_item)
{
(void)context;
ck_assert_msg(changed_item == expected_changed_item,
"Expected changed_item == %d, got %d",
changed_item, expected_changed_item);

View File

@ -211,6 +211,10 @@
struct getdns_dict *response,
void *userarg,
getdns_transaction_t transaction_id);
typedef struct fn_cont {
void (*fn)(struct extracted_response *ex_response);
} fn_cont;
/*
* callbackfn is the callback function given to all
* asynchronous query tests. It is expected to only

View File

@ -55,9 +55,13 @@
* GETDNS_RETURN_GOOD
*/
struct getdns_context *context = NULL;
getdns_append_name_t append_name;
CONTEXT_CREATE(TRUE);
// TODO: Do something here to verify set_from_os = TRUE
getdns_context_set_append_name(context, GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST);
getdns_context_get_append_name(context, &append_name);
ck_assert_msg(append_name == GETDNS_APPEND_NAME_TO_SINGLE_LABEL_FIRST, "suffix is not correct");
CONTEXT_DESTROY;
}
END_TEST

View File

@ -68,6 +68,7 @@
* expect: callback should be called before getdns_context_destroy() returns
*/
void verify_getdns_context_destroy(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_context_destroy };
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
@ -78,7 +79,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_general(context, "google.com", GETDNS_RRTYPE_A, NULL,
verify_getdns_context_destroy, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_general()");
RUN_EVENT_LOOP;
@ -95,6 +96,7 @@
* expect: callback should be called before getdns_context_destroy() returns
*/
void verify_getdns_context_destroy(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_context_destroy };
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
@ -105,7 +107,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_address(context, "google.com", NULL,
verify_getdns_context_destroy, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_address()");
RUN_EVENT_LOOP;
@ -122,6 +124,7 @@
* expect: callback should be called before getdns_context_destroy() returns
*/
void verify_getdns_context_destroy(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_context_destroy };
struct getdns_context *context = NULL;
void* eventloop = NULL;
struct getdns_bindata address_type = { 5, (void *)"IPv4" };
@ -141,7 +144,7 @@
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata");
ASSERT_RC(getdns_hostname(context, address, NULL,
verify_getdns_context_destroy, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_address()");
RUN_EVENT_LOOP;
@ -159,6 +162,7 @@
* expect: callback should be called before getdns_context_destroy() returns
*/
void verify_getdns_context_destroy(struct extracted_response *ex_response);
fn_cont fn_ref = { verify_getdns_context_destroy };
struct getdns_context *context = NULL;
void* eventloop = NULL;
getdns_transaction_t transaction_id = 0;
@ -169,7 +173,7 @@
EVENT_BASE_CREATE;
ASSERT_RC(getdns_service(context, "google.com", NULL,
verify_getdns_context_destroy, &transaction_id, callbackfn),
&fn_ref, &transaction_id, callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_service()");
RUN_EVENT_LOOP;
@ -267,6 +271,7 @@
void verify_getdns_context_destroy(struct extracted_response *ex_response)
{
(void)ex_response;
/*
* Sleep for a second to make getdns_context_destroy() wait.
*/

View File

@ -111,6 +111,8 @@
*/
struct getdns_context *context = NULL;
getdns_namespace_t namespace_arr[2] = {GETDNS_NAMESPACE_DNS, GETDNS_NAMESPACE_LOCALNAMES};
size_t count;
getdns_namespace_t *namespaces;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -118,8 +120,12 @@
expected_changed_item = GETDNS_CONTEXT_CODE_NAMESPACES;
ASSERT_RC(getdns_context_set_namespaces(context, 2,namespace_arr),
ASSERT_RC(getdns_context_set_namespaces(context, 2, namespace_arr),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_namespaces()");
ASSERT_RC(getdns_context_get_namespaces(context, &count, &namespaces),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_namespaces()");
ck_assert_msg(count == 2 && namespaces[0] == 500 && namespaces[1] == 501, "namespaces are not correctly set");
CONTEXT_DESTROY;
@ -207,6 +213,7 @@
* expect: GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS
*/
struct getdns_context *context = NULL;
getdns_redirects_t redir;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -215,6 +222,8 @@
expected_changed_item = GETDNS_CONTEXT_CODE_FOLLOW_REDIRECTS;
(void) getdns_context_set_follow_redirects(context, GETDNS_REDIRECTS_DO_NOT_FOLLOW);
(void) getdns_context_get_follow_redirects(context, &redir);
ck_assert_msg(redir == GETDNS_REDIRECTS_DO_NOT_FOLLOW, "getdns_context_get_follow_redirects failed");
CONTEXT_DESTROY;
@ -301,6 +310,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_EXTENDED_RCODE
*/
struct getdns_context *context = NULL;
uint8_t extended_rcode;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -310,6 +321,9 @@
ASSERT_RC(getdns_context_set_edns_extended_rcode(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_extended_rcode()");
ASSERT_RC(getdns_context_get_edns_extended_rcode(context, &extended_rcode),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_extended_rcode()");
ck_assert_msg(extended_rcode == 1, "extended_rcode should be 1, got %d", (int)extended_rcode);
CONTEXT_DESTROY;
@ -325,6 +339,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_VERSION
*/
struct getdns_context *context = NULL;
uint8_t version;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -334,6 +350,9 @@
ASSERT_RC(getdns_context_set_edns_version(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_version()");
ASSERT_RC(getdns_context_get_edns_version(context, &version),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_version()");
ck_assert_msg(version == 1, "version should be 1, got %d", (int)version);
CONTEXT_DESTROY;
@ -373,6 +392,8 @@
* expect: GETDNS_CONTEXT_CODE_EDNS_CLIENT_SUBNET_PRIVATE
*/
struct getdns_context *context = NULL;
uint8_t client_subnet_private;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -382,6 +403,9 @@
ASSERT_RC(getdns_context_set_edns_client_subnet_private(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_client_subnet_private()");
ASSERT_RC(getdns_context_get_edns_client_subnet_private(context, &client_subnet_private),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_client_subnet_private()");
ck_assert_msg(client_subnet_private == 1, "client_subnet_private should be 1, got %d", (int)client_subnet_private);
CONTEXT_DESTROY;
@ -397,6 +421,8 @@
* expect: GETDNS_CONTEXT_CODE_TLS_QUERY_PADDING_BLOCKSIZE
*/
struct getdns_context *context = NULL;
uint16_t pad;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
@ -406,6 +432,9 @@
ASSERT_RC(getdns_context_set_tls_query_padding_blocksize(context, 1400),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_tls_query_padding_blocksize()");
ASSERT_RC(getdns_context_get_tls_query_padding_blocksize(context, &pad),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_tls_query_padding_blocksize()");
ck_assert_msg(pad == 1400, "padding_blocksize should be 1400 but got %d", (int) pad);
CONTEXT_DESTROY;
@ -434,6 +463,33 @@
}
END_TEST
START_TEST (getdns_context_set_context_update_callback_23)
{
/*
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_context *context = NULL;
uint8_t round_robin;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_context_update_callback(context, update_callbackfn),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_context_update_callback()");
expected_changed_item = GETDNS_CONTEXT_CODE_ROUND_ROBIN_UPSTREAMS;
ASSERT_RC(getdns_context_set_round_robin_upstreams(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_round_robin_upstream()");
ASSERT_RC(getdns_context_get_round_robin_upstreams(context, &round_robin),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_round_robin_upstream()");
ck_assert_msg( round_robin == 1, "round_robin should be 1, got %d", (int)round_robin);
CONTEXT_DESTROY;
}
END_TEST
Suite *
getdns_context_set_context_update_callback_suite (void)
@ -462,6 +518,7 @@
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_20);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_21);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_22);
tcase_add_test(tc_pos, getdns_context_set_context_update_callback_23);
suite_add_tcase(s, tc_pos);
return s;

View File

@ -39,7 +39,7 @@
{
/*
* context is NULL
* expect: GETDNS_RETURN_BAD_CONTEXT
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_context *context = NULL;
@ -47,7 +47,12 @@
ASSERT_RC(getdns_context_set_dns_transport(context, value),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_context_unset_edns_maximum_udp_payload_size(context),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_context_unset_edns_maximum_udp_payload_size()");
}
END_TEST
@ -55,6 +60,7 @@
{
/*
* value is an undefined transport value
* do_bit is not correct
* expect: GETDNS_RETURN_CONTEXT_UPDATE_FAIL
*/
@ -66,6 +72,9 @@
ASSERT_RC(getdns_context_set_dns_transport(context, 233),
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_do_bit(context, 5),
GETDNS_RETURN_CONTEXT_UPDATE_FAIL, "Return code from getdns_context_set_edns_do_bit()");
CONTEXT_DESTROY;
}
@ -132,6 +141,9 @@
uint32_t tc;
uint32_t transport;
uint32_t type;
uint16_t payload_size;
uint8_t do_bit;
getdns_transport_t trans;
/* Note that stricly this test just establishes that the requested transport
and the reported transport are consistent, it does not guarentee which
@ -147,10 +159,22 @@
/* Request a response that should be truncated over UDP */
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_UDP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_get_dns_transport(context, &trans),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_dns_transport()");
ck_assert_msg(trans == 541, "dns_transport should be 541(GETDNS_TRANSPORT_UDP_ONLY) but got %d", (int)trans);
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_maximum_udp_payload_size()");
ASSERT_RC(getdns_context_get_edns_maximum_udp_payload_size(context, &payload_size),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_maximum_udp_payload_size()");
ck_assert_msg(payload_size == 512, "payload_size should be 512, got %d", (int)payload_size);
ASSERT_RC(getdns_context_set_edns_do_bit(context, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_edns_do_bit()");
ASSERT_RC(getdns_context_get_edns_do_bit(context, &do_bit),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_edns_do_bit()");
ck_assert_msg(do_bit == 1, "do_bit should be 1, got %d", (int)do_bit);
ASSERT_RC(getdns_general_sync(context, "large.getdnsapi.net", GETDNS_RRTYPE_TXT, extensions, &response),
GETDNS_RETURN_GOOD, "Return code from getdns_general_sync()");
@ -192,6 +216,9 @@
GETDNS_RETURN_GOOD, "Failed to extract \"tc\"");
ASSERT_RC(tc, 0, "Packet trucated - not as expected");
ASSERT_RC(getdns_context_unset_edns_maximum_udp_payload_size(context),
GETDNS_RETURN_GOOD, "Return code from getdns_context_unset_edns_maximum_udp_payload_size()");
CONTEXT_DESTROY;
}
@ -261,7 +288,9 @@
* suspect them to be a bit more reliable.
*/
struct getdns_list *root_servers = getdns_list_create();
struct getdns_list *root_servers2 = getdns_list_create();
struct getdns_bindata nlnetlabs_root = { 4, (void *)"\xB9\x31\x8D\x25" };
struct getdns_bindata *answer = NULL;
uint32_t status;
uint32_t type;
@ -277,10 +306,17 @@
/* Re-do over TCP */
ASSERT_RC(getdns_dict_set_int(extensions,"return_call_reporting", GETDNS_EXTENSION_TRUE),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_list_set_bindata(root_servers,0,&nlnetlabs_root),
ASSERT_RC(getdns_list_set_bindata(root_servers, 0, &nlnetlabs_root),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_context_set_dns_root_servers(context, root_servers),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_root_servers()");
ASSERT_RC(getdns_context_get_dns_root_servers(context, &root_servers2),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_dns_root_servers()");
ASSERT_RC(getdns_list_get_bindata(root_servers2, 0, &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_bindata()");
ck_assert_msg(strncmp((char *)answer->data, (char *)nlnetlabs_root.data, 4) == 0,
"Expected answer data to be 185.49.141.37");
ASSERT_RC(getdns_context_set_dns_transport(context, GETDNS_TRANSPORT_TCP_ONLY),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport()");
ASSERT_RC(getdns_context_set_edns_maximum_udp_payload_size(context, 512),
@ -348,6 +384,60 @@
}
END_TEST
START_TEST (getdns_context_set_dns_transport_recursing_9)
{
/*
* Check TLS
*/
struct getdns_context *context = NULL;
getdns_resolution_t resolution_type;
getdns_transport_list_t transport_list[1];
getdns_transport_list_t *transport_list2;
size_t count;
getdns_tls_authentication_t auth;
uint16_t backoff;
uint16_t retries;
transport_list[0] = GETDNS_TRANSPORT_TLS;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_resolution_type(context, GETDNS_RESOLUTION_STUB),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_resolution_type()");
ASSERT_RC(getdns_context_get_resolution_type(context, &resolution_type),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_resolution_type()");
ck_assert_msg(resolution_type == GETDNS_RESOLUTION_STUB, "resolution_type should be stub (520), got %d", (int)resolution_type);
ASSERT_RC(getdns_context_set_dns_transport_list(context, 1, transport_list),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_dns_transport_list()");
ASSERT_RC(getdns_context_get_dns_transport_list(context, &count, &transport_list2),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_dns_transport_list()");
ck_assert_msg(transport_list2[0] == GETDNS_TRANSPORT_TLS, "transport_list should be 1202 but got %d", (int) transport_list2[0]);
ASSERT_RC(getdns_context_set_tls_authentication(context, GETDNS_AUTHENTICATION_REQUIRED),
GETDNS_RETURN_GOOD, "Return cond from getdns_context_set_tls_authentication()");
ASSERT_RC(getdns_context_get_tls_authentication(context, &auth),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_tls_authentication()");
ck_assert_msg(auth == 1301, "tls_authentication should be 1301, but got %d", (int) auth);
ASSERT_RC(getdns_context_set_tls_backoff_time(context, 1000),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_tls_backoff_time()");
ASSERT_RC(getdns_context_get_tls_backoff_time(context, &backoff),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_tls_backoff_time()");
ck_assert_msg(backoff == 1000, "backoff should be 1000, but got %d", (int) backoff);
ASSERT_RC(getdns_context_set_tls_connection_retries(context, 5),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_tls_connection_retries()");
ASSERT_RC(getdns_context_get_tls_connection_retries(context, &retries),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_tls_connection_retries()");
ck_assert_msg(retries == 5, "retries should be 5 but got %d", (int) retries);
/*TODO: should extend the test */
CONTEXT_DESTROY;
}
END_TEST
@ -372,7 +462,8 @@
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_6);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_7);
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_8);
/* TODO: TLS... */
/* TLS */
tcase_add_test(tc_pos, getdns_context_set_dns_transport_recursing_9);
suite_add_tcase(s, tc_pos);

View File

@ -94,15 +94,21 @@ END_TEST
START_TEST (getdns_context_set_idle_timeout_2)
{
/*
* timeout is 0
* timeout is 0 and then 100
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_context *context = NULL;
uint64_t time;
CONTEXT_CREATE(TRUE);
ASSERT_RC(getdns_context_set_idle_timeout(context, 0),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
ASSERT_RC(getdns_context_set_idle_timeout(context, 100),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
ASSERT_RC(getdns_context_get_idle_timeout(context, &time),
GETDNS_RETURN_GOOD, "Return code from getdns_context_set_timeout()");
ck_assert_msg(time == 100, "idle_timeout should be 100, got %d", (int)time);
CONTEXT_DESTROY;
@ -114,6 +120,23 @@ END_TEST
#define GETDNS_STR_ADDRESS_TYPE "address_type"
#define GETDNS_STR_ADDRESS_DATA "address_data"
#define GETDNS_STR_PORT "port"
#define TEST_PORT 43210
static uint16_t get_test_port(void)
{
char *test_port_str;
uint16_t test_port;
struct timeval tv;
if (!(test_port_str = getenv("GETDNS_TEST_PORT")) ||
!(test_port = (uint16_t)atoi(test_port_str)))
test_port = TEST_PORT;
(void)gettimeofday(&tv, NULL);
srandom((int)getpid() + (int)tv.tv_usec);
test_port += random() % 1000;
return test_port;
}
/* utilities to start a junk udp listener */
typedef struct timeout_thread_data {
@ -243,6 +266,7 @@ void timeout_3_cb(struct getdns_context *context,
getdns_callback_type_t callback_type,
struct getdns_dict * response,
void *userarg, getdns_transaction_t transaction_id) {
(void)response; (void)transaction_id;
timeout_thread_data *tdata = (timeout_thread_data*)userarg;
tdata->num_callbacks++;
if (callback_type == GETDNS_CALLBACK_TIMEOUT) {
@ -280,7 +304,8 @@ START_TEST (getdns_context_set_timeout_3)
t_data.running = 0;
t_data.num_callbacks = 0;
t_data.num_timeouts = 0;
t_data.port = 43210;
uint64_t timeout;
t_data.port = get_test_port();
pthread_create(&thread, NULL, run_server, (void *)&t_data);
@ -300,7 +325,7 @@ START_TEST (getdns_context_set_timeout_3)
bindata.data = (uint8_t*) &local_addr;
ASSERT_RC(getdns_dict_set_bindata(server_dict, GETDNS_STR_ADDRESS_DATA, &bindata),
GETDNS_RETURN_GOOD, "set addr bindata");
ASSERT_RC(getdns_dict_set_int(server_dict, GETDNS_STR_PORT, 43210),
ASSERT_RC(getdns_dict_set_int(server_dict, GETDNS_STR_PORT, t_data.port),
GETDNS_RETURN_GOOD, "set addr port");
upstream_list = getdns_list_create_with_context(context);
@ -323,6 +348,10 @@ START_TEST (getdns_context_set_timeout_3)
RUN_EVENT_LOOP;
ASSERT_RC(getdns_context_get_timeout(context, &timeout),
GETDNS_RETURN_GOOD, "Return code from getdns_context_get_timeout()");
ck_assert_msg(timeout == 500, "timeout should be 500, got %d", (int)timeout);
CONTEXT_DESTROY;
t_data.running = 0;

Some files were not shown because too many files have changed in this diff Show More