sunrpc: add common routine for copying address portion of a sockaddr
[safe/jmp/linux-2.6] / include / linux / sunrpc / clnt.h
index 2636e8a..044f531 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/sunrpc/xdr.h>
 #include <linux/sunrpc/timer.h>
 #include <asm/signal.h>
+#include <linux/path.h>
+#include <net/ipv6.h>
 
 struct rpc_inode;
 
@@ -54,9 +56,7 @@ struct rpc_clnt {
 
        int                     cl_nodelen;     /* nodename length */
        char                    cl_nodename[UNX_MAXNODENAME];
-       char                    cl_pathname[30];/* Path in rpc_pipe_fs */
-       struct vfsmount *       cl_vfsmnt;
-       struct dentry *         cl_dentry;      /* inode */
+       struct path             cl_path;
        struct rpc_clnt *       cl_parent;      /* Points to parent of clones */
        struct rpc_rtt          cl_rtt_default;
        struct rpc_timeout      cl_timeout_default;
@@ -189,5 +189,102 @@ static inline void rpc_set_port(struct sockaddr *sap,
 #define IPV6_SCOPE_DELIMITER           '%'
 #define IPV6_SCOPE_ID_LEN              sizeof("%nnnnnnnnnn")
 
+static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
+                                  const struct sockaddr *sap2)
+{
+       const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
+       const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
+
+       return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
+}
+
+static inline bool __rpc_copy_addr4(struct sockaddr *dst,
+                                   const struct sockaddr *src)
+{
+       const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
+       struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
+
+       dsin->sin_family = ssin->sin_family;
+       dsin->sin_addr.s_addr = ssin->sin_addr.s_addr;
+       return true;
+}
+
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
+                                  const struct sockaddr *sap2)
+{
+       const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
+       const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
+       return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
+}
+
+static inline bool __rpc_copy_addr6(struct sockaddr *dst,
+                                   const struct sockaddr *src)
+{
+       const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src;
+       struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst;
+
+       dsin6->sin6_family = ssin6->sin6_family;
+       ipv6_addr_copy(&dsin6->sin6_addr, &ssin6->sin6_addr);
+       return true;
+}
+#else  /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
+static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
+                                  const struct sockaddr *sap2)
+{
+       return false;
+}
+
+static inline bool __rpc_copy_addr6(struct sockaddr *dst,
+                                   const struct sockaddr *src)
+{
+       return false;
+}
+#endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
+
+/**
+ * rpc_cmp_addr - compare the address portion of two sockaddrs.
+ * @sap1: first sockaddr
+ * @sap2: second sockaddr
+ *
+ * Just compares the family and address portion. Ignores port, scope, etc.
+ * Returns true if the addrs are equal, false if they aren't.
+ */
+static inline bool rpc_cmp_addr(const struct sockaddr *sap1,
+                               const struct sockaddr *sap2)
+{
+       if (sap1->sa_family == sap2->sa_family) {
+               switch (sap1->sa_family) {
+               case AF_INET:
+                       return __rpc_cmp_addr4(sap1, sap2);
+               case AF_INET6:
+                       return __rpc_cmp_addr6(sap1, sap2);
+               }
+       }
+       return false;
+}
+
+/**
+ * rpc_copy_addr - copy the address portion of one sockaddr to another
+ * @dst: destination sockaddr
+ * @src: source sockaddr
+ *
+ * Just copies the address portion and family. Ignores port, scope, etc.
+ * Caller is responsible for making certain that dst is large enough to hold
+ * the address in src. Returns true if address family is supported. Returns
+ * false otherwise.
+ */
+static inline bool rpc_copy_addr(struct sockaddr *dst,
+                                const struct sockaddr *src)
+{
+       switch (src->sa_family) {
+       case AF_INET:
+               return __rpc_copy_addr4(dst, src);
+       case AF_INET6:
+               return __rpc_copy_addr6(dst, src);
+       }
+       return false;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_CLNT_H */