After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 687092 - IPv6 <-> IPv4 mismatch when subscribing to multicast (send)
IPv6 <-> IPv4 mismatch when subscribing to multicast (send)
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
2.35.x
Other Linux
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-10-29 08:48 UTC by Marc Leeman
Modified: 2012-12-17 14:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use IPv4 socket handling when mc address is IPv4, even on IPv6 socket (1.12 KB, patch)
2012-10-29 10:33 UTC, Marc Leeman
none Details | Review
force ipv4 socket if dest is ipv4 (954 bytes, patch)
2012-10-29 15:07 UTC, Marc Leeman
none Details | Review
verbose socket creation (1.92 KB, patch)
2012-10-29 15:08 UTC, Marc Leeman
none Details | Review
gsocket: improve sockopt handling for IPv4-wrapped-IPv6 sockets (3.04 KB, patch)
2012-12-12 15:53 UTC, Dan Winship
committed Details | Review

Description Marc Leeman 2012-10-29 08:48:45 UTC
Entered in GStreamer, but is caused by GLib.

https://bugzilla.gnome.org/show_bug.cgi?id=687090

I am trying to confirm with git atm.
Comment 1 Marc Leeman 2012-10-29 09:35:06 UTC
A system built with jhbuild and including a git version of glib has the same issue.

libglib-2.0.so.0.3501.0
Comment 2 Marc Leeman 2012-10-29 10:33:27 UTC
Created attachment 227514 [details] [review]
Use IPv4 socket handling when mc address is IPv4, even on IPv6 socket
Comment 3 Dan Winship 2012-10-29 12:11:45 UTC
> Debian is running in IPv6 completely; while providing compatibility with an
> IPv4 network.

Can you clarify exactly what you mean by that? How is your networking configured?
Comment 4 Marc Leeman 2012-10-29 12:20:03 UTC
As far as I know, a lot of distros are internally running IPv6; so software is mostly creating IPv6 sockets; but the configuration provides compatibility with a classical ipv4 network. As a result the software can completely be written for IPv6; while the lower layers of the OS do the backwards compatibility layer.

So, when a socket is created, it is mostly an ipv6 socket on modern distros (tested with Debian, ArchLinux, I assume that Ubuntu is the same).

In the case of GLib; an IPv6 socket is also created and used; but when joining a multicast group, there is check if the socket (IPv6) matches the family of the multicast group (IPv4); if this fails; the code exits.

The patch here removes this check and will apply the IPv4 logic if either the socket is IPv4 or if the multicast group is IPv4.

As a result; the IPv6 socket joins a IPv4 multicast group.

eth0      Link encap:Ethernet  HWaddr bc:ae:c5:0d:da:d6  
          inet addr:172.16.10.78  Bcast:172.16.10.255  Mask:255.255.255.0
          inet6 addr: fe80::beae:c5ff:fe0d:dad6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5230258 errors:0 dropped:4 overruns:0 frame:0
          TX packets:3972303 errors:0 dropped:0 overruns:0 carrier:13
          collisions:0 txqueuelen:1000 
          RX bytes:4544346828 (4.2 GiB)  TX bytes:1388919311 (1.2 GiB)

Because of this strict checking; GStreamer cannot send out data on a multicast address on any of these OSes.
Comment 5 Dan Winship 2012-10-29 14:02:32 UTC
Comment on attachment 227514 [details] [review]
Use IPv4 socket handling when mc address is IPv4, even on IPv6 socket

That's not entirely accurate, but, ok, yes, udpsink appears to always create IPv6 sockets and then expect the v4mapping magic to work.

>+  if ((socket->priv->family == G_SOCKET_FAMILY_IPV4)
>+		  || (g_inet_address_get_family (group) == G_SOCKET_FAMILY_IPV4))

Really, we should just base the decision on the address's family, not the socket's, and just return the underlying setsockopt() error if the caller tries to do something that doesn't work.

However, there's still another problem, which is that the g_socket_set_multicast_loopback(), g_socket_set_multicast_ttl(), and g_socket_set_ttl() calls will end up setting the IPv6 sockopts, not the IPv4 sockopts, and so won't have any effect on IPv4 multicast. I think. Are you able to test that?

If so, there's not really any good fix for this, other than "don't try to do IPv4 multicast on an IPv6 socket"
Comment 6 Marc Leeman 2012-10-29 15:06:53 UTC
I'm attaching a patch to catch this on GStreamer level, the alternative would be to catch the error on setsockopts for IPv4 and try again with IPv6.
Comment 7 Marc Leeman 2012-10-29 15:07:43 UTC
Created attachment 227538 [details] [review]
force ipv4 socket if dest is ipv4
Comment 8 Marc Leeman 2012-10-29 15:08:52 UTC
Created attachment 227539 [details] [review]
verbose socket creation
Comment 9 Dan Winship 2012-11-02 14:25:18 UTC
(In reply to comment #5)
> If so, there's not really any good fix for this, other than "don't try to do
> IPv4 multicast on an IPv6 socket"

actually, that's not true; we can just always try to set both the IPv6 property and the IPv4 property if we have an IPv6 socket
Comment 10 Dan Winship 2012-12-12 15:53:09 UTC
Created attachment 231388 [details] [review]
gsocket: improve sockopt handling for IPv4-wrapped-IPv6 sockets

On IPv6 sockets, set both the IPv4 and IPv6 versions of IP socket
options, in case the socket is (or might become) IPv4-wrapped. (But
ignore errors when setting the IPv4 version.)

Similarly, when joining or leaving a multicast group, pick the sockopt
to use based on the address family of the multicast address rather
than the address family of the socket.
Comment 11 Colin Walters 2012-12-12 16:20:20 UTC
Review of attachment 231388 [details] [review]:

Ok, not a networking expert, but this looks reasonable to me.
Comment 12 Dan Winship 2012-12-17 14:03:07 UTC
Attachment 231388 [details] pushed as df334d6 - gsocket: improve sockopt handling for IPv4-wrapped-IPv6 sockets