This source file includes following definitions.
- dns_resolve_server_name_to_ip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include <linux/slab.h>
29 #include <linux/dns_resolver.h>
30 #include "dns_resolve.h"
31 #include "cifsglob.h"
32 #include "cifsproto.h"
33 #include "cifs_debug.h"
34
35
36
37
38
39
40
41
42
43
44
45 int
46 dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
47 {
48 struct sockaddr_storage ss;
49 const char *hostname, *sep;
50 char *name;
51 int len, rc;
52
53 if (!ip_addr || !unc)
54 return -EINVAL;
55
56 len = strlen(unc);
57 if (len < 3) {
58 cifs_dbg(FYI, "%s: unc is too short: %s\n", __func__, unc);
59 return -EINVAL;
60 }
61
62
63 len -= 2;
64 hostname = unc + 2;
65
66
67 sep = memchr(hostname, '/', len);
68 if (sep)
69 len = sep - hostname;
70 else
71 cifs_dbg(FYI, "%s: probably server name is whole unc: %s\n",
72 __func__, unc);
73
74
75 rc = cifs_convert_address((struct sockaddr *)&ss, hostname, len);
76 if (rc > 0)
77 goto name_is_IP_address;
78
79
80 rc = dns_query(current->nsproxy->net_ns, NULL, hostname, len,
81 NULL, ip_addr, NULL, false);
82 if (rc < 0)
83 cifs_dbg(FYI, "%s: unable to resolve: %*.*s\n",
84 __func__, len, len, hostname);
85 else
86 cifs_dbg(FYI, "%s: resolved: %*.*s to %s\n",
87 __func__, len, len, hostname, *ip_addr);
88 return rc;
89
90 name_is_IP_address:
91 name = kmalloc(len + 1, GFP_KERNEL);
92 if (!name)
93 return -ENOMEM;
94 memcpy(name, hostname, len);
95 name[len] = 0;
96 cifs_dbg(FYI, "%s: unc is IP, skipping dns upcall: %s\n",
97 __func__, name);
98 *ip_addr = name;
99 return 0;
100 }