From 416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
+s6-dns
+ The standard C library provides an API to perform name
+resolution:
+getaddrinfo(),
+formerly gethostbyname(). However, for DNS resolution as well as
+implementation in the libc, this interface is very impractical, to the point of
+being unusable. Here are a few reasons why.
+
+ I explained this point in a message to the
+Busybox mailing-list. You can
+read
+the post here.
+(There is a mistake in that post about /etc/nsswitch.conf and
+/etc/host.conf syntax; the following two messages in the thread
+correct that mistake.)
+
+ TLDR: depending on the machine configuration, it is possible that
+getaddrinfo() will not use DNS at all.
+
+ DNS resolution performs network I/O, which can take a non-negligible
+amount of time. getaddrinfo() is a blocking call and there is
+no way to specify a timeout to make it return early, so it may block
+indefinitely. This is bad design.
+
+ Also, network operations being asynchronous by nature, even a
+synchronous API should provide a way to perform several queries at
+once and return when one of them, or all of them, get an answer.
+getaddrinfo() does not even offer that.
+
+ Because it's generic, getaddrinfo() is cumbersome to use.
+ The data structures are impractical, requiring the user to fill in
+information that is irrelevant to DNS resolution. The details of the
+network transport protocols are of no interest to the user who just
+wants answers to his DNS queries!
+
+ But at the same time, getaddrinfo() does not allow the
+user to provide the details he wants or refine his search. It's a very
+basic and monolithic entry point, with no DNS-specific knobs. For
+instance, only A and AAAA queries are supported, which is clearly
+insufficient.
+
+getaddrinfo() is a toy interface. For any half-serious DNS work,
+another API must be used.
+
+ Most people who need a real DNS client library use BIND's libresolv.
+This page explains what is wrong with it,
+and what s6-dns tries to do better.
+
+Software
+ s6-dns is a suite of DNS client programs and libraries for Unix
+systems, as an alternative to the BIND, djbdns or other DNS clients.
+
+ s6-dns may include its own series of DNS caches and servers at some
+point in the future.
+
+ s6-dns is free software. It is available under the
+ISC license.
+
+ All these commands exit 111 if they encounter a temporary error or
+hardware error, and
+100 if they encounter a permanent error - such as a misuse. Short-lived
+commands exit 0 on success. Other exit codes are documented in the
+relevant page.
+
+s6-dns
+ The BIND name server software comes with its own client library,
+named libresolv.
+
+ As can be expected from an ISC product, libresolv is not good software.
+Here are a few reasons why.
+
+ The same people who wrote BIND wrote libresolv. That is the amount of
+trust you can place in libresolv. Ten years ago, the security status
+of libresolv looked like
+this. I am not
+confident that is has improved: bugs in the software may have been
+fixed, but new ones will appear, and most importantly, the security
+management policy at ISC is still the same: security holes will be
+denied instead of acknowledged and worked upon.
+
+ If you find a bug, and a fortiori a security hole, in
+s6-dns, you can be sure it will be fixed promptly with apologies
+from the author. skarnet.org doesn't do obfuscation, and never lets
+politics get in the way of technical quality.
+
+ You'd expect a real DNS client library to do better in this aspect
+than getaddrinfo(), but no: libresolv's
+function calls are still purely synchronous and may uncontrollably
+block if the network is unresponsive.
+
+ Additionally, libresolv only provides a synchronous
+interface to clients. Despite the fundamentally asynchronous nature
+of DNS, and the need to implement asynchronous primitives
+internally, only blocking calls are made available in the API.
+This forces users to stack yet another piece of software on top
+of their dependencies if they need asynchronous DNS resolution.
+
+ libs6dns provides several layers of asynchronous interfaces.
+The user has access to
+low-level packet sending
+and receiving, to
+synchronous
+resolution of several queries at once, and to a
+real high-level asynchronous DNS library.
+
+ The libresolv-2.13.so binary file compiled for an i386
+Debian Linux system is roughly 71k bytes. The libs6dns.so.2.0
+file, for the same system, is roughly 41k bytes, while offering
+more functionality. libresolv does not do any high-level answer
+parsing, so the user still has to do some work after the libresolv
+calls. s6-dns tries to be small and still provide the user comfortable
+interfaces.
+
+ Some examples of less-than-ideal interfaces for the users:
+
+ There is a reason why system calls and local functions take
+user-supplied buffers as arguments. They are relatively fast, it is
+not too costly to call them again if the buffer is too small the
+first time, and the result is consistent, i.e. after the first call,
+the right buffer length is known. But functions making
+network exchanges with variable-length results from one call to
+another ? Those need heap-allocated storage. It is
+good design to avoid using the heap whenever possible, but it is
+not good design to waste network round-trips to save a malloc().
+
+ Like many other "standards", and C library interfaces in particular,
+libresolv is at best a mediocre one, that people use because
+there has been nothing better so far.
+
+ s6-dns tries to be an alternative solution - not as ambitious,
+but based on solid design principles and a reliable code base.
+
+s6-dns
+ libs6dns is a DNS client library, designed for clarity
+and simplicity - which translates into smallness of the code.
+
+ A major focus of libs6dns is to avoid unnecessary use
+of heap memory. Memory is only allocated in the heap to store
+queries and response packets during a DNS resolution process, and
+to store the final answers into a user-provided
+
+stralloc; all the other operations use stack memory, and perform
+as few copies as possible.
+
+ The s6dns.h header is actually a concatenation of other headers:
+the libs6dns is separated into several modules, each of them with its
+own header.
+
+ (User-level asynchronous resolution functions are provided in the
+skadns library.)
+
+ Two functional macros are actually directly declared in the s6dns.h
+header:
+
+libs6dns
+ The following functions and structures are declared in the s6-dns/s6dns-domain.h header,
+and implemented in the libs6dns.a or libs6dns.so library.
+
+ s6dns_domain provides primitives to perform basic operations
+on domain names.
+
+ A s6dns_domain_t is a structure that s6dns uses internally to
+represent a domain name. It can be in string form (or
+decoded form), which is close to the printable form seen
+by users, or in packet form (or encoded form), which
+is the format used in the DNS protocol.
+
+ A s6dns_domain_t is a flat structure and can be declared
+on the stack.
+
+
+
+
+
+
+
+
+
+
+
+
+libs6dns
+ The following functions are declared in the s6-dns/s6dns-engine.h header,
+and implemented in the libs6dns.a or libs6dns.so library.
+
+ s6dns_engine is the nitty-gritty of DNS query management. These
+are the low-level asynchronous primitives sending DNS queries over the
+network, and getting answers.
+
+ s6dns_engine has been inspired by Dan J. Bernstein's
+dns_transmit
+library, but does not borrow any code from it. Unlike
+dns_transmit, s6dns_engine does not assume that
+network send operations are instant successes; s6dns_engine
+descriptors can be selected for writing as well as for reading.
+Also, if the underlying
+skalibs has been compiled with IPv6 support, s6dns_engine
+supports native IPv6 transport.
+
+ The s6dns_engine functions are used in the implementation of the
+s6dns_resolven_loop function - which is nothing more than a
+simple event loop around the s6dns_engine primitives - and the
+skadnsd daemon. Both pieces of code are
+good examples of how to use s6dns_engine.
+
+ However, unless you're implementing a DNS cache, you probably should
+not call the
+s6dns_engine functions directly: they are very low-level. If you
+need synchronous resolution, use the
+s6dns_resolve functions. If you need
+asynchronous DNS operations, use the
+skadns functions, which are
+designed to provide a higher level interface to multiple asynchronous
+DNS queries.
+
+ A s6dns_engine_t structure holds all the data necessary to
+manage a DNS query (and response). It must be initialized to S6DNS_ENGINE_ZERO
+when first declared, and recycled with s6dns_engine_recycle()
+after each use. It contains a stralloc, so it must be freed with
+s6dns_engine_free() before being discarded, to avoid memory leaks.
+
+
+Initializes dt with query q of length qlen
+and type qtype. If d is an
+encoded s6dns_domain_t, then d.s and d.len
+are appropriate candidates for arguments q and qlen
+respectively.
+
+options can be 0 or an OR'ed
+combination of the following, defined in s6-dns/s6dns-constants.h:
+
+servers must point to a list of IP addresses as defined in
+s6-dns/s6dns-ip46.h. Such a list can be
+obtained from the /etc/resolv.conf file via the
+s6dns_rci_fill() call when performing a
+recursive query, or it must be constructed from a list of relevant
+NS addresses when performing an iterative query.
+
+stamp must be an accurate enough timestamp. deadline
+sets up a deadline for the query: if the query hasn't been
+satisfactorily answered by deadline - no matter how many
+round-trips to network servers the library performs internally - then
+it will be considered failed, and a timeout will be reported.
+
+The function returns 1 if all went well, and 0 if an error occurred.
+It returns instantly; it does not perform any network operation,
+it just prepares dt to send a query. The actual data sending
+will take place on the next s6dns_engine_event() call.
+
+
+Recycles dt, making it ready for another use. This function
+does not deallocate the heap memory used by dt, so it's faster than
+s6dns_engine_free() and does not cause heap fragmentation.
+
+
+Frees the heap memory used by dt. Also makes dt
+ready for another use. It's advised to only use this function when
+certain that dt will not be reused.
+
+ The descriptor to select on is available as the fd field in
+the s6dns_engine_t structure.
+dt→fd should be read every iteration, because it can
+change between iterations even if no event or timeout is reported
+for dt.
+
+
+If dt needs handling before the absolute date *a,
+then *a is updated
+so it contains the earlier date. This is useful to compute the next
+deadline in an iopause() loop.
+
+
+Returns nonzero iff dt→fd is to be selected for reading.
+Should be called in every iteration.
+
+
+Returns nonzero iff dt→fd is to be selected for writing.
+Should be called in every iteration.
+
+
+This function should be called if your selecting function returned 0, which
+means that an event timed out.
+stamp should contain the current time. The function returns -1 if
+an error occurred, 1 if dt actually timed out, and 0 if nothing
+special happened to dt (and your iopause timeout was caused by
+something else). If the return value is not 0, dt is automatically
+recycled.
+
+
+This function should be called if your selecting function returned a positive
+number, which means that some event got triggered.
+stamp should contain the current time. The function returns
+-1 if an error occurred (and dt is automatically recycled). It
+returns 0 if no answer has arrived yet, and 1 if an answer is available.
+
+The s6dns_engine_timeout() and s6dns_engine_event() functions,
+when returning -1, make use of the following error codes:
+
+
+Points to the response packet received from the network,
+if s6dns_engine_event() returned 1.
+
+
+Gives the length of the response packet,
+if s6dns_engine_event() returned 1.
+
+ You should recycle or free dt after reading the response packet.
+
+libs6dns
+ The following functions and structures are declared in the s6-dns/s6dns-fmt.h header,
+and implemented in the libs6dns.a or libs6dns.so library.
+
+ s6dns_fmt provides primitives to format RR contents into
+printable strings.
+
+
+
+
+
+
+
+libs6dns
+ The following functions are declared in the s6-dns/s6dns-ip46.h header,
+and implemented as macros.
+
+ s6dns_ip46 is the transport abstraction layer. It allows
+the functions declared in s6-dns/s6dns-engine.h
+and s6-dns/s6dns-rci.h to be transport-agnostic,
+i.e. to be able to work with both IPv4 and IPv6.
+
+ If the underlying skalibs
+has been compiled with
+ flag-noipv6,
+or if it has detected at build time that the target host does not support
+IPv6, then the s6dns-ip46 abstraction will be totally transparent and use
+no resources at all.
+
+ A s6dns_ip46list_t structure holds a list of S6DNS_MAX_SERVERS (16)
+IPv4 or IPv6 addresses. Such a mixed list can be constructed, for
+instance, if the /etc/resolv.conf file contains both v4 and v6
+nameserver lines.
+
+ If list is a s6dns_ip46list_t and i an integer
+between 0 and DNS_MAX_SERVERS-1, then
+
+libs6dns
+ The following functions are declared in the s6-dns/s6dns-message.h header,
+and implemented in the libs6dns.a or libs6dns.so library.
+
+ s6dns_message provides functions to read and parse DNS messages
+sent by servers and caches and containing answers to queries.
+
+ A s6dns_message_header_t is a structure containing the header
+of a received DNS packet, broken down for easy access to the bits.
+
+ A s6dns_message_rr_t is a structure containing the information
+about a resource record given by an answer packet - all of it, except the
+value of the answer itself, which is rtype-specific and has to be decoded
+by rtype-specific functions.
+
+ A s6dns_message_rr_func_t is the type of such a function. The
+prototype is
+ Various structures designed to store specific resource record types are
+also provided. The list includes:
+
+
+
+ The following primitives are used in the implementation of
+s6dns_message_rr_func_t-typed functions, to read and decode information
+stored in a DNS packet. Their arguments are:
+
+
+
+
+
+
+
+
+
+
+
+Software
+skarnet.org
+ The problem with getaddrinfo()
+
+ getaddrinfo() performs NSS resolution, not DNS resolution.
+
+ It is unboundedly synchronous.
+
+ It focuses on the wrong details.
+
+ Conclusion
+
+
+skarnet.org
+ s6-dns
+
+ What is it ?
+
+
+
+
+
+
+
+
+ Installation
+
+ Requirements
+
+
+
+
+ Licensing
+
+ Download
+
+
+
+
+ git clone git://git.skarnet.org/s6-dns
Compilation
+
+
+
+
+ Upgrade notes
+
+
+
+
+ Reference
+
+ Commands
+
+ Command-line DNS clients programs
+
+
+
+
+ Filtering tools
+
+
+
+ Command-line qualification
+
+
+
+ DNS analysis and debug tools
+
+
+
+ Miscellaneous utilities
+
+
+
+
+ Libraries
+
+ Protocol implementation and synchronous resolution
+
+
+
+ Asynchronous resolution
+
+
+
+
+
+
+ Related resources
+
+
+ s6-dns discussion
+
+
+
+
+ Similar work
+
+
+
+
+
+
diff --git a/doc/libresolv.html b/doc/libresolv.html
new file mode 100644
index 0000000..7a9fd31
--- /dev/null
+++ b/doc/libresolv.html
@@ -0,0 +1,140 @@
+
+
+
+
+
+Software
+skarnet.org
+ The problem with libresolv
+
+ libresolv's security model is flawed.
+
+ libresolv is unboundedly synchronous.
+
+ It is too big for what it does.
+
+ The API is cumbersome to use.
+
+
+
+
+ Conclusion
+
+
+Software
+skarnet.org
+ The s6dns library interface
+
+ General information
+
+ Compiling
+
+
+
+
+ Linking
+
+
+
+
+ Programming
+
+
+
+
+
+
+
+
+
diff --git a/doc/libs6dns/s6dns-domain.html b/doc/libs6dns/s6dns-domain.html
new file mode 100644
index 0000000..b1492c3
--- /dev/null
+++ b/doc/libs6dns/s6dns-domain.html
@@ -0,0 +1,137 @@
+
+
+
+
+
+s6-dns
+Software
+skarnet.org
+ The s6dns_domain library interface
+
+ General information
+
+ Data structures
+
+ Functions
+
+ int s6dns_domain_fromstring (s6dns_domain_t *d, char const *s, unsigned int len)
+Makes a (string form) domain from string s of length len,
+and stores it into *d. Returns 1 if it succeeds, otherwise it
+returns 0 and sets errno appropriately - most likely ENAMETOOLONG, i.e.
+the name in s is not a well-formed domain name.
+ unsigned int s6dns_domain_tostring (char *s, unsigned int max, s6dns_domain_t const *d)
+Writes into string s the domain contained in *d (in string
+form). Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+ int s6dns_domain_noqualify (s6dns_domain_t *d)
+Makes sure that *d is fully qualified. This is done without using
+qualification: a trailing dot is simply appended if the domain
+doesn't already have one. Returns 1 if it succeeds, or 0 if it fails.
+ unsigned int s6dns_domain_qualify (s6dns_domain_t *list, s6dns_domain_t const *d, char const *rules, unsigned int rulesnum)
+Performs qualification on domain *d according to the first
+rulesnum rules stored in string rules. Stores the output
+(at most rulesnum domains) into the array pointed to by list.
+Returns 0 on failure, or the number of written domains if it succeeds. This
+number can be lesser than rulesnum, for instance if *d is
+already fully qualified.
+Valid rules and rulesnum can be obtained via functions
+declared in s6dns-rci.h.
+ int s6dns_domain_encode (s6dns_domain_t *d)
+Encodes domain *d from string form to packet form. Returns 1
+if it succeeds or 0 if it fails - for instance, *d is not a
+valid string form (EINVAL).
+ unsigned int s6dns_domain_encodelist (s6dns_domain_t *list, unsigned int n)
+Encodes n domains pointed to by list from string form to packet form,
+stopping at the first failure.
+Returns the number of successfully encoded domains, normally n.
+ int s6dns_domain_decode (s6dns_domain_t *d)
+Decodes domain *d from packet form to string form. Returns 1
+if it succeeds or 0 if it fails - for instance, *d is not a
+valid packet form (EPROTO).
+ int s6dns_domain_fromstring_noqualify_encode (s6dns_domain_t *d, char const *s, unsigned int len)
+Higher-level function wrapping some of the above. Makes an encoded, fully qualified
+(without resorting to qualification) domain from string s of
+length len. Returns 1 if it succeeds and 0 if it fails.
+ unsigned int s6dns_domain_fromstring_qualify_encode (s6dns_domain_t *list, char const *s, unsigned int len, char const *rules, unsigned int rulesnum)
+Another wrapping function. It makes a list of encoded, fully qualified domains,
+from string s of length len using rulesnum qualification
+rules in rules. It writes at most rulesnum domains into the array
+pointed to by list and returns the number of written domains, or 0 on an
+error.
+ void s6dns_domain_arpafromip4 (s6dns_domain_t *d, char const *ip)
+Writes into d the in-addr.arpa. domain corresponding to IPv4 address
+ip (4 bytes, in network byte order), in string form.
+ void s6dns_domain_arpafromip6 (s6dns_domain_t *d, char const *ip, unsigned int mask)
+Writes into d the ip6.arpa. domain corresponding to the first
+mask bits of IPv6 address ip (16 bytes, in network byte order),
+in string form.
+Only multiples of 4 count for mask, i.e. the output will be the same
+if mask is (for instance) 125, 126, 127 or 128.
+
+s6-dns
+Software
+skarnet.org
+ The s6dns_engine library interface
+
+ General information
+
+ Data structures
+
+ Functions
+
+ s6dns_engine_t life cycle
+
+ int s6dns_engine_init (s6dns_engine_t *dt, s6dns_ip46list_t const *servers, uint32 options, char const *q, unsigned int qlen, uint16 qtype, struct taia const *deadline, struct taia const *stamp)
+
+
+
+ void s6dns_engine_recycle (s6dns_engine_t *dt)
+ void s6dns_engine_free (s6dns_engine_t *dt)
+ Before the iopause()
+
+ void s6dns_engine_nextdeadline (s6dns_engine_t const *dt, struct taia *a)
+ int s6dns_engine_isreadable (s6dns_engine_t const *dt)
+ int s6dns_engine_iswritable (s6dns_engine_t const *dt)
+ After the iopause()
+
+ int s6dns_engine_timeout (s6dns_engine_t *dt, struct taia const *stamp)
+ int s6dns_engine_event (s6dns_engine_t *dt, struct taia const *stamp)
+
+
+
+ char *s6dns_engine_packet (s6dns_engine_t const *dt)
+ unsigned int s6dns_engine_packetlen (s6dns_engine_t const *dt)
+
+s6-dns
+Software
+skarnet.org
+ The s6dns_fmt library interface
+
+ General information
+
+ Functions
+
+ unsigned int s6dns_fmt_domain (char *s, unsigned int max, s6dns_domain_t const *d)
+Writes into string s the domain contained in *d (in string
+form). Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_DOMAIN is a suitable number of bytes to preallocate s.
+This function is actually an alias to s6dns_domain_tostring.
+ unsigned int s6dns_fmt_domainlist (char *s, unsigned int max, s6dns_domain_t const *list, unsigned int n, char const *delin, unsigned int delimlen)
+Writes into string s the list of n domains (in string form)
+pointed to by list. Between each domain (and not after the last one),
+string delim of length delimlen is appended.
+The function returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_DOMAINLIST(n) is a suitable number of bytes to preallocate s.
+ unsigned int s6dns_fmt_hinfo (char *s, unsigned int max, s6dns_message_rr_hinfo_t const *p)
+Writes into string s the HINFO contained in *p: cpu, then os,
+separated by a space.
+Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_HINFO is a suitable number of bytes to preallocate s.
+ unsigned int s6dns_fmt_mx (char *s, unsigned int max, s6dns_message_rr_mx_t const *p)
+Writes into string s the MX contained in *p: preference, then
+exchanger name, separated by a space.
+Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_MX is a suitable number of bytes to preallocate s.
+ unsigned int s6dns_fmt_soa (char *s, unsigned int max, s6dns_message_rr_soa_t const *p)
+Writes into string s the SOA contained in *p:
+mname, then rname, then serial number, refresh time, retry time, expiration time
+and minimum time, separated by spaces.
+Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_SOA is a suitable number of bytes to preallocate s.
+ unsigned int s6dns_fmt_srv (char *s, unsigned int max, s6dns_message_rr_srv_t const *p)
+Writes into string s the SRV contained in *p: priority,
+then weight, then port, then target, separated by spaces.
+Returns the number of bytes written, or 0 in case of failure. If
+the output would be more than max bytes, 0 ENAMETOOLONG is returned.
+To avoid that, S6DNS_FMT_SRV is a suitable number of bytes to preallocate s.
+
+s6-dns
+Software
+skarnet.org
+ The s6dns_ip46 library interface
+
+ General information
+
+ Data structures
+
+ Functions
+
+
+
+
+
+
diff --git a/doc/libs6dns/s6dns-message.html b/doc/libs6dns/s6dns-message.html
new file mode 100644
index 0000000..e06aa91
--- /dev/null
+++ b/doc/libs6dns/s6dns-message.html
@@ -0,0 +1,261 @@
+
+
+
+
+ s6dns_ip46list_is6(&list, i) is 1 if the ith
+address in list is IPv6 and 0 if it is IPv4. s6dns_ip46list_ip(&list, i) is a char * pointer to
+16 (if IPv6) or 4 (IPv4) bytes representing the ith address in
+list, in network byte order.
+s6-dns
+Software
+skarnet.org
+ The s6dns_message library interface
+
+ General information
+
+ Data structures
+
+
+ int f (s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int pos, unsigned int section, void *data)
+
+
+
+
+
+
+ Functions
+
+ Header management
+
+ void s6dns_message_header_pack (char *s, s6dns_message_header_t const *h)
+Packs the header *h into the 12 bytes pointed to by s.
+ void s6dns_message_header_unpack (char const *s, s6dns_message_header_t *h)
+Unpacks the 12 bytes pointed to by s into the structure *h.
+ Low-level RR decoding
+
+
+
+
+ int s6dns_message_get_string (s6dns_domain_t *d, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a character-string and stores it into *d. Returns 1 on success
+and 0 on failure. Note that *d does not contain a domain, but the
+s6dns_domain_t structure is adapted to store strings that do not
+exceed 255 characters. d→s can be used to access the string,
+and d→len its length.
+ int s6dns_message_get_strings (char *s, unsigned int rdlength, char const *packet, unsigned int packetlen, unsigned int *pos
+This function takes an additional parameter rdlength. It reads a series of
+character-strings and stores their concatenation into the string s, which
+must be preallocated; it can never store more than rdlength bytes. It returns
+-1 if it fails; on success, it returns the number of bytes written. The
+rdlength parameter must be the length of the resource record containing
+the series of character-strings.
+ unsigned int s6dns_message_get_domain (s6dns_domain_t *d, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a domain and stores it, in string form, into *d.
+Returns 1 on success and 0 on failure, and sets errno:
+
+
+
+ int s6dns_message_get_hinfo (s6dns_message_rr_hinfo_t *p, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a HINFO RR and stores it into *p. Returns 1 on success or 0
+on failure.
+ int s6dns_message_get_mx (s6dns_message_rr_mx_t *p, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a MX RR and stores it into *p. Returns 1 on success or 0 on failure.
+ int s6dns_message_get_soa (s6dns_message_rr_soa_t *p, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a SOA RR and stores it into *p. Returns 1 on success or 0 on failure.
+ int s6dns_message_get_srv (s6dns_message_rr_srv_t *p, char const *packet, unsigned int packetlen, unsigned int *pos)
+Reads a SRV RR and stores it into *p. Returns 1 on success or 0 on failure.
+ High-level RR-specific parsing functions
+
+ s6dns_message_func_t s6dns_message_parse_answer_strings
+Parses character-strings located in the answer section of the packet. The
+data argument is interpreted as a pointer to a s6dns_mpag_t,
+which is a structure defined in the s6-dns/s6dns-message.h header
+and used to store multiple character-strings.
+ s6dns_message_func_t s6dns_message_parse_answer_domain
+Parses domains located in the answer section of the packet. The
+data argument is interpreted as a pointer to a s6dns_dpag_t,
+which is a structure defined in the s6-dns/s6dns-message.h header
+and used to store multiple domains.
+ s6dns_message_func_t s6dns_message_parse_answer_a
+Parses A RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+stralloc,
+and 4 bytes are appended to this stralloc for every IPv4 address found.
+ s6dns_message_func_t s6dns_message_parse_answer_aaaa
+Parses AAAA RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+stralloc,
+and 16 bytes are appended to this stralloc for every IPv6 address found.
+
+ s6dns_message_func_t s6dns_message_parse_answer_hinfo
+Parses HINFO RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+genalloc
+containing s6dns_message_rr_hinfo_t structures.
+
+ s6dns_message_func_t s6dns_message_parse_answer_mx
+Parses MX RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+genalloc
+containing s6dns_message_rr_mx_t structures.
+
+ s6dns_message_func_t s6dns_message_parse_answer_soa
+Parses SOA RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+genalloc
+containing s6dns_message_rr_soa_t structures.
+
+ s6dns_message_func_t s6dns_message_parse_answer_srv
+Parses SRV RRs located in the answer section of the packet. The
+data argument is interpreted as a pointer to a
+genalloc
+containing s6dns_message_rr_srv_t structures.
+
+ int s6dns_message_parse (s6dns_message_header_t *h, char const *packet, unsigned int packetlen, s6dns_message_rr_func_t *f, void *data)
+ This function parses the DNS packet packet of length packetlen.
+It stores the packet header into *h. Then, for every RR in the answer,
+authority or additional section of the packet, it calls f with the
+relevant parameters. data is the extra pointer given to f to
+store information. The function returns 1 if the parsing succeeds. Otherwise it
+returns -1 if there is a local error unrelated to the packet, or 0 if no
+appropriate answer can be decoded from the packet. errno then contains one
+of the following values:
+
+libs6dns
+s6-dns
+Software
+skarnet.org
+
+ The following functions and structures are declared in the s6-dns/s6dns-rci.h header, +and implemented in the libs6dns.a or libs6dns.so library. +
+ ++ s6dns_rci provides functions to get information from +the /etc/resolv.conf file. +
+ ++ A s6dns_rci_t is a structure storing information +provided by the /etc/resolv.conf file, i.e. +
+ ++ Nameserver addresses are stored in a +s6dns_ip46list_t. Qualification rules are +stored in a stralloc +with an additional integer storing the number of rules. +
+ ++ Most programs won't need more than one s6dns_rci_t, so +the library provides the global variable s6dns_rci_here, used +by default in simple resolution macros. +
+ +
+ int s6dns_rci_init (s6dns_rci_t *rci, char const *file)
+Extracts information from file, which must be in /etc/resolv.conf
+format, and stores it into *rci. rci must be previously
+initialized to the S6DNS_RCI_ZERO constant. The function returns 1 if
+it succeeds, or 0 (and sets errno) if it fails.
+
+ If the DNSCACHEIP environment variable is set, and contains a list of +IP addresses separated by commas, semicolons, spaces, tabs, newlines or +carriage returns, then this list overrides any nameserver information +from file. If the variable is empty, file will be used +as the source of the information. +
+ ++ If the DNSQUALIFY environment variable is set, a list of domain suffixes, +separated by spaces, tabs, newlines or carriage returns, is read from it, +and overrides any qualification information from file. If the +variable is empty, it amounts to one rule saying "no qualification". +
+ ++ s6dns_init() is an alias to +s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf"). +
+ +
+ void s6dns_rci_free (s6dns_rci_t *rci)
+Frees the memory used by *rci. rci is then suitable to
+be reused in a s6dns_rci_init call.
+
+ s6dns_finish() calls s6dns_rci_free(&s6dns_rci_here). +
+ +
+ unsigned int s6dns_qualify (s6dns_domain_t *list, s6dns_domain_t const *d)
+Qualifies domain *d into the list of domains pointed to by list
+according to the rules stored in s6dns_rci_here. Returns the number of
+written domains (0 if it fails); this number cannot exceed
+s6dns_rci_here.rulesnum.
+
+libs6dns
+s6-dns
+Software
+skarnet.org
+
+ The following functions are declared in the s6-dns/s6dns-resolve.h header, +and implemented in the libs6dns.a or libs6dns.so library. +
+ ++ s6dns_resolve provides functions and macros - mostly macros - +to perform high level synchronous DNS resolution. +
+ ++ All the functions declared here make synchronous calls to the network, so +they can block for a non-negligible amount of time. To avoid unbounded +waiting times, they always take 2 arguments at the end, deadline +and stamp. deadline is the read-only address of a +struct taia +containing an absolute time which is the deadline for the function, and +stamp is the read-write address of a struct taia being +an accurate enough representation of the current absolute time. If +the function has not returned by *deadline, then it immediately +returns with a failure code and errno set to ETIMEDOUT. In every case, +*stamp is automatically updated so it always represents the +absolute time accurately enough. +
+ ++ In a single-threaded program, the STAMP global variable can be used to +store the current time. Macros ending with _g use this variable +automatically so you don't have to provide the stamp argument +everytime. Additionally, several resolution functions make implicit use +of global variables such as: +
+ ++ Reentrant, non-global-using functions are also provided, with the _r +suffix. In other words, if foobarfunc is a resolution function, +the following prototypes are generally provided, from the simplest to the +most complex: +
+ ++ For each set of four functions, only one is documented here. +The other prototypes can be found in the s6-dns/s6dns-resolve.h file. +
+ ++ Some errno codes reported by these functions do not have +exactly the system meaning given by +strerror(). +To get a user-friendly error message, use +s6dns_constants_error_str(errno) instead. The s6dns_constants_error_str +function is declared in the s6dns-constants.h header. +
+ ++ These functions are ordered from the lowest level to the highest level. +
+ +
+ int s6dns_resolve_loop_r_g (s6dns_engine_t *dt, struct taia const *deadline)
+Resolves the query stored in dt.
+Returns 1 on success or 0 on failure.
+
+ int s6dns_resolve_core_g (s6dns_domain_t const *d, uint16 qtype, struct taia const *deadline)
+Resolves the query on domain *d (in packet form), of type qtype.
+Returns 0 on failure, or 1 on success, in which case
+s6dns_engine_here contains the answer.
+
+ int s6dns_resolve_parse_g (s6dns_domain_t const *d, uint16 qtype, s6dns_message_rr_func_t *f, void *data, struct taia const *deadline)
+Resolves the query on domain *d (in packet form), of type qtype,
+then parses the answer with function f and stores the result into data.
+Returns 1 if it succeeds, 0 if no data can be extracted from the answer, or -1 if an
+error occurs. Sets errno in the last two cases.
+
+ Note that the function can return 1 without appending anything to data. +This means that the servers confirmed that the domain exists, but f +has not been able to find any data relevant to the query in the answer. +This is very different from NXDOMAIN, which means that +the servers deny the actual existence of the domain, and which is reported +here as a return code of 0 with errno set to ENOENT. +
+ +
+ int s6dns_resolvenoq_g (char const *name, unsigned int len, uint16 qtype, s6dns_message_rr_func_t *f, void *data, struct taia const *deadline)
+Performs a query of type qtype on name name of length len,
+without qualifying it. Parses the answer with function f and stores the
+result into data. Returns 1 if it succeeds, 0 if no data can be extracted,
+or -1 if an error occurs. Sets errno in the last two cases.
+
+ int s6dns_resolveq_g (char const *name, unsigned int len, uint16 qtype, s6dns_message_rr_func_t *f, void *data, struct taia const *deadline)
+Performs a query of type qtype on name name of length len,
+qualifying it first. Parses the answer with function f and stores the
+result into data. Returns 1 if it succeeds, 0 if none of the FQDNs can
+get a positive answer, or -1 if an error occurs. Sets errno in the last two cases.
+
+ int s6dns_resolve_g (char const *name, unsigned int len, uint16 qtype, s6dns_message_rr_func_t *f, void *data, int qualif, struct taia const *deadline)
+Performs a query of type qtype on name name of length len.
+Qualifies name first if qualif is nonzero; else, does not
+qualify it. Parses the answer with function f and stores the
+result into data. Returns 1 if it succeeds, 0 if none of the FQDNs can
+get a positive answer, or -1 if an error occurs. Sets errno in the last two cases.
+
+ int s6dns_resolve_a_g (stralloc *ips, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs an A query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the IPs are
+appended to the stralloc *ips, using 4 bytes per answer.
+
+ int s6dns_resolve_aaaa_g (stralloc *ips, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs an AAAA query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the IPs are
+appended to the stralloc *ips, using 16 bytes per answer.
+
+ int s6dns_resolve_aaaaa_g (genalloc *ips, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs an AAAA query and an A query at the same time on name name
+of length len, qualifying it first iff qualif is nonzero.
+Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or a positive number if it succeeds: 1 if IPv4 addresses
+were found, 2 if IPv6 addresses were found, and 3 if both were found.
+The IPs are appended to the genalloc *ips, which contains an array of
+ip46_t, the skalibs structure used to store IPv4 and IPv6 addresses
+indiscriminately.
+
+ int s6dns_resolve_ptr_g (genalloc *ds, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs a PTR query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *ds, which contains an array of s6dns_domain_t.
+
+ int s6dns_resolve_name4_g (genalloc *ds, char const *ip, struct taia const *deadline)
+Performs a PTR query on the in-addr.arpa. name representing the IPv4
+address ip (4 network-order bytes).
+Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *ds, which contains an array of s6dns_domain_t.
+
+ int s6dns_resolve_name6_g (genalloc *ds, char const *ip, struct taia const *deadline)
+Performs a PTR query on the ip6.arpa. name representing the IPv6
+address ip (16 network-order bytes).
+Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *ds, which contains an array of s6dns_domain_t.
+
+ int s6dns_resolve_name46_g (genalloc *ds, ip46_t const *ip, struct taia const *deadline)
+Calls s6dns_resolve_name6_g() or s6dns_resolve_name4_g()
+depending on which ip is an IPv6 or IPv4 address.
+
+ int s6dns_resolve_ns_g (genalloc *ds, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs a NS query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *ds, which contains an array of s6dns_domain_t.
+
+ int s6dns_resolve_cname_g (genalloc *ds, char const *name, unsigned int len, int qualif, struct taia const *deadline)
+Performs a CNAME query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *ds, which contains an array of s6dns_domain_t.
+
+ int s6dns_resolve_hinfo_g (genalloc *hinfos, char const *name,
+unsigned int len, int qualif, struct taia const *deadline)
+ Performs an HINFO query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *hinfos, which contains an array of
+s6dns_message_rr_hinfo_t.
+
+ int s6dns_resolve_mx_g (genalloc *mxs, char const *name,
+unsigned int len, int qualif, struct taia const *deadline)
+ Performs an MX query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *mxs, which contains an array of
+s6dns_message_rr_mx_t.
+
+ int s6dns_resolve_soa_g (genalloc *soas, char const *name,
+unsigned int len, int qualif, struct taia const *deadline)
+ Performs an SOA query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *soas, which contains an array of
+s6dns_message_rr_soa_t.
+
+ int s6dns_resolve_srv_g (genalloc *srvs, char const *name,
+unsigned int len, int qualif, struct taia const *deadline)
+ Performs an SRV query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case the domains are
+appended to the genalloc *srvs, which contains an array of
+s6dns_message_rr_srv_t.
+
+ int s6dns_resolve_txt_g (stralloc *sa, genalloc *offsets, char const *name,
+unsigned int len, int qualif, struct taia const *deadline)
+ Performs an TXT query on name name of length len, qualifying it
+iff qualif is nonzero. Returns -1 if an error occurs, or 0 if no answer
+can be obtained from servers, or 1 if it succeeds, in which case:
+
+ int s6dns_resolven_loop_g (s6dns_engine_t *dtl, unsigned int n,
+unsigned int or, struct taia const *deadline)
+ Resolves the n queries stored in the array pointed to by dtl,
+in parallel. If or is zero, it does not return before all answers
+have arrived. If or is 1, it returns when an answer arrives, but does
+not return if a query generates an error (unless all queries do so). If
+or is 2, it returns when an answer arrives or an error occurs.
+Other values of or are unspecified yet.
+
+
+ The return code is as follows: +
+ ++ If or is 1, a return code of -1 with errno set to ENOENT +means that all the queries failed. +
+ ++ After the function returns, the status field of each +s6dns_engine_t contains the error code relative to the query. +A status of 0 means that an answer has properly arrived; EAGAIN means +that the query is still pending (and the s6dns_engine_t has not been +recycled); ECONNABORTED means that the query has not been properly +initialized. Other codes report various network problems. +
+ +
+ int s6dns_resolven_parse_g (s6dns_resolve_t const *list, unsigned int n,
+struct taia const *deadline)
+Performs n complete resolutions in parallel, parsing the results.
+Returns 1 in case of success or 0 if a global error occurred.
+
+list is a pointer to an array of n s6dns_resolve_t, +which is a structure containing at least the following fields: +
+ ++ The s6dns_resolven_parse() function is a simple, convenient way to +perform several resolutions in parallel to avoid the waiting time +incurred by serial resolutions. However, it is still a synchronous +function, and cannot replace a real asynchronous DNS library: for +more complex parallel resolution needs, use the +skadns library. +
+ + + diff --git a/doc/s6-dnsip4-filter.html b/doc/s6-dnsip4-filter.html new file mode 100644 index 0000000..5433438 --- /dev/null +++ b/doc/s6-dnsip4-filter.html @@ -0,0 +1,111 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsip4-filter reads domain names on its standard input and +prints the corresponding IPv4 addresses on its standard output. +
+ ++ s6-dnsip4-filter [ -l maxlines ] [ -c maxconn ] [ -t timeout ] [ -f normalfmt ] [ -e errorfmt ] ++ +
+ normalfmt and errorfmt are format strings, i.e. they tell the +program how a line must be printed. The following sequences are recognized: +
+ ++ s6-dnsns google.com | s6-dnsip4-filter -f "%d" ++ +
+ prints all the nameserver addresses for the google.com +domain. This is useful, for instance, to give the result as an +argument to s6-dnsq. +
+ ++ s6-dnsip4-filter does not perform DNS resolutions itself. Instead, if forks +a skadnsd child and sends it queries, getting +the results asynchronously. The s6-dns filter programs have actually been +written as example uses of the skadns library. +
+ + + diff --git a/doc/s6-dnsip4.html b/doc/s6-dnsip4.html new file mode 100644 index 0000000..72f585b --- /dev/null +++ b/doc/s6-dnsip4.html @@ -0,0 +1,63 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsip4 finds the IPv4 addresses associated to a domain name. +
+ ++ s6-dnsip4 [ -q ] [ -r ] [ -t timeout ] domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsip6-filter reads domain names on its standard input and +prints the corresponding IPv6 addresses on its standard output. +
+ ++ s6-dnsip6-filter [ -l maxlines ] [ -c maxconn ] [ -t timeout ] [ -f normalfmt ] [ -e errorfmt ] ++ +
+ normalfmt and errorfmt are format strings, i.e. they tell the +program how a line must be printed. The following sequences are recognized: +
+ ++ s6-dnsip6-filter does not perform DNS resolutions itself. Instead, if forks +a skadnsd child and sends it queries, getting +the results asynchronously. The s6-dns filter programs have actually been +written as example uses of the skadns library. +
+ + + diff --git a/doc/s6-dnsip6.html b/doc/s6-dnsip6.html new file mode 100644 index 0000000..d417011 --- /dev/null +++ b/doc/s6-dnsip6.html @@ -0,0 +1,73 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsip6 finds the IPv6 addresses associated to a domain name. +
+ ++ s6-dnsip6 [ -q ] [ -r ] [ -t timeout ] domain ++ +
+ Bear in mind that making AAAA queries is very different, and +totally independent, from using IPv6 transport for the DNS queries. +Even if the underlying skalibs has been compiled without IPv6 support, +or IPv6 DNS transport is unavailable for any reason, you can still perform +AAAA queries and s6-dnsip6 will answer correctly. +
+ + + diff --git a/doc/s6-dnsmx.html b/doc/s6-dnsmx.html new file mode 100644 index 0000000..1396aed --- /dev/null +++ b/doc/s6-dnsmx.html @@ -0,0 +1,64 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsmx finds the MX information associated to a domain name. +
+ ++ s6-dnsmx [ -q ] [ -r ] [ -t timeout ] domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsname-filter reads IP addresses on its standard input and +prints the corresponding domain names on its standard output. +
+ ++ s6-dnsname-filter [ -4 ] [ -6 ] [ -l maxlines ] [ -c maxconn ] [ -t timeout ] [ -f normalfmt ] [ -e errorfmt ] ++ +
+ normalfmt and errorfmt are format strings, i.e. they tell the +program how a line must be printed. The following sequences are recognized: +
+ ++ s6-dnsname-filter does not perform DNS resolutions itself. Instead, if forks +a skadnsd child and sends it queries, getting +the results asynchronously. The s6-dns filter programs have actually been +written as example uses of the skadns library. +
+ + + diff --git a/doc/s6-dnsname.html b/doc/s6-dnsname.html new file mode 100644 index 0000000..0c0c5b0 --- /dev/null +++ b/doc/s6-dnsname.html @@ -0,0 +1,72 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsname finds the name associated to an IPv4 or IPv6 address. +
+ ++ s6-dnsname [ -4 | -6 ] [ -r ] [ -t timeout ] ip ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsns finds the relevant nameservers providing data for a domain. +
+ ++ s6-dnsns [ -q ] [ -r ] [ -t timeout ] domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsq is an analysis and debug tool. It performs a non-recursive DNS query +to a given list of servers, +then prints the contents of the answer packet, and optionally debug +information during the resolution. +
+ ++ s6-dnsq [ -1 | -2 ] [ -t timeout ] [ -D level ] qtype domain serverlist ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsqr is an analysis and debug tool. It performs a DNS resolution, +then prints the contents of the answer packet, and optionally debug +information during the resolution. +
+ ++ s6-dnsqr [ -1 | -2 ] [ -t timeout ] [ -D level ] qtype domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnsqualify qualifies a domain name. +
+ ++ s6-dnsqualify domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnssoa finds the SOA information associated to a domain. +
+ ++ s6-dnssoa [ -q ] [ -r ] [ -t timeout ] domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnssrv finds the SRV information associated to a +service name, protocol name and domain name. +
+ ++ s6-dnssrv [ -q ] [ -r ] [ -t timeout ] service proto domain ++ +
+s6-dns
+Software
+skarnet.org
+
+ s6-dnstxt finds the TXT information associated to a domain name. +
+ ++ s6-dnstxt [ -q ] [ -r ] [ -t timeout ] domain ++ +
+ There can be more than one character-string in a TXT RR, and there can be +more than one TXT RR per domain. DNS clients usually concatenate all this +and only give one string. s6-dnstxt concatenates all the character-strings +in one TXT record, but separates different TXT records, printing each one +on a separate line. +
+ + + diff --git a/doc/s6-randomip.html b/doc/s6-randomip.html new file mode 100644 index 0000000..0ad3b46 --- /dev/null +++ b/doc/s6-randomip.html @@ -0,0 +1,57 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ s6-randomip generates random IP addresses and prints them to +its standard output, one per line. +
+ ++ s6-randomip [ -4 ] [ -6 ] [ -n max ] ++ +
+ s6-randomip can be used in conjunction with +s6-dnsname-filter to stress-test your +DNS architecture. Please use this responsibly and ethically. +
+ + + diff --git a/doc/skadns/index.html b/doc/skadns/index.html new file mode 100644 index 0000000..f02f2dd --- /dev/null +++ b/doc/skadns/index.html @@ -0,0 +1,262 @@ + + + + +
+s6-dns
+Software
+skarnet.org
+
+ The skadns library provides an API for asynchronous DNS +resolution. +
+ ++ Check the s6-dns/skadns.h header for the +exact function prototypes. +
+ ++ Make sure your application is not disturbed by children it doesn't +know it has. This means paying some attention to the SIGCHLD handler, +if any, and to the way you perform waitpid()s. The best +practice is to use a +self-pipe +to handle SIGCHLD (as well as other signals the application needs to trap), +and to always use wait_nohang() to reap children, +simply ignoring pids you don't know. +
+ ++ If your (badly programmed) application has trouble handling unknown +children, consider using a skadnsd service. +
+ ++ The src/clients/s6dns_generic_filter_main.c file in the s6-dns +package, used in the s6-dns*-filter programs, illustrates how to +use the skadns library. +
+ ++skadns_t a = SKADNS_ZERO ; +tain_t deadline, stamp ; + +tain_now(&stamp) ; +tain_addsec(&deadline, &stamp, 2) + +// char const *path = SKADNS_IPCPATH ; +// skadns_start(&a, path, &deadline, &stamp) ; +skadns_startf(&a, &deadline, &stamp) ; ++ +
+skadns_start starts a session with a skadnsd service, listening
+on path.
+skadns_startf starts a session with a skadnsd process as a child
+(which is the simplest usage).
+a is a skadns_t structure that must be declared and
+initialized to SKADNS_ZERO.
+stamp must be an accurate enough timestamp.
+If the session initialization fails, the function returns 0 and errno is set;
+else the function returns 1.
+
+If the absolute time deadline is reached and the function +has not returned yet, it immediately returns 0 with errno set to ETIMEDOUT. + +Only local interprocess communications are involved; unless your system is +heavily overloaded, the function should return near-instantly. One or two +seconds of delay between stamp and deadline should be +enough: if the function takes more than that to return, then there is a +problem with the underlying processes. +
+ ++ You can have more than one session open in parallel, by declaring +several distinct skadns_t structures and calling +skadns_startf (or skadns_start) more than once. +However, this is only useful if you need to perform more than +SKADNS_MAXCONCURRENCY, i.e. a thousand, concurrent requests. In +most situations, a single skadns session will be enough. +
+ ++skadns_end(&a) ; ++ +
+skadns_end frees all the resources used by the session. The +a structure is then reusable for another session. +
+ ++s6dns_domain_t d ; +uint16 qtype ; +uint16 id ; +tain_t limit, deadline, stamp ; + +skadns_send(&a, &id, &d, qtype, &limit, &deadline, &stamp) ; ++ +
+skadns_send starts the asynchronous resolution of domain d +with query type qtype. d must be encoded in packet form. +stamp must be an accurate enough timetamp. +If the resolution hasn't completed by deadline limit, it will +automatically fail with a status set to ETIMEDOUT. +
+ ++ Like skadns_startf(), the skadns_send() call +is synchronous but should not be blocking; however, if it hasn't returned by +deadline deadline, it then returns 0 with errno set to ETIMEDOUT. +On failure, the call returns 0 and sets errno. On success, it returns 1 and +id is set to a 16-bit number identifying the query. +
+ ++skadns_cancel(&a, id, &deadline, &stamp) ; ++ +
+ skadns_cancel cancels the resolution identified by id. +stamp must be an accurate enough timestamp. +The call returns 1 on success, or 0 (and sets errno) on failure. It is +synchronous but should return almost-instantly; if it hasn't returned +by deadline, it then returns 0 ETIMEDOUT. +
+ ++ After a query has been successfully canceled, its id can be discarded. +
+ ++ (from now on, the functions are listed with their prototypes instead +of usage examples.) +
+ ++int skadns_fd (skadns_t const *a) ++ +
+ Returns a file descriptor to select on for reading. Do not +read() it though. +
+ ++int skadns_update (skadns_t *a) ++ +
+ Call this function whenever the fd checks readability: it will +update a's internal structures with information from the +skadnsd daemon. It returns -1 if an error +occurs; in case of success, it returns the number of identifiers for +which something happened. +
+ ++ When skadns_update returns, +genalloc_s(uint16, &a->list) points to an array of +genalloc_len(uint16, &a->list) 16-bit unsigned +integers. Those integers are valid ids that can be used with the +following functions. +
+ ++char const *skadns_packet (skadns_t *a, uint16 id) +int skadns_packetlen (skadns_t *a, uint16 id) ++ +
+ skadns_packet() returns a pointer to the DNS packet +containing the answer to the query identified by id, +and skadns_packetlen() returns its length. If an +error has occurred, skadns_packet() returns NULL and +skadns_packetlen() returns -1; either call sets errno +to a value identifying the error. Some errno values have a +special meaning: +
+ ++int skadns_release (skadns_t *a, uint16 id) ++ +
+ skadns_release() frees the cell holding the result of +query id. It returns 1 on success, then id can +be discarded - further calls to skadns_send() may reuse +the same number. +
+ ++ skadns_release() may fail, and return 0. This signals a +programming error and shouldn't be relied on - however, if it happens, +errno can help you identify the problem: +
+ ++skadnsd is the skadns daemon. It reads a series of +queries from the client on stdin, resolves them asynchronously, +and writes +the answers to the client as soon as it gets them. It exits 0 +when its stdin closes. It exits 111 on any serious error, +writing the error message to stderr. +
+ ++skadnsd is a stub resolver. It reads /etc/resolv.conf +at start looking for a "nameserver" line containing +the address of a DNS cache (aka full resolver). It will exit 111 if it cannot +find any valid cache address in /etc/resolv.conf. If the +DNSCACHEIP environment variable is set, its value overrides +what /etc/resolv.conf says. +
+ ++skadnsd does not fork, does not background itself automatically, +and does not use syslog. It is not meant to be run directly by the +user: it will be invoked and spawned by the skadns library calls. +
+ ++ There are 2 ways to use skadnsd: +
++ This is the simplest and safest way of using skadns. Forget +about skadnsd: just start your library calls with +skadns_startf() and end them with skadns_end(). +Be careful though: if you're using SIGCHLD handlers, make sure they do +not interfere with the child processes your application has without +knowing. This is a general Unix programming rule. +
+ ++ In this mode, you set up a daemon listening on a Unix domain socket, +and clients connect to this socket to access the service. The +advantage of this setup is that it works even with badly written +clients that have trouble handling a child process; the drawback is +that it requires support from the system administrator. +
+ ++skadnsd has no "standalone" mode: it is designed to work with a Unix +domain superserver, like +s6-ipcserver. +skadnsd follows the UCSPI" +interface, it can be directly executed from the superserver. +
+ ++You should run skadnsd (and its Unix superserver) under a specific user +and group, for elementary security reasons; and you should run its +dedicated logger as another specific user. Do NOT run skadnsd as root; +check your super-server documentation to find how +to run it under a specific account. +
+ +
+s6-dns
+Software
+skarnet.org
+