Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: zmq_connect with IPv6 "source:port;dest:port" format is broken #2107

Closed
Prachi2807 opened this issue Sep 15, 2016 · 12 comments
Closed

Comments

@Prachi2807
Copy link

Prachi2807 commented Sep 15, 2016

Following is the snippet of code :

void* ctx= zmq_ctx_new();
void* socket =zmq_socket(ctx,ZMQ_DEALER);
int opt = 1;
zmq_setsockopt(socket, ZMQ_IPV6, &opt, sizeof(int));
int rc1=zmq_bind(socket,"tcp://[::ffff:127.0.0.1]:5559");
assert(rc1==0);
rc1=zmq_connect(socket,"tcp://[::ffff:127.0.0.1:5552];[::ffff:127.0.0.1]:5558");
assert(rc1==0);
zmq_close(socket);
zmq_ctx_destroy(ctx);

output :
int main(): Assertion `rc1==0' failed.
Aborted (core dumped)

Can u tell why it's happening? With IPV4 addresses its working fine.

@bluca
Copy link
Member

bluca commented Sep 15, 2016

Which version of libzmq? Which operating system and version?

@bluca
Copy link
Member

bluca commented Sep 15, 2016

Also you can't both bind and connect the same socket

@Prachi2807
Copy link
Author

Libzmq version - zeromq-4.1.4

OS - Linux Version 2.6.32-504.30.3.el6.x86_64 x86_64

@Prachi2807
Copy link
Author

But when I tried the same code with IPV4 address, its working fine.

@bluca
Copy link
Member

bluca commented Sep 15, 2016

First of all, there was a new release and there were a couple ipv6 fixes, check 4.1.5.
Then, what is the point of both binding and connecting a socket? Have you tried with 2 different sockets?

@Prachi2807
Copy link
Author

void* ctx= zmq_ctx_new();
void* socket2=zmq_socket(ctx,ZMQ_DEALER);
int opt = 1;
zmq_setsockopt(socket2, ZMQ_IPV6, &opt, sizeof(int));
int rc1=zmq_connect(socket2,"tcp://[::ffff:127.0.0.1]:15000;[::ffff:127.0.0.1]:5558");
if(rc1!=0)
printf ("Error occurred during zmq_init(): %s\n", zmq_strerror (errno));
// assert(rc1==0);
zmq_close(socket2);
zmq_ctx_destroy(ctx);
return 0;

I tried in zeromq-4.1.5
The error now is coming :
Error occurred during zmq_init(): Invalid argument

@Prachi2807
Copy link
Author

Correction :
This is the output
Error occurred during zmq_connect(): Invalid argument

@bluca
Copy link
Member

bluca commented Sep 16, 2016

Yes I can reproduce the problem in a simple test, thanks for the report. I can have a look early next week as I'm travelling this weekend.

@bluca bluca changed the title zmq connect with source(ipv6:port) : assertion failed Problem: zmq_connect with many IPv6 endpoints is broken Sep 16, 2016
@Prachi2807
Copy link
Author

Found the issue :
in the file socket_base.cpp
inside the function
int zmq::socket_base_t::connect (const char *addr)
{
1 const char _check = address.c_str ();
2 if (isalnum (_check) || isxdigit (_check) || *check == '[') {
3 check++;
4 while (isalnum (check)
5 || isxdigit (*check)
6 || *check == '.' || *check == '-' || *check == ':'|| *check == ';'
7 || *check == ']')
8 {
9 check++;
10 }
11 }
}

for zmq_connect with source ipv6addr:port
value of check = [::ffff:127.0.0.1]:15000;[::ffff:127.0.0.1]:5558
in Line 2, first check is there for '[' and then it will go inside the while loop
in while loop , it will check for alpnum, hexadecimal digit, '.' , '-' , ':', ';', ']'
for the second square bracket '[' in check ([::ffff:127.0.0.1]:15000;[::ffff:127.0.0.1]:5558) will fail, as in the while loop no check is there for opening square bracket.
so , the correction will be to add opening square bracket as below

_while (isalnum (_check)
|| isxdigit (check)
*|| check == '['
|| *check == '.' || *check == '-' || *check == ':'|| *check == ';'
|| *check == ']')

@bluca
Copy link
Member

bluca commented Sep 16, 2016

Yes I found that, unfortunately there's bigger problems than that, bouncing messages with multiple connects seems broken as well, I'll dig deeper on Monday

@bluca
Copy link
Member

bluca commented Sep 17, 2016

Ah, a silly oversight! Went back and checked again, and the ";" delimiter is to separate source and destination addresses when connecting, not for multiple endpoints: http://api.zeromq.org/4-1:zmq-tcp

For multiple endpoints simply do multiple zmq_connect calls.

That said, the source;dest is indeed broken with IPv6, will send a PR to fix it.

@bluca bluca changed the title Problem: zmq_connect with many IPv6 endpoints is broken Problem: zmq_connect with IPv6 "source:port;dest:port" format is broken Sep 17, 2016
@Prachi2807
Copy link
Author

Yeah dts wt I told you, for zmq_connect with sourceIp:port and
destinationIp:port, it was failing. Now , the problem is fixed. That's
good.

On 17-Sep-2016 11:40 pm, "Luca Boccassi" notifications@github.com wrote:

Ah, a silly oversight! Went back and checked again, and the ";" delimiter
is to separate source and destination addresses when connecting, not for
multiple endpoints: http://api.zeromq.org/4-1:zmq-tcp

For multiple endpoints simply do multiple zmq_connect calls.

That said, the source;dest is indeed broken with IPv6, will send a PR to
fix it.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2107 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AVL7vWalZEHqzLm-JF5-ynrQGkdcGsjHks5qrCz7gaJpZM4J96kt
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants