diff mbox

librdmacm: Add command line option to specify server

Message ID 20180301125846.5385-1-yuval.shaia@oracle.com (mailing list archive)
State Accepted
Delegated to: Leon Romanovsky
Headers show

Commit Message

Yuval Shaia March 1, 2018, 12:58 p.m. UTC
Add a command line option to allow selecting specific address as done in
rdma_client.

Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
---
 librdmacm/examples/rdma_server.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Leon Romanovsky March 5, 2018, 6:55 a.m. UTC | #1
On Thu, Mar 01, 2018 at 02:58:46PM +0200, Yuval Shaia wrote:
> Add a command line option to allow selecting specific address as done in
> rdma_client.
>
> Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> ---
>  librdmacm/examples/rdma_server.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/librdmacm/examples/rdma_server.c b/librdmacm/examples/rdma_server.c
> index bcf649fe..77c021ac 100644
> --- a/librdmacm/examples/rdma_server.c
> +++ b/librdmacm/examples/rdma_server.c
> @@ -36,6 +36,7 @@
>  #include <rdma/rdma_cma.h>
>  #include <rdma/rdma_verbs.h>
>
> +static const char *server = "127.0.0.1";
>  static const char *port = "7471";
>
>  static struct rdma_cm_id *listen_id, *id;
> @@ -55,7 +56,7 @@ static int run(void)
>  	memset(&hints, 0, sizeof hints);
>  	hints.ai_flags = RAI_PASSIVE;
>  	hints.ai_port_space = RDMA_PS_TCP;
> -	ret = rdma_getaddrinfo(NULL, port, &hints, &res);
> +	ret = rdma_getaddrinfo(server, port, &hints, &res);

In such case (server is going to be not-NULL), the AI_PASSIVE hint
will be ignored by getaddrinfo, but don't know whenever it is safe to
remove "hints.ai_flags = RAI_PASSIVE;" line above.

What do you think?

Thanks
Leon Romanovsky March 12, 2018, 2:01 p.m. UTC | #2
On Mon, Mar 05, 2018 at 08:55:25AM +0200, Leon Romanovsky wrote:
> On Thu, Mar 01, 2018 at 02:58:46PM +0200, Yuval Shaia wrote:
> > Add a command line option to allow selecting specific address as done in
> > rdma_client.
> >
> > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> > ---
> >  librdmacm/examples/rdma_server.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/librdmacm/examples/rdma_server.c b/librdmacm/examples/rdma_server.c
> > index bcf649fe..77c021ac 100644
> > --- a/librdmacm/examples/rdma_server.c
> > +++ b/librdmacm/examples/rdma_server.c
> > @@ -36,6 +36,7 @@
> >  #include <rdma/rdma_cma.h>
> >  #include <rdma/rdma_verbs.h>
> >
> > +static const char *server = "127.0.0.1";
> >  static const char *port = "7471";
> >
> >  static struct rdma_cm_id *listen_id, *id;
> > @@ -55,7 +56,7 @@ static int run(void)
> >  	memset(&hints, 0, sizeof hints);
> >  	hints.ai_flags = RAI_PASSIVE;
> >  	hints.ai_port_space = RDMA_PS_TCP;
> > -	ret = rdma_getaddrinfo(NULL, port, &hints, &res);
> > +	ret = rdma_getaddrinfo(server, port, &hints, &res);
>
> In such case (server is going to be not-NULL), the AI_PASSIVE hint
> will be ignored by getaddrinfo, but don't know whenever it is safe to
> remove "hints.ai_flags = RAI_PASSIVE;" line above.
>
> What do you think?

Yuval?

>
> Thanks
Yuval Shaia March 12, 2018, 5:29 p.m. UTC | #3
On Mon, Mar 05, 2018 at 08:55:25AM +0200, Leon Romanovsky wrote:
> On Thu, Mar 01, 2018 at 02:58:46PM +0200, Yuval Shaia wrote:
> > Add a command line option to allow selecting specific address as done in
> > rdma_client.
> >
> > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
> > ---
> >  librdmacm/examples/rdma_server.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/librdmacm/examples/rdma_server.c b/librdmacm/examples/rdma_server.c
> > index bcf649fe..77c021ac 100644
> > --- a/librdmacm/examples/rdma_server.c
> > +++ b/librdmacm/examples/rdma_server.c
> > @@ -36,6 +36,7 @@
> >  #include <rdma/rdma_cma.h>
> >  #include <rdma/rdma_verbs.h>
> >
> > +static const char *server = "127.0.0.1";
> >  static const char *port = "7471";
> >
> >  static struct rdma_cm_id *listen_id, *id;
> > @@ -55,7 +56,7 @@ static int run(void)
> >  	memset(&hints, 0, sizeof hints);
> >  	hints.ai_flags = RAI_PASSIVE;
> >  	hints.ai_port_space = RDMA_PS_TCP;
> > -	ret = rdma_getaddrinfo(NULL, port, &hints, &res);
> > +	ret = rdma_getaddrinfo(server, port, &hints, &res);

Hi Leon,

> 
> In such case (server is going to be not-NULL), the AI_PASSIVE hint
> will be ignored by getaddrinfo, but don't know whenever it is safe to
> remove "hints.ai_flags = RAI_PASSIVE;" line above.
> 
> What do you think?

Just read man page and realized that you are correct, when 'node' argument
is given the AI_PASSIVE is ignored.
I am confused, why can't i have them both? i.e be *passive* side of the
connection *while* still bind to specific source address.

I tried your suggestions, first this flag is used not only in call to
getaddrinfo so not sure it is safe to remove the setting. Second, i tried
that :) and it fails in rdma_listen phase.

> 
> Thanks


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hefty, Sean March 12, 2018, 5:39 p.m. UTC | #4
> Just read man page and realized that you are correct, when 'node'
> argument is given the AI_PASSIVE is ignored.
> I am confused, why can't i have them both? i.e be *passive* side of
> the connection *while* still bind to specific source address.

The behavior matches getaddrinfo():

       If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
       NULL, then the returned socket addresses will be suitable for
       bind(2)ing a socket that will accept(2) connections.  The returned
       socket address will contain the "wildcard address" (INADDR_ANY for
       IPv4 addresses, IN6ADDR_ANY_INIT for IPv6 address).  The wildcard
       address is used by applications (typically servers) that intend to
       accept connections on any of the host's network addresses.  If node
       is not NULL, then the AI_PASSIVE flag is ignored.

You can call getaddrinfo() without the passive flag and simply use the returned address as input into bind, provided that you know the address is local.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yuval Shaia March 12, 2018, 6:40 p.m. UTC | #5
On Mon, Mar 12, 2018 at 05:39:07PM +0000, Hefty, Sean wrote:
> > Just read man page and realized that you are correct, when 'node'
> > argument is given the AI_PASSIVE is ignored.
> > I am confused, why can't i have them both? i.e be *passive* side of
> > the connection *while* still bind to specific source address.
> 
> The behavior matches getaddrinfo():
> 
>        If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
>        NULL, then the returned socket addresses will be suitable for
>        bind(2)ing a socket that will accept(2) connections.  The returned
>        socket address will contain the "wildcard address" (INADDR_ANY for
>        IPv4 addresses, IN6ADDR_ANY_INIT for IPv6 address).  The wildcard
>        address is used by applications (typically servers) that intend to
>        accept connections on any of the host's network addresses.  If node
>        is not NULL, then the AI_PASSIVE flag is ignored.
> 
> You can call getaddrinfo() without the passive flag and simply use the returned address as input into bind, provided that you know the address is local.

Yeah perfect, it goes hand by hand with my testings. So actually AI_PASSIVE
can be skipped in local server case, right?

Leon,
Since RAI_PASSIVE is used not only for getaddrinfo i would leave it's
settings as it is unless you have an objection.

What do you think?

> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leon Romanovsky March 13, 2018, 4:58 p.m. UTC | #6
On Mon, Mar 12, 2018 at 08:40:14PM +0200, Yuval Shaia wrote:
> On Mon, Mar 12, 2018 at 05:39:07PM +0000, Hefty, Sean wrote:
> > > Just read man page and realized that you are correct, when 'node'
> > > argument is given the AI_PASSIVE is ignored.
> > > I am confused, why can't i have them both? i.e be *passive* side of
> > > the connection *while* still bind to specific source address.
> >
> > The behavior matches getaddrinfo():
> >
> >        If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
> >        NULL, then the returned socket addresses will be suitable for
> >        bind(2)ing a socket that will accept(2) connections.  The returned
> >        socket address will contain the "wildcard address" (INADDR_ANY for
> >        IPv4 addresses, IN6ADDR_ANY_INIT for IPv6 address).  The wildcard
> >        address is used by applications (typically servers) that intend to
> >        accept connections on any of the host's network addresses.  If node
> >        is not NULL, then the AI_PASSIVE flag is ignored.
> >
> > You can call getaddrinfo() without the passive flag and simply use the returned address as input into bind, provided that you know the address is local.
>
> Yeah perfect, it goes hand by hand with my testings. So actually AI_PASSIVE
> can be skipped in local server case, right?
>
> Leon,
> Since RAI_PASSIVE is used not only for getaddrinfo i would leave it's
> settings as it is unless you have an objection.
>
> What do you think?

Thanks, applied.

>
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yuval Shaia March 14, 2018, 11 a.m. UTC | #7
On Tue, Mar 13, 2018 at 06:58:58PM +0200, Leon Romanovsky wrote:
> On Mon, Mar 12, 2018 at 08:40:14PM +0200, Yuval Shaia wrote:
> > On Mon, Mar 12, 2018 at 05:39:07PM +0000, Hefty, Sean wrote:
> > > > Just read man page and realized that you are correct, when 'node'
> > > > argument is given the AI_PASSIVE is ignored.
> > > > I am confused, why can't i have them both? i.e be *passive* side of
> > > > the connection *while* still bind to specific source address.
> > >
> > > The behavior matches getaddrinfo():
> > >
> > >        If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
> > >        NULL, then the returned socket addresses will be suitable for
> > >        bind(2)ing a socket that will accept(2) connections.  The returned
> > >        socket address will contain the "wildcard address" (INADDR_ANY for
> > >        IPv4 addresses, IN6ADDR_ANY_INIT for IPv6 address).  The wildcard
> > >        address is used by applications (typically servers) that intend to
> > >        accept connections on any of the host's network addresses.  If node
> > >        is not NULL, then the AI_PASSIVE flag is ignored.
> > >
> > > You can call getaddrinfo() without the passive flag and simply use the returned address as input into bind, provided that you know the address is local.
> >
> > Yeah perfect, it goes hand by hand with my testings. So actually AI_PASSIVE
> > can be skipped in local server case, right?
> >
> > Leon,
> > Since RAI_PASSIVE is used not only for getaddrinfo i would leave it's
> > settings as it is unless you have an objection.
> >
> > What do you think?
> 
> Thanks, applied.

Thanks, is this means that PR against github repo is not needed?

> 
> >
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leon Romanovsky March 14, 2018, 11:28 a.m. UTC | #8
On Wed, Mar 14, 2018 at 01:00:46PM +0200, Yuval Shaia wrote:
> On Tue, Mar 13, 2018 at 06:58:58PM +0200, Leon Romanovsky wrote:
> > On Mon, Mar 12, 2018 at 08:40:14PM +0200, Yuval Shaia wrote:
> > > On Mon, Mar 12, 2018 at 05:39:07PM +0000, Hefty, Sean wrote:
> > > > > Just read man page and realized that you are correct, when 'node'
> > > > > argument is given the AI_PASSIVE is ignored.
> > > > > I am confused, why can't i have them both? i.e be *passive* side of
> > > > > the connection *while* still bind to specific source address.
> > > >
> > > > The behavior matches getaddrinfo():
> > > >
> > > >        If the AI_PASSIVE flag is specified in hints.ai_flags, and node is
> > > >        NULL, then the returned socket addresses will be suitable for
> > > >        bind(2)ing a socket that will accept(2) connections.  The returned
> > > >        socket address will contain the "wildcard address" (INADDR_ANY for
> > > >        IPv4 addresses, IN6ADDR_ANY_INIT for IPv6 address).  The wildcard
> > > >        address is used by applications (typically servers) that intend to
> > > >        accept connections on any of the host's network addresses.  If node
> > > >        is not NULL, then the AI_PASSIVE flag is ignored.
> > > >
> > > > You can call getaddrinfo() without the passive flag and simply use the returned address as input into bind, provided that you know the address is local.
> > >
> > > Yeah perfect, it goes hand by hand with my testings. So actually AI_PASSIVE
> > > can be skipped in local server case, right?
> > >
> > > Leon,
> > > Since RAI_PASSIVE is used not only for getaddrinfo i would leave it's
> > > settings as it is unless you have an objection.
> > >
> > > What do you think?
> >
> > Thanks, applied.
>
> Thanks, is this means that PR against github repo is not needed?

Yes, there is no need in PR.

>
> >
> > >
> > > > --
> > > > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> > > > the body of a message to majordomo@vger.kernel.org
> > > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
diff mbox

Patch

diff --git a/librdmacm/examples/rdma_server.c b/librdmacm/examples/rdma_server.c
index bcf649fe..77c021ac 100644
--- a/librdmacm/examples/rdma_server.c
+++ b/librdmacm/examples/rdma_server.c
@@ -36,6 +36,7 @@ 
 #include <rdma/rdma_cma.h>
 #include <rdma/rdma_verbs.h>
 
+static const char *server = "127.0.0.1";
 static const char *port = "7471";
 
 static struct rdma_cm_id *listen_id, *id;
@@ -55,7 +56,7 @@  static int run(void)
 	memset(&hints, 0, sizeof hints);
 	hints.ai_flags = RAI_PASSIVE;
 	hints.ai_port_space = RDMA_PS_TCP;
-	ret = rdma_getaddrinfo(NULL, port, &hints, &res);
+	ret = rdma_getaddrinfo(server, port, &hints, &res);
 	if (ret) {
 		printf("rdma_getaddrinfo: %s\n", gai_strerror(ret));
 		return ret;
@@ -163,8 +164,11 @@  int main(int argc, char **argv)
 {
 	int op, ret;
 
-	while ((op = getopt(argc, argv, "p:")) != -1) {
+	while ((op = getopt(argc, argv, "s:p:")) != -1) {
 		switch (op) {
+		case 's':
+			server = optarg;
+			break;
 		case 'p':
 			port = optarg;
 			break;