19 The DNS resolver module provides a way for kernel services to make DNS queries
20 by way of requesting a key of key type dns_resolver. These queries are
21 upcalled to userspace through /sbin/request-key.
23 These routines must be supported by userspace tools dns.upcall, cifs.upcall and
24 request-key. It is under development and does not yet provide the full feature
25 set. The features it does support include:
27 (*) Implements the dns_resolver key_type to contact userspace.
29 It does not yet support the following AFS features:
31 (*) Dns query support for AFSDB resource record.
33 This code is extracted from the CIFS filesystem.
40 The module should be enabled by turning on the kernel configuration options:
42 CONFIG_DNS_RESOLVER - tristate "DNS Resolver support"
49 To set up this facility, the /etc/request-key.conf file must be altered so that
50 /sbin/request-key can appropriately direct the upcalls. For example, to handle
51 basic dname to IPv4/IPv6 address resolution, the following line should be
54 #OP TYPE DESC CO-INFO PROGRAM ARG1 ARG2 ARG3 ...
55 #====== ============ ======= ======= ==========================
56 create dns_resolver * * /usr/sbin/cifs.upcall %k
58 To direct a query for query type 'foo', a line of the following should be added
59 before the more general line given above as the first match is the one taken.
61 create dns_resolver foo:* * /usr/sbin/dns.foo %k
69 To make use of this facility, one of the following functions that are
70 implemented in the module can be called after doing:
72 #include <linux/dns_resolver.h>
74 (1) int dns_query(const char *type, const char *name, size_t namelen,
75 const char *options, char **_result, time_t *_expiry);
77 This is the basic access function. It looks for a cached DNS query and if
78 it doesn't find it, it upcalls to userspace to make a new DNS query, which
79 may then be cached. The key description is constructed as a string of the
84 where <type> optionally specifies the particular upcall program to invoke,
85 and thus the type of query to do, and <name> specifies the string to be
86 looked up. The default query type is a straight hostname to IP address
89 The name parameter is not required to be a NUL-terminated string, and its
90 length should be given by the namelen argument.
92 The options parameter may be NULL or it may be a set of options
93 appropriate to the query type.
95 The return value is a string appropriate to the query type. For instance,
96 for the default query type it is just a list of comma-separated IPv4 and
97 IPv6 addresses. The caller must free the result.
99 The length of the result string is returned on success, and a negative
100 error code is returned otherwise. -EKEYREJECTED will be returned if the
103 If _expiry is non-NULL, the expiry time (TTL) of the result will be
111 The dnsresolver module registers a key type called "dns_resolver". Keys of
112 this type are used to transport and cache DNS lookup results from userspace.
114 When dns_query() is invoked, it calls request_key() to search the local
115 keyrings for a cached DNS result. If that fails to find one, it upcalls to
116 userspace to get a new result.
118 Upcalls to userspace are made through the request_key() upcall vector, and are
119 directed by means of configuration lines in /etc/request-key.conf that tell
120 /sbin/request-key what program to run to instantiate the key.
122 The upcall handler program is responsible for querying the DNS, processing the
123 result into a form suitable for passing to the keyctl_instantiate_key()
124 routine. This then passes the data to dns_resolver_instantiate() which strips
125 off and processes any options included in the data, and then attaches the
126 remainder of the string to the key as its payload.
128 The upcall handler program should set the expiry time on the key to that of the
129 lowest TTL of all the records it has extracted a result from. This means that
130 the key will be discarded and recreated when the data it holds has expired.
132 dns_query() returns a copy of the value attached to the key, or an error if
133 that is indicated instead.
135 See <file:Documentation/keys-request-key.txt> for further information about
136 request-key function.
143 Debugging messages can be turned on dynamically by writing a 1 into the
146 /sys/module/dnsresolver/parameters/debug