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

IpV6 link local addresses resolve but don't connect #1464

Open
rdaum opened this issue Apr 9, 2024 · 2 comments
Open

IpV6 link local addresses resolve but don't connect #1464

rdaum opened this issue Apr 9, 2024 · 2 comments

Comments

@rdaum
Copy link

rdaum commented Apr 9, 2024

Describe the bug

ipv6 link local style addresses don't work.

paho.mqtt.c successfully resolves addresses of the form

tcp://[xxxx::xxxx:xxxx:xxxx%eth0]:1883

But when it comes to connect, the complete results from getaddrinfo are not copied over into the addrinfo, as per line 1130 of Socket.c:

		if (res->ai_family == AF_INET6)
		{
			address6.sin6_port = htons(port);
			address6.sin6_family = family = AF_INET6;
			memcpy(&address6.sin6_addr, &((struct sockaddr_in6*)(res->ai_addr))->sin6_addr, sizeof(address6.sin6_addr));

This only copies over the address, but not the sin6_scope_id and sin6_flowinfo, so the complete link local address cannot connect.

Adding these two lines (or cleaner variant thereof) led to success for me:

			memcpy(&address6.sin6_scope_id, &((struct sockaddr_in6*)(res->ai_addr))->sin6_scope_id, sizeof(address6.sin6_scope_id));
			memcpy(&address6.sin6_flowinfo, &((struct sockaddr_in6*)(res->ai_addr))->sin6_flowinfo, sizeof(address6.sin6_flowinfo));
		}

To Reproduce

Attempt to connect to an ipv6 link local address to a mqtt broker. It will fail at connect time. Adding the two lines listed above makes it succeed.

Expected behavior

Paho should be able to connect to a broker using such an address.

** Environment (please complete the following information):**

  • Linux
  • paho.mqtt.c checked out @ commit hash 6b1e202
rdaum pushed a commit to rdaum/paho.mqtt.c that referenced this issue Apr 10, 2024
Paho currently successfully resolves IPv6 link-local addresses (of the
form `tcp://[xxxx::xxxx:xxxx:xxxx%eth0]:1883`). But it does not copy
the resolved link information over when attempting to make the
connection.

This is a 3-line fix.

See: eclipse-paho#1464
@rdaum
Copy link
Author

rdaum commented Apr 10, 2024

Fix at master...rdaum:paho.mqtt.c:master

I'd create a PR, but I'm not going to go register and sign the Eclipse contributors agreement just for this. Please apply it yourselves.

jumoog pushed a commit to jumoog/paho.mqtt.c that referenced this issue Apr 10, 2024
Paho currently successfully resolves IPv6 link-local addresses (of the
form `tcp://[xxxx::xxxx:xxxx:xxxx%eth0]:1883`). But it does not copy
the resolved link information over when attempting to make the
connection.

This is a 3-line fix.

See: eclipse-paho#1464
jumoog added a commit to jumoog/paho.mqtt.c that referenced this issue Apr 10, 2024
Paho currently successfully resolves IPv6 link-local addresses (of the
form `tcp://[xxxx::xxxx:xxxx:xxxx%eth0]:1883`). But it does not copy
the resolved link information over when attempting to make the
connection.

This is a 3-line fix.

See: eclipse-paho#1464
@jumoog
Copy link
Contributor

jumoog commented Apr 10, 2024

I made a PR.. #1466 I had to reset the author to pass eca check. I hope thats fine for everybody.

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