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

Copy scope id when binding to IPv6 Link-Local address #2969

Open
wants to merge 2 commits into
base: fixes
Choose a base branch
from

Conversation

ThymoNL
Copy link

@ThymoNL ThymoNL commented Dec 18, 2023

Thank you for contributing your time to the Mosquitto project!

Before you go any further, please note that we cannot accept contributions if
you haven't signed the Eclipse Contributor Agreement.
If you aren't able to do that, or just don't want to, please describe your bug
fix/feature change in an issue. For simple bug fixes it is can be just as easy
for us to be told about the problem and then go fix it directly.

Then please check the following list of things we ask for in your pull request:

  • Have you signed the Eclipse Contributor Agreement, using the same email address as you used in your commits?
  • Do each of your commits have a "Signed-off-by" line, with the correct email address? Use "git commit -s" to generate this line for you.
  • If you are contributing a bugfix, is your work based off the fixes branch?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run make test with your changes locally?

Configuring a listener with bind_interface on an interface with an ipv6 link-local address causes Mosquitto to exit with "Error: invalid argument". This happens due to the the IPv6 scope ID not being copied to the returned addrinfo struct when resolving interfaces matching bind_interface.

This PR adds a commit that also copies the sin6_scope_id when a matching interface is found.

Fixes #2696

Signed-off-by: Thymo van Beers <[email protected]>
Binding to an IPv6 Link-Local address requires the scope ID to be set.
If this is not set bind will return EINVAL.

Signed-off-by: Thymo van Beers <[email protected]>
@ThymoNL
Copy link
Author

ThymoNL commented Jan 24, 2024

@ralight May I gently bump this your way? Hoping you can take a look at this bugfix. 🙂

@@ -673,6 +673,9 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
memcpy(&((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr,
&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr,
sizeof(struct in6_addr));

((struct sockaddr_in6 *)rp->ai_addr)->sin6_scope_id = ((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why the memcpy call in line 673 isn't sufficient to copy this value already?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your question why only copying the in6_addr is not enough? That's because for link-local addresses they are only valid for a specific interface, you can specify which interface the address belongs to with the scope id.

If your question is why I didn't group everything into a single memcpy call. That was for readability.

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

Successfully merging this pull request may close these issues.

None yet

2 participants