From: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
To: "Hefty, Sean" <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: linux-rdma <linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 1/2] rdma/cm: fix handling of ipv6 addressing in cma_use_port
Date: Tue, 10 May 2011 14:30:20 -0700 [thread overview]
Message-ID: <20110510143020.7e6d3d4e.weiny2@llnl.gov> (raw)
In-Reply-To: <CF9C39F99A89134C9CF9C4CCB68B8DDF25DCC49B2B-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
On Fri, 15 Apr 2011 23:42:48 -0700
"Hefty, Sean" <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:
> cma_use_port is coded assuming that the sockaddr is an ipv4 address.
> Since ipv6 addressing is supported, and also to support other address
> families, make the code more generic in its address handling.
>
> Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Acked-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
> ---
> This patch was originally submitted as patch 2 of the AF_IB patch set;
> however, it will also be used by the REUSEADDR support for patch 2/2.
>
> drivers/infiniband/core/cma.c | 29 ++++++++++++++++++++++-------
> 1 files changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 6884da2..a1b1e27 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -708,6 +708,21 @@ static inline int cma_any_addr(struct sockaddr *addr)
> return cma_zero_addr(addr) || cma_loopback_addr(addr);
> }
>
> +static int cma_addr_cmp(struct sockaddr *src, struct sockaddr *dst)
> +{
> + if (src->sa_family != dst->sa_family)
> + return -1;
> +
> + switch (src->sa_family) {
> + case AF_INET:
> + return ((struct sockaddr_in *) src)->sin_addr.s_addr !=
> + ((struct sockaddr_in *) dst)->sin_addr.s_addr;
> + default:
> + return ipv6_addr_cmp(&((struct sockaddr_in6 *) src)->sin6_addr,
> + &((struct sockaddr_in6 *) dst)->sin6_addr);
> + }
> +}
> +
> static inline __be16 cma_port(struct sockaddr *addr)
> {
> if (addr->sa_family == AF_INET)
> @@ -2159,13 +2174,13 @@ retry:
> static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
> {
> struct rdma_id_private *cur_id;
> - struct sockaddr_in *sin, *cur_sin;
> + struct sockaddr *addr, *cur_addr;
> struct rdma_bind_list *bind_list;
> struct hlist_node *node;
> unsigned short snum;
>
> - sin = (struct sockaddr_in *) &id_priv->id.route.addr.src_addr;
> - snum = ntohs(sin->sin_port);
> + addr = (struct sockaddr *) &id_priv->id.route.addr.src_addr;
> + snum = ntohs(cma_port(addr));
> if (snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
> return -EACCES;
>
> @@ -2177,15 +2192,15 @@ static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
> * We don't support binding to any address if anyone is bound to
> * a specific address on the same port.
> */
> - if (cma_any_addr((struct sockaddr *) &id_priv->id.route.addr.src_addr))
> + if (cma_any_addr(addr))
> return -EADDRNOTAVAIL;
>
> hlist_for_each_entry(cur_id, node, &bind_list->owners, node) {
> - if (cma_any_addr((struct sockaddr *) &cur_id->id.route.addr.src_addr))
> + cur_addr = (struct sockaddr *) &cur_id->id.route.addr.src_addr;
> + if (cma_any_addr(cur_addr))
> return -EADDRNOTAVAIL;
>
> - cur_sin = (struct sockaddr_in *) &cur_id->id.route.addr.src_addr;
> - if (sin->sin_addr.s_addr == cur_sin->sin_addr.s_addr)
> + if (!cma_addr_cmp(addr, cur_addr))
> return -EADDRINUSE;
> }
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Ira Weiny
Math Programmer/Computer Scientist
Lawrence Livermore National Lab
925-423-8008
weiny2-i2BcT+NCU+M@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2011-05-10 21:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-16 6:42 [PATCH 1/2] rdma/cm: fix handling of ipv6 addressing in cma_use_port Hefty, Sean
[not found] ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25DCC49B2B-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-04-16 6:46 ` [PATCH 2/2] rdma/cm: Support REUSEADDR Hefty, Sean
[not found] ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25DCC49B2C-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2011-04-29 16:12 ` Roland Dreier
2011-05-10 21:30 ` Ira Weiny
2011-05-10 21:30 ` Ira Weiny [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110510143020.7e6d3d4e.weiny2@llnl.gov \
--to=weiny2-i2bct+ncu+m@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox