aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sunrpc/clnt.h
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-08-14 12:57:54 -0400
committerJ. Bruce Fields <bfields@citi.umich.edu>2009-08-21 11:27:42 -0400
commit4516fc0454e7ffe2f369e80045b23c2b32155004 (patch)
treeb1068b9fbad76b5381b103fc57617373ec2ae37d /include/linux/sunrpc/clnt.h
parente9dc122166b8d863d3057a66ada04838e5548e52 (diff)
sunrpc: add routine for comparing addresses
lockd needs these sort of routines, as does the NFSv4 callback code. Move lockd's routines into common code and rename them so that they can be used by others. Signed-off-by: Jeff Layton <jlayton@redhat.com> Acked-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'include/linux/sunrpc/clnt.h')
-rw-r--r--include/linux/sunrpc/clnt.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index ab3f6e90caa5..b17df361be82 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -22,6 +22,7 @@
22#include <linux/sunrpc/timer.h> 22#include <linux/sunrpc/timer.h>
23#include <asm/signal.h> 23#include <asm/signal.h>
24#include <linux/path.h> 24#include <linux/path.h>
25#include <net/ipv6.h>
25 26
26struct rpc_inode; 27struct rpc_inode;
27 28
@@ -188,5 +189,52 @@ static inline void rpc_set_port(struct sockaddr *sap,
188#define IPV6_SCOPE_DELIMITER '%' 189#define IPV6_SCOPE_DELIMITER '%'
189#define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") 190#define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn")
190 191
192static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
193 const struct sockaddr *sap2)
194{
195 const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
196 const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
197
198 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
199}
200
201#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
202static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
203 const struct sockaddr *sap2)
204{
205 const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
206 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
207 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
208}
209#else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
210static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
211 const struct sockaddr *sap2)
212{
213 return false;
214}
215#endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
216
217/**
218 * rpc_cmp_addr - compare the address portion of two sockaddrs.
219 * @sap1: first sockaddr
220 * @sap2: second sockaddr
221 *
222 * Just compares the family and address portion. Ignores port, scope, etc.
223 * Returns true if the addrs are equal, false if they aren't.
224 */
225static inline bool rpc_cmp_addr(const struct sockaddr *sap1,
226 const struct sockaddr *sap2)
227{
228 if (sap1->sa_family == sap2->sa_family) {
229 switch (sap1->sa_family) {
230 case AF_INET:
231 return __rpc_cmp_addr4(sap1, sap2);
232 case AF_INET6:
233 return __rpc_cmp_addr6(sap1, sap2);
234 }
235 }
236 return false;
237}
238
191#endif /* __KERNEL__ */ 239#endif /* __KERNEL__ */
192#endif /* _LINUX_SUNRPC_CLNT_H */ 240#endif /* _LINUX_SUNRPC_CLNT_H */