Skip to content

Commit 4516fc0

Browse files
jtlaytonJ. Bruce Fields
authored andcommitted
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>
1 parent e9dc122 commit 4516fc0

6 files changed

Lines changed: 53 additions & 48 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ __be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
166166
*/
167167
if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
168168
continue;
169-
if (!nlm_cmp_addr(nlm_addr(block->b_host), addr))
169+
if (!rpc_cmp_addr(nlm_addr(block->b_host), addr))
170170
continue;
171171
if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
172172
continue;

‎fs/lockd/host.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
111111
*/
112112
chain = &nlm_hosts[nlm_hash_address(ni->sap)];
113113
hlist_for_each_entry(host, pos, chain, h_hash) {
114-
if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
114+
if (!rpc_cmp_addr(nlm_addr(host), ni->sap))
115115
continue;
116116

117117
/* See if we have an NSM handle for this client */
@@ -125,7 +125,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
125125
if (host->h_server != ni->server)
126126
continue;
127127
if (ni->server &&
128-
!nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
128+
!rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap))
129129
continue;
130130

131131
/* Move to head of hash chain. */

‎fs/lockd/mon.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
209209
struct nsm_handle *nsm;
210210

211211
list_for_each_entry(nsm, &nsm_handles, sm_link)
212-
if (nlm_cmp_addr(nsm_addr(nsm), sap))
212+
if (rpc_cmp_addr(nsm_addr(nsm), sap))
213213
return nsm;
214214
return NULL;
215215
}

‎fs/lockd/svcsubs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
417417
static int
418418
nlmsvc_match_ip(void *datap, struct nlm_host *host)
419419
{
420-
return nlm_cmp_addr(nlm_srcaddr(host), datap);
420+
return rpc_cmp_addr(nlm_srcaddr(host), datap);
421421
}
422422

423423
/**

‎include/linux/lockd/lockd.h‎

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -338,49 +338,6 @@ static inline int nlm_privileged_requester(const struct svc_rqst *rqstp)
338338
}
339339
}
340340

341-
static inline int __nlm_cmp_addr4(const struct sockaddr *sap1,
342-
const struct sockaddr *sap2)
343-
{
344-
const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
345-
const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
346-
return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
347-
}
348-
349-
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
350-
static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
351-
const struct sockaddr *sap2)
352-
{
353-
const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
354-
const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
355-
return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
356-
}
357-
#else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
358-
static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
359-
const struct sockaddr *sap2)
360-
{
361-
return 0;
362-
}
363-
#endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
364-
365-
/*
366-
* Compare two host addresses
367-
*
368-
* Return TRUE if the addresses are the same; otherwise FALSE.
369-
*/
370-
static inline int nlm_cmp_addr(const struct sockaddr *sap1,
371-
const struct sockaddr *sap2)
372-
{
373-
if (sap1->sa_family == sap2->sa_family) {
374-
switch (sap1->sa_family) {
375-
case AF_INET:
376-
return __nlm_cmp_addr4(sap1, sap2);
377-
case AF_INET6:
378-
return __nlm_cmp_addr6(sap1, sap2);
379-
}
380-
}
381-
return 0;
382-
}
383-
384341
/*
385342
* Compare two NLM locks.
386343
* When the second lock is of type F_UNLCK, this acts like a wildcard.

‎include/linux/sunrpc/clnt.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/sunrpc/timer.h>
2323
#include <asm/signal.h>
2424
#include <linux/path.h>
25+
#include <net/ipv6.h>
2526

2627
struct rpc_inode;
2728

@@ -188,5 +189,52 @@ static inline void rpc_set_port(struct sockaddr *sap,
188189
#define IPV6_SCOPE_DELIMITER '%'
189190
#define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn")
190191

192+
static 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)
202+
static 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) */
210+
static 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+
*/
225+
static 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+
191239
#endif /* __KERNEL__ */
192240
#endif /* _LINUX_SUNRPC_CLNT_H */

0 commit comments

Comments
 (0)