aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/dns_resolve.c
diff options
context:
space:
mode:
authorSteve French <sfrench@us.ibm.com>2008-04-25 20:22:23 -0400
committerSteve French <sfrench@us.ibm.com>2008-04-25 20:22:23 -0400
commitd09e860cf07e7c9ee12920a09f5080e30a12a23a (patch)
tree576e2626128ab5d1d147a397a8914c2b4ce3d4fa /fs/cifs/dns_resolve.c
parent404e86e1550cc2c84bb57a372af784585c732f9a (diff)
[CIFS] Adds to dns_resolver checking if the server name is an IP addr and skipping upcall in this case.
Signed-off-by: Igor Mammedov <niallain@gmail.com> Signed-off-by: sfrench@us.ibm.com
Diffstat (limited to 'fs/cifs/dns_resolve.c')
-rw-r--r--fs/cifs/dns_resolve.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index 7cc86c418182..939e256f8497 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -55,6 +55,32 @@ struct key_type key_type_dns_resolver = {
55 .match = user_match, 55 .match = user_match,
56}; 56};
57 57
58/* Checks if supplied name is IP address
59 * returns:
60 * 1 - name is IP
61 * 0 - name is not IP
62 */
63static int is_ip(const char *name)
64{
65 int rc;
66 struct sockaddr_in sin_server;
67 struct sockaddr_in6 sin_server6;
68
69 rc = cifs_inet_pton(AF_INET, name,
70 &sin_server.sin_addr.s_addr);
71
72 if (rc <= 0) {
73 /* not ipv4 address, try ipv6 */
74 rc = cifs_inet_pton(AF_INET6, name,
75 &sin_server6.sin6_addr.in6_u);
76 if (rc > 0)
77 return 1;
78 } else {
79 return 1;
80 }
81 /* we failed translating address */
82 return 0;
83}
58 84
59/* Resolves server name to ip address. 85/* Resolves server name to ip address.
60 * input: 86 * input:
@@ -67,8 +93,9 @@ int
67dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) 93dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
68{ 94{
69 int rc = -EAGAIN; 95 int rc = -EAGAIN;
70 struct key *rkey; 96 struct key *rkey = ERR_PTR(-EAGAIN);
71 char *name; 97 char *name;
98 char *data = NULL;
72 int len; 99 int len;
73 100
74 if (!ip_addr || !unc) 101 if (!ip_addr || !unc)
@@ -97,26 +124,41 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
97 memcpy(name, unc+2, len); 124 memcpy(name, unc+2, len);
98 name[len] = 0; 125 name[len] = 0;
99 126
127 if (is_ip(name)) {
128 cFYI(1, ("%s: it is IP, skipping dns upcall: %s",
129 __func__, name));
130 data = name;
131 goto skip_upcall;
132 }
133
100 rkey = request_key(&key_type_dns_resolver, name, ""); 134 rkey = request_key(&key_type_dns_resolver, name, "");
101 if (!IS_ERR(rkey)) { 135 if (!IS_ERR(rkey)) {
102 len = strlen(rkey->payload.data); 136 data = rkey->payload.data;
103 *ip_addr = kmalloc(len+1, GFP_KERNEL); 137 cFYI(1, ("%s: resolved: %s to %s", __func__,
104 if (*ip_addr) {
105 memcpy(*ip_addr, rkey->payload.data, len);
106 (*ip_addr)[len] = '\0';
107 cFYI(1, ("%s: resolved: %s to %s", __func__,
108 rkey->description, 138 rkey->description,
109 *ip_addr 139 *ip_addr
110 )); 140 ));
141 } else {
142 cERROR(1, ("%s: unable to resolve: %s", __func__, name));
143 goto out;
144 }
145
146skip_upcall:
147 if (data) {
148 len = strlen(data);
149 *ip_addr = kmalloc(len+1, GFP_KERNEL);
150 if (*ip_addr) {
151 memcpy(*ip_addr, data, len);
152 (*ip_addr)[len] = '\0';
111 rc = 0; 153 rc = 0;
112 } else { 154 } else {
113 rc = -ENOMEM; 155 rc = -ENOMEM;
114 } 156 }
115 key_put(rkey); 157 if (!IS_ERR(rkey))
116 } else { 158 key_put(rkey);
117 cERROR(1, ("%s: unable to resolve: %s", __func__, name));
118 } 159 }
119 160
161out:
120 kfree(name); 162 kfree(name);
121 return rc; 163 return rc;
122} 164}