Skip to content

Commit

Permalink
DNS: Separate out CIFS DNS Resolver code
Browse files Browse the repository at this point in the history
Separate out the DNS resolver key type from the CIFS filesystem into its own
module so that it can be made available for general use, including the AFS
filesystem module.

This facility makes it possible for the kernel to upcall to userspace to have
it issue DNS requests, package up the replies and present them to the kernel
in a useful form.  The kernel is then able to cache the DNS replies as keys
can be retained in keyrings.

Resolver keys are of type "dns_resolver" and have a case-insensitive
description that is of the form "[<type>:]<domain_name>".  The optional <type>
indicates the particular DNS lookup and packaging that's required.  The
<domain_name> is the query to be made.

If <type> isn't given, a basic hostname to IP address lookup is made, and the
result is stored in the key in the form of a printable string consisting of a
comma-separated list of IPv4 and IPv6 addresses.

This key type is supported by userspace helpers driven from /sbin/request-key
and configured through /etc/request-key.conf.  The cifs.upcall utility is
invoked for UNC path server name to IP address resolution.

The CIFS functionality is encapsulated by the dns_resolve_unc_to_ip() function,
which is used to resolve a UNC path to an IP address for CIFS filesystem.  This
part remains in the CIFS module for now.

See the added Documentation/networking/dns_resolver.txt for more information.

Signed-off-by: Wang Lei <[email protected]>
Signed-off-by: David Howells <[email protected]>
Acked-by: Jeff Layton <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
weylan authored and Steve French committed Aug 5, 2010
1 parent ba5dadb commit 1a4240f
Show file tree
Hide file tree
Showing 14 changed files with 708 additions and 205 deletions.
146 changes: 146 additions & 0 deletions Documentation/networking/dns_resolver.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
===================
DNS Resolver Module
===================

Contents:

- Overview.
- Compilation.
- Setting up.
- Usage.
- Mechanism.
- Debugging.


========
OVERVIEW
========

The DNS resolver module provides a way for kernel services to make DNS queries
by way of requesting a key of key type dns_resolver. These queries are
upcalled to userspace through /sbin/request-key.

These routines must be supported by userspace tools dns.upcall, cifs.upcall and
request-key. It is under development and does not yet provide the full feature
set. The features it does support include:

(*) Implements the dns_resolver key_type to contact userspace.

It does not yet support the following AFS features:

(*) Dns query support for AFSDB resource record.

This code is extracted from the CIFS filesystem.


===========
COMPILATION
===========

The module should be enabled by turning on the kernel configuration options:

CONFIG_DNS_RESOLVER - tristate "DNS Resolver support"


==========
SETTING UP
==========

To set up this facility, the /etc/request-key.conf file must be altered so that
/sbin/request-key can appropriately direct the upcalls. For example, to handle
basic dname to IPv4/IPv6 address resolution, the following line should be
added:

#OP TYPE DESC CO-INFO PROGRAM ARG1 ARG2 ARG3 ...
#====== ============ ======= ======= ==========================
create dns_resolver * * /usr/sbin/cifs.upcall %k

To direct a query for query type 'foo', a line of the following should be added
before the more general line given above as the first match is the one taken.

create dns_resolver foo:* * /usr/sbin/dns.foo %k



=====
USAGE
=====

To make use of this facility, one of the following functions that are
implemented in the module can be called after doing:

#include <linux/dns_resolver.h>

(1) int dns_query(const char *type, const char *name, size_t namelen,
const char *options, char **_result, time_t *_expiry);

This is the basic access function. It looks for a cached DNS query and if
it doesn't find it, it upcalls to userspace to make a new DNS query, which
may then be cached. The key description is constructed as a string of the
form:

[<type>:]<name>

where <type> optionally specifies the particular upcall program to invoke,
and thus the type of query to do, and <name> specifies the string to be
looked up. The default query type is a straight hostname to IP address
set lookup.

The name parameter is not required to be a NUL-terminated string, and its
length should be given by the namelen argument.

The options parameter may be NULL or it may be a set of options
appropriate to the query type.

The return value is a string appropriate to the query type. For instance,
for the default query type it is just a list of comma-separated IPv4 and
IPv6 addresses. The caller must free the result.

The length of the result string is returned on success, and a -ve error
code is returned otherwise. -EKEYREJECTED will be returned if the DNS
lookup failed.

If _expiry is non-NULL, the expiry time (TTL) of the result will be
returned also.


=========
MECHANISM
=========

The dnsresolver module registers a key type called "dns_resolver". Keys of
this type are used to transport and cache DNS lookup results from userspace.

When dns_query() is invoked, it calls request_key() to search the local
keyrings for a cached DNS result. If that fails to find one, it upcalls to
userspace to get a new result.

Upcalls to userspace are made through the request_key() upcall vector, and are
directed by means of configuration lines in /etc/request-key.conf that tell
/sbin/request-key what program to run to instantiate the key.

The upcall handler program is responsible for querying the DNS, processing the
result into a form suitable for passing to the keyctl_instantiate_key()
routine. This then passes the data to dns_resolver_instantiate() which strips
off and processes any options included in the data, and then attaches the
remainder of the string to the key as its payload.

The upcall handler program should set the expiry time on the key to that of the
lowest TTL of all the records it has extracted a result from. This means that
the key will be discarded and recreated when the data it holds has expired.

dns_query() returns a copy of the value attached to the key, or an error if
that is indicated instead.

See <file:Documentation/keys-request-key.txt> for further information about
request-key function.


=========
DEBUGGING
=========

Debugging messages can be turned on dynamically by writing a 1 into the
following file:

/sys/module/dnsresolver/parameters/debug
17 changes: 9 additions & 8 deletions fs/cifs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ config CIFS_WEAK_PW_HASH
If unsure, say N.

config CIFS_UPCALL
bool "Kerberos/SPNEGO advanced session setup"
depends on CIFS && KEYS
help
Enables an upcall mechanism for CIFS which accesses
userspace helper utilities to provide SPNEGO packaged (RFC 4178)
Kerberos tickets which are needed to mount to certain secure servers
(for which more secure Kerberos authentication is required). If
unsure, say N.
bool "Kerberos/SPNEGO advanced session setup"
depends on CIFS && KEYS
select DNS_RESOLVER
help
Enables an upcall mechanism for CIFS which accesses userspace helper
utilities to provide SPNEGO packaged (RFC 4178) Kerberos tickets
which are needed to mount to certain secure servers (for which more
secure Kerberos authentication is required). If unsure, say N.

config CIFS_XATTR
bool "CIFS extended attributes"
Expand Down Expand Up @@ -122,6 +122,7 @@ config CIFS_DEBUG2
config CIFS_DFS_UPCALL
bool "DFS feature support"
depends on CIFS && KEYS
select DNS_RESOLVER
help
Distributed File System (DFS) support is used to access shares
transparently in an enterprise name space, even if the share
Expand Down
13 changes: 1 addition & 12 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "cifs_fs_sb.h"
#include <linux/mm.h>
#include <linux/key-type.h>
#include "dns_resolve.h"
#include "cifs_spnego.h"
#include "fscache.h"
#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
Expand Down Expand Up @@ -933,23 +932,14 @@ init_cifs(void)
rc = register_key_type(&cifs_spnego_key_type);
if (rc)
goto out_unregister_filesystem;
#endif
#ifdef CONFIG_CIFS_DFS_UPCALL
rc = cifs_init_dns_resolver();
if (rc)
goto out_unregister_key_type;
#endif
rc = slow_work_register_user(THIS_MODULE);
if (rc)
goto out_unregister_resolver_key;
goto out_unregister_key_type;

return 0;

out_unregister_resolver_key:
#ifdef CONFIG_CIFS_DFS_UPCALL
cifs_exit_dns_resolver();
out_unregister_key_type:
#endif
#ifdef CONFIG_CIFS_UPCALL
unregister_key_type(&cifs_spnego_key_type);
out_unregister_filesystem:
Expand All @@ -976,7 +966,6 @@ exit_cifs(void)
cifs_fscache_unregister();
#ifdef CONFIG_CIFS_DFS_UPCALL
cifs_dfs_release_automount_timer();
cifs_exit_dns_resolver();
#endif
#ifdef CONFIG_CIFS_UPCALL
unregister_key_type(&cifs_spnego_key_type);
Expand Down
Loading

0 comments on commit 1a4240f

Please sign in to comment.