~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/networking/dns_resolver.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 .. SPDX-License-Identifier: GPL-2.0
  2 
  3 ===================
  4 DNS Resolver Module
  5 ===================
  6 
  7 .. Contents:
  8 
  9  - Overview.
 10  - Compilation.
 11  - Setting up.
 12  - Usage.
 13  - Mechanism.
 14  - Debugging.
 15 
 16 
 17 Overview
 18 ========
 19 
 20 The DNS resolver module provides a way for kernel services to make DNS queries
 21 by way of requesting a key of key type dns_resolver.  These queries are
 22 upcalled to userspace through /sbin/request-key.
 23 
 24 These routines must be supported by userspace tools dns.upcall, cifs.upcall and
 25 request-key.  It is under development and does not yet provide the full feature
 26 set.  The features it does support include:
 27 
 28  (*) Implements the dns_resolver key_type to contact userspace.
 29 
 30 It does not yet support the following AFS features:
 31 
 32  (*) Dns query support for AFSDB resource record.
 33 
 34 This code is extracted from the CIFS filesystem.
 35 
 36 
 37 Compilation
 38 ===========
 39 
 40 The module should be enabled by turning on the kernel configuration options::
 41 
 42         CONFIG_DNS_RESOLVER     - tristate "DNS Resolver support"
 43 
 44 
 45 Setting up
 46 ==========
 47 
 48 To set up this facility, the /etc/request-key.conf file must be altered so that
 49 /sbin/request-key can appropriately direct the upcalls.  For example, to handle
 50 basic dname to IPv4/IPv6 address resolution, the following line should be
 51 added::
 52 
 53 
 54         #OP     TYPE            DESC    CO-INFO PROGRAM ARG1 ARG2 ARG3 ...
 55         #====== ============    ======= ======= ==========================
 56         create  dns_resolver    *       *       /usr/sbin/cifs.upcall %k
 57 
 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::
 60 
 61         create  dns_resolver    foo:*   *       /usr/sbin/dns.foo %k
 62 
 63 
 64 Usage
 65 =====
 66 
 67 To make use of this facility, one of the following functions that are
 68 implemented in the module can be called after doing::
 69 
 70         #include <linux/dns_resolver.h>
 71 
 72      ::
 73 
 74         int dns_query(const char *type, const char *name, size_t namelen,
 75                      const char *options, char **_result, time_t *_expiry);
 76 
 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
 80      form::
 81 
 82                 [<type>:]<name>
 83 
 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
 87      set lookup.
 88 
 89      The name parameter is not required to be a NUL-terminated string, and its
 90      length should be given by the namelen argument.
 91 
 92      The options parameter may be NULL or it may be a set of options
 93      appropriate to the query type.
 94 
 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.
 98 
 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
101      DNS lookup failed.
102 
103      If _expiry is non-NULL, the expiry time (TTL) of the result will be
104      returned also.
105 
106 The kernel maintains an internal keyring in which it caches looked up keys.
107 This can be cleared by any process that has the CAP_SYS_ADMIN capability by
108 the use of KEYCTL_KEYRING_CLEAR on the keyring ID.
109 
110 
111 Reading DNS Keys from Userspace
112 ===============================
113 
114 Keys of dns_resolver type can be read from userspace using keyctl_read() or
115 "keyctl read/print/pipe".
116 
117 
118 Mechanism
119 =========
120 
121 The dns_resolver module registers a key type called "dns_resolver".  Keys of
122 this type are used to transport and cache DNS lookup results from userspace.
123 
124 When dns_query() is invoked, it calls request_key() to search the local
125 keyrings for a cached DNS result.  If that fails to find one, it upcalls to
126 userspace to get a new result.
127 
128 Upcalls to userspace are made through the request_key() upcall vector, and are
129 directed by means of configuration lines in /etc/request-key.conf that tell
130 /sbin/request-key what program to run to instantiate the key.
131 
132 The upcall handler program is responsible for querying the DNS, processing the
133 result into a form suitable for passing to the keyctl_instantiate_key()
134 routine.  This then passes the data to dns_resolver_instantiate() which strips
135 off and processes any options included in the data, and then attaches the
136 remainder of the string to the key as its payload.
137 
138 The upcall handler program should set the expiry time on the key to that of the
139 lowest TTL of all the records it has extracted a result from.  This means that
140 the key will be discarded and recreated when the data it holds has expired.
141 
142 dns_query() returns a copy of the value attached to the key, or an error if
143 that is indicated instead.
144 
145 See <file:Documentation/security/keys/request-key.rst> for further
146 information about request-key function.
147 
148 
149 Debugging
150 =========
151 
152 Debugging messages can be turned on dynamically by writing a 1 into the
153 following file::
154 
155         /sys/module/dns_resolver/parameters/debug

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php