aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sunrpc
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-08-14 12:57:55 -0400
committerJ. Bruce Fields <bfields@citi.umich.edu>2009-08-21 11:27:43 -0400
commitbe3ad6b0b675fd1d6b48362ca30bdee75fbef6b4 (patch)
treea71d748cce9e6284e18aa681ed30ab8775415480 /include/linux/sunrpc
parent4516fc0454e7ffe2f369e80045b23c2b32155004 (diff)
sunrpc: add common routine for copying address portion of a sockaddr
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')
-rw-r--r--include/linux/sunrpc/clnt.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index b17df361be82..044f531aee70 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -198,6 +198,17 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
198 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; 198 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
199} 199}
200 200
201static inline bool __rpc_copy_addr4(struct sockaddr *dst,
202 const struct sockaddr *src)
203{
204 const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
205 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
206
207 dsin->sin_family = ssin->sin_family;
208 dsin->sin_addr.s_addr = ssin->sin_addr.s_addr;
209 return true;
210}
211
201#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 212#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
202static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, 213static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
203 const struct sockaddr *sap2) 214 const struct sockaddr *sap2)
@@ -206,12 +217,29 @@ static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
206 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; 217 const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
207 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr); 218 return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
208} 219}
220
221static inline bool __rpc_copy_addr6(struct sockaddr *dst,
222 const struct sockaddr *src)
223{
224 const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src;
225 struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst;
226
227 dsin6->sin6_family = ssin6->sin6_family;
228 ipv6_addr_copy(&dsin6->sin6_addr, &ssin6->sin6_addr);
229 return true;
230}
209#else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ 231#else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
210static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, 232static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1,
211 const struct sockaddr *sap2) 233 const struct sockaddr *sap2)
212{ 234{
213 return false; 235 return false;
214} 236}
237
238static inline bool __rpc_copy_addr6(struct sockaddr *dst,
239 const struct sockaddr *src)
240{
241 return false;
242}
215#endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ 243#endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
216 244
217/** 245/**
@@ -236,5 +264,27 @@ static inline bool rpc_cmp_addr(const struct sockaddr *sap1,
236 return false; 264 return false;
237} 265}
238 266
267/**
268 * rpc_copy_addr - copy the address portion of one sockaddr to another
269 * @dst: destination sockaddr
270 * @src: source sockaddr
271 *
272 * Just copies the address portion and family. Ignores port, scope, etc.
273 * Caller is responsible for making certain that dst is large enough to hold
274 * the address in src. Returns true if address family is supported. Returns
275 * false otherwise.
276 */
277static inline bool rpc_copy_addr(struct sockaddr *dst,
278 const struct sockaddr *src)
279{
280 switch (src->sa_family) {
281 case AF_INET:
282 return __rpc_copy_addr4(dst, src);
283 case AF_INET6:
284 return __rpc_copy_addr6(dst, src);
285 }
286 return false;
287}
288
239#endif /* __KERNEL__ */ 289#endif /* __KERNEL__ */
240#endif /* _LINUX_SUNRPC_CLNT_H */ 290#endif /* _LINUX_SUNRPC_CLNT_H */