xref: /openbmc/linux/Documentation/networking/dns_resolver.rst (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1*9dfe1361SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
2*9dfe1361SMauro Carvalho Chehab
3*9dfe1361SMauro Carvalho Chehab===================
4*9dfe1361SMauro Carvalho ChehabDNS Resolver Module
5*9dfe1361SMauro Carvalho Chehab===================
6*9dfe1361SMauro Carvalho Chehab
7*9dfe1361SMauro Carvalho Chehab.. Contents:
8*9dfe1361SMauro Carvalho Chehab
9*9dfe1361SMauro Carvalho Chehab - Overview.
10*9dfe1361SMauro Carvalho Chehab - Compilation.
11*9dfe1361SMauro Carvalho Chehab - Setting up.
12*9dfe1361SMauro Carvalho Chehab - Usage.
13*9dfe1361SMauro Carvalho Chehab - Mechanism.
14*9dfe1361SMauro Carvalho Chehab - Debugging.
15*9dfe1361SMauro Carvalho Chehab
16*9dfe1361SMauro Carvalho Chehab
17*9dfe1361SMauro Carvalho ChehabOverview
18*9dfe1361SMauro Carvalho Chehab========
19*9dfe1361SMauro Carvalho Chehab
20*9dfe1361SMauro Carvalho ChehabThe DNS resolver module provides a way for kernel services to make DNS queries
21*9dfe1361SMauro Carvalho Chehabby way of requesting a key of key type dns_resolver.  These queries are
22*9dfe1361SMauro Carvalho Chehabupcalled to userspace through /sbin/request-key.
23*9dfe1361SMauro Carvalho Chehab
24*9dfe1361SMauro Carvalho ChehabThese routines must be supported by userspace tools dns.upcall, cifs.upcall and
25*9dfe1361SMauro Carvalho Chehabrequest-key.  It is under development and does not yet provide the full feature
26*9dfe1361SMauro Carvalho Chehabset.  The features it does support include:
27*9dfe1361SMauro Carvalho Chehab
28*9dfe1361SMauro Carvalho Chehab (*) Implements the dns_resolver key_type to contact userspace.
29*9dfe1361SMauro Carvalho Chehab
30*9dfe1361SMauro Carvalho ChehabIt does not yet support the following AFS features:
31*9dfe1361SMauro Carvalho Chehab
32*9dfe1361SMauro Carvalho Chehab (*) Dns query support for AFSDB resource record.
33*9dfe1361SMauro Carvalho Chehab
34*9dfe1361SMauro Carvalho ChehabThis code is extracted from the CIFS filesystem.
35*9dfe1361SMauro Carvalho Chehab
36*9dfe1361SMauro Carvalho Chehab
37*9dfe1361SMauro Carvalho ChehabCompilation
38*9dfe1361SMauro Carvalho Chehab===========
39*9dfe1361SMauro Carvalho Chehab
40*9dfe1361SMauro Carvalho ChehabThe module should be enabled by turning on the kernel configuration options::
41*9dfe1361SMauro Carvalho Chehab
42*9dfe1361SMauro Carvalho Chehab	CONFIG_DNS_RESOLVER	- tristate "DNS Resolver support"
43*9dfe1361SMauro Carvalho Chehab
44*9dfe1361SMauro Carvalho Chehab
45*9dfe1361SMauro Carvalho ChehabSetting up
46*9dfe1361SMauro Carvalho Chehab==========
47*9dfe1361SMauro Carvalho Chehab
48*9dfe1361SMauro Carvalho ChehabTo set up this facility, the /etc/request-key.conf file must be altered so that
49*9dfe1361SMauro Carvalho Chehab/sbin/request-key can appropriately direct the upcalls.  For example, to handle
50*9dfe1361SMauro Carvalho Chehabbasic dname to IPv4/IPv6 address resolution, the following line should be
51*9dfe1361SMauro Carvalho Chehabadded::
52*9dfe1361SMauro Carvalho Chehab
53*9dfe1361SMauro Carvalho Chehab
54*9dfe1361SMauro Carvalho Chehab	#OP	TYPE		DESC	CO-INFO	PROGRAM ARG1 ARG2 ARG3 ...
55*9dfe1361SMauro Carvalho Chehab	#======	============	=======	=======	==========================
56*9dfe1361SMauro Carvalho Chehab	create	dns_resolver  	*	*	/usr/sbin/cifs.upcall %k
57*9dfe1361SMauro Carvalho Chehab
58*9dfe1361SMauro Carvalho ChehabTo direct a query for query type 'foo', a line of the following should be added
59*9dfe1361SMauro Carvalho Chehabbefore the more general line given above as the first match is the one taken::
60*9dfe1361SMauro Carvalho Chehab
61*9dfe1361SMauro Carvalho Chehab	create	dns_resolver  	foo:*	*	/usr/sbin/dns.foo %k
62*9dfe1361SMauro Carvalho Chehab
63*9dfe1361SMauro Carvalho Chehab
64*9dfe1361SMauro Carvalho ChehabUsage
65*9dfe1361SMauro Carvalho Chehab=====
66*9dfe1361SMauro Carvalho Chehab
67*9dfe1361SMauro Carvalho ChehabTo make use of this facility, one of the following functions that are
68*9dfe1361SMauro Carvalho Chehabimplemented in the module can be called after doing::
69*9dfe1361SMauro Carvalho Chehab
70*9dfe1361SMauro Carvalho Chehab	#include <linux/dns_resolver.h>
71*9dfe1361SMauro Carvalho Chehab
72*9dfe1361SMauro Carvalho Chehab     ::
73*9dfe1361SMauro Carvalho Chehab
74*9dfe1361SMauro Carvalho Chehab	int dns_query(const char *type, const char *name, size_t namelen,
75*9dfe1361SMauro Carvalho Chehab		     const char *options, char **_result, time_t *_expiry);
76*9dfe1361SMauro Carvalho Chehab
77*9dfe1361SMauro Carvalho Chehab     This is the basic access function.  It looks for a cached DNS query and if
78*9dfe1361SMauro Carvalho Chehab     it doesn't find it, it upcalls to userspace to make a new DNS query, which
79*9dfe1361SMauro Carvalho Chehab     may then be cached.  The key description is constructed as a string of the
80*9dfe1361SMauro Carvalho Chehab     form::
81*9dfe1361SMauro Carvalho Chehab
82*9dfe1361SMauro Carvalho Chehab		[<type>:]<name>
83*9dfe1361SMauro Carvalho Chehab
84*9dfe1361SMauro Carvalho Chehab     where <type> optionally specifies the particular upcall program to invoke,
85*9dfe1361SMauro Carvalho Chehab     and thus the type of query to do, and <name> specifies the string to be
86*9dfe1361SMauro Carvalho Chehab     looked up.  The default query type is a straight hostname to IP address
87*9dfe1361SMauro Carvalho Chehab     set lookup.
88*9dfe1361SMauro Carvalho Chehab
89*9dfe1361SMauro Carvalho Chehab     The name parameter is not required to be a NUL-terminated string, and its
90*9dfe1361SMauro Carvalho Chehab     length should be given by the namelen argument.
91*9dfe1361SMauro Carvalho Chehab
92*9dfe1361SMauro Carvalho Chehab     The options parameter may be NULL or it may be a set of options
93*9dfe1361SMauro Carvalho Chehab     appropriate to the query type.
94*9dfe1361SMauro Carvalho Chehab
95*9dfe1361SMauro Carvalho Chehab     The return value is a string appropriate to the query type.  For instance,
96*9dfe1361SMauro Carvalho Chehab     for the default query type it is just a list of comma-separated IPv4 and
97*9dfe1361SMauro Carvalho Chehab     IPv6 addresses.  The caller must free the result.
98*9dfe1361SMauro Carvalho Chehab
99*9dfe1361SMauro Carvalho Chehab     The length of the result string is returned on success, and a negative
100*9dfe1361SMauro Carvalho Chehab     error code is returned otherwise.  -EKEYREJECTED will be returned if the
101*9dfe1361SMauro Carvalho Chehab     DNS lookup failed.
102*9dfe1361SMauro Carvalho Chehab
103*9dfe1361SMauro Carvalho Chehab     If _expiry is non-NULL, the expiry time (TTL) of the result will be
104*9dfe1361SMauro Carvalho Chehab     returned also.
105*9dfe1361SMauro Carvalho Chehab
106*9dfe1361SMauro Carvalho ChehabThe kernel maintains an internal keyring in which it caches looked up keys.
107*9dfe1361SMauro Carvalho ChehabThis can be cleared by any process that has the CAP_SYS_ADMIN capability by
108*9dfe1361SMauro Carvalho Chehabthe use of KEYCTL_KEYRING_CLEAR on the keyring ID.
109*9dfe1361SMauro Carvalho Chehab
110*9dfe1361SMauro Carvalho Chehab
111*9dfe1361SMauro Carvalho ChehabReading DNS Keys from Userspace
112*9dfe1361SMauro Carvalho Chehab===============================
113*9dfe1361SMauro Carvalho Chehab
114*9dfe1361SMauro Carvalho ChehabKeys of dns_resolver type can be read from userspace using keyctl_read() or
115*9dfe1361SMauro Carvalho Chehab"keyctl read/print/pipe".
116*9dfe1361SMauro Carvalho Chehab
117*9dfe1361SMauro Carvalho Chehab
118*9dfe1361SMauro Carvalho ChehabMechanism
119*9dfe1361SMauro Carvalho Chehab=========
120*9dfe1361SMauro Carvalho Chehab
121*9dfe1361SMauro Carvalho ChehabThe dnsresolver module registers a key type called "dns_resolver".  Keys of
122*9dfe1361SMauro Carvalho Chehabthis type are used to transport and cache DNS lookup results from userspace.
123*9dfe1361SMauro Carvalho Chehab
124*9dfe1361SMauro Carvalho ChehabWhen dns_query() is invoked, it calls request_key() to search the local
125*9dfe1361SMauro Carvalho Chehabkeyrings for a cached DNS result.  If that fails to find one, it upcalls to
126*9dfe1361SMauro Carvalho Chehabuserspace to get a new result.
127*9dfe1361SMauro Carvalho Chehab
128*9dfe1361SMauro Carvalho ChehabUpcalls to userspace are made through the request_key() upcall vector, and are
129*9dfe1361SMauro Carvalho Chehabdirected by means of configuration lines in /etc/request-key.conf that tell
130*9dfe1361SMauro Carvalho Chehab/sbin/request-key what program to run to instantiate the key.
131*9dfe1361SMauro Carvalho Chehab
132*9dfe1361SMauro Carvalho ChehabThe upcall handler program is responsible for querying the DNS, processing the
133*9dfe1361SMauro Carvalho Chehabresult into a form suitable for passing to the keyctl_instantiate_key()
134*9dfe1361SMauro Carvalho Chehabroutine.  This then passes the data to dns_resolver_instantiate() which strips
135*9dfe1361SMauro Carvalho Chehaboff and processes any options included in the data, and then attaches the
136*9dfe1361SMauro Carvalho Chehabremainder of the string to the key as its payload.
137*9dfe1361SMauro Carvalho Chehab
138*9dfe1361SMauro Carvalho ChehabThe upcall handler program should set the expiry time on the key to that of the
139*9dfe1361SMauro Carvalho Chehablowest TTL of all the records it has extracted a result from.  This means that
140*9dfe1361SMauro Carvalho Chehabthe key will be discarded and recreated when the data it holds has expired.
141*9dfe1361SMauro Carvalho Chehab
142*9dfe1361SMauro Carvalho Chehabdns_query() returns a copy of the value attached to the key, or an error if
143*9dfe1361SMauro Carvalho Chehabthat is indicated instead.
144*9dfe1361SMauro Carvalho Chehab
145*9dfe1361SMauro Carvalho ChehabSee <file:Documentation/security/keys/request-key.rst> for further
146*9dfe1361SMauro Carvalho Chehabinformation about request-key function.
147*9dfe1361SMauro Carvalho Chehab
148*9dfe1361SMauro Carvalho Chehab
149*9dfe1361SMauro Carvalho ChehabDebugging
150*9dfe1361SMauro Carvalho Chehab=========
151*9dfe1361SMauro Carvalho Chehab
152*9dfe1361SMauro Carvalho ChehabDebugging messages can be turned on dynamically by writing a 1 into the
153*9dfe1361SMauro Carvalho Chehabfollowing file::
154*9dfe1361SMauro Carvalho Chehab
155*9dfe1361SMauro Carvalho Chehab	/sys/module/dnsresolver/parameters/debug
156