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

Comments

Projects
None yet
5 participants
@Alex-Richman

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

This comment has been minimized.

Show comment
Hide comment
@lategoodbye

lategoodbye Jun 30, 2018

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

lategoodbye commented Jun 30, 2018

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

@toast-uz

This comment has been minimized.

Show comment
Hide comment
@toast-uz

toast-uz Jul 31, 2018

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?

Contributor

toast-uz commented Jul 31, 2018

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?

@Alex-Richman

This comment has been minimized.

Show comment
Hide comment
@Alex-Richman

Alex-Richman Jul 31, 2018

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.

Alex-Richman commented Jul 31, 2018

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

This comment has been minimized.

Show comment
Hide comment
@toast-uz

toast-uz Jul 31, 2018

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.

Contributor

toast-uz commented Jul 31, 2018

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

This comment has been minimized.

Show comment
Hide comment
@toast-uz

toast-uz Jul 31, 2018

Contributor

Sorry the former and the latter should be replaced.

Contributor

toast-uz commented Jul 31, 2018

Sorry the former and the latter should be replaced.

@Alex-Richman

This comment has been minimized.

Show comment
Hide comment
@Alex-Richman

Alex-Richman Jul 31, 2018

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.

Alex-Richman commented Jul 31, 2018

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

This comment has been minimized.

Show comment
Hide comment
@toast-uz

toast-uz Jul 31, 2018

Contributor

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

Contributor

toast-uz commented Jul 31, 2018

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

@karlp

This comment has been minimized.

Show comment
Hide comment
@karlp

karlp Jul 31, 2018

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@Alex-Richman

Alex-Richman Jul 31, 2018

My mistake, fixed :)

Cheers,

  • Alex.

Alex-Richman commented Jul 31, 2018

My mistake, fixed :)

Cheers,

  • Alex.

ralight added a commit that referenced this issue Aug 2, 2018

Remove use of AI_ADDRCONFIG.
Closes #869, #901.

Thanks to Alex Richman.

Signed-off-by: Roger A. Light <roger@atchoo.org>

@ralight ralight added this to the 1.5.1 milestone Aug 2, 2018

@ralight

This comment has been minimized.

Show comment
Hide comment
@ralight

ralight Aug 2, 2018

Contributor

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.

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

This comment has been minimized.

Show comment
Hide comment
@Alex-Richman

Alex-Richman Aug 2, 2018

Nice one, I can confirm the fixes branch works.

Cheers,

  • Alex.

Alex-Richman commented Aug 2, 2018

Nice one, I can confirm the fixes branch works.

Cheers,

  • Alex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment