1212 *
1313 */
1414
15+ #include <linux/inet.h>
1516#include <linux/slab.h>
1617#include <linux/dns_resolver.h>
1718#include "dns_resolve.h"
2526 * @ip_addr: Where to return the IP address.
2627 * @expiry: Where to return the expiry time for the dns record.
2728 *
28- * The IP address will be returned in string form, and the caller is
29- * responsible for freeing it.
30- *
31- * Returns length of result on success, -ve on error.
29+ * Returns zero success, -ve on error.
3230 */
3331int
34- dns_resolve_server_name_to_ip (const char * unc , char * * ip_addr , time64_t * expiry )
32+ dns_resolve_server_name_to_ip (const char * unc , struct sockaddr * ip_addr , time64_t * expiry )
3533{
36- struct sockaddr_storage ss ;
3734 const char * hostname , * sep ;
38- char * name ;
35+ char * ip ;
3936 int len , rc ;
4037
4138 if (!ip_addr || !unc )
@@ -60,30 +57,32 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr, time64_t *expiry)
6057 __func__ , unc );
6158
6259 /* Try to interpret hostname as an IPv4 or IPv6 address */
63- rc = cifs_convert_address ((struct sockaddr * )& ss , hostname , len );
64- if (rc > 0 )
65- goto name_is_IP_address ;
60+ rc = cifs_convert_address (ip_addr , hostname , len );
61+ if (rc > 0 ) {
62+ cifs_dbg (FYI , "%s: unc is IP, skipping dns upcall: %*.*s\n" , __func__ , len , len ,
63+ hostname );
64+ return 0 ;
65+ }
6666
6767 /* Perform the upcall */
6868 rc = dns_query (current -> nsproxy -> net_ns , NULL , hostname , len ,
69- NULL , ip_addr , expiry , false);
70- if (rc < 0 )
69+ NULL , & ip , expiry , false);
70+ if (rc < 0 ) {
7171 cifs_dbg (FYI , "%s: unable to resolve: %*.*s\n" ,
7272 __func__ , len , len , hostname );
73- else
73+ } else {
7474 cifs_dbg (FYI , "%s: resolved: %*.*s to %s expiry %llu\n" ,
75- __func__ , len , len , hostname , * ip_addr ,
75+ __func__ , len , len , hostname , ip ,
7676 expiry ? (* expiry ) : 0 );
77- return rc ;
7877
79- name_is_IP_address :
80- name = kmalloc ( len + 1 , GFP_KERNEL );
81- if (! name )
82- return - ENOMEM ;
83- memcpy ( name , hostname , len );
84- name [ len ] = 0 ;
85- cifs_dbg ( FYI , "%s: unc is IP, skipping dns upcall: %s\n" ,
86- __func__ , name ) ;
87- * ip_addr = name ;
88- return 0 ;
78+ rc = cifs_convert_address ( ip_addr , ip , strlen ( ip ));
79+ kfree ( ip );
80+
81+ if (! rc ) {
82+ cifs_dbg ( FYI , "%s: unable to determine ip address\n" , __func__ );
83+ rc = - EHOSTUNREACH ;
84+ } else
85+ rc = 0 ;
86+ }
87+ return rc ;
8988}
0 commit comments