From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-afs-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Wang Lei <wang840925-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH 2/4] Implement a DNS Resolver Module
Date: Wed, 7 Jul 2010 08:02:57 -0400 [thread overview]
Message-ID: <20100707080257.1d627e09@corrin.poochiereds.net> (raw)
In-Reply-To: <20100707091411.16573.81747.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
On Wed, 07 Jul 2010 10:14:11 +0100
David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
-----------------[snip]----------------
> diff --git a/net/dnsresolver/resolv_unc_to_ip.c b/net/dnsresolver/resolv_unc_to_ip.c
> new file mode 100644
> index 0000000..169f9d9
> --- /dev/null
> +++ b/net/dnsresolver/resolv_unc_to_ip.c
> @@ -0,0 +1,111 @@
> +/*
> + * Copyright (c) 2007 Igor Mammedov
> + * Author(s): Igor Mammedov (niallain-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org)
> + * Steve French (sfrench-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org)
> + * Wang Lei (wang840925-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org)
> + *
> + * Routines used for Universal Naming Convention (UNC) path style hostname to
> + * IP address translation. For this function to work, the userspace tool
> + * dns.upcall is needed and something like the following lines should be
> + * added to the /etc/request-key.conf file:
> + *
> + * create dns_resolver * * /sbin/dns.upcall %k
> + *
> + * This library is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU Lesser General Public License as published
> + * by the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> + * the GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/socket.h>
> +#include <linux/in.h>
> +#include <linux/inet.h>
> +#include <linux/in6.h>
> +#include <linux/string.h>
> +#include <linux/dns_resolver.h>
> +#include <keys/dnsresolver-type.h>
> +#include "internal.h"
> +
> +/**
> + * dns_resolve_unc_to_ip - Resolve UNC server name to ip address.
> + * @unc: UNC path specifying the server
> + * @ip_addr: Where to return the IP address.
> + *
> + * The IP address will be returned in string form, and the caller is
> + * responsible for freeing it.
> + *
> + * Returns 0 on success, -ve on error.
> + */
> +int
> +dns_resolve_unc_to_ip(const char *unc, char **ip_addr)
> +{
> + struct in_addr s4;
> + struct in6_addr s6;
> + char *name, *sep;
> + int len, rc;
> +
> + kenter("%s,", unc);
> +
> + rc = -EINVAL;
> + if (!ip_addr || !unc)
> + goto out;
> +
> + len = strlen(unc);
> + if (len < 3)
> + goto out;
> +
> + /* discount leading slashes for cifs */
> + len -= 2;
> + unc += 2;
> +
> + /* search for server name delimiter */
> + sep = memchr(unc, '\\', len);
> + if (sep)
> + len = sep - unc;
> + kdebug("server name:%*.*s", len, len, unc);
> +
> + rc = -ENOMEM;
> + name = kmalloc(len + 1, GFP_KERNEL);
> + if (!name)
> + goto out;
> +
> + memcpy(name, unc, len);
> + name[len] = 0;
> + kdebug("name to resolve '%s'", name);
> +
> + /* Try to convert a string to an IPv4 address */
> + rc = in4_pton(name, len, (void *)&s4.s_addr, '\\', NULL);
> + if (rc > 0) {
> + *ip_addr = name;
> + kleave(" = 0 [UNC is IPv4]");
> + return 0;
> + }
> +
> + /* Try to convert a string to an IPv6 address */
> + rc = in6_pton(name, len, (void *)&s6.s6_addr, '\\', NULL);
> + if (rc > 0) {
> + *ip_addr = name;
> + kleave(" = 0 [UNC is IPv6]");
> + return 0;
> + }
> +
> + /* perform the upcall */
> + rc = request_dns_resolution(name, NULL, ip_addr);
> + kfree(name);
> +
> +out:
> + kleave(" = %d", rc);
> + return rc;
> +}
> +EXPORT_SYMBOL(dns_resolve_unc_to_ip);
>
I'm not sold that the above function really belongs in generic code. It
seems like it might make more sense to have a cifs function that parses
out the host portion of the UNC and then pass that to a generic
function that does the in4_pton/in6_pton and then the upcall if that
fails?
Nice work on the set. Moving the DNS upcall into generic code is
definitely a good move.
--
Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
next prev parent reply other threads:[~2010-07-07 12:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-07 9:14 [PATCH 0/4] Generalise dns_resolver David Howells
2010-07-07 9:14 ` [PATCH 1/4] KEYS: Authorise keyctl_set_timeout() on a key if we have its authorisation key David Howells
[not found] ` <20100707091400.16573.2817.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2010-07-07 9:14 ` [PATCH 2/4] Implement a DNS Resolver Module David Howells
[not found] ` <20100707091411.16573.81747.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2010-07-07 12:02 ` Jeff Layton [this message]
2010-07-20 15:25 ` Jeff Layton
[not found] ` <20100720112506.7f7cfe1d-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-07-20 15:39 ` Steve French
2010-07-20 15:42 ` David Howells
2010-07-07 9:14 ` [PATCH 3/4] Provide generic DNS query function David Howells
2010-07-07 9:14 ` [PATCH 4/4] Add DNS support for AFS David Howells
2010-07-07 19:08 ` [PATCH 0/4] Generalise dns_resolver Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100707080257.1d627e09@corrin.poochiereds.net \
--to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=linux-afs-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=wang840925-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).