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

SocketUtil: explicitly set V6ONLY socket option #712

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

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Jan 16, 2020

Currently, MPD emits the following warning on Linux when
net.ipv6.bindv6only is set to the default value zero:

exception: bind to '0.0.0.0:6600' failed (continuing anyway, because binding to '[::]:6600' succeeded): Failed to bind socket: Address already in use

This is a known issues (#673, #557, …) caused by the fact that MPD, by
default, creates separate sockets for AF_INET and AF_INET6. With
this architecture it is not necessary to use the AF_INET6 socket for
both IPv6 and IPv4. For this reason, explicitly enable the V6ONLY
socket option for AF_INET6 sockets, thereby preventing the error
causing the warning to be emitted.

@MaxKellermann
Copy link
Member

I thought of doing this a few times, but didn't because I didn't want to override the admin's global setting for this. By default, MPD should be a good citizen and should follow global configuration.
And don't forget: your proposed code change breaks configurations where admins have disabled "v6only" globally and made MPD bind to "::"; with your change, they can't use IPv4 anymore.
Do you have a good justification for this breaking change?

@nmeum
Copy link
Contributor Author

nmeum commented Jan 16, 2020

And don't forget: your proposed code change breaks configurations where admins have disabled "v6only" globally and made MPD bind to "::"; with your change, they can't use IPv4 anymore.

I think the amount of people doing that is close to zero. Besides, if you bind a socket to a specific IPv6 address through a software configuration option I would not expect the software to create an IPv4 socket as well. Also keep in mind that this only works for in6addr_any. If you bind explicitly to some other IPv6 address it will only create an IPv6 socket, even on current git head. If the intention of the admin is to bind MPD to both IPv6 and IPv4 he can simply use bind_to_address "any" instead of bind_to_address "::" in the first place.

I thought of doing this a few times, but didn't because I didn't want to override the admin's global setting for this. By default, MPD should be a good citizen and should follow global configuration.

I don't think that this is a popular interpretation of net.ipv6.bindv6only. In my experience, most software sets this socket option explicitly, either creating a single IPv6 socket and disabling V6ONLY or creating two sockets and enabling V6ONLY.

@neheb
Copy link
Contributor

neheb commented Feb 18, 2020

This needs to be rebased to pass Travis.

@nmeum nmeum force-pushed the v6only branch 2 times, most recently from 6a8c4e3 to 65b4c5e Compare February 19, 2020 10:51
@nmeum
Copy link
Contributor Author

nmeum commented Feb 19, 2020

Rebased and fixed the build on Mac OS.

MPD seems to only support Linux and Mac OS currently. The IPV6_V6ONLY
socket option is supported by both of these operating systems. Regarding
Mac OS X, consult the ip6(4) man page for more information.
Currently, MPD emits the following warning on Linux when
`net.ipv6.bindv6only` is set to the default value zero:

	exception: bind to '0.0.0.0:6600' failed (continuing anyway,
	because binding to '[::]:6600' succeeded): Failed to bind
	socket: Address already in use

This is a known issues (MusicPlayerDaemon#673, MusicPlayerDaemon#557, …) caused by the fact that MPD, by
default, creates separate sockets for `AF_INET` and `AF_INET6`. With
this architecture it is not necessary to use the `AF_INET6` socket for
both IPv6 and IPv4. For this reason, explicitly enable the V6ONLY
socket option for `AF_INET6` sockets, thereby preventing the error
causing the warning to be emitted.
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

3 participants