]>
git.ipfire.org Git - people/ms/linux.git/blob - fs/cifs/dns_resolve.c
1 // SPDX-License-Identifier: LGPL-2.1
4 * Copyright (c) 2007 Igor Mammedov
5 * Author(s): Igor Mammedov (niallain@gmail.com)
6 * Steve French (sfrench@us.ibm.com)
7 * Wang Lei (wang840925@gmail.com)
8 * David Howells (dhowells@redhat.com)
10 * Contains the CIFS DFS upcall routines used for hostname to
11 * IP address translation.
15 #include <linux/slab.h>
16 #include <linux/dns_resolver.h>
17 #include "dns_resolve.h"
19 #include "cifsproto.h"
20 #include "cifs_debug.h"
23 * dns_resolve_server_name_to_ip - Resolve UNC server name to ip address.
24 * @unc: UNC path specifying the server (with '/' as delimiter)
25 * @ip_addr: Where to return the IP address.
26 * @expiry: Where to return the expiry time for the dns record.
28 * The IP address will be returned in string form, and the caller is
29 * responsible for freeing it.
31 * Returns length of result on success, -ve on error.
34 dns_resolve_server_name_to_ip(const char *unc
, char **ip_addr
, time64_t
*expiry
)
36 struct sockaddr_storage ss
;
37 const char *hostname
, *sep
;
46 cifs_dbg(FYI
, "%s: unc is too short: %s\n", __func__
, unc
);
50 /* Discount leading slashes for cifs */
54 /* Search for server name delimiter */
55 sep
= memchr(hostname
, '/', len
);
59 cifs_dbg(FYI
, "%s: probably server name is whole unc: %s\n",
62 /* Try to interpret hostname as an IPv4 or IPv6 address */
63 rc
= cifs_convert_address((struct sockaddr
*)&ss
, hostname
, len
);
65 goto name_is_IP_address
;
67 /* Perform the upcall */
68 rc
= dns_query(current
->nsproxy
->net_ns
, NULL
, hostname
, len
,
69 NULL
, ip_addr
, expiry
, false);
71 cifs_dbg(FYI
, "%s: unable to resolve: %*.*s\n",
72 __func__
, len
, len
, hostname
);
74 cifs_dbg(FYI
, "%s: resolved: %*.*s to %s expiry %llu\n",
75 __func__
, len
, len
, hostname
, *ip_addr
,
76 expiry
? (*expiry
) : 0);
80 name
= kmalloc(len
+ 1, GFP_KERNEL
);
83 memcpy(name
, hostname
, len
);
85 cifs_dbg(FYI
, "%s: unc is IP, skipping dns upcall: %s\n",