summaryrefslogtreecommitdiffstats
path: root/fs/nfs/client.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2008-01-03 13:28:58 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2008-01-30 02:05:54 -0500
commit3b0d3f93d01bb013c3dcf9555d2d111c91ac6a1e (patch)
treeb59e7051ffad487d6c621ffe9526e3d9dd037a1d /fs/nfs/client.c
parent0d0f0c192df0282600c6d11c8cc252e7e7a80afc (diff)
downloadop-kernel-dev-3b0d3f93d01bb013c3dcf9555d2d111c91ac6a1e.zip
op-kernel-dev-3b0d3f93d01bb013c3dcf9555d2d111c91ac6a1e.tar.gz
NFS: Add support for AF_INET6 addresses in __nfs_find_client()
Introduce AF_INET6-specific address checking to __nfs_find_client(). Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/client.c')
-rw-r--r--fs/nfs/client.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 701cd19..876162c 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -34,6 +34,8 @@
#include <linux/nfs_idmap.h>
#include <linux/vfs.h>
#include <linux/inet.h>
+#include <linux/in6.h>
+#include <net/ipv6.h>
#include <linux/nfs_xdr.h>
#include <asm/system.h>
@@ -208,16 +210,44 @@ void nfs_put_client(struct nfs_client *clp)
}
}
+static int nfs_sockaddr_match_ipaddr4(const struct sockaddr_in *sa1,
+ const struct sockaddr_in *sa2)
+{
+ return sa1->sin_addr.s_addr == sa2->sin_addr.s_addr;
+}
+
+static int nfs_sockaddr_match_ipaddr6(const struct sockaddr_in6 *sa1,
+ const struct sockaddr_in6 *sa2)
+{
+ return ipv6_addr_equal(&sa1->sin6_addr, &sa2->sin6_addr);
+}
+
+static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
+ const struct sockaddr *sa2)
+{
+ switch (sa1->sa_family) {
+ case AF_INET:
+ return nfs_sockaddr_match_ipaddr4((const struct sockaddr_in *)sa1,
+ (const struct sockaddr_in *)sa2);
+ case AF_INET6:
+ return nfs_sockaddr_match_ipaddr6((const struct sockaddr_in6 *)sa1,
+ (const struct sockaddr_in6 *)sa2);
+ }
+ BUG();
+}
+
/*
* Find a client by IP address and protocol version
* - returns NULL if no such client
*/
-struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
+struct nfs_client *_nfs_find_client(const struct sockaddr *addr, int nfsversion)
{
struct nfs_client *clp;
spin_lock(&nfs_client_lock);
list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
+ struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
+
/* Don't match clients that failed to initialise properly */
if (clp->cl_cons_state != NFS_CS_READY)
continue;
@@ -226,8 +256,10 @@ struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversio
if (clp->rpc_ops->version != nfsversion)
continue;
+ if (addr->sa_family != clap->sa_family)
+ continue;
/* Match only the IP address, not the port number */
- if (clp->cl_addr.sin_addr.s_addr != addr->sin_addr.s_addr)
+ if (!nfs_sockaddr_match_ipaddr(addr, clap))
continue;
atomic_inc(&clp->cl_count);
@@ -238,6 +270,11 @@ struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversio
return NULL;
}
+struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversion)
+{
+ return _nfs_find_client((const struct sockaddr *)addr, nfsversion);
+}
+
/*
* Find an nfs_client on the list that matches the initialisation data
* that is supplied.
OpenPOWER on IntegriCloud