Skip to content

Commit c2e8139

Browse files
Bryan SchumakerSteve French
authored andcommitted
NFS: Use kernel DNS resolver [ver #2]
Use the kernel DNS resolver to translate hostnames to IP addresses. Create a new config option to choose between the legacy DNS resolver and the new resolver. Signed-off-by: Bryan Schumaker <[email protected]> Acked-by: Trond Myklebust <[email protected]> Signed-off-by: David Howells <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 3694b91 commit c2e8139

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

fs/nfs/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,19 @@ config NFS_FSCACHE
100100
help
101101
Say Y here if you want NFS data to be cached locally on disc through
102102
the general filesystem cache manager
103+
104+
config NFS_USE_LEGACY_DNS
105+
bool "Use the legacy NFS DNS resolver"
106+
depends on NFS_V4
107+
help
108+
The kernel now provides a method for translating a host name into an
109+
IP address. Select Y here if you would rather use your own DNS
110+
resolver script.
111+
112+
If unsure, say N
113+
114+
config NFS_USE_KERNEL_DNS
115+
bool
116+
depends on NFS_V4 && !NFS_USE_LEGACY_DNS
117+
select DNS_RESOLVER
118+
default y

fs/nfs/dns_resolve.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66
* Resolves DNS hostnames into valid ip addresses
77
*/
88

9+
#ifdef CONFIG_NFS_USE_KERNEL_DNS
10+
11+
#include <linux/sunrpc/clnt.h>
12+
#include <linux/dns_resolver.h>
13+
14+
ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
15+
struct sockaddr *sa, size_t salen)
16+
{
17+
ssize_t ret;
18+
char *ip_addr = NULL;
19+
int ip_len;
20+
21+
ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
22+
if (ip_len > 0)
23+
ret = rpc_pton(ip_addr, ip_len, sa, salen);
24+
else
25+
ret = -ESRCH;
26+
kfree(ip_addr);
27+
return ret;
28+
}
29+
30+
#else
31+
932
#include <linux/hash.h>
1033
#include <linux/string.h>
1134
#include <linux/kmod.h>
@@ -346,3 +369,4 @@ void nfs_dns_resolver_destroy(void)
346369
nfs_cache_unregister(&nfs_dns_resolve);
347370
}
348371

372+
#endif

fs/nfs/dns_resolve.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@
66

77
#define NFS_DNS_HOSTNAME_MAXLEN (128)
88

9+
10+
#ifdef CONFIG_NFS_USE_KERNEL_DNS
11+
static inline int nfs_dns_resolver_init(void)
12+
{
13+
return 0;
14+
}
15+
16+
static inline void nfs_dns_resolver_destroy(void)
17+
{}
18+
#else
919
extern int nfs_dns_resolver_init(void);
1020
extern void nfs_dns_resolver_destroy(void);
21+
#endif
22+
1123
extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
1224
struct sockaddr *sa, size_t salen);
1325

0 commit comments

Comments
 (0)