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

mosquitto_connect() fails on systems with no IPv4 addresses configured. #869

Closed
Alex-Richman opened this issue Jun 28, 2018 · 11 comments
Closed
Labels
Component: mosquitto-broker Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Milestone

Comments

@Alex-Richman
Copy link

Alex-Richman commented Jun 28, 2018

mosquitto_connect() will fail on systems with no IPv4 addresses configured. Even when connecting via the loopback interface to localhost.

e.g.:

ip addr flush dev eth0
./redacted 127.0.0.1
... [ Snip ] ...
Unable to connect: mosquitto_connect() failed (Lookup error)

ip addr add 192.168.0.1 dev eth0
./redacted 127.0.0.1
... [ Snip ] ...
Connected to broker on 127.0.0.1

From a brief look at the source, I believe this is because net__try_connect (lib/net_mosq.c:300) is using AI_ADDRCONFIG to enumerate local IP addresses to bind to. Per the RFC this fails when the system has no IPv4 addresses configured (lo not being considered a configured address):

 - If the AI_ADDRCONFIG flag is specified, IPv4 addresses shall be
   returned only if an IPv4 address is configured on the local system,
   and IPv6 addresses shall be returned only if an IPv6 address is
   configured on the local system.  The loopback address is not
   considered for this case as valid as a configured address.

This may be related to #736

(internal ID CORE4-909)

Cheers,

  • Alex.
@lategoodbye
Copy link

Do we always need the flag AI_ADDRCONFIG for both getaddrinfo cases?

@toast-uz
Copy link
Contributor

I'd like to confirm the background. Disabling IPv4 addresses is frequently in these days? Many other network softwares have already corresponded with the situation?

@toast-uz toast-uz added the Status: Blocked Another issue needs to be resolved first label Jul 31, 2018
@Alex-Richman
Copy link
Author

Certainly on embedded devices having no IPv4 addresses configured is very common (indeed having no interfaces except loopback is common).

In our case mosquitto is brokering messages between various modules which are themselves attempting to configure the system's IPv4 addresses as part of system startup (but are having a hard time since mosquitto needs the IPv4 addresses to be configured before it will connect...).

Either way I did patch this locally by removing the AI_ADDRCONFIG flag, which seems to work fine on our systems - I don't know if it's compatible with all configurations though.

Cheers,

  • Alex.

@toast-uz
Copy link
Contributor

Thanks @Alex-Richman . It's great If you can submit your patch as a new PR.

I'd like to consult you. Should this issue be treated as a bug by lack of a primitive and nothing special feature, or as a new great and special feature?

If the former, I will label as an enhancement and close this issue, you can submit a new PR and link this close issue. If the latter, I will label as a bug and keep this issue, you can submit a new PR and link this open issue.

@toast-uz
Copy link
Contributor

Sorry the former and the latter should be replaced.

@Alex-Richman
Copy link
Author

Sure, PR above (#901).

I'd consider it a bug. As far as I can tell the AI_ADDRCONFIG flag isn't required and seems to cause issues so shrug.

Cheers,

  • Alex.

@toast-uz toast-uz added Type: Bug Component: mosquitto-broker and removed Status: Blocked Another issue needs to be resolved first labels Jul 31, 2018
@toast-uz
Copy link
Contributor

OK. I labeled. Keep this issue until your PR merged.

@karlp
Copy link
Contributor

karlp commented Jul 31, 2018

This is for a system with loopback only not just "no ipv4" If you had ipv6 addresses, you'd get a v6 address back, which would still work. Bug's valid, fix looks correct, just the description is a little off.

@Alex-Richman
Copy link
Author

My mistake, fixed :)

Cheers,

  • Alex.

ralight added a commit that referenced this issue Aug 2, 2018
Closes #869, #901.

Thanks to Alex Richman.

Signed-off-by: Roger A. Light <[email protected]>
@ralight ralight added this to the 1.5.1 milestone Aug 2, 2018
@ralight ralight added the Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. label Aug 2, 2018
@ralight
Copy link
Contributor

ralight commented Aug 2, 2018

I've made the change that removes this, if you test the fixes branch you should get that new code. If you're happy, please close the issue. There were a few other places to remove it from as well, so I did it myself rather than using your PR, I hope you don't mind.

@Alex-Richman
Copy link
Author

Nice one, I can confirm the fixes branch works.

Cheers,

  • Alex.

ralight added a commit that referenced this issue Nov 8, 2018
Closes #869, #901.

Thanks to Alex Richman.

Signed-off-by: Roger A. Light <[email protected]>
@lock lock bot locked as resolved and limited conversation to collaborators Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: mosquitto-broker Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Projects
None yet
Development

No branches or pull requests

5 participants