Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4516fc04 authored by Jeff Layton's avatar Jeff Layton Committed by J. Bruce Fields
Browse files

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: default avatarJeff Layton <jlayton@redhat.com>
Acked-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
parent e9dc1221
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -166,7 +166,7 @@ __be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
		 */
		 */
		if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
		if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
			continue;
			continue;
		if (!nlm_cmp_addr(nlm_addr(block->b_host), addr))
		if (!rpc_cmp_addr(nlm_addr(block->b_host), addr))
			continue;
			continue;
		if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
		if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
			continue;
			continue;
+2 −2
Original line number Original line Diff line number Diff line
@@ -111,7 +111,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
	 */
	 */
	chain = &nlm_hosts[nlm_hash_address(ni->sap)];
	chain = &nlm_hosts[nlm_hash_address(ni->sap)];
	hlist_for_each_entry(host, pos, chain, h_hash) {
	hlist_for_each_entry(host, pos, chain, h_hash) {
		if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
		if (!rpc_cmp_addr(nlm_addr(host), ni->sap))
			continue;
			continue;


		/* See if we have an NSM handle for this client */
		/* 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)
		if (host->h_server != ni->server)
		if (host->h_server != ni->server)
			continue;
			continue;
		if (ni->server &&
		if (ni->server &&
		    !nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
		    !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap))
			continue;
			continue;


		/* Move to head of hash chain. */
		/* Move to head of hash chain. */
+1 −1
Original line number Original line Diff line number Diff line
@@ -209,7 +209,7 @@ static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
	struct nsm_handle *nsm;
	struct nsm_handle *nsm;


	list_for_each_entry(nsm, &nsm_handles, sm_link)
	list_for_each_entry(nsm, &nsm_handles, sm_link)
		if (nlm_cmp_addr(nsm_addr(nsm), sap))
		if (rpc_cmp_addr(nsm_addr(nsm), sap))
			return nsm;
			return nsm;
	return NULL;
	return NULL;
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
static int
static int
nlmsvc_match_ip(void *datap, struct nlm_host *host)
nlmsvc_match_ip(void *datap, struct nlm_host *host)
{
{
	return nlm_cmp_addr(nlm_srcaddr(host), datap);
	return rpc_cmp_addr(nlm_srcaddr(host), datap);
}
}


/**
/**
+0 −43
Original line number Original line Diff line number Diff line
@@ -338,49 +338,6 @@ static inline int nlm_privileged_requester(const struct svc_rqst *rqstp)
	}
	}
}
}


static inline int __nlm_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;
}

#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
static inline int __nlm_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);
}
#else	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
				  const struct sockaddr *sap2)
{
	return 0;
}
#endif	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */

/*
 * Compare two host addresses
 *
 * Return TRUE if the addresses are the same; otherwise FALSE.
 */
static inline int nlm_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 __nlm_cmp_addr4(sap1, sap2);
		case AF_INET6:
			return __nlm_cmp_addr6(sap1, sap2);
		}
	}
	return 0;
}

/*
/*
 * Compare two NLM locks.
 * Compare two NLM locks.
 * When the second lock is of type F_UNLCK, this acts like a wildcard.
 * When the second lock is of type F_UNLCK, this acts like a wildcard.
Loading